@malloy-publisher/sdk 0.9.13 → 0.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/RenderedResult-BClN_PG6.cjs.js +154 -0
  2. package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
  3. package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
  4. package/dist/ServerProvider-e2369oom.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +80 -79
  6. package/dist/builder/index.es.js +7430 -6548
  7. package/dist/client/api.d.ts +30 -6
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
  11. package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
  12. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  13. package/dist/components/Dashboard/index.d.ts +1 -1
  14. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  15. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
  18. package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
  19. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  20. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  21. package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
  22. package/dist/components/Report/Report.d.ts +7 -1
  23. package/dist/components/Report/ReportPage.d.ts +7 -0
  24. package/dist/components/Report/layoutRules.d.ts +45 -0
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  26. package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
  27. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  28. package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
  29. package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
  30. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  31. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  32. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  33. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  34. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  35. package/dist/components/ReportBuilder/document.d.ts +53 -5
  36. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  37. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  38. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  39. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  40. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  41. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  42. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  43. package/dist/index.cjs.js +7 -7
  44. package/dist/index.es.js +3328 -3287
  45. package/dist/text/index.es.js +1 -1
  46. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  47. package/dist/theme/resolveTheme.d.ts +15 -0
  48. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  49. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  50. package/dist/utils/blankQuoted.d.ts +15 -0
  51. package/package.json +1 -1
  52. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  53. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  54. package/src/components/Dashboard/DashboardView.tsx +63 -10
  55. package/src/components/Dashboard/TileCard.tsx +6 -0
  56. package/src/components/Dashboard/index.ts +1 -0
  57. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  58. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  59. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  60. package/src/components/Dashboard/useStuck.ts +76 -28
  61. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  62. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  63. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  64. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  65. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  66. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  67. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  68. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  69. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  70. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  71. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  72. package/src/components/RenderedResult/resultSizing.ts +65 -11
  73. package/src/components/Report/Report.spec.tsx +19 -0
  74. package/src/components/Report/Report.tsx +8 -1
  75. package/src/components/Report/ReportPage.tsx +13 -1
  76. package/src/components/Report/layoutRules.spec.ts +43 -3
  77. package/src/components/Report/layoutRules.ts +70 -0
  78. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  79. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  80. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  81. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  82. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  83. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  84. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  85. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  86. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  87. package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
  88. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  89. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  90. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  91. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  92. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  93. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  94. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  95. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  96. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  97. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
  98. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  99. package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
  100. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  101. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  102. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  103. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  104. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  105. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  106. package/src/components/ReportBuilder/catalog.ts +90 -37
  107. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  108. package/src/components/ReportBuilder/chartLine.ts +80 -2
  109. package/src/components/ReportBuilder/controls.ts +4 -3
  110. package/src/components/ReportBuilder/document.ts +65 -7
  111. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  112. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  113. package/src/components/ReportBuilder/imports.ts +1 -1
  114. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  115. package/src/components/ReportBuilder/layout.ts +3 -0
  116. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  117. package/src/components/ReportBuilder/placement.ts +250 -0
  118. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  119. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  120. package/src/components/ReportBuilder/preview.ts +203 -40
  121. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  122. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  123. package/src/components/ReportBuilder/readDocument.ts +194 -23
  124. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  125. package/src/components/ReportBuilder/sortable.tsx +4 -0
  126. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  127. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  128. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  129. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  130. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  131. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  132. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  133. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  134. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  135. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  136. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  137. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  138. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  139. package/src/components/given/FilterButton.spec.tsx +27 -11
  140. package/src/components/given/FilterButton.tsx +19 -6
  141. package/src/theme/resolveTheme.spec.ts +72 -1
  142. package/src/theme/resolveTheme.ts +43 -0
  143. package/src/utils/blankQuoted.spec.ts +50 -0
  144. package/src/utils/blankQuoted.ts +32 -0
  145. package/src/utils/malloyText.ts +2 -1
  146. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  147. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  148. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -1,52 +1,52 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),S=require("../useCompiledDocument-D0OAMejE.cjs.js"),$=require("@mui/material"),k=require("react"),ke=require("../ServerProvider-BIFPCzTD.cjs.js"),he=require("../text-entry-BJwltZiy.cjs.js"),Ju=require("react-dom"),ef=require("@malloydata/malloy-tag"),Fl=require("@tanstack/react-query"),zl=S.createSvgIcon(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Wl=S.createSvgIcon(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),tf=S.createSvgIcon(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Nl(e){const{theme:t}=ke.usePublisherTheme(),n=t.ui,[r,s]=k.useState(null),{status:i,draftKeptAt:o,discard:a,restored:c,dismissRestored:f}=e,d=c!==void 0&&!c.pending&&i==="unsaved"?c:void 0,l=i==="saved"?"Saved":i==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=d?`Restored your unsaved edits from ${Ii(d.savedAt)}`:void 0,h=i==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,p=a!==void 0&&i==="unsaved",y=()=>{s(null),d&&f?.()},w=v=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:i==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...p?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),_=m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i==="saved"?m.jsx(S.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":d?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:d?t.accent:i==="saving"||o!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${S.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:l}),m.jsx(S.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:p?"visible":"hidden"}})]}),g=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:nf,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[g,m.jsx($.Tooltip,{title:u??h,describeChild:!0,children:p?m.jsx($.ButtonBase,{className:S.reportClasses.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>s(v.currentTarget),sx:w,children:_}):m.jsx($.Box,{component:"span",className:S.reportClasses.saveStatus,sx:w,children:_})}),m.jsxs($.Menu,{className:S.reportClasses.menu,anchorEl:r,open:r!==null,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${S.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${Ii(o)}`}),m.jsxs($.MenuItem,{onClick:()=>{s(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(tf,{fontSize:"small"}),"Discard edits"]})]})]})}function Ii(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const nf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},ji=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xt=ji?"⌘":"Ctrl+",Pa=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},ui=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function rf(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=ji?i.metaKey:i.ctrlKey,c=i.key.toLowerCase();if(i.key==="Escape"){if(Pa(i.target)||ui(i.target))return;o.escape();return}if(Pa(i.target)){if(a&&c==="s"){if(i.preventDefault(),!o.save||ui(i.target))return;i.target.blur(),r(!0)}return}if(ui(i.target)){a&&c==="s"&&i.preventDefault();return}if(a&&c==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!ji&&a&&c==="y"){i.preventDefault(),o.redo();return}if(a&&c==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const vr=(e,t,n=ke.DEFAULT_UI)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),_s=(e=ke.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),ks={height:20,alignSelf:"center",mx:.5,my:0},Ss=(e,t=ke.DEFAULT_UI)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Pi={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function sf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:c,saveButton:f,actions:d,onAddTile:l,onExit:u,saveStatus:h}){const{theme:p}=ke.usePublisherTheme(),y=S.edgeColor(p.cardBorder),w=S.hoverEdgeColor(p.cardBorder,p.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[l&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),onClick:l,"aria-label":"Add tile",sx:vr(y,w,p.ui),children:"Tile"}),l&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:_s(p.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:_s(p.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(d||o||u)&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),d,o&&h&&m.jsx(Nl,{...h}),o?m.jsx($.Tooltip,{title:s?`Save (${Xt}S) · ${c??Pi[a]}`:c??Pi[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:f,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{...vr(y,w,p.ui),minWidth:88},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&m.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),u&&m.jsx(S.SecondaryButton,{label:"Close",icon:m.jsx(S.CheckIcon,{}),onClick:u})]})}const of={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Gl(e,t,n){const s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:of[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ra(e){return e.description??S.readableName(e.name)}const af={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},Yr=(e,t)=>`${e}\0${t}`;function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o,renderPreview:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,d=S.edgeColor(c.cardBorder),l=k.useMemo(()=>n?.sources??[],[n]),[u,h]=k.useState(""),[p,y]=k.useState(),[w,_]=k.useState(""),[g,v]=k.useState("default"),x=k.useRef(null),b=k.useMemo(()=>{const I=new Set(t.sources.map(z=>z.base));return[...l].sort((z,V)=>Number(I.has(V.name))-Number(I.has(z.name)))},[l,t]),T=b.filter(I=>I.views.length>0),C=b.filter(I=>I.views.length===0),M=k.useMemo(()=>new Map(T.flatMap(I=>I.views.map(z=>[Yr(I.name,z.name),{source:I,view:z,key:Yr(I.name,z.name)}]))),[T]),E=k.useMemo(()=>T.map(I=>({key:I.name,label:I.name,...I.description?{detail:I.description}:{},entries:I.views.map(z=>({key:Yr(I.name,z.name),name:z.name,title:Ra(z),...z.chart?{chart:z.chart}:{}}))})),[T]),O=p===void 0?void 0:M.get(p);k.useEffect(()=>{if(!e)return;h(""),_(""),v("default");const I=T[0]?.views[0];y(I&&T[0]?Yr(T[0].name,I.name):void 0)},[e]);const P=O?[O.source.name,O.view.name].filter(I=>!he.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,A=O!==void 0&&P===void 0,L=O?Ra(O.view):"",W=g!=="default"&&O?{chart:g,chartCarried:O.view.chart?[O.view.chart]:[]}:{},U=(I=O)=>{if(!I||![I.source.name,I.view.name].every(he.isBareName))return;const z=I.key===O?.key;i({base:I.source.name,modelPath:I.source.modelPath,...I.source.exporters?{exporters:I.source.exporters}:{},view:I.view.name,...z&&w.trim()?{label:w.trim()}:{},...z?W:{},colspan:Math.ceil(r/2)})},N=O?Gl(O.view,g).filter(I=>I.value!=="custom"&&I.disabled!==!0):[];return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:x,title:"Add a tile",description:"Pick a view from this package. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!A,onClick:()=>U(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${d}`,borderBottom:`1px solid ${d}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${d}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(S.ViewPicker,{groups:E,query:u,onQuery:h,picked:O?.key,onPick:I=>{y(I),v("default")},onTake:I=>U(M.get(I)),searchRef:x,empty:m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,p:2},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}),footer:C.length>0&&m.jsxs($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",C.map(I=>I.name).join(", "),"."]})})}),m.jsx($.Box,{sx:I=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${I.palette.text.primary} 3%, ${I.palette.background.paper})`}),children:O?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:I=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${d}`,bgcolor:I.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${I.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:O.source.name,modelPath:O.source.modelPath,view:O.view.name,label:w.trim()||L,...g!=="default"?W:{},givens:O.source.givens})}):m.jsxs($.Box,{sx:I=>({flex:1,border:`1px solid ${d}`,borderRadius:f.radius.tile,bgcolor:I.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(S.ChartGlyph,{chart:O.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[O.source.name," → ",O.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:w,onChange:I=>_(I.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:g,"aria-label":"Chart",onChange:(I,z)=>{z!==null&&v(z)},sx:{...Ss(d,f),"& .MuiToggleButton-root":{...Ss(d,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:N.map(I=>m.jsx($.ToggleButton,{value:I.value,children:I.label},I.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:O.view.chart?`The view declares ${af[O.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),P&&m.jsx($.Typography,{variant:"body2",color:"error",children:P})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const Ie=e=>e.kind==="text",oe=e=>e.kind!=="text",Qn=e=>oe(e)?e.label??e.name:e.name,We=e=>Ie(e)?`text.${e.name}`:`${e.source}.${e.name}`;function cf(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:i}){t.modelPath&&!r&&(e.imports=S.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Vl(e,t.base),a=Ri(e,o.name,t.view);e.tiles.splice(i??e.tiles.length,0,{name:a,source:o.name,declaration:{kind:"reference",from:t.view},...s?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Vl(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let i=`${t}_tiles`;for(let a=2;s.has(i);a++)i=`${t}_tiles_${a}`;const o={name:i,base:t};return e.sources.push(o),o}function Ri(e,t,n){const r=new Set(e.tiles.filter(oe).filter(i=>i.source===t).map(i=>i.name));let s=`${n}_tile`;for(let i=2;r.has(s);i++)s=`${n}_tile_${i}`;return s}function $s(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function df(e,t){const n=e.tiles[t];if(!n||!oe(n)||$s(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...i}=structuredClone(n);r={...i,name:Ri(e,n.source,n.declaration.from)}}else{const i=e.sources.find(o=>o.name===n.source)??Vl(e,n.source,{unscoped:!0});r={name:Ri(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const Xr="self";function uf({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:i,onClose:o,onApply:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,[d,l]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(v=>v.source===n.name);l((n.dimensions??[]).map(v=>{const x=g.find(b=>b.name===v.name);return{name:v.name,expression:v.expression,to:x?.to??[],given:x?.given??""}}))},[e,n,t]);const u=(g,v)=>l(x=>x.map((b,T)=>{if(T!==g)return b;const C={...b};return v(C),C})),h=[Xr,...s.filter(g=>g!==Xr)],p=g=>g===Xr?"This report":g,y=()=>{n&&(a(d.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),o())},w=S.edgeColor(c.cardBorder),_=(g,v)=>u(g,x=>{v?x.to=x.lastTo?.length?x.lastTo:[Xr]:(x.lastTo=x.to,x.to=[])});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[i&&m.jsxs($.Box,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[i," ·"," "]}),"A click on a cell sets a filter to its value, on this report or on the one it opens."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:y,disabled:d.length===0,children:"Apply"})]}),children:d.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx($.Box,{role:"list","aria-label":"Dimensions",children:d.map((g,v)=>{const x=g.to.length>0;return m.jsxs($.Box,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:v===0?"none":`1px solid ${w}`},children:[m.jsx($.Switch,{size:"small",checked:x,onChange:b=>_(v,b.target.checked),slotProps:{input:{"aria-label":`${g.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:ff(g.name)}),m.jsxs($.Box,{title:g.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[g.name," is ",g.expression]})]}),x?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(p).join(", ")},onChange:b=>u(v,T=>{const C=b.target.value,M=Array.isArray(C)?C:String(C).split(",").filter(Boolean);M.length===0&&(T.lastTo=T.to),T.to=M}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:h.map(b=>m.jsxs($.MenuItem,{value:b,children:[m.jsx($.Checkbox,{size:"small",checked:g.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:p(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:g.given,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?g.name:String(b)},onChange:b=>u(v,T=>{T.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:g.name,secondary:"Named like the dimension"})}),r.map(b=>m.jsx($.MenuItem,{value:b,children:b},b))]})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},g.name)})})})}function ff(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const hf=S.createSvgIcon(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),pf=S.createSvgIcon(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),gf=S.createSvgIcon(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),mf=S.createSvgIcon(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),vf=S.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),yf=S.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function bf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of oe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function Ts(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function xf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function yr(e,t){const n=xf(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Ai(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function wf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const _f=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function kf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=he.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Sf=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function er(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Li=e=>oe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function $f(e,t){return e.tiles.map(n=>{const r=(oe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:Ts(t.type)!==void 0?{op:Ts(t.type)}:{}}})}function Tf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Li(i))return;const o=(i.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function Ef(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function Cf(e,t){for(const r of e.tiles){if(!oe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Bi=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Of({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:i,onApply:o}){const a=k.useRef(n);e&&(a.current=n);const c=e?n:a.current,f=c!==void 0,[d,l]=k.useState({kind:"new"}),[u,h]=k.useState(""),[p,y]=k.useState("select"),[w,_]=k.useState(""),[g,v]=k.useState(""),[x,b]=k.useState([]),[T,C]=k.useState(!1),[M,E]=k.useState(!1),O=D=>t.sources.find(R=>R.name===D.source)?.base??D.source;k.useEffect(()=>{if(e)if(E(n!==void 0),n){l({kind:"existing",name:n.name}),h(n.label??"");const D=$f(t,n);b(D);const R=D.filter(F=>F.include),j=new Set(R.map(F=>F.field));v(j.size===1?R[0].field:n.field??""),C(j.size>1)}else l({kind:"new"}),h(""),y("select"),v(""),_(new Date().toISOString().slice(0,10)),b(t.tiles.map(D=>({include:Li(D),field:""}))),C(!1)},[e,n,t]);const P=k.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...s],[t,r,s]),A=k.useMemo(()=>g.trim()?kf(g.trim(),P):"",[g,P]),L=d.kind==="existing"?n??r.find(D=>D.name===d.name):A?{name:A,type:er({name:A,label:u,kind:p,field:g}).type}:void 0,W=L?.type!==void 0&&!L.type.startsWith("filter<"),U=x.find(D=>D.include)?.op??Ts(L?.type),N=(D,R)=>{E(!0),b(j=>j.map((F,J)=>J===D?{...F,...R}:F))},I=D=>{E(!0),b(R=>R.map(j=>({...j,op:D})))},z=D=>{const R=Ts(D);b(j=>j.map(({op:F,...J})=>R?{...J,op:R}:J))},V=D=>{E(!0),l({kind:"existing",name:D.name}),v(D.field??""),z(D.type)},B=D=>{E(!0),y(D),z(er({name:"X",label:u,kind:D,field:g}).type)},G=t.tiles.map(Li),Q=G.filter(Boolean).length,Z=x.filter((D,R)=>D.include&&G[R]).length,X=t.tiles.filter((D,R)=>(x[R]?.include??!1)&&G[R]&&oe(D)),H=X.length>0?X:t.tiles.filter((D,R)=>G[R]&&oe(D)),Pe=k.useMemo(()=>{const D=new Map;let R=!1;for(const j of H){const F=i?.(j);if(F){R=!0;for(const J of F)D.has(J.name)||D.set(J.name,J)}}return R?[...D.values()]:void 0},[x,t.tiles,i]),ve=(()=>{const D=g.trim();for(const R of X){const j=i?.(R);if(!j||j.some(F=>F.name===D))return O(R)}return X[0]?O(X[0]):t.sources[0]?.base})(),pe=D=>{E(!0),b(R=>R.map((j,F)=>({...j,include:D&&G[F]})))},Se=k.useMemo(()=>T?x:x.map(D=>({...D,field:g})),[T,x,g]),ee=D=>{for(const R of H){const j=i?.(R)?.find(F=>F.name===D.trim());if(j?.type)return j.type}},Re=D=>yr(L?.type,D.type),ce=(D,R)=>{if(D.trim()==="")return"Pick the field this filter compares.";const j=R?i?.(R):void 0;if(!j)return;const F=j.find(J=>J.name===D.trim());if(!F)return`Not a field of ${R?O(R):"the tiles' source"}.`;if(F.type&&!yr(L?.type,F.type))return`${D.trim()} is ${Ai(F.type)}; this filter compares ${Ai(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ie=D=>{if(E(!0),v(D),f||d.kind!=="new")return;const R=ee(D),j=er({name:"X",label:u,kind:p,field:D}).type;R&&!yr(j,R)&&B(wf(R))},$e=D=>{const R=t.tiles[D];return R&&oe(R)?R:void 0},de=Se.map((D,R)=>D.include&&G[R]?ce(D.field,$e(R)):void 0),xe=de.every(D=>D===void 0),we=M?de:de.map(()=>{}),Ge=M&&!T&&Z>0?X.map(D=>ce(g,D)).find(Boolean):void 0,me=L!==void 0&&xe&&(d.kind==="existing"||g.trim()!==""&&A!==""),Ae=()=>{if(!(!L||!me))if(d.kind==="new")o(L.name,Se,er({name:L.name,label:u.trim()||Bi(L.name),kind:p,field:g.trim(),...ve?{source:ve}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),R=D!==(n.local.label??"");o(L.name,Se,R?{...n.local,...D?{label:D}:{}}:void 0)}else o(L.name,Se)},Fe=f&&c.origin==="model";return{editing:f,shown:c,fromModel:Fe,source:d,setSource:l,label:u,setLabel:h,kind:p,dateDefault:w,setDateDefault:_,field:g,rows:x,setRows:b,perTile:T,setPerTile:C,newName:A,target:L,valueTyped:W,commonOp:U,setRow:N,setCommonOp:I,pickExisting:V,pickKind:B,bindable:G,bindableCount:Q,included:Z,commonFields:Pe,setAll:pe,accepts:Re,pickField:ie,rowProblems:we,commonProblem:Ge,canApply:me,apply:Ae}}function Aa({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:c,autoFocus:f,placeholder:d,inputRef:l,sx:u}){const h=k.useMemo(()=>(n??[]).filter(y=>r?.(y)??!0).map(y=>y.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(y=>[y.name,y.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(y,w)=>t(w),value:e,onChange:(y,w)=>t(typeof w=="string"?w:""),disabled:c,disableClearable:!0,renderOption:(y,w)=>k.createElement("li",{...y,key:w},m.jsx(Ba,{type:p.get(w)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:y=>m.jsx($.TextField,{...y,label:s,placeholder:d,autoFocus:f,...l?{inputRef:l}:{},error:o,helperText:a,InputLabelProps:{...y.InputLabelProps,shrink:!0},InputProps:{...y.InputProps,startAdornment:p.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ba,{type:p.get(e.trim())})}):void 0},inputProps:{...y.inputProps,"aria-label":i}}),sx:u})}const Df=e=>e&&oe(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function Mf({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:i,onClose:o,onApply:a,onRemove:c}){const{theme:f}=ke.usePublisherTheme(),d=f.ui,{editing:l,shown:u,fromModel:h,source:p,setSource:y,label:w,setLabel:_,kind:g,dateDefault:v,setDateDefault:x,field:b,rows:T,setRows:C,perTile:M,setPerTile:E,newName:O,target:P,valueTyped:A,commonOp:L,setRow:W,setCommonOp:U,pickExisting:N,pickKind:I,bindable:z,bindableCount:V,included:B,commonFields:G,setAll:Q,accepts:Z,pickField:X,rowProblems:H,commonProblem:Pe,canApply:ve,apply:pe}=Of({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:i,onApply:a}),Se=k.useRef(null),ee=S.edgeColor(f.cardBorder),Re=S.hoverEdgeColor(f.cardBorder,f.tileTitle),[ce,ie]=k.useState(!1),[$e,de]=k.useState(!1);k.useEffect(()=>{e?de(!0):ie(!1)},[e]),k.useEffect(()=>{$e&&(de(!1),ie(l&&B<V))},[$e]),k.useEffect(()=>{M&&ie(!0)},[M]);const xe=G?.find(D=>D.name===b.trim())?.type,we=D=>{if(!xe)return;const R=er({name:"X",label:w,kind:D,field:b}).type;return yr(R,xe)?void 0:`${b.trim()} is ${Ai(xe)}, which this control cannot filter.`},Ge=w.trim()||(O?Bi(O):"Filter"),me=g==="number"?"Any":g==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ae={...Ss(ee,d),alignSelf:"flex-start","& .MuiToggleButton-root":{...Ss(ee,d)["& .MuiToggleButton-root"],textTransform:"none"}},Fe=(D,R,j)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:F=>R(F.target.value),inputProps:{"aria-label":j},sx:{width:130},children:_f.filter(F=>F.op!=="~").map(F=>m.jsx($.MenuItem,{value:F.op,children:F.label},F.op))});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:Se},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:d.font.mono},children:["$",u.name]}),h?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[l&&m.jsx($.Button,{color:"error",startIcon:m.jsx(S.DeleteOutlineIcon,{}),onClick:()=>c(u.name),sx:D=>({mr:"auto",color:S.dangerTextColor(D)}),children:"Remove filter"}),m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Tooltip,{title:ve||P===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:pe,disabled:!ve,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:p.kind,onChange:(D,R)=>{R==="new"?y({kind:"new"}):R==="existing"&&r[0]&&N(r[0])},"aria-label":"Where the filter comes from",sx:Ae,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!l&&p.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:p.name,onChange:D=>{const R=r.find(j=>j.name===D.target.value);R&&N(R)},children:r.map(D=>m.jsxs($.MenuItem,{value:D.name,children:[D.label??D.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!M&&m.jsx(Aa,{value:b,onChange:X,fields:G,accepts:Z,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:Se,error:Pe!==void 0,helperText:Pe??(!l&&O?`Declared as $${O}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:O?Bi(O):"",value:w,onChange:D=>_(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),A&&!M&&Fe(L,U,"Comparison"),!l&&p.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Control"}),m.jsx($.Box,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:Sf.map(D=>{const R=D.kind===g,j=we(D.kind);return m.jsx($.Tooltip,{title:j??D.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":R,"aria-label":D.label,"aria-disabled":j!==void 0,onClick:()=>{j===void 0&&I(D.kind)},sx:F=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:d.radius.tile,border:`1px solid ${R?f.accent:ee}`,boxShadow:R?`0 0 0 1px ${f.accent}`:"none",bgcolor:R?`color-mix(in srgb, ${f.accent} 6%, ${F.palette.background.paper})`:F.palette.background.paper,color:R?f.accent:F.palette.text.secondary,opacity:j?.45:1,cursor:j?"default":"pointer",transition:`border-color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"&:hover":j||R?{}:{borderColor:Re}}),children:[m.jsx(jf,{kind:D.kind}),m.jsx($.Box,{component:"span",sx:{...d.type.caption,fontWeight:R?600:500,color:R?f.accent:"text.primary",textAlign:"center"},children:If[D.kind]})]})},D.kind)})}),g==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:v,onChange:D=>x(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${ee}`,borderRadius:d.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(yf,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs($.Typography,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:B===V&&V>0?`Applies to all ${B} tile${B===1?"":"s"}`:`Applies to ${B} of ${V} tile${V===1?"":"s"}`}),!M&&b.trim()!==""&&B>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...d.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":ce,onClick:()=>ie(D=>!D),children:ce?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:ce,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${ee}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:V>0&&B===V,indeterminate:B>0&&B<V,disabled:V===0,onChange:D=>Q(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{M||C(D=>D.map(R=>({...R,field:b}))),E(D=>!D)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((D,R)=>{if(!oe(D))return null;const j=T[R],F=D.label??D.name,J=M?H[R]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:z[R]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!z[R],checked:(j?.include??!1)&&z[R],inputProps:{"aria-label":`Filter ${F}`},onChange:q=>W(R,{include:q.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:F}),z[R]?M&&m.jsxs(m.Fragment,{children:[A&&Fe(j?.op,q=>W(R,{op:q}),`Comparison for ${F}`),m.jsx(Aa,{value:j?.field??"",onChange:q=>W(R,{field:q}),fields:i?.(D),accepts:Z,label:"Field",ariaLabel:`Field for ${F}`,disabled:!j?.include,error:J!==void 0,helperText:J,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Df(t.tiles[R]).reason})]},`${D.source}.${D.name}`)})})]})})]}),B===0&&m.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!h&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Preview"}),m.jsx($.Box,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:d.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:d.radius.control,border:`1px solid ${ee}`,bgcolor:D.palette.background.paper,...d.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:Ge}),m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:me}),m.jsx(S.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function La({children:e}){const t=ke.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const If={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function jf({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(hf,{sx:t});case"multiselect":return m.jsx(pf,{sx:t});case"text":return m.jsx(vf,{sx:t});case"number":return m.jsx(mf,{sx:t});case"date":return m.jsx(gf,{sx:t})}}function Ba({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=ke.usePublisherTheme().theme.ui;return n?m.jsx($.Box,{component:"span","aria-hidden":!0,sx:s=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:s.palette.text.secondary,bgcolor:s.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Pf=S.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Ul(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:d=>i(l=>{if(l===void 0)return l;const u=structuredClone(l);return d(u),u}),apply:d=>{if(s===void 0)return;const l=structuredClone(s);d(l),i(l),JSON.stringify(l)!==JSON.stringify(e)&&n(l)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const Rf=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,Af="Declared on its source, so its chart is set in the model.";function Lf({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:i,duplicateBlocked:o,view:a}){const{theme:c}=ke.usePublisherTheme(),f=c.ui,{draft:d,apply:l,close:u}=Ul(t,e!==null,r,n),[h,p]=k.useState(void 0),y=d!==void 0&&oe(d)?d:void 0,w=y!==void 0&&y.declaration.kind!=="inherited",_=P=>l(A=>{oe(A)&&P(A)}),g=k.useRef(void 0),v=e!==null;k.useEffect(()=>{v?g.current=t&&oe(t)?t.chart:void 0:p(void 0)},[v]);const x=y?.chart??"default",b=Gl(a,x),T=y?w?y.chart==="custom"?Rf(y.chartLines):void 0:Af:void 0,C=P=>_(A=>{const L=g.current;P===(L??"default")?(L===void 0?delete A.chart:A.chart=L,delete A.chartCarried):(A.chart=P,a?A.chartCarried=a.chart?[a.chart]:[]:delete A.chartCarried)}),M=w?s?void 0:"Its source declares no dimension a click could filter by.":void 0,E=P=>A=>p({kind:P,anchor:A.currentTarget}),O=(P,A,L)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:P,...L?{secondary:L}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),A&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:A})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:S.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":y?`${y.source} ${y.name}`:"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:f.radius.menu,border:`1px solid ${S.edgeColor(c.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[y&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":h?.kind==="chart",disabled:T!==void 0,onClick:E("chart"),onKeyDown:P=>{P.key==="ArrowRight"&&T===void 0&&p({kind:"chart",anchor:P.currentTarget})},children:[O("Chart",T?void 0:b.find(P=>P.value===x)?.label,T),m.jsx(Pf,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),w&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:M!==void 0,onClick:()=>{u(),s?.()},children:O("Clickable cells…",void 0,M)}),y&&i&&m.jsx($.MenuItem,{disabled:o!==void 0,onClick:()=>{u(),i()},children:O("Duplicate",void 0,o)}),y?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:c.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",y.declaration.why,", so a filter has no single place to go."]}),y&&m.jsx($.Divider,{}),y&&m.jsxs($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[y.source," → ",y.name]})]}),m.jsx($.Menu,{className:S.reportClasses.menu,open:h?.kind==="chart",anchorEl:h?.anchor??null,onClose:()=>p(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:P=>{P.key==="ArrowLeft"&&(P.preventDefault(),p(void 0))}},children:b.filter(P=>P.value!=="custom").map(P=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":P.value===x,disabled:P.disabled===!0,onClick:()=>{C(P.value),p(void 0)},children:[m.jsx($.ListItemText,{primary:P.label,...P.reason?{secondary:P.reason}:{}}),P.value===x&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(S.CheckIcon,{fontSize:"small",sx:{color:c.accent}})})]},P.value))})]})}const _n=e=>e.label??S.tileTitle(`${e.source} -> ${e.name}`);function Bf({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,exitDialog:c,renderViewPreview:f,takenGivenNames:d}){const{filterDialog:l,setFilterDialog:u}=s,{menu:h,setMenu:p}=i,[y,w]=k.useState(),_=h===void 0?void 0:e.document.tiles[h.index],g=_&&oe(_)?_:void 0,v=(()=>{if(!g||!t)return;const x=e.document.sources.find(T=>T.name===g.source)?.base??g.source,b=g.declaration.kind==="reference"?g.declaration.from:g.name;return t.sources.find(T=>T.name===x)?.views.find(T=>T.name===b)})();return m.jsxs(m.Fragment,{children:[m.jsx(Mf,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:s.available,...d?{takenNames:d}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Lf,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>p(void 0),onCommit:x=>{const b=h?.index;b!==void 0&&e.update(T=>{T.tiles[b]=x})},view:v,onDuplicate:()=>{h&&i.duplicate(h.index)},...g&&$s(g)!==void 0?{duplicateBlocked:$s(g)}:{},...(e.document.sources.find(x=>x.name===g?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(g?_n(g):void 0),a(g?.source)}}:{}}),m.jsx(uf,{open:o!==void 0,document:e.document,source:e.document.sources.find(x=>x.name===o),givenNames:s.controlList.map(x=>x.name),dashboards:r??[],...y?{tileLabel:y}:{},onClose:()=>a(void 0),onApply:x=>e.update(b=>{const C=[...(b.drills??[]).filter(M=>M.source!==o),...x];C.length===0?delete b.drills:b.drills=C})}),m.jsx(S.UnsavedChangesDialog,{...c}),m.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText,...f?{renderPreview:f}:{}})]})}var Ff=Symbol.for("preact-signals");function Ys(){if(_t>1)_t--;else{var e,t=!1;for((function(){var s=Cs;for(Cs=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();xr!==void 0;){var n=xr;for(xr=void 0,Es++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&ql(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Es=0,_t--,t)throw e}}function Ce(e){if(_t>0)return e();Fi=++zf,_t++;try{return e()}finally{Ys()}}var br,ye=void 0;function te(e){var t=ye,n=br;ye=void 0,br=void 0;try{return e()}finally{ye=t,br=n}}var xr=void 0,_t=0,Es=0,zf=0,Fi=0,Cs=void 0,Os=0;function Hl(e){if(ye!==void 0){var t=e.n;if(t===void 0||t.t!==ye)return t={i:0,S:e,p:ye.s,n:void 0,t:ye,e:void 0,x:void 0,r:t},ye.s!==void 0&&(ye.s.n=t),ye.s=t,e.n=t,32&ye.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ye.s,t.n=void 0,ye.s.n=t,ye.s=t),t}}function Qe(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Qe.prototype.brand=Ff;Qe.prototype.h=function(){return!0};Qe.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:te(function(){var r;(r=t.W)==null||r.call(t)}))};Qe.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&te(function(){var s;(s=t.Z)==null||s.call(t)}))}};Qe.prototype.subscribe=function(e){var t=this;return ct(function(){var n=t.value;te(function(){return e(n)})},{name:"sub"})};Qe.prototype.valueOf=function(){return this.value};Qe.prototype.toString=function(){return this.value+""};Qe.prototype.toJSON=function(){return this.value};Qe.prototype.peek=function(){var e=this;return te(function(){return e.value})};Object.defineProperty(Qe.prototype,"value",{get:function(){var e=Hl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Es>100)throw new Error("Cycle detected");(function(n){_t!==0&&Es===0&&n.l!==Fi&&(n.l=Fi,Cs={S:n,v:n.v,i:n.i,o:Cs})})(this),this.v=e,this.i++,Os++,_t++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Ys()}}}});function In(e,t){return new Qe(e,t)}function ql(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Kl(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Yl(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function Jt(e,t){Qe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Os-1,this.f=4}Jt.prototype=new Qe;Jt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Os))return!0;if(this.g=Os,this.f|=1,this.i>0&&!ql(this))return this.f&=-2,!0;var e=ye;try{Kl(this),ye=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ye=e,Yl(this),this.f&=-2,!0};Jt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Qe.prototype.S.call(this,e)};Jt.prototype.U=function(e){if(this.t!==void 0&&(Qe.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Jt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Jt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Hl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Fa(e,t){return new Jt(e,t)}function Xl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){_t++;var n=ye;ye=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,To(e),r}finally{ye=n,Ys()}}}function To(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Xl(e)}function Wf(e){if(ye!==this)throw new Error("Out-of-order effect");Yl(this),ye=e,this.f&=-2,8&this.f&&To(this),Ys()}function jn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,br&&br.push(this)}jn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};jn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Xl(this),Kl(this),_t++;var e=ye;return ye=this,Wf.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.u=xr,xr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||To(this)};jn.prototype.dispose=function(){this.d()};function ct(e,t){var n=new jn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Nf=Object.create,Eo=Object.defineProperty,Gf=Object.defineProperties,Vf=Object.getOwnPropertyDescriptor,Uf=Object.getOwnPropertyDescriptors,za=Object.getOwnPropertySymbols,Hf=Object.prototype.hasOwnProperty,qf=Object.prototype.propertyIsEnumerable,Kf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Pn=e=>{throw TypeError(e)},zi=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yf=(e,t)=>{for(var n in t||(t={}))Hf.call(t,n)&&zi(e,n,t[n]);if(za)for(var n of za(t))qf.call(t,n)&&zi(e,n,t[n]);return e},Xf=(e,t)=>Gf(e,Uf(t)),Wa=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),Qf=e=>{var t;return[,,,Nf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Pn("Function expected"):e,Zf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?Pn("Already initialized"):s.push(tr(i||null))}),Zl=(e,t)=>zi(t,Kf("metadata"),e[3]),Ft=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},Rn=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=Ql[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&Vf(l<4?s:{get[n](){return st(this,i)},set[n](x){return Dt(this,i,x)}},n));l?h&&l<4&&Wa(i,(l>2?"set ":l>1?"get ":"")+n):Wa(s,n);for(var v=r.length-1;v>=0;v--)f=Zf(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>Jf(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?st:eh)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>Dt(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?tr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?Pn("Object expected"):(tr(o=a.get)&&(g.get=o),tr(o=a.set)&&(g.set=o),tr(o=a.init)&&w.unshift(o));return l||Zl(e,s),g&&Eo(s,n,g),h?l^4?i:g:s},Co=(e,t,n)=>t.has(e)||Pn("Cannot "+n),Jf=(e,t)=>Object(t)!==t?Pn('Cannot use the "in" operator on this value'):e.has(t),st=(e,t,n)=>(Co(e,t,"read from private field"),n?n.call(e):t.get(e)),nr=(e,t,n)=>t.has(e)?Pn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Dt=(e,t,n,r)=>(Co(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),eh=(e,t,n)=>(Co(e,t,"access private method"),n);function Wi(e,t){if(t){let n;return Fa(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Fa(e)}function ut(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!ut(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!ut(e[i],t[i]))}return!1}function ne({get:e},t){return{init(n){return In(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function De(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Wi(e.bind(this)),n.set(this,r)),r.value}}function fi(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Xf(Yf({},s),{enumerable:e}))})}}function Lr(...e){const t=e.map(n=>ct(n));return()=>t.forEach(n=>n())}var Jl,ec,tc,nc,rc,sc,Ke,Oo,hi,Ni,Gi,He,Do,pi,ic,Vi,Mo,gi,Ui,Hi;sc=[ne],rc=[ne],nc=[ne],tc=[fi()],ec=[fi()],Jl=[fi()];var en=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ft(Ke,5,this),nr(this,He),nr(this,Oo,Ft(Ke,8,this)),Ft(Ke,11,this),nr(this,Do,Ft(Ke,12,this)),Ft(Ke,15,this),nr(this,Mo,Ft(Ke,16,this)),Ft(Ke,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return st(this,He,Ui)}get initial(){return st(this,He,Ni)}get previous(){return st(this,He,ic)}set current(e){const t=te(()=>st(this,He,Ui));e&&t&&this.equals(t,e)||Ce(()=>{st(this,He,Ni)||Dt(this,He,e,Gi),Dt(this,He,t,Vi),Dt(this,He,e,Hi)})}reset(e=this.defaultValue){Ce(()=>{Dt(this,He,void 0,Vi),Dt(this,He,e,Gi),Dt(this,He,e,Hi)})}};Ke=Qf();Oo=new WeakMap;He=new WeakSet;Do=new WeakMap;Mo=new WeakMap;hi=Rn(Ke,20,"#initial",sc,He,Oo),Ni=hi.get,Gi=hi.set;pi=Rn(Ke,20,"#previous",rc,He,Do),ic=pi.get,Vi=pi.set;gi=Rn(Ke,20,"#current",nc,He,Mo),Ui=gi.get,Hi=gi.set;Rn(Ke,2,"current",tc,en);Rn(Ke,2,"initial",ec,en);Rn(Ke,2,"previous",Jl,en);Zl(Ke,en);function mi(e){return te(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var zt,th=class{constructor(){nr(this,zt,new WeakMap)}get(e,t){var n;return e?(n=st(this,zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return st(this,zt).has(e)||st(this,zt).set(e,new Map),(r=st(this,zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=st(this,zt).get(e))==null?void 0:t.clear():void 0}};zt=new WeakMap;var nh=Object.create,oc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xs=e=>{throw TypeError(e)},Ga=Math.pow,qi=(e,t,n)=>t in e?oc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&qi(e,n,t[n]);if(Na)for(var n of Na(t))ih.call(t,n)&&qi(e,n,t[n]);return e},ah=e=>{var t;return[,,,nh((t=e?.[ac("metadata")])!=null?t:null)]},lc=["class","method","getter","setter","accessor","field","value","get","set"],cc=e=>e!==void 0&&typeof e!="function"?Xs("Function expected"):e,lh=(e,t,n,r,s)=>({kind:lc[e],name:t,metadata:r,addInitializer:i=>n._?Xs("Already initialized"):s.push(cc(i||null))}),ch=(e,t)=>qi(t,ac("metadata"),e[3]),dh=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=lc[d+5],y=e[h]||(e[h]=[]),w=(s=s.prototype,rh(s,n)),_=r.length-1;_>=0;_--)c=lh(d,n,a={},e[3],y),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(w[p],c),a._=1,cc(o)&&(w[p]=o);return w&&oc(s,n,w),s},uc=(e,t,n)=>t.has(e)||Xs("Cannot "+n),uh=(e,t,n)=>(uc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Xs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(uc(e,t,"write to private field"),t.set(e,n),n),it=class Ki{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ki(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Ki(t,n)}},yt=class Wt{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:i,height:o,scale:a}=this,c=new Wt(s+t,r+n,i,o);return c.scale=oh({},a),c}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new it((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Wt))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Wt?ph(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new Wt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],c=o==="x"?i.left:i.top,f=o==="x"?i.width:i.height;return a=="start"?c:a=="end"?c+f:c+f/2};return it.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Wt.from(t).intersectionRatio(Wt.from(n))}};function ph(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var fc,hc,Yi,ls,Br,Qs=class extends(Yi=en,hc=[De],fc=[De],Yi){constructor(t){const n=it.from(t);super(n,(r,s)=>it.equals(r,s)),dh(Br,5,this),fh(this,ls,0),this.velocity={x:0,y:0}}get delta(){return it.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=it.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-uh(this,ls),a=c=>Math.round(c/o*100);Ce(()=>{hh(this,ls,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(it.from(t)),this.velocity={x:0,y:0}}};Br=ah(Yi);ls=new WeakMap;dc(Br,2,"delta",hc,Qs);dc(Br,2,"direction",fc,Qs);ch(Br,Qs);function Xi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Ga(r,2)+Ga(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var pc=(e=>(e.Horizontal="x",e.Vertical="y",e))(pc||{}),gc=Object.values(pc),gh=Object.create,Io=Object.defineProperty,mh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,Ds=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,yc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),An=e=>{throw TypeError(e)},Qi=(e,t,n)=>t in e?Io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jo=(e,t)=>{for(var n in t||(t={}))mc.call(t,n)&&Qi(e,n,t[n]);if(Ds)for(var n of Ds(t))vc.call(t,n)&&Qi(e,n,t[n]);return e},Po=(e,t)=>mh(e,yh(t)),Va=(e,t)=>Io(e,"name",{value:t,configurable:!0}),bc=(e,t)=>{var n={};for(var r in e)mc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ds)for(var r of Ds(e))t.indexOf(r)<0&&vc.call(e,r)&&(n[r]=e[r]);return n},Ln=e=>{var t;return[,,,gh((t=e?.[yc("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?An("Function expected"):e,bh=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:i=>n._?An("Already initialized"):s.push(rr(i||null))}),tn=(e,t)=>Qi(t,yc("metadata"),e[3]),Y=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},re=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=xc[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&vh(l<4?s:{get[n](){return Oe(this,i)},set[n](x){return tt(this,i,x)}},n));l?h&&l<4&&Va(i,(l>2?"set ":l>1?"get ":"")+n):Va(s,n);for(var v=r.length-1;v>=0;v--)f=bh(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>xh(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?Oe:wc)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>tt(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?rr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?An("Object expected"):(rr(o=a.get)&&(g.get=o),rr(o=a.set)&&(g.set=o),rr(o=a.init)&&w.unshift(o));return l||tn(e,s),g&&Io(s,n,g),h?l^4?i:g:s},Ro=(e,t,n)=>t.has(e)||An("Cannot "+n),xh=(e,t)=>Object(t)!==t?An('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Ro(e,t,"read from private field"),n?n.call(e):t.get(e)),le=(e,t,n)=>t.has(e)?An("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),tt=(e,t,n,r)=>(Ro(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wc=(e,t,n)=>(Ro(e,t,"access private method"),n);function _c(e,t){return{plugin:e,options:t}}function Fr(e){return t=>_c(e,t)}function Tr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var kc,Er,Ao,cs;kc=[ne];var qe=class{constructor(e,t){this.manager=e,this.options=t,le(this,Ao,Y(Er,8,this,!1)),Y(Er,11,this),le(this,cs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return te(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=ct(e.bind(this));return Oe(this,cs).add(t),t}destroy(){Oe(this,cs).forEach(e=>e())}static configure(e){return _c(this,e)}};Er=Ln(null);Ao=new WeakMap;cs=new WeakMap;re(Er,4,"disabled",kc,qe,Ao);tn(Er,qe);var zr=class extends qe{},ds,vi=class{constructor(e){this.manager=e,this.instances=new Map,le(this,ds,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Tr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,ds))if(!n.includes(r)){if(r.prototype instanceof zr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);tt(this,ds,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};ds=new WeakMap;function wh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Qr=[],fn,hn,_h=class extends qe{constructor(e){super(e),le(this,fn),le(this,hn),this.computeCollisions=this.computeCollisions.bind(this),tt(this,hn,In(Qr)),this.destroy=Lr(()=>{const t=this.computeCollisions(),n=te(()=>this.manager.dragOperation.position.current);if(t!==Qr){const r=Oe(this,fn);if(tt(this,fn,n),r&&n.x==r.x&&n.y==r.y)return}else tt(this,fn,void 0);Oe(this,hn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){te(()=>{e?Oe(this,hn).value=this.computeCollisions():tt(this,fn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Qr;const a=[],c=[];for(const f of e??n.droppables){if(f.disabled||s&&!f.accepts(s))continue;const d=t??f.collisionDetector;if(!d)continue;c.push(f),f.shape;const l=te(()=>d({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return c.length===0?Qr:(a.sort(wh),a)}get collisions(){return Oe(this,hn).value}};fn=new WeakMap;hn=new WeakMap;var Sc,$c,Tc,Lo,Ec,ft,Bo,bn,Fo,zo;Tc=[ne],$c=[ne],Sc=[ne];var St=class Nt{constructor(t,n){le(this,Bo,Y(ft,8,this)),Y(ft,11,this),le(this,bn),le(this,Fo,Y(ft,12,this)),Y(ft,15,this),le(this,zo,Y(ft,16,this)),Y(ft,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let c=s;tt(this,bn,In(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var f;return[()=>{const{id:d,manager:l}=this;if(d!==c)return c=d,l?.registry.register(this),()=>l?.registry.unregister(this)},...(f=r?.())!=null?f:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Oe(this,bn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,bn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return wc(i=Nt,Lo,Ec).call(i)})),Nt.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};ft=Ln(null);Lo=new WeakSet;Ec=function(){const e=St.pendingIdChanges;St.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)Oe(t,bn).value=n})};Bo=new WeakMap;bn=new WeakMap;Fo=new WeakMap;zo=new WeakMap;re(ft,4,"manager",Tc,St,Bo);re(ft,4,"data",$c,St,Fo);re(ft,4,"disabled",Sc,St,zo);le(St,Lo);tn(ft,St);St.pendingIdChanges=null;var Zs=St,Ua=class{constructor(){this.map=In(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,c]of n)if(c===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Lr(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Cc,Oc,Dc,Mc,Ic,jc,Zi,Ye,Wo,No,Go,bt=class extends(Zi=Zs,jc=[ne],Ic=[ne],Mc=[ne],Dc=[De],Oc=[De],Cc=[De],Zi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:c}=r,f=bc(r,["modifiers","type","sensors","plugins","effects"]);super(Po(jo({},f),{effects:()=>{var d;return[...(d=c?.())!=null?d:[],()=>{const{manager:l,plugins:u}=this;if(!(!l||!u))for(const h of u){const{plugin:p}=Tr(h);l.registry.plugins.register(p)}}]}}),n),Y(Ye,5,this),le(this,Wo,Y(Ye,8,this)),Y(Ye,11,this),le(this,No,Y(Ye,12,this)),Y(Ye,15,this),le(this,Go,Y(Ye,16,this,this.isDragSource?"dragging":"idle")),Y(Ye,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=f.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=Tr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};Ye=Ln(Zi);Wo=new WeakMap;No=new WeakMap;Go=new WeakMap;re(Ye,4,"type",jc,bt,Wo);re(Ye,4,"modifiers",Ic,bt,No);re(Ye,4,"status",Mc,bt,Go);re(Ye,2,"isDropping",Dc,bt);re(Ye,2,"isDragging",Oc,bt);re(Ye,2,"isDragSource",Cc,bt);tn(Ye,bt);var Pc,Rc,Ac,Lc,Bc,Fc,Ji,ze,Vo,Uo,Ho,qo,Ko,xt=class extends(Ji=Zs,Fc=[ne],Bc=[ne],Lc=[ne],Ac=[ne],Rc=[ne],Pc=[De],Ji){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,c=bc(r,["accept","collisionDetector","collisionPriority","type"]);super(c,n),Y(ze,5,this),le(this,Vo,Y(ze,8,this)),Y(ze,11,this),le(this,Uo,Y(ze,12,this)),Y(ze,15,this),le(this,Ho,Y(ze,16,this)),Y(ze,19,this),le(this,qo,Y(ze,20,this)),Y(ze,23,this),le(this,Ko,Y(ze,24,this)),Y(ze,27,this),this.accept=s,this.collisionDetector=i,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};ze=Ln(Ji);Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;qo=new WeakMap;Ko=new WeakMap;re(ze,4,"accept",Fc,xt,Vo);re(ze,4,"type",Bc,xt,Uo);re(ze,4,"collisionDetector",Lc,xt,Ho);re(ze,4,"collisionPriority",Ac,xt,qo);re(ze,4,"shape",Rc,xt,Ko);re(ze,2,"isDropTarget",Pc,xt);tn(ze,xt);var kh=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function us(e,t=!0){let n=!1;return Po(jo({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var $h=class extends zr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Lr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Zs.pendingIdChanges)return;const o=us({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;te(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Bn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Bn||{}),Fn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Fn||{}),zc,Wc,Nc,Gc,Vc,Uc,Hc,lt,Yo;Hc=[ne],Uc=[De],Vc=[De],Gc=[De],Nc=[De],Wc=[De],zc=[De];var Tt=class{constructor(){Y(lt,5,this),le(this,Yo,Y(lt,8,this,"idle")),Y(lt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};lt=Ln(null);Yo=new WeakMap;re(lt,4,"value",Hc,Tt,Yo);re(lt,2,"current",Uc,Tt);re(lt,2,"idle",Vc,Tt);re(lt,2,"initializing",Gc,Tt);re(lt,2,"initialized",Nc,Tt);re(lt,2,"dragging",Wc,Tt);re(lt,2,"dropped",zc,Tt);tn(lt,Tt);var Th=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return te(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=us({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return te(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:i}=e;Ce(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=us({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return te(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=us({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,f,d,l;if(o.defaultPrevented)return;const u=(l=e.to)!=null?l:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((d=(f=e.by)==null?void 0:f.y)!=null?d:0)};r.position.current=u})})}stop(e={}){return te(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const c={resume:()=>{},abort:()=>{}};return i=new Promise((f,d)=>{c.resume=f,c.abort=d}),c};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=te(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),f=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(c){const{source:d}=r,l=ct(()=>{d?.status==="idle"&&(l(),f())})}else this.manager.renderer.rendering.then(f)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),i?i.then(a).catch(()=>r.reset()):a()})}},Tn=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Eh=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},fs,qc=class{constructor(e){this.options=e,le(this,fs)}set controller(e){tt(this,fs,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,fs))==null||t.activate(e)}};fs=new WeakMap;var Ha=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Ch=class{constructor(e){this.draggables=new Ua,this.droppables=new Ua,this.plugins=new vi(e),this.sensors=new vi(e),this.modifiers=new vi(e)}register(e,t){if(e instanceof bt)return this.draggables.register(e.id,e);if(e instanceof xt)return this.droppables.register(e.id,e);if(e.prototype instanceof Ha)return this.modifiers.register(e,t);if(e.prototype instanceof Tn)return this.sensors.register(e,t);if(e.prototype instanceof qe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Zs)return e instanceof bt?this.draggables.unregister(e.id,e):e instanceof xt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Ha)return this.modifiers.unregister(e);if(e.prototype instanceof Tn)return this.sensors.unregister(e);if(e.prototype instanceof qe)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},Kc,Yc,Xc,Qc,Zc,Jc,ed,td,nd,sr,hs,pn,Ee,Xo,Qo,Zo,Jo,ea,ir;nd=[De],td=[ne],ed=[ne],Jc=[ne],Zc=[ne],Qc=[ne],Xc=[De],Yc=[De],Kc=[De];var gt=class{constructor(e){Y(Ee,5,this),le(this,sr),le(this,hs),le(this,pn,new en(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Tt,le(this,Xo,Y(Ee,8,this,!1)),Y(Ee,11,this),le(this,Qo,Y(Ee,12,this,null)),Y(Ee,15,this),le(this,Zo,Y(Ee,16,this,null)),Y(Ee,19,this),le(this,Jo,Y(Ee,20,this,null)),Y(Ee,23,this),le(this,ea,Y(Ee,24,this,[])),Y(Ee,27,this),this.position=new Qs({x:0,y:0}),le(this,ir,{x:0,y:0}),tt(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,pn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,pn).current=e:Oe(this,pn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,sr).registry.draggables.get(t);return n&&tt(this,hs,n),(e=n??Oe(this,hs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,sr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Po(jo({},this.snapshot()),{transform:n}));return tt(this,ir,n),n}snapshot(){return te(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,ir),shape:this.shape?mi(this.shape):null,position:mi(this.position),status:mi(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,pn).reset(),this.position.reset({x:0,y:0}),tt(this,ir,{x:0,y:0}),this.modifiers=[]})}};Ee=Ln(null);sr=new WeakMap;hs=new WeakMap;pn=new WeakMap;Xo=new WeakMap;Qo=new WeakMap;Zo=new WeakMap;Jo=new WeakMap;ea=new WeakMap;ir=new WeakMap;re(Ee,2,"shape",nd,gt);re(Ee,4,"canceled",td,gt,Xo);re(Ee,4,"activatorEvent",ed,gt,Qo);re(Ee,4,"sourceIdentifier",Jc,gt,Zo);re(Ee,4,"targetIdentifier",Zc,gt,Jo);re(Ee,4,"modifiers",Qc,gt,ea);re(Ee,2,"source",Xc,gt);re(Ee,2,"target",Yc,gt);re(Ee,2,"transform",Kc,gt);tn(Ee,gt);var Oh={get rendering(){return Promise.resolve()}};function pt(e,t){return typeof e=="function"?e(t):e??t}var Dh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(u=>u.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=pt(r.plugins,[]),i=pt(r.sensors,[]),o=pt(r.modifiers,[]),a=(n=r.renderer)!=null?n:Oh,c=new Sh(this),f=new Ch(this);this.registry=f,this.monitor=c,this.renderer=a,this.actions=new Th(this),this.dragOperation=new gt(this),this.collisionObserver=new _h(this),this.plugins=[$h,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,l=Lr(()=>{var u,h,p;const y=te(()=>this.dragOperation.modifiers),w=this.modifiers;for(const _ of y)w.includes(_)||_.destroy();this.dragOperation.modifiers=(p=(h=(u=this.dragOperation.source)==null?void 0:u.modifiers)==null?void 0:h.map(_=>{const{plugin:g,options:v}=Tr(_);return new g(this,v)}))!=null?p:w});this.destroy=()=>{l(),d()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},rd=e=>{throw TypeError(e)},ta=(e,t,n)=>t.has(e)||rd("Cannot "+n),K=(e,t,n)=>(ta(e,t,"read from private field"),t.get(e)),Ze=(e,t,n)=>t.has(e)?rd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),et=(e,t,n,r)=>(ta(e,t,"write to private field"),t.set(e,n),n),sd=(e,t,n)=>(ta(e,t,"access private method"),n);function Js(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(Js(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function ei(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function na(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Wr(e){return"nodeType"in e}function nt(e){var t,n,r;return e?na(e)?e:Wr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function ra(e){const{Document:t}=nt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Rt(e){return!e||na(e)?!1:e instanceof nt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function od(e){return e instanceof nt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function zn(e){return e?na(e)?e.document:Wr(e)?ra(e)?e:Rt(e)||od(e)?e.ownerDocument:document:document:document}function Mh(e){var t,n,r,s;const{documentElement:i}=zn(e),o=nt(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,c=(n=o?.height)!=null?n:i.clientHeight,f=(r=o?.offsetTop)!=null?r:0,d=(s=o?.offsetLeft)!=null?s:0;return{top:f,left:d,right:d+a,bottom:f+c,width:a,height:c}}function Ih(e,t){if(jh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function jh(e){return e.tagName==="DETAILS"}function Cr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let c=t;const{ownerDocument:f}=e,d=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Ih(l)){const v=l.getBoundingClientRect(),x=n*(v.bottom-v.top),b=n*(v.right-v.left),T=n*(v.bottom-v.top),C=n*(v.right-v.left);c={top:Math.max(c.top,v.top-x),right:Math.min(c.right,v.right+b),bottom:Math.min(c.bottom,v.bottom+T),left:Math.max(c.left,v.left-C),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}l=l.parentElement}const u=d.visualViewport,h=(s=u?.offsetTop)!=null?s:0,p=(i=u?.offsetLeft)!=null?i:0,y=(o=u?.width)!=null?o:d.innerWidth,w=(a=u?.height)!=null?a:d.innerHeight,_=n*w,g=n*y;return c={top:Math.max(c.top,h-_),right:Math.min(c.right,p+y+g),bottom:Math.min(c.bottom,h+w+_),left:Math.max(c.left,p-g),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function En(e){return{x:e.clientX,y:e.clientY}}var ad=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function eo(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...eo(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...eo(s.document,t))}}catch{}return n}function sa(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ld(){var e,t;const n=sa()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ia(e){return!e||!Wr(e)?!1:e instanceof nt(e).ShadowRoot}function Ms(e){if(e&&Wr(e)){let t=e.getRootNode();if(ia(t))return t;if(t instanceof Document)return t}return zn(e)}function oa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ph(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,o)=>{const a=r[o];if(qa(i)&&qa(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Ka(i)&&Ka(a)&&a.width>0&&a.height>0){const c=i.getContext("2d");c?.drawImage(a,0,0)}}),n}function qa(e){return"value"in e}function Ka(e){return e.tagName==="CANVAS"}function cd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Rh(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return cd(s,{x:t-i,y:n-o})}}return r}function Rh(e){return e?.tagName==="IFRAME"}var to=new WeakMap;function Ah(e){return e.closest(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),k=require("../useCompiledDocument-D9t5ry_t.cjs.js"),$=require("@mui/material"),S=require("react"),we=require("../ServerProvider-e2369oom.cjs.js"),ve=require("../text-entry-BJwltZiy.cjs.js"),Df=require("react-dom"),cc=require("@tanstack/react-query"),dc=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"})),uc=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"})),If=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 fc(e){const{theme:t}=we.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 ${No(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,g=a!==void 0&&o==="unsaved",v=()=>{s(null),c&&u?.()},_=y=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:o==="saved"?y.palette.text.secondary:y.palette.text.primary,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...g?{"&:hover":{bgcolor:y.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:y=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:o==="saving"||i!==void 0?y.palette.text.disabled:y.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:g?"visible":"hidden"}})]}),p=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:Rf,children:f?`${d}. ${f}.`:d});return m.jsxs(m.Fragment,{children:[p,m.jsx($.Tooltip,{title:f??h,describeChild:!0,children:g?m.jsx($.ButtonBase,{className:k.reportClasses.saveStatus,"aria-label":d,...f?{"aria-description":f}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:y=>s(y.currentTarget),sx:_,children:x}):m.jsx($.Box,{component:"span",className:k.reportClasses.saveStatus,sx:_,children:x})}),m.jsxs($.Menu,{className:k.reportClasses.menu,anchorEl:r,open:r!==null,onClose:v,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${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 ${No(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(If,{fontSize:"small"}),"Discard edits"]})]})]})}function No(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 Rf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Go=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),rn=Go?"⌘":"Ctrl+",Va=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},bo=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Pf(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=Go?o.metaKey:o.ctrlKey,l=o.key.toLowerCase();if(o.key==="Escape"){if(Va(o.target)||bo(o.target))return;i.escape();return}if(Va(o.target)){if(a&&l==="s"){if(o.preventDefault(),!i.save||bo(o.target))return;o.target.blur(),r(!0)}return}if(bo(o.target)){a&&l==="s"&&o.preventDefault();return}if(a&&l==="z"){o.preventDefault(),o.shiftKey?i.redo():i.undo();return}if(!Go&&a&&l==="y"){o.preventDefault(),i.redo();return}if(a&&l==="s"){o.preventDefault(),i.save?.();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 kr=(e,t,n=we.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}}}),Os=(e=we.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Ms={height:20,alignSelf:"center",mx:.5,my:0},Ds=(e,t=we.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"}}}),Ho={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function jf({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,onExit:f,saveStatus:h}){const{theme:g}=we.usePublisherTheme(),v=k.edgeColor(g.cardBorder),_=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:[d&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),onClick:d,"aria-label":"Add tile",sx:kr(v,_,g.ui),children:"Tile"}),d&&m.jsx($.Divider,{orientation:"vertical",sx:Ms}),m.jsx($.Tooltip,{title:`Undo (${rn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Os(g.ui),children:m.jsx(uc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${rn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Os(g.ui),children:m.jsx(dc,{fontSize:"small"})})})}),(c||i||f)&&m.jsx($.Divider,{orientation:"vertical",sx:Ms}),c,i&&h&&m.jsx(fc,{...h}),i?m.jsx($.Tooltip,{title:s?`Save (${rn}S) · ${l??Ho[a]}`:l??Ho[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||o,onClick:i,sx:{...kr(v,_,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"}),f&&m.jsx(k.SecondaryButton,{label:"Close",icon:m.jsx(k.CheckIcon,{}),onClick:f})]})}const Af=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Ka={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 hc(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 ${Ka[a].toLowerCase()} chart`;switch(k.chartShapeGap(a,s)){case"no_x_axis":return Af(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:Ka[a],...l?{disabled:!0,reason:l}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Xa(e){return e.description??k.readableName(e.name)}const Lf={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"},ns=(e,t)=>`${e}\0${t}`;function Bf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:o,onAddText:i,renderPreview:a}){const{theme:l}=we.usePublisherTheme(),u=l.ui,c=k.edgeColor(l.cardBorder),d=S.useMemo(()=>n?.sources??[],[n]),[f,h]=S.useState(""),[g,v]=S.useState(),[_,x]=S.useState(""),[p,y]=S.useState("default"),w=S.useRef(null),b=S.useMemo(()=>{const I=new Set(t.sources.map(N=>N.base));return[...d].sort((N,j)=>Number(I.has(j.name))-Number(I.has(N.name)))},[d,t]),E=b.filter(I=>I.views.length>0),T=b.filter(I=>I.views.length===0),C=S.useMemo(()=>new Map(E.flatMap(I=>I.views.map(N=>[ns(I.name,N.name),{source:I,view:N,key:ns(I.name,N.name)}]))),[E]),M=S.useMemo(()=>E.map(I=>({key:I.name,label:I.name,...I.description?{detail:I.description}:{},entries:I.views.map(N=>({key:ns(I.name,N.name),name:N.name,title:Xa(N),...N.chart?{chart:N.chart}:{}}))})),[E]),O=g===void 0?void 0:C.get(g);S.useEffect(()=>{if(!e)return;h(""),x(""),y("default");const I=E[0]?.views[0];v(I&&E[0]?ns(E[0].name,I.name):void 0)},[e]);const P=O?[O.source.name,O.view.name].filter(I=>!ve.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,L=O!==void 0&&P===void 0,A=O?Xa(O.view):"",H=p!=="default"&&O?{chart:p,chartCarried:O.view.chart?[O.view.chart]:[]}:{},z=(I=O)=>{if(!I||![I.source.name,I.view.name].every(ve.isBareName))return;const N=I.key===O?.key,j=k.writtenSpan(Math.ceil(r/2),r);o({base:I.source.name,modelPath:I.source.modelPath,...I.source.exporters?{exporters:I.source.exporters}:{},view:I.view.name,...N&&_.trim()?{label:_.trim()}:{},...N?H:{},...j!==void 0?{colspan:j}:{}})},Y=O?hc(O.view,p).filter(I=>I.value!=="custom"&&I.disabled!==!0):[];return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:w,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:!L,onClick:()=>z(),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:M,query:f,onQuery:h,picked:O?.key,onPick:I=>{v(I),y("default")},onTake:I=>z(C.get(I)),searchRef:w,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(I=>I.name).join(", "),"."]})})}),m.jsx($.Box,{sx:I=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${I.palette.text.primary} 3%, ${I.palette.background.paper})`}),children:O?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:I=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:u.radius.tile,border:`1px solid ${c}`,bgcolor:I.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${I.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:O.source.name,modelPath:O.source.modelPath,view:O.view.name,label:_.trim()||A,...p!=="default"?H:{},givens:O.source.givens})}):m.jsxs($.Box,{sx:I=>({flex:1,border:`1px solid ${c}`,borderRadius:u.radius.tile,bgcolor:I.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(k.ChartGlyph,{chart:O.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[O.source.name," → ",O.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:A,value:_,onChange:I=>x(I.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:(I,N)=>{N!==null&&y(N)},sx:{...Ds(c,u),"& .MuiToggleButton-root":{...Ds(c,u)["& .MuiToggleButton-root"],textTransform:"none"}},children:Y.map(I=>m.jsx($.ToggleButton,{value:I.value,children:I.label},I.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:O.view.chart?`The model sets ${Lf[O.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),P&&m.jsx($.Typography,{variant:"body2",color:"error",children:P})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const Re=e=>e.kind==="text",ce=e=>e.kind!=="text",fn=e=>ce(e)?e.label??e.name:e.name,lt=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,Fn=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",Se=e=>Re(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Ai=e=>Re(e)?k.MIN_TEXT_TILE_ROWS:k.MIN_TILE_ROWS,Li=e=>e.rowspan??k.PLACED_DEFAULT_ROWSPAN[Re(e)?"text":"query"];function Ir(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:Li(e)}}const pc=(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 Ff(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 to(e,t,n){const r=e.map(a=>({...a})),s=[],o=a=>{const l=Ir(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=Ir(r[a],t);if(l){for(;;){const u=s.filter(c=>pc(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 Wf(e,t,n,r){const s=e.flatMap((l,u)=>{const c=u===t?void 0:Ir(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=Ir(i,r);if(a){for(;;){const l=s.filter(u=>u.row<a.row&&pc(a,u));if(l.length===0)break;a.row=Math.max(...l.map(u=>u.row+u.rowspan))}i.row=a.row}return to(e.map((l,u)=>u===t?i:l),r,t)}const Ya=(e,t)=>(e-k.GRID_GAP_PX*(t-1))/t,gc=k.TILE_ROW_PX+k.GRID_GAP_PX;function mc(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/gc)+1),col:Math.min(Math.max(i,1),r-o+1)}}function zf(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)));return{...u,...mc(a.left,a.top,c,n,r),colspan:c,rowspan:o.rowspan??Math.max(Ai(o),Math.round((a.height+k.GRID_GAP_PX)/gc))}});return to(s,n)}function Qa(e,t,n){const r=e.flatMap((o,i)=>{const a=i===t?void 0:Ir(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 Nf(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=vc(e,t.base),a=qo(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 vc(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 qo(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 Is(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 Gf(e,t){const n=e.tiles[t];if(!n||!ce(n)||Is(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:o,...i}=structuredClone(n);r={...i,name:qo(e,n.source,n.declaration.from)}}else{const i=e.sources.find(a=>a.name===n.source)??vc(e,n.source,{unscoped:!0});r={name:qo(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)+Li(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),s&&(e.tiles=to(e.tiles,e.columns??k.DEFAULT_COLUMNS,t+1)),t+1}const rs="self";function Hf({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:o,onClose:i,onApply:a}){const{theme:l}=we.usePublisherTheme(),u=l.ui,[c,d]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(y=>y.source===n.name);d((n.dimensions??[]).map(y=>{const w=p.find(b=>b.name===y.name);return{name:y.name,expression:y.expression,to:w?.to??[],given:w?.given??""}}))},[e,n,t]);const f=(p,y)=>d(w=>w.map((b,E)=>{if(E!==p)return b;const T={...b};return y(T),T})),h=[rs,...s.filter(p=>p!==rs)],g=p=>p===rs?"This report":p,v=()=>{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())},_=k.edgeColor(l.cardBorder),x=(p,y)=>f(p,w=>{y?w.to=w.lastTo?.length?w.lastTo:[rs]:(w.lastTo=w.to,w.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:v,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,y)=>{const w=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:y===0?"none":`1px solid ${_}`},children:[m.jsx($.Switch,{size:"small",checked:w,onChange:b=>x(y,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:qf(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]})]}),w?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(g).join(", ")},onChange:b=>f(y,E=>{const T=b.target.value,C=Array.isArray(T)?T:String(T).split(",").filter(Boolean);C.length===0&&(E.lastTo=E.to),E.to=C}),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:g(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(y,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 qf(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const Uf=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"})),Vf=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"})),Kf=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"})),Xf=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"})),Yf=k.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),Qf=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 Zf(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 Rs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Jf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Sr(e,t){const n=Jf(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 Uo(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 eh(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const th=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function nh(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=ve.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 rh=[{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 ir(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 Vo=e=>ce(e)&&!Fn(e)&&e.declaration.kind!=="opaque";function sh(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}:Rs(t.type)!==void 0?{op:Rs(t.type)}:{}}})}function oh(e,t,n){n.forEach((r,s)=>{const o=e.tiles[s];if(!o||!Vo(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 ih(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 ah(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 Ko=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function lh({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(""),[g,v]=S.useState("select"),[_,x]=S.useState(""),[p,y]=S.useState(""),[w,b]=S.useState([]),[E,T]=S.useState(!1),[C,M]=S.useState(!1),O=D=>t.sources.find(B=>B.name===D.source)?.base??D.source;S.useEffect(()=>{if(e)if(M(n!==void 0),n){d({kind:"existing",name:n.name}),h(n.label??"");const D=sh(t,n);b(D);const B=D.filter(X=>X.include),U=new Set(B.map(X=>X.field));y(U.size===1?B[0].field:n.field??""),T(U.size>1)}else d({kind:"new"}),h(""),v("select"),y(""),x(new Date().toISOString().slice(0,10)),b(t.tiles.map(D=>({include:Vo(D),field:""}))),T(!1)},[e,n,t]);const P=S.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...s],[t,r,s]),L=S.useMemo(()=>p.trim()?nh(p.trim(),P):"",[p,P]),A=c.kind==="existing"?n??r.find(D=>D.name===c.name):L?{name:L,type:ir({name:L,label:f,kind:g,field:p}).type}:void 0,H=A?.type!==void 0&&!A.type.startsWith("filter<"),z=w.find(D=>D.include)?.op??Rs(A?.type),Y=(D,B)=>{M(!0),b(U=>U.map((X,ge)=>ge===D?{...X,...B}:X))},I=D=>{M(!0),b(B=>B.map(U=>({...U,op:D})))},N=D=>{const B=Rs(D);b(U=>U.map(({op:X,...ge})=>B?{...ge,op:B}:ge))},j=D=>{M(!0),d({kind:"existing",name:D.name}),y(D.field??""),N(D.type)},R=D=>{M(!0),v(D),N(ir({name:"X",label:f,kind:D,field:p}).type)},W=t.tiles.map(Vo),q=W.filter(Boolean).length,V=w.filter((D,B)=>D.include&&W[B]).length,G=t.tiles.filter((D,B)=>(w[B]?.include??!1)&&W[B]&&ce(D)),K=G.length>0?G:t.tiles.filter((D,B)=>W[B]&&ce(D)),re=S.useMemo(()=>{const D=new Map;let B=!1;for(const U of K){const X=o?.(U);if(X){B=!0;for(const ge of X)D.has(ge.name)||D.set(ge.name,ge)}}return B?[...D.values()]:void 0},[w,t.tiles,o]),se=(()=>{const D=p.trim();for(const B of G){const U=o?.(B);if(!U||U.some(X=>X.name===D))return O(B)}return G[0]?O(G[0]):t.sources[0]?.base})(),oe=D=>{M(!0),b(B=>B.map((U,X)=>({...U,include:D&&W[X]})))},ye=S.useMemo(()=>E?w:w.map(D=>({...D,field:p})),[E,w,p]),Pe=D=>{for(const B of K){const U=o?.(B)?.find(X=>X.name===D.trim());if(U?.type)return U.type}},be=D=>Sr(A?.type,D.type),Ge=(D,B)=>{if(D.trim()==="")return"Pick the field this filter compares.";const U=B?o?.(B):void 0;if(!U)return;const X=U.find(ge=>ge.name===D.trim());if(!X)return`Not a field of ${B?O(B):"the tiles' source"}.`;if(X.type&&!Sr(A?.type,X.type))return`${D.trim()} is ${Uo(X.type)}; this filter compares ${Uo(A?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=D=>{if(M(!0),y(D),u||c.kind!=="new")return;const B=Pe(D),U=ir({name:"X",label:f,kind:g,field:D}).type;B&&!Sr(U,B)&&R(eh(B))},Ke=D=>{const B=t.tiles[D];return B&&ce(B)?B:void 0},_e=ye.map((D,B)=>D.include&&W[B]?Ge(D.field,Ke(B)):void 0),fe=_e.every(D=>D===void 0),Te=C?_e:_e.map(()=>{}),je=C&&!E&&V>0?G.map(D=>Ge(p,D)).find(Boolean):void 0,ie=A!==void 0&&fe&&(c.kind==="existing"||p.trim()!==""&&L!==""),He=()=>{if(!(!A||!ie))if(c.kind==="new")i(A.name,ye,ir({name:A.name,label:f.trim()||Ko(A.name),kind:g,field:p.trim(),...se?{source:se}:{},..._?{dateDefault:_}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=f.trim(),B=D!==(n.local.label??"");i(A.name,ye,B?{...n.local,...D?{label:D}:{}}:void 0)}else i(A.name,ye)},Xe=u&&l.origin==="model";return{editing:u,shown:l,fromModel:Xe,source:c,setSource:d,label:f,setLabel:h,kind:g,dateDefault:_,setDateDefault:x,field:p,rows:w,setRows:b,perTile:E,setPerTile:T,newName:L,target:A,valueTyped:H,commonOp:z,setRow:Y,setCommonOp:I,pickExisting:j,pickKind:R,bindable:W,bindableCount:q,included:V,commonFields:re,setAll:oe,accepts:be,pickField:Z,rowProblems:Te,commonProblem:je,canApply:ie,apply:He}}function Za({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(v=>r?.(v)??!0).map(v=>v.name),[n,r]),g=S.useMemo(()=>new Map((n??[]).map(v=>[v.name,v.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(v,_)=>t(_),value:e,onChange:(v,_)=>t(typeof _=="string"?_:""),disabled:l,disableClearable:!0,renderOption:(v,_)=>S.createElement("li",{...v,key:_},m.jsx(el,{type:g.get(_)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:_})),renderInput:v=>m.jsx($.TextField,{...v,label:s,placeholder:c,autoFocus:u,...d?{inputRef:d}:{},error:i,helperText:a,InputLabelProps:{...v.InputLabelProps,shrink:!0},InputProps:{...v.InputProps,startAdornment:g.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(el,{type:g.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":o}}),sx:f})}const ch=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 dh({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:o,onClose:i,onApply:a,onRemove:l}){const{theme:u}=we.usePublisherTheme(),c=u.ui,{editing:d,shown:f,fromModel:h,source:g,setSource:v,label:_,setLabel:x,kind:p,dateDefault:y,setDateDefault:w,field:b,rows:E,setRows:T,perTile:C,setPerTile:M,newName:O,target:P,valueTyped:L,commonOp:A,setRow:H,setCommonOp:z,pickExisting:Y,pickKind:I,bindable:N,bindableCount:j,included:R,commonFields:W,setAll:q,accepts:V,pickField:G,rowProblems:K,commonProblem:re,canApply:se,apply:oe}=lh({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:o,onApply:a}),ye=S.useRef(null),Pe=k.edgeColor(u.cardBorder),be=k.hoverEdgeColor(u.cardBorder,u.tileTitle),[Ge,Z]=S.useState(!1),[Ke,_e]=S.useState(!1);S.useEffect(()=>{e?_e(!0):Z(!1)},[e]),S.useEffect(()=>{Ke&&(_e(!1),Z(d&&R<j))},[Ke]),S.useEffect(()=>{C&&Z(!0)},[C]);const fe=W?.find(D=>D.name===b.trim())?.type,Te=D=>{if(!fe)return;const B=ir({name:"X",label:_,kind:D,field:b}).type;return Sr(B,fe)?void 0:`${b.trim()} is ${Uo(fe)}, which this control cannot filter.`},je=_.trim()||(O?Ko(O):"Filter"),ie=p==="number"?"Any":p==="date"?y?new Date(`${y}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",He={...Ds(Pe,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...Ds(Pe,c)["& .MuiToggleButton-root"],textTransform:"none"}},Xe=(D,B,U)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:X=>B(X.target.value),inputProps:{"aria-label":U},sx:{width:130},children:th.filter(X=>X.op!=="~").map(X=>m.jsx($.MenuItem,{value:X.op,children:X.label},X.op))});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.filterDialog}`,open:e,onClose:i,...d?{}:{initialFocus:ye},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:D=>({mr:"auto",color:k.dangerTextColor(D)}),children:"Remove filter"}),m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Tooltip,{title:se||P===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:oe,disabled:!se,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:g.kind,onChange:(D,B)=>{B==="new"?v({kind:"new"}):B==="existing"&&r[0]&&Y(r[0])},"aria-label":"Where the filter comes from",sx:He,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&g.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:g.name,onChange:D=>{const B=r.find(U=>U.name===D.target.value);B&&Y(B)},children:r.map(D=>m.jsxs($.MenuItem,{value:D.name,children:[D.label??D.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!C&&m.jsx(Za,{value:b,onChange:G,fields:W,accepts:V,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ye,error:re!==void 0,helperText:re??(!d&&O?`Declared as $${O}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:O?Ko(O):"",value:_,onChange:D=>x(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),L&&!C&&Xe(A,z,"Comparison"),!d&&g.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(Ja,{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:rh.map(D=>{const B=D.kind===p,U=Te(D.kind);return m.jsx($.Tooltip,{title:U??D.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":B,"aria-label":D.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&I(D.kind)},sx:X=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${B?u.accent:Pe}`,boxShadow:B?`0 0 0 1px ${u.accent}`:"none",bgcolor:B?`color-mix(in srgb, ${u.accent} 6%, ${X.palette.background.paper})`:X.palette.background.paper,color:B?u.accent:X.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"&:hover":U||B?{}:{borderColor:be}}),children:[m.jsx(fh,{kind:D.kind}),m.jsx($.Box,{component:"span",sx:{...c.type.caption,fontWeight:B?600:500,color:B?u.accent:"text.primary",textAlign:"center"},children:uh[D.kind]})]})},D.kind)})}),p==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:y,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${Pe}`,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(Qf,{"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:R===j&&j>0?`Applies to all ${R} tile${R===1?"":"s"}`:`Applies to ${R} of ${j} tile${j===1?"":"s"}`}),!C&&b.trim()!==""&&R>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()})]})]}),!C&&m.jsx($.Button,{size:"small","aria-expanded":Ge,onClick:()=>Z(D=>!D),children:Ge?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:Ge,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${Pe}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:j>0&&R===j,indeterminate:R>0&&R<j,disabled:j===0,onChange:D=>q(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{C||T(D=>D.map(B=>({...B,field:b}))),M(D=>!D)},children:C?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:C?1:0},children:t.tiles.map((D,B)=>{if(!ce(D))return null;const U=E[B],X=D.label??D.name,ge=C?K[B]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:C?"flex-start":"center",opacity:N[B]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!N[B],checked:(U?.include??!1)&&N[B],inputProps:{"aria-label":`Filter ${X}`},onChange:Ce=>H(B,{include:Ce.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:C?1:0},noWrap:!0,children:X}),N[B]?C&&m.jsxs(m.Fragment,{children:[L&&Xe(U?.op,Ce=>H(B,{op:Ce}),`Comparison for ${X}`),m.jsx(Za,{value:U?.field??"",onChange:Ce=>H(B,{field:Ce}),fields:o?.(D),accepts:V,label:"Field",ariaLabel:`Field for ${X}`,disabled:!U?.include,error:ge!==void 0,helperText:ge,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:u.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:ch(t.tiles[B]).reason})]},Se(D))})})]})})]}),R===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(Ja,{children:"Preview"}),m.jsx($.Box,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${Pe}`,bgcolor:D.palette.background.paper,...c.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:je}),m.jsx($.Box,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:ie}),m.jsx(k.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Ja({children:e}){const t=we.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const uh={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function fh({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(Uf,{sx:t});case"multiselect":return m.jsx(Vf,{sx:t});case"text":return m.jsx(Yf,{sx:t});case"number":return m.jsx(Xf,{sx:t});case"date":return m.jsx(Kf,{sx:t})}}function el({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=we.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 tl=k.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function yc(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 hh=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.`,ph=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),gh="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",mh="Declared on its source, so its chart is set in the model.",vh="It names a query, so its chart is set where that query is declared.";function yh({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:o,duplicateBlocked:i,view:a,viewStatus:l}){const{theme:u}=we.usePublisherTheme(),c=u.ui,{draft:d,apply:f,patch:h,close:g}=yc(t,e!==null,r,n),[v,_]=S.useState(void 0),x=d!==void 0&&ce(d)?d:void 0,p=x!==void 0&&!Fn(x),y=j=>f(R=>{ce(R)&&j(R)}),w=S.useRef(void 0),b=S.useRef(null),E=e!==null;S.useEffect(()=>{E?w.current=t&&ce(t)?t.chart:void 0:_(void 0)},[E]);const T=x?.chart??"default",C=hc(a,T,l),M=x?x.declaration.kind==="query"?vh:p?x.chart==="custom"?hh(x.chartLines):void 0:mh:void 0,O=j=>y(R=>{const W=w.current;j===(W??"default")?(W===void 0?delete R.chart:R.chart=W,delete R.chartCarried):(R.chart=j,a?R.chartCarried=a.chart?[a.chart]:[]:delete R.chartCarried)}),P=p?s?void 0:"Its source declares no dimension a click could filter by.":void 0,L=T==="default"?a?.chart:T,A=L!==void 0&&ph.has(L)?gh:void 0,H=j=>R=>_({kind:j,anchor:R.currentTarget}),z=M??(L===void 0||!bh.has(L)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),Y=Array.from(new Set(u.series.map(k.seriesColorFrom).filter(j=>j!==void 0))).slice(0,8),I=j=>y(R=>{j===void 0?delete R.color:R.color=j.toLowerCase()}),N=(j,R,W)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:j,...W?{secondary:W}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),R&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:R})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:k.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":x?lt(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":v?.kind==="chart",disabled:M!==void 0,onClick:H("chart"),onKeyDown:j=>{j.key==="ArrowRight"&&M===void 0&&_({kind:"chart",anchor:j.currentTarget})},children:[N("Chart",M?void 0:C.find(j=>j.value===T)?.label,M),m.jsx(tl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&M===void 0&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":v?.kind==="color",disabled:z!==void 0,onClick:H("color"),onKeyDown:j=>{j.key==="ArrowRight"&&z===void 0&&_({kind:"color",anchor:j.currentTarget})},children:[N("Color",z?void 0:x.color??"Theme",z),!z&&m.jsx(xo,{color:x.color??u.series[0],trailing:!0}),m.jsx(tl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),p&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:P!==void 0,onClick:()=>{g(),s?.()},children:N("Clickable cells…",void 0,P??A)}),x&&o&&m.jsx($.MenuItem,{disabled:i!==void 0,onClick:()=>{g(),o()},children:N("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:lt(x).replace("->","→")})]}),m.jsx($.Menu,{className:k.reportClasses.menu,open:v?.kind==="chart",anchorEl:v?.anchor??null,onClose:()=>_(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:j=>{j.key==="ArrowLeft"&&(j.preventDefault(),_(void 0))}},children:C.filter(j=>j.value!=="custom").map(j=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":j.value===T,disabled:j.disabled===!0,onClick:()=>{O(j.value),_(void 0)},children:[m.jsx($.ListItemText,{primary:j.label,...j.reason??j.hint?{secondary:j.reason??j.hint}:{}}),j.value===T&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:u.accent}})})]},j.value))}),m.jsxs($.Menu,{className:k.reportClasses.menu,open:v?.kind==="color",anchorEl:v?.anchor??null,onClose:()=>_(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:j=>{j.key==="ArrowLeft"&&(j.preventDefault(),_(void 0))}},children:[m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===void 0,onClick:()=>{I(void 0),_(void 0)},children:[m.jsx(xo,{color:u.series[0]}),m.jsx($.ListItemText,{primary:"Theme",secondary:"The page's own colors"}),x?.color===void 0&&m.jsx(nl,{color:u.accent})]}),Y.map(j=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===j.toLowerCase(),onClick:()=>{I(j),_(void 0)},children:[m.jsx(xo,{color:j}),m.jsx($.ListItemText,{primary:j.toLowerCase()}),x?.color===j.toLowerCase()&&m.jsx(nl,{color:u.accent})]},j)),m.jsx($.Divider,{}),m.jsxs($.MenuItem,{component:"label","aria-checked":x?.color!==void 0&&!Y.some(j=>j.toLowerCase()===x.color),role:"menuitemradio",onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),b.current?.click())},children:[m.jsx("input",{ref:b,type:"color","aria-label":"Other color",value:x?.color??xh(u.series[0]),onChange:j=>{const R=j.target.value;k.isSeriesColor(R)&&h(W=>{ce(W)&&(W.color=R.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx($.ListItemText,{primary:"Other color…"})]})]})]})}const bh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),xh=e=>(e&&k.seriesColorFrom(e))??"#000000";function xo({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 nl({color:e}){return m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:e}})})}const no=e=>e.label??k.tileTitle(lt(e));function wh({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:g}=o,[v,_]=S.useState(),x=h===void 0?void 0:e.document.tiles[h.index],p=x&&ce(x)?x:void 0,y=(()=>{if(!p||!t)return;const w=t.documentViews?.get(p.source??"")?.get(p.name);if(w&&e.document.sources.some(T=>T.name===p.source))return w;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(dh,{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(yh,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>g(void 0),onCommit:w=>{const b=h?.index;b!==void 0&&e.update(E=>{E.tiles[b]=w})},view:y,...y===void 0&&p?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{h&&o.duplicate(h.index)},...p&&Is(p)!==void 0?{duplicateBlocked:Is(p)}:{},...(e.document.sources.find(w=>w.name===p?.source)?.dimensions?.length??0)>0?{onDrills:()=>{_(p?no(p):void 0),a(p?.source)}}:{}}),m.jsx(Hf,{open:i!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===i),givenNames:s.controlList.map(w=>w.name),dashboards:r??[],...v?{tileLabel:v}:{},onClose:()=>a(void 0),onApply:w=>e.update(b=>{const T=[...(b.drills??[]).filter(C=>C.source!==i),...w];T.length===0?delete b.drills:b.drills=T})}),m.jsx(k.UnsavedChangesDialog,{...l}),m.jsx(Bf,{open:o.addingTile,document:e.document,catalog:t,columns:n,onClose:o.closeAdd,onAdd:o.addTile,onAddText:o.addText,...u?{renderPreview:u}:{}})]})}var _h=Symbol.for("preact-signals");function ro(){if(Mt>1)Mt--;else{var e,t=!1;for((function(){var s=js;for(js=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}})();Tr!==void 0;){var n=Tr;for(Tr=void 0,Ps++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&xc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Ps=0,Mt--,t)throw e}}function Ie(e){if(Mt>0)return e();Xo=++kh,Mt++;try{return e()}finally{ro()}}var $r,ke=void 0;function ae(e){var t=ke,n=$r;ke=void 0,$r=void 0;try{return e()}finally{ke=t,$r=n}}var Tr=void 0,Mt=0,Ps=0,kh=0,Xo=0,js=void 0,As=0;function bc(e){if(ke!==void 0){var t=e.n;if(t===void 0||t.t!==ke)return t={i:0,S:e,p:ke.s,n:void 0,t:ke,e:void 0,x:void 0,r:t},ke.s!==void 0&&(ke.s.n=t),ke.s=t,e.n=t,32&ke.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=ke.s,t.n=void 0,ke.s.n=t,ke.s=t),t}}function st(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}st.prototype.brand=_h;st.prototype.h=function(){return!0};st.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:ae(function(){var r;(r=t.W)==null||r.call(t)}))};st.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&ae(function(){var s;(s=t.Z)==null||s.call(t)}))}};st.prototype.subscribe=function(e){var t=this;return gt(function(){var n=t.value;ae(function(){return e(n)})},{name:"sub"})};st.prototype.valueOf=function(){return this.value};st.prototype.toString=function(){return this.value+""};st.prototype.toJSON=function(){return this.value};st.prototype.peek=function(){var e=this;return ae(function(){return e.value})};Object.defineProperty(st.prototype,"value",{get:function(){var e=bc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ps>100)throw new Error("Cycle detected");(function(n){Mt!==0&&Ps===0&&n.l!==Xo&&(n.l=Xo,js={S:n,v:n.v,i:n.i,o:js})})(this),this.v=e,this.i++,As++,Mt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{ro()}}}});function Wn(e,t){return new st(e,t)}function xc(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 wc(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 _c(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 an(e,t){st.call(this,void 0,t),this.x=e,this.s=void 0,this.g=As-1,this.f=4}an.prototype=new st;an.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===As))return!0;if(this.g=As,this.f|=1,this.i>0&&!xc(this))return this.f&=-2,!0;var e=ke;try{wc(this),ke=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 ke=e,_c(this),this.f&=-2,!0};an.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}st.prototype.S.call(this,e)};an.prototype.U=function(e){if(this.t!==void 0&&(st.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};an.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(an.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=bc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function rl(e,t){return new an(e,t)}function kc(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Mt++;var n=ke;ke=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Bi(e),r}finally{ke=n,ro()}}}function Bi(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,kc(e)}function Sh(e){if(ke!==this)throw new Error("Out-of-order effect");_c(this),ke=e,this.f&=-2,8&this.f&&Bi(this),ro()}function zn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,$r&&$r.push(this)}zn.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()}};zn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,kc(this),wc(this),Mt++;var e=ke;return ke=this,Sh.bind(this,e)};zn.prototype.N=function(){2&this.f||(this.f|=2,this.u=Tr,Tr=this)};zn.prototype.d=function(){this.f|=8,1&this.f||Bi(this)};zn.prototype.dispose=function(){this.d()};function gt(e,t){var n=new zn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var $h=Object.create,Fi=Object.defineProperty,Th=Object.defineProperties,Eh=Object.getOwnPropertyDescriptor,Ch=Object.getOwnPropertyDescriptors,sl=Object.getOwnPropertySymbols,Oh=Object.prototype.hasOwnProperty,Mh=Object.prototype.propertyIsEnumerable,Dh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Nn=e=>{throw TypeError(e)},Yo=(e,t,n)=>t in e?Fi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ih=(e,t)=>{for(var n in t||(t={}))Oh.call(t,n)&&Yo(e,n,t[n]);if(sl)for(var n of sl(t))Mh.call(t,n)&&Yo(e,n,t[n]);return e},Rh=(e,t)=>Th(e,Ch(t)),ol=(e,t)=>Fi(e,"name",{value:t,configurable:!0}),Ph=e=>{var t;return[,,,$h((t=void 0)!=null?t:null)]},Sc=["class","method","getter","setter","accessor","field","value","get","set"],ar=e=>e!==void 0&&typeof e!="function"?Nn("Function expected"):e,jh=(e,t,n,r,s)=>({kind:Sc[e],name:t,metadata:r,addInitializer:o=>n._?Nn("Already initialized"):s.push(ar(o||null))}),$c=(e,t)=>Yo(t,Dh("metadata"),e[3]),Ut=(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},Gn=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,v=Sc[d+5],_=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&Eh(d<4?s:{get[n](){return ut(this,o)},set[n](w){return Bt(this,o,w)}},n));d?h&&d<4&&ol(o,(d>2?"set ":d>1?"get ":"")+n):ol(s,n);for(var y=r.length-1;y>=0;y--)u=jh(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?w=>Ah(s,w):w=>n in w},d^3&&(c.get=h?w=>(d^1?ut:Lh)(w,s,d^4?o:p.get):w=>w[n]),d>2&&(c.set=h?(w,b)=>Bt(w,s,b,d^4?o:p.set):(w,b)=>w[n]=b)),a=(0,r[y])(d?d<4?h?o:p[v]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?ar(a)&&(d>4?_.unshift(a):d?h?o=a:p[v]=a:s=a):typeof a!="object"||a===null?Nn("Object expected"):(ar(i=a.get)&&(p.get=i),ar(i=a.set)&&(p.set=i),ar(i=a.init)&&_.unshift(i));return d||$c(e,s),p&&Fi(s,n,p),h?d^4?o:p:s},Wi=(e,t,n)=>t.has(e)||Nn("Cannot "+n),Ah=(e,t)=>Object(t)!==t?Nn('Cannot use the "in" operator on this value'):e.has(t),ut=(e,t,n)=>(Wi(e,t,"read from private field"),n?n.call(e):t.get(e)),lr=(e,t,n)=>t.has(e)?Nn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Bt=(e,t,n,r)=>(Wi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Lh=(e,t,n)=>(Wi(e,t,"access private method"),n);function Qo(e,t){if(t){let n;return rl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return rl(e)}function vt(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)=>!vt(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=>!vt(e[o],t[o]))}return!1}function le({get:e},t){return{init(n){return Wn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Le(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Qo(e.bind(this)),n.set(this,r)),r.value}}function wo(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,Rh(Ih({},s),{enumerable:e}))})}}function Hr(...e){const t=e.map(n=>gt(n));return()=>t.forEach(n=>n())}var Tc,Ec,Cc,Oc,Mc,Dc,et,zi,_o,Zo,Jo,Ze,Ni,ko,Ic,ei,Gi,So,ti,ni;Dc=[le],Mc=[le],Oc=[le],Cc=[wo()],Ec=[wo()],Tc=[wo()];var ln=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ut(et,5,this),lr(this,Ze),lr(this,zi,Ut(et,8,this)),Ut(et,11,this),lr(this,Ni,Ut(et,12,this)),Ut(et,15,this),lr(this,Gi,Ut(et,16,this)),Ut(et,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return ut(this,Ze,ti)}get initial(){return ut(this,Ze,Zo)}get previous(){return ut(this,Ze,Ic)}set current(e){const t=ae(()=>ut(this,Ze,ti));e&&t&&this.equals(t,e)||Ie(()=>{ut(this,Ze,Zo)||Bt(this,Ze,e,Jo),Bt(this,Ze,t,ei),Bt(this,Ze,e,ni)})}reset(e=this.defaultValue){Ie(()=>{Bt(this,Ze,void 0,ei),Bt(this,Ze,e,Jo),Bt(this,Ze,e,ni)})}};et=Ph();zi=new WeakMap;Ze=new WeakSet;Ni=new WeakMap;Gi=new WeakMap;_o=Gn(et,20,"#initial",Dc,Ze,zi),Zo=_o.get,Jo=_o.set;ko=Gn(et,20,"#previous",Mc,Ze,Ni),Ic=ko.get,ei=ko.set;So=Gn(et,20,"#current",Oc,Ze,Gi),ti=So.get,ni=So.set;Gn(et,2,"current",Cc,ln);Gn(et,2,"initial",Ec,ln);Gn(et,2,"previous",Tc,ln);$c(et,ln);function $o(e){return ae(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Vt,Bh=class{constructor(){lr(this,Vt,new WeakMap)}get(e,t){var n;return e?(n=ut(this,Vt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return ut(this,Vt).has(e)||ut(this,Vt).set(e,new Map),(r=ut(this,Vt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=ut(this,Vt).get(e))==null?void 0:t.clear():void 0}};Vt=new WeakMap;var Fh=Object.create,Rc=Object.defineProperty,Wh=Object.getOwnPropertyDescriptor,il=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Nh=Object.prototype.propertyIsEnumerable,Pc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),so=e=>{throw TypeError(e)},al=Math.pow,ri=(e,t,n)=>t in e?Rc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gh=(e,t)=>{for(var n in t||(t={}))zh.call(t,n)&&ri(e,n,t[n]);if(il)for(var n of il(t))Nh.call(t,n)&&ri(e,n,t[n]);return e},Hh=e=>{var t;return[,,,Fh((t=e?.[Pc("metadata")])!=null?t:null)]},jc=["class","method","getter","setter","accessor","field","value","get","set"],Ac=e=>e!==void 0&&typeof e!="function"?so("Function expected"):e,qh=(e,t,n,r,s)=>({kind:jc[e],name:t,metadata:r,addInitializer:o=>n._?so("Already initialized"):s.push(Ac(o||null))}),Uh=(e,t)=>ri(t,Pc("metadata"),e[3]),Vh=(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},Lc=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,g=jc[c+5],v=e[h]||(e[h]=[]),_=(s=s.prototype,Wh(s,n)),x=r.length-1;x>=0;x--)l=qh(c,n,a={},e[3],v),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(_[g],l),a._=1,Ac(i)&&(_[g]=i);return _&&Rc(s,n,_),s},Bc=(e,t,n)=>t.has(e)||so("Cannot "+n),Kh=(e,t,n)=>(Bc(e,t,"read from private field"),t.get(e)),Xh=(e,t,n)=>t.has(e)?so("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Yh=(e,t,n,r)=>(Bc(e,t,"write to private field"),t.set(e,n),n),ft=class si{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new si(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 si(t,n)}},St=class Kt{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 Kt(s+t,r+n,o,i);return l.scale=Gh({},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 ft((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Kt))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 Kt?Qh(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 Kt(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 ft.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Kt.from(t).intersectionRatio(Kt.from(n))}};function Qh(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 Fc,Wc,oi,gs,qr,oo=class extends(oi=ln,Wc=[Le],Fc=[Le],oi){constructor(t){const n=ft.from(t);super(n,(r,s)=>ft.equals(r,s)),Vh(qr,5,this),Xh(this,gs,0),this.velocity={x:0,y:0}}get delta(){return ft.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=ft.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),i=o-Kh(this,gs),a=l=>Math.round(l/i*100);Ie(()=>{Yh(this,gs,o),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(ft.from(t)),this.velocity={x:0,y:0}}};qr=Hh(oi);gs=new WeakMap;Lc(qr,2,"delta",Wc,oo);Lc(qr,2,"direction",Fc,oo);Uh(qr,oo);function ii({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(al(r,2)+al(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 zc=(e=>(e.Horizontal="x",e.Vertical="y",e))(zc||{}),Nc=Object.values(zc),Zh=Object.create,Hi=Object.defineProperty,Jh=Object.defineProperties,ep=Object.getOwnPropertyDescriptor,tp=Object.getOwnPropertyDescriptors,Ls=Object.getOwnPropertySymbols,Gc=Object.prototype.hasOwnProperty,Hc=Object.prototype.propertyIsEnumerable,qc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Hn=e=>{throw TypeError(e)},ai=(e,t,n)=>t in e?Hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qi=(e,t)=>{for(var n in t||(t={}))Gc.call(t,n)&&ai(e,n,t[n]);if(Ls)for(var n of Ls(t))Hc.call(t,n)&&ai(e,n,t[n]);return e},Ui=(e,t)=>Jh(e,tp(t)),ll=(e,t)=>Hi(e,"name",{value:t,configurable:!0}),Uc=(e,t)=>{var n={};for(var r in e)Gc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ls)for(var r of Ls(e))t.indexOf(r)<0&&Hc.call(e,r)&&(n[r]=e[r]);return n},qn=e=>{var t;return[,,,Zh((t=e?.[qc("metadata")])!=null?t:null)]},Vc=["class","method","getter","setter","accessor","field","value","get","set"],cr=e=>e!==void 0&&typeof e!="function"?Hn("Function expected"):e,np=(e,t,n,r,s)=>({kind:Vc[e],name:t,metadata:r,addInitializer:o=>n._?Hn("Already initialized"):s.push(cr(o||null))}),cn=(e,t)=>ai(t,qc("metadata"),e[3]),ne=(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),g=d>3?e.length+1:d?f?1:2:0,v=Vc[d+5],_=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&ep(d<4?s:{get[n](){return Ae(this,o)},set[n](w){return ct(this,o,w)}},n));d?h&&d<4&&ll(o,(d>2?"set ":d>1?"get ":"")+n):ll(s,n);for(var y=r.length-1;y>=0;y--)u=np(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?w=>rp(s,w):w=>n in w},d^3&&(c.get=h?w=>(d^1?Ae:Kc)(w,s,d^4?o:p.get):w=>w[n]),d>2&&(c.set=h?(w,b)=>ct(w,s,b,d^4?o:p.set):(w,b)=>w[n]=b)),a=(0,r[y])(d?d<4?h?o:p[v]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?cr(a)&&(d>4?_.unshift(a):d?h?o=a:p[v]=a:s=a):typeof a!="object"||a===null?Hn("Object expected"):(cr(i=a.get)&&(p.get=i),cr(i=a.set)&&(p.set=i),cr(i=a.init)&&_.unshift(i));return d||cn(e,s),p&&Hi(s,n,p),h?d^4?o:p:s},Vi=(e,t,n)=>t.has(e)||Hn("Cannot "+n),rp=(e,t)=>Object(t)!==t?Hn('Cannot use the "in" operator on this value'):e.has(t),Ae=(e,t,n)=>(Vi(e,t,"read from private field"),n?n.call(e):t.get(e)),me=(e,t,n)=>t.has(e)?Hn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ct=(e,t,n,r)=>(Vi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Kc=(e,t,n)=>(Vi(e,t,"access private method"),n);function Xc(e,t){return{plugin:e,options:t}}function Ur(e){return t=>Xc(e,t)}function Rr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Yc,Pr,Ki,ms;Yc=[le];var Je=class{constructor(e,t){this.manager=e,this.options=t,me(this,Ki,ne(Pr,8,this,!1)),ne(Pr,11,this),me(this,ms,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ae(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=gt(e.bind(this));return Ae(this,ms).add(t),t}destroy(){Ae(this,ms).forEach(e=>e())}static configure(e){return Xc(this,e)}};Pr=qn(null);Ki=new WeakMap;ms=new WeakMap;de(Pr,4,"disabled",Yc,Je,Ki);cn(Pr,Je);var Vr=class extends Je{},vs,To=class{constructor(e){this.manager=e,this.instances=new Map,me(this,vs,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Rr).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 Ae(this,vs))if(!n.includes(r)){if(r.prototype instanceof Vr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);ct(this,vs,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()}};vs=new WeakMap;function sp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ss=[],bn,xn,op=class extends Je{constructor(e){super(e),me(this,bn),me(this,xn),this.computeCollisions=this.computeCollisions.bind(this),ct(this,xn,Wn(ss)),this.destroy=Hr(()=>{const t=this.computeCollisions(),n=ae(()=>this.manager.dragOperation.position.current);if(t!==ss){const r=Ae(this,bn);if(ct(this,bn,n),r&&n.x==r.x&&n.y==r.y)return}else ct(this,bn,void 0);Ae(this,xn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ae(()=>{e?Ae(this,xn).value=this.computeCollisions():ct(this,bn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:i}=r;if(!i.initialized||!o)return ss;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?ss:(a.sort(sp),a)}get collisions(){return Ae(this,xn).value}};bn=new WeakMap;xn=new WeakMap;var Qc,Zc,Jc,Xi,ed,yt,Yi,Tn,Qi,Zi;Jc=[le],Zc=[le],Qc=[le];var It=class Xt{constructor(t,n){me(this,Yi,ne(yt,8,this)),ne(yt,11,this),me(this,Tn),me(this,Qi,ne(yt,12,this)),ne(yt,15,this),me(this,Zi,ne(yt,16,this)),ne(yt,19,this);const{effects:r,id:s,data:o={},disabled:i=!1,register:a=!0}=t;let l=s;ct(this,Tn,Wn(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=Ae(this,Tn).value;return(n=(t=Xt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Xt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Ae(this,Tn).peek();t!==s&&(Xt.pendingIdChanges||(Xt.pendingIdChanges=new Map,queueMicrotask(()=>{var o;return Kc(o=Xt,Xi,ed).call(o)})),Xt.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};yt=qn(null);Xi=new WeakSet;ed=function(){const e=It.pendingIdChanges;It.pendingIdChanges=null,e&&Ie(()=>{for(const[t,n]of e)Ae(t,Tn).value=n})};Yi=new WeakMap;Tn=new WeakMap;Qi=new WeakMap;Zi=new WeakMap;de(yt,4,"manager",Jc,It,Yi);de(yt,4,"data",Zc,It,Qi);de(yt,4,"disabled",Qc,It,Zi);me(It,Xi);cn(yt,It);It.pendingIdChanges=null;var io=It,cl=class{constructor(){this.map=Wn(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=Hr(...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}},td,nd,rd,sd,od,id,li,tt,Ji,ea,ta,$t=class extends(li=io,id=[le],od=[le],sd=[le],rd=[Le],nd=[Le],td=[Le],li){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:i,plugins:a,effects:l}=r,u=Uc(r,["modifiers","type","sensors","plugins","effects"]);super(Ui(qi({},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:g}=Rr(h);d.registry.plugins.register(g)}}]}}),n),ne(tt,5,this),me(this,Ji,ne(tt,8,this)),ne(tt,11,this),me(this,ea,ne(tt,12,this)),ne(tt,15,this),me(this,ta,ne(tt,16,this,this.isDragSource?"dragging":"idle")),ne(tt,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=Rr(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}};tt=qn(li);Ji=new WeakMap;ea=new WeakMap;ta=new WeakMap;de(tt,4,"type",id,$t,Ji);de(tt,4,"modifiers",od,$t,ea);de(tt,4,"status",sd,$t,ta);de(tt,2,"isDropping",rd,$t);de(tt,2,"isDragging",nd,$t);de(tt,2,"isDragSource",td,$t);cn(tt,$t);var ad,ld,cd,dd,ud,fd,ci,Ue,na,ra,sa,oa,ia,Tt=class extends(ci=io,fd=[le],ud=[le],dd=[le],cd=[le],ld=[le],ad=[Le],ci){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:i,type:a}=r,l=Uc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ne(Ue,5,this),me(this,na,ne(Ue,8,this)),ne(Ue,11,this),me(this,ra,ne(Ue,12,this)),ne(Ue,15,this),me(this,sa,ne(Ue,16,this)),ne(Ue,19,this),me(this,oa,ne(Ue,20,this)),ne(Ue,23,this),me(this,ia,ne(Ue,24,this)),ne(Ue,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}};Ue=qn(ci);na=new WeakMap;ra=new WeakMap;sa=new WeakMap;oa=new WeakMap;ia=new WeakMap;de(Ue,4,"accept",fd,Tt,na);de(Ue,4,"type",ud,Tt,ra);de(Ue,4,"collisionDetector",dd,Tt,sa);de(Ue,4,"collisionPriority",cd,Tt,oa);de(Ue,4,"shape",ld,Tt,ia);de(Ue,2,"isDropTarget",ad,Tt);cn(Ue,Tt);var ip=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)}},ap=class extends ip{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function ys(e,t=!0){let n=!1;return Ui(qi({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var lp=class extends Vr{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Hr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled()||io.pendingIdChanges)return;const i=ys({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()}))})})}},Un=(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))(Un||{}),Vn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Vn||{}),hd,pd,gd,md,vd,yd,bd,pt,aa;bd=[le],yd=[Le],vd=[Le],md=[Le],gd=[Le],pd=[Le],hd=[Le];var Pt=class{constructor(){ne(pt,5,this),me(this,aa,ne(pt,8,this,"idle")),ne(pt,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}};pt=qn(null);aa=new WeakMap;de(pt,4,"value",bd,Pt,aa);de(pt,2,"current",yd,Pt);de(pt,2,"idle",vd,Pt);de(pt,2,"initializing",md,Pt);de(pt,2,"initialized",gd,Pt);de(pt,2,"dragging",pd,Pt);de(pt,2,"dropped",hd,Pt);cn(pt,Pt);var cp=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=ys({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;Ie(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const i=ys({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"&&Ie(()=>{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=ys({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=gt(()=>{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()})}},Rn=class extends Je{constructor(e,t){super(e,t),this.manager=e,this.options=t}},dp=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)}},bs,xd=class{constructor(e){this.options=e,me(this,bs)}set controller(e){ct(this,bs,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ae(this,bs))==null||t.activate(e)}};bs=new WeakMap;var dl=class extends Je{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},up=class{constructor(e){this.draggables=new cl,this.droppables=new cl,this.plugins=new To(e),this.sensors=new To(e),this.modifiers=new To(e)}register(e,t){if(e instanceof $t)return this.draggables.register(e.id,e);if(e instanceof Tt)return this.droppables.register(e.id,e);if(e.prototype instanceof dl)return this.modifiers.register(e,t);if(e.prototype instanceof Rn)return this.sensors.register(e,t);if(e.prototype instanceof Je)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof io)return e instanceof $t?this.draggables.unregister(e.id,e):e instanceof Tt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof dl)return this.modifiers.unregister(e);if(e.prototype instanceof Rn)return this.sensors.unregister(e);if(e.prototype instanceof Je)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},wd,_d,kd,Sd,$d,Td,Ed,Cd,Od,dr,xs,wn,De,la,ca,da,ua,fa,ur;Od=[Le],Cd=[le],Ed=[le],Td=[le],$d=[le],Sd=[le],kd=[Le],_d=[Le],wd=[Le];var wt=class{constructor(e){ne(De,5,this),me(this,dr),me(this,xs),me(this,wn,new ln(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Pt,me(this,la,ne(De,8,this,!1)),ne(De,11,this),me(this,ca,ne(De,12,this,null)),ne(De,15,this),me(this,da,ne(De,16,this,null)),ne(De,19,this),me(this,ua,ne(De,20,this,null)),ne(De,23,this),me(this,fa,ne(De,24,this,[])),ne(De,27,this),this.position=new oo({x:0,y:0}),me(this,ur,{x:0,y:0}),ct(this,dr,e)}get shape(){const{current:e,initial:t,previous:n}=Ae(this,wn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ae(this,wn).current=e:Ae(this,wn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ae(this,dr).registry.draggables.get(t);return n&&ct(this,xs,n),(e=n??Ae(this,xs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ae(this,dr).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(Ui(qi({},this.snapshot()),{transform:n}));return ct(this,ur,n),n}snapshot(){return ae(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ae(this,ur),shape:this.shape?$o(this.shape):null,position:$o(this.position),status:$o(this.status),canceled:this.canceled}))}reset(){Ie(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ae(this,wn).reset(),this.position.reset({x:0,y:0}),ct(this,ur,{x:0,y:0}),this.modifiers=[]})}};De=qn(null);dr=new WeakMap;xs=new WeakMap;wn=new WeakMap;la=new WeakMap;ca=new WeakMap;da=new WeakMap;ua=new WeakMap;fa=new WeakMap;ur=new WeakMap;de(De,2,"shape",Od,wt);de(De,4,"canceled",Cd,wt,la);de(De,4,"activatorEvent",Ed,wt,ca);de(De,4,"sourceIdentifier",Td,wt,da);de(De,4,"targetIdentifier",$d,wt,ua);de(De,4,"modifiers",Sd,wt,fa);de(De,2,"source",kd,wt);de(De,2,"target",_d,wt);de(De,2,"transform",wd,wt);cn(De,wt);var fp={get rendering(){return Promise.resolve()}};function xt(e,t){return typeof e=="function"?e(t):e??t}var hp=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=xt(r.plugins,[]),o=xt(r.sensors,[]),i=xt(r.modifiers,[]),a=(n=r.renderer)!=null?n:fp,l=new ap(this),u=new up(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new cp(this),this.dragOperation=new wt(this),this.collisionObserver=new op(this),this.plugins=[lp,...s],this.modifiers=i,this.sensors=o;const{destroy:c}=this,d=Hr(()=>{var f,h,g;const v=ae(()=>this.dragOperation.modifiers),_=this.modifiers;for(const x of v)_.includes(x)||x.destroy();this.dragOperation.modifiers=(g=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:p,options:y}=Rr(x);return new p(this,y)}))!=null?g:_});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}},Md=e=>{throw TypeError(e)},ha=(e,t,n)=>t.has(e)||Md("Cannot "+n),te=(e,t,n)=>(ha(e,t,"read from private field"),t.get(e)),ot=(e,t,n)=>t.has(e)?Md("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),at=(e,t,n,r)=>(ha(e,t,"write to private field"),t.set(e,n),n),Dd=(e,t,n)=>(ha(e,t,"access private method"),n);function ao(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:o}=s,a=(ao(o)?o.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function lo(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 pa(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Kr(e){return"nodeType"in e}function dt(e){var t,n,r;return e?pa(e)?e:Kr(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 ga(e){const{Document:t}=dt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Gt(e){return!e||pa(e)?!1:e instanceof dt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Rd(e){return e instanceof dt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Kn(e){return e?pa(e)?e.document:Kr(e)?ga(e)?e:Gt(e)||Rd(e)?e.ownerDocument:document:document:document}function pp(e){var t,n,r,s;const{documentElement:o}=Kn(e),i=dt(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 gp(e,t){if(mp(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function mp(e){return e.tagName==="DETAILS"}function jr(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(!gp(d)){const y=d.getBoundingClientRect(),w=n*(y.bottom-y.top),b=n*(y.right-y.left),E=n*(y.bottom-y.top),T=n*(y.right-y.left);l={top:Math.max(l.top,y.top-w),right:Math.min(l.right,y.right+b),bottom:Math.min(l.bottom,y.bottom+E),left:Math.max(l.left,y.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,g=(o=f?.offsetLeft)!=null?o:0,v=(i=f?.width)!=null?i:c.innerWidth,_=(a=f?.height)!=null?a:c.innerHeight,x=n*_,p=n*v;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,g+v+p),bottom:Math.min(l.bottom,h+_+x),left:Math.max(l.left,g-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 Pn(e){return{x:e.clientX,y:e.clientY}}var Pd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function di(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(...di(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(...di(s.document,t))}}catch{}return n}function ma(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function jd(){var e,t;const n=ma()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function va(e){return!e||!Kr(e)?!1:e instanceof dt(e).ShadowRoot}function Bs(e){if(e&&Kr(e)){let t=e.getRootNode();if(va(t))return t;if(t instanceof Document)return t}return Kn(e)}function ya(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function vp(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(ul(o)&&ul(a)&&(o.type!=="file"&&(o.value=a.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),fl(o)&&fl(a)&&a.width>0&&a.height>0){const l=o.getContext("2d");l?.drawImage(a,0,0)}}),n}function ul(e){return"value"in e}function fl(e){return e.tagName==="CANVAS"}function Ad(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(yp(r)){const{contentDocument:s}=r;if(s){const{left:o,top:i}=r.getBoundingClientRect();return Ad(s,{x:t-o,y:n-i})}}return r}function yp(e){return e?.tagName==="IFRAME"}var ui=new WeakMap;function bp(e){return e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),
5
5
  button:not([disabled]),
6
6
  a[href],
7
7
  [contenteditable]:not([contenteditable="false"])
8
- `)}var dd=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:c,listener:f,options:d}=a,l=[o,a];o.addEventListener(c,f,d),this.entries.add(l),s.push(l)}const i=this.entries;return function(){for(const a of s){const[c,{type:f,listener:d,options:l}]=a;c.removeEventListener(f,d,l),i.delete(a)}}}};function Cn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Lh(e){const t=new Set;let n=Cn(e);for(;n;)t.add(n),n=Cn(n);return t}function Bh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ud(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Bh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Fh(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function zh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Cr(e,t);return n>0&&r>0}var Wh=ad?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ps,Nh=class extends Wh{constructor(e){super(t=>{if(!K(this,ps)){et(this,ps,!0);return}e(t,this)}),Ze(this,ps,!1)}};ps=new WeakMap;var Ya=Array.from({length:100},(e,t)=>t/100),fd=75,Gt,Is,Ct,Vt,or,Ue,wr,ar,js,hd,pd,gd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ze(this,js),this.disconnect=()=>{var i,o,a;et(this,wr,!0),(i=K(this,Ct))==null||i.disconnect(),(o=K(this,Vt))==null||o.disconnect(),K(this,or).disconnect(),(a=K(this,Ue))==null||a.remove()},Ze(this,Gt,!0),Ze(this,Is),Ze(this,Ct),Ze(this,Vt),Ze(this,or),Ze(this,Ue),Ze(this,wr,!1),Ze(this,ar,ud(()=>{var i,o,a;const{element:c}=this;if((i=K(this,Vt))==null||i.disconnect(),K(this,wr)||!K(this,Gt)||!c.isConnected)return;const f=(o=c.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=c.getBoundingClientRect(),h=Cr(c,u),{top:p,left:y,bottom:w,right:_}=h,g=-Math.floor(p),v=-Math.floor(y),x=-Math.floor(l-_),b=-Math.floor(d-w),T=`${g}px ${x}px ${b}px ${v}px`;this.boundingClientRect=u,et(this,Vt,new IntersectionObserver(C=>{const[M]=C,{intersectionRect:E}=M;(M.intersectionRatio!==1?M.intersectionRatio:yt.intersectionRatio(E,Cr(c)))!==1&&K(this,ar).call(this)},{threshold:Ya,rootMargin:T,root:f})),K(this,Vt).observe(c),sd(this,js,hd).call(this)},fd)),this.boundingClientRect=e.getBoundingClientRect(),et(this,Gt,zh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(et(this,Ue,document.createElement("div")),K(this,Ue).style.background="rgba(0,0,0,0.15)",K(this,Ue).style.position="fixed",K(this,Ue).style.pointerEvents="none",s.body.appendChild(K(this,Ue))),et(this,or,new IntersectionObserver(i=>{var o,a;const c=i[i.length-1],{boundingClientRect:f,isIntersecting:d}=c,{width:l,height:u}=f,h=K(this,Gt);et(this,Gt,d),!(!l&&!u)&&(h&&!d?((o=K(this,Vt))==null||o.disconnect(),this.callback(null),(a=K(this,Ct))==null||a.disconnect(),et(this,Ct,void 0),K(this,Ue)&&(K(this,Ue).style.visibility="hidden")):K(this,ar).call(this),d&&!K(this,Ct)&&(et(this,Ct,new Nh(K(this,ar))),K(this,Ct).observe(e)))},{threshold:Ya,root:s})),K(this,Gt)&&!n.skipInitial&&this.callback(this.boundingClientRect),K(this,or).observe(e)}};Gt=new WeakMap;Is=new WeakMap;Ct=new WeakMap;Vt=new WeakMap;or=new WeakMap;Ue=new WeakMap;wr=new WeakMap;ar=new WeakMap;js=new WeakSet;hd=function(){K(this,wr)||(sd(this,js,pd).call(this),!Fh(this.boundingClientRect,K(this,Is))&&(this.callback(this.boundingClientRect),et(this,Is,this.boundingClientRect)))};pd=function(){if(K(this,Ue)){const{top:e,left:t,width:n,height:r}=Cr(this.element);K(this,Ue).style.overflow="hidden",K(this,Ue).style.visibility="visible",K(this,Ue).style.top=`${Math.floor(e)}px`,K(this,Ue).style.left=`${Math.floor(t)}px`,K(this,Ue).style.width=`${Math.floor(n)}px`,K(this,Ue).style.height=`${Math.floor(r)}px`}};var Zr=new WeakMap,Jr=new WeakMap;function Gh(e,t){let n=Zr.get(e);return n||(n={disconnect:new gd(e,s=>{const i=Zr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Zr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Zr.delete(e),n.disconnect())}}function Vh(e,t){const n=new Set;for(const r of e){const s=Gh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Uh(e,t){var n;const r=e.ownerDocument;if(!Jr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(f=>f(c)),{capture:!0,passive:!0,signal:o.signal}),Jr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Jr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Jr.delete(r))})}var lr,cr,gs,no,Hh=class{constructor(e,t,n){this.callback=t,Ze(this,lr),Ze(this,cr,!1),Ze(this,gs),Ze(this,no,ud(o=>{if(!K(this,cr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of K(this,gs))if(o.target.contains(a)){this.callback(K(this,lr).boundingClientRect);break}}},fd));const r=Lh(e),s=Vh(r,t),i=Uh(e,K(this,no));et(this,gs,r),et(this,lr,new gd(e,t,n)),this.disconnect=()=>{K(this,cr)||(et(this,cr,!0),s(),i(),K(this,lr).disconnect())}}};lr=new WeakMap;cr=new WeakMap;gs=new WeakMap;no=new WeakMap;function ro(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function kn(e){try{ro(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Xa(e){return!ad||!e?!1:e===zn(e).scrollingElement}function md(e){var t,n;const r=nt(e),s=Xa(e)?Mh(e):ei(e),i=r.visualViewport,o=Xa(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},c=a.current.y<=0,f=a.current.x<=0,d=a.current.y>=a.max.y,l=a.current.x>=a.max.x;return{rect:s,position:a,isTop:c,isLeft:f,isBottom:d,isRight:l}}function qh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=md(e),{x:a,y:c}=t??{x:0,y:0},f=!n&&o.current.y+c>0,d=!r&&o.current.y+c<o.max.y,l=!s&&o.current.x+a>0,u=!i&&o.current.x+a<o.max.x;return{top:f,bottom:d,left:l,right:u,x:l||u,y:f||d}}var aa=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Ps=new aa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Kh=new aa(e=>setTimeout(e,50)),Rs=new Map,Yh=Rs.clear.bind(Rs);function wt(e,t=!1){if(!t)return Qa(e);let n=Rs.get(e);return n||(n=Qa(e),Rs.set(e,n),Kh.schedule(Yh),n)}function Qa(e){return nt(e).getComputedStyle(e)}function Xh(e,t=wt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Qh(e,t=wt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Zh={excludeElement:!0,escapeShadowDOM:!0};function so(e,t=Zh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(ra(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ia(a))return o(a.host);if(!Rt(a))return od(a)?o(a.parentElement):i;if(i.has(a))return i;const c=wt(a,!0);if(r&&a===e||Qh(a,c)&&i.add(a),Xh(a,c)){const{scrollingElement:f}=a.ownerDocument;return f&&i.add(f),i}return o(a.parentNode)}return e?o(e):i}function On(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Cn(e);for(;r;){if(r===t)return n;const s=ei(r),{x:i,y:o}=Jh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=Cn(r)}return n}function Jh(e,t=ei(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Rt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=wt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function ep(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Or(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function ti(e){var t,n,r,s,i,o,a,c,f;const{scale:d,transform:l,translate:u}=e,h=ep(d),p=Or(u),y=tp(l);if(!y&&!h&&!p)return null;const w={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},_={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},g={x:(i=y?.x)!=null?i:0,y:(o=y?.y)!=null?o:0,scaleX:(a=y?.scaleX)!=null?a:1,scaleY:(c=y?.scaleY)!=null?c:1};return{x:_.x+g.x,y:_.y+g.y,z:(f=p?.z)!=null?f:0,scaleX:w.x*g.scaleX,scaleY:w.y*g.scaleY}}function tp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var ot=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(ot||{}),np={x:.2,y:.2},rp={x:10,y:10};function sp(e,t,n,r=25,s=np,i=rp){const{x:o,y:a}=t,{rect:c,isTop:f,isBottom:d,isLeft:l,isRight:u}=md(e),h=On(e),p=wt(e,!0),y=ti(p),w=y!==null?y?.scaleX<0:!1,_=y!==null?y?.scaleY<0:!1,g=new yt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),v={x:0,y:0},x={x:0,y:0},b={height:g.height*s.y,width:g.width*s.x};return b.height>0&&(!f||_&&!d)&&a<=g.top+b.height&&n?.y!==1&&o>=g.left-i.x&&o<=g.right+i.x?(v.y=_?1:-1,x.y=r*Math.abs((g.top+b.height-a)/b.height)):b.height>0&&(!d||_&&!f)&&a>=g.bottom-b.height&&n?.y!==-1&&o>=g.left-i.x&&o<=g.right+i.x&&(v.y=_?-1:1,x.y=r*Math.abs((g.bottom-b.height-a)/b.height)),b.width>0&&(!u||w&&!l)&&o>=g.right-b.width&&n?.x!==-1&&a>=g.top-i.y&&a<=g.bottom+i.y?(v.x=w?-1:1,x.x=r*Math.abs((g.right-b.width-o)/b.width)):b.width>0&&(!l||w&&!u)&&o<=g.left+b.width&&n?.x!==1&&a>=g.top-i.y&&a<=g.bottom+i.y&&(v.x=w?1:-1,x.x=r*Math.abs((g.left+b.width-o)/b.width)),{direction:v,speed:x}}function vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Rt(e))return;const r=so(e),s=[];for(const i of r){if(!Rt(i))continue;const{top:o,left:a}=ip(e,i);let c=o,f=a;for(const d of s)c-=d.scrollTop,f-=d.scrollLeft;if(t!=="none"){const d=c<i.scrollTop,l=c+e.offsetHeight>i.scrollTop+i.clientHeight;d!==l&&(t==="center"?i.scrollTop=c-i.clientHeight/2+e.offsetHeight/2:d?i.scrollTop=c:i.scrollTop=c+e.offsetHeight-i.clientHeight)}if(n!=="none"){const d=f<i.scrollLeft,l=f+e.offsetWidth>i.scrollLeft+i.clientWidth;d!==l&&(n==="center"?i.scrollLeft=f-i.clientWidth/2+e.offsetWidth/2:d?i.scrollLeft=f:i.scrollLeft=f+e.offsetWidth-i.clientWidth)}s.push(i)}}function Za(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Rt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function ip(e,t){const n=Za(e),r=Za(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function op(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),c=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width*r:e.width,d=s?e.height*s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function ap(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),c=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width/r:e.width,d=s?e.height/s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function yd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Ja(e,t=wt(e).translate,n=!0){if(n){const r=id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=Or(s);if(i)return i}}}if(t){const r=Or(t);if(r)return r}return{x:0,y:0,z:0}}var lp=new aa(e=>setTimeout(e,0)),_r=new Map,cp=_r.clear.bind(_r);function dp(e){const t=e.ownerDocument;let n=_r.get(t);if(n)return n;n=t.getAnimations(),_r.set(t,n),lp.schedule(cp);const r=n.filter(s=>Js(s.effect)&&s.effect.target===e);return _r.set(e,r),n}function up(e,t){const n=dp(e).filter(r=>{var s,i;if(Js(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(c=>{for(const f of t.properties)if(c[f])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var vt=class extends yt{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=On(e),ignoreTransforms:a,getBoundingClientRect:c=ei}=t,f=up(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||sa())&&b.contains(e)}),d=c(e);let{top:l,left:u,width:h,height:p}=d,y;const w=wt(e),_=ti(w),g={x:(n=_?.scaleX)!=null?n:1,y:(r=_?.scaleY)!=null?r:1},v=fp(e,w);f?.(),_&&(y=ap(d,_,w.transformOrigin),(a||v)&&(l=y.top,u=y.left,h=y.width,p=y.height));const x={width:(s=y?.width)!=null?s:h,height:(i=y?.height)!=null?i:p};if(v&&!a&&y){const b=op(y,v,w.transformOrigin);l=b.top,u=b.left,h=b.width,p=b.height,g.x=v.scaleX,g.y=v.scaleY}o&&(a||(u*=o.scaleX,h*=o.scaleX,l*=o.scaleY,p*=o.scaleY),u+=o.x,l+=o.y),super(u,l,h,p),this.scale=g,this.intrinsicWidth=x.width,this.intrinsicHeight=x.height}};function fp(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const c=Js(a.effect)?a.effect.getKeyframes():[],f=c[c.length-1];if(!f)continue;const{transform:d,translate:l,scale:u}=f;typeof d=="string"&&d&&(r=d,o=!0),typeof l=="string"&&l&&(s=l,o=!0),typeof u=="string"&&u&&(i=u,o=!0)}return o?ti({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function kr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var hp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(kr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(kr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(kr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Qt(e){return e?e instanceof nt(e).Element||Wr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Dr(e){if(!e)return!1;const{KeyboardEvent:t}=nt(e.target);return e instanceof t}function pp(e){if(!e)return!1;const{PointerEvent:t}=nt(e.target);return e instanceof t}function gp(e){if(!Qt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||mp(e)}function mp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var yi={};function io(e){const t=yi[e]==null?0:yi[e]+1;return yi[e]=t,`${e}-${t}`}var la=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=it.distance(t.shape.center,n);return{id:r,value:1/s,type:Fn.PointerIntersection,priority:Bn.High}}return null},vp=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=it.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Fn.ShapeIntersection,priority:Bn.Normal}}return null},bd=e=>{var t;return(t=la(e))!=null?t:vp(e)},yp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?yt.from(r.current.boundingRectangle).corners:void 0,a=yt.from(n.shape.boundingRectangle).corners.reduce((c,f,d)=>{var l;return c+it.distance(it.from(f),(l=i?.[d])!=null?l:s.current)},0)/4;return{id:n.id,value:1/a,type:Fn.Collision,priority:Bn.Normal}},bp=Object.create,ca=Object.defineProperty,xp=Object.defineProperties,wp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyDescriptors,As=Object.getOwnPropertySymbols,xd=Object.prototype.hasOwnProperty,wd=Object.prototype.propertyIsEnumerable,_d=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Wn=e=>{throw TypeError(e)},oo=(e,t,n)=>t in e?ca(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mr=(e,t)=>{for(var n in t||(t={}))xd.call(t,n)&&oo(e,n,t[n]);if(As)for(var n of As(t))wd.call(t,n)&&oo(e,n,t[n]);return e},da=(e,t)=>xp(e,_p(t)),el=(e,t)=>ca(e,"name",{value:t,configurable:!0}),kd=(e,t)=>{var n={};for(var r in e)xd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&As)for(var r of As(e))t.indexOf(r)<0&&wd.call(e,r)&&(n[r]=e[r]);return n},Nn=e=>{var t;return[,,,bp((t=e?.[_d("metadata")])!=null?t:null)]},Sd=["class","method","getter","setter","accessor","field","value","get","set"],dr=e=>e!==void 0&&typeof e!="function"?Wn("Function expected"):e,kp=(e,t,n,r,s)=>({kind:Sd[e],name:t,metadata:r,addInitializer:i=>n._?Wn("Already initialized"):s.push(dr(i||null))}),nn=(e,t)=>oo(t,_d("metadata"),e[3]),Ne=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},dt=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,y=Sd[l+5],w=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&wp(l<4?s:{get[n](){return ge(this,i)},set[n](x){return Xe(this,i,x)}},n));l?h&&l<4&&el(i,(l>2?"set ":l>1?"get ":"")+n):el(s,n);for(var v=r.length-1;v>=0;v--)f=kp(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?x=>Sp(s,x):x=>n in x},l^3&&(d.get=h?x=>(l^1?ge:Zt)(x,s,l^4?i:g.get):x=>x[n]),l>2&&(d.set=h?(x,b)=>Xe(x,s,b,l^4?i:g.set):(x,b)=>x[n]=b)),a=(0,r[v])(l?l<4?h?i:g[y]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?dr(a)&&(l>4?w.unshift(a):l?h?i=a:g[y]=a:s=a):typeof a!="object"||a===null?Wn("Object expected"):(dr(o=a.get)&&(g.get=o),dr(o=a.set)&&(g.set=o),dr(o=a.init)&&w.unshift(o));return l||nn(e,s),g&&ca(s,n,g),h?l^4?i:g:s},ua=(e,t,n)=>t.has(e)||Wn("Cannot "+n),Sp=(e,t)=>Object(t)!==t?Wn('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(ua(e,t,"read from private field"),n?n.call(e):t.get(e)),je=(e,t,n)=>t.has(e)?Wn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(ua(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zt=(e,t,n)=>(ua(e,t,"access private method"),n),tl={role:"button",roleDescription:"draggable"},$p="dnd-kit-description",Tp="dnd-kit-announcement",Ep={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Cp={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Op(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Dp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Mp(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Ip=["dragover","dragmove"],jp=class extends qe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=$p,announcement:s=Tp}={},announcements:i=Cp,screenReaderInstructions:o=Ep,debounce:a=500}=t??{},c=n?`${r}-${n}`:io(r),f=n?`${s}-${n}`:io(s);let d,l,u,h;const p=(b=h)=>{!u||!b||u?.nodeValue!==b&&(u.nodeValue=b)},y=()=>Ps.schedule(p),w=Pp(y,a),_=Object.entries(i).map(([b,T])=>this.manager.monitor.addEventListener(b,(C,M)=>{const E=u;if(!E)return;const O=T?.(C,M);O&&E.nodeValue!==O&&(h=O,Ip.includes(b)?w():(y(),w.cancel()))})),g=()=>{let b=[];d?.isConnected||(d=Dp(c,o.draggable),b.push(d)),l?.isConnected||(l=Mp(f),u=document.createTextNode(""),l.appendChild(u),b.push(l)),b.length>0&&document.body.append(...b)},v=new Set;function x(){for(const b of v)b()}this.registerEffect(()=>{var b;v.clear();for(const T of this.manager.registry.draggables.value){const C=(b=T.handle)!=null?b:T.element;if(C){(!d||!l)&&v.add(g),(!Op(C)||sa())&&!C.hasAttribute("tabindex")&&v.add(()=>C.setAttribute("tabindex","0")),!C.hasAttribute("role")&&C.tagName.toLowerCase()!=="button"&&v.add(()=>C.setAttribute("role",tl.role)),C.hasAttribute("aria-roledescription")||v.add(()=>C.setAttribute("aria-roledescription",tl.roleDescription)),C.hasAttribute("aria-describedby")||v.add(()=>C.setAttribute("aria-describedby",c));for(const E of["aria-pressed","aria-grabbed"]){const O=String(T.isDragging);C.getAttribute(E)!==O&&v.add(()=>C.setAttribute(E,O))}const M=String(T.disabled);C.getAttribute("aria-disabled")!==M&&v.add(()=>C.setAttribute("aria-disabled",M))}}v.size>0&&Ps.schedule(x)}),this.destroy=()=>{super.destroy(),d?.remove(),l?.remove(),_.forEach(b=>b())}}};function Pp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Ls=new Map,$d,Td,Ed,Cd,ao,Sr,kt,fa,Dn,Od,Dd,Md,Id,At=class extends(ao=zr,Cd=[ne],Ed=[De],Td=[De],$d=[De],ao){constructor(t,n){super(t,n),Ne(kt,5,this),je(this,Dn),je(this,Sr,new Set),je(this,fa,Ne(kt,8,this,new Set)),Ne(kt,11,this),this.registerEffect(Zt(this,Dn,Od))}register(t){return ge(this,Sr).add(t),()=>{ge(this,Sr).delete(t)}}addRoot(t){return te(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{te(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Ms((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Ms((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};kt=Nn(ao);Sr=new WeakMap;fa=new WeakMap;Dn=new WeakSet;Od=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,Sr))t.push(Zt(this,Dn,Dd).call(this,n,r));return()=>{for(const n of t)n()}};Dd=function(e,t){let n=Ls.get(e);n||(n=new Map,Ls.set(e,n));let r=n.get(t);if(!r){const i=ra(e)?Zt(this,Dn,Md).call(this,e,n,t):Zt(this,Dn,Id).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Md=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const c of a)for(const f of Array.from(c.removedNodes))if(f===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Ls.delete(e)}}};Id=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(ia(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Ls.delete(e)}}};dt(kt,4,"additionalRoots",Cd,At,fa);dt(kt,2,"sourceRoot",Ed,At);dt(kt,2,"targetRoot",Td,At);dt(kt,2,"roots",$d,At);nn(kt,At);At.configure=Fr(At);var ni=At,Rp=class extends qe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(ni),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Nr="data-dnd-",lo=`${Nr}dropping`,Ve="--dnd-",mt=`${Nr}dragging`,Bs=`${Nr}placeholder`,Ap=[mt,Bs,"popover","aria-pressed","aria-grabbing"],Lp=["view-transition-name"],Bp=`
9
- :is(:root,:host) [${mt}] {
8
+ `)}var Ld=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 jn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function xp(e){const t=new Set;let n=jn(e);for(;n;)t.add(n),n=jn(n);return t}function wp(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function Bd(e,t){const n=()=>performance.now();let r,s;return function(...o){const i=this;s?(r?.(),r=wp(()=>{e.apply(i,o),s=n()},t-(n()-s))):(e.apply(i,o),s=n())}}function _p(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 kp(e,t=e.getBoundingClientRect()){const{width:n,height:r}=jr(e,t);return n>0&&r>0}var Sp=Pd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ws,$p=class extends Sp{constructor(e){super(t=>{if(!te(this,ws)){at(this,ws,!0);return}e(t,this)}),ot(this,ws,!1)}};ws=new WeakMap;var hl=Array.from({length:100},(e,t)=>t/100),Fd=75,Yt,Fs,At,Qt,fr,Qe,Er,hr,Ws,Wd,zd,Nd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,ot(this,Ws),this.disconnect=()=>{var o,i,a;at(this,Er,!0),(o=te(this,At))==null||o.disconnect(),(i=te(this,Qt))==null||i.disconnect(),te(this,fr).disconnect(),(a=te(this,Qe))==null||a.remove()},ot(this,Yt,!0),ot(this,Fs),ot(this,At),ot(this,Qt),ot(this,fr),ot(this,Qe),ot(this,Er,!1),ot(this,hr,Bd(()=>{var o,i,a;const{element:l}=this;if((o=te(this,Qt))==null||o.disconnect(),te(this,Er)||!te(this,Yt)||!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=jr(l,f),{top:g,left:v,bottom:_,right:x}=h,p=-Math.floor(g),y=-Math.floor(v),w=-Math.floor(d-x),b=-Math.floor(c-_),E=`${p}px ${w}px ${b}px ${y}px`;this.boundingClientRect=f,at(this,Qt,new IntersectionObserver(T=>{const[C]=T,{intersectionRect:M}=C;(C.intersectionRatio!==1?C.intersectionRatio:St.intersectionRatio(M,jr(l)))!==1&&te(this,hr).call(this)},{threshold:hl,rootMargin:E,root:u})),te(this,Qt).observe(l),Dd(this,Ws,Wd).call(this)},Fd)),this.boundingClientRect=e.getBoundingClientRect(),at(this,Yt,kp(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(at(this,Qe,document.createElement("div")),te(this,Qe).style.background="rgba(0,0,0,0.15)",te(this,Qe).style.position="fixed",te(this,Qe).style.pointerEvents="none",s.body.appendChild(te(this,Qe))),at(this,fr,new IntersectionObserver(o=>{var i,a;const l=o[o.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:f}=u,h=te(this,Yt);at(this,Yt,c),!(!d&&!f)&&(h&&!c?((i=te(this,Qt))==null||i.disconnect(),this.callback(null),(a=te(this,At))==null||a.disconnect(),at(this,At,void 0),te(this,Qe)&&(te(this,Qe).style.visibility="hidden")):te(this,hr).call(this),c&&!te(this,At)&&(at(this,At,new $p(te(this,hr))),te(this,At).observe(e)))},{threshold:hl,root:s})),te(this,Yt)&&!n.skipInitial&&this.callback(this.boundingClientRect),te(this,fr).observe(e)}};Yt=new WeakMap;Fs=new WeakMap;At=new WeakMap;Qt=new WeakMap;fr=new WeakMap;Qe=new WeakMap;Er=new WeakMap;hr=new WeakMap;Ws=new WeakSet;Wd=function(){te(this,Er)||(Dd(this,Ws,zd).call(this),!_p(this.boundingClientRect,te(this,Fs))&&(this.callback(this.boundingClientRect),at(this,Fs,this.boundingClientRect)))};zd=function(){if(te(this,Qe)){const{top:e,left:t,width:n,height:r}=jr(this.element);te(this,Qe).style.overflow="hidden",te(this,Qe).style.visibility="visible",te(this,Qe).style.top=`${Math.floor(e)}px`,te(this,Qe).style.left=`${Math.floor(t)}px`,te(this,Qe).style.width=`${Math.floor(n)}px`,te(this,Qe).style.height=`${Math.floor(r)}px`}};var os=new WeakMap,is=new WeakMap;function Tp(e,t){let n=os.get(e);return n||(n={disconnect:new Nd(e,s=>{const o=os.get(e);o&&o.callbacks.forEach(i=>i(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),os.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(os.delete(e),n.disconnect())}}function Ep(e,t){const n=new Set;for(const r of e){const s=Tp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Cp(e,t){var n;const r=e.ownerDocument;if(!is.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}),is.set(r,{disconnect:()=>i.abort(),listeners:a})}const{listeners:s,disconnect:o}=(n=is.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),is.delete(r))})}var pr,gr,_s,fi,Op=class{constructor(e,t,n){this.callback=t,ot(this,pr),ot(this,gr,!1),ot(this,_s),ot(this,fi,Bd(i=>{if(!te(this,gr)&&i.target&&"contains"in i.target&&typeof i.target.contains=="function"){for(const a of te(this,_s))if(i.target.contains(a)){this.callback(te(this,pr).boundingClientRect);break}}},Fd));const r=xp(e),s=Ep(r,t),o=Cp(e,te(this,fi));at(this,_s,r),at(this,pr,new Nd(e,t,n)),this.disconnect=()=>{te(this,gr)||(at(this,gr,!0),s(),o(),te(this,pr).disconnect())}}};pr=new WeakMap;gr=new WeakMap;_s=new WeakMap;fi=new WeakMap;function hi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function On(e){try{hi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function pl(e){return!Pd||!e?!1:e===Kn(e).scrollingElement}function Gd(e){var t,n;const r=dt(e),s=pl(e)?pp(e):lo(e),o=r.visualViewport,i=pl(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 Mp(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:i}=Gd(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 ba=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))}},zs=new ba(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Dp=new ba(e=>setTimeout(e,50)),Ns=new Map,Ip=Ns.clear.bind(Ns);function Et(e,t=!1){if(!t)return gl(e);let n=Ns.get(e);return n||(n=gl(e),Ns.set(e,n),Dp.schedule(Ip),n)}function gl(e){return dt(e).getComputedStyle(e)}function Rp(e,t=Et(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Pp(e,t=Et(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 jp={excludeElement:!0,escapeShadowDOM:!0};function pi(e,t=jp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function i(a){if(n!=null&&o.size>=n||!a)return o;if(ga(a)&&a.scrollingElement!=null&&!o.has(a.scrollingElement))return o.add(a.scrollingElement),o;if(s&&va(a))return i(a.host);if(!Gt(a))return Rd(a)?i(a.parentElement):o;if(o.has(a))return o;const l=Et(a,!0);if(r&&a===e||Pp(a,l)&&o.add(a),Rp(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&o.add(u),o}return i(a.parentNode)}return e?i(e):o}function An(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=jn(e);for(;r;){if(r===t)return n;const s=lo(r),{x:o,y:i}=Ap(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=jn(r)}return n}function Ap(e,t=lo(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Gt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=Et(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Lp(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 Ar(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 co(e){var t,n,r,s,o,i,a,l,u;const{scale:c,transform:d,translate:f}=e,h=Lp(c),g=Ar(f),v=Bp(d);if(!v&&!h&&!g)return null;const _={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=g?.x)!=null?r:0,y:(s=g?.y)!=null?s:0},p={x:(o=v?.x)!=null?o:0,y:(i=v?.y)!=null?i:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(l=v?.scaleY)!=null?l:1};return{x:x.x+p.x,y:x.y+p.y,z:(u=g?.z)!=null?u:0,scaleX:_.x*p.scaleX,scaleY:_.y*p.scaleY}}function Bp(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 ht=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(ht||{}),Fp={x:.2,y:.2},Wp={x:10,y:10};function zp(e,t,n,r=25,s=Fp,o=Wp){const{x:i,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:f}=Gd(e),h=An(e),g=Et(e,!0),v=co(g),_=v!==null?v?.scaleX<0:!1,x=v!==null?v?.scaleY<0:!1,p=new St(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),y={x:0,y:0},w={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?(y.y=x?1:-1,w.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&&(y.y=x?-1:1,w.y=r*Math.abs((p.bottom-b.height-a)/b.height)),b.width>0&&(!f||_&&!d)&&i>=p.right-b.width&&n?.x!==-1&&a>=p.top-o.y&&a<=p.bottom+o.y?(y.x=_?-1:1,w.x=r*Math.abs((p.right-b.width-i)/b.width)):b.width>0&&(!d||_&&!f)&&i<=p.left+b.width&&n?.x!==1&&a>=p.top-o.y&&a<=p.bottom+o.y&&(y.x=_?1:-1,w.x=r*Math.abs((p.left+b.width-i)/b.width)),{direction:y,speed:w}}function Hd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Gt(e))return;const r=pi(e),s=[];for(const o of r){if(!Gt(o))continue;const{top:i,left:a}=Np(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 ml(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Gt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Np(e,t){const n=ml(e),r=ml(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Gp(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 Hp(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 qd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function vl(e,t=Et(e).translate,n=!0){if(n){const r=Id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const o=Ar(s);if(o)return o}}}if(t){const r=Ar(t);if(r)return r}return{x:0,y:0,z:0}}var qp=new ba(e=>setTimeout(e,0)),Cr=new Map,Up=Cr.clear.bind(Cr);function Vp(e){const t=e.ownerDocument;let n=Cr.get(t);if(n)return n;n=t.getAnimations(),Cr.set(t,n),qp.schedule(Up);const r=n.filter(s=>ao(s.effect)&&s.effect.target===e);return Cr.set(e,r),n}function Kp(e,t){const n=Vp(e).filter(r=>{var s,o;if(ao(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 kt=class extends St{constructor(e,t={}){var n,r,s,o;const{frameTransform:i=An(e),ignoreTransforms:a,getBoundingClientRect:l=lo}=t,u=Kp(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ma())&&b.contains(e)}),c=l(e);let{top:d,left:f,width:h,height:g}=c,v;const _=Et(e),x=co(_),p={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},y=Xp(e,_);u?.(),x&&(v=Hp(c,x,_.transformOrigin),(a||y)&&(d=v.top,f=v.left,h=v.width,g=v.height));const w={width:(s=v?.width)!=null?s:h,height:(o=v?.height)!=null?o:g};if(y&&!a&&v){const b=Gp(v,y,_.transformOrigin);d=b.top,f=b.left,h=b.width,g=b.height,p.x=y.scaleX,p.y=y.scaleY}i&&(a||(f*=i.scaleX,h*=i.scaleX,d*=i.scaleY,g*=i.scaleY),f+=i.x,d+=i.y),super(f,d,h,g),this.scale=p,this.intrinsicWidth=w.width,this.intrinsicHeight=w.height}};function Xp(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=ao(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?co({transform:r??t.transform,translate:s??t.translate,scale:o??t.scale}):null}function Or(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 Yp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Or(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(Or(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(Or(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function sn(e){return e?e instanceof dt(e).Element||Kr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Lr(e){if(!e)return!1;const{KeyboardEvent:t}=dt(e.target);return e instanceof t}function Qp(e){if(!e)return!1;const{PointerEvent:t}=dt(e.target);return e instanceof t}function Zp(e){if(!sn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Jp(e)}function Jp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Eo={};function gi(e){const t=Eo[e]==null?0:Eo[e]+1;return Eo[e]=t,`${e}-${t}`}var xa=({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=ft.distance(t.shape.center,n);return{id:r,value:1/s,type:Vn.PointerIntersection,priority:Un.High}}return null},eg=({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=ft.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Vn.ShapeIntersection,priority:Un.Normal}}return null},Ud=e=>{var t;return(t=xa(e))!=null?t:eg(e)},tg=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const o=r?St.from(r.current.boundingRectangle).corners:void 0,a=St.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+ft.distance(ft.from(u),(d=o?.[c])!=null?d:s.current)},0)/4;return{id:n.id,value:1/a,type:Vn.Collision,priority:Un.Normal}},ng=Object.create,wa=Object.defineProperty,rg=Object.defineProperties,sg=Object.getOwnPropertyDescriptor,og=Object.getOwnPropertyDescriptors,Gs=Object.getOwnPropertySymbols,Vd=Object.prototype.hasOwnProperty,Kd=Object.prototype.propertyIsEnumerable,Xd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xn=e=>{throw TypeError(e)},mi=(e,t,n)=>t in e?wa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Br=(e,t)=>{for(var n in t||(t={}))Vd.call(t,n)&&mi(e,n,t[n]);if(Gs)for(var n of Gs(t))Kd.call(t,n)&&mi(e,n,t[n]);return e},_a=(e,t)=>rg(e,og(t)),yl=(e,t)=>wa(e,"name",{value:t,configurable:!0}),Yd=(e,t)=>{var n={};for(var r in e)Vd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Gs)for(var r of Gs(e))t.indexOf(r)<0&&Kd.call(e,r)&&(n[r]=e[r]);return n},Yn=e=>{var t;return[,,,ng((t=e?.[Xd("metadata")])!=null?t:null)]},Qd=["class","method","getter","setter","accessor","field","value","get","set"],mr=e=>e!==void 0&&typeof e!="function"?Xn("Function expected"):e,ig=(e,t,n,r,s)=>({kind:Qd[e],name:t,metadata:r,addInitializer:o=>n._?Xn("Already initialized"):s.push(mr(o||null))}),dn=(e,t)=>mi(t,Xd("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},mt=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?f?1:2:0,v=Qd[d+5],_=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&sg(d<4?s:{get[n](){return xe(this,o)},set[n](w){return nt(this,o,w)}},n));d?h&&d<4&&yl(o,(d>2?"set ":d>1?"get ":"")+n):yl(s,n);for(var y=r.length-1;y>=0;y--)u=ig(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?w=>ag(s,w):w=>n in w},d^3&&(c.get=h?w=>(d^1?xe:on)(w,s,d^4?o:p.get):w=>w[n]),d>2&&(c.set=h?(w,b)=>nt(w,s,b,d^4?o:p.set):(w,b)=>w[n]=b)),a=(0,r[y])(d?d<4?h?o:p[v]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?mr(a)&&(d>4?_.unshift(a):d?h?o=a:p[v]=a:s=a):typeof a!="object"||a===null?Xn("Object expected"):(mr(i=a.get)&&(p.get=i),mr(i=a.set)&&(p.set=i),mr(i=a.init)&&_.unshift(i));return d||dn(e,s),p&&wa(s,n,p),h?d^4?o:p:s},ka=(e,t,n)=>t.has(e)||Xn("Cannot "+n),ag=(e,t)=>Object(t)!==t?Xn('Cannot use the "in" operator on this value'):e.has(t),xe=(e,t,n)=>(ka(e,t,"read from private field"),n?n.call(e):t.get(e)),Fe=(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),nt=(e,t,n,r)=>(ka(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),on=(e,t,n)=>(ka(e,t,"access private method"),n),bl={role:"button",roleDescription:"draggable"},lg="dnd-kit-description",cg="dnd-kit-announcement",dg={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."},ug={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 fg(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function hg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function pg(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 gg=["dragover","dragmove"],mg=class extends Je{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=lg,announcement:s=cg}={},announcements:o=ug,screenReaderInstructions:i=dg,debounce:a=500}=t??{},l=n?`${r}-${n}`:gi(r),u=n?`${s}-${n}`:gi(s);let c,d,f,h;const g=(b=h)=>{!f||!b||f?.nodeValue!==b&&(f.nodeValue=b)},v=()=>zs.schedule(g),_=vg(v,a),x=Object.entries(o).map(([b,E])=>this.manager.monitor.addEventListener(b,(T,C)=>{const M=f;if(!M)return;const O=E?.(T,C);O&&M.nodeValue!==O&&(h=O,gg.includes(b)?_():(v(),_.cancel()))})),p=()=>{let b=[];c?.isConnected||(c=hg(l,i.draggable),b.push(c)),d?.isConnected||(d=pg(u),f=document.createTextNode(""),d.appendChild(f),b.push(d)),b.length>0&&document.body.append(...b)},y=new Set;function w(){for(const b of y)b()}this.registerEffect(()=>{var b;y.clear();for(const E of this.manager.registry.draggables.value){const T=(b=E.handle)!=null?b:E.element;if(T){(!c||!d)&&y.add(p),(!fg(T)||ma())&&!T.hasAttribute("tabindex")&&y.add(()=>T.setAttribute("tabindex","0")),!T.hasAttribute("role")&&T.tagName.toLowerCase()!=="button"&&y.add(()=>T.setAttribute("role",bl.role)),T.hasAttribute("aria-roledescription")||y.add(()=>T.setAttribute("aria-roledescription",bl.roleDescription)),T.hasAttribute("aria-describedby")||y.add(()=>T.setAttribute("aria-describedby",l));for(const M of["aria-pressed","aria-grabbed"]){const O=String(E.isDragging);T.getAttribute(M)!==O&&y.add(()=>T.setAttribute(M,O))}const C=String(E.disabled);T.getAttribute("aria-disabled")!==C&&y.add(()=>T.setAttribute("aria-disabled",C))}}y.size>0&&zs.schedule(w)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),x.forEach(b=>b())}}};function vg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Hs=new Map,Zd,Jd,eu,tu,vi,Mr,Dt,Sa,Ln,nu,ru,su,ou,Ht=class extends(vi=Vr,tu=[le],eu=[Le],Jd=[Le],Zd=[Le],vi){constructor(t,n){super(t,n),Ve(Dt,5,this),Fe(this,Ln),Fe(this,Mr,new Set),Fe(this,Sa,Ve(Dt,8,this,new Set)),Ve(Dt,11,this),this.registerEffect(on(this,Ln,nu))}register(t){return xe(this,Mr).add(t),()=>{xe(this,Mr).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 Bs((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Bs((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}};Dt=Yn(vi);Mr=new WeakMap;Sa=new WeakMap;Ln=new WeakSet;nu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of xe(this,Mr))t.push(on(this,Ln,ru).call(this,n,r));return()=>{for(const n of t)n()}};ru=function(e,t){let n=Hs.get(e);n||(n=new Map,Hs.set(e,n));let r=n.get(t);if(!r){const o=ga(e)?on(this,Ln,su).call(this,e,n,t):on(this,Ln,ou).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())}};su=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&&Hs.delete(e)}}};ou=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(va(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&&Hs.delete(e)}}};mt(Dt,4,"additionalRoots",tu,Ht,Sa);mt(Dt,2,"sourceRoot",eu,Ht);mt(Dt,2,"targetRoot",Jd,Ht);mt(Dt,2,"roots",Zd,Ht);dn(Dt,Ht);Ht.configure=Ur(Ht);var uo=Ht,yg=class extends Je{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(uo),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}}},Xr="data-dnd-",yi=`${Xr}dropping`,Ye="--dnd-",_t=`${Xr}dragging`,qs=`${Xr}placeholder`,bg=[_t,qs,"popover","aria-pressed","aria-grabbing"],xg=["view-transition-name"],wg=`
9
+ :is(:root,:host) [${_t}] {
10
10
  position: fixed !important;
11
11
  pointer-events: none !important;
12
12
  touch-action: none;
13
13
  z-index: calc(infinity);
14
14
  will-change: translate;
15
- top: var(${Ve}top, 0px) !important;
16
- left: var(${Ve}left, 0px) !important;
15
+ top: var(${Ye}top, 0px) !important;
16
+ left: var(${Ye}left, 0px) !important;
17
17
  right: unset !important;
18
18
  bottom: unset !important;
19
- width: var(${Ve}width, auto);
20
- max-width: var(${Ve}width, auto);
21
- height: var(${Ve}height, auto);
22
- max-height: var(${Ve}height, auto);
23
- transform: var(${Ve}transform, none) !important;
24
- transition: var(${Ve}transition) !important;
19
+ width: var(${Ye}width, auto);
20
+ max-width: var(${Ye}width, auto);
21
+ height: var(${Ye}height, auto);
22
+ max-height: var(${Ye}height, auto);
23
+ transform: var(${Ye}transform, none) !important;
24
+ transition: var(${Ye}transition) !important;
25
25
  }
26
26
 
27
- :is(:root,:host) [${Bs}] {
27
+ :is(:root,:host) [${qs}] {
28
28
  transition: none;
29
29
  }
30
30
 
31
- :is(:root,:host) [${Bs}='hidden'] {
31
+ :is(:root,:host) [${qs}='hidden'] {
32
32
  visibility: hidden;
33
33
  }
34
34
 
35
- [${mt}] * {
35
+ [${_t}] * {
36
36
  pointer-events: none !important;
37
37
  }
38
38
 
39
- [${mt}]:not([${lo}]) {
40
- translate: var(${Ve}translate) !important;
39
+ [${_t}]:not([${yi}]) {
40
+ translate: var(${Ye}translate) !important;
41
41
  }
42
42
 
43
- [${mt}][style*='${Ve}scale'] {
44
- scale: var(${Ve}scale) !important;
45
- transform-origin: var(${Ve}transform-origin) !important;
43
+ [${_t}][style*='${Ye}scale'] {
44
+ scale: var(${Ye}scale) !important;
45
+ transform-origin: var(${Ye}transform-origin) !important;
46
46
  }
47
47
 
48
48
  @layer dnd-kit {
49
- :where([${mt}][popover]) {
49
+ :where([${_t}][popover]) {
50
50
  overflow: visible;
51
51
  background: unset;
52
52
  border: unset;
@@ -60,84 +60,85 @@
60
60
  }
61
61
  }
62
62
  }
63
- [${mt}]::backdrop, [${Nr}overlay]:not([${mt}]) {
63
+ [${_t}]::backdrop, [${Xr}overlay]:not([${_t}]) {
64
64
  display: none;
65
65
  visibility: hidden;
66
66
  }
67
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Fp(e,t="hidden"){return te(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=zp(n,r.registry.droppables),i=[],o=Ph(n),{remove:a}=o;return Wp(s,o,i),Np(o,t),o.remove=()=>{i.forEach(c=>c()),a.call(o)},o})}function zp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Nr}${io("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Wp(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),to.set(a,o),n.push(()=>{to.delete(a),r.proxy=void 0})}}function Np(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Bs,t)}function jd(e,t){return e===t?!0:Cn(e)===Cn(t)}function nl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Qt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>kn(t))}function co(e){return e.tagName==="TR"}function Gp(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Ap.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(kr(e)&&kr(t)){const f=e.style;for(const d of Array.from(t.style))f.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(f)){if(Lp.includes(d)||d.startsWith(Ve))continue;const l=f.getPropertyValue(d);t.style.setProperty(d,l)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Vp(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),kn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),kn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),kn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Up(e){return new ResizeObserver(()=>{var t,n,r;const s=new vt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,c=ld();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},Ve),(n=e.getElementMutationObserver())==null||n.takeRecords(),co(e.element)&&co(e.placeholder)){const y=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(y.map(_=>_.style.width));for(const[_,g]of y.entries()){const v=w[_];g.style.width=`${v.getBoundingClientRect().width}px`}}const f=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+c.x+f.x,l=e.top+a+c.y+f.y,u=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new yt(d*p.scaleX+p.x,l*p.scaleY+p.y,u*p.scaleX,h*p.scaleY)})}var Hp=250,qp="ease";function Kp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const g=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(g).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Hp,easing:a=qp}=i??{};kn(e.feedbackElement);const[,c]=(t=id(e.feedbackElement,g=>"translate"in g))!=null?t:[];c?.pause();const f=(n=e.placeholder)!=null?n:e.element,d={frameTransform:jd(e.feedbackElement,f)?null:void 0},l=new vt(e.feedbackElement,d),u=(r=Or(wt(e.feedbackElement).translate))!=null?r:e.translate,h=new vt(f,d),p=yt.delta(l,h,e.alignment),y={x:u.x-p.x,y:u.y-p.y},w=Math.round(l.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},_=Math.round(l.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Ve),e.feedbackElement.setAttribute(lo,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),yd({element:e.feedbackElement,keyframes:da(Mr(Mr({},w),_),{translate:[`${u.x}px ${u.y}px 0`,`${y.x}px ${y.y}px 0`]}),options:{duration:oa(nt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(lo),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Pd,uo,Ir,ha,ms,Rd,Ad,Mn=class extends(uo=qe,Pd=[ne],uo){constructor(t,n){super(t,n),je(this,ms),je(this,ha,Ne(Ir,8,this)),Ne(Ir,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(ni),s=r?.register(Bp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Zt(this,ms,Rd).bind(this,r)),this.registerEffect(Zt(this,ms,Ad))}};Ir=Nn(uo);ha=new WeakMap;ms=new WeakSet;Rd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Ms(t);if(n)return e.addRoot(n)};Ad=function(){var e,t,n,r,s,i,o;const{state:a,manager:c,options:f}=this,{dragOperation:d}=c,{position:l,source:u,status:h}=d;if(h.idle){a.current={},a.initial={};return}if(!u)return;const{element:p}=u,y=u.pluginConfig(Mn),w=(t=(e=y?.feedback)!=null?e:f?.feedback)!=null?t:"default",_=typeof w=="function"?w(u,c):w;if(!p||_==="none"||!h.initialized||h.initializing)return;const{initial:g}=a,v=(n=this.overlay)!=null?n:p,x=On(v),b=On(p),T=!jd(p,v),C=new vt(p,{frameTransform:T?b:null,ignoreTransforms:!T}),M={x:b.scaleX/x.scaleX,y:b.scaleY/x.scaleY};let{width:E,height:O,top:P,left:A}=C;T&&(E=E/M.x,O=O/M.y);const L=new hp(v),W=wt(p),{transition:U,translate:N,boxSizing:I,paddingBlockStart:z,paddingBlockEnd:V,paddingInlineStart:B,paddingInlineEnd:G,borderInlineStartWidth:Q,borderInlineEndWidth:Z,borderBlockStartWidth:X,borderBlockEndWidth:H}=W,Pe=U.split(",").filter(fe=>!/^\s*(transform|translate|scale)\b/.test(fe)).join(","),ve=ti(W),pe=W.transform,Se=_==="clone",ee=I==="content-box",Re=ee?parseInt(B)+parseInt(G)+parseInt(Q)+parseInt(Z):0,ce=ee?parseInt(z)+parseInt(V)+parseInt(X)+parseInt(H):0,ie=_!=="move"&&!this.overlay?Fp(u,Se?"clone":"hidden"):null,$e=te(()=>Dr(c.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&ve)g.translate={x:ve.x,y:ve.y};else if(N!=="none"){const fe=Or(N);fe&&(g.translate=fe)}}if(!g.transformOrigin){const fe=te(()=>l.current),Le=A+((r=ve?.x)!=null?r:0),Je=P+((s=ve?.y)!=null?s:0);g.transformOrigin={x:(fe.x-Le*x.scaleX-x.x)/(E*x.scaleX),y:(fe.y-Je*x.scaleY-x.y)/(O*x.scaleY)}}const{transformOrigin:de}=g,xe=P*x.scaleY+x.y,we=A*x.scaleX+x.x;if(!g.coordinates&&(g.coordinates={x:we,y:xe},M.x!==1||M.y!==1)){const{scaleX:fe,scaleY:Le}=b,{x:Je,y:Et}=de;g.coordinates.x+=(E*fe-E)*Je,g.coordinates.y+=(O*Le-O)*Et}g.dimensions||(g.dimensions={width:E,height:O}),g.frameTransform||(g.frameTransform=x);const Ge={x:g.coordinates.x-we,y:g.coordinates.y-xe},me={width:(g.dimensions.width*g.frameTransform.scaleX-E*x.scaleX)*de.x,height:(g.dimensions.height*g.frameTransform.scaleY-O*x.scaleY)*de.y},Ae={x:Ge.x/x.scaleX+me.width,y:Ge.y/x.scaleY+me.height},Fe={left:A+Ae.x,top:P+Ae.y};v.setAttribute(mt,"true");const D=te(()=>d.transform),R=(i=g.translate)!=null?i:{x:0,y:0},j=D.x*x.scaleX+R.x,F=D.y*x.scaleY+R.y,J=ld();L.set({width:E-Re,height:O-ce,top:Fe.top+J.y,left:Fe.left+J.x,translate:`${j}px ${F}px 0`,transform:this.overlay?"none":pe,transition:Pe?`${Pe}, translate 0ms linear`:"translate 0ms linear",scale:T?`${M.x} ${M.y}`:"","transform-origin":`${de.x*100}% ${de.y*100}%`},Ve),ie&&(p.insertAdjacentElement("afterend",ie),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(p)),ro(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),kn(v),v.addEventListener("beforetoggle",nl));let q,ae,se;const ue=Up({placeholder:ie,element:p,feedbackElement:v,frameTransform:x,transformOrigin:de,width:E,height:O,top:P,left:A,widthOffset:Re,heightOffset:ce,delta:Ae,styles:L,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>q,getSavedCellWidths:()=>se,setSavedCellWidths:fe=>{se=fe}}),rt=new vt(v);te(()=>d.shape=rt);const Un=nt(v),Bt=fe=>{this.manager.actions.stop({event:fe})},Hn=oa(Un);$e&&Un.addEventListener("resize",Bt),te(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),ie&&(ue.observe(ie),q=Gp(p,ie,Se),ae=Vp(p,ie,v));const qn=(o=c.dragOperation.source)==null?void 0:o.id,Ma=()=>{var fe;if(!$e||qn==null)return;const Le=c.registry.draggables.get(qn),Je=(fe=Le?.handle)!=null?fe:Le?.element;Rt(Je)&&Je.focus()},Kn=()=>{q?.disconnect(),ae?.disconnect(),ue.disconnect(),Un.removeEventListener("resize",Bt),ro(v)&&(v.removeEventListener("beforetoggle",nl),v.removeAttribute("popover")),v.removeAttribute(mt),L.reset();const fe=()=>{var Le;if(se&&co(p)){const ci=Array.from(p.cells);for(const[Kr,sn]of ci.entries())sn.style.width=(Le=se[Kr])!=null?Le:""}u.status="idle";const Je=a.current.translate!=null,Et=d.status.dragging;ie&&(!Et&&Je||ie.parentElement!==v.parentElement)&&v.isConnected&&ie.replaceWith(v),ie?.remove()};v===this.overlay?setTimeout(fe,0):fe()},ai=f?.dropAnimation,rn=this,li=Lr(()=>{var fe,Le,Je;const{transform:Et,status:ci}=d;if(!(!Et.x&&!Et.y&&!a.current.translate)&&ci.dragging){const Kr=(fe=g.translate)!=null?fe:{x:0,y:0},sn={x:Et.x/x.scaleX+Kr.x,y:Et.y/x.scaleY+Kr.y},Ia=a.current.translate,Zu=te(()=>d.modifiers),di=te(()=>{var Xn;return(Xn=d.shape)==null?void 0:Xn.current}),Yn=f?.keyboardTransition,ja=$e&&!Hn&&Yn!==null?`${(Le=Yn?.duration)!=null?Le:250}ms ${(Je=Yn?.easing)!=null?Je:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:Pe?`${Pe}, translate ${ja}`:`translate ${ja}`,translate:`${sn.x}px ${sn.y}px 0`},Ve),q?.takeRecords(),di&&di!==rt&&Ia&&!Zu.length){const Xn=it.delta(sn,Ia);d.shape=yt.from(di.boundingRectangle).translate(Xn.x*x.scaleX,Xn.y*x.scaleY)}else d.shape=new vt(v);a.current.translate=sn}},function(){if(d.status.dropped){this.dispose(),u.status="dropping";const fe=y?.dropAnimation!==void 0?y.dropAnimation:rn.dropAnimation!==void 0?rn.dropAnimation:ai;let Le=a.current.translate;const Je=Le!=null;if(!Le&&p!==v&&(Le={x:0,y:0}),!Le||fe===null){Kn();return}c.renderer.rendering.then(()=>{Kp({source:u,element:p,feedbackElement:v,placeholder:ie,translate:Le,moved:Je,transition:U,alignment:u.alignment,styles:L,animation:fe??void 0,getElementMutationObserver:()=>q,cleanup:Kn,restoreFocus:Ma})})}});return()=>{Kn(),li()}};dt(Ir,4,"overlay",Pd,Mn,ha);nn(Ir,Mn);Mn.configure=Fr(Mn);var pa=Mn,Zn=!0,Yp=!1,Ld,Bd,Fd,zd,Mt,ga,ma;zd=(Fd=[ne],ot.Forward),Bd=(Ld=[ne],ot.Reverse);var jr=class{constructor(){je(this,ga,Ne(Mt,8,this,Zn)),Ne(Mt,11,this),je(this,ma,Ne(Mt,12,this,Zn)),Ne(Mt,15,this)}isLocked(e){return e===ot.Idle?!1:e==null?this[ot.Forward]===Zn&&this[ot.Reverse]===Zn:this[e]===Zn}unlock(e){e!==ot.Idle&&(this[e]=Yp)}};Mt=Nn(null);ga=new WeakMap;ma=new WeakMap;dt(Mt,4,zd,Fd,jr,ga);dt(Mt,4,Bd,Ld,jr,ma);nn(Mt,jr);var Xp=[ot.Forward,ot.Reverse],rl=class{constructor(){this.x=new jr,this.y=new jr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Qp=class extends qe{constructor(e){super(e);const t=In(new rl);let n=null;this.signal=t,ct(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new rl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:sl(s.x,n.x),y:sl(s.y,n.y)},o=t.peek();Ce(()=>{for(const a of gc)for(const c of Xp)i[a]===c&&o[a].unlock(c);t.value=o})}n=s})}get current(){return this.signal.peek()}};function sl(e,t){return Math.sign(e-t)}var Wd,fo,Pr,va,Ot,ho,Gr=class extends(fo=zr,Wd=[ne],fo){constructor(e){super(e),je(this,va,Ne(Pr,8,this,!1)),Ne(Pr,11,this),je(this,Ot),je(this,ho,()=>{if(!ge(this,Ot))return;const{element:i,by:o}=ge(this,Ot);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Xe(this,Ot,void 0),!1;const{position:f}=this.manager.dragOperation,d=f?.current;if(d){const{by:l}=i??{},u=l?{x:il(l.x),y:il(l.y)}:void 0,h=u?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of c){const y=qh(p,l);if(y.x||y.y){const{speed:w,direction:_}=sp(p,d,u,o?.acceleration,o?.threshold);if(h)for(const g of gc)h[g].isLocked(_[g])&&(w[g]=0,_[g]=0);if(_.x||_.y){const{x:g,y:v}=l??_,x=g*w.x,b=v*w.y;if(x||b){const T=(a=ge(this,Ot))==null?void 0:a.by;if(this.autoScrolling&&T&&(T.x&&!x||T.y&&!b))continue;return Xe(this,Ot,{element:p,by:{x,y:b}}),Ps.schedule(ge(this,ho)),!0}}}}}return Xe(this,Ot,void 0),!1};let t=null,n=null;const r=Wi(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=cd(Ms(o?.element),i.current);return a&&(t=a),a??t}),s=Wi(()=>{const i=r.value,{documentElement:o}=zn(i);if(!i||i===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const f=so(c,{excludeElement:!1});return n=f,f}}if(i){const a=so(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ut);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Qp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!Dr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};Pr=Nn(fo);va=new WeakMap;Ot=new WeakMap;ho=new WeakMap;dt(Pr,4,"autoScrolling",Wd,Gr,va);nn(Pr,Gr);function il(e){return e>0?ot.Forward:e<0?ot.Reverse:ot.Idle}var Zp=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},Jp=new Zp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),eg=10,po=class extends qe{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Gr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=ct(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:c}=t.dragOperation;if(c.dragging){const f={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,f)){r.autoScrolling=!0;const l=setInterval(()=>Jp.schedule(()=>r.scroll(void 0,f)),eg);return()=>{clearInterval(l)}}else r.autoScrolling=!1}})}};po.configure=Fr(po);var Nd=po,ol={capture:!0,passive:!0},ur,tg=class extends zr{constructor(e){super(e),je(this,ur),this.handleScroll=()=>{ge(this,ur)==null&&Xe(this,ur,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Xe(this,ur,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=ct(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,ol),()=>{o.removeEventListener("scroll",this.handleScroll,ol)}}})}};ur=new WeakMap;var ng="* { user-select: none !important; -webkit-user-select: none !important; }",rg=class extends qe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(ni),n=t?.register(ng);if(this.destroy=ct(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return bi(),document.addEventListener("selectionchange",bi,{capture:!0}),()=>{document.removeEventListener("selectionchange",bi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function bi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var fr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),gn,Fs=class extends Tn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,gn,[]),this.listeners=new dd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Qt(r.target)||s.disabled)return;const{keyboardCodes:o=fr.keyboardCodes,preventActivation:a=fr.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return ct(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{Dr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),vd(s);const{center:i}=new vt(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=zn(s),c=[this.listeners.bind(a,[{type:"keydown",listener:f=>this.handleKeyDown(f,n,r),options:{capture:!0}}])];ge(this,gn).push(...c)}handleKeyDown(t,n,r){const{keyboardCodes:s=fr.keyboardCodes}=r??{};if(on(t,[...s.end,...s.cancel])){t.preventDefault();const i=on(t,s.cancel);this.handleEnd(t,i);return}on(t,s.up)?this.handleMove("up",t):on(t,s.down)&&this.handleMove("down",t),on(t,s.left)?this.handleMove("left",t):on(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},c=(s=(r=this.options)==null?void 0:r.offset)!=null?s:fr.offset;if(typeof c=="number"&&(c={x:c,y:c}),!!i){switch(t){case"up":a={x:0,y:-c.y*o};break;case"down":a={x:0,y:c.y*o};break;case"left":a={x:-c.x*o,y:0};break;case"right":a={x:c.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Nd);t?.disabled===!1&&(t.disable(),ge(this,gn).push(()=>{t.enable()}))}cleanup(){ge(this,gn).forEach(t=>t()),Xe(this,gn,[])}destroy(){this.cleanup(),this.listeners.clear()}};gn=new WeakMap;Fs.configure=Fr(Fs);Fs.defaults=fr;var Gd=Fs;function on(e,t){return t.includes(e.code)}var Ut,sg=class extends qc{constructor(){super(...arguments),je(this,Ut)}onEvent(e){switch(e.type){case"pointerdown":Xe(this,Ut,En(e));break;case"pointermove":if(!ge(this,Ut))return;const{x:t,y:n}=En(e),r={x:t-ge(this,Ut).x,y:n-ge(this,Ut).y},{tolerance:s}=this.options;if(s&&Xi(r,s)){this.abort();return}Xi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Xe(this,Ut,void 0)}};Ut=new WeakMap;var mn,Ht,ig=class extends qc{constructor(){super(...arguments),je(this,mn),je(this,Ht)}onEvent(e){switch(e.type){case"pointerdown":Xe(this,Ht,En(e)),Xe(this,mn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,Ht))return;const{x:t,y:n}=En(e),r={x:t-ge(this,Ht).x,y:n-ge(this,Ht).y};Xi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,mn)&&(clearTimeout(ge(this,mn)),Xe(this,Ht,void 0),Xe(this,mn,void 0))}};mn=new WeakMap;Ht=new WeakMap;var xn=class{};xn.Delay=ig;xn.Distance=sg;var go=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Qt(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new xn.Delay({value:250,tolerance:5})]:gp(s)&&!e.defaultPrevented?[new xn.Delay({value:200,tolerance:0})]:[new xn.Delay({value:200,tolerance:10}),new xn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Qt(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Ah(r);return s===t.element?!1:!!s}}),vn,zs=class extends Tn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,vn,new Set),this.listeners=new dd,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=go.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return ct(()=>{var s;const i=new AbortController,{signal:o}=i,a=f=>{pp(f)&&this.handlePointerDown(f,t,n)};let c=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?c=n.activatorElements:c=n.activatorElements(t));for(const f of c)f&&(lg(f.ownerDocument.defaultView),f.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Qt(t.target)||n.disabled||og(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=go.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Rt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=On(n.element),{x:c,y:f}=En(t);this.initialCoordinates={x:c*a.scaleX+a.x,y:f*a.scaleY+a.y};const d=this.activationConstraints(t,n,r);t.sensor=this;const l=new Eh(d,y=>this.handleStart(n,y));l.signal.onabort=()=>this.handleCancel(t),l.onEvent(t),this.controller=l;const u=eo(),h=this.listeners.bind(u,[{type:"pointermove",listener:y=>this.handlePointerMove(y,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:es,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};ge(this,vn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=En(t),o=On(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Ps.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=zn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const c=Qt(n.target)?[n.target,a]:a,f=this.listeners.bind(c,[{type:"touchmove",listener:es,options:{passive:!1}},{type:"click",listener:es},{type:"contextmenu",listener:es},{type:"keydown",listener:this.handleKeyDown}]);ge(this,vn).add(f)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},ge(this,vn).forEach(n=>n()),ge(this,vn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};vn=new WeakMap;zs.configure=Fr(zs);zs.defaults=go;var mo=zs;function og(e){return"sensor"in e}function es(e){e.preventDefault()}function ag(){}var al=new WeakSet;function lg(e){!e||al.has(e)||(e.addEventListener("touchmove",ag,{capture:!1,passive:!1}),al.add(e))}var Sn={modifiers:[],plugins:[jp,Nd,Rp,pa,rg],sensors:[mo,Gd]},Vd=class extends Dh{constructor(e={}){const t=pt(e.plugins,Sn.plugins),n=pt(e.sensors,Sn.sensors),r=pt(e.modifiers,Sn.modifiers);super(da(Mr({},e),{plugins:[tg,Gr,ni,...t],sensors:n,modifiers:r}))}},Ud,Hd,vo,It,ya,ba,ri=class extends(vo=bt,Hd=[ne],Ud=[ne],vo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=kd(n,["element","effects","handle"]);super(Mr({effects:()=>[...s(),()=>{var a,c;const{manager:f}=this;if(!f)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Tr))!=null?c:[...f.sensors]).map(u=>{const h=u instanceof Tn?u:f.registry.register(u.plugin),p=u instanceof Tn?void 0:u.options;return h.bind(this,p)});return function(){l.forEach(h=>h())}}]},o),t),je(this,ya,Ne(It,8,this)),Ne(It,11,this),je(this,ba,Ne(It,12,this)),Ne(It,15,this),this.element=r,this.handle=i}};It=Nn(vo);ya=new WeakMap;ba=new WeakMap;dt(It,4,"handle",Hd,ri,ya);dt(It,4,"element",Ud,ri,ba);nn(It,ri);var qd,Kd,yo,jt,xa,xi,Yd,Xd,$r,wa,si=class extends(yo=xt,Kd=[ne],qd=[ne],yo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=kd(n,["element","effects"]);const{collisionDetector:o=bd}=i,a=f=>{const{manager:d,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!d)return;const u=new vt(l),h=te(()=>this.shape);return u&&h?.equals(u)?h:(this.shape=u,u)},c=In(!1);super(da(Mr({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:f,manager:d}=this;if(!d)return;const{dragOperation:l}=d,{source:u}=l;c.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(c.value&&f){const d=new Hh(f,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),je(this,$r),je(this,xa,Ne(jt,8,this)),Ne(jt,11,this),je(this,wa,Ne(jt,12,this)),Ne(jt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Xe(this,$r,e,Xd)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,$r,Yd)}};jt=Nn(yo);xa=new WeakMap;$r=new WeakSet;wa=new WeakMap;xi=dt(jt,20,"#element",Kd,$r,xa),Yd=xi.get,Xd=xi.set;dt(jt,4,"proxy",qd,si,wa);nn(jt,si);function cg(e){return e!=null&&typeof e=="object"&&"current"in e}function $n(e){var t;if(e!=null)return cg(e)?(t=e.current)!=null?t:void 0:e}var dg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Gn=dg?k.useLayoutEffect:k.useEffect;function ug(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qd(e,t){const n=k.useRef(new Map),r=ug();return Gn(()=>{if(!e){n.current.clear();return}return ct(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[c]=a,f=te(()=>a[1]),d=e[c];f!==d&&(i=!0,n.current.set(c,d),o=(s=t?.(c,f,d))!=null?s:!1)}i&&(o?queueMicrotask(()=>Ju.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function fg(e,t){e()}function an(e){const t=k.useRef(e);return Gn(()=>{t.current=e},[e]),t}function Te(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function vs(e,t){const n=k.useRef($n(e));Gn(()=>{const r=$n(e);r!==n.current&&(n.current=r,t(r))})}var hg=Object.defineProperty,pg=Object.defineProperties,gg=Object.getOwnPropertyDescriptors,Ws=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,ll=(e,t,n)=>t in e?hg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mg=(e,t)=>{for(var n in t||(t={}))Zd.call(t,n)&&ll(e,n,t[n]);if(Ws)for(var n of Ws(t))Jd.call(t,n)&&ll(e,n,t[n]);return e},vg=(e,t)=>pg(e,gg(t)),yg=(e,t)=>{var n={};for(var r in e)Zd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ws)for(var r of Ws(e))t.indexOf(r)<0&&Jd.call(e,r)&&(n[r]=e[r]);return n},bg=new Vd,eu=k.createContext(bg),xg=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(c=>{i.current=c})),k.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Gn(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),wi=[void 0,ut];function wg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:c}=t,f=yg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:l,modifiers:u,sensors:h}=f,p=pt(l,Sn.plugins),y=pt(h,Sn.sensors),w=pt(u,Sn.modifiers),_=an(s),g=an(i),v=an(a),x=an(o),b=an(c),T=an(r),C=_g(()=>{var M;return(M=f.manager)!=null?M:new Vd(f)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:E}=d.current,{monitor:O}=C;C.renderer=M;const P=[O.addEventListener("beforedragstart",A=>{const L=_.current;L&&E(()=>L(A,C))}),O.addEventListener("dragstart",A=>{var L;return(L=g.current)==null?void 0:L.call(g,A,C)}),O.addEventListener("dragover",A=>{const L=v.current;L&&E(()=>L(A,C))}),O.addEventListener("dragmove",A=>{const L=x.current;L&&E(()=>L(A,C))}),O.addEventListener("dragend",A=>{const L=b.current;L&&E(()=>L(A,C))}),O.addEventListener("collision",A=>{var L;return(L=T.current)==null?void 0:L.call(T,A,C)})];return()=>P.forEach(A=>A())},[C]),Te(p,()=>C&&(C.plugins=p),...wi),Te(y,()=>C&&(C.sensors=y),...wi),Te(w,()=>C&&(C.modifiers=w),...wi),m.jsxs(eu.Provider,{value:C,children:[m.jsx(xg,{ref:d,children:n}),n]})}function _g(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function kg(){return k.useContext(eu)}function tu(e){var t;const n=(t=kg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Gn(r.register,[n,r]),r}var Sg=Object.create,nu=Object.defineProperty,$g=Object.getOwnPropertyDescriptor,ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ii=e=>{throw TypeError(e)},Tg=(e,t,n)=>t in e?nu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Eg=e=>{var t;return[,,,Sg((t=e?.[ru("metadata")])!=null?t:null)]},su=["class","method","getter","setter","accessor","field","value","get","set"],iu=e=>e!==void 0&&typeof e!="function"?ii("Function expected"):e,Cg=(e,t,n,r,s)=>({kind:su[e],name:t,metadata:r,addInitializer:i=>n._?ii("Already initialized"):s.push(iu(i||null))}),Og=(e,t)=>Tg(t,ru("metadata"),e[3]),Dg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ou=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=su[d+5],y=e[h]||(e[h]=[]),w=(s=s.prototype,$g(s,n)),_=r.length-1;_>=0;_--)c=Cg(d,n,a={},e[3],y),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(w[p],c),a._=1,iu(o)&&(w[p]=o);return w&&nu(s,n,w),s},au=(e,t,n)=>t.has(e)||ii("Cannot "+n),Mg=(e,t,n)=>(au(e,t,"read from private field"),t.get(e)),Ig=(e,t,n)=>t.has(e)?ii("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jg=(e,t,n,r)=>(au(e,t,"write to private field"),t.set(e,n),n),Kt=class bo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new bo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new bo(t,n)}},lu,cu,xo,ys,Vr,_a=class extends(xo=en,cu=[De],lu=[De],xo){constructor(e){const t=Kt.from(e);super(t,(n,r)=>Kt.equals(n,r)),Dg(Vr,5,this),Ig(this,ys,0),this.velocity={x:0,y:0}}get delta(){return Kt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=Kt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-Mg(this,ys),o=a=>Math.round(a/i*100);Ce(()=>{jg(this,ys,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Kt.from(e)),this.velocity={x:0,y:0}}};Vr=Eg(xo);ys=new WeakMap;ou(Vr,2,"delta",cu,_a);ou(Vr,2,"direction",lu,_a);Og(Vr,_a);var du=(e=>(e.Horizontal="x",e.Vertical="y",e))(du||{});Object.values(du);var Pg=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Kt.distance(t.shape.center,n);return{id:r,value:1/s,type:Fn.PointerIntersection,priority:Bn.High}}return null},Rg=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=Kt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Fn.ShapeIntersection,priority:Bn.Normal}}return null},Ag=e=>{var t;return(t=Pg(e))!=null?t:Rg(e)};function Lg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,c=tu(d=>new si(vg(mg({},e),{register:!1,element:$n(s)}),d)),f=Qd(c);return Te(i,()=>c.id=i),vs(s,d=>c.element=d),Te(o,()=>c.accept=o,void 0,ut),Te(t,()=>c.collisionDetector=t??Ag),Te(n,()=>n&&(c.data=n)),Te(r,()=>c.disabled=r===!0),Te(a,()=>c.type=a),{droppable:f,get isDropTarget(){return f.isDropTarget},ref:k.useCallback(d=>{var l,u;!d&&((l=c.element)!=null&&l.isConnected)&&!((u=c.manager)!=null&&u.dragOperation.status.idle)||(c.element=d??void 0)},[c])}}const uu=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},fu=k.createContext(void 0);function hu(e,t){const n=k.useContext(fu),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function wo({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=ke.usePublisherTheme(),[o,a]=k.useState(void 0),c=k.useRef(!1),f=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};hu(o!==void 0&&o!==e,()=>(f(),!0));const d=()=>{c.current=!1,a(e)};if(o===void 0){const l=e==="",u=l&&s;return m.jsx($.Box,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:d,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),d())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...l&&{fontStyle:"italic",opacity:u?0:.6}},uu(i)],children:l?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:l=>l.target.select(),onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!l.nativeEvent.isComposing?f():l.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:f,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Bg=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Fg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},pu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gu=e=>`gap.${e}`,zg=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),c=o===0||i.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:We(e[o-1]),colspan:t-r}),c&&(r=0),n.push(pu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:We(s),colspan:t-r}),n};var Wg=Object.create,mu=Object.defineProperty,Ng=Object.defineProperties,Gg=Object.getOwnPropertyDescriptor,Vg=Object.getOwnPropertyDescriptors,Ns=Object.getOwnPropertySymbols,vu=Object.prototype.hasOwnProperty,yu=Object.prototype.propertyIsEnumerable,Ug=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ur=e=>{throw TypeError(e)},_o=(e,t,n)=>t in e?mu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_i=(e,t)=>{for(var n in t||(t={}))vu.call(t,n)&&_o(e,n,t[n]);if(Ns)for(var n of Ns(t))yu.call(t,n)&&_o(e,n,t[n]);return e},ki=(e,t)=>Ng(e,Vg(t)),Hg=(e,t)=>{var n={};for(var r in e)vu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ns)for(var r of Ns(e))t.indexOf(r)<0&&yu.call(e,r)&&(n[r]=e[r]);return n},qg=e=>{var t;return[,,,Wg((t=void 0)!=null?t:null)]},bu=["class","method","getter","setter","accessor","field","value","get","set"],hr=e=>e!==void 0&&typeof e!="function"?Ur("Function expected"):e,Kg=(e,t,n,r,s)=>({kind:bu[e],name:t,metadata:r,addInitializer:i=>n._?Ur("Already initialized"):s.push(hr(i||null))}),Yg=(e,t)=>_o(t,Ug("metadata"),e[3]),ts=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},xu=(e,t,n,r,s,i)=>{for(var o,a,c,f,d,l=t&7,u=!1,h=!1,p=e.length+1,y=bu[l+5],w=e[p-1]=[],_=e[p]||(e[p]=[]),g=(s=s.prototype,Gg({get[n](){return pr(this,i)},set[n](x){return qt(this,i,x)}},n)),v=r.length-1;v>=0;v--)f=Kg(l,n,c={},e[3],_),f.static=u,f.private=h,d=f.access={has:x=>n in x},d.get=x=>x[n],d.set=(x,b)=>x[n]=b,a=(0,r[v])({get:g.get,set:g.set},f),c._=1,a===void 0?hr(a)&&(g[y]=a):typeof a!="object"||a===null?Ur("Object expected"):(hr(o=a.get)&&(g.get=o),hr(o=a.set)&&(g.set=o),hr(o=a.init)&&w.unshift(o));return g&&mu(s,n,g),s},wu=(e,t,n)=>t.has(e)||Ur("Cannot "+n),pr=(e,t,n)=>(wu(e,t,"read from private field"),t.get(e)),Jn=(e,t,n)=>t.has(e)?Ur("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qt=(e,t,n,r)=>(wu(e,t,"write to private field"),t.set(e,n),n);function Yt(e){return e instanceof $a||e instanceof $u}var ns=10,Xg=class extends qe{constructor(e){super(e);const t=ct(()=>{const{dragOperation:r}=e;if(Dr(r.activatorEvent)&&Yt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Gr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!Dr(r.nativeEvent)||!Yt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:c}=s,{by:f}=r;if(!f)return;const d=Qg(f),{source:l,target:u}=i,{center:h}=i.shape.current,p=[],y=[];Ce(()=>{for(const b of c.droppables){const{id:T}=b;if(!b.accepts(l)||T===u?.id&&Yt(b)||!b.element)continue;let C=b.shape;const M=new vt(b.element,{getBoundingClientRect:E=>Cr(E,void 0,.2)});!M.height||!M.width||(d=="down"&&h.y+ns<M.center.y||d=="up"&&h.y-ns>M.center.y||d=="left"&&h.x-ns>M.center.x||d=="right"&&h.x+ns<M.center.x)&&(p.push(b),b.shape=M,y.push(()=>b.shape=C))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(p,yp);Ce(()=>y.forEach(b=>b()));const[_]=w;if(!_)return;const{id:g}=_,{index:v,group:x}=l.sortable;o.setDropTarget(g).then(()=>{const{source:b,target:T,shape:C}=i;if(!b||!Yt(b)||!C)return;const{index:M,group:E,target:O}=b.sortable,P=v!==M||x!==E,A=P?O:T?.element;if(!A)return;vd(A);const L=new vt(A);if(!L)return;const W=yt.delta(L,yt.from(C.current.boundingRectangle),b.alignment);o.move({by:W}),P?o.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Qg(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var Zg=Object.defineProperty,Jg=Object.defineProperties,em=Object.getOwnPropertyDescriptors,cl=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,nm=Object.prototype.propertyIsEnumerable,dl=(e,t,n)=>t in e?Zg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ln=(e,t)=>{for(var n in t||(t={}))tm.call(t,n)&&dl(e,n,t[n]);if(cl)for(var n of cl(t))nm.call(t,n)&&dl(e,n,t[n]);return e},cn=(e,t)=>Jg(e,em(t));function rm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function rs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Si(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sm(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(v,x)=>v===x||v!==null&&typeof v=="object"&&"id"in v&&v.id===x;if(Array.isArray(e)){const v=e.findIndex(b=>c(b,i.id)),x=e.findIndex(b=>c(b,o.id));if(v===-1||x===-1){if(Si(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==v)return n(e,v,b)}return n(e,v,x)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[v,x]of f)if(d===-1&&(d=x.findIndex(b=>c(b,i.id)),d!==-1&&(l=v)),u===-1&&(u=x.findIndex(b=>c(b,o.id)),u!==-1&&(h=v)),d!==-1&&u!==-1)break;if(d===-1&&Si(i)){const v=i.initialGroup==null?void 0:rs(e,i.initialGroup),x=i.initialIndex,b=i.group==null?void 0:rs(e,i.group),T=i.index;if(v==null||b==null||v===b&&x===T)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return cn(ln({},e),{[v]:n(e[v],x,T)});const C=e[v][x];return cn(ln({},e),{[v]:[...e[v].slice(0,x),...e[v].slice(x+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,y=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const v=rs(e,o.id);if(v!=null){const x=o.shape&&y.y>o.shape.center.y?e[v].length:0;h=v,u=x}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Si(i)){const v=i.group==null?void 0:rs(e,i.group),x=i.group!=null&&v!==l,b=i.index!==d;if(x||b){const T=i.group==null?l:v;if(T!=null){if(l===T)return cn(ln({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return cn(ln({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return cn(ln({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(y.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return cn(ln({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function im(e,t){return sm(e,t,rm)}function ul(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function fl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var hl="__default__",om=class extends qe{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof $a){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Yt(o)||!Yt(a)||o.sortable===a.sortable)return;const c=t(),f=ul(c),d=o.sortable.group===a.sortable.group,l=c.get(o.sortable.group),u=d?l:c.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const y=t();if(fl(f,c,y))return;const w=o.sortable.element,_=a.sortable.element;if(!_||!w||!d&&a.id===o.sortable.group)return;const g=ss(l),v=d?g:ss(u),x=(h=o.sortable.group)!=null?h:hl,b=(p=a.sortable.group)!=null?p:hl,T={[x]:g,[b]:v},C=im(T,r);if(T===C)return;const M=C[b].indexOf(o.sortable),E=C[b].indexOf(a.sortable);s.collisionObserver.disable(),pl(w,M,_,E),Ce(()=>{for(const[O,P]of C[x].entries())P.index=O;if(!d)for(const[O,P]of C[b].entries())P.group=a.sortable.group,P.index=O}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Yt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=ul(a),f=a.get(o.sortable.initialGroup);f&&s.renderer.rendering.then(()=>{const d=t();if(fl(c,a,d))return;const l=ss(f),u=ss(f,lm),h=o.sortable.element,p=u.indexOf(o.sortable),y=l[p],w=y?.element;!y||!w||!h||(pl(h,y.index,w,o.index),Ce(()=>{for(const _ of a.values()){const g=Array.from(_).values();for(const v of g)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function pl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function am(e,t){return e.index-t.index}function lm(e,t){return e.initialIndex-t.initialIndex}function ss(e,t=am){return Array.from(e).sort(t)}var gl=[Xg,om],_u={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ml(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var is=new th,ku,Su,Pt,ka,gr,mr,Sa,yn;Su=[ne],ku=[ne];var oi=class{constructor(e,t){Jn(this,ka,ts(Pt,8,this)),ts(Pt,11,this),Jn(this,gr),Jn(this,mr),Jn(this,Sa,ts(Pt,12,this)),ts(Pt,15,this),Jn(this,yn),this.register=()=>(Ce(()=>{var p,y;(p=this.manager)==null||p.registry.register(this.droppable),(y=this.manager)==null||y.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var p,y;(p=this.manager)==null||p.registry.unregister(this.droppable),(y=this.manager)==null||y.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:c,transition:f=_u,plugins:d}=n,l=Hg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=pt(d,gl),h=ml(s);this.droppable=new $a(ki(_i({},l),{disabled:h.droppable}),t,this),this.draggable=new $u(ki(_i({},l),{disabled:h.draggable,plugins:u,effects:()=>[()=>{var p,y,w;const _=(p=this.manager)==null?void 0:p.dragOperation.status;_?.initializing&&this.id===((w=(y=this.manager)==null?void 0:y.dragOperation.source)==null?void 0:w.id)&&is.clear(this.manager),_?.dragging&&is.set(this.manager,this.id,te(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:y,manager:w}=this,_=pr(this,mr),g=pr(this,gr);(p!==_||y!==g)&&(qt(this,mr,p),qt(this,gr,y),this.animate())},()=>{var p,y;const{target:w}=this,{isDragSource:_}=this.draggable;((y=(p=this.draggable.pluginConfig(pa))==null?void 0:p.feedback)!=null?y:"default")==="move"&&_&&(this.droppable.disabled=!w)},...r()],type:c,sensors:a}),t,this),qt(this,yn,l.element),this.manager=t,this.index=o,qt(this,mr,o),this.group=i,qt(this,gr,i),this.type=c,this.transition=f}get initialIndex(){var e,t;return(t=(e=is.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=is.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){te(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const d of s.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=wt(s),c=Ja(s,a,!1),f=Ja(s,a);if(o.x||o.y){const d=oa(nt(s))?ki(_i({},t),{duration:0}):t;yd({element:s,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${f.x}px ${f.y}px ${f.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Ce(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ce(()=>{const t=pr(this,yn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),qt(this,yn,e)})}get element(){var e,t;const n=pr(this,yn);if(n)return(t=(e=to.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=pt(e,gl)}set disabled(e){const t=ml(e);Ce(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ce(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??bd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ce(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Pt=qg();ka=new WeakMap;gr=new WeakMap;mr=new WeakMap;Sa=new WeakMap;yn=new WeakMap;xu(Pt,4,"index",Su,oi,ka);xu(Pt,4,"group",ku,oi,Sa);Yg(Pt,oi);var $u=class extends ri{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},$a=class extends si{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,vl=Object.getOwnPropertySymbols,fm=Object.prototype.hasOwnProperty,hm=Object.prototype.propertyIsEnumerable,yl=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$i=(e,t)=>{for(var n in t||(t={}))fm.call(t,n)&&yl(e,n,t[n]);if(vl)for(var n of vl(t))hm.call(t,n)&&yl(e,n,t[n]);return e},pm=(e,t)=>dm(e,um(t));function gm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:c,group:f,disabled:d,modifiers:l,sensors:u,target:h,type:p,plugins:y}=e,w=$i($i({},_u),e.transition),_=tu(v=>new oi(pm($i({},e),{transition:w,register:!1,handle:$n(a),element:$n(o),target:$n(h)}),v)),g=Qd(_,mm);return Te(s,()=>_.id=s),Gn(()=>{Ce(()=>{_.group=f,_.index=c})},[_,f,c]),Te(p,()=>_.type=p),Te(t,()=>_.accept=t,void 0,ut),Te(i,()=>i&&(_.data=i)),Te(c,()=>{var v;(v=_.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&_.refreshShape()},fg),vs(a,v=>_.handle=v),vs(o,v=>_.element=v),vs(h,v=>_.target=v),Te(d,()=>_.disabled=d??!1,void 0,ut),Te(u,()=>_.sensors=u,void 0,ut),Te(n,()=>_.collisionDetector=n),Te(r,()=>_.collisionPriority=r),Te(y,()=>_.plugins=y,void 0,ut),Te(w,()=>_.transition=w,void 0,ut),Te(l,()=>_.modifiers=l,void 0,ut),Te(e.alignment,()=>_.alignment=e.alignment),{sortable:g,get isDragging(){return g.isDragging},get isDropping(){return g.isDropping},get isDragSource(){return g.isDragSource},get isDropTarget(){return g.isDropTarget},handleRef:k.useCallback(v=>{_.handle=v??void 0},[_]),ref:k.useCallback(v=>{var x,b;!v&&((x=_.element)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.element=v??void 0)},[_]),sourceRef:k.useCallback(v=>{var x,b;!v&&((x=_.source)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.source=v??void 0)},[_]),targetRef:k.useCallback(v=>{var x,b;!v&&((x=_.target)!=null&&x.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.target=v??void 0)},[_])}}function mm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const ko="tile",Tu="gap",vm=[mo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Eu}], ${ym}`)!==null||(mo.defaults.preventActivation?.(e,t)??!1)}),Gd],Eu="data-no-drag",ym=".malloy-render, .malloy-table",bm=e=>[...e,pa.configure({feedback:"clone"})];function xm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=gm({id:e,index:t,type:ko,accept:ko,collisionDetector:la,plugins:bm});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function wm({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Lg({id:e,type:Tu,accept:ko,collisionDetector:la,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cu=e=>e.ok===!1,Be=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Vn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,_e={sourceDefinition:e=>Be(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Be(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Be(e,"VIEW","subQueryDefList"),defDimension:e=>Be(e,"defList","DIMENSION"),exploreProperties:e=>Be(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Be(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Be(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Be(e,"WHERE","filterClauseList"),givenDef:e=>Be(e,"givenNameDef"),givenStatement:e=>Be(e,"GIVEN","givenDefList"),importStatement:e=>Be(e,"IMPORT","importURL"),vArrow:e=>Be(e,"ARROW","vExpr","segExpr"),segRefine:e=>Be(e,"PLUS","segExpr"),segOps:e=>Be(e,"queryProperties"),segField:e=>Be(e,"fieldPath")&&!Be(e,"segExpr"),segParen:e=>Be(e,"OPAREN","CPAREN","vExpr"),compare:e=>Be(e,"fieldExpr","compareOp"),givenRef:e=>Be(e,"GIVEN_REF")};function _m(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function km(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
- `&&t.push(n+1);return t}function Ou(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!Vn(s))continue;const i=Me(s,"docAnnotations");if(i)for(const o of Lt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class Du{constructor(t){this.text=t,this.map=_m(t),this.lineStarts=km(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!Vn(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function Hr(e,t,n=[]){Vn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Hr(e.getChild(r),t,n);return n}const Sm=e=>Be(e,"OCURLY","CCURLY");function Rr(e,t){const n=[],r=s=>{if(Vn(s)){if(t(s)){n.push(s);return}if(!Sm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Me=(e,t)=>e[t]?.call(e),Lt=(e,t)=>e[t]?.call(e)??[];function $m(e,t){if(!_e.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!_e.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Mu(e,t){const n=e.positioned(t);if(!n)return;const r=Me(t,"filterClauseList"),s=[];for(const i of r?Lt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=Hr(i,_e.givenRef).map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.replace(/^\$/,""));s.push({...o,givens:a,binding:$m(e,i)})}return{...n,clauses:s}}function So(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const f of Rr(t,_e.queryStatement)){const d=e.positioned(f);d&&r.push(d);const l=Me(f,"whereStatement");if(l&&_e.whereStatement(l)){const u=Mu(e,l);u&&s.push(u)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
- `),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:c,oneLine:a}}function Ta(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function Tm(e,t){const n=Me(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=_e.vArrow(t);if(_e.segOps(n)){const s=Me(n,"queryProperties"),i=s&&So(e,s);return i?{kind:"inline",stage:i,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(_e.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(_e.segRefine(n)){const s=Lt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;_e.segRefine(a);){const u=Lt(a,"segExpr");if(u.some(h=>_e.segOps(h)||_e.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&_e.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!_e.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const c=e.span(i);if(!c||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!_e.segOps(o)){const u=e.span(n);return u?{kind:"reference",from:e.text.slice(u.start,u.end),fromSpan:u}:{kind:"unsupported",why:"an unreadable refinement"}}const f=e.text.slice(c.start,c.end),d=Me(o,"queryProperties"),l=d&&So(e,d);return l?{kind:"reference",from:f,fromSpan:c,refinement:l}:{kind:"reference",from:f,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function Em(e,t){const n=[];for(const r of Rr(t,_e.defExploreQuery)){const s=e.span(r),i=Me(r,"subQueryDefList");if(!s||!i)continue;const o=Lt(i,"exploreQueryDef").filter(_e.exploreQueryDef),a=e.terminal(Me(r,"VIEW"));for(const c of o){const f=e.span(c),d=Me(c,"exploreQueryNameDef"),l=e.text_(d),u=Me(c,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:s,tags:Ta(e,s,a?.start??f.start),siblings:o.length,body:Tm(e,u)})}}return n}function Cm(e,t){const n=[];for(const r of Rr(t,_e.defDimension)){const s=e.span(r),i=Me(r,"defList");if(!s||!i)continue;const o=e.terminal(Me(r,"DIMENSION"));for(const a of Lt(i,"fieldDef")){const c=e.span(a),f=e.text_(Me(a,"fieldNameDef"))?.trim(),d=e.text_(Me(a,"fieldExpr"))?.trim();!c||!f||d===void 0||n.push({name:f,expression:d,span:c,line:e.line(c.start),statement:s,tags:Ta(e,s,o?.start??c.start)})}}return n}function Om(e,t){const n=[];for(const r of Hr(t,_e.sourceDefinition)){const s=e.span(r),i=e.text_(Me(r,"sourceNameDef")),o=Me(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),c=a?e.text.slice(a.start,a.end):"",f=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(c)?.[1]??"").trim(),d=Rr(o,_e.exploreProperties)[0],l=d&&So(e,d),u={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(d)for(const p of Rr(d,_e.whereStatement)){const y=Mu(e,p);y&&h.push(y)}n.push({name:i,base:f,span:s,line:e.line(s.start),statement:u,...l?{properties:l}:{},views:d?Em(e,d):[],dimensions:d?Cm(e,d):[],wheres:h})}return n}function Dm(e,t){const n=[];for(const r of Hr(t,_e.givenStatement)){const s=e.terminal(Me(r,"GIVEN")),i=Me(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Lt(i,"givenDef"):[]){const c=e.span(a),f=e.span(Me(a,"givenNameDef")),d=f&&e.text.slice(f.start,f.end);if(!c||!f||!d)continue;const l={start:f.start,end:c.end},u=e.line(l.start);n.push({name:d,declaration:e.text.slice(l.start,l.end),span:l,line:u,statement:{start:e.lineStarts[u],end:l.end},tags:Ta(e,c,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function Mm(e,t){const n=[];for(const r of Hr(t,_e.importStatement)){const s=e.span(r),i=e.text_(Me(r,"importURL"));if(!s||i===void 0)continue;const o=Me(r,"importSelect"),a=o?Lt(o,"importItem").map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Iu(e){let t;try{t=await Ea(e,"file://dashboard-builder.malloy")}catch(u){return{ok:!1,reason:`Malloy could not read this file: ${u}`}}const n=t.problems.filter(u=>u.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!Vn(s)||typeof s.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new Du(e),c=Im(a,i);a.commentLines=c.lines;const f=e.split(`
70
- `),d=u=>c.lines.has(u);a.proseLines=he.markdownLines(f,d),a.blocks=he.blockSpans(f,d).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=Om(a,s);return l.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Mm(a,s),sources:l,givens:Dm(a,s),textBlocks:Pm(a,i),modelNotes:Ou(a,s),trailingComment:u=>c.trailing.get(u),comments:c.all,commentLine:u=>c.lines.has(u),proseLine:u=>a.proseLines.has(u),commentIn:u=>c.all.find(h=>h.start>=u.start&&h.start<u.end),blockStart:u=>jm(a,c.lines,u)}}}async function Ea(e,t){const{MalloyTranslator:n}=await S.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Im(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const d of t.getTokens?.()??[]){const l=i?.getSymbolicName(d.type);if(l!=="COMMENT_TO_EOL"&&l!=="BLOCK_COMMENT")continue;const u=e.utf16(d.startIndex);let h=e.utf16(d.stopIndex+1);if(!(u===void 0||h===void 0||h<u)){for(;h>u&&(e.text[h-1]===`
71
- `||e.text[h-1]==="\r");)h--;s.push({start:u,end:h})}}const o=[...s].sort((d,l)=>d.start-l.start);let a="",c=0;for(const d of o)a+=e.text.slice(c,Math.max(c,d.start)),a+=e.text.slice(Math.max(c,d.start),Math.max(c,d.end)).replace(/[^\n\r]/g," "),c=Math.max(c,d.end);a+=e.text.slice(c);const f=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of s){const l=e.line(d.start),u=e.line(d.end-1);for(let y=l;y<=u;y++)f(y).trim()===""&&r.add(y);const h=a.slice(e.lineStarts[l],d.start).trim(),p=a.slice(d.end,e.lineStarts[u+1]??a.length).trim();h!==""&&p===""&&n.set(u,d)}return{trailing:n,lines:r,all:s}}function jm(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,c])=>c===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function Pm(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const c=he.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!c)continue;const f=[];let d=a+1;for(;s(n[d]??n[a])==="BLOCK_ANNOTATION_TEXT";d++)f.push(i(n[d]));const l=n[d];if(!l||s(l)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(l.stopIndex+1)??e.text.length,p=c.name===void 0&&c.rest?[`${c.rest}
72
- `]:[];o.push({...c.name===void 0?{}:{name:c.name},route:c.route,body:[...p,...f].join("").replace(/\r\n?/g,`
73
- `).replace(/\n$/,""),span:{start:e.lineStarts[u],end:h},line:u}),a=d}return o}function ju(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Pu(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=ju(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const i=/^tiles\s*=\s*\[/.exec(e.slice(r));if(i)return Rm(e,r+i[0].length-1)}}}function Rm(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),c=a.length-a.trimStart().length,f=a.trim();f!==""&&n.push({text:f,span:{start:s+c,end:s+c+f.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=ju(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return i(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(i(o),s=o+1)}}function Am(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function _g(e,t="hidden"){return ae(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=kg(n,r.registry.droppables),o=[],i=vp(n),{remove:a}=i;return Sg(s,i,o),$g(i,t),i.remove=()=>{o.forEach(l=>l()),a.call(i)},i})}function kg(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Xr}${gi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Sg(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),ui.set(a,i),n.push(()=>{ui.delete(a),r.proxy=void 0})}}function $g(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(qs,t)}function iu(e,t){return e===t?!0:jn(e)===jn(t)}function xl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&sn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>On(t))}function bi(e){return e.tagName==="TR"}function Tg(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-")||bg.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(Or(e)&&Or(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(xg.includes(c)||c.startsWith(Ye))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 Eg(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),On(n);return}if(i.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),On(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),On(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Cg(e){return new ResizeObserver(()=>{var t,n,r;const s=new kt(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=jd();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},Ye),(n=e.getElementMutationObserver())==null||n.takeRecords(),bi(e.element)&&bi(e.placeholder)){const v=Array.from(e.element.cells),_=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(x=>x.style.width));for(const[x,p]of v.entries()){const y=_[x];p.style.width=`${y.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,g=e.frameTransform;e.dragOperation.shape=new St(c*g.scaleX+g.x,d*g.scaleY+g.y,f*g.scaleX,h*g.scaleY)})}var Og=250,Mg="ease";function Dg(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=Og,easing:a=Mg}=o??{};On(e.feedbackElement);const[,l]=(t=Id(e.feedbackElement,p=>"translate"in p))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:iu(e.feedbackElement,u)?null:void 0},d=new kt(e.feedbackElement,c),f=(r=Ar(Et(e.feedbackElement).translate))!=null?r:e.translate,h=new kt(u,c),g=St.delta(d,h,e.alignment),v={x:f.x-g.x,y:f.y-g.y},_=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},Ye),e.feedbackElement.setAttribute(yi,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),qd({element:e.feedbackElement,keyframes:_a(Br(Br({},_),x),{translate:[`${f.x}px ${f.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:ya(dt(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?i:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(yi),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var au,xi,Fr,$a,ks,lu,cu,Bn=class extends(xi=Je,au=[le],xi){constructor(t,n){super(t,n),Fe(this,ks),Fe(this,$a,Ve(Fr,8,this)),Ve(Fr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(uo),s=r?.register(wg);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(on(this,ks,lu).bind(this,r)),this.registerEffect(on(this,ks,cu))}};Fr=Yn(xi);$a=new WeakMap;ks=new WeakSet;lu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Bs(t);if(n)return e.addRoot(n)};cu=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:g}=f,v=f.pluginConfig(Bn),_=(t=(e=v?.feedback)!=null?e:u?.feedback)!=null?t:"default",x=typeof _=="function"?_(f,l):_;if(!g||x==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,y=(n=this.overlay)!=null?n:g,w=An(y),b=An(g),E=!iu(g,y),T=new kt(g,{frameTransform:E?b:null,ignoreTransforms:!E}),C={x:b.scaleX/w.scaleX,y:b.scaleY/w.scaleY};let{width:M,height:O,top:P,left:L}=T;E&&(M=M/C.x,O=O/C.y);const A=new Yp(y),H=Et(g),{transition:z,translate:Y,boxSizing:I,paddingBlockStart:N,paddingBlockEnd:j,paddingInlineStart:R,paddingInlineEnd:W,borderInlineStartWidth:q,borderInlineEndWidth:V,borderBlockStartWidth:G,borderBlockEndWidth:K}=H,re=z.split(",").filter(ue=>!/^\s*(transform|translate|scale)\b/.test(ue)).join(","),se=co(H),oe=H.transform,ye=x==="clone",Pe=I==="content-box",be=Pe?parseInt(R)+parseInt(W)+parseInt(q)+parseInt(V):0,Ge=Pe?parseInt(N)+parseInt(j)+parseInt(G)+parseInt(K):0,Z=x!=="move"&&!this.overlay?_g(f,ye?"clone":"hidden"):null,Ke=ae(()=>Lr(l.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&se)p.translate={x:se.x,y:se.y};else if(Y!=="none"){const ue=Ar(Y);ue&&(p.translate=ue)}}if(!p.transformOrigin){const ue=ae(()=>d.current),Oe=L+((r=se?.x)!=null?r:0),it=P+((s=se?.y)!=null?s:0);p.transformOrigin={x:(ue.x-Oe*w.scaleX-w.x)/(M*w.scaleX),y:(ue.y-it*w.scaleY-w.y)/(O*w.scaleY)}}const{transformOrigin:_e}=p,fe=P*w.scaleY+w.y,Te=L*w.scaleX+w.x;if(!p.coordinates&&(p.coordinates={x:Te,y:fe},C.x!==1||C.y!==1)){const{scaleX:ue,scaleY:Oe}=b,{x:it,y:jt}=_e;p.coordinates.x+=(M*ue-M)*it,p.coordinates.y+=(O*Oe-O)*jt}p.dimensions||(p.dimensions={width:M,height:O}),p.frameTransform||(p.frameTransform=w);const je={x:p.coordinates.x-Te,y:p.coordinates.y-fe},ie={width:(p.dimensions.width*p.frameTransform.scaleX-M*w.scaleX)*_e.x,height:(p.dimensions.height*p.frameTransform.scaleY-O*w.scaleY)*_e.y},He={x:je.x/w.scaleX+ie.width,y:je.y/w.scaleY+ie.height},Xe={left:L+He.x,top:P+He.y};y.setAttribute(_t,"true");const D=ae(()=>c.transform),B=(o=p.translate)!=null?o:{x:0,y:0},U=D.x*w.scaleX+B.x,X=D.y*w.scaleY+B.y,ge=jd();A.set({width:M-be,height:O-Ge,top:Xe.top+ge.y,left:Xe.left+ge.x,translate:`${U}px ${X}px 0`,transform:this.overlay?"none":oe,transition:re?`${re}, translate 0ms linear`:"translate 0ms linear",scale:E?`${C.x} ${C.y}`:"","transform-origin":`${_e.x*100}% ${_e.y*100}%`},Ye),Z&&(g.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(g)),hi(y)&&(y.hasAttribute("popover")||y.setAttribute("popover","manual"),On(y),y.addEventListener("beforetoggle",xl));let Ce,We,F;const J=Cg({placeholder:Z,element:g,feedbackElement:y,frameTransform:w,transformOrigin:_e,width:M,height:O,top:P,left:L,widthOffset:be,heightOffset:Ge,delta:He,styles:A,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>Ce,getSavedCellWidths:()=>F,setSavedCellWidths:ue=>{F=ue}}),ze=new kt(y);ae(()=>c.shape=ze);const Q=dt(y),he=ue=>{this.manager.actions.stop({event:ue})},ee=ya(Q);Ke&&Q.addEventListener("resize",he),ae(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&(J.observe(Z),Ce=Tg(g,Z,ye),We=Eg(g,Z,y));const pe=(i=l.dragOperation.source)==null?void 0:i.id,qe=()=>{var ue;if(!Ke||pe==null)return;const Oe=l.registry.draggables.get(pe),it=(ue=Oe?.handle)!=null?ue:Oe?.element;Gt(it)&&it.focus()},Ct=()=>{Ce?.disconnect(),We?.disconnect(),J.disconnect(),Q.removeEventListener("resize",he),hi(y)&&(y.removeEventListener("beforetoggle",xl),y.removeAttribute("popover")),y.removeAttribute(_t),A.reset();const ue=()=>{var Oe;if(F&&bi(g)){const vo=Array.from(g.cells);for(const[ts,un]of vo.entries())un.style.width=(Oe=F[ts])!=null?Oe:""}f.status="idle";const it=a.current.translate!=null,jt=c.status.dragging;Z&&(!jt&&it||Z.parentElement!==y.parentElement)&&y.isConnected&&Z.replaceWith(y),Z?.remove()};y===this.overlay?setTimeout(ue,0):ue()},er=u?.dropAnimation,es=this,mo=Hr(()=>{var ue,Oe,it;const{transform:jt,status:vo}=c;if(!(!jt.x&&!jt.y&&!a.current.translate)&&vo.dragging){const ts=(ue=p.translate)!=null?ue:{x:0,y:0},un={x:jt.x/w.scaleX+ts.x,y:jt.y/w.scaleY+ts.y},qa=a.current.translate,Mf=ae(()=>c.modifiers),yo=ae(()=>{var nr;return(nr=c.shape)==null?void 0:nr.current}),tr=u?.keyboardTransition,Ua=Ke&&!ee&&tr!==null?`${(Oe=tr?.duration)!=null?Oe:250}ms ${(it=tr?.easing)!=null?it:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:re?`${re}, translate ${Ua}`:`translate ${Ua}`,translate:`${un.x}px ${un.y}px 0`},Ye),Ce?.takeRecords(),yo&&yo!==ze&&qa&&!Mf.length){const nr=ft.delta(un,qa);c.shape=St.from(yo.boundingRectangle).translate(nr.x*w.scaleX,nr.y*w.scaleY)}else c.shape=new kt(y);a.current.translate=un}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ue=v?.dropAnimation!==void 0?v.dropAnimation:es.dropAnimation!==void 0?es.dropAnimation:er;let Oe=a.current.translate;const it=Oe!=null;if(!Oe&&g!==y&&(Oe={x:0,y:0}),!Oe||ue===null){Ct();return}l.renderer.rendering.then(()=>{Dg({source:f,element:g,feedbackElement:y,placeholder:Z,translate:Oe,moved:it,transition:z,alignment:f.alignment,styles:A,animation:ue??void 0,getElementMutationObserver:()=>Ce,cleanup:Ct,restoreFocus:qe})})}});return()=>{Ct(),mo()}};mt(Fr,4,"overlay",au,Bn,$a);dn(Fr,Bn);Bn.configure=Ur(Bn);var Ta=Bn,rr=!0,Ig=!1,du,uu,fu,hu,Ft,Ea,Ca;hu=(fu=[le],ht.Forward),uu=(du=[le],ht.Reverse);var Wr=class{constructor(){Fe(this,Ea,Ve(Ft,8,this,rr)),Ve(Ft,11,this),Fe(this,Ca,Ve(Ft,12,this,rr)),Ve(Ft,15,this)}isLocked(e){return e===ht.Idle?!1:e==null?this[ht.Forward]===rr&&this[ht.Reverse]===rr:this[e]===rr}unlock(e){e!==ht.Idle&&(this[e]=Ig)}};Ft=Yn(null);Ea=new WeakMap;Ca=new WeakMap;mt(Ft,4,hu,fu,Wr,Ea);mt(Ft,4,uu,du,Wr,Ca);dn(Ft,Wr);var Rg=[ht.Forward,ht.Reverse],wl=class{constructor(){this.x=new Wr,this.y=new Wr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Pg=class extends Je{constructor(e){super(e);const t=Wn(new wl);let n=null;this.signal=t,gt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new wl;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:_l(s.x,n.x),y:_l(s.y,n.y)},i=t.peek();Ie(()=>{for(const a of Nc)for(const l of Rg)o[a]===l&&i[a].unlock(l);t.value=i})}n=s})}get current(){return this.signal.peek()}};function _l(e,t){return Math.sign(e-t)}var pu,wi,zr,Oa,Lt,_i,Yr=class extends(wi=Vr,pu=[le],wi){constructor(e){super(e),Fe(this,Oa,Ve(zr,8,this,!1)),Ve(zr,11,this),Fe(this,Lt),Fe(this,_i,()=>{if(!xe(this,Lt))return;const{element:o,by:i}=xe(this,Lt);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 nt(this,Lt,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=o??{},f=d?{x:kl(d.x),y:kl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const g of l){const v=Mp(g,d);if(v.x||v.y){const{speed:_,direction:x}=zp(g,c,f,i?.acceleration,i?.threshold);if(h)for(const p of Nc)h[p].isLocked(x[p])&&(_[p]=0,x[p]=0);if(x.x||x.y){const{x:p,y}=d??x,w=p*_.x,b=y*_.y;if(w||b){const E=(a=xe(this,Lt))==null?void 0:a.by;if(this.autoScrolling&&E&&(E.x&&!w||E.y&&!b))continue;return nt(this,Lt,{element:g,by:{x:w,y:b}}),zs.schedule(xe(this,_i)),!0}}}}}return nt(this,Lt,void 0),!1};let t=null,n=null;const r=Qo(()=>{const{position:o,source:i}=e.dragOperation;if(!o)return null;const a=Ad(Bs(i?.element),o.current);return a&&(t=a),a??t}),s=Qo(()=>{const o=r.value,{documentElement:i}=Kn(o);if(!o||o===i){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=pi(l,{excludeElement:!1});return n=u,u}}if(o){const a=pi(o,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},vt);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Pg(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Lr(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};zr=Yn(wi);Oa=new WeakMap;Lt=new WeakMap;_i=new WeakMap;mt(zr,4,"autoScrolling",pu,Yr,Oa);dn(zr,Yr);function kl(e){return e>0?ht.Forward:e<0?ht.Reverse:ht.Idle}var jg=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))}},Ag=new jg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Lg=10,ki=class extends Je{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Yr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=gt(()=>{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(()=>Ag.schedule(()=>r.scroll(void 0,u)),Lg);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};ki.configure=Ur(ki);var gu=ki,Sl={capture:!0,passive:!0},vr,Bg=class extends Vr{constructor(e){super(e),Fe(this,vr),this.handleScroll=()=>{xe(this,vr)==null&&nt(this,vr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),nt(this,vr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=gt(()=>{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,Sl),()=>{i.removeEventListener("scroll",this.handleScroll,Sl)}}})}};vr=new WeakMap;var Fg="* { user-select: none !important; -webkit-user-select: none !important; }",Wg=class extends Je{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(uo),n=t?.register(Fg);if(this.destroy=gt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Co(),document.addEventListener("selectionchange",Co,{capture:!0}),()=>{document.removeEventListener("selectionchange",Co,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Co(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var yr=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}}),_n,Us=class extends Rn{constructor(t,n){super(t),this.manager=t,this.options=n,Fe(this,_n,[]),this.listeners=new Ld,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!sn(r.target)||s.disabled)return;const{keyboardCodes:i=yr.keyboardCodes,preventActivation:a=yr.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 gt(()=>{var s;const o=(s=t.handle)!=null?s:t.element,i=a=>{Lr(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(),Hd(s);const{center:o}=new kt(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=Kn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];xe(this,_n).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=yr.keyboardCodes}=r??{};if(hn(t,[...s.end,...s.cancel])){t.preventDefault();const o=hn(t,s.cancel);this.handleEnd(t,o);return}hn(t,s.up)?this.handleMove("up",t):hn(t,s.down)&&this.handleMove("down",t),hn(t,s.left)?this.handleMove("left",t):hn(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:yr.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(gu);t?.disabled===!1&&(t.disable(),xe(this,_n).push(()=>{t.enable()}))}cleanup(){xe(this,_n).forEach(t=>t()),nt(this,_n,[])}destroy(){this.cleanup(),this.listeners.clear()}};_n=new WeakMap;Us.configure=Ur(Us);Us.defaults=yr;var mu=Us;function hn(e,t){return t.includes(e.code)}var Zt,zg=class extends xd{constructor(){super(...arguments),Fe(this,Zt)}onEvent(e){switch(e.type){case"pointerdown":nt(this,Zt,Pn(e));break;case"pointermove":if(!xe(this,Zt))return;const{x:t,y:n}=Pn(e),r={x:t-xe(this,Zt).x,y:n-xe(this,Zt).y},{tolerance:s}=this.options;if(s&&ii(r,s)){this.abort();return}ii(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){nt(this,Zt,void 0)}};Zt=new WeakMap;var kn,Jt,Ng=class extends xd{constructor(){super(...arguments),Fe(this,kn),Fe(this,Jt)}onEvent(e){switch(e.type){case"pointerdown":nt(this,Jt,Pn(e)),nt(this,kn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!xe(this,Jt))return;const{x:t,y:n}=Pn(e),r={x:t-xe(this,Jt).x,y:n-xe(this,Jt).y};ii(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){xe(this,kn)&&(clearTimeout(xe(this,kn)),nt(this,Jt,void 0),nt(this,kn,void 0))}};kn=new WeakMap;Jt=new WeakMap;var En=class{};En.Delay=Ng;En.Distance=zg;var Si=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&sn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new En.Delay({value:250,tolerance:5})]:Zp(s)&&!e.defaultPrevented?[new En.Delay({value:200,tolerance:0})]:[new En.Delay({value:200,tolerance:10}),new En.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!sn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=bp(r);return s===t.element?!1:!!s}}),Sn,Vs=class extends Rn{constructor(t,n){super(t),this.manager=t,this.options=n,Fe(this,Sn,new Set),this.listeners=new Ld,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=Si.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return gt(()=>{var s;const o=new AbortController,{signal:i}=o,a=u=>{Qp(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&&(qg(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:i}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!sn(t.target)||n.disabled||Gg(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Si.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,i=Gt(o)&&o.draggable&&o.getAttribute("draggable")==="true",a=An(n.element),{x:l,y:u}=Pn(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 dp(c,v=>this.handleStart(n,v));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const f=di(),h=this.listeners.bind(f,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:i?this.handleCancel:as,options:{capture:!0}}]),g=()=>{h(),this.initialCoordinates=void 0};xe(this,Sn).add(g)}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=Pn(t),i=An(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,zs.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=Kn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=sn(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:as,options:{passive:!1}},{type:"click",listener:as},{type:"contextmenu",listener:as},{type:"keydown",listener:this.handleKeyDown}]);xe(this,Sn).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,Sn).forEach(n=>n()),xe(this,Sn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Sn=new WeakMap;Vs.configure=Ur(Vs);Vs.defaults=Si;var $i=Vs;function Gg(e){return"sensor"in e}function as(e){e.preventDefault()}function Hg(){}var $l=new WeakSet;function qg(e){!e||$l.has(e)||(e.addEventListener("touchmove",Hg,{capture:!1,passive:!1}),$l.add(e))}var Mn={modifiers:[],plugins:[mg,gu,yg,Ta,Wg],sensors:[$i,mu]},vu=class extends hp{constructor(e={}){const t=xt(e.plugins,Mn.plugins),n=xt(e.sensors,Mn.sensors),r=xt(e.modifiers,Mn.modifiers);super(_a(Br({},e),{plugins:[Bg,Yr,uo,...t],sensors:n,modifiers:r}))}},yu,bu,Ti,Wt,Ma,Da,fo=class extends(Ti=$t,bu=[le],yu=[le],Ti){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o}=n,i=Yd(n,["element","effects","handle"]);super(Br({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(Rr))!=null?l:[...u.sensors]).map(f=>{const h=f instanceof Rn?f:u.registry.register(f.plugin),g=f instanceof Rn?void 0:f.options;return h.bind(this,g)});return function(){d.forEach(h=>h())}}]},i),t),Fe(this,Ma,Ve(Wt,8,this)),Ve(Wt,11,this),Fe(this,Da,Ve(Wt,12,this)),Ve(Wt,15,this),this.element=r,this.handle=o}};Wt=Yn(Ti);Ma=new WeakMap;Da=new WeakMap;mt(Wt,4,"handle",bu,fo,Ma);mt(Wt,4,"element",yu,fo,Da);dn(Wt,fo);var xu,wu,Ei,zt,Ia,Oo,_u,ku,Dr,Ra,ho=class extends(Ei=Tt,wu=[le],xu=[le],Ei){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=Yd(n,["element","effects"]);const{collisionDetector:i=Ud}=o,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const f=new kt(d),h=ae(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=Wn(!1);super(_a(Br({},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 Op(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),Fe(this,Dr),Fe(this,Ia,Ve(zt,8,this)),Ve(zt,11,this),Fe(this,Ra,Ve(zt,12,this)),Ve(zt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){nt(this,Dr,e,ku)}get element(){var e;return(e=this.proxy)!=null?e:xe(this,Dr,_u)}};zt=Yn(Ei);Ia=new WeakMap;Dr=new WeakSet;Ra=new WeakMap;Oo=mt(zt,20,"#element",wu,Dr,Ia),_u=Oo.get,ku=Oo.set;mt(zt,4,"proxy",xu,ho,Ra);dn(zt,ho);function Ug(e){return e!=null&&typeof e=="object"&&"current"in e}function Dn(e){var t;if(e!=null)return Ug(e)?(t=e.current)!=null?t:void 0:e}var Vg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Qn=Vg?S.useLayoutEffect:S.useEffect;function Kg(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Su(e,t){const n=S.useRef(new Map),r=Kg();return Qn(()=>{if(!e){n.current.clear();return}return gt(()=>{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(()=>Df.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 Xg(e,t){e()}function pn(e){const t=S.useRef(e);return Qn(()=>{t.current=e},[e]),t}function Me(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 Ss(e,t){const n=S.useRef(Dn(e));Qn(()=>{const r=Dn(e);r!==n.current&&(n.current=r,t(r))})}var Yg=Object.defineProperty,Qg=Object.defineProperties,Zg=Object.getOwnPropertyDescriptors,Ks=Object.getOwnPropertySymbols,$u=Object.prototype.hasOwnProperty,Tu=Object.prototype.propertyIsEnumerable,Tl=(e,t,n)=>t in e?Yg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jg=(e,t)=>{for(var n in t||(t={}))$u.call(t,n)&&Tl(e,n,t[n]);if(Ks)for(var n of Ks(t))Tu.call(t,n)&&Tl(e,n,t[n]);return e},em=(e,t)=>Qg(e,Zg(t)),tm=(e,t)=>{var n={};for(var r in e)$u.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ks)for(var r of Ks(e))t.indexOf(r)<0&&Tu.call(e,r)&&(n[r]=e[r]);return n},nm=new vu,Eu=S.createContext(nm),rm=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 Qn(()=>{var a;(a=o.current)==null||a.call(o),s.current=null},[e,n]),S.useImperativeHandle(t,()=>i),null})),Mo=[void 0,vt];function sm(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:i,onDragOver:a,onDragEnd:l}=t,u=tm(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,g=xt(d,Mn.plugins),v=xt(h,Mn.sensors),_=xt(f,Mn.modifiers),x=pn(s),p=pn(o),y=pn(a),w=pn(i),b=pn(l),E=pn(r),T=om(()=>{var C;return(C=u.manager)!=null?C:new vu(u)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:C,trackRendering:M}=c.current,{monitor:O}=T;T.renderer=C;const P=[O.addEventListener("beforedragstart",L=>{const A=x.current;A&&M(()=>A(L,T))}),O.addEventListener("dragstart",L=>{var A;return(A=p.current)==null?void 0:A.call(p,L,T)}),O.addEventListener("dragover",L=>{const A=y.current;A&&M(()=>A(L,T))}),O.addEventListener("dragmove",L=>{const A=w.current;A&&M(()=>A(L,T))}),O.addEventListener("dragend",L=>{const A=b.current;A&&M(()=>A(L,T))}),O.addEventListener("collision",L=>{var A;return(A=E.current)==null?void 0:A.call(E,L,T)})];return()=>P.forEach(L=>L())},[T]),Me(g,()=>T&&(T.plugins=g),...Mo),Me(v,()=>T&&(T.sensors=v),...Mo),Me(_,()=>T&&(T.modifiers=_),...Mo),m.jsxs(Eu.Provider,{value:T,children:[m.jsx(rm,{ref:c,children:n}),n]})}function om(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 im(){return S.useContext(Eu)}function Cu(e){var t;const n=(t=im())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Qn(r.register,[n,r]),r}var am=Object.create,Ou=Object.defineProperty,lm=Object.getOwnPropertyDescriptor,Mu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),po=e=>{throw TypeError(e)},cm=(e,t,n)=>t in e?Ou(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dm=e=>{var t;return[,,,am((t=e?.[Mu("metadata")])!=null?t:null)]},Du=["class","method","getter","setter","accessor","field","value","get","set"],Iu=e=>e!==void 0&&typeof e!="function"?po("Function expected"):e,um=(e,t,n,r,s)=>({kind:Du[e],name:t,metadata:r,addInitializer:o=>n._?po("Already initialized"):s.push(Iu(o||null))}),fm=(e,t)=>cm(t,Mu("metadata"),e[3]),hm=(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},Ru=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,g=Du[c+5],v=e[h]||(e[h]=[]),_=(s=s.prototype,lm(s,n)),x=r.length-1;x>=0;x--)l=um(c,n,a={},e[3],v),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(_[g],l),a._=1,Iu(i)&&(_[g]=i);return _&&Ou(s,n,_),s},Pu=(e,t,n)=>t.has(e)||po("Cannot "+n),pm=(e,t,n)=>(Pu(e,t,"read from private field"),t.get(e)),gm=(e,t,n)=>t.has(e)?po("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),mm=(e,t,n,r)=>(Pu(e,t,"write to private field"),t.set(e,n),n),tn=class Ci{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ci(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 Ci(t,n)}},ju,Au,Oi,$s,Qr,Pa=class extends(Oi=ln,Au=[Le],ju=[Le],Oi){constructor(e){const t=tn.from(e);super(t,(n,r)=>tn.equals(n,r)),hm(Qr,5,this),gm(this,$s,0),this.velocity={x:0,y:0}}get delta(){return tn.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=tn.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-pm(this,$s),i=a=>Math.round(a/o*100);Ie(()=>{mm(this,$s,s),this.velocity={x:i(r.x),y:i(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(tn.from(e)),this.velocity={x:0,y:0}}};Qr=dm(Oi);$s=new WeakMap;Ru(Qr,2,"delta",Au,Pa);Ru(Qr,2,"direction",ju,Pa);fm(Qr,Pa);var Lu=(e=>(e.Horizontal="x",e.Vertical="y",e))(Lu||{});Object.values(Lu);var vm=({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=tn.distance(t.shape.center,n);return{id:r,value:1/s,type:Vn.PointerIntersection,priority:Un.High}}return null},ym=({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=tn.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Vn.ShapeIntersection,priority:Un.Normal}}return null},bm=e=>{var t;return(t=vm(e))!=null?t:ym(e)};function xm(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:o,accept:i,type:a}=e,l=Cu(c=>new ho(em(Jg({},e),{register:!1,element:Dn(s)}),c)),u=Su(l);return Me(o,()=>l.id=o),Ss(s,c=>l.element=c),Me(i,()=>l.accept=i,void 0,vt),Me(t,()=>l.collisionDetector=t??bm),Me(n,()=>n&&(l.data=n)),Me(r,()=>l.disabled=r===!0),Me(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 Bu=(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}}},Fu=S.createContext(void 0);function Wu(e,t){const n=S.useContext(Fu),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 Mi({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:o}=we.usePublisherTheme(),[i,a]=S.useState(void 0),l=S.useRef(!1),u=()=>{l.current||i===void 0||(a(void 0),i!==e&&r(i))};Wu(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}},Bu(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 wm=(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}),_m=(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},zu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),Nu=e=>`gap.${e}`,km=(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:Se(e[i-1]),colspan:t-r}),l&&(r=0),n.push(zu(o,i)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Se(s),colspan:t-r}),n};var Sm=Object.create,Gu=Object.defineProperty,$m=Object.defineProperties,Tm=Object.getOwnPropertyDescriptor,Em=Object.getOwnPropertyDescriptors,Xs=Object.getOwnPropertySymbols,Hu=Object.prototype.hasOwnProperty,qu=Object.prototype.propertyIsEnumerable,Cm=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zr=e=>{throw TypeError(e)},Di=(e,t,n)=>t in e?Gu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Do=(e,t)=>{for(var n in t||(t={}))Hu.call(t,n)&&Di(e,n,t[n]);if(Xs)for(var n of Xs(t))qu.call(t,n)&&Di(e,n,t[n]);return e},Io=(e,t)=>$m(e,Em(t)),Om=(e,t)=>{var n={};for(var r in e)Hu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Xs)for(var r of Xs(e))t.indexOf(r)<0&&qu.call(e,r)&&(n[r]=e[r]);return n},Mm=e=>{var t;return[,,,Sm((t=void 0)!=null?t:null)]},Uu=["class","method","getter","setter","accessor","field","value","get","set"],br=e=>e!==void 0&&typeof e!="function"?Zr("Function expected"):e,Dm=(e,t,n,r,s)=>({kind:Uu[e],name:t,metadata:r,addInitializer:o=>n._?Zr("Already initialized"):s.push(br(o||null))}),Im=(e,t)=>Di(t,Cm("metadata"),e[3]),ls=(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},Vu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c,d=t&7,f=!1,h=!1,g=e.length+1,v=Uu[d+5],_=e[g-1]=[],x=e[g]||(e[g]=[]),p=(s=s.prototype,Tm({get[n](){return xr(this,o)},set[n](w){return en(this,o,w)}},n)),y=r.length-1;y>=0;y--)u=Dm(d,n,l={},e[3],x),u.static=f,u.private=h,c=u.access={has:w=>n in w},c.get=w=>w[n],c.set=(w,b)=>w[n]=b,a=(0,r[y])({get:p.get,set:p.set},u),l._=1,a===void 0?br(a)&&(p[v]=a):typeof a!="object"||a===null?Zr("Object expected"):(br(i=a.get)&&(p.get=i),br(i=a.set)&&(p.set=i),br(i=a.init)&&_.unshift(i));return p&&Gu(s,n,p),s},Ku=(e,t,n)=>t.has(e)||Zr("Cannot "+n),xr=(e,t,n)=>(Ku(e,t,"read from private field"),t.get(e)),sr=(e,t,n)=>t.has(e)?Zr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),en=(e,t,n,r)=>(Ku(e,t,"write to private field"),t.set(e,n),n);function nn(e){return e instanceof La||e instanceof Zu}var cs=10,Rm=class extends Je{constructor(e){super(e);const t=gt(()=>{const{dragOperation:r}=e;if(Lr(r.activatorEvent)&&nn(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Yr);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(!Lr(r.nativeEvent)||!nn(o.source)||!o.shape)return;const{actions:i,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const c=Pm(u),{source:d,target:f}=o,{center:h}=o.shape.current,g=[],v=[];Ie(()=>{for(const b of l.droppables){const{id:E}=b;if(!b.accepts(d)||E===f?.id&&nn(b)||!b.element)continue;let T=b.shape;const C=new kt(b.element,{getBoundingClientRect:M=>jr(M,void 0,.2)});!C.height||!C.width||(c=="down"&&h.y+cs<C.center.y||c=="up"&&h.y-cs>C.center.y||c=="left"&&h.x-cs>C.center.x||c=="right"&&h.x+cs<C.center.x)&&(g.push(b),b.shape=C,v.push(()=>b.shape=T))}}),r.preventDefault(),a.disable();const _=a.computeCollisions(g,tg);Ie(()=>v.forEach(b=>b()));const[x]=_;if(!x)return;const{id:p}=x,{index:y,group:w}=d.sortable;i.setDropTarget(p).then(()=>{const{source:b,target:E,shape:T}=o;if(!b||!nn(b)||!T)return;const{index:C,group:M,target:O}=b.sortable,P=y!==C||w!==M,L=P?O:E?.element;if(!L)return;Hd(L);const A=new kt(L);if(!A)return;const H=St.delta(A,St.from(T.current.boundingRectangle),b.alignment);i.move({by:H}),P?i.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Pm(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 jm=Object.defineProperty,Am=Object.defineProperties,Lm=Object.getOwnPropertyDescriptors,El=Object.getOwnPropertySymbols,Bm=Object.prototype.hasOwnProperty,Fm=Object.prototype.propertyIsEnumerable,Cl=(e,t,n)=>t in e?jm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gn=(e,t)=>{for(var n in t||(t={}))Bm.call(t,n)&&Cl(e,n,t[n]);if(El)for(var n of El(t))Fm.call(t,n)&&Cl(e,n,t[n]);return e},mn=(e,t)=>Am(e,Lm(t));function Wm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ds(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Ro(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function zm(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=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>l(b,o.id)),w=e.findIndex(b=>l(b,i.id));if(y===-1||w===-1){if(Ro(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!==y)return n(e,y,b)}return n(e,y,w)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[y,w]of u)if(c===-1&&(c=w.findIndex(b=>l(b,o.id)),c!==-1&&(d=y)),f===-1&&(f=w.findIndex(b=>l(b,i.id)),f!==-1&&(h=y)),c!==-1&&f!==-1)break;if(c===-1&&Ro(o)){const y=o.initialGroup==null?void 0:ds(e,o.initialGroup),w=o.initialIndex,b=o.group==null?void 0:ds(e,o.group),E=o.index;if(y==null||b==null||y===b&&w===E)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return mn(gn({},e),{[y]:n(e[y],w,E)});const T=e[y][w];return mn(gn({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:g}=o.manager,v=(s=(r=g.shape)==null?void 0:r.current.center)!=null?s:g.position.current;if(h==null){const y=ds(e,i.id);if(y!=null){const w=i.shape&&v.y>i.shape.center.y?e[y].length:0;h=y,f=w}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&Ro(o)){const y=o.group==null?void 0:ds(e,o.group),w=o.group!=null&&y!==d,b=o.index!==c;if(w||b){const E=o.group==null?d:y;if(E!=null){if(d===E)return mn(gn({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return mn(gn({},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 mn(gn({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(v.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return mn(gn({},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 Nm(e,t){return zm(e,t,Wm)}function Ol(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Ml(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__",Gm=class extends Je{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof La){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(!nn(i)||!nn(a)||i.sortable===a.sortable)return;const l=t(),u=Ol(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,g;const v=t();if(Ml(u,l,v))return;const _=i.sortable.element,x=a.sortable.element;if(!x||!_||!c&&a.id===i.sortable.group)return;const p=us(d),y=c?p:us(f),w=(h=i.sortable.group)!=null?h:Dl,b=(g=a.sortable.group)!=null?g:Dl,E={[w]:p,[b]:y},T=Nm(E,r);if(E===T)return;const C=T[b].indexOf(i.sortable),M=T[b].indexOf(a.sortable);s.collisionObserver.disable(),Il(_,C,x,M),Ie(()=>{for(const[O,P]of T[w].entries())P.index=O;if(!c)for(const[O,P]of T[b].entries())P.group=a.sortable.group,P.index=O}),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;nn(i)&&(i.sortable.initialIndex===i.sortable.index&&i.sortable.initialGroup===i.sortable.group||queueMicrotask(()=>{const a=t(),l=Ol(a),u=a.get(i.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const c=t();if(Ml(l,a,c))return;const d=us(u),f=us(u,qm),h=i.sortable.element,g=f.indexOf(i.sortable),v=d[g],_=v?.element;!v||!_||!h||(Il(h,v.index,_,i.index),Ie(()=>{for(const x of a.values()){const p=Array.from(x).values();for(const y of p)y.index=y.initialIndex,y.group=y.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Il(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Hm(e,t){return e.index-t.index}function qm(e,t){return e.initialIndex-t.initialIndex}function us(e,t=Hm){return Array.from(e).sort(t)}var Rl=[Rm,Gm],Xu={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Pl(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 fs=new Bh,Yu,Qu,Nt,ja,wr,_r,Aa,$n;Qu=[le],Yu=[le];var go=class{constructor(e,t){sr(this,ja,ls(Nt,8,this)),ls(Nt,11,this),sr(this,wr),sr(this,_r),sr(this,Aa,ls(Nt,12,this)),ls(Nt,15,this),sr(this,$n),this.register=()=>(Ie(()=>{var g,v;(g=this.manager)==null||g.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ie(()=>{var g,v;(g=this.manager)==null||g.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Ie(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:o,index:i,sensors:a,type:l,transition:u=Xu,plugins:c}=n,d=Om(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=xt(c,Rl),h=Pl(s);this.droppable=new La(Io(Do({},d),{disabled:h.droppable}),t,this),this.draggable=new Zu(Io(Do({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var g,v,_;const x=(g=this.manager)==null?void 0:g.dragOperation.status;x?.initializing&&this.id===((_=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:_.id)&&fs.clear(this.manager),x?.dragging&&fs.set(this.manager,this.id,ae(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:v,manager:_}=this,x=xr(this,_r),p=xr(this,wr);(g!==x||v!==p)&&(en(this,_r,g),en(this,wr,v),this.animate())},()=>{var g,v;const{target:_}=this,{isDragSource:x}=this.draggable;((v=(g=this.draggable.pluginConfig(Ta))==null?void 0:g.feedback)!=null?v:"default")==="move"&&x&&(this.droppable.disabled=!_)},...r()],type:l,sensors:a}),t,this),en(this,$n,d.element),this.manager=t,this.index=i,en(this,_r,i),this.group=o,en(this,wr,o),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=fs.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=fs.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}=Et(s),l=vl(s,a,!1),u=vl(s,a);if(i.x||i.y){const c=ya(dt(s))?Io(Do({},t),{duration:0}):t;qd({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){Ie(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ie(()=>{const t=xr(this,$n),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),en(this,$n,e)})}get element(){var e,t;const n=xr(this,$n);if(n)return(t=(e=ui.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=xt(e,Rl)}set disabled(e){const t=Pl(e);Ie(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ie(()=>{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??Ud}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ie(()=>{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)}};Nt=Mm();ja=new WeakMap;wr=new WeakMap;_r=new WeakMap;Aa=new WeakMap;$n=new WeakMap;Vu(Nt,4,"index",Qu,go,ja);Vu(Nt,4,"group",Yu,go,Aa);Im(Nt,go);var Zu=class extends fo{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}},La=class extends ho{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Um=Object.defineProperty,Vm=Object.defineProperties,Km=Object.getOwnPropertyDescriptors,jl=Object.getOwnPropertySymbols,Xm=Object.prototype.hasOwnProperty,Ym=Object.prototype.propertyIsEnumerable,Al=(e,t,n)=>t in e?Um(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Po=(e,t)=>{for(var n in t||(t={}))Xm.call(t,n)&&Al(e,n,t[n]);if(jl)for(var n of jl(t))Ym.call(t,n)&&Al(e,n,t[n]);return e},Qm=(e,t)=>Vm(e,Km(t));function Zm(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:g,plugins:v}=e,_=Po(Po({},Xu),e.transition),x=Cu(y=>new go(Qm(Po({},e),{transition:_,register:!1,handle:Dn(a),element:Dn(i),target:Dn(h)}),y)),p=Su(x,Jm);return Me(s,()=>x.id=s),Qn(()=>{Ie(()=>{x.group=u,x.index=l})},[x,u,l]),Me(g,()=>x.type=g),Me(t,()=>x.accept=t,void 0,vt),Me(o,()=>o&&(x.data=o)),Me(l,()=>{var y;(y=x.manager)!=null&&y.dragOperation.status.idle&&_?.idle&&x.refreshShape()},Xg),Ss(a,y=>x.handle=y),Ss(i,y=>x.element=y),Ss(h,y=>x.target=y),Me(c,()=>x.disabled=c??!1,void 0,vt),Me(f,()=>x.sensors=f,void 0,vt),Me(n,()=>x.collisionDetector=n),Me(r,()=>x.collisionPriority=r),Me(v,()=>x.plugins=v,void 0,vt),Me(_,()=>x.transition=_,void 0,vt),Me(d,()=>x.modifiers=d,void 0,vt),Me(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(y=>{x.handle=y??void 0},[x]),ref:S.useCallback(y=>{var w,b;!y&&((w=x.element)!=null&&w.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.element=y??void 0)},[x]),sourceRef:S.useCallback(y=>{var w,b;!y&&((w=x.source)!=null&&w.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.source=y??void 0)},[x]),targetRef:S.useCallback(y=>{var w,b;!y&&((w=x.target)!=null&&w.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.target=y??void 0)},[x])}}function Jm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ii="tile",Ju="gap",ev=[$i.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Ba}], ${tv}`)!==null||($i.defaults.preventActivation?.(e,t)??!1)}),mu],Ba="data-no-drag",tv=".malloy-render, .malloy-table",nv=e=>[...e,Ta.configure({feedback:"clone"})];function rv({id:e,index:t,disabled:n=!1,children:r}){const{ref:s,handleRef:o,isDragSource:i}=Zm({id:e,index:t,disabled:n,type:Ii,accept:Ii,collisionDetector:xa,plugins:nv});return m.jsx(m.Fragment,{children:r({ref:s,handleRef:o,isDragSource:i})})}function sv({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=xm({id:e,type:Ju,accept:Ii,collisionDetector:xa,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const ef=e=>e.ok===!1,Ne=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Zn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Ee={sourceDefinition:e=>Ne(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Ne(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Ne(e,"VIEW","subQueryDefList"),defDimension:e=>Ne(e,"defList","DIMENSION"),exploreProperties:e=>Ne(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Ne(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Ne(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Ne(e,"WHERE","filterClauseList"),givenDef:e=>Ne(e,"givenNameDef"),givenStatement:e=>Ne(e,"GIVEN","givenDefList"),importStatement:e=>Ne(e,"IMPORT","importURL"),vArrow:e=>Ne(e,"ARROW","vExpr","segExpr"),segRefine:e=>Ne(e,"PLUS","segExpr"),segOps:e=>Ne(e,"queryProperties"),segField:e=>Ne(e,"fieldPath")&&!Ne(e,"segExpr"),segParen:e=>Ne(e,"OPAREN","CPAREN","vExpr"),compare:e=>Ne(e,"fieldExpr","compareOp"),givenRef:e=>Ne(e,"GIVEN_REF")};function ov(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 iv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}function tf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!Zn(s))continue;const o=Be(s,"docAnnotations");if(o)for(const i of qt(o,"docAnnotation")){const a=e.text_(i);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class nf{constructor(t){this.text=t,this.map=ov(t),this.lineStarts=iv(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!Zn(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 Jr(e,t,n=[]){Zn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Jr(e.getChild(r),t,n);return n}const av=e=>Ne(e,"OCURLY","CCURLY");function Nr(e,t){const n=[],r=s=>{if(Zn(s)){if(t(s)){n.push(s);return}if(!av(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 Be=(e,t)=>e[t]?.call(e),qt=(e,t)=>e[t]?.call(e)??[];function lv(e,t){if(!Ee.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Ee.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 rf(e,t){const n=e.positioned(t);if(!n)return;const r=Be(t,"filterClauseList"),s=[];for(const o of r?qt(r,"fieldExpr"):[]){const i=e.positioned(o);if(!i)continue;const a=Jr(o,Ee.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...i,givens:a,binding:lv(e,o)})}return{...n,clauses:s}}function Ri(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const u of Nr(t,Ee.queryStatement)){const c=e.positioned(u);c&&r.push(c);const d=Be(u,"whereStatement");if(d&&Ee.whereStatement(d)){const f=rf(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
+ `),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 Fa(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 cv(e,t){const n=Be(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Ee.vArrow(t);if(Ee.segOps(n)){const s=Be(n,"queryProperties"),o=s&&Ri(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(Ee.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(Ee.segRefine(n)){const s=qt(n,"segExpr"),o=s[0],i=s[s.length-1];let a=o;for(;Ee.segRefine(a);){const f=qt(a,"segExpr");if(f.some(h=>Ee.segOps(h)||Ee.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&Ee.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Ee.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(!Ee.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=Be(i,"queryProperties"),d=c&&Ri(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 dv(e,t){const n=[];for(const r of Nr(t,Ee.defExploreQuery)){const s=e.span(r),o=Be(r,"subQueryDefList");if(!s||!o)continue;const i=qt(o,"exploreQueryDef").filter(Ee.exploreQueryDef),a=e.terminal(Be(r,"VIEW"));for(const l of i){const u=e.span(l),c=Be(l,"exploreQueryNameDef"),d=e.text_(c),f=Be(l,"vExpr");!u||!d||!f||n.push({name:d,span:u,line:e.line(u.start),statement:s,tags:Fa(e,s,a?.start??u.start),siblings:i.length,body:cv(e,f)})}}return n}function uv(e,t){const n=[];for(const r of Nr(t,Ee.defDimension)){const s=e.span(r),o=Be(r,"defList");if(!s||!o)continue;const i=e.terminal(Be(r,"DIMENSION"));for(const a of qt(o,"fieldDef")){const l=e.span(a),u=e.text_(Be(a,"fieldNameDef"))?.trim(),c=e.text_(Be(a,"fieldExpr"))?.trim();!l||!u||c===void 0||n.push({name:u,expression:c,span:l,line:e.line(l.start),statement:s,tags:Fa(e,s,i?.start??l.start)})}}return n}function fv(e,t){const n=[];for(const r of Jr(t,Ee.sourceDefinition)){const s=e.span(r),o=e.text_(Be(r,"sourceNameDef")),i=Be(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=Nr(i,Ee.exploreProperties)[0],d=c&&Ri(e,c),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(c)for(const g of Nr(c,Ee.whereStatement)){const v=rf(e,g);v&&h.push(v)}n.push({name:o,base:u,span:s,line:e.line(s.start),statement:f,...d?{properties:d}:{},views:c?dv(e,c):[],dimensions:c?uv(e,c):[],wheres:h})}return n}function hv(e,t){const n=[];for(const r of Jr(t,Ee.givenStatement)){const s=e.terminal(Be(r,"GIVEN")),o=Be(r,"givenDefList"),i=s?e.line(s.start):void 0;for(const a of o?qt(o,"givenDef"):[]){const l=e.span(a),u=e.span(Be(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:Fa(e,l,d.start),...i!==void 0&&i!==f?{blockHeader:i}:{}})}}return n}function pv(e,t){const n=[];for(const r of Jr(t,Ee.importStatement)){const s=e.span(r),o=e.text_(Be(r,"importURL"));if(!s||o===void 0)continue;const i=Be(r,"importSelect"),a=i?qt(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 sf(e){let t;try{t=await Wa(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||!Zn(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 nf(e),l=gv(a,o);a.commentLines=l.lines;const u=e.split(`
70
+ `),c=f=>l.lines.has(f);a.proseLines=ve.markdownLines(u,c),a.blocks=ve.blockSpans(u,c).filter(([f])=>!u[f].trimStart().startsWith("##"));const d=fv(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:pv(a,s),sources:d,givens:hv(a,s),textBlocks:vv(a,o),modelNotes:tf(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=>mv(a,l.lines,f)}}}async function Wa(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 gv(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]===`
71
+ `||e.text[h-1]==="\r");)h--;s.push({start:f,end:h})}}const i=[...s].sort((c,d)=>c.start-d.start);let a="",l=0;for(const c of i)a+=e.text.slice(l,Math.max(l,c.start)),a+=e.text.slice(Math.max(l,c.start),Math.max(l,c.end)).replace(/[^\n\r]/g," "),l=Math.max(l,c.end);a+=e.text.slice(l);const u=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of s){const d=e.line(c.start),f=e.line(c.end-1);for(let v=d;v<=f;v++)u(v).trim()===""&&r.add(v);const h=a.slice(e.lineStarts[d],c.start).trim(),g=a.slice(c.end,e.lineStarts[f+1]??a.length).trim();h!==""&&g===""&&n.set(f,c)}return{trailing:n,lines:r,all:s}}function mv(e,t,n){const r=o=>e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();let s=n;for(let o=n-1;o>=0;o--){const i=r(o),a=e.blocks.find(([,l])=>l===o);if(a){s=o=a[0];continue}if(i===""&&!t.has(o))break;if(i.startsWith("#")||t.has(o))s=o;else break}return s}function vv(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),o=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),i=[];for(let a=0;a<n.length;a++){if(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=ve.textBlockOpener(o(n[a]).replace(/\r?\n$/,""));if(!l)continue;const u=[];let c=a+1;for(;s(n[c]??n[a])==="BLOCK_ANNOTATION_TEXT";c++)u.push(o(n[c]));const d=n[c];if(!d||s(d)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(d.stopIndex+1)??e.text.length,g=l.name===void 0&&l.rest?[`${l.rest}
72
+ `]:[];i.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...g,...u].join("").replace(/\r\n?/g,`
73
+ `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=c}return i}function of(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 af(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=of(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 yv(e,r+o[0].length-1)}}}function yv(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=of(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 bv(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
- `,r),i=s===-1?e.length:s;if(e.slice(r,i).trim()===">>>")return i;if(s===-1)return e.length;r=s+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let s=t+3;s<e.length;s++)if(e[s]==="\\")s++;else if(e.startsWith(r,s))return s+3;return e.length}for(let s=t+1;s<e.length;s++)if(e[s]==="\\")s++;else{if(e[s]===n)return s+1;if(e[s]===`
76
- `)return s}return e.length}return t}function Lm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Am(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const i=e[r];if(/[=[,]/.test(i)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${i}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=i,r+=1}return n}function Ru(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(i=>{if(e([i]).log.length===0)return i;const o=Lm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const bl=(e,t)=>{try{return e.text(t)}catch{return}},Bm=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Fm=e=>`\`kind=${e}\` is no longer read, so this file is not a report. Fix: remove \`kind=${e}\` and write \`layout=grid\` or \`layout=linear\`.`,zm=e=>`\`layout=${e}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`,Wm="A linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";function Au(e,t){const n=e.filter(Bm).filter(d=>!d.includes("@env.")).map(he.tagAnnotation),{tag:r,errors:s}=n.length>0?Ru(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(he.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=bl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=bl(i,"layout"),c=i.has("tiles");if(c&&i.array("tiles")===void 0)return{status:"unparsed",errors:s};const f=a==="grid"||a==="linear"?a:c||r?.tag("dashboard")!==void 0?"grid":"linear";return f==="linear"&&!c?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:f}}async function Nm(e){const{parseAnnotation:t}=await S.loadMalloyTag();let n=[];try{const r=(await Ea(e,"file://report.malloy")).parse?.root;r&&Vn(r)&&typeof r.getChild=="function"&&(n=Ou(new Du(e),r))}catch{n=[]}return Au(n,t)}const Gs=e=>e.ok===!1;function qr(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Vs=e=>e.map(t=>t.text);function xl(e){const t=Vs(e),n=S.chartStateOfTagLines(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:S.chartLinesOf(t)}:{chart:n}}function Gm(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:he.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Vm(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Um(n(Vs(qr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Um(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 Ti(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 Hm=/^"((?:[^"\\]|\\.)+)"$/,qm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Us(e,t,n=!1){try{return await Km(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 Km(e){const{parseAnnotation:t}=await S.loadMalloyTag(),n=he.splitSourceLines(e),r=await Iu(e);if(Cu(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=he.descriptionNotes(n).text,o=Au(s.modelNotes,t);if(o.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(o.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${o.errors[0]?`: ${o.errors[0]}`:"."}`};if(o.status==="kind-removed")return{ok:!1,reason:Fm(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?zm(o.unknownLayout):Wm};const a=o.layout,c=he.artifactTag(n);if(c===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!he.artifactLeads(c.text))return{ok:!1,reason:he.ARTIFACT_NOT_FIRST,line:c.from+1};const{tag:f,errors:d}=Ru(t,[he.tagAnnotation(c.text)]),l=f?.tag("artifact"),u=Pu(c.text);if(u===void 0)return d.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${d[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),p=[],y=[],w=new Map;for(const T of s.sources){const C={name:T.name,base:T.base};T.dimensions.length>0&&(C.dimensions=T.dimensions.map(E=>({name:E.name,expression:E.expression})));const M=new Set(T.wheres.flatMap(E=>E.clauses.flatMap(O=>O.givens)));M.size>0&&(C.scopedBy=Array.from(M)),p.push(C);for(const E of T.dimensions){const O=t(Vs(qr(s,n,E.line).tags)).tag?.tag("drill");if(!O)continue;const P=O.textArray("to")??[O.text("to")??""];y.push({source:T.name,name:E.name,expression:E.expression,to:P.filter(Boolean),...O.text("given")?{given:O.text("given")}:{}})}w.set(T.name,new Map(T.views.map(E=>[E.name,E])))}const _=[];for(const{text:T}of u.entries){const C=Hm.exec(T),M=C?void 0:qm.exec(T)?.[1];if(M!==void 0){const I=t([`# ${T}`]).tag?.tag(M);if(I?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${M} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(_.some(V=>Ie(V)&&V.name===M))return{ok:!1,reason:`Two text tiles are named \`${M}\`, so the builder cannot tell them apart.`};const z=Ti(I,"colspan");_.push({kind:"text",name:M,markdown:s.textBlocks.find(V=>V.name===M)?.body??"",...z===void 0?{}:{colspan:z},...I.has("break")?{break:!0}:{}});continue}const E=C?.[1]??T,O=C?he.tileSteps(E):void 0;if(!O)return{ok:!1,reason:`The tile \`${E}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:P,view:A}=O,L=w.get(P)?.get(A);if(L===void 0){_.push({name:A,source:P,declaration:{kind:"inherited"}});continue}const W=t(Vs(L.tags)).tag,U=L.body.kind==="reference"?{kind:"reference",from:L.body.from}:L.body.kind==="inline"?{kind:"inline"}:void 0;if(U===void 0){_.push({name:A,source:P,declaration:{kind:"opaque",why:L.body.kind==="unsupported"?L.body.why:"unreadable"},...W?.text("label")?{label:W.text("label")}:{},...W?.text("subtitle")?{subtitle:W.text("subtitle")}:{},...W?.numeric("colspan")!==void 0?{colspan:W.numeric("colspan")}:{},...xl(L.tags),...W?.has("break")?{break:!0}:{},...W?.has("borderless")?{borderless:!0}:{}});continue}const N=Gm(L.body.kind==="reference"?L.body.refinement:L.body.kind==="inline"?L.body.stage:void 0);_.push({name:A,source:P,declaration:U,...N?{filters:N}:{},...W?.text("label")?{label:W.text("label")}:{},...W?.text("subtitle")?{subtitle:W.text("subtitle")}:{},...W?.numeric("colspan")!==void 0?{colspan:W.numeric("colspan")}:{},...xl(L.tags),...W?.has("break")?{break:!0}:{},...W?.has("borderless")?{borderless:!0}:{}})}const g=Vm(s,n,t),v={},x=l?.tag("givens");for(const T of Object.keys(x?.dict??{})){const C=x?.text(T);C!==void 0&&(v[T]=C)}const b=f?.tag("dashboard")?.has("columns")?Ti(f.tag("dashboard"),"columns"):l?.array("tiles")?Ti(l,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:l?.text("title")??"",...i?{description:i}:{},...b===void 0?{}:{columns:b},...l?.has("autorun")?{autorun:l.isTrue("autorun")}:{},imports:h,sources:p,...g?{localGivens:g}:{},...Object.keys(v).length>0?{startingGivens:v}:{},...y.length>0?{drills:y}:{},tiles:_}}}const Hs=e=>e.ok===!1;async function wl(e){const{problems:t}=await Ea(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function be(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Lu(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Ym(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
- `&&t.push(n+1);return t}function Xm(e,t){let n=e;const r=t.map((s,i)=>({edit:s,index:i}));for(const{edit:s}of r.sort((i,o)=>o.edit.start-i.edit.start||o.edit.end-i.edit.end||o.index-i.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const Bu=e=>e==="none"||S.isChartPick(e)?e:void 0;function Fu(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${ht(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${ht(e.subtitle)}`);const r=t?Bu(e.chart):void 0;return r!==void 0&&n.push(S.chartLineText(r,e.chartCarried)),n}function bs(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Qm=new Set(["colspan","break","borderless","label","subtitle"]),Zm=new Set(["label","description","control","suggest","range_min","range_max"]);function _l(e){const t=[];if(e.label!==void 0&&t.push(`label=${ht(e.label)}`),e.description!==void 0&&t.push(`description=${ht(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=${ht(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${ht(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const kl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Jm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Sl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:ht(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(ht).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const qs=e=>`${e.source}.${e.name}`,ht=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,$o=e=>Ie(e)?be(["text",e.name]):be([e.name,e.source,e.declaration]),at=$o,$l=e=>be(e.tiles.map(at));function ev(e,t,n){const r=new Set(e.tiles.map(at)),s=new Set(t.tiles.map(at)),i=e.tiles.filter(h=>!s.has(at(h))),o=t.tiles.filter(h=>!r.has(at(h))),c=i.length>0||o.length>0||$l(e)!==$l(t);for(const h of o)if(oe(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const f=new Map(e.sources.map(h=>[h.name,h])),d=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)d.add(h.base);const l=t.imports.some(h=>h.kind==="all"),u=t.sources.filter(h=>!f.has(h.name));for(const h of e.sources){const p=t.sources.find(y=>y.name===h.name);if(!p||p.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of u){if(!o.some(p=>oe(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!d.has(h.base)&&!l&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:i,addedTiles:o,newSources:u,currentSources:f,reordered:c}}const Tl=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function tv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Ar(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function El(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=tv(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=f=>{const d=f.exec(o);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),o=o.slice(0,d.index)+o.slice(d.index+d[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const c=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${c.join(" ")} }${t.slice(s+1)}`}function nv(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:c}=e,f=new Map(r.tiles.filter(Ie).map(g=>[g.name,g])),d=s.tiles.filter(Ie).some(g=>{const v=f.get(g.name);return v!==void 0&&Tl(v,g)});if(!i&&!d)return;const l=he.artifactTag(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,h=Pu(u);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const p=new Map;for(const{text:g}of h.entries){const v=/^"((?:[^"\\]|\\.)+)"$/.exec(g);if(v){const b=v[1].split("->").map(T=>T.trim());b.length===2&&p.set(`${b[0]}->${b[1]}`,g);continue}const x=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(g)?.[1];x!==void 0&&p.set(`text.${x}`,g)}const y=s.tiles.map(g=>{const v=!o.has(at(g));if(Ie(g)){const x=p.get(`text.${g.name}`);return x!==void 0?f.has(g.name)&&!Tl(f.get(g.name),g)?x:El(g,x):v?El(g):void 0}return p.get(`${g.source}->${g.name}`)??(v?`"${g.source} -> ${g.name}"`:void 0)});if(y.some(g=>g===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const w=u.slice(0,h.open).search(/tiles\s*=\s*$/),_=`${u.slice(0,w)}tiles=[${rv(u,h,y)}]${u.slice(h.close+1)}`;_!==u&&c.push({...zu(n,l),text:`${_}
78
- `})}function zu(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function rv(e,t,n){const r=t.entries[0],s=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const i=e.slice(t.open+1,r.span.start),o=e.slice(s.span.end,t.close),a=i.slice(i.lastIndexOf(`
79
- `)),c=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
- `)?a:" "}`;return`${i}${n.join(c)}${o}`}function sv(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Ar(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,c=e[a]==='"'?Ar(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),f=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,f)+e.slice(c)}}return e}function iv(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Ar(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Ar(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Ar(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function ov(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||be(r.startingGivens)!==be(s.startingGivens)){const o=he.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zu(n,o),c=i.find(v=>v.start===a.start&&v.end===a.end);let f=c?c.text.replace(/\n$/,""):o.text;const d=r.layout!==s.layout,l=f.indexOf("artifact"),u=f.indexOf("{",l);let h=0,p=-1;for(let v=u;v<f.length;v++)if(f[v]==="{")h++;else if(f[v]==="}"&&--h===0){p=v;break}if(u<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let y=f.slice(u+1,p);const w=o.block?`
81
- ${/\n([ \t]+)\S/.exec(y)?.[1]??" "}`:" ",_=v=>o.block?`${y.trimEnd()}${w}${v}
82
- `:`${y.trimEnd()} ${v} `,g=(v,x)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${v}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(x===void 0){const T=new RegExp(`
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 xv(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=bv(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 lf(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=xv(o);return e([i]).log.length===0?i:o}),s=e(r);return{tag:s.tag,errors:s.log.map(o=>o.message)}}const Ll=(e,t)=>{try{return e.text(t)}catch{return}},wv=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),_v=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\`.`,kv=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=[…]\`.`,Sv="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 cf(e,t){const n=e.filter(wv).filter(c=>!c.includes("@env.")).map(ve.tagAnnotation),{tag:r,errors:s}=n.length>0?lf(t,n):{tag:void 0,errors:[]},o=r?.tag("artifact");if(!o)return e.some(ve.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const i=Ll(o,"kind");if(i!==void 0)return{status:"kind-removed",kind:i};const a=Ll(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 $v(e){const{parseAnnotation:t}=await k.loadMalloyTag();let n=[];try{const r=(await Wa(e,"file://report.malloy")).parse?.root;r&&Zn(r)&&typeof r.getChild=="function"&&(n=tf(new nf(e),r))}catch{n=[]}return cf(n,t)}const Ys=e=>e.ok===!1;function Jn(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 In=e=>e.map(t=>t.text);function Bl(e){const t=In(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 Fl(e,t){return In(e).some(r=>k.seriesColorOf(r)===void 0&&t([r]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Tv(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:ve.readPath(s),given:i,...o==="~"?{}:{op:o}})}return t.length>0?t:void 0}function Ev(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(),...Cv(n(In(Jn(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Cv(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 Wl(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function Cn(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 Ov=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function jo(e){const t=Cn(e,"colspan"),n=Cn(e,"rowspan"),r=Cn(e,"row"),s=Cn(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 or(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 Mv=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Dv=/^[A-Za-z_][A-Za-z0-9_]*$/;function Iv(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 Jn(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 Nl(e){const{colspan:t,break:n,...r}=e;return r}async function Qs(e,t,n=!1){try{return await Rv(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 Rv(e){const{parseAnnotation:t}=await k.loadMalloyTag(),n=ve.splitSourceLines(e),r=await sf(e);if(ef(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,o=ve.descriptionNotes(n).text,i=cf(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:_v(i.kind)};if(i.status==="cells-removed")return{ok:!1,reason:i.unknownLayout!==void 0?kv(i.unknownLayout):Sv};const a=i.layout,l=ve.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ve.artifactLeads(l.text))return{ok:!1,reason:ve.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:u,errors:c}=lf(t,[ve.tagAnnotation(l.text)]),d=u?.tag("artifact"),f=af(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}),g=[],v=[],_=new Map;for(const T of s.sources){const C={name:T.name,base:T.base};T.dimensions.length>0&&(C.dimensions=T.dimensions.map(O=>({name:O.name,expression:O.expression})));const M=new Set(T.wheres.flatMap(O=>O.clauses.flatMap(P=>P.givens)));M.size>0&&(C.scopedBy=Array.from(M)),g.push(C);for(const O of T.dimensions){const P=t(In(Jn(s,n,O.line).tags)).tag?.tag("drill");if(!P)continue;const L=P.textArray("to")??[P.text("to")??""];v.push({source:T.name,name:O.name,expression:O.expression,to:L.filter(Boolean),...P.text("given")?{given:P.text("given")}:{}})}_.set(T.name,new Map(T.views.map(O=>[O.name,O])))}const x=[],p=(T,C)=>{const M=zl(t(In(Iv(s,n,T))).tag);return{name:T,declaration:{kind:"query"},...Nl(M),...or({colspan:M.colspan,break:M.break},C)}};for(const{text:T}of f.entries){const C=Ov.exec(T),M=C?void 0:Mv.exec(T)?.[1];if(M!==void 0){const j=t([`# ${T}`]).tag?.tag(M),R=j?.text("kind");if(R===void 0||R==="query"){x.push(p(M,jo(j)));continue}if(R!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${M} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(W=>Re(W)&&W.name===M))return{ok:!1,reason:`Two text tiles are named \`${M}\`, so the builder cannot tell them apart.`};x.push({kind:"text",name:M,markdown:s.textBlocks.find(W=>W.name===M)?.body??"",...or({},jo(j))});continue}const O=C?.[1]??T,P=jo(C?.[2]?t([`# tile ${C[2]}`]).tag?.tag("tile")??void 0:void 0);if(Dv.test(O.trim())){x.push(p(O.trim(),P));continue}const L=C?ve.tileSteps(O):void 0;if(!L)return{ok:!1,reason:`The tile \`${O}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:A,view:H}=L,z=_.get(A)?.get(H);if(z===void 0){x.push({name:H,source:A,declaration:{kind:"inherited"},...or({},P)});continue}const Y=t(In(z.tags)).tag,I=z.body.kind==="reference"?{kind:"reference",from:z.body.from}:z.body.kind==="inline"?{kind:"inline"}:void 0;if(I===void 0){x.push({name:H,source:A,declaration:{kind:"opaque",why:z.body.kind==="unsupported"?z.body.why:"unreadable"},...Nl(zl(Y)),...or(Wl(Y),P),...Bl(z.tags),...Fl(z.tags,t)});continue}const N=Tv(z.body.kind==="reference"?z.body.refinement:z.body.kind==="inline"?z.body.stage:void 0);x.push({name:H,source:A,declaration:I,...N?{filters:N}:{},...Y?.text("label")?{label:Y.text("label")}:{},...Y?.text("subtitle")?{subtitle:Y.text("subtitle")}:{},...or(Wl(Y),P),...Bl(z.tags),...Fl(z.tags,t),...Y?.has("borderless")?{borderless:!0}:{}})}const y=Ev(s,n,t),w={},b=d?.tag("givens");for(const T of Object.keys(b?.dict??{})){const C=b?.text(T);C!==void 0&&(w[T]=C)}const E=u?.tag("dashboard")?.has("columns")?Cn(u.tag("dashboard"),"columns"):d?.array("tiles")?Cn(d,"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:g,...y?{localGivens:y}:{},...Object.keys(w).length>0?{startingGivens:w}:{},...v.length>0?{drills:v}:{},tiles:x}}}const Zs=e=>e.ok===!1;async function Gl(e){const{problems:t}=await Wa(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function $e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function df(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Pv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function jv(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 uf=e=>e==="none"||k.isChartPick(e)?e:void 0;function ff(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${bt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${bt(e.subtitle)}`);const r=t?uf(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 hf="theme.palette.series";function Ts(e){return k.seriesColorOf(e)!==void 0?hf:/^#\s*([a-z_]+)/.exec(e)?.[1]}const Av=new Set(["colspan","break","borderless","label","subtitle",hf]),Lv=new Set(["label","description","control","suggest","range_min","range_max"]);function Hl(e){const t=[];if(e.label!==void 0&&t.push(`label=${bt(e.label)}`),e.description!==void 0&&t.push(`description=${bt(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=${bt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${bt(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 ql=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Bv(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Ul(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:bt(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(bt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Js=e=>`${e.source}.${e.name}`,bt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Pi=e=>Re(e)?$e(["text",e.name]):$e([e.name,e.source,e.declaration]),rt=Pi,Vl=e=>$e(e.tiles.map(rt));function Fv(e,t,n){const r=new Set(e.tiles.map(rt)),s=new Set(t.tiles.map(rt)),o=e.tiles.filter(h=>!s.has(rt(h))),i=t.tiles.filter(h=>!r.has(rt(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 g=t.sources.find(v=>v.name===h.name);if(!g||g.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(g=>ce(g)&&g.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 Wv=new Set(["colspan","break"]),ji=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,Kl=e=>{const{colspan:t,break:n,rowspan:r,row:s,col:o,...i}=e;return i},zv=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 pf(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Gr(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Xl(e,t){const n=zv(e);if(t===void 0){const c=Re(e)?e.name:`"${lt(e)}"`,d=[...Re(e)?["kind=text"]:[],...n];return d.length>0?`${c} { ${d.join(" ")} }`:c}const r=pf(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 Nv(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=>[rt(p),p])),c=s.tiles.some(p=>{const y=u.get(rt(p));return y!==void 0&&ji(y,p)});if(!o&&!c)return;const d=ve.artifactTag(t);if(!d)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=d.text,h=af(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 g=new Map;for(const{text:p}of h.entries){const y=/^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(p);if(y){const b=y[1].split("->").map(E=>E.trim());b.length===2?g.set(`${b[0]}->${b[1]}`,p):b.length===1&&g.set(`query.${b[0]}`,p);continue}if(ve.isIdentifier(p)){g.set(`query.${p}`,p);continue}const w=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(p)?.[1];w!==void 0&&g.set(/\bkind\s*=\s*text\b/.test(pf(p))?`text.${w}`:`query.${w}`,p)}const v=s.tiles.map(p=>{const y=!i.has(rt(p)),w=g.get(Re(p)?`text.${p.name}`:p.declaration.kind==="query"?`query.${p.name}`:`${p.source}->${p.name}`);if(w===void 0)return y?Xl(p):void 0;const b=u.get(rt(p));return b!==void 0&&!ji(b,p)?w:Xl(p,w)});if(v.some(p=>p===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const _=f.slice(0,h.open).search(/tiles\s*=\s*$/),x=`${f.slice(0,_)}tiles=[${Gv(f,h,v)}]${f.slice(h.close+1)}`;x!==f&&l.push({...gf(n,d),text:`${x}
78
+ `})}function gf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Gv(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
+ `)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
+ `)?a:" "}`;return`${o}${n.join(l)}${i}`}function Hv(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const o=e[s];if(o==='"')s=Gr(e,s);else if(o==="{"||o==="[")n++===0&&r++;else if(o==="}"||o==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const i=/^\s*=\s*/.exec(e.slice(s+t.length));if(!i)continue;const a=s+t.length+i[0].length,l=e[a]==='"'?Gr(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),u=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,u)+e.slice(l)}}return e}function qv(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Gr(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=Gr(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 Gr(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 Uv(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||$e(r.startingGivens)!==$e(s.startingGivens)){const i=ve.artifactTag(t);if(!i)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=gf(n,i),l=o.find(y=>y.start===a.start&&y.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,g=-1;for(let y=f;y<u.length;y++)if(u[y]==="{")h++;else if(u[y]==="}"&&--h===0){g=y;break}if(f<0||g<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=u.slice(f+1,g);const _=i.block?`
81
+ ${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",x=y=>i.block?`${v.trimEnd()}${_}${y}
82
+ `:`${v.trimEnd()} ${y} `,p=(y,w)=>{const b=new RegExp(`${i.block?"[ \\t]*":"\\s*"}\\b${y}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(w===void 0){const E=new RegExp(`
83
83
  ${b.source}[ \\t]*(?=
84
- )`);y=y.replace(o.block&&T.test(y)?T:b,"")}else b.test(y)?y=y.replace(b,T=>`${o.block?T.slice(0,T.length-T.trimStart().length):" "}${v}=${x}`):y=_(`${v}=${x}`)};if(d&&g("layout",s.layout),r.title!==s.title&&g("title",s.title?ht(s.title):void 0),r.autorun!==s.autorun&&g("autorun",s.autorun===void 0?void 0:String(s.autorun)),be(r.startingGivens)!==be(s.startingGivens)){y=y.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const v=Object.entries(s.startingGivens??{});v.length>0&&(y=_(`givens { ${v.map(([x,b])=>`${x}=${ht(b)}`).join(" ")} }`))}o.block?f=`${f.slice(0,u+1)}${y}${f.slice(p)}`:(y=y.replace(/\s{2,}/g," "),f=`${f.slice(0,u+1)}${y.startsWith(" ")?y:` ${y}`}${y.endsWith(" ")?"":" "}${f.slice(p)}`),r.columns!==s.columns&&(f=sv(f,"dashboard_columns"),f=iv(f),s.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${s.columns} }`)),c?c.text=`${f}
85
- `:i.push({...a,text:`${f}
86
- `})}if(r.description!==s.description){const{read:o,blankAbove:a,below:c,belowBlock:f,inBlock:d}=he.descriptionNotes(t);if(d||s.description===void 0&&f)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const l=Lu(s.description??"").split(`
87
- `).map(y=>y.trim()===""?'##"':`##" ${y.trim()}`).join(`
88
- `),u=o.length>0&&o[0]<he.artifactLine(t),h=s.description===void 0,p=u?[...o.slice(1),...h?c:[]]:[...o,...a];for(const y of p)i.push({...n(y),text:""});if(u)i.push({...n(o[0]),text:s.description===void 0?"":`${l}
89
- `});else if(s.description!==void 0){const y=n(he.artifactLine(t)).start;i.push({start:y,end:y,text:`${l}
90
- `})}}}function av(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.localGivens??[]).map(h=>[h.name,h])),f=new Map((i.localGivens??[]).map(h=>[h.name,h])),d=new Map(a.givens.map(h=>[h.name,h])),l=new Set;for(const[h,p]of c){const y=f.get(h);if(y!==void 0&&be(y)===be(p))continue;const w=d.get(h);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:_,prose:g}=qr(a,t,w.line),x=[...(y===void 0?_:_.filter(O=>{const P=bs(O.text);return P!==void 0&&Zm.has(P)})).map(O=>O.line),...y===void 0?g:[]];for(const O of x)o.push({...n(O),text:""}),l.add(O);const b=$t(a,w.span.end-1);if(y===void 0){o.push({start:n(w.line).start,end:n(b).end,text:""});for(let U=w.line;U<=b;U++)l.add(U);const O=Math.min(w.line,...x),P=w.blockHeader??O,A=(t[b+1]??"x").trim()==="",L=P===0||t[P-1].trim()==="",W=w.blockHeader===void 0||![...d.values()].some(U=>U.blockHeader===w.blockHeader&&U.line>w.line&&f.has([...d.entries()].find(([,N])=>N===U)?.[0]??""));A&&L&&W&&!l.has(b+1)&&(o.push({...n(b+1),text:""}),l.add(b+1));continue}const T=r(w.line),C=_l(y),E=y.type!==p.type||y.default!==p.default?w.blockHeader===void 0?kl(y):`${y.name} :: ${y.type} is ${y.default}`:t.slice(w.line,b+1).join(`
91
- `).trim();o.push({start:n(w.line).start,end:n(b).end,text:(C?`${T}${C}
92
- `:"")+`${T}${E}
93
- `})}for(const[h,p]of d){if(p.blockHeader===void 0||f.has(h))continue;![...d.values()].some(w=>w.blockHeader===p.blockHeader&&!l.has(w.line))&&!l.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),l.add(p.blockHeader))}const u=[...f.values()].filter(h=>!c.has(h.name));if(u.length>0){const h=Math.max(-1,...[...d.values()].map(v=>v.line)),p=(()=>{let v=-1;for(let x=0;x<t.length;x++){const b=t[x].trim();(b.startsWith("import ")||v>=0&&/^}\s*from\s/.test(b))&&(v=x)}return v})(),y=h>=0?h:p,w=u.map(v=>{const x=_l(v);return(x?`${x}
94
- `:"")+`${kl(v)}
84
+ )`);v=v.replace(i.block&&E.test(v)?E:b,"")}else b.test(v)?v=v.replace(b,E=>`${i.block?E.slice(0,E.length-E.trimStart().length):" "}${y}=${w}`):v=x(`${y}=${w}`)};if(c&&p("layout",s.layout),r.title!==s.title&&p("title",s.title?bt(s.title):void 0),r.autorun!==s.autorun&&p("autorun",s.autorun===void 0?void 0:String(s.autorun)),$e(r.startingGivens)!==$e(s.startingGivens)){v=v.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const y=Object.entries(s.startingGivens??{});y.length>0&&(v=x(`givens { ${y.map(([w,b])=>`${w}=${bt(b)}`).join(" ")} }`))}i.block?u=`${u.slice(0,f+1)}${v}${u.slice(g)}`:(v=v.replace(/\s{2,}/g," "),u=`${u.slice(0,f+1)}${v.startsWith(" ")?v:` ${v}`}${v.endsWith(" ")?"":" "}${u.slice(g)}`),r.columns!==s.columns&&(u=Hv(u,"dashboard_columns"),u=qv(u),s.columns!==void 0&&(u=`${u.trimEnd()} dashboard { columns=${s.columns} }`)),l?l.text=`${u}
85
+ `:o.push({...a,text:`${u}
86
+ `})}if(r.description!==s.description){const{read:i,blankAbove:a,below:l,belowBlock:u,inBlock:c}=ve.descriptionNotes(t);if(c||s.description===void 0&&u)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const d=df(s.description??"").split(`
87
+ `).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
88
+ `),f=i.length>0&&i[0]<ve.artifactLine(t),h=s.description===void 0,g=f?[...i.slice(1),...h?l:[]]:[...i,...a];for(const v of g)o.push({...n(v),text:""});if(f)o.push({...n(i[0]),text:s.description===void 0?"":`${d}
89
+ `});else if(s.description!==void 0){const v=n(ve.artifactLine(t)).start;o.push({start:v,end:v,text:`${d}
90
+ `})}}}function Vv(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,g]of l){const v=u.get(h);if(v!==void 0&&$e(v)===$e(g))continue;const _=c.get(h);if(_===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:p}=Jn(a,t,_.line),w=[...(v===void 0?x:x.filter(O=>{const P=Ts(O.text);return P!==void 0&&Lv.has(P)})).map(O=>O.line),...v===void 0?p:[]];for(const O of w)i.push({...n(O),text:""}),d.add(O);const b=Rt(a,_.span.end-1);if(v===void 0){i.push({start:n(_.line).start,end:n(b).end,text:""});for(let z=_.line;z<=b;z++)d.add(z);const O=Math.min(_.line,...w),P=_.blockHeader??O,L=(t[b+1]??"x").trim()==="",A=P===0||t[P-1].trim()==="",H=_.blockHeader===void 0||![...c.values()].some(z=>z.blockHeader===_.blockHeader&&z.line>_.line&&u.has([...c.entries()].find(([,Y])=>Y===z)?.[0]??""));L&&A&&H&&!d.has(b+1)&&(i.push({...n(b+1),text:""}),d.add(b+1));continue}const E=r(_.line),T=Hl(v),M=v.type!==g.type||v.default!==g.default?_.blockHeader===void 0?ql(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(_.line,b+1).join(`
91
+ `).trim();i.push({start:n(_.line).start,end:n(b).end,text:(T?`${E}${T}
92
+ `:"")+`${E}${M}
93
+ `})}for(const[h,g]of c){if(g.blockHeader===void 0||u.has(h))continue;![...c.values()].some(_=>_.blockHeader===g.blockHeader&&!d.has(_.line))&&!d.has(g.blockHeader)&&(i.push({...n(g.blockHeader),text:""}),d.add(g.blockHeader))}const f=[...u.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...c.values()].map(y=>y.line)),g=(()=>{let y=-1;for(let w=0;w<t.length;w++){const b=t[w].trim();(b.startsWith("import ")||y>=0&&/^}\s*from\s/.test(b))&&(y=w)}return y})(),v=h>=0?h:g,_=f.map(y=>{const w=Hl(y);return(w?`${w}
94
+ `:"")+`${ql(y)}
95
95
  `}).join(`
96
- `),_=y>=0?n(y).end:n(0).end;o.push({start:_,end:_,text:`
97
- ${w}`}),t.some(v=>v.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
- `})}}const Cl=(e,t)=>`import { ${e.join(", ")} } from ${ht(t)}`;function lv(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=l=>be(l.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(be(n.imports)===be(r.imports))return;const a=r.imports.flatMap(l=>l.kind==="names"?[{...l,claimed:!1}]:[]),c=new Set([...r.sources.map(l=>l.base),...r.tiles.filter(oe).map(l=>l.source)]),f=t.imports.map((l,u)=>({statement:l,entry:n.imports[u]}));for(const{statement:l,entry:u}of f){if(!u||u.kind!=="names")continue;const h=a.find(v=>!v.claimed&&v.from===u.from);h&&(h.claimed=!0);const p=h?.names??[],w=u.names.filter(v=>!p.includes(v)).find(v=>c.has(v));if(w!==void 0)return{ok:!1,reason:`\`${w}\` is still read by a tile, so its import cannot be removed.`};if(be(p)===be(u.names))continue;const _=p.length===0?Ca(t,l.statement):l.statement,g=t.commentIn(_);if(g)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(g.start,g.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({..._,text:p.length===0?"":Cl(p,u.from)})}const d=a.filter(l=>!l.claimed);if(d.length>0){const l=t.imports.at(-1);if(!l)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const u=i($t(t,l.statement.end-1)).end;s.push({start:u,end:u,text:d.map(h=>`${Cl(h.names,h.from)}
99
- `).join("")})}}function cv(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.drills??[]).map(d=>[qs(d),d])),f=new Map((i.drills??[]).map(d=>[qs(d),d]));for(const d of new Set([...c.keys(),...f.keys()])){const l=c.get(d),u=f.get(d);if(l&&u&&be(l)===be(u))continue;const h=u??l;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const p=a.sources.find(g=>g.name===h.source)?.dimensions.find(g=>g.name===h.name);if(p===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:y}=qr(a,t,p.line),w=y.find(g=>/^#\s*drill\b/.test(g.text)),_=r(p.line);if(u===void 0)w&&o.push({...n(w.line),text:""});else if(w)o.push({...n(w.line),text:`${_}${Sl(u)}
100
- `});else{const g=n(p.line).start;o.push({start:g,end:g,text:`${_}${Sl(u)}
101
- `})}}}function dv(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(Ie(o)||o.declaration.kind==="inherited")continue;const a=Wu(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const c=$t(i,a.statement.start),f=$t(i,a.statement.end-1),d=i.trailingComment(f),l=d&&d.start>=a.statement.end?d.end:a.statement.end;if(i.text.slice(i.lineStarts[c],a.statement.start).trim()!==""||i.text.slice(l,n(f).end).trim()!==""){s.push({...Ca(i,a.statement),text:""});continue}s.push({start:i.lineStarts[c],end:n(f).end,text:""});const h=c===0?"":t[c-1].trim();(t[f+1]??"x").trim()===""&&(c===0||h===""||h.endsWith("{"))&&s.push({...n(f+1),text:""})}}function uv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:c}=e,f=new Map;for(const u of s){if(Ie(u))continue;const h=f.get(u.source)??[];h.push(u),f.set(u.source,h)}const d=(u,h)=>{const p=u.declaration.kind==="reference"?u.declaration.from:u.name,y=(u.filters??[]).map(w=>`where: ${he.malloyPath(w.field)} ${w.op??"~"} $${w.given}`).join(", ");return[...Fu(u).map(w=>`${h}${w}`),`${h}view: ${u.name} is ${p}${y?` + { ${y} }`:""}`].join(`
102
- `)};let l=-1;for(const u of c.sources)l=Math.max(l,$t(c,u.span.end-1));for(const[u,h]of f)if(o.has(u)){const p=c.sources.find(x=>x.name===u);if(!p)return{ok:!1,reason:`Could not find where the source \`${u}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${u}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const y=p.line,w=$t(c,p.properties.closeStart);let _=" ";for(let x=y+1;x<w;x++){const b=/^(\s+)view:/.exec(n[x]);if(b){_=b[1];break}}const g=r(w).start,v=(n[w-1]??"").trim()==="";a.push({start:g,end:g,text:(v?"":`
103
- `)+h.map(x=>d(x,_)).join(`
96
+ `),x=v>=0?n(v).end:n(0).end;i.push({start:x,end:x,text:`
97
+ ${_}`}),t.some(y=>y.trim().startsWith("##! experimental.givens"))||i.push({start:0,end:0,text:`##! experimental.givens
98
+ `})}}const Yl=(e,t)=>`import { ${e.join(", ")} } from ${bt(t)}`;function Kv(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:o}=e,i=d=>$e(d.imports.flatMap(f=>f.kind==="all"?[f.from]:[]).sort());if(i(n)!==i(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if($e(n.imports)===$e(r.imports))return;const a=r.imports.flatMap(d=>d.kind==="names"?[{...d,claimed:!1}]:[]),l=new Set([...r.sources.map(d=>d.base),...r.tiles.filter(ce).map(d=>d.source)]),u=t.imports.map((d,f)=>({statement:d,entry:n.imports[f]}));for(const{statement:d,entry:f}of u){if(!f||f.kind!=="names")continue;const h=a.find(y=>!y.claimed&&y.from===f.from);h&&(h.claimed=!0);const g=h?.names??[],_=f.names.filter(y=>!g.includes(y)).find(y=>l.has(y));if(_!==void 0)return{ok:!1,reason:`\`${_}\` is still read by a tile, so its import cannot be removed.`};if($e(g)===$e(f.names))continue;const x=g.length===0?za(t,d.statement):d.statement,p=t.commentIn(x);if(p)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(p.start,p.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({...x,text:g.length===0?"":Yl(g,f.from)})}const c=a.filter(d=>!d.claimed);if(c.length>0){const d=t.imports.at(-1);if(!d)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=o(Rt(t,d.statement.end-1)).end;s.push({start:f,end:f,text:c.map(h=>`${Yl(h.names,h.from)}
99
+ `).join("")})}}function Xv(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:o,edits:i,parsed:a}=e,l=new Map((s.drills??[]).map(c=>[Js(c),c])),u=new Map((o.drills??[]).map(c=>[Js(c),c]));for(const c of new Set([...l.keys(),...u.keys()])){const d=l.get(c),f=u.get(c);if(d&&f&&$e(d)===$e(f))continue;const h=f??d;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const g=a.sources.find(p=>p.name===h.source)?.dimensions.find(p=>p.name===h.name);if(g===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:v}=Jn(a,t,g.line),_=v.find(p=>/^#\s*drill\b/.test(p.text)),x=r(g.line);if(f===void 0)_&&i.push({...n(_.line),text:""});else if(_)i.push({...n(_.line),text:`${x}${Ul(f)}
100
+ `});else{const p=n(g.line).start;i.push({start:p,end:p,text:`${x}${Ul(f)}
101
+ `})}}}function Yv(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:o}=e;for(const i of r){if(Re(i)||Fn(i))continue;const a=mf(e,i);if(!a)return{ok:!1,reason:`Could not find where \`${i.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${i.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const l=Rt(o,a.statement.start),u=Rt(o,a.statement.end-1),c=o.trailingComment(u),d=c&&c.start>=a.statement.end?c.end:a.statement.end;if(o.text.slice(o.lineStarts[l],a.statement.start).trim()!==""||o.text.slice(d,n(u).end).trim()!==""){s.push({...za(o,a.statement),text:""});continue}s.push({start:o.lineStarts[l],end:n(u).end,text:""});const h=l===0?"":t[l-1].trim();(t[u+1]??"x").trim()===""&&(l===0||h===""||h.endsWith("{"))&&s.push({...n(u+1),text:""})}}function Qv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:o,currentSources:i,edits:a,parsed:l}=e,u=new Map;for(const f of s){if(Re(f))continue;const h=u.get(f.source)??[];h.push(f),u.set(f.source,h)}const c=(f,h)=>{const g=f.declaration.kind==="reference"?f.declaration.from:f.name,v=(f.filters??[]).map(_=>`where: ${ve.malloyPath(_.field)} ${_.op??"~"} $${_.given}`).join(", ");return[...ff(f).map(_=>`${h}${_}`),`${h}view: ${f.name} is ${g}${v?` + { ${v} }`:""}`].join(`
102
+ `)};let d=-1;for(const f of l.sources)d=Math.max(d,Rt(l,f.span.end-1));for(const[f,h]of u)if(i.has(f)){const g=l.sources.find(w=>w.name===f);if(!g)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!g.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=g.line,_=Rt(l,g.properties.closeStart);let x=" ";for(let w=v+1;w<_;w++){const b=/^(\s+)view:/.exec(n[w]);if(b){x=b[1];break}}const p=r(_).start,y=(n[_-1]??"").trim()==="";a.push({start:p,end:p,text:(y?"":`
103
+ `)+h.map(w=>c(w,x)).join(`
104
104
 
105
105
  `)+`
106
- `})}else{const p=i.find(v=>v.name===u);if(!p)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const y=`
107
- source: ${p.name} is ${p.base} extend {
108
- `+h.map(v=>d(v," ")).join(`
106
+ `})}else{const g=o.find(y=>y.name===f);if(!g)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const v=`
107
+ source: ${g.name} is ${g.base} extend {
108
+ `+h.map(y=>c(y," ")).join(`
109
109
 
110
110
  `)+`
111
111
  }
112
- `;let w=l;if(w<0)for(let v=0;v<n.length;v++){const x=n[v].trim();(/^(import\s|given:|}\s*from\s)/.test(x)||/^[A-Z_]+\s*::/.test(x))&&(w=v)}const _=w>=0?r(w).end:t.length,g=_===t.length&&!t.endsWith(`
112
+ `;let _=d;if(_<0)for(let y=0;y<n.length;y++){const w=n[y].trim();(/^(import\s|given:|}\s*from\s)/.test(w)||/^[A-Z_]+\s*::/.test(w))&&(_=y)}const x=_>=0?r(_).end:t.length,p=x===t.length&&!t.endsWith(`
113
113
  `)?`
114
- `:"";a.push({start:_,end:_,text:g+y}),l=w}}function fv(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:c}=e,f=new Map(i.tiles.map(d=>[at(d),d]));for(const d of o.tiles){const l=f.get(at(d));if(l===void 0||Ie(d)||Ie(l)||be(Ks(l))===be(Ks(d)))continue;if(d.declaration.kind==="inherited")return{ok:!1,reason:`\`${d.source} -> ${d.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const u=Jm(c,d.source,d.name);if(u<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:h}=qr(c,t,u),p=s(u),y=Fu(d,!1),w=new Map(y.map(E=>[bs(E)??E,E])),_=new Set,g=Bu(d.chart),v=Ol(l)!==Ol(d);if(v){const E=h.filter(A=>S.mentionsChartTag(A.text)),O=h.filter(A=>S.parseChartLine(A.text)),P=l.chart==="custom"?h.filter(A=>S.parseChartLine(A.text)||S.mentionsChartTag(A.text)):E.length>0?E:O.length>1?O:[];if(P.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${P.map(A=>A.text).join(" and ")}), so its chart cannot be changed here.`}}let x=!1;for(const E of h){if(v&&S.parseChartLine(E.text)){g===void 0?a.push({...r(E.line),text:""}):E.text!==S.chartLineText(g,d.chartCarried)&&a.push({...r(E.line),text:`${p}${S.chartLineText(g,d.chartCarried)}
115
- `}),x=!0;continue}const O=bs(E.text);if(O===void 0||!Qm.has(O))continue;const P=w.get(O);if(P===void 0){a.push({...r(E.line),text:""});continue}_.add(O),P!==E.text&&a.push({...r(E.line),text:`${p}${P}
116
- `})}const b=y.filter(E=>!_.has(bs(E)??E));if(v&&g!==void 0&&!x&&b.push(S.chartLineText(g,d.chartCarried)),b.length>0){const E=n[u];a.push({start:E,end:E,text:b.map(O=>`${p}${O}
117
- `).join("")})}if(be(l.filters)===be(d.filters))continue;const T=Wu(e,d);if(!T)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(T.body.kind==="reference"){const E=bv(e,d,T);if(E)return E;continue}if(T.body.kind!=="inline")return{ok:!1,reason:`\`${d.name}\`'s body is ${T.body.why}, so there is no single first stage to write its filter into.`};const C=Nu(d.filters,T.body.stage);if(C)return Gu(d.name,C.given);const M=Vu(e,d,T.body.stage);if(M)return M}}const Ol=e=>e.chart==="default"?void 0:e.chart,Ks=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function hv(e,t){const n=new Map(e.tiles.map(r=>[at(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(at(r));return oe(r)&&r.chart===void 0&&s&&oe(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function xs(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function pv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!he.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=xs(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const Ei=e=>`##|(markdown) ${e.name}
114
+ `:"";a.push({start:x,end:x,text:p+v}),d=_}}function Zv(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=>[rt(c),c]));for(const c of i.tiles){const d=u.get(rt(c));if(d===void 0||Re(c)||Re(d))continue;const f=ji(d,c),h=$e(Kl(eo(d)))!==$e(Kl(eo(c)));if(!h&&!f)continue;if(c.declaration.kind==="inherited"){if(!h)continue;return{ok:!1,reason:`\`${lt(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 g=Bv(l,c.source,c.name);if(g<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:v}=Jn(l,t,g),_=s(g),x=ff(c,!1),p=new Map(x.map(P=>[Ts(P)??P,P])),y=new Set,w=uf(c.chart),b=Ql(d)!==Ql(c);if(b){const P=v.filter(H=>k.mentionsChartTag(H.text)),L=v.filter(H=>k.parseChartLine(H.text)),A=d.chart==="custom"?v.filter(H=>k.parseChartLine(H.text)||k.mentionsChartTag(H.text)):P.length>0?P:L.length>1?L:[];if(A.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${A.map(H=>H.text).join(" and ")}), so its chart cannot be changed here.`}}let E=!1;for(const P of v){if(b&&k.parseChartLine(P.text)){w===void 0?a.push({...r(P.line),text:""}):P.text!==k.chartLineText(w,c.chartCarried)&&a.push({...r(P.line),text:`${_}${k.chartLineText(w,c.chartCarried)}
115
+ `}),E=!0;continue}const L=Ts(P.text);if(L===void 0||!Av.has(L))continue;if(Wv.has(L)){f&&a.push({...r(P.line),text:""});continue}const A=p.get(L);if(A===void 0){a.push({...r(P.line),text:""});continue}y.add(L),A!==P.text&&a.push({...r(P.line),text:`${_}${A}
116
+ `})}const T=x.filter(P=>!y.has(Ts(P)??P));if(b&&w!==void 0&&!E&&T.push(k.chartLineText(w,c.chartCarried)),T.length>0){const P=n[g];a.push({start:P,end:P,text:T.map(L=>`${_}${L}
117
+ `).join("")})}if($e(d.filters)===$e(c.filters))continue;const C=mf(e,c);if(!C)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(C.body.kind==="reference"){const P=oy(e,c,C);if(P)return P;continue}if(C.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${C.body.why}, so there is no single first stage to write its filter into.`};const M=vf(c.filters,C.body.stage);if(M)return yf(c.name,M.given);const O=bf(e,c,C.body.stage);if(O)return O}}const Ql=e=>e.chart==="default"?void 0:e.chart,eo=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...o}=r;return o};function Jv(e,t){const n=new Map(e.tiles.map(r=>[rt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(rt(r));return ce(r)&&r.chart===void 0&&s&&ce(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function Es(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 ey(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&&!ve.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=Es(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 Ao=e=>`##|(markdown) ${e.name}
118
118
  ${e.markdown===""?"":`${e.markdown}
119
119
  `}|##
120
- `;function gv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,c=new Map(s.tiles.filter(Ie).map(h=>[h.name,h])),f=i.tiles.filter(Ie),d=h=>o.textBlocks.find(p=>p.name===h),l=new Set(f.map(h=>h.name));for(const h of c.keys()){const p=l.has(h)?void 0:d(h);if(!p)continue;const y=$t(o,p.span.end-1);a.push({...p.span,text:""});const w=r(y+1),_=p.line===0||n[p.line-1].trim()==="";w.end>w.start&&n[y+1].trim()===""&&_?a.push({...w,text:""}):p.line>0&&_&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const u=[];for(const h of f){const p=c.get(h.name),y=d(h.name);if(p===void 0){if(y)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};u.push(Ei(h))}else p.markdown!==h.markdown&&(y?a.push({...y.span,text:Ei(h)}):u.push(Ei(h)))}if(u.length>0){const h=o.textBlocks.filter(g=>g.name===void 0||l.has(g.name)),p=h[h.length-1],y=o.sources.find(g=>g.name.endsWith("_tiles"));if(p){const g=p.span.end,v=t.slice(g);a.push({start:g,end:g,text:`
121
- ${u.join(`
122
- `)}${v===""||v.startsWith(`
120
+ `;function ty(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:o,parsed:i,edits:a}=e,l=new Map(s.tiles.filter(Re).map(h=>[h.name,h])),u=o.tiles.filter(Re),c=h=>i.textBlocks.find(g=>g.name===h),d=new Set(u.map(h=>h.name));for(const h of l.keys()){const g=d.has(h)?void 0:c(h);if(!g)continue;const v=Rt(i,g.span.end-1);a.push({...g.span,text:""});const _=r(v+1),x=g.line===0||n[g.line-1].trim()==="";_.end>_.start&&n[v+1].trim()===""&&x?a.push({..._,text:""}):g.line>0&&x&&t.slice(g.span.end).trim()===""&&a.push({...r(g.line-1),text:""})}const f=[];for(const h of u){const g=l.get(h.name),v=c(h.name);if(g===void 0){if(v)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(Ao(h))}else g.markdown!==h.markdown&&(v?a.push({...v.span,text:Ao(h)}):f.push(Ao(h)))}if(f.length>0){const h=i.textBlocks.filter(p=>p.name===void 0||d.has(p.name)),g=h[h.length-1],v=i.sources.find(p=>p.name.endsWith("_tiles"));if(g){const p=g.span.end,y=t.slice(p);a.push({start:p,end:p,text:`
121
+ ${f.join(`
122
+ `)}${y===""||y.startsWith(`
123
123
  `)?"":`
124
- `}`});return}if(y){const g=e.starts[o.blockStart(y.line)],v=g===0||t.slice(0,g).endsWith(`
124
+ `}`});return}if(v){const p=e.starts[i.blockStart(v.line)],y=p===0||t.slice(0,p).endsWith(`
125
125
 
126
- `);a.push({start:g,end:g,text:`${v?"":`
127
- `}${u.join(`
126
+ `);a.push({start:p,end:p,text:`${y?"":`
127
+ `}${f.join(`
128
128
  `)}
129
- `});return}const w=t.length,_=t===""||t.endsWith(`
129
+ `});return}const _=t.length,x=t===""||t.endsWith(`
130
130
 
131
131
  `)?"":t.endsWith(`
132
132
  `)?`
133
133
  `:`
134
134
 
135
- `;a.push({start:w,end:w,text:_+u.join(`
136
- `)})}}const os=(e,t=he.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function mv(e,t){const n=new Map(e.tiles.map(o=>[at(o),o]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const o of t.tiles){const a=n.get(at(o));if(Ie(o)){const l=pv(o,a&&Ie(a)?a:void 0,r);if(l)return l;continue}const c=a&&oe(a)?a:void 0;if(a&&!c)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!S.isChartPick(f)&&!(f==="custom"&&c?.chart==="custom"))return`"${String(f)}" is not a chart this editor writes.`;const d=new Set(c?.filters?.map(l=>l.field));for(const l of o.filters??[])if(!d.has(l.field)&&/[\r\n]/.test(l.field))return"A filter field is one line.";if(a===void 0){const l=[o.name,o.source];o.declaration.kind==="reference"&&l.push(o.declaration.from);for(const u of l){const h=os(u);if(h)return h}}for(const l of["label","subtitle"]){const u=o[l];if(u===void 0||u===c?.[l])continue;const h=S.annotationTextProblem(`tile ${l}`,u);if(h)return h}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const c=os(a);if(c)return c}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=S.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=S.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const f=os(o.name,he.isStrictName);if(f)return f}const c=o.suggest?.source;if(c!==void 0&&c!==a?.suggest?.source){const f=os(c);if(f)return`The suggest source is not a name. ${f}`}for(const f of["query","dimension"]){const d=o.suggest?.[f];if(d===void 0||d===a?.suggest?.[f])continue;const l=S.annotationTextProblem(`suggest ${f}`,d);if(l)return l}for(const f of["label","description"]){const d=o[f];if(d===void 0||d===i.get(o.name)?.[f])continue;const l=S.annotationTextProblem(`given ${f}`,d);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const c=S.annotationTextProblem(`starting value for ${o}`,a);if(c)return c}}const $t=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wu(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Nu(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Gu(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const ws=e=>`where: ${he.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Dl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function vv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment($t(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function yv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Ca(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
- `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Vu(e,t,n){const{parsed:r,edits:s}=e,i=new Map((t.filters??[]).map(u=>[u.given,u])),o=new Set;let a;for(const u of n.wheres){const h=u.clauses.map((y,w)=>({clause:y,index:w})).filter(({clause:y})=>y.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:y})=>i.has(y.binding.given));for(const{clause:y}of h)o.add(y.binding.given);if(p.length===0&&h.length===u.clauses.length){const y=Ca(r,u.span),w=vv(r,u.span,y);if(w)return Dl(t.name,r,w);s.push({...y,text:""});continue}p.length>0&&(a=u.span);for(let y=h.length-1;y>=0;y--){const{clause:w,index:_}=h[y],g=i.get(w.binding.given);if(!g){const x=yv(u.clauses,_),b=r.commentIn(x);if(b)return Dl(t.name,r,b);s.push({...x,text:""});continue}const v=ws(g).replace(/^where:\s*/,"");v!==r.text.slice(w.span.start,w.span.end)&&s.push({...w.span,text:v})}}const c=(t.filters??[]).filter(u=>!o.has(u.given));if(c.length===0)return;let f=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const u=r.trailingComment($t(r,f));u&&u.start>=f&&(f=u.end)}const d=a!==void 0&&!/,\s*$/.test(r.text.slice(0,f))?", ":" ",l=n.oneLine?`${d}${c.map(ws).join(", ")}`:c.map(u=>`
138
- ${n.indent}${ws(u)}`).join("");s.push({start:f,end:f,text:l})}function bv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Nu(t.filters,i);if(o)return Gu(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const d=` + { ${a.map(ws).join(", ")} }`;r.push({start:s.end,end:s.end,text:d});return}const c=i.wheres.some(d=>d.clauses.some(l=>!l.binding)),f=i.statements.some(d=>!i.wheres.some(l=>l.span.start===d.span.start));if(a.length===0&&!c&&!f){const d={start:s.end,end:i.span.end},l=e.parsed.commentIn(d);if(l)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(l.start,l.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...d,text:""});return}return Vu(e,t,i)}async function Uu(e,t,n={}){if(!(e.includes(`\r
139
- `)&&!/(?<!\r)\n/.test(e)))return Ml(e,t,n);const s=await Ml(e.replace(/\r\n/g,`
140
- `),t,n);return Hs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
- `)}}async function Ml(e,t,n){const r=await Us(e);if(Gs(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=hv(s,t),o=ev(s,i,n.visibleSources);if("reason"in o)return o;const a=mv(s,i);if(a)return{ok:!1,reason:a};const c=await Iu(e);if(Cu(c))return{ok:!1,reason:`Cannot edit a file that will not open: ${c.reason}`};const f=e.split(`
142
- `),d=Ym(e),l=g=>({start:d[g],end:g+1<d.length?d[g+1]:e.length}),u=g=>/^\s*/.exec(f[g])?.[0]??"",h=[],p={...o,sourceText:e,parsed:c.parsed,lines:f,starts:d,wholeLine:l,indentOf:u,current:s,next:i,edits:h};for(const g of[nv,ov,lv,av,cv,dv,uv,fv,gv]){const v=g(p);if(v)return v}const y=g=>{const{drills:v,localGivens:x,description:b,...T}=g,C=g.tiles.map(M=>{if(Ie(M))return M;if(M.filters?.length)return Ks(M);const{filters:E,...O}=M;return Ks(O)});return{...T,...b===void 0?{}:{description:Lu(b)},tiles:C,...v?.length?{drills:[...v].sort((M,E)=>qs(M).localeCompare(qs(E)))}:{},...x?.length?{localGivens:x}:{}}};if(h.length===0)return be(y(s))!==be(y(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const w=Xm(e,h);if((await wl(e)).length===0){const g=await wl(w);if(g.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${g[0]}). Your changes are still here.`}}const _=await Us(w);return Gs(_)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${_.reason}`}:be(y(_.document))!==be(y(i))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:w}}function Hu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=ke.usePublisherTheme(),i=s.ui,o=k.useId(),[a,c]=k.useState(!1),f=k.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:d,patch:l,close:u,discard:h}=Ul(f,a,x=>n(x.text),()=>c(!1)),p=a&&d!==void 0&&d.text!==e,y=d!==void 0&&d.text!==e?xs(d.text):void 0;hu(p,()=>y!==void 0?!1:(u(),!0));const w=k.useRef(!1);k.useEffect(()=>{a||(w.current=!1)},[a]);const _=k.useCallback(x=>{!x||w.current||(w.current=!0,x.setSelectionRange(x.value.length,x.value.length))},[]);if(!a||d===void 0){const x=e.trim()?xs(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():c(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),c(!0)))},sx:[{minHeight:24},uu(s,"prose")],children:[e.trim()?m.jsx(S.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),x&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:x})]})}const g=d.text!==e?xs(d.text):void 0,v=()=>{g===void 0&&u()};return m.jsxs($.Box,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx($.InputBase,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:d.text,placeholder:t,error:g!==void 0,inputRef:_,inputProps:{"aria-label":"Markdown","aria-describedby":o,...g!==void 0?{"aria-invalid":!0}:{}},onChange:x=>l(b=>{b.text=x.target.value}),onKeyDown:x=>{x.key==="Escape"?(x.preventDefault(),h(),c(!1)):x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),v())},onBlur:()=>u(),sx:{p:0,...i.type.prose,color:"inherit",maxWidth:S.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),g!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g}),m.jsxs($.Typography,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Xt,"↩ done · Esc cancels"]})]})}const xv="Write markdown: # heading, **bold**, - list";function wv({tile:e,onChange:t}){return m.jsx(S.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Hu,{markdown:e.markdown,placeholder:xv,onCommit:t})})}const _v={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},qu=(e,t)=>t===0?e:qu(t,e%t);function kv(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=qu(e,t),s=_v[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function Sv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,onRemove:f,removeBlocked:d,resizing:l=!1,width:u,onResizeStart:h,onResizeMove:p,onResizeEnd:y,children:w}){const{theme:_}=ke.usePublisherTheme(),g=_.ui;return m.jsx(xm,{id:We(e),index:t,children:({ref:v,handleRef:x})=>m.jsxs($.Box,{ref:v,onClick:a,onPointerDown:b=>{b.button===0&&a()},role:"group",className:S.reportClasses.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":We(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ku(_,{selected:n,flash:r,bare:i}),...!i&&{[`& .${S.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:_.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${_.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...S.removeBadgeRevealSx,...n&&{[`& .${S.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[w,m.jsx($.Box,{ref:x,"aria-label":`Move ${Qn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(S.RemoveBadge,{label:`Remove ${Qn(e)}`,onRemove:f,...d?{disabledReason:d}:{},inset:i?S.BARE_RING_OFFSET_PX:0}),!Ie(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Qn(e)}`,onClick:b=>{b.stopPropagation(),c(b.currentTarget)},sx:{position:"absolute",top:i?0:`${Il}px`,right:i?0:`${Il}px`,borderRadius:g.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(Cv,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${S.reportClasses.widthHandle}`,[Eu]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Qn(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:b=>{if(!u)return;const T=b.key==="ArrowRight"?u.span+1:b.key==="ArrowLeft"?u.span-1:b.key==="Home"?1:b.key==="End"?u.columns:void 0;T!==void 0&&(b.preventDefault(),b.stopPropagation(),u.onStep(Math.min(Math.max(T,1),u.columns)))},onPointerDown:h,onPointerMove:p,onPointerUp:y,onPointerCancel:y,onClick:b=>b.stopPropagation(),sx:b=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:l||n?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${_.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:g.radius.control,border:`1px solid ${l?_.accent:S.edgeColor(_.cardBorder)}`,bgcolor:b.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${S.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,borderRight:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,boxSizing:"border-box",opacity:l?1:.7},"&:hover::before":{borderColor:_.accent},"&:hover::after":{borderColor:_.accent,opacity:1}}),children:l&&u&&m.jsx($.Box,{"aria-hidden":!0,sx:b=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:g.radius.control,bgcolor:b.palette.text.primary,color:b.palette.background.paper,...g.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:kv(u.span,u.columns)})}),o&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Qn(e)}`,onClick:b=>{b.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${S.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:_.tileTitle,bgcolor:_.tile,border:_.cardBorder,opacity:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:_.tile}},children:m.jsx(S.AddIcon,{sx:{fontSize:14}})})]})})}const Il=14,Ci=7,Ku=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=S.BARE_RING_OFFSET_PX})=>{const i=e.ui,o=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,c=`outline-color ${S.MOTION_FAST}, border-color ${S.MOTION_FAST}, opacity ${S.MOTION_FAST}, box-shadow ${S.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof s=="number"?`${-s}px`:`${-s.y}px ${-s.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:c,...S.reducedMotionSx}}:{borderRadius:i.radius.tile,"& > .MuiPaper-root":{transition:c,...S.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:c,...S.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:S.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function $v({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=ke.usePublisherTheme();return m.jsxs(S.TileCard,{chrome:r,children:[m.jsx(S.TileHeading,{title:t?.title??_n(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Tv({after:e}){const{theme:t}=ke.usePublisherTheme();return m.jsx(wm,{id:gu(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx($.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...S.reducedMotionSx}})})}function Ev({columns:e}){const{theme:t}=ke.usePublisherTheme();return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${S.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>m.jsx($.Box,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function Cv(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function Ov({editor:e,reorder:t,resizing:n,gridBox:r,defaultSpan:s=1,rules:i,canAdd:o,selected:a,flash:c,menuIndex:f,onSelect:d,onOpenMenu:l,onRemove:u,removeBlocked:h,openAdd:p,editTile:y,renderTile:w}){const{dragging:_,preview:g,onDragStart:v,onDragOver:x,onDragEnd:b}=t,{columns:T}=i,{resize:C,startResize:M,onResize:E,endResize:O}=n,P=N=>N.colspan===void 0?{...N,colspan:s}:N,A=(C!==void 0?e.document.tiles.map((N,I)=>I===C.index?{...N,colspan:C.span}:N):g??e.document.tiles).map(P),L=e.document.tiles.length===0,W=_||C!==void 0?zg(A,T):A.map(pu),U=N=>Dv(N,_n(N),y);return m.jsxs(m.Fragment,{children:[m.jsx(wg,{sensors:vm,onDragStart:v,onDragOver:x,onDragEnd:b,children:m.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[i.widths&&(_||C!==void 0)&&m.jsx(Ev,{columns:T}),m.jsx(S.DashboardGrid,{tiles:W,columns:T,rowGapPx:S.GRID_GAP_PX,keyOf:N=>N.kind==="gap"?gu(N.after):We(N.tile),renderTile:N=>{if(N.kind==="gap")return m.jsx(Tv,{after:N.after});const{tile:I,index:z}=N;return m.jsx(Sv,{tile:I,index:z,selected:z===a,flash:We(I)===c,menuOpen:f===z,bare:Ie(I),...i.insertBetween&&o&&z<e.document.tiles.length-1?{onInsertAfter:()=>p(z+1)}:{},...i.widths&&Mv(I)?{resizing:C?.index===z,width:{span:I.colspan??1,columns:T,onStep:V=>{V!==(I.colspan??1)&&e.update(B=>{const G=B.tiles[z];G&&(G.colspan=V)})}},onResizeStart:V=>M(V,z),onResizeMove:E,onResizeEnd:O}:{},onSelect:()=>d(z),onOpenMenu:V=>l(V,z),onRemove:()=>u(z),...h?{removeBlocked:h}:{},children:Ie(I)?m.jsx(wv,{tile:I,onChange:V=>y(We(I),B=>{Ie(B)&&(B.markdown=V)})}):w?w(I,U(I),"card"):m.jsx($v,{tile:I,heading:U(I)})})}})]})}),i.insertBetween&&o&&!L&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Dv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=We(e),s=i=>o=>n(r,a=>{oe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:m.jsx(wo,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(wo,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Mv=e=>Ie(e)||e.declaration.kind!=="inherited",Iv={x:12,y:6};function jv({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:i}=ke.usePublisherTheme();return m.jsx(S.ReportHeader,{actions:n,title:m.jsx(wo,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(S.TextTileFrame,{sx:{position:"relative",overflow:"visible",...Ku(i,{selected:r,bare:!0,ringOffset:Iv})},children:m.jsx(Hu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const Pv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=S.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:c})=>i({type:"report.saved",tiles:o,structural:a,where:r,durationMs:c}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}};function Rv(e,t){const n=k.useRef(t);n.current=t;const r=k.useRef(e);r.current=e;const s=k.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.()}),[]),{status:i,saveTarget:o,canUndo:a,canRedo:c,add:{filterUnavailable:f}}=t,d=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,h=t.add.filter!==void 0,p=t.exit!==void 0,y=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:_}=t,g=t.restored?.savedAt,v=t.restored?.stale??!1,x=t.restored?.pending??!1,b=t.restore!==void 0,T=t.dismissRestored!==void 0,C=k.useMemo(()=>({status:i,saveTarget:o,...d?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:c,redo:s.redo,add:{...l?{tile:s.addTile}:{},...u?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...p?{exit:s.exit}:{},...y?{done:s.done}:{},..._!==void 0?{draftKeptAt:_}:{},...w?{discard:s.discard}:{},...g!==void 0?{restored:{savedAt:g,stale:v,pending:x}}:{},...b?{restore:s.restore}:{},...T?{dismissRestored:s.dismissRestored}:{}}),[s,i,o,d,a,c,l,u,h,f,p,y,_,w,g,v,x,b,T]),M=e!==void 0;k.useEffect(()=>{r.current?.(C)},[C,M]),k.useEffect(()=>()=>r.current?.(void 0),[])}function Av({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:i,fixedFilters:o,onOpenModel:a,startingValues:c,onStartingValue:f,children:d}){const l=d!=null,u=k.useMemo(()=>{const h=new Map(e.map(p=>[p.name,p]));return{stateOf:p=>{const y=o?.get(p);if(y!==void 0){const{modelPath:g}=y;return{origin:"model",fixed:y.reason,...g!==void 0&&a?{openModel:()=>a(g)}:{}}}const w=h.get(p);if(!w)return;const _=t(w.name,w.type);return{origin:w.origin,..._.length>0?{problem:`Cannot filter on ${_.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:l?e.filter(p=>p.boundTiles===0&&!o?.has(p.name)).map(p=>({name:p.name,label:p.label??p.name})):[],onEdit:p=>{const y=h.get(p);y&&n(y)},onRemove:i,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...f?{startingValueOf:p=>c?.[p],setStartingValue:f}:{}}},[e,t,l,n,i,r,s,o,a,c,f]);return m.jsx(S.StickyControls,{children:m.jsx(S.FilterEditingContext.Provider,{value:u,children:l?d:m.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(h=>m.jsx(S.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(S.AddFilterButton,{})]})})})}function Lv(e,t){const n=new Map(e.tiles.map((r,s)=>[We(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(We(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return We(s)}}function Bv({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(w=>r(_=>typeof _=="object"&&_.tile===w?_:{tile:w}),[]),a=k.useCallback(()=>r(w=>w==="description"?w:void 0),[]),c=k.useCallback(()=>r("description"),[]),f=k.useCallback(()=>r(void 0),[]),d=n!==void 0;k.useEffect(()=>{if(!d)return;const w=_=>{const g=_.target;g instanceof Element&&g!==document.documentElement&&g.closest(Fv)===null&&f()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[d,f]);const[l,u]=k.useState(void 0),h=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const w=p.current;if(p.current=e.document,!h.current)return;h.current=!1;const _=Lv(w,e.document);if(_===void 0)return;u(_),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===_)?.scrollIntoView?.({block:"nearest",behavior:S.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(l===void 0)return;const w=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(w)},[l]);const y=k.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:f,flash:l,stepEditor:y}}const Fv=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function zv({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,c]=k.useState(!1),f=k.useRef(r);f.current=r;const d=k.useRef(s);d.current=s;const l=k.useRef(0),u=k.useCallback(async()=>{const y=++l.current;c(!1),o("saving");try{await f.current()}catch{l.current===y&&o("idle");return}l.current===y&&c(!0)},[]);k.useEffect(()=>{if(i==="waiting"){if(t)return;e?u():(o("idle"),d.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[i,a,t,e,u]);const h=k.useCallback(()=>{i==="idle"&&(e?o("asking"):d.current())},[i,e]),p=k.useCallback(()=>{i==="idle"&&(e?n?t?o("waiting"):u():o("asking"):d.current())},[i,e,n,t,u]);return{requestExit:h,saveAndExit:p,finishing:i==="saving"||i==="waiting",dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):u())}}}}function Wv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,keepsEdits:o=!1,report:a,unit:c,prepare:f,shortcuts:d}){const[l,u]=k.useState(!1),[h,p]=k.useState(!1),y=k.useRef(null),w=k.useRef(a);w.current=a;const _=e.dirty||i,g=(e.edited??e.dirty)||i,v=o?i:g;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(g,v)},[g,v,n]);const x=k.useRef(n);x.current=n,k.useEffect(()=>()=>x.current?.(!1,!1),[]);const b=k.useRef(c);b.current=c,k.useEffect(()=>{p(!1)},[e.document]);const T=k.useCallback(()=>{u(!0),p(!1);const I=S.now(),{structural:z}=e,V=w.current.size;return e.save().then(B=>{B.ok===!0?w.current.saved({size:V,structural:z,durationMs:S.now()-I}):w.current.refused(B.reason)}).finally(()=>u(!1))},[e]),C=k.useRef(!1),M=k.useRef(!1);k.useEffect(()=>{!M.current||l||(M.current=!1,y.current?.focus())},[h,l]);const E=k.useCallback(()=>{if(!t||l||C.current||!e.canUndoSave)return;C.current=!0,u(!0);const I=S.now(),z=e.lastSave?.structural??!1,V=w.current.size;return e.undoSave().then(B=>{B.ok===!0?(M.current=!0,p(!0),w.current.undone({size:V,structural:z,durationMs:S.now()-I})):w.current.undoRefused(B.reason)}).finally(()=>{C.current=!1,u(!1)})},[t,l,e]),O=k.useCallback(()=>{if(!(!t||!e.dirty||l))return T()},[t,e,l,T]),P=k.useRef(O);P.current=O;const A=k.useCallback(()=>{const I=()=>P.current();return f?f(I):I()},[f]),L=zv({dirty:g,saving:l,canSave:!!t,save:A,onExit:()=>r?.()});rf(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:A}:{},paused:L.dialog.open}),[d,e,t,A,L.dialog.open]));const W=!!t&&!l&&e.canUndoSave,U=e.lastSave,N={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:_,saving:l,saveButton:y,...t?{onSave:A}:{},...r?{onExit:L.requestExit}:{}};return{saving:l,save:A,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:E,canUndoSave:W,lastSave:U,toolbarProps:N}}const Nv=1;function Yu(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Yu(a,`${t}${i}.`,n-1))}}}return r}function Gv(e){const t=new Map;for(const n of Xu(e))t.set(n.name,Yu(n.schema?.fields,"",Nv));return t}function Xu(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Vv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&ef.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Uv(e){const t=new Map;for(const n of Xu(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Vv)&&r.add(s.name)}t.set(n.name,r)}return t}function jl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Pl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.path||e.modelPath||"";function Qu(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=S.exportedSources(a.modelInfo);i.set(a,f);for(const{name:d}of a.sources??[])d&&o.set(d,[...o.get(d)??[],c]);for(const d of f)s.set(d,[...s.get(d)??[],c])}for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=Gv(a),d=Uv(a);for(const l of a.sources??[]){const u=l.name;if(!u||!i.get(a)?.has(u)||r.has(u))continue;r.add(u);const h=(l.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:u,modelPath:c,exporters:s.get(u)??[c],visibleIn:o.get(u)??[c],...S.docOf(l.annotations)?{description:S.docOf(l.annotations)}:{},views:(l.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...S.docOf(p.annotations)?{description:S.docOf(p.annotations)}:{},...S.chartOf(p.annotations)?{chart:S.chartOf(p.annotations)}:{},...d.get(u)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:f.get(u)??[]})}}return{sources:n}}function Hv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const p=new Set((t.localGivens??[]).map(y=>y.name));return(n??[]).filter(y=>!p.has(y.name))},[t,n]),a=k.useMemo(()=>bf(e.document,o),[e.document,o]),c=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,jl(r,p.base)])),[r,e.document.sources]),f=k.useCallback(p=>c.get(p.source)??jl(r,p.source),[c,r]),d=(p,y)=>{const w=[];for(const _ of e.document.tiles){if(!oe(_))continue;const g=f(_);if(!g)continue;const v=new Map(g.map(x=>[x.name,x.type]));for(const x of _.filters??[])x.given===p&&(!v.has(x.field)||!yr(y,v.get(x.field)))&&w.push(`${x.field} on ${_.label??_.name} (${e.document.sources.find(b=>b.name===_.source)?.base??_.source})`)}return w},l=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:f,unknownFieldsOf:d,available:l,applyFilter:(p,y,w)=>{i(void 0),e.update(_=>{w&&Ef(_,w),Tf(_,p,y)})},dropControl:p=>{i(void 0),e.update(y=>Cf(y,p))}}}function qv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[i,o]=k.useState({stack:[e.document],index:0}),[a,c]=k.useState(e.source),[f,d]=k.useState(void 0),[l,u]=k.useState(e.document),[h,p]=k.useState(e.replaces),[y,w]=k.useState(!1),_=i.stack[i.index],g=k.useRef(i);g.current=i;const v=k.useRef(!1),[x,b]=k.useState(!1),T=B=>{v.current=B,b(B)},[C,M]=k.useState(void 0),E=k.useCallback(B=>{d(void 0),o(G=>{const Q=structuredClone(G.stack[G.index]);if(B(Q),JSON.stringify(Q)===JSON.stringify(G.stack[G.index]))return G;const X=[...G.stack.slice(0,G.index+1),Q].slice(-100);return{stack:X,index:X.length-1}})},[]),O=k.useCallback(()=>{d(void 0),o(B=>B.index>0?{...B,index:B.index-1}:B)},[]),P=k.useCallback(()=>{d(void 0),o(B=>B.index<B.stack.length-1?{...B,index:B.index+1}:B)},[]),A=k.useCallback(async(B,G)=>{try{return await t(B,G)}catch(Q){return{ok:!1,reason:`Could not build the file: ${Q instanceof Error?Q.message:String(Q)}`}}},[t]),L=k.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const B={source:a,saved:l,history:g.current,replacing:h,unwritten:y},G=s?.(l,_)??!1,Q=r?.(l,_)??!1;T(!0);try{const Z=await A(a,_);if(Hs(Z))return d(Z.reason),{ok:!1,reason:Z.reason};try{await n?.(Z.source,{purpose:"save",document:_})}catch(H){const Pe=`Could not save: ${H instanceof Error?H.message:String(H)}`;return d(Pe),{ok:!1,reason:Pe}}c(Z.source),u(_),p(void 0),w(!1);const X=G?{stack:[_],index:0}:B.history;return o(H=>H===B.history?X:G?{stack:[H.stack[H.index]],index:0}:H),M(n?{before:B,after:X,lastSave:{before:h??a,after:Z.source,structural:Q,clearsHistory:G}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[_,A,n,a,l,h,y,s,r]),W=k.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||C===void 0||C.after!==g.current)return{ok:!1,reason:"There is no save to undo."};const{before:B}=C;T(!0);try{await n(B.replacing??B.source,{purpose:"undo",document:B.saved})}catch(G){const Q=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return d(Q),{ok:!1,reason:Q}}finally{T(!1)}return c(B.source),u(B.saved),p(B.replacing),w(B.unwritten||B.replacing!==void 0),o(G=>G===C.after?B.history:G),M(void 0),d(void 0),{ok:!0}},[n,C]),U=k.useMemo(()=>y||JSON.stringify(_)!==JSON.stringify(l),[_,l,y]),N=k.useMemo(()=>r?.(l,_)??!1,[_,l,r]),I=k.useMemo(()=>s?.(l,_)??!1,[_,l,s]),z=C!==void 0&&C.after===i,V=k.useCallback(async()=>{const B=await A(a,_);return Hs(B)?{ok:!1,reason:B.reason}:{ok:!0,source:B.source}},[_,A,a]);return{document:_,saved:l,source:a,canUndo:i.index>0,canRedo:i.index<i.stack.length-1,dirty:U,edited:U,...f===void 0?{}:{error:f},update:E,undo:O,redo:P,save:L,preview:V,structural:N,clearsHistory:I,canUndoSave:z&&!x&&n!==void 0,...z?{lastSave:C.lastSave}:{},undoSave:W}}const Kv=(e,t)=>{const n=new Set(e.tiles.map($o)),r=new Set(t.tiles.map($o));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Yv(e){const{visibleSources:t,...n}=e,r=k.useCallback((s,i)=>Uu(s,i,t?{visibleSources:t}:{}),[t]);return qv({...n,splice:r,structural:Kv})}function Xv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(c=>{s.current=()=>c(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}function Qv({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(!1),[d,l]=k.useState(void 0),u=b=>{l(b),f(!0)},h=()=>f(!1),p=b=>{f(!1),e.update(T=>cf(T,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:d})),s(d??e.document.tiles.length)},y=()=>_(d),w=()=>_(void 0),_=b=>{f(!1),e.update(T=>{const C=new Set(T.tiles.filter(Ie).map(E=>E.name));let M=1;for(;C.has(`text_${M}`);)M++;T.tiles.splice(b??T.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}})}),s(b??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:c,openAdd:u,closeAdd:h,addTile:p,addText:y,appendText:w,editTile:(b,T)=>e.update(C=>{const M=C.tiles.find(E=>We(E)===b);M&&T(M)}),removeTile:b=>{a(void 0),i(),e.update(T=>{T.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const T=e.document.tiles[b],C=T&&oe(T)&&$s(T)===void 0?b+1:void 0;e.update(M=>{df(M,b)}),C!==void 0&&s(C)}}}var Zv=Object.defineProperty,Jv=Object.defineProperties,ey=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,ty=Object.prototype.hasOwnProperty,ny=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?Zv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dn=(e,t)=>{for(var n in t||(t={}))ty.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))ny.call(t,n)&&Ll(e,n,t[n]);return e},un=(e,t)=>Jv(e,ey(t));function ry(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function as(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Oi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sy(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(v,x)=>v===x||v!==null&&typeof v=="object"&&"id"in v&&v.id===x;if(Array.isArray(e)){const v=e.findIndex(b=>c(b,i.id)),x=e.findIndex(b=>c(b,o.id));if(v===-1||x===-1){if(Oi(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==v)return n(e,v,b)}return n(e,v,x)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[v,x]of f)if(d===-1&&(d=x.findIndex(b=>c(b,i.id)),d!==-1&&(l=v)),u===-1&&(u=x.findIndex(b=>c(b,o.id)),u!==-1&&(h=v)),d!==-1&&u!==-1)break;if(d===-1&&Oi(i)){const v=i.initialGroup==null?void 0:as(e,i.initialGroup),x=i.initialIndex,b=i.group==null?void 0:as(e,i.group),T=i.index;if(v==null||b==null||v===b&&x===T)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return un(dn({},e),{[v]:n(e[v],x,T)});const C=e[v][x];return un(dn({},e),{[v]:[...e[v].slice(0,x),...e[v].slice(x+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,y=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const v=as(e,o.id);if(v!=null){const x=o.shape&&y.y>o.shape.center.y?e[v].length:0;h=v,u=x}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Oi(i)){const v=i.group==null?void 0:as(e,i.group),x=i.group!=null&&v!==l,b=i.index!==d;if(x||b){const T=i.group==null?l:v;if(T!=null){if(l===T)return un(dn({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return un(dn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return un(dn({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(y.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return un(dn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function iy(e,t){return sy(e,t,ry)}function oy({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:l=>{const{source:u,target:h}=l.operation;if(!u||!h)return;const p=i.current??e;let y;if(h.type===Tu){const{after:w}=h.data,_=p.findIndex(x=>We(x)===u.id);if(_<0||w===u.id)return;const v=p.filter((x,b)=>b!==_).findIndex(x=>We(x)===w)+1;y=Fg(p,_,v)}else{const w=p.map(We),_=iy(w,l);if(_.every((v,x)=>v===w[x]))return;const g=new Map(p.map(v=>[We(v),v]));y=Bg(_.map(v=>g.get(v)),e.map(v=>v.break??!1))}i.current=y,s(y)},onDragEnd:l=>{a(!1);const u=i.current;if(i.current=void 0,s(void 0),l.canceled||!u)return;t(u);const h=u.findIndex(p=>We(p)===l.operation.source?.id);h>=0&&n(h)}}}const Di=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function ay({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),c=u=>{a.current=u,o(u)};return k.useEffect(()=>()=>Di(!1),[]),{resize:i,startResize:(u,h)=>{const p=n.current?.getBoundingClientRect(),y=u.currentTarget.parentElement?.getBoundingClientRect();if(!p||!y)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Di(!0),r(h);const w=e[h]?.colspan??1;c({index:h,span:w,from:w,left:y.left,track:(p.width-S.GRID_GAP_PX*(t-1))/t})},onResize:u=>{const h=a.current;if(!h)return;const p=u.clientX-h.left,y=Math.round((p+S.GRID_GAP_PX)/(h.track+S.GRID_GAP_PX)),w=Math.min(Math.max(y,1),t);w!==h.span&&c({...h,span:w})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Di(!1);const h=a.current;if(!h)return;const{index:p,span:y,from:w}=h;c(void 0),!(u.type==="pointercancel"||y===w)&&s(p,y)}}}function Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,renderViewPreview:a,controls:c,givens:f,catalog:d,toolbar:l,dashboards:u,onEvent:h,savesTo:p="package",saveLabel:y,replaces:w,modelPath:_,visibleSources:g,addFilterDisabledReason:v,fixedFilters:x,onOpenModel:b,takenGivenNames:T,onControlsChange:C,draftKey:M}){const E=Yv({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...g?{visibleSources:g}:{}}),O=S.useReportDraft(M,E,e),P=k.useRef(null),{selected:A,descriptionSelected:L,selectTile:W,deselectTile:U,selectDescription:N,clearSelection:I,flash:z,stepEditor:V}=Bv({editor:E,gridBox:P}),B=S.layoutRules(E.document.layout,E.document.columns),{columns:G}=B,Q=_?.split("/").at(-1)?.replace(/\.malloy$/,""),Z=oy({tiles:E.document.tiles,commit:q=>E.update(ae=>{ae.tiles=q}),onLanded:W}),{dragging:X}=Z,H=S.useDefaultTileSpan(P,G),Pe=k.useMemo(()=>E.document.tiles.map(q=>q.colspan===void 0?{...q,colspan:H}:q),[E.document.tiles,H]),ve=ay({tiles:Pe,columns:G,gridBox:P,onStart:W,commit:(q,ae)=>E.update(se=>{const ue=se.tiles[q];ue&&(ue.colspan=ae)})}),pe=Qv({editor:E,rules:B,modelPath:_,textHeld:g!==void 0,selectTile:W,deselectTile:U}),{menu:Se,addingTile:ee,openAdd:Re}=pe,ce=Hv({editor:E,opened:t,givens:f,catalog:d}),{filterDialog:ie,setFilterDialog:$e}=ce,[de,xe]=k.useState(void 0),{draftDirty:we,openDraft:Ge,prepare:me}=Xv({editorDirty:E.dirty}),Ae=k.useMemo(()=>({escape:()=>{!Se&&!ie&&!ee&&de===void 0&&I()},nudge:q=>{if(X||A===void 0||!B.widths)return;const ae=E.document.tiles[A];if(!ae||oe(ae)&&ae.declaration.kind==="inherited")return;const se=S.nudgedSpan(ae.colspan??H,q,G);se!==(ae.colspan??H)&&E.update(ue=>{ue.tiles[A].colspan=se})}}),[H,E,Se,ie,ee,de,I,A,G,B,X]),Fe=Wv({editor:V,extraDirty:we,keepsEdits:M!==void 0&&O.keeping,prepare:me,unit:{name:"tile",count:q=>q.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:Ae,report:Pv({size:E.document.tiles.length,path:_??"",layout:E.document.layout,savesTo:p,onEvent:h})}),D=E.document.tiles.length===0,{toolbarProps:R}=Fe,j=O.restored,F={status:Fe.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:y??Pi[p],...O.keptAt!==void 0?{draftKeptAt:O.keptAt}:{},...(R.dirty||j?.pending)&&M!==void 0?{discard:O.discard}:{},...j?{restored:j}:{},...j&&!j.pending?{dismissRestored:O.dismissRestored}:{}};Rv(C,{...F,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...d?{tile:()=>pe.openAdd()}:{},text:pe.appendText,...v!==void 0?{filterUnavailable:v}:D?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>$e({})}},...R.onExit?{exit:R.onExit}:{},...Fe.done?{done:Fe.done}:{},...j?.pending?{restore:O.restoreOffered}:{}});const J=C?void 0:m.jsx(sf,{...Fe.toolbarProps,...l?{actions:l}:{},...d?{onAddTile:()=>Re()}:{},savesTo:p,...y?{saveLabel:y}:{},...M!==void 0&&R.onSave?{saveStatus:F}:{}});return m.jsx(fu.Provider,{value:Ge,children:m.jsx($.Stack,{className:S.reportClasses.builder,"data-saves-to":p,sx:{gap:0,mx:`-${Ci}px`},children:m.jsxs(S.ReportPage,{layout:B.layout,sx:{px:`${Ci}px`,pb:`${Ci}px`},header:m.jsx(jv,{editor:E,documentSlug:Q,actions:J,descriptionSelected:L,selectDescription:N}),controls:D?void 0:m.jsx(Av,{controls:ce.controlList,unknownFieldsOf:ce.unknownFieldsOf,onEdit:q=>$e({control:q}),onAdd:()=>$e({}),...v?{addDisabledReason:v}:{},onRemove:ce.dropControl,...x?{fixedFilters:x}:{},...b?{onOpenModel:b}:{},...E.document.startingGivens?{startingValues:E.document.startingGivens}:{},onStartingValue:(q,ae)=>E.update(se=>{const ue={...se.startingGivens??{}};ae===void 0?delete ue[q]:ue[q]=ae,Object.keys(ue).length>0?se.startingGivens=ue:delete se.startingGivens}),children:c}),children:[D&&m.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),d&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),onClick:()=>Re(),children:"Add tile"})]}),j?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:O.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:O.discard,children:"Discard"})]}),children:`You have unsaved edits from ${Ii(j.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),E.error&&m.jsx($.Alert,{severity:"warning",children:E.error}),m.jsx(Ov,{editor:E,reorder:Z,resizing:ve,gridBox:P,defaultSpan:H,rules:B,canAdd:!!d,selected:A,flash:z,menuIndex:Se?.index,onSelect:W,onOpenMenu:(q,ae)=>{W(ae),pe.setMenu({anchor:q,index:ae})},onRemove:pe.removeTile,...E.document.tiles.length===1&&E.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:Re,editTile:pe.editTile,...o?{renderTile:o}:{}}),m.jsx(Bf,{editor:E,catalog:d,columns:G,dashboards:u,bindings:ce,tiles:pe,drillSource:de,setDrillSource:xe,exitDialog:Fe.exitGuard.dialog,...a?{renderViewPreview:a}:{},...T?{takenGivenNames:T}:{}})]})})})}const ly=S.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),cy=S.createSvgIcon(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),dy=S.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function uy({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=ke.usePublisherTheme(),i=S.edgeColor(s.cardBorder),o=S.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,c]=k.useState(null),f=e?.save!==void 0&&e.status!=="saved",d=e?.done??n,l=f&&e?.done===void 0,u=e?.add,h=u!==void 0&&(u.tile!==void 0||u.text!==void 0||u.filter!==void 0||u.filterUnavailable!==void 0),p=y=>()=>{c(null),y?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:S.reportClasses.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(Nl,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:_s(s.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:_s(s.ui),children:m.jsx(zl,{fontSize:"small"})})})}),h&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),endIcon:m.jsx(S.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:y=>c(y.currentTarget),sx:{...vr(i,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>c(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:fy(i,s.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(Mi,{icon:m.jsx(cy,{}),title:"Tile",detail:"A view from the model",onClick:p(u.tile)}),u?.text&&m.jsx(Mi,{icon:m.jsx(dy,{}),title:"Text",detail:"Prose between the tiles",onClick:p(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Mi,{icon:m.jsx(ly,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:p(u.filter)})]})]})]})]}),(d||l)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:ks}),d&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:d,sx:{...vr(i,o,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx($.Tooltip,{title:`Save (${Xt}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...vr(i,o,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const fy=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Mi({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:i}=ke.usePublisherTheme(),o=i.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:o.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:o.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:i.accent,bgcolor:`color-mix(in srgb, ${i.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function hy(e,t,n=new Set){const r=new Set;for(const o of e.tiles)for(const a of oe(o)?o.filters??[]:[])r.add(a.given);const s=[],i=new Set;for(const o of e.localGivens??[])r.has(o.name)&&(i.add(o.name),s.push(S.localGivenSpec(o)));for(const o of t)o.name===void 0||i.has(o.name)||!(r.has(o.name)||n.has(o.name))||(i.add(o.name),s.push(o));return s}function py(e,t,n){const r=new Map;for(const i of t.tiles)oe(i)&&r.set(wn(`${i.source} -> ${i.name}`),new Set((i.filters??[]).map(o=>o.given)));const s=new Set;for(const i of e.tiles){if(!oe(i))continue;const o=wn(`${i.source} -> ${i.name}`),a=r.get(o);for(const c of n.get(o)??[])a?.has(c)||s.add(c)}return s}function gy(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function my(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function wn(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function vy(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(w=>[w.name,w.type])),c=new Map((e.localGivens??[]).map(w=>[w.name,w.default])),f=e.sources.find(w=>w.name===i)?.scopedBy??[],d=new Set([...f,...s??[]].filter(w=>n.has(w))),l=new Set([...f,...s??[]]),u=[];for(const w of t.filters??[]){const _=`where: ${he.malloyPath(w.field)} ${w.op??"~"}`;if(n.has(w.given)){d.add(w.given),l.add(w.given),u.push(`${_} $${w.given}`);continue}if(!a.has(w.given))continue;l.add(w.given);const g=S.malloyLiteral(r.get(w.given),a.get(w.given))??gy(c.get(w.given));g!==void 0&&u.push(`${_} ${g}`)}const h=u.join(", "),p=t.chart,y=p==="none"||S.isChartPick(p)?S.chartLineText(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
- `):p==="default"&&my(t.declaration)?S.chartLineText("none"):void 0;return{...y?{annotation:y}:{},expression:`${i} -> ${o}`+(h?` + { ${h} }`:""),givenNames:Array.from(d),reads:s||l.size>0?Array.from(l):void 0}}function yy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=ke.useServer(),{data:c}=S.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(p=>p.path&&!p.error?[p.path]:[])}),f=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),d=k.useMemo(()=>i?(c??[]).filter(p=>!f.has(p)):[],[c,f,i]),l=Fl.useQueries({queries:d.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),u=c!==void 0&&i&&l.every(p=>p.isSuccess||p.isError),h=l.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>u?Qu(l.flatMap((p,y)=>p.data?[{...p.data,path:d[y]}]:[]),f):void 0,[u,d,h,f])}const by={};function xy({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,opened:i,replaces:o,onSave:a,onDirtyChange:c,onExit:f,onOpenModel:d,onControlsChange:l,draftKey:u,onEvent:h,savesTo:p,saveLabel:y,note:w}){const{apiClients:_}=ke.useServer(),[g,v]=k.useState(i.document.tiles.length>0);k.useEffect(()=>v(i.document.tiles.length>0),[i.generation,i.document]);const{data:x,isSuccess:b,isError:T}=S.useQueryWithApiError({...S.reportQueryOptions(_,{environmentName:t,packageName:n,path:r,versionId:s},S.BUILDER_HANDOFF_STALE_MS),enabled:g&&!e}),C=e?.modelPath??r,M=_y(i.source,e?.compileSource),E=S.useCompiledDocument({environmentName:t,packageName:n,modelPath:C,source:M.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&M.text!==void 0}),O=E.data?.document,P=e?E.isSuccess?O?.manifest??by:void 0:x,A=e?E.isSuccess:b,L=e?E.isError||M.problem!==void 0:T,W=e?S.documentPreamble(O?.cells):void 0,U=(E.data?.result.problems??[]).filter(j=>j.severity==="error"),N=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),I=e?.givens,z=k.useMemo(()=>new Set((P?.tiles??[]).flatMap(j=>j.restricted&&j.query?[wn(j.query)]:[])),[P]),{reports:V,settled:B}=S.useReportListing(t,n,s),G=k.useMemo(()=>V.map(j=>j.path).filter(j=>!!j&&j!==r&&j.endsWith(".malloy")).map(j=>j.replace(/\.malloy$/,"")),[V,r]),Q=yy({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:V,reportsSettled:B}),Z=k.useMemo(()=>e?(Q?.sources??[]).filter(j=>(j.visibleIn??j.exporters??[j.modelPath]).includes(C)).map(j=>j.name):void 0,[Q,e,C]),X=k.useMemo(()=>Q&&Z?{sources:Q.sources.filter(j=>Z.includes(j.name))}:Q,[Q,Z]),[H,Pe]=k.useState(i.document);k.useEffect(()=>Pe(i.document),[i.document]);const ve=k.useMemo(()=>a&&(async(j,F)=>{await a(j,F.document.layout),p==="package"&&v(F.document.tiles.length>0)}),[a,p]),pe=k.useMemo(()=>(P?.givens??[]).filter(j=>!(e&&j.secure===!0)&&!(j.name!==void 0&&N.has(j.name))),[P,N,e]),Se=k.useMemo(()=>new Set([...pe.map(j=>j.name).filter(j=>j!==void 0),...Object.keys(I??{})]),[pe,I]),ee=k.useMemo(()=>new Map((P?.tiles??[]).flatMap(j=>j.kind!=="text"&&j.query&&j.givenNames?[[wn(j.query),j.givenNames]]:[])),[P]),Re=k.useMemo(()=>py(H,i.document,ee),[H,i.document,ee]),ce=k.useMemo(()=>hy(H,pe,Re),[H,pe,Re]),ie=k.useMemo(()=>{const j=new Set(H.tiles.flatMap(se=>oe(se)?(se.filters??[]).map(ue=>ue.given):[])),F=new Set((H.localGivens??[]).map(se=>se.name)),J=[...new Set(H.imports.map(se=>se.from))],q=J.length===1?ky(r,J[0]):J.length===0&&e?e.modelPath:void 0,ae=se=>{const ue=H.sources.filter(rt=>rt.scopedBy?.includes(se)).map(rt=>rt.name);return ue.length>0?{reason:`Applied to every tile on ${ue.join(", ")} by this report's own source. Edit the file to change it.`}:F.has(se)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:q!==void 0?{reason:`Set in the model ${q}. Edit the model to change it.`,modelPath:q}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...Re].filter(se=>!j.has(se)).map(se=>[se,ae(se)]))},[H,Re,e,r]),{declaredTypes:$e,applied:de,panel:xe}=S.useDocumentControls({specs:ce,loaded:A,startingValues:P?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:P?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?C:P?.path,versionId:s,documentName:r,...W!==void 0?{preamble:W}:{},...I?{hostGivens:I}:{}}),we=k.useMemo(()=>S.missingRequiredGivens(ce,de,I),[ce,de,I]),Ge=k.useMemo(()=>Object.fromEntries(Object.entries(I??{}).filter(([j])=>!$e.has(j))),[I,$e]),me=!g||A||L,Ae=e!==void 0&&(M.problem!==void 0||E.isError||U.length>0),Fe=k.useMemo(()=>new Map(i.document.tiles.map(j=>[We(j),j])),[i.document]),D=k.useMemo(()=>function(F,J,q="card"){if(Ae)return m.jsxs(S.TileCard,{chrome:q,children:[m.jsx(S.TileHeading,{title:J?.title??_n(F),subtitle:J?J.subtitle:F.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!me)return m.jsxs(S.TileCard,{chrome:q,children:[m.jsx(S.TileHeading,{title:J?.title??_n(F),subtitle:J?J.subtitle:F.subtitle}),m.jsx(S.Loading,{text:"Running…"})]});const ae=ee.get(wn(`${F.source} -> ${F.name}`)),ue=W===void 0&&ae!==void 0&&wy(Fe.get(We(F)),F)?{expression:`${F.source} -> ${F.name}`,givenNames:[...ae],reads:[...ae]}:vy(H,F,Se,de,ae);return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:C,...W!==void 0?{preamble:W}:{},...z.has(wn(`${F.source} -> ${F.name}`))?{restricted:!0}:{},tile:ue.expression,...ue.annotation?{annotation:ue.annotation}:{},label:_n(F),chrome:q,subtitle:F.subtitle,...J?{heading:J}:{},borderless:F.borderless,givens:de,hostGivens:Ge,declaredTypes:$e,givenNames:ue.givenNames,...(()=>{const rt=S.waitingOn(we,ue.reads??ue.givenNames);return rt.length>0?{waitingFor:S.waitingText(rt)}:{}})(),ignoredFilters:S.tileIgnoredFilterLabels(ue.reads,ce),height:S.TILE_MAX_HEIGHT})},[H,Fe,me,Ae,we,Se,ee,t,n,s,C,W,z,de,Ge,$e,ce]),R=k.useMemo(()=>function(F){return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:F.modelPath,tile:`${F.base} -> ${F.view}`,...F.chart?{annotation:S.chartLineText(F.chart,F.chartCarried)}:{},label:F.label,borderless:!0,givens:de,hostGivens:Ge,declaredTypes:$e,givenNames:F.givens,height:200})},[t,n,s,de,Ge,$e]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&U.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",U.map(j=>j.message).join("; ")]}),we.length>0&&!Ae&&m.jsx($.Alert,{severity:"info",children:S.requiredPrompt(we)}),e&&M.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",M.problem]}),e&&E.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),m.jsx(Oa,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:i.source,document:i.document,fixedFilters:ie,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:D,renderViewPreview:R,givens:ce.filter(j=>j.name!==void 0).map(j=>({name:j.name,...j.label?{label:j.label}:{},...j.type?{type:j.type}:{},...j.suggest?.dimension?{field:j.suggest.dimension}:{}})),onChange:Pe,onDirtyChange:c,...f?{onExit:f}:{},...d?{onOpenModel:d}:{},...l?{onControlsChange:l}:{},...u!==void 0?{draftKey:u}:{},...X?{catalog:X}:{},dashboards:G,...h?{onEvent:h}:{},controls:A?m.jsx(S.GivensPanel,{...xe,layout:"bar"}):void 0,...ve?{onSave:ve}:{},savesTo:p,...y?{saveLabel:y}:{},...o!==void 0?{replaces:o}:{},modelPath:r,...e?{visibleSources:Z}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:w})})]})}function wy(e,t){return e!==void 0&&JSON.stringify(Bl(e))===JSON.stringify(Bl(t))}function Bl(e){const{label:t,subtitle:n,colspan:r,break:s,borderless:i,...o}=e;return o}function _y(e,t){const n=k.useRef(t);n.current=t;const r=t!==void 0,[s,i]=k.useState();return k.useEffect(()=>{if(!r)return;let o=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{o&&i({from:e,text:a})},a=>{o&&i({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{o=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function ky(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Sy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(void 0),[d,l]=k.useState(e===void 0),[u,h]=k.useState(!1),[p,y]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let w=!1;return y(void 0),(async()=>{try{const _=S.chooseWorkspace(await e.listWorkspaces(!1));if(w)return;if(a(_),_!==void 0&&(!n||_.authoritative)){const g=await e.getDocument(S.locatorFor(t,_.name,r,s,i)).catch(v=>{if(!S.isDocumentNotFound(v))throw v});if(w)return;f(g),h(g!==void 0)}}catch(_){if(w)return;y(S.storageErrorMessage(_))}w||l(!0)})(),()=>{w=!0}},[e,t,n,r,s,i]),{workspace:o,draft:c,setDraft:f,draftChecked:d,offered:u,setOffered:h,readFailure:p}}const $y=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Ty(e){const t=await Us(e);return Gs(t)?{ok:!1,reason:$y(t.reason,t.line)}:{ok:!0,document:t.document}}const Ey="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Cy="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Oy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:c,notebook:f,noun:d,legacyFormat:l,textHeld:u,startedAt:h,onEventRef:p}){const y=k.useRef({path:a,layout:c});y.current={path:a,layout:c};const w=k.useRef((xe,we)=>{try{p.current?.(S.withReportContext(xe,{...y.current,...we?{layout:we}:{}}))}catch{}}),_=e?.authoritative===!0,g=_&&r!==void 0,[v,x]=k.useState(void 0),b=(_||v===!0)&&t!==void 0,[T,C]=k.useState(void 0),[M,E]=k.useState(l?Ey:void 0),O=k.useRef(void 0),P=k.useRef(void 0),[A,L]=k.useState(void 0),W=k.useRef(i);W.current=i;const U=A!==void 0&&A.onFetch===i?A.text:s,N=k.useRef(U);N.current=U;const I=b?t:U,[z,V]=k.useState(!1),[B,G]=k.useState(void 0),[Q,Z]=k.useState(void 0),X=I!==void 0&&I!==Q,H=T?.source,ve=X&&(z||!_&&t!==void 0&&H===t&&t!==U)&&H!==void 0&&I!==B,pe=ve?H:X?I:H??I,Se=ve?I:void 0,ee=k.useRef(H);ee.current=H;const Re=k.useRef(I);Re.current=I;const ce=k.useRef("package");ce.current=b?_?"record":"draft":"package",k.useEffect(()=>{if(pe===void 0||!n||g||pe===ee.current)return;let xe=!1;const we=N.current,Ge=Re.current;return Ty(pe).then(me=>{if(!xe){if(me.ok===!1){E(me.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}E(void 0),O.current=void 0,P.current=we,L(void 0),G(void 0),Z(Ge),C(Ae=>({source:pe,document:me.document,...we!==void 0?{packageText:we}:{},generation:(Ae?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:ce.current,tiles:me.document.tiles.length,durationMs:S.now()-h.current},me.document.layout)}}).catch(me=>{if(xe)return;const Ae=`Could not read the ${d}: ${me instanceof Error?me.message:String(me)}`;E(Ae),w.current({type:"report.load_failed",surface:"edit",category:S.failureCategory(me)})}),()=>{xe=!0}},[pe,a,n,g,f,d,u,h]),k.useEffect(()=>{l&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),k.useEffect(()=>{!u||!n||T||r!==void 0||(_?t===void 0&&E("the host's storage has no document at this location."):E("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,T,r,_,t]);const ie=f&&!u&&!T&&n&&!b&&o&&s===void 0;return k.useEffect(()=>{ie&&(E(Cy),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[ie]),{authoritative:_,blockedOnRecord:g,resume:v,setResume:x,fromDraft:b,opened:T,setOpened:C,openError:M,savedHashRef:O,packageBaseRef:P,setWrote:L,fetchedAtRef:W,setDirty:V,setSeen:Z,held:Se,choose:xe=>{h.current=S.now(),G(xe?t:U),x(xe)},acceptHeld:()=>{h.current=S.now(),G(Se)}}}function Dy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:c,queryClient:f,mutable:d,textHeld:l,readFailure:u,authoritative:h,resume:p,setResume:y,setOpened:w,setDraft:_,setOffered:g,setSeen:v,setWrote:x,savedHashRef:b,packageBaseRef:T,fetchedAtRef:C}){const M=k.useCallback(B=>t===void 0?void 0:S.locatorFor(B,t.name,s,i,o),[t,s,i,o]),E=M(n),O=k.useCallback(async(B,G=n)=>{const Q=M(G);if(!e||!Q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(Q,B),w(Z=>Z&&{...Z,source:B}),_(B),(h||p===!0)&&v(B),h||y(Z=>Z??!1)},[e,M,n,h,p,w,_,v,y]),[P,A]=k.useState(void 0),L=k.useCallback(async B=>{const G=await S.expectedHashFor(b.current,T.current);if(G===void 0)throw new Error("The package file is still loading; try again.");const Q=["dashboard-editor-model",s,i,o,a,r];await S.writePackageFile({apiClients:c,queryClient:f,environmentName:s,packageName:i,modelPath:o,source:B,expectedHash:G,invalidateOnError:[Q],afterWrite:async Z=>{if(w(X=>X&&{...X,source:B}),x({text:B,onFetch:C.current}),v(B),b.current=Z,A(void 0),e&&E)try{await e.deleteDocument(E),_(void 0),g(!1)}catch(X){S.isDocumentNotFound(X)?(_(void 0),g(!1)):A(S.storageErrorMessage(X))}y(!1)},invalidate:[{queryKey:Q,wait:!0},{queryKey:S.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})}]}),S.invalidateReportQueries(f,s,i,o)},[c,s,i,o,a,r,e,E,f,b,T,C,w,x,v,_,g,y]),W=t?.writeable===!0,U=d===!0&&!l,{savesTo:N,pinnedPackageSave:I,writer:z}=S.saveTarget({authoritative:h,mutable:U,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!E&&W&&(!r||h),readFailed:u!==void 0});return{save:z==="storage"?O:z==="package"?L:void 0,savesTo:N,writer:z,pinnedPackageSave:I,takesWrites:U,supersedeFailure:P}}function Da(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:i,onControlsChange:o,keepDraft:a,kind:c,path:f,textSource:d}=e,l=e.layout??(c?S.layoutOfKind(c):"grid"),u=l==="linear",h=d!==void 0,{environmentName:p,packageName:y,versionId:w,namesBoth:_}=S.resolveEditorTarget(e),v=("resourceUri"in e?e.dashboard:e.dashboardName)??S.documentSlug(f)??"",x="report",{apiClients:b,mutable:T,isLoadingStatus:C,server:M}=ke.useServer(),E=Fl.useQueryClient(),O=k.useRef(S.now()),P=k.useRef(t);P.current=t;const A=k.useRef(r);A.current=r;const L=S.useOptionalDocumentStorage()?.documentStorage,W=f??S.legacyNamedPath(c??"dashboard",v),U=/\.malloynb$/i.test(W)||u&&/\.malloynb$/i.test(v),N=S.useQueryWithApiError({queryKey:["dashboard-editor-model",p,y,W,w,u],queryFn:()=>b.models.getModel(p,y,W,w,u?!0:void 0),enabled:_&&!U&&!h}),I=N.data?.data?.sourceText,{workspace:z,draft:V,setDraft:B,draftChecked:G,offered:Q,setOffered:Z,readFailure:X}=Sy({storage:L,layout:l,notebook:u,environmentName:p,packageName:y,modelPath:W}),{authoritative:H,blockedOnRecord:Pe,resume:ve,setResume:pe,fromDraft:Se,opened:ee,setOpened:Re,openError:ce,savedHashRef:ie,packageBaseRef:$e,setWrote:de,fetchedAtRef:xe,setDirty:we,setSeen:Ge,held:me,choose:Ae,acceptHeld:Fe}=Oy({workspace:z,draft:V,draftChecked:G,readFailure:X,packageText:I,fetchedAt:N.dataUpdatedAt,packageSettled:N.isSuccess&&!N.isFetching,modelPath:W,layout:l,notebook:u,noun:x,legacyFormat:U,textHeld:h,startedAt:O,onEventRef:P}),{save:D,savesTo:R,writer:j,pinnedPackageSave:F,takesWrites:J,supersedeFailure:q}=Dy({storage:L,workspace:z,layout:l,notebook:u,environmentName:p,packageName:y,modelPath:W,versionId:w,apiClients:b,queryClient:E,mutable:T,textHeld:h,readFailure:X,authoritative:H,resume:ve,setResume:pe,setOpened:Re,setDraft:B,setOffered:Z,setSeen:Ge,setWrote:de,savedHashRef:ie,packageBaseRef:$e,fetchedAtRef:xe}),ae=z?.name,se=k.useCallback(rn=>{P.current?.(S.withWorkspace(rn,ae))},[ae]),ue=N.isError&&!ee,rt=k.useRef(!1);k.useEffect(()=>{!ue||rt.current||(rt.current=!0,S.reportEmitter({path:W,layout:l},P.current).emit({type:"report.load_failed",surface:"edit",category:S.failureCategory(N.error)}))},[ue,N.error,W,l]);const Un=k.useCallback((rn,li)=>{we(rn),A.current?.(li)},[we]),Bt=a?S.reportDraftKey({server:M,environmentName:p,packageName:y,versionId:w,path:f??v}):void 0,Hn=R==="host"&&z?.description?z.description:void 0,qn=!H&&!h&&T===void 0?C?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":S.saveCaption({authoritative:H,mutable:J,pinnedPackageSave:F,...z?{workspace:z}:{},...X!==void 0?{readFailure:X}:{},...w!==void 0?{versionId:w}:{}}),Kn=R==="package"&&J===!0&&!F&&X===void 0||qn===Hn?"":qn;if(!_&&"resourceUri"in e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",x," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(ce)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",ce]});if(N.isError&&!ee)return m.jsx(S.ApiErrorDisplay,{error:N.error,context:`Opening the ${x}`});if(!ee&&(!(h||I)||!G))return n??m.jsx(S.Loading,{text:`Opening the ${x}…`});if(Pe)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",X]});const ai=V!==void 0&&V!==I;return m.jsxs($.Stack,{sx:{gap:2},children:[N.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",N.error?.message,". Your edits are still here."]}),!u&&!H&&Q&&ai&&ve===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Ae(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Ae(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),me!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{Bt!==void 0&&S.clearReportDraft(Bt),Fe()},children:"Load it"}),children:R==="package"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":R==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),q!==void 0&&m.jsxs($.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",q]}),!ee&&(n??m.jsx(S.Loading,{text:`Opening the ${x}…`})),ee&&m.jsx(xy,{environmentName:p,packageName:y,modelPath:W,...d?{textSource:d}:{},slug:v,...w!==void 0?{versionId:w}:{},opened:ee,...Se&&j==="package"&&ee.packageText!==void 0?{replaces:ee.packageText}:{},onSave:D,onDirtyChange:Un,...s?{onExit:s}:{},...i?{onOpenModel:i}:{},...o?{onControlsChange:o}:{},...Bt!==void 0?{draftKey:Bt}:{},savesTo:R,...Hn?{saveLabel:Hn}:{},...t?{onEvent:se}:{},note:Kn},ee.generation)]})}const My=Da,Iy=Oa;function jy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Da,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=S.MAX_SLUG_ATTEMPTS;exports.createDocument=S.createDocument;exports.createRoute=S.createRoute;exports.locatorFor=S.locatorFor;exports.newDashboardSource=S.newDashboardSource;exports.newDocumentProblem=S.newDocumentProblem;exports.newNotebookSource=S.newNotebookSource;exports.reportPathFor=S.reportPathFor;exports.reportPathForTitle=S.reportPathForTitle;exports.slugFor=S.slugFor;exports.slugOrFallback=S.slugOrFallback;exports.useDocumentChoices=S.useDocumentChoices;exports.BuilderBar=uy;exports.DashboardBuilder=Iy;exports.DashboardEditor=My;exports.NotebookEditor=jy;exports.ReportBuilder=Oa;exports.ReportEditor=Da;exports.buildCatalog=Qu;exports.readDashboardDocument=Us;exports.readFailed=Gs;exports.readReportTagOfText=Nm;exports.spliceDashboardDocument=Uu;exports.spliceFailed=Hs;
135
+ `;a.push({start:_,end:_,text:x+f.join(`
136
+ `)})}}const hs=(e,t=ve.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function ny(e,t){const n=new Map(e.tiles.map(i=>[rt(i),i]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const i of t.tiles){const a=n.get(rt(i));if(Re(i)){const d=ey(i,a&&Re(a)?a:void 0,r);if(d)return d;continue}const l=a&&ce(a)?a:void 0;if(a&&!l)continue;const u=i.chart;if(u!==void 0&&u!=="default"&&u!=="none"&&!k.isChartPick(u)&&!(u==="custom"&&l?.chart==="custom"))return`"${String(u)}" is not a chart this editor writes.`;const c=new Set(l?.filters?.map(d=>d.field));for(const d of i.filters??[])if(!c.has(d.field)&&/[\r\n]/.test(d.field))return"A filter field is one line.";if(a===void 0){const d=[i.name,i.source];i.declaration.kind==="reference"&&d.push(i.declaration.from);for(const f of d){const h=hs(f);if(h)return h}}for(const d of["label","subtitle"]){const f=i[d];if(f===void 0||f===l?.[d])continue;const h=k.annotationTextProblem(`tile ${d}`,f);if(h)return h}}const s=new Set(e.sources.map(i=>i.name));for(const i of t.sources)if(!s.has(i.name))for(const a of[i.name,i.base]){const l=hs(a);if(l)return l}if(t.description!==e.description)for(const i of(t.description??"").split(/\r?\n/)){const a=k.annotationTextProblem("description line",i);if(a)return a}if(t.title!==e.title){const i=k.annotationTextProblem("title",t.title);if(i)return i}const o=new Map((e.localGivens??[]).map(i=>[i.name,i]));for(const i of t.localGivens??[]){const a=o.get(i.name);if(a===void 0){const u=hs(i.name,ve.isStrictName);if(u)return u}const l=i.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const u=hs(l);if(u)return`The suggest source is not a name. ${u}`}for(const u of["query","dimension"]){const c=i.suggest?.[u];if(c===void 0||c===a?.suggest?.[u])continue;const d=k.annotationTextProblem(`suggest ${u}`,c);if(d)return d}for(const u of["label","description"]){const c=i[u];if(c===void 0||c===o.get(i.name)?.[u])continue;const d=k.annotationTextProblem(`given ${u}`,c);if(d)return d}}for(const[i,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[i])continue;const l=k.annotationTextProblem(`starting value for ${i}`,a);if(l)return l}}const Rt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function mf(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function vf(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const o of s.givens)n.add(o);return(e??[]).find(r=>n.has(r.given))}function yf(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const Cs=e=>`where: ${ve.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Zl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function ry(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(Rt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function sy(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function za(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
+ `,t.end),o=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&o.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(o)?.[0].length??0;return{start:t.start,end:t.end+a}}const i=r.replace(/[\s,]*$/,"");return{start:n+i.length,end:t.end}}function bf(e,t,n){const{parsed:r,edits:s}=e,o=new Map((t.filters??[]).map(f=>[f.given,f])),i=new Set;let a;for(const f of n.wheres){const h=f.clauses.map((v,_)=>({clause:v,index:_})).filter(({clause:v})=>v.binding!==void 0);if(h.length===0)continue;const g=h.filter(({clause:v})=>o.has(v.binding.given));for(const{clause:v}of h)i.add(v.binding.given);if(g.length===0&&h.length===f.clauses.length){const v=za(r,f.span),_=ry(r,f.span,v);if(_)return Zl(t.name,r,_);s.push({...v,text:""});continue}g.length>0&&(a=f.span);for(let v=h.length-1;v>=0;v--){const{clause:_,index:x}=h[v],p=o.get(_.binding.given);if(!p){const w=sy(f.clauses,x),b=r.commentIn(w);if(b)return Zl(t.name,r,b);s.push({...w,text:""});continue}const y=Cs(p).replace(/^where:\s*/,"");y!==r.text.slice(_.span.start,_.span.end)&&s.push({..._.span,text:y})}}const l=(t.filters??[]).filter(f=>!i.has(f.given));if(l.length===0)return;let u=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(Rt(r,u));f&&f.start>=u&&(u=f.end)}const c=a!==void 0&&!/,\s*$/.test(r.text.slice(0,u))?", ":" ",d=n.oneLine?`${c}${l.map(Cs).join(", ")}`:l.map(f=>`
138
+ ${n.indent}${Cs(f)}`).join("");s.push({start:u,end:u,text:d})}function oy(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:o}=n.body,i=vf(t.filters,o);if(i)return yf(t.name,i.given);const a=t.filters??[];if(!o){if(a.length===0)return;const c=` + { ${a.map(Cs).join(", ")} }`;r.push({start:s.end,end:s.end,text:c});return}const l=o.wheres.some(c=>c.clauses.some(d=>!d.binding)),u=o.statements.some(c=>!o.wheres.some(d=>d.span.start===c.span.start));if(a.length===0&&!l&&!u){const c={start:s.end,end:o.span.end},d=e.parsed.commentIn(c);if(d)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(d.start,d.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...c,text:""});return}return bf(e,t,o)}async function xf(e,t,n={}){if(!(e.includes(`\r
139
+ `)&&!/(?<!\r)\n/.test(e)))return Jl(e,t,n);const s=await Jl(e.replace(/\r\n/g,`
140
+ `),t,n);return Zs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
+ `)}}async function Jl(e,t,n){const r=await Qs(e);if(Ys(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,o=Jv(s,t),i=Fv(s,o,n.visibleSources);if("reason"in i)return i;const a=ny(s,o);if(a)return{ok:!1,reason:a};const l=await sf(e);if(ef(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const u=e.split(`
142
+ `),c=Pv(e),d=p=>({start:c[p],end:p+1<c.length?c[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],g={...i,sourceText:e,parsed:l.parsed,lines:u,starts:c,wholeLine:d,indentOf:f,current:s,next:o,edits:h};for(const p of[Nv,Uv,Kv,Vv,Xv,Yv,Qv,Zv,ty]){const y=p(g);if(y)return y}const v=p=>{const{drills:y,localGivens:w,description:b,...E}=p,T=p.tiles.map(C=>{if(Re(C))return C;if(C.filters?.length)return eo(C);const{filters:M,...O}=C;return eo(O)});return{...E,...b===void 0?{}:{description:df(b)},tiles:T,...y?.length?{drills:[...y].sort((C,M)=>Js(C).localeCompare(Js(M)))}:{},...w?.length?{localGivens:w}:{}}};if(h.length===0)return $e(v(s))!==$e(v(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 _=jv(e,h);if((await Gl(e)).length===0){const p=await Gl(_);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 Qs(_);return Ys(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:$e(v(x.document))!==$e(v(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:_}}function wf({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=we.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}=yc(u,a,w=>n(w.text),()=>l(!1)),g=a&&c!==void 0&&c.text!==e,v=c!==void 0&&c.text!==e?Es(c.text):void 0;Wu(g,()=>v!==void 0?!1:(f(),!0));const _=S.useRef(!1);S.useEffect(()=>{a||(_.current=!1)},[a]);const x=S.useCallback(w=>{!w||_.current||(_.current=!0,w.setSelectionRange(w.value.length,w.value.length))},[]);if(!a||c===void 0){const w=e.trim()?Es(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},Bu(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}),w&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:w})]})}const p=c.text!==e?Es(c.text):void 0,y=()=>{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:w=>d(b=>{b.text=w.target.value}),onKeyDown:w=>{w.key==="Escape"?(w.preventDefault(),h(),l(!1)):w.key==="Enter"&&(w.metaKey||w.ctrlKey)&&(w.preventDefault(),y())},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 · ",rn,"↩ done · Esc cancels"]})]})}const iy="Write markdown: # heading, **bold**, - list";function ay({tile:e,onChange:t}){return m.jsx(k.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(wf,{markdown:e.markdown,placeholder:iy,onCommit:t})})}const ly={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},_f=(e,t)=>t===0?e:_f(t,e%t);function cy(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=_f(e,t),s=ly[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function dy({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:o=!1,onInsertAfter:i,onSelect:a,onOpenMenu:l,onRemove:u,removeBlocked:c,resizing:d=!1,width:f,onResizeStart:h,onResizeMove:g,onResizeEnd:v,heightEdge:_,fixed:x=!1,children:p}){const{theme:y}=we.usePublisherTheme(),w=y.ui;return m.jsx(rv,{id:Se(e),index:t,disabled:x,children:({ref:b,handleRef:E})=>m.jsxs($.Box,{ref:b,onClick:a,onPointerDown:T=>{T.button===0&&a()},role:"group",className:k.reportClasses.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Se(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",...kf(y,{selected:n,flash:r,bare:o}),...!o&&{[`& .${k.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:y.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${y.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:[p,m.jsx($.Box,{ref:E,"aria-label":`Move ${fn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(k.RemoveBadge,{label:`Remove ${fn(e)}`,onRemove:u,...c?{disabledReason:c}:{},inset:o?k.BARE_RING_OFFSET_PX:0}),!Re(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${fn(e)}`,onClick:T=>{T.stopPropagation(),l(T.currentTarget)},sx:{position:"absolute",top:o?0:`${ec}px`,right:o?0:`${ec}px`,borderRadius:w.radius.control,width:28,height:28,zIndex:2,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(py,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${k.reportClasses.widthHandle}`,[Ba]:"",role:"separator",tabIndex:f?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${fn(e)}`,...f?{"aria-valuenow":f.span,"aria-valuemin":1,"aria-valuemax":f.max??f.columns,"aria-valuetext":`${f.span} of ${f.columns} columns`}:{},onKeyDown:T=>{if(!f)return;const C=T.key==="ArrowRight"?f.span+1:T.key==="ArrowLeft"?f.span-1:T.key==="Home"?1:T.key==="End"?f.max??f.columns:void 0;C!==void 0&&(T.preventDefault(),T.stopPropagation(),f.onStep(Math.min(Math.max(C,1),f.max??f.columns)))},onPointerDown:h,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onClick:T=>T.stopPropagation(),sx:T=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:d||n?1:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${y.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:w.radius.control,border:`1px solid ${d?y.accent:k.edgeColor(y.cardBorder)}`,bgcolor:T.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${k.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${d?y.accent:T.palette.text.secondary}`,borderRight:`1.5px solid ${d?y.accent:T.palette.text.secondary}`,boxSizing:"border-box",opacity:d?1:.7},"&:hover::before":{borderColor:y.accent},"&:hover::after":{borderColor:y.accent,opacity:1}}),children:d&&f&&m.jsx($.Box,{"aria-hidden":!0,sx:T=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:w.radius.control,bgcolor:T.palette.text.primary,color:T.palette.background.paper,...w.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:cy(f.span,f.columns)})}),_&&m.jsx(gy,{edge:_,label:fn(e),selected:n}),i&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${fn(e)}`,onClick:T=>{T.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:y.tileTitle,bgcolor:y.tile,border:y.cardBorder,opacity:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:y.tile}},children:m.jsx(k.AddIcon,{sx:{fontSize:14}})})]})})}const ec=14,Lo=7,kf=(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 uy({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=we.usePublisherTheme();return m.jsxs(k.TileCard,{chrome:r,children:[m.jsx(k.TileHeading,{title:t?.title??no(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:lt(e).replace("->","→")})]})}function fy({after:e}){const{theme:t}=we.usePublisherTheme();return m.jsx(sv,{id:Nu(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 hy({columns:e}){const{theme:t}=we.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},(n,r)=>m.jsx($.Box,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function tc({top:e}){const{theme:t}=we.usePublisherTheme(),n=k.TILE_ROW_PX+k.GRID_GAP_PX,r=-Math.ceil(e/n);return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-r+4*k.MAX_TILE_ROWS},(s,o)=>m.jsx($.Box,{sx:{position:"absolute",top:e+(r+o)*n,left:0,right:0,height:k.TILE_ROW_PX,bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},o))})}function py(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function gy({edge:e,label:t,selected:n}){const{theme:r}=we.usePublisherTheme(),s=r.ui,{rows:o,dragging:i}=e,a=o===void 0;return m.jsx($.Box,{className:"builder-affordance",[Ba]:"",role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${t}`,"aria-valuemin":e.min,"aria-valuemax":k.MAX_TILE_ROWS,...a?{}:{"aria-valuenow":o},"aria-valuetext":nc(o),onKeyDown:l=>{const u=o??e.min,c=l.key==="ArrowDown"?u+1:l.key==="ArrowUp"?u-1:l.key==="Home"?e.min:l.key==="End"?k.MAX_TILE_ROWS:l.key==="Delete"||l.key==="Backspace"?null:void 0;if(c===void 0)return;if(l.preventDefault(),l.stopPropagation(),c===null){a||e.onStep(void 0);return}const d=Math.min(Math.max(c,e.min),k.MAX_TILE_ROWS);d!==o&&e.onStep(d)},onPointerDown:e.onStart,onPointerMove:e.onMove,onPointerUp:e.onEnd,onPointerCancel:e.onEnd,onClick:l=>l.stopPropagation(),onDoubleClick:l=>{l.stopPropagation(),a||e.onStep(void 0)},sx:l=>({position:"absolute",left:0,right:0,bottom:"-8px",height:"16px",cursor:"row-resize",touchAction:"none",zIndex:2,opacity:i||n?1:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${r.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"40px",height:"12px",boxSizing:"border-box",borderRadius:s.radius.control,border:`1px solid ${i?r.accent:k.edgeColor(r.cardBorder)}`,bgcolor:l.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${k.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"16px",height:"5px",borderTop:`1.5px solid ${i?r.accent:l.palette.text.secondary}`,borderBottom:`1.5px solid ${i?r.accent:l.palette.text.secondary}`,boxSizing:"border-box",opacity:i?1:.7},"&:hover::before":{borderColor:r.accent},"&:hover::after":{borderColor:r.accent,opacity:1}}),children:i&&m.jsx($.Box,{"aria-hidden":!0,sx:l=>({position:"absolute",left:"50%",bottom:"50%",transform:"translate(32px, 50%)",px:1,py:.5,borderRadius:s.radius.control,bgcolor:l.palette.text.primary,color:l.palette.background.paper,...s.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:nc(o)})})}const nc=e=>e===void 0?"Auto height":`${e} rows tall`,Na=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1),Bo=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function my({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[o,i]=S.useState(void 0),a=S.useRef(void 0),l=f=>{a.current=f,i(f)};return S.useEffect(()=>()=>Bo(!1),[]),{resize:o,startResize:(f,h)=>{const g=n.current?.getBoundingClientRect(),v=f.currentTarget.parentElement?.getBoundingClientRect();if(!g||!v)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),Bo(!0),r(h);const _=e[h]?.colspan??1,x=Na(e[h],t);l({index:h,span:_,from:_,left:v.left,track:(g.width-k.GRID_GAP_PX*(t-1))/t,max:x})},onResize:f=>{const h=a.current;if(!h)return;const g=f.clientX-h.left,v=Math.round((g+k.GRID_GAP_PX)/(h.track+k.GRID_GAP_PX)),_=Math.min(Math.max(v,1),h.max);_!==h.span&&l({...h,span:_})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),Bo(!1);const h=a.current;if(!h)return;const{index:g,span:v,from:_}=h;l(void 0),!(f.type==="pointercancel"||v===_)&&s(g,v)}}}function vy({editor:e,reorder:t,resizing:n,sizing:r,place:s=w=>w,arrange:o=!0,gridBox:i,defaultSpan:a=1,rules:l,canAdd:u,selected:c,flash:d,menuIndex:f,onSelect:h,onOpenMenu:g,onRemove:v,removeBlocked:_,openAdd:x,editTile:p,renderTile:y}){const{dragging:w,preview:b,onDragStart:E,onDragMove:T,onDragOver:C,onDragEnd:M}=t,{columns:O}=l,{resize:P,startResize:L,onResize:A,endResize:H}=n,z=r?.height,Y=q=>q.colspan===void 0?{...q,colspan:a}:q,I=(P!==void 0?s(e.document.tiles.map((q,V)=>V===P.index?{...q,colspan:P.span}:q),P.index):z!==void 0?s(e.document.tiles.map((q,V)=>V===z.index?yy(q,z.rows):q),z.index):b??e.document.tiles).map(Y),N=k.isPlaced(I),j=e.document.tiles.length===0,R=(w||P!==void 0)&&!N?km(I,O):I.map(zu),W=q=>by(q,no(q),p);return m.jsxs(m.Fragment,{children:[m.jsx(sm,{sensors:ev,onDragStart:E,onDragMove:T,onDragOver:C,onDragEnd:M,children:m.jsxs($.Box,{ref:i,sx:{position:"relative"},children:[l.widths&&(w||P!==void 0)&&m.jsx(hy,{columns:O}),z!==void 0?m.jsx(tc,{top:z.guideTop}):N&&(w||P!==void 0)&&m.jsx(tc,{top:0}),m.jsx(k.DashboardGrid,{tiles:R,columns:O,rowGapPx:k.GRID_GAP_PX,defaultRowspan:q=>q.kind==="tile"?Li(q.tile):k.PLACED_DEFAULT_ROWSPAN.query,keyOf:q=>q.kind==="gap"?Nu(q.after):Se(q.tile),renderTile:q=>{if(q.kind==="gap")return m.jsx(fy,{after:q.after});const{tile:V,index:G}=q;return m.jsx(dy,{tile:V,index:G,selected:G===c,flash:Se(V)===d,menuOpen:f===G,bare:Re(V),...l.insertBetween&&u&&G<e.document.tiles.length-1?{onInsertAfter:()=>x(G+1)}:{},fixed:!o,...l.widths&&o?{resizing:P?.index===G,width:{span:V.colspan??1,columns:O,max:Na(V,O),onStep:K=>{K!==(V.colspan??1)&&e.update(re=>{if(!Number.isInteger(G)||G<0)return;const se=re.tiles[G];se&&(re.tiles[G]=k.withSpan(se,K,O,a)),re.tiles=s(re.tiles,G)})}},onResizeStart:K=>L(K,G),onResizeMove:A,onResizeEnd:H}:{},...l.widths&&r?{heightEdge:{rows:V.rowspan,dragging:z?.index===G,min:Ai(V),onStart:K=>r.startHeight(K,G),onMove:r.onHeight,onEnd:r.endHeight,onStep:K=>e.update(re=>{if(!Number.isInteger(G)||G<0)return;const se=re.tiles[G];se&&(K===void 0?delete se.rowspan:se.rowspan=K,re.tiles=s(re.tiles,G))})}}:{},onSelect:()=>h(G),onOpenMenu:K=>g(K,G),onRemove:()=>v(G),..._?{removeBlocked:_}:{},children:Re(V)?m.jsx(ay,{tile:V,onChange:K=>p(Se(V),re=>{Re(re)&&(re.markdown=K)})}):y?y(V,W(V),"card"):m.jsx(uy,{tile:V,heading:W(V)})})}})]})}),l.insertBetween&&u&&!j&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>x(),sx:{alignSelf:"center"},children:"Add tile"})]})}const yy=(e,t)=>{const{rowspan:n,...r}=e;return t===void 0?r:{...r,rowspan:t}},by=(e,t,n)=>{if(Fn(e))return;const r=Se(e),s=o=>i=>n(r,a=>{ce(a)&&(i===""?delete a[o]:a[o]=i)});return{title:m.jsx(Mi,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(Mi,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},xy={x:12,y:6};function wy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:o}=we.usePublisherTheme();return m.jsx(k.ReportHeader,{actions:n,title:m.jsx(Mi,{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",...kf(o,{selected:r,bare:!0,ringOffset:xy})},children:m.jsx(wf,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:i=>e.update(a=>{i.trim()===""?delete a.description:a.description=i})})})})})}const _y=({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?.()}),[]),{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,g=t.exit!==void 0,v=t.done!==void 0,_=t.discard!==void 0,{draftKeptAt:x}=t,p=t.restored?.savedAt,y=t.restored?.stale??!1,w=t.restored?.pending??!1,b=t.restore!==void 0,E=t.dismissRestored!==void 0,T=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}:{}},...g?{exit:s.exit}:{},...v?{done:s.done}:{},...x!==void 0?{draftKeptAt:x}:{},..._?{discard:s.discard}:{},...p!==void 0?{restored:{savedAt:p,stale:y,pending:w}}:{},...b?{restore:s.restore}:{},...E?{dismissRestored:s.dismissRestored}:{}}),[s,o,i,c,a,l,d,f,h,u,g,v,x,_,p,y,w,b,E]),C=e!==void 0;S.useEffect(()=>{r.current?.(T)},[T,C]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Sy({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(g=>[g.name,g]));return{stateOf:g=>{const v=i?.get(g);if(v!==void 0){const{modelPath:p}=v;return{origin:h.get(g)?.origin??"model",fixed:v.reason,...p!==void 0&&a?{openModel:()=>a(p)}:{}}}const _=h.get(g);if(!_)return;const x=t(_.name,_.type);return{origin:_.origin,...x.length>0?{problem:`Cannot filter on ${x.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:d?e.filter(g=>g.boundTiles===0&&!i?.has(g.name)).map(g=>({name:g.name,label:g.label??g.name})):[],onEdit:g=>{const v=h.get(g);v&&n(v)},onRemove:o,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...u?{startingValueOf:g=>l?.[g],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 $y(e,t){const n=new Map(e.tiles.map((r,s)=>[Se(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const o=n.get(Se(s));if(!o||o.index!==r||JSON.stringify(o.tile)!==JSON.stringify(s))return Se(s)}}function Ty({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(_=>r(x=>typeof x=="object"&&x.tile===_?x:{tile:_}),[]),a=S.useCallback(()=>r(_=>_==="description"?_:void 0),[]),l=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const _=x=>{const p=x.target;p instanceof Element&&p!==document.documentElement&&p.closest(Ey)===null&&u()};return document.addEventListener("pointerdown",_,!0),()=>document.removeEventListener("pointerdown",_,!0)},[c,u]);const[d,f]=S.useState(void 0),h=S.useRef(!1),g=S.useRef(e.document);S.useEffect(()=>{const _=g.current;if(g.current=e.document,!h.current)return;h.current=!1;const x=$y(_,e.document);if(x===void 0)return;f(x),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(y=>y.dataset.tileKey===x)?.scrollIntoView?.({block:"nearest",behavior:k.scrollBehavior()})},[e.document,t]),S.useEffect(()=>{if(d===void 0)return;const _=setTimeout(()=>f(void 0),1500);return()=>clearTimeout(_)},[d]);const v=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:v}}const Ey=["[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 Cy({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 v=++d.current;l(!1),i("saving");try{await u.current()}catch{d.current===v&&i("idle");return}d.current===v&&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]),g=S.useCallback(()=>{o==="idle"&&(e?n?t?i("waiting"):f():i("asking"):c.current())},[o,e,n,t,f]);return{requestExit:h,saveAndExit:g,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 Oy({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,g]=S.useState(!1),v=S.useRef(null),_=S.useRef(a);_.current=a;const x=e.dirty||o,p=(e.edited??e.dirty)||o,y=i?o:p;S.useEffect(()=>{s?.(e.document)},[e.document,s]),S.useLayoutEffect(()=>{n?.(p,y)},[p,y,n]);const w=S.useRef(n);w.current=n,S.useEffect(()=>()=>w.current?.(!1,!1),[]);const b=S.useRef(l);b.current=l,S.useEffect(()=>{g(!1)},[e.document]);const E=S.useCallback(()=>{f(!0),g(!1);const I=k.now(),{structural:N}=e,j=_.current.size;return e.save().then(R=>{R.ok===!0?_.current.saved({size:j,structural:N,durationMs:k.now()-I}):_.current.refused(R.reason)}).finally(()=>f(!1))},[e]),T=S.useRef(!1),C=S.useRef(!1);S.useEffect(()=>{!C.current||d||(C.current=!1,v.current?.focus())},[h,d]);const M=S.useCallback(()=>{if(!t||d||T.current||!e.canUndoSave)return;T.current=!0,f(!0);const I=k.now(),N=e.lastSave?.structural??!1,j=_.current.size;return e.undoSave().then(R=>{R.ok===!0?(C.current=!0,g(!0),_.current.undone({size:j,structural:N,durationMs:k.now()-I})):_.current.undoRefused(R.reason)}).finally(()=>{T.current=!1,f(!1)})},[t,d,e]),O=S.useCallback(()=>{if(!(!t||!e.dirty||d))return E()},[t,e,d,E]),P=S.useRef(O);P.current=O;const L=S.useCallback(()=>{const I=()=>P.current();return u?u(I):I()},[u]),A=Cy({dirty:p,saving:d,canSave:!!t,save:L,onExit:()=>r?.()});Pf(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:L}:{},paused:A.dialog.open}),[c,e,t,L,A.dialog.open]));const H=!!t&&!d&&e.canUndoSave,z=e.lastSave,Y={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:x,saving:d,saveButton:v,...t?{onSave:L}:{},...r?{onExit:A.requestExit}:{}};return{saving:d,save:L,exitGuard:A,...r?{done:A.saveAndExit}:{},undoSave:M,canUndoSave:H,lastSave:z,toolbarProps:Y}}const My=1;function Sf(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(...Sf(a,`${t}${o}.`,n-1))}}}return r}function Dy(e){const t=new Map;for(const n of $f(e))t.set(n.name,Sf(n.schema?.fields,"",My));return t}function $f(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 Tf(e){const t=new Map;for(const n of $f(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 Ef(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 Cf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function Iy(e){const t=Tf(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(Cf(r).map(o=>[o.name,Ef(o,s?.get(o.name))])))}return n}function rc(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const sc=(e,t)=>e!==void 0&&t.has(e),oc=e=>e.path||e.modelPath||"";function Of(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=oc(a);if(sc(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=oc(a);if(sc(l,t))continue;const u=Dy(a),c=Tf(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(g=>g.name).filter(g=>typeof g=="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:Cf(d).map(g=>Ef(g,c.get(f)?.get(g.name))),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function Ry({editor:e,opened:t,givens:n,catalog:r}){const[s,o]=S.useState(void 0),i=S.useMemo(()=>{const g=new Set((t.localGivens??[]).map(v=>v.name));return(n??[]).filter(v=>!g.has(v.name))},[t,n]),a=S.useMemo(()=>Zf(e.document,i),[e.document,i]),l=S.useMemo(()=>new Map(e.document.sources.map(g=>[g.name,rc(r,g.base)])),[r,e.document.sources]),u=S.useCallback(g=>l.get(g.source)??rc(r,g.source),[l,r]),c=(g,v)=>{const _=[];for(const x of e.document.tiles){if(!ce(x))continue;const p=u(x);if(!p)continue;const y=new Map(p.map(w=>[w.name,w.type]));for(const w of x.filters??[])w.given===g&&(!y.has(w.field)||!Sr(v,y.get(w.field)))&&_.push(`${w.field} on ${x.label??x.name} (${e.document.sources.find(b=>b.name===x.source)?.base??x.source})`)}return _},d=S.useMemo(()=>a.filter(g=>g.origin==="model"&&g.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:o,controlList:a,fieldsFor:u,unknownFieldsOf:c,available:d,applyFilter:(g,v,_)=>{o(void 0),e.update(x=>{_&&ih(x,_),oh(x,g,v)})},dropControl:g=>{o(void 0),e.update(v=>ah(v,g))}}}function Py(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,g]=S.useState(e.replaces),[v,_]=S.useState(!1),x=o.stack[o.index],p=S.useRef(o);p.current=o;const y=S.useRef(!1),[w,b]=S.useState(!1),E=R=>{y.current=R,b(R)},[T,C]=S.useState(void 0),M=S.useCallback(R=>{c(void 0),i(W=>{const q=structuredClone(W.stack[W.index]);if(R(q),JSON.stringify(q)===JSON.stringify(W.stack[W.index]))return W;const G=[...W.stack.slice(0,W.index+1),q].slice(-100);return{stack:G,index:G.length-1}})},[]),O=S.useCallback(()=>{c(void 0),i(R=>R.index>0?{...R,index:R.index-1}:R)},[]),P=S.useCallback(()=>{c(void 0),i(R=>R.index<R.stack.length-1?{...R,index:R.index+1}:R)},[]),L=S.useCallback(async(R,W)=>{try{return await t(R,W)}catch(q){return{ok:!1,reason:`Could not build the file: ${q instanceof Error?q.message:String(q)}`}}},[t]),A=S.useCallback(async()=>{if(y.current)return{ok:!1,reason:"A save is still being written."};const R={source:a,saved:d,history:p.current,replacing:h,unwritten:v},W=s?.(d,x)??!1,q=r?.(d,x)??!1;E(!0);try{const V=await L(a,x);if(Zs(V))return c(V.reason),{ok:!1,reason:V.reason};try{await n?.(V.source,{purpose:"save",document:x})}catch(K){const re=`Could not save: ${K instanceof Error?K.message:String(K)}`;return c(re),{ok:!1,reason:re}}l(V.source),f(x),g(void 0),_(!1);const G=W?{stack:[x],index:0}:R.history;return i(K=>K===R.history?G:W?{stack:[K.stack[K.index]],index:0}:K),C(n?{before:R,after:G,lastSave:{before:h??a,after:V.source,structural:q,clearsHistory:W}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[x,L,n,a,d,h,v,s,r]),H=S.useCallback(async()=>{if(y.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:R}=T;E(!0);try{await n(R.replacing??R.source,{purpose:"undo",document:R.saved})}catch(W){const q=`Could not undo the save: ${W instanceof Error?W.message:String(W)}`;return c(q),{ok:!1,reason:q}}finally{E(!1)}return l(R.source),f(R.saved),g(R.replacing),_(R.unwritten||R.replacing!==void 0),i(W=>W===T.after?R.history:W),C(void 0),c(void 0),{ok:!0}},[n,T]),z=S.useMemo(()=>v||JSON.stringify(x)!==JSON.stringify(d),[x,d,v]),Y=S.useMemo(()=>r?.(d,x)??!1,[x,d,r]),I=S.useMemo(()=>s?.(d,x)??!1,[x,d,s]),N=T!==void 0&&T.after===o,j=S.useCallback(async()=>{const R=await L(a,x);return Zs(R)?{ok:!1,reason:R.reason}:{ok:!0,source:R.source}},[x,L,a]);return{document:x,saved:d,source:a,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:z,edited:z,...u===void 0?{}:{error:u},update:M,undo:O,redo:P,save:A,preview:j,structural:Y,clearsHistory:I,canUndoSave:N&&!w&&n!==void 0,...N?{lastSave:T.lastSave}:{},undoSave:H}}const jy=(e,t)=>{const n=new Set(e.tiles.map(Pi)),r=new Set(t.tiles.map(Pi));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Ay(e){const{visibleSources:t,...n}=e,r=S.useCallback((s,o)=>xf(s,o,t?{visibleSources:t}:{}),[t]);return Py({...n,splice:r,structural:jy})}function Ly({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 By({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),g=b=>{u(!1),e.update(E=>{Nf(E,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(E.tiles=Qa(E.tiles,c??E.tiles.length-1,t.columns))}),s(c??e.document.tiles.length)},v=()=>x(c),_=()=>x(void 0),x=b=>{u(!1),e.update(E=>{const T=new Set(E.tiles.filter(Re).map(M=>M.name));let C=1;for(;T.has(`text_${C}`);)C++;E.tiles.splice(b??E.tiles.length,0,{kind:"text",name:`text_${C}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(E.tiles=Qa(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:g,addText:v,appendText:_,editTile:(b,E)=>e.update(T=>{const C=T.tiles.find(M=>Se(M)===b);C&&E(C)}),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)&&Is(E)===void 0?b+1:void 0;e.update(C=>{Gf(C,b)}),T!==void 0&&s(T)}}}var Fy=Object.defineProperty,Wy=Object.defineProperties,zy=Object.getOwnPropertyDescriptors,ic=Object.getOwnPropertySymbols,Ny=Object.prototype.hasOwnProperty,Gy=Object.prototype.propertyIsEnumerable,ac=(e,t,n)=>t in e?Fy(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vn=(e,t)=>{for(var n in t||(t={}))Ny.call(t,n)&&ac(e,n,t[n]);if(ic)for(var n of ic(t))Gy.call(t,n)&&ac(e,n,t[n]);return e},yn=(e,t)=>Wy(e,zy(t));function Hy(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ps(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Fo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function qy(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=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>l(b,o.id)),w=e.findIndex(b=>l(b,i.id));if(y===-1||w===-1){if(Fo(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!==y)return n(e,y,b)}return n(e,y,w)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[y,w]of u)if(c===-1&&(c=w.findIndex(b=>l(b,o.id)),c!==-1&&(d=y)),f===-1&&(f=w.findIndex(b=>l(b,i.id)),f!==-1&&(h=y)),c!==-1&&f!==-1)break;if(c===-1&&Fo(o)){const y=o.initialGroup==null?void 0:ps(e,o.initialGroup),w=o.initialIndex,b=o.group==null?void 0:ps(e,o.group),E=o.index;if(y==null||b==null||y===b&&w===E)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return yn(vn({},e),{[y]:n(e[y],w,E)});const T=e[y][w];return yn(vn({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:g}=o.manager,v=(s=(r=g.shape)==null?void 0:r.current.center)!=null?s:g.position.current;if(h==null){const y=ps(e,i.id);if(y!=null){const w=i.shape&&v.y>i.shape.center.y?e[y].length:0;h=y,f=w}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&Fo(o)){const y=o.group==null?void 0:ps(e,o.group),w=o.group!=null&&y!==d,b=o.index!==c;if(w||b){const E=o.group==null?d:y;if(E!=null){if(d===E)return yn(vn({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return yn(vn({},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 yn(vn({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(v.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return yn(vn({},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 Uy(e,t){return qy(e,t,Hy)}function Vy(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 Ky({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:g=>{l(!0),i.current=e;const v=r?.gridBox.current,_=g?.operation.source?.id;if(!r||!v)return;const x=e.findIndex(C=>Se(C)===_),p=Vy(v),y=p.get(String(_));if(x<0||!y)return;const w=zf(e,e.map(C=>p.get(Se(C))),r.columns,Ya(v.getBoundingClientRect().width,r.columns)),b=v.getBoundingClientRect(),E=g?.operation.position?.current,T=E?{x:E.x-(b.left+y.left),y:E.y-(b.top+y.top)}:{x:0,y:0};u.current={base:w,index:x,from:y,grab:T},i.current=w,o(w)},onDragMove:g=>{const v=u.current,_=r?.gridBox.current;if(!v||!r||!_)return;const x=_.getBoundingClientRect(),p=g.operation.position.current,y=g.to??(g.by?{x:p.x+g.by.x,y:p.y+g.by.y}:p),w=v.base[v.index],b=mc(y.x-v.grab.x-x.left,y.y-v.grab.y-x.top,w.colspan??1,r.columns,Ya(_.getBoundingClientRect().width,r.columns)),E=i.current?.[v.index];if(E?.row===b.row&&E.col===b.col)return;const T=Wf(v.base,v.index,b,r.columns);i.current=T,o(T)},onDragOver:g=>{if(u.current){g.preventDefault();return}const{source:v,target:_}=g.operation;if(!v||!_)return;const x=i.current??e;let p;if(_.type===Ju){const{after:y}=_.data,w=x.findIndex(T=>Se(T)===v.id);if(w<0||y===v.id)return;const E=x.filter((T,C)=>C!==w).findIndex(T=>Se(T)===y)+1;p=_m(x,w,E)}else{const y=x.map(Se),w=Uy(y,g);if(w.every((E,T)=>E===y[T]))return;const b=new Map(x.map(E=>[Se(E),E]));p=wm(w.map(E=>b.get(E)),e.map(E=>E.break??!1))}i.current=p,o(p)},onDragEnd:g=>{l(!1);const v=u.current,_=v!==void 0;u.current=void 0;const x=i.current,p=v!==void 0&&x!==void 0&&x[v.index]?.row===v.base[v.index]?.row&&x[v.index]?.col===v.base[v.index]?.col,y=_&&x?Ff(x):x;if(i.current=void 0,o(void 0),g.canceled||!y||p)return;t(y);const w=y.findIndex(b=>Se(b)===g.operation.source?.id);w>=0&&n(w)}}}const Wo=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"row-resize":""};function Xy({tiles:e,gridBox:t,onStart:n,commit:r}){const[s,o]=S.useState(void 0),i=S.useRef(void 0),a=S.useRef(void 0),l=h=>{i.current=h,o(h)};S.useEffect(()=>()=>Wo(!1),[]);const u=h=>{const g=new Set(e.filter(x=>x.rowspan===void 0).map(Se)),v=e[h.index];let _=a.current;for(const x of t.current?.querySelectorAll("[data-tile-key]")??[]){const p=x.dataset.tileKey;if(!p||!g.has(p)||v&&p===Se(v))continue;const y=x.getBoundingClientRect();Math.abs(y.top-h.top)>1||(_=Math.max(_??0,y.height))}return _};return{height:s,startHeight:(h,g)=>{const v=h.currentTarget.parentElement?.getBoundingClientRect(),_=t.current?.getBoundingClientRect();if(!v||!_)return;h.stopPropagation(),h.preventDefault(),h.currentTarget.setPointerCapture(h.pointerId),Wo(!0),n(g);const x=e[g]?.rowspan;a.current=x===void 0?v.height:void 0,l({index:g,rows:x,from:x,top:v.top,guideTop:v.top-_.top})},onHeight:h=>{const g=i.current;if(!g)return;const v=h.clientY-g.top,_=e[g.index],x=k.rowsForHeight(v,_?Ai(_):void 0),p=u(g),y=p!==void 0&&Math.abs(v-p)<Math.abs(v-k.tileHeightPx(x))?void 0:x;y!==g.rows&&l({...g,rows:y})},endHeight:h=>{h.currentTarget.hasPointerCapture(h.pointerId)&&h.currentTarget.releasePointerCapture(h.pointerId),Wo(!1);const g=i.current;if(!g)return;const{index:v,rows:_,from:x}=g;l(void 0),a.current=void 0,!(h.type==="pointercancel"||_===x)&&r(v,_)}}}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:g="package",saveLabel:v,replaces:_,modelPath:x,visibleSources:p,addFilterDisabledReason:y,fixedFilters:w,onOpenModel:b,takenGivenNames:E,onControlsChange:T,draftKey:C}){const M=Ay({source:e,document:t,...n?{onSave:n}:{},..._!==void 0?{replaces:_}:{},...p?{visibleSources:p}:{}}),O=k.useReportDraft(C,M,e),P=S.useRef(null),{selected:L,descriptionSelected:A,selectTile:H,deselectTile:z,selectDescription:Y,clearSelection:I,flash:N,stepEditor:j}=Ty({editor:M,gridBox:P}),R=k.layoutRules(M.document.layout,M.document.columns),{columns:W}=R,q=x?.split("/").at(-1)?.replace(/\.malloy$/,""),V=$.useMediaQuery("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),G=!R.widths||V,K=Ky({tiles:M.document.tiles,commit:Q=>M.update(he=>{he.tiles=Q}),onLanded:H,...R.widths&&V?{placement:{columns:W,gridBox:P}}:{}}),re=R.widths,se=S.useCallback((Q,he)=>re&&k.isPlaced(Q)?to(Q,W,he):Q,[re,W]),{dragging:oe}=K,ye=k.useDefaultTileSpan(P,W),Pe=S.useMemo(()=>M.document.tiles.map(Q=>Q.colspan===void 0?{...Q,colspan:ye}:Q),[M.document.tiles,ye]),be=my({tiles:Pe,columns:W,gridBox:P,onStart:H,commit:(Q,he)=>M.update(ee=>{const pe=ee.tiles[Q];pe&&(ee.tiles[Q]=k.withSpan(pe,he,W,ye)),ee.tiles=se(ee.tiles,Q)})}),Ge=Xy({tiles:M.document.tiles,gridBox:P,onStart:H,commit:(Q,he)=>M.update(ee=>{const pe=ee.tiles[Q];pe&&(he===void 0?delete pe.rowspan:pe.rowspan=he,ee.tiles=se(ee.tiles,Q))})}),Z=By({editor:M,rules:R,modelPath:x,textHeld:p!==void 0,selectTile:H,deselectTile:z}),{menu:Ke,addingTile:_e,openAdd:fe}=Z,Te=Ry({editor:M,opened:t,givens:u,catalog:c}),{filterDialog:je,setFilterDialog:ie}=Te,[He,Xe]=S.useState(void 0),{draftDirty:D,openDraft:B,prepare:U}=Ly({editorDirty:M.dirty}),X=S.useMemo(()=>({escape:()=>{!Ke&&!je&&!_e&&He===void 0&&I()},nudge:Q=>{if(oe||L===void 0||!R.widths||!G)return;const he=M.document.tiles[L];if(!he)return;const ee=k.nudgedSpan(he.colspan??ye,Q,Na(he,W));ee!==(he.colspan??ye)&&M.update(pe=>{pe.tiles[L]=k.withSpan(pe.tiles[L],ee,W,ye),pe.tiles=se(pe.tiles,L)})}}),[ye,G,se,M,Ke,je,_e,He,I,L,W,R,oe]),ge=Oy({editor:j,extraDirty:D,keepsEdits:C!==void 0&&O.keeping,prepare:U,unit:{name:"tile",count:Q=>Q.tiles.length},onSave:n,onDirtyChange:s,onExit:o,onChange:r,shortcuts:X,report:_y({size:M.document.tiles.length,path:x??"",layout:M.document.layout,savesTo:g,onEvent:h})}),Ce=M.document.tiles.length===0,{toolbarProps:We}=ge,F=O.restored,J={status:ge.saving?"saving":We.dirty?"unsaved":"saved",saveTarget:v??Ho[g],...O.keptAt!==void 0?{draftKeptAt:O.keptAt}:{},...(We.dirty||F?.pending)&&C!==void 0?{discard:O.discard}:{},...F?{restored:F}:{},...F&&!F.pending?{dismissRestored:O.dismissRestored}:{}};ky(T,{...J,...We.onSave?{save:We.onSave}:{},canUndo:We.canUndo,undo:We.onUndo,canRedo:We.canRedo,redo:We.onRedo,add:{...c?{tile:()=>Z.openAdd()}:{},text:Z.appendText,...y!==void 0?{filterUnavailable:y}:Ce?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>ie({})}},...We.onExit?{exit:We.onExit}:{},...ge.done?{done:ge.done}:{},...F?.pending?{restore:O.restoreOffered}:{}});const ze=T?void 0:m.jsx(jf,{...ge.toolbarProps,...d?{actions:d}:{},...c?{onAddTile:()=>fe()}:{},savesTo:g,...v?{saveLabel:v}:{},...C!==void 0&&We.onSave?{saveStatus:J}:{}});return m.jsx(Fu.Provider,{value:B,children:m.jsx($.Stack,{className:k.reportClasses.builder,"data-saves-to":g,sx:{gap:0,mx:`-${Lo}px`},children:m.jsxs(k.ReportPage,{layout:R.layout,sx:{px:`${Lo}px`,pb:`${Lo}px`},header:m.jsx(wy,{editor:M,documentSlug:q,actions:ze,descriptionSelected:A,selectDescription:Y}),controls:Ce?void 0:m.jsx(Sy,{controls:Te.controlList,unknownFieldsOf:Te.unknownFieldsOf,onEdit:Q=>ie({control:Q}),onAdd:()=>ie({}),...y?{addDisabledReason:y}:{},onRemove:Te.dropControl,...w?{fixedFilters:w}:{},...b?{onOpenModel:b}:{},...M.document.startingGivens?{startingValues:M.document.startingGivens}:{},onStartingValue:(Q,he)=>M.update(ee=>{const pe={...ee.startingGivens??{}};he===void 0?delete pe[Q]:pe[Q]=he,Object.keys(pe).length>0?ee.startingGivens=pe:delete ee.startingGivens}),children:l}),children:[Ce&&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:()=>fe(),children:"Add tile"})]}),F?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:O.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:O.discard,children:"Discard"})]}),children:`You have unsaved edits from ${No(F.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),M.error&&m.jsx($.Alert,{severity:"warning",children:M.error}),!G&&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(vy,{editor:M,arrange:G,reorder:K,resizing:be,sizing:Ge,place:se,gridBox:P,defaultSpan:ye,rules:R,canAdd:!!c,selected:L,flash:N,menuIndex:Ke?.index,onSelect:H,onOpenMenu:(Q,he)=>{H(he),Z.setMenu({anchor:Q,index:he})},onRemove:Z.removeTile,...M.document.tiles.length===1&&M.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:fe,editTile:Z.editTile,...i?{renderTile:i}:{}}),m.jsx(wh,{editor:M,catalog:c,columns:W,dashboards:f,bindings:Te,tiles:Z,drillSource:He,setDrillSource:Xe,exitDialog:ge.exitGuard.dialog,...a?{renderViewPreview:a}:{},...E?{takenGivenNames:E}:{}})]})})})}const Yy=k.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),Qy=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"})),Zy=k.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function Jy({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=we.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),g=v=>()=>{l(null),v?.()};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(fc,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${rn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Os(s.ui),children:m.jsx(uc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${rn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Os(s.ui),children:m.jsx(dc,{fontSize:"small"})})})}),h&&m.jsx($.Divider,{orientation:"vertical",sx:Ms}),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:v=>l(v.currentTarget),sx:{...kr(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:eb(o,s.ui)}},MenuListProps:{sx:{p:.5}},children:[f?.tile&&m.jsx(zo,{icon:m.jsx(Qy,{}),title:"Tile",detail:"A chart or table from the model",onClick:g(f.tile)}),f?.text&&m.jsx(zo,{icon:m.jsx(Zy,{}),title:"Text",detail:"Prose between the tiles",onClick:g(f.text)}),(f?.filter||f?.filterUnavailable)&&m.jsx(zo,{icon:m.jsx(Yy,{}),title:"Filter",detail:f.filterUnavailable??"A control the tiles read",disabled:f.filter===void 0,onClick:g(f.filter)})]})]})]})]}),(c||d)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:Ms}),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:{...kr(o,i,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&d&&m.jsx($.Tooltip,{title:`Save (${rn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...kr(o,i,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const eb=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function zo({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:o}=we.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 tb(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(Ot(`${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 nb(e,t,n){const r=new Map;for(const o of t.tiles)ce(o)&&r.set(Ot(lt(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=Ot(lt(o)),a=r.get(i);for(const l of n.get(i)??[])a?.has(l)||s.add(l)}return s}function rb(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function sb(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Ot(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function ob(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 ib(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 ab(e,t,n,r=new Map,s,o){if(Fn(t))return{expression:lt(t),givenNames:void 0,reads:s&&[...s]};const i=ib(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))),g=new Set([...f,...s??[]]),v=[];for(const b of t.filters??[]){const E=`where: ${ve.malloyPath(b.field)} ${b.op??"~"}`;if(u.has(b.given)){h.add(b.given),g.add(b.given),v.push(`${E} $${b.given}`);continue}if(!c.has(b.given))continue;g.add(b.given);const T=k.malloyLiteral(r.get(b.given),c.get(b.given))??rb(d.get(b.given));T!==void 0&&v.push(`${E} ${T}`)}const _=v.join(", "),x=t.chart,p=x==="none"||k.isChartPick(x)?k.chartLineText(x,t.chartCarried):x==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
+ `):x==="default"&&sb(t.declaration)?k.chartResetLine():void 0,y=t.color!==void 0?k.seriesColorLine(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?k.seriesColorResetLine:void 0,w=[p,y].filter(Boolean).join(`
144
+ `)||void 0;return{...w?{annotation:w}:{},...i?.modelPath!==void 0?{modelPath:i.modelPath}:{},expression:`${a} -> ${l}`+(_?` + { ${_} }`:""),givenNames:Array.from(h),reads:s||g.size>0?Array.from(g):void 0}}function lb({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:o}){const{apiClients:i,server:a}=we.useServer(),{data:l}=k.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await i.models.listModels(e,t,n)).data.flatMap(g=>g.path&&!g.error?[g.path]:[])}),u=S.useMemo(()=>new Set([r,...s.flatMap(g=>g.path?[g.path]:[])]),[s,r]),c=S.useMemo(()=>o?(l??[]).filter(g=>!u.has(g)):[],[l,u,o]),d=cc.useQueries({queries:c.map(g=>({queryKey:["report-editor-model",e,t,g,n,a],queryFn:async()=>(await i.models.getModel(e,t,g,n)).data,retry:!1}))}),f=l!==void 0&&o&&d.every(g=>g.isSuccess||g.isError),h=d.map(g=>g.dataUpdatedAt).join();return S.useMemo(()=>f?Of(d.flatMap((g,v)=>g.data?[{...g.data,path:c[v]}]:[]),u):void 0,[f,c,h,u])}const cb={};function db({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:g,savesTo:v,saveLabel:_,note:x,fileModel:p}){const{apiClients:y}=we.useServer(),[w,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:C}=k.useQueryWithApiError({...k.reportQueryOptions(y,{environmentName:t,packageName:n,path:r,versionId:o},k.BUILDER_HANDOFF_STALE_MS),enabled:w&&!e}),M=e?.modelPath??r,O=fb(i.source,e?.compileSource),P=k.useCompiledDocument({environmentName:t,packageName:n,modelPath:M,source:O.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&O.text!==void 0}),L=P.data?.document,A=e?P.isSuccess?L?.manifest??cb:void 0:E,H=e?P.isSuccess:T,z=e?P.isError||O.problem!==void 0:C,Y=e?k.documentPreamble(L?.cells):void 0,I=(P.data?.result.problems??[]).filter(F=>F.severity==="error"),N=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),j=e?.givens,R=S.useMemo(()=>new Set((A?.tiles??[]).flatMap(F=>F.restricted&&F.query?[Ot(F.query)]:[])),[A]),{reports:W,settled:q}=k.useReportListing(t,n,o),V=S.useMemo(()=>W.map(F=>F.path).filter(F=>!!F&&F!==r&&F.endsWith(".malloy")).map(F=>F.replace(/\.malloy$/,"")),[W,r]),G=lb({environmentName:t,packageName:n,...o!==void 0?{versionId:o}:{},modelPath:r,reports:W,reportsSettled:q}),K=S.useMemo(()=>e?(G?.sources??[]).filter(F=>(F.visibleIn??F.exporters??[F.modelPath]).includes(M)).map(F=>F.name):void 0,[G,e,M]),re=S.useMemo(()=>p?Iy(p):void 0,[p]),se=S.useMemo(()=>{const F=G&&K?{sources:G.sources.filter(J=>K.includes(J.name))}:G;return F&&re?{...F,documentViews:re}:F},[G,K,re]),[oe,ye]=S.useState(i.document);S.useEffect(()=>ye(i.document),[i.document]);const Pe=S.useMemo(()=>l&&(async(F,J)=>{await l(F,J.document.layout),v==="package"&&b(J.document.tiles.length>0)}),[l,v]),be=S.useMemo(()=>(A?.givens??[]).filter(F=>!(e&&F.secure===!0)&&!(F.name!==void 0&&N.has(F.name))),[A,N,e]),Ge=S.useMemo(()=>new Set([...be.map(F=>F.name).filter(F=>F!==void 0),...Object.keys(j??{})]),[be,j]),Z=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(F=>F.kind!=="text"&&F.query&&F.givenNames?[[Ot(F.query),F.givenNames]]:[])),[A]),Ke=S.useMemo(()=>new Map((A?.tiles??[]).flatMap(F=>F.kind!=="text"&&F.query&&F.label?[[Ot(F.query),F.label]]:[])),[A]),_e=S.useMemo(()=>nb(oe,i.document,Z),[oe,i.document,Z]),fe=S.useMemo(()=>tb(oe,be,_e,Z),[oe,be,_e,Z]),Te=S.useMemo(()=>{const F=new Set(oe.tiles.flatMap(ee=>ce(ee)?(ee.filters??[]).map(pe=>pe.given):[])),J=new Set((oe.localGivens??[]).map(ee=>ee.name)),ze=[...new Set(oe.imports.map(ee=>ee.from))],Q=ze.length===1?hb(r,ze[0]):ze.length===0&&e?e.modelPath:void 0,he=ee=>{const pe=oe.sources.filter(qe=>qe.scopedBy?.includes(ee)).map(qe=>qe.name);return pe.length>0?{reason:`Applied to every tile on ${pe.join(", ")} by this report's own source. Edit the file to change it.`}:J.has(ee)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Q!==void 0?{reason:`Set in the model ${Q}. Edit the model to change it.`,modelPath:Q}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([..._e].filter(ee=>!F.has(ee)).map(ee=>[ee,he(ee)]))},[oe,_e,e,r]),{declaredTypes:je,applied:ie,panel:He}=k.useDocumentControls({specs:fe,loaded:H,startingValues:A?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:A?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?M:A?.path,versionId:o,documentName:r,...Y!==void 0?{preamble:Y}:{},...j?{hostGivens:j}:{}}),Xe=S.useMemo(()=>k.missingRequiredGivens(fe,ie,j),[fe,ie,j]),D=S.useMemo(()=>Object.fromEntries(Object.entries(j??{}).filter(([F])=>!je.has(F))),[j,je]),B=!w||H||z,U=e!==void 0&&(O.problem!==void 0||P.isError||I.length>0),X=S.useMemo(()=>new Map(i.document.tiles.map(F=>[Se(F),F])),[i.document]),ge=S.useMemo(()=>ob(oe,i.document,r,!!e),[oe,i.document,r,e]),Ce=S.useMemo(()=>function(J,ze,Q="card"){const he=(Fn(J)?Ke.get(Ot(lt(J))):void 0)??no(J);if(U)return m.jsxs(k.TileCard,{chrome:Q,children:[m.jsx(k.TileHeading,{title:ze?.title??he,subtitle:ze?ze.subtitle:J.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!B)return m.jsxs(k.TileCard,{chrome:Q,children:[m.jsx(k.TileHeading,{title:ze?.title??he,subtitle:ze?ze.subtitle:J.subtitle}),m.jsx(k.Loading,{text:"Running…"})]});const ee=Z.get(Ot(lt(J))),qe=Y===void 0&&ee!==void 0&&ub(X.get(Se(J)),J)?{expression:lt(J),givenNames:[...ee],reads:[...ee]}:ab(oe,J,Ge,ie,ee,ge),Ct=k.layoutRules(oe.layout,oe.columns);return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:qe.modelPath??M,...Y!==void 0&&qe.modelPath===void 0?{preamble:Y}:{},...R.has(Ot(lt(J)))?{restricted:!0}:{},tile:qe.expression,...qe.annotation?{annotation:qe.annotation}:{},label:he,chrome:Q,subtitle:J.subtitle,...ze?{heading:ze}:{},borderless:J.borderless,givens:ie,hostGivens:D,declaredTypes:je,givenNames:qe.givenNames,...(()=>{const er=k.waitingOn(Xe,qe.reads??qe.givenNames);return er.length>0?{waitingFor:k.waitingText(er)}:{}})(),ignoredFilters:k.tileIgnoredFilterLabels(qe.reads,fe),height:J.rowspan!==void 0||J.row!==void 0?k.tileHeightPx(J.rowspan??k.PLACED_DEFAULT_ROWSPAN.query):Ct.tileMaxHeight,tableMaxHeight:Ct.tableMaxHeight})},[oe,X,B,U,Xe,Ge,Z,Ke,t,n,o,M,Y,ge,R,ie,D,je,fe]),We=S.useMemo(()=>function(J){return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:J.modelPath,tile:`${J.base} -> ${J.view}`,...J.chart?{annotation:k.chartLineText(J.chart,J.chartCarried)}:{},label:J.label,borderless:!0,givens:ie,hostGivens:D,declaredTypes:je,givenNames:J.givens,height:200})},[t,n,o,ie,D,je]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&I.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",I.map(F=>F.message).join("; ")]}),Xe.length>0&&!U&&m.jsx($.Alert,{severity:"info",children:k.requiredPrompt(Xe)}),e&&O.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",O.problem]}),e&&P.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",P.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:Te,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:Ce,renderViewPreview:We,givens:fe.filter(F=>F.name!==void 0).map(F=>({name:F.name,...F.label?{label:F.label}:{},...F.type?{type:F.type}:{},...F.suggest?.dimension?{field:F.suggest.dimension}:{}})),onChange:ye,onDirtyChange:u,...c?{onExit:c}:{},...d?{onOpenModel:d}:{},...f?{onControlsChange:f}:{},...h!==void 0?{draftKey:h}:{},...se?{catalog:se}:{},dashboards:V,...g?{onEvent:g}:{},controls:H?m.jsx(k.GivensPanel,{...He,layout:"bar"}):void 0,...Pe?{onSave:Pe}:{},savesTo:v,..._?{saveLabel:_}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:K}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:x})})]})}function ub(e,t){return e!==void 0&&JSON.stringify(lc(e))===JSON.stringify(lc(t))}function lc(e){const{label:t,subtitle:n,colspan:r,break:s,rowspan:o,row:i,col:a,borderless:l,...u}=e;return u}function fb(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 hb(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 pb({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),[g,v]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let _=!1;return v(void 0),(async()=>{try{const x=k.chooseWorkspace(await e.listWorkspaces(!1));if(_)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const p=await e.getDocument(k.locatorFor(t,x.name,r,s,o)).catch(y=>{if(!k.isDocumentNotFound(y))throw y});if(_)return;u(p),h(p!==void 0)}}catch(x){if(_)return;v(k.storageErrorMessage(x))}_||d(!0)})(),()=>{_=!0}},[e,t,n,r,s,o]),{workspace:i,draft:l,setDraft:u,draftChecked:c,offered:f,setOffered:h,readFailure:g}}const gb=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function mb(e){const t=await Qs(e);return Ys(t)?{ok:!1,reason:gb(t.reason,t.line)}:{ok:!0,document:t.document}}const vb="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",yb="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function bb({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:g}){const v=S.useRef({path:a,layout:l});v.current={path:a,layout:l};const _=S.useRef((fe,Te)=>{try{g.current?.(k.withReportContext(fe,{...v.current,...Te?{layout:Te}:{}}))}catch{}}),x=e?.authoritative===!0,p=x&&r!==void 0,[y,w]=S.useState(void 0),b=(x||y===!0)&&t!==void 0,[E,T]=S.useState(void 0),[C,M]=S.useState(d?vb:void 0),O=S.useRef(void 0),P=S.useRef(void 0),[L,A]=S.useState(void 0),H=S.useRef(o);H.current=o;const z=L!==void 0&&L.onFetch===o?L.text:s,Y=S.useRef(z);Y.current=z;const I=b?t:z,[N,j]=S.useState(!1),[R,W]=S.useState(void 0),[q,V]=S.useState(void 0),G=I!==void 0&&I!==q,K=E?.source,se=G&&(N||!x&&t!==void 0&&K===t&&t!==z)&&K!==void 0&&I!==R,oe=se?K:G?I:K??I,ye=se?I:void 0,Pe=S.useRef(K);Pe.current=K;const be=S.useRef(I);be.current=I;const Ge=S.useRef("package");Ge.current=b?x?"record":"draft":"package",S.useEffect(()=>{if(oe===void 0||!n||p||oe===Pe.current)return;let fe=!1;const Te=Y.current,je=be.current;return mb(oe).then(ie=>{if(!fe){if(ie.ok===!1){M(ie.reason),_.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}M(void 0),O.current=void 0,P.current=Te,A(void 0),W(void 0),V(je),T(He=>({source:oe,document:ie.document,...Te!==void 0?{packageText:Te}:{},generation:(He?.generation??0)+1})),_.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(fe)return;const He=`Could not read the ${c}: ${ie instanceof Error?ie.message:String(ie)}`;M(He),_.current({type:"report.load_failed",surface:"edit",category:k.failureCategory(ie)})}),()=>{fe=!0}},[oe,a,n,p,u,c,f,h]),S.useEffect(()=>{d&&_.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||E||r!==void 0||(x?t===void 0&&M("the host's storage has no document at this location."):M("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&&(M(yb),_.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:x,blockedOnRecord:p,resume:y,setResume:w,fromDraft:b,opened:E,setOpened:T,openError:C,savedHashRef:O,packageBaseRef:P,setWrote:A,fetchedAtRef:H,setDirty:j,setSeen:V,held:ye,choose:fe=>{h.current=k.now(),W(fe?t:z),w(fe)},acceptHeld:()=>{h.current=k.now(),W(ye)}}}function xb({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:g,setResume:v,setOpened:_,setDraft:x,setOffered:p,setSeen:y,setWrote:w,savedHashRef:b,packageBaseRef:E,fetchedAtRef:T}){const C=S.useCallback(R=>t===void 0?void 0:k.locatorFor(R,t.name,s,o,i),[t,s,o,i]),M=C(n),O=S.useCallback(async(R,W=n)=>{const q=C(W);if(!e||!q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(q,R),_(V=>V&&{...V,source:R}),x(R),(h||g===!0)&&y(R),h||v(V=>V??!1)},[e,C,n,h,g,_,x,y,v]),[P,L]=S.useState(void 0),A=S.useCallback(async R=>{const W=await k.expectedHashFor(b.current,E.current);if(W===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:R,expectedHash:W,invalidateOnError:[q],afterWrite:async V=>{if(_(G=>G&&{...G,source:R}),w({text:R,onFetch:T.current}),y(R),b.current=V,L(void 0),e&&M)try{await e.deleteDocument(M),x(void 0),p(!1)}catch(G){k.isDocumentNotFound(G)?(x(void 0),p(!1)):L(k.storageErrorMessage(G))}v(!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,M,u,b,E,T,_,w,y,x,p,v]),H=t?.writeable===!0,z=c===!0&&!d,{savesTo:Y,pinnedPackageSave:I,writer:N}=k.saveTarget({authoritative:h,mutable:z,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!M&&H&&(!r||h),readFailed:f!==void 0});return{save:N==="storage"?O:N==="package"?A:void 0,savesTo:Y,writer:N,pinnedPackageSave:I,takesWrites:z,supersedeFailure:P}}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",g=c!==void 0,{environmentName:v,packageName:_,versionId:x,namesBoth:p}=k.resolveEditorTarget(e),w=("resourceUri"in e?e.dashboard:e.dashboardName)??k.documentSlug(u)??"",b="report",{apiClients:E,mutable:T,isLoadingStatus:C,server:M}=we.useServer(),O=cc.useQueryClient(),P=S.useRef(k.now()),L=S.useRef(t);L.current=t;const A=S.useRef(r);A.current=r;const H=k.useOptionalDocumentStorage()?.documentStorage,z=u??k.legacyNamedPath(l??"dashboard",w),Y=/\.malloynb$/i.test(z)||h&&/\.malloynb$/i.test(w),I=k.useQueryWithApiError({queryKey:["dashboard-editor-model",v,_,z,x,h],queryFn:()=>E.models.getModel(v,_,z,x,h?!0:void 0),enabled:p&&!Y&&!g}),N=I.data?.data?.sourceText,{workspace:j,draft:R,setDraft:W,draftChecked:q,offered:V,setOffered:G,readFailure:K}=pb({storage:H,layout:f,notebook:h,environmentName:v,packageName:_,modelPath:z}),{authoritative:re,blockedOnRecord:se,resume:oe,setResume:ye,fromDraft:Pe,opened:be,setOpened:Ge,openError:Z,savedHashRef:Ke,packageBaseRef:_e,setWrote:fe,fetchedAtRef:Te,setDirty:je,setSeen:ie,held:He,choose:Xe,acceptHeld:D}=bb({workspace:j,draft:R,draftChecked:q,readFailure:K,packageText:N,fetchedAt:I.dataUpdatedAt,packageSettled:I.isSuccess&&!I.isFetching,modelPath:z,layout:f,notebook:h,noun:b,legacyFormat:Y,textHeld:g,startedAt:P,onEventRef:L}),{save:B,savesTo:U,writer:X,pinnedPackageSave:ge,takesWrites:Ce,supersedeFailure:We}=xb({storage:H,workspace:j,layout:f,notebook:h,environmentName:v,packageName:_,modelPath:z,versionId:x,apiClients:E,queryClient:O,mutable:T,textHeld:g,readFailure:K,authoritative:re,resume:oe,setResume:ye,setOpened:Ge,setDraft:W,setOffered:G,setSeen:ie,setWrote:fe,savedHashRef:Ke,packageBaseRef:_e,fetchedAtRef:Te}),F=j?.name,J=S.useCallback(ue=>{L.current?.(k.withWorkspace(ue,F))},[F]),ze=I.isError&&!be,Q=S.useRef(!1);S.useEffect(()=>{!ze||Q.current||(Q.current=!0,k.reportEmitter({path:z,layout:f},L.current).emit({type:"report.load_failed",surface:"edit",category:k.failureCategory(I.error)}))},[ze,I.error,z,f]);const he=S.useCallback((ue,Oe)=>{je(ue),A.current?.(Oe)},[je]),ee=!c&&I.data?.data&&N!==void 0&&be?.source===N?I.data.data:void 0,pe=a?k.reportDraftKey({server:M,environmentName:v,packageName:_,versionId:x,path:u??w}):void 0,qe=U==="host"&&j?.description?j.description:void 0,Ct=!re&&!g&&T===void 0?C?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":k.saveCaption({authoritative:re,mutable:Ce,pinnedPackageSave:ge,...j?{workspace:j}:{},...K!==void 0?{readFailure:K}:{},...x!==void 0?{versionId:x}:{}}),es=U==="package"&&Ce===!0&&!ge&&K===void 0||Ct===qe?"":Ct;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(I.isError&&!be)return m.jsx(k.ApiErrorDisplay,{error:I.error,context:`Opening the ${b}`});if(!be&&(!(g||N)||!q))return n??m.jsx(k.Loading,{text:`Opening the ${b}…`});if(se)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",K]});const mo=R!==void 0&&R!==N;return m.jsxs($.Stack,{sx:{gap:2},children:[I.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",I.error?.message,". Your edits are still here."]}),!h&&!re&&V&&mo&&oe===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Xe(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Xe(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),He!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{pe!==void 0&&k.clearReportDraft(pe),D()},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."}),We!==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:"," ",We]}),!be&&(n??m.jsx(k.Loading,{text:`Opening the ${b}…`})),be&&m.jsx(db,{environmentName:v,packageName:_,modelPath:z,...c?{textSource:c}:{},slug:w,...x!==void 0?{versionId:x}:{},...(d??x)!==void 0?{queryVersionId:d??x}:{},opened:be,...Pe&&X==="package"&&be.packageText!==void 0?{replaces:be.packageText}:{},onSave:B,onDirtyChange:he,...s?{onExit:s}:{},...o?{onOpenModel:o}:{},...i?{onControlsChange:i}:{},...pe!==void 0?{draftKey:pe}:{},savesTo:U,...qe?{saveLabel:qe}:{},...t?{onEvent:J}:{},note:es,...ee?{fileModel:ee}:{}},be.generation)]})}const wb=Ha,_b=Ga;function kb(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=Jy;exports.DashboardBuilder=_b;exports.DashboardEditor=wb;exports.NotebookEditor=kb;exports.ReportBuilder=Ga;exports.ReportEditor=Ha;exports.buildCatalog=Of;exports.readDashboardDocument=Qs;exports.readFailed=Ys;exports.readReportTagOfText=$v;exports.spliceDashboardDocument=xf;exports.spliceFailed=Zs;