@malloy-publisher/sdk 0.9.14 → 0.9.16

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 (164) hide show
  1. package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
  2. package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
  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 +7732 -6717
  7. package/dist/builder-entry.d.ts +1 -1
  8. package/dist/client/api.d.ts +31 -7
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
  12. package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
  13. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  14. package/dist/components/Dashboard/index.d.ts +1 -1
  15. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  16. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  17. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  18. package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
  19. package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
  20. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  21. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  22. package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
  23. package/dist/components/Report/Report.d.ts +7 -1
  24. package/dist/components/Report/ReportPage.d.ts +7 -0
  25. package/dist/components/Report/layoutRules.d.ts +45 -0
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  27. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
  29. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  30. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  31. package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
  32. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  33. package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
  34. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  35. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  36. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  37. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  38. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  39. package/dist/components/ReportBuilder/document.d.ts +53 -5
  40. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  41. package/dist/components/ReportBuilder/placement.d.ts +121 -0
  42. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  43. package/dist/components/ReportBuilder/sortable.d.ts +12 -1
  44. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  45. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  46. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  47. package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
  48. package/dist/index.cjs.js +7 -7
  49. package/dist/index.es.js +3349 -3307
  50. package/dist/text/index.es.js +1 -1
  51. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  52. package/dist/theme/classes.d.ts +1 -1
  53. package/dist/theme/resolveTheme.d.ts +15 -0
  54. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
  55. package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
  56. package/dist/utils/blankQuoted.d.ts +15 -0
  57. package/package.json +1 -1
  58. package/src/builder-entry.ts +1 -0
  59. package/src/components/Dashboard/DashboardGrid.tsx +129 -10
  60. package/src/components/Dashboard/DashboardTile.tsx +15 -1
  61. package/src/components/Dashboard/DashboardView.tsx +64 -10
  62. package/src/components/Dashboard/TileCard.tsx +6 -0
  63. package/src/components/Dashboard/index.ts +1 -0
  64. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  65. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  66. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  67. package/src/components/Dashboard/useStuck.ts +76 -28
  68. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  69. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  70. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  71. package/src/components/RenderedResult/RenderedResult.tsx +39 -6
  72. package/src/components/RenderedResult/ResultContainer.tsx +99 -10
  73. package/src/components/RenderedResult/ResultPanel.tsx +25 -1
  74. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  75. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  76. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  77. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  78. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  79. package/src/components/RenderedResult/resultSizing.ts +71 -11
  80. package/src/components/Report/Report.spec.tsx +19 -0
  81. package/src/components/Report/Report.tsx +8 -1
  82. package/src/components/Report/ReportPage.tsx +13 -1
  83. package/src/components/Report/layoutRules.spec.ts +43 -3
  84. package/src/components/Report/layoutRules.ts +70 -0
  85. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  86. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  87. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  88. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  89. package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
  90. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
  91. package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
  92. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  93. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  94. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  95. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  96. package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
  97. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  98. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  99. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  100. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  101. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  102. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
  103. package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
  104. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  105. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  106. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  107. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  108. package/src/components/ReportBuilder/TileFrame.tsx +366 -170
  109. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  110. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  111. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  112. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  113. package/src/components/ReportBuilder/builderControls.ts +34 -0
  114. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  115. package/src/components/ReportBuilder/catalog.ts +90 -37
  116. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  117. package/src/components/ReportBuilder/chartLine.ts +80 -2
  118. package/src/components/ReportBuilder/controls.ts +4 -3
  119. package/src/components/ReportBuilder/document.ts +65 -7
  120. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  121. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  122. package/src/components/ReportBuilder/imports.ts +1 -1
  123. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  124. package/src/components/ReportBuilder/layout.ts +3 -0
  125. package/src/components/ReportBuilder/placement.spec.ts +401 -0
  126. package/src/components/ReportBuilder/placement.ts +416 -0
  127. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  128. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  129. package/src/components/ReportBuilder/preview.ts +203 -40
  130. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  131. package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
  132. package/src/components/ReportBuilder/readDocument.ts +197 -29
  133. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  134. package/src/components/ReportBuilder/sortable.tsx +30 -2
  135. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  136. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  137. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  138. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
  139. package/src/components/ReportBuilder/spliceDocument.ts +139 -91
  140. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  141. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  142. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  143. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  144. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  145. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  146. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  147. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  148. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  149. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  150. package/src/components/given/FilterButton.spec.tsx +27 -11
  151. package/src/components/given/FilterButton.tsx +19 -6
  152. package/src/theme/classes.ts +1 -1
  153. package/src/theme/resolveTheme.spec.ts +72 -1
  154. package/src/theme/resolveTheme.ts +43 -0
  155. package/src/utils/blankQuoted.spec.ts +50 -0
  156. package/src/utils/blankQuoted.ts +32 -0
  157. package/src/utils/malloyText.ts +2 -1
  158. package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
  159. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  160. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  161. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
  162. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
  163. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  164. package/src/components/ReportBuilder/useTileResize.ts +0 -133
@@ -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"),Se=require("../ServerProvider-BIFPCzTD.cjs.js"),pe=require("../text-entry-BJwltZiy.cjs.js"),Ju=require("react-dom"),ef=require("@malloydata/malloy-tag"),Fl=require("@tanstack/react-query"),zl=S.createSvgIcon(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Wl=S.createSvgIcon(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),tf=S.createSvgIcon(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function Nl(e){const{theme:t}=Se.usePublisherTheme(),n=t.ui,[r,s]=k.useState(null),{status:i,draftKeptAt:o,discard:a,restored:c,dismissRestored:f}=e,d=c!==void 0&&!c.pending&&i==="unsaved"?c:void 0,l=i==="saved"?"Saved":i==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",u=d?`Restored your unsaved edits from ${ji(d.savedAt)}`:void 0,h=i==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,p=a!==void 0&&i==="unsaved",v=()=>{s(null),d&&f?.()},x=y=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:i==="saved"?y.palette.text.secondary:y.palette.text.primary,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...p?{"&:hover":{bgcolor:y.palette.action.hover}}:{}}),_=m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i==="saved"?m.jsx(S.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":d?"true":void 0,sx:y=>({width:7,height:7,borderRadius:"50%",bgcolor:d?t.accent:i==="saving"||o!==void 0?y.palette.text.disabled:y.palette.warning.main,transition:`background-color ${S.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:l}),m.jsx(S.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:p?"visible":"hidden"}})]}),g=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:nf,children:u?`${l}. ${u}.`:l});return m.jsxs(m.Fragment,{children:[g,m.jsx($.Tooltip,{title:u??h,describeChild:!0,children:p?m.jsx($.ButtonBase,{className:S.reportClasses.saveStatus,"aria-label":l,...u?{"aria-description":u}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:y=>s(y.currentTarget),sx:x,children:_}):m.jsx($.Box,{component:"span",className:S.reportClasses.saveStatus,sx:x,children:_})}),m.jsxs($.Menu,{className:S.reportClasses.menu,anchorEl:r,open:r!==null,onClose:v,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${S.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(u!==void 0||o!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:u??`Kept in this browser at ${ji(o)}`}),m.jsxs($.MenuItem,{onClick:()=>{s(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(tf,{fontSize:"small"}),"Discard edits"]})]})]})}function ji(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const nf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Pi=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xt=Pi?"⌘":"Ctrl+",Pa=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},fi=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function rf(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=Pi?i.metaKey:i.ctrlKey,c=i.key.toLowerCase();if(i.key==="Escape"){if(Pa(i.target)||fi(i.target))return;o.escape();return}if(Pa(i.target)){if(a&&c==="s"){if(i.preventDefault(),!o.save||fi(i.target))return;i.target.blur(),r(!0)}return}if(fi(i.target)){a&&c==="s"&&i.preventDefault();return}if(a&&c==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!Pi&&a&&c==="y"){i.preventDefault(),o.redo();return}if(a&&c==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const gr=(e,t,n=Se.DEFAULT_UI)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),Ss=(e=Se.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),$s={height:20,alignSelf:"center",mx:.5,my:0},Ts=(e,t=Se.DEFAULT_UI)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Ri={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function sf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:c,saveButton:f,actions:d,onAddTile:l,onExit:u,saveStatus:h}){const{theme:p}=Se.usePublisherTheme(),v=S.edgeColor(p.cardBorder),x=S.hoverEdgeColor(p.cardBorder,p.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[l&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),onClick:l,"aria-label":"Add tile",sx:gr(v,x,p.ui),children:"Tile"}),l&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Ss(p.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Ss(p.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(d||o||u)&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),d,o&&h&&m.jsx(Nl,{...h}),o?m.jsx($.Tooltip,{title:s?`Save (${Xt}S) · ${c??Ri[a]}`:c??Ri[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:f,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{...gr(v,x,p.ui),minWidth:88},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&m.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),u&&m.jsx(S.SecondaryButton,{label:"Close",icon:m.jsx(S.CheckIcon,{}),onClick:u})]})}const of={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Gl(e,t,n){const s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:of[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ra(e){return e.description??S.readableName(e.name)}const af={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},Qr=(e,t)=>`${e}\0${t}`;function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o,renderPreview:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,d=S.edgeColor(c.cardBorder),l=k.useMemo(()=>n?.sources??[],[n]),[u,h]=k.useState(""),[p,v]=k.useState(),[x,_]=k.useState(""),[g,y]=k.useState("default"),w=k.useRef(null),b=k.useMemo(()=>{const I=new Set(t.sources.map(F=>F.base));return[...l].sort((F,H)=>Number(I.has(H.name))-Number(I.has(F.name)))},[l,t]),T=b.filter(I=>I.views.length>0),C=b.filter(I=>I.views.length===0),M=k.useMemo(()=>new Map(T.flatMap(I=>I.views.map(F=>[Qr(I.name,F.name),{source:I,view:F,key:Qr(I.name,F.name)}]))),[T]),E=k.useMemo(()=>T.map(I=>({key:I.name,label:I.name,...I.description?{detail:I.description}:{},entries:I.views.map(F=>({key:Qr(I.name,F.name),name:F.name,title:Ra(F),...F.chart?{chart:F.chart}:{}}))})),[T]),O=p===void 0?void 0:M.get(p);k.useEffect(()=>{if(!e)return;h(""),_(""),y("default");const I=T[0]?.views[0];v(I&&T[0]?Qr(T[0].name,I.name):void 0)},[e]);const A=O?[O.source.name,O.view.name].filter(I=>!pe.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,j=O!==void 0&&A===void 0,L=O?Ra(O.view):"",N=g!=="default"&&O?{chart:g,chartCarried:O.view.chart?[O.view.chart]:[]}:{},W=(I=O)=>{if(!I||![I.source.name,I.view.name].every(pe.isBareName))return;const F=I.key===O?.key;i({base:I.source.name,modelPath:I.source.modelPath,...I.source.exporters?{exporters:I.source.exporters}:{},view:I.view.name,...F&&x.trim()?{label:x.trim()}:{},...F?N:{},colspan:Math.ceil(r/2)})},V=O?Gl(O.view,g).filter(I=>I.value!=="custom"&&I.disabled!==!0):[];return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:w,title:"Add a tile",description:"Pick a view from this package. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!j,onClick:()=>W(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${d}`,borderBottom:`1px solid ${d}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${d}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(S.ViewPicker,{groups:E,query:u,onQuery:h,picked:O?.key,onPick:I=>{v(I),y("default")},onTake:I=>W(M.get(I)),searchRef:w,empty:m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,p:2},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}),footer:C.length>0&&m.jsxs($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",C.map(I=>I.name).join(", "),"."]})})}),m.jsx($.Box,{sx:I=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${I.palette.text.primary} 3%, ${I.palette.background.paper})`}),children:O?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:I=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${d}`,bgcolor:I.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${I.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:O.source.name,modelPath:O.source.modelPath,view:O.view.name,label:x.trim()||L,...g!=="default"?N:{},givens:O.source.givens})}):m.jsxs($.Box,{sx:I=>({flex:1,border:`1px solid ${d}`,borderRadius:f.radius.tile,bgcolor:I.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(S.ChartGlyph,{chart:O.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[O.source.name," → ",O.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:L,value:x,onChange:I=>_(I.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...f.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:g,"aria-label":"Chart",onChange:(I,F)=>{F!==null&&y(F)},sx:{...Ts(d,f),"& .MuiToggleButton-root":{...Ts(d,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:V.map(I=>m.jsx($.ToggleButton,{value:I.value,children:I.label},I.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:O.view.chart?`The view declares ${af[O.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),A&&m.jsx($.Typography,{variant:"body2",color:"error",children:A})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const je=e=>e.kind==="text",ae=e=>e.kind!=="text",Yn=e=>ae(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`;function cf(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:i}){t.modelPath&&!r&&(e.imports=S.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const o=Ul(e,t.base),a=Ai(e,o.name,t.view);e.tiles.splice(i??e.tiles.length,0,{name:a,source:o.name,declaration:{kind:"reference",from:t.view},...s?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Ul(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let i=`${t}_tiles`;for(let a=2;s.has(i);a++)i=`${t}_tiles_${a}`;const o={name:i,base:t};return e.sources.push(o),o}function Ai(e,t,n){const r=new Set(e.tiles.filter(ae).filter(i=>i.source===t).map(i=>i.name));let s=`${n}_tile`;for(let i=2;r.has(s);i++)s=`${n}_tile_${i}`;return s}function Es(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function df(e,t){const n=e.tiles[t];if(!n||!ae(n)||Es(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...i}=structuredClone(n);r={...i,name:Ai(e,n.source,n.declaration.from)}}else{const i=e.sources.find(o=>o.name===n.source)??Ul(e,n.source,{unscoped:!0});r={name:Ai(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const Zr="self";function uf({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:i,onClose:o,onApply:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,[d,l]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(y=>y.source===n.name);l((n.dimensions??[]).map(y=>{const w=g.find(b=>b.name===y.name);return{name:y.name,expression:y.expression,to:w?.to??[],given:w?.given??""}}))},[e,n,t]);const u=(g,y)=>l(w=>w.map((b,T)=>{if(T!==g)return b;const C={...b};return y(C),C})),h=[Zr,...s.filter(g=>g!==Zr)],p=g=>g===Zr?"This report":g,v=()=>{n&&(a(d.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),o())},x=S.edgeColor(c.cardBorder),_=(g,y)=>u(g,w=>{y?w.to=w.lastTo?.length?w.lastTo:[Zr]:(w.lastTo=w.to,w.to=[])});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.clickableCellsDialog}`,open:e,onClose:o,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[i&&m.jsxs($.Box,{component:"span",sx:{fontWeight:f.type.label.fontWeight},children:[i," ·"," "]}),"A click on a cell sets a filter to its value, on this report or on the one it opens."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:v,disabled:d.length===0,children:"Apply"})]}),children:d.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:c.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx($.Box,{role:"list","aria-label":"Dimensions",children:d.map((g,y)=>{const w=g.to.length>0;return m.jsxs($.Box,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:y===0?"none":`1px solid ${x}`},children:[m.jsx($.Switch,{size:"small",checked:w,onChange:b=>_(y,b.target.checked),slotProps:{input:{"aria-label":`${g.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...f.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:ff(g.name)}),m.jsxs($.Box,{title:g.expression,sx:{...f.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[g.name," is ",g.expression]})]}),w?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...f.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(p).join(", ")},onChange:b=>u(y,T=>{const C=b.target.value,M=Array.isArray(C)?C:String(C).split(",").filter(Boolean);M.length===0&&(T.lastTo=T.to),T.to=M}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:h.map(b=>m.jsxs($.MenuItem,{value:b,children:[m.jsx($.Checkbox,{size:"small",checked:g.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:p(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:g.given,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?g.name:String(b)},onChange:b=>u(y,T=>{T.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:g.name,secondary:"Named like the dimension"})}),r.map(b=>m.jsx($.MenuItem,{value:b,children:b},b))]})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},g.name)})})})}function ff(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const hf=S.createSvgIcon(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),pf=S.createSvgIcon(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),gf=S.createSvgIcon(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),mf=S.createSvgIcon(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),vf=S.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),yf=S.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function bf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of ae(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function Cs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function xf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function mr(e,t){const n=xf(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Li(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function wf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const _f=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function kf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=pe.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Sf=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function Zn(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Bi=e=>ae(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function $f(e,t){return e.tiles.map(n=>{const r=(ae(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:Cs(t.type)!==void 0?{op:Cs(t.type)}:{}}})}function Tf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Bi(i))return;const o=(i.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function Ef(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function Cf(e,t){for(const r of e.tiles){if(!ae(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Fi=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Of({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:i,onApply:o}){const a=k.useRef(n);e&&(a.current=n);const c=e?n:a.current,f=c!==void 0,[d,l]=k.useState({kind:"new"}),[u,h]=k.useState(""),[p,v]=k.useState("select"),[x,_]=k.useState(""),[g,y]=k.useState(""),[w,b]=k.useState([]),[T,C]=k.useState(!1),[M,E]=k.useState(!1),O=D=>t.sources.find(R=>R.name===D.source)?.base??D.source;k.useEffect(()=>{if(e)if(E(n!==void 0),n){l({kind:"existing",name:n.name}),h(n.label??"");const D=$f(t,n);b(D);const R=D.filter(P=>P.include),z=new Set(R.map(P=>P.field));y(z.size===1?R[0].field:n.field??""),C(z.size>1)}else l({kind:"new"}),h(""),v("select"),y(""),_(new Date().toISOString().slice(0,10)),b(t.tiles.map(D=>({include:Bi(D),field:""}))),C(!1)},[e,n,t]);const A=k.useMemo(()=>[...(t.localGivens??[]).map(D=>D.name),...r.map(D=>D.name),...s],[t,r,s]),j=k.useMemo(()=>g.trim()?kf(g.trim(),A):"",[g,A]),L=d.kind==="existing"?n??r.find(D=>D.name===d.name):j?{name:j,type:Zn({name:j,label:u,kind:p,field:g}).type}:void 0,N=L?.type!==void 0&&!L.type.startsWith("filter<"),W=w.find(D=>D.include)?.op??Cs(L?.type),V=(D,R)=>{E(!0),b(z=>z.map((P,U)=>U===D?{...P,...R}:P))},I=D=>{E(!0),b(R=>R.map(z=>({...z,op:D})))},F=D=>{const R=Cs(D);b(z=>z.map(({op:P,...U})=>R?{...U,op:R}:U))},H=D=>{E(!0),l({kind:"existing",name:D.name}),y(D.field??""),F(D.type)},B=D=>{E(!0),v(D),F(Zn({name:"X",label:u,kind:D,field:g}).type)},G=t.tiles.map(Bi),ee=G.filter(Boolean).length,Q=w.filter((D,R)=>D.include&&G[R]).length,J=t.tiles.filter((D,R)=>(w[R]?.include??!1)&&G[R]&&ae(D)),X=J.length>0?J:t.tiles.filter((D,R)=>G[R]&&ae(D)),te=k.useMemo(()=>{const D=new Map;let R=!1;for(const z of X){const P=i?.(z);if(P){R=!0;for(const U of P)D.has(U.name)||D.set(U.name,U)}}return R?[...D.values()]:void 0},[w,t.tiles,i]),we=(()=>{const D=g.trim();for(const R of J){const z=i?.(R);if(!z||z.some(P=>P.name===D))return O(R)}return J[0]?O(J[0]):t.sources[0]?.base})(),me=D=>{E(!0),b(R=>R.map((z,P)=>({...z,include:D&&G[P]})))},ye=k.useMemo(()=>T?w:w.map(D=>({...D,field:g})),[T,w,g]),$e=D=>{for(const R of X){const z=i?.(R)?.find(P=>P.name===D.trim());if(z?.type)return z.type}},ue=D=>mr(L?.type,D.type),ve=(D,R)=>{if(D.trim()==="")return"Pick the field this filter compares.";const z=R?i?.(R):void 0;if(!z)return;const P=z.find(U=>U.name===D.trim());if(!P)return`Not a field of ${R?O(R):"the tiles' source"}.`;if(P.type&&!mr(L?.type,P.type))return`${D.trim()} is ${Li(P.type)}; this filter compares ${Li(L?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=D=>{if(E(!0),y(D),f||d.kind!=="new")return;const R=$e(D),z=Zn({name:"X",label:u,kind:p,field:D}).type;R&&!mr(z,R)&&B(wf(R))},Ue=D=>{const R=t.tiles[D];return R&&ae(R)?R:void 0},fe=ye.map((D,R)=>D.include&&G[R]?ve(D.field,Ue(R)):void 0),le=fe.every(D=>D===void 0),Le=M?fe:fe.map(()=>{}),We=M&&!T&&Q>0?J.map(D=>ve(g,D)).find(Boolean):void 0,he=L!==void 0&&le&&(d.kind==="existing"||g.trim()!==""&&j!==""),Ne=()=>{if(!(!L||!he))if(d.kind==="new")o(L.name,ye,Zn({name:L.name,label:u.trim()||Fi(L.name),kind:p,field:g.trim(),...we?{source:we}:{},...x?{dateDefault:x}:{}}));else if(n?.origin==="dashboard"&&n.local){const D=u.trim(),R=D!==(n.local.label??"");o(L.name,ye,R?{...n.local,...D?{label:D}:{}}:void 0)}else o(L.name,ye)},Oe=f&&c.origin==="model";return{editing:f,shown:c,fromModel:Oe,source:d,setSource:l,label:u,setLabel:h,kind:p,dateDefault:x,setDateDefault:_,field:g,rows:w,setRows:b,perTile:T,setPerTile:C,newName:j,target:L,valueTyped:N,commonOp:W,setRow:V,setCommonOp:I,pickExisting:H,pickKind:B,bindable:G,bindableCount:ee,included:Q,commonFields:te,setAll:me,accepts:ue,pickField:Z,rowProblems:Le,commonProblem:We,canApply:he,apply:Ne}}function Aa({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:c,autoFocus:f,placeholder:d,inputRef:l,sx:u}){const h=k.useMemo(()=>(n??[]).filter(v=>r?.(v)??!0).map(v=>v.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(v=>[v.name,v.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(v,x)=>t(x),value:e,onChange:(v,x)=>t(typeof x=="string"?x:""),disabled:c,disableClearable:!0,renderOption:(v,x)=>k.createElement("li",{...v,key:x},m.jsx(Ba,{type:p.get(x)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:x})),renderInput:v=>m.jsx($.TextField,{...v,label:s,placeholder:d,autoFocus:f,...l?{inputRef:l}:{},error:o,helperText:a,InputLabelProps:{...v.InputLabelProps,shrink:!0},InputProps:{...v.InputProps,startAdornment:p.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(Ba,{type:p.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":i}}),sx:u})}const Df=e=>e&&ae(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function Mf({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:i,onClose:o,onApply:a,onRemove:c}){const{theme:f}=Se.usePublisherTheme(),d=f.ui,{editing:l,shown:u,fromModel:h,source:p,setSource:v,label:x,setLabel:_,kind:g,dateDefault:y,setDateDefault:w,field:b,rows:T,setRows:C,perTile:M,setPerTile:E,newName:O,target:A,valueTyped:j,commonOp:L,setRow:N,setCommonOp:W,pickExisting:V,pickKind:I,bindable:F,bindableCount:H,included:B,commonFields:G,setAll:ee,accepts:Q,pickField:J,rowProblems:X,commonProblem:te,canApply:we,apply:me}=Of({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:i,onApply:a}),ye=k.useRef(null),$e=S.edgeColor(f.cardBorder),ue=S.hoverEdgeColor(f.cardBorder,f.tileTitle),[ve,Z]=k.useState(!1),[Ue,fe]=k.useState(!1);k.useEffect(()=>{e?fe(!0):Z(!1)},[e]),k.useEffect(()=>{Ue&&(fe(!1),Z(l&&B<H))},[Ue]),k.useEffect(()=>{M&&Z(!0)},[M]);const le=G?.find(D=>D.name===b.trim())?.type,Le=D=>{if(!le)return;const R=Zn({name:"X",label:x,kind:D,field:b}).type;return mr(R,le)?void 0:`${b.trim()} is ${Li(le)}, which this control cannot filter.`},We=x.trim()||(O?Fi(O):"Filter"),he=g==="number"?"Any":g==="date"?y?new Date(`${y}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",Ne={...Ts($e,d),alignSelf:"flex-start","& .MuiToggleButton-root":{...Ts($e,d)["& .MuiToggleButton-root"],textTransform:"none"}},Oe=(D,R,z)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:D??">=",onChange:P=>R(P.target.value),inputProps:{"aria-label":z},sx:{width:130},children:_f.filter(P=>P.op!=="~").map(P=>m.jsx($.MenuItem,{value:P.op,children:P.label},P.op))});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ye},title:l?u.label??u.name:"Add a filter",description:l?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:d.font.mono},children:["$",u.name]}),h?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[l&&m.jsx($.Button,{color:"error",startIcon:m.jsx(S.DeleteOutlineIcon,{}),onClick:()=>c(u.name),sx:D=>({mr:"auto",color:S.dangerTextColor(D)}),children:"Remove filter"}),m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Tooltip,{title:we||A===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:me,disabled:!we,children:l?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!l&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:p.kind,onChange:(D,R)=>{R==="new"?v({kind:"new"}):R==="existing"&&r[0]&&V(r[0])},"aria-label":"Where the filter comes from",sx:Ne,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!l&&p.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:p.name,onChange:D=>{const R=r.find(z=>z.name===D.target.value);R&&V(R)},children:r.map(D=>m.jsxs($.MenuItem,{value:D.name,children:[D.label??D.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",D.name]})]},D.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!M&&m.jsx(Aa,{value:b,onChange:J,fields:G,accepts:Q,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ye,error:te!==void 0,helperText:te??(!l&&O?`Declared as $${O}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:O?Fi(O):"",value:x,onChange:D=>_(D.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),j&&!M&&Oe(L,W,"Comparison"),!l&&p.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Control"}),m.jsx($.Box,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:Sf.map(D=>{const R=D.kind===g,z=Le(D.kind);return m.jsx($.Tooltip,{title:z??D.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":R,"aria-label":D.label,"aria-disabled":z!==void 0,onClick:()=>{z===void 0&&I(D.kind)},sx:P=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:d.radius.tile,border:`1px solid ${R?f.accent:$e}`,boxShadow:R?`0 0 0 1px ${f.accent}`:"none",bgcolor:R?`color-mix(in srgb, ${f.accent} 6%, ${P.palette.background.paper})`:P.palette.background.paper,color:R?f.accent:P.palette.text.secondary,opacity:z?.45:1,cursor:z?"default":"pointer",transition:`border-color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"&:hover":z||R?{}:{borderColor:ue}}),children:[m.jsx(jf,{kind:D.kind}),m.jsx($.Box,{component:"span",sx:{...d.type.caption,fontWeight:R?600:500,color:R?f.accent:"text.primary",textAlign:"center"},children:If[D.kind]})]})},D.kind)})}),g==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:y,onChange:D=>w(D.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${$e}`,borderRadius:d.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(yf,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs($.Typography,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:B===H&&H>0?`Applies to all ${B} tile${B===1?"":"s"}`:`Applies to ${B} of ${H} tile${H===1?"":"s"}`}),!M&&b.trim()!==""&&B>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...d.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":ve,onClick:()=>Z(D=>!D),children:ve?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:ve,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${$e}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:H>0&&B===H,indeterminate:B>0&&B<H,disabled:H===0,onChange:D=>ee(D.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{M||C(D=>D.map(R=>({...R,field:b}))),E(D=>!D)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((D,R)=>{if(!ae(D))return null;const z=T[R],P=D.label??D.name,U=M?X[R]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:F[R]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!F[R],checked:(z?.include??!1)&&F[R],inputProps:{"aria-label":`Filter ${P}`},onChange:K=>N(R,{include:K.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:P}),F[R]?M&&m.jsxs(m.Fragment,{children:[j&&Oe(z?.op,K=>N(R,{op:K}),`Comparison for ${P}`),m.jsx(Aa,{value:z?.field??"",onChange:K=>N(R,{field:K}),fields:i?.(D),accepts:Q,label:"Field",ariaLabel:`Field for ${P}`,disabled:!z?.include,error:U!==void 0,helperText:U,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Df(t.tiles[R]).reason})]},`${D.source}.${D.name}`)})})]})})]}),B===0&&m.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!h&&m.jsxs($.Box,{children:[m.jsx(La,{children:"Preview"}),m.jsx($.Box,{sx:D=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:d.radius.tile,bgcolor:D.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:D=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:d.radius.control,border:`1px solid ${$e}`,bgcolor:D.palette.background.paper,...d.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:We}),m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:he}),m.jsx(S.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function La({children:e}){const t=Se.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const If={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function jf({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(hf,{sx:t});case"multiselect":return m.jsx(pf,{sx:t});case"text":return m.jsx(vf,{sx:t});case"number":return m.jsx(mf,{sx:t});case"date":return m.jsx(gf,{sx:t})}}function Ba({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=Se.usePublisherTheme().theme.ui;return n?m.jsx($.Box,{component:"span","aria-hidden":!0,sx:s=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:s.palette.text.secondary,bgcolor:s.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const Pf=S.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Hl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:d=>i(l=>{if(l===void 0)return l;const u=structuredClone(l);return d(u),u}),apply:d=>{if(s===void 0)return;const l=structuredClone(s);d(l),i(l),JSON.stringify(l)!==JSON.stringify(e)&&n(l)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const Rf=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,Af="Declared on its source, so its chart is set in the model.";function Lf({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:i,duplicateBlocked:o,view:a}){const{theme:c}=Se.usePublisherTheme(),f=c.ui,{draft:d,apply:l,close:u}=Hl(t,e!==null,r,n),[h,p]=k.useState(void 0),v=d!==void 0&&ae(d)?d:void 0,x=v!==void 0&&v.declaration.kind!=="inherited",_=A=>l(j=>{ae(j)&&A(j)}),g=k.useRef(void 0),y=e!==null;k.useEffect(()=>{y?g.current=t&&ae(t)?t.chart:void 0:p(void 0)},[y]);const w=v?.chart??"default",b=Gl(a,w),T=v?x?v.chart==="custom"?Rf(v.chartLines):void 0:Af:void 0,C=A=>_(j=>{const L=g.current;A===(L??"default")?(L===void 0?delete j.chart:j.chart=L,delete j.chartCarried):(j.chart=A,a?j.chartCarried=a.chart?[a.chart]:[]:delete j.chartCarried)}),M=x?s?void 0:"Its source declares no dimension a click could filter by.":void 0,E=A=>j=>p({kind:A,anchor:j.currentTarget}),O=(A,j,L)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:A,...L?{secondary:L}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),j&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:j})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:S.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":v?`${v.source} ${v.name}`:"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:f.radius.menu,border:`1px solid ${S.edgeColor(c.cardBorder)}`,boxShadow:f.shadow.menu}}},children:[v&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":h?.kind==="chart",disabled:T!==void 0,onClick:E("chart"),onKeyDown:A=>{A.key==="ArrowRight"&&T===void 0&&p({kind:"chart",anchor:A.currentTarget})},children:[O("Chart",T?void 0:b.find(A=>A.value===w)?.label,T),m.jsx(Pf,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:M!==void 0,onClick:()=>{u(),s?.()},children:O("Clickable cells…",void 0,M)}),v&&i&&m.jsx($.MenuItem,{disabled:o!==void 0,onClick:()=>{u(),i()},children:O("Duplicate",void 0,o)}),v?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:c.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",v.declaration.why,", so a filter has no single place to go."]}),v&&m.jsx($.Divider,{}),v&&m.jsxs($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...f.type.code,color:"text.secondary"},children:[v.source," → ",v.name]})]}),m.jsx($.Menu,{className:S.reportClasses.menu,open:h?.kind==="chart",anchorEl:h?.anchor??null,onClose:()=>p(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:A=>{A.key==="ArrowLeft"&&(A.preventDefault(),p(void 0))}},children:b.filter(A=>A.value!=="custom").map(A=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":A.value===w,disabled:A.disabled===!0,onClick:()=>{C(A.value),p(void 0)},children:[m.jsx($.ListItemText,{primary:A.label,...A.reason?{secondary:A.reason}:{}}),A.value===w&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(S.CheckIcon,{fontSize:"small",sx:{color:c.accent}})})]},A.value))})]})}const kn=e=>e.label??S.tileTitle(`${e.source} -> ${e.name}`);function Bf({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,exitDialog:c,renderViewPreview:f,takenGivenNames:d}){const{filterDialog:l,setFilterDialog:u}=s,{menu:h,setMenu:p}=i,[v,x]=k.useState(),_=h===void 0?void 0:e.document.tiles[h.index],g=_&&ae(_)?_:void 0,y=(()=>{if(!g||!t)return;const w=e.document.sources.find(T=>T.name===g.source)?.base??g.source,b=g.declaration.kind==="reference"?g.declaration.from:g.name;return t.sources.find(T=>T.name===w)?.views.find(T=>T.name===b)})();return m.jsxs(m.Fragment,{children:[m.jsx(Mf,{open:l!==void 0,document:e.document,...l?.control?{control:l.control}:{},available:s.available,...d?{takenNames:d}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Lf,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>p(void 0),onCommit:w=>{const b=h?.index;b!==void 0&&e.update(T=>{T.tiles[b]=w})},view:y,onDuplicate:()=>{h&&i.duplicate(h.index)},...g&&Es(g)!==void 0?{duplicateBlocked:Es(g)}:{},...(e.document.sources.find(w=>w.name===g?.source)?.dimensions?.length??0)>0?{onDrills:()=>{x(g?kn(g):void 0),a(g?.source)}}:{}}),m.jsx(uf,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:s.controlList.map(w=>w.name),dashboards:r??[],...v?{tileLabel:v}:{},onClose:()=>a(void 0),onApply:w=>e.update(b=>{const C=[...(b.drills??[]).filter(M=>M.source!==o),...w];C.length===0?delete b.drills:b.drills=C})}),m.jsx(S.UnsavedChangesDialog,{...c}),m.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText,...f?{renderPreview:f}:{}})]})}var Ff=Symbol.for("preact-signals");function Qs(){if(kt>1)kt--;else{var e,t=!1;for((function(){var s=Ds;for(Ds=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();yr!==void 0;){var n=yr;for(yr=void 0,Os++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Kl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Os=0,kt--,t)throw e}}function Ce(e){if(kt>0)return e();zi=++zf,kt++;try{return e()}finally{Qs()}}var vr,be=void 0;function ne(e){var t=be,n=vr;be=void 0,vr=void 0;try{return e()}finally{be=t,vr=n}}var yr=void 0,kt=0,Os=0,zf=0,zi=0,Ds=void 0,Ms=0;function Vl(e){if(be!==void 0){var t=e.n;if(t===void 0||t.t!==be)return t={i:0,S:e,p:be.s,n:void 0,t:be,e:void 0,x:void 0,r:t},be.s!==void 0&&(be.s.n=t),be.s=t,e.n=t,32&be.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=be.s,t.n=void 0,be.s.n=t,be.s=t),t}}function Ze(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Ze.prototype.brand=Ff;Ze.prototype.h=function(){return!0};Ze.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:ne(function(){var r;(r=t.W)==null||r.call(t)}))};Ze.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&ne(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ze.prototype.subscribe=function(e){var t=this;return dt(function(){var n=t.value;ne(function(){return e(n)})},{name:"sub"})};Ze.prototype.valueOf=function(){return this.value};Ze.prototype.toString=function(){return this.value+""};Ze.prototype.toJSON=function(){return this.value};Ze.prototype.peek=function(){var e=this;return ne(function(){return e.value})};Object.defineProperty(Ze.prototype,"value",{get:function(){var e=Vl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Os>100)throw new Error("Cycle detected");(function(n){kt!==0&&Os===0&&n.l!==zi&&(n.l=zi,Ds={S:n,v:n.v,i:n.i,o:Ds})})(this),this.v=e,this.i++,Ms++,kt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Qs()}}}});function jn(e,t){return new Ze(e,t)}function Kl(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function ql(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Yl(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function Jt(e,t){Ze.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Ms-1,this.f=4}Jt.prototype=new Ze;Jt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ms))return!0;if(this.g=Ms,this.f|=1,this.i>0&&!Kl(this))return this.f&=-2,!0;var e=be;try{ql(this),be=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return be=e,Yl(this),this.f&=-2,!0};Jt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Ze.prototype.S.call(this,e)};Jt.prototype.U=function(e){if(this.t!==void 0&&(Ze.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Jt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Jt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Vl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Fa(e,t){return new Jt(e,t)}function Xl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){kt++;var n=be;be=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Eo(e),r}finally{be=n,Qs()}}}function Eo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Xl(e)}function Wf(e){if(be!==this)throw new Error("Out-of-order effect");Yl(this),be=e,this.f&=-2,8&this.f&&Eo(this),Qs()}function Pn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,vr&&vr.push(this)}Pn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Pn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Xl(this),ql(this),kt++;var e=be;return be=this,Wf.bind(this,e)};Pn.prototype.N=function(){2&this.f||(this.f|=2,this.u=yr,yr=this)};Pn.prototype.d=function(){this.f|=8,1&this.f||Eo(this)};Pn.prototype.dispose=function(){this.d()};function dt(e,t){var n=new Pn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Nf=Object.create,Co=Object.defineProperty,Gf=Object.defineProperties,Uf=Object.getOwnPropertyDescriptor,Hf=Object.getOwnPropertyDescriptors,za=Object.getOwnPropertySymbols,Vf=Object.prototype.hasOwnProperty,Kf=Object.prototype.propertyIsEnumerable,qf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Rn=e=>{throw TypeError(e)},Wi=(e,t,n)=>t in e?Co(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yf=(e,t)=>{for(var n in t||(t={}))Vf.call(t,n)&&Wi(e,n,t[n]);if(za)for(var n of za(t))Kf.call(t,n)&&Wi(e,n,t[n]);return e},Xf=(e,t)=>Gf(e,Hf(t)),Wa=(e,t)=>Co(e,"name",{value:t,configurable:!0}),Qf=e=>{var t;return[,,,Nf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],Jn=e=>e!==void 0&&typeof e!="function"?Rn("Function expected"):e,Zf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?Rn("Already initialized"):s.push(Jn(i||null))}),Zl=(e,t)=>Wi(t,qf("metadata"),e[3]),Ft=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},An=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=Ql[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&Uf(l<4?s:{get[n](){return it(this,i)},set[n](w){return Mt(this,i,w)}},n));l?h&&l<4&&Wa(i,(l>2?"set ":l>1?"get ":"")+n):Wa(s,n);for(var y=r.length-1;y>=0;y--)f=Zf(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>Jf(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?it:eh)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>Mt(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?Jn(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Rn("Object expected"):(Jn(o=a.get)&&(g.get=o),Jn(o=a.set)&&(g.set=o),Jn(o=a.init)&&x.unshift(o));return l||Zl(e,s),g&&Co(s,n,g),h?l^4?i:g:s},Oo=(e,t,n)=>t.has(e)||Rn("Cannot "+n),Jf=(e,t)=>Object(t)!==t?Rn('Cannot use the "in" operator on this value'):e.has(t),it=(e,t,n)=>(Oo(e,t,"read from private field"),n?n.call(e):t.get(e)),er=(e,t,n)=>t.has(e)?Rn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mt=(e,t,n,r)=>(Oo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),eh=(e,t,n)=>(Oo(e,t,"access private method"),n);function Ni(e,t){if(t){let n;return Fa(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Fa(e)}function ft(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!ft(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!ft(e[i],t[i]))}return!1}function re({get:e},t){return{init(n){return jn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Me(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ni(e.bind(this)),n.set(this,r)),r.value}}function hi(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Xf(Yf({},s),{enumerable:e}))})}}function Rr(...e){const t=e.map(n=>dt(n));return()=>t.forEach(n=>n())}var Jl,ec,tc,nc,rc,sc,Ye,Do,pi,Gi,Ui,Ke,Mo,gi,ic,Hi,Io,mi,Vi,Ki;sc=[re],rc=[re],nc=[re],tc=[hi()],ec=[hi()],Jl=[hi()];var en=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ft(Ye,5,this),er(this,Ke),er(this,Do,Ft(Ye,8,this)),Ft(Ye,11,this),er(this,Mo,Ft(Ye,12,this)),Ft(Ye,15,this),er(this,Io,Ft(Ye,16,this)),Ft(Ye,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return it(this,Ke,Vi)}get initial(){return it(this,Ke,Gi)}get previous(){return it(this,Ke,ic)}set current(e){const t=ne(()=>it(this,Ke,Vi));e&&t&&this.equals(t,e)||Ce(()=>{it(this,Ke,Gi)||Mt(this,Ke,e,Ui),Mt(this,Ke,t,Hi),Mt(this,Ke,e,Ki)})}reset(e=this.defaultValue){Ce(()=>{Mt(this,Ke,void 0,Hi),Mt(this,Ke,e,Ui),Mt(this,Ke,e,Ki)})}};Ye=Qf();Do=new WeakMap;Ke=new WeakSet;Mo=new WeakMap;Io=new WeakMap;pi=An(Ye,20,"#initial",sc,Ke,Do),Gi=pi.get,Ui=pi.set;gi=An(Ye,20,"#previous",rc,Ke,Mo),ic=gi.get,Hi=gi.set;mi=An(Ye,20,"#current",nc,Ke,Io),Vi=mi.get,Ki=mi.set;An(Ye,2,"current",tc,en);An(Ye,2,"initial",ec,en);An(Ye,2,"previous",Jl,en);Zl(Ye,en);function vi(e){return ne(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var zt,th=class{constructor(){er(this,zt,new WeakMap)}get(e,t){var n;return e?(n=it(this,zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return it(this,zt).has(e)||it(this,zt).set(e,new Map),(r=it(this,zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=it(this,zt).get(e))==null?void 0:t.clear():void 0}};zt=new WeakMap;var nh=Object.create,oc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zs=e=>{throw TypeError(e)},Ga=Math.pow,qi=(e,t,n)=>t in e?oc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&qi(e,n,t[n]);if(Na)for(var n of Na(t))ih.call(t,n)&&qi(e,n,t[n]);return e},ah=e=>{var t;return[,,,nh((t=e?.[ac("metadata")])!=null?t:null)]},lc=["class","method","getter","setter","accessor","field","value","get","set"],cc=e=>e!==void 0&&typeof e!="function"?Zs("Function expected"):e,lh=(e,t,n,r,s)=>({kind:lc[e],name:t,metadata:r,addInitializer:i=>n._?Zs("Already initialized"):s.push(cc(i||null))}),ch=(e,t)=>qi(t,ac("metadata"),e[3]),dh=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=lc[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,rh(s,n)),_=r.length-1;_>=0;_--)c=lh(d,n,a={},e[3],v),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(x[p],c),a._=1,cc(o)&&(x[p]=o);return x&&oc(s,n,x),s},uc=(e,t,n)=>t.has(e)||Zs("Cannot "+n),uh=(e,t,n)=>(uc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Zs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(uc(e,t,"write to private field"),t.set(e,n),n),ot=class Yi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Yi(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Yi(t,n)}},bt=class Wt{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:i,height:o,scale:a}=this,c=new Wt(s+t,r+n,i,o);return c.scale=oh({},a),c}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new ot((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Wt))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Wt?ph(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new Wt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],c=o==="x"?i.left:i.top,f=o==="x"?i.width:i.height;return a=="start"?c:a=="end"?c+f:c+f/2};return ot.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Wt.from(t).intersectionRatio(Wt.from(n))}};function ph(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var fc,hc,Xi,ds,Ar,Js=class extends(Xi=en,hc=[Me],fc=[Me],Xi){constructor(t){const n=ot.from(t);super(n,(r,s)=>ot.equals(r,s)),dh(Ar,5,this),fh(this,ds,0),this.velocity={x:0,y:0}}get delta(){return ot.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=ot.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-uh(this,ds),a=c=>Math.round(c/o*100);Ce(()=>{hh(this,ds,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(ot.from(t)),this.velocity={x:0,y:0}}};Ar=ah(Xi);ds=new WeakMap;dc(Ar,2,"delta",hc,Js);dc(Ar,2,"direction",fc,Js);ch(Ar,Js);function Qi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Ga(r,2)+Ga(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var pc=(e=>(e.Horizontal="x",e.Vertical="y",e))(pc||{}),gc=Object.values(pc),gh=Object.create,jo=Object.defineProperty,mh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,Is=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,yc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ln=e=>{throw TypeError(e)},Zi=(e,t,n)=>t in e?jo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Po=(e,t)=>{for(var n in t||(t={}))mc.call(t,n)&&Zi(e,n,t[n]);if(Is)for(var n of Is(t))vc.call(t,n)&&Zi(e,n,t[n]);return e},Ro=(e,t)=>mh(e,yh(t)),Ua=(e,t)=>jo(e,"name",{value:t,configurable:!0}),bc=(e,t)=>{var n={};for(var r in e)mc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Is)for(var r of Is(e))t.indexOf(r)<0&&vc.call(e,r)&&(n[r]=e[r]);return n},Bn=e=>{var t;return[,,,gh((t=e?.[yc("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Ln("Function expected"):e,bh=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:i=>n._?Ln("Already initialized"):s.push(tr(i||null))}),tn=(e,t)=>Zi(t,yc("metadata"),e[3]),Y=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},se=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=xc[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&vh(l<4?s:{get[n](){return De(this,i)},set[n](w){return rt(this,i,w)}},n));l?h&&l<4&&Ua(i,(l>2?"set ":l>1?"get ":"")+n):Ua(s,n);for(var y=r.length-1;y>=0;y--)f=bh(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>xh(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?De:wc)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>rt(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?tr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Ln("Object expected"):(tr(o=a.get)&&(g.get=o),tr(o=a.set)&&(g.set=o),tr(o=a.init)&&x.unshift(o));return l||tn(e,s),g&&jo(s,n,g),h?l^4?i:g:s},Ao=(e,t,n)=>t.has(e)||Ln("Cannot "+n),xh=(e,t)=>Object(t)!==t?Ln('Cannot use the "in" operator on this value'):e.has(t),De=(e,t,n)=>(Ao(e,t,"read from private field"),n?n.call(e):t.get(e)),de=(e,t,n)=>t.has(e)?Ln("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Ao(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wc=(e,t,n)=>(Ao(e,t,"access private method"),n);function _c(e,t){return{plugin:e,options:t}}function Lr(e){return t=>_c(e,t)}function Sr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var kc,$r,Lo,us;kc=[re];var qe=class{constructor(e,t){this.manager=e,this.options=t,de(this,Lo,Y($r,8,this,!1)),Y($r,11,this),de(this,us,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ne(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=dt(e.bind(this));return De(this,us).add(t),t}destroy(){De(this,us).forEach(e=>e())}static configure(e){return _c(this,e)}};$r=Bn(null);Lo=new WeakMap;us=new WeakMap;se($r,4,"disabled",kc,qe,Lo);tn($r,qe);var Br=class extends qe{},fs,yi=class{constructor(e){this.manager=e,this.instances=new Map,de(this,fs,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Sr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of De(this,fs))if(!n.includes(r)){if(r.prototype instanceof Br)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);rt(this,fs,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};fs=new WeakMap;function wh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Jr=[],hn,pn,_h=class extends qe{constructor(e){super(e),de(this,hn),de(this,pn),this.computeCollisions=this.computeCollisions.bind(this),rt(this,pn,jn(Jr)),this.destroy=Rr(()=>{const t=this.computeCollisions(),n=ne(()=>this.manager.dragOperation.position.current);if(t!==Jr){const r=De(this,hn);if(rt(this,hn,n),r&&n.x==r.x&&n.y==r.y)return}else rt(this,hn,void 0);De(this,pn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ne(()=>{e?De(this,pn).value=this.computeCollisions():rt(this,hn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Jr;const a=[],c=[];for(const f of e??n.droppables){if(f.disabled||s&&!f.accepts(s))continue;const d=t??f.collisionDetector;if(!d)continue;c.push(f),f.shape;const l=ne(()=>d({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return c.length===0?Jr:(a.sort(wh),a)}get collisions(){return De(this,pn).value}};hn=new WeakMap;pn=new WeakMap;var Sc,$c,Tc,Bo,Ec,ht,Fo,xn,zo,Wo;Tc=[re],$c=[re],Sc=[re];var $t=class Nt{constructor(t,n){de(this,Fo,Y(ht,8,this)),Y(ht,11,this),de(this,xn),de(this,zo,Y(ht,12,this)),Y(ht,15,this),de(this,Wo,Y(ht,16,this)),Y(ht,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let c=s;rt(this,xn,jn(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var f;return[()=>{const{id:d,manager:l}=this;if(d!==c)return c=d,l?.registry.register(this),()=>l?.registry.unregister(this)},...(f=r?.())!=null?f:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=De(this,xn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:De(this,xn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return wc(i=Nt,Bo,Ec).call(i)})),Nt.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};ht=Bn(null);Bo=new WeakSet;Ec=function(){const e=$t.pendingIdChanges;$t.pendingIdChanges=null,e&&Ce(()=>{for(const[t,n]of e)De(t,xn).value=n})};Fo=new WeakMap;xn=new WeakMap;zo=new WeakMap;Wo=new WeakMap;se(ht,4,"manager",Tc,$t,Fo);se(ht,4,"data",$c,$t,zo);se(ht,4,"disabled",Sc,$t,Wo);de($t,Bo);tn(ht,$t);$t.pendingIdChanges=null;var ei=$t,Ha=class{constructor(){this.map=jn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,c]of n)if(c===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Rr(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Cc,Oc,Dc,Mc,Ic,jc,Ji,Xe,No,Go,Uo,xt=class extends(Ji=ei,jc=[re],Ic=[re],Mc=[re],Dc=[Me],Oc=[Me],Cc=[Me],Ji){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:c}=r,f=bc(r,["modifiers","type","sensors","plugins","effects"]);super(Ro(Po({},f),{effects:()=>{var d;return[...(d=c?.())!=null?d:[],()=>{const{manager:l,plugins:u}=this;if(!(!l||!u))for(const h of u){const{plugin:p}=Sr(h);l.registry.plugins.register(p)}}]}}),n),Y(Xe,5,this),de(this,No,Y(Xe,8,this)),Y(Xe,11,this),de(this,Go,Y(Xe,12,this)),Y(Xe,15,this),de(this,Uo,Y(Xe,16,this,this.isDragSource?"dragging":"idle")),Y(Xe,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=f.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=Sr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};Xe=Bn(Ji);No=new WeakMap;Go=new WeakMap;Uo=new WeakMap;se(Xe,4,"type",jc,xt,No);se(Xe,4,"modifiers",Ic,xt,Go);se(Xe,4,"status",Mc,xt,Uo);se(Xe,2,"isDropping",Dc,xt);se(Xe,2,"isDragging",Oc,xt);se(Xe,2,"isDragSource",Cc,xt);tn(Xe,xt);var Pc,Rc,Ac,Lc,Bc,Fc,eo,Be,Ho,Vo,Ko,qo,Yo,wt=class extends(eo=ei,Fc=[re],Bc=[re],Lc=[re],Ac=[re],Rc=[re],Pc=[Me],eo){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,c=bc(r,["accept","collisionDetector","collisionPriority","type"]);super(c,n),Y(Be,5,this),de(this,Ho,Y(Be,8,this)),Y(Be,11,this),de(this,Vo,Y(Be,12,this)),Y(Be,15,this),de(this,Ko,Y(Be,16,this)),Y(Be,19,this),de(this,qo,Y(Be,20,this)),Y(Be,23,this),de(this,Yo,Y(Be,24,this)),Y(Be,27,this),this.accept=s,this.collisionDetector=i,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Be=Bn(eo);Ho=new WeakMap;Vo=new WeakMap;Ko=new WeakMap;qo=new WeakMap;Yo=new WeakMap;se(Be,4,"accept",Fc,wt,Ho);se(Be,4,"type",Bc,wt,Vo);se(Be,4,"collisionDetector",Lc,wt,Ko);se(Be,4,"collisionPriority",Ac,wt,qo);se(Be,4,"shape",Rc,wt,Yo);se(Be,2,"isDropTarget",Pc,wt);tn(Be,wt);var kh=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function hs(e,t=!0){let n=!1;return Ro(Po({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var $h=class extends Br{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Rr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||ei.pendingIdChanges)return;const o=hs({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;ne(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Fn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Fn||{}),zn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(zn||{}),zc,Wc,Nc,Gc,Uc,Hc,Vc,ct,Xo;Vc=[re],Hc=[Me],Uc=[Me],Gc=[Me],Nc=[Me],Wc=[Me],zc=[Me];var Et=class{constructor(){Y(ct,5,this),de(this,Xo,Y(ct,8,this,"idle")),Y(ct,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};ct=Bn(null);Xo=new WeakMap;se(ct,4,"value",Vc,Et,Xo);se(ct,2,"current",Hc,Et);se(ct,2,"idle",Uc,Et);se(ct,2,"initializing",Gc,Et);se(ct,2,"initialized",Nc,Et);se(ct,2,"dragging",Wc,Et);se(ct,2,"dropped",zc,Et);tn(ct,Et);var Th=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return ne(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=hs({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ne(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:i}=e;Ce(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=hs({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Ce(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ne(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=hs({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,c,f,d,l;if(o.defaultPrevented)return;const u=(l=e.to)!=null?l:{x:r.position.current.x+((c=(a=e.by)==null?void 0:a.x)!=null?c:0),y:r.position.current.y+((d=(f=e.by)==null?void 0:f.y)!=null?d:0)};r.position.current=u})})}stop(e={}){return ne(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const c={resume:()=>{},abort:()=>{}};return i=new Promise((f,d)=>{c.resume=f,c.abort=d}),c};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const c=ne(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),f=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(c){const{source:d}=r,l=dt(()=>{d?.status==="idle"&&(l(),f())})}else this.manager.renderer.rendering.then(f)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),i?i.then(a).catch(()=>r.reset()):a()})}},En=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Eh=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},ps,Kc=class{constructor(e){this.options=e,de(this,ps)}set controller(e){rt(this,ps,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=De(this,ps))==null||t.activate(e)}};ps=new WeakMap;var Va=class extends qe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Ch=class{constructor(e){this.draggables=new Ha,this.droppables=new Ha,this.plugins=new yi(e),this.sensors=new yi(e),this.modifiers=new yi(e)}register(e,t){if(e instanceof xt)return this.draggables.register(e.id,e);if(e instanceof wt)return this.droppables.register(e.id,e);if(e.prototype instanceof Va)return this.modifiers.register(e,t);if(e.prototype instanceof En)return this.sensors.register(e,t);if(e.prototype instanceof qe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof ei)return e instanceof xt?this.draggables.unregister(e.id,e):e instanceof wt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Va)return this.modifiers.unregister(e);if(e.prototype instanceof En)return this.sensors.unregister(e);if(e.prototype instanceof qe)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},qc,Yc,Xc,Qc,Zc,Jc,ed,td,nd,nr,gs,gn,Ee,Qo,Zo,Jo,ea,ta,rr;nd=[Me],td=[re],ed=[re],Jc=[re],Zc=[re],Qc=[re],Xc=[Me],Yc=[Me],qc=[Me];var mt=class{constructor(e){Y(Ee,5,this),de(this,nr),de(this,gs),de(this,gn,new en(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Et,de(this,Qo,Y(Ee,8,this,!1)),Y(Ee,11,this),de(this,Zo,Y(Ee,12,this,null)),Y(Ee,15,this),de(this,Jo,Y(Ee,16,this,null)),Y(Ee,19,this),de(this,ea,Y(Ee,20,this,null)),Y(Ee,23,this),de(this,ta,Y(Ee,24,this,[])),Y(Ee,27,this),this.position=new Js({x:0,y:0}),de(this,rr,{x:0,y:0}),rt(this,nr,e)}get shape(){const{current:e,initial:t,previous:n}=De(this,gn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?De(this,gn).current=e:De(this,gn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=De(this,nr).registry.draggables.get(t);return n&&rt(this,gs,n),(e=n??De(this,gs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=De(this,nr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Ro(Po({},this.snapshot()),{transform:n}));return rt(this,rr,n),n}snapshot(){return ne(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:De(this,rr),shape:this.shape?vi(this.shape):null,position:vi(this.position),status:vi(this.status),canceled:this.canceled}))}reset(){Ce(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,De(this,gn).reset(),this.position.reset({x:0,y:0}),rt(this,rr,{x:0,y:0}),this.modifiers=[]})}};Ee=Bn(null);nr=new WeakMap;gs=new WeakMap;gn=new WeakMap;Qo=new WeakMap;Zo=new WeakMap;Jo=new WeakMap;ea=new WeakMap;ta=new WeakMap;rr=new WeakMap;se(Ee,2,"shape",nd,mt);se(Ee,4,"canceled",td,mt,Qo);se(Ee,4,"activatorEvent",ed,mt,Zo);se(Ee,4,"sourceIdentifier",Jc,mt,Jo);se(Ee,4,"targetIdentifier",Zc,mt,ea);se(Ee,4,"modifiers",Qc,mt,ta);se(Ee,2,"source",Xc,mt);se(Ee,2,"target",Yc,mt);se(Ee,2,"transform",qc,mt);tn(Ee,mt);var Oh={get rendering(){return Promise.resolve()}};function gt(e,t){return typeof e=="function"?e(t):e??t}var Dh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(u=>u.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=gt(r.plugins,[]),i=gt(r.sensors,[]),o=gt(r.modifiers,[]),a=(n=r.renderer)!=null?n:Oh,c=new Sh(this),f=new Ch(this);this.registry=f,this.monitor=c,this.renderer=a,this.actions=new Th(this),this.dragOperation=new mt(this),this.collisionObserver=new _h(this),this.plugins=[$h,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,l=Rr(()=>{var u,h,p;const v=ne(()=>this.dragOperation.modifiers),x=this.modifiers;for(const _ of v)x.includes(_)||_.destroy();this.dragOperation.modifiers=(p=(h=(u=this.dragOperation.source)==null?void 0:u.modifiers)==null?void 0:h.map(_=>{const{plugin:g,options:y}=Sr(_);return new g(this,y)}))!=null?p:x});this.destroy=()=>{l(),d()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},rd=e=>{throw TypeError(e)},na=(e,t,n)=>t.has(e)||rd("Cannot "+n),q=(e,t,n)=>(na(e,t,"read from private field"),t.get(e)),Je=(e,t,n)=>t.has(e)?rd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),nt=(e,t,n,r)=>(na(e,t,"write to private field"),t.set(e,n),n),sd=(e,t,n)=>(na(e,t,"access private method"),n);function ti(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(ti(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function ni(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function ra(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Fr(e){return"nodeType"in e}function st(e){var t,n,r;return e?ra(e)?e:Fr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function sa(e){const{Document:t}=st(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function At(e){return!e||ra(e)?!1:e instanceof st(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function od(e){return e instanceof st(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Wn(e){return e?ra(e)?e.document:Fr(e)?sa(e)?e:At(e)||od(e)?e.ownerDocument:document:document:document}function Mh(e){var t,n,r,s;const{documentElement:i}=Wn(e),o=st(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,c=(n=o?.height)!=null?n:i.clientHeight,f=(r=o?.offsetTop)!=null?r:0,d=(s=o?.offsetLeft)!=null?s:0;return{top:f,left:d,right:d+a,bottom:f+c,width:a,height:c}}function Ih(e,t){if(jh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function jh(e){return e.tagName==="DETAILS"}function Tr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let c=t;const{ownerDocument:f}=e,d=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Ih(l)){const y=l.getBoundingClientRect(),w=n*(y.bottom-y.top),b=n*(y.right-y.left),T=n*(y.bottom-y.top),C=n*(y.right-y.left);c={top:Math.max(c.top,y.top-w),right:Math.min(c.right,y.right+b),bottom:Math.min(c.bottom,y.bottom+T),left:Math.max(c.left,y.left-C),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top}l=l.parentElement}const u=d.visualViewport,h=(s=u?.offsetTop)!=null?s:0,p=(i=u?.offsetLeft)!=null?i:0,v=(o=u?.width)!=null?o:d.innerWidth,x=(a=u?.height)!=null?a:d.innerHeight,_=n*x,g=n*v;return c={top:Math.max(c.top,h-_),right:Math.min(c.right,p+v+g),bottom:Math.min(c.bottom,h+x+_),left:Math.max(c.left,p-g),width:0,height:0},c.width=c.right-c.left,c.height=c.bottom-c.top,c.width<0&&(c.width=0),c.height<0&&(c.height=0),c}function Cn(e){return{x:e.clientX,y:e.clientY}}var ad=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function to(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...to(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...to(s.document,t))}}catch{}return n}function ia(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ld(){var e,t;const n=ia()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function oa(e){return!e||!Fr(e)?!1:e instanceof st(e).ShadowRoot}function js(e){if(e&&Fr(e)){let t=e.getRootNode();if(oa(t))return t;if(t instanceof Document)return t}return Wn(e)}function aa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ph(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,o)=>{const a=r[o];if(Ka(i)&&Ka(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),qa(i)&&qa(a)&&a.width>0&&a.height>0){const c=i.getContext("2d");c?.drawImage(a,0,0)}}),n}function Ka(e){return"value"in e}function qa(e){return e.tagName==="CANVAS"}function cd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Rh(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return cd(s,{x:t-i,y:n-o})}}return r}function Rh(e){return e?.tagName==="IFRAME"}var no=new WeakMap;function Ah(e){return e.closest(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),k=require("../useCompiledDocument-zYEfLogf.cjs.js"),$=require("@mui/material"),S=require("react"),be=require("../ServerProvider-e2369oom.cjs.js"),me=require("../text-entry-BJwltZiy.cjs.js"),Nf=require("react-dom"),uc=require("@tanstack/react-query"),Ie=e=>e.kind==="text",ce=e=>e.kind!=="text",lr=e=>ce(e)?e.label??e.name:e.name,dt=e=>e.declaration.kind==="query"?e.name:`${e.source} -> ${e.name}`,Hn=e=>e.declaration.kind==="inherited"||e.declaration.kind==="query",fe=e=>Ie(e)?`text.${e.name}`:e.declaration.kind==="query"?`query.${e.name}`:`${e.source}.${e.name}`,Ka=".malloy-big-value, .malloy-table",zf=e=>e.querySelector(Ka)!==null&&![...e.querySelectorAll(".malloy-chart")].some(t=>t.closest(Ka)===null),As=(e,t)=>Ie(e)?k.MIN_TEXT_TILE_ROWS:t&&zf(t)?k.MIN_VALUE_TILE_ROWS:k.MIN_TILE_ROWS,Fr=e=>e.rowspan??k.PLACED_DEFAULT_ROWSPAN[Ie(e)?"text":"query"];function Ut(e,t){if(e.row===void 0||e.col===void 0)return;const n=Math.min(e.colspan??1,t);return{row:e.row,col:Math.min(e.col,t-n+1),colspan:n,rowspan:Fr(e)}}const Wr=(e,t)=>e.col<t.col+t.colspan&&t.col<e.col+e.colspan&&e.row<t.row+t.rowspan&&t.row<e.row+e.rowspan;function In(e){return e.map((t,n)=>({tile:t,index:n})).sort((t,n)=>(t.tile.row??1/0)-(n.tile.row??1/0)||(t.tile.col??1/0)-(n.tile.col??1/0)||t.index-n.index).map(({tile:t})=>t)}function Rt(e,t,n){const r=e.map(a=>({...a})),s=[],o=a=>{const l=Ut(r[a],t);l&&(r[a].col=l.col,s.push(l))};n!==void 0&&o(n);const i=r.map((a,l)=>({tile:a,index:l})).filter(({index:a,tile:l})=>a!==n&&l.row!==void 0).sort((a,l)=>(a.tile.row??0)-(l.tile.row??0)||(a.tile.col??0)-(l.tile.col??0)||a.index-l.index);for(const{index:a}of i){const l=Ut(r[a],t);if(l){for(;;){const u=s.filter(c=>Wr(l,c));if(u.length===0)break;l.row=Math.max(...u.map(c=>c.row+c.rowspan))}r[a].row=l.row,o(a)}}return r}function Gf(e,t,n,r){const s=e.flatMap((l,u)=>{const c=u===t?void 0:Ut(l,r);return c?[c]:[]}),o=Math.max(1,...s.map(l=>l.row+l.rowspan)),i={...e[t],...n,row:Math.min(n.row,o)},a=Ut(i,r);if(a){for(;;){const l=s.filter(u=>u.row<a.row&&Wr(a,u));if(l.length===0)break;a.row=Math.max(...l.map(u=>u.row+u.rowspan))}i.row=a.row}return Rt(e.map((l,u)=>u===t?i:l),r,t)}const Ls=(e,t)=>(e-k.GRID_GAP_PX*(t-1))/t,fc=k.TILE_ROW_PX+k.GRID_GAP_PX;function hc(e,t,n,r,s){const o=Math.min(n,r),i=Math.round(e/(s+k.GRID_GAP_PX))+1;return{row:Math.max(1,Math.round(t/fc)+1),col:Math.min(Math.max(i,1),r-o+1)}}function pc(e,t,n,r){const s=e.map((o,i)=>{if(o.row!==void 0&&o.col!==void 0)return o;const a=t[i];if(!a)return o;const{break:l,...u}=o,c=o.colspan??Math.max(1,Math.round((a.width+k.GRID_GAP_PX)/(r+k.GRID_GAP_PX))),d=hc(a.left,a.top,c,n,r),f=Math.round((a.top+a.height+k.GRID_GAP_PX)/fc);return{...u,...d,colspan:c,rowspan:o.rowspan??Math.max(As(o),f-d.row+1)}});return Rt(s,n)}function Va(e,t,n){const r=e.flatMap((o,i)=>{const a=i===t?void 0:Ut(o,n);return a?[a]:[]});if(r.length===0)return[...e];const s=Math.max(...r.map(o=>o.row+o.rowspan));return e.map((o,i)=>i===t?{...o,row:s,col:1}:o)}function gc(e,t){const n=e.map(o=>({...o})),r=[],s=n.map((o,i)=>({tile:o,index:i})).filter(({tile:o})=>o.row!==void 0&&o.col!==void 0).sort((o,i)=>(o.tile.row??0)-(i.tile.row??0)||(o.tile.col??0)-(i.tile.col??0)||o.index-i.index);for(const{index:o}of s){const i=Ut(n[o],t);if(i){for(;i.row>1&&!r.some(a=>Wr({...i,row:i.row-1},a));)i.row-=1;n[o].row=i.row,n[o].col=i.col,r.push(i)}}return n}const Hf=(e,t)=>gc(e,t).some((n,r)=>n.row!==e[r].row||n.col!==e[r].col);function qf(e){return In(e).map(t=>{const{row:n,col:r,...s}=t;return s})}const Uf=(e,t,n)=>e.map((r,s)=>s===t?{...r,...n}:r);function Xa(e,t,n,r,s){const o=Ut(e[t],s);if(!o)return[...e];const i={row:Math.max(1,o.row+n),col:Math.min(Math.max(1,o.col+r),s-o.colspan+1)};if(i.row===o.row&&i.col===o.col)return[...e];const a={...o,...i},l=e.flatMap((h,y)=>{const g=y===t?void 0:Ut(h,s);return g&&Wr(a,g)&&!Wr(o,g)?[{i:y,other:g}]:[]}),u=l.length===1?l[0]:void 0;if(!u)return Rt(Uf(e,t,i),s,t);const{i:c,other:d}=u,f=e.map(h=>({...h}));return n>0?(f[c].row=o.row,f[t].row=o.row+d.rowspan):n<0?(f[t].row=d.row,f[c].row=d.row+o.rowspan):r>0?(f[c].col=o.col,f[t].col=o.col+d.colspan):(f[t].col=d.col,f[c].col=d.col+o.colspan),Rt(f,s,t)}const mc=(e,t)=>e?.col===void 0?t:Math.max(1,t-e.col+1);function Kf(e){return Ie(e)||e.rowspan===void 0?e:k.isChartPick(e.chart)&&e.chart!=="big_value"&&e.rowspan<k.MIN_TILE_ROWS?{...e,rowspan:k.MIN_TILE_ROWS}:e}const vc=k.createSvgIcon(m.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),yc=k.createSvgIcon(m.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),Vf=k.createSvgIcon(m.jsx("path",{d:"M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8m-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91"}));function xc(e){const{theme:t}=be.usePublisherTheme(),n=t.ui,[r,s]=S.useState(null),{status:o,draftKeptAt:i,discard:a,restored:l,dismissRestored:u}=e,c=l!==void 0&&!l.pending&&o==="unsaved"?l:void 0,d=o==="saved"?"Saved":o==="saving"?"Saving…":i!==void 0?"Draft saved":"Unsaved changes",f=c?`Restored your unsaved edits from ${qo(c.savedAt)}`:void 0,h=o==="unsaved"&&i!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,y=a!==void 0&&o==="unsaved",g=()=>{s(null),c&&u?.()},w=v=>({display:"inline-flex",alignItems:"center",justifyContent:"flex-end",gap:.75,minWidth:132,height:n.size.control,px:1,borderRadius:n.radius.control,font:"inherit",...n.type.control,whiteSpace:"nowrap",color:o==="saved"?v.palette.text.secondary:v.palette.text.primary,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...y?{"&:hover":{bgcolor:v.palette.action.hover}}:{}}),x=m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"span","aria-hidden":!0,sx:{width:16,height:16,flex:"none",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:o==="saved"?m.jsx(k.CheckIcon,{sx:{fontSize:16}}):m.jsx($.Box,{component:"span","data-restored":c?"true":void 0,sx:v=>({width:7,height:7,borderRadius:"50%",bgcolor:c?t.accent:o==="saving"||i!==void 0?v.palette.text.disabled:v.palette.warning.main,transition:`background-color ${k.MOTION_FAST}`})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:d}),m.jsx(k.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:y?"visible":"hidden"}})]}),p=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:Xf,children:f?`${d}. ${f}.`:d});return m.jsxs(m.Fragment,{children:[p,m.jsx($.Tooltip,{title:f??h,describeChild:!0,children:y?m.jsx($.ButtonBase,{className:k.reportClasses.saveStatus,"aria-label":d,...f?{"aria-description":f}:{},"aria-haspopup":"menu","aria-expanded":r!==null,onClick:v=>s(v.currentTarget),sx:w,children:x}):m.jsx($.Box,{component:"span",className:k.reportClasses.saveStatus,sx:w,children:x})}),m.jsxs($.Menu,{className:k.reportClasses.menu,anchorEl:r,open:r!==null,onClose:g,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:-4,horizontal:"left"},slotProps:{paper:{sx:{minWidth:240,borderRadius:n.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:n.shadow.menu}}},MenuListProps:{dense:!0,sx:{py:.5}},children:[(f!==void 0||i!==void 0)&&m.jsx($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:f??`Kept in this browser at ${qo(i)}`}),m.jsxs($.MenuItem,{onClick:()=>{s(null),a?.()},sx:{mx:.5,borderRadius:n.radius.control,gap:1.25,color:"error.main","&.Mui-focusVisible":{outline:"none",bgcolor:"action.hover"}},children:[m.jsx(Vf,{fontSize:"small"}),"Discard edits"]})]})]})}function qo(e){const t=new Date(e);return new Date().toDateString()===t.toDateString()?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):t.toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}const Xf={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},Uo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),cn=Uo?"⌘":"Ctrl+",Ya=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},So=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function Yf(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e});const[n,r]=S.useState(!1);S.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),S.useEffect(()=>{const s=o=>{const i=t.current;if(i.paused)return;const a=Uo?o.metaKey:o.ctrlKey,l=o.key.toLowerCase();if(o.key==="Escape"){if(Ya(o.target)||So(o.target))return;i.escape();return}if(Ya(o.target)){if(a&&l==="s"){if(o.preventDefault(),!i.save||So(o.target))return;o.target.blur(),r(!0)}return}if(So(o.target)){a&&l==="s"&&o.preventDefault();return}if(a&&l==="z"){o.preventDefault(),o.shiftKey?i.redo():i.undo();return}if(!Uo&&a&&l==="y"){o.preventDefault(),i.redo();return}if(a&&l==="s"){o.preventDefault(),i.save?.();return}if(i.move&&o.altKey&&!a&&!o.shiftKey){const u=o.key==="ArrowLeft"?[0,-1]:o.key==="ArrowRight"?[0,1]:o.key==="ArrowUp"?[-1,0]:o.key==="ArrowDown"?[1,0]:void 0;if(u&&i.move(u[0],u[1])){o.preventDefault();return}}i.nudge&&!a&&!o.altKey&&!o.shiftKey&&(o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.preventDefault(),i.nudge(o.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Mr=(e,t,n=be.DEFAULT_UI)=>({height:n.size.control,minHeight:n.size.control,px:1.5,borderRadius:n.radius.control,boxShadow:"none",...n.type.control,"&:hover":{boxShadow:"none"},"& .MuiButton-startIcon":{mr:.5,"& svg":{fontSize:18}},"&.MuiButton-outlined":{borderColor:e,"&:hover":{borderColor:t}}}),Nr=(e=be.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),Bs={height:20,alignSelf:"center",mx:.5,my:0},Fs=(e,t=be.DEFAULT_UI)=>({height:t.size.control,boxSizing:"border-box",borderRadius:t.radius.control,border:`1px solid ${e}`,overflow:"hidden",bgcolor:"background.paper","& .MuiToggleButton-root":{border:"none",borderRadius:"0 !important",m:"0 !important",px:1.5,py:0,height:"100%",...t.type.control,color:"text.secondary","& + .MuiToggleButton-root":{borderLeft:`1px solid ${e}`},"&:hover":{bgcolor:"action.hover"},"&.Mui-selected, &.Mui-selected:hover":{bgcolor:"action.selected",color:"text.primary"}}}),Ko={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function Qf({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:o,onSave:i,savesTo:a="package",saveLabel:l,saveButton:u,actions:c,onAddTile:d,arrange:f,onExit:h,saveStatus:y}){const{theme:g}=be.usePublisherTheme(),w=k.edgeColor(g.cardBorder),x=k.hoverEdgeColor(g.cardBorder,g.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[f,d&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),onClick:d,"aria-label":"Add tile",sx:Mr(w,x,g.ui),children:"Tile"}),d&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Nr(g.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:Nr(g.ui),children:m.jsx(vc,{fontSize:"small"})})})}),(c||i||h)&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c,i&&y&&m.jsx(xc,{...y}),i?m.jsx($.Tooltip,{title:s?`Save (${cn}S) · ${l??Ko[a]}`:l??Ko[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||o,onClick:i,sx:{...Mr(w,x,g.ui),minWidth:88},children:o?"Saving…":s?"Save":"Saved"})})}):null,i&&m.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:o?"Saving":s?"Unsaved changes":"All changes saved"}),h&&m.jsx(k.SecondaryButton,{label:"Close",icon:m.jsx(k.CheckIcon,{}),onClick:h})]})}const Zf=e=>`This view has no field for the x-axis: ${e.toLowerCase()} needs a group by, such as a date or a category`,Qa={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map",combo_chart:"Bar and line"};function bc(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this tile's details":n==="unlisted"?"Not in the model's list, so its shape is unknown":void 0,s=e?.shape,o=a=>{if(t===a)return;if(a==="big_value")return e?.aggregateOnly===!0?void 0:s&&s.groupBys>0?"This view has a group by, so it is more than one row; big numbers need a view of totals only":r??"Needs results that are only totals (no group by)";if(a==="shape_map"||a==="segment_map")return e?.chart===a?void 0:r??"Needs a map chart set in the model";if(e?.chart===a)return;if(!s)return a==="combo_chart"?r??"Needs a view with a group by and exactly two totals: the first is drawn as bars, the second as a line":void 0;const l=`A ${Qa[a].toLowerCase()} chart`;switch(k.chartShapeGap(a,s)){case"no_x_axis":return Zf(l);case"combo_totals":return`A bar and line chart needs exactly two totals, the first drawn as bars and the second as a line; this view has ${s.totals}`;case"no_y_axis":return`This view has no total for the y-axis: ${l.toLowerCase()} needs at least one aggregate`;default:return}};return[{value:"default",label:"Default",hint:"As set in the model"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map","combo_chart"].map(a=>{const l=o(a);return{value:a,label:Qa[a],...l?{disabled:!0,reason:l}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Za(e){return e.description??k.readableName(e.name)}const Jf={bar_chart:"a bar chart",line_chart:"a line chart",scatter_chart:"a scatter chart",combo_chart:"a bar and line chart",shape_map:"a shape map",segment_map:"a segment map",big_value:"a big value",sparkline:"a sparkline"},ls=(e,t)=>`${e}\0${t}`;function eh({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:o,onAddText:i,renderPreview:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,c=k.edgeColor(l.cardBorder),d=S.useMemo(()=>n?.sources??[],[n]),[f,h]=S.useState(""),[y,g]=S.useState(),[w,x]=S.useState(""),[p,v]=S.useState("default"),_=S.useRef(null),b=S.useMemo(()=>{const j=new Set(t.sources.map(z=>z.base));return[...d].sort((z,D)=>Number(j.has(D.name))-Number(j.has(z.name)))},[d,t]),E=b.filter(j=>j.views.length>0),T=b.filter(j=>j.views.length===0),M=S.useMemo(()=>new Map(E.flatMap(j=>j.views.map(z=>[ls(j.name,z.name),{source:j,view:z,key:ls(j.name,z.name)}]))),[E]),O=S.useMemo(()=>E.map(j=>({key:j.name,label:j.name,...j.description?{detail:j.description}:{},entries:j.views.map(z=>({key:ls(j.name,z.name),name:z.name,title:Za(z),...z.chart?{chart:z.chart}:{}}))})),[E]),C=y===void 0?void 0:M.get(y);S.useEffect(()=>{if(!e)return;h(""),x(""),v("default");const j=E[0]?.views[0];g(j&&E[0]?ls(E[0].name,j.name):void 0)},[e]);const A=C?[C.source.name,C.view.name].filter(j=>!me.isBareName(j)).map(j=>`"${j}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,R=C!==void 0&&A===void 0,B=C?Za(C.view):"",G=p!=="default"&&C?{chart:p,chartCarried:C.view.chart?[C.view.chart]:[]}:{},N=(j=C)=>{if(!j||![j.source.name,j.view.name].every(me.isBareName))return;const z=j.key===C?.key,D=k.writtenSpan(Math.ceil(r/2),r);o({base:j.source.name,modelPath:j.source.modelPath,...j.source.exporters?{exporters:j.source.exporters}:{},view:j.view.name,...z&&w.trim()?{label:w.trim()}:{},...z?G:{},...D!==void 0?{colspan:D}:{}})},X=C?bc(C.view,p).filter(j=>j.value!=="custom"&&j.disabled!==!0):[];return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.addTileDialog}`,open:e,onClose:s,maxWidth:"md",initialFocus:_,title:"Add a tile",description:"Pick what the tile shows from the model. You can change its title and chart now or later.",actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,sx:{mr:"auto"},children:"Add text instead"}),m.jsx($.Button,{onClick:s,children:"Cancel"}),m.jsx($.Button,{variant:"contained",disabled:!R,onClick:()=>N(),children:"Add tile"})]}),children:m.jsxs($.Box,{sx:{mx:-3,mb:-1,borderTop:`1px solid ${c}`,borderBottom:`1px solid ${c}`,display:"grid",gridTemplateColumns:{xs:"1fr",md:"320px minmax(0, 1fr)"},height:{md:460}},children:[m.jsx($.Box,{sx:{display:"flex",flexDirection:"column",minHeight:0,borderRight:{md:`1px solid ${c}`},maxHeight:{xs:280,md:"none"}},children:m.jsx(k.ViewPicker,{groups:O,query:f,onQuery:h,picked:C?.key,onPick:j=>{g(j),v("default")},onTake:j=>N(M.get(j)),searchRef:_,empty:m.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,p:2},children:n?"This package's models have nothing to put on a tile yet.":"The package's sources are still loading."}),footer:T.length>0&&m.jsxs($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",px:2,pt:1.5},children:["Also in this package, with no views to show:"," ",T.map(j=>j.name).join(", "),"."]})})}),m.jsx($.Box,{sx:j=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${j.palette.text.primary} 3%, ${j.palette.background.paper})`}),children:C?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:j=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:u.radius.tile,border:`1px solid ${c}`,bgcolor:j.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${j.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:C.source.name,modelPath:C.source.modelPath,view:C.view.name,label:w.trim()||B,...p!=="default"?G:{},givens:C.source.givens})}):m.jsxs($.Box,{sx:j=>({flex:1,border:`1px solid ${c}`,borderRadius:u.radius.tile,bgcolor:j.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(k.ChartGlyph,{chart:C.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[C.source.name," → ",C.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:B,value:w,onChange:j=>x(j.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Tile title"}}),m.jsxs($.Box,{children:[m.jsx($.Typography,{component:"div",sx:{...u.type.label,color:"text.secondary",mb:.75},children:"Chart"}),m.jsx($.ToggleButtonGroup,{size:"small",exclusive:!0,value:p,"aria-label":"Chart",onChange:(j,z)=>{z!==null&&v(z)},sx:{...Fs(c,u),"& .MuiToggleButton-root":{...Fs(c,u)["& .MuiToggleButton-root"],textTransform:"none"}},children:X.map(j=>m.jsx($.ToggleButton,{value:j.value,children:j.label},j.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:C.view.chart?`The model sets ${Jf[C.view.chart]??"a chart"}.`:"The model sets no chart, so it shows as a table."})]}),A&&m.jsx($.Typography,{variant:"body2",color:"error",children:A})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}function th(e,t,{modelPath:n,textHeld:r,widths:s,insertAt:o}){t.modelPath&&!r&&(e.imports=k.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));const i=wc(e,t.base),a=Vo(e,i.name,t.view);e.tiles.splice(o??e.tiles.length,0,{name:a,source:i.name,declaration:{kind:"reference",from:t.view},...s&&t.colspan!==void 0?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function wc(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let o=`${t}_tiles`;for(let a=2;s.has(o);a++)o=`${t}_tiles_${a}`;const i={name:o,base:t};return e.sources.push(i),i}function Vo(e,t,n){const r=new Set(e.tiles.filter(ce).filter(o=>o.source===t).map(o=>o.name));let s=`${n}_tile`;for(let o=2;r.has(s);o++)s=`${n}_tile_${o}`;return s}function Ws(e){switch(e.declaration.kind){case"inline":return"Its query is written in this file, and the builder does not copy a query's body.";case"opaque":return`Its query is ${e.declaration.why}, which the builder does not copy.`;case"query":return"It names a query, and a copy could not be told apart from it: the builder writes nothing about such a tile but its place.";default:return e.chart==="custom"?"Its chart line is one the builder does not write, so a copy would lose it.":void 0}}function nh(e,t){const n=e.tiles[t];if(!n||!ce(n)||Ws(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:o,...i}=structuredClone(n);r={...i,name:Vo(e,n.source,n.declaration.from)}}else{const i=e.sources.find(a=>a.name===n.source)??wc(e,n.source,{unscoped:!0});r={name:Vo(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}const s=n.row!==void 0&&n.col!==void 0;return s&&(r={...r,row:(n.row??1)+Fr(n),col:n.col,...n.rowspan!==void 0?{rowspan:n.rowspan}:{}}),e.tiles.splice(t+1,0,r),s&&(e.tiles=Rt(e.tiles,e.columns??k.DEFAULT_COLUMNS,t+1)),t+1}const cs="self";function rh({open:e,document:t,source:n,givenNames:r,dashboards:s,tileLabel:o,onClose:i,onApply:a}){const{theme:l}=be.usePublisherTheme(),u=l.ui,[c,d]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(v=>v.source===n.name);d((n.dimensions??[]).map(v=>{const _=p.find(b=>b.name===v.name);return{name:v.name,expression:v.expression,to:_?.to??[],given:_?.given??""}}))},[e,n,t]);const f=(p,v)=>d(_=>_.map((b,E)=>{if(E!==p)return b;const T={...b};return v(T),T})),h=[cs,...s.filter(p=>p!==cs)],y=p=>p===cs?"This report":p,g=()=>{n&&(a(c.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())},w=k.edgeColor(l.cardBorder),x=(p,v)=>f(p,_=>{v?_.to=_.lastTo?.length?_.lastTo:[cs]:(_.lastTo=_.to,_.to=[])});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.clickableCellsDialog}`,open:e,onClose:i,title:"Clickable cells",description:m.jsxs(m.Fragment,{children:[o&&m.jsxs($.Box,{component:"span",sx:{fontWeight:u.type.label.fontWeight},children:[o," ·"," "]}),"A click on a table cell sets a filter to its value, on this report or on the one it opens. Bars, lines and points on a chart do not respond to a click. Clicks work in the report, not while you edit it."]}),actions:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Button,{variant:"contained",onClick:g,disabled:c.length===0,children:"Apply"})]}),children:c.length===0?m.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,pt:1},children:n?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A click is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",m.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):m.jsx($.Box,{role:"list","aria-label":"Dimensions",children:c.map((p,v)=>{const _=p.to.length>0;return m.jsxs($.Box,{role:"listitem",sx:{display:"grid",gridTemplateColumns:{xs:"auto minmax(0, 1fr)",sm:"auto minmax(0, 0.9fr) minmax(0, 1.6fr)"},alignItems:"center",columnGap:1.5,rowGap:1,py:1.25,borderTop:v===0?"none":`1px solid ${w}`},children:[m.jsx($.Switch,{size:"small",checked:_,onChange:b=>x(v,b.target.checked),slotProps:{input:{"aria-label":`${p.name} is clickable`}}}),m.jsxs($.Box,{sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...u.type.control,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:sh(p.name)}),m.jsxs($.Box,{title:p.expression,sx:{...u.type.code,color:"text.secondary",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[p.name," is ",p.expression]})]}),_?m.jsxs($.Stack,{direction:"row",sx:{gridColumn:{xs:"1 / -1",sm:"auto"},alignItems:"center",gap:1,justifyContent:"flex-end",...u.type.control},children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"Opens"}),m.jsx($.TextField,{select:!0,size:"small",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.map(y).join(", ")},onChange:b=>f(v,E=>{const T=b.target.value,M=Array.isArray(T)?T:String(T).split(",").filter(Boolean);M.length===0&&(E.lastTo=E.to),E.to=M}),sx:{flex:"1 1 150px",minWidth:0,maxWidth:200},children:h.map(b=>m.jsxs($.MenuItem,{value:b,children:[m.jsx($.Checkbox,{size:"small",checked:p.to.includes(b),sx:{p:0,mr:1}}),m.jsx($.ListItemText,{primary:y(b)})]},b))}),m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:"sets"}),m.jsxs($.TextField,{select:!0,size:"small",value:p.given,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0,renderValue:b=>b===""?p.name:String(b)},onChange:b=>f(v,E=>{E.given=b.target.value}),sx:{flex:"1 1 120px",minWidth:0,maxWidth:170},children:[m.jsx($.MenuItem,{value:"",children:m.jsx($.ListItemText,{primary:p.name,secondary:"Named like the dimension"})}),r.map(b=>m.jsx($.MenuItem,{value:b,children:b},b))]})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",textAlign:"right",display:{xs:"none",sm:"block"}},children:"Not clickable"})]},p.name)})})})}function sh(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const oh=k.createSvgIcon(m.jsx("path",{d:"M12 4c4.41 0 8 3.59 8 8s-3.59 8-8 8-8-3.59-8-8 3.59-8 8-8m0-2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 13-4-4h8z"})),ih=k.createSvgIcon(m.jsx("path",{d:"M11 7H2v2h9zm0 8H2v2h9zm5.34-4L12.8 7.46l1.41-1.41 2.12 2.12 4.24-4.24L22 5.34zm0 8-3.54-3.54 1.41-1.41 2.12 2.12 4.24-4.24L22 13.34z"})),ah=k.createSvgIcon(m.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 16H5V10h14zm0-12H5V6h14zm-7 5h5v5h-5z"})),lh=k.createSvgIcon(m.jsx("path",{d:"M19.5 9.5c-1.03 0-1.9.62-2.29 1.5h-2.92c-.39-.88-1.26-1.5-2.29-1.5s-1.9.62-2.29 1.5H6.79c-.39-.88-1.26-1.5-2.29-1.5C3.12 9.5 2 10.62 2 12s1.12 2.5 2.5 2.5c1.03 0 1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5s1.9-.62 2.29-1.5h2.92c.39.88 1.26 1.5 2.29 1.5 1.38 0 2.5-1.12 2.5-2.5s-1.12-2.5-2.5-2.5"})),ch=k.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),dh=k.createSvgIcon(m.jsx("path",{d:"M3 5v14h18V5zm5.33 12H5V7h3.33zm5.34 0h-3.33v-4h3.33zM19 17h-3.33v-4H19zm0-6h-8.67V7H19z"}));function uh(e,t=[]){const n=new Map;for(const o of e.tiles)for(const i of ce(o)?o.filters??[]:[])n.set(i.given,(n.get(i.given)??0)+1);const r=[],s=new Set;for(const o of e.localGivens??[])s.add(o.name),r.push({name:o.name,...o.label===void 0?{}:{label:o.label},type:o.type,...o.suggest?{field:o.suggest.dimension}:{},origin:"dashboard",local:o,boundTiles:n.get(o.name)??0});for(const o of t)s.has(o.name)||(s.add(o.name),r.push({...o,origin:"model",boundTiles:n.get(o.name)??0}));for(const[o,i]of n)s.has(o)||r.push({name:o,origin:"model",boundTiles:i});return r}function Ns(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function fh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function Ir(e,t){const n=fh(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Xo(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function hh(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const ph=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function gh(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,o=me.isStrictName(s)?s:`${s}_FILTER`,i=new Set(t);if(!i.has(o))return o;for(let a=2;;a++)if(!i.has(`${o}_${a}`))return`${o}_${a}`}const mh=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function fr(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Yo=e=>ce(e)&&!Hn(e)&&e.declaration.kind!=="opaque";function vh(e,t){return e.tiles.map(n=>{const r=(ce(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:Ns(t.type)!==void 0?{op:Ns(t.type)}:{}}})}function yh(e,t,n){n.forEach((r,s)=>{const o=e.tiles[s];if(!o||!Yo(o))return;const i=(o.filters??[]).filter(l=>l.given!==t),a=r.include?[...i,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:i;a.length>0?o.filters=a:delete o.filters})}function xh(e,t){const n=(e.localGivens??[]).filter(o=>o.name!==t.name),r=(e.localGivens??[]).findIndex(o=>o.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function bh(e,t){for(const r of e.tiles){if(!ce(r))continue;const s=(r.filters??[]).filter(o=>o.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Qo=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function wh({open:e,document:t,control:n,available:r,takenNames:s=[],fieldsFor:o,onApply:i}){const a=S.useRef(n);e&&(a.current=n);const l=e?n:a.current,u=l!==void 0,[c,d]=S.useState({kind:"new"}),[f,h]=S.useState(""),[y,g]=S.useState("select"),[w,x]=S.useState(""),[p,v]=S.useState(""),[_,b]=S.useState([]),[E,T]=S.useState(!1),[M,O]=S.useState(!1),C=P=>t.sources.find(F=>F.name===P.source)?.base??P.source;S.useEffect(()=>{if(e)if(O(n!==void 0),n){d({kind:"existing",name:n.name}),h(n.label??"");const P=vh(t,n);b(P);const F=P.filter(Y=>Y.include),U=new Set(F.map(Y=>Y.field));v(U.size===1?F[0].field:n.field??""),T(U.size>1)}else d({kind:"new"}),h(""),g("select"),v(""),x(new Date().toISOString().slice(0,10)),b(t.tiles.map(P=>({include:Yo(P),field:""}))),T(!1)},[e,n,t]);const A=S.useMemo(()=>[...(t.localGivens??[]).map(P=>P.name),...r.map(P=>P.name),...s],[t,r,s]),R=S.useMemo(()=>p.trim()?gh(p.trim(),A):"",[p,A]),B=c.kind==="existing"?n??r.find(P=>P.name===c.name):R?{name:R,type:fr({name:R,label:f,kind:y,field:p}).type}:void 0,G=B?.type!==void 0&&!B.type.startsWith("filter<"),N=_.find(P=>P.include)?.op??Ns(B?.type),X=(P,F)=>{O(!0),b(U=>U.map((Y,Se)=>Se===P?{...Y,...F}:Y))},j=P=>{O(!0),b(F=>F.map(U=>({...U,op:P})))},z=P=>{const F=Ns(P);b(U=>U.map(({op:Y,...Se})=>F?{...Se,op:F}:Se))},D=P=>{O(!0),d({kind:"existing",name:P.name}),v(P.field??""),z(P.type)},I=P=>{O(!0),g(P),z(fr({name:"X",label:f,kind:P,field:p}).type)},L=t.tiles.map(Yo),q=L.filter(Boolean).length,H=_.filter((P,F)=>P.include&&L[F]).length,K=t.tiles.filter((P,F)=>(_[F]?.include??!1)&&L[F]&&ce(P)),te=K.length>0?K:t.tiles.filter((P,F)=>L[F]&&ce(P)),ye=S.useMemo(()=>{const P=new Map;let F=!1;for(const U of te){const Y=o?.(U);if(Y){F=!0;for(const Se of Y)P.has(Se.name)||P.set(Se.name,Se)}}return F?[...P.values()]:void 0},[_,t.tiles,o]),_e=(()=>{const P=p.trim();for(const F of K){const U=o?.(F);if(!U||U.some(Y=>Y.name===P))return C(F)}return K[0]?C(K[0]):t.sources[0]?.base})(),re=P=>{O(!0),b(F=>F.map((U,Y)=>({...U,include:P&&L[Y]})))},De=S.useMemo(()=>E?_:_.map(P=>({...P,field:p})),[E,_,p]),ge=P=>{for(const F of te){const U=o?.(F)?.find(Y=>Y.name===P.trim());if(U?.type)return U.type}},ve=P=>Ir(B?.type,P.type),Ge=(P,F)=>{if(P.trim()==="")return"Pick the field this filter compares.";const U=F?o?.(F):void 0;if(!U)return;const Y=U.find(Se=>Se.name===P.trim());if(!Y)return`Not a field of ${F?C(F):"the tiles' source"}.`;if(Y.type&&!Ir(B?.type,Y.type))return`${P.trim()} is ${Xo(Y.type)}; this filter compares ${Xo(B?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},Z=P=>{if(O(!0),v(P),u||c.kind!=="new")return;const F=ge(P),U=fr({name:"X",label:f,kind:y,field:P}).type;F&&!Ir(U,F)&&I(hh(F))},Xe=P=>{const F=t.tiles[P];return F&&ce(F)?F:void 0},ke=De.map((P,F)=>P.include&&L[F]?Ge(P.field,Xe(F)):void 0),ue=ke.every(P=>P===void 0),Ce=M?ke:ke.map(()=>{}),Ae=M&&!E&&H>0?K.map(P=>Ge(p,P)).find(Boolean):void 0,ie=B!==void 0&&ue&&(c.kind==="existing"||p.trim()!==""&&R!==""),qe=()=>{if(!(!B||!ie))if(c.kind==="new")i(B.name,De,fr({name:B.name,label:f.trim()||Qo(B.name),kind:y,field:p.trim(),..._e?{source:_e}:{},...w?{dateDefault:w}:{}}));else if(n?.origin==="dashboard"&&n.local){const P=f.trim(),F=P!==(n.local.label??"");i(B.name,De,F?{...n.local,...P?{label:P}:{}}:void 0)}else i(B.name,De)},Ye=u&&l.origin==="model";return{editing:u,shown:l,fromModel:Ye,source:c,setSource:d,label:f,setLabel:h,kind:y,dateDefault:w,setDateDefault:x,field:p,rows:_,setRows:b,perTile:E,setPerTile:T,newName:R,target:B,valueTyped:G,commonOp:N,setRow:X,setCommonOp:j,pickExisting:D,pickKind:I,bindable:L,bindableCount:q,included:H,commonFields:ye,setAll:re,accepts:ve,pickField:Z,rowProblems:Ce,commonProblem:Ae,canApply:ie,apply:qe}}function Ja({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:o,error:i,helperText:a,disabled:l,autoFocus:u,placeholder:c,inputRef:d,sx:f}){const h=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),y=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return m.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(g,w)=>t(w),value:e,onChange:(g,w)=>t(typeof w=="string"?w:""),disabled:l,disableClearable:!0,renderOption:(g,w)=>S.createElement("li",{...g,key:w},m.jsx(tl,{type:y.get(w)}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,ml:1},children:w})),renderInput:g=>m.jsx($.TextField,{...g,label:s,placeholder:c,autoFocus:u,...d?{inputRef:d}:{},error:i,helperText:a,InputLabelProps:{...g.InputLabelProps,shrink:!0},InputProps:{...g.InputProps,startAdornment:y.get(e.trim())?m.jsx($.Box,{sx:{display:"flex",ml:.5,mr:-.25},children:m.jsx(tl,{type:y.get(e.trim())})}):void 0},inputProps:{...g.inputProps,"aria-label":o}}),sx:f})}const _h=e=>e&&ce(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:e&&ce(e)&&e.declaration.kind==="query"?{label:"Not bindable",reason:"It names a query, whose filters live in that query's own definition."}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function kh({open:e,document:t,control:n,available:r,takenNames:s,fieldsFor:o,onClose:i,onApply:a,onRemove:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{editing:d,shown:f,fromModel:h,source:y,setSource:g,label:w,setLabel:x,kind:p,dateDefault:v,setDateDefault:_,field:b,rows:E,setRows:T,perTile:M,setPerTile:O,newName:C,target:A,valueTyped:R,commonOp:B,setRow:G,setCommonOp:N,pickExisting:X,pickKind:j,bindable:z,bindableCount:D,included:I,commonFields:L,setAll:q,accepts:H,pickField:K,rowProblems:te,commonProblem:ye,canApply:_e,apply:re}=wh({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:o,onApply:a}),De=S.useRef(null),ge=k.edgeColor(u.cardBorder),ve=k.hoverEdgeColor(u.cardBorder,u.tileTitle),[Ge,Z]=S.useState(!1),[Xe,ke]=S.useState(!1);S.useEffect(()=>{e?ke(!0):Z(!1)},[e]),S.useEffect(()=>{Xe&&(ke(!1),Z(d&&I<D))},[Xe]),S.useEffect(()=>{M&&Z(!0)},[M]);const ue=L?.find(P=>P.name===b.trim())?.type,Ce=P=>{if(!ue)return;const F=fr({name:"X",label:w,kind:P,field:b}).type;return Ir(F,ue)?void 0:`${b.trim()} is ${Xo(ue)}, which this control cannot filter.`},Ae=w.trim()||(C?Qo(C):"Filter"),ie=p==="number"?"Any":p==="date"?v?new Date(`${v}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",qe={...Fs(ge,c),alignSelf:"flex-start","& .MuiToggleButton-root":{...Fs(ge,c)["& .MuiToggleButton-root"],textTransform:"none"}},Ye=(P,F,U)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:P??">=",onChange:Y=>F(Y.target.value),inputProps:{"aria-label":U},sx:{width:130},children:ph.filter(Y=>Y.op!=="~").map(Y=>m.jsx($.MenuItem,{value:Y.op,children:Y.label},Y.op))});return m.jsx(k.AppDialog,{className:`${k.reportClasses.dialog} ${k.reportClasses.filterDialog}`,open:e,onClose:i,...d?{}:{initialFocus:De},title:d?f.label??f.name:"Add a filter",description:d?m.jsxs(m.Fragment,{children:[m.jsxs($.Box,{component:"span",sx:{fontFamily:c.font.mono},children:["$",f.name]}),h?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:m.jsxs(m.Fragment,{children:[d&&m.jsx($.Button,{color:"error",startIcon:m.jsx(k.DeleteOutlineIcon,{}),onClick:()=>l(f.name),sx:P=>({mr:"auto",color:k.dangerTextColor(P)}),children:"Remove filter"}),m.jsx($.Button,{onClick:i,children:"Cancel"}),m.jsx($.Tooltip,{title:_e||A===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",onClick:re,disabled:!_e,children:d?"Apply":"Add filter"})})})]}),children:m.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&m.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:y.kind,onChange:(P,F)=>{F==="new"?g({kind:"new"}):F==="existing"&&r[0]&&X(r[0])},"aria-label":"Where the filter comes from",sx:qe,children:[m.jsx($.ToggleButton,{value:"new",children:"New in this report"}),m.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&y.kind==="existing"?m.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:y.name,onChange:P=>{const F=r.find(U=>U.name===P.target.value);F&&X(F)},children:r.map(P=>m.jsxs($.MenuItem,{value:P.name,children:[P.label??P.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",P.name]})]},P.name))}):null,m.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:h?"1fr":"minmax(0, 1.4fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[!M&&m.jsx(Ja,{value:b,onChange:K,fields:L,accepts:H,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:De,error:ye!==void 0,helperText:ye??(!d&&C?`Declared as $${C}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:C?Qo(C):"",value:w,onChange:P=>x(P.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),R&&!M&&Ye(B,N,"Comparison"),!d&&y.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(el,{children:"Control"}),m.jsx($.Box,{role:"radiogroup","aria-label":"Filter kind",sx:{display:"grid",gridTemplateColumns:{xs:"repeat(3, minmax(0, 1fr))",sm:"repeat(5, minmax(0, 1fr))"},gap:1},children:mh.map(P=>{const F=P.kind===p,U=Ce(P.kind);return m.jsx($.Tooltip,{title:U??P.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":F,"aria-label":P.label,"aria-disabled":U!==void 0,onClick:()=>{U===void 0&&j(P.kind)},sx:Y=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:c.radius.tile,border:`1px solid ${F?u.accent:ge}`,boxShadow:F?`0 0 0 1px ${u.accent}`:"none",bgcolor:F?`color-mix(in srgb, ${u.accent} 6%, ${Y.palette.background.paper})`:Y.palette.background.paper,color:F?u.accent:Y.palette.text.secondary,opacity:U?.45:1,cursor:U?"default":"pointer",transition:`border-color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"&:hover":U||F?{}:{borderColor:ve}}),children:[m.jsx($h,{kind:P.kind}),m.jsx($.Box,{component:"span",sx:{...c.type.caption,fontWeight:F?600:500,color:F?u.accent:"text.primary",textAlign:"center"},children:Sh[P.kind]})]})},P.kind)})}),p==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:v,onChange:P=>_(P.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${ge}`,borderRadius:c.radius.tile,overflow:"hidden"},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:1.25,px:1.5,py:1},children:[m.jsx(dh,{"aria-hidden":!0,sx:{fontSize:18,color:"text.secondary"}}),m.jsxs($.Typography,{variant:"body2",sx:{flex:1,minWidth:0},children:[m.jsx($.Box,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:I===D&&D>0?`Applies to all ${I} tile${I===1?"":"s"}`:`Applies to ${I} of ${D} tile${D===1?"":"s"}`}),!M&&b.trim()!==""&&I>0&&m.jsxs($.Box,{component:"span",sx:{color:"text.secondary"},children:[" · each filters on ",m.jsx($.Box,{component:"span",sx:{...c.type.code},children:b.trim()})]})]}),!M&&m.jsx($.Button,{size:"small","aria-expanded":Ge,onClick:()=>Z(P=>!P),children:Ge?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:Ge,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${ge}`,px:.5,pb:1},children:[m.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5,pt:.5},children:[m.jsx($.Checkbox,{size:"small",checked:D>0&&I===D,indeterminate:I>0&&I<D,disabled:D===0,onChange:P=>q(P.target.checked),inputProps:{"aria-label":"All tiles"}}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,color:"text.secondary"},children:"All tiles"}),m.jsx($.Button,{size:"small",onClick:()=>{M||T(P=>P.map(F=>({...F,field:b}))),O(P=>!P)},children:M?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:M?1:0},children:t.tiles.map((P,F)=>{if(!ce(P))return null;const U=E[F],Y=P.label??P.name,Se=M?te[F]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:M?"flex-start":"center",opacity:z[F]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!z[F],checked:(U?.include??!1)&&z[F],inputProps:{"aria-label":`Filter ${Y}`},onChange:we=>G(F,{include:we.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:M?1:0},noWrap:!0,children:Y}),z[F]?M&&m.jsxs(m.Fragment,{children:[R&&Ye(U?.op,we=>G(F,{op:we}),`Comparison for ${Y}`),m.jsx(Ja,{value:U?.field??"",onChange:we=>G(F,{field:we}),fields:o?.(P),accepts:H,label:"Field",ariaLabel:`Field for ${Y}`,disabled:!U?.include,error:Se!==void 0,helperText:Se,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:u.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:_h(t.tiles[F]).reason})]},fe(P))})})]})})]}),I===0&&m.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:-1.5},children:"No tile is ticked, so this control will not appear on the report."}),!h&&m.jsxs($.Box,{children:[m.jsx(el,{children:"Preview"}),m.jsx($.Box,{sx:P=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:c.radius.tile,bgcolor:P.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:P=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:c.radius.control,border:`1px solid ${ge}`,bgcolor:P.palette.background.paper,...c.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:Ae}),m.jsx($.Box,{component:"span",sx:{fontWeight:c.type.label.fontWeight},children:ie}),m.jsx(k.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function el({children:e}){const t=be.usePublisherTheme().theme.ui;return m.jsx($.Typography,{component:"div",sx:{...t.type.label,color:"text.secondary",mb:.75},children:e})}const Sh={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function $h({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(oh,{sx:t});case"multiselect":return m.jsx(ih,{sx:t});case"text":return m.jsx(ch,{sx:t});case"number":return m.jsx(lh,{sx:t});case"date":return m.jsx(ah,{sx:t})}}function tl({type:e}){const t=e?.replace(/_type$/,""),n=t==="string"?"Abc":t==="number"?"#":t==="date"||t==="timestamp"?"Date":t==="boolean"?"T/F":void 0,r=be.usePublisherTheme().theme.ui;return n?m.jsx($.Box,{component:"span","aria-hidden":!0,sx:s=>({fontFamily:r.font.mono,fontSize:10,fontWeight:r.type.label.fontWeight,color:s.palette.text.secondary,bgcolor:s.palette.action.hover,borderRadius:"4px",px:.5,py:.25,minWidth:22,textAlign:"center",flex:"none"}),children:n}):null}const nl=k.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function _c(e,t,n,r){const[s,o]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&o(structuredClone(e))},[t,e]),{draft:s,patch:c=>o(d=>{if(d===void 0)return d;const f=structuredClone(d);return c(f),f}),apply:c=>{if(s===void 0)return;const d=structuredClone(s);c(d),o(d),JSON.stringify(d)!==JSON.stringify(e)&&n(d)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>o(void 0)}}const Th=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,Eh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Ch="Its chart's bars, lines and points do not respond to a click; show it as a table to click its cells.",Oh="Declared on its source, so its chart is set in the model.",Mh="It names a query, so its chart is set where that query is declared.";function Ih({anchor:e,tile:t,onClose:n,onCommit:r,onDrills:s,onDuplicate:o,duplicateBlocked:i,view:a,viewStatus:l}){const{theme:u}=be.usePublisherTheme(),c=u.ui,{draft:d,apply:f,patch:h,close:y}=_c(t,e!==null,r,n),[g,w]=S.useState(void 0),x=d!==void 0&&ce(d)?d:void 0,p=x!==void 0&&!Hn(x),v=D=>f(I=>{ce(I)&&D(I)}),_=S.useRef(void 0),b=S.useRef(null),E=e!==null;S.useEffect(()=>{E?_.current=t&&ce(t)?t.chart:void 0:w(void 0)},[E]);const T=x?.chart??"default",M=bc(a,T,l),O=x?x.declaration.kind==="query"?Mh:p?x.chart==="custom"?Th(x.chartLines):void 0:Oh:void 0,C=D=>v(I=>{const L=_.current;D===(L??"default")?(L===void 0?delete I.chart:I.chart=L,delete I.chartCarried):(I.chart=D,a?I.chartCarried=a.chart?[a.chart]:[]:delete I.chartCarried)}),A=p?s?void 0:"Its source declares no dimension a click could filter by.":void 0,R=T==="default"?a?.chart:T,B=R!==void 0&&Eh.has(R)?Ch:void 0,G=D=>I=>w({kind:D,anchor:I.currentTarget}),N=O??(R===void 0||!Dh.has(R)?"Only a bar, line, scatter or bar and line chart has a color to set.":void 0),X=Array.from(new Set(u.series.map(k.seriesColorFrom).filter(D=>D!==void 0))).slice(0,8),j=D=>v(I=>{D===void 0?delete I.color:I.color=D.toLowerCase()}),z=(D,I,L)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:D,...L?{secondary:L}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),I&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:I})]});return m.jsxs(m.Fragment,{children:[m.jsxs($.Menu,{className:k.reportClasses.menu,open:e!==null&&d!==void 0,anchorEl:e,onClose:y,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":x?dt(x):"Tile"},slotProps:{paper:{sx:{minWidth:240,mt:.5,borderRadius:c.radius.menu,border:`1px solid ${k.edgeColor(u.cardBorder)}`,boxShadow:c.shadow.menu}}},children:[x&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="chart",disabled:O!==void 0,onClick:G("chart"),onKeyDown:D=>{D.key==="ArrowRight"&&O===void 0&&w({kind:"chart",anchor:D.currentTarget})},children:[z("Chart",O?void 0:M.find(D=>D.value===T)?.label,O),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&O===void 0&&m.jsxs($.MenuItem,{"aria-haspopup":"menu","aria-expanded":g?.kind==="color",disabled:N!==void 0,onClick:G("color"),onKeyDown:D=>{D.key==="ArrowRight"&&N===void 0&&w({kind:"color",anchor:D.currentTarget})},children:[z("Color",N?void 0:x.color??"Theme",N),!N&&m.jsx($o,{color:x.color??u.series[0],trailing:!0}),m.jsx(nl,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),p&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:A!==void 0,onClick:()=>{y(),s?.()},children:z("Clickable cells…",void 0,A??B)}),x&&o&&m.jsx($.MenuItem,{disabled:i!==void 0,onClick:()=>{y(),o()},children:z("Duplicate",void 0,i)}),x?.declaration.kind==="opaque"&&m.jsxs($.Typography,{variant:"body2",sx:{color:u.tileTitle,px:2,py:.75,maxWidth:260},children:["Its body is ",x.declaration.why,", so a filter has no single place to go."]}),x&&m.jsx($.Divider,{}),x&&m.jsx($.Box,{"aria-hidden":!0,sx:{px:2,py:.5,...c.type.code,color:"text.secondary"},children:dt(x).replace("->","→")})]}),m.jsx($.Menu,{className:k.reportClasses.menu,open:g?.kind==="chart",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,disabledItemsFocusable:!0,"aria-label":"Chart",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:M.filter(D=>D.value!=="custom").map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":D.value===T,disabled:D.disabled===!0,onClick:()=>{C(D.value),w(void 0)},children:[m.jsx($.ListItemText,{primary:D.label,...D.reason??D.hint?{secondary:D.reason??D.hint}:{}}),D.value===T&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:u.accent}})})]},D.value))}),m.jsxs($.Menu,{className:k.reportClasses.menu,open:g?.kind==="color",anchorEl:g?.anchor??null,onClose:()=>w(void 0),anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{dense:!0,"aria-label":"Color",onKeyDown:D=>{D.key==="ArrowLeft"&&(D.preventDefault(),w(void 0))}},children:[m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===void 0,onClick:()=>{j(void 0),w(void 0)},children:[m.jsx($o,{color:u.series[0]}),m.jsx($.ListItemText,{primary:"Theme",secondary:"The page's own colors"}),x?.color===void 0&&m.jsx(rl,{color:u.accent})]}),X.map(D=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":x?.color===D.toLowerCase(),onClick:()=>{j(D),w(void 0)},children:[m.jsx($o,{color:D}),m.jsx($.ListItemText,{primary:D.toLowerCase()}),x?.color===D.toLowerCase()&&m.jsx(rl,{color:u.accent})]},D)),m.jsx($.Divider,{}),m.jsxs($.MenuItem,{component:"label","aria-checked":x?.color!==void 0&&!X.some(D=>D.toLowerCase()===x.color),role:"menuitemradio",onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),b.current?.click())},children:[m.jsx("input",{ref:b,type:"color","aria-label":"Other color",value:x?.color??Ph(u.series[0]),onChange:D=>{const I=D.target.value;k.isSeriesColor(I)&&h(L=>{ce(L)&&(L.color=I.toLowerCase())})},style:{width:18,height:18,padding:0,border:"none",background:"none",marginRight:12}}),m.jsx($.ListItemText,{primary:"Other color…"})]})]})]})}const Dh=new Set(["bar_chart","line_chart","scatter_chart","combo_chart"]),Ph=e=>(e&&k.seriesColorFrom(e))??"#000000";function $o({color:e,trailing:t=!1}){return m.jsx($.Box,{"aria-hidden":!0,"data-swatch":t?"trailing":"leading",sx:{width:14,height:14,borderRadius:"3px",bgcolor:e,border:"1px solid rgba(0,0,0,0.15)",...t?{ml:1}:{mr:1.5},flex:"none"}})}function rl({color:e}){return m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(k.CheckIcon,{fontSize:"small",sx:{color:e}})})}const co=e=>e.label??k.tileTitle(dt(e));function jh({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:o,drillSource:i,setDrillSource:a,exitDialog:l,renderViewPreview:u,takenGivenNames:c}){const{filterDialog:d,setFilterDialog:f}=s,{menu:h,setMenu:y}=o,[g,w]=S.useState(),x=h===void 0?void 0:e.document.tiles[h.index],p=x&&ce(x)?x:void 0,v=(()=>{if(!p||!t)return;const _=t.documentViews?.get(p.source??"")?.get(p.name);if(_&&e.document.sources.some(T=>T.name===p.source))return _;if(p.declaration.kind==="inline"||p.declaration.kind==="opaque")return;const b=e.document.sources.find(T=>T.name===p.source)?.base??p.source,E=p.declaration.kind==="reference"?p.declaration.from:p.name;return t.sources.find(T=>T.name===b)?.views.find(T=>T.name===E)})();return m.jsxs(m.Fragment,{children:[m.jsx(kh,{open:d!==void 0,document:e.document,...d?.control?{control:d.control}:{},available:s.available,...c?{takenNames:c}:{},...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>f(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),m.jsx(Ih,{anchor:h?.anchor??null,tile:h===void 0?void 0:e.document.tiles[h.index],onClose:()=>y(void 0),onCommit:_=>{const b=h?.index;if(b===void 0)return;const E=Kf(_);e.update(T=>{T.tiles[b]=E,E!==_&&k.isPlaced(T.tiles)&&(T.tiles=Rt(T.tiles,n,b))})},view:v,...v===void 0&&p?{viewStatus:t?"unlisted":"loading"}:{},onDuplicate:()=>{h&&o.duplicate(h.index)},...p&&Ws(p)!==void 0?{duplicateBlocked:Ws(p)}:{},...(e.document.sources.find(_=>_.name===p?.source)?.dimensions?.length??0)>0?{onDrills:()=>{w(p?co(p):void 0),a(p?.source)}}:{}}),m.jsx(rh,{open:i!==void 0,document:e.document,source:e.document.sources.find(_=>_.name===i),givenNames:s.controlList.map(_=>_.name),dashboards:r??[],...g?{tileLabel:g}:{},onClose:()=>a(void 0),onApply:_=>e.update(b=>{const T=[...(b.drills??[]).filter(M=>M.source!==i),..._];T.length===0?delete b.drills:b.drills=T})}),m.jsx(k.UnsavedChangesDialog,{...l}),m.jsx(eh,{open:o.addingTile,document:e.document,catalog:t,columns:n,onClose:o.closeAdd,onAdd:o.addTile,onAddText:o.addText,...u?{renderPreview:u}:{}})]})}var Rh=Symbol.for("preact-signals");function uo(){if(Pt>1)Pt--;else{var e,t=!1;for((function(){var s=Gs;for(Gs=void 0;s!==void 0;){var o=s.S;if(o.v===s.v)for(var i=o.t;i!==void 0;i=i.x)i.i===s.i&&(i.i=o.i);s=s.o}})();Pr!==void 0;){var n=Pr;for(Pr=void 0,zs++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Sc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(zs=0,Pt--,t)throw e}}function Re(e){if(Pt>0)return e();Zo=++Ah,Pt++;try{return e()}finally{uo()}}var Dr,Te=void 0;function ae(e){var t=Te,n=Dr;Te=void 0,Dr=void 0;try{return e()}finally{Te=t,Dr=n}}var Pr=void 0,Pt=0,zs=0,Ah=0,Zo=0,Gs=void 0,Hs=0;function kc(e){if(Te!==void 0){var t=e.n;if(t===void 0||t.t!==Te)return t={i:0,S:e,p:Te.s,n:void 0,t:Te,e:void 0,x:void 0,r:t},Te.s!==void 0&&(Te.s.n=t),Te.s=t,e.n=t,32&Te.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=Te.s,t.n=void 0,Te.s.n=t,Te.s=t),t}}function it(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}it.prototype.brand=Rh;it.prototype.h=function(){return!0};it.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:ae(function(){var r;(r=t.W)==null||r.call(t)}))};it.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&ae(function(){var s;(s=t.Z)==null||s.call(t)}))}};it.prototype.subscribe=function(e){var t=this;return yt(function(){var n=t.value;ae(function(){return e(n)})},{name:"sub"})};it.prototype.valueOf=function(){return this.value};it.prototype.toString=function(){return this.value+""};it.prototype.toJSON=function(){return this.value};it.prototype.peek=function(){var e=this;return ae(function(){return e.value})};Object.defineProperty(it.prototype,"value",{get:function(){var e=kc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(zs>100)throw new Error("Cycle detected");(function(n){Pt!==0&&zs===0&&n.l!==Zo&&(n.l=Zo,Gs={S:n,v:n.v,i:n.i,o:Gs})})(this),this.v=e,this.i++,Hs++,Pt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{uo()}}}});function qn(e,t){return new it(e,t)}function Sc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function $c(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Tc(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function fn(e,t){it.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Hs-1,this.f=4}fn.prototype=new it;fn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Hs))return!0;if(this.g=Hs,this.f|=1,this.i>0&&!Sc(this))return this.f&=-2,!0;var e=Te;try{$c(this),Te=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return Te=e,Tc(this),this.f&=-2,!0};fn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}it.prototype.S.call(this,e)};fn.prototype.U=function(e){if(this.t!==void 0&&(it.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};fn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(fn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=kc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function sl(e,t){return new fn(e,t)}function Ec(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Pt++;var n=Te;Te=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Wi(e),r}finally{Te=n,uo()}}}function Wi(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Ec(e)}function Lh(e){if(Te!==this)throw new Error("Out-of-order effect");Tc(this),Te=e,this.f&=-2,8&this.f&&Wi(this),uo()}function Un(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Dr&&Dr.push(this)}Un.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Un.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ec(this),$c(this),Pt++;var e=Te;return Te=this,Lh.bind(this,e)};Un.prototype.N=function(){2&this.f||(this.f|=2,this.u=Pr,Pr=this)};Un.prototype.d=function(){this.f|=8,1&this.f||Wi(this)};Un.prototype.dispose=function(){this.d()};function yt(e,t){var n=new Un(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Bh=Object.create,Ni=Object.defineProperty,Fh=Object.defineProperties,Wh=Object.getOwnPropertyDescriptor,Nh=Object.getOwnPropertyDescriptors,ol=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Gh=Object.prototype.propertyIsEnumerable,Hh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Kn=e=>{throw TypeError(e)},Jo=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qh=(e,t)=>{for(var n in t||(t={}))zh.call(t,n)&&Jo(e,n,t[n]);if(ol)for(var n of ol(t))Gh.call(t,n)&&Jo(e,n,t[n]);return e},Uh=(e,t)=>Fh(e,Nh(t)),il=(e,t)=>Ni(e,"name",{value:t,configurable:!0}),Kh=e=>{var t;return[,,,Bh((t=void 0)!=null?t:null)]},Cc=["class","method","getter","setter","accessor","field","value","get","set"],hr=e=>e!==void 0&&typeof e!="function"?Kn("Function expected"):e,Vh=(e,t,n,r,s)=>({kind:Cc[e],name:t,metadata:r,addInitializer:o=>n._?Kn("Already initialized"):s.push(hr(o||null))}),Oc=(e,t)=>Jo(t,Hh("metadata"),e[3]),Qt=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Vn=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Cc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&Wh(d<4?s:{get[n](){return pt(this,o)},set[n](_){return Nt(this,o,_)}},n));d?h&&d<4&&il(o,(d>2?"set ":d>1?"get ":"")+n):il(s,n);for(var v=r.length-1;v>=0;v--)u=Vh(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>Xh(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?pt:Yh)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>Nt(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?hr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Kn("Object expected"):(hr(i=a.get)&&(p.get=i),hr(i=a.set)&&(p.set=i),hr(i=a.init)&&w.unshift(i));return d||Oc(e,s),p&&Ni(s,n,p),h?d^4?o:p:s},zi=(e,t,n)=>t.has(e)||Kn("Cannot "+n),Xh=(e,t)=>Object(t)!==t?Kn('Cannot use the "in" operator on this value'):e.has(t),pt=(e,t,n)=>(zi(e,t,"read from private field"),n?n.call(e):t.get(e)),pr=(e,t,n)=>t.has(e)?Kn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Nt=(e,t,n,r)=>(zi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Yh=(e,t,n)=>(zi(e,t,"access private method"),n);function ei(e,t){if(t){let n;return sl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return sl(e)}function wt(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!wt(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(o=>!wt(e[o],t[o]))}return!1}function le({get:e},t){return{init(n){return qn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function We(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ei(e.bind(this)),n.set(this,r)),r.value}}function To(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Uh(qh({},s),{enumerable:e}))})}}function Zr(...e){const t=e.map(n=>yt(n));return()=>t.forEach(n=>n())}var Mc,Ic,Dc,Pc,jc,Rc,nt,Gi,Eo,ti,ni,Je,Hi,Co,Ac,ri,qi,Oo,si,oi;Rc=[le],jc=[le],Pc=[le],Dc=[To()],Ic=[To()],Mc=[To()];var hn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Qt(nt,5,this),pr(this,Je),pr(this,Gi,Qt(nt,8,this)),Qt(nt,11,this),pr(this,Hi,Qt(nt,12,this)),Qt(nt,15,this),pr(this,qi,Qt(nt,16,this)),Qt(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return pt(this,Je,si)}get initial(){return pt(this,Je,ti)}get previous(){return pt(this,Je,Ac)}set current(e){const t=ae(()=>pt(this,Je,si));e&&t&&this.equals(t,e)||Re(()=>{pt(this,Je,ti)||Nt(this,Je,e,ni),Nt(this,Je,t,ri),Nt(this,Je,e,oi)})}reset(e=this.defaultValue){Re(()=>{Nt(this,Je,void 0,ri),Nt(this,Je,e,ni),Nt(this,Je,e,oi)})}};nt=Kh();Gi=new WeakMap;Je=new WeakSet;Hi=new WeakMap;qi=new WeakMap;Eo=Vn(nt,20,"#initial",Rc,Je,Gi),ti=Eo.get,ni=Eo.set;Co=Vn(nt,20,"#previous",jc,Je,Hi),Ac=Co.get,ri=Co.set;Oo=Vn(nt,20,"#current",Pc,Je,qi),si=Oo.get,oi=Oo.set;Vn(nt,2,"current",Dc,hn);Vn(nt,2,"initial",Ic,hn);Vn(nt,2,"previous",Mc,hn);Oc(nt,hn);function Mo(e){return ae(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Zt,Qh=class{constructor(){pr(this,Zt,new WeakMap)}get(e,t){var n;return e?(n=pt(this,Zt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return pt(this,Zt).has(e)||pt(this,Zt).set(e,new Map),(r=pt(this,Zt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=pt(this,Zt).get(e))==null?void 0:t.clear():void 0}};Zt=new WeakMap;var Zh=Object.create,Lc=Object.defineProperty,Jh=Object.getOwnPropertyDescriptor,al=Object.getOwnPropertySymbols,ep=Object.prototype.hasOwnProperty,tp=Object.prototype.propertyIsEnumerable,Bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),fo=e=>{throw TypeError(e)},ll=Math.pow,ii=(e,t,n)=>t in e?Lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,np=(e,t)=>{for(var n in t||(t={}))ep.call(t,n)&&ii(e,n,t[n]);if(al)for(var n of al(t))tp.call(t,n)&&ii(e,n,t[n]);return e},rp=e=>{var t;return[,,,Zh((t=e?.[Bc("metadata")])!=null?t:null)]},Fc=["class","method","getter","setter","accessor","field","value","get","set"],Wc=e=>e!==void 0&&typeof e!="function"?fo("Function expected"):e,sp=(e,t,n,r,s)=>({kind:Fc[e],name:t,metadata:r,addInitializer:o=>n._?fo("Already initialized"):s.push(Wc(o||null))}),op=(e,t)=>ii(t,Bc("metadata"),e[3]),ip=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Nc=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Fc[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,Jh(s,n)),x=r.length-1;x>=0;x--)l=sp(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Wc(i)&&(w[y]=i);return w&&Lc(s,n,w),s},zc=(e,t,n)=>t.has(e)||fo("Cannot "+n),ap=(e,t,n)=>(zc(e,t,"read from private field"),t.get(e)),lp=(e,t,n)=>t.has(e)?fo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),cp=(e,t,n,r)=>(zc(e,t,"write to private field"),t.set(e,n),n),gt=class ai{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ai(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new ai(t,n)}},Ct=class Jt{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:o,height:i,scale:a}=this,l=new Jt(s+t,r+n,o,i);return l.scale=np({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:o,bottom:i}=this;return{width:t,height:n,left:r,top:s,right:o,bottom:i}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new gt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Jt))return!1;const{left:n,top:r,width:s,height:o}=this;return n===t.left&&r===t.top&&s===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:o}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof Jt?dp(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new Jt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(o,i)=>{const a=r[i],l=i==="x"?o.left:o.top,u=i==="x"?o.width:o.height;return a=="start"?l:a=="end"?l+u:l+u/2};return gt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Jt.from(t).intersectionRatio(Jt.from(n))}};function dp(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),i=s-r,a=o-n;return r<s&&n<o?i*a:0}var Gc,Hc,li,_s,Jr,ho=class extends(li=hn,Hc=[We],Gc=[We],li){constructor(t){const n=gt.from(t);super(n,(r,s)=>gt.equals(r,s)),ip(Jr,5,this),lp(this,_s,0),this.velocity={x:0,y:0}}get delta(){return gt.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=gt.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),i=o-ap(this,_s),a=l=>Math.round(l/i*100);Re(()=>{cp(this,_s,o),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(gt.from(t)),this.velocity={x:0,y:0}}};Jr=rp(li);_s=new WeakMap;Nc(Jr,2,"delta",Hc,ho);Nc(Jr,2,"direction",Gc,ho);op(Jr,ho);function ci({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(ll(r,2)+ll(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var qc=(e=>(e.Horizontal="x",e.Vertical="y",e))(qc||{}),Uc=Object.values(qc),up=Object.create,Ui=Object.defineProperty,fp=Object.defineProperties,hp=Object.getOwnPropertyDescriptor,pp=Object.getOwnPropertyDescriptors,qs=Object.getOwnPropertySymbols,Kc=Object.prototype.hasOwnProperty,Vc=Object.prototype.propertyIsEnumerable,Xc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Xn=e=>{throw TypeError(e)},di=(e,t,n)=>t in e?Ui(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ki=(e,t)=>{for(var n in t||(t={}))Kc.call(t,n)&&di(e,n,t[n]);if(qs)for(var n of qs(t))Vc.call(t,n)&&di(e,n,t[n]);return e},Vi=(e,t)=>fp(e,pp(t)),cl=(e,t)=>Ui(e,"name",{value:t,configurable:!0}),Yc=(e,t)=>{var n={};for(var r in e)Kc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&qs)for(var r of qs(e))t.indexOf(r)<0&&Vc.call(e,r)&&(n[r]=e[r]);return n},Yn=e=>{var t;return[,,,up((t=e?.[Xc("metadata")])!=null?t:null)]},Qc=["class","method","getter","setter","accessor","field","value","get","set"],gr=e=>e!==void 0&&typeof e!="function"?Xn("Function expected"):e,gp=(e,t,n,r,s)=>({kind:Qc[e],name:t,metadata:r,addInitializer:o=>n._?Xn("Already initialized"):s.push(gr(o||null))}),pn=(e,t)=>di(t,Xc("metadata"),e[3]),ee=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},de=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=Qc[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&hp(d<4?s:{get[n](){return Fe(this,o)},set[n](_){return ut(this,o,_)}},n));d?h&&d<4&&cl(o,(d>2?"set ":d>1?"get ":"")+n):cl(s,n);for(var v=r.length-1;v>=0;v--)u=gp(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>mp(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?Fe:Zc)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>ut(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?gr(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?Xn("Object expected"):(gr(i=a.get)&&(p.get=i),gr(i=a.set)&&(p.set=i),gr(i=a.init)&&w.unshift(i));return d||pn(e,s),p&&Ui(s,n,p),h?d^4?o:p:s},Xi=(e,t,n)=>t.has(e)||Xn("Cannot "+n),mp=(e,t)=>Object(t)!==t?Xn('Cannot use the "in" operator on this value'):e.has(t),Fe=(e,t,n)=>(Xi(e,t,"read from private field"),n?n.call(e):t.get(e)),pe=(e,t,n)=>t.has(e)?Xn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ut=(e,t,n,r)=>(Xi(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zc=(e,t,n)=>(Xi(e,t,"access private method"),n);function Jc(e,t){return{plugin:e,options:t}}function es(e){return t=>Jc(e,t)}function zr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var ed,Gr,Yi,ks;ed=[le];var et=class{constructor(e,t){this.manager=e,this.options=t,pe(this,Yi,ee(Gr,8,this,!1)),ee(Gr,11,this),pe(this,ks,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ae(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=yt(e.bind(this));return Fe(this,ks).add(t),t}destroy(){Fe(this,ks).forEach(e=>e())}static configure(e){return Jc(this,e)}};Gr=Yn(null);Yi=new WeakMap;ks=new WeakMap;de(Gr,4,"disabled",ed,et,Yi);pn(Gr,et);var ts=class extends et{},Ss,Io=class{constructor(e){this.manager=e,this.instances=new Map,pe(this,Ss,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(zr).reduce((r,s)=>{const o=r.find(({plugin:i})=>i===s.plugin);return o?(o.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Fe(this,Ss))if(!n.includes(r)){if(r.prototype instanceof ts)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);ut(this,Ss,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};Ss=new WeakMap;function vp(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ds=[],Sn,$n,yp=class extends et{constructor(e){super(e),pe(this,Sn),pe(this,$n),this.computeCollisions=this.computeCollisions.bind(this),ut(this,$n,qn(ds)),this.destroy=Zr(()=>{const t=this.computeCollisions(),n=ae(()=>this.manager.dragOperation.position.current);if(t!==ds){const r=Fe(this,Sn);if(ut(this,Sn,n),r&&n.x==r.x&&n.y==r.y)return}else ut(this,Sn,void 0);Fe(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ae(()=>{e?Fe(this,$n).value=this.computeCollisions():ut(this,Sn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:i}=r;if(!i.initialized||!o)return ds;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||s&&!u.accepts(s))continue;const c=t??u.collisionDetector;if(!c)continue;l.push(u),u.shape;const d=ae(()=>c({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return l.length===0?ds:(a.sort(vp),a)}get collisions(){return Fe(this,$n).value}};Sn=new WeakMap;$n=new WeakMap;var td,nd,rd,Qi,sd,_t,Zi,Dn,Ji,ea;rd=[le],nd=[le],td=[le];var At=class en{constructor(t,n){pe(this,Zi,ee(_t,8,this)),ee(_t,11,this),pe(this,Dn),pe(this,Ji,ee(_t,12,this)),ee(_t,15,this),pe(this,ea,ee(_t,16,this)),ee(_t,19,this);const{effects:r,id:s,data:o={},disabled:i=!1,register:a=!0}=t;let l=s;ut(this,Dn,qn(s)),this.manager=n,this.data=o,this.disabled=i,this.effects=()=>{var u;return[()=>{const{id:c,manager:d}=this;if(c!==l)return l=c,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Fe(this,Dn).value;return(n=(t=en.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=en.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Fe(this,Dn).peek();t!==s&&(en.pendingIdChanges||(en.pendingIdChanges=new Map,queueMicrotask(()=>{var o;return Zc(o=en,Qi,sd).call(o)})),en.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};_t=Yn(null);Qi=new WeakSet;sd=function(){const e=At.pendingIdChanges;At.pendingIdChanges=null,e&&Re(()=>{for(const[t,n]of e)Fe(t,Dn).value=n})};Zi=new WeakMap;Dn=new WeakMap;Ji=new WeakMap;ea=new WeakMap;de(_t,4,"manager",rd,At,Zi);de(_t,4,"data",nd,At,Ji);de(_t,4,"disabled",td,At,ea);pe(At,Qi);pn(_t,At);At.pendingIdChanges=null;var po=At,dl=class{constructor(){this.map=qn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const o=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){o.delete(a);break}o.set(e,t),this.map.value=o;const i=Zr(...t.effects());return this.cleanupFunctions.set(t,i),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},od,id,ad,ld,cd,dd,ui,rt,ta,na,ra,Ot=class extends(ui=po,dd=[le],cd=[le],ld=[le],ad=[We],id=[We],od=[We],ui){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:i,plugins:a,effects:l}=r,u=Yc(r,["modifiers","type","sensors","plugins","effects"]);super(Vi(Ki({},u),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:d,plugins:f}=this;if(!(!d||!f))for(const h of f){const{plugin:y}=zr(h);d.registry.plugins.register(y)}}]}}),n),ee(rt,5,this),pe(this,ta,ee(rt,8,this)),ee(rt,11,this),pe(this,na,ee(rt,12,this)),ee(rt,15,this),pe(this,ra,ee(rt,16,this,this.isDragSource?"dragging":"idle")),ee(rt,19,this),this.type=o,this.sensors=i,this.modifiers=s,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=zr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};rt=Yn(ui);ta=new WeakMap;na=new WeakMap;ra=new WeakMap;de(rt,4,"type",dd,Ot,ta);de(rt,4,"modifiers",cd,Ot,na);de(rt,4,"status",ld,Ot,ra);de(rt,2,"isDropping",ad,Ot);de(rt,2,"isDragging",id,Ot);de(rt,2,"isDragSource",od,Ot);pn(rt,Ot);var ud,fd,hd,pd,gd,md,fi,Ke,sa,oa,ia,aa,la,Mt=class extends(fi=po,md=[le],gd=[le],pd=[le],hd=[le],fd=[le],ud=[We],fi){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:i,type:a}=r,l=Yc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ee(Ke,5,this),pe(this,sa,ee(Ke,8,this)),ee(Ke,11,this),pe(this,oa,ee(Ke,12,this)),ee(Ke,15,this),pe(this,ia,ee(Ke,16,this)),ee(Ke,19,this),pe(this,aa,ee(Ke,20,this)),ee(Ke,23,this),pe(this,la,ee(Ke,24,this)),ee(Ke,27,this),this.accept=s,this.collisionDetector=o,this.collisionPriority=i,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Ke=Yn(fi);sa=new WeakMap;oa=new WeakMap;ia=new WeakMap;aa=new WeakMap;la=new WeakMap;de(Ke,4,"accept",md,Mt,sa);de(Ke,4,"type",gd,Mt,oa);de(Ke,4,"collisionDetector",pd,Mt,ia);de(Ke,4,"collisionPriority",hd,Mt,aa);de(Ke,4,"shape",fd,Mt,la);de(Ke,2,"isDropTarget",ud,Mt);pn(Ke,Mt);var xp=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},bp=class extends xp{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function $s(e,t=!0){let n=!1;return Vi(Ki({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var wp=class extends ts{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Zr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled()||po.pendingIdChanges)return;const i=$s({collisions:o});if(s.dispatch("collision",i),i.defaultPrevented||t(o,n))return;n=o;const[a]=o;ae(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Qn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Qn||{}),Zn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Zn||{}),vd,yd,xd,bd,wd,_d,kd,vt,ca;kd=[le],_d=[We],wd=[We],bd=[We],xd=[We],yd=[We],vd=[We];var Bt=class{constructor(){ee(vt,5,this),pe(this,ca,ee(vt,8,this,"idle")),ee(vt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};vt=Yn(null);ca=new WeakMap;de(vt,4,"value",kd,Bt,ca);de(vt,2,"current",_d,Bt);de(vt,2,"idle",wd,Bt);de(vt,2,"initializing",bd,Bt);de(vt,2,"initialized",xd,Bt);de(vt,2,"dragging",yd,Bt);de(vt,2,"dropped",vd,Bt);pn(vt,Bt);var _p=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return ae(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=$s({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ae(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:o}=e;Re(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const i=$s({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",i),i.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Re(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:o}=r;if(!s.dragging||!o||o.signal.aborted)return;const i=$s({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",i),queueMicrotask(()=>{var a,l,u,c,d;if(i.defaultPrevented)return;const f=(d=e.to)!=null?d:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(u=e.by)==null?void 0:u.y)!=null?c:0)};r.position.current=f})})}stop(e={}){return ae(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let o;const i=()=>{const l={resume:()=>{},abort:()=>{}};return o=new Promise((u,c)=>{l.resume=u,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=ae(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),u=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,d=yt(()=>{c?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:i}),o?o.then(a).catch(()=>r.reset()):a()})}},Bn=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}},kp=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},Ts,Sd=class{constructor(e){this.options=e,pe(this,Ts)}set controller(e){ut(this,Ts,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Fe(this,Ts))==null||t.activate(e)}};Ts=new WeakMap;var ul=class extends et{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Sp=class{constructor(e){this.draggables=new dl,this.droppables=new dl,this.plugins=new Io(e),this.sensors=new Io(e),this.modifiers=new Io(e)}register(e,t){if(e instanceof Ot)return this.draggables.register(e.id,e);if(e instanceof Mt)return this.droppables.register(e.id,e);if(e.prototype instanceof ul)return this.modifiers.register(e,t);if(e.prototype instanceof Bn)return this.sensors.register(e,t);if(e.prototype instanceof et)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof po)return e instanceof Ot?this.draggables.unregister(e.id,e):e instanceof Mt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ul)return this.modifiers.unregister(e);if(e.prototype instanceof Bn)return this.sensors.unregister(e);if(e.prototype instanceof et)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},$d,Td,Ed,Cd,Od,Md,Id,Dd,Pd,mr,Es,Tn,je,da,ua,fa,ha,pa,vr;Pd=[We],Dd=[le],Id=[le],Md=[le],Od=[le],Cd=[le],Ed=[We],Td=[We],$d=[We];var $t=class{constructor(e){ee(je,5,this),pe(this,mr),pe(this,Es),pe(this,Tn,new hn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Bt,pe(this,da,ee(je,8,this,!1)),ee(je,11,this),pe(this,ua,ee(je,12,this,null)),ee(je,15,this),pe(this,fa,ee(je,16,this,null)),ee(je,19,this),pe(this,ha,ee(je,20,this,null)),ee(je,23,this),pe(this,pa,ee(je,24,this,[])),ee(je,27,this),this.position=new ho({x:0,y:0}),pe(this,vr,{x:0,y:0}),ut(this,mr,e)}get shape(){const{current:e,initial:t,previous:n}=Fe(this,Tn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Fe(this,Tn).current=e:Fe(this,Tn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Fe(this,mr).registry.draggables.get(t);return n&&ut(this,Es,n),(e=n??Fe(this,Es))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Fe(this,mr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Vi(Ki({},this.snapshot()),{transform:n}));return ut(this,vr,n),n}snapshot(){return ae(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Fe(this,vr),shape:this.shape?Mo(this.shape):null,position:Mo(this.position),status:Mo(this.status),canceled:this.canceled}))}reset(){Re(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Fe(this,Tn).reset(),this.position.reset({x:0,y:0}),ut(this,vr,{x:0,y:0}),this.modifiers=[]})}};je=Yn(null);mr=new WeakMap;Es=new WeakMap;Tn=new WeakMap;da=new WeakMap;ua=new WeakMap;fa=new WeakMap;ha=new WeakMap;pa=new WeakMap;vr=new WeakMap;de(je,2,"shape",Pd,$t);de(je,4,"canceled",Dd,$t,da);de(je,4,"activatorEvent",Id,$t,ua);de(je,4,"sourceIdentifier",Md,$t,fa);de(je,4,"targetIdentifier",Od,$t,ha);de(je,4,"modifiers",Cd,$t,pa);de(je,2,"source",Ed,$t);de(je,2,"target",Td,$t);de(je,2,"transform",$d,$t);pn(je,$t);var $p={get rendering(){return Promise.resolve()}};function St(e,t){return typeof e=="function"?e(t):e??t}var Tp=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=St(r.plugins,[]),o=St(r.sensors,[]),i=St(r.modifiers,[]),a=(n=r.renderer)!=null?n:$p,l=new bp(this),u=new Sp(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new _p(this),this.dragOperation=new $t(this),this.collisionObserver=new yp(this),this.plugins=[wp,...s],this.modifiers=i,this.sensors=o;const{destroy:c}=this,d=Zr(()=>{var f,h,y;const g=ae(()=>this.dragOperation.modifiers),w=this.modifiers;for(const x of g)w.includes(x)||x.destroy();this.dragOperation.modifiers=(y=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:p,options:v}=zr(x);return new p(this,v)}))!=null?y:w});this.destroy=()=>{d(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},jd=e=>{throw TypeError(e)},ga=(e,t,n)=>t.has(e)||jd("Cannot "+n),J=(e,t,n)=>(ga(e,t,"read from private field"),t.get(e)),at=(e,t,n)=>t.has(e)?jd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ct=(e,t,n,r)=>(ga(e,t,"write to private field"),t.set(e,n),n),Rd=(e,t,n)=>(ga(e,t,"access private method"),n);function go(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Ad(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:o}=s,a=(go(o)?o.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function mo(e){const{width:t,height:n,top:r,left:s,bottom:o,right:i}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:o,right:i}}function ma(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ns(e){return"nodeType"in e}function ft(e){var t,n,r;return e?ma(e)?e:ns(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function va(e){const{Document:t}=ft(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Kt(e){return!e||ma(e)?!1:e instanceof ft(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ld(e){return e instanceof ft(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Jn(e){return e?ma(e)?e.document:ns(e)?va(e)?e:Kt(e)||Ld(e)?e.ownerDocument:document:document:document}function Ep(e){var t,n,r,s;const{documentElement:o}=Jn(e),i=ft(e).visualViewport,a=(t=i?.width)!=null?t:o.clientWidth,l=(n=i?.height)!=null?n:o.clientHeight,u=(r=i?.offsetTop)!=null?r:0,c=(s=i?.offsetLeft)!=null?s:0;return{top:u,left:c,right:c+a,bottom:u+l,width:a,height:l}}function Cp(e,t){if(Op(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Op(e){return e.tagName==="DETAILS"}function Hr(e,t=e.getBoundingClientRect(),n=0){var r,s,o,i,a;let l=t;const{ownerDocument:u}=e,c=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!Cp(d)){const v=d.getBoundingClientRect(),_=n*(v.bottom-v.top),b=n*(v.right-v.left),E=n*(v.bottom-v.top),T=n*(v.right-v.left);l={top:Math.max(l.top,v.top-_),right:Math.min(l.right,v.right+b),bottom:Math.min(l.bottom,v.bottom+E),left:Math.max(l.left,v.left-T),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const f=c.visualViewport,h=(s=f?.offsetTop)!=null?s:0,y=(o=f?.offsetLeft)!=null?o:0,g=(i=f?.width)!=null?i:c.innerWidth,w=(a=f?.height)!=null?a:c.innerHeight,x=n*w,p=n*g;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,y+g+p),bottom:Math.min(l.bottom,h+w+x),left:Math.max(l.left,y-p),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Fn(e){return{x:e.clientX,y:e.clientY}}var Bd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function hi(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...hi(s.document,t))}}catch{}return n}function ya(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Fd(){var e,t;const n=ya()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function xa(e){return!e||!ns(e)?!1:e instanceof ft(e).ShadowRoot}function Us(e){if(e&&ns(e)){let t=e.getRootNode();if(xa(t))return t;if(t instanceof Document)return t}return Jn(e)}function ba(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Mp(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((o,i)=>{const a=r[i];if(fl(o)&&fl(a)&&(o.type!=="file"&&(o.value=a.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),hl(o)&&hl(a)&&a.width>0&&a.height>0){const l=o.getContext("2d");l?.drawImage(a,0,0)}}),n}function fl(e){return"value"in e}function hl(e){return e.tagName==="CANVAS"}function Wd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Ip(r)){const{contentDocument:s}=r;if(s){const{left:o,top:i}=r.getBoundingClientRect();return Wd(s,{x:t-o,y:n-i})}}return r}function Ip(e){return e?.tagName==="IFRAME"}var pi=new WeakMap;function Dp(e){return e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),
5
5
  button:not([disabled]),
6
6
  a[href],
7
7
  [contenteditable]:not([contenteditable="false"])
8
- `)}var dd=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:c,listener:f,options:d}=a,l=[o,a];o.addEventListener(c,f,d),this.entries.add(l),s.push(l)}const i=this.entries;return function(){for(const a of s){const[c,{type:f,listener:d,options:l}]=a;c.removeEventListener(f,d,l),i.delete(a)}}}};function On(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Lh(e){const t=new Set;let n=On(e);for(;n;)t.add(n),n=On(n);return t}function Bh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ud(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Bh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Fh(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function zh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Tr(e,t);return n>0&&r>0}var Wh=ad?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ms,Nh=class extends Wh{constructor(e){super(t=>{if(!q(this,ms)){nt(this,ms,!0);return}e(t,this)}),Je(this,ms,!1)}};ms=new WeakMap;var Ya=Array.from({length:100},(e,t)=>t/100),fd=75,Gt,Ps,Ot,Ut,sr,Ve,br,ir,Rs,hd,pd,gd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Je(this,Rs),this.disconnect=()=>{var i,o,a;nt(this,br,!0),(i=q(this,Ot))==null||i.disconnect(),(o=q(this,Ut))==null||o.disconnect(),q(this,sr).disconnect(),(a=q(this,Ve))==null||a.remove()},Je(this,Gt,!0),Je(this,Ps),Je(this,Ot),Je(this,Ut),Je(this,sr),Je(this,Ve),Je(this,br,!1),Je(this,ir,ud(()=>{var i,o,a;const{element:c}=this;if((i=q(this,Ut))==null||i.disconnect(),q(this,br)||!q(this,Gt)||!c.isConnected)return;const f=(o=c.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=c.getBoundingClientRect(),h=Tr(c,u),{top:p,left:v,bottom:x,right:_}=h,g=-Math.floor(p),y=-Math.floor(v),w=-Math.floor(l-_),b=-Math.floor(d-x),T=`${g}px ${w}px ${b}px ${y}px`;this.boundingClientRect=u,nt(this,Ut,new IntersectionObserver(C=>{const[M]=C,{intersectionRect:E}=M;(M.intersectionRatio!==1?M.intersectionRatio:bt.intersectionRatio(E,Tr(c)))!==1&&q(this,ir).call(this)},{threshold:Ya,rootMargin:T,root:f})),q(this,Ut).observe(c),sd(this,Rs,hd).call(this)},fd)),this.boundingClientRect=e.getBoundingClientRect(),nt(this,Gt,zh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(nt(this,Ve,document.createElement("div")),q(this,Ve).style.background="rgba(0,0,0,0.15)",q(this,Ve).style.position="fixed",q(this,Ve).style.pointerEvents="none",s.body.appendChild(q(this,Ve))),nt(this,sr,new IntersectionObserver(i=>{var o,a;const c=i[i.length-1],{boundingClientRect:f,isIntersecting:d}=c,{width:l,height:u}=f,h=q(this,Gt);nt(this,Gt,d),!(!l&&!u)&&(h&&!d?((o=q(this,Ut))==null||o.disconnect(),this.callback(null),(a=q(this,Ot))==null||a.disconnect(),nt(this,Ot,void 0),q(this,Ve)&&(q(this,Ve).style.visibility="hidden")):q(this,ir).call(this),d&&!q(this,Ot)&&(nt(this,Ot,new Nh(q(this,ir))),q(this,Ot).observe(e)))},{threshold:Ya,root:s})),q(this,Gt)&&!n.skipInitial&&this.callback(this.boundingClientRect),q(this,sr).observe(e)}};Gt=new WeakMap;Ps=new WeakMap;Ot=new WeakMap;Ut=new WeakMap;sr=new WeakMap;Ve=new WeakMap;br=new WeakMap;ir=new WeakMap;Rs=new WeakSet;hd=function(){q(this,br)||(sd(this,Rs,pd).call(this),!Fh(this.boundingClientRect,q(this,Ps))&&(this.callback(this.boundingClientRect),nt(this,Ps,this.boundingClientRect)))};pd=function(){if(q(this,Ve)){const{top:e,left:t,width:n,height:r}=Tr(this.element);q(this,Ve).style.overflow="hidden",q(this,Ve).style.visibility="visible",q(this,Ve).style.top=`${Math.floor(e)}px`,q(this,Ve).style.left=`${Math.floor(t)}px`,q(this,Ve).style.width=`${Math.floor(n)}px`,q(this,Ve).style.height=`${Math.floor(r)}px`}};var es=new WeakMap,ts=new WeakMap;function Gh(e,t){let n=es.get(e);return n||(n={disconnect:new gd(e,s=>{const i=es.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),es.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(es.delete(e),n.disconnect())}}function Uh(e,t){const n=new Set;for(const r of e){const s=Gh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Hh(e,t){var n;const r=e.ownerDocument;if(!ts.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",c=>a.forEach(f=>f(c)),{capture:!0,passive:!0,signal:o.signal}),ts.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=ts.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),ts.delete(r))})}var or,ar,vs,ro,Vh=class{constructor(e,t,n){this.callback=t,Je(this,or),Je(this,ar,!1),Je(this,vs),Je(this,ro,ud(o=>{if(!q(this,ar)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of q(this,vs))if(o.target.contains(a)){this.callback(q(this,or).boundingClientRect);break}}},fd));const r=Lh(e),s=Uh(r,t),i=Hh(e,q(this,ro));nt(this,vs,r),nt(this,or,new gd(e,t,n)),this.disconnect=()=>{q(this,ar)||(nt(this,ar,!0),s(),i(),q(this,or).disconnect())}}};or=new WeakMap;ar=new WeakMap;vs=new WeakMap;ro=new WeakMap;function so(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Sn(e){try{so(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Xa(e){return!ad||!e?!1:e===Wn(e).scrollingElement}function md(e){var t,n;const r=st(e),s=Xa(e)?Mh(e):ni(e),i=r.visualViewport,o=Xa(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},c=a.current.y<=0,f=a.current.x<=0,d=a.current.y>=a.max.y,l=a.current.x>=a.max.x;return{rect:s,position:a,isTop:c,isLeft:f,isBottom:d,isRight:l}}function Kh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=md(e),{x:a,y:c}=t??{x:0,y:0},f=!n&&o.current.y+c>0,d=!r&&o.current.y+c<o.max.y,l=!s&&o.current.x+a>0,u=!i&&o.current.x+a<o.max.x;return{top:f,bottom:d,left:l,right:u,x:l||u,y:f||d}}var la=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},As=new la(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qh=new la(e=>setTimeout(e,50)),Ls=new Map,Yh=Ls.clear.bind(Ls);function _t(e,t=!1){if(!t)return Qa(e);let n=Ls.get(e);return n||(n=Qa(e),Ls.set(e,n),qh.schedule(Yh),n)}function Qa(e){return st(e).getComputedStyle(e)}function Xh(e,t=_t(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Qh(e,t=_t(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Zh={excludeElement:!0,escapeShadowDOM:!0};function io(e,t=Zh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(sa(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&oa(a))return o(a.host);if(!At(a))return od(a)?o(a.parentElement):i;if(i.has(a))return i;const c=_t(a,!0);if(r&&a===e||Qh(a,c)&&i.add(a),Xh(a,c)){const{scrollingElement:f}=a.ownerDocument;return f&&i.add(f),i}return o(a.parentNode)}return e?o(e):i}function Dn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=On(e);for(;r;){if(r===t)return n;const s=ni(r),{x:i,y:o}=Jh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=On(r)}return n}function Jh(e,t=ni(e)){const n=Math.round(t.width),r=Math.round(t.height);if(At(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=_t(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function ep(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Er(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function ri(e){var t,n,r,s,i,o,a,c,f;const{scale:d,transform:l,translate:u}=e,h=ep(d),p=Er(u),v=tp(l);if(!v&&!h&&!p)return null;const x={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},_={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},g={x:(i=v?.x)!=null?i:0,y:(o=v?.y)!=null?o:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(c=v?.scaleY)!=null?c:1};return{x:_.x+g.x,y:_.y+g.y,z:(f=p?.z)!=null?f:0,scaleX:x.x*g.scaleX,scaleY:x.y*g.scaleY}}function tp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var at=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(at||{}),np={x:.2,y:.2},rp={x:10,y:10};function sp(e,t,n,r=25,s=np,i=rp){const{x:o,y:a}=t,{rect:c,isTop:f,isBottom:d,isLeft:l,isRight:u}=md(e),h=Dn(e),p=_t(e,!0),v=ri(p),x=v!==null?v?.scaleX<0:!1,_=v!==null?v?.scaleY<0:!1,g=new bt(c.left*h.scaleX+h.x,c.top*h.scaleY+h.y,c.width*h.scaleX,c.height*h.scaleY),y={x:0,y:0},w={x:0,y:0},b={height:g.height*s.y,width:g.width*s.x};return b.height>0&&(!f||_&&!d)&&a<=g.top+b.height&&n?.y!==1&&o>=g.left-i.x&&o<=g.right+i.x?(y.y=_?1:-1,w.y=r*Math.abs((g.top+b.height-a)/b.height)):b.height>0&&(!d||_&&!f)&&a>=g.bottom-b.height&&n?.y!==-1&&o>=g.left-i.x&&o<=g.right+i.x&&(y.y=_?-1:1,w.y=r*Math.abs((g.bottom-b.height-a)/b.height)),b.width>0&&(!u||x&&!l)&&o>=g.right-b.width&&n?.x!==-1&&a>=g.top-i.y&&a<=g.bottom+i.y?(y.x=x?-1:1,w.x=r*Math.abs((g.right-b.width-o)/b.width)):b.width>0&&(!l||x&&!u)&&o<=g.left+b.width&&n?.x!==1&&a>=g.top-i.y&&a<=g.bottom+i.y&&(y.x=x?1:-1,w.x=r*Math.abs((g.left+b.width-o)/b.width)),{direction:y,speed:w}}function vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!At(e))return;const r=io(e),s=[];for(const i of r){if(!At(i))continue;const{top:o,left:a}=ip(e,i);let c=o,f=a;for(const d of s)c-=d.scrollTop,f-=d.scrollLeft;if(t!=="none"){const d=c<i.scrollTop,l=c+e.offsetHeight>i.scrollTop+i.clientHeight;d!==l&&(t==="center"?i.scrollTop=c-i.clientHeight/2+e.offsetHeight/2:d?i.scrollTop=c:i.scrollTop=c+e.offsetHeight-i.clientHeight)}if(n!=="none"){const d=f<i.scrollLeft,l=f+e.offsetWidth>i.scrollLeft+i.clientWidth;d!==l&&(n==="center"?i.scrollLeft=f-i.clientWidth/2+e.offsetWidth/2:d?i.scrollLeft=f:i.scrollLeft=f+e.offsetWidth-i.clientWidth)}s.push(i)}}function Za(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!At(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function ip(e,t){const n=Za(e),r=Za(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function op(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),c=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width*r:e.width,d=s?e.height*s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function ap(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),c=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),f=r?e.width/r:e.width,d=s?e.height/s:e.height;return{width:f,height:d,top:c,right:a+f,bottom:c+d,left:a}}function yd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Ja(e,t=_t(e).translate,n=!0){if(n){const r=id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=Er(s);if(i)return i}}}if(t){const r=Er(t);if(r)return r}return{x:0,y:0,z:0}}var lp=new la(e=>setTimeout(e,0)),xr=new Map,cp=xr.clear.bind(xr);function dp(e){const t=e.ownerDocument;let n=xr.get(t);if(n)return n;n=t.getAnimations(),xr.set(t,n),lp.schedule(cp);const r=n.filter(s=>ti(s.effect)&&s.effect.target===e);return xr.set(e,r),n}function up(e,t){const n=dp(e).filter(r=>{var s,i;if(ti(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(c=>{for(const f of t.properties)if(c[f])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var yt=class extends bt{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=Dn(e),ignoreTransforms:a,getBoundingClientRect:c=ni}=t,f=up(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ia())&&b.contains(e)}),d=c(e);let{top:l,left:u,width:h,height:p}=d,v;const x=_t(e),_=ri(x),g={x:(n=_?.scaleX)!=null?n:1,y:(r=_?.scaleY)!=null?r:1},y=fp(e,x);f?.(),_&&(v=ap(d,_,x.transformOrigin),(a||y)&&(l=v.top,u=v.left,h=v.width,p=v.height));const w={width:(s=v?.width)!=null?s:h,height:(i=v?.height)!=null?i:p};if(y&&!a&&v){const b=op(v,y,x.transformOrigin);l=b.top,u=b.left,h=b.width,p=b.height,g.x=y.scaleX,g.y=y.scaleY}o&&(a||(u*=o.scaleX,h*=o.scaleX,l*=o.scaleY,p*=o.scaleY),u+=o.x,l+=o.y),super(u,l,h,p),this.scale=g,this.intrinsicWidth=w.width,this.intrinsicHeight=w.height}};function fp(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const c=ti(a.effect)?a.effect.getKeyframes():[],f=c[c.length-1];if(!f)continue;const{transform:d,translate:l,scale:u}=f;typeof d=="string"&&d&&(r=d,o=!0),typeof l=="string"&&l&&(s=l,o=!0),typeof u=="string"&&u&&(i=u,o=!0)}return o?ri({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function wr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var hp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(wr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(wr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(wr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Qt(e){return e?e instanceof st(e).Element||Fr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Cr(e){if(!e)return!1;const{KeyboardEvent:t}=st(e.target);return e instanceof t}function pp(e){if(!e)return!1;const{PointerEvent:t}=st(e.target);return e instanceof t}function gp(e){if(!Qt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||mp(e)}function mp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var bi={};function oo(e){const t=bi[e]==null?0:bi[e]+1;return bi[e]=t,`${e}-${t}`}var ca=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=ot.distance(t.shape.center,n);return{id:r,value:1/s,type:zn.PointerIntersection,priority:Fn.High}}return null},vp=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=ot.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:zn.ShapeIntersection,priority:Fn.Normal}}return null},bd=e=>{var t;return(t=ca(e))!=null?t:vp(e)},yp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?bt.from(r.current.boundingRectangle).corners:void 0,a=bt.from(n.shape.boundingRectangle).corners.reduce((c,f,d)=>{var l;return c+ot.distance(ot.from(f),(l=i?.[d])!=null?l:s.current)},0)/4;return{id:n.id,value:1/a,type:zn.Collision,priority:Fn.Normal}},bp=Object.create,da=Object.defineProperty,xp=Object.defineProperties,wp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyDescriptors,Bs=Object.getOwnPropertySymbols,xd=Object.prototype.hasOwnProperty,wd=Object.prototype.propertyIsEnumerable,_d=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Nn=e=>{throw TypeError(e)},ao=(e,t,n)=>t in e?da(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Or=(e,t)=>{for(var n in t||(t={}))xd.call(t,n)&&ao(e,n,t[n]);if(Bs)for(var n of Bs(t))wd.call(t,n)&&ao(e,n,t[n]);return e},ua=(e,t)=>xp(e,_p(t)),el=(e,t)=>da(e,"name",{value:t,configurable:!0}),kd=(e,t)=>{var n={};for(var r in e)xd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Bs)for(var r of Bs(e))t.indexOf(r)<0&&wd.call(e,r)&&(n[r]=e[r]);return n},Gn=e=>{var t;return[,,,bp((t=e?.[_d("metadata")])!=null?t:null)]},Sd=["class","method","getter","setter","accessor","field","value","get","set"],lr=e=>e!==void 0&&typeof e!="function"?Nn("Function expected"):e,kp=(e,t,n,r,s)=>({kind:Sd[e],name:t,metadata:r,addInitializer:i=>n._?Nn("Already initialized"):s.push(lr(i||null))}),nn=(e,t)=>ao(t,_d("metadata"),e[3]),ze=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},ut=(e,t,n,r,s,i)=>{var o,a,c,f,d,l=t&7,u=!!(t&8),h=!!(t&16),p=l>3?e.length+1:l?u?1:2:0,v=Sd[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&wp(l<4?s:{get[n](){return ge(this,i)},set[n](w){return Qe(this,i,w)}},n));l?h&&l<4&&el(i,(l>2?"set ":l>1?"get ":"")+n):el(s,n);for(var y=r.length-1;y>=0;y--)f=kp(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>Sp(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?ge:Zt)(w,s,l^4?i:g.get):w=>w[n]),l>2&&(d.set=h?(w,b)=>Qe(w,s,b,l^4?i:g.set):(w,b)=>w[n]=b)),a=(0,r[y])(l?l<4?h?i:g[v]:l>4?void 0:{get:g.get,set:g.set}:s,f),c._=1,l^4||a===void 0?lr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Nn("Object expected"):(lr(o=a.get)&&(g.get=o),lr(o=a.set)&&(g.set=o),lr(o=a.init)&&x.unshift(o));return l||nn(e,s),g&&da(s,n,g),h?l^4?i:g:s},fa=(e,t,n)=>t.has(e)||Nn("Cannot "+n),Sp=(e,t)=>Object(t)!==t?Nn('Cannot use the "in" operator on this value'):e.has(t),ge=(e,t,n)=>(fa(e,t,"read from private field"),n?n.call(e):t.get(e)),Pe=(e,t,n)=>t.has(e)?Nn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Qe=(e,t,n,r)=>(fa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zt=(e,t,n)=>(fa(e,t,"access private method"),n),tl={role:"button",roleDescription:"draggable"},$p="dnd-kit-description",Tp="dnd-kit-announcement",Ep={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Cp={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Op(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Dp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Mp(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Ip=["dragover","dragmove"],jp=class extends qe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=$p,announcement:s=Tp}={},announcements:i=Cp,screenReaderInstructions:o=Ep,debounce:a=500}=t??{},c=n?`${r}-${n}`:oo(r),f=n?`${s}-${n}`:oo(s);let d,l,u,h;const p=(b=h)=>{!u||!b||u?.nodeValue!==b&&(u.nodeValue=b)},v=()=>As.schedule(p),x=Pp(v,a),_=Object.entries(i).map(([b,T])=>this.manager.monitor.addEventListener(b,(C,M)=>{const E=u;if(!E)return;const O=T?.(C,M);O&&E.nodeValue!==O&&(h=O,Ip.includes(b)?x():(v(),x.cancel()))})),g=()=>{let b=[];d?.isConnected||(d=Dp(c,o.draggable),b.push(d)),l?.isConnected||(l=Mp(f),u=document.createTextNode(""),l.appendChild(u),b.push(l)),b.length>0&&document.body.append(...b)},y=new Set;function w(){for(const b of y)b()}this.registerEffect(()=>{var b;y.clear();for(const T of this.manager.registry.draggables.value){const C=(b=T.handle)!=null?b:T.element;if(C){(!d||!l)&&y.add(g),(!Op(C)||ia())&&!C.hasAttribute("tabindex")&&y.add(()=>C.setAttribute("tabindex","0")),!C.hasAttribute("role")&&C.tagName.toLowerCase()!=="button"&&y.add(()=>C.setAttribute("role",tl.role)),C.hasAttribute("aria-roledescription")||y.add(()=>C.setAttribute("aria-roledescription",tl.roleDescription)),C.hasAttribute("aria-describedby")||y.add(()=>C.setAttribute("aria-describedby",c));for(const E of["aria-pressed","aria-grabbed"]){const O=String(T.isDragging);C.getAttribute(E)!==O&&y.add(()=>C.setAttribute(E,O))}const M=String(T.disabled);C.getAttribute("aria-disabled")!==M&&y.add(()=>C.setAttribute("aria-disabled",M))}}y.size>0&&As.schedule(w)}),this.destroy=()=>{super.destroy(),d?.remove(),l?.remove(),_.forEach(b=>b())}}};function Pp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Fs=new Map,$d,Td,Ed,Cd,lo,_r,St,ha,Mn,Od,Dd,Md,Id,Lt=class extends(lo=Br,Cd=[re],Ed=[Me],Td=[Me],$d=[Me],lo){constructor(t,n){super(t,n),ze(St,5,this),Pe(this,Mn),Pe(this,_r,new Set),Pe(this,ha,ze(St,8,this,new Set)),ze(St,11,this),this.registerEffect(Zt(this,Mn,Od))}register(t){return ge(this,_r).add(t),()=>{ge(this,_r).delete(t)}}addRoot(t){return ne(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ne(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return js((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return js((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};St=Gn(lo);_r=new WeakMap;ha=new WeakMap;Mn=new WeakSet;Od=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ge(this,_r))t.push(Zt(this,Mn,Dd).call(this,n,r));return()=>{for(const n of t)n()}};Dd=function(e,t){let n=Fs.get(e);n||(n=new Map,Fs.set(e,n));let r=n.get(t);if(!r){const i=sa(e)?Zt(this,Mn,Md).call(this,e,n,t):Zt(this,Mn,Id).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Md=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const c of a)for(const f of Array.from(c.removedNodes))if(f===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Fs.delete(e)}}};Id=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(oa(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Fs.delete(e)}}};ut(St,4,"additionalRoots",Cd,Lt,ha);ut(St,2,"sourceRoot",Ed,Lt);ut(St,2,"targetRoot",Td,Lt);ut(St,2,"roots",$d,Lt);nn(St,Lt);Lt.configure=Lr(Lt);var si=Lt,Rp=class extends qe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(si),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},zr="data-dnd-",co=`${zr}dropping`,He="--dnd-",vt=`${zr}dragging`,zs=`${zr}placeholder`,Ap=[vt,zs,"popover","aria-pressed","aria-grabbing"],Lp=["view-transition-name"],Bp=`
9
- :is(:root,:host) [${vt}] {
8
+ `)}var Nd=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const i of n)for(const a of r){const{type:l,listener:u,options:c}=a,d=[i,a];i.addEventListener(l,u,c),this.entries.add(d),s.push(d)}const o=this.entries;return function(){for(const a of s){const[l,{type:u,listener:c,options:d}]=a;l.removeEventListener(u,c,d),o.delete(a)}}}};function Wn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Pp(e){const t=new Set;let n=Wn(e);for(;n;)t.add(n),n=Wn(n);return t}function jp(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function zd(e,t){const n=()=>performance.now();let r,s;return function(...o){const i=this;s?(r?.(),r=jp(()=>{e.apply(i,o),s=n()},t-(n()-s))):(e.apply(i,o),s=n())}}function Rp(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function Ap(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Hr(e,t);return n>0&&r>0}var Lp=Bd?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Cs,Bp=class extends Lp{constructor(e){super(t=>{if(!J(this,Cs)){ct(this,Cs,!0);return}e(t,this)}),at(this,Cs,!1)}};Cs=new WeakMap;var pl=Array.from({length:100},(e,t)=>t/100),Gd=75,tn,Ks,Ft,nn,yr,Ze,jr,xr,Vs,Hd,qd,Ud=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,at(this,Vs),this.disconnect=()=>{var o,i,a;ct(this,jr,!0),(o=J(this,Ft))==null||o.disconnect(),(i=J(this,nn))==null||i.disconnect(),J(this,yr).disconnect(),(a=J(this,Ze))==null||a.remove()},at(this,tn,!0),at(this,Ks),at(this,Ft),at(this,nn),at(this,yr),at(this,Ze),at(this,jr,!1),at(this,xr,zd(()=>{var o,i,a;const{element:l}=this;if((o=J(this,nn))==null||o.disconnect(),J(this,jr)||!J(this,tn)||!l.isConnected)return;const u=(i=l.ownerDocument)!=null?i:document,{innerHeight:c,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=Hr(l,f),{top:y,left:g,bottom:w,right:x}=h,p=-Math.floor(y),v=-Math.floor(g),_=-Math.floor(d-x),b=-Math.floor(c-w),E=`${p}px ${_}px ${b}px ${v}px`;this.boundingClientRect=f,ct(this,nn,new IntersectionObserver(T=>{const[M]=T,{intersectionRect:O}=M;(M.intersectionRatio!==1?M.intersectionRatio:Ct.intersectionRatio(O,Hr(l)))!==1&&J(this,xr).call(this)},{threshold:pl,rootMargin:E,root:u})),J(this,nn).observe(l),Rd(this,Vs,Hd).call(this)},Gd)),this.boundingClientRect=e.getBoundingClientRect(),ct(this,tn,Ap(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(ct(this,Ze,document.createElement("div")),J(this,Ze).style.background="rgba(0,0,0,0.15)",J(this,Ze).style.position="fixed",J(this,Ze).style.pointerEvents="none",s.body.appendChild(J(this,Ze))),ct(this,yr,new IntersectionObserver(o=>{var i,a;const l=o[o.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:f}=u,h=J(this,tn);ct(this,tn,c),!(!d&&!f)&&(h&&!c?((i=J(this,nn))==null||i.disconnect(),this.callback(null),(a=J(this,Ft))==null||a.disconnect(),ct(this,Ft,void 0),J(this,Ze)&&(J(this,Ze).style.visibility="hidden")):J(this,xr).call(this),c&&!J(this,Ft)&&(ct(this,Ft,new Bp(J(this,xr))),J(this,Ft).observe(e)))},{threshold:pl,root:s})),J(this,tn)&&!n.skipInitial&&this.callback(this.boundingClientRect),J(this,yr).observe(e)}};tn=new WeakMap;Ks=new WeakMap;Ft=new WeakMap;nn=new WeakMap;yr=new WeakMap;Ze=new WeakMap;jr=new WeakMap;xr=new WeakMap;Vs=new WeakSet;Hd=function(){J(this,jr)||(Rd(this,Vs,qd).call(this),!Rp(this.boundingClientRect,J(this,Ks))&&(this.callback(this.boundingClientRect),ct(this,Ks,this.boundingClientRect)))};qd=function(){if(J(this,Ze)){const{top:e,left:t,width:n,height:r}=Hr(this.element);J(this,Ze).style.overflow="hidden",J(this,Ze).style.visibility="visible",J(this,Ze).style.top=`${Math.floor(e)}px`,J(this,Ze).style.left=`${Math.floor(t)}px`,J(this,Ze).style.width=`${Math.floor(n)}px`,J(this,Ze).style.height=`${Math.floor(r)}px`}};var us=new WeakMap,fs=new WeakMap;function Fp(e,t){let n=us.get(e);return n||(n={disconnect:new Ud(e,s=>{const o=us.get(e);o&&o.callbacks.forEach(i=>i(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),us.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(us.delete(e),n.disconnect())}}function Wp(e,t){const n=new Set;for(const r of e){const s=Fp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Np(e,t){var n;const r=e.ownerDocument;if(!fs.has(r)){const i=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(u=>u(l)),{capture:!0,passive:!0,signal:i.signal}),fs.set(r,{disconnect:()=>i.abort(),listeners:a})}const{listeners:s,disconnect:o}=(n=fs.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),fs.delete(r))})}var br,wr,Os,gi,zp=class{constructor(e,t,n){this.callback=t,at(this,br),at(this,wr,!1),at(this,Os),at(this,gi,zd(i=>{if(!J(this,wr)&&i.target&&"contains"in i.target&&typeof i.target.contains=="function"){for(const a of J(this,Os))if(i.target.contains(a)){this.callback(J(this,br).boundingClientRect);break}}},Gd));const r=Pp(e),s=Wp(r,t),o=Np(e,J(this,gi));ct(this,Os,r),ct(this,br,new Ud(e,t,n)),this.disconnect=()=>{J(this,wr)||(ct(this,wr,!0),s(),o(),J(this,br).disconnect())}}};br=new WeakMap;wr=new WeakMap;Os=new WeakMap;gi=new WeakMap;function mi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function jn(e){try{mi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function gl(e){return!Bd||!e?!1:e===Jn(e).scrollingElement}function Kd(e){var t,n;const r=ft(e),s=gl(e)?Ep(e):mo(e),o=r.visualViewport,i=gl(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-i.width,y:e.scrollHeight-i.height}},l=a.current.y<=0,u=a.current.x<=0,c=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:u,isBottom:c,isRight:d}}function Gp(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:i}=Kd(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&i.current.y+l>0,c=!r&&i.current.y+l<i.max.y,d=!s&&i.current.x+a>0,f=!o&&i.current.x+a<i.max.x;return{top:u,bottom:c,left:d,right:f,x:d||f,y:u||c}}var wa=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Xs=new wa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Hp=new wa(e=>setTimeout(e,50)),Ys=new Map,qp=Ys.clear.bind(Ys);function It(e,t=!1){if(!t)return ml(e);let n=Ys.get(e);return n||(n=ml(e),Ys.set(e,n),Hp.schedule(qp),n)}function ml(e){return ft(e).getComputedStyle(e)}function Up(e,t=It(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Kp(e,t=It(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}var Vp={excludeElement:!0,escapeShadowDOM:!0};function vi(e,t=Vp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function i(a){if(n!=null&&o.size>=n||!a)return o;if(va(a)&&a.scrollingElement!=null&&!o.has(a.scrollingElement))return o.add(a.scrollingElement),o;if(s&&xa(a))return i(a.host);if(!Kt(a))return Ld(a)?i(a.parentElement):o;if(o.has(a))return o;const l=It(a,!0);if(r&&a===e||Kp(a,l)&&o.add(a),Up(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&o.add(u),o}return i(a.parentNode)}return e?i(e):o}function Nn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Wn(e);for(;r;){if(r===t)return n;const s=mo(r),{x:o,y:i}=Xp(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*i,r=Wn(r)}return n}function Xp(e,t=mo(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Kt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=It(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Yp(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function qr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function vo(e){var t,n,r,s,o,i,a,l,u;const{scale:c,transform:d,translate:f}=e,h=Yp(c),y=qr(f),g=Qp(d);if(!g&&!h&&!y)return null;const w={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=y?.x)!=null?r:0,y:(s=y?.y)!=null?s:0},p={x:(o=g?.x)!=null?o:0,y:(i=g?.y)!=null?i:0,scaleX:(a=g?.scaleX)!=null?a:1,scaleY:(l=g?.scaleY)!=null?l:1};return{x:x.x+p.x,y:x.y+p.y,z:(u=y?.z)!=null?u:0,scaleX:w.x*p.scaleX,scaleY:w.y*p.scaleY}}function Qp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var mt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(mt||{}),Zp={x:.2,y:.2},Jp={x:10,y:10};function eg(e,t,n,r=25,s=Zp,o=Jp){const{x:i,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:f}=Kd(e),h=Nn(e),y=It(e,!0),g=vo(y),w=g!==null?g?.scaleX<0:!1,x=g!==null?g?.scaleY<0:!1,p=new Ct(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),v={x:0,y:0},_={x:0,y:0},b={height:p.height*s.y,width:p.width*s.x};return b.height>0&&(!u||x&&!c)&&a<=p.top+b.height&&n?.y!==1&&i>=p.left-o.x&&i<=p.right+o.x?(v.y=x?1:-1,_.y=r*Math.abs((p.top+b.height-a)/b.height)):b.height>0&&(!c||x&&!u)&&a>=p.bottom-b.height&&n?.y!==-1&&i>=p.left-o.x&&i<=p.right+o.x&&(v.y=x?-1:1,_.y=r*Math.abs((p.bottom-b.height-a)/b.height)),b.width>0&&(!f||w&&!d)&&i>=p.right-b.width&&n?.x!==-1&&a>=p.top-o.y&&a<=p.bottom+o.y?(v.x=w?-1:1,_.x=r*Math.abs((p.right-b.width-i)/b.width)):b.width>0&&(!d||w&&!f)&&i<=p.left+b.width&&n?.x!==1&&a>=p.top-o.y&&a<=p.bottom+o.y&&(v.x=w?1:-1,_.x=r*Math.abs((p.left+b.width-i)/b.width)),{direction:v,speed:_}}function Vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Kt(e))return;const r=vi(e),s=[];for(const o of r){if(!Kt(o))continue;const{top:i,left:a}=tg(e,o);let l=i,u=a;for(const c of s)l-=c.scrollTop,u-=c.scrollLeft;if(t!=="none"){const c=l<o.scrollTop,d=l+e.offsetHeight>o.scrollTop+o.clientHeight;c!==d&&(t==="center"?o.scrollTop=l-o.clientHeight/2+e.offsetHeight/2:c?o.scrollTop=l:o.scrollTop=l+e.offsetHeight-o.clientHeight)}if(n!=="none"){const c=u<o.scrollLeft,d=u+e.offsetWidth>o.scrollLeft+o.clientWidth;c!==d&&(n==="center"?o.scrollLeft=u-o.clientWidth/2+e.offsetWidth/2:c?o.scrollLeft=u:o.scrollLeft=u+e.offsetWidth-o.clientWidth)}s.push(o)}}function vl(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Kt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function tg(e,t){const n=vl(e),r=vl(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function ng(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left+o+(1-r)*parseFloat(n),l=e.top+i+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function rg(e,t,n){const{scaleX:r,scaleY:s,x:o,y:i}=t,a=e.left-o-(1-r)*parseFloat(n),l=e.top-i-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Xd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function yl(e,t=It(e).translate,n=!0){if(n){const r=Ad(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const o=qr(s);if(o)return o}}}if(t){const r=qr(t);if(r)return r}return{x:0,y:0,z:0}}var sg=new wa(e=>setTimeout(e,0)),Rr=new Map,og=Rr.clear.bind(Rr);function ig(e){const t=e.ownerDocument;let n=Rr.get(t);if(n)return n;n=t.getAnimations(),Rr.set(t,n),sg.schedule(og);const r=n.filter(s=>go(s.effect)&&s.effect.target===e);return Rr.set(e,r),n}function ag(e,t){const n=ig(e).filter(r=>{var s,o;if(go(r.effect)){const{target:i}=r.effect;if((o=i&&((s=t.isValidTarget)==null?void 0:s.call(t,i)))!=null?o:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:s,currentTime:o}=r,i=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof i=="number"&&typeof o=="number"&&o<i)return r.currentTime=i,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Et=class extends Ct{constructor(e,t={}){var n,r,s,o;const{frameTransform:i=Nn(e),ignoreTransforms:a,getBoundingClientRect:l=mo}=t,u=ag(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||ya())&&b.contains(e)}),c=l(e);let{top:d,left:f,width:h,height:y}=c,g;const w=It(e),x=vo(w),p={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},v=lg(e,w);u?.(),x&&(g=rg(c,x,w.transformOrigin),(a||v)&&(d=g.top,f=g.left,h=g.width,y=g.height));const _={width:(s=g?.width)!=null?s:h,height:(o=g?.height)!=null?o:y};if(v&&!a&&g){const b=ng(g,v,w.transformOrigin);d=b.top,f=b.left,h=b.width,y=b.height,p.x=v.scaleX,p.y=v.scaleY}i&&(a||(f*=i.scaleX,h*=i.scaleX,d*=i.scaleY,y*=i.scaleY),f+=i.x,d+=i.y),super(f,d,h,y),this.scale=p,this.intrinsicWidth=_.width,this.intrinsicHeight=_.height}};function lg(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,o,i=!1;for(const a of n){if(a.playState!=="running")continue;const l=go(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:c,translate:d,scale:f}=u;typeof c=="string"&&c&&(r=c,i=!0),typeof d=="string"&&d&&(s=d,i=!0),typeof f=="string"&&f&&(o=f,i=!0)}return i?vo({transform:r??t.transform,translate:s??t.translate,scale:o??t.scale}):null}function Ar(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var cg=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(Ar(n))for(const[r,s]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(Ar(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(Ar(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function dn(e){return e?e instanceof ft(e).Element||ns(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Ur(e){if(!e)return!1;const{KeyboardEvent:t}=ft(e.target);return e instanceof t}function dg(e){if(!e)return!1;const{PointerEvent:t}=ft(e.target);return e instanceof t}function ug(e){if(!dn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||fg(e)}function fg(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Do={};function yi(e){const t=Do[e]==null?0:Do[e]+1;return Do[e]=t,`${e}-${t}`}var _a=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=gt.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},hg=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,o=gt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Yd=e=>{var t;return(t=_a(e))!=null?t:hg(e)},pg=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const o=r?Ct.from(r.current.boundingRectangle).corners:void 0,a=Ct.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+gt.distance(gt.from(u),(d=o?.[c])!=null?d:s.current)},0)/4;return{id:n.id,value:1/a,type:Zn.Collision,priority:Qn.Normal}},gg=Object.create,ka=Object.defineProperty,mg=Object.defineProperties,vg=Object.getOwnPropertyDescriptor,yg=Object.getOwnPropertyDescriptors,Qs=Object.getOwnPropertySymbols,Qd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,Jd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),er=e=>{throw TypeError(e)},xi=(e,t,n)=>t in e?ka(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Kr=(e,t)=>{for(var n in t||(t={}))Qd.call(t,n)&&xi(e,n,t[n]);if(Qs)for(var n of Qs(t))Zd.call(t,n)&&xi(e,n,t[n]);return e},Sa=(e,t)=>mg(e,yg(t)),xl=(e,t)=>ka(e,"name",{value:t,configurable:!0}),eu=(e,t)=>{var n={};for(var r in e)Qd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Qs)for(var r of Qs(e))t.indexOf(r)<0&&Zd.call(e,r)&&(n[r]=e[r]);return n},tr=e=>{var t;return[,,,gg((t=e?.[Jd("metadata")])!=null?t:null)]},tu=["class","method","getter","setter","accessor","field","value","get","set"],_r=e=>e!==void 0&&typeof e!="function"?er("Function expected"):e,xg=(e,t,n,r,s)=>({kind:tu[e],name:t,metadata:r,addInitializer:o=>n._?er("Already initialized"):s.push(_r(o||null))}),gn=(e,t)=>xi(t,Jd("metadata"),e[3]),Ve=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},xt=(e,t,n,r,s,o)=>{var i,a,l,u,c,d=t&7,f=!!(t&8),h=!!(t&16),y=d>3?e.length+1:d?f?1:2:0,g=tu[d+5],w=d>3&&(e[y-1]=[]),x=e[y]||(e[y]=[]),p=d&&(!h&&!f&&(s=s.prototype),d<5&&(d>3||!h)&&vg(d<4?s:{get[n](){return xe(this,o)},set[n](_){return st(this,o,_)}},n));d?h&&d<4&&xl(o,(d>2?"set ":d>1?"get ":"")+n):xl(s,n);for(var v=r.length-1;v>=0;v--)u=xg(d,n,l={},e[3],x),d&&(u.static=f,u.private=h,c=u.access={has:h?_=>bg(s,_):_=>n in _},d^3&&(c.get=h?_=>(d^1?xe:un)(_,s,d^4?o:p.get):_=>_[n]),d>2&&(c.set=h?(_,b)=>st(_,s,b,d^4?o:p.set):(_,b)=>_[n]=b)),a=(0,r[v])(d?d<4?h?o:p[g]:d>4?void 0:{get:p.get,set:p.set}:s,u),l._=1,d^4||a===void 0?_r(a)&&(d>4?w.unshift(a):d?h?o=a:p[g]=a:s=a):typeof a!="object"||a===null?er("Object expected"):(_r(i=a.get)&&(p.get=i),_r(i=a.set)&&(p.set=i),_r(i=a.init)&&w.unshift(i));return d||gn(e,s),p&&ka(s,n,p),h?d^4?o:p:s},$a=(e,t,n)=>t.has(e)||er("Cannot "+n),bg=(e,t)=>Object(t)!==t?er('Cannot use the "in" operator on this value'):e.has(t),xe=(e,t,n)=>($a(e,t,"read from private field"),n?n.call(e):t.get(e)),ze=(e,t,n)=>t.has(e)?er("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),st=(e,t,n,r)=>($a(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),un=(e,t,n)=>($a(e,t,"access private method"),n),bl={role:"button",roleDescription:"draggable"},wg="dnd-kit-description",_g="dnd-kit-announcement",kg={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Sg={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function $g(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Tg(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Eg(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Cg=["dragover","dragmove"],Og=class extends et{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=wg,announcement:s=_g}={},announcements:o=Sg,screenReaderInstructions:i=kg,debounce:a=500}=t??{},l=n?`${r}-${n}`:yi(r),u=n?`${s}-${n}`:yi(s);let c,d,f,h;const y=(b=h)=>{!f||!b||f?.nodeValue!==b&&(f.nodeValue=b)},g=()=>Xs.schedule(y),w=Mg(g,a),x=Object.entries(o).map(([b,E])=>this.manager.monitor.addEventListener(b,(T,M)=>{const O=f;if(!O)return;const C=E?.(T,M);C&&O.nodeValue!==C&&(h=C,Cg.includes(b)?w():(g(),w.cancel()))})),p=()=>{let b=[];c?.isConnected||(c=Tg(l,i.draggable),b.push(c)),d?.isConnected||(d=Eg(u),f=document.createTextNode(""),d.appendChild(f),b.push(d)),b.length>0&&document.body.append(...b)},v=new Set;function _(){for(const b of v)b()}this.registerEffect(()=>{var b;v.clear();for(const E of this.manager.registry.draggables.value){const T=(b=E.handle)!=null?b:E.element;if(T){(!c||!d)&&v.add(p),(!$g(T)||ya())&&!T.hasAttribute("tabindex")&&v.add(()=>T.setAttribute("tabindex","0")),!T.hasAttribute("role")&&T.tagName.toLowerCase()!=="button"&&v.add(()=>T.setAttribute("role",bl.role)),T.hasAttribute("aria-roledescription")||v.add(()=>T.setAttribute("aria-roledescription",bl.roleDescription)),T.hasAttribute("aria-describedby")||v.add(()=>T.setAttribute("aria-describedby",l));for(const O of["aria-pressed","aria-grabbed"]){const C=String(E.isDragging);T.getAttribute(O)!==C&&v.add(()=>T.setAttribute(O,C))}const M=String(E.disabled);T.getAttribute("aria-disabled")!==M&&v.add(()=>T.setAttribute("aria-disabled",M))}}v.size>0&&Xs.schedule(_)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),x.forEach(b=>b())}}};function Mg(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Zs=new Map,nu,ru,su,ou,bi,Lr,jt,Ta,zn,iu,au,lu,cu,Vt=class extends(bi=ts,ou=[le],su=[We],ru=[We],nu=[We],bi){constructor(t,n){super(t,n),Ve(jt,5,this),ze(this,zn),ze(this,Lr,new Set),ze(this,Ta,Ve(jt,8,this,new Set)),Ve(jt,11,this),this.registerEffect(un(this,zn,iu))}register(t){return xe(this,Lr).add(t),()=>{xe(this,Lr).delete(t)}}addRoot(t){return ae(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ae(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Us((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Us((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};jt=tr(bi);Lr=new WeakMap;Ta=new WeakMap;zn=new WeakSet;iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of xe(this,Lr))t.push(un(this,zn,au).call(this,n,r));return()=>{for(const n of t)n()}};au=function(e,t){let n=Zs.get(e);n||(n=new Map,Zs.set(e,n));let r=n.get(t);if(!r){const o=va(e)?un(this,zn,lu).call(this,e,n,t):un(this,zn,cu).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};lu=function(e,t,n){var r;const s=e.createElement("style"),{nonce:o}=(r=this.options)!=null?r:{};o&&s.setAttribute("nonce",o),s.textContent=n,e.head.prepend(s);const i=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===s){e.head.prepend(s);return}});return i.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{i.disconnect(),s.remove(),t.delete(n),t.size===0&&Zs.delete(e)}}};cu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const o=new s;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var i;if(xa(e)&&((i=e.host)!=null&&i.isConnected)){const a=e.adoptedStyleSheets.indexOf(o);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Zs.delete(e)}}};xt(jt,4,"additionalRoots",ou,Vt,Ta);xt(jt,2,"sourceRoot",su,Vt);xt(jt,2,"targetRoot",ru,Vt);xt(jt,2,"roots",nu,Vt);gn(jt,Vt);Vt.configure=es(Vt);var yo=Vt,Ig=class extends et{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(yo),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}}},rs="data-dnd-",wi=`${rs}dropping`,Qe="--dnd-",Tt=`${rs}dragging`,Js=`${rs}placeholder`,Dg=[Tt,Js,"popover","aria-pressed","aria-grabbing"],Pg=["view-transition-name"],jg=`
9
+ :is(:root,:host) [${Tt}] {
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(${He}top, 0px) !important;
16
- left: var(${He}left, 0px) !important;
15
+ top: var(${Qe}top, 0px) !important;
16
+ left: var(${Qe}left, 0px) !important;
17
17
  right: unset !important;
18
18
  bottom: unset !important;
19
- width: var(${He}width, auto);
20
- max-width: var(${He}width, auto);
21
- height: var(${He}height, auto);
22
- max-height: var(${He}height, auto);
23
- transform: var(${He}transform, none) !important;
24
- transition: var(${He}transition) !important;
19
+ width: var(${Qe}width, auto);
20
+ max-width: var(${Qe}width, auto);
21
+ height: var(${Qe}height, auto);
22
+ max-height: var(${Qe}height, auto);
23
+ transform: var(${Qe}transform, none) !important;
24
+ transition: var(${Qe}transition) !important;
25
25
  }
26
26
 
27
- :is(:root,:host) [${zs}] {
27
+ :is(:root,:host) [${Js}] {
28
28
  transition: none;
29
29
  }
30
30
 
31
- :is(:root,:host) [${zs}='hidden'] {
31
+ :is(:root,:host) [${Js}='hidden'] {
32
32
  visibility: hidden;
33
33
  }
34
34
 
35
- [${vt}] * {
35
+ [${Tt}] * {
36
36
  pointer-events: none !important;
37
37
  }
38
38
 
39
- [${vt}]:not([${co}]) {
40
- translate: var(${He}translate) !important;
39
+ [${Tt}]:not([${wi}]) {
40
+ translate: var(${Qe}translate) !important;
41
41
  }
42
42
 
43
- [${vt}][style*='${He}scale'] {
44
- scale: var(${He}scale) !important;
45
- transform-origin: var(${He}transform-origin) !important;
43
+ [${Tt}][style*='${Qe}scale'] {
44
+ scale: var(${Qe}scale) !important;
45
+ transform-origin: var(${Qe}transform-origin) !important;
46
46
  }
47
47
 
48
48
  @layer dnd-kit {
49
- :where([${vt}][popover]) {
49
+ :where([${Tt}][popover]) {
50
50
  overflow: visible;
51
51
  background: unset;
52
52
  border: unset;
@@ -60,84 +60,85 @@
60
60
  }
61
61
  }
62
62
  }
63
- [${vt}]::backdrop, [${zr}overlay]:not([${vt}]) {
63
+ [${Tt}]::backdrop, [${rs}overlay]:not([${Tt}]) {
64
64
  display: none;
65
65
  visibility: hidden;
66
66
  }
67
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Fp(e,t="hidden"){return ne(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=zp(n,r.registry.droppables),i=[],o=Ph(n),{remove:a}=o;return Wp(s,o,i),Np(o,t),o.remove=()=>{i.forEach(c=>c()),a.call(o)},o})}function zp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${zr}${oo("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Wp(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),no.set(a,o),n.push(()=>{no.delete(a),r.proxy=void 0})}}function Np(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(zs,t)}function jd(e,t){return e===t?!0:On(e)===On(t)}function nl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Qt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Sn(t))}function uo(e){return e.tagName==="TR"}function Gp(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Ap.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(wr(e)&&wr(t)){const f=e.style;for(const d of Array.from(t.style))f.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(f)){if(Lp.includes(d)||d.startsWith(He))continue;const l=f.getPropertyValue(d);t.style.setProperty(d,l)}}}else c!==null?t.setAttribute(a,c):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Up(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Sn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Sn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),Sn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Hp(e){return new ResizeObserver(()=>{var t,n,r;const s=new yt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,c=ld();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+c.y,left:e.left+o+c.x},He),(n=e.getElementMutationObserver())==null||n.takeRecords(),uo(e.element)&&uo(e.placeholder)){const v=Array.from(e.element.cells),x=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(_=>_.style.width));for(const[_,g]of v.entries()){const y=x[_];g.style.width=`${y.getBoundingClientRect().width}px`}}const f=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+c.x+f.x,l=e.top+a+c.y+f.y,u=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new bt(d*p.scaleX+p.x,l*p.scaleY+p.y,u*p.scaleX,h*p.scaleY)})}var Vp=250,Kp="ease";function qp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const g=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(g).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Vp,easing:a=Kp}=i??{};Sn(e.feedbackElement);const[,c]=(t=id(e.feedbackElement,g=>"translate"in g))!=null?t:[];c?.pause();const f=(n=e.placeholder)!=null?n:e.element,d={frameTransform:jd(e.feedbackElement,f)?null:void 0},l=new yt(e.feedbackElement,d),u=(r=Er(_t(e.feedbackElement).translate))!=null?r:e.translate,h=new yt(f,d),p=bt.delta(l,h,e.alignment),v={x:u.x-p.x,y:u.y-p.y},x=Math.round(l.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${l.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},_=Math.round(l.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${l.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},He),e.feedbackElement.setAttribute(co,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),yd({element:e.feedbackElement,keyframes:ua(Or(Or({},x),_),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:aa(st(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(co),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Pd,fo,Dr,pa,ys,Rd,Ad,In=class extends(fo=qe,Pd=[re],fo){constructor(t,n){super(t,n),Pe(this,ys),Pe(this,pa,ze(Dr,8,this)),ze(Dr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(si),s=r?.register(Bp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Zt(this,ys,Rd).bind(this,r)),this.registerEffect(Zt(this,ys,Ad))}};Dr=Gn(fo);pa=new WeakMap;ys=new WeakSet;Rd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=js(t);if(n)return e.addRoot(n)};Ad=function(){var e,t,n,r,s,i,o;const{state:a,manager:c,options:f}=this,{dragOperation:d}=c,{position:l,source:u,status:h}=d;if(h.idle){a.current={},a.initial={};return}if(!u)return;const{element:p}=u,v=u.pluginConfig(In),x=(t=(e=v?.feedback)!=null?e:f?.feedback)!=null?t:"default",_=typeof x=="function"?x(u,c):x;if(!p||_==="none"||!h.initialized||h.initializing)return;const{initial:g}=a,y=(n=this.overlay)!=null?n:p,w=Dn(y),b=Dn(p),T=!jd(p,y),C=new yt(p,{frameTransform:T?b:null,ignoreTransforms:!T}),M={x:b.scaleX/w.scaleX,y:b.scaleY/w.scaleY};let{width:E,height:O,top:A,left:j}=C;T&&(E=E/M.x,O=O/M.y);const L=new hp(y),N=_t(p),{transition:W,translate:V,boxSizing:I,paddingBlockStart:F,paddingBlockEnd:H,paddingInlineStart:B,paddingInlineEnd:G,borderInlineStartWidth:ee,borderInlineEndWidth:Q,borderBlockStartWidth:J,borderBlockEndWidth:X}=N,te=W.split(",").filter(ce=>!/^\s*(transform|translate|scale)\b/.test(ce)).join(","),we=ri(N),me=N.transform,ye=_==="clone",$e=I==="content-box",ue=$e?parseInt(B)+parseInt(G)+parseInt(ee)+parseInt(Q):0,ve=$e?parseInt(F)+parseInt(H)+parseInt(J)+parseInt(X):0,Z=_!=="move"&&!this.overlay?Fp(u,ye?"clone":"hidden"):null,Ue=ne(()=>Cr(c.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&we)g.translate={x:we.x,y:we.y};else if(V!=="none"){const ce=Er(V);ce&&(g.translate=ce)}}if(!g.transformOrigin){const ce=ne(()=>l.current),Re=j+((r=we?.x)!=null?r:0),tt=A+((s=we?.y)!=null?s:0);g.transformOrigin={x:(ce.x-Re*w.scaleX-w.x)/(E*w.scaleX),y:(ce.y-tt*w.scaleY-w.y)/(O*w.scaleY)}}const{transformOrigin:fe}=g,le=A*w.scaleY+w.y,Le=j*w.scaleX+w.x;if(!g.coordinates&&(g.coordinates={x:Le,y:le},M.x!==1||M.y!==1)){const{scaleX:ce,scaleY:Re}=b,{x:tt,y:Ct}=fe;g.coordinates.x+=(E*ce-E)*tt,g.coordinates.y+=(O*Re-O)*Ct}g.dimensions||(g.dimensions={width:E,height:O}),g.frameTransform||(g.frameTransform=w);const We={x:g.coordinates.x-Le,y:g.coordinates.y-le},he={width:(g.dimensions.width*g.frameTransform.scaleX-E*w.scaleX)*fe.x,height:(g.dimensions.height*g.frameTransform.scaleY-O*w.scaleY)*fe.y},Ne={x:We.x/w.scaleX+he.width,y:We.y/w.scaleY+he.height},Oe={left:j+Ne.x,top:A+Ne.y};y.setAttribute(vt,"true");const D=ne(()=>d.transform),R=(i=g.translate)!=null?i:{x:0,y:0},z=D.x*w.scaleX+R.x,P=D.y*w.scaleY+R.y,U=ld();L.set({width:E-ue,height:O-ve,top:Oe.top+U.y,left:Oe.left+U.x,translate:`${z}px ${P}px 0`,transform:this.overlay?"none":me,transition:te?`${te}, translate 0ms linear`:"translate 0ms linear",scale:T?`${M.x} ${M.y}`:"","transform-origin":`${fe.x*100}% ${fe.y*100}%`},He),Z&&(p.insertAdjacentElement("afterend",Z),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(p)),so(y)&&(y.hasAttribute("popover")||y.setAttribute("popover","manual"),Sn(y),y.addEventListener("beforetoggle",nl));let K,ie,_e;const oe=Hp({placeholder:Z,element:p,feedbackElement:y,frameTransform:w,transformOrigin:fe,width:E,height:O,top:A,left:j,widthOffset:ue,heightOffset:ve,delta:Ne,styles:L,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>K,getSavedCellWidths:()=>_e,setSavedCellWidths:ce=>{_e=ce}}),Ge=new yt(y);ne(()=>d.shape=Ge);const et=st(y),Vr=ce=>{this.manager.actions.stop({event:ce})},rn=aa(et);Ue&&et.addEventListener("resize",Vr),ne(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),Z&&(oe.observe(Z),K=Gp(p,Z,ye),ie=Up(p,Z,y));const sn=(o=c.dragOperation.source)==null?void 0:o.id,Kr=()=>{var ce;if(!Ue||sn==null)return;const Re=c.registry.draggables.get(sn),tt=(ce=Re?.handle)!=null?ce:Re?.element;At(tt)&&tt.focus()},qr=()=>{K?.disconnect(),ie?.disconnect(),oe.disconnect(),et.removeEventListener("resize",Vr),so(y)&&(y.removeEventListener("beforetoggle",nl),y.removeAttribute("popover")),y.removeAttribute(vt),L.reset();const ce=()=>{var Re;if(_e&&uo(p)){const di=Array.from(p.cells);for(const[Xr,on]of di.entries())on.style.width=(Re=_e[Xr])!=null?Re:""}u.status="idle";const tt=a.current.translate!=null,Ct=d.status.dragging;Z&&(!Ct&&tt||Z.parentElement!==y.parentElement)&&y.isConnected&&Z.replaceWith(y),Z?.remove()};y===this.overlay?setTimeout(ce,0):ce()},ci=f?.dropAnimation,Yr=this,Vn=Rr(()=>{var ce,Re,tt;const{transform:Ct,status:di}=d;if(!(!Ct.x&&!Ct.y&&!a.current.translate)&&di.dragging){const Xr=(ce=g.translate)!=null?ce:{x:0,y:0},on={x:Ct.x/w.scaleX+Xr.x,y:Ct.y/w.scaleY+Xr.y},Ia=a.current.translate,Zu=ne(()=>d.modifiers),ui=ne(()=>{var qn;return(qn=d.shape)==null?void 0:qn.current}),Kn=f?.keyboardTransition,ja=Ue&&!rn&&Kn!==null?`${(Re=Kn?.duration)!=null?Re:250}ms ${(tt=Kn?.easing)!=null?tt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(L.set({transition:te?`${te}, translate ${ja}`:`translate ${ja}`,translate:`${on.x}px ${on.y}px 0`},He),K?.takeRecords(),ui&&ui!==Ge&&Ia&&!Zu.length){const qn=ot.delta(on,Ia);d.shape=bt.from(ui.boundingRectangle).translate(qn.x*w.scaleX,qn.y*w.scaleY)}else d.shape=new yt(y);a.current.translate=on}},function(){if(d.status.dropped){this.dispose(),u.status="dropping";const ce=v?.dropAnimation!==void 0?v.dropAnimation:Yr.dropAnimation!==void 0?Yr.dropAnimation:ci;let Re=a.current.translate;const tt=Re!=null;if(!Re&&p!==y&&(Re={x:0,y:0}),!Re||ce===null){qr();return}c.renderer.rendering.then(()=>{qp({source:u,element:p,feedbackElement:y,placeholder:Z,translate:Re,moved:tt,transition:W,alignment:u.alignment,styles:L,animation:ce??void 0,getElementMutationObserver:()=>K,cleanup:qr,restoreFocus:Kr})})}});return()=>{qr(),Vn()}};ut(Dr,4,"overlay",Pd,In,pa);nn(Dr,In);In.configure=Lr(In);var ga=In,Xn=!0,Yp=!1,Ld,Bd,Fd,zd,It,ma,va;zd=(Fd=[re],at.Forward),Bd=(Ld=[re],at.Reverse);var Mr=class{constructor(){Pe(this,ma,ze(It,8,this,Xn)),ze(It,11,this),Pe(this,va,ze(It,12,this,Xn)),ze(It,15,this)}isLocked(e){return e===at.Idle?!1:e==null?this[at.Forward]===Xn&&this[at.Reverse]===Xn:this[e]===Xn}unlock(e){e!==at.Idle&&(this[e]=Yp)}};It=Gn(null);ma=new WeakMap;va=new WeakMap;ut(It,4,zd,Fd,Mr,ma);ut(It,4,Bd,Ld,Mr,va);nn(It,Mr);var Xp=[at.Forward,at.Reverse],rl=class{constructor(){this.x=new Mr,this.y=new Mr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Qp=class extends qe{constructor(e){super(e);const t=jn(new rl);let n=null;this.signal=t,dt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new rl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:sl(s.x,n.x),y:sl(s.y,n.y)},o=t.peek();Ce(()=>{for(const a of gc)for(const c of Xp)i[a]===c&&o[a].unlock(c);t.value=o})}n=s})}get current(){return this.signal.peek()}};function sl(e,t){return Math.sign(e-t)}var Wd,ho,Ir,ya,Dt,po,Wr=class extends(ho=Br,Wd=[re],ho){constructor(e){super(e),Pe(this,ya,ze(Ir,8,this,!1)),ze(Ir,11,this),Pe(this,Dt),Pe(this,po,()=>{if(!ge(this,Dt))return;const{element:i,by:o}=ge(this,Dt);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const c=this.getScrollableElements();if(!c)return Qe(this,Dt,void 0),!1;const{position:f}=this.manager.dragOperation,d=f?.current;if(d){const{by:l}=i??{},u=l?{x:il(l.x),y:il(l.y)}:void 0,h=u?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of c){const v=Kh(p,l);if(v.x||v.y){const{speed:x,direction:_}=sp(p,d,u,o?.acceleration,o?.threshold);if(h)for(const g of gc)h[g].isLocked(_[g])&&(x[g]=0,_[g]=0);if(_.x||_.y){const{x:g,y}=l??_,w=g*x.x,b=y*x.y;if(w||b){const T=(a=ge(this,Dt))==null?void 0:a.by;if(this.autoScrolling&&T&&(T.x&&!w||T.y&&!b))continue;return Qe(this,Dt,{element:p,by:{x:w,y:b}}),As.schedule(ge(this,po)),!0}}}}}return Qe(this,Dt,void 0),!1};let t=null,n=null;const r=Ni(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=cd(js(o?.element),i.current);return a&&(t=a),a??t}),s=Ni(()=>{const i=r.value,{documentElement:o}=Wn(i);if(!i||i===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const f=io(c,{excludeElement:!1});return n=f,f}}if(i){const a=io(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ft);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Qp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!Cr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};Ir=Gn(ho);ya=new WeakMap;Dt=new WeakMap;po=new WeakMap;ut(Ir,4,"autoScrolling",Wd,Wr,ya);nn(Ir,Wr);function il(e){return e>0?at.Forward:e<0?at.Reverse:at.Idle}var Zp=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},Jp=new Zp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),eg=10,go=class extends qe{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Wr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=dt(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:c}=t.dragOperation;if(c.dragging){const f={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,f)){r.autoScrolling=!0;const l=setInterval(()=>Jp.schedule(()=>r.scroll(void 0,f)),eg);return()=>{clearInterval(l)}}else r.autoScrolling=!1}})}};go.configure=Lr(go);var Nd=go,ol={capture:!0,passive:!0},cr,tg=class extends Br{constructor(e){super(e),Pe(this,cr),this.handleScroll=()=>{ge(this,cr)==null&&Qe(this,cr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Qe(this,cr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=dt(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,ol),()=>{o.removeEventListener("scroll",this.handleScroll,ol)}}})}};cr=new WeakMap;var ng="* { user-select: none !important; -webkit-user-select: none !important; }",rg=class extends qe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(si),n=t?.register(ng);if(this.destroy=dt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return xi(),document.addEventListener("selectionchange",xi,{capture:!0}),()=>{document.removeEventListener("selectionchange",xi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function xi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var dr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),mn,Ws=class extends En{constructor(t,n){super(t),this.manager=t,this.options=n,Pe(this,mn,[]),this.listeners=new dd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Qt(r.target)||s.disabled)return;const{keyboardCodes:o=dr.keyboardCodes,preventActivation:a=dr.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return dt(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{Cr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),vd(s);const{center:i}=new yt(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Wn(s),c=[this.listeners.bind(a,[{type:"keydown",listener:f=>this.handleKeyDown(f,n,r),options:{capture:!0}}])];ge(this,mn).push(...c)}handleKeyDown(t,n,r){const{keyboardCodes:s=dr.keyboardCodes}=r??{};if(an(t,[...s.end,...s.cancel])){t.preventDefault();const i=an(t,s.cancel);this.handleEnd(t,i);return}an(t,s.up)?this.handleMove("up",t):an(t,s.down)&&this.handleMove("down",t),an(t,s.left)?this.handleMove("left",t):an(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},c=(s=(r=this.options)==null?void 0:r.offset)!=null?s:dr.offset;if(typeof c=="number"&&(c={x:c,y:c}),!!i){switch(t){case"up":a={x:0,y:-c.y*o};break;case"down":a={x:0,y:c.y*o};break;case"left":a={x:-c.x*o,y:0};break;case"right":a={x:c.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Nd);t?.disabled===!1&&(t.disable(),ge(this,mn).push(()=>{t.enable()}))}cleanup(){ge(this,mn).forEach(t=>t()),Qe(this,mn,[])}destroy(){this.cleanup(),this.listeners.clear()}};mn=new WeakMap;Ws.configure=Lr(Ws);Ws.defaults=dr;var Gd=Ws;function an(e,t){return t.includes(e.code)}var Ht,sg=class extends Kc{constructor(){super(...arguments),Pe(this,Ht)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Ht,Cn(e));break;case"pointermove":if(!ge(this,Ht))return;const{x:t,y:n}=Cn(e),r={x:t-ge(this,Ht).x,y:n-ge(this,Ht).y},{tolerance:s}=this.options;if(s&&Qi(r,s)){this.abort();return}Qi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Qe(this,Ht,void 0)}};Ht=new WeakMap;var vn,Vt,ig=class extends Kc{constructor(){super(...arguments),Pe(this,vn),Pe(this,Vt)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Vt,Cn(e)),Qe(this,vn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ge(this,Vt))return;const{x:t,y:n}=Cn(e),r={x:t-ge(this,Vt).x,y:n-ge(this,Vt).y};Qi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ge(this,vn)&&(clearTimeout(ge(this,vn)),Qe(this,Vt,void 0),Qe(this,vn,void 0))}};vn=new WeakMap;Vt=new WeakMap;var wn=class{};wn.Delay=ig;wn.Distance=sg;var mo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Qt(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new wn.Delay({value:250,tolerance:5})]:gp(s)&&!e.defaultPrevented?[new wn.Delay({value:200,tolerance:0})]:[new wn.Delay({value:200,tolerance:10}),new wn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Qt(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Ah(r);return s===t.element?!1:!!s}}),yn,Ns=class extends En{constructor(t,n){super(t),this.manager=t,this.options=n,Pe(this,yn,new Set),this.listeners=new dd,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=mo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return dt(()=>{var s;const i=new AbortController,{signal:o}=i,a=f=>{pp(f)&&this.handlePointerDown(f,t,n)};let c=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?c=n.activatorElements:c=n.activatorElements(t));for(const f of c)f&&(lg(f.ownerDocument.defaultView),f.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Qt(t.target)||n.disabled||og(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=mo.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=At(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=Dn(n.element),{x:c,y:f}=Cn(t);this.initialCoordinates={x:c*a.scaleX+a.x,y:f*a.scaleY+a.y};const d=this.activationConstraints(t,n,r);t.sensor=this;const l=new Eh(d,v=>this.handleStart(n,v));l.signal.onabort=()=>this.handleCancel(t),l.onEvent(t),this.controller=l;const u=to(),h=this.listeners.bind(u,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:ns,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};ge(this,yn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=Cn(t),o=Dn(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,As.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Wn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const c=Qt(n.target)?[n.target,a]:a,f=this.listeners.bind(c,[{type:"touchmove",listener:ns,options:{passive:!1}},{type:"click",listener:ns},{type:"contextmenu",listener:ns},{type:"keydown",listener:this.handleKeyDown}]);ge(this,yn).add(f)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},ge(this,yn).forEach(n=>n()),ge(this,yn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};yn=new WeakMap;Ns.configure=Lr(Ns);Ns.defaults=mo;var vo=Ns;function og(e){return"sensor"in e}function ns(e){e.preventDefault()}function ag(){}var al=new WeakSet;function lg(e){!e||al.has(e)||(e.addEventListener("touchmove",ag,{capture:!1,passive:!1}),al.add(e))}var $n={modifiers:[],plugins:[jp,Nd,Rp,ga,rg],sensors:[vo,Gd]},Ud=class extends Dh{constructor(e={}){const t=gt(e.plugins,$n.plugins),n=gt(e.sensors,$n.sensors),r=gt(e.modifiers,$n.modifiers);super(ua(Or({},e),{plugins:[tg,Wr,si,...t],sensors:n,modifiers:r}))}},Hd,Vd,yo,jt,ba,xa,ii=class extends(yo=xt,Vd=[re],Hd=[re],yo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=kd(n,["element","effects","handle"]);super(Or({effects:()=>[...s(),()=>{var a,c;const{manager:f}=this;if(!f)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Sr))!=null?c:[...f.sensors]).map(u=>{const h=u instanceof En?u:f.registry.register(u.plugin),p=u instanceof En?void 0:u.options;return h.bind(this,p)});return function(){l.forEach(h=>h())}}]},o),t),Pe(this,ba,ze(jt,8,this)),ze(jt,11,this),Pe(this,xa,ze(jt,12,this)),ze(jt,15,this),this.element=r,this.handle=i}};jt=Gn(yo);ba=new WeakMap;xa=new WeakMap;ut(jt,4,"handle",Vd,ii,ba);ut(jt,4,"element",Hd,ii,xa);nn(jt,ii);var Kd,qd,bo,Pt,wa,wi,Yd,Xd,kr,_a,oi=class extends(bo=wt,qd=[re],Kd=[re],bo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=kd(n,["element","effects"]);const{collisionDetector:o=bd}=i,a=f=>{const{manager:d,element:l}=this;if(!l||f===null){this.shape=void 0;return}if(!d)return;const u=new yt(l),h=ne(()=>this.shape);return u&&h?.equals(u)?h:(this.shape=u,u)},c=jn(!1);super(ua(Or({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:f,manager:d}=this;if(!d)return;const{dragOperation:l}=d,{source:u}=l;c.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(c.value&&f){const d=new Vh(f,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Pe(this,kr),Pe(this,wa,ze(Pt,8,this)),ze(Pt,11,this),Pe(this,_a,ze(Pt,12,this)),ze(Pt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Qe(this,kr,e,Xd)}get element(){var e;return(e=this.proxy)!=null?e:ge(this,kr,Yd)}};Pt=Gn(bo);wa=new WeakMap;kr=new WeakSet;_a=new WeakMap;wi=ut(Pt,20,"#element",qd,kr,wa),Yd=wi.get,Xd=wi.set;ut(Pt,4,"proxy",Kd,oi,_a);nn(Pt,oi);function cg(e){return e!=null&&typeof e=="object"&&"current"in e}function Tn(e){var t;if(e!=null)return cg(e)?(t=e.current)!=null?t:void 0:e}var dg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Un=dg?k.useLayoutEffect:k.useEffect;function ug(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qd(e,t){const n=k.useRef(new Map),r=ug();return Un(()=>{if(!e){n.current.clear();return}return dt(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[c]=a,f=ne(()=>a[1]),d=e[c];f!==d&&(i=!0,n.current.set(c,d),o=(s=t?.(c,f,d))!=null?s:!1)}i&&(o?queueMicrotask(()=>Ju.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function fg(e,t){e()}function ln(e){const t=k.useRef(e);return Un(()=>{t.current=e},[e]),t}function Te(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function bs(e,t){const n=k.useRef(Tn(e));Un(()=>{const r=Tn(e);r!==n.current&&(n.current=r,t(r))})}var hg=Object.defineProperty,pg=Object.defineProperties,gg=Object.getOwnPropertyDescriptors,Gs=Object.getOwnPropertySymbols,Zd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,ll=(e,t,n)=>t in e?hg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mg=(e,t)=>{for(var n in t||(t={}))Zd.call(t,n)&&ll(e,n,t[n]);if(Gs)for(var n of Gs(t))Jd.call(t,n)&&ll(e,n,t[n]);return e},vg=(e,t)=>pg(e,gg(t)),yg=(e,t)=>{var n={};for(var r in e)Zd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Gs)for(var r of Gs(e))t.indexOf(r)<0&&Jd.call(e,r)&&(n[r]=e[r]);return n},bg=new Ud,eu=k.createContext(bg),xg=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(c=>{i.current=c})),k.startTransition(()=>{a(),r(c=>c+1)})}}),[]);return Un(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),_i=[void 0,ft];function wg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:c}=t,f=yg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:l,modifiers:u,sensors:h}=f,p=gt(l,$n.plugins),v=gt(h,$n.sensors),x=gt(u,$n.modifiers),_=ln(s),g=ln(i),y=ln(a),w=ln(o),b=ln(c),T=ln(r),C=_g(()=>{var M;return(M=f.manager)!=null?M:new Ud(f)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:E}=d.current,{monitor:O}=C;C.renderer=M;const A=[O.addEventListener("beforedragstart",j=>{const L=_.current;L&&E(()=>L(j,C))}),O.addEventListener("dragstart",j=>{var L;return(L=g.current)==null?void 0:L.call(g,j,C)}),O.addEventListener("dragover",j=>{const L=y.current;L&&E(()=>L(j,C))}),O.addEventListener("dragmove",j=>{const L=w.current;L&&E(()=>L(j,C))}),O.addEventListener("dragend",j=>{const L=b.current;L&&E(()=>L(j,C))}),O.addEventListener("collision",j=>{var L;return(L=T.current)==null?void 0:L.call(T,j,C)})];return()=>A.forEach(j=>j())},[C]),Te(p,()=>C&&(C.plugins=p),..._i),Te(v,()=>C&&(C.sensors=v),..._i),Te(x,()=>C&&(C.modifiers=x),..._i),m.jsxs(eu.Provider,{value:C,children:[m.jsx(xg,{ref:d,children:n}),n]})}function _g(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function kg(){return k.useContext(eu)}function tu(e){var t;const n=(t=kg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Un(r.register,[n,r]),r}var Sg=Object.create,nu=Object.defineProperty,$g=Object.getOwnPropertyDescriptor,ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ai=e=>{throw TypeError(e)},Tg=(e,t,n)=>t in e?nu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Eg=e=>{var t;return[,,,Sg((t=e?.[ru("metadata")])!=null?t:null)]},su=["class","method","getter","setter","accessor","field","value","get","set"],iu=e=>e!==void 0&&typeof e!="function"?ai("Function expected"):e,Cg=(e,t,n,r,s)=>({kind:su[e],name:t,metadata:r,addInitializer:i=>n._?ai("Already initialized"):s.push(iu(i||null))}),Og=(e,t)=>Tg(t,ru("metadata"),e[3]),Dg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ou=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=su[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,$g(s,n)),_=r.length-1;_>=0;_--)c=Cg(d,n,a={},e[3],v),c.static=l,c.private=u,f=c.access={has:g=>n in g},f.get=g=>g[n],o=(0,r[_])(x[p],c),a._=1,iu(o)&&(x[p]=o);return x&&nu(s,n,x),s},au=(e,t,n)=>t.has(e)||ai("Cannot "+n),Mg=(e,t,n)=>(au(e,t,"read from private field"),t.get(e)),Ig=(e,t,n)=>t.has(e)?ai("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jg=(e,t,n,r)=>(au(e,t,"write to private field"),t.set(e,n),n),qt=class xo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new xo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new xo(t,n)}},lu,cu,wo,xs,Nr,ka=class extends(wo=en,cu=[Me],lu=[Me],wo){constructor(e){const t=qt.from(e);super(t,(n,r)=>qt.equals(n,r)),Dg(Nr,5,this),Ig(this,xs,0),this.velocity={x:0,y:0}}get delta(){return qt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=qt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-Mg(this,xs),o=a=>Math.round(a/i*100);Ce(()=>{jg(this,xs,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(qt.from(e)),this.velocity={x:0,y:0}}};Nr=Eg(wo);xs=new WeakMap;ou(Nr,2,"delta",cu,ka);ou(Nr,2,"direction",lu,ka);Og(Nr,ka);var du=(e=>(e.Horizontal="x",e.Vertical="y",e))(du||{});Object.values(du);var Pg=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=qt.distance(t.shape.center,n);return{id:r,value:1/s,type:zn.PointerIntersection,priority:Fn.High}}return null},Rg=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=qt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:zn.ShapeIntersection,priority:Fn.Normal}}return null},Ag=e=>{var t;return(t=Pg(e))!=null?t:Rg(e)};function Lg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,c=tu(d=>new oi(vg(mg({},e),{register:!1,element:Tn(s)}),d)),f=Qd(c);return Te(i,()=>c.id=i),bs(s,d=>c.element=d),Te(o,()=>c.accept=o,void 0,ft),Te(t,()=>c.collisionDetector=t??Ag),Te(n,()=>n&&(c.data=n)),Te(r,()=>c.disabled=r===!0),Te(a,()=>c.type=a),{droppable:f,get isDropTarget(){return f.isDropTarget},ref:k.useCallback(d=>{var l,u;!d&&((l=c.element)!=null&&l.isConnected)&&!((u=c.manager)!=null&&u.dragOperation.status.idle)||(c.element=d??void 0)},[c])}}const uu=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},fu=k.createContext(void 0);function hu(e,t){const n=k.useContext(fu),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function _o({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Se.usePublisherTheme(),[o,a]=k.useState(void 0),c=k.useRef(!1),f=()=>{c.current||o===void 0||(a(void 0),o!==e&&r(o))};hu(o!==void 0&&o!==e,()=>(f(),!0));const d=()=>{c.current=!1,a(e)};if(o===void 0){const l=e==="",u=l&&s;return m.jsx($.Box,{component:"button",type:"button",className:u?"builder-affordance":void 0,onClick:d,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),d())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...l&&{fontStyle:"italic",opacity:u?0:.6}},uu(i)],children:l?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:l=>l.target.select(),onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!l.nativeEvent.isComposing?f():l.key==="Escape"&&(c.current=!0,a(void 0))},onBlur:f,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Bg=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Fg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},pu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gu=e=>`gap.${e}`,zg=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),c=o===0||i.break===!0||r+a>t;c&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),c&&(r=0),n.push(pu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Wg=Object.create,mu=Object.defineProperty,Ng=Object.defineProperties,Gg=Object.getOwnPropertyDescriptor,Ug=Object.getOwnPropertyDescriptors,Us=Object.getOwnPropertySymbols,vu=Object.prototype.hasOwnProperty,yu=Object.prototype.propertyIsEnumerable,Hg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Gr=e=>{throw TypeError(e)},ko=(e,t,n)=>t in e?mu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ki=(e,t)=>{for(var n in t||(t={}))vu.call(t,n)&&ko(e,n,t[n]);if(Us)for(var n of Us(t))yu.call(t,n)&&ko(e,n,t[n]);return e},Si=(e,t)=>Ng(e,Ug(t)),Vg=(e,t)=>{var n={};for(var r in e)vu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Us)for(var r of Us(e))t.indexOf(r)<0&&yu.call(e,r)&&(n[r]=e[r]);return n},Kg=e=>{var t;return[,,,Wg((t=void 0)!=null?t:null)]},bu=["class","method","getter","setter","accessor","field","value","get","set"],ur=e=>e!==void 0&&typeof e!="function"?Gr("Function expected"):e,qg=(e,t,n,r,s)=>({kind:bu[e],name:t,metadata:r,addInitializer:i=>n._?Gr("Already initialized"):s.push(ur(i||null))}),Yg=(e,t)=>ko(t,Hg("metadata"),e[3]),rs=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},xu=(e,t,n,r,s,i)=>{for(var o,a,c,f,d,l=t&7,u=!1,h=!1,p=e.length+1,v=bu[l+5],x=e[p-1]=[],_=e[p]||(e[p]=[]),g=(s=s.prototype,Gg({get[n](){return fr(this,i)},set[n](w){return Kt(this,i,w)}},n)),y=r.length-1;y>=0;y--)f=qg(l,n,c={},e[3],_),f.static=u,f.private=h,d=f.access={has:w=>n in w},d.get=w=>w[n],d.set=(w,b)=>w[n]=b,a=(0,r[y])({get:g.get,set:g.set},f),c._=1,a===void 0?ur(a)&&(g[v]=a):typeof a!="object"||a===null?Gr("Object expected"):(ur(o=a.get)&&(g.get=o),ur(o=a.set)&&(g.set=o),ur(o=a.init)&&x.unshift(o));return g&&mu(s,n,g),s},wu=(e,t,n)=>t.has(e)||Gr("Cannot "+n),fr=(e,t,n)=>(wu(e,t,"read from private field"),t.get(e)),Qn=(e,t,n)=>t.has(e)?Gr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kt=(e,t,n,r)=>(wu(e,t,"write to private field"),t.set(e,n),n);function Yt(e){return e instanceof Ta||e instanceof $u}var ss=10,Xg=class extends qe{constructor(e){super(e);const t=dt(()=>{const{dragOperation:r}=e;if(Cr(r.activatorEvent)&&Yt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Wr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!Cr(r.nativeEvent)||!Yt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:c}=s,{by:f}=r;if(!f)return;const d=Qg(f),{source:l,target:u}=i,{center:h}=i.shape.current,p=[],v=[];Ce(()=>{for(const b of c.droppables){const{id:T}=b;if(!b.accepts(l)||T===u?.id&&Yt(b)||!b.element)continue;let C=b.shape;const M=new yt(b.element,{getBoundingClientRect:E=>Tr(E,void 0,.2)});!M.height||!M.width||(d=="down"&&h.y+ss<M.center.y||d=="up"&&h.y-ss>M.center.y||d=="left"&&h.x-ss>M.center.x||d=="right"&&h.x+ss<M.center.x)&&(p.push(b),b.shape=M,v.push(()=>b.shape=C))}}),r.preventDefault(),a.disable();const x=a.computeCollisions(p,yp);Ce(()=>v.forEach(b=>b()));const[_]=x;if(!_)return;const{id:g}=_,{index:y,group:w}=l.sortable;o.setDropTarget(g).then(()=>{const{source:b,target:T,shape:C}=i;if(!b||!Yt(b)||!C)return;const{index:M,group:E,target:O}=b.sortable,A=y!==M||w!==E,j=A?O:T?.element;if(!j)return;vd(j);const L=new yt(j);if(!L)return;const N=bt.delta(L,bt.from(C.current.boundingRectangle),b.alignment);o.move({by:N}),A?o.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Qg(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var Zg=Object.defineProperty,Jg=Object.defineProperties,em=Object.getOwnPropertyDescriptors,cl=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,nm=Object.prototype.propertyIsEnumerable,dl=(e,t,n)=>t in e?Zg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,cn=(e,t)=>{for(var n in t||(t={}))tm.call(t,n)&&dl(e,n,t[n]);if(cl)for(var n of cl(t))nm.call(t,n)&&dl(e,n,t[n]);return e},dn=(e,t)=>Jg(e,em(t));function rm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function is(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function $i(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sm(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>c(b,i.id)),w=e.findIndex(b=>c(b,o.id));if(y===-1||w===-1){if($i(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==y)return n(e,y,b)}return n(e,y,w)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[y,w]of f)if(d===-1&&(d=w.findIndex(b=>c(b,i.id)),d!==-1&&(l=y)),u===-1&&(u=w.findIndex(b=>c(b,o.id)),u!==-1&&(h=y)),d!==-1&&u!==-1)break;if(d===-1&&$i(i)){const y=i.initialGroup==null?void 0:is(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:is(e,i.group),T=i.index;if(y==null||b==null||y===b&&w===T)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return dn(cn({},e),{[y]:n(e[y],w,T)});const C=e[y][w];return dn(cn({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,v=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const y=is(e,o.id);if(y!=null){const w=o.shape&&v.y>o.shape.center.y?e[y].length:0;h=y,u=w}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&$i(i)){const y=i.group==null?void 0:is(e,i.group),w=i.group!=null&&y!==l,b=i.index!==d;if(w||b){const T=i.group==null?l:y;if(T!=null){if(l===T)return dn(cn({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return dn(cn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return dn(cn({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return dn(cn({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function im(e,t){return sm(e,t,rm)}function ul(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function fl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var hl="__default__",om=class extends qe{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof Ta){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Yt(o)||!Yt(a)||o.sortable===a.sortable)return;const c=t(),f=ul(c),d=o.sortable.group===a.sortable.group,l=c.get(o.sortable.group),u=d?l:c.get(a.sortable.group);!l||!u||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const v=t();if(fl(f,c,v))return;const x=o.sortable.element,_=a.sortable.element;if(!_||!x||!d&&a.id===o.sortable.group)return;const g=os(l),y=d?g:os(u),w=(h=o.sortable.group)!=null?h:hl,b=(p=a.sortable.group)!=null?p:hl,T={[w]:g,[b]:y},C=im(T,r);if(T===C)return;const M=C[b].indexOf(o.sortable),E=C[b].indexOf(a.sortable);s.collisionObserver.disable(),pl(x,M,_,E),Ce(()=>{for(const[O,A]of C[w].entries())A.index=O;if(!d)for(const[O,A]of C[b].entries())A.group=a.sortable.group,A.index=O}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Yt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),c=ul(a),f=a.get(o.sortable.initialGroup);f&&s.renderer.rendering.then(()=>{const d=t();if(fl(c,a,d))return;const l=os(f),u=os(f,lm),h=o.sortable.element,p=u.indexOf(o.sortable),v=l[p],x=v?.element;!v||!x||!h||(pl(h,v.index,x,o.index),Ce(()=>{for(const _ of a.values()){const g=Array.from(_).values();for(const y of g)y.index=y.initialIndex,y.group=y.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function pl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function am(e,t){return e.index-t.index}function lm(e,t){return e.initialIndex-t.initialIndex}function os(e,t=am){return Array.from(e).sort(t)}var gl=[Xg,om],_u={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ml(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var as=new th,ku,Su,Rt,Sa,hr,pr,$a,bn;Su=[re],ku=[re];var li=class{constructor(e,t){Qn(this,Sa,rs(Rt,8,this)),rs(Rt,11,this),Qn(this,hr),Qn(this,pr),Qn(this,$a,rs(Rt,12,this)),rs(Rt,15,this),Qn(this,bn),this.register=()=>(Ce(()=>{var p,v;(p=this.manager)==null||p.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Ce(()=>{var p,v;(p=this.manager)==null||p.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Ce(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:c,transition:f=_u,plugins:d}=n,l=Vg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=gt(d,gl),h=ml(s);this.droppable=new Ta(Si(ki({},l),{disabled:h.droppable}),t,this),this.draggable=new $u(Si(ki({},l),{disabled:h.draggable,plugins:u,effects:()=>[()=>{var p,v,x;const _=(p=this.manager)==null?void 0:p.dragOperation.status;_?.initializing&&this.id===((x=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:x.id)&&as.clear(this.manager),_?.dragging&&as.set(this.manager,this.id,ne(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:v,manager:x}=this,_=fr(this,pr),g=fr(this,hr);(p!==_||v!==g)&&(Kt(this,pr,p),Kt(this,hr,v),this.animate())},()=>{var p,v;const{target:x}=this,{isDragSource:_}=this.draggable;((v=(p=this.draggable.pluginConfig(ga))==null?void 0:p.feedback)!=null?v:"default")==="move"&&_&&(this.droppable.disabled=!x)},...r()],type:c,sensors:a}),t,this),Kt(this,bn,l.element),this.manager=t,this.index=o,Kt(this,pr,o),this.group=i,Kt(this,hr,i),this.type=c,this.transition=f}get initialIndex(){var e,t;return(t=(e=as.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=as.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ne(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const d of s.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=_t(s),c=Ja(s,a,!1),f=Ja(s,a);if(o.x||o.y){const d=aa(st(s))?Si(ki({},t),{duration:0}):t;yd({element:s,keyframes:{translate:[`${c.x+o.x}px ${c.y+o.y}px ${c.z}`,`${f.x}px ${f.y}px ${f.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Ce(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ce(()=>{const t=fr(this,bn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Kt(this,bn,e)})}get element(){var e,t;const n=fr(this,bn);if(n)return(t=(e=no.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=gt(e,gl)}set disabled(e){const t=ml(e);Ce(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ce(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??bd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Ce(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Rt=Kg();Sa=new WeakMap;hr=new WeakMap;pr=new WeakMap;$a=new WeakMap;bn=new WeakMap;xu(Rt,4,"index",Su,li,Sa);xu(Rt,4,"group",ku,li,$a);Yg(Rt,li);var $u=class extends ii{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Ta=class extends oi{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,vl=Object.getOwnPropertySymbols,fm=Object.prototype.hasOwnProperty,hm=Object.prototype.propertyIsEnumerable,yl=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||(t={}))fm.call(t,n)&&yl(e,n,t[n]);if(vl)for(var n of vl(t))hm.call(t,n)&&yl(e,n,t[n]);return e},pm=(e,t)=>dm(e,um(t));function gm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:c,group:f,disabled:d,modifiers:l,sensors:u,target:h,type:p,plugins:v}=e,x=Ti(Ti({},_u),e.transition),_=tu(y=>new li(pm(Ti({},e),{transition:x,register:!1,handle:Tn(a),element:Tn(o),target:Tn(h)}),y)),g=Qd(_,mm);return Te(s,()=>_.id=s),Un(()=>{Ce(()=>{_.group=f,_.index=c})},[_,f,c]),Te(p,()=>_.type=p),Te(t,()=>_.accept=t,void 0,ft),Te(i,()=>i&&(_.data=i)),Te(c,()=>{var y;(y=_.manager)!=null&&y.dragOperation.status.idle&&x?.idle&&_.refreshShape()},fg),bs(a,y=>_.handle=y),bs(o,y=>_.element=y),bs(h,y=>_.target=y),Te(d,()=>_.disabled=d??!1,void 0,ft),Te(u,()=>_.sensors=u,void 0,ft),Te(n,()=>_.collisionDetector=n),Te(r,()=>_.collisionPriority=r),Te(v,()=>_.plugins=v,void 0,ft),Te(x,()=>_.transition=x,void 0,ft),Te(l,()=>_.modifiers=l,void 0,ft),Te(e.alignment,()=>_.alignment=e.alignment),{sortable:g,get isDragging(){return g.isDragging},get isDropping(){return g.isDropping},get isDragSource(){return g.isDragSource},get isDropTarget(){return g.isDropTarget},handleRef:k.useCallback(y=>{_.handle=y??void 0},[_]),ref:k.useCallback(y=>{var w,b;!y&&((w=_.element)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.element=y??void 0)},[_]),sourceRef:k.useCallback(y=>{var w,b;!y&&((w=_.source)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.source=y??void 0)},[_]),targetRef:k.useCallback(y=>{var w,b;!y&&((w=_.target)!=null&&w.isConnected)&&!((b=_.manager)!=null&&b.dragOperation.status.idle)||(_.target=y??void 0)},[_])}}function mm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const So="tile",Tu="gap",vm=[vo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Eu}], ${ym}`)!==null||(vo.defaults.preventActivation?.(e,t)??!1)}),Gd],Eu="data-no-drag",ym=".malloy-render, .malloy-table",bm=e=>[...e,ga.configure({feedback:"clone"})];function xm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=gm({id:e,index:t,type:So,accept:So,collisionDetector:ca,plugins:bm});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function wm({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Lg({id:e,type:Tu,accept:So,collisionDetector:ca,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cu=e=>e.ok===!1,Ae=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Hn=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>Ae(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Ae(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Ae(e,"VIEW","subQueryDefList"),defDimension:e=>Ae(e,"defList","DIMENSION"),exploreProperties:e=>Ae(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Ae(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Ae(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Ae(e,"WHERE","filterClauseList"),givenDef:e=>Ae(e,"givenNameDef"),givenStatement:e=>Ae(e,"GIVEN","givenDefList"),importStatement:e=>Ae(e,"IMPORT","importURL"),vArrow:e=>Ae(e,"ARROW","vExpr","segExpr"),segRefine:e=>Ae(e,"PLUS","segExpr"),segOps:e=>Ae(e,"queryProperties"),segField:e=>Ae(e,"fieldPath")&&!Ae(e,"segExpr"),segParen:e=>Ae(e,"OPAREN","CPAREN","vExpr"),compare:e=>Ae(e,"fieldExpr","compareOp"),givenRef:e=>Ae(e,"GIVEN_REF")};function _m(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function km(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
- `&&t.push(n+1);return t}function Ou(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!Hn(s))continue;const i=Ie(s,"docAnnotations");if(i)for(const o of Bt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class Du{constructor(t){this.text=t,this.map=_m(t),this.lineStarts=km(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!Hn(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function Ur(e,t,n=[]){Hn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Ur(e.getChild(r),t,n);return n}const Sm=e=>Ae(e,"OCURLY","CCURLY");function jr(e,t){const n=[],r=s=>{if(Hn(s)){if(t(s)){n.push(s);return}if(!Sm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ie=(e,t)=>e[t]?.call(e),Bt=(e,t)=>e[t]?.call(e)??[];function $m(e,t){if(!ke.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!ke.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Mu(e,t){const n=e.positioned(t);if(!n)return;const r=Ie(t,"filterClauseList"),s=[];for(const i of r?Bt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=Ur(i,ke.givenRef).map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.replace(/^\$/,""));s.push({...o,givens:a,binding:$m(e,i)})}return{...n,clauses:s}}function $o(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const f of jr(t,ke.queryStatement)){const d=e.positioned(f);d&&r.push(d);const l=Ie(f,"whereStatement");if(l&&ke.whereStatement(l)){const u=Mu(e,l);u&&s.push(u)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
- `),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:c,oneLine:a}}function Ea(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function Tm(e,t){const n=Ie(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ie(n,"queryProperties"),i=s&&$o(e,s);return i?{kind:"inline",stage:i,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ke.segField(n)){const s=e.span(n);return s?{kind:"reference",from:e.text.slice(s.start,s.end),fromSpan:s}:{kind:"unsupported",why:"an unreadable name"}}if(ke.segRefine(n)){const s=Bt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const u=Bt(a,"segExpr");if(u.some(h=>ke.segOps(h)||ke.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=u[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const c=e.span(i);if(!c||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const u=e.span(n);return u?{kind:"reference",from:e.text.slice(u.start,u.end),fromSpan:u}:{kind:"unsupported",why:"an unreadable refinement"}}const f=e.text.slice(c.start,c.end),d=Ie(o,"queryProperties"),l=d&&$o(e,d);return l?{kind:"reference",from:f,fromSpan:c,refinement:l}:{kind:"reference",from:f,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function Em(e,t){const n=[];for(const r of jr(t,ke.defExploreQuery)){const s=e.span(r),i=Ie(r,"subQueryDefList");if(!s||!i)continue;const o=Bt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ie(r,"VIEW"));for(const c of o){const f=e.span(c),d=Ie(c,"exploreQueryNameDef"),l=e.text_(d),u=Ie(c,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:s,tags:Ea(e,s,a?.start??f.start),siblings:o.length,body:Tm(e,u)})}}return n}function Cm(e,t){const n=[];for(const r of jr(t,ke.defDimension)){const s=e.span(r),i=Ie(r,"defList");if(!s||!i)continue;const o=e.terminal(Ie(r,"DIMENSION"));for(const a of Bt(i,"fieldDef")){const c=e.span(a),f=e.text_(Ie(a,"fieldNameDef"))?.trim(),d=e.text_(Ie(a,"fieldExpr"))?.trim();!c||!f||d===void 0||n.push({name:f,expression:d,span:c,line:e.line(c.start),statement:s,tags:Ea(e,s,o?.start??c.start)})}}return n}function Om(e,t){const n=[];for(const r of Ur(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ie(r,"sourceNameDef")),o=Ie(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),c=a?e.text.slice(a.start,a.end):"",f=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(c)?.[1]??"").trim(),d=jr(o,ke.exploreProperties)[0],l=d&&$o(e,d),u={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(d)for(const p of jr(d,ke.whereStatement)){const v=Mu(e,p);v&&h.push(v)}n.push({name:i,base:f,span:s,line:e.line(s.start),statement:u,...l?{properties:l}:{},views:d?Em(e,d):[],dimensions:d?Cm(e,d):[],wheres:h})}return n}function Dm(e,t){const n=[];for(const r of Ur(t,ke.givenStatement)){const s=e.terminal(Ie(r,"GIVEN")),i=Ie(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Bt(i,"givenDef"):[]){const c=e.span(a),f=e.span(Ie(a,"givenNameDef")),d=f&&e.text.slice(f.start,f.end);if(!c||!f||!d)continue;const l={start:f.start,end:c.end},u=e.line(l.start);n.push({name:d,declaration:e.text.slice(l.start,l.end),span:l,line:u,statement:{start:e.lineStarts[u],end:l.end},tags:Ea(e,c,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function Mm(e,t){const n=[];for(const r of Ur(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ie(r,"importURL"));if(!s||i===void 0)continue;const o=Ie(r,"importSelect"),a=o?Bt(o,"importItem").map(c=>e.text_(c)).filter(c=>c!==void 0).map(c=>c.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Iu(e){let t;try{t=await Ca(e,"file://dashboard-builder.malloy")}catch(u){return{ok:!1,reason:`Malloy could not read this file: ${u}`}}const n=t.problems.filter(u=>u.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!Hn(s)||typeof s.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new Du(e),c=Im(a,i);a.commentLines=c.lines;const f=e.split(`
70
- `),d=u=>c.lines.has(u);a.proseLines=pe.markdownLines(f,d),a.blocks=pe.blockSpans(f,d).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=Om(a,s);return l.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Mm(a,s),sources:l,givens:Dm(a,s),textBlocks:Pm(a,i),modelNotes:Ou(a,s),trailingComment:u=>c.trailing.get(u),comments:c.all,commentLine:u=>c.lines.has(u),proseLine:u=>a.proseLines.has(u),commentIn:u=>c.all.find(h=>h.start>=u.start&&h.start<u.end),blockStart:u=>jm(a,c.lines,u)}}}async function Ca(e,t){const{MalloyTranslator:n}=await S.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Im(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const d of t.getTokens?.()??[]){const l=i?.getSymbolicName(d.type);if(l!=="COMMENT_TO_EOL"&&l!=="BLOCK_COMMENT")continue;const u=e.utf16(d.startIndex);let h=e.utf16(d.stopIndex+1);if(!(u===void 0||h===void 0||h<u)){for(;h>u&&(e.text[h-1]===`
71
- `||e.text[h-1]==="\r");)h--;s.push({start:u,end:h})}}const o=[...s].sort((d,l)=>d.start-l.start);let a="",c=0;for(const d of o)a+=e.text.slice(c,Math.max(c,d.start)),a+=e.text.slice(Math.max(c,d.start),Math.max(c,d.end)).replace(/[^\n\r]/g," "),c=Math.max(c,d.end);a+=e.text.slice(c);const f=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of s){const l=e.line(d.start),u=e.line(d.end-1);for(let v=l;v<=u;v++)f(v).trim()===""&&r.add(v);const h=a.slice(e.lineStarts[l],d.start).trim(),p=a.slice(d.end,e.lineStarts[u+1]??a.length).trim();h!==""&&p===""&&n.set(u,d)}return{trailing:n,lines:r,all:s}}function jm(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,c])=>c===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function Pm(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const c=pe.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!c)continue;const f=[];let d=a+1;for(;s(n[d]??n[a])==="BLOCK_ANNOTATION_TEXT";d++)f.push(i(n[d]));const l=n[d];if(!l||s(l)!=="BLOCK_ANNOTATION_END")continue;const u=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(l.stopIndex+1)??e.text.length,p=c.name===void 0&&c.rest?[`${c.rest}
72
- `]:[];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 Rg(e,t="hidden"){return ae(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Ag(n,r.registry.droppables),o=[],i=Mp(n),{remove:a}=i;return Lg(s,i,o),Bg(i,t),i.remove=()=>{o.forEach(l=>l()),a.call(i)},i})}function Ag(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${rs}${yi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Lg(e,t,n){for(const[r,s]of e){if(!r.element)continue;const o=`[${s}]`,i=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(s),!i)continue;const a=r.element;r.proxy=i,i.removeAttribute(s),pi.set(a,i),n.push(()=>{pi.delete(a),r.proxy=void 0})}}function Bg(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Js,t)}function du(e,t){return e===t?!0:Wn(e)===Wn(t)}function wl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&dn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>jn(t))}function _i(e){return e.tagName==="TR"}function Fg(e,t,n){const r=new MutationObserver(s=>{let o=!1;for(const i of s){if(i.target!==e){o=!0;continue}if(i.type!=="attributes")continue;const a=i.attributeName;if(a.startsWith("aria-")||Dg.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(Ar(e)&&Ar(t)){const u=e.style;for(const c of Array.from(t.style))u.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(u)){if(Pg.includes(c)||c.startsWith(Qe))continue;const d=u.getPropertyValue(c);t.style.setProperty(c,d)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}o&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Wg(e,t,n){const r=new MutationObserver(s=>{for(const o of s)if(o.addedNodes.length!==0)for(const i of Array.from(o.addedNodes)){if(i.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),jn(n);return}if(i.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),jn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),jn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Ng(e){return new ResizeObserver(()=>{var t,n,r;const s=new Et(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),o=(t=e.transformOrigin)!=null?t:{x:1,y:1},i=(e.width-s.width)*o.x+e.delta.x,a=(e.height-s.height)*o.y+e.delta.y,l=Fd();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+i+l.x},Qe),(n=e.getElementMutationObserver())==null||n.takeRecords(),_i(e.element)&&_i(e.placeholder)){const g=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(g.map(x=>x.style.width));for(const[x,p]of g.entries()){const v=w[x];p.style.width=`${v.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+i+l.x+u.x,d=e.top+a+l.y+u.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,y=e.frameTransform;e.dragOperation.shape=new Ct(c*y.scaleX+y.x,d*y.scaleY+y.y,f*y.scaleX,h*y.scaleY)})}var zg=250,Gg="ease";function Hg(e){var t,n,r,s;const{animation:o}=e;if(typeof o=="function"){const p=o({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(p).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:i=zg,easing:a=Gg}=o??{};jn(e.feedbackElement);const[,l]=(t=Ad(e.feedbackElement,p=>"translate"in p))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:du(e.feedbackElement,u)?null:void 0},d=new Et(e.feedbackElement,c),f=(r=qr(It(e.feedbackElement).translate))!=null?r:e.translate,h=new Et(u,c),y=Ct.delta(d,h,e.alignment),g={x:f.x-y.x,y:f.y-y.y},w=Math.round(d.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},x=Math.round(d.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Qe),e.feedbackElement.setAttribute(wi,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),Xd({element:e.feedbackElement,keyframes:Sa(Kr(Kr({},w),x),{translate:[`${f.x}px ${f.y}px 0`,`${g.x}px ${g.y}px 0`]}),options:{duration:ba(ft(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?i:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(wi),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var uu,ki,Vr,Ea,Ms,fu,hu,Gn=class extends(ki=et,uu=[le],ki){constructor(t,n){super(t,n),ze(this,Ms),ze(this,Ea,Ve(Vr,8,this)),Ve(Vr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(yo),s=r?.register(jg);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(un(this,Ms,fu).bind(this,r)),this.registerEffect(un(this,Ms,hu))}};Vr=tr(ki);Ea=new WeakMap;Ms=new WeakSet;fu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Us(t);if(n)return e.addRoot(n)};hu=function(){var e,t,n,r,s,o,i;const{state:a,manager:l,options:u}=this,{dragOperation:c}=l,{position:d,source:f,status:h}=c;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:y}=f,g=f.pluginConfig(Gn),w=(t=(e=g?.feedback)!=null?e:u?.feedback)!=null?t:"default",x=typeof w=="function"?w(f,l):w;if(!y||x==="none"||!h.initialized||h.initializing)return;const{initial:p}=a,v=(n=this.overlay)!=null?n:y,_=Nn(v),b=Nn(y),E=!du(y,v),T=new Et(y,{frameTransform:E?b:null,ignoreTransforms:!E}),M={x:b.scaleX/_.scaleX,y:b.scaleY/_.scaleY};let{width:O,height:C,top:A,left:R}=T;E&&(O=O/M.x,C=C/M.y);const B=new cg(v),G=It(y),{transition:N,translate:X,boxSizing:j,paddingBlockStart:z,paddingBlockEnd:D,paddingInlineStart:I,paddingInlineEnd:L,borderInlineStartWidth:q,borderInlineEndWidth:H,borderBlockStartWidth:K,borderBlockEndWidth:te}=G,ye=N.split(",").filter(ne=>!/^\s*(transform|translate|scale)\b/.test(ne)).join(","),_e=vo(G),re=G.transform,De=x==="clone",ge=j==="content-box",ve=ge?parseInt(I)+parseInt(L)+parseInt(q)+parseInt(H):0,Ge=ge?parseInt(z)+parseInt(D)+parseInt(K)+parseInt(te):0,Z=x!=="move"&&!this.overlay?Rg(f,De?"clone":"hidden"):null,Xe=ae(()=>Ur(l.dragOperation.activatorEvent));if(!p.translate){if(this.overlay&&_e)p.translate={x:_e.x,y:_e.y};else if(X!=="none"){const ne=qr(X);ne&&(p.translate=ne)}}if(!p.transformOrigin){const ne=ae(()=>d.current),oe=R+((r=_e?.x)!=null?r:0),Ue=A+((s=_e?.y)!=null?s:0);p.transformOrigin={x:(ne.x-oe*_.scaleX-_.x)/(O*_.scaleX),y:(ne.y-Ue*_.scaleY-_.y)/(C*_.scaleY)}}const{transformOrigin:ke}=p,ue=A*_.scaleY+_.y,Ce=R*_.scaleX+_.x;if(!p.coordinates&&(p.coordinates={x:Ce,y:ue},M.x!==1||M.y!==1)){const{scaleX:ne,scaleY:oe}=b,{x:Ue,y:bt}=ke;p.coordinates.x+=(O*ne-O)*Ue,p.coordinates.y+=(C*oe-C)*bt}p.dimensions||(p.dimensions={width:O,height:C}),p.frameTransform||(p.frameTransform=_);const Ae={x:p.coordinates.x-Ce,y:p.coordinates.y-ue},ie={width:(p.dimensions.width*p.frameTransform.scaleX-O*_.scaleX)*ke.x,height:(p.dimensions.height*p.frameTransform.scaleY-C*_.scaleY)*ke.y},qe={x:Ae.x/_.scaleX+ie.width,y:Ae.y/_.scaleY+ie.height},Ye={left:R+qe.x,top:A+qe.y};v.setAttribute(Tt,"true");const P=ae(()=>c.transform),F=(o=p.translate)!=null?o:{x:0,y:0},U=P.x*_.scaleX+F.x,Y=P.y*_.scaleY+F.y,Se=Fd();B.set({width:O-ve,height:C-Ge,top:Ye.top+Se.y,left:Ye.left+Se.x,translate:`${U}px ${Y}px 0`,transform:this.overlay?"none":re,transition:ye?`${ye}, translate 0ms linear`:"translate 0ms linear",scale:E?`${M.x} ${M.y}`:"","transform-origin":`${ke.x*100}% ${ke.y*100}%`},Qe),Z&&(y.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(y)),mi(v)&&(v.hasAttribute("popover")||v.setAttribute("popover","manual"),jn(v),v.addEventListener("beforetoggle",wl));let we,ht,W;const Q=Ng({placeholder:Z,element:y,feedbackElement:v,frameTransform:_,transformOrigin:ke,width:O,height:C,top:A,left:R,widthOffset:ve,heightOffset:Ge,delta:qe,styles:B,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>we,getSavedCellWidths:()=>W,setSavedCellWidths:ne=>{W=ne}}),Le=new Et(v);ae(()=>c.shape=Le);const Be=ft(v),lt=ne=>{this.manager.actions.stop({event:ne})},he=ba(Be);Xe&&Be.addEventListener("resize",lt),ae(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&(Q.observe(Z),we=Fg(y,Z,De),ht=Wg(y,Z,v));const tt=(i=l.dragOperation.source)==null?void 0:i.id,V=()=>{var ne;if(!Xe||tt==null)return;const oe=l.registry.draggables.get(tt),Ue=(ne=oe?.handle)!=null?ne:oe?.element;Kt(Ue)&&Ue.focus()},se=()=>{we?.disconnect(),ht?.disconnect(),Q.disconnect(),Be.removeEventListener("resize",lt),mi(v)&&(v.removeEventListener("beforetoggle",wl),v.removeAttribute("popover")),v.removeAttribute(Tt),B.reset();const ne=()=>{var oe;if(W&&_i(y)){const or=Array.from(y.cells);for(const[mn,vn]of or.entries())vn.style.width=(oe=W[mn])!=null?oe:""}f.status="idle";const Ue=a.current.translate!=null,bt=c.status.dragging;Z&&(!bt&&Ue||Z.parentElement!==v.parentElement)&&v.isConnected&&Z.replaceWith(v),Z?.remove()};v===this.overlay?setTimeout(ne,0):ne()},Oe=u?.dropAnimation,$e=this,Yt=Zr(()=>{var ne,oe,Ue;const{transform:bt,status:or}=c;if(!(!bt.x&&!bt.y&&!a.current.translate)&&or.dragging){const mn=(ne=p.translate)!=null?ne:{x:0,y:0},vn={x:bt.x/_.scaleX+mn.x,y:bt.y/_.scaleY+mn.y},qa=a.current.translate,Wf=ae(()=>c.modifiers),ko=ae(()=>{var ar;return(ar=c.shape)==null?void 0:ar.current}),ir=u?.keyboardTransition,Ua=Xe&&!he&&ir!==null?`${(oe=ir?.duration)!=null?oe:250}ms ${(Ue=ir?.easing)!=null?Ue:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(B.set({transition:ye?`${ye}, translate ${Ua}`:`translate ${Ua}`,translate:`${vn.x}px ${vn.y}px 0`},Qe),we?.takeRecords(),ko&&ko!==Le&&qa&&!Wf.length){const ar=gt.delta(vn,qa);c.shape=Ct.from(ko.boundingRectangle).translate(ar.x*_.scaleX,ar.y*_.scaleY)}else c.shape=new Et(v);a.current.translate=vn}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ne=g?.dropAnimation!==void 0?g.dropAnimation:$e.dropAnimation!==void 0?$e.dropAnimation:Oe;let oe=a.current.translate;const Ue=oe!=null;if(!oe&&y!==v&&(oe={x:0,y:0}),!oe||ne===null){se();return}l.renderer.rendering.then(()=>{Hg({source:f,element:y,feedbackElement:v,placeholder:Z,translate:oe,moved:Ue,transition:N,alignment:f.alignment,styles:B,animation:ne??void 0,getElementMutationObserver:()=>we,cleanup:se,restoreFocus:V})})}});return()=>{se(),Yt()}};xt(Vr,4,"overlay",uu,Gn,Ea);gn(Vr,Gn);Gn.configure=es(Gn);var Ca=Gn,cr=!0,qg=!1,pu,gu,mu,vu,zt,Oa,Ma;vu=(mu=[le],mt.Forward),gu=(pu=[le],mt.Reverse);var Xr=class{constructor(){ze(this,Oa,Ve(zt,8,this,cr)),Ve(zt,11,this),ze(this,Ma,Ve(zt,12,this,cr)),Ve(zt,15,this)}isLocked(e){return e===mt.Idle?!1:e==null?this[mt.Forward]===cr&&this[mt.Reverse]===cr:this[e]===cr}unlock(e){e!==mt.Idle&&(this[e]=qg)}};zt=tr(null);Oa=new WeakMap;Ma=new WeakMap;xt(zt,4,vu,mu,Xr,Oa);xt(zt,4,gu,pu,Xr,Ma);gn(zt,Xr);var Ug=[mt.Forward,mt.Reverse],_l=class{constructor(){this.x=new Xr,this.y=new Xr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Kg=class extends et{constructor(e){super(e);const t=qn(new _l);let n=null;this.signal=t,yt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new _l;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:kl(s.x,n.x),y:kl(s.y,n.y)},i=t.peek();Re(()=>{for(const a of Uc)for(const l of Ug)o[a]===l&&i[a].unlock(l);t.value=i})}n=s})}get current(){return this.signal.peek()}};function kl(e,t){return Math.sign(e-t)}var yu,Si,Yr,Ia,Wt,$i,ss=class extends(Si=ts,yu=[le],Si){constructor(e){super(e),ze(this,Ia,Ve(Yr,8,this,!1)),Ve(Yr,11,this),ze(this,Wt),ze(this,$i,()=>{if(!xe(this,Wt))return;const{element:o,by:i}=xe(this,Wt);i.y&&(o.scrollTop+=i.y),i.x&&(o.scrollLeft+=i.x)}),this.scroll=(o,i)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return st(this,Wt,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=o??{},f=d?{x:Sl(d.x),y:Sl(d.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const y of l){const g=Gp(y,d);if(g.x||g.y){const{speed:w,direction:x}=eg(y,c,f,i?.acceleration,i?.threshold);if(h)for(const p of Uc)h[p].isLocked(x[p])&&(w[p]=0,x[p]=0);if(x.x||x.y){const{x:p,y:v}=d??x,_=p*w.x,b=v*w.y;if(_||b){const E=(a=xe(this,Wt))==null?void 0:a.by;if(this.autoScrolling&&E&&(E.x&&!_||E.y&&!b))continue;return st(this,Wt,{element:y,by:{x:_,y:b}}),Xs.schedule(xe(this,$i)),!0}}}}}return st(this,Wt,void 0),!1};let t=null,n=null;const r=ei(()=>{const{position:o,source:i}=e.dragOperation;if(!o)return null;const a=Wd(Us(i?.element),o.current);return a&&(t=a),a??t}),s=ei(()=>{const o=r.value,{documentElement:i}=Jn(o);if(!o||o===i){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=vi(l,{excludeElement:!1});return n=u,u}}if(o){const a=vi(o,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},wt);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Kg(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Ur(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};Yr=tr(Si);Ia=new WeakMap;Wt=new WeakMap;$i=new WeakMap;xt(Yr,4,"autoScrolling",yu,ss,Ia);gn(Yr,ss);function Sl(e){return e>0?mt.Forward:e<0?mt.Reverse:mt.Idle}var Vg=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},Xg=new Vg(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Yg=10,Ti=class extends et{constructor(t,n){super(t,n);const r=t.registry.plugins.get(ss);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=yt(()=>{var s,o,i;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((o=this.options)==null?void 0:o.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(i=this.options)==null?void 0:i.threshold};if(r.scroll(void 0,u)){r.autoScrolling=!0;const d=setInterval(()=>Xg.schedule(()=>r.scroll(void 0,u)),Yg);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};Ti.configure=es(Ti);var xu=Ti,$l={capture:!0,passive:!0},kr,Qg=class extends ts{constructor(e){super(e),ze(this,kr),this.handleScroll=()=>{xe(this,kr)==null&&st(this,kr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),st(this,kr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=yt(()=>{var n,r,s;if(t.status.dragging){const i=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return i.addEventListener("scroll",this.handleScroll,$l),()=>{i.removeEventListener("scroll",this.handleScroll,$l)}}})}};kr=new WeakMap;var Zg="* { user-select: none !important; -webkit-user-select: none !important; }",Jg=class extends et{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(yo),n=t?.register(Zg);if(this.destroy=yt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Po(),document.addEventListener("selectionchange",Po,{capture:!0}),()=>{document.removeEventListener("selectionchange",Po,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Po(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Sr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),En,eo=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,En,[]),this.listeners=new Nd,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!dn(r.target)||s.disabled)return;const{keyboardCodes:i=Sr.keyboardCodes,preventActivation:a=Sr.preventActivation}=o??{};i.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,o))}}bind(t,n=this.options){return yt(()=>{var s;const o=(s=t.handle)!=null?s:t.element,i=a=>{Ur(a)&&this.handleSourceKeyDown(a,t,n)};if(o)return o.addEventListener("keydown",i),()=>{o.removeEventListener("keydown",i)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),Vd(s);const{center:o}=new Et(s);if(this.manager.actions.start({event:t,coordinates:{x:o.x,y:o.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Jn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];xe(this,En).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=Sr.keyboardCodes}=r??{};if(yn(t,[...s.end,...s.cancel])){t.preventDefault();const o=yn(t,s.cancel);this.handleEnd(t,o);return}yn(t,s.up)?this.handleMove("up",t):yn(t,s.down)&&this.handleMove("down",t),yn(t,s.left)?this.handleMove("left",t):yn(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:o}=this.manager.dragOperation,i=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:Sr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!o){switch(t){case"up":a={x:0,y:-l.y*i};break;case"down":a={x:0,y:l.y*i};break;case"left":a={x:-l.x*i,y:0};break;case"right":a={x:l.x*i,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(xu);t?.disabled===!1&&(t.disable(),xe(this,En).push(()=>{t.enable()}))}cleanup(){xe(this,En).forEach(t=>t()),st(this,En,[])}destroy(){this.cleanup(),this.listeners.clear()}};En=new WeakMap;eo.configure=es(eo);eo.defaults=Sr;var bu=eo;function yn(e,t){return t.includes(e.code)}var rn,em=class extends Sd{constructor(){super(...arguments),ze(this,rn)}onEvent(e){switch(e.type){case"pointerdown":st(this,rn,Fn(e));break;case"pointermove":if(!xe(this,rn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,rn).x,y:n-xe(this,rn).y},{tolerance:s}=this.options;if(s&&ci(r,s)){this.abort();return}ci(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){st(this,rn,void 0)}};rn=new WeakMap;var Cn,sn,tm=class extends Sd{constructor(){super(...arguments),ze(this,Cn),ze(this,sn)}onEvent(e){switch(e.type){case"pointerdown":st(this,sn,Fn(e)),st(this,Cn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!xe(this,sn))return;const{x:t,y:n}=Fn(e),r={x:t-xe(this,sn).x,y:n-xe(this,sn).y};ci(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){xe(this,Cn)&&(clearTimeout(xe(this,Cn)),st(this,sn,void 0),st(this,Cn,void 0))}};Cn=new WeakMap;sn=new WeakMap;var Pn=class{};Pn.Delay=tm;Pn.Distance=em;var Ei=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&dn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new Pn.Delay({value:250,tolerance:5})]:ug(s)&&!e.defaultPrevented?[new Pn.Delay({value:200,tolerance:0})]:[new Pn.Delay({value:200,tolerance:10}),new Pn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!dn(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Dp(r);return s===t.element?!1:!!s}}),On,to=class extends Bn{constructor(t,n){super(t),this.manager=t,this.options=n,ze(this,On,new Set),this.listeners=new Nd,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=Ei.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return yt(()=>{var s;const o=new AbortController,{signal:i}=o,a=u=>{dg(u)&&this.handlePointerDown(u,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(sm(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:i}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!dn(t.target)||n.disabled||nm(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Ei.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,i=Kt(o)&&o.draggable&&o.getAttribute("draggable")==="true",a=Nn(n.element),{x:l,y:u}=Fn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:u*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const d=new kp(c,g=>this.handleStart(n,g));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const f=hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:g=>this.handlePointerMove(g,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:i?this.handleCancel:hs,options:{capture:!0}}]),y=()=>{h(),this.initialCoordinates=void 0};xe(this,On).add(y)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const o=Fn(t),i=Nn(n.element);o.x=o.x*i.scaleX+i.x,o.y=o.y*i.scaleY+i.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=o,Xs.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Jn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=dn(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:hs,options:{passive:!1}},{type:"click",listener:hs},{type:"contextmenu",listener:hs},{type:"keydown",listener:this.handleKeyDown}]);xe(this,On).add(u)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},xe(this,On).forEach(n=>n()),xe(this,On).clear()}destroy(){this.cleanup(),this.listeners.clear()}};On=new WeakMap;to.configure=es(to);to.defaults=Ei;var Ci=to;function nm(e){return"sensor"in e}function hs(e){e.preventDefault()}function rm(){}var Tl=new WeakSet;function sm(e){!e||Tl.has(e)||(e.addEventListener("touchmove",rm,{capture:!1,passive:!1}),Tl.add(e))}var Rn={modifiers:[],plugins:[Og,xu,Ig,Ca,Jg],sensors:[Ci,bu]},wu=class extends Tp{constructor(e={}){const t=St(e.plugins,Rn.plugins),n=St(e.sensors,Rn.sensors),r=St(e.modifiers,Rn.modifiers);super(Sa(Kr({},e),{plugins:[Qg,ss,yo,...t],sensors:n,modifiers:r}))}},_u,ku,Oi,Gt,Da,Pa,xo=class extends(Oi=Ot,ku=[le],_u=[le],Oi){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o}=n,i=eu(n,["element","effects","handle"]);super(Kr({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(zr))!=null?l:[...u.sensors]).map(f=>{const h=f instanceof Bn?f:u.registry.register(f.plugin),y=f instanceof Bn?void 0:f.options;return h.bind(this,y)});return function(){d.forEach(h=>h())}}]},i),t),ze(this,Da,Ve(Gt,8,this)),Ve(Gt,11,this),ze(this,Pa,Ve(Gt,12,this)),Ve(Gt,15,this),this.element=r,this.handle=o}};Gt=tr(Oi);Da=new WeakMap;Pa=new WeakMap;xt(Gt,4,"handle",ku,xo,Da);xt(Gt,4,"element",_u,xo,Pa);gn(Gt,xo);var Su,$u,Mi,Ht,ja,jo,Tu,Eu,Br,Ra,bo=class extends(Mi=Mt,$u=[le],Su=[le],Mi){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=eu(n,["element","effects"]);const{collisionDetector:i=Yd}=o,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const f=new Et(d),h=ae(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=qn(!1);super(Sa(Kr({},o),{collisionDetector:i,effects:()=>[...s(),()=>{const{element:u,manager:c}=this;if(!c)return;const{dragOperation:d}=c,{source:f}=d;l.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const c=new zp(u,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),ze(this,Br),ze(this,ja,Ve(Ht,8,this)),Ve(Ht,11,this),ze(this,Ra,Ve(Ht,12,this)),Ve(Ht,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){st(this,Br,e,Eu)}get element(){var e;return(e=this.proxy)!=null?e:xe(this,Br,Tu)}};Ht=tr(Mi);ja=new WeakMap;Br=new WeakSet;Ra=new WeakMap;jo=xt(Ht,20,"#element",$u,Br,ja),Tu=jo.get,Eu=jo.set;xt(Ht,4,"proxy",Su,bo,Ra);gn(Ht,bo);function om(e){return e!=null&&typeof e=="object"&&"current"in e}function An(e){var t;if(e!=null)return om(e)?(t=e.current)!=null?t:void 0:e}var im=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",nr=im?S.useLayoutEffect:S.useEffect;function am(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Cu(e,t){const n=S.useRef(new Map),r=am();return nr(()=>{if(!e){n.current.clear();return}return yt(()=>{var s;let o=!1,i=!1;for(const a of n.current){const[l]=a,u=ae(()=>a[1]),c=e[l];u!==c&&(o=!0,n.current.set(l,c),i=(s=t?.(l,u,c))!=null?s:!1)}o&&(i?queueMicrotask(()=>Nf.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(s,o){const i=s[o];return n.current.set(o,i),i}}),[e])}function lm(e,t){e()}function xn(e){const t=S.useRef(e);return nr(()=>{t.current=e},[e]),t}function Pe(e,t,n=S.useEffect,r=Object.is){const s=S.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}function Is(e,t){const n=S.useRef(An(e));nr(()=>{const r=An(e);r!==n.current&&(n.current=r,t(r))})}var cm=Object.defineProperty,dm=Object.defineProperties,um=Object.getOwnPropertyDescriptors,no=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Mu=Object.prototype.propertyIsEnumerable,El=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fm=(e,t)=>{for(var n in t||(t={}))Ou.call(t,n)&&El(e,n,t[n]);if(no)for(var n of no(t))Mu.call(t,n)&&El(e,n,t[n]);return e},hm=(e,t)=>dm(e,um(t)),pm=(e,t)=>{var n={};for(var r in e)Ou.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&no)for(var r of no(e))t.indexOf(r)<0&&Mu.call(e,r)&&(n[r]=e[r]);return n},gm=new wu,Iu=S.createContext(gm),mm=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),s=S.useRef(null),o=S.useRef(null),i=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{o.current=l})),S.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return nr(()=>{var a;(a=o.current)==null||a.call(o),s.current=null},[e,n]),S.useImperativeHandle(t,()=>i),null})),Ro=[void 0,wt];function vm(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:i,onDragOver:a,onDragEnd:l}=t,u=pm(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:d,modifiers:f,sensors:h}=u,y=St(d,Rn.plugins),g=St(h,Rn.sensors),w=St(f,Rn.modifiers),x=xn(s),p=xn(o),v=xn(a),_=xn(i),b=xn(l),E=xn(r),T=ym(()=>{var M;return(M=u.manager)!=null?M:new wu(u)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:O}=c.current,{monitor:C}=T;T.renderer=M;const A=[C.addEventListener("beforedragstart",R=>{const B=x.current;B&&O(()=>B(R,T))}),C.addEventListener("dragstart",R=>{var B;return(B=p.current)==null?void 0:B.call(p,R,T)}),C.addEventListener("dragover",R=>{const B=v.current;B&&O(()=>B(R,T))}),C.addEventListener("dragmove",R=>{const B=_.current;B&&O(()=>B(R,T))}),C.addEventListener("dragend",R=>{const B=b.current;B&&O(()=>B(R,T))}),C.addEventListener("collision",R=>{var B;return(B=E.current)==null?void 0:B.call(E,R,T)})];return()=>A.forEach(R=>R())},[T]),Pe(y,()=>T&&(T.plugins=y),...Ro),Pe(g,()=>T&&(T.sensors=g),...Ro),Pe(w,()=>T&&(T.modifiers=w),...Ro),m.jsxs(Iu.Provider,{value:T,children:[m.jsx(mm,{ref:c,children:n}),n]})}function ym(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Du(){return S.useContext(Iu)}function Pu(e){var t;const n=(t=Du())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),nr(r.register,[n,r]),r}var xm=Object.create,ju=Object.defineProperty,bm=Object.getOwnPropertyDescriptor,Ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),wo=e=>{throw TypeError(e)},wm=(e,t,n)=>t in e?ju(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_m=e=>{var t;return[,,,xm((t=e?.[Ru("metadata")])!=null?t:null)]},Au=["class","method","getter","setter","accessor","field","value","get","set"],Lu=e=>e!==void 0&&typeof e!="function"?wo("Function expected"):e,km=(e,t,n,r,s)=>({kind:Au[e],name:t,metadata:r,addInitializer:o=>n._?wo("Already initialized"):s.push(Lu(o||null))}),Sm=(e,t)=>wm(t,Ru("metadata"),e[3]),$m=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Bu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c=t&7,d=!1,f=!1,h=2,y=Au[c+5],g=e[h]||(e[h]=[]),w=(s=s.prototype,bm(s,n)),x=r.length-1;x>=0;x--)l=km(c,n,a={},e[3],g),l.static=d,l.private=f,u=l.access={has:p=>n in p},u.get=p=>p[n],i=(0,r[x])(w[y],l),a._=1,Lu(i)&&(w[y]=i);return w&&ju(s,n,w),s},Fu=(e,t,n)=>t.has(e)||wo("Cannot "+n),Tm=(e,t,n)=>(Fu(e,t,"read from private field"),t.get(e)),Em=(e,t,n)=>t.has(e)?wo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Cm=(e,t,n,r)=>(Fu(e,t,"write to private field"),t.set(e,n),n),an=class Ii{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ii(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Ii(t,n)}},Wu,Nu,Di,Ds,os,Aa=class extends(Di=hn,Nu=[We],Wu=[We],Di){constructor(e){const t=an.from(e);super(t,(n,r)=>an.equals(n,r)),$m(os,5,this),Em(this,Ds,0),this.velocity={x:0,y:0}}get delta(){return an.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=an.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-Tm(this,Ds),i=a=>Math.round(a/o*100);Re(()=>{Cm(this,Ds,s),this.velocity={x:i(r.x),y:i(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(an.from(e)),this.velocity={x:0,y:0}}};os=_m(Di);Ds=new WeakMap;Bu(os,2,"delta",Nu,Aa);Bu(os,2,"direction",Wu,Aa);Sm(os,Aa);var zu=(e=>(e.Horizontal="x",e.Vertical="y",e))(zu||{});Object.values(zu);var Om=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=an.distance(t.shape.center,n);return{id:r,value:1/s,type:Zn.PointerIntersection,priority:Qn.High}}return null},Mm=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,o=an.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:a,type:Zn.ShapeIntersection,priority:Qn.Normal}}return null},Im=e=>{var t;return(t=Om(e))!=null?t:Mm(e)};function Dm(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:o,accept:i,type:a}=e,l=Pu(c=>new bo(hm(fm({},e),{register:!1,element:An(s)}),c)),u=Cu(l);return Pe(o,()=>l.id=o),Is(s,c=>l.element=c),Pe(i,()=>l.accept=i,void 0,wt),Pe(t,()=>l.collisionDetector=t??Im),Pe(n,()=>n&&(l.data=n)),Pe(r,()=>l.disabled=r===!0),Pe(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(c=>{var d,f;!c&&((d=l.element)!=null&&d.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const Gu=(e,t="line")=>{const[n,r]=t==="line"?["6px","2px"]:["10px","6px"];return{cursor:"text",borderRadius:t==="line"?"4px":"6px",mx:`-${n}`,px:n,my:`-${r}`,py:r,transition:`background-color ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{bgcolor:"action.hover"},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:-2}}},Hu=S.createContext(void 0);function qu(e,t){const n=S.useContext(Hu),r=S.useRef(t);r.current=t,S.useEffect(()=>{if(!n||!e)return;const o=()=>r.current();return n.commitRef.current=o,()=>{n.commitRef.current===o&&(n.commitRef.current=void 0)}},[n,e]);const s=S.useRef(!1);S.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),S.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function Pi({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:o}=be.usePublisherTheme(),[i,a]=S.useState(void 0),l=S.useRef(!1),u=()=>{l.current||i===void 0||(a(void 0),i!==e&&r(i))};qu(i!==void 0&&i!==e,()=>(u(),!0));const c=()=>{l.current=!1,a(e)};if(i===void 0){const d=e==="",f=d&&s;return m.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},Gu(o)],children:d?t:e})}return m.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:i,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Pm=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const o={...n};return s?o.break=!0:delete o.break,o}),jm=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const o=r[t];s.break&&o&&!o.break&&(r[t]={...o,break:!0});const i={...s};return delete i.break,r.splice(n,0,i),r},Uu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break,rowspan:e.rowspan,row:e.row,col:e.col}),Ku=e=>`gap.${e}`,Rm=(e,t)=>{const n=[];let r=0;e.forEach((o,i)=>{const a=Math.min(o.colspan??1,t),l=i===0||o.break===!0||r+a>t;l&&i>0&&r<t&&n.push({kind:"gap",after:fe(e[i-1]),colspan:t-r}),l&&(r=0),n.push(Uu(o,i)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:fe(s),colspan:t-r}),n};var Am=Object.create,Vu=Object.defineProperty,Lm=Object.defineProperties,Bm=Object.getOwnPropertyDescriptor,Fm=Object.getOwnPropertyDescriptors,ro=Object.getOwnPropertySymbols,Xu=Object.prototype.hasOwnProperty,Yu=Object.prototype.propertyIsEnumerable,Wm=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),is=e=>{throw TypeError(e)},ji=(e,t,n)=>t in e?Vu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ao=(e,t)=>{for(var n in t||(t={}))Xu.call(t,n)&&ji(e,n,t[n]);if(ro)for(var n of ro(t))Yu.call(t,n)&&ji(e,n,t[n]);return e},Lo=(e,t)=>Lm(e,Fm(t)),Nm=(e,t)=>{var n={};for(var r in e)Xu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ro)for(var r of ro(e))t.indexOf(r)<0&&Yu.call(e,r)&&(n[r]=e[r]);return n},zm=e=>{var t;return[,,,Am((t=void 0)!=null?t:null)]},Qu=["class","method","getter","setter","accessor","field","value","get","set"],$r=e=>e!==void 0&&typeof e!="function"?is("Function expected"):e,Gm=(e,t,n,r,s)=>({kind:Qu[e],name:t,metadata:r,addInitializer:o=>n._?is("Already initialized"):s.push($r(o||null))}),Hm=(e,t)=>ji(t,Wm("metadata"),e[3]),ps=(e,t,n,r)=>{for(var s=0,o=e[t>>1],i=o&&o.length;s<i;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Zu=(e,t,n,r,s,o)=>{for(var i,a,l,u,c,d=t&7,f=!1,h=!1,y=e.length+1,g=Qu[d+5],w=e[y-1]=[],x=e[y]||(e[y]=[]),p=(s=s.prototype,Bm({get[n](){return Tr(this,o)},set[n](_){return on(this,o,_)}},n)),v=r.length-1;v>=0;v--)u=Gm(d,n,l={},e[3],x),u.static=f,u.private=h,c=u.access={has:_=>n in _},c.get=_=>_[n],c.set=(_,b)=>_[n]=b,a=(0,r[v])({get:p.get,set:p.set},u),l._=1,a===void 0?$r(a)&&(p[g]=a):typeof a!="object"||a===null?is("Object expected"):($r(i=a.get)&&(p.get=i),$r(i=a.set)&&(p.set=i),$r(i=a.init)&&w.unshift(i));return p&&Vu(s,n,p),s},Ju=(e,t,n)=>t.has(e)||is("Cannot "+n),Tr=(e,t,n)=>(Ju(e,t,"read from private field"),t.get(e)),dr=(e,t,n)=>t.has(e)?is("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),on=(e,t,n,r)=>(Ju(e,t,"write to private field"),t.set(e,n),n);function ln(e){return e instanceof Fa||e instanceof rf}var gs=10,qm=class extends et{constructor(e){super(e);const t=yt(()=>{const{dragOperation:r}=e;if(Ur(r.activatorEvent)&&ln(r.source)&&r.status.initialized){const s=e.registry.plugins.get(ss);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:o}=s;if(!Ur(r.nativeEvent)||!ln(o.source)||!o.shape)return;const{actions:i,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const c=Um(u),{source:d,target:f}=o,{center:h}=o.shape.current,y=[],g=[];Re(()=>{for(const b of l.droppables){const{id:E}=b;if(!b.accepts(d)||E===f?.id&&ln(b)||!b.element)continue;let T=b.shape;const M=new Et(b.element,{getBoundingClientRect:O=>Hr(O,void 0,.2)});!M.height||!M.width||(c=="down"&&h.y+gs<M.center.y||c=="up"&&h.y-gs>M.center.y||c=="left"&&h.x-gs>M.center.x||c=="right"&&h.x+gs<M.center.x)&&(y.push(b),b.shape=M,g.push(()=>b.shape=T))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(y,pg);Re(()=>g.forEach(b=>b()));const[x]=w;if(!x)return;const{id:p}=x,{index:v,group:_}=d.sortable;i.setDropTarget(p).then(()=>{const{source:b,target:E,shape:T}=o;if(!b||!ln(b)||!T)return;const{index:M,group:O,target:C}=b.sortable,A=v!==M||_!==O,R=A?C:E?.element;if(!R)return;Vd(R);const B=new Et(R);if(!B)return;const G=Ct.delta(B,Ct.from(T.current.boundingRectangle),b.alignment);i.move({by:G}),A?i.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Um(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var Km=Object.defineProperty,Vm=Object.defineProperties,Xm=Object.getOwnPropertyDescriptors,Cl=Object.getOwnPropertySymbols,Ym=Object.prototype.hasOwnProperty,Qm=Object.prototype.propertyIsEnumerable,Ol=(e,t,n)=>t in e?Km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))Ym.call(t,n)&&Ol(e,n,t[n]);if(Cl)for(var n of Cl(t))Qm.call(t,n)&&Ol(e,n,t[n]);return e},wn=(e,t)=>Vm(e,Xm(t));function Zm(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ms(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Bo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Jm(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(Bo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&Bo(o)){const v=o.initialGroup==null?void 0:ms(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:ms(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return wn(bn({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return wn(bn({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=ms(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&Bo(o)){const v=o.group==null?void 0:ms(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return wn(bn({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return wn(bn({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return wn(bn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function ev(e,t){return Jm(e,t,Zm)}function Ml(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Il(e,t,n){var r;for(const[s,o]of t)for(const i of o){const a=e.get(i.id);if(i.index!==a||i.group!==s||!((r=n.get(s))!=null&&r.has(i)))return!0}return!1}var Dl="__default__",tv=class extends et{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof Fa){const{sortable:o}=s,{group:i}=o;let a=r.get(i);a||(a=new Set,r.set(i,a)),a.add(o)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:o}=s,{source:i,target:a}=o;if(!ln(i)||!ln(a)||i.sortable===a.sortable)return;const l=t(),u=Ml(l),c=i.sortable.group===a.sortable.group,d=l.get(i.sortable.group),f=c?d:l.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,y;const g=t();if(Il(u,l,g))return;const w=i.sortable.element,x=a.sortable.element;if(!x||!w||!c&&a.id===i.sortable.group)return;const p=vs(d),v=c?p:vs(f),_=(h=i.sortable.group)!=null?h:Dl,b=(y=a.sortable.group)!=null?y:Dl,E={[_]:p,[b]:v},T=ev(E,r);if(E===T)return;const M=T[b].indexOf(i.sortable),O=T[b].indexOf(a.sortable);s.collisionObserver.disable(),Pl(w,M,x,O),Re(()=>{for(const[C,A]of T[_].entries())A.index=C;if(!c)for(const[C,A]of T[b].entries())A.group=a.sortable.group,A.index=C}),s.actions.setDropTarget(i.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:o}=s,{source:i}=o;ln(i)&&(i.sortable.initialIndex===i.sortable.index&&i.sortable.initialGroup===i.sortable.group||queueMicrotask(()=>{const a=t(),l=Ml(a),u=a.get(i.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const c=t();if(Il(l,a,c))return;const d=vs(u),f=vs(u,rv),h=i.sortable.element,y=f.indexOf(i.sortable),g=d[y],w=g?.element;!g||!w||!h||(Pl(h,g.index,w,i.index),Re(()=>{for(const x of a.values()){const p=Array.from(x).values();for(const v of p)v.index=v.initialIndex,v.group=v.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Pl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function nv(e,t){return e.index-t.index}function rv(e,t){return e.initialIndex-t.initialIndex}function vs(e,t=nv){return Array.from(e).sort(t)}var jl=[qm,tv],ef={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Rl(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var ys=new Qh,tf,nf,qt,La,Er,Cr,Ba,Mn;nf=[le],tf=[le];var _o=class{constructor(e,t){dr(this,La,ps(qt,8,this)),ps(qt,11,this),dr(this,Er),dr(this,Cr),dr(this,Ba,ps(qt,12,this)),ps(qt,15,this),dr(this,Mn),this.register=()=>(Re(()=>{var y,g;(y=this.manager)==null||y.registry.register(this.droppable),(g=this.manager)==null||g.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Re(()=>{var y,g;(y=this.manager)==null||y.registry.unregister(this.droppable),(g=this.manager)==null||g.registry.unregister(this.draggable)})},this.destroy=()=>{Re(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:o,index:i,sensors:a,type:l,transition:u=ef,plugins:c}=n,d=Nm(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=St(c,jl),h=Rl(s);this.droppable=new Fa(Lo(Ao({},d),{disabled:h.droppable}),t,this),this.draggable=new rf(Lo(Ao({},d),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var y,g,w;const x=(y=this.manager)==null?void 0:y.dragOperation.status;x?.initializing&&this.id===((w=(g=this.manager)==null?void 0:g.dragOperation.source)==null?void 0:w.id)&&ys.clear(this.manager),x?.dragging&&ys.set(this.manager,this.id,ae(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:y,group:g,manager:w}=this,x=Tr(this,Cr),p=Tr(this,Er);(y!==x||g!==p)&&(on(this,Cr,y),on(this,Er,g),this.animate())},()=>{var y,g;const{target:w}=this,{isDragSource:x}=this.draggable;((g=(y=this.draggable.pluginConfig(Ca))==null?void 0:y.feedback)!=null?g:"default")==="move"&&x&&(this.droppable.disabled=!w)},...r()],type:l,sensors:a}),t,this),on(this,Mn,d.element),this.manager=t,this.index=i,on(this,Cr,i),this.group=o,on(this,Er,o),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ys.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ae(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const o=this.refreshShape();if(!o)return;const i={x:n.boundingRectangle.left-o.boundingRectangle.left,y:n.boundingRectangle.top-o.boundingRectangle.top},{translate:a}=It(s),l=yl(s,a,!1),u=yl(s,a);if(i.x||i.y){const c=ba(ft(s))?Lo(Ao({},t),{duration:0}):t;Xd({element:s,keyframes:{translate:[`${l.x+i.x}px ${l.y+i.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Re(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Re(()=>{const t=Tr(this,Mn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),on(this,Mn,e)})}get element(){var e,t;const n=Tr(this,Mn);if(n)return(t=(e=pi.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=St(e,jl)}set disabled(e){const t=Rl(e);Re(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Re(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??Yd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Re(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};qt=zm();La=new WeakMap;Er=new WeakMap;Cr=new WeakMap;Ba=new WeakMap;Mn=new WeakMap;Zu(qt,4,"index",nf,_o,La);Zu(qt,4,"group",tf,_o,Ba);Hm(qt,_o);var rf=class extends xo{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Fa=class extends bo{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},sv=Object.defineProperty,ov=Object.defineProperties,iv=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,av=Object.prototype.hasOwnProperty,lv=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?sv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fo=(e,t)=>{for(var n in t||(t={}))av.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))lv.call(t,n)&&Ll(e,n,t[n]);return e},cv=(e,t)=>ov(e,iv(t));function dv(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:o,element:i,handle:a,index:l,group:u,disabled:c,modifiers:d,sensors:f,target:h,type:y,plugins:g}=e,w=Fo(Fo({},ef),e.transition),x=Pu(v=>new _o(cv(Fo({},e),{transition:w,register:!1,handle:An(a),element:An(i),target:An(h)}),v)),p=Cu(x,uv);return Pe(s,()=>x.id=s),nr(()=>{Re(()=>{x.group=u,x.index=l})},[x,u,l]),Pe(y,()=>x.type=y),Pe(t,()=>x.accept=t,void 0,wt),Pe(o,()=>o&&(x.data=o)),Pe(l,()=>{var v;(v=x.manager)!=null&&v.dragOperation.status.idle&&w?.idle&&x.refreshShape()},lm),Is(a,v=>x.handle=v),Is(i,v=>x.element=v),Is(h,v=>x.target=v),Pe(c,()=>x.disabled=c??!1,void 0,wt),Pe(f,()=>x.sensors=f,void 0,wt),Pe(n,()=>x.collisionDetector=n),Pe(r,()=>x.collisionPriority=r),Pe(g,()=>x.plugins=g,void 0,wt),Pe(w,()=>x.transition=w,void 0,wt),Pe(d,()=>x.modifiers=d,void 0,wt),Pe(e.alignment,()=>x.alignment=e.alignment),{sortable:p,get isDragging(){return p.isDragging},get isDropping(){return p.isDropping},get isDragSource(){return p.isDragSource},get isDropTarget(){return p.isDropTarget},handleRef:S.useCallback(v=>{x.handle=v??void 0},[x]),ref:S.useCallback(v=>{var _,b;!v&&((_=x.element)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.element=v??void 0)},[x]),sourceRef:S.useCallback(v=>{var _,b;!v&&((_=x.source)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.source=v??void 0)},[x]),targetRef:S.useCallback(v=>{var _,b;!v&&((_=x.target)!=null&&_.isConnected)&&!((b=x.manager)!=null&&b.dragOperation.status.idle)||(x.target=v??void 0)},[x])}}function uv(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ri="tile",sf="gap",fv=[Ci.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${of}], ${hv}`)!==null||(Ci.defaults.preventActivation?.(e,t)??!1)}),bu],of="data-no-drag",hv=".malloy-render, .malloy-table",pv=e=>[...e,Ca.configure({feedback:"clone"})];function gv({id:e,index:t,disabled:n=!1,children:r}){const{ref:s,handleRef:o,isDragSource:i}=dv({id:e,index:t,disabled:n,type:Ri,accept:Ri,collisionDetector:_a,plugins:pv});return m.jsx(m.Fragment,{children:r({ref:s,handleRef:o,isDragSource:i})})}function mv({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Dm({id:e,type:sf,accept:Ri,collisionDetector:_a,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}function vv({active:e}){const t=Du();return S.useEffect(()=>{if(!e||!t)return;const n=r=>{r.key!=="Escape"||t.dragOperation.status.idle||(r.preventDefault(),r.stopPropagation(),t.actions.stop({event:r,canceled:!0}))};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)},[e,t]),null}const af=e=>e.ok===!1,He=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),rr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,Me={sourceDefinition:e=>He(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>He(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>He(e,"VIEW","subQueryDefList"),defDimension:e=>He(e,"defList","DIMENSION"),exploreProperties:e=>He(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>He(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>He(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>He(e,"WHERE","filterClauseList"),givenDef:e=>He(e,"givenNameDef"),givenStatement:e=>He(e,"GIVEN","givenDefList"),importStatement:e=>He(e,"IMPORT","importURL"),vArrow:e=>He(e,"ARROW","vExpr","segExpr"),segRefine:e=>He(e,"PLUS","segExpr"),segOps:e=>He(e,"queryProperties"),segField:e=>He(e,"fieldPath")&&!He(e,"segExpr"),segParen:e=>He(e,"OPAREN","CPAREN","vExpr"),compare:e=>He(e,"fieldExpr","compareOp"),givenRef:e=>He(e,"GIVEN_REF")};function yv(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function xv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}function lf(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!rr(s))continue;const o=Ne(s,"docAnnotations");if(o)for(const i of Xt(o,"docAnnotation")){const a=e.text_(i);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class cf{constructor(t){this.text=t,this.map=yv(t),this.lineStarts=xv(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!rr(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],o=this.map[r.stopIndex+1];if(!(s===void 0||o===void 0||o<s))return{start:s,end:o}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function as(e,t,n=[]){rr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)as(e.getChild(r),t,n);return n}const bv=e=>He(e,"OCURLY","CCURLY");function Qr(e,t){const n=[],r=s=>{if(rr(s)){if(t(s)){n.push(s);return}if(!bv(s))for(let o=0;o<(s.childCount??0);o++)r(s.getChild(o))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ne=(e,t)=>e[t]?.call(e),Xt=(e,t)=>e[t]?.call(e)??[];function wv(e,t){if(!Me.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!Me.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),o=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:o.replace(/^\$/,"")}}function df(e,t){const n=e.positioned(t);if(!n)return;const r=Ne(t,"filterClauseList"),s=[];for(const o of r?Xt(r,"fieldExpr"):[]){const i=e.positioned(o);if(!i)continue;const a=as(o,Me.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...i,givens:a,binding:wv(e,o)})}return{...n,clauses:s}}function Ai(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const u of Qr(t,Me.queryStatement)){const c=e.positioned(u);c&&r.push(c);const d=Ne(u,"whereStatement");if(d&&Me.whereStatement(d)){const f=df(e,d);f&&s.push(f)}}const o=n.start+1,i=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
+ `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:o,closeStart:i,statements:r,wheres:s,indent:l,oneLine:a}}function Wa(e,t,n){const r=[],s=e.line(t.start),o=e.line(n);for(let i=s;i<o;i++){if(e.commentLines.has(i)||e.proseLines.has(i))continue;const a=e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:i,text:a})}return r}function _v(e,t){const n=Ne(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=Me.vArrow(t);if(Me.segOps(n)){const s=Ne(n,"queryProperties"),o=s&&Ai(e,s);return o?{kind:"inline",stage:o,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(Me.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(Me.segRefine(n)){const s=Xt(n,"segExpr"),o=s[0],i=s[s.length-1];let a=o;for(;Me.segRefine(a);){const f=Xt(a,"segExpr");if(f.some(h=>Me.segOps(h)||Me.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&Me.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!Me.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(!Me.segOps(i)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(l.start,l.end),c=Ne(i,"queryProperties"),d=c&&Ai(e,c);return d?{kind:"reference",from:u,fromSpan:l,refinement:d}:{kind:"reference",from:u,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function kv(e,t){const n=[];for(const r of Qr(t,Me.defExploreQuery)){const s=e.span(r),o=Ne(r,"subQueryDefList");if(!s||!o)continue;const i=Xt(o,"exploreQueryDef").filter(Me.exploreQueryDef),a=e.terminal(Ne(r,"VIEW"));for(const l of i){const u=e.span(l),c=Ne(l,"exploreQueryNameDef"),d=e.text_(c),f=Ne(l,"vExpr");!u||!d||!f||n.push({name:d,span:u,line:e.line(u.start),statement:s,tags:Wa(e,s,a?.start??u.start),siblings:i.length,body:_v(e,f)})}}return n}function Sv(e,t){const n=[];for(const r of Qr(t,Me.defDimension)){const s=e.span(r),o=Ne(r,"defList");if(!s||!o)continue;const i=e.terminal(Ne(r,"DIMENSION"));for(const a of Xt(o,"fieldDef")){const l=e.span(a),u=e.text_(Ne(a,"fieldNameDef"))?.trim(),c=e.text_(Ne(a,"fieldExpr"))?.trim();!l||!u||c===void 0||n.push({name:u,expression:c,span:l,line:e.line(l.start),statement:s,tags:Wa(e,s,i?.start??l.start)})}}return n}function $v(e,t){const n=[];for(const r of as(t,Me.sourceDefinition)){const s=e.span(r),o=e.text_(Ne(r,"sourceNameDef")),i=Ne(r,"sqExplore");if(!s||!o||!i)continue;const a=e.span(i),l=a?e.text.slice(a.start,a.end):"",u=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),c=Qr(i,Me.exploreProperties)[0],d=c&&Ai(e,c),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(c)for(const y of Qr(c,Me.whereStatement)){const g=df(e,y);g&&h.push(g)}n.push({name:o,base:u,span:s,line:e.line(s.start),statement:f,...d?{properties:d}:{},views:c?kv(e,c):[],dimensions:c?Sv(e,c):[],wheres:h})}return n}function Tv(e,t){const n=[];for(const r of as(t,Me.givenStatement)){const s=e.terminal(Ne(r,"GIVEN")),o=Ne(r,"givenDefList"),i=s?e.line(s.start):void 0;for(const a of o?Xt(o,"givenDef"):[]){const l=e.span(a),u=e.span(Ne(a,"givenNameDef")),c=u&&e.text.slice(u.start,u.end);if(!l||!u||!c)continue;const d={start:u.start,end:l.end},f=e.line(d.start);n.push({name:c,declaration:e.text.slice(d.start,d.end),span:d,line:f,statement:{start:e.lineStarts[f],end:d.end},tags:Wa(e,l,d.start),...i!==void 0&&i!==f?{blockHeader:i}:{}})}}return n}function Ev(e,t){const n=[];for(const r of as(t,Me.importStatement)){const s=e.span(r),o=e.text_(Ne(r,"importURL"));if(!s||o===void 0)continue;const i=Ne(r,"importSelect"),a=i?Xt(i,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:o.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function uf(e){let t;try{t=await Na(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!rr(s)||typeof s.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const o=r?.tokenStream??{},i=typeof o.getTokens=="function"?o.getTokens():void 0;if(!i||typeof o.tokenSource?.vocabulary?.getSymbolicName!="function"||i.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new cf(e),l=Cv(a,o);a.commentLines=l.lines;const u=e.split(`
70
+ `),c=f=>l.lines.has(f);a.proseLines=me.markdownLines(u,c),a.blocks=me.blockSpans(u,c).filter(([f])=>!u[f].trimStart().startsWith("##"));const d=$v(a,s);return d.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Ev(a,s),sources:d,givens:Tv(a,s),textBlocks:Mv(a,o),modelNotes:lf(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>Ov(a,l.lines,f)}}}async function Na(e,t){const{MalloyTranslator:n}=await k.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Cv(e,t){const n=new Map,r=new Set,s=[],o=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const d=o?.getSymbolicName(c.type);if(d!=="COMMENT_TO_EOL"&&d!=="BLOCK_COMMENT")continue;const f=e.utf16(c.startIndex);let h=e.utf16(c.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
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 g=d;g<=f;g++)u(g).trim()===""&&r.add(g);const h=a.slice(e.lineStarts[d],c.start).trim(),y=a.slice(c.end,e.lineStarts[f+1]??a.length).trim();h!==""&&y===""&&n.set(f,c)}return{trailing:n,lines:r,all:s}}function Ov(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 Mv(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=me.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,y=l.name===void 0&&l.rest?[`${l.rest}
72
+ `]:[];i.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...y,...u].join("").replace(/\r\n?/g,`
73
+ `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=c}return i}function ff(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function hf(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=ff(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const o=/^tiles\s*=\s*\[/.exec(e.slice(r));if(o)return Iv(e,r+o[0].length-1)}}}function Iv(e,t){const n=[];let r=0,s=t+1;const o=i=>{const a=e.slice(s,i),l=a.length-a.trimStart().length,u=a.trim();u!==""&&n.push({text:u,span:{start:s+l,end:s+l+u.length}})};for(let i=t+1;i<e.length;i++){const a=e[i];if(a==='"')i=ff(e,i);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return o(i),{open:t,close:i,entries:n};r--}else a===","&&r===0&&(o(i),s=i+1)}}function Dv(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
74
74
  `)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const s=e.indexOf(`
75
- `,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(pe.tagAnnotation),{tag:r,errors:s}=n.length>0?Ru(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(pe.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=bl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=bl(i,"layout"),c=i.has("tiles");if(c&&i.array("tiles")===void 0)return{status:"unparsed",errors:s};const f=a==="grid"||a==="linear"?a:c||r?.tag("dashboard")!==void 0?"grid":"linear";return f==="linear"&&!c?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:f}}async function Nm(e){const{parseAnnotation:t}=await S.loadMalloyTag();let n=[];try{const r=(await Ca(e,"file://report.malloy")).parse?.root;r&&Hn(r)&&typeof r.getChild=="function"&&(n=Ou(new Du(e),r))}catch{n=[]}return Au(n,t)}const Hs=e=>e.ok===!1;function Hr(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Vs=e=>e.map(t=>t.text);function xl(e){const t=Vs(e),n=S.chartStateOfTagLines(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:S.chartLinesOf(t)}:{chart:n}}function Gm(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:pe.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Um(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Hm(n(Vs(Hr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Hm(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...s===void 0?{}:{rangeMax:s}}}function Ei(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const Vm=/^"((?:[^"\\]|\\.)+)"$/,Km=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Ks(e,t,n=!1){try{return await qm(e)}catch(r){return{ok:!1,reason:`A value in this file's tags cannot be read (${r instanceof Error?r.message:String(r)}), so it cannot be opened in the builder.`}}}async function qm(e){const{parseAnnotation:t}=await S.loadMalloyTag(),n=pe.splitSourceLines(e),r=await Iu(e);if(Cu(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=pe.descriptionNotes(n).text,o=Au(s.modelNotes,t);if(o.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(o.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${o.errors[0]?`: ${o.errors[0]}`:"."}`};if(o.status==="kind-removed")return{ok:!1,reason:Fm(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?zm(o.unknownLayout):Wm};const a=o.layout,c=pe.artifactTag(n);if(c===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!pe.artifactLeads(c.text))return{ok:!1,reason:pe.ARTIFACT_NOT_FIRST,line:c.from+1};const{tag:f,errors:d}=Ru(t,[pe.tagAnnotation(c.text)]),l=f?.tag("artifact"),u=Pu(c.text);if(u===void 0)return d.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${d[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),p=[],v=[],x=new Map;for(const T of s.sources){const C={name:T.name,base:T.base};T.dimensions.length>0&&(C.dimensions=T.dimensions.map(E=>({name:E.name,expression:E.expression})));const M=new Set(T.wheres.flatMap(E=>E.clauses.flatMap(O=>O.givens)));M.size>0&&(C.scopedBy=Array.from(M)),p.push(C);for(const E of T.dimensions){const O=t(Vs(Hr(s,n,E.line).tags)).tag?.tag("drill");if(!O)continue;const A=O.textArray("to")??[O.text("to")??""];v.push({source:T.name,name:E.name,expression:E.expression,to:A.filter(Boolean),...O.text("given")?{given:O.text("given")}:{}})}x.set(T.name,new Map(T.views.map(E=>[E.name,E])))}const _=[];for(const{text:T}of u.entries){const C=Vm.exec(T),M=C?void 0:Km.exec(T)?.[1];if(M!==void 0){const I=t([`# ${T}`]).tag?.tag(M);if(I?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${M} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(_.some(H=>je(H)&&H.name===M))return{ok:!1,reason:`Two text tiles are named \`${M}\`, so the builder cannot tell them apart.`};const F=Ei(I,"colspan");_.push({kind:"text",name:M,markdown:s.textBlocks.find(H=>H.name===M)?.body??"",...F===void 0?{}:{colspan:F},...I.has("break")?{break:!0}:{}});continue}const E=C?.[1]??T,O=C?pe.tileSteps(E):void 0;if(!O)return{ok:!1,reason:`The tile \`${E}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:A,view:j}=O,L=x.get(A)?.get(j);if(L===void 0){_.push({name:j,source:A,declaration:{kind:"inherited"}});continue}const N=t(Vs(L.tags)).tag,W=L.body.kind==="reference"?{kind:"reference",from:L.body.from}:L.body.kind==="inline"?{kind:"inline"}:void 0;if(W===void 0){_.push({name:j,source:A,declaration:{kind:"opaque",why:L.body.kind==="unsupported"?L.body.why:"unreadable"},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...xl(L.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}});continue}const V=Gm(L.body.kind==="reference"?L.body.refinement:L.body.kind==="inline"?L.body.stage:void 0);_.push({name:j,source:A,declaration:W,...V?{filters:V}:{},...N?.text("label")?{label:N.text("label")}:{},...N?.text("subtitle")?{subtitle:N.text("subtitle")}:{},...N?.numeric("colspan")!==void 0?{colspan:N.numeric("colspan")}:{},...xl(L.tags),...N?.has("break")?{break:!0}:{},...N?.has("borderless")?{borderless:!0}:{}})}const g=Um(s,n,t),y={},w=l?.tag("givens");for(const T of Object.keys(w?.dict??{})){const C=w?.text(T);C!==void 0&&(y[T]=C)}const b=f?.tag("dashboard")?.has("columns")?Ei(f.tag("dashboard"),"columns"):l?.array("tiles")?Ei(l,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:l?.text("title")??"",...i?{description:i}:{},...b===void 0?{}:{columns:b},...l?.has("autorun")?{autorun:l.isTrue("autorun")}:{},imports:h,sources:p,...g?{localGivens:g}:{},...Object.keys(y).length>0?{startingGivens:y}:{},...v.length>0?{drills:v}:{},tiles:_}}}const qs=e=>e.ok===!1;async function wl(e){const{problems:t}=await Ca(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function xe(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Lu(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Ym(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
- `&&t.push(n+1);return t}function Xm(e,t){let n=e;const r=t.map((s,i)=>({edit:s,index:i}));for(const{edit:s}of r.sort((i,o)=>o.edit.start-i.edit.start||o.edit.end-i.edit.end||o.index-i.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const Bu=e=>e==="none"||S.isChartPick(e)?e:void 0;function Fu(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${pt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${pt(e.subtitle)}`);const r=t?Bu(e.chart):void 0;return r!==void 0&&n.push(S.chartLineText(r,e.chartCarried)),n}function ws(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Qm=new Set(["colspan","break","borderless","label","subtitle"]),Zm=new Set(["label","description","control","suggest","range_min","range_max"]);function _l(e){const t=[];if(e.label!==void 0&&t.push(`label=${pt(e.label)}`),e.description!==void 0&&t.push(`description=${pt(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${pt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${pt(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const kl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Jm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Sl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:pt(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(pt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ys=e=>`${e.source}.${e.name}`,pt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,To=e=>je(e)?xe(["text",e.name]):xe([e.name,e.source,e.declaration]),lt=To,$l=e=>xe(e.tiles.map(lt));function ev(e,t,n){const r=new Set(e.tiles.map(lt)),s=new Set(t.tiles.map(lt)),i=e.tiles.filter(h=>!s.has(lt(h))),o=t.tiles.filter(h=>!r.has(lt(h))),c=i.length>0||o.length>0||$l(e)!==$l(t);for(const h of o)if(ae(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const f=new Map(e.sources.map(h=>[h.name,h])),d=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)d.add(h.base);const l=t.imports.some(h=>h.kind==="all"),u=t.sources.filter(h=>!f.has(h.name));for(const h of e.sources){const p=t.sources.find(v=>v.name===h.name);if(!p||p.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of u){if(!o.some(p=>ae(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!d.has(h.base)&&!l&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:i,addedTiles:o,newSources:u,currentSources:f,reordered:c}}const Tl=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function tv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Pr(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function El(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=tv(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=f=>{const d=f.exec(o);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),o=o.slice(0,d.index)+o.slice(d.index+d[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const c=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${c.join(" ")} }${t.slice(s+1)}`}function nv(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:c}=e,f=new Map(r.tiles.filter(je).map(g=>[g.name,g])),d=s.tiles.filter(je).some(g=>{const y=f.get(g.name);return y!==void 0&&Tl(y,g)});if(!i&&!d)return;const l=pe.artifactTag(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,h=Pu(u);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const p=new Map;for(const{text:g}of h.entries){const y=/^"((?:[^"\\]|\\.)+)"$/.exec(g);if(y){const b=y[1].split("->").map(T=>T.trim());b.length===2&&p.set(`${b[0]}->${b[1]}`,g);continue}const w=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(g)?.[1];w!==void 0&&p.set(`text.${w}`,g)}const v=s.tiles.map(g=>{const y=!o.has(lt(g));if(je(g)){const w=p.get(`text.${g.name}`);return w!==void 0?f.has(g.name)&&!Tl(f.get(g.name),g)?w:El(g,w):y?El(g):void 0}return p.get(`${g.source}->${g.name}`)??(y?`"${g.source} -> ${g.name}"`:void 0)});if(v.some(g=>g===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const x=u.slice(0,h.open).search(/tiles\s*=\s*$/),_=`${u.slice(0,x)}tiles=[${rv(u,h,v)}]${u.slice(h.close+1)}`;_!==u&&c.push({...zu(n,l),text:`${_}
78
- `})}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=Pr(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,c=e[a]==='"'?Pr(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),f=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,f)+e.slice(c)}}return e}function iv(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Pr(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Pr(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Pr(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function ov(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||xe(r.startingGivens)!==xe(s.startingGivens)){const o=pe.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zu(n,o),c=i.find(y=>y.start===a.start&&y.end===a.end);let f=c?c.text.replace(/\n$/,""):o.text;const d=r.layout!==s.layout,l=f.indexOf("artifact"),u=f.indexOf("{",l);let h=0,p=-1;for(let y=u;y<f.length;y++)if(f[y]==="{")h++;else if(f[y]==="}"&&--h===0){p=y;break}if(u<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=f.slice(u+1,p);const x=o.block?`
81
- ${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",_=y=>o.block?`${v.trimEnd()}${x}${y}
82
- `:`${v.trimEnd()} ${y} `,g=(y,w)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${y}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(w===void 0){const T=new RegExp(`
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 Pv(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Dv(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const o=e[r];if(/[=[,]/.test(o)){const i=t.exec(e.slice(r+1));if(i){const a=i[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${o}${i[1]}"f'${a}'"`,r+=1+i[0].length;continue}}n+=o,r+=1}return n}function pf(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(o=>{if(e([o]).log.length===0)return o;const i=Pv(o);return e([i]).log.length===0?i:o}),s=e(r);return{tag:s.tag,errors:s.log.map(o=>o.message)}}const Bl=(e,t)=>{try{return e.text(t)}catch{return}},jv=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Rv=e=>`\`kind=${e}\` is no longer read, so this file is not a report. Fix: remove \`kind=${e}\` and write \`layout=grid\` or \`layout=linear\`.`,Av=e=>`\`layout=${e}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`,Lv="A linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";function gf(e,t){const n=e.filter(jv).filter(c=>!c.includes("@env.")).map(me.tagAnnotation),{tag:r,errors:s}=n.length>0?pf(t,n):{tag:void 0,errors:[]},o=r?.tag("artifact");if(!o)return e.some(me.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const i=Bl(o,"kind");if(i!==void 0)return{status:"kind-removed",kind:i};const a=Bl(o,"layout"),l=o.has("tiles");if(l&&o.array("tiles")===void 0)return{status:"unparsed",errors:s};const u=a==="grid"||a==="linear"?a:l||r?.tag("dashboard")!==void 0?"grid":"linear";return u==="linear"&&!l?a!==void 0&&a!=="grid"&&a!=="linear"?{status:"cells-removed",unknownLayout:a}:{status:"cells-removed"}:{status:"report",layout:u}}async function Bv(e){const{parseAnnotation:t}=await k.loadMalloyTag();let n=[];try{const r=(await Na(e,"file://report.malloy")).parse?.root;r&&rr(r)&&typeof r.getChild=="function"&&(n=lf(new cf(e),r))}catch{n=[]}return gf(n,t)}const so=e=>e.ok===!1;function sr(e,t,n){const r=e.blockStart(n),s=[],o=[];for(let i=r;i<n;i++){if(e.commentLine(i))continue;if(e.proseLine(i)){o.push(i);continue}const a=t[i].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:i,text:a})}return{start:r,tags:s,prose:o}}const Ln=e=>e.map(t=>t.text);function Fl(e){const t=Ln(e),n=k.chartStateOfTagLines(t),r=t.map(k.seriesColorOf).filter(Boolean).at(-1),s=r?{color:r}:{};return n===void 0?s:n==="custom"?{chart:n,chartLines:k.chartLinesOf(t),...s}:{chart:n,...s}}function Wl(e,t){return Ln(e).some(r=>k.seriesColorOf(r)===void 0&&t([r]).tag?.tag("theme")?.tag("palette")?.tag("series")!==void 0)?{ownPalette:!0}:{}}function Fv(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:o,given:i}=r.binding;t.push({field:me.readPath(s),given:i,...o==="~"?{}:{op:o}})}return t.length>0?t:void 0}function Wv(e,t,n){const r=[];for(const s of e.givens){const o=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);o&&r.push({name:o[1],type:o[2],default:o[3].trim(),...Nv(n(Ln(sr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Nv(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...s===void 0?{}:{rangeMax:s}}}function Nl(e){const t=e?.numeric("colspan");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:!0}:{}}}function Or(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const zv=/^"((?:[^"\\]|\\.)+)"\s*(\{[\s\S]*\})?$/;function Wo(e){const t=Or(e,"colspan"),n=Or(e,"rowspan"),r=Or(e,"row"),s=Or(e,"col");return{...t===void 0?{}:{colspan:t},...e?.has("break")?{break:e.text("break")!=="false"}:{},...n===void 0?{}:{rowspan:n},...r===void 0?{}:{row:r},...s===void 0?{}:{col:s}}}function ur(e,t){const n=t.colspan??e.colspan;return{...n===void 0?{}:{colspan:n},...t.break??e.break?{break:!0}:{},...t.rowspan===void 0?{}:{rowspan:t.rowspan},...t.row===void 0?{}:{row:t.row},...t.col===void 0?{}:{col:t.col}}}const Gv=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/,Hv=/^[A-Za-z_][A-Za-z0-9_]*$/;function qv(e,t,n){const r=new RegExp(`^\\s*query\\s*:\\s*${n}\\s+is\\b`);for(let s=0;s<t.length;s++)if(!(e.commentLine(s)||e.proseLine(s))&&r.test(t[s]))return sr(e,t,s).tags;return[]}function zl(e){return{...e?.text("label")?{label:e.text("label")}:{},...e?.text("subtitle")?{subtitle:e.text("subtitle")}:{},...e?.numeric("colspan")!==void 0?{colspan:e.numeric("colspan")}:{},...e?.has("break")?{break:!0}:{},...e?.has("borderless")?{borderless:!0}:{}}}function Gl(e){const{colspan:t,break:n,...r}=e;return r}async function oo(e,t,n=!1){try{return await Uv(e)}catch(r){return{ok:!1,reason:`A value in this file's tags cannot be read (${r instanceof Error?r.message:String(r)}), so it cannot be opened in the builder.`}}}async function Uv(e){const{parseAnnotation:t}=await k.loadMalloyTag(),n=me.splitSourceLines(e),r=await uf(e);if(af(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,o=me.descriptionNotes(n).text,i=gf(s.modelNotes,t);if(i.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(i.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${i.errors[0]?`: ${i.errors[0]}`:"."}`};if(i.status==="kind-removed")return{ok:!1,reason:Rv(i.kind)};if(i.status==="cells-removed")return{ok:!1,reason:i.unknownLayout!==void 0?Av(i.unknownLayout):Lv};const a=i.layout,l=me.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!me.artifactLeads(l.text))return{ok:!1,reason:me.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:u,errors:c}=pf(t,[me.tagAnnotation(l.text)]),d=u?.tag("artifact"),f=hf(l.text);if(f===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[0]}`}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),y=[],g=[],w=new Map;for(const T of s.sources){const M={name:T.name,base:T.base};T.dimensions.length>0&&(M.dimensions=T.dimensions.map(C=>({name:C.name,expression:C.expression})));const O=new Set(T.wheres.flatMap(C=>C.clauses.flatMap(A=>A.givens)));O.size>0&&(M.scopedBy=Array.from(O)),y.push(M);for(const C of T.dimensions){const A=t(Ln(sr(s,n,C.line).tags)).tag?.tag("drill");if(!A)continue;const R=A.textArray("to")??[A.text("to")??""];g.push({source:T.name,name:C.name,expression:C.expression,to:R.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}w.set(T.name,new Map(T.views.map(C=>[C.name,C])))}const x=[],p=(T,M)=>{const O=zl(t(Ln(qv(s,n,T))).tag);return{name:T,declaration:{kind:"query"},...Gl(O),...ur({colspan:O.colspan,break:O.break},M)}};for(const{text:T}of f.entries){const M=zv.exec(T),O=M?void 0:Gv.exec(T)?.[1];if(O!==void 0){const D=t([`# ${T}`]).tag?.tag(O),I=D?.text("kind");if(I===void 0||I==="query"){x.push(p(O,Wo(D)));continue}if(I!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${O} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(L=>Ie(L)&&L.name===O))return{ok:!1,reason:`Two text tiles are named \`${O}\`, so the builder cannot tell them apart.`};x.push({kind:"text",name:O,markdown:s.textBlocks.find(L=>L.name===O)?.body??"",...ur({},Wo(D))});continue}const C=M?.[1]??T,A=Wo(M?.[2]?t([`# tile ${M[2]}`]).tag?.tag("tile")??void 0:void 0);if(Hv.test(C.trim())){x.push(p(C.trim(),A));continue}const R=M?me.tileSteps(C):void 0;if(!R)return{ok:!1,reason:`The tile \`${C}\` is neither a \`source -> view\` expression nor the name of a query, which are the forms the builder can lay out.`};const{source:B,view:G}=R,N=w.get(B)?.get(G);if(N===void 0){x.push({name:G,source:B,declaration:{kind:"inherited"},...ur({},A)});continue}const X=t(Ln(N.tags)).tag,j=N.body.kind==="reference"?{kind:"reference",from:N.body.from}:N.body.kind==="inline"?{kind:"inline"}:void 0;if(j===void 0){x.push({name:G,source:B,declaration:{kind:"opaque",why:N.body.kind==="unsupported"?N.body.why:"unreadable"},...Gl(zl(X)),...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t)});continue}const z=Fv(N.body.kind==="reference"?N.body.refinement:N.body.kind==="inline"?N.body.stage:void 0);x.push({name:G,source:B,declaration:j,...z?{filters:z}:{},...X?.text("label")?{label:X.text("label")}:{},...X?.text("subtitle")?{subtitle:X.text("subtitle")}:{},...ur(Nl(X),A),...Fl(N.tags),...Wl(N.tags,t),...X?.has("borderless")?{borderless:!0}:{}})}const v=Wv(s,n,t),_={},b=d?.tag("givens");for(const T of Object.keys(b?.dict??{})){const M=b?.text(T);M!==void 0&&(_[T]=M)}const E=u?.tag("dashboard")?.has("columns")?Or(u.tag("dashboard"),"columns"):void 0;return{ok:!0,document:{layout:a,title:d?.text("title")??"",...o?{description:o}:{},...E===void 0?{}:{columns:E},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:h,sources:y,...v?{localGivens:v}:{},...Object.keys(_).length>0?{startingGivens:_}:{},...g.length>0?{drills:g}:{},tiles:x}}}const io=e=>e.ok===!1;async function Hl(e){const{problems:t}=await Na(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function Ee(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function mf(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Kv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function Vv(e,t){let n=e;const r=t.map((s,o)=>({edit:s,index:o}));for(const{edit:s}of r.sort((o,i)=>i.edit.start-o.edit.start||i.edit.end-o.edit.end||i.index-o.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const vf=e=>e==="none"||k.isChartPick(e)?e:void 0;function yf(e,t=!0){const n=[];e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${kt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${kt(e.subtitle)}`);const r=t?vf(e.chart):void 0;return r!==void 0&&n.push(k.chartLineText(r,e.chartCarried)),e.color!==void 0&&n.push(k.seriesColorLine(e.color)),n}const xf="theme.palette.series";function Ps(e){return k.seriesColorOf(e)!==void 0?xf:/^#\s*([a-z_]+)/.exec(e)?.[1]}const Xv=new Set(["colspan","break","borderless","label","subtitle",xf]),Yv=new Set(["label","description","control","suggest","range_min","range_max"]);function ql(e){const t=[];if(e.label!==void 0&&t.push(`label=${kt(e.label)}`),e.description!==void 0&&t.push(`description=${kt(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${kt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${kt(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const Ul=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Qv(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function Kl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:kt(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(kt).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const ao=e=>`${e.source}.${e.name}`,kt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Li=e=>Ie(e)?Ee(["text",e.name]):Ee([e.name,e.source,e.declaration]),ot=Li,Vl=e=>Ee(e.tiles.map(ot));function Zv(e,t,n){const r=new Set(e.tiles.map(ot)),s=new Set(t.tiles.map(ot)),o=e.tiles.filter(h=>!s.has(ot(h))),i=t.tiles.filter(h=>!r.has(ot(h))),l=o.length>0||i.length>0||Vl(e)!==Vl(t);for(const h of i)if(ce(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const u=new Map(e.sources.map(h=>[h.name,h])),c=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)c.add(h.base);const d=t.imports.some(h=>h.kind==="all"),f=t.sources.filter(h=>!u.has(h.name));for(const h of e.sources){const y=t.sources.find(g=>g.name===h.name);if(!y||y.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of f){if(!i.some(y=>ce(y)&&y.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!c.has(h.base)&&!d&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:o,addedTiles:i,newSources:f,currentSources:u,reordered:l}}const Jv=new Set(["colspan","break"]),Bi=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break||e.rowspan!==t.rowspan||e.row!==t.row||e.col!==t.col,Xl=e=>{const{colspan:t,break:n,rowspan:r,row:s,col:o,...i}=e;return i},ey=e=>[...e.row===void 0?[]:[`row=${e.row}`],...e.col===void 0?[]:[`col=${e.col}`],...e.colspan===void 0?[]:[`colspan=${e.colspan}`],...e.break?["break"]:[],...e.rowspan===void 0?[]:[`rowspan=${e.rowspan}`]];function bf(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Fi(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Yl(e,t){const n=ey(e);if(t===void 0){const c=Ie(e)?e.name:`"${dt(e)}"`,d=[...Ie(e)?["kind=text"]:[],...n];return d.length>0?`${c} { ${d.join(" ")} }`:c}const r=bf(t),s=r.indexOf("{");if(s===-1)return n.length>0?`${t} { ${n.join(" ")} }`:t;const o=r.lastIndexOf("}");let i=t.slice(s+1,o),a=r.slice(s+1,o);const l=c=>{const d=c.exec(a);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),a=a.slice(0,d.index)+a.slice(d.index+d[0].length))};l(/\s*\bcolspan\s*=\s*[^\s}]+/),l(/\s*\bbreak\b(?:\s*=\s*[^\s}]+)?/),l(/\s*\browspan\s*=\s*[^\s}]+/),l(/\s*\brow\s*=\s*[^\s}]+/),l(/\s*\bcol\s*=\s*[^\s}]+/);const u=[i.trim(),...n].filter(Boolean);return u.length===0?t.slice(0,s).trimEnd():`${t.slice(0,s)}{ ${u.join(" ")} }${t.slice(o+1)}`}function ty(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:o,currentKeys:i,nextKeys:a,edits:l}=e,u=new Map(r.tiles.map(p=>[ot(p),p])),c=s.tiles.some(p=>{const v=u.get(ot(p));return v!==void 0&&Bi(v,p)});if(!o&&!c)return;const d=me.artifactTag(t);if(!d)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=d.text,h=hf(f);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&i.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const y=new Map;for(const{text:p}of h.entries){const v=/^"((?:[^"\\]|\\.)+)"\s*(?:\{[\s\S]*\})?$/.exec(p);if(v){const b=v[1].split("->").map(E=>E.trim());b.length===2?y.set(`${b[0]}->${b[1]}`,p):b.length===1&&y.set(`query.${b[0]}`,p);continue}if(me.isIdentifier(p)){y.set(`query.${p}`,p);continue}const _=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(p)?.[1];_!==void 0&&y.set(/\bkind\s*=\s*text\b/.test(bf(p))?`text.${_}`:`query.${_}`,p)}const g=s.tiles.map(p=>{const v=!i.has(ot(p)),_=y.get(Ie(p)?`text.${p.name}`:p.declaration.kind==="query"?`query.${p.name}`:`${p.source}->${p.name}`);if(_===void 0)return v?Yl(p):void 0;const b=u.get(ot(p));return b!==void 0&&!Bi(b,p)?_:Yl(p,_)});if(g.some(p=>p===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const w=f.slice(0,h.open).search(/tiles\s*=\s*$/),x=`${f.slice(0,w)}tiles=[${ny(f,h,g)}]${f.slice(h.close+1)}`;x!==f&&l.push({...wf(n,d),text:`${x}
78
+ `})}function wf(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function ny(e,t,n){const r=t.entries[0],s=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const o=e.slice(t.open+1,r.span.start),i=e.slice(s.span.end,t.close),a=o.slice(o.lastIndexOf(`
79
+ `)),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 ry(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Fi(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let o=1,i=n+s[0].length;for(;i<e.length&&o>0;i++)e[i]==='"'?i=Fi(e,i):e[i]==="{"?o++:e[i]==="}"&&o--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(i)}}return e}function Fi(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function sy(e){const{lines:t,wholeLine:n,current:r,next:s,edits:o}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||Ee(r.startingGivens)!==Ee(s.startingGivens)){const i=me.artifactTag(t);if(!i)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=wf(n,i),l=o.find(v=>v.start===a.start&&v.end===a.end);let u=l?l.text.replace(/\n$/,""):i.text;const c=r.layout!==s.layout,d=u.indexOf("artifact"),f=u.indexOf("{",d);let h=0,y=-1;for(let v=f;v<u.length;v++)if(u[v]==="{")h++;else if(u[v]==="}"&&--h===0){y=v;break}if(f<0||y<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let g=u.slice(f+1,y);const w=i.block?`
81
+ ${/\n([ \t]+)\S/.exec(g)?.[1]??" "}`:" ",x=v=>i.block?`${g.trimEnd()}${w}${v}
82
+ `:`${g.trimEnd()} ${v} `,p=(v,_)=>{const b=new RegExp(`${i.block?"[ \\t]*":"\\s*"}\\b${v}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(_===void 0){const E=new RegExp(`
83
83
  ${b.source}[ \\t]*(?=
84
- )`);v=v.replace(o.block&&T.test(v)?T:b,"")}else b.test(v)?v=v.replace(b,T=>`${o.block?T.slice(0,T.length-T.trimStart().length):" "}${y}=${w}`):v=_(`${y}=${w}`)};if(d&&g("layout",s.layout),r.title!==s.title&&g("title",s.title?pt(s.title):void 0),r.autorun!==s.autorun&&g("autorun",s.autorun===void 0?void 0:String(s.autorun)),xe(r.startingGivens)!==xe(s.startingGivens)){v=v.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const y=Object.entries(s.startingGivens??{});y.length>0&&(v=_(`givens { ${y.map(([w,b])=>`${w}=${pt(b)}`).join(" ")} }`))}o.block?f=`${f.slice(0,u+1)}${v}${f.slice(p)}`:(v=v.replace(/\s{2,}/g," "),f=`${f.slice(0,u+1)}${v.startsWith(" ")?v:` ${v}`}${v.endsWith(" ")?"":" "}${f.slice(p)}`),r.columns!==s.columns&&(f=sv(f,"dashboard_columns"),f=iv(f),s.columns!==void 0&&(f=`${f.trimEnd()} dashboard { columns=${s.columns} }`)),c?c.text=`${f}
85
- `:i.push({...a,text:`${f}
86
- `})}if(r.description!==s.description){const{read:o,blankAbove:a,below:c,belowBlock:f,inBlock:d}=pe.descriptionNotes(t);if(d||s.description===void 0&&f)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const l=Lu(s.description??"").split(`
87
- `).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
88
- `),u=o.length>0&&o[0]<pe.artifactLine(t),h=s.description===void 0,p=u?[...o.slice(1),...h?c:[]]:[...o,...a];for(const v of p)i.push({...n(v),text:""});if(u)i.push({...n(o[0]),text:s.description===void 0?"":`${l}
89
- `});else if(s.description!==void 0){const v=n(pe.artifactLine(t)).start;i.push({start:v,end:v,text:`${l}
90
- `})}}}function av(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.localGivens??[]).map(h=>[h.name,h])),f=new Map((i.localGivens??[]).map(h=>[h.name,h])),d=new Map(a.givens.map(h=>[h.name,h])),l=new Set;for(const[h,p]of c){const v=f.get(h);if(v!==void 0&&xe(v)===xe(p))continue;const x=d.get(h);if(x===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:_,prose:g}=Hr(a,t,x.line),w=[...(v===void 0?_:_.filter(O=>{const A=ws(O.text);return A!==void 0&&Zm.has(A)})).map(O=>O.line),...v===void 0?g:[]];for(const O of w)o.push({...n(O),text:""}),l.add(O);const b=Tt(a,x.span.end-1);if(v===void 0){o.push({start:n(x.line).start,end:n(b).end,text:""});for(let W=x.line;W<=b;W++)l.add(W);const O=Math.min(x.line,...w),A=x.blockHeader??O,j=(t[b+1]??"x").trim()==="",L=A===0||t[A-1].trim()==="",N=x.blockHeader===void 0||![...d.values()].some(W=>W.blockHeader===x.blockHeader&&W.line>x.line&&f.has([...d.entries()].find(([,V])=>V===W)?.[0]??""));j&&L&&N&&!l.has(b+1)&&(o.push({...n(b+1),text:""}),l.add(b+1));continue}const T=r(x.line),C=_l(v),E=v.type!==p.type||v.default!==p.default?x.blockHeader===void 0?kl(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(x.line,b+1).join(`
91
- `).trim();o.push({start:n(x.line).start,end:n(b).end,text:(C?`${T}${C}
92
- `:"")+`${T}${E}
93
- `})}for(const[h,p]of d){if(p.blockHeader===void 0||f.has(h))continue;![...d.values()].some(x=>x.blockHeader===p.blockHeader&&!l.has(x.line))&&!l.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),l.add(p.blockHeader))}const u=[...f.values()].filter(h=>!c.has(h.name));if(u.length>0){const h=Math.max(-1,...[...d.values()].map(y=>y.line)),p=(()=>{let y=-1;for(let w=0;w<t.length;w++){const b=t[w].trim();(b.startsWith("import ")||y>=0&&/^}\s*from\s/.test(b))&&(y=w)}return y})(),v=h>=0?h:p,x=u.map(y=>{const w=_l(y);return(w?`${w}
94
- `:"")+`${kl(y)}
84
+ )`);g=g.replace(i.block&&E.test(g)?E:b,"")}else b.test(g)?g=g.replace(b,E=>`${i.block?E.slice(0,E.length-E.trimStart().length):" "}${v}=${_}`):g=x(`${v}=${_}`)};if(c&&p("layout",s.layout),r.title!==s.title&&p("title",s.title?kt(s.title):void 0),r.autorun!==s.autorun&&p("autorun",s.autorun===void 0?void 0:String(s.autorun)),Ee(r.startingGivens)!==Ee(s.startingGivens)){g=g.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const v=Object.entries(s.startingGivens??{});v.length>0&&(g=x(`givens { ${v.map(([_,b])=>`${_}=${kt(b)}`).join(" ")} }`))}i.block?u=`${u.slice(0,f+1)}${g}${u.slice(y)}`:(g=g.replace(/\s{2,}/g," "),u=`${u.slice(0,f+1)}${g.startsWith(" ")?g:` ${g}`}${g.endsWith(" ")?"":" "}${u.slice(y)}`),r.columns!==s.columns&&(u=ry(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}=me.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=mf(s.description??"").split(`
87
+ `).map(g=>g.trim()===""?'##"':`##" ${g.trim()}`).join(`
88
+ `),f=i.length>0&&i[0]<me.artifactLine(t),h=s.description===void 0,y=f?[...i.slice(1),...h?l:[]]:[...i,...a];for(const g of y)o.push({...n(g),text:""});if(f)o.push({...n(i[0]),text:s.description===void 0?"":`${d}
89
+ `});else if(s.description!==void 0){const g=n(me.artifactLine(t)).start;o.push({start:g,end:g,text:`${d}
90
+ `})}}}function oy(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:o,edits:i,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),u=new Map((o.localGivens??[]).map(h=>[h.name,h])),c=new Map(a.givens.map(h=>[h.name,h])),d=new Set;for(const[h,y]of l){const g=u.get(h);if(g!==void 0&&Ee(g)===Ee(y))continue;const w=c.get(h);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:p}=sr(a,t,w.line),_=[...(g===void 0?x:x.filter(C=>{const A=Ps(C.text);return A!==void 0&&Yv.has(A)})).map(C=>C.line),...g===void 0?p:[]];for(const C of _)i.push({...n(C),text:""}),d.add(C);const b=Lt(a,w.span.end-1);if(g===void 0){i.push({start:n(w.line).start,end:n(b).end,text:""});for(let N=w.line;N<=b;N++)d.add(N);const C=Math.min(w.line,..._),A=w.blockHeader??C,R=(t[b+1]??"x").trim()==="",B=A===0||t[A-1].trim()==="",G=w.blockHeader===void 0||![...c.values()].some(N=>N.blockHeader===w.blockHeader&&N.line>w.line&&u.has([...c.entries()].find(([,X])=>X===N)?.[0]??""));R&&B&&G&&!d.has(b+1)&&(i.push({...n(b+1),text:""}),d.add(b+1));continue}const E=r(w.line),T=ql(g),O=g.type!==y.type||g.default!==y.default?w.blockHeader===void 0?Ul(g):`${g.name} :: ${g.type} is ${g.default}`:t.slice(w.line,b+1).join(`
91
+ `).trim();i.push({start:n(w.line).start,end:n(b).end,text:(T?`${E}${T}
92
+ `:"")+`${E}${O}
93
+ `})}for(const[h,y]of c){if(y.blockHeader===void 0||u.has(h))continue;![...c.values()].some(w=>w.blockHeader===y.blockHeader&&!d.has(w.line))&&!d.has(y.blockHeader)&&(i.push({...n(y.blockHeader),text:""}),d.add(y.blockHeader))}const f=[...u.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...c.values()].map(v=>v.line)),y=(()=>{let v=-1;for(let _=0;_<t.length;_++){const b=t[_].trim();(b.startsWith("import ")||v>=0&&/^}\s*from\s/.test(b))&&(v=_)}return v})(),g=h>=0?h:y,w=f.map(v=>{const _=ql(v);return(_?`${_}
94
+ `:"")+`${Ul(v)}
95
95
  `}).join(`
96
- `),_=v>=0?n(v).end:n(0).end;o.push({start:_,end:_,text:`
97
- ${x}`}),t.some(y=>y.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
- `})}}const Cl=(e,t)=>`import { ${e.join(", ")} } from ${pt(t)}`;function lv(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=l=>xe(l.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(xe(n.imports)===xe(r.imports))return;const a=r.imports.flatMap(l=>l.kind==="names"?[{...l,claimed:!1}]:[]),c=new Set([...r.sources.map(l=>l.base),...r.tiles.filter(ae).map(l=>l.source)]),f=t.imports.map((l,u)=>({statement:l,entry:n.imports[u]}));for(const{statement:l,entry:u}of f){if(!u||u.kind!=="names")continue;const h=a.find(y=>!y.claimed&&y.from===u.from);h&&(h.claimed=!0);const p=h?.names??[],x=u.names.filter(y=>!p.includes(y)).find(y=>c.has(y));if(x!==void 0)return{ok:!1,reason:`\`${x}\` is still read by a tile, so its import cannot be removed.`};if(xe(p)===xe(u.names))continue;const _=p.length===0?Oa(t,l.statement):l.statement,g=t.commentIn(_);if(g)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(g.start,g.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({..._,text:p.length===0?"":Cl(p,u.from)})}const d=a.filter(l=>!l.claimed);if(d.length>0){const l=t.imports.at(-1);if(!l)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const u=i(Tt(t,l.statement.end-1)).end;s.push({start:u,end:u,text:d.map(h=>`${Cl(h.names,h.from)}
99
- `).join("")})}}function cv(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,c=new Map((s.drills??[]).map(d=>[Ys(d),d])),f=new Map((i.drills??[]).map(d=>[Ys(d),d]));for(const d of new Set([...c.keys(),...f.keys()])){const l=c.get(d),u=f.get(d);if(l&&u&&xe(l)===xe(u))continue;const h=u??l;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const p=a.sources.find(g=>g.name===h.source)?.dimensions.find(g=>g.name===h.name);if(p===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:v}=Hr(a,t,p.line),x=v.find(g=>/^#\s*drill\b/.test(g.text)),_=r(p.line);if(u===void 0)x&&o.push({...n(x.line),text:""});else if(x)o.push({...n(x.line),text:`${_}${Sl(u)}
100
- `});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(je(o)||o.declaration.kind==="inherited")continue;const a=Wu(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const c=Tt(i,a.statement.start),f=Tt(i,a.statement.end-1),d=i.trailingComment(f),l=d&&d.start>=a.statement.end?d.end:a.statement.end;if(i.text.slice(i.lineStarts[c],a.statement.start).trim()!==""||i.text.slice(l,n(f).end).trim()!==""){s.push({...Oa(i,a.statement),text:""});continue}s.push({start:i.lineStarts[c],end:n(f).end,text:""});const h=c===0?"":t[c-1].trim();(t[f+1]??"x").trim()===""&&(c===0||h===""||h.endsWith("{"))&&s.push({...n(f+1),text:""})}}function uv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:c}=e,f=new Map;for(const u of s){if(je(u))continue;const h=f.get(u.source)??[];h.push(u),f.set(u.source,h)}const d=(u,h)=>{const p=u.declaration.kind==="reference"?u.declaration.from:u.name,v=(u.filters??[]).map(x=>`where: ${pe.malloyPath(x.field)} ${x.op??"~"} $${x.given}`).join(", ");return[...Fu(u).map(x=>`${h}${x}`),`${h}view: ${u.name} is ${p}${v?` + { ${v} }`:""}`].join(`
102
- `)};let l=-1;for(const u of c.sources)l=Math.max(l,Tt(c,u.span.end-1));for(const[u,h]of f)if(o.has(u)){const p=c.sources.find(w=>w.name===u);if(!p)return{ok:!1,reason:`Could not find where the source \`${u}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${u}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=p.line,x=Tt(c,p.properties.closeStart);let _=" ";for(let w=v+1;w<x;w++){const b=/^(\s+)view:/.exec(n[w]);if(b){_=b[1];break}}const g=r(x).start,y=(n[x-1]??"").trim()==="";a.push({start:g,end:g,text:(y?"":`
103
- `)+h.map(w=>d(w,_)).join(`
96
+ `),x=g>=0?n(g).end:n(0).end;i.push({start:x,end:x,text:`
97
+ ${w}`}),t.some(v=>v.trim().startsWith("##! experimental.givens"))||i.push({start:0,end:0,text:`##! experimental.givens
98
+ `})}}const Ql=(e,t)=>`import { ${e.join(", ")} } from ${kt(t)}`;function iy(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:o}=e,i=d=>Ee(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(Ee(n.imports)===Ee(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(v=>!v.claimed&&v.from===f.from);h&&(h.claimed=!0);const y=h?.names??[],w=f.names.filter(v=>!y.includes(v)).find(v=>l.has(v));if(w!==void 0)return{ok:!1,reason:`\`${w}\` is still read by a tile, so its import cannot be removed.`};if(Ee(y)===Ee(f.names))continue;const x=y.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:y.length===0?"":Ql(y,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(Lt(t,d.statement.end-1)).end;s.push({start:f,end:f,text:c.map(h=>`${Ql(h.names,h.from)}
99
+ `).join("")})}}function ay(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:o,edits:i,parsed:a}=e,l=new Map((s.drills??[]).map(c=>[ao(c),c])),u=new Map((o.drills??[]).map(c=>[ao(c),c]));for(const c of new Set([...l.keys(),...u.keys()])){const d=l.get(c),f=u.get(c);if(d&&f&&Ee(d)===Ee(f))continue;const h=f??d;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const y=a.sources.find(p=>p.name===h.source)?.dimensions.find(p=>p.name===h.name);if(y===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:g}=sr(a,t,y.line),w=g.find(p=>/^#\s*drill\b/.test(p.text)),x=r(y.line);if(f===void 0)w&&i.push({...n(w.line),text:""});else if(w)i.push({...n(w.line),text:`${x}${Kl(f)}
100
+ `});else{const p=n(y.line).start;i.push({start:p,end:p,text:`${x}${Kl(f)}
101
+ `})}}}function ly(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:o}=e;for(const i of r){if(Ie(i)||Hn(i))continue;const a=_f(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=Lt(o,a.statement.start),u=Lt(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 cy(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(Ie(f))continue;const h=u.get(f.source)??[];h.push(f),u.set(f.source,h)}const c=(f,h)=>{const y=f.declaration.kind==="reference"?f.declaration.from:f.name,g=(f.filters??[]).map(w=>`where: ${me.malloyPath(w.field)} ${w.op??"~"} $${w.given}`).join(", ");return[...yf(f).map(w=>`${h}${w}`),`${h}view: ${f.name} is ${y}${g?` + { ${g} }`:""}`].join(`
102
+ `)};let d=-1;for(const f of l.sources)d=Math.max(d,Lt(l,f.span.end-1));for(const[f,h]of u)if(i.has(f)){const y=l.sources.find(_=>_.name===f);if(!y)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!y.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const g=y.line,w=Lt(l,y.properties.closeStart);let x=" ";for(let _=g+1;_<w;_++){const b=/^(\s+)view:/.exec(n[_]);if(b){x=b[1];break}}const p=r(w).start,v=(n[w-1]??"").trim()==="";a.push({start:p,end:p,text:(v?"":`
103
+ `)+h.map(_=>c(_,x)).join(`
104
104
 
105
105
  `)+`
106
- `})}else{const p=i.find(y=>y.name===u);if(!p)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const v=`
107
- source: ${p.name} is ${p.base} extend {
108
- `+h.map(y=>d(y," ")).join(`
106
+ `})}else{const y=o.find(v=>v.name===f);if(!y)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const g=`
107
+ source: ${y.name} is ${y.base} extend {
108
+ `+h.map(v=>c(v," ")).join(`
109
109
 
110
110
  `)+`
111
111
  }
112
- `;let x=l;if(x<0)for(let y=0;y<n.length;y++){const w=n[y].trim();(/^(import\s|given:|}\s*from\s)/.test(w)||/^[A-Z_]+\s*::/.test(w))&&(x=y)}const _=x>=0?r(x).end:t.length,g=_===t.length&&!t.endsWith(`
112
+ `;let w=d;if(w<0)for(let v=0;v<n.length;v++){const _=n[v].trim();(/^(import\s|given:|}\s*from\s)/.test(_)||/^[A-Z_]+\s*::/.test(_))&&(w=v)}const x=w>=0?r(w).end:t.length,p=x===t.length&&!t.endsWith(`
113
113
  `)?`
114
- `:"";a.push({start:_,end:_,text:g+v}),l=x}}function fv(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:c}=e,f=new Map(i.tiles.map(d=>[lt(d),d]));for(const d of o.tiles){const l=f.get(lt(d));if(l===void 0||je(d)||je(l)||xe(Xs(l))===xe(Xs(d)))continue;if(d.declaration.kind==="inherited")return{ok:!1,reason:`\`${d.source} -> ${d.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const u=Jm(c,d.source,d.name);if(u<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:h}=Hr(c,t,u),p=s(u),v=Fu(d,!1),x=new Map(v.map(E=>[ws(E)??E,E])),_=new Set,g=Bu(d.chart),y=Ol(l)!==Ol(d);if(y){const E=h.filter(j=>S.mentionsChartTag(j.text)),O=h.filter(j=>S.parseChartLine(j.text)),A=l.chart==="custom"?h.filter(j=>S.parseChartLine(j.text)||S.mentionsChartTag(j.text)):E.length>0?E:O.length>1?O:[];if(A.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${A.map(j=>j.text).join(" and ")}), so its chart cannot be changed here.`}}let w=!1;for(const E of h){if(y&&S.parseChartLine(E.text)){g===void 0?a.push({...r(E.line),text:""}):E.text!==S.chartLineText(g,d.chartCarried)&&a.push({...r(E.line),text:`${p}${S.chartLineText(g,d.chartCarried)}
115
- `}),w=!0;continue}const O=ws(E.text);if(O===void 0||!Qm.has(O))continue;const A=x.get(O);if(A===void 0){a.push({...r(E.line),text:""});continue}_.add(O),A!==E.text&&a.push({...r(E.line),text:`${p}${A}
116
- `})}const b=v.filter(E=>!_.has(ws(E)??E));if(y&&g!==void 0&&!w&&b.push(S.chartLineText(g,d.chartCarried)),b.length>0){const E=n[u];a.push({start:E,end:E,text:b.map(O=>`${p}${O}
117
- `).join("")})}if(xe(l.filters)===xe(d.filters))continue;const T=Wu(e,d);if(!T)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(T.body.kind==="reference"){const E=bv(e,d,T);if(E)return E;continue}if(T.body.kind!=="inline")return{ok:!1,reason:`\`${d.name}\`'s body is ${T.body.why}, so there is no single first stage to write its filter into.`};const C=Nu(d.filters,T.body.stage);if(C)return Gu(d.name,C.given);const M=Uu(e,d,T.body.stage);if(M)return M}}const Ol=e=>e.chart==="default"?void 0:e.chart,Xs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function hv(e,t){const n=new Map(e.tiles.map(r=>[lt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(lt(r));return ae(r)&&r.chart===void 0&&s&&ae(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function _s(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function pv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!pe.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=_s(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const Ci=e=>`##|(markdown) ${e.name}
114
+ `:"";a.push({start:x,end:x,text:p+g}),d=w}}function dy(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:o,next:i,edits:a,parsed:l}=e,u=new Map(o.tiles.map(c=>[ot(c),c]));for(const c of i.tiles){const d=u.get(ot(c));if(d===void 0||Ie(c)||Ie(d))continue;const f=Bi(d,c),h=Ee(Xl(lo(d)))!==Ee(Xl(lo(c)));if(!h&&!f)continue;if(c.declaration.kind==="inherited"){if(!h)continue;return{ok:!1,reason:`\`${dt(c)}\` is declared on its source, not in this report, so its presentation cannot be changed here.`}}if(c.declaration.kind==="query"){if(!h)continue;return{ok:!1,reason:`\`${c.name}\` names a query, whose presentation is the query's own, so it cannot be changed here.`}}const y=Qv(l,c.source,c.name);if(y<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:g}=sr(l,t,y),w=s(y),x=yf(c,!1),p=new Map(x.map(A=>[Ps(A)??A,A])),v=new Set,_=vf(c.chart),b=Zl(d)!==Zl(c);if(b){const A=g.filter(G=>k.mentionsChartTag(G.text)),R=g.filter(G=>k.parseChartLine(G.text)),B=d.chart==="custom"?g.filter(G=>k.parseChartLine(G.text)||k.mentionsChartTag(G.text)):A.length>0?A:R.length>1?R:[];if(B.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${B.map(G=>G.text).join(" and ")}), so its chart cannot be changed here.`}}let E=!1;for(const A of g){if(b&&k.parseChartLine(A.text)){_===void 0?a.push({...r(A.line),text:""}):A.text!==k.chartLineText(_,c.chartCarried)&&a.push({...r(A.line),text:`${w}${k.chartLineText(_,c.chartCarried)}
115
+ `}),E=!0;continue}const R=Ps(A.text);if(R===void 0||!Xv.has(R))continue;if(Jv.has(R)){f&&a.push({...r(A.line),text:""});continue}const B=p.get(R);if(B===void 0){a.push({...r(A.line),text:""});continue}v.add(R),B!==A.text&&a.push({...r(A.line),text:`${w}${B}
116
+ `})}const T=x.filter(A=>!v.has(Ps(A)??A));if(b&&_!==void 0&&!E&&T.push(k.chartLineText(_,c.chartCarried)),T.length>0){const A=n[y];a.push({start:A,end:A,text:T.map(R=>`${w}${R}
117
+ `).join("")})}if(Ee(d.filters)===Ee(c.filters))continue;const M=_f(e,c);if(!M)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(M.body.kind==="reference"){const A=vy(e,c,M);if(A)return A;continue}if(M.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${M.body.why}, so there is no single first stage to write its filter into.`};const O=kf(c.filters,M.body.stage);if(O)return Sf(c.name,O.given);const C=$f(e,c,M.body.stage);if(C)return C}}const Zl=e=>e.chart==="default"?void 0:e.chart,lo=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...o}=r;return o};function uy(e,t){const n=new Map(e.tiles.map(r=>[ot(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(ot(r));return ce(r)&&r.chart===void 0&&s&&ce(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function js(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function fy(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!me.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=js(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const No=e=>`##|(markdown) ${e.name}
118
118
  ${e.markdown===""?"":`${e.markdown}
119
119
  `}|##
120
- `;function gv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,c=new Map(s.tiles.filter(je).map(h=>[h.name,h])),f=i.tiles.filter(je),d=h=>o.textBlocks.find(p=>p.name===h),l=new Set(f.map(h=>h.name));for(const h of c.keys()){const p=l.has(h)?void 0:d(h);if(!p)continue;const v=Tt(o,p.span.end-1);a.push({...p.span,text:""});const x=r(v+1),_=p.line===0||n[p.line-1].trim()==="";x.end>x.start&&n[v+1].trim()===""&&_?a.push({...x,text:""}):p.line>0&&_&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const u=[];for(const h of f){const p=c.get(h.name),v=d(h.name);if(p===void 0){if(v)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};u.push(Ci(h))}else p.markdown!==h.markdown&&(v?a.push({...v.span,text:Ci(h)}):u.push(Ci(h)))}if(u.length>0){const h=o.textBlocks.filter(g=>g.name===void 0||l.has(g.name)),p=h[h.length-1],v=o.sources.find(g=>g.name.endsWith("_tiles"));if(p){const g=p.span.end,y=t.slice(g);a.push({start:g,end:g,text:`
121
- ${u.join(`
122
- `)}${y===""||y.startsWith(`
120
+ `;function hy(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:o,parsed:i,edits:a}=e,l=new Map(s.tiles.filter(Ie).map(h=>[h.name,h])),u=o.tiles.filter(Ie),c=h=>i.textBlocks.find(y=>y.name===h),d=new Set(u.map(h=>h.name));for(const h of l.keys()){const y=d.has(h)?void 0:c(h);if(!y)continue;const g=Lt(i,y.span.end-1);a.push({...y.span,text:""});const w=r(g+1),x=y.line===0||n[y.line-1].trim()==="";w.end>w.start&&n[g+1].trim()===""&&x?a.push({...w,text:""}):y.line>0&&x&&t.slice(y.span.end).trim()===""&&a.push({...r(y.line-1),text:""})}const f=[];for(const h of u){const y=l.get(h.name),g=c(h.name);if(y===void 0){if(g)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(No(h))}else y.markdown!==h.markdown&&(g?a.push({...g.span,text:No(h)}):f.push(No(h)))}if(f.length>0){const h=i.textBlocks.filter(p=>p.name===void 0||d.has(p.name)),y=h[h.length-1],g=i.sources.find(p=>p.name.endsWith("_tiles"));if(y){const p=y.span.end,v=t.slice(p);a.push({start:p,end:p,text:`
121
+ ${f.join(`
122
+ `)}${v===""||v.startsWith(`
123
123
  `)?"":`
124
- `}`});return}if(v){const g=e.starts[o.blockStart(v.line)],y=g===0||t.slice(0,g).endsWith(`
124
+ `}`});return}if(g){const p=e.starts[i.blockStart(g.line)],v=p===0||t.slice(0,p).endsWith(`
125
125
 
126
- `);a.push({start:g,end:g,text:`${y?"":`
127
- `}${u.join(`
126
+ `);a.push({start:p,end:p,text:`${v?"":`
127
+ `}${f.join(`
128
128
  `)}
129
- `});return}const x=t.length,_=t===""||t.endsWith(`
129
+ `});return}const w=t.length,x=t===""||t.endsWith(`
130
130
 
131
131
  `)?"":t.endsWith(`
132
132
  `)?`
133
133
  `:`
134
134
 
135
- `;a.push({start:x,end:x,text:_+u.join(`
136
- `)})}}const ls=(e,t=pe.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function mv(e,t){const n=new Map(e.tiles.map(o=>[lt(o),o]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const o of t.tiles){const a=n.get(lt(o));if(je(o)){const l=pv(o,a&&je(a)?a:void 0,r);if(l)return l;continue}const c=a&&ae(a)?a:void 0;if(a&&!c)continue;const f=o.chart;if(f!==void 0&&f!=="default"&&f!=="none"&&!S.isChartPick(f)&&!(f==="custom"&&c?.chart==="custom"))return`"${String(f)}" is not a chart this editor writes.`;const d=new Set(c?.filters?.map(l=>l.field));for(const l of o.filters??[])if(!d.has(l.field)&&/[\r\n]/.test(l.field))return"A filter field is one line.";if(a===void 0){const l=[o.name,o.source];o.declaration.kind==="reference"&&l.push(o.declaration.from);for(const u of l){const h=ls(u);if(h)return h}}for(const l of["label","subtitle"]){const u=o[l];if(u===void 0||u===c?.[l])continue;const h=S.annotationTextProblem(`tile ${l}`,u);if(h)return h}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const c=ls(a);if(c)return c}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=S.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=S.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const f=ls(o.name,pe.isStrictName);if(f)return f}const c=o.suggest?.source;if(c!==void 0&&c!==a?.suggest?.source){const f=ls(c);if(f)return`The suggest source is not a name. ${f}`}for(const f of["query","dimension"]){const d=o.suggest?.[f];if(d===void 0||d===a?.suggest?.[f])continue;const l=S.annotationTextProblem(`suggest ${f}`,d);if(l)return l}for(const f of["label","description"]){const d=o[f];if(d===void 0||d===i.get(o.name)?.[f])continue;const l=S.annotationTextProblem(`given ${f}`,d);if(l)return l}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const c=S.annotationTextProblem(`starting value for ${o}`,a);if(c)return c}}const Tt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wu(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Nu(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Gu(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const ks=e=>`where: ${pe.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Dl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function vv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(Tt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function yv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Oa(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
- `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Uu(e,t,n){const{parsed:r,edits:s}=e,i=new Map((t.filters??[]).map(u=>[u.given,u])),o=new Set;let a;for(const u of n.wheres){const h=u.clauses.map((v,x)=>({clause:v,index:x})).filter(({clause:v})=>v.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:v})=>i.has(v.binding.given));for(const{clause:v}of h)o.add(v.binding.given);if(p.length===0&&h.length===u.clauses.length){const v=Oa(r,u.span),x=vv(r,u.span,v);if(x)return Dl(t.name,r,x);s.push({...v,text:""});continue}p.length>0&&(a=u.span);for(let v=h.length-1;v>=0;v--){const{clause:x,index:_}=h[v],g=i.get(x.binding.given);if(!g){const w=yv(u.clauses,_),b=r.commentIn(w);if(b)return Dl(t.name,r,b);s.push({...w,text:""});continue}const y=ks(g).replace(/^where:\s*/,"");y!==r.text.slice(x.span.start,x.span.end)&&s.push({...x.span,text:y})}}const c=(t.filters??[]).filter(u=>!o.has(u.given));if(c.length===0)return;let f=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const u=r.trailingComment(Tt(r,f));u&&u.start>=f&&(f=u.end)}const d=a!==void 0&&!/,\s*$/.test(r.text.slice(0,f))?", ":" ",l=n.oneLine?`${d}${c.map(ks).join(", ")}`:c.map(u=>`
138
- ${n.indent}${ks(u)}`).join("");s.push({start:f,end:f,text:l})}function bv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Nu(t.filters,i);if(o)return Gu(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const d=` + { ${a.map(ks).join(", ")} }`;r.push({start:s.end,end:s.end,text:d});return}const c=i.wheres.some(d=>d.clauses.some(l=>!l.binding)),f=i.statements.some(d=>!i.wheres.some(l=>l.span.start===d.span.start));if(a.length===0&&!c&&!f){const d={start:s.end,end:i.span.end},l=e.parsed.commentIn(d);if(l)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(l.start,l.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...d,text:""});return}return Uu(e,t,i)}async function Hu(e,t,n={}){if(!(e.includes(`\r
139
- `)&&!/(?<!\r)\n/.test(e)))return Ml(e,t,n);const s=await Ml(e.replace(/\r\n/g,`
140
- `),t,n);return qs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
- `)}}async function Ml(e,t,n){const r=await Ks(e);if(Hs(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=hv(s,t),o=ev(s,i,n.visibleSources);if("reason"in o)return o;const a=mv(s,i);if(a)return{ok:!1,reason:a};const c=await Iu(e);if(Cu(c))return{ok:!1,reason:`Cannot edit a file that will not open: ${c.reason}`};const f=e.split(`
142
- `),d=Ym(e),l=g=>({start:d[g],end:g+1<d.length?d[g+1]:e.length}),u=g=>/^\s*/.exec(f[g])?.[0]??"",h=[],p={...o,sourceText:e,parsed:c.parsed,lines:f,starts:d,wholeLine:l,indentOf:u,current:s,next:i,edits:h};for(const g of[nv,ov,lv,av,cv,dv,uv,fv,gv]){const y=g(p);if(y)return y}const v=g=>{const{drills:y,localGivens:w,description:b,...T}=g,C=g.tiles.map(M=>{if(je(M))return M;if(M.filters?.length)return Xs(M);const{filters:E,...O}=M;return Xs(O)});return{...T,...b===void 0?{}:{description:Lu(b)},tiles:C,...y?.length?{drills:[...y].sort((M,E)=>Ys(M).localeCompare(Ys(E)))}:{},...w?.length?{localGivens:w}:{}}};if(h.length===0)return xe(v(s))!==xe(v(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const x=Xm(e,h);if((await wl(e)).length===0){const g=await wl(x);if(g.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${g[0]}). Your changes are still here.`}}const _=await Ks(x);return Hs(_)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${_.reason}`}:xe(v(_.document))!==xe(v(i))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:x}}function Vu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Se.usePublisherTheme(),i=s.ui,o=k.useId(),[a,c]=k.useState(!1),f=k.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:d,patch:l,close:u,discard:h}=Hl(f,a,w=>n(w.text),()=>c(!1)),p=a&&d!==void 0&&d.text!==e,v=d!==void 0&&d.text!==e?_s(d.text):void 0;hu(p,()=>v!==void 0?!1:(u(),!0));const x=k.useRef(!1);k.useEffect(()=>{a||(x.current=!1)},[a]);const _=k.useCallback(w=>{!w||x.current||(x.current=!0,w.setSelectionRange(w.value.length,w.value.length))},[]);if(!a||d===void 0){const w=e.trim()?_s(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():c(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),c(!0)))},sx:[{minHeight:24},uu(s,"prose")],children:[e.trim()?m.jsx(S.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),w&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:w})]})}const g=d.text!==e?_s(d.text):void 0,y=()=>{g===void 0&&u()};return m.jsxs($.Box,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx($.InputBase,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:d.text,placeholder:t,error:g!==void 0,inputRef:_,inputProps:{"aria-label":"Markdown","aria-describedby":o,...g!==void 0?{"aria-invalid":!0}:{}},onChange:w=>l(b=>{b.text=w.target.value}),onKeyDown:w=>{w.key==="Escape"?(w.preventDefault(),h(),c(!1)):w.key==="Enter"&&(w.metaKey||w.ctrlKey)&&(w.preventDefault(),y())},onBlur:()=>u(),sx:{p:0,...i.type.prose,color:"inherit",maxWidth:S.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),g!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g}),m.jsxs($.Typography,{id:o,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",Xt,"↩ done · Esc cancels"]})]})}const xv="Write markdown: # heading, **bold**, - list";function wv({tile:e,onChange:t}){return m.jsx(S.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Vu,{markdown:e.markdown,placeholder:xv,onCommit:t})})}const _v={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Ku=(e,t)=>t===0?e:Ku(t,e%t);function kv(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Ku(e,t),s=_v[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function Sv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:c,onRemove:f,removeBlocked:d,resizing:l=!1,width:u,onResizeStart:h,onResizeMove:p,onResizeEnd:v,children:x}){const{theme:_}=Se.usePublisherTheme(),g=_.ui;return m.jsx(xm,{id:Fe(e),index:t,children:({ref:y,handleRef:w})=>m.jsxs($.Box,{ref:y,onClick:a,onPointerDown:b=>{b.button===0&&a()},role:"group",className:S.reportClasses.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...qu(_,{selected:n,flash:r,bare:i}),...!i&&{[`& .${S.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:_.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${_.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...S.removeBadgeRevealSx,...n&&{[`& .${S.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[x,m.jsx($.Box,{ref:w,"aria-label":`Move ${Yn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(S.RemoveBadge,{label:`Remove ${Yn(e)}`,onRemove:f,...d?{disabledReason:d}:{},inset:i?S.BARE_RING_OFFSET_PX:0}),!je(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Yn(e)}`,onClick:b=>{b.stopPropagation(),c(b.currentTarget)},sx:{position:"absolute",top:i?0:`${Il}px`,right:i?0:`${Il}px`,borderRadius:g.radius.control,width:28,height:28,zIndex:2,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(Cv,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${S.reportClasses.widthHandle}`,[Eu]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Yn(e)}`,...u?{"aria-valuenow":u.span,"aria-valuemin":1,"aria-valuemax":u.columns,"aria-valuetext":`${u.span} of ${u.columns} columns`}:{},onKeyDown:b=>{if(!u)return;const T=b.key==="ArrowRight"?u.span+1:b.key==="ArrowLeft"?u.span-1:b.key==="Home"?1:b.key==="End"?u.columns:void 0;T!==void 0&&(b.preventDefault(),b.stopPropagation(),u.onStep(Math.min(Math.max(T,1),u.columns)))},onPointerDown:h,onPointerMove:p,onPointerUp:v,onPointerCancel:v,onClick:b=>b.stopPropagation(),sx:b=>({position:"absolute",top:0,bottom:0,right:"-8px",width:"16px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:l||n?1:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${_.accent}`,outlineOffset:1,borderRadius:"3px"},"&::before":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"12px",height:"40px",boxSizing:"border-box",borderRadius:g.radius.control,border:`1px solid ${l?_.accent:S.edgeColor(_.cardBorder)}`,bgcolor:b.palette.background.paper,boxShadow:"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",transition:`border-color ${S.MOTION_FAST}`},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"5px",height:"16px",borderLeft:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,borderRight:`1.5px solid ${l?_.accent:b.palette.text.secondary}`,boxSizing:"border-box",opacity:l?1:.7},"&:hover::before":{borderColor:_.accent},"&:hover::after":{borderColor:_.accent,opacity:1}}),children:l&&u&&m.jsx($.Box,{"aria-hidden":!0,sx:b=>({position:"absolute",top:"50%",right:"50%",transform:"translateY(calc(-100% - 28px))",px:1,py:.5,borderRadius:g.radius.control,bgcolor:b.palette.text.primary,color:b.palette.background.paper,...g.type.label,whiteSpace:"nowrap",pointerEvents:"none"}),children:kv(u.span,u.columns)})}),o&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Yn(e)}`,onClick:b=>{b.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${S.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:_.tileTitle,bgcolor:_.tile,border:_.cardBorder,opacity:0,transition:`opacity ${S.MOTION_FAST}`,...S.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:_.tile}},children:m.jsx(S.AddIcon,{sx:{fontSize:14}})})]})})}const Il=14,Oi=7,qu=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=S.BARE_RING_OFFSET_PX})=>{const i=e.ui,o=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,c=`outline-color ${S.MOTION_FAST}, border-color ${S.MOTION_FAST}, opacity ${S.MOTION_FAST}, box-shadow ${S.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof s=="number"?`${-s}px`:`${-s.y}px ${-s.x}px`,borderRadius:1,border:`2px solid ${o}`,...a&&{boxShadow:a},pointerEvents:"none",transition:c,...S.reducedMotionSx}}:{borderRadius:i.radius.tile,"& > .MuiPaper-root":{transition:c,...S.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:c,...S.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:S.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function $v({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Se.usePublisherTheme();return m.jsxs(S.TileCard,{chrome:r,children:[m.jsx(S.TileHeading,{title:t?.title??kn(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Tv({after:e}){const{theme:t}=Se.usePublisherTheme();return m.jsx(wm,{id:gu(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx($.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...S.reducedMotionSx}})})}function Ev({columns:e}){const{theme:t}=Se.usePublisherTheme();return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${S.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>m.jsx($.Box,{sx:{bgcolor:t.accent,opacity:.06,borderRadius:"3px"}},r))})}function Cv(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function Ov({editor:e,reorder:t,resizing:n,gridBox:r,defaultSpan:s=1,rules:i,canAdd:o,selected:a,flash:c,menuIndex:f,onSelect:d,onOpenMenu:l,onRemove:u,removeBlocked:h,openAdd:p,editTile:v,renderTile:x}){const{dragging:_,preview:g,onDragStart:y,onDragOver:w,onDragEnd:b}=t,{columns:T}=i,{resize:C,startResize:M,onResize:E,endResize:O}=n,A=V=>V.colspan===void 0?{...V,colspan:s}:V,j=(C!==void 0?e.document.tiles.map((V,I)=>I===C.index?{...V,colspan:C.span}:V):g??e.document.tiles).map(A),L=e.document.tiles.length===0,N=_||C!==void 0?zg(j,T):j.map(pu),W=V=>Dv(V,kn(V),v);return m.jsxs(m.Fragment,{children:[m.jsx(wg,{sensors:vm,onDragStart:y,onDragOver:w,onDragEnd:b,children:m.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[i.widths&&(_||C!==void 0)&&m.jsx(Ev,{columns:T}),m.jsx(S.DashboardGrid,{tiles:N,columns:T,rowGapPx:S.GRID_GAP_PX,keyOf:V=>V.kind==="gap"?gu(V.after):Fe(V.tile),renderTile:V=>{if(V.kind==="gap")return m.jsx(Tv,{after:V.after});const{tile:I,index:F}=V;return m.jsx(Sv,{tile:I,index:F,selected:F===a,flash:Fe(I)===c,menuOpen:f===F,bare:je(I),...i.insertBetween&&o&&F<e.document.tiles.length-1?{onInsertAfter:()=>p(F+1)}:{},...i.widths&&Mv(I)?{resizing:C?.index===F,width:{span:I.colspan??1,columns:T,onStep:H=>{H!==(I.colspan??1)&&e.update(B=>{const G=B.tiles[F];G&&(G.colspan=H)})}},onResizeStart:H=>M(H,F),onResizeMove:E,onResizeEnd:O}:{},onSelect:()=>d(F),onOpenMenu:H=>l(H,F),onRemove:()=>u(F),...h?{removeBlocked:h}:{},children:je(I)?m.jsx(wv,{tile:I,onChange:H=>v(Fe(I),B=>{je(B)&&(B.markdown=H)})}):x?x(I,W(I),"card"):m.jsx($v,{tile:I,heading:W(I)})})}})]})}),i.insertBetween&&o&&!L&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Dv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{ae(a)&&(o===""?delete a[i]:a[i]=o)});return{title:m.jsx(_o,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(_o,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Mv=e=>je(e)||e.declaration.kind!=="inherited",Iv={x:12,y:6};function jv({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:i}=Se.usePublisherTheme();return m.jsx(S.ReportHeader,{actions:n,title:m.jsx(_o,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(S.TextTileFrame,{sx:{position:"relative",overflow:"visible",...qu(i,{selected:r,bare:!0,ringOffset:Iv})},children:m.jsx(Vu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const Pv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=S.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:c})=>i({type:"report.saved",tiles:o,structural:a,where:r,durationMs:c}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:c})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:c}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}};function Rv(e,t){const n=k.useRef(t);n.current=t;const r=k.useRef(e);r.current=e;const s=k.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.()}),[]),{status:i,saveTarget:o,canUndo:a,canRedo:c,add:{filterUnavailable:f}}=t,d=t.save!==void 0,l=t.add.tile!==void 0,u=t.add.text!==void 0,h=t.add.filter!==void 0,p=t.exit!==void 0,v=t.done!==void 0,x=t.discard!==void 0,{draftKeptAt:_}=t,g=t.restored?.savedAt,y=t.restored?.stale??!1,w=t.restored?.pending??!1,b=t.restore!==void 0,T=t.dismissRestored!==void 0,C=k.useMemo(()=>({status:i,saveTarget:o,...d?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:c,redo:s.redo,add:{...l?{tile:s.addTile}:{},...u?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...p?{exit:s.exit}:{},...v?{done:s.done}:{},..._!==void 0?{draftKeptAt:_}:{},...x?{discard:s.discard}:{},...g!==void 0?{restored:{savedAt:g,stale:y,pending:w}}:{},...b?{restore:s.restore}:{},...T?{dismissRestored:s.dismissRestored}:{}}),[s,i,o,d,a,c,l,u,h,f,p,v,_,x,g,y,w,b,T]),M=e!==void 0;k.useEffect(()=>{r.current?.(C)},[C,M]),k.useEffect(()=>()=>r.current?.(void 0),[])}function Av({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:i,fixedFilters:o,onOpenModel:a,startingValues:c,onStartingValue:f,children:d}){const l=d!=null,u=k.useMemo(()=>{const h=new Map(e.map(p=>[p.name,p]));return{stateOf:p=>{const v=o?.get(p);if(v!==void 0){const{modelPath:g}=v;return{origin:"model",fixed:v.reason,...g!==void 0&&a?{openModel:()=>a(g)}:{}}}const x=h.get(p);if(!x)return;const _=t(x.name,x.type);return{origin:x.origin,..._.length>0?{problem:`Cannot filter on ${_.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:l?e.filter(p=>p.boundTiles===0&&!o?.has(p.name)).map(p=>({name:p.name,label:p.label??p.name})):[],onEdit:p=>{const v=h.get(p);v&&n(v)},onRemove:i,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...f?{startingValueOf:p=>c?.[p],setStartingValue:f}:{}}},[e,t,l,n,i,r,s,o,a,c,f]);return m.jsx(S.StickyControls,{children:m.jsx(S.FilterEditingContext.Provider,{value:u,children:l?d:m.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(h=>m.jsx(S.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(S.AddFilterButton,{})]})})})}function Lv(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Bv({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(x=>r(_=>typeof _=="object"&&_.tile===x?_:{tile:x}),[]),a=k.useCallback(()=>r(x=>x==="description"?x:void 0),[]),c=k.useCallback(()=>r("description"),[]),f=k.useCallback(()=>r(void 0),[]),d=n!==void 0;k.useEffect(()=>{if(!d)return;const x=_=>{const g=_.target;g instanceof Element&&g!==document.documentElement&&g.closest(Fv)===null&&f()};return document.addEventListener("pointerdown",x,!0),()=>document.removeEventListener("pointerdown",x,!0)},[d,f]);const[l,u]=k.useState(void 0),h=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const x=p.current;if(p.current=e.document,!h.current)return;h.current=!1;const _=Lv(x,e.document);if(_===void 0)return;u(_),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(y=>y.dataset.tileKey===_)?.scrollIntoView?.({block:"nearest",behavior:S.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(l===void 0)return;const x=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(x)},[l]);const v=k.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:c,clearSelection:f,flash:l,stepEditor:v}}const Fv=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function zv({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,c]=k.useState(!1),f=k.useRef(r);f.current=r;const d=k.useRef(s);d.current=s;const l=k.useRef(0),u=k.useCallback(async()=>{const v=++l.current;c(!1),o("saving");try{await f.current()}catch{l.current===v&&o("idle");return}l.current===v&&c(!0)},[]);k.useEffect(()=>{if(i==="waiting"){if(t)return;e?u():(o("idle"),d.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[i,a,t,e,u]);const h=k.useCallback(()=>{i==="idle"&&(e?o("asking"):d.current())},[i,e]),p=k.useCallback(()=>{i==="idle"&&(e?n?t?o("waiting"):u():o("asking"):d.current())},[i,e,n,t,u]);return{requestExit:h,saveAndExit:p,finishing:i==="saving"||i==="waiting",dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):u())}}}}function Wv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,keepsEdits:o=!1,report:a,unit:c,prepare:f,shortcuts:d}){const[l,u]=k.useState(!1),[h,p]=k.useState(!1),v=k.useRef(null),x=k.useRef(a);x.current=a;const _=e.dirty||i,g=(e.edited??e.dirty)||i,y=o?i:g;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(g,y)},[g,y,n]);const w=k.useRef(n);w.current=n,k.useEffect(()=>()=>w.current?.(!1,!1),[]);const b=k.useRef(c);b.current=c,k.useEffect(()=>{p(!1)},[e.document]);const T=k.useCallback(()=>{u(!0),p(!1);const I=S.now(),{structural:F}=e,H=x.current.size;return e.save().then(B=>{B.ok===!0?x.current.saved({size:H,structural:F,durationMs:S.now()-I}):x.current.refused(B.reason)}).finally(()=>u(!1))},[e]),C=k.useRef(!1),M=k.useRef(!1);k.useEffect(()=>{!M.current||l||(M.current=!1,v.current?.focus())},[h,l]);const E=k.useCallback(()=>{if(!t||l||C.current||!e.canUndoSave)return;C.current=!0,u(!0);const I=S.now(),F=e.lastSave?.structural??!1,H=x.current.size;return e.undoSave().then(B=>{B.ok===!0?(M.current=!0,p(!0),x.current.undone({size:H,structural:F,durationMs:S.now()-I})):x.current.undoRefused(B.reason)}).finally(()=>{C.current=!1,u(!1)})},[t,l,e]),O=k.useCallback(()=>{if(!(!t||!e.dirty||l))return T()},[t,e,l,T]),A=k.useRef(O);A.current=O;const j=k.useCallback(()=>{const I=()=>A.current();return f?f(I):I()},[f]),L=zv({dirty:g,saving:l,canSave:!!t,save:j,onExit:()=>r?.()});rf(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:j}:{},paused:L.dialog.open}),[d,e,t,j,L.dialog.open]));const N=!!t&&!l&&e.canUndoSave,W=e.lastSave,V={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:_,saving:l,saveButton:v,...t?{onSave:j}:{},...r?{onExit:L.requestExit}:{}};return{saving:l,save:j,exitGuard:L,...r?{done:L.saveAndExit}:{},undoSave:E,canUndoSave:N,lastSave:W,toolbarProps:V}}const Nv=1;function Yu(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Yu(a,`${t}${i}.`,n-1))}}}return r}function Gv(e){const t=new Map;for(const n of Xu(e))t.set(n.name,Yu(n.schema?.fields,"",Nv));return t}function Xu(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Uv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&ef.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Hv(e){const t=new Map;for(const n of Xu(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Uv)&&r.add(s.name)}t.set(n.name,r)}return t}function jl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Pl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.path||e.modelPath||"";function Qu(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=S.exportedSources(a.modelInfo);i.set(a,f);for(const{name:d}of a.sources??[])d&&o.set(d,[...o.get(d)??[],c]);for(const d of f)s.set(d,[...s.get(d)??[],c])}for(const a of e){const c=Rl(a);if(Pl(c,t))continue;const f=Gv(a),d=Hv(a);for(const l of a.sources??[]){const u=l.name;if(!u||!i.get(a)?.has(u)||r.has(u))continue;r.add(u);const h=(l.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:u,modelPath:c,exporters:s.get(u)??[c],visibleIn:o.get(u)??[c],...S.docOf(l.annotations)?{description:S.docOf(l.annotations)}:{},views:(l.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...S.docOf(p.annotations)?{description:S.docOf(p.annotations)}:{},...S.chartOf(p.annotations)?{chart:S.chartOf(p.annotations)}:{},...d.get(u)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:f.get(u)??[]})}}return{sources:n}}function Vv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const p=new Set((t.localGivens??[]).map(v=>v.name));return(n??[]).filter(v=>!p.has(v.name))},[t,n]),a=k.useMemo(()=>bf(e.document,o),[e.document,o]),c=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,jl(r,p.base)])),[r,e.document.sources]),f=k.useCallback(p=>c.get(p.source)??jl(r,p.source),[c,r]),d=(p,v)=>{const x=[];for(const _ of e.document.tiles){if(!ae(_))continue;const g=f(_);if(!g)continue;const y=new Map(g.map(w=>[w.name,w.type]));for(const w of _.filters??[])w.given===p&&(!y.has(w.field)||!mr(v,y.get(w.field)))&&x.push(`${w.field} on ${_.label??_.name} (${e.document.sources.find(b=>b.name===_.source)?.base??_.source})`)}return x},l=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:f,unknownFieldsOf:d,available:l,applyFilter:(p,v,x)=>{i(void 0),e.update(_=>{x&&Ef(_,x),Tf(_,p,v)})},dropControl:p=>{i(void 0),e.update(v=>Cf(v,p))}}}function Kv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[i,o]=k.useState({stack:[e.document],index:0}),[a,c]=k.useState(e.source),[f,d]=k.useState(void 0),[l,u]=k.useState(e.document),[h,p]=k.useState(e.replaces),[v,x]=k.useState(!1),_=i.stack[i.index],g=k.useRef(i);g.current=i;const y=k.useRef(!1),[w,b]=k.useState(!1),T=B=>{y.current=B,b(B)},[C,M]=k.useState(void 0),E=k.useCallback(B=>{d(void 0),o(G=>{const ee=structuredClone(G.stack[G.index]);if(B(ee),JSON.stringify(ee)===JSON.stringify(G.stack[G.index]))return G;const J=[...G.stack.slice(0,G.index+1),ee].slice(-100);return{stack:J,index:J.length-1}})},[]),O=k.useCallback(()=>{d(void 0),o(B=>B.index>0?{...B,index:B.index-1}:B)},[]),A=k.useCallback(()=>{d(void 0),o(B=>B.index<B.stack.length-1?{...B,index:B.index+1}:B)},[]),j=k.useCallback(async(B,G)=>{try{return await t(B,G)}catch(ee){return{ok:!1,reason:`Could not build the file: ${ee instanceof Error?ee.message:String(ee)}`}}},[t]),L=k.useCallback(async()=>{if(y.current)return{ok:!1,reason:"A save is still being written."};const B={source:a,saved:l,history:g.current,replacing:h,unwritten:v},G=s?.(l,_)??!1,ee=r?.(l,_)??!1;T(!0);try{const Q=await j(a,_);if(qs(Q))return d(Q.reason),{ok:!1,reason:Q.reason};try{await n?.(Q.source,{purpose:"save",document:_})}catch(X){const te=`Could not save: ${X instanceof Error?X.message:String(X)}`;return d(te),{ok:!1,reason:te}}c(Q.source),u(_),p(void 0),x(!1);const J=G?{stack:[_],index:0}:B.history;return o(X=>X===B.history?J:G?{stack:[X.stack[X.index]],index:0}:X),M(n?{before:B,after:J,lastSave:{before:h??a,after:Q.source,structural:ee,clearsHistory:G}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[_,j,n,a,l,h,v,s,r]),N=k.useCallback(async()=>{if(y.current)return{ok:!1,reason:"A save is still being written."};if(!n||C===void 0||C.after!==g.current)return{ok:!1,reason:"There is no save to undo."};const{before:B}=C;T(!0);try{await n(B.replacing??B.source,{purpose:"undo",document:B.saved})}catch(G){const ee=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return d(ee),{ok:!1,reason:ee}}finally{T(!1)}return c(B.source),u(B.saved),p(B.replacing),x(B.unwritten||B.replacing!==void 0),o(G=>G===C.after?B.history:G),M(void 0),d(void 0),{ok:!0}},[n,C]),W=k.useMemo(()=>v||JSON.stringify(_)!==JSON.stringify(l),[_,l,v]),V=k.useMemo(()=>r?.(l,_)??!1,[_,l,r]),I=k.useMemo(()=>s?.(l,_)??!1,[_,l,s]),F=C!==void 0&&C.after===i,H=k.useCallback(async()=>{const B=await j(a,_);return qs(B)?{ok:!1,reason:B.reason}:{ok:!0,source:B.source}},[_,j,a]);return{document:_,saved:l,source:a,canUndo:i.index>0,canRedo:i.index<i.stack.length-1,dirty:W,edited:W,...f===void 0?{}:{error:f},update:E,undo:O,redo:A,save:L,preview:H,structural:V,clearsHistory:I,canUndoSave:F&&!w&&n!==void 0,...F?{lastSave:C.lastSave}:{},undoSave:N}}const qv=(e,t)=>{const n=new Set(e.tiles.map(To)),r=new Set(t.tiles.map(To));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Yv(e){const{visibleSources:t,...n}=e,r=k.useCallback((s,i)=>Hu(s,i,t?{visibleSources:t}:{}),[t]);return Kv({...n,splice:r,structural:qv})}function Xv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(c=>{s.current=()=>c(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}function Qv({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(!1),[d,l]=k.useState(void 0),u=b=>{l(b),f(!0)},h=()=>f(!1),p=b=>{f(!1),e.update(T=>cf(T,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:d})),s(d??e.document.tiles.length)},v=()=>_(d),x=()=>_(void 0),_=b=>{f(!1),e.update(T=>{const C=new Set(T.tiles.filter(je).map(E=>E.name));let M=1;for(;C.has(`text_${M}`);)M++;T.tiles.splice(b??T.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}})}),s(b??e.document.tiles.length)};return{menu:o,setMenu:a,addingTile:c,openAdd:u,closeAdd:h,addTile:p,addText:v,appendText:x,editTile:(b,T)=>e.update(C=>{const M=C.tiles.find(E=>Fe(E)===b);M&&T(M)}),removeTile:b=>{a(void 0),i(),e.update(T=>{T.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const T=e.document.tiles[b],C=T&&ae(T)&&Es(T)===void 0?b+1:void 0;e.update(M=>{df(M,b)}),C!==void 0&&s(C)}}}var Zv=Object.defineProperty,Jv=Object.defineProperties,ey=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,ty=Object.prototype.hasOwnProperty,ny=Object.prototype.propertyIsEnumerable,Ll=(e,t,n)=>t in e?Zv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,un=(e,t)=>{for(var n in t||(t={}))ty.call(t,n)&&Ll(e,n,t[n]);if(Al)for(var n of Al(t))ny.call(t,n)&&Ll(e,n,t[n]);return e},fn=(e,t)=>Jv(e,ey(t));function ry(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function cs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Di(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function sy(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const c=(y,w)=>y===w||y!==null&&typeof y=="object"&&"id"in y&&y.id===w;if(Array.isArray(e)){const y=e.findIndex(b=>c(b,i.id)),w=e.findIndex(b=>c(b,o.id));if(y===-1||w===-1){if(Di(i)){const b=i.initialIndex,T=i.index;return b===T||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,T)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const b=i.index;if(b!==y)return n(e,y,b)}return n(e,y,w)}const f=Object.entries(e);let d=-1,l,u=-1,h;for(const[y,w]of f)if(d===-1&&(d=w.findIndex(b=>c(b,i.id)),d!==-1&&(l=y)),u===-1&&(u=w.findIndex(b=>c(b,o.id)),u!==-1&&(h=y)),d!==-1&&u!==-1)break;if(d===-1&&Di(i)){const y=i.initialGroup==null?void 0:cs(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:cs(e,i.group),T=i.index;if(y==null||b==null||y===b&&w===T)return"preventDefault"in t&&t.preventDefault(),e;if(y===b)return fn(un({},e),{[y]:n(e[y],w,T)});const C=e[y][w];return fn(un({},e),{[y]:[...e[y].slice(0,w),...e[y].slice(w+1)],[b]:[...e[b].slice(0,T),C,...e[b].slice(T)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,v=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const y=cs(e,o.id);if(y!=null){const w=o.shape&&v.y>o.shape.center.y?e[y].length:0;h=y,u=w}}if(l==null||h==null||l===h&&d===u){if(l!=null&&l===h&&d===u&&Di(i)){const y=i.group==null?void 0:cs(e,i.group),w=i.group!=null&&y!==l,b=i.index!==d;if(w||b){const T=i.group==null?l:y;if(T!=null){if(l===T)return fn(un({},e),{[l]:n(e[l],d,i.index)});const C=e[l][d];return fn(un({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[T]:[...e[T].slice(0,i.index),C,...e[T].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(l===h)return fn(un({},e),{[l]:n(e[l],d,u)});const _=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[l][d];return fn(un({},e),{[l]:[...e[l].slice(0,d),...e[l].slice(d+1)],[h]:[...e[h].slice(0,u+_),g,...e[h].slice(u+_)]})}function iy(e,t){return sy(e,t,ry)}function oy({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:l=>{const{source:u,target:h}=l.operation;if(!u||!h)return;const p=i.current??e;let v;if(h.type===Tu){const{after:x}=h.data,_=p.findIndex(w=>Fe(w)===u.id);if(_<0||x===u.id)return;const y=p.filter((w,b)=>b!==_).findIndex(w=>Fe(w)===x)+1;v=Fg(p,_,y)}else{const x=p.map(Fe),_=iy(x,l);if(_.every((y,w)=>y===x[w]))return;const g=new Map(p.map(y=>[Fe(y),y]));v=Bg(_.map(y=>g.get(y)),e.map(y=>y.break??!1))}i.current=v,s(v)},onDragEnd:l=>{a(!1);const u=i.current;if(i.current=void 0,s(void 0),l.canceled||!u)return;t(u);const h=u.findIndex(p=>Fe(p)===l.operation.source?.id);h>=0&&n(h)}}}const Mi=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function ay({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),c=u=>{a.current=u,o(u)};return k.useEffect(()=>()=>Mi(!1),[]),{resize:i,startResize:(u,h)=>{const p=n.current?.getBoundingClientRect(),v=u.currentTarget.parentElement?.getBoundingClientRect();if(!p||!v)return;u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Mi(!0),r(h);const x=e[h]?.colspan??1;c({index:h,span:x,from:x,left:v.left,track:(p.width-S.GRID_GAP_PX*(t-1))/t})},onResize:u=>{const h=a.current;if(!h)return;const p=u.clientX-h.left,v=Math.round((p+S.GRID_GAP_PX)/(h.track+S.GRID_GAP_PX)),x=Math.min(Math.max(v,1),t);x!==h.span&&c({...h,span:x})},endResize:u=>{u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Mi(!1);const h=a.current;if(!h)return;const{index:p,span:v,from:x}=h;c(void 0),!(u.type==="pointercancel"||v===x)&&s(p,v)}}}function Da({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,renderViewPreview:a,controls:c,givens:f,catalog:d,toolbar:l,dashboards:u,onEvent:h,savesTo:p="package",saveLabel:v,replaces:x,modelPath:_,visibleSources:g,addFilterDisabledReason:y,fixedFilters:w,onOpenModel:b,takenGivenNames:T,onControlsChange:C,draftKey:M}){const E=Yv({source:e,document:t,...n?{onSave:n}:{},...x!==void 0?{replaces:x}:{},...g?{visibleSources:g}:{}}),O=S.useReportDraft(M,E,e),A=k.useRef(null),{selected:j,descriptionSelected:L,selectTile:N,deselectTile:W,selectDescription:V,clearSelection:I,flash:F,stepEditor:H}=Bv({editor:E,gridBox:A}),B=S.layoutRules(E.document.layout,E.document.columns),{columns:G}=B,ee=_?.split("/").at(-1)?.replace(/\.malloy$/,""),Q=oy({tiles:E.document.tiles,commit:K=>E.update(ie=>{ie.tiles=K}),onLanded:N}),{dragging:J}=Q,X=S.useDefaultTileSpan(A,G),te=k.useMemo(()=>E.document.tiles.map(K=>K.colspan===void 0?{...K,colspan:X}:K),[E.document.tiles,X]),we=ay({tiles:te,columns:G,gridBox:A,onStart:N,commit:(K,ie)=>E.update(_e=>{const oe=_e.tiles[K];oe&&(oe.colspan=ie)})}),me=Qv({editor:E,rules:B,modelPath:_,textHeld:g!==void 0,selectTile:N,deselectTile:W}),{menu:ye,addingTile:$e,openAdd:ue}=me,ve=Vv({editor:E,opened:t,givens:f,catalog:d}),{filterDialog:Z,setFilterDialog:Ue}=ve,[fe,le]=k.useState(void 0),{draftDirty:Le,openDraft:We,prepare:he}=Xv({editorDirty:E.dirty}),Ne=k.useMemo(()=>({escape:()=>{!ye&&!Z&&!$e&&fe===void 0&&I()},nudge:K=>{if(J||j===void 0||!B.widths)return;const ie=E.document.tiles[j];if(!ie||ae(ie)&&ie.declaration.kind==="inherited")return;const _e=S.nudgedSpan(ie.colspan??X,K,G);_e!==(ie.colspan??X)&&E.update(oe=>{oe.tiles[j].colspan=_e})}}),[X,E,ye,Z,$e,fe,I,j,G,B,J]),Oe=Wv({editor:H,extraDirty:Le,keepsEdits:M!==void 0&&O.keeping,prepare:he,unit:{name:"tile",count:K=>K.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:Ne,report:Pv({size:E.document.tiles.length,path:_??"",layout:E.document.layout,savesTo:p,onEvent:h})}),D=E.document.tiles.length===0,{toolbarProps:R}=Oe,z=O.restored,P={status:Oe.saving?"saving":R.dirty?"unsaved":"saved",saveTarget:v??Ri[p],...O.keptAt!==void 0?{draftKeptAt:O.keptAt}:{},...(R.dirty||z?.pending)&&M!==void 0?{discard:O.discard}:{},...z?{restored:z}:{},...z&&!z.pending?{dismissRestored:O.dismissRestored}:{}};Rv(C,{...P,...R.onSave?{save:R.onSave}:{},canUndo:R.canUndo,undo:R.onUndo,canRedo:R.canRedo,redo:R.onRedo,add:{...d?{tile:()=>me.openAdd()}:{},text:me.appendText,...y!==void 0?{filterUnavailable:y}:D?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>Ue({})}},...R.onExit?{exit:R.onExit}:{},...Oe.done?{done:Oe.done}:{},...z?.pending?{restore:O.restoreOffered}:{}});const U=C?void 0:m.jsx(sf,{...Oe.toolbarProps,...l?{actions:l}:{},...d?{onAddTile:()=>ue()}:{},savesTo:p,...v?{saveLabel:v}:{},...M!==void 0&&R.onSave?{saveStatus:P}:{}});return m.jsx(fu.Provider,{value:We,children:m.jsx($.Stack,{className:S.reportClasses.builder,"data-saves-to":p,sx:{gap:0,mx:`-${Oi}px`},children:m.jsxs(S.ReportPage,{layout:B.layout,sx:{px:`${Oi}px`,pb:`${Oi}px`},header:m.jsx(jv,{editor:E,documentSlug:ee,actions:U,descriptionSelected:L,selectDescription:V}),controls:D?void 0:m.jsx(Av,{controls:ve.controlList,unknownFieldsOf:ve.unknownFieldsOf,onEdit:K=>Ue({control:K}),onAdd:()=>Ue({}),...y?{addDisabledReason:y}:{},onRemove:ve.dropControl,...w?{fixedFilters:w}:{},...b?{onOpenModel:b}:{},...E.document.startingGivens?{startingValues:E.document.startingGivens}:{},onStartingValue:(K,ie)=>E.update(_e=>{const oe={..._e.startingGivens??{}};ie===void 0?delete oe[K]:oe[K]=ie,Object.keys(oe).length>0?_e.startingGivens=oe:delete _e.startingGivens}),children:c}),children:[D&&m.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),d&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),onClick:()=>ue(),children:"Add tile"})]}),z?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:O.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:O.discard,children:"Discard"})]}),children:`You have unsaved edits from ${ji(z.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),E.error&&m.jsx($.Alert,{severity:"warning",children:E.error}),m.jsx(Ov,{editor:E,reorder:Q,resizing:we,gridBox:A,defaultSpan:X,rules:B,canAdd:!!d,selected:j,flash:F,menuIndex:ye?.index,onSelect:N,onOpenMenu:(K,ie)=>{N(ie),me.setMenu({anchor:K,index:ie})},onRemove:me.removeTile,...E.document.tiles.length===1&&E.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:ue,editTile:me.editTile,...o?{renderTile:o}:{}}),m.jsx(Bf,{editor:E,catalog:d,columns:G,dashboards:u,bindings:ve,tiles:me,drillSource:fe,setDrillSource:le,exitDialog:Oe.exitGuard.dialog,...a?{renderViewPreview:a}:{},...T?{takenGivenNames:T}:{}})]})})})}const ly=S.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),cy=S.createSvgIcon(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),dy=S.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function uy({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=Se.usePublisherTheme(),i=S.edgeColor(s.cardBorder),o=S.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,c]=k.useState(null),f=e?.save!==void 0&&e.status!=="saved",d=e?.done??n,l=f&&e?.done===void 0,u=e?.add,h=u!==void 0&&(u.tile!==void 0||u.text!==void 0||u.filter!==void 0||u.filterUnavailable!==void 0),p=v=>()=>{c(null),v?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:S.reportClasses.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(Nl,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Ss(s.ui),children:m.jsx(Wl,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${Xt}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Ss(s.ui),children:m.jsx(zl,{fontSize:"small"})})})}),h&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),endIcon:m.jsx(S.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:v=>c(v.currentTarget),sx:{...gr(i,o),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>c(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:fy(i,s.ui)}},MenuListProps:{sx:{p:.5}},children:[u?.tile&&m.jsx(Ii,{icon:m.jsx(cy,{}),title:"Tile",detail:"A view from the model",onClick:p(u.tile)}),u?.text&&m.jsx(Ii,{icon:m.jsx(dy,{}),title:"Text",detail:"Prose between the tiles",onClick:p(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(Ii,{icon:m.jsx(ly,{}),title:"Filter",detail:u.filterUnavailable??"A control the tiles read",disabled:u.filter===void 0,onClick:p(u.filter)})]})]})]})]}),(d||l)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:$s}),d&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&f?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:l?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:d,sx:{...gr(i,o,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&l&&m.jsx($.Tooltip,{title:`Save (${Xt}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...gr(i,o,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const fy=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Ii({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:i}=Se.usePublisherTheme(),o=i.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:o.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:o.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:i.accent,bgcolor:`color-mix(in srgb, ${i.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...o.type.control,fontWeight:o.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...o.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function hy(e,t,n=new Set){const r=new Set;for(const o of e.tiles)for(const a of ae(o)?o.filters??[]:[])r.add(a.given);const s=[],i=new Set;for(const o of e.localGivens??[])r.has(o.name)&&(i.add(o.name),s.push(S.localGivenSpec(o)));for(const o of t)o.name===void 0||i.has(o.name)||!(r.has(o.name)||n.has(o.name))||(i.add(o.name),s.push(o));return s}function py(e,t,n){const r=new Map;for(const i of t.tiles)ae(i)&&r.set(_n(`${i.source} -> ${i.name}`),new Set((i.filters??[]).map(o=>o.given)));const s=new Set;for(const i of e.tiles){if(!ae(i))continue;const o=_n(`${i.source} -> ${i.name}`),a=r.get(o);for(const c of n.get(o)??[])a?.has(c)||s.add(c)}return s}function gy(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function my(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function _n(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function vy(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(x=>[x.name,x.type])),c=new Map((e.localGivens??[]).map(x=>[x.name,x.default])),f=e.sources.find(x=>x.name===i)?.scopedBy??[],d=new Set([...f,...s??[]].filter(x=>n.has(x))),l=new Set([...f,...s??[]]),u=[];for(const x of t.filters??[]){const _=`where: ${pe.malloyPath(x.field)} ${x.op??"~"}`;if(n.has(x.given)){d.add(x.given),l.add(x.given),u.push(`${_} $${x.given}`);continue}if(!a.has(x.given))continue;l.add(x.given);const g=S.malloyLiteral(r.get(x.given),a.get(x.given))??gy(c.get(x.given));g!==void 0&&u.push(`${_} ${g}`)}const h=u.join(", "),p=t.chart,v=p==="none"||S.isChartPick(p)?S.chartLineText(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
- `):p==="default"&&my(t.declaration)?S.chartLineText("none"):void 0;return{...v?{annotation:v}:{},expression:`${i} -> ${o}`+(h?` + { ${h} }`:""),givenNames:Array.from(d),reads:s||l.size>0?Array.from(l):void 0}}function yy({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=Se.useServer(),{data:c}=S.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(p=>p.path&&!p.error?[p.path]:[])}),f=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),d=k.useMemo(()=>i?(c??[]).filter(p=>!f.has(p)):[],[c,f,i]),l=Fl.useQueries({queries:d.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),u=c!==void 0&&i&&l.every(p=>p.isSuccess||p.isError),h=l.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>u?Qu(l.flatMap((p,v)=>p.data?[{...p.data,path:d[v]}]:[]),f):void 0,[u,d,h,f])}const by={};function xy({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,queryVersionId:i,opened:o,replaces:a,onSave:c,onDirtyChange:f,onExit:d,onOpenModel:l,onControlsChange:u,draftKey:h,onEvent:p,savesTo:v,saveLabel:x,note:_}){const{apiClients:g}=Se.useServer(),[y,w]=k.useState(o.document.tiles.length>0);k.useEffect(()=>w(o.document.tiles.length>0),[o.generation,o.document]);const{data:b,isSuccess:T,isError:C}=S.useQueryWithApiError({...S.reportQueryOptions(g,{environmentName:t,packageName:n,path:r,versionId:i},S.BUILDER_HANDOFF_STALE_MS),enabled:y&&!e}),M=e?.modelPath??r,E=_y(o.source,e?.compileSource),O=S.useCompiledDocument({environmentName:t,packageName:n,modelPath:M,source:E.text??o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&E.text!==void 0}),A=O.data?.document,j=e?O.isSuccess?A?.manifest??by:void 0:b,L=e?O.isSuccess:T,N=e?O.isError||E.problem!==void 0:C,W=e?S.documentPreamble(A?.cells):void 0,V=(O.data?.result.problems??[]).filter(P=>P.severity==="error"),I=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),F=e?.givens,H=k.useMemo(()=>new Set((j?.tiles??[]).flatMap(P=>P.restricted&&P.query?[_n(P.query)]:[])),[j]),{reports:B,settled:G}=S.useReportListing(t,n,i),ee=k.useMemo(()=>B.map(P=>P.path).filter(P=>!!P&&P!==r&&P.endsWith(".malloy")).map(P=>P.replace(/\.malloy$/,"")),[B,r]),Q=yy({environmentName:t,packageName:n,...i!==void 0?{versionId:i}:{},modelPath:r,reports:B,reportsSettled:G}),J=k.useMemo(()=>e?(Q?.sources??[]).filter(P=>(P.visibleIn??P.exporters??[P.modelPath]).includes(M)).map(P=>P.name):void 0,[Q,e,M]),X=k.useMemo(()=>Q&&J?{sources:Q.sources.filter(P=>J.includes(P.name))}:Q,[Q,J]),[te,we]=k.useState(o.document);k.useEffect(()=>we(o.document),[o.document]);const me=k.useMemo(()=>c&&(async(P,U)=>{await c(P,U.document.layout),v==="package"&&w(U.document.tiles.length>0)}),[c,v]),ye=k.useMemo(()=>(j?.givens??[]).filter(P=>!(e&&P.secure===!0)&&!(P.name!==void 0&&I.has(P.name))),[j,I,e]),$e=k.useMemo(()=>new Set([...ye.map(P=>P.name).filter(P=>P!==void 0),...Object.keys(F??{})]),[ye,F]),ue=k.useMemo(()=>new Map((j?.tiles??[]).flatMap(P=>P.kind!=="text"&&P.query&&P.givenNames?[[_n(P.query),P.givenNames]]:[])),[j]),ve=k.useMemo(()=>py(te,o.document,ue),[te,o.document,ue]),Z=k.useMemo(()=>hy(te,ye,ve),[te,ye,ve]),Ue=k.useMemo(()=>{const P=new Set(te.tiles.flatMap(oe=>ae(oe)?(oe.filters??[]).map(Ge=>Ge.given):[])),U=new Set((te.localGivens??[]).map(oe=>oe.name)),K=[...new Set(te.imports.map(oe=>oe.from))],ie=K.length===1?ky(r,K[0]):K.length===0&&e?e.modelPath:void 0,_e=oe=>{const Ge=te.sources.filter(et=>et.scopedBy?.includes(oe)).map(et=>et.name);return Ge.length>0?{reason:`Applied to every tile on ${Ge.join(", ")} by this report's own source. Edit the file to change it.`}:U.has(oe)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:ie!==void 0?{reason:`Set in the model ${ie}. Edit the model to change it.`,modelPath:ie}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ve].filter(oe=>!P.has(oe)).map(oe=>[oe,_e(oe)]))},[te,ve,e,r]),{declaredTypes:fe,applied:le,panel:Le}=S.useDocumentControls({specs:Z,loaded:L,startingValues:j?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:j?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?M:j?.path,versionId:i,documentName:r,...W!==void 0?{preamble:W}:{},...F?{hostGivens:F}:{}}),We=k.useMemo(()=>S.missingRequiredGivens(Z,le,F),[Z,le,F]),he=k.useMemo(()=>Object.fromEntries(Object.entries(F??{}).filter(([P])=>!fe.has(P))),[F,fe]),Ne=!y||L||N,Oe=e!==void 0&&(E.problem!==void 0||O.isError||V.length>0),D=k.useMemo(()=>new Map(o.document.tiles.map(P=>[Fe(P),P])),[o.document]),R=k.useMemo(()=>function(U,K,ie="card"){if(Oe)return m.jsxs(S.TileCard,{chrome:ie,children:[m.jsx(S.TileHeading,{title:K?.title??kn(U),subtitle:K?K.subtitle:U.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!Ne)return m.jsxs(S.TileCard,{chrome:ie,children:[m.jsx(S.TileHeading,{title:K?.title??kn(U),subtitle:K?K.subtitle:U.subtitle}),m.jsx(S.Loading,{text:"Running…"})]});const _e=ue.get(_n(`${U.source} -> ${U.name}`)),Ge=W===void 0&&_e!==void 0&&wy(D.get(Fe(U)),U)?{expression:`${U.source} -> ${U.name}`,givenNames:[..._e],reads:[..._e]}:vy(te,U,$e,le,_e);return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:i,modelPath:M,...W!==void 0?{preamble:W}:{},...H.has(_n(`${U.source} -> ${U.name}`))?{restricted:!0}:{},tile:Ge.expression,...Ge.annotation?{annotation:Ge.annotation}:{},label:kn(U),chrome:ie,subtitle:U.subtitle,...K?{heading:K}:{},borderless:U.borderless,givens:le,hostGivens:he,declaredTypes:fe,givenNames:Ge.givenNames,...(()=>{const et=S.waitingOn(We,Ge.reads??Ge.givenNames);return et.length>0?{waitingFor:S.waitingText(et)}:{}})(),ignoredFilters:S.tileIgnoredFilterLabels(Ge.reads,Z),height:S.TILE_MAX_HEIGHT})},[te,D,Ne,Oe,We,$e,ue,t,n,i,M,W,H,le,he,fe,Z]),z=k.useMemo(()=>function(U){return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:i,modelPath:U.modelPath,tile:`${U.base} -> ${U.view}`,...U.chart?{annotation:S.chartLineText(U.chart,U.chartCarried)}:{},label:U.label,borderless:!0,givens:le,hostGivens:he,declaredTypes:fe,givenNames:U.givens,height:200})},[t,n,i,le,he,fe]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&V.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",V.map(P=>P.message).join("; ")]}),We.length>0&&!Oe&&m.jsx($.Alert,{severity:"info",children:S.requiredPrompt(We)}),e&&E.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",E.problem]}),e&&O.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",O.error?.message]}),m.jsx(Da,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,fixedFilters:Ue,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:R,renderViewPreview:z,givens:Z.filter(P=>P.name!==void 0).map(P=>({name:P.name,...P.label?{label:P.label}:{},...P.type?{type:P.type}:{},...P.suggest?.dimension?{field:P.suggest.dimension}:{}})),onChange:we,onDirtyChange:f,...d?{onExit:d}:{},...l?{onOpenModel:l}:{},...u?{onControlsChange:u}:{},...h!==void 0?{draftKey:h}:{},...X?{catalog:X}:{},dashboards:ee,...p?{onEvent:p}:{},controls:L?m.jsx(S.GivensPanel,{...Le,layout:"bar"}):void 0,...me?{onSave:me}:{},savesTo:v,...x?{saveLabel:x}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:J}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:_})})]})}function wy(e,t){return e!==void 0&&JSON.stringify(Bl(e))===JSON.stringify(Bl(t))}function Bl(e){const{label:t,subtitle:n,colspan:r,break:s,borderless:i,...o}=e;return o}function _y(e,t){const n=k.useRef(t);n.current=t;const r=t!==void 0,[s,i]=k.useState();return k.useEffect(()=>{if(!r)return;let o=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{o&&i({from:e,text:a})},a=>{o&&i({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{o=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function ky(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Sy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[c,f]=k.useState(void 0),[d,l]=k.useState(e===void 0),[u,h]=k.useState(!1),[p,v]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let x=!1;return v(void 0),(async()=>{try{const _=S.chooseWorkspace(await e.listWorkspaces(!1));if(x)return;if(a(_),_!==void 0&&(!n||_.authoritative)){const g=await e.getDocument(S.locatorFor(t,_.name,r,s,i)).catch(y=>{if(!S.isDocumentNotFound(y))throw y});if(x)return;f(g),h(g!==void 0)}}catch(_){if(x)return;v(S.storageErrorMessage(_))}x||l(!0)})(),()=>{x=!0}},[e,t,n,r,s,i]),{workspace:o,draft:c,setDraft:f,draftChecked:d,offered:u,setOffered:h,readFailure:p}}const $y=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Ty(e){const t=await Ks(e);return Hs(t)?{ok:!1,reason:$y(t.reason,t.line)}:{ok:!0,document:t.document}}const Ey="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Cy="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Oy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:c,notebook:f,noun:d,legacyFormat:l,textHeld:u,startedAt:h,onEventRef:p}){const v=k.useRef({path:a,layout:c});v.current={path:a,layout:c};const x=k.useRef((le,Le)=>{try{p.current?.(S.withReportContext(le,{...v.current,...Le?{layout:Le}:{}}))}catch{}}),_=e?.authoritative===!0,g=_&&r!==void 0,[y,w]=k.useState(void 0),b=(_||y===!0)&&t!==void 0,[T,C]=k.useState(void 0),[M,E]=k.useState(l?Ey:void 0),O=k.useRef(void 0),A=k.useRef(void 0),[j,L]=k.useState(void 0),N=k.useRef(i);N.current=i;const W=j!==void 0&&j.onFetch===i?j.text:s,V=k.useRef(W);V.current=W;const I=b?t:W,[F,H]=k.useState(!1),[B,G]=k.useState(void 0),[ee,Q]=k.useState(void 0),J=I!==void 0&&I!==ee,X=T?.source,we=J&&(F||!_&&t!==void 0&&X===t&&t!==W)&&X!==void 0&&I!==B,me=we?X:J?I:X??I,ye=we?I:void 0,$e=k.useRef(X);$e.current=X;const ue=k.useRef(I);ue.current=I;const ve=k.useRef("package");ve.current=b?_?"record":"draft":"package",k.useEffect(()=>{if(me===void 0||!n||g||me===$e.current)return;let le=!1;const Le=V.current,We=ue.current;return Ty(me).then(he=>{if(!le){if(he.ok===!1){E(he.reason),x.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}E(void 0),O.current=void 0,A.current=Le,L(void 0),G(void 0),Q(We),C(Ne=>({source:me,document:he.document,...Le!==void 0?{packageText:Le}:{},generation:(Ne?.generation??0)+1})),x.current({type:"report.opened",surface:"edit",from:ve.current,tiles:he.document.tiles.length,durationMs:S.now()-h.current},he.document.layout)}}).catch(he=>{if(le)return;const Ne=`Could not read the ${d}: ${he instanceof Error?he.message:String(he)}`;E(Ne),x.current({type:"report.load_failed",surface:"edit",category:S.failureCategory(he)})}),()=>{le=!0}},[me,a,n,g,f,d,u,h]),k.useEffect(()=>{l&&x.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[l]),k.useEffect(()=>{!u||!n||T||r!==void 0||(_?t===void 0&&E("the host's storage has no document at this location."):E("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[u,n,T,r,_,t]);const Z=f&&!u&&!T&&n&&!b&&o&&s===void 0;return k.useEffect(()=>{Z&&(E(Cy),x.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:_,blockedOnRecord:g,resume:y,setResume:w,fromDraft:b,opened:T,setOpened:C,openError:M,savedHashRef:O,packageBaseRef:A,setWrote:L,fetchedAtRef:N,setDirty:H,setSeen:Q,held:ye,choose:le=>{h.current=S.now(),G(le?t:W),w(le)},acceptHeld:()=>{h.current=S.now(),G(ye)}}}function Dy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:c,queryClient:f,mutable:d,textHeld:l,readFailure:u,authoritative:h,resume:p,setResume:v,setOpened:x,setDraft:_,setOffered:g,setSeen:y,setWrote:w,savedHashRef:b,packageBaseRef:T,fetchedAtRef:C}){const M=k.useCallback(B=>t===void 0?void 0:S.locatorFor(B,t.name,s,i,o),[t,s,i,o]),E=M(n),O=k.useCallback(async(B,G=n)=>{const ee=M(G);if(!e||!ee)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(ee,B),x(Q=>Q&&{...Q,source:B}),_(B),(h||p===!0)&&y(B),h||v(Q=>Q??!1)},[e,M,n,h,p,x,_,y,v]),[A,j]=k.useState(void 0),L=k.useCallback(async B=>{const G=await S.expectedHashFor(b.current,T.current);if(G===void 0)throw new Error("The package file is still loading; try again.");const ee=["dashboard-editor-model",s,i,o,a,r];await S.writePackageFile({apiClients:c,queryClient:f,environmentName:s,packageName:i,modelPath:o,source:B,expectedHash:G,invalidateOnError:[ee],afterWrite:async Q=>{if(x(J=>J&&{...J,source:B}),w({text:B,onFetch:C.current}),y(B),b.current=Q,j(void 0),e&&E)try{await e.deleteDocument(E),_(void 0),g(!1)}catch(J){S.isDocumentNotFound(J)?(_(void 0),g(!1)):j(S.storageErrorMessage(J))}v(!1)},invalidate:[{queryKey:ee,wait:!0},{queryKey:S.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})}]}),S.invalidateReportQueries(f,s,i,o)},[c,s,i,o,a,r,e,E,f,b,T,C,x,w,y,_,g,v]),N=t?.writeable===!0,W=d===!0&&!l,{savesTo:V,pinnedPackageSave:I,writer:F}=S.saveTarget({authoritative:h,mutable:W,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!E&&N&&(!r||h),readFailed:u!==void 0});return{save:F==="storage"?O:F==="package"?L:void 0,savesTo:V,writer:F,pinnedPackageSave:I,takesWrites:W,supersedeFailure:A}}function Ma(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:i,onControlsChange:o,keepDraft:a,kind:c,path:f,textSource:d,queryVersionId:l}=e,u=e.layout??(c?S.layoutOfKind(c):"grid"),h=u==="linear",p=d!==void 0,{environmentName:v,packageName:x,versionId:_,namesBoth:g}=S.resolveEditorTarget(e),w=("resourceUri"in e?e.dashboard:e.dashboardName)??S.documentSlug(f)??"",b="report",{apiClients:T,mutable:C,isLoadingStatus:M,server:E}=Se.useServer(),O=Fl.useQueryClient(),A=k.useRef(S.now()),j=k.useRef(t);j.current=t;const L=k.useRef(r);L.current=r;const N=S.useOptionalDocumentStorage()?.documentStorage,W=f??S.legacyNamedPath(c??"dashboard",w),V=/\.malloynb$/i.test(W)||h&&/\.malloynb$/i.test(w),I=S.useQueryWithApiError({queryKey:["dashboard-editor-model",v,x,W,_,h],queryFn:()=>T.models.getModel(v,x,W,_,h?!0:void 0),enabled:g&&!V&&!p}),F=I.data?.data?.sourceText,{workspace:H,draft:B,setDraft:G,draftChecked:ee,offered:Q,setOffered:J,readFailure:X}=Sy({storage:N,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:W}),{authoritative:te,blockedOnRecord:we,resume:me,setResume:ye,fromDraft:$e,opened:ue,setOpened:ve,openError:Z,savedHashRef:Ue,packageBaseRef:fe,setWrote:le,fetchedAtRef:Le,setDirty:We,setSeen:he,held:Ne,choose:Oe,acceptHeld:D}=Oy({workspace:H,draft:B,draftChecked:ee,readFailure:X,packageText:F,fetchedAt:I.dataUpdatedAt,packageSettled:I.isSuccess&&!I.isFetching,modelPath:W,layout:u,notebook:h,noun:b,legacyFormat:V,textHeld:p,startedAt:A,onEventRef:j}),{save:R,savesTo:z,writer:P,pinnedPackageSave:U,takesWrites:K,supersedeFailure:ie}=Dy({storage:N,workspace:H,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:W,versionId:_,apiClients:T,queryClient:O,mutable:C,textHeld:p,readFailure:X,authoritative:te,resume:me,setResume:ye,setOpened:ve,setDraft:G,setOffered:J,setSeen:he,setWrote:le,savedHashRef:Ue,packageBaseRef:fe,fetchedAtRef:Le}),_e=H?.name,oe=k.useCallback(Vn=>{j.current?.(S.withWorkspace(Vn,_e))},[_e]),Ge=I.isError&&!ue,et=k.useRef(!1);k.useEffect(()=>{!Ge||et.current||(et.current=!0,S.reportEmitter({path:W,layout:u},j.current).emit({type:"report.load_failed",surface:"edit",category:S.failureCategory(I.error)}))},[Ge,I.error,W,u]);const Vr=k.useCallback((Vn,ce)=>{We(Vn),L.current?.(ce)},[We]),rn=a?S.reportDraftKey({server:E,environmentName:v,packageName:x,versionId:_,path:f??w}):void 0,sn=z==="host"&&H?.description?H.description:void 0,Kr=!te&&!p&&C===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":S.saveCaption({authoritative:te,mutable:K,pinnedPackageSave:U,...H?{workspace:H}:{},...X!==void 0?{readFailure:X}:{},..._!==void 0?{versionId:_}:{}}),ci=z==="package"&&K===!0&&!U&&X===void 0||Kr===sn?"":Kr;if(!g&&"resourceUri"in e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",b," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(Z)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened in the builder: ",Z]});if(I.isError&&!ue)return m.jsx(S.ApiErrorDisplay,{error:I.error,context:`Opening the ${b}`});if(!ue&&(!(p||F)||!ee))return n??m.jsx(S.Loading,{text:`Opening the ${b}…`});if(we)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",X]});const Yr=B!==void 0&&B!==F;return m.jsxs($.Stack,{sx:{gap:2},children:[I.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",I.error?.message,". Your edits are still here."]}),!h&&!te&&Q&&Yr&&me===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Oe(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Oe(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),Ne!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{rn!==void 0&&S.clearReportDraft(rn),D()},children:"Load it"}),children:z==="package"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":z==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),ie!==void 0&&m.jsxs($.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",ie]}),!ue&&(n??m.jsx(S.Loading,{text:`Opening the ${b}…`})),ue&&m.jsx(xy,{environmentName:v,packageName:x,modelPath:W,...d?{textSource:d}:{},slug:w,..._!==void 0?{versionId:_}:{},...(l??_)!==void 0?{queryVersionId:l??_}:{},opened:ue,...$e&&P==="package"&&ue.packageText!==void 0?{replaces:ue.packageText}:{},onSave:R,onDirtyChange:Vr,...s?{onExit:s}:{},...i?{onOpenModel:i}:{},...o?{onControlsChange:o}:{},...rn!==void 0?{draftKey:rn}:{},savesTo:z,...sn?{saveLabel:sn}:{},...t?{onEvent:oe}:{},note:ci},ue.generation)]})}const My=Ma,Iy=Da;function jy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Ma,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=S.MAX_SLUG_ATTEMPTS;exports.createDocument=S.createDocument;exports.createRoute=S.createRoute;exports.locatorFor=S.locatorFor;exports.newDashboardSource=S.newDashboardSource;exports.newDocumentProblem=S.newDocumentProblem;exports.newNotebookSource=S.newNotebookSource;exports.reportPathFor=S.reportPathFor;exports.reportPathForTitle=S.reportPathForTitle;exports.slugFor=S.slugFor;exports.slugOrFallback=S.slugOrFallback;exports.useDocumentChoices=S.useDocumentChoices;exports.BuilderBar=uy;exports.DashboardBuilder=Iy;exports.DashboardEditor=My;exports.NotebookEditor=jy;exports.ReportBuilder=Da;exports.ReportEditor=Ma;exports.buildCatalog=Qu;exports.readDashboardDocument=Ks;exports.readFailed=Hs;exports.readReportTagOfText=Nm;exports.spliceDashboardDocument=Hu;exports.spliceFailed=qs;
135
+ `;a.push({start:w,end:w,text:x+f.join(`
136
+ `)})}}const xs=(e,t=me.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function py(e,t){const n=new Map(e.tiles.map(i=>[ot(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(ot(i));if(Ie(i)){const d=fy(i,a&&Ie(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=xs(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=xs(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=xs(i.name,me.isStrictName);if(u)return u}const l=i.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const u=xs(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 Lt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function _f(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function kf(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 Sf(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 Rs=e=>`where: ${me.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Jl(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 gy(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(Lt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function my(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 $f(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((g,w)=>({clause:g,index:w})).filter(({clause:g})=>g.binding!==void 0);if(h.length===0)continue;const y=h.filter(({clause:g})=>o.has(g.binding.given));for(const{clause:g}of h)i.add(g.binding.given);if(y.length===0&&h.length===f.clauses.length){const g=za(r,f.span),w=gy(r,f.span,g);if(w)return Jl(t.name,r,w);s.push({...g,text:""});continue}y.length>0&&(a=f.span);for(let g=h.length-1;g>=0;g--){const{clause:w,index:x}=h[g],p=o.get(w.binding.given);if(!p){const _=my(f.clauses,x),b=r.commentIn(_);if(b)return Jl(t.name,r,b);s.push({..._,text:""});continue}const v=Rs(p).replace(/^where:\s*/,"");v!==r.text.slice(w.span.start,w.span.end)&&s.push({...w.span,text:v})}}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(Lt(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(Rs).join(", ")}`:l.map(f=>`
138
+ ${n.indent}${Rs(f)}`).join("");s.push({start:u,end:u,text:d})}function vy(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:o}=n.body,i=kf(t.filters,o);if(i)return Sf(t.name,i.given);const a=t.filters??[];if(!o){if(a.length===0)return;const c=` + { ${a.map(Rs).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 $f(e,t,o)}async function Tf(e,t,n={}){if(!(e.includes(`\r
139
+ `)&&!/(?<!\r)\n/.test(e)))return ec(e,t,n);const s=await ec(e.replace(/\r\n/g,`
140
+ `),t,n);return io(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
+ `)}}async function ec(e,t,n){const r=await oo(e);if(so(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,o=uy(s,t),i=Zv(s,o,n.visibleSources);if("reason"in i)return i;const a=py(s,o);if(a)return{ok:!1,reason:a};const l=await uf(e);if(af(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const u=e.split(`
142
+ `),c=Kv(e),d=p=>({start:c[p],end:p+1<c.length?c[p+1]:e.length}),f=p=>/^\s*/.exec(u[p])?.[0]??"",h=[],y={...i,sourceText:e,parsed:l.parsed,lines:u,starts:c,wholeLine:d,indentOf:f,current:s,next:o,edits:h};for(const p of[ty,sy,iy,oy,ay,ly,cy,dy,hy]){const v=p(y);if(v)return v}const g=p=>{const{drills:v,localGivens:_,description:b,...E}=p,T=p.tiles.map(M=>{if(Ie(M))return M;if(M.filters?.length)return lo(M);const{filters:O,...C}=M;return lo(C)});return{...E,...b===void 0?{}:{description:mf(b)},tiles:T,...v?.length?{drills:[...v].sort((M,O)=>ao(M).localeCompare(ao(O)))}:{},..._?.length?{localGivens:_}:{}}};if(h.length===0)return Ee(g(s))!==Ee(g(o))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const w=Vv(e,h);if((await Hl(e)).length===0){const p=await Hl(w);if(p.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${p[0]}). Your changes are still here.`}}const x=await oo(w);return so(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:Ee(g(x.document))!==Ee(g(o))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:w}}function Ef({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=be.usePublisherTheme(),o=s.ui,i=S.useId(),[a,l]=S.useState(!1),u=S.useMemo(()=>a?{text:e}:void 0,[a,e]),{draft:c,patch:d,close:f,discard:h}=_c(u,a,_=>n(_.text),()=>l(!1)),y=a&&c!==void 0&&c.text!==e,g=c!==void 0&&c.text!==e?js(c.text):void 0;qu(y,()=>g!==void 0?!1:(f(),!0));const w=S.useRef(!1);S.useEffect(()=>{a||(w.current=!1)},[a]);const x=S.useCallback(_=>{!_||w.current||(w.current=!0,_.setSelectionRange(_.value.length,_.value.length))},[]);if(!a||c===void 0){const _=e.trim()?js(e):void 0;return m.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():l(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),l(!0)))},sx:[{minHeight:24},Gu(s,"prose")],children:[e.trim()?m.jsx(k.Prose,{variant:r,children:e}):m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),_&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:_})]})}const p=c.text!==e?js(c.text):void 0,v=()=>{p===void 0&&f()};return m.jsxs($.Box,{sx:{position:"relative",mx:"-10px",px:"10px",my:"-6px",py:"6px"},children:[m.jsx($.InputBase,{multiline:!0,autoFocus:!0,minRows:2,fullWidth:!0,value:c.text,placeholder:t,error:p!==void 0,inputRef:x,inputProps:{"aria-label":"Markdown","aria-describedby":i,...p!==void 0?{"aria-invalid":!0}:{}},onChange:_=>d(b=>{b.text=_.target.value}),onKeyDown:_=>{_.key==="Escape"?(_.preventDefault(),h(),l(!1)):_.key==="Enter"&&(_.metaKey||_.ctrlKey)&&(_.preventDefault(),v())},onBlur:()=>f(),sx:{p:0,...o.type.prose,color:"inherit",maxWidth:k.PROSE_MAX_WIDTH,"& textarea":{p:0}}}),p!==void 0&&m.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:p}),m.jsxs($.Typography,{id:i,variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,color:"text.secondary",pointerEvents:"none"},children:["Markdown · ",cn,"↩ done · Esc cancels"]})]})}const yy="Write markdown: # heading, **bold**, - list";function xy({tile:e,onChange:t}){return m.jsx(k.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Ef,{markdown:e.markdown,placeholder:yy,onCommit:t})})}var by=Object.defineProperty,wy=Object.defineProperties,_y=Object.getOwnPropertyDescriptors,tc=Object.getOwnPropertySymbols,ky=Object.prototype.hasOwnProperty,Sy=Object.prototype.propertyIsEnumerable,nc=(e,t,n)=>t in e?by(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_n=(e,t)=>{for(var n in t||(t={}))ky.call(t,n)&&nc(e,n,t[n]);if(tc)for(var n of tc(t))Sy.call(t,n)&&nc(e,n,t[n]);return e},kn=(e,t)=>wy(e,_y(t));function $y(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function bs(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function zo(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Ty(e,t,n){var r,s;const{source:o,target:i,canceled:a}=t.operation;if(!o||!i||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(v,_)=>v===_||v!==null&&typeof v=="object"&&"id"in v&&v.id===_;if(Array.isArray(e)){const v=e.findIndex(b=>l(b,o.id)),_=e.findIndex(b=>l(b,i.id));if(v===-1||_===-1){if(zo(o)){const b=o.initialIndex,E=o.index;return b===E||b<0||b>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,b,E)}return e}if(!a&&"index"in o&&typeof o.index=="number"){const b=o.index;if(b!==v)return n(e,v,b)}return n(e,v,_)}const u=Object.entries(e);let c=-1,d,f=-1,h;for(const[v,_]of u)if(c===-1&&(c=_.findIndex(b=>l(b,o.id)),c!==-1&&(d=v)),f===-1&&(f=_.findIndex(b=>l(b,i.id)),f!==-1&&(h=v)),c!==-1&&f!==-1)break;if(c===-1&&zo(o)){const v=o.initialGroup==null?void 0:bs(e,o.initialGroup),_=o.initialIndex,b=o.group==null?void 0:bs(e,o.group),E=o.index;if(v==null||b==null||v===b&&_===E)return"preventDefault"in t&&t.preventDefault(),e;if(v===b)return kn(_n({},e),{[v]:n(e[v],_,E)});const T=e[v][_];return kn(_n({},e),{[v]:[...e[v].slice(0,_),...e[v].slice(_+1)],[b]:[...e[b].slice(0,E),T,...e[b].slice(E)]})}if(!o.manager)return e;const{dragOperation:y}=o.manager,g=(s=(r=y.shape)==null?void 0:r.current.center)!=null?s:y.position.current;if(h==null){const v=bs(e,i.id);if(v!=null){const _=i.shape&&g.y>i.shape.center.y?e[v].length:0;h=v,f=_}}if(d==null||h==null||d===h&&c===f){if(d!=null&&d===h&&c===f&&zo(o)){const v=o.group==null?void 0:bs(e,o.group),_=o.group!=null&&v!==d,b=o.index!==c;if(_||b){const E=o.group==null?d:v;if(E!=null){if(d===E)return kn(_n({},e),{[d]:n(e[d],c,o.index)});const T=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[E]:[...e[E].slice(0,o.index),T,...e[E].slice(o.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===h)return kn(_n({},e),{[d]:n(e[d],c,f)});const x=i.shape&&Math.round(g.y)>Math.round(i.shape.center.y)?1:0,p=e[d][c];return kn(_n({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[h]:[...e[h].slice(0,f+x),p,...e[h].slice(f+x)]})}function Ey(e,t){return Ty(e,t,$y)}function Cf(e){const t=e.getBoundingClientRect(),n=new Map;for(const r of e.querySelectorAll("[data-tile-key]")){const s=r.dataset.tileKey;if(!s)continue;const o=r.getBoundingClientRect();n.set(s,{top:o.top-t.top,left:o.left-t.left,width:o.width,height:o.height})}return n}function Cy({tiles:e,commit:t,onLanded:n,placement:r}){const[s,o]=S.useState(void 0),i=S.useRef(void 0),[a,l]=S.useState(!1),u=S.useRef(void 0);return{dragging:a,preview:s,onDragStart:y=>{l(!0),i.current=e;const g=r?.gridBox.current,w=y?.operation.source?.id;if(!r||!g)return;const x=e.findIndex(M=>fe(M)===w),p=Cf(g),v=p.get(String(w));if(x<0||!v)return;const _=pc(e,e.map(M=>p.get(fe(M))),r.columns,Ls(g.getBoundingClientRect().width,r.columns)),b=g.getBoundingClientRect(),E=y?.operation.position?.current,T=E?{x:E.x-(b.left+v.left),y:E.y-(b.top+v.top)}:{x:0,y:0};u.current={base:_,index:x,from:v,grab:T},i.current=_,o(_)},onDragMove:y=>{const g=u.current,w=r?.gridBox.current;if(!g||!r||!w)return;const x=w.getBoundingClientRect(),p=y.operation.position.current,v=y.to??(y.by?{x:p.x+y.by.x,y:p.y+y.by.y}:p),_=g.base[g.index],b=hc(v.x-g.grab.x-x.left,v.y-g.grab.y-x.top,_.colspan??1,r.columns,Ls(w.getBoundingClientRect().width,r.columns)),E=i.current?.[g.index];if(E?.row===b.row&&E.col===b.col)return;const T=Gf(g.base,g.index,b,r.columns);i.current=T,o(T)},onDragOver:y=>{if(u.current){y.preventDefault();return}const{source:g,target:w}=y.operation;if(!g||!w)return;const x=i.current??e;let p;if(w.type===sf){const{after:v}=w.data,_=x.findIndex(T=>fe(T)===g.id);if(_<0||v===g.id)return;const E=x.filter((T,M)=>M!==_).findIndex(T=>fe(T)===v)+1;p=jm(x,_,E)}else{const v=x.map(fe),_=Ey(v,y);if(_.every((E,T)=>E===v[T]))return;const b=new Map(x.map(E=>[fe(E),E]));p=Pm(_.map(E=>b.get(E)),e.map(E=>E.break??!1))}i.current=p,o(p)},onDragEnd:y=>{l(!1);const g=u.current,w=g!==void 0;u.current=void 0;const x=i.current,p=g!==void 0&&x!==void 0&&x[g.index]?.row===g.base[g.index]?.row&&x[g.index]?.col===g.base[g.index]?.col,v=w&&x?In(x):x;if(i.current=void 0,o(void 0),y.canceled||!v||p)return;t(v);const _=v.findIndex(b=>fe(b)===y.operation.source?.id);_>=0&&n(_)}}}const Oy={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Of=(e,t)=>t===0?e:Of(t,e%t);function My(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Of(e,t),s=Oy[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}const rc=k.TILE_ROW_PX+k.GRID_GAP_PX,Mf=e=>e.n&&e.w||e.s&&e.e?"nwse-resize":e.n&&e.e||e.s&&e.w?"nesw-resize":e.n||e.s?"ns-resize":"ew-resize",ws=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e??""},Iy=e=>({...e.row!==void 0?{row:e.row}:{},...e.col!==void 0?{col:e.col}:{},colspan:e.colspan??1,rowspan:e.rowspan}),sc=(e,t)=>e.row===t.row&&e.col===t.col&&e.colspan===t.colspan&&e.rowspan===t.rowspan;function If(e,t,n,r){const s={...e};return(n.e||n.w)&&(s.colspan=t.colspan,r&&t.col!==void 0&&(s.col=t.col)),(n.n||n.s)&&(t.rowspan===void 0?delete s.rowspan:s.rowspan=t.rowspan,r&&t.row!==void 0&&(s.row=t.row)),s}function Dy({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[o,i]=S.useState(void 0),a=S.useRef(void 0),l=S.useRef(void 0),u=g=>{a.current=g,i(g)};S.useEffect(()=>()=>ws(void 0),[]);const c=o!==void 0;S.useEffect(()=>{if(!c)return;const g=w=>{w.key!=="Escape"||!a.current||(w.preventDefault(),w.stopPropagation(),a.current=void 0,i(void 0),l.current=void 0,ws(void 0))};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[c]);const d=g=>{const w=new Set(g.base.filter(v=>v.rowspan===void 0).map(fe)),x=g.base[g.index];let p=l.current;for(const v of n.current?.querySelectorAll("[data-tile-key]")??[]){const _=v.dataset.tileKey;if(!_||!w.has(_)||x&&_===fe(x))continue;const b=v.getBoundingClientRect();Math.abs(b.top-g.top)>1||(p=Math.max(p??0,b.height))}return p};return{drag:o,start:(g,w,x)=>{const p=n.current,v=p?.getBoundingClientRect(),_=g.currentTarget.parentElement?.getBoundingClientRect();if(!p||!v||!_||!e[w])return;g.stopPropagation(),g.preventDefault(),g.currentTarget.setPointerCapture(g.pointerId),ws(Mf(x)),r(w);const b=(x.n||x.w)&&(!k.isPlaced(e)||e[w].row===void 0||e[w].col===void 0),E=b?(()=>{const A=Cf(p);return pc(e,e.map(R=>A.get(fe(R))),t,Ls(v.width,t))})():[...e],T=k.isPlaced(E),M=E[w],O=Iy(M);!T&&O.rowspan===void 0?l.current=_.height:l.current=void 0;const C=T?{...O,rowspan:Fr(M)}:O;u({index:w,edges:x,base:E,placedHere:!!b,placed:T,from:O,begun:C,shape:C,guideTop:_.top-v.top,min:As(M,g.currentTarget.parentElement),top:_.top,left:_.left})},move:g=>{const w=a.current,x=n.current?.getBoundingClientRect();if(!w||!x)return;const p=w.base[w.index];if(!p)return;const _=Ls(x.width,t)+k.GRID_GAP_PX,b=g.clientX-x.left,E=g.clientY-x.top,T=g.currentTarget.parentElement?.getBoundingClientRect(),M=T?.top??w.top,O=T?.left??w.left,{min:C}=w,A=w.shape;let{row:R,col:B,colspan:G,rowspan:N}=A;if(w.placed&&B!==void 0&&R!==void 0){const j=w.from,z=j.col??B,D=z+j.colspan-1,I=j.row??R,L=j.rowspan??Fr(p),q=I+L-1;if(w.edges.e){const H=Math.round((b+k.GRID_GAP_PX)/_);G=Math.min(Math.max(H,z),t)-z+1,B=z}if(w.edges.w){const H=Math.round(b/_)+1;B=Math.min(Math.max(H,1),D),G=D-B+1}if(w.edges.s){const H=w.edges.n?x.top+(I-1)*rc:M;N=k.rowsForHeight(g.clientY-H,C),R=I}if(w.edges.n){const H=Math.round(E/rc)+1,K=Math.min(C,L);R=Math.max(1,Math.min(Math.max(H,q-k.MAX_TILE_ROWS+1),q-K+1)),N=q-R+1}}else{if(w.edges.e){const j=Math.round((g.clientX-O+k.GRID_GAP_PX)/_);G=Math.min(Math.max(j,1),t)}if(w.edges.s){const j=g.clientY-M,z=k.rowsForHeight(j,C),D=d(w);N=D!==void 0&&Math.abs(j-D)<Math.abs(j-k.tileHeightPx(z))?void 0:z}}const X={...R!==void 0?{row:R}:{},...B!==void 0?{col:B}:{},colspan:G,rowspan:N};sc(X,A)||u({...w,shape:X})},end:g=>{g.currentTarget.hasPointerCapture(g.pointerId)&&g.currentTarget.releasePointerCapture(g.pointerId),ws(void 0);const w=a.current;l.current=void 0,w&&(u(void 0),!(g.type==="pointercancel"||sc(w.shape,w.begun))&&s({index:w.index,edges:w.edges,shape:w.shape,placed:w.placed,...w.placedHere?{placedAll:w.base}:{}}))}}}function Py(e,t){const n=[];return(e.edges.e||e.edges.w)&&n.push(My(e.shape.colspan,t)),(e.edges.n||e.edges.s)&&n.push(e.shape.rowspan===void 0?"Auto height":`${e.shape.rowspan} rows tall`),n.join(" · ")}function jy({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:o=!1,onInsertAfter:i,onSelect:a,onOpenMenu:l,onRemove:u,removeBlocked:c,width:d,edges:f,heightEdge:h,fixed:y=!1,children:g}){const{theme:w}=be.usePublisherTheme(),x=w.ui;return m.jsx(gv,{id:fe(e),index:t,disabled:y,children:({ref:p,handleRef:v})=>m.jsxs($.Box,{ref:p,onClick:a,onPointerDown:_=>{_.button===0&&a()},role:"group",className:k.reportClasses.builderTile,"aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",...(e.rowspan!==void 0||e.row!==void 0)&&{gridTemplateRows:"minmax(0, 1fr)",minHeight:0},minWidth:0,cursor:"grab",...Df(w,{selected:n,flash:r,bare:o}),...!o&&{[`& .${k.TILE_HEADING_CLASS}`]:{pr:"36px"}},"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:w.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${w.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},...k.removeBadgeRevealSx,...n&&{[`& .${k.REMOVE_BADGE_CLASS}`]:{opacity:1}},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[g,m.jsx($.Box,{ref:v,"aria-label":`Move ${lr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(k.RemoveBadge,{label:`Remove ${lr(e)}`,onRemove:u,...c?{disabledReason:c}:{},inset:o?k.BARE_RING_OFFSET_PX:0}),!Ie(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${lr(e)}`,onClick:_=>{_.stopPropagation(),l(_.currentTarget)},sx:{position:"absolute",top:o?0:`${oc}px`,right:o?0:`${oc}px`,borderRadius:x.radius.control,width:28,height:28,zIndex:3,color:"text.secondary",bgcolor:"action.hover",opacity:n||s?1:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover":{opacity:1,bgcolor:"action.selected"}},children:m.jsx(By,{})}),f&&m.jsx(Wy,{edges:f,width:d,heightEdge:h,label:lr(e)}),i&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${lr(e)}`,onClick:_=>{_.stopPropagation(),i()},sx:{position:"absolute",bottom:`-${k.GRID_GAP_PX/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:w.tileTitle,bgcolor:w.tile,border:w.cardBorder,opacity:0,transition:`opacity ${k.MOTION_FAST}`,...k.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:w.tile}},children:m.jsx(k.AddIcon,{sx:{fontSize:14}})})]})})}const oc=14,Go=7,Df=(e,{selected:t,flash:n=!1,bare:r=!1,ringOffset:s=k.BARE_RING_OFFSET_PX})=>{const o=e.ui,i=t||n?e.accent:"transparent",a=n?`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`:t?`0 0 0 4px color-mix(in srgb, ${e.accent} 14%, transparent)`:void 0,l=`outline-color ${k.MOTION_FAST}, border-color ${k.MOTION_FAST}, opacity ${k.MOTION_FAST}, box-shadow ${k.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:typeof s=="number"?`${-s}px`:`${-s.y}px ${-s.x}px`,borderRadius:1,border:`2px solid ${i}`,...a&&{boxShadow:a},pointerEvents:"none",transition:l,...k.reducedMotionSx}}:{borderRadius:o.radius.tile,"& > .MuiPaper-root":{transition:l,...k.reducedMotionSx,...(t||n)&&{borderColor:e.accent,boxShadow:`0 0 0 1px ${e.accent}${a?`, ${a}`:""}`}},transition:l,...k.reducedMotionSx,"&:hover":{boxShadow:e.shadow.lift,...!(t||n)&&{"& > .MuiPaper-root":{borderColor:k.hoverEdgeColor(e.cardBorder,e.tileTitle)}}}}};function Ry({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=be.usePublisherTheme();return m.jsxs(k.TileCard,{chrome:r,children:[m.jsx(k.TileHeading,{title:t?.title??co(e),subtitle:t?t.subtitle:e.subtitle}),n&&m.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),m.jsx($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:dt(e).replace("->","→")})]})}function Ay({after:e}){const{theme:t}=be.usePublisherTheme();return m.jsx(mv,{id:Ku(e),after:e,children:({ref:n,isDropTarget:r})=>m.jsx($.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,...k.reducedMotionSx}})})}function Ly({columns:e,faint:t=!1}){const{theme:n}=be.usePublisherTheme();return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${k.GRID_GAP_PX}px`},children:Array.from({length:e},(r,s)=>m.jsx($.Box,{sx:{bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},s))})}function ic({top:e,faint:t=!1}){const{theme:n}=be.usePublisherTheme(),r=k.TILE_ROW_PX+k.GRID_GAP_PX,s=-Math.ceil(e/r);return m.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none",zIndex:0},children:Array.from({length:-s+4*k.MAX_TILE_ROWS},(o,i)=>m.jsx($.Box,{sx:{position:"absolute",top:e+(s+i)*r,left:0,right:0,height:k.TILE_ROW_PX,bgcolor:n.accent,opacity:t?.03:.06,borderRadius:"3px"}},i))})}function By(){return m.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[m.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),m.jsx("circle",{cx:"12",cy:"12",r:"2"}),m.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}const Fy=[{edges:{n:!0},sx:{top:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{s:!0},sx:{bottom:"-6px",left:"12px",right:"12px",height:"12px"}},{edges:{e:!0},sx:{right:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{w:!0},sx:{left:"-6px",top:"12px",bottom:"12px",width:"12px"}},{edges:{n:!0,w:!0},sx:{top:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{n:!0,e:!0},sx:{top:"-8px",right:"-8px",width:"32px",height:"32px"}},{edges:{s:!0,w:!0},sx:{bottom:"-8px",left:"-8px",width:"20px",height:"20px"}},{edges:{s:!0,e:!0},sx:{bottom:"-8px",right:"-8px",width:"20px",height:"20px"}}];function Wy({edges:e,width:t,heightEdge:n,label:r}){const{theme:s}=be.usePublisherTheme(),o=s.ui,[i,a]=S.useState(void 0),l=i??n?.min??k.MIN_TILE_ROWS,u=f=>n&&a(n.minFor?.(f)??n.min),c=f=>(!(f.n||f.w)||e.all)&&(!f.e||e.right),d={"&:focus-visible":{outline:`2px solid ${s.accent}`,outlineOffset:-4,borderRadius:"3px"}};return m.jsxs(m.Fragment,{children:[Fy.filter(f=>c(f.edges)).map(f=>{const h=Object.keys(f.edges).join(""),y=h==="e",w=y&&t?{role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":`Width of ${r}`,"aria-valuenow":t.span,"aria-valuemin":1,"aria-valuemax":t.max??t.columns,"aria-valuetext":`${t.span} of ${t.columns} columns`,onKeyDown:x=>{if(x.altKey)return;const p=t.max??t.columns,v=x.key==="ArrowRight"?t.span+1:x.key==="ArrowLeft"?t.span-1:x.key==="Home"?1:x.key==="End"?p:void 0;v!==void 0&&(x.preventDefault(),x.stopPropagation(),t.onStep(Math.min(Math.max(v,1),p)))}}:h==="s"&&n?{role:"separator",tabIndex:0,"aria-orientation":"horizontal","aria-label":`Height of ${r}`,"aria-valuemin":l,onFocus:x=>u(x.currentTarget.parentElement),onPointerEnter:x=>u(x.currentTarget.parentElement),"aria-valuemax":k.MAX_TILE_ROWS,...n.rows===void 0?{}:{"aria-valuenow":n.rows},"aria-valuetext":Ny(n.rows),onKeyDown:x=>{if(x.altKey)return;const p=n.rows,v=p??l,_=x.key==="ArrowDown"?v+1:x.key==="ArrowUp"?v-1:x.key==="Home"?l:x.key==="End"?k.MAX_TILE_ROWS:x.key==="Delete"||x.key==="Backspace"?null:void 0;if(_===void 0)return;if(x.preventDefault(),x.stopPropagation(),_===null){p!==void 0&&n.onStep(void 0);return}const b=Math.min(Math.max(_,l),k.MAX_TILE_ROWS);b!==p&&n.onStep(b)}}:{"aria-hidden":!0};return m.jsx($.Box,{className:`builder-affordance${y?` ${k.reportClasses.widthHandle}`:""}`,[of]:"",...w,"data-edge":h,onPointerDown:x=>{x.button===0&&e.start(x,f.edges)},onPointerMove:e.move,onPointerUp:e.end,onPointerCancel:e.end,onClick:x=>x.stopPropagation(),onDoubleClick:x=>{!f.edges.s||f.edges.e||f.edges.w||(x.stopPropagation(),n&&n.rows!==void 0&&n.onStep(void 0))},sx:{position:"absolute",...f.sx,cursor:Mf(f.edges),touchAction:"none",zIndex:Object.keys(f.edges).length>1?2:1,...d}},h)}),e.label&&m.jsx($.Box,{"aria-hidden":!0,sx:f=>({position:"absolute",right:12,bottom:12,px:1,py:.5,borderRadius:o.radius.control,bgcolor:f.palette.text.primary,color:f.palette.background.paper,...o.type.label,whiteSpace:"nowrap",pointerEvents:"none",zIndex:4}),children:e.label})]})}const Ny=e=>e===void 0?"Auto height":`${e} rows tall`;function zy({editor:e,reorder:t,edging:n,place:r=v=>v,arrange:s=!0,gridBox:o,defaultSpan:i=1,rules:a,canAdd:l,selected:u,flash:c,menuIndex:d,onSelect:f,onOpenMenu:h,onRemove:y,removeBlocked:g,openAdd:w,editTile:x,renderTile:p}){const{dragging:v,preview:_,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M}=t,{columns:O}=a,C=n.drag,A=D=>D.colspan===void 0?{...D,colspan:i}:D,R=(C!==void 0?(()=>{const D=C.placedHere?C.base:e.document.tiles;if(!D[C.index])return D;const L=D.map((q,H)=>H===C.index?If(q,C.shape,C.edges,C.placed):q);return C.placed?Rt(L,O,C.index):L})():_??e.document.tiles).map(A),B=k.isPlaced(R),G=v||C!==void 0,N=!G&&B&&s&&u!==void 0,X=e.document.tiles.length===0,j=G&&!B?Rm(R,O):R.map(Uu),z=D=>Gy(D,co(D),x);return m.jsxs(m.Fragment,{children:[m.jsxs(vm,{sensors:fv,onDragStart:b,onDragMove:E,onDragOver:T,onDragEnd:M,children:[m.jsx(vv,{active:v}),m.jsxs($.Box,{ref:o,sx:{position:"relative"},children:[a.widths&&(G||N)&&m.jsx(Ly,{columns:O,faint:!G}),C!==void 0&&!C.placed?(C.edges.s||C.edges.n)&&m.jsx(ic,{top:C.guideTop}):B&&(G||N)&&m.jsx(ic,{top:0,faint:!G}),m.jsx(k.DashboardGrid,{tiles:j,columns:O,rowGapPx:k.GRID_GAP_PX,defaultRowspan:D=>D.kind==="tile"?Fr(D.tile):k.PLACED_DEFAULT_ROWSPAN.query,keyOf:D=>D.kind==="gap"?Ku(D.after):fe(D.tile),renderTile:D=>{if(D.kind==="gap")return m.jsx(Ay,{after:D.after});const{tile:I,index:L}=D;return m.jsx(jy,{tile:I,index:L,selected:L===u,flash:fe(I)===c,menuOpen:d===L,bare:Ie(I),...a.insertBetween&&l&&L<e.document.tiles.length-1?{onInsertAfter:()=>w(L+1)}:{},fixed:!s,...a.widths?{edges:{all:s,right:s,start:(q,H)=>n.start(q,L,H),move:n.move,end:n.end,...C?.index===L?{label:Py(C,O)}:{}}}:{},...a.widths&&s?{width:{span:I.colspan??1,columns:O,max:mc(I,O),onStep:q=>{q!==(I.colspan??1)&&e.update(H=>{if(!Number.isInteger(L)||L<0)return;const K=H.tiles[L];K&&(H.tiles[L]=k.withSpan(K,q,O,i)),H.tiles=r(H.tiles,L)})}}}:{},...a.widths?{heightEdge:{rows:I.rowspan,min:As(I),minFor:q=>As(I,q),onStep:q=>e.update(H=>{if(!Number.isInteger(L)||L<0)return;const K=H.tiles[L];K&&(q===void 0?delete K.rowspan:K.rowspan=q,H.tiles=r(H.tiles,L))})}}:{},onSelect:()=>f(L),onOpenMenu:q=>h(q,L),onRemove:()=>y(L),...g?{removeBlocked:g}:{},children:Ie(I)?m.jsx(xy,{tile:I,onChange:q=>x(fe(I),H=>{Ie(H)&&(H.markdown=q)})}):p?p(I,z(I),"card"):m.jsx(Ry,{tile:I,heading:z(I)})})}})]})]}),a.insertBetween&&l&&!X&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>w(),sx:{alignSelf:"center"},children:"Add tile"})]})}const Gy=(e,t,n)=>{if(Hn(e))return;const r=fe(e),s=o=>i=>n(r,a=>{ce(a)&&(i===""?delete a[o]:a[o]=i)});return{title:m.jsx(Pi,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(Pi,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Hy={x:12,y:6};function qy({editor:e,documentSlug:t,actions:n,descriptionSelected:r,selectDescription:s}){const{theme:o}=be.usePublisherTheme();return m.jsx(k.ReportHeader,{actions:n,title:m.jsx(Pi,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:i=>e.update(a=>{a.title=i})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(k.TextTileFrame,{sx:{position:"relative",overflow:"visible",...Df(o,{selected:r,bare:!0,ringOffset:Hy})},children:m.jsx(Ef,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:i=>e.update(a=>{i.trim()===""?delete a.description:a.description=i})})})})})}const Uy=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:o}=k.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:i,structural:a,durationMs:l})=>o({type:"report.saved",tiles:i,structural:a,where:r,durationMs:l}),refused:i=>o({type:"report.save_refused",reason:i}),undone:({size:i,structural:a,durationMs:l})=>o({type:"report.save_undone",tiles:i,structural:a,where:r,durationMs:l}),undoRefused:i=>o({type:"report.save_undo_refused",reason:i})}};function Ky(e,t){const n=S.useRef(t);n.current=t;const r=S.useRef(e);r.current=e;const s=S.useMemo(()=>({save:()=>n.current.save?.(),undo:()=>n.current.undo(),redo:()=>n.current.redo(),addTile:()=>n.current.add.tile?.(),addText:()=>n.current.add.text?.(),addFilter:()=>n.current.add.filter?.(),exit:()=>n.current.exit?.(),done:()=>n.current.done?.(),discard:()=>n.current.discard?.(),restore:()=>n.current.restore?.(),dismissRestored:()=>n.current.dismissRestored?.(),pack:()=>n.current.arrange?.pack?.(),flow:()=>n.current.arrange?.flow()}),[]),{status:o,saveTarget:i,canUndo:a,canRedo:l,add:{filterUnavailable:u}}=t,c=t.save!==void 0,d=t.add.tile!==void 0,f=t.add.text!==void 0,h=t.add.filter!==void 0,y=t.exit!==void 0,g=t.done!==void 0,w=t.discard!==void 0,{draftKeptAt:x}=t,p=t.restored?.savedAt,v=t.restored?.stale??!1,_=t.restored?.pending??!1,b=t.restore!==void 0,E=t.dismissRestored!==void 0,T=t.arrange!==void 0,M=t.arrange?.pack!==void 0,O=S.useMemo(()=>({status:o,saveTarget:i,...c?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:l,redo:s.redo,add:{...d?{tile:s.addTile}:{},...f?{text:s.addText}:{},...h?{filter:s.addFilter}:{},...u!==void 0?{filterUnavailable:u}:{}},...y?{exit:s.exit}:{},...g?{done:s.done}:{},...x!==void 0?{draftKeptAt:x}:{},...w?{discard:s.discard}:{},...p!==void 0?{restored:{savedAt:p,stale:v,pending:_}}:{},...b?{restore:s.restore}:{},...E?{dismissRestored:s.dismissRestored}:{},...T?{arrange:{...M?{pack:s.pack}:{},flow:s.flow}}:{}}),[s,o,i,c,a,l,d,f,h,u,y,g,x,w,p,v,_,b,E,T,M]),C=e!==void 0;S.useEffect(()=>{r.current?.(O)},[O,C]),S.useEffect(()=>()=>r.current?.(void 0),[])}function Vy({controls:e,unknownFieldsOf:t,onEdit:n,onAdd:r,addDisabledReason:s,onRemove:o,fixedFilters:i,onOpenModel:a,startingValues:l,onStartingValue:u,children:c}){const d=c!=null,f=S.useMemo(()=>{const h=new Map(e.map(y=>[y.name,y]));return{stateOf:y=>{const g=i?.get(y);if(g!==void 0){const{modelPath:p}=g;return{origin:h.get(y)?.origin??"model",fixed:g.reason,...p!==void 0&&a?{openModel:()=>a(p)}:{}}}const w=h.get(y);if(!w)return;const x=t(w.name,w.type);return{origin:w.origin,...x.length>0?{problem:`Cannot filter on ${x.join(", ")}: a tile it applies to has no such field.`}:{}}},unrendered:d?e.filter(y=>y.boundTiles===0&&!i?.has(y.name)).map(y=>({name:y.name,label:y.label??y.name})):[],onEdit:y=>{const g=h.get(y);g&&n(g)},onRemove:o,onAdd:r,...s!==void 0?{addDisabledReason:s}:{},...u?{startingValueOf:y=>l?.[y],setStartingValue:u}:{}}},[e,t,d,n,o,r,s,i,a,l,u]);return m.jsx(k.StickyControls,{children:m.jsx(k.FilterEditingContext.Provider,{value:f,children:d?c:m.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",useFlexGap:!0,sx:{flexWrap:"wrap",alignItems:"center",gap:1},children:[e.map(h=>m.jsx(k.FilterSettingsButton,{name:h.name,label:h.label??h.name,unused:h.boundTiles===0},h.name)),m.jsx(k.AddFilterButton,{})]})})})}function Xy(e,t){const n=new Map(e.tiles.map((r,s)=>[fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const o=n.get(fe(s));if(!o||o.index!==r||JSON.stringify(o.tile)!==JSON.stringify(s))return fe(s)}}function Yy({editor:e,gridBox:t}){const[n,r]=S.useState(void 0),s=typeof n=="object"?n.tile:void 0,o=n==="description",i=S.useCallback(w=>r(x=>typeof x=="object"&&x.tile===w?x:{tile:w}),[]),a=S.useCallback(()=>r(w=>w==="description"?w:void 0),[]),l=S.useCallback(()=>r("description"),[]),u=S.useCallback(()=>r(void 0),[]),c=n!==void 0;S.useEffect(()=>{if(!c)return;const w=x=>{const p=x.target;p instanceof Element&&p!==document.documentElement&&p.closest(Qy)===null&&u()};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[c,u]);const[d,f]=S.useState(void 0),h=S.useRef(!1),y=S.useRef(e.document);S.useEffect(()=>{const w=y.current;if(y.current=e.document,!h.current)return;h.current=!1;const x=Xy(w,e.document);if(x===void 0)return;f(x),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===x)?.scrollIntoView?.({block:"nearest",behavior:k.scrollBehavior()})},[e.document,t]),S.useEffect(()=>{if(d===void 0)return;const w=setTimeout(()=>f(void 0),1500);return()=>clearTimeout(w)},[d]);const g=S.useMemo(()=>({...e,undo:()=>{h.current=!0,e.undo()},redo:()=>{h.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:o,selectTile:i,deselectTile:a,selectDescription:l,clearSelection:u,flash:d,stepEditor:g}}const Qy=["[data-tile-key]",'[role="group"][aria-label="Description"]','[role="toolbar"][aria-label="Report builder"]','[aria-label="Builder actions"]',".MuiPopover-root",".MuiPopper-root",".MuiDialog-root",".MuiModal-root",'[role="menu"]','[role="dialog"]','[role="listbox"]','[role="tooltip"]'].join(", ");function Zy({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[o,i]=S.useState("idle"),[a,l]=S.useState(!1),u=S.useRef(r);u.current=r;const c=S.useRef(s);c.current=s;const d=S.useRef(0),f=S.useCallback(async()=>{const g=++d.current;l(!1),i("saving");try{await u.current()}catch{d.current===g&&i("idle");return}d.current===g&&l(!0)},[]);S.useEffect(()=>{if(o==="waiting"){if(t)return;e?f():(i("idle"),c.current())}else if(o==="saving"){if(!a||t)return;i("idle"),e||c.current()}},[o,a,t,e,f]);const h=S.useCallback(()=>{o==="idle"&&(e?i("asking"):c.current())},[o,e]),y=S.useCallback(()=>{o==="idle"&&(e?n?t?i("waiting"):f():i("asking"):c.current())},[o,e,n,t,f]);return{requestExit:h,saveAndExit:y,finishing:o==="saving"||o==="waiting",dialog:{open:o==="asking",canSave:n,onKeepEditing:()=>{o==="asking"&&i("idle")},onDiscard:()=>{o==="asking"&&(i("idle"),c.current())},onSaveAndExit:()=>{o==="asking"&&(t?i("waiting"):f())}}}}function Jy({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:o=!1,keepsEdits:i=!1,report:a,unit:l,prepare:u,shortcuts:c}){const[d,f]=S.useState(!1),[h,y]=S.useState(!1),g=S.useRef(null),w=S.useRef(a);w.current=a;const x=e.dirty||o,p=(e.edited??e.dirty)||o,v=i?o:p;S.useEffect(()=>{s?.(e.document)},[e.document,s]),S.useLayoutEffect(()=>{n?.(p,v)},[p,v,n]);const _=S.useRef(n);_.current=n,S.useEffect(()=>()=>_.current?.(!1,!1),[]);const b=S.useRef(l);b.current=l,S.useEffect(()=>{y(!1)},[e.document]);const E=S.useCallback(()=>{f(!0),y(!1);const j=k.now(),{structural:z}=e,D=w.current.size;return e.save().then(I=>{I.ok===!0?w.current.saved({size:D,structural:z,durationMs:k.now()-j}):w.current.refused(I.reason)}).finally(()=>f(!1))},[e]),T=S.useRef(!1),M=S.useRef(!1);S.useEffect(()=>{!M.current||d||(M.current=!1,g.current?.focus())},[h,d]);const O=S.useCallback(()=>{if(!t||d||T.current||!e.canUndoSave)return;T.current=!0,f(!0);const j=k.now(),z=e.lastSave?.structural??!1,D=w.current.size;return e.undoSave().then(I=>{I.ok===!0?(M.current=!0,y(!0),w.current.undone({size:D,structural:z,durationMs:k.now()-j})):w.current.undoRefused(I.reason)}).finally(()=>{T.current=!1,f(!1)})},[t,d,e]),C=S.useCallback(()=>{if(!(!t||!e.dirty||d))return E()},[t,e,d,E]),A=S.useRef(C);A.current=C;const R=S.useCallback(()=>{const j=()=>A.current();return u?u(j):j()},[u]),B=Zy({dirty:p,saving:d,canSave:!!t,save:R,onExit:()=>r?.()});Yf(S.useMemo(()=>({...c,undo:e.undo,redo:e.redo,...t?{save:R}:{},paused:B.dialog.open||c.paused===!0}),[c,e,t,R,B.dialog.open]));const G=!!t&&!d&&e.canUndoSave,N=e.lastSave,X={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:x,saving:d,saveButton:g,...t?{onSave:R}:{},...r?{onExit:B.requestExit}:{}};return{saving:d,save:R,exitGuard:B,...r?{done:B.saveAndExit}:{},undoSave:O,canUndoSave:G,lastSave:N,toolbarProps:X}}const ex=1;function Pf(e,t,n){const r=[];for(const s of e??[]){const o=s.name,i=s.kind;if(typeof o=="string"){if(i==="dimension"||i==="measure"){const a=s.type?.kind;r.push({name:t+o,kind:i,...a?{type:a}:{}})}else if(i==="join"&&n>0){const a=s.schema?.fields;r.push(...Pf(a,`${t}${o}.`,n-1))}}}return r}function tx(e){const t=new Map;for(const n of jf(e))t.set(n.name,Pf(n.schema?.fields,"",ex));return t}function jf(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}function Rf(e){const t=new Map;for(const n of jf(e)){const r=new Map;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const o=s.schema?.fields;if(!o||o.length===0)continue;const{groupBys:i,totals:a}=k.columnCounts(o);r.set(s.name,{shape:{groupBys:i,totals:a},...a===o.length?{aggregateOnly:!0}:{}})}t.set(n.name,r)}return t}function Af(e,t){const n=k.docOf(e.annotations),r=k.chartOf(e.annotations);return{name:e.name,...n?{description:n}:{},...r?{chart:r}:{},...t}}const Lf=e=>(e.views??[]).filter(t=>typeof t.name=="string");function nx(e){const t=Rf(e),n=new Map;for(const r of e.sources??[]){if(!r.name)continue;const s=t.get(r.name);n.set(r.name,new Map(Lf(r).map(o=>[o.name,Af(o,s?.get(o.name))])))}return n}function ac(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const lc=(e,t)=>e!==void 0&&t.has(e),cc=e=>e.path||e.modelPath||"";function Bf(e,t=new Set){const n=[],r=new Set,s=new Map,o=new Map,i=new Map;for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=k.exportedSources(a.modelInfo);o.set(a,u);for(const{name:c}of a.sources??[])c&&i.set(c,[...i.get(c)??[],l]);for(const c of u)s.set(c,[...s.get(c)??[],l])}for(const a of e){const l=cc(a);if(lc(l,t))continue;const u=tx(a),c=Rf(a);for(const d of a.sources??[]){const f=d.name;if(!f||!o.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(d.givens??[]).map(y=>y.name).filter(y=>typeof y=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:i.get(f)??[l],...k.docOf(d.annotations)?{description:k.docOf(d.annotations)}:{},views:Lf(d).map(y=>Af(y,c.get(f)?.get(y.name))),givens:h,fields:u.get(f)??[]})}}return{sources:n}}function rx({editor:e,opened:t,givens:n,catalog:r}){const[s,o]=S.useState(void 0),i=S.useMemo(()=>{const y=new Set((t.localGivens??[]).map(g=>g.name));return(n??[]).filter(g=>!y.has(g.name))},[t,n]),a=S.useMemo(()=>uh(e.document,i),[e.document,i]),l=S.useMemo(()=>new Map(e.document.sources.map(y=>[y.name,ac(r,y.base)])),[r,e.document.sources]),u=S.useCallback(y=>l.get(y.source)??ac(r,y.source),[l,r]),c=(y,g)=>{const w=[];for(const x of e.document.tiles){if(!ce(x))continue;const p=u(x);if(!p)continue;const v=new Map(p.map(_=>[_.name,_.type]));for(const _ of x.filters??[])_.given===y&&(!v.has(_.field)||!Ir(g,v.get(_.field)))&&w.push(`${_.field} on ${x.label??x.name} (${e.document.sources.find(b=>b.name===x.source)?.base??x.source})`)}return w},d=S.useMemo(()=>a.filter(y=>y.origin==="model"&&y.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:o,controlList:a,fieldsFor:u,unknownFieldsOf:c,available:d,applyFilter:(y,g,w)=>{o(void 0),e.update(x=>{w&&xh(x,w),yh(x,y,g)})},dropControl:y=>{o(void 0),e.update(g=>bh(g,y))}}}function sx(e){const{splice:t,onSave:n,structural:r,clearsHistory:s}=e,[o,i]=S.useState({stack:[e.document],index:0}),[a,l]=S.useState(e.source),[u,c]=S.useState(void 0),[d,f]=S.useState(e.document),[h,y]=S.useState(e.replaces),[g,w]=S.useState(!1),x=o.stack[o.index],p=S.useRef(o);p.current=o;const v=S.useRef(!1),[_,b]=S.useState(!1),E=I=>{v.current=I,b(I)},[T,M]=S.useState(void 0),O=S.useCallback(I=>{c(void 0),i(L=>{const q=structuredClone(L.stack[L.index]);if(I(q),JSON.stringify(q)===JSON.stringify(L.stack[L.index]))return L;const K=[...L.stack.slice(0,L.index+1),q].slice(-100);return{stack:K,index:K.length-1}})},[]),C=S.useCallback(()=>{c(void 0),i(I=>I.index>0?{...I,index:I.index-1}:I)},[]),A=S.useCallback(()=>{c(void 0),i(I=>I.index<I.stack.length-1?{...I,index:I.index+1}:I)},[]),R=S.useCallback(async(I,L)=>{try{return await t(I,L)}catch(q){return{ok:!1,reason:`Could not build the file: ${q instanceof Error?q.message:String(q)}`}}},[t]),B=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};const I={source:a,saved:d,history:p.current,replacing:h,unwritten:g},L=s?.(d,x)??!1,q=r?.(d,x)??!1;E(!0);try{const H=await R(a,x);if(io(H))return c(H.reason),{ok:!1,reason:H.reason};try{await n?.(H.source,{purpose:"save",document:x})}catch(te){const ye=`Could not save: ${te instanceof Error?te.message:String(te)}`;return c(ye),{ok:!1,reason:ye}}l(H.source),f(x),y(void 0),w(!1);const K=L?{stack:[x],index:0}:I.history;return i(te=>te===I.history?K:L?{stack:[te.stack[te.index]],index:0}:te),M(n?{before:I,after:K,lastSave:{before:h??a,after:H.source,structural:q,clearsHistory:L}}:void 0),c(void 0),{ok:!0}}finally{E(!1)}},[x,R,n,a,d,h,g,s,r]),G=S.useCallback(async()=>{if(v.current)return{ok:!1,reason:"A save is still being written."};if(!n||T===void 0||T.after!==p.current)return{ok:!1,reason:"There is no save to undo."};const{before:I}=T;E(!0);try{await n(I.replacing??I.source,{purpose:"undo",document:I.saved})}catch(L){const q=`Could not undo the save: ${L instanceof Error?L.message:String(L)}`;return c(q),{ok:!1,reason:q}}finally{E(!1)}return l(I.source),f(I.saved),y(I.replacing),w(I.unwritten||I.replacing!==void 0),i(L=>L===T.after?I.history:L),M(void 0),c(void 0),{ok:!0}},[n,T]),N=S.useMemo(()=>g||JSON.stringify(x)!==JSON.stringify(d),[x,d,g]),X=S.useMemo(()=>r?.(d,x)??!1,[x,d,r]),j=S.useMemo(()=>s?.(d,x)??!1,[x,d,s]),z=T!==void 0&&T.after===o,D=S.useCallback(async()=>{const I=await R(a,x);return io(I)?{ok:!1,reason:I.reason}:{ok:!0,source:I.source}},[x,R,a]);return{document:x,saved:d,source:a,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:N,edited:N,...u===void 0?{}:{error:u},update:O,undo:C,redo:A,save:B,preview:D,structural:X,clearsHistory:j,canUndoSave:z&&!_&&n!==void 0,...z?{lastSave:T.lastSave}:{},undoSave:G}}const ox=(e,t)=>{const n=new Set(e.tiles.map(Li)),r=new Set(t.tiles.map(Li));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function ix(e){const{visibleSources:t,...n}=e,r=S.useCallback((s,o)=>Tf(s,o,t?{visibleSources:t}:{}),[t]);return sx({...n,splice:r,structural:ox})}function ax({editorDirty:e}){const[t,n]=S.useState(!1),r=S.useRef(void 0),s=S.useRef(void 0),o=S.useMemo(()=>({setDirty:n,commitRef:r}),[]),i=S.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return S.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:o,prepare:i}}function lx({editor:e,rules:t,modelPath:n,textHeld:r,selectTile:s,deselectTile:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(!1),[c,d]=S.useState(void 0),f=b=>{d(b),u(!0)},h=()=>u(!1),y=b=>{u(!1),e.update(E=>{th(E,b,{modelPath:n,textHeld:r,widths:t.widths,insertAt:c}),t.widths&&(E.tiles=Va(E.tiles,c??E.tiles.length-1,t.columns))}),s(c??e.document.tiles.length)},g=()=>x(c),w=()=>x(void 0),x=b=>{u(!1),e.update(E=>{const T=new Set(E.tiles.filter(Ie).map(O=>O.name));let M=1;for(;T.has(`text_${M}`);)M++;E.tiles.splice(b??E.tiles.length,0,{kind:"text",name:`text_${M}`,markdown:"",...t.widths?{colspan:t.columns}:{}}),t.widths&&(E.tiles=Va(E.tiles,b??E.tiles.length-1,t.columns))}),s(b??e.document.tiles.length)};return{menu:i,setMenu:a,addingTile:l,openAdd:f,closeAdd:h,addTile:y,addText:g,appendText:w,editTile:(b,E)=>e.update(T=>{const M=T.tiles.find(O=>fe(O)===b);M&&E(M)}),removeTile:b=>{a(void 0),o(),e.update(E=>{E.tiles.splice(b,1)})},duplicate:b=>{a(void 0);const E=e.document.tiles[b],T=E&&ce(E)&&Ws(E)===void 0?b+1:void 0;e.update(M=>{nh(M,b)}),T!==void 0&&s(T)}}}const cx=k.createSvgIcon(m.jsx("path",{d:"M19 5v2h-4V5zM9 5v6H5V5zm10 8v6h-4v-6zM9 17v2H5v-2zM21 3h-8v6h8zM11 3H3v10h8zm10 8h-8v10h8zm-10 4H3v6h8z"}));function Ff({arrange:e}){const{theme:t}=be.usePublisherTheme(),[n,r]=S.useState(null),s=o=>()=>{r(null),o?.()};return m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:"Arrange tiles",children:m.jsx($.IconButton,{"aria-label":"Arrange tiles","aria-haspopup":"menu","aria-expanded":n!==null,onClick:o=>r(o.currentTarget),sx:Nr(t.ui),children:m.jsx(cx,{fontSize:"small"})})}),m.jsxs($.Menu,{anchorEl:n,open:n!==null,onClose:()=>r(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:{minWidth:260,borderRadius:t.ui.radius.menu,border:`1px solid ${k.edgeColor(t.cardBorder)}`,boxShadow:t.ui.shadow.menu}}},children:[m.jsx($.MenuItem,{disabled:!e.pack,onClick:s(e.pack),children:m.jsx($.ListItemText,{primary:"Pack tiles upward",secondary:e.pack?"Close every gap above a tile":"There are no gaps to close"})}),m.jsx($.MenuItem,{onClick:s(e.flow),children:m.jsx($.ListItemText,{primary:"Let tiles flow",secondary:"Clear each tile's place; keep its size"})})]})]})}function Ga({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:o,renderTile:i,renderViewPreview:a,controls:l,givens:u,catalog:c,toolbar:d,dashboards:f,onEvent:h,savesTo:y="package",saveLabel:g,replaces:w,modelPath:x,visibleSources:p,addFilterDisabledReason:v,fixedFilters:_,onOpenModel:b,takenGivenNames:E,onControlsChange:T,draftKey:M}){const O=ix({source:e,document:t,...n?{onSave:n}:{},...w!==void 0?{replaces:w}:{},...p?{visibleSources:p}:{}}),C=k.useReportDraft(M,O,e),A=S.useRef(null),{selected:R,descriptionSelected:B,selectTile:G,deselectTile:N,selectDescription:X,clearSelection:j,flash:z,stepEditor:D}=Yy({editor:O,gridBox:A}),I=k.layoutRules(O.document.layout,O.document.columns),{columns:L}=I,q=x?.split("/").at(-1)?.replace(/\.malloy$/,""),H=$.useMediaQuery("(min-width:900px)",{defaultMatches:!0,noSsr:!0}),K=!I.widths||H,te=Cy({tiles:O.document.tiles,commit:V=>O.update(se=>{se.tiles=V}),onLanded:G,...I.widths&&H?{placement:{columns:L,gridBox:A}}:{}}),ye=(V,se)=>{if(O.update($e=>{$e.tiles=V}),se===void 0)return;const Oe=V.findIndex($e=>fe($e)===se);Oe>=0&&G(Oe)},_e=I.widths,re=S.useCallback((V,se)=>_e&&k.isPlaced(V)?Rt(V,L,se):V,[_e,L]),{dragging:De}=te,ge=k.useDefaultTileSpan(A,L),ve=S.useMemo(()=>O.document.tiles.map(V=>V.colspan===void 0?{...V,colspan:ge}:V),[O.document.tiles,ge]),Ge=Dy({tiles:ve,columns:L,gridBox:A,onStart:G,commit:({index:V,edges:se,shape:Oe,placed:$e,placedAll:Yt})=>{const ne=Yt??O.document.tiles,oe=ne[V];if(!oe)return;let Ue=If(oe,Oe,se,$e);(se.e||se.w)&&(Ue=k.withSpan(Ue,Oe.colspan,L,ge));const bt=ne.map((or,mn)=>mn===V?Ue:or);ye($e?In(Rt(bt,L,V)):bt,fe(oe))}}),Z=lx({editor:O,rules:I,modelPath:x,textHeld:p!==void 0,selectTile:G,deselectTile:N}),{menu:Xe,addingTile:ke,openAdd:ue}=Z,Ce=rx({editor:O,opened:t,givens:u,catalog:c}),{filterDialog:Ae,setFilterDialog:ie}=Ce,[qe,Ye]=S.useState(void 0),{draftDirty:P,openDraft:F,prepare:U}=ax({editorDirty:O.dirty}),Y=Ge.drag!==void 0,Se=S.useMemo(()=>({paused:Y,escape:()=>{!Xe&&!Ae&&!ke&&qe===void 0&&j()},move:(V,se)=>{if(De||R===void 0||!I.widths||!K)return!1;const Oe=O.document.tiles[R];if(!Oe||Oe.row===void 0||Oe.col===void 0)return!1;const $e=Xa(O.document.tiles,R,V,se,L);if($e.every((oe,Ue)=>oe===O.document.tiles[Ue]))return!0;const Yt=fe(Oe);O.update(oe=>{oe.tiles=In(Xa(oe.tiles,R,V,se,L))});const ne=In($e).findIndex(oe=>fe(oe)===Yt);return ne>=0&&G(ne),!0},nudge:V=>{if(De||R===void 0||!I.widths||!K)return;const se=O.document.tiles[R];if(!se)return;const Oe=k.nudgedSpan(se.colspan??ge,V,mc(se,L));Oe!==(se.colspan??ge)&&O.update($e=>{$e.tiles[R]=k.withSpan($e.tiles[R],Oe,L,ge),$e.tiles=re($e.tiles,R)})}}),[Y,ge,K,re,G,O,Xe,Ae,ke,qe,j,R,L,I,De]),we=Jy({editor:D,extraDirty:P,keepsEdits:M!==void 0&&C.keeping,prepare:U,unit:{name:"tile",count:V=>V.tiles.length},onSave:n,onDirtyChange:s,onExit:o,onChange:r,shortcuts:Se,report:Uy({size:O.document.tiles.length,path:x??"",layout:O.document.layout,savesTo:y,onEvent:h})}),ht=O.document.tiles.length===0,{toolbarProps:W}=we,Q=C.restored,Le={status:we.saving?"saving":W.dirty?"unsaved":"saved",saveTarget:g??Ko[y],...C.keptAt!==void 0?{draftKeptAt:C.keptAt}:{},...(W.dirty||Q?.pending)&&M!==void 0?{discard:C.discard}:{},...Q?{restored:Q}:{},...Q&&!Q.pending?{dismissRestored:C.dismissRestored}:{}},Be=O.document.tiles,lt=R!==void 0&&Be[R]?fe(Be[R]):void 0,he=I.widths&&K&&k.isPlaced(Be)?{...Hf(Be,L)?{pack:()=>ye(In(gc(Be,L)),lt)}:{},flow:()=>ye(qf(Be),lt)}:void 0;Ky(T,{...Le,...W.onSave?{save:W.onSave}:{},canUndo:W.canUndo,undo:W.onUndo,canRedo:W.canRedo,redo:W.onRedo,add:{...c?{tile:()=>Z.openAdd()}:{},text:Z.appendText,...v!==void 0?{filterUnavailable:v}:ht?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>ie({})}},...W.onExit?{exit:W.onExit}:{},...we.done?{done:we.done}:{},...Q?.pending?{restore:C.restoreOffered}:{},...he?{arrange:he}:{}});const tt=T?void 0:m.jsx(Qf,{...we.toolbarProps,...d?{actions:d}:{},...c?{onAddTile:()=>ue()}:{},...he?{arrange:m.jsx(Ff,{arrange:he})}:{},savesTo:y,...g?{saveLabel:g}:{},...M!==void 0&&W.onSave?{saveStatus:Le}:{}});return m.jsx(Hu.Provider,{value:F,children:m.jsx($.Stack,{className:k.reportClasses.builder,"data-saves-to":y,sx:{gap:0,mx:`-${Go}px`},children:m.jsxs(k.ReportPage,{layout:I.layout,sx:{px:`${Go}px`,pb:`${Go}px`},header:m.jsx(qy,{editor:O,documentSlug:q,actions:tt,descriptionSelected:B,selectDescription:X}),controls:ht?void 0:m.jsx(Vy,{controls:Ce.controlList,unknownFieldsOf:Ce.unknownFieldsOf,onEdit:V=>ie({control:V}),onAdd:()=>ie({}),...v?{addDisabledReason:v}:{},onRemove:Ce.dropControl,..._?{fixedFilters:_}:{},...b?{onOpenModel:b}:{},...O.document.startingGivens?{startingValues:O.document.startingGivens}:{},onStartingValue:(V,se)=>O.update(Oe=>{const $e={...Oe.startingGivens??{}};se===void 0?delete $e[V]:$e[V]=se,Object.keys($e).length>0?Oe.startingGivens=$e:delete Oe.startingGivens}),children:l}),children:[ht&&m.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[m.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),c&&m.jsx($.Button,{size:"small",startIcon:m.jsx(k.AddIcon,{}),onClick:()=>ue(),children:"Add tile"})]}),Q?.pending&&m.jsx($.Alert,{severity:"warning",action:m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:C.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:C.discard,children:"Discard"})]}),children:`You have unsaved edits from ${qo(Q.savedAt)}, made before this report changed. Restoring them replaces the current version.`}),O.error&&m.jsx($.Alert,{severity:"warning",children:O.error}),!K&&m.jsx($.Alert,{severity:"info",children:"This window is too narrow for the grid, so tiles stack in one column, as on a phone. Widen it to move tiles or change their width."}),m.jsx(zy,{editor:O,arrange:K,reorder:te,edging:Ge,place:re,gridBox:A,defaultSpan:ge,rules:I,canAdd:!!c,selected:R,flash:z,menuIndex:Xe?.index,onSelect:G,onOpenMenu:(V,se)=>{G(se),Z.setMenu({anchor:V,index:se})},onRemove:Z.removeTile,...O.document.tiles.length===1&&O.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:ue,editTile:Z.editTile,...i?{renderTile:i}:{}}),m.jsx(jh,{editor:O,catalog:c,columns:L,dashboards:f,bindings:Ce,tiles:Z,drillSource:qe,setDrillSource:Ye,exitDialog:we.exitGuard.dialog,...a?{renderViewPreview:a}:{},...E?{takenGivenNames:E}:{}})]})})})}const dx=k.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),ux=k.createSvgIcon(m.jsx("path",{d:"M9 17H7v-7h2zm4 0h-2V7h2zm4 0h-2v-4h2zm2.5 2.1h-15V5h15zm0-16.1h-15c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2"})),fx=k.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"}));function hx({controls:e,onDone:t}){const n=t??e?.exit,r=$.useMediaQuery("(max-width: 599.95px)"),{theme:s}=be.usePublisherTheme(),o=k.edgeColor(s.cardBorder),i=k.hoverEdgeColor(s.cardBorder,s.tileTitle),[a,l]=S.useState(null),u=e?.save!==void 0&&e.status!=="saved",c=e?.done??n,d=u&&e?.done===void 0,f=e?.add,h=f!==void 0&&(f.tile!==void 0||f.text!==void 0||f.filter!==void 0||f.filterUnavailable!==void 0),y=g=>()=>{l(null),g?.()};return m.jsxs($.Stack,{direction:"row",role:"toolbar",className:k.reportClasses.builderBar,"aria-label":"Report builder",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[e&&m.jsxs(m.Fragment,{children:[e.save&&m.jsx(xc,{...e}),!r&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:`Undo (${cn}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e.canUndo,onClick:e.undo,sx:Nr(s.ui),children:m.jsx(yc,{fontSize:"small"})})})}),m.jsx($.Tooltip,{title:`Redo (${cn}⇧Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Redo",disabled:!e.canRedo,onClick:e.redo,sx:Nr(s.ui),children:m.jsx(vc,{fontSize:"small"})})})}),e.arrange&&m.jsx(Ff,{arrange:e.arrange}),h&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),h&&m.jsxs(m.Fragment,{children:[m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(k.AddIcon,{}),endIcon:m.jsx(k.ExpandMoreIcon,{}),"aria-haspopup":"menu","aria-expanded":a!==null,onClick:g=>l(g.currentTarget),sx:{...Mr(o,i),"& .MuiButton-endIcon":{ml:.25,"& svg":{fontSize:16}}},children:"Add"}),m.jsxs($.Menu,{anchorEl:a,open:a!==null,onClose:()=>l(null),disableRestoreFocus:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:-6,horizontal:"right"},slotProps:{paper:{sx:px(o,s.ui)}},MenuListProps:{sx:{p:.5}},children:[f?.tile&&m.jsx(Ho,{icon:m.jsx(ux,{}),title:"Tile",detail:"A chart or table from the model",onClick:y(f.tile)}),f?.text&&m.jsx(Ho,{icon:m.jsx(fx,{}),title:"Text",detail:"Prose between the tiles",onClick:y(f.text)}),(f?.filter||f?.filterUnavailable)&&m.jsx(Ho,{icon:m.jsx(dx,{}),title:"Filter",detail:f.filterUnavailable??"A control the tiles read",disabled:f.filter===void 0,onClick:y(f.filter)})]})]})]})]}),(c||d)&&e&&m.jsx($.Divider,{orientation:"vertical",sx:Bs}),c&&m.jsx($.Tooltip,{enterDelay:800,enterNextDelay:800,title:e?.done&&u?`Saves your edits, then shows the report · ${e.saveTarget}`:"",children:m.jsx("span",{children:m.jsx($.Button,{variant:d?"outlined":"contained",disableElevation:!0,disabled:e?.status==="saving",onClick:c,sx:{...Mr(o,i,s.ui),width:92},children:e?.done&&e.status==="saving"?"Saving…":"Done"})})}),e?.save&&d&&m.jsx($.Tooltip,{title:`Save (${cn}S) · ${e.saveTarget}`,children:m.jsx("span",{children:m.jsx($.Button,{variant:"contained",disableElevation:!0,disabled:e.status==="saving",onClick:e.save,sx:{...Mr(o,i,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}const px=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function Ho({icon:e,title:t,detail:n,disabled:r=!1,onClick:s}){const{theme:o}=be.usePublisherTheme(),i=o.ui;return m.jsxs($.MenuItem,{onClick:s,disabled:r,sx:a=>({gap:1.5,px:1.25,py:1,borderRadius:i.radius.control,alignItems:"center","& .add-icon":{width:32,height:32,flex:"none",borderRadius:i.radius.tile,display:"flex",alignItems:"center",justifyContent:"center",color:a.palette.text.secondary,bgcolor:a.palette.action.hover,transition:`color ${k.MOTION_FAST}, background-color ${k.MOTION_FAST}`,"& svg":{fontSize:18}},"&:hover .add-icon, &.Mui-focusVisible .add-icon":{color:o.accent,bgcolor:`color-mix(in srgb, ${o.accent} 10%, ${a.palette.background.paper})`},"&.Mui-focusVisible":{outline:"none",bgcolor:a.palette.action.hover},"&.Mui-disabled":{opacity:1},"&.Mui-disabled .add-text":{opacity:.5},"&.Mui-disabled .add-icon":{opacity:.5}}),children:[m.jsx($.Box,{className:"add-icon","aria-hidden":!0,children:e}),m.jsxs($.Box,{className:"add-text",sx:{minWidth:0},children:[m.jsx($.Box,{sx:{...i.type.control,fontWeight:i.type.label.fontWeight,lineHeight:1.3},children:t}),m.jsx($.Box,{sx:{...i.type.caption,color:"text.secondary",whiteSpace:"normal",maxWidth:220},children:n})]})]})}function gx(e,t,n=new Set,r=new Map){const s=[];for(const c of e.tiles){if(!ce(c))continue;const d=(c.filters??[]).map(h=>h.given),f=r.get(Dt(`${c.source} -> ${c.name}`))??[];for(const h of f)(n.has(h)||d.includes(h))&&s.push(h);s.push(...d)}const o=new Set(s),i=t.flatMap(c=>c.name!==void 0&&n.has(c.name)&&!o.has(c.name)?[c.name]:[]),a=new Map((e.localGivens??[]).map(c=>[c.name,c])),l=new Map(t.flatMap(c=>c.name===void 0?[]:[[c.name,c]])),u=[];for(const c of new Set([...i,...s])){const d=a.get(c),f=d?k.localGivenSpec(d):l.get(c);f&&u.push(f)}return u}function mx(e,t,n){const r=new Map;for(const o of t.tiles)ce(o)&&r.set(Dt(dt(o)),new Set((o.filters??[]).map(i=>i.given)));const s=new Set;for(const o of e.tiles){if(!ce(o))continue;const i=Dt(dt(o)),a=r.get(i);for(const l of n.get(i)??[])a?.has(l)||s.add(l)}return s}function vx(e){const t=e?.trim();if(!(!t||/^f(['"])\1$/.test(t)))return t}function yx(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function Dt(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function xx(e,t,n,r){const s=new Set(t.sources.map(a=>a.name)),o=new Set(e.sources.map(a=>a.name).filter(a=>!s.has(a)));return o.size===0?void 0:{sources:o,modelOf:a=>{if(r)return;const l=e.imports.find(c=>c.kind==="names"&&c.names.includes(a));if(l===void 0)return;const u=k.resolvedOf(l.from,n);return k.reaches(t,a,u,n)?void 0:u}}}function bx(e,t,n){if(!n||t.declaration.kind!=="reference")return;let r=t.source,s=t.declaration.from;if(r===void 0||!n.sources.has(r))return;const o=e.tiles.length+e.sources.length;for(let i=0;i<=o;i++){if(!n.sources.has(r)){const u=n.modelOf?.(r);return{source:r,view:s,...u?{modelPath:u}:{}}}const a=e.sources.find(u=>u.name===r);if(!a||a.scopedBy?.length)return;const l=e.tiles.find(u=>ce(u)&&u.source===r&&u.name===s);if(!l)r=a.base;else if(l.declaration.kind==="reference")s=l.declaration.from;else return}}function wx(e,t,n,r=new Map,s,o){if(Hn(t))return{expression:dt(t),givenNames:void 0,reads:s&&[...s]};const i=bx(e,t,o),a=i?.source??t.source,l=i?.view??(t.declaration.kind==="reference"?t.declaration.from:t.name),u=i?.modelPath!==void 0?new Set:n,c=new Map((e.localGivens??[]).map(b=>[b.name,b.type])),d=new Map((e.localGivens??[]).map(b=>[b.name,b.default])),f=e.sources.find(b=>b.name===a)?.scopedBy??[],h=new Set([...f,...s??[]].filter(b=>u.has(b))),y=new Set([...f,...s??[]]),g=[];for(const b of t.filters??[]){const E=`where: ${me.malloyPath(b.field)} ${b.op??"~"}`;if(u.has(b.given)){h.add(b.given),y.add(b.given),g.push(`${E} $${b.given}`);continue}if(!c.has(b.given))continue;y.add(b.given);const T=k.malloyLiteral(r.get(b.given),c.get(b.given))??vx(d.get(b.given));T!==void 0&&g.push(`${E} ${T}`)}const w=g.join(", "),x=t.chart,p=x==="none"||k.isChartPick(x)?k.chartLineText(x,t.chartCarried):x==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
+ `):x==="default"&&yx(t.declaration)?k.chartResetLine():void 0,v=t.color!==void 0?k.seriesColorLine(t.color):t.declaration.kind!=="reference"&&!t.ownPalette?k.seriesColorResetLine:void 0,_=[p,v].filter(Boolean).join(`
144
+ `)||void 0;return{..._?{annotation:_}:{},...i?.modelPath!==void 0?{modelPath:i.modelPath}:{},expression:`${a} -> ${l}`+(w?` + { ${w} }`:""),givenNames:Array.from(h),reads:s||y.size>0?Array.from(y):void 0}}function _x({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:o}){const{apiClients:i,server:a}=be.useServer(),{data:l}=k.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await i.models.listModels(e,t,n)).data.flatMap(y=>y.path&&!y.error?[y.path]:[])}),u=S.useMemo(()=>new Set([r,...s.flatMap(y=>y.path?[y.path]:[])]),[s,r]),c=S.useMemo(()=>o?(l??[]).filter(y=>!u.has(y)):[],[l,u,o]),d=uc.useQueries({queries:c.map(y=>({queryKey:["report-editor-model",e,t,y,n,a],queryFn:async()=>(await i.models.getModel(e,t,y,n)).data,retry:!1}))}),f=l!==void 0&&o&&d.every(y=>y.isSuccess||y.isError),h=d.map(y=>y.dataUpdatedAt).join();return S.useMemo(()=>f?Bf(d.flatMap((y,g)=>y.data?[{...y.data,path:c[g]}]:[]),u):void 0,[f,c,h,u])}const kx={};function Sx({textSource:e,environmentName:t,packageName:n,modelPath:r,versionId:s,queryVersionId:o,opened:i,replaces:a,onSave:l,onDirtyChange:u,onExit:c,onOpenModel:d,onControlsChange:f,draftKey:h,onEvent:y,savesTo:g,saveLabel:w,note:x,fileModel:p}){const{apiClients:v}=be.useServer(),[_,b]=S.useState(i.document.tiles.length>0);S.useEffect(()=>b(i.document.tiles.length>0),[i.generation,i.document]);const{data:E,isSuccess:T,isError:M}=k.useQueryWithApiError({...k.reportQueryOptions(v,{environmentName:t,packageName:n,path:r,versionId:o},k.BUILDER_HANDOFF_STALE_MS),enabled:_&&!e}),O=e?.modelPath??r,C=Tx(i.source,e?.compileSource),A=k.useCompiledDocument({environmentName:t,packageName:n,modelPath:O,source:C.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&C.text!==void 0}),R=A.data?.document,B=e?A.isSuccess?R?.manifest??kx:void 0:E,G=e?A.isSuccess:T,N=e?A.isError||C.problem!==void 0:M,X=e?k.documentPreamble(R?.cells):void 0,j=(A.data?.result.problems??[]).filter(W=>W.severity==="error"),z=S.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),D=e?.givens,I=S.useMemo(()=>new Set((B?.tiles??[]).flatMap(W=>W.restricted&&W.query?[Dt(W.query)]:[])),[B]),{reports:L,settled:q}=k.useReportListing(t,n,o),H=S.useMemo(()=>L.map(W=>W.path).filter(W=>!!W&&W!==r&&W.endsWith(".malloy")).map(W=>W.replace(/\.malloy$/,"")),[L,r]),K=_x({environmentName:t,packageName:n,...o!==void 0?{versionId:o}:{},modelPath:r,reports:L,reportsSettled:q}),te=S.useMemo(()=>e?(K?.sources??[]).filter(W=>(W.visibleIn??W.exporters??[W.modelPath]).includes(O)).map(W=>W.name):void 0,[K,e,O]),ye=S.useMemo(()=>p?nx(p):void 0,[p]),_e=S.useMemo(()=>{const W=K&&te?{sources:K.sources.filter(Q=>te.includes(Q.name))}:K;return W&&ye?{...W,documentViews:ye}:W},[K,te,ye]),[re,De]=S.useState(i.document);S.useEffect(()=>De(i.document),[i.document]);const ge=S.useMemo(()=>l&&(async(W,Q)=>{await l(W,Q.document.layout),g==="package"&&b(Q.document.tiles.length>0)}),[l,g]),ve=S.useMemo(()=>(B?.givens??[]).filter(W=>!(e&&W.secure===!0)&&!(W.name!==void 0&&z.has(W.name))),[B,z,e]),Ge=S.useMemo(()=>new Set([...ve.map(W=>W.name).filter(W=>W!==void 0),...Object.keys(D??{})]),[ve,D]),Z=S.useMemo(()=>new Map((B?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.givenNames?[[Dt(W.query),W.givenNames]]:[])),[B]),Xe=S.useMemo(()=>new Map((B?.tiles??[]).flatMap(W=>W.kind!=="text"&&W.query&&W.label?[[Dt(W.query),W.label]]:[])),[B]),ke=S.useMemo(()=>mx(re,i.document,Z),[re,i.document,Z]),ue=S.useMemo(()=>gx(re,ve,ke,Z),[re,ve,ke,Z]),Ce=S.useMemo(()=>{const W=new Set(re.tiles.flatMap(he=>ce(he)?(he.filters??[]).map(tt=>tt.given):[])),Q=new Set((re.localGivens??[]).map(he=>he.name)),Le=[...new Set(re.imports.map(he=>he.from))],Be=Le.length===1?Ex(r,Le[0]):Le.length===0&&e?e.modelPath:void 0,lt=he=>{const tt=re.sources.filter(V=>V.scopedBy?.includes(he)).map(V=>V.name);return tt.length>0?{reason:`Applied to every tile on ${tt.join(", ")} by this report's own source. Edit the file to change it.`}:Q.has(he)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:Be!==void 0?{reason:`Set in the model ${Be}. Edit the model to change it.`,modelPath:Be}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([...ke].filter(he=>!W.has(he)).map(he=>[he,lt(he)]))},[re,ke,e,r]),{declaredTypes:Ae,applied:ie,panel:qe}=k.useDocumentControls({specs:ue,loaded:G,startingValues:B?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:B?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?O:B?.path,versionId:o,documentName:r,...X!==void 0?{preamble:X}:{},...D?{hostGivens:D}:{}}),Ye=S.useMemo(()=>k.missingRequiredGivens(ue,ie,D),[ue,ie,D]),P=S.useMemo(()=>Object.fromEntries(Object.entries(D??{}).filter(([W])=>!Ae.has(W))),[D,Ae]),F=!_||G||N,U=e!==void 0&&(C.problem!==void 0||A.isError||j.length>0),Y=S.useMemo(()=>new Map(i.document.tiles.map(W=>[fe(W),W])),[i.document]),Se=S.useMemo(()=>xx(re,i.document,r,!!e),[re,i.document,r,e]),we=S.useMemo(()=>function(Q,Le,Be="card"){const lt=(Hn(Q)?Xe.get(Dt(dt(Q))):void 0)??co(Q);if(U)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!F)return m.jsxs(k.TileCard,{chrome:Be,children:[m.jsx(k.TileHeading,{title:Le?.title??lt,subtitle:Le?Le.subtitle:Q.subtitle}),m.jsx(k.Loading,{text:"Running…"})]});const he=Z.get(Dt(dt(Q))),V=X===void 0&&he!==void 0&&$x(Y.get(fe(Q)),Q)?{expression:dt(Q),givenNames:[...he],reads:[...he]}:wx(re,Q,Ge,ie,he,Se),se=k.layoutRules(re.layout,re.columns);return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:V.modelPath??O,...X!==void 0&&V.modelPath===void 0?{preamble:X}:{},...I.has(Dt(dt(Q)))?{restricted:!0}:{},tile:V.expression,...V.annotation?{annotation:V.annotation}:{},label:lt,chrome:Be,subtitle:Q.subtitle,...Le?{heading:Le}:{},borderless:Q.borderless,givens:ie,hostGivens:P,declaredTypes:Ae,givenNames:V.givenNames,...(()=>{const Oe=k.waitingOn(Ye,V.reads??V.givenNames);return Oe.length>0?{waitingFor:k.waitingText(Oe)}:{}})(),ignoredFilters:k.tileIgnoredFilterLabels(V.reads,ue),height:Q.rowspan!==void 0||k.isPlaced(re.tiles)?k.tileHeightPx(Q.rowspan??k.PLACED_DEFAULT_ROWSPAN.query):se.tileMaxHeight,tableMaxHeight:se.tableMaxHeight,fixedHeight:Q.rowspan!==void 0||k.isPlaced(re.tiles)})},[re,Y,F,U,Ye,Ge,Z,Xe,t,n,o,O,X,Se,I,ie,P,Ae,ue]),ht=S.useMemo(()=>function(Q){return m.jsx(k.DashboardTile,{environmentName:t,packageName:n,versionId:o,modelPath:Q.modelPath,tile:`${Q.base} -> ${Q.view}`,...Q.chart?{annotation:k.chartLineText(Q.chart,Q.chartCarried)}:{},label:Q.label,borderless:!0,givens:ie,hostGivens:P,declaredTypes:Ae,givenNames:Q.givens,height:200})},[t,n,o,ie,P,Ae]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&j.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",j.map(W=>W.message).join("; ")]}),Ye.length>0&&!U&&m.jsx($.Alert,{severity:"info",children:k.requiredPrompt(Ye)}),e&&C.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",C.problem]}),e&&A.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",A.error?.message]}),m.jsx(Ga,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:i.source,document:i.document,fixedFilters:Ce,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:we,renderViewPreview:ht,givens:ue.filter(W=>W.name!==void 0).map(W=>({name:W.name,...W.label?{label:W.label}:{},...W.type?{type:W.type}:{},...W.suggest?.dimension?{field:W.suggest.dimension}:{}})),onChange:De,onDirtyChange:u,...c?{onExit:c}:{},...d?{onOpenModel:d}:{},...f?{onControlsChange:f}:{},...h!==void 0?{draftKey:h}:{},..._e?{catalog:_e}:{},dashboards:H,...y?{onEvent:y}:{},controls:G?m.jsx(k.GivensPanel,{...qe,layout:"bar"}):void 0,...ge?{onSave:ge}:{},savesTo:g,...w?{saveLabel:w}:{},...a!==void 0?{replaces:a}:{},modelPath:r,...e?{visibleSources:te}:{}}),m.jsx($.Box,{sx:{px:.5},children:m.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:x})})]})}function $x(e,t){return e!==void 0&&JSON.stringify(dc(e))===JSON.stringify(dc(t))}function dc(e){const{label:t,subtitle:n,colspan:r,break:s,rowspan:o,row:i,col:a,borderless:l,...u}=e;return u}function Tx(e,t){const n=S.useRef(t);n.current=t;const r=t!==void 0,[s,o]=S.useState();return S.useEffect(()=>{if(!r)return;let i=!0;return Promise.resolve().then(()=>n.current(e)).then(a=>{i&&o({from:e,text:a})},a=>{i&&o({from:e,problem:a instanceof Error?a.message:String(a)})}),()=>{i=!1}},[e,r]),r?s?.from!==e?{}:s.problem!==void 0?{problem:s.problem}:{text:s.text}:{text:e}}function Ex(e,t){const n=e.split("/").slice(0,-1);for(const r of t.split("/"))r===".."?n.pop():r!=="."&&r!==""&&n.push(r);return n.join("/")}function Cx({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:o}){const[i,a]=S.useState(void 0),[l,u]=S.useState(void 0),[c,d]=S.useState(e===void 0),[f,h]=S.useState(!1),[y,g]=S.useState(void 0);return S.useEffect(()=>{if(!e)return;let w=!1;return g(void 0),(async()=>{try{const x=k.chooseWorkspace(await e.listWorkspaces(!1));if(w)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const p=await e.getDocument(k.locatorFor(t,x.name,r,s,o)).catch(v=>{if(!k.isDocumentNotFound(v))throw v});if(w)return;u(p),h(p!==void 0)}}catch(x){if(w)return;g(k.storageErrorMessage(x))}w||d(!0)})(),()=>{w=!0}},[e,t,n,r,s,o]),{workspace:i,draft:l,setDraft:u,draftChecked:c,offered:f,setOffered:h,readFailure:y}}const Ox=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function Mx(e){const t=await oo(e);return so(t)?{ok:!1,reason:Ox(t.reason,t.line)}:{ok:!0,document:t.document}}const Ix="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",Dx="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function Px({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:o,packageSettled:i,modelPath:a,layout:l,notebook:u,noun:c,legacyFormat:d,textHeld:f,startedAt:h,onEventRef:y}){const g=S.useRef({path:a,layout:l});g.current={path:a,layout:l};const w=S.useRef((ue,Ce)=>{try{y.current?.(k.withReportContext(ue,{...g.current,...Ce?{layout:Ce}:{}}))}catch{}}),x=e?.authoritative===!0,p=x&&r!==void 0,[v,_]=S.useState(void 0),b=(x||v===!0)&&t!==void 0,[E,T]=S.useState(void 0),[M,O]=S.useState(d?Ix:void 0),C=S.useRef(void 0),A=S.useRef(void 0),[R,B]=S.useState(void 0),G=S.useRef(o);G.current=o;const N=R!==void 0&&R.onFetch===o?R.text:s,X=S.useRef(N);X.current=N;const j=b?t:N,[z,D]=S.useState(!1),[I,L]=S.useState(void 0),[q,H]=S.useState(void 0),K=j!==void 0&&j!==q,te=E?.source,_e=K&&(z||!x&&t!==void 0&&te===t&&t!==N)&&te!==void 0&&j!==I,re=_e?te:K?j:te??j,De=_e?j:void 0,ge=S.useRef(te);ge.current=te;const ve=S.useRef(j);ve.current=j;const Ge=S.useRef("package");Ge.current=b?x?"record":"draft":"package",S.useEffect(()=>{if(re===void 0||!n||p||re===ge.current)return;let ue=!1;const Ce=X.current,Ae=ve.current;return Mx(re).then(ie=>{if(!ue){if(ie.ok===!1){O(ie.reason),w.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}O(void 0),C.current=void 0,A.current=Ce,B(void 0),L(void 0),H(Ae),T(qe=>({source:re,document:ie.document,...Ce!==void 0?{packageText:Ce}:{},generation:(qe?.generation??0)+1})),w.current({type:"report.opened",surface:"edit",from:Ge.current,tiles:ie.document.tiles.length,durationMs:k.now()-h.current},ie.document.layout)}}).catch(ie=>{if(ue)return;const qe=`Could not read the ${c}: ${ie instanceof Error?ie.message:String(ie)}`;O(qe),w.current({type:"report.load_failed",surface:"edit",category:k.failureCategory(ie)})}),()=>{ue=!0}},[re,a,n,p,u,c,f,h]),S.useEffect(()=>{d&&w.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[d]),S.useEffect(()=>{!f||!n||E||r!==void 0||(x?t===void 0&&O("the host's storage has no document at this location."):O("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,E,r,x,t]);const Z=u&&!f&&!E&&n&&!b&&i&&s===void 0;return S.useEffect(()=>{Z&&(O(Dx),w.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[Z]),{authoritative:x,blockedOnRecord:p,resume:v,setResume:_,fromDraft:b,opened:E,setOpened:T,openError:M,savedHashRef:C,packageBaseRef:A,setWrote:B,fetchedAtRef:G,setDirty:D,setSeen:H,held:De,choose:ue=>{h.current=k.now(),L(ue?t:N),_(ue)},acceptHeld:()=>{h.current=k.now(),L(De)}}}function jx({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:o,modelPath:i,versionId:a,apiClients:l,queryClient:u,mutable:c,textHeld:d,readFailure:f,authoritative:h,resume:y,setResume:g,setOpened:w,setDraft:x,setOffered:p,setSeen:v,setWrote:_,savedHashRef:b,packageBaseRef:E,fetchedAtRef:T}){const M=S.useCallback(I=>t===void 0?void 0:k.locatorFor(I,t.name,s,o,i),[t,s,o,i]),O=M(n),C=S.useCallback(async(I,L=n)=>{const q=M(L);if(!e||!q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(q,I),w(H=>H&&{...H,source:I}),x(I),(h||y===!0)&&v(I),h||g(H=>H??!1)},[e,M,n,h,y,w,x,v,g]),[A,R]=S.useState(void 0),B=S.useCallback(async I=>{const L=await k.expectedHashFor(b.current,E.current);if(L===void 0)throw new Error("The package file is still loading; try again.");const q=["dashboard-editor-model",s,o,i,a,r];await k.writePackageFile({apiClients:l,queryClient:u,environmentName:s,packageName:o,modelPath:i,source:I,expectedHash:L,invalidateOnError:[q],afterWrite:async H=>{if(w(K=>K&&{...K,source:I}),_({text:I,onFetch:T.current}),v(I),b.current=H,R(void 0),e&&O)try{await e.deleteDocument(O),x(void 0),p(!1)}catch(K){k.isDocumentNotFound(K)?(x(void 0),p(!1)):R(k.storageErrorMessage(K))}g(!1)},invalidate:[{queryKey:q,wait:!0},{queryKey:k.modelResultsKey({environmentName:s,packageName:o,versionId:a,modelPath:i})}]}),k.invalidateReportQueries(u,s,o,i)},[l,s,o,i,a,r,e,O,u,b,E,T,w,_,v,x,p,g]),G=t?.writeable===!0,N=c===!0&&!d,{savesTo:X,pinnedPackageSave:j,writer:z}=k.saveTarget({authoritative:h,mutable:N,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!O&&G&&(!r||h),readFailed:f!==void 0});return{save:z==="storage"?C:z==="package"?B:void 0,savesTo:X,writer:z,pinnedPackageSave:j,takesWrites:N,supersedeFailure:A}}function Ha(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:o,onControlsChange:i,keepDraft:a,kind:l,path:u,textSource:c,queryVersionId:d}=e,f=e.layout??(l?k.layoutOfKind(l):"grid"),h=f==="linear",y=c!==void 0,{environmentName:g,packageName:w,versionId:x,namesBoth:p}=k.resolveEditorTarget(e),_=("resourceUri"in e?e.dashboard:e.dashboardName)??k.documentSlug(u)??"",b="report",{apiClients:E,mutable:T,isLoadingStatus:M,server:O}=be.useServer(),C=uc.useQueryClient(),A=S.useRef(k.now()),R=S.useRef(t);R.current=t;const B=S.useRef(r);B.current=r;const G=k.useOptionalDocumentStorage()?.documentStorage,N=u??k.legacyNamedPath(l??"dashboard",_),X=/\.malloynb$/i.test(N)||h&&/\.malloynb$/i.test(_),j=k.useQueryWithApiError({queryKey:["dashboard-editor-model",g,w,N,x,h],queryFn:()=>E.models.getModel(g,w,N,x,h?!0:void 0),enabled:p&&!X&&!y}),z=j.data?.data?.sourceText,{workspace:D,draft:I,setDraft:L,draftChecked:q,offered:H,setOffered:K,readFailure:te}=Cx({storage:G,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N}),{authoritative:ye,blockedOnRecord:_e,resume:re,setResume:De,fromDraft:ge,opened:ve,setOpened:Ge,openError:Z,savedHashRef:Xe,packageBaseRef:ke,setWrote:ue,fetchedAtRef:Ce,setDirty:Ae,setSeen:ie,held:qe,choose:Ye,acceptHeld:P}=Px({workspace:D,draft:I,draftChecked:q,readFailure:te,packageText:z,fetchedAt:j.dataUpdatedAt,packageSettled:j.isSuccess&&!j.isFetching,modelPath:N,layout:f,notebook:h,noun:b,legacyFormat:X,textHeld:y,startedAt:A,onEventRef:R}),{save:F,savesTo:U,writer:Y,pinnedPackageSave:Se,takesWrites:we,supersedeFailure:ht}=jx({storage:G,workspace:D,layout:f,notebook:h,environmentName:g,packageName:w,modelPath:N,versionId:x,apiClients:E,queryClient:C,mutable:T,textHeld:y,readFailure:te,authoritative:ye,resume:re,setResume:De,setOpened:Ge,setDraft:L,setOffered:K,setSeen:ie,setWrote:ue,savedHashRef:Xe,packageBaseRef:ke,fetchedAtRef:Ce}),W=D?.name,Q=S.useCallback(ne=>{R.current?.(k.withWorkspace(ne,W))},[W]),Le=j.isError&&!ve,Be=S.useRef(!1);S.useEffect(()=>{!Le||Be.current||(Be.current=!0,k.reportEmitter({path:N,layout:f},R.current).emit({type:"report.load_failed",surface:"edit",category:k.failureCategory(j.error)}))},[Le,j.error,N,f]);const lt=S.useCallback((ne,oe)=>{Ae(ne),B.current?.(oe)},[Ae]),he=!c&&j.data?.data&&z!==void 0&&ve?.source===z?j.data.data:void 0,tt=a?k.reportDraftKey({server:O,environmentName:g,packageName:w,versionId:x,path:u??_}):void 0,V=U==="host"&&D?.description?D.description:void 0,se=!ye&&!y&&T===void 0?M?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":k.saveCaption({authoritative:ye,mutable:we,pinnedPackageSave:Se,...D?{workspace:D}:{},...te!==void 0?{readFailure:te}:{},...x!==void 0?{versionId:x}:{}}),$e=U==="package"&&we===!0&&!Se&&te===void 0||se===V?"":se;if(!p&&"resourceUri"in e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",b," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(Z)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened in the builder: ",Z]});if(j.isError&&!ve)return m.jsx(k.ApiErrorDisplay,{error:j.error,context:`Opening the ${b}`});if(!ve&&(!(y||z)||!q))return n??m.jsx(k.Loading,{text:`Opening the ${b}…`});if(_e)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",te]});const Yt=I!==void 0&&I!==z;return m.jsxs($.Stack,{sx:{gap:2},children:[j.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",j.error?.message,". Your edits are still here."]}),!h&&!ye&&H&&Yt&&re===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>Ye(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>Ye(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),qe!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{tt!==void 0&&k.clearReportDraft(tt),P()},children:"Load it"}),children:U==="package"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":U==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),ht!==void 0&&m.jsxs($.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",ht]}),!ve&&(n??m.jsx(k.Loading,{text:`Opening the ${b}…`})),ve&&m.jsx(Sx,{environmentName:g,packageName:w,modelPath:N,...c?{textSource:c}:{},slug:_,...x!==void 0?{versionId:x}:{},...(d??x)!==void 0?{queryVersionId:d??x}:{},opened:ve,...ge&&Y==="package"&&ve.packageText!==void 0?{replaces:ve.packageText}:{},onSave:F,onDirtyChange:lt,...s?{onExit:s}:{},...o?{onOpenModel:o}:{},...i?{onControlsChange:i}:{},...tt!==void 0?{draftKey:tt}:{},savesTo:U,...V?{saveLabel:V}:{},...t?{onEvent:Q}:{},note:$e,...he?{fileModel:he}:{}},ve.generation)]})}const Rx=Ha,Ax=Ga;function Lx(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,o="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Ha,{...o,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=k.MAX_SLUG_ATTEMPTS;exports.createDocument=k.createDocument;exports.createRoute=k.createRoute;exports.locatorFor=k.locatorFor;exports.newDashboardSource=k.newDashboardSource;exports.newDocumentProblem=k.newDocumentProblem;exports.newNotebookSource=k.newNotebookSource;exports.reportPathFor=k.reportPathFor;exports.reportPathForTitle=k.reportPathForTitle;exports.slugFor=k.slugFor;exports.slugOrFallback=k.slugOrFallback;exports.useDocumentChoices=k.useDocumentChoices;exports.BuilderBar=hx;exports.DashboardBuilder=Ax;exports.DashboardEditor=Rx;exports.NotebookEditor=Lx;exports.ReportBuilder=Ga;exports.ReportEditor=Ha;exports.buildCatalog=Bf;exports.readDashboardDocument=oo;exports.readFailed=so;exports.readReportTagOfText=Bv;exports.spliceDashboardDocument=Tf;exports.spliceFailed=io;