@malloy-publisher/sdk 0.9.10 → 0.9.11

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 (257) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7493 -6769
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  17. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  18. package/dist/components/Package/PackageProblems.d.ts +14 -0
  19. package/dist/components/RemoveBadge.d.ts +40 -0
  20. package/dist/components/Report/Report.d.ts +13 -4
  21. package/dist/components/Report/ReportPage.d.ts +60 -0
  22. package/dist/components/Report/layoutRules.d.ts +32 -0
  23. package/dist/components/Report/reportQuery.d.ts +30 -0
  24. package/dist/components/Report/telemetry.d.ts +0 -2
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  26. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  27. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  29. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  30. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  31. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  32. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  33. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  34. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
  35. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  36. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  37. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  38. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  39. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  40. package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
  41. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  42. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  43. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  44. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  45. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  46. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  47. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  48. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  49. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  50. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  51. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  52. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  53. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  54. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  55. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  56. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  57. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  58. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  59. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  60. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  61. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  62. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  63. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  64. package/dist/components/ServerProvider.d.ts +9 -0
  65. package/dist/components/controlTokens.d.ts +45 -0
  66. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  67. package/dist/components/given/FilterButton.d.ts +35 -0
  68. package/dist/components/given/GivensPanel.d.ts +2 -1
  69. package/dist/components/given/filterEditing.d.ts +54 -0
  70. package/dist/components/given/filterSummary.d.ts +9 -0
  71. package/dist/components/given/paramCodec.d.ts +11 -0
  72. package/dist/components/given/required.d.ts +25 -0
  73. package/dist/components/index.d.ts +3 -0
  74. package/dist/components/legacy/index.d.ts +1 -1
  75. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  76. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  77. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  78. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  79. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  80. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  81. package/dist/components/styles.d.ts +0 -2
  82. package/dist/hooks/useQueryResult.d.ts +7 -0
  83. package/dist/index.cjs.js +16 -19
  84. package/dist/index.es.js +8324 -7769
  85. package/dist/theme/ThemeContext.d.ts +8 -1
  86. package/dist/theme/classes.d.ts +49 -0
  87. package/dist/theme/index.d.ts +2 -0
  88. package/dist/theme/types.d.ts +7 -0
  89. package/dist/theme/ui.d.ts +75 -0
  90. package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
  91. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  92. package/package.json +2 -2
  93. package/src/builder-entry.ts +9 -0
  94. package/src/components/AppDialog.tsx +23 -0
  95. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  96. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  97. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  98. package/src/components/Dashboard/DashboardView.tsx +137 -155
  99. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  100. package/src/components/Dashboard/TileCard.tsx +28 -10
  101. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  102. package/src/components/Dashboard/useStuck.ts +28 -17
  103. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  104. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  105. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  106. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  107. package/src/components/Package/Package.create.spec.tsx +7 -6
  108. package/src/components/Package/Package.tsx +10 -7
  109. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  110. package/src/components/Package/PackageProblems.tsx +95 -0
  111. package/src/components/Prose.tsx +12 -7
  112. package/src/components/RemoveBadge.tsx +94 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  114. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  115. package/src/components/Report/Report.spec.tsx +50 -32
  116. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  117. package/src/components/Report/Report.tsx +45 -77
  118. package/src/components/Report/ReportPage.tsx +168 -0
  119. package/src/components/Report/layoutRules.spec.ts +35 -0
  120. package/src/components/Report/layoutRules.ts +55 -0
  121. package/src/components/Report/reportQuery.ts +53 -0
  122. package/src/components/Report/telemetry.ts +0 -2
  123. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  124. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  125. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  126. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  127. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  128. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  129. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  130. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  131. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  132. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  133. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  134. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  135. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  136. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  137. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  138. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  139. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  140. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  141. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  142. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  143. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  144. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  145. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  146. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  147. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  148. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  149. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  150. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  151. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  152. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  153. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  154. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  155. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  156. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  157. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  158. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  159. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  160. package/src/components/ReportBuilder/builderControls.ts +164 -0
  161. package/src/components/ReportBuilder/builderReport.ts +1 -2
  162. package/src/components/ReportBuilder/catalog.ts +10 -26
  163. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  164. package/src/components/ReportBuilder/localGiven.ts +56 -0
  165. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  166. package/src/components/ReportBuilder/preview.ts +60 -44
  167. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  168. package/src/components/ReportBuilder/readDocument.ts +14 -11
  169. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  170. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  171. package/src/components/ReportBuilder/reportTag.ts +28 -7
  172. package/src/components/ReportBuilder/sortable.tsx +15 -7
  173. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  174. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  175. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  176. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  177. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  178. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  179. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  180. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  181. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  182. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  183. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  184. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  185. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  186. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  187. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  188. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  189. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  190. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  191. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  192. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  193. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  194. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  195. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  196. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  197. package/src/components/ServerProvider.tsx +11 -0
  198. package/src/components/controlTokens.ts +47 -0
  199. package/src/components/drill/markDrillableCells.ts +2 -1
  200. package/src/components/given/FilterButton.spec.tsx +143 -0
  201. package/src/components/given/FilterButton.tsx +478 -0
  202. package/src/components/given/GivenInput.spec.tsx +47 -0
  203. package/src/components/given/GivenInput.tsx +20 -2
  204. package/src/components/given/GivensPanel.spec.tsx +11 -3
  205. package/src/components/given/GivensPanel.tsx +45 -44
  206. package/src/components/given/filterEditing.ts +60 -0
  207. package/src/components/given/filterSummary.spec.ts +108 -0
  208. package/src/components/given/filterSummary.ts +109 -0
  209. package/src/components/given/paramCodec.ts +1 -1
  210. package/src/components/given/required.spec.ts +60 -0
  211. package/src/components/given/required.ts +78 -0
  212. package/src/components/index.ts +9 -0
  213. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  214. package/src/components/legacy/index.ts +1 -1
  215. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  216. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  217. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  218. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  219. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  220. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  221. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  222. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  223. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  224. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  225. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  226. package/src/components/styles.ts +0 -18
  227. package/src/hooks/useGivensState.ts +7 -3
  228. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  229. package/src/hooks/useQueryResult.ts +26 -1
  230. package/src/theme/ThemeContext.tsx +21 -1
  231. package/src/theme/classes.ts +52 -0
  232. package/src/theme/index.ts +8 -0
  233. package/src/theme/resolveTheme.ts +3 -0
  234. package/src/theme/types.ts +7 -0
  235. package/src/theme/ui.spec.tsx +91 -0
  236. package/src/theme/ui.ts +115 -0
  237. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  238. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  239. package/dist/components/Notebook/cellKind.d.ts +0 -20
  240. package/dist/components/Report/LinearReport.d.ts +0 -18
  241. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  242. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  243. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  244. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  245. package/src/components/Notebook/cellKind.spec.ts +0 -199
  246. package/src/components/Notebook/cellKind.ts +0 -74
  247. package/src/components/Report/LinearReport.tsx +0 -71
  248. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  249. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  250. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  251. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  252. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  253. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  254. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  255. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  256. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  257. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -1,52 +1,52 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),O=require("../useCompiledDocument-UY28ITET.cjs.js"),$=require("@mui/material"),k=require("react"),Be=require("../ServerProvider-B0dUY8be.cjs.js"),ge=require("../text-entry-BJwltZiy.cjs.js"),nf=require("react-dom"),rf=require("@malloydata/malloy-tag"),ql=require("@tanstack/react-query"),sf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function of(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:sf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ai({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:s,onOpen:i,onChange:o,variant:a="standard"}){const l=of(t,e,n),d=k.useId();return w.jsx($.TextField,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:s!==void 0,onChange:c=>{const u=c.target.value;l.find(f=>f.value===u)?.disabled||o(u)},helperText:s,FormHelperTextProps:{id:d},SelectProps:{...i?{onOpen:i}:{},renderValue:c=>l.find(u=>u.value===c)?.label??String(c),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...s?{"aria-describedby":d}:{}}},sx:{minWidth:140},children:l.map(c=>w.jsx($.MenuItem,{value:c.value,disabled:c.value==="custom"||c.disabled===!0,children:w.jsx($.ListItemText,{primary:c.label,...c.reason?{secondary:c.reason}:{}})},c.value))})}function af({sources:e,source:t,view:n,onSource:r,onView:s}){const{theme:i}=Be.usePublisherTheme(),o=e.find(a=>a.name===t);return w.jsxs(w.Fragment,{children:[w.jsx($.TextField,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>w.jsxs($.MenuItem,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),w.jsxs($.Box,{children:[w.jsx($.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),w.jsxs($.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:i.border,borderRadius:1},children:[(o?.views??[]).map(a=>w.jsxs($.ListItemButton,{selected:n===a.name,onClick:()=>s(a.name),"aria-label":`View ${a.name}`,children:[w.jsx($.ListItemText,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&w.jsx($.Chip,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&w.jsx($.Typography,{variant:"body2",sx:{p:1.5,color:i.tileTitle},children:"This source declares no views."})]})]})]})}function lf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o}){const{theme:a}=Be.usePublisherTheme(),l=k.useMemo(()=>n?.sources??[],[n]),[d,c]=k.useState("query"),[u,f]=k.useState(""),[h,p]=k.useState(""),[m,b]=k.useState(""),[x,v]=k.useState("default"),[g,y]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;c("query");const T=A=>l.some(q=>q.name===A&&q.views.length>0);f(t.sources.map(A=>A.base).find(T)??l.find(A=>A.views.length>0)?.name??""),p(""),b(""),v("default"),y(Math.ceil(r/2))},[e,t,l,r]);const _=u!==""&&h!=="",S=[u,h].filter(T=>T!==""&&!ge.isBareName(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],E=l.find(T=>T.name===u),D=E?.views.find(T=>T.name===h);return w.jsx(O.AppDialog,{open:e,onClose:s,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:s,children:"Cancel"}),w.jsx($.Button,{variant:"contained",disabled:d==="query"&&(!_||S!==void 0),onClick:()=>d==="text"?o():i({base:u,modelPath:E?.modelPath??"",...E?.exporters?{exporters:E.exporters}:{},view:h,...m.trim()?{label:m.trim()}:{},...x!=="default"?{chart:x,...D?{chartCarried:D.chart?[D.chart]:[]}:{}}:{},colspan:g}),children:d==="text"?"Add text":"Add tile"})]}),children:w.jsxs($.Stack,{sx:{gap:2,pt:1},children:[w.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:d,"aria-label":"Tile type",onChange:(T,A)=>{A!==null&&c(A)},children:[w.jsx($.ToggleButton,{value:"query",sx:{px:1.5},children:"Query"}),w.jsx($.ToggleButton,{value:"text",sx:{px:1.5},children:"Text"})]}),d==="text"?w.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):l.length===0?w.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}):w.jsxs(w.Fragment,{children:[w.jsx(af,{sources:l,source:u,view:h,onSource:T=>{f(T),p("")},onView:T=>{p(T),v("default")}}),S&&w.jsx($.Typography,{variant:"body2",color:"error",children:S}),w.jsx(Ai,{state:x,view:D,cellLabel:"new tile",variant:"outlined",...D?{}:{disabledReason:"Pick a view to choose its chart."},onChange:T=>v(T)}),w.jsx($.Stack,{direction:"row",sx:{gap:1.5},children:w.jsx($.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:T=>b(T.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const je=e=>e.kind==="text",xe=e=>e.kind!=="text",Kr=e=>xe(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`,ai="self";function cf({open:e,document:t,source:n,givenNames:r,dashboards:s,onClose:i,onApply:o}){const{theme:a}=Be.usePublisherTheme(),[l,d]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const p=(t.drills??[]).filter(m=>m.source===n.name);d((n.dimensions??[]).map(m=>{const b=p.find(x=>x.name===m.name);return{name:m.name,expression:m.expression,to:b?.to??[],given:b?.given??""}}))},[e,n,t]);const c=(p,m)=>d(b=>b.map((x,v)=>{if(v!==p)return x;const g={...x};return m(g),g})),u=[ai,...s.filter(p=>p!==ai)],f=p=>p===ai?"This report":p,h=()=>{n&&(o(l.filter(p=>p.to.length>0).map(p=>({source:n.name,name:p.name,expression:p.expression,to:p.to,...p.given?{given:p.given}:{}}))),i())};return w.jsx(O.AppDialog,{open:e,onClose:i,title:"Drill",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the report it opens.",actions:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:i,children:"Cancel"}),w.jsx($.Button,{variant:"contained",onClick:h,disabled:l.length===0,children:"Apply"})]}),children:w.jsx($.Stack,{sx:{gap:2,pt:1},children:l.length===0?w.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?w.jsxs(w.Fragment,{children:[w.jsx($.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",w.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((p,m)=>w.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[w.jsxs($.Box,{sx:{minWidth:0,pt:.75},children:[w.jsx($.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:p.name}),w.jsxs($.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:p.expression,children:["is ",p.expression]})]}),w.jsx($.TextField,{select:!0,size:"small",label:"Clicks go to",value:p.to,inputProps:{"aria-label":`Where ${p.name} goes`},SelectProps:{multiple:!0,renderValue:b=>b.length===0?"Not clickable":b.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:b=>c(m,x=>{const v=b.target.value;x.to=Array.isArray(v)?v:String(v).split(",").filter(Boolean)}),children:u.map(b=>w.jsxs($.MenuItem,{value:b,children:[w.jsx($.Checkbox,{size:"small",checked:p.to.includes(b),sx:{p:0,mr:1}}),w.jsx($.ListItemText,{primary:f(b)})]},b))}),w.jsxs($.TextField,{select:!0,size:"small",label:"Sets the filter",value:p.given,disabled:p.to.length===0,inputProps:{"aria-label":`Control ${p.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:p.given===""?`Named ${p.name}, like the dimension`:void 0,onChange:b=>c(m,x=>{x.given=b.target.value}),children:[w.jsx($.MenuItem,{value:"",children:w.jsx("em",{children:"Same name as the dimension"})}),r.map(b=>w.jsx($.MenuItem,{value:b,children:b},b))]})]},p.name))})})}function uf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function _s(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function df(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function as(e,t){const n=df(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Ma(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function ff(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const hf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function pf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=ge.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Pa=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"On or after a date",hint:"A date picker; tiles keep rows on or after it"}];function Vr(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Di=e=>xe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function gf(e,t){return e.tiles.map(n=>{const r=(xe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:_s(t.type)!==void 0?{op:_s(t.type)}:{}}})}function mf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Di(i))return;const o=(i.filters??[]).filter(l=>l.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function vf(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function yf(e,t){for(const r of e.tiles){if(!xe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Kl=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:i}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[d,c]=k.useState({kind:"new"}),[u,f]=k.useState(""),[h,p]=k.useState("select"),[m,b]=k.useState(""),[x,v]=k.useState(""),[g,y]=k.useState([]),[_,S]=k.useState(!1),[E,D]=k.useState(!1),T=R=>t.sources.find(F=>F.name===R.source)?.base??R.source;k.useEffect(()=>{if(e)if(D(n!==void 0),n){c({kind:"existing",name:n.name}),f(n.label??"");const R=gf(t,n);y(R);const F=R.filter(ue=>ue.include),re=new Set(F.map(ue=>ue.field));v(re.size===1?F[0].field:n.field??""),S(re.size>1)}else c({kind:"new"}),f(""),p("select"),v(""),b(new Date().toISOString().slice(0,10)),y(t.tiles.map(R=>({include:Di(R),field:""}))),S(!1)},[e,n,t]);const A=k.useMemo(()=>[...(t.localGivens??[]).map(R=>R.name),...r.map(R=>R.name)],[t,r]),q=k.useMemo(()=>x.trim()?pf(x.trim(),A):"",[x,A]),P=d.kind==="existing"?n??r.find(R=>R.name===d.name):q?{name:q,type:Vr({name:q,label:u,kind:h,field:x}).type}:void 0,z=P?.type!==void 0&&!P.type.startsWith("filter<"),U=g.find(R=>R.include)?.op??_s(P?.type),K=(R,F)=>{D(!0),y(re=>re.map((ue,Re)=>Re===R?{...ue,...F}:ue))},Z=R=>{D(!0),y(F=>F.map(re=>({...re,op:R})))},J=R=>{const F=_s(R);y(re=>re.map(({op:ue,...Re})=>F?{...Re,op:F}:Re))},ie=R=>{D(!0),c({kind:"existing",name:R.name}),v(R.field??""),J(R.type)},de=R=>{D(!0),p(R),J(Vr({name:"X",label:u,kind:R,field:x}).type)},I=t.tiles.map(Di),V=I.filter(Boolean).length,B=g.filter((R,F)=>R.include&&I[F]).length,j=t.tiles.filter((R,F)=>(g[F]?.include??!1)&&I[F]&&xe(R)),G=j.length>0?j:t.tiles.filter((R,F)=>I[F]&&xe(R)),ne=k.useMemo(()=>{const R=new Map;let F=!1;for(const re of G){const ue=s?.(re);if(ue){F=!0;for(const Re of ue)R.has(Re.name)||R.set(Re.name,Re)}}return F?[...R.values()]:void 0},[g,t.tiles,s]),Y=(()=>{const R=x.trim();for(const F of j){const re=s?.(F);if(!re||re.some(ue=>ue.name===R))return T(F)}return j[0]?T(j[0]):t.sources[0]?.base})(),H=R=>{D(!0),y(F=>F.map((re,ue)=>({...re,include:R&&I[ue]})))},L=k.useMemo(()=>_?g:g.map(R=>({...R,field:x})),[_,g,x]),C=R=>{for(const F of G){const re=s?.(F)?.find(ue=>ue.name===R.trim());if(re?.type)return re.type}},W=R=>as(P?.type,R.type),M=(R,F)=>{if(R.trim()==="")return"Pick the field this filter compares.";const re=F?s?.(F):void 0;if(!re)return;const ue=re.find(Re=>Re.name===R.trim());if(!ue)return`Not a field of ${F?T(F):"the tiles' source"}.`;if(ue.type&&!as(P?.type,ue.type))return`${R.trim()} is ${Ma(ue.type)}; this filter compares ${Ma(P?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ee=R=>{if(D(!0),v(R),l||d.kind!=="new")return;const F=C(R),re=Vr({name:"X",label:u,kind:h,field:R}).type;F&&!as(re,F)&&de(ff(F))},X=R=>{const F=t.tiles[R];return F&&xe(F)?F:void 0},le=L.map((R,F)=>R.include&&I[F]?M(R.field,X(F)):void 0),ce=le.every(R=>R===void 0),N=E?le:le.map(()=>{}),Q=E&&!_&&B>0?j.map(R=>M(x,R)).find(Boolean):void 0,me=P!==void 0&&ce&&(d.kind==="existing"||x.trim()!==""&&q!==""),se=()=>{if(!(!P||!me))if(d.kind==="new")i(P.name,L,Vr({name:P.name,label:u.trim()||Kl(P.name),kind:h,field:x.trim(),...Y?{source:Y}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const R=u.trim(),F=R!==(n.local.label??"");i(P.name,L,F?{...n.local,...R?{label:R}:{}}:void 0)}else i(P.name,L)},te=l&&a.origin==="model";return{editing:l,shown:a,fromModel:te,source:d,setSource:c,label:u,setLabel:f,kind:h,dateDefault:m,setDateDefault:b,field:x,rows:g,setRows:y,perTile:_,setPerTile:S,newName:q,target:P,valueTyped:z,commonOp:U,setRow:K,setCommonOp:Z,pickExisting:ie,pickKind:de,bindable:I,bindableCount:V,included:B,commonFields:ne,setAll:H,accepts:W,pickField:ee,rowProblems:N,commonProblem:Q,canApply:me,apply:se}}function ja({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:l,autoFocus:d,placeholder:c,sx:u}){const f=k.useMemo(()=>(n??[]).filter(p=>r?.(p)??!0).map(p=>p.name),[n,r]),h=k.useMemo(()=>new Map((n??[]).map(p=>[p.name,p.type])),[n]);return w.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(p,m)=>t(m),value:e,onChange:(p,m)=>t(typeof m=="string"?m:""),disabled:l,disableClearable:!0,renderOption:(p,m)=>k.createElement("li",{...p,key:m},w.jsx($.Typography,{variant:"body2",sx:{flex:1},children:m}),h.get(m)&&w.jsx($.Typography,{variant:"caption",sx:{opacity:.6},children:h.get(m)?.replace(/_type$/,"")})),renderInput:p=>w.jsx($.TextField,{...p,label:s,placeholder:c,autoFocus:d,error:o,helperText:a,inputProps:{...p.inputProps,"aria-label":i}}),sx:u})}const Ra=e=>e&&xe(e)&&e.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this report does not write."};function xf({open:e,document:t,control:n,available:r,fieldsFor:s,onClose:i,onApply:o,onRemove:a}){const{theme:l}=Be.usePublisherTheme(),{editing:d,shown:c,fromModel:u,source:f,setSource:h,label:p,setLabel:m,kind:b,dateDefault:x,setDateDefault:v,field:g,rows:y,setRows:_,perTile:S,setPerTile:E,newName:D,target:T,valueTyped:A,commonOp:q,setRow:P,setCommonOp:z,pickExisting:U,pickKind:K,bindable:Z,bindableCount:J,included:ie,commonFields:de,setAll:I,accepts:V,pickField:B,rowProblems:j,commonProblem:G,canApply:ne,apply:Y}=bf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:o}),H=(L,C,W)=>w.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:L??">=",onChange:M=>C(M.target.value),inputProps:{"aria-label":W},sx:{width:130},children:hf.filter(M=>M.op!=="~").map(M=>w.jsx($.MenuItem,{value:M.op,children:M.label},M.op))});return w.jsx(O.AppDialog,{open:e,onClose:i,title:d?c.label??c.name:"Add a filter",description:d?w.jsxs(w.Fragment,{children:[w.jsxs($.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",c.name]}),u?" · declared in the model, so its label and options are set there":" · declared in this report"]}):"A filter on the page, and the tiles it filters.",actions:w.jsxs(w.Fragment,{children:[d&&w.jsx($.Button,{color:"error",startIcon:w.jsx(O.DeleteOutlineIcon,{}),onClick:()=>a(c.name),sx:L=>({mr:"auto",color:O.dangerTextColor(L)}),children:"Remove filter"}),w.jsx($.Button,{onClick:i,children:"Cancel"}),w.jsx($.Tooltip,{title:ne||T===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:w.jsx("span",{children:w.jsx($.Button,{variant:"contained",onClick:Y,disabled:!ne,children:d?"Apply":"Add filter"})})})]}),children:w.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&w.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:f.kind,onChange:(L,C)=>{C==="new"?h({kind:"new"}):C==="existing"&&r[0]&&U(r[0])},"aria-label":"Where the filter comes from",children:[w.jsx($.ToggleButton,{value:"new",children:"New in this report"}),w.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&f.kind==="existing"?w.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:f.name,onChange:L=>{const C=r.find(W=>W.name===L.target.value);C&&U(C)},children:r.map(L=>w.jsxs($.MenuItem,{value:L.name,children:[L.label??L.name,w.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",L.name]})]},L.name))}):null,w.jsxs($.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!S&&w.jsx(ja,{value:g,onChange:B,fields:de,accepts:V,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!d,error:G!==void 0,helperText:G??(!d&&D?`Declared as $${D}`:void 0),sx:{flex:1,minWidth:200}}),!u&&w.jsx($.TextField,{size:"small",label:"Label",placeholder:D?Kl(D):"",value:p,onChange:L=>m(L.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),A&&!S&&H(q,z,"Comparison")]}),!d&&f.kind==="new"&&w.jsxs($.Stack,{direction:"row",sx:{gap:1.5},children:[w.jsx($.TextField,{select:!0,size:"small",label:"Filter kind",value:b,onChange:L=>K(L.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:L=>Pa.find(C=>C.kind===L)?.label??String(L)}},sx:{flex:1},children:Pa.map(L=>w.jsxs($.MenuItem,{value:L.kind,children:[L.label,w.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:L.hint})]},L.kind))}),b==="date"&&w.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:x,onChange:L=>v(L.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),w.jsxs($.Box,{children:[w.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[w.jsx($.Checkbox,{size:"small",checked:J>0&&ie===J,indeterminate:ie>0&&ie<J,disabled:J===0,onChange:L=>I(L.target.checked),inputProps:{"aria-label":"All tiles"}}),w.jsxs($.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ie," of ",t.tiles.length," tiles"]}),w.jsx($.Button,{size:"small",onClick:()=>{S||_(L=>L.map(C=>({...C,field:g}))),E(L=>!L)},children:S?"Same field for all":"Adjust per tile"})]}),w.jsx($.Stack,{sx:{gap:S?1:0},children:t.tiles.map((L,C)=>{if(!xe(L))return null;const W=y[C],M=L.label??L.name,ee=S?j[C]:void 0;return w.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:S?"flex-start":"center",opacity:Z[C]?1:.6},children:[w.jsx($.Checkbox,{size:"small",disabled:!Z[C],checked:(W?.include??!1)&&Z[C],inputProps:{"aria-label":`Filter ${M}`},onChange:X=>P(C,{include:X.target.checked})}),w.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:S?1:0},noWrap:!0,children:M}),Z[C]?S&&w.jsxs(w.Fragment,{children:[A&&H(W?.op,X=>P(C,{op:X}),`Comparison for ${M}`),w.jsx(ja,{value:W?.field??"",onChange:X=>P(C,{field:X}),fields:s?.(L),accepts:V,label:"Field",ariaLabel:`Field for ${M}`,disabled:!W?.include,error:ee!==void 0,helperText:ee,sx:{width:220}})]}):w.jsx($.Tooltip,{title:Ra(t.tiles[C]).reason,children:w.jsx($.Typography,{variant:"caption",sx:{color:l.tileTitle},children:Ra(t.tiles[C]).label})})]},`${L.source}.${L.name}`)})}),ie===0&&w.jsx($.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}const wf=O.createSvgIcon(w.jsx("path",{d:"M11.71 17.99C8.53 17.84 6 15.22 6 12c0-3.31 2.69-6 6-6 3.22 0 5.84 2.53 5.99 5.71l-2.1-.63C15.48 9.31 13.89 8 12 8c-2.21 0-4 1.79-4 4 0 1.89 1.31 3.48 3.08 3.89zM22 12c0 .3-.01.6-.04.9l-1.97-.59c.01-.1.01-.21.01-.31 0-4.42-3.58-8-8-8s-8 3.58-8 8 3.58 8 8 8c.1 0 .21 0 .31-.01l.59 1.97c-.3.03-.6.04-.9.04-5.52 0-10-4.48-10-10S6.48 2 12 2s10 4.48 10 10m-3.77 4.26L22 15l-10-3 3 10 1.26-3.77 4.27 4.27 1.98-1.98z"}));function Vl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:c=>i(u=>{if(u===void 0)return u;const f=structuredClone(u);return c(f),f}),apply:c=>{if(s===void 0)return;const u=structuredClone(s);c(u),i(u),JSON.stringify(u)!==JSON.stringify(e)&&n(u)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const _f=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,kf="This tile's view is declared on its source, so its chart is set in the model.";function Sf({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:s,removeBlocked:i,onDrills:o,view:a}){const l=k.useId(),{theme:d}=Be.usePublisherTheme(),{draft:c,apply:u,close:f,discard:h}=Vl(t,e!==null,r,n),p=c!==void 0&&xe(c)?c:void 0,m=p!==void 0&&p.declaration.kind!=="inherited",b=g=>u(y=>{xe(y)&&g(y)}),x=k.useRef(void 0),v=e!==null;return k.useEffect(()=>{v&&(x.current=t&&xe(t)?t.chart:void 0)},[v]),w.jsx($.Popover,{open:e!==null&&c!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:c&&w.jsxs($.Stack,{sx:{gap:1.5},children:[w.jsx($.Typography,{variant:"overline",sx:{color:d.tileTitle,lineHeight:1.5},children:p?`${p.source} → ${p.name}`:`Text · ${c.name}`}),p&&m&&w.jsx(w.Fragment,{children:w.jsx(Ai,{state:p.chart??"default",view:a,cellLabel:`${p.source} ${p.name}`,...p.chart==="custom"?{disabledReason:_f(p.chartLines)}:{},onChange:g=>b(y=>{const _=x.current;g===(_??"default")?(_===void 0?delete y.chart:y.chart=_,delete y.chartCarried):(y.chart=g,a?y.chartCarried=a.chart?[a.chart]:[]:delete y.chartCarried)})})}),p&&!m&&w.jsxs(w.Fragment,{children:[w.jsx($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),w.jsx(Ai,{state:"default",view:a,cellLabel:`${p.source} ${p.name}`,disabledReason:kf,onChange:()=>{}})]}),p?.declaration.kind==="opaque"&&w.jsxs($.Typography,{variant:"body2",sx:{color:d.tileTitle},children:["Its body is ",p.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),w.jsxs($.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[m&&o?w.jsx($.Button,{size:"small",startIcon:w.jsx(wf,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):w.jsx("span",{}),w.jsx($.Button,{color:"error",size:"small",startIcon:w.jsx(O.DeleteOutlineIcon,{}),"aria-disabled":i!==void 0||void 0,"aria-describedby":i!==void 0?l:void 0,disableRipple:i!==void 0,sx:g=>({color:O.dangerTextColor(g),...i!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{i===void 0&&(h(),s())},children:"Delete"})]}),i!==void 0&&w.jsx($.Typography,{id:l,variant:"caption",sx:{color:d.tileTitle},children:i})]})})}function $f({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,confirmConversion:l,exitDialog:d}){const{filterDialog:c,setFilterDialog:u}=s,{menu:f,setMenu:h}=i,p=f===void 0?void 0:e.document.tiles[f.index],m=p&&xe(p)?p:void 0,b=(()=>{if(!m||!t)return;const x=e.document.sources.find(g=>g.name===m.source)?.base??m.source,v=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(g=>g.name===x)?.views.find(g=>g.name===v)})();return w.jsxs(w.Fragment,{children:[w.jsx(xf,{open:c!==void 0,document:e.document,...c?.control?{control:c.control}:{},available:s.available,...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>u(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),w.jsx(Sf,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>h(void 0),onCommit:x=>{const v=f?.index;v!==void 0&&e.update(g=>{g.tiles[v]=x})},onRemove:()=>{f!==void 0&&i.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},view:b,...(e.document.sources.find(x=>x.name===m?.source)?.dimensions?.length??0)>0?{onDrills:()=>a(m?.source)}:{}}),w.jsx(cf,{open:o!==void 0,document:e.document,source:e.document.sources.find(x=>x.name===o),givenNames:s.controlList.map(x=>x.name),dashboards:r??[],onClose:()=>a(void 0),onApply:x=>e.update(v=>{const y=[...(v.drills??[]).filter(_=>_.source!==o),...x];y.length===0?delete v.drills:v.drills=y})}),w.jsx(O.AppDialog,{open:l!==void 0,onClose:()=>l?.stop(),title:"Convert this report?",description:"Saving rewrites this report in the tile layout. The builder cannot take that back; the file's history in your repository can.",actions:w.jsxs(w.Fragment,{children:[w.jsx($.Button,{onClick:()=>l?.stop(),children:"Cancel"}),w.jsx($.Button,{variant:"contained",onClick:()=>l?.go(),children:"Convert and save"})]}),children:null}),w.jsx(O.UnsavedChangesDialog,{...d}),w.jsx(lf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText})]})}var Tf=Symbol.for("preact-signals");function qs(){if(vt>1)vt--;else{var e,t=!1;for((function(){var s=Ss;for(Ss=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();dr!==void 0;){var n=dr;for(dr=void 0,ks++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Hl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ks=0,vt--,t)throw e}}function Te(e){if(vt>0)return e();Mi=++Of,vt++;try{return e()}finally{qs()}}var ur,we=void 0;function fe(e){var t=we,n=ur;we=void 0,ur=void 0;try{return e()}finally{we=t,ur=n}}var dr=void 0,vt=0,ks=0,Of=0,Mi=0,Ss=void 0,$s=0;function Ul(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function Ve(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Ve.prototype.brand=Tf;Ve.prototype.h=function(){return!0};Ve.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:fe(function(){var r;(r=t.W)==null||r.call(t)}))};Ve.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&fe(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ve.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;fe(function(){return e(n)})},{name:"sub"})};Ve.prototype.valueOf=function(){return this.value};Ve.prototype.toString=function(){return this.value+""};Ve.prototype.toJSON=function(){return this.value};Ve.prototype.peek=function(){var e=this;return fe(function(){return e.value})};Object.defineProperty(Ve.prototype,"value",{get:function(){var e=Ul(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ks>100)throw new Error("Cycle detected");(function(n){vt!==0&&ks===0&&n.l!==Mi&&(n.l=Mi,Ss={S:n,v:n.v,i:n.i,o:Ss})})(this),this.v=e,this.i++,$s++,vt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{qs()}}}});function En(e,t){return new Ve(e,t)}function Hl(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Xl(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Yl(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function Yt(e,t){Ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=$s-1,this.f=4}Yt.prototype=new Ve;Yt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===$s))return!0;if(this.g=$s,this.f|=1,this.i>0&&!Hl(this))return this.f&=-2,!0;var e=we;try{Xl(this),we=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return we=e,Yl(this),this.f&=-2,!0};Yt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Ve.prototype.S.call(this,e)};Yt.prototype.U=function(e){if(this.t!==void 0&&(Ve.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Yt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Yt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Ul(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function La(e,t){return new Yt(e,t)}function Zl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){vt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,_o(e),r}finally{we=n,qs()}}}function _o(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Zl(e)}function Ef(e){if(we!==this)throw new Error("Out-of-order effect");Yl(this),we=e,this.f&=-2,8&this.f&&_o(this),qs()}function Cn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,ur&&ur.push(this)}Cn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Cn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zl(this),Xl(this),vt++;var e=we;return we=this,Ef.bind(this,e)};Cn.prototype.N=function(){2&this.f||(this.f|=2,this.u=dr,dr=this)};Cn.prototype.d=function(){this.f|=8,1&this.f||_o(this)};Cn.prototype.dispose=function(){this.d()};function rt(e,t){var n=new Cn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Cf=Object.create,ko=Object.defineProperty,If=Object.defineProperties,Af=Object.getOwnPropertyDescriptor,Df=Object.getOwnPropertyDescriptors,Na=Object.getOwnPropertySymbols,Mf=Object.prototype.hasOwnProperty,Pf=Object.prototype.propertyIsEnumerable,jf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),In=e=>{throw TypeError(e)},Pi=(e,t,n)=>t in e?ko(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rf=(e,t)=>{for(var n in t||(t={}))Mf.call(t,n)&&Pi(e,n,t[n]);if(Na)for(var n of Na(t))Pf.call(t,n)&&Pi(e,n,t[n]);return e},Lf=(e,t)=>If(e,Df(t)),Fa=(e,t)=>ko(e,"name",{value:t,configurable:!0}),Nf=e=>{var t;return[,,,Cf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],Hn=e=>e!==void 0&&typeof e!="function"?In("Function expected"):e,Ff=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:i=>n._?In("Already initialized"):s.push(Hn(i||null))}),Jl=(e,t)=>Pi(t,jf("metadata"),e[3]),Lt=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},An=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=Ql[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&Af(u<4?s:{get[n](){return Qe(this,i)},set[n](y){return Tt(this,i,y)}},n));u?h&&u<4&&Fa(i,(u>2?"set ":u>1?"get ":"")+n):Fa(s,n);for(var g=r.length-1;g>=0;g--)d=Ff(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>zf(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?Qe:Wf)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Tt(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?Hn(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?In("Object expected"):(Hn(o=a.get)&&(v.get=o),Hn(o=a.set)&&(v.set=o),Hn(o=a.init)&&b.unshift(o));return u||Jl(e,s),v&&ko(s,n,v),h?u^4?i:v:s},So=(e,t,n)=>t.has(e)||In("Cannot "+n),zf=(e,t)=>Object(t)!==t?In('Cannot use the "in" operator on this value'):e.has(t),Qe=(e,t,n)=>(So(e,t,"read from private field"),n?n.call(e):t.get(e)),Xn=(e,t,n)=>t.has(e)?In("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Tt=(e,t,n,r)=>(So(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Wf=(e,t,n)=>(So(e,t,"access private method"),n);function ji(e,t){if(t){let n;return La(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return La(e)}function it(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!it(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!it(e[i],t[i]))}return!1}function he({get:e},t){return{init(n){return En(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ee(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ji(e.bind(this)),n.set(this,r)),r.value}}function li(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Lf(Rf({},s),{enumerable:e}))})}}function Ar(...e){const t=e.map(n=>rt(n));return()=>t.forEach(n=>n())}var ec,tc,nc,rc,sc,ic,Ge,$o,ci,Ri,Li,ze,To,ui,oc,Ni,Oo,di,Fi,zi;ic=[he],sc=[he],rc=[he],nc=[li()],tc=[li()],ec=[li()];var Zt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Lt(Ge,5,this),Xn(this,ze),Xn(this,$o,Lt(Ge,8,this)),Lt(Ge,11,this),Xn(this,To,Lt(Ge,12,this)),Lt(Ge,15,this),Xn(this,Oo,Lt(Ge,16,this)),Lt(Ge,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Qe(this,ze,Fi)}get initial(){return Qe(this,ze,Ri)}get previous(){return Qe(this,ze,oc)}set current(e){const t=fe(()=>Qe(this,ze,Fi));e&&t&&this.equals(t,e)||Te(()=>{Qe(this,ze,Ri)||Tt(this,ze,e,Li),Tt(this,ze,t,Ni),Tt(this,ze,e,zi)})}reset(e=this.defaultValue){Te(()=>{Tt(this,ze,void 0,Ni),Tt(this,ze,e,Li),Tt(this,ze,e,zi)})}};Ge=Nf();$o=new WeakMap;ze=new WeakSet;To=new WeakMap;Oo=new WeakMap;ci=An(Ge,20,"#initial",ic,ze,$o),Ri=ci.get,Li=ci.set;ui=An(Ge,20,"#previous",sc,ze,To),oc=ui.get,Ni=ui.set;di=An(Ge,20,"#current",rc,ze,Oo),Fi=di.get,zi=di.set;An(Ge,2,"current",nc,Zt);An(Ge,2,"initial",tc,Zt);An(Ge,2,"previous",ec,Zt);Jl(Ge,Zt);function fi(e){return fe(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Nt,Bf=class{constructor(){Xn(this,Nt,new WeakMap)}get(e,t){var n;return e?(n=Qe(this,Nt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Qe(this,Nt).has(e)||Qe(this,Nt).set(e,new Map),(r=Qe(this,Nt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Qe(this,Nt).get(e))==null?void 0:t.clear():void 0}};Nt=new WeakMap;var Gf=Object.create,ac=Object.defineProperty,qf=Object.getOwnPropertyDescriptor,za=Object.getOwnPropertySymbols,Kf=Object.prototype.hasOwnProperty,Vf=Object.prototype.propertyIsEnumerable,lc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ks=e=>{throw TypeError(e)},Wa=Math.pow,Wi=(e,t,n)=>t in e?ac(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Uf=(e,t)=>{for(var n in t||(t={}))Kf.call(t,n)&&Wi(e,n,t[n]);if(za)for(var n of za(t))Vf.call(t,n)&&Wi(e,n,t[n]);return e},Hf=e=>{var t;return[,,,Gf((t=e?.[lc("metadata")])!=null?t:null)]},cc=["class","method","getter","setter","accessor","field","value","get","set"],uc=e=>e!==void 0&&typeof e!="function"?Ks("Function expected"):e,Xf=(e,t,n,r,s)=>({kind:cc[e],name:t,metadata:r,addInitializer:i=>n._?Ks("Already initialized"):s.push(uc(i||null))}),Yf=(e,t)=>Wi(t,lc("metadata"),e[3]),Zf=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,l,d,c=t&7,u=!1,f=!1,h=2,p=cc[c+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,qf(s,n)),x=r.length-1;x>=0;x--)l=Xf(c,n,a={},e[3],m),l.static=u,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[x])(b[p],l),a._=1,uc(o)&&(b[p]=o);return b&&ac(s,n,b),s},fc=(e,t,n)=>t.has(e)||Ks("Cannot "+n),Qf=(e,t,n)=>(fc(e,t,"read from private field"),t.get(e)),Jf=(e,t,n)=>t.has(e)?Ks("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),eh=(e,t,n,r)=>(fc(e,t,"write to private field"),t.set(e,n),n),Je=class Bi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Bi(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Bi(t,n)}},ht=class Ft{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:i,height:o,scale:a}=this,l=new Ft(s+t,r+n,i,o);return l.scale=Uf({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Je((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Ft))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Ft?th(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new Ft(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],l=o==="x"?i.left:i.top,d=o==="x"?i.width:i.height;return a=="start"?l:a=="end"?l+d:l+d/2};return Je.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Ft.from(t).intersectionRatio(Ft.from(n))}};function th(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var hc,pc,Gi,ls,Dr,Vs=class extends(Gi=Zt,pc=[Ee],hc=[Ee],Gi){constructor(t){const n=Je.from(t);super(n,(r,s)=>Je.equals(r,s)),Zf(Dr,5,this),Jf(this,ls,0),this.velocity={x:0,y:0}}get delta(){return Je.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Je.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-Qf(this,ls),a=l=>Math.round(l/o*100);Te(()=>{eh(this,ls,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Je.from(t)),this.velocity={x:0,y:0}}};Dr=Hf(Gi);ls=new WeakMap;dc(Dr,2,"delta",pc,Vs);dc(Dr,2,"direction",hc,Vs);Yf(Dr,Vs);function qi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Wa(r,2)+Wa(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var gc=(e=>(e.Horizontal="x",e.Vertical="y",e))(gc||{}),mc=Object.values(gc),nh=Object.create,Eo=Object.defineProperty,rh=Object.defineProperties,sh=Object.getOwnPropertyDescriptor,ih=Object.getOwnPropertyDescriptors,Ts=Object.getOwnPropertySymbols,vc=Object.prototype.hasOwnProperty,yc=Object.prototype.propertyIsEnumerable,bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Dn=e=>{throw TypeError(e)},Ki=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Co=(e,t)=>{for(var n in t||(t={}))vc.call(t,n)&&Ki(e,n,t[n]);if(Ts)for(var n of Ts(t))yc.call(t,n)&&Ki(e,n,t[n]);return e},Io=(e,t)=>rh(e,ih(t)),Ba=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),xc=(e,t)=>{var n={};for(var r in e)vc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ts)for(var r of Ts(e))t.indexOf(r)<0&&yc.call(e,r)&&(n[r]=e[r]);return n},Mn=e=>{var t;return[,,,nh((t=e?.[bc("metadata")])!=null?t:null)]},wc=["class","method","getter","setter","accessor","field","value","get","set"],Yn=e=>e!==void 0&&typeof e!="function"?Dn("Function expected"):e,oh=(e,t,n,r,s)=>({kind:wc[e],name:t,metadata:r,addInitializer:i=>n._?Dn("Already initialized"):s.push(Yn(i||null))}),Qt=(e,t)=>Ki(t,bc("metadata"),e[3]),ae=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},pe=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=wc[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&sh(u<4?s:{get[n](){return Oe(this,i)},set[n](y){return Ye(this,i,y)}},n));u?h&&u<4&&Ba(i,(u>2?"set ":u>1?"get ":"")+n):Ba(s,n);for(var g=r.length-1;g>=0;g--)d=oh(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>ah(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?Oe:_c)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Ye(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?Yn(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?Dn("Object expected"):(Yn(o=a.get)&&(v.get=o),Yn(o=a.set)&&(v.set=o),Yn(o=a.init)&&b.unshift(o));return u||Qt(e,s),v&&Eo(s,n,v),h?u^4?i:v:s},Ao=(e,t,n)=>t.has(e)||Dn("Cannot "+n),ah=(e,t)=>Object(t)!==t?Dn('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Ao(e,t,"read from private field"),n?n.call(e):t.get(e)),ve=(e,t,n)=>t.has(e)?Dn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Ao(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_c=(e,t,n)=>(Ao(e,t,"access private method"),n);function kc(e,t){return{plugin:e,options:t}}function Mr(e){return t=>kc(e,t)}function vr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Sc,yr,Do,cs;Sc=[he];var We=class{constructor(e,t){this.manager=e,this.options=t,ve(this,Do,ae(yr,8,this,!1)),ae(yr,11,this),ve(this,cs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return fe(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=rt(e.bind(this));return Oe(this,cs).add(t),t}destroy(){Oe(this,cs).forEach(e=>e())}static configure(e){return kc(this,e)}};yr=Mn(null);Do=new WeakMap;cs=new WeakMap;pe(yr,4,"disabled",Sc,We,Do);Qt(yr,We);var Pr=class extends We{},us,hi=class{constructor(e){this.manager=e,this.instances=new Map,ve(this,us,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(vr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,us))if(!n.includes(r)){if(r.prototype instanceof Pr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);Ye(this,us,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};us=new WeakMap;function lh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Ur=[],cn,un,ch=class extends We{constructor(e){super(e),ve(this,cn),ve(this,un),this.computeCollisions=this.computeCollisions.bind(this),Ye(this,un,En(Ur)),this.destroy=Ar(()=>{const t=this.computeCollisions(),n=fe(()=>this.manager.dragOperation.position.current);if(t!==Ur){const r=Oe(this,cn);if(Ye(this,cn,n),r&&n.x==r.x&&n.y==r.y)return}else Ye(this,cn,void 0);Oe(this,un).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){fe(()=>{e?Oe(this,un).value=this.computeCollisions():Ye(this,cn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Ur;const a=[],l=[];for(const d of e??n.droppables){if(d.disabled||s&&!d.accepts(s))continue;const c=t??d.collisionDetector;if(!c)continue;l.push(d),d.shape;const u=fe(()=>c({droppable:d,dragOperation:r}));u&&(d.collisionPriority!=null&&(u.priority=d.collisionPriority),a.push(u))}return l.length===0?Ur:(a.sort(lh),a)}get collisions(){return Oe(this,un).value}};cn=new WeakMap;un=new WeakMap;var $c,Tc,Oc,Mo,Ec,ot,Po,mn,jo,Ro;Oc=[he],Tc=[he],$c=[he];var bt=class zt{constructor(t,n){ve(this,Po,ae(ot,8,this)),ae(ot,11,this),ve(this,mn),ve(this,jo,ae(ot,12,this)),ae(ot,15,this),ve(this,Ro,ae(ot,16,this)),ae(ot,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let l=s;Ye(this,mn,En(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var d;return[()=>{const{id:c,manager:u}=this;if(c!==l)return l=c,u?.registry.register(this),()=>u?.registry.unregister(this)},...(d=r?.())!=null?d:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=Oe(this,mn).value;return(n=(t=zt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=zt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,mn).peek();t!==s&&(zt.pendingIdChanges||(zt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return _c(i=zt,Mo,Ec).call(i)})),zt.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};ot=Mn(null);Mo=new WeakSet;Ec=function(){const e=bt.pendingIdChanges;bt.pendingIdChanges=null,e&&Te(()=>{for(const[t,n]of e)Oe(t,mn).value=n})};Po=new WeakMap;mn=new WeakMap;jo=new WeakMap;Ro=new WeakMap;pe(ot,4,"manager",Oc,bt,Po);pe(ot,4,"data",Tc,bt,jo);pe(ot,4,"disabled",$c,bt,Ro);ve(bt,Mo);Qt(ot,bt);bt.pendingIdChanges=null;var Us=bt,Ga=class{constructor(){this.map=En(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Ar(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Cc,Ic,Ac,Dc,Mc,Pc,Vi,qe,Lo,No,Fo,pt=class extends(Vi=Us,Pc=[he],Mc=[he],Dc=[he],Ac=[Ee],Ic=[Ee],Cc=[Ee],Vi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:l}=r,d=xc(r,["modifiers","type","sensors","plugins","effects"]);super(Io(Co({},d),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:u,plugins:f}=this;if(!(!u||!f))for(const h of f){const{plugin:p}=vr(h);u.registry.plugins.register(p)}}]}}),n),ae(qe,5,this),ve(this,Lo,ae(qe,8,this)),ae(qe,11,this),ve(this,No,ae(qe,12,this)),ae(qe,15,this),ve(this,Fo,ae(qe,16,this,this.isDragSource?"dragging":"idle")),ae(qe,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=d.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=vr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};qe=Mn(Vi);Lo=new WeakMap;No=new WeakMap;Fo=new WeakMap;pe(qe,4,"type",Pc,pt,Lo);pe(qe,4,"modifiers",Mc,pt,No);pe(qe,4,"status",Dc,pt,Fo);pe(qe,2,"isDropping",Ac,pt);pe(qe,2,"isDragging",Ic,pt);pe(qe,2,"isDragSource",Cc,pt);Qt(qe,pt);var jc,Rc,Lc,Nc,Fc,zc,Ui,Me,zo,Wo,Bo,Go,qo,gt=class extends(Ui=Us,zc=[he],Fc=[he],Nc=[he],Lc=[he],Rc=[he],jc=[Ee],Ui){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,l=xc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ae(Me,5,this),ve(this,zo,ae(Me,8,this)),ae(Me,11,this),ve(this,Wo,ae(Me,12,this)),ae(Me,15,this),ve(this,Bo,ae(Me,16,this)),ae(Me,19,this),ve(this,Go,ae(Me,20,this)),ae(Me,23,this),ve(this,qo,ae(Me,24,this)),ae(Me,27,this),this.accept=s,this.collisionDetector=i,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Me=Mn(Ui);zo=new WeakMap;Wo=new WeakMap;Bo=new WeakMap;Go=new WeakMap;qo=new WeakMap;pe(Me,4,"accept",zc,gt,zo);pe(Me,4,"type",Fc,gt,Wo);pe(Me,4,"collisionDetector",Nc,gt,Bo);pe(Me,4,"collisionPriority",Lc,gt,Go);pe(Me,4,"shape",Rc,gt,qo);pe(Me,2,"isDropTarget",jc,gt);Qt(Me,gt);var uh=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},dh=class extends uh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function ds(e,t=!0){let n=!1;return Io(Co({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var fh=class extends Pr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Ar(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Us.pendingIdChanges)return;const o=ds({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;fe(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Pn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Pn||{}),jn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(jn||{}),Wc,Bc,Gc,qc,Kc,Vc,Uc,nt,Ko;Uc=[he],Vc=[Ee],Kc=[Ee],qc=[Ee],Gc=[Ee],Bc=[Ee],Wc=[Ee];var wt=class{constructor(){ae(nt,5,this),ve(this,Ko,ae(nt,8,this,"idle")),ae(nt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};nt=Mn(null);Ko=new WeakMap;pe(nt,4,"value",Uc,wt,Ko);pe(nt,2,"current",Vc,wt);pe(nt,2,"idle",Kc,wt);pe(nt,2,"initializing",qc,wt);pe(nt,2,"initialized",Gc,wt);pe(nt,2,"dragging",Bc,wt);pe(nt,2,"dropped",Wc,wt);Qt(nt,wt);var hh=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return fe(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=ds({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return fe(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:i}=e;Te(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=ds({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&Te(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=ds({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,l,d,c,u;if(o.defaultPrevented)return;const f=(u=e.to)!=null?u:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(d=e.by)==null?void 0:d.y)!=null?c:0)};r.position.current=f})})}stop(e={}){return fe(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const l={resume:()=>{},abort:()=>{}};return i=new Promise((d,c)=>{l.resume=d,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=fe(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),d=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,u=rt(()=>{c?.status==="idle"&&(u(),d())})}else this.manager.renderer.rendering.then(d)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),i?i.then(a).catch(()=>r.reset()):a()})}},_n=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}},ph=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},fs,Hc=class{constructor(e){this.options=e,ve(this,fs)}set controller(e){Ye(this,fs,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,fs))==null||t.activate(e)}};fs=new WeakMap;var qa=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},gh=class{constructor(e){this.draggables=new Ga,this.droppables=new Ga,this.plugins=new hi(e),this.sensors=new hi(e),this.modifiers=new hi(e)}register(e,t){if(e instanceof pt)return this.draggables.register(e.id,e);if(e instanceof gt)return this.droppables.register(e.id,e);if(e.prototype instanceof qa)return this.modifiers.register(e,t);if(e.prototype instanceof _n)return this.sensors.register(e,t);if(e.prototype instanceof We)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Us)return e instanceof pt?this.draggables.unregister(e.id,e):e instanceof gt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof qa)return this.modifiers.unregister(e);if(e.prototype instanceof _n)return this.sensors.unregister(e);if(e.prototype instanceof We)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},Xc,Yc,Zc,Qc,Jc,eu,tu,nu,ru,Zn,hs,dn,$e,Vo,Uo,Ho,Xo,Yo,Qn;ru=[Ee],nu=[he],tu=[he],eu=[he],Jc=[he],Qc=[he],Zc=[Ee],Yc=[Ee],Xc=[Ee];var ct=class{constructor(e){ae($e,5,this),ve(this,Zn),ve(this,hs),ve(this,dn,new Zt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new wt,ve(this,Vo,ae($e,8,this,!1)),ae($e,11,this),ve(this,Uo,ae($e,12,this,null)),ae($e,15,this),ve(this,Ho,ae($e,16,this,null)),ae($e,19,this),ve(this,Xo,ae($e,20,this,null)),ae($e,23,this),ve(this,Yo,ae($e,24,this,[])),ae($e,27,this),this.position=new Vs({x:0,y:0}),ve(this,Qn,{x:0,y:0}),Ye(this,Zn,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,dn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,dn).current=e:Oe(this,dn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,Zn).registry.draggables.get(t);return n&&Ye(this,hs,n),(e=n??Oe(this,hs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,Zn).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Io(Co({},this.snapshot()),{transform:n}));return Ye(this,Qn,n),n}snapshot(){return fe(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,Qn),shape:this.shape?fi(this.shape):null,position:fi(this.position),status:fi(this.status),canceled:this.canceled}))}reset(){Te(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,dn).reset(),this.position.reset({x:0,y:0}),Ye(this,Qn,{x:0,y:0}),this.modifiers=[]})}};$e=Mn(null);Zn=new WeakMap;hs=new WeakMap;dn=new WeakMap;Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;Xo=new WeakMap;Yo=new WeakMap;Qn=new WeakMap;pe($e,2,"shape",ru,ct);pe($e,4,"canceled",nu,ct,Vo);pe($e,4,"activatorEvent",tu,ct,Uo);pe($e,4,"sourceIdentifier",eu,ct,Ho);pe($e,4,"targetIdentifier",Jc,ct,Xo);pe($e,4,"modifiers",Qc,ct,Yo);pe($e,2,"source",Zc,ct);pe($e,2,"target",Yc,ct);pe($e,2,"transform",Xc,ct);Qt($e,ct);var mh={get rendering(){return Promise.resolve()}};function lt(e,t){return typeof e=="function"?e(t):e??t}var vh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=lt(r.plugins,[]),i=lt(r.sensors,[]),o=lt(r.modifiers,[]),a=(n=r.renderer)!=null?n:mh,l=new dh(this),d=new gh(this);this.registry=d,this.monitor=l,this.renderer=a,this.actions=new hh(this),this.dragOperation=new ct(this),this.collisionObserver=new ch(this),this.plugins=[fh,...s],this.modifiers=o,this.sensors=i;const{destroy:c}=this,u=Ar(()=>{var f,h,p;const m=fe(()=>this.dragOperation.modifiers),b=this.modifiers;for(const x of m)b.includes(x)||x.destroy();this.dragOperation.modifiers=(p=(h=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:h.map(x=>{const{plugin:v,options:g}=vr(x);return new v(this,g)}))!=null?p:b});this.destroy=()=>{u(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},su=e=>{throw TypeError(e)},Zo=(e,t,n)=>t.has(e)||su("Cannot "+n),oe=(e,t,n)=>(Zo(e,t,"read from private field"),t.get(e)),Ue=(e,t,n)=>t.has(e)?su("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Xe=(e,t,n,r)=>(Zo(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Zo(e,t,"access private method"),n);function Hs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function ou(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(Hs(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function Xs(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function Qo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function jr(e){return"nodeType"in e}function Ze(e){var t,n,r;return e?Qo(e)?e:jr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function Jo(e){const{Document:t}=Ze(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Dt(e){return!e||Qo(e)?!1:e instanceof Ze(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function au(e){return e instanceof Ze(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Rn(e){return e?Qo(e)?e.document:jr(e)?Jo(e)?e:Dt(e)||au(e)?e.ownerDocument:document:document:document}function yh(e){var t,n,r,s;const{documentElement:i}=Rn(e),o=Ze(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,l=(n=o?.height)!=null?n:i.clientHeight,d=(r=o?.offsetTop)!=null?r:0,c=(s=o?.offsetLeft)!=null?s:0;return{top:d,left:c,right:c+a,bottom:d+l,width:a,height:l}}function bh(e,t){if(xh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function xh(e){return e.tagName==="DETAILS"}function br(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let l=t;const{ownerDocument:d}=e,c=(r=d.defaultView)!=null?r:window;let u=e.parentElement;for(;u&&u!==d.documentElement;){if(!bh(u)){const g=u.getBoundingClientRect(),y=n*(g.bottom-g.top),_=n*(g.right-g.left),S=n*(g.bottom-g.top),E=n*(g.right-g.left);l={top:Math.max(l.top,g.top-y),right:Math.min(l.right,g.right+_),bottom:Math.min(l.bottom,g.bottom+S),left:Math.max(l.left,g.left-E),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}u=u.parentElement}const f=c.visualViewport,h=(s=f?.offsetTop)!=null?s:0,p=(i=f?.offsetLeft)!=null?i:0,m=(o=f?.width)!=null?o:c.innerWidth,b=(a=f?.height)!=null?a:c.innerHeight,x=n*b,v=n*m;return l={top:Math.max(l.top,h-x),right:Math.min(l.right,p+m+v),bottom:Math.min(l.bottom,h+b+x),left:Math.max(l.left,p-v),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function kn(e){return{x:e.clientX,y:e.clientY}}var lu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Hi(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...Hi(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Hi(s.document,t))}}catch{}return n}function ea(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function cu(){var e,t;const n=ea()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ta(e){return!e||!jr(e)?!1:e instanceof Ze(e).ShadowRoot}function Os(e){if(e&&jr(e)){let t=e.getRootNode();if(ta(t))return t;if(t instanceof Document)return t}return Rn(e)}function na(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function wh(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((i,o)=>{const a=r[o];if(Ka(i)&&Ka(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Va(i)&&Va(a)&&a.width>0&&a.height>0){const l=i.getContext("2d");l?.drawImage(a,0,0)}}),n}function Ka(e){return"value"in e}function Va(e){return e.tagName==="CANVAS"}function uu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(_h(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return uu(s,{x:t-i,y:n-o})}}return r}function _h(e){return e?.tagName==="IFRAME"}var Xi=new WeakMap;function kh(e){return e.closest(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),S=require("../useCompiledDocument-B21sVbb4.cjs.js"),$=require("@mui/material"),k=require("react"),Se=require("../ServerProvider-BOgiW8MX.cjs.js"),ge=require("../text-entry-BJwltZiy.cjs.js"),Zu=require("react-dom"),Ju=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"})),Ii=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xt=Ii?"⌘":"Ctrl+",Ia=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 ef(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=Ii?i.metaKey:i.ctrlKey,c=i.key.toLowerCase();if(i.key==="Escape"){if(Ia(i.target)||fi(i.target))return;o.escape();return}if(Ia(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(!Ii&&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 mr=(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}}}),Ts=(e=Se.DEFAULT_UI)=>({width:e.size.control,height:e.size.control,borderRadius:e.radius.control,"& svg":{fontSize:18}}),vr={height:20,alignSelf:"center",mx:.5,my:0},En=(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"}}}),Pi={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function tf({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,layout:h,onLayoutChange:p}){const{theme:v}=Se.usePublisherTheme(),x=S.edgeColor(v.cardBorder),_=S.hoverEdgeColor(v.cardBorder,v.tileTitle);return m.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&p&&m.jsxs(m.Fragment,{children:[m.jsx($.Tooltip,{title:"Layout: tiles side by side, or one after another",children:m.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(g,y)=>{y&&y!==h&&p(y)},sx:En(x,v.ui),children:[m.jsx($.ToggleButton,{value:"linear","aria-label":"Linear layout",children:"Linear"}),m.jsx($.ToggleButton,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),m.jsx($.Divider,{orientation:"vertical",sx:vr})]}),l&&m.jsx($.Button,{variant:"outlined",startIcon:m.jsx(S.AddIcon,{}),onClick:l,"aria-label":"Add tile",sx:mr(x,_,v.ui),children:"Tile"}),l&&m.jsx($.Divider,{orientation:"vertical",sx:vr}),m.jsx($.Tooltip,{title:`Undo (${Xt}Z)`,children:m.jsx("span",{children:m.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:Ts(v.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:Ts(v.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(d||o||u)&&m.jsx($.Divider,{orientation:"vertical",sx:vr}),d,o?m.jsx($.Tooltip,{title:s?`Save (${Xt}S) · ${c??Pi[a]}`:c??Pi[a],children:m.jsx("span",{children:m.jsx($.Button,{ref:f,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{...mr(x,_,v.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 nf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function Nl(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:nf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Pa(e){return e.description??S.readableName(e.name)}const rf={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"},Jr=(e,t)=>`${e}\0${t}`;function sf({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 M=new Set(t.sources.map(F=>F.base));return[...l].sort((F,H)=>Number(M.has(H.name))-Number(M.has(F.name)))},[l,t]),T=b.filter(M=>M.views.length>0),C=b.filter(M=>M.views.length===0),j=k.useMemo(()=>new Map(T.flatMap(M=>M.views.map(F=>[Jr(M.name,F.name),{source:M,view:F,key:Jr(M.name,F.name)}]))),[T]),D=k.useMemo(()=>T.map(M=>({key:M.name,label:M.name,...M.description?{detail:M.description}:{},entries:M.views.map(F=>({key:Jr(M.name,F.name),name:F.name,title:Pa(F),...F.chart?{chart:F.chart}:{}}))})),[T]),E=p===void 0?void 0:j.get(p);k.useEffect(()=>{if(!e)return;h(""),_(""),y("default");const M=T[0]?.views[0];v(M&&T[0]?Jr(T[0].name,M.name):void 0)},[e]);const R=E?[E.source.name,E.view.name].filter(M=>!ge.isBareName(M)).map(M=>`"${M}" is not a plain Malloy name, so a tile cannot be written for it.`)[0]:void 0,P=E!==void 0&&R===void 0,A=E?Pa(E.view):"",U=g!=="default"&&E?{chart:g,chartCarried:E.view.chart?[E.view.chart]:[]}:{},z=(M=E)=>{if(!M||![M.source.name,M.view.name].every(ge.isBareName))return;const F=M.key===E?.key;i({base:M.source.name,modelPath:M.source.modelPath,...M.source.exporters?{exporters:M.source.exporters}:{},view:M.view.name,...F&&x.trim()?{label:x.trim()}:{},...F?U:{},colspan:Math.ceil(r/2)})},q=E?Nl(E.view,g).filter(M=>M.value!=="custom"&&M.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:!P,onClick:()=>z(),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:D,query:u,onQuery:h,picked:E?.key,onPick:M=>{v(M),y("default")},onTake:M=>z(j.get(M)),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(M=>M.name).join(", "),"."]})})}),m.jsx($.Box,{sx:M=>({p:2.5,display:"flex",flexDirection:"column",gap:2,minHeight:0,overflowY:"auto",bgcolor:`color-mix(in srgb, ${M.palette.text.primary} 3%, ${M.palette.background.paper})`}),children:E?m.jsxs(m.Fragment,{children:[m.jsx($.Box,{"aria-label":"Preview",role:"region",sx:M=>({height:240,flex:"none",display:"flex",position:"relative",overflow:"hidden",borderRadius:f.radius.tile,border:`1px solid ${d}`,bgcolor:M.palette.background.paper,"&::after":{content:'""',position:"absolute",left:0,right:0,bottom:0,height:40,pointerEvents:"none",background:`linear-gradient(to bottom, transparent, ${M.palette.background.paper})`}}),children:a?m.jsx($.Box,{sx:{flex:1,minWidth:0,px:2,pt:1.5},children:a({base:E.source.name,modelPath:E.source.modelPath,view:E.view.name,label:x.trim()||A,...g!=="default"?U:{},givens:E.source.givens})}):m.jsxs($.Box,{sx:M=>({flex:1,border:`1px solid ${d}`,borderRadius:f.radius.tile,bgcolor:M.palette.background.paper,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:1,color:"text.secondary"}),children:[m.jsx(S.ChartGlyph,{chart:E.view.chart}),m.jsxs($.Typography,{variant:"body2",children:[E.source.name," → ",E.view.name]})]})}),m.jsx($.TextField,{size:"small",label:"Title",placeholder:A,value:x,onChange:M=>_(M.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:(M,F)=>{F!==null&&y(F)},sx:{...En(d,f),"& .MuiToggleButton-root":{...En(d,f)["& .MuiToggleButton-root"],textTransform:"none"}},children:q.map(M=>m.jsx($.ToggleButton,{value:M.value,children:M.label},M.value))}),m.jsx($.Typography,{variant:"caption",component:"p",sx:{color:"text.secondary",mt:.75},children:E.view.chart?`The view declares ${rf[E.view.chart]??"a chart"}.`:"The view declares no chart, so it shows as a table."})]}),R&&m.jsx($.Typography,{variant:"body2",color:"error",children:R})]}):m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",m:"auto"},children:"Pick a view to see it here."})})]})})}const Me=e=>e.kind==="text",le=e=>e.kind!=="text",Xn=e=>le(e)?e.label??e.name:e.name,Be=e=>Me(e)?`text.${e.name}`:`${e.source}.${e.name}`;function of(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=Gl(e,t.base),a=Ri(e,o.name,t.view);e.tiles.splice(i??e.tiles.length,0,{name:a,source:o.name,declaration:{kind:"reference",from:t.view},...s?{colspan:t.colspan}:{},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Gl(e,t,{unscoped:n=!1}={}){const r=e.sources.find(a=>a.base===t&&(!n||!a.scopedBy?.length));if(r)return r;const s=new Set(e.sources.map(a=>a.name));let i=`${t}_tiles`;for(let a=2;s.has(i);a++)i=`${t}_tiles_${a}`;const o={name:i,base:t};return e.sources.push(o),o}function Ri(e,t,n){const r=new Set(e.tiles.filter(le).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 af(e,t){const n=e.tiles[t];if(!n||!le(n)||Es(n)!==void 0)return;let r;if(n.declaration.kind==="reference"){const{break:s,...i}=structuredClone(n);r={...i,name:Ri(e,n.source,n.declaration.from)}}else{const i=e.sources.find(o=>o.name===n.source)??Gl(e,n.source,{unscoped:!0});r={name:Ri(e,i.name,n.name),source:i.name,declaration:{kind:"reference",from:n.name},...n.colspan!==void 0?{colspan:n.colspan}:{}}}return e.tiles.splice(t+1,0,r),t+1}const es="self";function lf({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=[es,...s.filter(g=>g!==es)],p=g=>g===es?"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:[es]:(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:cf(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,j=Array.isArray(C)?C:String(C).split(",").filter(Boolean);j.length===0&&(T.lastTo=T.to),T.to=j}),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 cf(e){const t=e.replace(/_+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const df=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"})),uf=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"})),ff=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"})),hf=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"})),pf=S.createSvgIcon(m.jsx("path",{d:"M4 9h16v2H4zm0 4h10v2H4z"})),gf=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 mf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of le(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 vf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function yr(e,t){const n=vf(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Ai(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function yf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const bf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function xf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=ge.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const wf=[{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 Jn(e){const t=e.label.trim()||e.name,n=e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Li=e=>le(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function _f(e,t){return e.tiles.map(n=>{const r=(le(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 kf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Li(i))return;const o=(i.filters??[]).filter(c=>c.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?i.filters=a:delete i.filters})}function Sf(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 $f(e,t){for(const r of e.tiles){if(!le(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Bi=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function Tf({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),[j,D]=k.useState(!1),E=O=>t.sources.find(L=>L.name===O.source)?.base??O.source;k.useEffect(()=>{if(e)if(D(n!==void 0),n){l({kind:"existing",name:n.name}),h(n.label??"");const O=_f(t,n);b(O);const L=O.filter(I=>I.include),N=new Set(L.map(I=>I.field));y(N.size===1?L[0].field:n.field??""),C(N.size>1)}else l({kind:"new"}),h(""),v("select"),y(""),_(new Date().toISOString().slice(0,10)),b(t.tiles.map(O=>({include:Li(O),field:""}))),C(!1)},[e,n,t]);const R=k.useMemo(()=>[...(t.localGivens??[]).map(O=>O.name),...r.map(O=>O.name),...s],[t,r,s]),P=k.useMemo(()=>g.trim()?xf(g.trim(),R):"",[g,R]),A=d.kind==="existing"?n??r.find(O=>O.name===d.name):P?{name:P,type:Jn({name:P,label:u,kind:p,field:g}).type}:void 0,U=A?.type!==void 0&&!A.type.startsWith("filter<"),z=w.find(O=>O.include)?.op??Cs(A?.type),q=(O,L)=>{D(!0),b(N=>N.map((I,V)=>V===O?{...I,...L}:I))},M=O=>{D(!0),b(L=>L.map(N=>({...N,op:O})))},F=O=>{const L=Cs(O);b(N=>N.map(({op:I,...V})=>L?{...V,op:L}:V))},H=O=>{D(!0),l({kind:"existing",name:O.name}),y(O.field??""),F(O.type)},B=O=>{D(!0),v(O),F(Jn({name:"X",label:u,kind:O,field:g}).type)},W=t.tiles.map(Li),Q=W.filter(Boolean).length,J=w.filter((O,L)=>O.include&&W[L]).length,ee=t.tiles.filter((O,L)=>(w[L]?.include??!1)&&W[L]&&le(O)),te=ee.length>0?ee:t.tiles.filter((O,L)=>W[L]&&le(O)),Z=k.useMemo(()=>{const O=new Map;let L=!1;for(const N of te){const I=i?.(N);if(I){L=!0;for(const V of I)O.has(V.name)||O.set(V.name,V)}}return L?[...O.values()]:void 0},[w,t.tiles,i]),xe=(()=>{const O=g.trim();for(const L of ee){const N=i?.(L);if(!N||N.some(I=>I.name===O))return E(L)}return ee[0]?E(ee[0]):t.sources[0]?.base})(),Re=O=>{D(!0),b(L=>L.map((N,I)=>({...N,include:O&&W[I]})))},ue=k.useMemo(()=>T?w:w.map(O=>({...O,field:g})),[T,w,g]),we=O=>{for(const L of te){const N=i?.(L)?.find(I=>I.name===O.trim());if(N?.type)return N.type}},fe=O=>yr(A?.type,O.type),_e=(O,L)=>{if(O.trim()==="")return"Pick the field this filter compares.";const N=L?i?.(L):void 0;if(!N)return;const I=N.find(V=>V.name===O.trim());if(!I)return`Not a field of ${L?E(L):"the tiles' source"}.`;if(I.type&&!yr(A?.type,I.type))return`${O.trim()} is ${Ai(I.type)}; this filter compares ${Ai(A?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},X=O=>{if(D(!0),y(O),f||d.kind!=="new")return;const L=we(O),N=Jn({name:"X",label:u,kind:p,field:O}).type;L&&!yr(N,L)&&B(yf(L))},Ue=O=>{const L=t.tiles[O];return L&&le(L)?L:void 0},he=ue.map((O,L)=>O.include&&W[L]?_e(O.field,Ue(L)):void 0),oe=he.every(O=>O===void 0),Ae=j?he:he.map(()=>{}),ze=j&&!T&&J>0?ee.map(O=>_e(g,O)).find(Boolean):void 0,pe=A!==void 0&&oe&&(d.kind==="existing"||g.trim()!==""&&P!==""),We=()=>{if(!(!A||!pe))if(d.kind==="new")o(A.name,ue,Jn({name:A.name,label:u.trim()||Bi(A.name),kind:p,field:g.trim(),...xe?{source:xe}:{},...x?{dateDefault:x}:{}}));else if(n?.origin==="dashboard"&&n.local){const O=u.trim(),L=O!==(n.local.label??"");o(A.name,ue,L?{...n.local,...O?{label:O}:{}}:void 0)}else o(A.name,ue)},He=f&&c.origin==="model";return{editing:f,shown:c,fromModel:He,source:d,setSource:l,label:u,setLabel:h,kind:p,dateDefault:x,setDateDefault:_,field:g,rows:w,setRows:b,perTile:T,setPerTile:C,newName:P,target:A,valueTyped:U,commonOp:z,setRow:q,setCommonOp:M,pickExisting:H,pickKind:B,bindable:W,bindableCount:Q,included:J,commonFields:Z,setAll:Re,accepts:fe,pickField:X,rowProblems:Ae,commonProblem:ze,canApply:pe,apply:We}}function Ra({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(La,{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(La,{type:p.get(e.trim())})}):void 0},inputProps:{...v.inputProps,"aria-label":i}}),sx:u})}const Ef=e=>e&&le(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 Cf({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:j,setPerTile:D,newName:E,target:R,valueTyped:P,commonOp:A,setRow:U,setCommonOp:z,pickExisting:q,pickKind:M,bindable:F,bindableCount:H,included:B,commonFields:W,setAll:Q,accepts:J,pickField:ee,rowProblems:te,commonProblem:Z,canApply:xe,apply:Re}=Tf({open:e,document:t,control:n,available:r,...s?{takenNames:s}:{},fieldsFor:i,onApply:a}),ue=k.useRef(null),we=S.edgeColor(f.cardBorder),fe=S.hoverEdgeColor(f.cardBorder,f.tileTitle),[_e,X]=k.useState(!1),[Ue,he]=k.useState(!1);k.useEffect(()=>{e?he(!0):X(!1)},[e]),k.useEffect(()=>{Ue&&(he(!1),X(l&&B<H))},[Ue]),k.useEffect(()=>{j&&X(!0)},[j]);const oe=W?.find(O=>O.name===b.trim())?.type,Ae=O=>{if(!oe)return;const L=Jn({name:"X",label:x,kind:O,field:b}).type;return yr(L,oe)?void 0:`${b.trim()} is ${Ai(oe)}, which this control cannot filter.`},ze=x.trim()||(E?Bi(E):"Filter"),pe=g==="number"?"Any":g==="date"?y?new Date(`${y}T00:00:00`).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"}):"Any":"All",We={...En(we,d),alignSelf:"flex-start","& .MuiToggleButton-root":{...En(we,d)["& .MuiToggleButton-root"],textTransform:"none"}},He=(O,L,N)=>m.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:O??">=",onChange:I=>L(I.target.value),inputProps:{"aria-label":N},sx:{width:130},children:bf.filter(I=>I.op!=="~").map(I=>m.jsx($.MenuItem,{value:I.op,children:I.label},I.op))});return m.jsx(S.AppDialog,{className:`${S.reportClasses.dialog} ${S.reportClasses.filterDialog}`,open:e,onClose:o,...l?{}:{initialFocus:ue},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:O=>({mr:"auto",color:S.dangerTextColor(O)}),children:"Remove filter"}),m.jsx($.Button,{onClick:o,children:"Cancel"}),m.jsx($.Tooltip,{title:xe||R===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:!xe,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:(O,L)=>{L==="new"?v({kind:"new"}):L==="existing"&&r[0]&&q(r[0])},"aria-label":"Where the filter comes from",sx:We,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:O=>{const L=r.find(N=>N.name===O.target.value);L&&q(L)},children:r.map(O=>m.jsxs($.MenuItem,{value:O.name,children:[O.label??O.name,m.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",O.name]})]},O.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:[!j&&m.jsx(Ra,{value:b,onChange:ee,fields:W,accepts:J,label:"Field",ariaLabel:"Field to filter",placeholder:"category",inputRef:ue,error:Z!==void 0,helperText:Z??(!l&&E?`Declared as $${E}`:void 0)}),!h&&m.jsx($.TextField,{size:"small",label:"Label",placeholder:E?Bi(E):"",value:x,onChange:O=>_(O.target.value),InputLabelProps:{shrink:!0},inputProps:{"aria-label":"Filter label"}})]}),P&&!j&&He(A,z,"Comparison"),!l&&p.kind==="new"&&m.jsxs($.Box,{children:[m.jsx(Aa,{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:wf.map(O=>{const L=O.kind===g,N=Ae(O.kind);return m.jsx($.Tooltip,{title:N??O.hint,describeChild:!0,children:m.jsxs($.ButtonBase,{role:"radio","aria-checked":L,"aria-label":O.label,"aria-disabled":N!==void 0,onClick:()=>{N===void 0&&M(O.kind)},sx:I=>({flexDirection:"column",gap:.5,px:1,py:1.25,borderRadius:d.radius.tile,border:`1px solid ${L?f.accent:we}`,boxShadow:L?`0 0 0 1px ${f.accent}`:"none",bgcolor:L?`color-mix(in srgb, ${f.accent} 6%, ${I.palette.background.paper})`:I.palette.background.paper,color:L?f.accent:I.palette.text.secondary,opacity:N?.45:1,cursor:N?"default":"pointer",transition:`border-color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,"&:hover":N||L?{}:{borderColor:fe}}),children:[m.jsx(Df,{kind:O.kind}),m.jsx($.Box,{component:"span",sx:{...d.type.caption,fontWeight:L?600:500,color:L?f.accent:"text.primary",textAlign:"center"},children:Of[O.kind]})]})},O.kind)})}),g==="date"&&m.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:y,onChange:O=>w(O.target.value),InputLabelProps:{shrink:!0},sx:{mt:1.5,width:200}})]}),m.jsxs($.Box,{sx:{border:`1px solid ${we}`,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(gf,{"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"}`}),!j&&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()})]})]}),!j&&m.jsx($.Button,{size:"small","aria-expanded":_e,onClick:()=>X(O=>!O),children:_e?"Done choosing":"Choose tiles"})]}),m.jsx($.Collapse,{in:_e,unmountOnExit:!0,children:m.jsxs($.Box,{sx:{borderTop:`1px solid ${we}`,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:O=>Q(O.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:()=>{j||C(O=>O.map(L=>({...L,field:b}))),D(O=>!O)},children:j?"Same field for all":"Adjust per tile"})]}),m.jsx($.Stack,{sx:{gap:j?1:0},children:t.tiles.map((O,L)=>{if(!le(O))return null;const N=T[L],I=O.label??O.name,V=j?te[L]:void 0;return m.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:j?"flex-start":"center",opacity:F[L]?1:.6},children:[m.jsx($.Checkbox,{size:"small",disabled:!F[L],checked:(N?.include??!1)&&F[L],inputProps:{"aria-label":`Filter ${I}`},onChange:G=>U(L,{include:G.target.checked})}),m.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:j?1:0},noWrap:!0,children:I}),F[L]?j&&m.jsxs(m.Fragment,{children:[P&&He(N?.op,G=>U(L,{op:G}),`Comparison for ${I}`),m.jsx(Ra,{value:N?.field??"",onChange:G=>U(L,{field:G}),fields:i?.(O),accepts:J,label:"Field",ariaLabel:`Field for ${I}`,disabled:!N?.include,error:V!==void 0,helperText:V,sx:{width:220,pr:1}})]}):m.jsx($.Typography,{variant:"caption",sx:{color:f.tileTitle,pr:1,maxWidth:260,textAlign:"right"},children:Ef(t.tiles[L]).reason})]},`${O.source}.${O.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(Aa,{children:"Preview"}),m.jsx($.Box,{sx:O=>({display:"flex",alignItems:"center",gap:1,p:1.5,borderRadius:d.radius.tile,bgcolor:O.palette.action.hover}),children:m.jsxs($.Box,{"aria-hidden":!0,sx:O=>({display:"inline-flex",alignItems:"center",gap:.75,height:30,px:1.25,borderRadius:d.radius.control,border:`1px solid ${we}`,bgcolor:O.palette.background.paper,...d.type.control}),children:[m.jsx($.Box,{component:"span",sx:{color:"text.secondary"},children:ze}),m.jsx($.Box,{component:"span",sx:{fontWeight:d.type.label.fontWeight},children:pe}),m.jsx(S.ExpandMoreIcon,{sx:{fontSize:16,color:"text.secondary"}})]})})]})]})})}function Aa({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 Of={select:"Pick one",multiselect:"Pick several",text:"Text",number:"Range",date:"Date"};function Df({kind:e}){const t={fontSize:22};switch(e){case"select":return m.jsx(df,{sx:t});case"multiselect":return m.jsx(uf,{sx:t});case"text":return m.jsx(pf,{sx:t});case"number":return m.jsx(hf,{sx:t});case"date":return m.jsx(ff,{sx:t})}}function La({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 Mf=S.createSvgIcon(m.jsx("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}));function Vl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch: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 jf=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.`,If="Declared on its source, so its chart is set in the model.";function Pf({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}=Vl(t,e!==null,r,n),[h,p]=k.useState(void 0),v=d!==void 0&&le(d)?d:void 0,x=v!==void 0&&v.declaration.kind!=="inherited",_=R=>l(P=>{le(P)&&R(P)}),g=k.useRef(void 0),y=e!==null;k.useEffect(()=>{y?g.current=t&&le(t)?t.chart:void 0:p(void 0)},[y]);const w=v?.chart??"default",b=Nl(a,w),T=v?x?v.chart==="custom"?jf(v.chartLines):void 0:If:void 0,C=R=>_(P=>{const A=g.current;R===(A??"default")?(A===void 0?delete P.chart:P.chart=A,delete P.chartCarried):(P.chart=R,a?P.chartCarried=a.chart?[a.chart]:[]:delete P.chartCarried)}),j=x?s?void 0:"Its source declares no dimension a click could filter by.":void 0,D=R=>P=>p({kind:R,anchor:P.currentTarget}),E=(R,P,A)=>m.jsxs(m.Fragment,{children:[m.jsx($.ListItemText,{primary:R,...A?{secondary:A}:{},secondaryTypographyProps:{sx:{whiteSpace:"normal",maxWidth:240}}}),P&&m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",ml:2},children:P})]});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:D("chart"),onKeyDown:R=>{R.key==="ArrowRight"&&T===void 0&&p({kind:"chart",anchor:R.currentTarget})},children:[E("Chart",T?void 0:b.find(R=>R.value===w)?.label,T),m.jsx(Mf,{fontSize:"small",sx:{ml:1,color:"text.secondary"}})]}),x&&m.jsx($.MenuItem,{"aria-haspopup":"dialog",disabled:j!==void 0,onClick:()=>{u(),s?.()},children:E("Clickable cells…",void 0,j)}),v&&i&&m.jsx($.MenuItem,{disabled:o!==void 0,onClick:()=>{u(),i()},children:E("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:R=>{R.key==="ArrowLeft"&&(R.preventDefault(),p(void 0))}},children:b.filter(R=>R.value!=="custom").map(R=>m.jsxs($.MenuItem,{role:"menuitemradio","aria-checked":R.value===w,disabled:R.disabled===!0,onClick:()=>{C(R.value),p(void 0)},children:[m.jsx($.ListItemText,{primary:R.label,...R.reason?{secondary:R.reason}:{}}),R.value===w&&m.jsx($.ListItemIcon,{sx:{minWidth:0,ml:2},children:m.jsx(S.CheckIcon,{fontSize:"small",sx:{color:c.accent}})})]},R.value))})]})}const kn=e=>e.label??S.tileTitle(`${e.source} -> ${e.name}`);function Rf({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=_&&le(_)?_: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(Cf,{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(Pf,{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(lf,{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(j=>j.source!==o),...w];C.length===0?delete b.drills:b.drills=C})}),m.jsx(S.UnsavedChangesDialog,{...c}),m.jsx(sf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText,...f?{renderPreview:f}:{}})]})}var Af=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}})();xr!==void 0;){var n=xr;for(xr=void 0,Os++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Hl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Os=0,kt--,t)throw e}}function Ee(e){if(kt>0)return e();Fi=++Lf,kt++;try{return e()}finally{Qs()}}var br,ye=void 0;function re(e){var t=ye,n=br;ye=void 0,br=void 0;try{return e()}finally{ye=t,br=n}}var xr=void 0,kt=0,Os=0,Lf=0,Fi=0,Ds=void 0,Ms=0;function Ul(e){if(ye!==void 0){var t=e.n;if(t===void 0||t.t!==ye)return t={i:0,S:e,p:ye.s,n:void 0,t:ye,e:void 0,x:void 0,r:t},ye.s!==void 0&&(ye.s.n=t),ye.s=t,e.n=t,32&ye.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ye.s,t.n=void 0,ye.s.n=t,ye.s=t),t}}function 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=Af;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:re(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&&re(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;re(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 re(function(){return e.value})};Object.defineProperty(Ze.prototype,"value",{get:function(){var e=Ul(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Os>100)throw new Error("Cycle detected");(function(n){kt!==0&&Os===0&&n.l!==Fi&&(n.l=Fi,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 Pn(e,t){return new Ze(e,t)}function Hl(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function 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 Kl(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&&!Hl(this))return this.f&=-2,!0;var e=ye;try{ql(this),ye=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ye=e,Kl(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=Ul(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Ba(e,t){return new Jt(e,t)}function Yl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){kt++;var n=ye;ye=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,To(e),r}finally{ye=n,Qs()}}}function To(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Yl(e)}function Bf(e){if(ye!==this)throw new Error("Out-of-order effect");Kl(this),ye=e,this.f&=-2,8&this.f&&To(this),Qs()}function Rn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,br&&br.push(this)}Rn.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()}};Rn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Yl(this),ql(this),kt++;var e=ye;return ye=this,Bf.bind(this,e)};Rn.prototype.N=function(){2&this.f||(this.f|=2,this.u=xr,xr=this)};Rn.prototype.d=function(){this.f|=8,1&this.f||To(this)};Rn.prototype.dispose=function(){this.d()};function dt(e,t){var n=new Rn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Ff=Object.create,Eo=Object.defineProperty,zf=Object.defineProperties,Wf=Object.getOwnPropertyDescriptor,Nf=Object.getOwnPropertyDescriptors,Fa=Object.getOwnPropertySymbols,Gf=Object.prototype.hasOwnProperty,Vf=Object.prototype.propertyIsEnumerable,Uf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),An=e=>{throw TypeError(e)},zi=(e,t,n)=>t in e?Eo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hf=(e,t)=>{for(var n in t||(t={}))Gf.call(t,n)&&zi(e,n,t[n]);if(Fa)for(var n of Fa(t))Vf.call(t,n)&&zi(e,n,t[n]);return e},qf=(e,t)=>zf(e,Nf(t)),za=(e,t)=>Eo(e,"name",{value:t,configurable:!0}),Kf=e=>{var t;return[,,,Ff((t=void 0)!=null?t:null)]},Xl=["class","method","getter","setter","accessor","field","value","get","set"],er=e=>e!==void 0&&typeof e!="function"?An("Function expected"):e,Yf=(e,t,n,r,s)=>({kind:Xl[e],name:t,metadata:r,addInitializer:i=>n._?An("Already initialized"):s.push(er(i||null))}),Ql=(e,t)=>zi(t,Uf("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},Ln=(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=Xl[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&Wf(l<4?s:{get[n](){return it(this,i)},set[n](w){return Mt(this,i,w)}},n));l?h&&l<4&&za(i,(l>2?"set ":l>1?"get ":"")+n):za(s,n);for(var y=r.length-1;y>=0;y--)f=Yf(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>Xf(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?it:Qf)(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?er(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?An("Object expected"):(er(o=a.get)&&(g.get=o),er(o=a.set)&&(g.set=o),er(o=a.init)&&x.unshift(o));return l||Ql(e,s),g&&Eo(s,n,g),h?l^4?i:g:s},Co=(e,t,n)=>t.has(e)||An("Cannot "+n),Xf=(e,t)=>Object(t)!==t?An('Cannot use the "in" operator on this value'):e.has(t),it=(e,t,n)=>(Co(e,t,"read from private field"),n?n.call(e):t.get(e)),tr=(e,t,n)=>t.has(e)?An("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Mt=(e,t,n,r)=>(Co(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Qf=(e,t,n)=>(Co(e,t,"access private method"),n);function Wi(e,t){if(t){let n;return Ba(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Ba(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 se({get:e},t){return{init(n){return Pn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Oe(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Wi(e.bind(this)),n.set(this,r)),r.value}}function 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,qf(Hf({},s),{enumerable:e}))})}}function Lr(...e){const t=e.map(n=>dt(n));return()=>t.forEach(n=>n())}var Zl,Jl,ec,tc,nc,rc,Ye,Oo,pi,Ni,Gi,qe,Do,gi,sc,Vi,Mo,mi,Ui,Hi;rc=[se],nc=[se],tc=[se],ec=[hi()],Jl=[hi()],Zl=[hi()];var en=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Ft(Ye,5,this),tr(this,qe),tr(this,Oo,Ft(Ye,8,this)),Ft(Ye,11,this),tr(this,Do,Ft(Ye,12,this)),Ft(Ye,15,this),tr(this,Mo,Ft(Ye,16,this)),Ft(Ye,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return it(this,qe,Ui)}get initial(){return it(this,qe,Ni)}get previous(){return it(this,qe,sc)}set current(e){const t=re(()=>it(this,qe,Ui));e&&t&&this.equals(t,e)||Ee(()=>{it(this,qe,Ni)||Mt(this,qe,e,Gi),Mt(this,qe,t,Vi),Mt(this,qe,e,Hi)})}reset(e=this.defaultValue){Ee(()=>{Mt(this,qe,void 0,Vi),Mt(this,qe,e,Gi),Mt(this,qe,e,Hi)})}};Ye=Kf();Oo=new WeakMap;qe=new WeakSet;Do=new WeakMap;Mo=new WeakMap;pi=Ln(Ye,20,"#initial",rc,qe,Oo),Ni=pi.get,Gi=pi.set;gi=Ln(Ye,20,"#previous",nc,qe,Do),sc=gi.get,Vi=gi.set;mi=Ln(Ye,20,"#current",tc,qe,Mo),Ui=mi.get,Hi=mi.set;Ln(Ye,2,"current",ec,en);Ln(Ye,2,"initial",Jl,en);Ln(Ye,2,"previous",Zl,en);Ql(Ye,en);function vi(e){return re(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var zt,Zf=class{constructor(){tr(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 Jf=Object.create,ic=Object.defineProperty,eh=Object.getOwnPropertyDescriptor,Wa=Object.getOwnPropertySymbols,th=Object.prototype.hasOwnProperty,nh=Object.prototype.propertyIsEnumerable,oc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zs=e=>{throw TypeError(e)},Na=Math.pow,qi=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rh=(e,t)=>{for(var n in t||(t={}))th.call(t,n)&&qi(e,n,t[n]);if(Wa)for(var n of Wa(t))nh.call(t,n)&&qi(e,n,t[n]);return e},sh=e=>{var t;return[,,,Jf((t=e?.[oc("metadata")])!=null?t:null)]},ac=["class","method","getter","setter","accessor","field","value","get","set"],lc=e=>e!==void 0&&typeof e!="function"?Zs("Function expected"):e,ih=(e,t,n,r,s)=>({kind:ac[e],name:t,metadata:r,addInitializer:i=>n._?Zs("Already initialized"):s.push(lc(i||null))}),oh=(e,t)=>qi(t,oc("metadata"),e[3]),ah=(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},cc=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=ac[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,eh(s,n)),_=r.length-1;_>=0;_--)c=ih(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,lc(o)&&(x[p]=o);return x&&ic(s,n,x),s},dc=(e,t,n)=>t.has(e)||Zs("Cannot "+n),lh=(e,t,n)=>(dc(e,t,"read from private field"),t.get(e)),ch=(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),dh=(e,t,n,r)=>(dc(e,t,"write to private field"),t.set(e,n),n),ot=class Ki{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ki(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Ki(t,n)}},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=rh({},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?uh(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 uh(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 uc,fc,Yi,fs,Br,Js=class extends(Yi=en,fc=[Oe],uc=[Oe],Yi){constructor(t){const n=ot.from(t);super(n,(r,s)=>ot.equals(r,s)),ah(Br,5,this),ch(this,fs,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-lh(this,fs),a=c=>Math.round(c/o*100);Ee(()=>{dh(this,fs,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}}};Br=sh(Yi);fs=new WeakMap;cc(Br,2,"delta",fc,Js);cc(Br,2,"direction",uc,Js);oh(Br,Js);function Xi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Na(r,2)+Na(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 hc=(e=>(e.Horizontal="x",e.Vertical="y",e))(hc||{}),pc=Object.values(hc),fh=Object.create,jo=Object.defineProperty,hh=Object.defineProperties,ph=Object.getOwnPropertyDescriptor,gh=Object.getOwnPropertyDescriptors,js=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,mc=Object.prototype.propertyIsEnumerable,vc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Bn=e=>{throw TypeError(e)},Qi=(e,t,n)=>t in e?jo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Io=(e,t)=>{for(var n in t||(t={}))gc.call(t,n)&&Qi(e,n,t[n]);if(js)for(var n of js(t))mc.call(t,n)&&Qi(e,n,t[n]);return e},Po=(e,t)=>hh(e,gh(t)),Ga=(e,t)=>jo(e,"name",{value:t,configurable:!0}),yc=(e,t)=>{var n={};for(var r in e)gc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&js)for(var r of js(e))t.indexOf(r)<0&&mc.call(e,r)&&(n[r]=e[r]);return n},Fn=e=>{var t;return[,,,fh((t=e?.[vc("metadata")])!=null?t:null)]},bc=["class","method","getter","setter","accessor","field","value","get","set"],nr=e=>e!==void 0&&typeof e!="function"?Bn("Function expected"):e,mh=(e,t,n,r,s)=>({kind:bc[e],name:t,metadata:r,addInitializer:i=>n._?Bn("Already initialized"):s.push(nr(i||null))}),tn=(e,t)=>Qi(t,vc("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},ie=(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=bc[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&ph(l<4?s:{get[n](){return Ce(this,i)},set[n](w){return rt(this,i,w)}},n));l?h&&l<4&&Ga(i,(l>2?"set ":l>1?"get ":"")+n):Ga(s,n);for(var y=r.length-1;y>=0;y--)f=mh(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>vh(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?Ce:xc)(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?nr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Bn("Object expected"):(nr(o=a.get)&&(g.get=o),nr(o=a.set)&&(g.set=o),nr(o=a.init)&&x.unshift(o));return l||tn(e,s),g&&jo(s,n,g),h?l^4?i:g:s},Ro=(e,t,n)=>t.has(e)||Bn("Cannot "+n),vh=(e,t)=>Object(t)!==t?Bn('Cannot use the "in" operator on this value'):e.has(t),Ce=(e,t,n)=>(Ro(e,t,"read from private field"),n?n.call(e):t.get(e)),de=(e,t,n)=>t.has(e)?Bn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Ro(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),xc=(e,t,n)=>(Ro(e,t,"access private method"),n);function wc(e,t){return{plugin:e,options:t}}function Fr(e){return t=>wc(e,t)}function Tr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var _c,Er,Ao,hs;_c=[se];var Ke=class{constructor(e,t){this.manager=e,this.options=t,de(this,Ao,Y(Er,8,this,!1)),Y(Er,11,this),de(this,hs,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return re(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=dt(e.bind(this));return Ce(this,hs).add(t),t}destroy(){Ce(this,hs).forEach(e=>e())}static configure(e){return wc(this,e)}};Er=Fn(null);Ao=new WeakMap;hs=new WeakMap;ie(Er,4,"disabled",_c,Ke,Ao);tn(Er,Ke);var zr=class extends Ke{},ps,yi=class{constructor(e){this.manager=e,this.instances=new Map,de(this,ps,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Tr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Ce(this,ps))if(!n.includes(r)){if(r.prototype instanceof zr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);rt(this,ps,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()}};ps=new WeakMap;function yh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var ts=[],hn,pn,bh=class extends Ke{constructor(e){super(e),de(this,hn),de(this,pn),this.computeCollisions=this.computeCollisions.bind(this),rt(this,pn,Pn(ts)),this.destroy=Lr(()=>{const t=this.computeCollisions(),n=re(()=>this.manager.dragOperation.position.current);if(t!==ts){const r=Ce(this,hn);if(rt(this,hn,n),r&&n.x==r.x&&n.y==r.y)return}else rt(this,hn,void 0);Ce(this,pn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){re(()=>{e?Ce(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 ts;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=re(()=>d({droppable:f,dragOperation:r}));l&&(f.collisionPriority!=null&&(l.priority=f.collisionPriority),a.push(l))}return c.length===0?ts:(a.sort(yh),a)}get collisions(){return Ce(this,pn).value}};hn=new WeakMap;pn=new WeakMap;var kc,Sc,$c,Lo,Tc,ht,Bo,xn,Fo,zo;$c=[se],Sc=[se],kc=[se];var $t=class Nt{constructor(t,n){de(this,Bo,Y(ht,8,this)),Y(ht,11,this),de(this,xn),de(this,Fo,Y(ht,12,this)),Y(ht,15,this),de(this,zo,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,Pn(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=Ce(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:Ce(this,xn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return xc(i=Nt,Lo,Tc).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=Fn(null);Lo=new WeakSet;Tc=function(){const e=$t.pendingIdChanges;$t.pendingIdChanges=null,e&&Ee(()=>{for(const[t,n]of e)Ce(t,xn).value=n})};Bo=new WeakMap;xn=new WeakMap;Fo=new WeakMap;zo=new WeakMap;ie(ht,4,"manager",$c,$t,Bo);ie(ht,4,"data",Sc,$t,Fo);ie(ht,4,"disabled",kc,$t,zo);de($t,Lo);tn(ht,$t);$t.pendingIdChanges=null;var ei=$t,Va=class{constructor(){this.map=Pn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,c]of n)if(c===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Lr(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Ec,Cc,Oc,Dc,Mc,jc,Zi,Xe,Wo,No,Go,xt=class extends(Zi=ei,jc=[se],Mc=[se],Dc=[se],Oc=[Oe],Cc=[Oe],Ec=[Oe],Zi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:c}=r,f=yc(r,["modifiers","type","sensors","plugins","effects"]);super(Po(Io({},f),{effects:()=>{var d;return[...(d=c?.())!=null?d:[],()=>{const{manager:l,plugins:u}=this;if(!(!l||!u))for(const h of u){const{plugin:p}=Tr(h);l.registry.plugins.register(p)}}]}}),n),Y(Xe,5,this),de(this,Wo,Y(Xe,8,this)),Y(Xe,11,this),de(this,No,Y(Xe,12,this)),Y(Xe,15,this),de(this,Go,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=Tr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};Xe=Fn(Zi);Wo=new WeakMap;No=new WeakMap;Go=new WeakMap;ie(Xe,4,"type",jc,xt,Wo);ie(Xe,4,"modifiers",Mc,xt,No);ie(Xe,4,"status",Dc,xt,Go);ie(Xe,2,"isDropping",Oc,xt);ie(Xe,2,"isDragging",Cc,xt);ie(Xe,2,"isDragSource",Ec,xt);tn(Xe,xt);var Ic,Pc,Rc,Ac,Lc,Bc,Ji,Le,Vo,Uo,Ho,qo,Ko,wt=class extends(Ji=ei,Bc=[se],Lc=[se],Ac=[se],Rc=[se],Pc=[se],Ic=[Oe],Ji){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,c=yc(r,["accept","collisionDetector","collisionPriority","type"]);super(c,n),Y(Le,5,this),de(this,Vo,Y(Le,8,this)),Y(Le,11,this),de(this,Uo,Y(Le,12,this)),Y(Le,15,this),de(this,Ho,Y(Le,16,this)),Y(Le,19,this),de(this,qo,Y(Le,20,this)),Y(Le,23,this),de(this,Ko,Y(Le,24,this)),Y(Le,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}};Le=Fn(Ji);Vo=new WeakMap;Uo=new WeakMap;Ho=new WeakMap;qo=new WeakMap;Ko=new WeakMap;ie(Le,4,"accept",Bc,wt,Vo);ie(Le,4,"type",Lc,wt,Uo);ie(Le,4,"collisionDetector",Ac,wt,Ho);ie(Le,4,"collisionPriority",Rc,wt,qo);ie(Le,4,"shape",Pc,wt,Ko);ie(Le,2,"isDropTarget",Ic,wt);tn(Le,wt);var xh=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)}},wh=class extends xh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function gs(e,t=!0){let n=!1;return Po(Io({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var _h=class extends zr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Lr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||ei.pendingIdChanges)return;const o=gs({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;re(()=>{var c;a?.id!==((c=e.dragOperation.target)==null?void 0:c.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},zn=(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))(zn||{}),Wn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Wn||{}),Fc,zc,Wc,Nc,Gc,Vc,Uc,ct,Yo;Uc=[se],Vc=[Oe],Gc=[Oe],Nc=[Oe],Wc=[Oe],zc=[Oe],Fc=[Oe];var Et=class{constructor(){Y(ct,5,this),de(this,Yo,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=Fn(null);Yo=new WeakMap;ie(ct,4,"value",Uc,Et,Yo);ie(ct,2,"current",Vc,Et);ie(ct,2,"idle",Gc,Et);ie(ct,2,"initializing",Nc,Et);ie(ct,2,"initialized",Wc,Et);ie(ct,2,"dragging",zc,Et);ie(ct,2,"dropped",Fc,Et);tn(ct,Et);var kh=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 re(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=gs({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return re(()=>{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;Ee(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=gs({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"&&Ee(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return re(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=gs({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 re(()=>{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=re(()=>{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()})}},Cn=class extends Ke{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Sh=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)}},ms,Hc=class{constructor(e){this.options=e,de(this,ms)}set controller(e){rt(this,ms,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ce(this,ms))==null||t.activate(e)}};ms=new WeakMap;var Ua=class extends Ke{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},$h=class{constructor(e){this.draggables=new Va,this.droppables=new Va,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 Ua)return this.modifiers.register(e,t);if(e.prototype instanceof Cn)return this.sensors.register(e,t);if(e.prototype instanceof Ke)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 Ua)return this.modifiers.unregister(e);if(e.prototype instanceof Cn)return this.sensors.unregister(e);if(e.prototype instanceof Ke)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,Kc,Yc,Xc,Qc,Zc,Jc,ed,td,rr,vs,gn,Te,Xo,Qo,Zo,Jo,ea,sr;td=[Oe],ed=[se],Jc=[se],Zc=[se],Qc=[se],Xc=[se],Yc=[Oe],Kc=[Oe],qc=[Oe];var mt=class{constructor(e){Y(Te,5,this),de(this,rr),de(this,vs),de(this,gn,new en(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Et,de(this,Xo,Y(Te,8,this,!1)),Y(Te,11,this),de(this,Qo,Y(Te,12,this,null)),Y(Te,15,this),de(this,Zo,Y(Te,16,this,null)),Y(Te,19,this),de(this,Jo,Y(Te,20,this,null)),Y(Te,23,this),de(this,ea,Y(Te,24,this,[])),Y(Te,27,this),this.position=new Js({x:0,y:0}),de(this,sr,{x:0,y:0}),rt(this,rr,e)}get shape(){const{current:e,initial:t,previous:n}=Ce(this,gn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ce(this,gn).current=e:Ce(this,gn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ce(this,rr).registry.draggables.get(t);return n&&rt(this,vs,n),(e=n??Ce(this,vs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ce(this,rr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Po(Io({},this.snapshot()),{transform:n}));return rt(this,sr,n),n}snapshot(){return re(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ce(this,sr),shape:this.shape?vi(this.shape):null,position:vi(this.position),status:vi(this.status),canceled:this.canceled}))}reset(){Ee(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ce(this,gn).reset(),this.position.reset({x:0,y:0}),rt(this,sr,{x:0,y:0}),this.modifiers=[]})}};Te=Fn(null);rr=new WeakMap;vs=new WeakMap;gn=new WeakMap;Xo=new WeakMap;Qo=new WeakMap;Zo=new WeakMap;Jo=new WeakMap;ea=new WeakMap;sr=new WeakMap;ie(Te,2,"shape",td,mt);ie(Te,4,"canceled",ed,mt,Xo);ie(Te,4,"activatorEvent",Jc,mt,Qo);ie(Te,4,"sourceIdentifier",Zc,mt,Zo);ie(Te,4,"targetIdentifier",Qc,mt,Jo);ie(Te,4,"modifiers",Xc,mt,ea);ie(Te,2,"source",Yc,mt);ie(Te,2,"target",Kc,mt);ie(Te,2,"transform",qc,mt);tn(Te,mt);var Th={get rendering(){return Promise.resolve()}};function gt(e,t){return typeof e=="function"?e(t):e??t}var Eh=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:Th,c=new wh(this),f=new $h(this);this.registry=f,this.monitor=c,this.renderer=a,this.actions=new kh(this),this.dragOperation=new mt(this),this.collisionObserver=new bh(this),this.plugins=[_h,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,l=Lr(()=>{var u,h,p;const v=re(()=>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}=Tr(_);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}},nd=e=>{throw TypeError(e)},ta=(e,t,n)=>t.has(e)||nd("Cannot "+n),K=(e,t,n)=>(ta(e,t,"read from private field"),t.get(e)),Je=(e,t,n)=>t.has(e)?nd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),nt=(e,t,n,r)=>(ta(e,t,"write to private field"),t.set(e,n),n),rd=(e,t,n)=>(ta(e,t,"access private method"),n);function ti(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function sd(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 na(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Wr(e){return"nodeType"in e}function st(e){var t,n,r;return e?na(e)?e:Wr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function ra(e){const{Document:t}=st(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function At(e){return!e||na(e)?!1:e instanceof st(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function id(e){return e instanceof st(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Nn(e){return e?na(e)?e.document:Wr(e)?ra(e)?e:At(e)||id(e)?e.ownerDocument:document:document:document}function Ch(e){var t,n,r,s;const{documentElement:i}=Nn(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 Oh(e,t){if(Dh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Dh(e){return e.tagName==="DETAILS"}function Cr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let c=t;const{ownerDocument:f}=e,d=(r=f.defaultView)!=null?r:window;let l=e.parentElement;for(;l&&l!==f.documentElement;){if(!Oh(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 On(e){return{x:e.clientX,y:e.clientY}}var od=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function eo(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...eo(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...eo(s.document,t))}}catch{}return n}function sa(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ad(){var e,t;const n=sa()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function ia(e){return!e||!Wr(e)?!1:e instanceof st(e).ShadowRoot}function Is(e){if(e&&Wr(e)){let t=e.getRootNode();if(ia(t))return t;if(t instanceof Document)return t}return Nn(e)}function oa(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Mh(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(Ha(i)&&Ha(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 Ha(e){return"value"in e}function qa(e){return e.tagName==="CANVAS"}function ld(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(jh(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return ld(s,{x:t-i,y:n-o})}}return r}function jh(e){return e?.tagName==="IFRAME"}var to=new WeakMap;function Ih(e){return e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),
5
5
  button:not([disabled]),
6
6
  a[href],
7
7
  [contenteditable]:not([contenteditable="false"])
8
- `)}var du=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:l,listener:d,options:c}=a,u=[o,a];o.addEventListener(l,d,c),this.entries.add(u),s.push(u)}const i=this.entries;return function(){for(const a of s){const[l,{type:d,listener:c,options:u}]=a;l.removeEventListener(d,c,u),i.delete(a)}}}};function Sn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Sh(e){const t=new Set;let n=Sn(e);for(;n;)t.add(n),n=Sn(n);return t}function $h(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function fu(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=$h(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Th(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function Oh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=br(e,t);return n>0&&r>0}var Eh=lu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ps,Ch=class extends Eh{constructor(e){super(t=>{if(!oe(this,ps)){Xe(this,ps,!0);return}e(t,this)}),Ue(this,ps,!1)}};ps=new WeakMap;var Ua=Array.from({length:100},(e,t)=>t/100),hu=75,Wt,Es,St,Bt,Jn,Ne,fr,er,Cs,pu,gu,mu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ue(this,Cs),this.disconnect=()=>{var i,o,a;Xe(this,fr,!0),(i=oe(this,St))==null||i.disconnect(),(o=oe(this,Bt))==null||o.disconnect(),oe(this,Jn).disconnect(),(a=oe(this,Ne))==null||a.remove()},Ue(this,Wt,!0),Ue(this,Es),Ue(this,St),Ue(this,Bt),Ue(this,Jn),Ue(this,Ne),Ue(this,fr,!1),Ue(this,er,fu(()=>{var i,o,a;const{element:l}=this;if((i=oe(this,Bt))==null||i.disconnect(),oe(this,fr)||!oe(this,Wt)||!l.isConnected)return;const d=(o=l.ownerDocument)!=null?o:document,{innerHeight:c,innerWidth:u}=(a=d.defaultView)!=null?a:window,f=l.getBoundingClientRect(),h=br(l,f),{top:p,left:m,bottom:b,right:x}=h,v=-Math.floor(p),g=-Math.floor(m),y=-Math.floor(u-x),_=-Math.floor(c-b),S=`${v}px ${y}px ${_}px ${g}px`;this.boundingClientRect=f,Xe(this,Bt,new IntersectionObserver(E=>{const[D]=E,{intersectionRect:T}=D;(D.intersectionRatio!==1?D.intersectionRatio:ht.intersectionRatio(T,br(l)))!==1&&oe(this,er).call(this)},{threshold:Ua,rootMargin:S,root:d})),oe(this,Bt).observe(l),iu(this,Cs,pu).call(this)},hu)),this.boundingClientRect=e.getBoundingClientRect(),Xe(this,Wt,Oh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(Xe(this,Ne,document.createElement("div")),oe(this,Ne).style.background="rgba(0,0,0,0.15)",oe(this,Ne).style.position="fixed",oe(this,Ne).style.pointerEvents="none",s.body.appendChild(oe(this,Ne))),Xe(this,Jn,new IntersectionObserver(i=>{var o,a;const l=i[i.length-1],{boundingClientRect:d,isIntersecting:c}=l,{width:u,height:f}=d,h=oe(this,Wt);Xe(this,Wt,c),!(!u&&!f)&&(h&&!c?((o=oe(this,Bt))==null||o.disconnect(),this.callback(null),(a=oe(this,St))==null||a.disconnect(),Xe(this,St,void 0),oe(this,Ne)&&(oe(this,Ne).style.visibility="hidden")):oe(this,er).call(this),c&&!oe(this,St)&&(Xe(this,St,new Ch(oe(this,er))),oe(this,St).observe(e)))},{threshold:Ua,root:s})),oe(this,Wt)&&!n.skipInitial&&this.callback(this.boundingClientRect),oe(this,Jn).observe(e)}};Wt=new WeakMap;Es=new WeakMap;St=new WeakMap;Bt=new WeakMap;Jn=new WeakMap;Ne=new WeakMap;fr=new WeakMap;er=new WeakMap;Cs=new WeakSet;pu=function(){oe(this,fr)||(iu(this,Cs,gu).call(this),!Th(this.boundingClientRect,oe(this,Es))&&(this.callback(this.boundingClientRect),Xe(this,Es,this.boundingClientRect)))};gu=function(){if(oe(this,Ne)){const{top:e,left:t,width:n,height:r}=br(this.element);oe(this,Ne).style.overflow="hidden",oe(this,Ne).style.visibility="visible",oe(this,Ne).style.top=`${Math.floor(e)}px`,oe(this,Ne).style.left=`${Math.floor(t)}px`,oe(this,Ne).style.width=`${Math.floor(n)}px`,oe(this,Ne).style.height=`${Math.floor(r)}px`}};var Hr=new WeakMap,Xr=new WeakMap;function Ih(e,t){let n=Hr.get(e);return n||(n={disconnect:new mu(e,s=>{const i=Hr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Hr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Hr.delete(e),n.disconnect())}}function Ah(e,t){const n=new Set;for(const r of e){const s=Ih(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Dh(e,t){var n;const r=e.ownerDocument;if(!Xr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(d=>d(l)),{capture:!0,passive:!0,signal:o.signal}),Xr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Xr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Xr.delete(r))})}var tr,nr,gs,Yi,Mh=class{constructor(e,t,n){this.callback=t,Ue(this,tr),Ue(this,nr,!1),Ue(this,gs),Ue(this,Yi,fu(o=>{if(!oe(this,nr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of oe(this,gs))if(o.target.contains(a)){this.callback(oe(this,tr).boundingClientRect);break}}},hu));const r=Sh(e),s=Ah(r,t),i=Dh(e,oe(this,Yi));Xe(this,gs,r),Xe(this,tr,new mu(e,t,n)),this.disconnect=()=>{oe(this,nr)||(Xe(this,nr,!0),s(),i(),oe(this,tr).disconnect())}}};tr=new WeakMap;nr=new WeakMap;gs=new WeakMap;Yi=new WeakMap;function Zi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function yn(e){try{Zi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ha(e){return!lu||!e?!1:e===Rn(e).scrollingElement}function vu(e){var t,n;const r=Ze(e),s=Ha(e)?yh(e):Xs(e),i=r.visualViewport,o=Ha(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},l=a.current.y<=0,d=a.current.x<=0,c=a.current.y>=a.max.y,u=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:d,isBottom:c,isRight:u}}function Ph(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=vu(e),{x:a,y:l}=t??{x:0,y:0},d=!n&&o.current.y+l>0,c=!r&&o.current.y+l<o.max.y,u=!s&&o.current.x+a>0,f=!i&&o.current.x+a<o.max.x;return{top:d,bottom:c,left:u,right:f,x:u||f,y:d||c}}var ra=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Is=new ra(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),jh=new ra(e=>setTimeout(e,50)),As=new Map,Rh=As.clear.bind(As);function mt(e,t=!1){if(!t)return Xa(e);let n=As.get(e);return n||(n=Xa(e),As.set(e,n),jh.schedule(Rh),n)}function Xa(e){return Ze(e).getComputedStyle(e)}function Lh(e,t=mt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Nh(e,t=mt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Fh={excludeElement:!0,escapeShadowDOM:!0};function Qi(e,t=Fh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(Jo(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ta(a))return o(a.host);if(!Dt(a))return au(a)?o(a.parentElement):i;if(i.has(a))return i;const l=mt(a,!0);if(r&&a===e||Nh(a,l)&&i.add(a),Lh(a,l)){const{scrollingElement:d}=a.ownerDocument;return d&&i.add(d),i}return o(a.parentNode)}return e?o(e):i}function $n(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Sn(e);for(;r;){if(r===t)return n;const s=Xs(r),{x:i,y:o}=zh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=Sn(r)}return n}function zh(e,t=Xs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Dt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=mt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Wh(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function xr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Ys(e){var t,n,r,s,i,o,a,l,d;const{scale:c,transform:u,translate:f}=e,h=Wh(c),p=xr(f),m=Bh(u);if(!m&&!h&&!p)return null;const b={x:(t=h?.x)!=null?t:1,y:(n=h?.y)!=null?n:1},x={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},v={x:(i=m?.x)!=null?i:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(l=m?.scaleY)!=null?l:1};return{x:x.x+v.x,y:x.y+v.y,z:(d=p?.z)!=null?d:0,scaleX:b.x*v.scaleX,scaleY:b.y*v.scaleY}}function Bh(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var et=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(et||{}),Gh={x:.2,y:.2},qh={x:10,y:10};function Kh(e,t,n,r=25,s=Gh,i=qh){const{x:o,y:a}=t,{rect:l,isTop:d,isBottom:c,isLeft:u,isRight:f}=vu(e),h=$n(e),p=mt(e,!0),m=Ys(p),b=m!==null?m?.scaleX<0:!1,x=m!==null?m?.scaleY<0:!1,v=new ht(l.left*h.scaleX+h.x,l.top*h.scaleY+h.y,l.width*h.scaleX,l.height*h.scaleY),g={x:0,y:0},y={x:0,y:0},_={height:v.height*s.y,width:v.width*s.x};return _.height>0&&(!d||x&&!c)&&a<=v.top+_.height&&n?.y!==1&&o>=v.left-i.x&&o<=v.right+i.x?(g.y=x?1:-1,y.y=r*Math.abs((v.top+_.height-a)/_.height)):_.height>0&&(!c||x&&!d)&&a>=v.bottom-_.height&&n?.y!==-1&&o>=v.left-i.x&&o<=v.right+i.x&&(g.y=x?-1:1,y.y=r*Math.abs((v.bottom-_.height-a)/_.height)),_.width>0&&(!f||b&&!u)&&o>=v.right-_.width&&n?.x!==-1&&a>=v.top-i.y&&a<=v.bottom+i.y?(g.x=b?-1:1,y.x=r*Math.abs((v.right-_.width-o)/_.width)):_.width>0&&(!u||b&&!f)&&o<=v.left+_.width&&n?.x!==1&&a>=v.top-i.y&&a<=v.bottom+i.y&&(g.x=b?1:-1,y.x=r*Math.abs((v.left+_.width-o)/_.width)),{direction:g,speed:y}}function yu(e,{block:t="nearest",inline:n="nearest"}={}){if(!Dt(e))return;const r=Qi(e),s=[];for(const i of r){if(!Dt(i))continue;const{top:o,left:a}=Vh(e,i);let l=o,d=a;for(const c of s)l-=c.scrollTop,d-=c.scrollLeft;if(t!=="none"){const c=l<i.scrollTop,u=l+e.offsetHeight>i.scrollTop+i.clientHeight;c!==u&&(t==="center"?i.scrollTop=l-i.clientHeight/2+e.offsetHeight/2:c?i.scrollTop=l:i.scrollTop=l+e.offsetHeight-i.clientHeight)}if(n!=="none"){const c=d<i.scrollLeft,u=d+e.offsetWidth>i.scrollLeft+i.clientWidth;c!==u&&(n==="center"?i.scrollLeft=d-i.clientWidth/2+e.offsetWidth/2:c?i.scrollLeft=d:i.scrollLeft=d+e.offsetWidth-i.clientWidth)}s.push(i)}}function Ya(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Dt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Vh(e,t){const n=Ya(e),r=Ya(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Uh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),l=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:d,height:c,top:l,right:a+d,bottom:l+c,left:a}}function Hh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),l=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:d,height:c,top:l,right:a+d,bottom:l+c,left:a}}function bu({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Za(e,t=mt(e).translate,n=!0){if(n){const r=ou(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=xr(s);if(i)return i}}}if(t){const r=xr(t);if(r)return r}return{x:0,y:0,z:0}}var Xh=new ra(e=>setTimeout(e,0)),hr=new Map,Yh=hr.clear.bind(hr);function Zh(e){const t=e.ownerDocument;let n=hr.get(t);if(n)return n;n=t.getAnimations(),hr.set(t,n),Xh.schedule(Yh);const r=n.filter(s=>Hs(s.effect)&&s.effect.target===e);return hr.set(e,r),n}function Qh(e,t){const n=Zh(e).filter(r=>{var s,i;if(Hs(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(l=>{for(const d of t.properties)if(l[d])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ft=class extends ht{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=$n(e),ignoreTransforms:a,getBoundingClientRect:l=Xs}=t,d=Qh(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||ea())&&_.contains(e)}),c=l(e);let{top:u,left:f,width:h,height:p}=c,m;const b=mt(e),x=Ys(b),v={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},g=Jh(e,b);d?.(),x&&(m=Hh(c,x,b.transformOrigin),(a||g)&&(u=m.top,f=m.left,h=m.width,p=m.height));const y={width:(s=m?.width)!=null?s:h,height:(i=m?.height)!=null?i:p};if(g&&!a&&m){const _=Uh(m,g,b.transformOrigin);u=_.top,f=_.left,h=_.width,p=_.height,v.x=g.scaleX,v.y=g.scaleY}o&&(a||(f*=o.scaleX,h*=o.scaleX,u*=o.scaleY,p*=o.scaleY),f+=o.x,u+=o.y),super(f,u,h,p),this.scale=v,this.intrinsicWidth=y.width,this.intrinsicHeight=y.height}};function Jh(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=Hs(a.effect)?a.effect.getKeyframes():[],d=l[l.length-1];if(!d)continue;const{transform:c,translate:u,scale:f}=d;typeof c=="string"&&c&&(r=c,o=!0),typeof u=="string"&&u&&(s=u,o=!0),typeof f=="string"&&f&&(i=f,o=!0)}return o?Ys({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function pr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var ep=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(pr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(pr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(pr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ht(e){return e?e instanceof Ze(e).Element||jr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function wr(e){if(!e)return!1;const{KeyboardEvent:t}=Ze(e.target);return e instanceof t}function tp(e){if(!e)return!1;const{PointerEvent:t}=Ze(e.target);return e instanceof t}function np(e){if(!Ht(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||rp(e)}function rp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var pi={};function Ji(e){const t=pi[e]==null?0:pi[e]+1;return pi[e]=t,`${e}-${t}`}var sa=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Je.distance(t.shape.center,n);return{id:r,value:1/s,type:jn.PointerIntersection,priority:Pn.High}}return null},sp=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=Je.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:jn.ShapeIntersection,priority:Pn.Normal}}return null},xu=e=>{var t;return(t=sa(e))!=null?t:sp(e)},ip=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?ht.from(r.current.boundingRectangle).corners:void 0,a=ht.from(n.shape.boundingRectangle).corners.reduce((l,d,c)=>{var u;return l+Je.distance(Je.from(d),(u=i?.[c])!=null?u:s.current)},0)/4;return{id:n.id,value:1/a,type:jn.Collision,priority:Pn.Normal}},op=Object.create,ia=Object.defineProperty,ap=Object.defineProperties,lp=Object.getOwnPropertyDescriptor,cp=Object.getOwnPropertyDescriptors,Ds=Object.getOwnPropertySymbols,wu=Object.prototype.hasOwnProperty,_u=Object.prototype.propertyIsEnumerable,ku=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ln=e=>{throw TypeError(e)},eo=(e,t,n)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_r=(e,t)=>{for(var n in t||(t={}))wu.call(t,n)&&eo(e,n,t[n]);if(Ds)for(var n of Ds(t))_u.call(t,n)&&eo(e,n,t[n]);return e},oa=(e,t)=>ap(e,cp(t)),Qa=(e,t)=>ia(e,"name",{value:t,configurable:!0}),Su=(e,t)=>{var n={};for(var r in e)wu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ds)for(var r of Ds(e))t.indexOf(r)<0&&_u.call(e,r)&&(n[r]=e[r]);return n},Nn=e=>{var t;return[,,,op((t=e?.[ku("metadata")])!=null?t:null)]},$u=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Ln("Function expected"):e,up=(e,t,n,r,s)=>({kind:$u[e],name:t,metadata:r,addInitializer:i=>n._?Ln("Already initialized"):s.push(rr(i||null))}),Jt=(e,t)=>eo(t,ku("metadata"),e[3]),Pe=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},st=(e,t,n,r,s,i)=>{var o,a,l,d,c,u=t&7,f=!!(t&8),h=!!(t&16),p=u>3?e.length+1:u?f?1:2:0,m=$u[u+5],b=u>3&&(e[p-1]=[]),x=e[p]||(e[p]=[]),v=u&&(!h&&!f&&(s=s.prototype),u<5&&(u>3||!h)&&lp(u<4?s:{get[n](){return be(this,i)},set[n](y){return Ke(this,i,y)}},n));u?h&&u<4&&Qa(i,(u>2?"set ":u>1?"get ":"")+n):Qa(s,n);for(var g=r.length-1;g>=0;g--)d=up(u,n,l={},e[3],x),u&&(d.static=f,d.private=h,c=d.access={has:h?y=>dp(s,y):y=>n in y},u^3&&(c.get=h?y=>(u^1?be:Xt)(y,s,u^4?i:v.get):y=>y[n]),u>2&&(c.set=h?(y,_)=>Ke(y,s,_,u^4?i:v.set):(y,_)=>y[n]=_)),a=(0,r[g])(u?u<4?h?i:v[m]:u>4?void 0:{get:v.get,set:v.set}:s,d),l._=1,u^4||a===void 0?rr(a)&&(u>4?b.unshift(a):u?h?i=a:v[m]=a:s=a):typeof a!="object"||a===null?Ln("Object expected"):(rr(o=a.get)&&(v.get=o),rr(o=a.set)&&(v.set=o),rr(o=a.init)&&b.unshift(o));return u||Jt(e,s),v&&ia(s,n,v),h?u^4?i:v:s},aa=(e,t,n)=>t.has(e)||Ln("Cannot "+n),dp=(e,t)=>Object(t)!==t?Ln('Cannot use the "in" operator on this value'):e.has(t),be=(e,t,n)=>(aa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ie=(e,t,n)=>t.has(e)?Ln("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ke=(e,t,n,r)=>(aa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Xt=(e,t,n)=>(aa(e,t,"access private method"),n),Ja={role:"button",roleDescription:"draggable"},fp="dnd-kit-description",hp="dnd-kit-announcement",pp={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},gp={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function mp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function vp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function yp(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var bp=["dragover","dragmove"],xp=class extends We{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=fp,announcement:s=hp}={},announcements:i=gp,screenReaderInstructions:o=pp,debounce:a=500}=t??{},l=n?`${r}-${n}`:Ji(r),d=n?`${s}-${n}`:Ji(s);let c,u,f,h;const p=(_=h)=>{!f||!_||f?.nodeValue!==_&&(f.nodeValue=_)},m=()=>Is.schedule(p),b=wp(m,a),x=Object.entries(i).map(([_,S])=>this.manager.monitor.addEventListener(_,(E,D)=>{const T=f;if(!T)return;const A=S?.(E,D);A&&T.nodeValue!==A&&(h=A,bp.includes(_)?b():(m(),b.cancel()))})),v=()=>{let _=[];c?.isConnected||(c=vp(l,o.draggable),_.push(c)),u?.isConnected||(u=yp(d),f=document.createTextNode(""),u.appendChild(f),_.push(u)),_.length>0&&document.body.append(..._)},g=new Set;function y(){for(const _ of g)_()}this.registerEffect(()=>{var _;g.clear();for(const S of this.manager.registry.draggables.value){const E=(_=S.handle)!=null?_:S.element;if(E){(!c||!u)&&g.add(v),(!mp(E)||ea())&&!E.hasAttribute("tabindex")&&g.add(()=>E.setAttribute("tabindex","0")),!E.hasAttribute("role")&&E.tagName.toLowerCase()!=="button"&&g.add(()=>E.setAttribute("role",Ja.role)),E.hasAttribute("aria-roledescription")||g.add(()=>E.setAttribute("aria-roledescription",Ja.roleDescription)),E.hasAttribute("aria-describedby")||g.add(()=>E.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const A=String(S.isDragging);E.getAttribute(T)!==A&&g.add(()=>E.setAttribute(T,A))}const D=String(S.disabled);E.getAttribute("aria-disabled")!==D&&g.add(()=>E.setAttribute("aria-disabled",D))}}g.size>0&&Is.schedule(y)}),this.destroy=()=>{super.destroy(),c?.remove(),u?.remove(),x.forEach(_=>_())}}};function wp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Ms=new Map,Tu,Ou,Eu,Cu,to,gr,yt,la,Tn,Iu,Au,Du,Mu,Mt=class extends(to=Pr,Cu=[he],Eu=[Ee],Ou=[Ee],Tu=[Ee],to){constructor(t,n){super(t,n),Pe(yt,5,this),Ie(this,Tn),Ie(this,gr,new Set),Ie(this,la,Pe(yt,8,this,new Set)),Pe(yt,11,this),this.registerEffect(Xt(this,Tn,Iu))}register(t){return be(this,gr).add(t),()=>{be(this,gr).delete(t)}}addRoot(t){return fe(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{fe(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Os((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};yt=Nn(to);gr=new WeakMap;la=new WeakMap;Tn=new WeakSet;Iu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of be(this,gr))t.push(Xt(this,Tn,Au).call(this,n,r));return()=>{for(const n of t)n()}};Au=function(e,t){let n=Ms.get(e);n||(n=new Map,Ms.set(e,n));let r=n.get(t);if(!r){const i=Jo(e)?Xt(this,Tn,Du).call(this,e,n,t):Xt(this,Tn,Mu).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Du=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const l of a)for(const d of Array.from(l.removedNodes))if(d===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Ms.delete(e)}}};Mu=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(ta(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Ms.delete(e)}}};st(yt,4,"additionalRoots",Cu,Mt,la);st(yt,2,"sourceRoot",Eu,Mt);st(yt,2,"targetRoot",Ou,Mt);st(yt,2,"roots",Tu,Mt);Jt(yt,Mt);Mt.configure=Mr(Mt);var Zs=Mt,_p=class extends We{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Zs),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Rr="data-dnd-",no=`${Rr}dropping`,Le="--dnd-",dt=`${Rr}dragging`,Ps=`${Rr}placeholder`,kp=[dt,Ps,"popover","aria-pressed","aria-grabbing"],Sp=["view-transition-name"],$p=`
9
- :is(:root,:host) [${dt}] {
8
+ `)}var cd=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 Dn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Ph(e){const t=new Set;let n=Dn(e);for(;n;)t.add(n),n=Dn(n);return t}function Rh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function dd(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Rh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Ah(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 Lh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=Cr(e,t);return n>0&&r>0}var Bh=od?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ys,Fh=class extends Bh{constructor(e){super(t=>{if(!K(this,ys)){nt(this,ys,!0);return}e(t,this)}),Je(this,ys,!1)}};ys=new WeakMap;var Ka=Array.from({length:100},(e,t)=>t/100),ud=75,Gt,Ps,Ot,Vt,ir,Ve,wr,or,Rs,fd,hd,pd=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,wr,!0),(i=K(this,Ot))==null||i.disconnect(),(o=K(this,Vt))==null||o.disconnect(),K(this,ir).disconnect(),(a=K(this,Ve))==null||a.remove()},Je(this,Gt,!0),Je(this,Ps),Je(this,Ot),Je(this,Vt),Je(this,ir),Je(this,Ve),Je(this,wr,!1),Je(this,or,dd(()=>{var i,o,a;const{element:c}=this;if((i=K(this,Vt))==null||i.disconnect(),K(this,wr)||!K(this,Gt)||!c.isConnected)return;const f=(o=c.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:l}=(a=f.defaultView)!=null?a:window,u=c.getBoundingClientRect(),h=Cr(c,u),{top:p,left: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,Vt,new IntersectionObserver(C=>{const[j]=C,{intersectionRect:D}=j;(j.intersectionRatio!==1?j.intersectionRatio:bt.intersectionRatio(D,Cr(c)))!==1&&K(this,or).call(this)},{threshold:Ka,rootMargin:T,root:f})),K(this,Vt).observe(c),rd(this,Rs,fd).call(this)},ud)),this.boundingClientRect=e.getBoundingClientRect(),nt(this,Gt,Lh(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")),K(this,Ve).style.background="rgba(0,0,0,0.15)",K(this,Ve).style.position="fixed",K(this,Ve).style.pointerEvents="none",s.body.appendChild(K(this,Ve))),nt(this,ir,new IntersectionObserver(i=>{var o,a;const c=i[i.length-1],{boundingClientRect:f,isIntersecting:d}=c,{width:l,height:u}=f,h=K(this,Gt);nt(this,Gt,d),!(!l&&!u)&&(h&&!d?((o=K(this,Vt))==null||o.disconnect(),this.callback(null),(a=K(this,Ot))==null||a.disconnect(),nt(this,Ot,void 0),K(this,Ve)&&(K(this,Ve).style.visibility="hidden")):K(this,or).call(this),d&&!K(this,Ot)&&(nt(this,Ot,new Fh(K(this,or))),K(this,Ot).observe(e)))},{threshold:Ka,root:s})),K(this,Gt)&&!n.skipInitial&&this.callback(this.boundingClientRect),K(this,ir).observe(e)}};Gt=new WeakMap;Ps=new WeakMap;Ot=new WeakMap;Vt=new WeakMap;ir=new WeakMap;Ve=new WeakMap;wr=new WeakMap;or=new WeakMap;Rs=new WeakSet;fd=function(){K(this,wr)||(rd(this,Rs,hd).call(this),!Ah(this.boundingClientRect,K(this,Ps))&&(this.callback(this.boundingClientRect),nt(this,Ps,this.boundingClientRect)))};hd=function(){if(K(this,Ve)){const{top:e,left:t,width:n,height:r}=Cr(this.element);K(this,Ve).style.overflow="hidden",K(this,Ve).style.visibility="visible",K(this,Ve).style.top=`${Math.floor(e)}px`,K(this,Ve).style.left=`${Math.floor(t)}px`,K(this,Ve).style.width=`${Math.floor(n)}px`,K(this,Ve).style.height=`${Math.floor(r)}px`}};var ns=new WeakMap,rs=new WeakMap;function zh(e,t){let n=ns.get(e);return n||(n={disconnect:new pd(e,s=>{const i=ns.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),ns.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(ns.delete(e),n.disconnect())}}function Wh(e,t){const n=new Set;for(const r of e){const s=zh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Nh(e,t){var n;const r=e.ownerDocument;if(!rs.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}),rs.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=rs.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),rs.delete(r))})}var ar,lr,bs,no,Gh=class{constructor(e,t,n){this.callback=t,Je(this,ar),Je(this,lr,!1),Je(this,bs),Je(this,no,dd(o=>{if(!K(this,lr)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of K(this,bs))if(o.target.contains(a)){this.callback(K(this,ar).boundingClientRect);break}}},ud));const r=Ph(e),s=Wh(r,t),i=Nh(e,K(this,no));nt(this,bs,r),nt(this,ar,new pd(e,t,n)),this.disconnect=()=>{K(this,lr)||(nt(this,lr,!0),s(),i(),K(this,ar).disconnect())}}};ar=new WeakMap;lr=new WeakMap;bs=new WeakMap;no=new WeakMap;function ro(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Sn(e){try{ro(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ya(e){return!od||!e?!1:e===Nn(e).scrollingElement}function gd(e){var t,n;const r=st(e),s=Ya(e)?Ch(e):ni(e),i=r.visualViewport,o=Ya(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 Vh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=gd(e),{x:a,y:c}=t??{x:0,y:0},f=!n&&o.current.y+c>0,d=!r&&o.current.y+c<o.max.y,l=!s&&o.current.x+a>0,u=!i&&o.current.x+a<o.max.x;return{top:f,bottom:d,left:l,right:u,x:l||u,y:f||d}}var aa=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},As=new aa(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Uh=new aa(e=>setTimeout(e,50)),Ls=new Map,Hh=Ls.clear.bind(Ls);function _t(e,t=!1){if(!t)return Xa(e);let n=Ls.get(e);return n||(n=Xa(e),Ls.set(e,n),Uh.schedule(Hh),n)}function Xa(e){return st(e).getComputedStyle(e)}function qh(e,t=_t(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Kh(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 Yh={excludeElement:!0,escapeShadowDOM:!0};function so(e,t=Yh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(ra(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&ia(a))return o(a.host);if(!At(a))return id(a)?o(a.parentElement):i;if(i.has(a))return i;const c=_t(a,!0);if(r&&a===e||Kh(a,c)&&i.add(a),qh(a,c)){const{scrollingElement:f}=a.ownerDocument;return f&&i.add(f),i}return o(a.parentNode)}return e?o(e):i}function Mn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Dn(e);for(;r;){if(r===t)return n;const s=ni(r),{x:i,y:o}=Xh(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=Dn(r)}return n}function Xh(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 Qh(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Or(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function ri(e){var t,n,r,s,i,o,a,c,f;const{scale:d,transform:l,translate:u}=e,h=Qh(d),p=Or(u),v=Zh(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 Zh(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||{}),Jh={x:.2,y:.2},ep={x:10,y:10};function tp(e,t,n,r=25,s=Jh,i=ep){const{x:o,y:a}=t,{rect:c,isTop:f,isBottom:d,isLeft:l,isRight:u}=gd(e),h=Mn(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 md(e,{block:t="nearest",inline:n="nearest"}={}){if(!At(e))return;const r=so(e),s=[];for(const i of r){if(!At(i))continue;const{top:o,left:a}=np(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 Qa(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 np(e,t){const n=Qa(e),r=Qa(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function rp(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 sp(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 vd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Za(e,t=_t(e).translate,n=!0){if(n){const r=sd(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=Or(s);if(i)return i}}}if(t){const r=Or(t);if(r)return r}return{x:0,y:0,z:0}}var ip=new aa(e=>setTimeout(e,0)),_r=new Map,op=_r.clear.bind(_r);function ap(e){const t=e.ownerDocument;let n=_r.get(t);if(n)return n;n=t.getAnimations(),_r.set(t,n),ip.schedule(op);const r=n.filter(s=>ti(s.effect)&&s.effect.target===e);return _r.set(e,r),n}function lp(e,t){const n=ap(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=Mn(e),ignoreTransforms:a,getBoundingClientRect:c=ni}=t,f=lp(e,{properties:["transform","translate","scale","width","height"],isValidTarget:b=>(b!==e||sa())&&b.contains(e)}),d=c(e);let{top:l,left:u,width:h,height:p}=d,v;const x=_t(e),_=ri(x),g={x:(n=_?.scaleX)!=null?n:1,y:(r=_?.scaleY)!=null?r:1},y=cp(e,x);f?.(),_&&(v=sp(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=rp(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 cp(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 kr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var dp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(kr(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(kr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(kr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Qt(e){return e?e instanceof st(e).Element||Wr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Dr(e){if(!e)return!1;const{KeyboardEvent:t}=st(e.target);return e instanceof t}function up(e){if(!e)return!1;const{PointerEvent:t}=st(e.target);return e instanceof t}function fp(e){if(!Qt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||hp(e)}function hp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var bi={};function io(e){const t=bi[e]==null?0:bi[e]+1;return bi[e]=t,`${e}-${t}`}var la=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=ot.distance(t.shape.center,n);return{id:r,value:1/s,type:Wn.PointerIntersection,priority:zn.High}}return null},pp=({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:Wn.ShapeIntersection,priority:zn.Normal}}return null},yd=e=>{var t;return(t=la(e))!=null?t:pp(e)},gp=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:Wn.Collision,priority:zn.Normal}},mp=Object.create,ca=Object.defineProperty,vp=Object.defineProperties,yp=Object.getOwnPropertyDescriptor,bp=Object.getOwnPropertyDescriptors,Bs=Object.getOwnPropertySymbols,bd=Object.prototype.hasOwnProperty,xd=Object.prototype.propertyIsEnumerable,wd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Gn=e=>{throw TypeError(e)},oo=(e,t,n)=>t in e?ca(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mr=(e,t)=>{for(var n in t||(t={}))bd.call(t,n)&&oo(e,n,t[n]);if(Bs)for(var n of Bs(t))xd.call(t,n)&&oo(e,n,t[n]);return e},da=(e,t)=>vp(e,bp(t)),Ja=(e,t)=>ca(e,"name",{value:t,configurable:!0}),_d=(e,t)=>{var n={};for(var r in e)bd.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&&xd.call(e,r)&&(n[r]=e[r]);return n},Vn=e=>{var t;return[,,,mp((t=e?.[wd("metadata")])!=null?t:null)]},kd=["class","method","getter","setter","accessor","field","value","get","set"],cr=e=>e!==void 0&&typeof e!="function"?Gn("Function expected"):e,xp=(e,t,n,r,s)=>({kind:kd[e],name:t,metadata:r,addInitializer:i=>n._?Gn("Already initialized"):s.push(cr(i||null))}),nn=(e,t)=>oo(t,wd("metadata"),e[3]),Fe=(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=kd[l+5],x=l>3&&(e[p-1]=[]),_=e[p]||(e[p]=[]),g=l&&(!h&&!u&&(s=s.prototype),l<5&&(l>3||!h)&&yp(l<4?s:{get[n](){return me(this,i)},set[n](w){return Qe(this,i,w)}},n));l?h&&l<4&&Ja(i,(l>2?"set ":l>1?"get ":"")+n):Ja(s,n);for(var y=r.length-1;y>=0;y--)f=xp(l,n,c={},e[3],_),l&&(f.static=u,f.private=h,d=f.access={has:h?w=>wp(s,w):w=>n in w},l^3&&(d.get=h?w=>(l^1?me: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?cr(a)&&(l>4?x.unshift(a):l?h?i=a:g[v]=a:s=a):typeof a!="object"||a===null?Gn("Object expected"):(cr(o=a.get)&&(g.get=o),cr(o=a.set)&&(g.set=o),cr(o=a.init)&&x.unshift(o));return l||nn(e,s),g&&ca(s,n,g),h?l^4?i:g:s},ua=(e,t,n)=>t.has(e)||Gn("Cannot "+n),wp=(e,t)=>Object(t)!==t?Gn('Cannot use the "in" operator on this value'):e.has(t),me=(e,t,n)=>(ua(e,t,"read from private field"),n?n.call(e):t.get(e)),je=(e,t,n)=>t.has(e)?Gn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Qe=(e,t,n,r)=>(ua(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Zt=(e,t,n)=>(ua(e,t,"access private method"),n),el={role:"button",roleDescription:"draggable"},_p="dnd-kit-description",kp="dnd-kit-announcement",Sp={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."},$p={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 Tp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Ep(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Cp(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 Op=["dragover","dragmove"],Dp=class extends Ke{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=_p,announcement:s=kp}={},announcements:i=$p,screenReaderInstructions:o=Sp,debounce:a=500}=t??{},c=n?`${r}-${n}`:io(r),f=n?`${s}-${n}`:io(s);let d,l,u,h;const p=(b=h)=>{!u||!b||u?.nodeValue!==b&&(u.nodeValue=b)},v=()=>As.schedule(p),x=Mp(v,a),_=Object.entries(i).map(([b,T])=>this.manager.monitor.addEventListener(b,(C,j)=>{const D=u;if(!D)return;const E=T?.(C,j);E&&D.nodeValue!==E&&(h=E,Op.includes(b)?x():(v(),x.cancel()))})),g=()=>{let b=[];d?.isConnected||(d=Ep(c,o.draggable),b.push(d)),l?.isConnected||(l=Cp(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),(!Tp(C)||sa())&&!C.hasAttribute("tabindex")&&y.add(()=>C.setAttribute("tabindex","0")),!C.hasAttribute("role")&&C.tagName.toLowerCase()!=="button"&&y.add(()=>C.setAttribute("role",el.role)),C.hasAttribute("aria-roledescription")||y.add(()=>C.setAttribute("aria-roledescription",el.roleDescription)),C.hasAttribute("aria-describedby")||y.add(()=>C.setAttribute("aria-describedby",c));for(const D of["aria-pressed","aria-grabbed"]){const E=String(T.isDragging);C.getAttribute(D)!==E&&y.add(()=>C.setAttribute(D,E))}const j=String(T.disabled);C.getAttribute("aria-disabled")!==j&&y.add(()=>C.setAttribute("aria-disabled",j))}}y.size>0&&As.schedule(w)}),this.destroy=()=>{super.destroy(),d?.remove(),l?.remove(),_.forEach(b=>b())}}};function Mp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Fs=new Map,Sd,$d,Td,Ed,ao,Sr,St,fa,jn,Cd,Od,Dd,Md,Lt=class extends(ao=zr,Ed=[se],Td=[Oe],$d=[Oe],Sd=[Oe],ao){constructor(t,n){super(t,n),Fe(St,5,this),je(this,jn),je(this,Sr,new Set),je(this,fa,Fe(St,8,this,new Set)),Fe(St,11,this),this.registerEffect(Zt(this,jn,Cd))}register(t){return me(this,Sr).add(t),()=>{me(this,Sr).delete(t)}}addRoot(t){return re(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{re(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return Is((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return Is((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=Vn(ao);Sr=new WeakMap;fa=new WeakMap;jn=new WeakSet;Cd=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of me(this,Sr))t.push(Zt(this,jn,Od).call(this,n,r));return()=>{for(const n of t)n()}};Od=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=ra(e)?Zt(this,jn,Dd).call(this,e,n,t):Zt(this,jn,Md).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())}};Dd=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)}}};Md=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(ia(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Fs.delete(e)}}};ut(St,4,"additionalRoots",Ed,Lt,fa);ut(St,2,"sourceRoot",Td,Lt);ut(St,2,"targetRoot",$d,Lt);ut(St,2,"roots",Sd,Lt);nn(St,Lt);Lt.configure=Fr(Lt);var si=Lt,jp=class extends Ke{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()}}}},Nr="data-dnd-",lo=`${Nr}dropping`,Ge="--dnd-",vt=`${Nr}dragging`,zs=`${Nr}placeholder`,Ip=[vt,zs,"popover","aria-pressed","aria-grabbing"],Pp=["view-transition-name"],Rp=`
9
+ :is(:root,:host) [${vt}] {
10
10
  position: fixed !important;
11
11
  pointer-events: none !important;
12
12
  touch-action: none;
13
13
  z-index: calc(infinity);
14
14
  will-change: translate;
15
- top: var(${Le}top, 0px) !important;
16
- left: var(${Le}left, 0px) !important;
15
+ top: var(${Ge}top, 0px) !important;
16
+ left: var(${Ge}left, 0px) !important;
17
17
  right: unset !important;
18
18
  bottom: unset !important;
19
- width: var(${Le}width, auto);
20
- max-width: var(${Le}width, auto);
21
- height: var(${Le}height, auto);
22
- max-height: var(${Le}height, auto);
23
- transform: var(${Le}transform, none) !important;
24
- transition: var(${Le}transition) !important;
19
+ width: var(${Ge}width, auto);
20
+ max-width: var(${Ge}width, auto);
21
+ height: var(${Ge}height, auto);
22
+ max-height: var(${Ge}height, auto);
23
+ transform: var(${Ge}transform, none) !important;
24
+ transition: var(${Ge}transition) !important;
25
25
  }
26
26
 
27
- :is(:root,:host) [${Ps}] {
27
+ :is(:root,:host) [${zs}] {
28
28
  transition: none;
29
29
  }
30
30
 
31
- :is(:root,:host) [${Ps}='hidden'] {
31
+ :is(:root,:host) [${zs}='hidden'] {
32
32
  visibility: hidden;
33
33
  }
34
34
 
35
- [${dt}] * {
35
+ [${vt}] * {
36
36
  pointer-events: none !important;
37
37
  }
38
38
 
39
- [${dt}]:not([${no}]) {
40
- translate: var(${Le}translate) !important;
39
+ [${vt}]:not([${lo}]) {
40
+ translate: var(${Ge}translate) !important;
41
41
  }
42
42
 
43
- [${dt}][style*='${Le}scale'] {
44
- scale: var(${Le}scale) !important;
45
- transform-origin: var(${Le}transform-origin) !important;
43
+ [${vt}][style*='${Ge}scale'] {
44
+ scale: var(${Ge}scale) !important;
45
+ transform-origin: var(${Ge}transform-origin) !important;
46
46
  }
47
47
 
48
48
  @layer dnd-kit {
49
- :where([${dt}][popover]) {
49
+ :where([${vt}][popover]) {
50
50
  overflow: visible;
51
51
  background: unset;
52
52
  border: unset;
@@ -60,136 +60,84 @@
60
60
  }
61
61
  }
62
62
  }
63
- [${dt}]::backdrop, [${Rr}overlay]:not([${dt}]) {
63
+ [${vt}]::backdrop, [${Nr}overlay]:not([${vt}]) {
64
64
  display: none;
65
65
  visibility: hidden;
66
66
  }
67
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Tp(e,t="hidden"){return fe(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Op(n,r.registry.droppables),i=[],o=wh(n),{remove:a}=o;return Ep(s,o,i),Cp(o,t),o.remove=()=>{i.forEach(l=>l()),a.call(o)},o})}function Op(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Rr}${Ji("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Ep(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),Xi.set(a,o),n.push(()=>{Xi.delete(a),r.proxy=void 0})}}function Cp(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Ps,t)}function Pu(e,t){return e===t?!0:Sn(e)===Sn(t)}function el(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ht(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>yn(t))}function ro(e){return e.tagName==="TR"}function Ip(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||kp.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(pr(e)&&pr(t)){const d=e.style;for(const c of Array.from(t.style))d.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(d)){if(Sp.includes(c)||c.startsWith(Le))continue;const u=d.getPropertyValue(c);t.style.setProperty(c,u)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Ap(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),yn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),yn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),yn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Dp(e){return new ResizeObserver(()=>{var t,n,r;const s=new ft(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,l=cu();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),ro(e.element)&&ro(e.placeholder)){const m=Array.from(e.element.cells),b=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(x=>x.style.width));for(const[x,v]of m.entries()){const g=b[x];v.style.width=`${g.getBoundingClientRect().width}px`}}const d=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+o+l.x+d.x,u=e.top+a+l.y+d.y,f=s.width-e.widthOffset,h=s.height-e.heightOffset,p=e.frameTransform;e.dragOperation.shape=new ht(c*p.scaleX+p.x,u*p.scaleY+p.y,f*p.scaleX,h*p.scaleY)})}var Mp=250,Pp="ease";function jp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const v=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(v).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Mp,easing:a=Pp}=i??{};yn(e.feedbackElement);const[,l]=(t=ou(e.feedbackElement,v=>"translate"in v))!=null?t:[];l?.pause();const d=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Pu(e.feedbackElement,d)?null:void 0},u=new ft(e.feedbackElement,c),f=(r=xr(mt(e.feedbackElement).translate))!=null?r:e.translate,h=new ft(d,c),p=ht.delta(u,h,e.alignment),m={x:f.x-p.x,y:f.y-p.y},b=Math.round(u.intrinsicHeight)!==Math.round(h.intrinsicHeight)?{minHeight:[`${u.intrinsicHeight}px`,`${h.intrinsicHeight}px`],maxHeight:[`${u.intrinsicHeight}px`,`${h.intrinsicHeight}px`]}:{},x=Math.round(u.intrinsicWidth)!==Math.round(h.intrinsicWidth)?{minWidth:[`${u.intrinsicWidth}px`,`${h.intrinsicWidth}px`],maxWidth:[`${u.intrinsicWidth}px`,`${h.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Le),e.feedbackElement.setAttribute(no,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),bu({element:e.feedbackElement,keyframes:oa(_r(_r({},b),x),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:na(Ze(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(no),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var ju,so,kr,ca,ms,Ru,Lu,On=class extends(so=We,ju=[he],so){constructor(t,n){super(t,n),Ie(this,ms),Ie(this,ca,Pe(kr,8,this)),Pe(kr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Zs),s=r?.register($p);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Xt(this,ms,Ru).bind(this,r)),this.registerEffect(Xt(this,ms,Lu))}};kr=Nn(so);ca=new WeakMap;ms=new WeakSet;Ru=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Os(t);if(n)return e.addRoot(n)};Lu=function(){var e,t,n,r,s,i,o;const{state:a,manager:l,options:d}=this,{dragOperation:c}=l,{position:u,source:f,status:h}=c;if(h.idle){a.current={},a.initial={};return}if(!f)return;const{element:p}=f,m=f.pluginConfig(On),b=(t=(e=m?.feedback)!=null?e:d?.feedback)!=null?t:"default",x=typeof b=="function"?b(f,l):b;if(!p||x==="none"||!h.initialized||h.initializing)return;const{initial:v}=a,g=(n=this.overlay)!=null?n:p,y=$n(g),_=$n(p),S=!Pu(p,g),E=new ft(p,{frameTransform:S?_:null,ignoreTransforms:!S}),D={x:_.scaleX/y.scaleX,y:_.scaleY/y.scaleY};let{width:T,height:A,top:q,left:P}=E;S&&(T=T/D.x,A=A/D.y);const z=new ep(g),U=mt(p),{transition:K,translate:Z,boxSizing:J,paddingBlockStart:ie,paddingBlockEnd:de,paddingInlineStart:I,paddingInlineEnd:V,borderInlineStartWidth:B,borderInlineEndWidth:j,borderBlockStartWidth:G,borderBlockEndWidth:ne}=U,Y=K.split(",").filter(ye=>!/^\s*(transform|translate|scale)\b/.test(ye)).join(","),H=Ys(U),L=U.transform,C=x==="clone",W=J==="content-box",M=W?parseInt(I)+parseInt(V)+parseInt(B)+parseInt(j):0,ee=W?parseInt(ie)+parseInt(de)+parseInt(G)+parseInt(ne):0,X=x!=="move"&&!this.overlay?Tp(f,C?"clone":"hidden"):null,le=fe(()=>wr(l.dragOperation.activatorEvent));if(!v.translate){if(this.overlay&&H)v.translate={x:H.x,y:H.y};else if(Z!=="none"){const ye=xr(Z);ye&&(v.translate=ye)}}if(!v.transformOrigin){const ye=fe(()=>u.current),Ae=P+((r=H?.x)!=null?r:0),He=q+((s=H?.y)!=null?s:0);v.transformOrigin={x:(ye.x-Ae*y.scaleX-y.x)/(T*y.scaleX),y:(ye.y-He*y.scaleY-y.y)/(A*y.scaleY)}}const{transformOrigin:ce}=v,N=q*y.scaleY+y.y,Q=P*y.scaleX+y.x;if(!v.coordinates&&(v.coordinates={x:Q,y:N},D.x!==1||D.y!==1)){const{scaleX:ye,scaleY:Ae}=_,{x:He,y:kt}=ce;v.coordinates.x+=(T*ye-T)*He,v.coordinates.y+=(A*Ae-A)*kt}v.dimensions||(v.dimensions={width:T,height:A}),v.frameTransform||(v.frameTransform=y);const me={x:v.coordinates.x-Q,y:v.coordinates.y-N},se={width:(v.dimensions.width*v.frameTransform.scaleX-T*y.scaleX)*ce.x,height:(v.dimensions.height*v.frameTransform.scaleY-A*y.scaleY)*ce.y},te={x:me.x/y.scaleX+se.width,y:me.y/y.scaleY+se.height},R={left:P+te.x,top:q+te.y};g.setAttribute(dt,"true");const F=fe(()=>c.transform),re=(i=v.translate)!=null?i:{x:0,y:0},ue=F.x*y.scaleX+re.x,Re=F.y*y.scaleY+re.y,jt=cu();z.set({width:T-M,height:A-ee,top:R.top+jt.y,left:R.left+jt.x,translate:`${ue}px ${Re}px 0`,transform:this.overlay?"none":L,transition:Y?`${Y}, translate 0ms linear`:"translate 0ms linear",scale:S?`${D.x} ${D.y}`:"","transform-origin":`${ce.x*100}% ${ce.y*100}%`},Le),X&&(p.insertAdjacentElement("afterend",X),d?.rootElement&&(typeof d.rootElement=="function"?d.rootElement(f):d.rootElement).appendChild(p)),Zi(g)&&(g.hasAttribute("popover")||g.setAttribute("popover","manual"),yn(g),g.addEventListener("beforetoggle",el));let ut,zn,_t;const Wn=Dp({placeholder:X,element:p,feedbackElement:g,frameTransform:y,transformOrigin:ce,width:T,height:A,top:q,left:P,widthOffset:M,heightOffset:ee,delta:te,styles:z,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>ut,getSavedCellWidths:()=>_t,setSavedCellWidths:ye=>{_t=ye}}),Gr=new ft(g);fe(()=>c.shape=Gr);const Bn=Ze(g),Rt=ye=>{this.manager.actions.stop({event:ye})},Zd=na(Bn);le&&Bn.addEventListener("resize",Rt),fe(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),X&&(Wn.observe(X),ut=Ip(p,X,C),zn=Ap(p,X,g));const Ca=(o=l.dragOperation.source)==null?void 0:o.id,Qd=()=>{var ye;if(!le||Ca==null)return;const Ae=l.registry.draggables.get(Ca),He=(ye=Ae?.handle)!=null?ye:Ae?.element;Dt(He)&&He.focus()},si=()=>{ut?.disconnect(),zn?.disconnect(),Wn.disconnect(),Bn.removeEventListener("resize",Rt),Zi(g)&&(g.removeEventListener("beforetoggle",el),g.removeAttribute("popover")),g.removeAttribute(dt),z.reset();const ye=()=>{var Ae;if(_t&&ro(p)){const ii=Array.from(p.cells);for(const[qr,tn]of ii.entries())tn.style.width=(Ae=_t[qr])!=null?Ae:""}f.status="idle";const He=a.current.translate!=null,kt=c.status.dragging;X&&(!kt&&He||X.parentElement!==g.parentElement)&&g.isConnected&&X.replaceWith(g),X?.remove()};g===this.overlay?setTimeout(ye,0):ye()},Jd=d?.dropAnimation,Ia=this,ef=Ar(()=>{var ye,Ae,He;const{transform:kt,status:ii}=c;if(!(!kt.x&&!kt.y&&!a.current.translate)&&ii.dragging){const qr=(ye=v.translate)!=null?ye:{x:0,y:0},tn={x:kt.x/y.scaleX+qr.x,y:kt.y/y.scaleY+qr.y},Aa=a.current.translate,tf=fe(()=>c.modifiers),oi=fe(()=>{var qn;return(qn=c.shape)==null?void 0:qn.current}),Gn=d?.keyboardTransition,Da=le&&!Zd&&Gn!==null?`${(Ae=Gn?.duration)!=null?Ae:250}ms ${(He=Gn?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(z.set({transition:Y?`${Y}, translate ${Da}`:`translate ${Da}`,translate:`${tn.x}px ${tn.y}px 0`},Le),ut?.takeRecords(),oi&&oi!==Gr&&Aa&&!tf.length){const qn=Je.delta(tn,Aa);c.shape=ht.from(oi.boundingRectangle).translate(qn.x*y.scaleX,qn.y*y.scaleY)}else c.shape=new ft(g);a.current.translate=tn}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const ye=m?.dropAnimation!==void 0?m.dropAnimation:Ia.dropAnimation!==void 0?Ia.dropAnimation:Jd;let Ae=a.current.translate;const He=Ae!=null;if(!Ae&&p!==g&&(Ae={x:0,y:0}),!Ae||ye===null){si();return}l.renderer.rendering.then(()=>{jp({source:f,element:p,feedbackElement:g,placeholder:X,translate:Ae,moved:He,transition:K,alignment:f.alignment,styles:z,animation:ye??void 0,getElementMutationObserver:()=>ut,cleanup:si,restoreFocus:Qd})})}});return()=>{si(),ef()}};st(kr,4,"overlay",ju,On,ca);Jt(kr,On);On.configure=Mr(On);var ua=On,Kn=!0,Rp=!1,Nu,Fu,zu,Wu,Ot,da,fa;Wu=(zu=[he],et.Forward),Fu=(Nu=[he],et.Reverse);var Sr=class{constructor(){Ie(this,da,Pe(Ot,8,this,Kn)),Pe(Ot,11,this),Ie(this,fa,Pe(Ot,12,this,Kn)),Pe(Ot,15,this)}isLocked(e){return e===et.Idle?!1:e==null?this[et.Forward]===Kn&&this[et.Reverse]===Kn:this[e]===Kn}unlock(e){e!==et.Idle&&(this[e]=Rp)}};Ot=Nn(null);da=new WeakMap;fa=new WeakMap;st(Ot,4,Wu,zu,Sr,da);st(Ot,4,Fu,Nu,Sr,fa);Jt(Ot,Sr);var Lp=[et.Forward,et.Reverse],tl=class{constructor(){this.x=new Sr,this.y=new Sr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Np=class extends We{constructor(e){super(e);const t=En(new tl);let n=null;this.signal=t,rt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new tl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:nl(s.x,n.x),y:nl(s.y,n.y)},o=t.peek();Te(()=>{for(const a of mc)for(const l of Lp)i[a]===l&&o[a].unlock(l);t.value=o})}n=s})}get current(){return this.signal.peek()}};function nl(e,t){return Math.sign(e-t)}var Bu,io,$r,ha,$t,oo,Lr=class extends(io=Pr,Bu=[he],io){constructor(e){super(e),Ie(this,ha,Pe($r,8,this,!1)),Pe($r,11,this),Ie(this,$t),Ie(this,oo,()=>{if(!be(this,$t))return;const{element:i,by:o}=be(this,$t);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return Ke(this,$t,void 0),!1;const{position:d}=this.manager.dragOperation,c=d?.current;if(c){const{by:u}=i??{},f=u?{x:rl(u.x),y:rl(u.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of l){const m=Ph(p,u);if(m.x||m.y){const{speed:b,direction:x}=Kh(p,c,f,o?.acceleration,o?.threshold);if(h)for(const v of mc)h[v].isLocked(x[v])&&(b[v]=0,x[v]=0);if(x.x||x.y){const{x:v,y:g}=u??x,y=v*b.x,_=g*b.y;if(y||_){const S=(a=be(this,$t))==null?void 0:a.by;if(this.autoScrolling&&S&&(S.x&&!y||S.y&&!_))continue;return Ke(this,$t,{element:p,by:{x:y,y:_}}),Is.schedule(be(this,oo)),!0}}}}}return Ke(this,$t,void 0),!1};let t=null,n=null;const r=ji(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=uu(Os(o?.element),i.current);return a&&(t=a),a??t}),s=ji(()=>{const i=r.value,{documentElement:o}=Rn(i);if(!i||i===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const d=Qi(l,{excludeElement:!1});return n=d,d}}if(i){const a=Qi(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},it);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Np(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!wr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};$r=Nn(io);ha=new WeakMap;$t=new WeakMap;oo=new WeakMap;st($r,4,"autoScrolling",Bu,Lr,ha);Jt($r,Lr);function rl(e){return e>0?et.Forward:e<0?et.Reverse:et.Idle}var Fp=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},zp=new Fp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Wp=10,ao=class extends We{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Lr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=rt(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const d={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,d)){r.autoScrolling=!0;const u=setInterval(()=>zp.schedule(()=>r.scroll(void 0,d)),Wp);return()=>{clearInterval(u)}}else r.autoScrolling=!1}})}};ao.configure=Mr(ao);var Gu=ao,sl={capture:!0,passive:!0},sr,Bp=class extends Pr{constructor(e){super(e),Ie(this,sr),this.handleScroll=()=>{be(this,sr)==null&&Ke(this,sr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ke(this,sr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=rt(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,sl),()=>{o.removeEventListener("scroll",this.handleScroll,sl)}}})}};sr=new WeakMap;var Gp="* { user-select: none !important; -webkit-user-select: none !important; }",qp=class extends We{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Zs),n=t?.register(Gp);if(this.destroy=rt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return gi(),document.addEventListener("selectionchange",gi,{capture:!0}),()=>{document.removeEventListener("selectionchange",gi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function gi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var ir=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),fn,js=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,fn,[]),this.listeners=new du,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Ht(r.target)||s.disabled)return;const{keyboardCodes:o=ir.keyboardCodes,preventActivation:a=ir.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return rt(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{wr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),yu(s);const{center:i}=new ft(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Rn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:d=>this.handleKeyDown(d,n,r),options:{capture:!0}}])];be(this,fn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=ir.keyboardCodes}=r??{};if(nn(t,[...s.end,...s.cancel])){t.preventDefault();const i=nn(t,s.cancel);this.handleEnd(t,i);return}nn(t,s.up)?this.handleMove("up",t):nn(t,s.down)&&this.handleMove("down",t),nn(t,s.left)?this.handleMove("left",t):nn(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:ir.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!i){switch(t){case"up":a={x:0,y:-l.y*o};break;case"down":a={x:0,y:l.y*o};break;case"left":a={x:-l.x*o,y:0};break;case"right":a={x:l.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Gu);t?.disabled===!1&&(t.disable(),be(this,fn).push(()=>{t.enable()}))}cleanup(){be(this,fn).forEach(t=>t()),Ke(this,fn,[])}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;js.configure=Mr(js);js.defaults=ir;var qu=js;function nn(e,t){return t.includes(e.code)}var Gt,Kp=class extends Hc{constructor(){super(...arguments),Ie(this,Gt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,Gt,kn(e));break;case"pointermove":if(!be(this,Gt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,Gt).x,y:n-be(this,Gt).y},{tolerance:s}=this.options;if(s&&qi(r,s)){this.abort();return}qi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ke(this,Gt,void 0)}};Gt=new WeakMap;var hn,qt,Vp=class extends Hc{constructor(){super(...arguments),Ie(this,hn),Ie(this,qt)}onEvent(e){switch(e.type){case"pointerdown":Ke(this,qt,kn(e)),Ke(this,hn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!be(this,qt))return;const{x:t,y:n}=kn(e),r={x:t-be(this,qt).x,y:n-be(this,qt).y};qi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){be(this,hn)&&(clearTimeout(be(this,hn)),Ke(this,qt,void 0),Ke(this,hn,void 0))}};hn=new WeakMap;qt=new WeakMap;var vn=class{};vn.Delay=Vp;vn.Distance=Kp;var lo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Ht(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new vn.Delay({value:250,tolerance:5})]:np(s)&&!e.defaultPrevented?[new vn.Delay({value:200,tolerance:0})]:[new vn.Delay({value:200,tolerance:10}),new vn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Ht(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=kh(r);return s===t.element?!1:!!s}}),pn,Rs=class extends _n{constructor(t,n){super(t),this.manager=t,this.options=n,Ie(this,pn,new Set),this.listeners=new du,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=lo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return rt(()=>{var s;const i=new AbortController,{signal:o}=i,a=d=>{tp(d)&&this.handlePointerDown(d,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const d of l)d&&(Xp(d.ownerDocument.defaultView),d.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ht(t.target)||n.disabled||Up(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=lo.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Dt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=$n(n.element),{x:l,y:d}=kn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:d*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const u=new ph(c,m=>this.handleStart(n,m));u.signal.onabort=()=>this.handleCancel(t),u.onEvent(t),this.controller=u;const f=Hi(),h=this.listeners.bind(f,[{type:"pointermove",listener:m=>this.handlePointerMove(m,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:Yr,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};be(this,pn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=kn(t),o=$n(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Is.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Rn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ht(n.target)?[n.target,a]:a,d=this.listeners.bind(l,[{type:"touchmove",listener:Yr,options:{passive:!1}},{type:"click",listener:Yr},{type:"contextmenu",listener:Yr},{type:"keydown",listener:this.handleKeyDown}]);be(this,pn).add(d)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},be(this,pn).forEach(n=>n()),be(this,pn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};pn=new WeakMap;Rs.configure=Mr(Rs);Rs.defaults=lo;var co=Rs;function Up(e){return"sensor"in e}function Yr(e){e.preventDefault()}function Hp(){}var il=new WeakSet;function Xp(e){!e||il.has(e)||(e.addEventListener("touchmove",Hp,{capture:!1,passive:!1}),il.add(e))}var bn={modifiers:[],plugins:[xp,Gu,_p,ua,qp],sensors:[co,qu]},Ku=class extends vh{constructor(e={}){const t=lt(e.plugins,bn.plugins),n=lt(e.sensors,bn.sensors),r=lt(e.modifiers,bn.modifiers);super(oa(_r({},e),{plugins:[Bp,Lr,Zs,...t],sensors:n,modifiers:r}))}},Vu,Uu,uo,Et,pa,ga,Qs=class extends(uo=pt,Uu=[he],Vu=[he],uo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=Su(n,["element","effects","handle"]);super(_r({effects:()=>[...s(),()=>{var a,l;const{manager:d}=this;if(!d)return;const u=((l=(a=this.sensors)==null?void 0:a.map(vr))!=null?l:[...d.sensors]).map(f=>{const h=f instanceof _n?f:d.registry.register(f.plugin),p=f instanceof _n?void 0:f.options;return h.bind(this,p)});return function(){u.forEach(h=>h())}}]},o),t),Ie(this,pa,Pe(Et,8,this)),Pe(Et,11,this),Ie(this,ga,Pe(Et,12,this)),Pe(Et,15,this),this.element=r,this.handle=i}};Et=Nn(uo);pa=new WeakMap;ga=new WeakMap;st(Et,4,"handle",Uu,Qs,pa);st(Et,4,"element",Vu,Qs,ga);Jt(Et,Qs);var Hu,Xu,fo,Ct,ma,mi,Yu,Zu,mr,va,Js=class extends(fo=gt,Xu=[he],Hu=[he],fo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=Su(n,["element","effects"]);const{collisionDetector:o=xu}=i,a=d=>{const{manager:c,element:u}=this;if(!u||d===null){this.shape=void 0;return}if(!c)return;const f=new ft(u),h=fe(()=>this.shape);return f&&h?.equals(f)?h:(this.shape=f,f)},l=En(!1);super(oa(_r({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:d,manager:c}=this;if(!c)return;const{dragOperation:u}=c,{source:f}=u;l.value=!!(f&&u.status.initialized&&d&&!this.disabled&&this.accepts(f))},()=>{const{element:d}=this;if(l.value&&d){const c=new Mh(d,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var d;if((d=this.manager)!=null&&d.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ie(this,mr),Ie(this,ma,Pe(Ct,8,this)),Pe(Ct,11,this),Ie(this,va,Pe(Ct,12,this)),Pe(Ct,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ke(this,mr,e,Zu)}get element(){var e;return(e=this.proxy)!=null?e:be(this,mr,Yu)}};Ct=Nn(fo);ma=new WeakMap;mr=new WeakSet;va=new WeakMap;mi=st(Ct,20,"#element",Xu,mr,ma),Yu=mi.get,Zu=mi.set;st(Ct,4,"proxy",Hu,Js,va);Jt(Ct,Js);function Yp(e){return e!=null&&typeof e=="object"&&"current"in e}function xn(e){var t;if(e!=null)return Yp(e)?(t=e.current)!=null?t:void 0:e}var Zp=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Fn=Zp?k.useLayoutEffect:k.useEffect;function Qp(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Qu(e,t){const n=k.useRef(new Map),r=Qp();return Fn(()=>{if(!e){n.current.clear();return}return rt(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[l]=a,d=fe(()=>a[1]),c=e[l];d!==c&&(i=!0,n.current.set(l,c),o=(s=t?.(l,d,c))!=null?s:!1)}i&&(o?queueMicrotask(()=>nf.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function Jp(e,t){e()}function rn(e){const t=k.useRef(e);return Fn(()=>{t.current=e},[e]),t}function Se(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function vs(e,t){const n=k.useRef(xn(e));Fn(()=>{const r=xn(e);r!==n.current&&(n.current=r,t(r))})}var eg=Object.defineProperty,tg=Object.defineProperties,ng=Object.getOwnPropertyDescriptors,Ls=Object.getOwnPropertySymbols,Ju=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,ol=(e,t,n)=>t in e?eg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rg=(e,t)=>{for(var n in t||(t={}))Ju.call(t,n)&&ol(e,n,t[n]);if(Ls)for(var n of Ls(t))ed.call(t,n)&&ol(e,n,t[n]);return e},sg=(e,t)=>tg(e,ng(t)),ig=(e,t)=>{var n={};for(var r in e)Ju.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ls)for(var r of Ls(e))t.indexOf(r)<0&&ed.call(e,r)&&(n[r]=e[r]);return n},og=new Ku,td=k.createContext(og),ag=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{i.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Fn(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),vi=[void 0,it];function lg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:l}=t,d=ig(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=k.useRef(null),{plugins:u,modifiers:f,sensors:h}=d,p=lt(u,bn.plugins),m=lt(h,bn.sensors),b=lt(f,bn.modifiers),x=rn(s),v=rn(i),g=rn(a),y=rn(o),_=rn(l),S=rn(r),E=cg(()=>{var D;return(D=d.manager)!=null?D:new Ku(d)});return k.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:D,trackRendering:T}=c.current,{monitor:A}=E;E.renderer=D;const q=[A.addEventListener("beforedragstart",P=>{const z=x.current;z&&T(()=>z(P,E))}),A.addEventListener("dragstart",P=>{var z;return(z=v.current)==null?void 0:z.call(v,P,E)}),A.addEventListener("dragover",P=>{const z=g.current;z&&T(()=>z(P,E))}),A.addEventListener("dragmove",P=>{const z=y.current;z&&T(()=>z(P,E))}),A.addEventListener("dragend",P=>{const z=_.current;z&&T(()=>z(P,E))}),A.addEventListener("collision",P=>{var z;return(z=S.current)==null?void 0:z.call(S,P,E)})];return()=>q.forEach(P=>P())},[E]),Se(p,()=>E&&(E.plugins=p),...vi),Se(m,()=>E&&(E.sensors=m),...vi),Se(b,()=>E&&(E.modifiers=b),...vi),w.jsxs(td.Provider,{value:E,children:[w.jsx(ag,{ref:c,children:n}),n]})}function cg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function ug(){return k.useContext(td)}function nd(e){var t;const n=(t=ug())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Fn(r.register,[n,r]),r}var dg=Object.create,rd=Object.defineProperty,fg=Object.getOwnPropertyDescriptor,sd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ei=e=>{throw TypeError(e)},hg=(e,t,n)=>t in e?rd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pg=e=>{var t;return[,,,dg((t=e?.[sd("metadata")])!=null?t:null)]},id=["class","method","getter","setter","accessor","field","value","get","set"],od=e=>e!==void 0&&typeof e!="function"?ei("Function expected"):e,gg=(e,t,n,r,s)=>({kind:id[e],name:t,metadata:r,addInitializer:i=>n._?ei("Already initialized"):s.push(od(i||null))}),mg=(e,t)=>hg(t,sd("metadata"),e[3]),vg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ad=(e,t,n,r,s,i)=>{for(var o,a,l,d,c=t&7,u=!1,f=!1,h=2,p=id[c+5],m=e[h]||(e[h]=[]),b=(s=s.prototype,fg(s,n)),x=r.length-1;x>=0;x--)l=gg(c,n,a={},e[3],m),l.static=u,l.private=f,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[x])(b[p],l),a._=1,od(o)&&(b[p]=o);return b&&rd(s,n,b),s},ld=(e,t,n)=>t.has(e)||ei("Cannot "+n),yg=(e,t,n)=>(ld(e,t,"read from private field"),t.get(e)),bg=(e,t,n)=>t.has(e)?ei("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),xg=(e,t,n,r)=>(ld(e,t,"write to private field"),t.set(e,n),n),Vt=class ho{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ho(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new ho(t,n)}},cd,ud,po,ys,Nr,ya=class extends(po=Zt,ud=[Ee],cd=[Ee],po){constructor(e){const t=Vt.from(e);super(t,(n,r)=>Vt.equals(n,r)),vg(Nr,5,this),bg(this,ys,0),this.velocity={x:0,y:0}}get delta(){return Vt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=Vt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-yg(this,ys),o=a=>Math.round(a/i*100);Te(()=>{xg(this,ys,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Vt.from(e)),this.velocity={x:0,y:0}}};Nr=pg(po);ys=new WeakMap;ad(Nr,2,"delta",ud,ya);ad(Nr,2,"direction",cd,ya);mg(Nr,ya);var dd=(e=>(e.Horizontal="x",e.Vertical="y",e))(dd||{});Object.values(dd);var wg=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Vt.distance(t.shape.center,n);return{id:r,value:1/s,type:jn.PointerIntersection,priority:Pn.High}}return null},_g=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=Vt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:jn.ShapeIntersection,priority:Pn.Normal}}return null},kg=e=>{var t;return(t=wg(e))!=null?t:_g(e)};function Sg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,l=nd(c=>new Js(sg(rg({},e),{register:!1,element:xn(s)}),c)),d=Qu(l);return Se(i,()=>l.id=i),vs(s,c=>l.element=c),Se(o,()=>l.accept=o,void 0,it),Se(t,()=>l.collisionDetector=t??kg),Se(n,()=>n&&(l.data=n)),Se(r,()=>l.disabled=r===!0),Se(a,()=>l.type=a),{droppable:d,get isDropTarget(){return d.isDropTarget},ref:k.useCallback(c=>{var u,f;!c&&((u=l.element)!=null&&u.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const al=`url("data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>')}")`,fd=(e,t="line")=>{const n=[":is(p, h1, h2, h3, h4, h5, h6):first-child::after","> * > span:only-child::after"],r=o=>n.map(a=>`${o} ${a}`).join(", "),s=t==="line"?"&::after":r("&"),i=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[s]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:al,WebkitMaskImage:al,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,pointerEvents:"none"},[i]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},hd=k.createContext(void 0);function pd(e,t){const n=k.useContext(hd),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function go({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Be.usePublisherTheme(),[o,a]=k.useState(void 0),l=k.useRef(!1),d=()=>{l.current||o===void 0||(a(void 0),o!==e&&r(o))};pd(o!==void 0&&o!==e,()=>(d(),!0));const c=()=>{l.current=!1,a(e)};if(o===void 0){const u=e==="",f=u&&s;return w.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...u&&{fontStyle:"italic",opacity:f?0:.6}},fd(i)],children:u?t:e})}return w.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:u=>u.target.select(),onChange:u=>a(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.nativeEvent.isComposing?d():u.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:d,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const $g=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Tg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},gd=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),md=e=>`gap.${e}`,Og=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),l=o===0||i.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),l&&(r=0),n.push(gd(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Eg=Object.create,vd=Object.defineProperty,Cg=Object.defineProperties,Ig=Object.getOwnPropertyDescriptor,Ag=Object.getOwnPropertyDescriptors,Ns=Object.getOwnPropertySymbols,yd=Object.prototype.hasOwnProperty,bd=Object.prototype.propertyIsEnumerable,Dg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Fr=e=>{throw TypeError(e)},mo=(e,t,n)=>t in e?vd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yi=(e,t)=>{for(var n in t||(t={}))yd.call(t,n)&&mo(e,n,t[n]);if(Ns)for(var n of Ns(t))bd.call(t,n)&&mo(e,n,t[n]);return e},bi=(e,t)=>Cg(e,Ag(t)),Mg=(e,t)=>{var n={};for(var r in e)yd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ns)for(var r of Ns(e))t.indexOf(r)<0&&bd.call(e,r)&&(n[r]=e[r]);return n},Pg=e=>{var t;return[,,,Eg((t=void 0)!=null?t:null)]},xd=["class","method","getter","setter","accessor","field","value","get","set"],or=e=>e!==void 0&&typeof e!="function"?Fr("Function expected"):e,jg=(e,t,n,r,s)=>({kind:xd[e],name:t,metadata:r,addInitializer:i=>n._?Fr("Already initialized"):s.push(or(i||null))}),Rg=(e,t)=>mo(t,Dg("metadata"),e[3]),Zr=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},wd=(e,t,n,r,s,i)=>{for(var o,a,l,d,c,u=t&7,f=!1,h=!1,p=e.length+1,m=xd[u+5],b=e[p-1]=[],x=e[p]||(e[p]=[]),v=(s=s.prototype,Ig({get[n](){return ar(this,i)},set[n](y){return Kt(this,i,y)}},n)),g=r.length-1;g>=0;g--)d=jg(u,n,l={},e[3],x),d.static=f,d.private=h,c=d.access={has:y=>n in y},c.get=y=>y[n],c.set=(y,_)=>y[n]=_,a=(0,r[g])({get:v.get,set:v.set},d),l._=1,a===void 0?or(a)&&(v[m]=a):typeof a!="object"||a===null?Fr("Object expected"):(or(o=a.get)&&(v.get=o),or(o=a.set)&&(v.set=o),or(o=a.init)&&b.unshift(o));return v&&vd(s,n,v),s},_d=(e,t,n)=>t.has(e)||Fr("Cannot "+n),ar=(e,t,n)=>(_d(e,t,"read from private field"),t.get(e)),Vn=(e,t,n)=>t.has(e)?Fr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kt=(e,t,n,r)=>(_d(e,t,"write to private field"),t.set(e,n),n);function Ut(e){return e instanceof wa||e instanceof Td}var Qr=10,Lg=class extends We{constructor(e){super(e);const t=rt(()=>{const{dragOperation:r}=e;if(wr(r.activatorEvent)&&Ut(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Lr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!wr(r.nativeEvent)||!Ut(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:l}=s,{by:d}=r;if(!d)return;const c=Ng(d),{source:u,target:f}=i,{center:h}=i.shape.current,p=[],m=[];Te(()=>{for(const _ of l.droppables){const{id:S}=_;if(!_.accepts(u)||S===f?.id&&Ut(_)||!_.element)continue;let E=_.shape;const D=new ft(_.element,{getBoundingClientRect:T=>br(T,void 0,.2)});!D.height||!D.width||(c=="down"&&h.y+Qr<D.center.y||c=="up"&&h.y-Qr>D.center.y||c=="left"&&h.x-Qr>D.center.x||c=="right"&&h.x+Qr<D.center.x)&&(p.push(_),_.shape=D,m.push(()=>_.shape=E))}}),r.preventDefault(),a.disable();const b=a.computeCollisions(p,ip);Te(()=>m.forEach(_=>_()));const[x]=b;if(!x)return;const{id:v}=x,{index:g,group:y}=u.sortable;o.setDropTarget(v).then(()=>{const{source:_,target:S,shape:E}=i;if(!_||!Ut(_)||!E)return;const{index:D,group:T,target:A}=_.sortable,q=g!==D||y!==T,P=q?A:S?.element;if(!P)return;yu(P);const z=new ft(P);if(!z)return;const U=ht.delta(z,ht.from(E.current.boundingRectangle),_.alignment);o.move({by:U}),q?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Ng(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var Fg=Object.defineProperty,zg=Object.defineProperties,Wg=Object.getOwnPropertyDescriptors,ll=Object.getOwnPropertySymbols,Bg=Object.prototype.hasOwnProperty,Gg=Object.prototype.propertyIsEnumerable,cl=(e,t,n)=>t in e?Fg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Bg.call(t,n)&&cl(e,n,t[n]);if(ll)for(var n of ll(t))Gg.call(t,n)&&cl(e,n,t[n]);return e},on=(e,t)=>zg(e,Wg(t));function qg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Jr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function xi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Kg(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(xi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let c=-1,u,f=-1,h;for(const[g,y]of d)if(c===-1&&(c=y.findIndex(_=>l(_,i.id)),c!==-1&&(u=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),c!==-1&&f!==-1)break;if(c===-1&&xi(i)){const g=i.initialGroup==null?void 0:Jr(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:Jr(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return on(sn({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return on(sn({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=Jr(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(u==null||h==null||u===h&&c===f){if(u!=null&&u===h&&c===f&&xi(i)){const g=i.group==null?void 0:Jr(e,i.group),y=i.group!=null&&g!==u,_=i.index!==c;if(y||_){const S=i.group==null?u:g;if(S!=null){if(u===S)return on(sn({},e),{[u]:n(e[u],c,i.index)});const E=e[u][c];return on(sn({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(u===h)return on(sn({},e),{[u]:n(e[u],c,f)});const x=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[u][c];return on(sn({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[h]:[...e[h].slice(0,f+x),v,...e[h].slice(f+x)]})}function Vg(e,t){return Kg(e,t,qg)}function ul(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function dl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var fl="__default__",Ug=class extends We{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof wa){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Ut(o)||!Ut(a)||o.sortable===a.sortable)return;const l=t(),d=ul(l),c=o.sortable.group===a.sortable.group,u=l.get(o.sortable.group),f=c?u:l.get(a.sortable.group);!u||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var h,p;const m=t();if(dl(d,l,m))return;const b=o.sortable.element,x=a.sortable.element;if(!x||!b||!c&&a.id===o.sortable.group)return;const v=es(u),g=c?v:es(f),y=(h=o.sortable.group)!=null?h:fl,_=(p=a.sortable.group)!=null?p:fl,S={[y]:v,[_]:g},E=Vg(S,r);if(S===E)return;const D=E[_].indexOf(o.sortable),T=E[_].indexOf(a.sortable);s.collisionObserver.disable(),hl(b,D,x,T),Te(()=>{for(const[A,q]of E[y].entries())q.index=A;if(!c)for(const[A,q]of E[_].entries())q.group=a.sortable.group,q.index=A}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Ut(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=ul(a),d=a.get(o.sortable.initialGroup);d&&s.renderer.rendering.then(()=>{const c=t();if(dl(l,a,c))return;const u=es(d),f=es(d,Xg),h=o.sortable.element,p=f.indexOf(o.sortable),m=u[p],b=m?.element;!m||!b||!h||(hl(h,m.index,b,o.index),Te(()=>{for(const x of a.values()){const v=Array.from(x).values();for(const g of v)g.index=g.initialIndex,g.group=g.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function hl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Hg(e,t){return e.index-t.index}function Xg(e,t){return e.initialIndex-t.initialIndex}function es(e,t=Hg){return Array.from(e).sort(t)}var pl=[Lg,Ug],kd={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function gl(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var ts=new Bf,Sd,$d,It,ba,lr,cr,xa,gn;$d=[he],Sd=[he];var ti=class{constructor(e,t){Vn(this,ba,Zr(It,8,this)),Zr(It,11,this),Vn(this,lr),Vn(this,cr),Vn(this,xa,Zr(It,12,this)),Zr(It,15,this),Vn(this,gn),this.register=()=>(Te(()=>{var p,m;(p=this.manager)==null||p.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Te(()=>{var p,m;(p=this.manager)==null||p.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Te(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:l,transition:d=kd,plugins:c}=n,u=Mg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=lt(c,pl),h=gl(s);this.droppable=new wa(bi(yi({},u),{disabled:h.droppable}),t,this),this.draggable=new Td(bi(yi({},u),{disabled:h.draggable,plugins:f,effects:()=>[()=>{var p,m,b;const x=(p=this.manager)==null?void 0:p.dragOperation.status;x?.initializing&&this.id===((b=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:b.id)&&ts.clear(this.manager),x?.dragging&&ts.set(this.manager,this.id,fe(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:m,manager:b}=this,x=ar(this,cr),v=ar(this,lr);(p!==x||m!==v)&&(Kt(this,cr,p),Kt(this,lr,m),this.animate())},()=>{var p,m;const{target:b}=this,{isDragSource:x}=this.draggable;((m=(p=this.draggable.pluginConfig(ua))==null?void 0:p.feedback)!=null?m:"default")==="move"&&x&&(this.droppable.disabled=!b)},...r()],type:l,sensors:a}),t,this),Kt(this,gn,u.element),this.manager=t,this.index=o,Kt(this,cr,o),this.group=i,Kt(this,lr,i),this.type=l,this.transition=d}get initialIndex(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=ts.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){fe(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=mt(s),l=Za(s,a,!1),d=Za(s,a);if(o.x||o.y){const c=na(Ze(s))?bi(yi({},t),{duration:0}):t;bu({element:s,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${d.x}px ${d.y}px ${d.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Te(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Te(()=>{const t=ar(this,gn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Kt(this,gn,e)})}get element(){var e,t;const n=ar(this,gn);if(n)return(t=(e=Xi.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=lt(e,pl)}set disabled(e){const t=gl(e);Te(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Te(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??xu}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Te(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};It=Pg();ba=new WeakMap;lr=new WeakMap;cr=new WeakMap;xa=new WeakMap;gn=new WeakMap;wd(It,4,"index",$d,ti,ba);wd(It,4,"group",Sd,ti,xa);Rg(It,ti);var Td=class extends Qs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},wa=class extends Js{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Yg=Object.defineProperty,Zg=Object.defineProperties,Qg=Object.getOwnPropertyDescriptors,ml=Object.getOwnPropertySymbols,Jg=Object.prototype.hasOwnProperty,em=Object.prototype.propertyIsEnumerable,vl=(e,t,n)=>t in e?Yg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wi=(e,t)=>{for(var n in t||(t={}))Jg.call(t,n)&&vl(e,n,t[n]);if(ml)for(var n of ml(t))em.call(t,n)&&vl(e,n,t[n]);return e},tm=(e,t)=>Zg(e,Qg(t));function nm(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:l,group:d,disabled:c,modifiers:u,sensors:f,target:h,type:p,plugins:m}=e,b=wi(wi({},kd),e.transition),x=nd(g=>new ti(tm(wi({},e),{transition:b,register:!1,handle:xn(a),element:xn(o),target:xn(h)}),g)),v=Qu(x,rm);return Se(s,()=>x.id=s),Fn(()=>{Te(()=>{x.group=d,x.index=l})},[x,d,l]),Se(p,()=>x.type=p),Se(t,()=>x.accept=t,void 0,it),Se(i,()=>i&&(x.data=i)),Se(l,()=>{var g;(g=x.manager)!=null&&g.dragOperation.status.idle&&b?.idle&&x.refreshShape()},Jp),vs(a,g=>x.handle=g),vs(o,g=>x.element=g),vs(h,g=>x.target=g),Se(c,()=>x.disabled=c??!1,void 0,it),Se(f,()=>x.sensors=f,void 0,it),Se(n,()=>x.collisionDetector=n),Se(r,()=>x.collisionPriority=r),Se(m,()=>x.plugins=m,void 0,it),Se(b,()=>x.transition=b,void 0,it),Se(u,()=>x.modifiers=u,void 0,it),Se(e.alignment,()=>x.alignment=e.alignment),{sortable:v,get isDragging(){return v.isDragging},get isDropping(){return v.isDropping},get isDragSource(){return v.isDragSource},get isDropTarget(){return v.isDropTarget},handleRef:k.useCallback(g=>{x.handle=g??void 0},[x]),ref:k.useCallback(g=>{var y,_;!g&&((y=x.element)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.element=g??void 0)},[x]),sourceRef:k.useCallback(g=>{var y,_;!g&&((y=x.source)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.source=g??void 0)},[x]),targetRef:k.useCallback(g=>{var y,_;!g&&((y=x.target)!=null&&y.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.target=g??void 0)},[x])}}function rm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const vo="tile",Od="gap",sm=[co.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Ed}]`)!==null||(co.defaults.preventActivation?.(e,t)??!1)}),qu],Ed="data-no-drag",im=e=>[...e,ua.configure({feedback:"clone"})];function om({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=nm({id:e,index:t,type:vo,accept:vo,collisionDetector:sa,plugins:im});return w.jsx(w.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function am({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Sg({id:e,type:Od,accept:vo,collisionDetector:sa,data:{after:t}});return w.jsx(w.Fragment,{children:n({ref:r,isDropTarget:s})})}const Cd=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],Id=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],ni=e=>Id.includes(e),yo=new Set([...Cd,"viz"]);function At(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let s;for(const i of n)if(i.startsWith("-")){if(s!==void 0)return;const o=i.slice(1);if(!yo.has(o))return;r.push(o)}else{if(s!==void 0||!yo.has(i))return;s=i}return{negated:r,...s!==void 0&&{pick:s}}}function Tr(e){const t=e.trim();return!/^#[ \t]/.test(t)||At(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(r=>yo.has(r))}function wn(e,t){return["#",...Id.filter(r=>r!==e&&(t===void 0||t.includes(r))).map(r=>`-${r}`),"-viz",...e==="none"?[]:[e]].join(" ")}function lm(e){return e.pick!==void 0?ni(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function cm(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=At(e[0]);return t?lm(t):"custom"}function um(e){const t=e.filter(n=>At(n));return e.some(Tr)?"custom":t.length===0?void 0:cm(t)}const dm=e=>e.filter(t=>At(t)||Tr(t)),Ad=e=>e.ok===!1,De=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),en=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>De(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>De(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>De(e,"VIEW","subQueryDefList"),defDimension:e=>De(e,"defList","DIMENSION"),exploreProperties:e=>De(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>De(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>De(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>De(e,"WHERE","filterClauseList"),givenDef:e=>De(e,"givenNameDef"),givenStatement:e=>De(e,"GIVEN","givenDefList"),importStatement:e=>De(e,"IMPORT","importURL"),vArrow:e=>De(e,"ARROW","vExpr","segExpr"),segRefine:e=>De(e,"PLUS","segExpr"),segOps:e=>De(e,"queryProperties"),segField:e=>De(e,"fieldPath")&&!De(e,"segExpr"),segParen:e=>De(e,"OPAREN","CPAREN","vExpr"),compare:e=>De(e,"fieldExpr","compareOp"),givenRef:e=>De(e,"GIVEN_REF")};function fm(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function hm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
- `&&t.push(n+1);return t}function Dd(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!en(s))continue;const i=Ce(s,"docAnnotations");if(i)for(const o of Pt(i,"docAnnotation")){const a=e.text_(o);a!==void 0&&n.push(a.replace(/\r?\n\|##[^\n]*\n?$/,""))}}return n}class ri{constructor(t){this.text=t,this.map=fm(t),this.lineStarts=hm(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!en(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function zr(e,t,n=[]){en(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)zr(e.getChild(r),t,n);return n}const pm=e=>De(e,"OCURLY","CCURLY");function Or(e,t){const n=[],r=s=>{if(en(s)){if(t(s)){n.push(s);return}if(!pm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ce=(e,t)=>e[t]?.call(e),Pt=(e,t)=>e[t]?.call(e)??[];function gm(e,t){if(!ke.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!ke.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Md(e,t){const n=e.positioned(t);if(!n)return;const r=Ce(t,"filterClauseList"),s=[];for(const i of r?Pt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=zr(i,ke.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...o,givens:a,binding:gm(e,i)})}return{...n,clauses:s}}function bo(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const d of Or(t,ke.queryStatement)){const c=e.positioned(d);c&&r.push(c);const u=Ce(d,"whereStatement");if(u&&ke.whereStatement(u)){const f=Md(e,u);f&&s.push(f)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
- `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:l,oneLine:a}}function _a(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function mm(e,t){const n=Ce(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ce(n,"queryProperties"),i=s&&bo(e,s);return i?{kind:"inline",stage:i,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ke.segField(n)){const s=e.span(n);return s?{kind:"reference",from:e.text.slice(s.start,s.end),fromSpan:s}:{kind:"unsupported",why:"an unreadable name"}}if(ke.segRefine(n)){const s=Pt(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const f=Pt(a,"segExpr");if(f.some(h=>ke.segOps(h)||ke.segParen(h)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const l=e.span(i);if(!l||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const d=e.text.slice(l.start,l.end),c=Ce(o,"queryProperties"),u=c&&bo(e,c);return u?{kind:"reference",from:d,fromSpan:l,refinement:u}:{kind:"reference",from:d,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function vm(e,t){const n=[];for(const r of Or(t,ke.defExploreQuery)){const s=e.span(r),i=Ce(r,"subQueryDefList");if(!s||!i)continue;const o=Pt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ce(r,"VIEW"));for(const l of o){const d=e.span(l),c=Ce(l,"exploreQueryNameDef"),u=e.text_(c),f=Ce(l,"vExpr");!d||!u||!f||n.push({name:u,span:d,line:e.line(d.start),statement:s,tags:_a(e,s,a?.start??d.start),siblings:o.length,body:mm(e,f)})}}return n}function ym(e,t){const n=[];for(const r of Or(t,ke.defDimension)){const s=e.span(r),i=Ce(r,"defList");if(!s||!i)continue;const o=e.terminal(Ce(r,"DIMENSION"));for(const a of Pt(i,"fieldDef")){const l=e.span(a),d=e.text_(Ce(a,"fieldNameDef"))?.trim(),c=e.text_(Ce(a,"fieldExpr"))?.trim();!l||!d||c===void 0||n.push({name:d,expression:c,span:l,line:e.line(l.start),statement:s,tags:_a(e,s,o?.start??l.start)})}}return n}function bm(e,t){const n=[];for(const r of zr(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ce(r,"sourceNameDef")),o=Ce(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),l=a?e.text.slice(a.start,a.end):"",d=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),c=Or(o,ke.exploreProperties)[0],u=c&&bo(e,c),f={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(c)for(const p of Or(c,ke.whereStatement)){const m=Md(e,p);m&&h.push(m)}n.push({name:i,base:d,span:s,line:e.line(s.start),statement:f,...u?{properties:u}:{},views:c?vm(e,c):[],dimensions:c?ym(e,c):[],wheres:h})}return n}function xm(e,t){const n=[];for(const r of zr(t,ke.givenStatement)){const s=e.terminal(Ce(r,"GIVEN")),i=Ce(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Pt(i,"givenDef"):[]){const l=e.span(a),d=e.span(Ce(a,"givenNameDef")),c=d&&e.text.slice(d.start,d.end);if(!l||!d||!c)continue;const u={start:d.start,end:l.end},f=e.line(u.start);n.push({name:c,declaration:e.text.slice(u.start,u.end),span:u,line:f,statement:{start:e.lineStarts[f],end:u.end},tags:_a(e,l,u.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function wm(e,t){const n=[];for(const r of zr(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ce(r,"importURL"));if(!s||i===void 0)continue;const o=Ce(r,"importSelect"),a=o?Pt(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Pd(e){let t;try{t=await Wr(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!en(s)||typeof s.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new ri(e),l=ka(a,i);a.commentLines=l.lines;const d=e.split(`
70
- `),c=f=>l.lines.has(f);a.proseLines=ge.markdownLines(d,c),a.blocks=ge.blockSpans(d,c).filter(([f])=>!d[f].trimStart().startsWith("##"));const u=bm(a,s);return u.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:wm(a,s),sources:u,givens:xm(a,s),textBlocks:km(a,i),modelNotes:Dd(a,s),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(h=>h.start>=f.start&&h.start<f.end),blockStart:f=>_m(a,l.lines,f)}}}async function Wr(e,t){const{MalloyTranslator:n}=await O.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function ka(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const u=i?.getSymbolicName(c.type);if(u!=="COMMENT_TO_EOL"&&u!=="BLOCK_COMMENT")continue;const f=e.utf16(c.startIndex);let h=e.utf16(c.stopIndex+1);if(!(f===void 0||h===void 0||h<f)){for(;h>f&&(e.text[h-1]===`
71
- `||e.text[h-1]==="\r");)h--;s.push({start:f,end:h})}}const o=[...s].sort((c,u)=>c.start-u.start);let a="",l=0;for(const c of o)a+=e.text.slice(l,Math.max(l,c.start)),a+=e.text.slice(Math.max(l,c.start),Math.max(l,c.end)).replace(/[^\n\r]/g," "),l=Math.max(l,c.end);a+=e.text.slice(l);const d=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of s){const u=e.line(c.start),f=e.line(c.end-1);for(let m=u;m<=f;m++)d(m).trim()===""&&r.add(m);const h=a.slice(e.lineStarts[u],c.start).trim(),p=a.slice(c.end,e.lineStarts[f+1]??a.length).trim();h!==""&&p===""&&n.set(f,c)}return{trailing:n,lines:r,all:s}}function _m(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,l])=>l===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function km(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=ge.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!l)continue;const d=[];let c=a+1;for(;s(n[c]??n[a])==="BLOCK_ANNOTATION_TEXT";c++)d.push(i(n[c]));const u=n[c];if(!u||s(u)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),h=e.utf16(u.stopIndex+1)??e.text.length,p=l.name===void 0&&l.rest?[`${l.rest}
72
- `]:[];o.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...p,...d].join("").replace(/\r\n?/g,`
73
- `).replace(/\n$/,""),span:{start:e.lineStarts[f],end:h},line:f}),a=c}return o}function jd(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Sa(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=jd(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const i=/^tiles\s*=\s*\[/.exec(e.slice(r));if(i)return Sm(e,r+i[0].length-1)}}}function Sm(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),l=a.length-a.trimStart().length,d=a.trim();d!==""&&n.push({text:d,span:{start:s+l,end:s+l+d.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=jd(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return i(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(i(o),s=o+1)}}function $m(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Ap(e,t="hidden"){return re(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Lp(n,r.registry.droppables),i=[],o=Mh(n),{remove:a}=o;return Bp(s,o,i),Fp(o,t),o.remove=()=>{i.forEach(c=>c()),a.call(o)},o})}function Lp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Nr}${io("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Bp(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),to.set(a,o),n.push(()=>{to.delete(a),r.proxy=void 0})}}function Fp(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:Dn(e)===Dn(t)}function tl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Qt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Sn(t))}function co(e){return e.tagName==="TR"}function zp(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-")||Ip.includes(a))continue;const c=e.getAttribute(a);if(a==="style"){if(kr(e)&&kr(t)){const f=e.style;for(const d of Array.from(t.style))f.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(f)){if(Pp.includes(d)||d.startsWith(Ge))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 Wp(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 Np(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=ad();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},Ge),(n=e.getElementMutationObserver())==null||n.takeRecords(),co(e.element)&&co(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 Gp=250,Vp="ease";function Up(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=Gp,easing:a=Vp}=i??{};Sn(e.feedbackElement);const[,c]=(t=sd(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=Or(_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},Ge),e.feedbackElement.setAttribute(lo,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),vd({element:e.feedbackElement,keyframes:da(Mr(Mr({},x),_),{translate:[`${u.x}px ${u.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:oa(st(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(lo),c?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Id,uo,jr,ha,xs,Pd,Rd,In=class extends(uo=Ke,Id=[se],uo){constructor(t,n){super(t,n),je(this,xs),je(this,ha,Fe(jr,8,this)),Fe(jr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(si),s=r?.register(Rp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Zt(this,xs,Pd).bind(this,r)),this.registerEffect(Zt(this,xs,Rd))}};jr=Vn(uo);ha=new WeakMap;xs=new WeakSet;Pd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=Is(t);if(n)return e.addRoot(n)};Rd=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=Mn(y),b=Mn(p),T=!jd(p,y),C=new yt(p,{frameTransform:T?b:null,ignoreTransforms:!T}),j={x:b.scaleX/w.scaleX,y:b.scaleY/w.scaleY};let{width:D,height:E,top:R,left:P}=C;T&&(D=D/j.x,E=E/j.y);const A=new dp(y),U=_t(p),{transition:z,translate:q,boxSizing:M,paddingBlockStart:F,paddingBlockEnd:H,paddingInlineStart:B,paddingInlineEnd:W,borderInlineStartWidth:Q,borderInlineEndWidth:J,borderBlockStartWidth:ee,borderBlockEndWidth:te}=U,Z=z.split(",").filter(ce=>!/^\s*(transform|translate|scale)\b/.test(ce)).join(","),xe=ri(U),Re=U.transform,ue=_==="clone",we=M==="content-box",fe=we?parseInt(B)+parseInt(W)+parseInt(Q)+parseInt(J):0,_e=we?parseInt(F)+parseInt(H)+parseInt(ee)+parseInt(te):0,X=_!=="move"&&!this.overlay?Ap(u,ue?"clone":"hidden"):null,Ue=re(()=>Dr(c.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&xe)g.translate={x:xe.x,y:xe.y};else if(q!=="none"){const ce=Or(q);ce&&(g.translate=ce)}}if(!g.transformOrigin){const ce=re(()=>l.current),Ie=P+((r=xe?.x)!=null?r:0),tt=R+((s=xe?.y)!=null?s:0);g.transformOrigin={x:(ce.x-Ie*w.scaleX-w.x)/(D*w.scaleX),y:(ce.y-tt*w.scaleY-w.y)/(E*w.scaleY)}}const{transformOrigin:he}=g,oe=R*w.scaleY+w.y,Ae=P*w.scaleX+w.x;if(!g.coordinates&&(g.coordinates={x:Ae,y:oe},j.x!==1||j.y!==1)){const{scaleX:ce,scaleY:Ie}=b,{x:tt,y:Ct}=he;g.coordinates.x+=(D*ce-D)*tt,g.coordinates.y+=(E*Ie-E)*Ct}g.dimensions||(g.dimensions={width:D,height:E}),g.frameTransform||(g.frameTransform=w);const ze={x:g.coordinates.x-Ae,y:g.coordinates.y-oe},pe={width:(g.dimensions.width*g.frameTransform.scaleX-D*w.scaleX)*he.x,height:(g.dimensions.height*g.frameTransform.scaleY-E*w.scaleY)*he.y},We={x:ze.x/w.scaleX+pe.width,y:ze.y/w.scaleY+pe.height},He={left:P+We.x,top:R+We.y};y.setAttribute(vt,"true");const O=re(()=>d.transform),L=(i=g.translate)!=null?i:{x:0,y:0},N=O.x*w.scaleX+L.x,I=O.y*w.scaleY+L.y,V=ad();A.set({width:D-fe,height:E-_e,top:He.top+V.y,left:He.left+V.x,translate:`${N}px ${I}px 0`,transform:this.overlay?"none":Re,transition:Z?`${Z}, translate 0ms linear`:"translate 0ms linear",scale:T?`${j.x} ${j.y}`:"","transform-origin":`${he.x*100}% ${he.y*100}%`},Ge),X&&(p.insertAdjacentElement("afterend",X),f?.rootElement&&(typeof f.rootElement=="function"?f.rootElement(u):f.rootElement).appendChild(p)),ro(y)&&(y.hasAttribute("popover")||y.setAttribute("popover","manual"),Sn(y),y.addEventListener("beforetoggle",tl));let G,ne,ve;const ae=Np({placeholder:X,element:p,feedbackElement:y,frameTransform:w,transformOrigin:he,width:D,height:E,top:R,left:P,widthOffset:fe,heightOffset:_e,delta:We,styles:A,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>G,getSavedCellWidths:()=>ve,setSavedCellWidths:ce=>{ve=ce}}),Ne=new yt(y);re(()=>d.shape=Ne);const et=st(y),Kr=ce=>{this.manager.actions.stop({event:ce})},rn=oa(et);Ue&&et.addEventListener("resize",Kr),re(()=>u.status)==="idle"&&requestAnimationFrame(()=>u.status="dragging"),X&&(ae.observe(X),G=zp(p,X,ue),ne=Wp(p,X,y));const sn=(o=c.dragOperation.source)==null?void 0:o.id,Yr=()=>{var ce;if(!Ue||sn==null)return;const Ie=c.registry.draggables.get(sn),tt=(ce=Ie?.handle)!=null?ce:Ie?.element;At(tt)&&tt.focus()},Xr=()=>{G?.disconnect(),ne?.disconnect(),ae.disconnect(),et.removeEventListener("resize",Kr),ro(y)&&(y.removeEventListener("beforetoggle",tl),y.removeAttribute("popover")),y.removeAttribute(vt),A.reset();const ce=()=>{var Ie;if(ve&&co(p)){const di=Array.from(p.cells);for(const[Zr,on]of di.entries())on.style.width=(Ie=ve[Zr])!=null?Ie:""}u.status="idle";const tt=a.current.translate!=null,Ct=d.status.dragging;X&&(!Ct&&tt||X.parentElement!==y.parentElement)&&y.isConnected&&X.replaceWith(y),X?.remove()};y===this.overlay?setTimeout(ce,0):ce()},ci=f?.dropAnimation,Qr=this,qn=Lr(()=>{var ce,Ie,tt;const{transform:Ct,status:di}=d;if(!(!Ct.x&&!Ct.y&&!a.current.translate)&&di.dragging){const Zr=(ce=g.translate)!=null?ce:{x:0,y:0},on={x:Ct.x/w.scaleX+Zr.x,y:Ct.y/w.scaleY+Zr.y},Ma=a.current.translate,Qu=re(()=>d.modifiers),ui=re(()=>{var Yn;return(Yn=d.shape)==null?void 0:Yn.current}),Kn=f?.keyboardTransition,ja=Ue&&!rn&&Kn!==null?`${(Ie=Kn?.duration)!=null?Ie:250}ms ${(tt=Kn?.easing)!=null?tt:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:Z?`${Z}, translate ${ja}`:`translate ${ja}`,translate:`${on.x}px ${on.y}px 0`},Ge),G?.takeRecords(),ui&&ui!==Ne&&Ma&&!Qu.length){const Yn=ot.delta(on,Ma);d.shape=bt.from(ui.boundingRectangle).translate(Yn.x*w.scaleX,Yn.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:Qr.dropAnimation!==void 0?Qr.dropAnimation:ci;let Ie=a.current.translate;const tt=Ie!=null;if(!Ie&&p!==y&&(Ie={x:0,y:0}),!Ie||ce===null){Xr();return}c.renderer.rendering.then(()=>{Up({source:u,element:p,feedbackElement:y,placeholder:X,translate:Ie,moved:tt,transition:z,alignment:u.alignment,styles:A,animation:ce??void 0,getElementMutationObserver:()=>G,cleanup:Xr,restoreFocus:Yr})})}});return()=>{Xr(),qn()}};ut(jr,4,"overlay",Id,In,ha);nn(jr,In);In.configure=Fr(In);var pa=In,Qn=!0,Hp=!1,Ad,Ld,Bd,Fd,jt,ga,ma;Fd=(Bd=[se],at.Forward),Ld=(Ad=[se],at.Reverse);var Ir=class{constructor(){je(this,ga,Fe(jt,8,this,Qn)),Fe(jt,11,this),je(this,ma,Fe(jt,12,this,Qn)),Fe(jt,15,this)}isLocked(e){return e===at.Idle?!1:e==null?this[at.Forward]===Qn&&this[at.Reverse]===Qn:this[e]===Qn}unlock(e){e!==at.Idle&&(this[e]=Hp)}};jt=Vn(null);ga=new WeakMap;ma=new WeakMap;ut(jt,4,Fd,Bd,Ir,ga);ut(jt,4,Ld,Ad,Ir,ma);nn(jt,Ir);var qp=[at.Forward,at.Reverse],nl=class{constructor(){this.x=new Ir,this.y=new Ir}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Kp=class extends Ke{constructor(e){super(e);const t=Pn(new nl);let n=null;this.signal=t,dt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new nl;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:rl(s.x,n.x),y:rl(s.y,n.y)},o=t.peek();Ee(()=>{for(const a of pc)for(const c of qp)i[a]===c&&o[a].unlock(c);t.value=o})}n=s})}get current(){return this.signal.peek()}};function rl(e,t){return Math.sign(e-t)}var zd,fo,Pr,va,Dt,ho,Gr=class extends(fo=zr,zd=[se],fo){constructor(e){super(e),je(this,va,Fe(Pr,8,this,!1)),Fe(Pr,11,this),je(this,Dt),je(this,ho,()=>{if(!me(this,Dt))return;const{element:i,by:o}=me(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:sl(l.x),y:sl(l.y)}:void 0,h=u?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const p of c){const v=Vh(p,l);if(v.x||v.y){const{speed:x,direction:_}=tp(p,d,u,o?.acceleration,o?.threshold);if(h)for(const g of pc)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=me(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(me(this,ho)),!0}}}}}return Qe(this,Dt,void 0),!1};let t=null,n=null;const r=Wi(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=ld(Is(o?.element),i.current);return a&&(t=a),a??t}),s=Wi(()=>{const i=r.value,{documentElement:o}=Nn(i);if(!i||i===o){const{target:a}=e.dragOperation,c=a?.element;if(c){const f=so(c,{excludeElement:!1});return n=f,f}}if(i){const a=so(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ft);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Kp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!Dr(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};Pr=Vn(fo);va=new WeakMap;Dt=new WeakMap;ho=new WeakMap;ut(Pr,4,"autoScrolling",zd,Gr,va);nn(Pr,Gr);function sl(e){return e>0?at.Forward:e<0?at.Reverse:at.Idle}var Yp=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))}},Xp=new Yp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Qp=10,po=class extends Ke{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Gr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=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(()=>Xp.schedule(()=>r.scroll(void 0,f)),Qp);return()=>{clearInterval(l)}}else r.autoScrolling=!1}})}};po.configure=Fr(po);var Wd=po,il={capture:!0,passive:!0},dr,Zp=class extends zr{constructor(e){super(e),je(this,dr),this.handleScroll=()=>{me(this,dr)==null&&Qe(this,dr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Qe(this,dr,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,il),()=>{o.removeEventListener("scroll",this.handleScroll,il)}}})}};dr=new WeakMap;var Jp="* { user-select: none !important; -webkit-user-select: none !important; }",eg=class extends Ke{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(si),n=t?.register(Jp);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 ur=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 Cn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,mn,[]),this.listeners=new cd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Qt(r.target)||s.disabled)return;const{keyboardCodes:o=ur.keyboardCodes,preventActivation:a=ur.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=>{Dr(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),md(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=Nn(s),c=[this.listeners.bind(a,[{type:"keydown",listener:f=>this.handleKeyDown(f,n,r),options:{capture:!0}}])];me(this,mn).push(...c)}handleKeyDown(t,n,r){const{keyboardCodes:s=ur.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:ur.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(Wd);t?.disabled===!1&&(t.disable(),me(this,mn).push(()=>{t.enable()}))}cleanup(){me(this,mn).forEach(t=>t()),Qe(this,mn,[])}destroy(){this.cleanup(),this.listeners.clear()}};mn=new WeakMap;Ws.configure=Fr(Ws);Ws.defaults=ur;var Nd=Ws;function an(e,t){return t.includes(e.code)}var Ut,tg=class extends Hc{constructor(){super(...arguments),je(this,Ut)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Ut,On(e));break;case"pointermove":if(!me(this,Ut))return;const{x:t,y:n}=On(e),r={x:t-me(this,Ut).x,y:n-me(this,Ut).y},{tolerance:s}=this.options;if(s&&Xi(r,s)){this.abort();return}Xi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Qe(this,Ut,void 0)}};Ut=new WeakMap;var vn,Ht,ng=class extends Hc{constructor(){super(...arguments),je(this,vn),je(this,Ht)}onEvent(e){switch(e.type){case"pointerdown":Qe(this,Ht,On(e)),Qe(this,vn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!me(this,Ht))return;const{x:t,y:n}=On(e),r={x:t-me(this,Ht).x,y:n-me(this,Ht).y};Xi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){me(this,vn)&&(clearTimeout(me(this,vn)),Qe(this,Ht,void 0),Qe(this,vn,void 0))}};vn=new WeakMap;Ht=new WeakMap;var wn=class{};wn.Delay=ng;wn.Distance=tg;var go=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Qt(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new wn.Delay({value:250,tolerance:5})]:fp(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=Ih(r);return s===t.element?!1:!!s}}),yn,Ns=class extends Cn{constructor(t,n){super(t),this.manager=t,this.options=n,je(this,yn,new Set),this.listeners=new cd,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=go.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return dt(()=>{var s;const i=new AbortController,{signal:o}=i,a=f=>{up(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&&(ig(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||rg(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=go.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=At(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=Mn(n.element),{x:c,y:f}=On(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 Sh(d,v=>this.handleStart(n,v));l.signal.onabort=()=>this.handleCancel(t),l.onEvent(t),this.controller=l;const u=eo(),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:ss,options:{capture:!0}}]),p=()=>{h(),this.initialCoordinates=void 0};me(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=On(t),o=Mn(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=Nn(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:ss,options:{passive:!1}},{type:"click",listener:ss},{type:"contextmenu",listener:ss},{type:"keydown",listener:this.handleKeyDown}]);me(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},me(this,yn).forEach(n=>n()),me(this,yn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};yn=new WeakMap;Ns.configure=Fr(Ns);Ns.defaults=go;var mo=Ns;function rg(e){return"sensor"in e}function ss(e){e.preventDefault()}function sg(){}var ol=new WeakSet;function ig(e){!e||ol.has(e)||(e.addEventListener("touchmove",sg,{capture:!1,passive:!1}),ol.add(e))}var $n={modifiers:[],plugins:[Dp,Wd,jp,pa,eg],sensors:[mo,Nd]},Gd=class extends Eh{constructor(e={}){const t=gt(e.plugins,$n.plugins),n=gt(e.sensors,$n.sensors),r=gt(e.modifiers,$n.modifiers);super(da(Mr({},e),{plugins:[Zp,Gr,si,...t],sensors:n,modifiers:r}))}},Vd,Ud,vo,It,ya,ba,ii=class extends(vo=xt,Ud=[se],Vd=[se],vo){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=_d(n,["element","effects","handle"]);super(Mr({effects:()=>[...s(),()=>{var a,c;const{manager:f}=this;if(!f)return;const l=((c=(a=this.sensors)==null?void 0:a.map(Tr))!=null?c:[...f.sensors]).map(u=>{const h=u instanceof Cn?u:f.registry.register(u.plugin),p=u instanceof Cn?void 0:u.options;return h.bind(this,p)});return function(){l.forEach(h=>h())}}]},o),t),je(this,ya,Fe(It,8,this)),Fe(It,11,this),je(this,ba,Fe(It,12,this)),Fe(It,15,this),this.element=r,this.handle=i}};It=Vn(vo);ya=new WeakMap;ba=new WeakMap;ut(It,4,"handle",Ud,ii,ya);ut(It,4,"element",Vd,ii,ba);nn(It,ii);var Hd,qd,yo,Pt,xa,wi,Kd,Yd,$r,wa,oi=class extends(yo=wt,qd=[se],Hd=[se],yo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=_d(n,["element","effects"]);const{collisionDetector:o=yd}=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=re(()=>this.shape);return u&&h?.equals(u)?h:(this.shape=u,u)},c=Pn(!1);super(da(Mr({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:f,manager:d}=this;if(!d)return;const{dragOperation:l}=d,{source:u}=l;c.value=!!(u&&l.status.initialized&&f&&!this.disabled&&this.accepts(u))},()=>{const{element:f}=this;if(c.value&&f){const d=new Gh(f,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var f;if((f=this.manager)!=null&&f.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),je(this,$r),je(this,xa,Fe(Pt,8,this)),Fe(Pt,11,this),je(this,wa,Fe(Pt,12,this)),Fe(Pt,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Qe(this,$r,e,Yd)}get element(){var e;return(e=this.proxy)!=null?e:me(this,$r,Kd)}};Pt=Vn(yo);xa=new WeakMap;$r=new WeakSet;wa=new WeakMap;wi=ut(Pt,20,"#element",qd,$r,xa),Kd=wi.get,Yd=wi.set;ut(Pt,4,"proxy",Hd,oi,wa);nn(Pt,oi);function og(e){return e!=null&&typeof e=="object"&&"current"in e}function Tn(e){var t;if(e!=null)return og(e)?(t=e.current)!=null?t:void 0:e}var ag=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Un=ag?k.useLayoutEffect:k.useEffect;function lg(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Xd(e,t){const n=k.useRef(new Map),r=lg();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=re(()=>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(()=>Zu.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 cg(e,t){e()}function ln(e){const t=k.useRef(e);return Un(()=>{t.current=e},[e]),t}function $e(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 ws(e,t){const n=k.useRef(Tn(e));Un(()=>{const r=Tn(e);r!==n.current&&(n.current=r,t(r))})}var dg=Object.defineProperty,ug=Object.defineProperties,fg=Object.getOwnPropertyDescriptors,Gs=Object.getOwnPropertySymbols,Qd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,al=(e,t,n)=>t in e?dg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hg=(e,t)=>{for(var n in t||(t={}))Qd.call(t,n)&&al(e,n,t[n]);if(Gs)for(var n of Gs(t))Zd.call(t,n)&&al(e,n,t[n]);return e},pg=(e,t)=>ug(e,fg(t)),gg=(e,t)=>{var n={};for(var r in e)Qd.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&&Zd.call(e,r)&&(n[r]=e[r]);return n},mg=new Gd,Jd=k.createContext(mg),vg=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 yg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:c}=t,f=gg(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=bg(()=>{var j;return(j=f.manager)!=null?j:new Gd(f)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:j,trackRendering:D}=d.current,{monitor:E}=C;C.renderer=j;const R=[E.addEventListener("beforedragstart",P=>{const A=_.current;A&&D(()=>A(P,C))}),E.addEventListener("dragstart",P=>{var A;return(A=g.current)==null?void 0:A.call(g,P,C)}),E.addEventListener("dragover",P=>{const A=y.current;A&&D(()=>A(P,C))}),E.addEventListener("dragmove",P=>{const A=w.current;A&&D(()=>A(P,C))}),E.addEventListener("dragend",P=>{const A=b.current;A&&D(()=>A(P,C))}),E.addEventListener("collision",P=>{var A;return(A=T.current)==null?void 0:A.call(T,P,C)})];return()=>R.forEach(P=>P())},[C]),$e(p,()=>C&&(C.plugins=p),..._i),$e(v,()=>C&&(C.sensors=v),..._i),$e(x,()=>C&&(C.modifiers=x),..._i),m.jsxs(Jd.Provider,{value:C,children:[m.jsx(vg,{ref:d,children:n}),n]})}function bg(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 xg(){return k.useContext(Jd)}function eu(e){var t;const n=(t=xg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Un(r.register,[n,r]),r}var wg=Object.create,tu=Object.defineProperty,_g=Object.getOwnPropertyDescriptor,nu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ai=e=>{throw TypeError(e)},kg=(e,t,n)=>t in e?tu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sg=e=>{var t;return[,,,wg((t=e?.[nu("metadata")])!=null?t:null)]},ru=["class","method","getter","setter","accessor","field","value","get","set"],su=e=>e!==void 0&&typeof e!="function"?ai("Function expected"):e,$g=(e,t,n,r,s)=>({kind:ru[e],name:t,metadata:r,addInitializer:i=>n._?ai("Already initialized"):s.push(su(i||null))}),Tg=(e,t)=>kg(t,nu("metadata"),e[3]),Eg=(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},iu=(e,t,n,r,s,i)=>{for(var o,a,c,f,d=t&7,l=!1,u=!1,h=2,p=ru[d+5],v=e[h]||(e[h]=[]),x=(s=s.prototype,_g(s,n)),_=r.length-1;_>=0;_--)c=$g(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,su(o)&&(x[p]=o);return x&&tu(s,n,x),s},ou=(e,t,n)=>t.has(e)||ai("Cannot "+n),Cg=(e,t,n)=>(ou(e,t,"read from private field"),t.get(e)),Og=(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),Dg=(e,t,n,r)=>(ou(e,t,"write to private field"),t.set(e,n),n),Kt=class bo{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new bo(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new bo(t,n)}},au,lu,xo,_s,Vr,_a=class extends(xo=en,lu=[Oe],au=[Oe],xo){constructor(e){const t=Kt.from(e);super(t,(n,r)=>Kt.equals(n,r)),Eg(Vr,5,this),Og(this,_s,0),this.velocity={x:0,y:0}}get delta(){return Kt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=Kt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-Cg(this,_s),o=a=>Math.round(a/i*100);Ee(()=>{Dg(this,_s,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Kt.from(e)),this.velocity={x:0,y:0}}};Vr=Sg(xo);_s=new WeakMap;iu(Vr,2,"delta",lu,_a);iu(Vr,2,"direction",au,_a);Tg(Vr,_a);var cu=(e=>(e.Horizontal="x",e.Vertical="y",e))(cu||{});Object.values(cu);var Mg=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Kt.distance(t.shape.center,n);return{id:r,value:1/s,type:Wn.PointerIntersection,priority:zn.High}}return null},jg=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,i=Kt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Wn.ShapeIntersection,priority:zn.Normal}}return null},Ig=e=>{var t;return(t=Mg(e))!=null?t:jg(e)};function Pg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,c=eu(d=>new oi(pg(hg({},e),{register:!1,element:Tn(s)}),d)),f=Xd(c);return $e(i,()=>c.id=i),ws(s,d=>c.element=d),$e(o,()=>c.accept=o,void 0,ft),$e(t,()=>c.collisionDetector=t??Ig),$e(n,()=>n&&(c.data=n)),$e(r,()=>c.disabled=r===!0),$e(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 du=(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}}},uu=k.createContext(void 0);function fu(e,t){const n=k.useContext(uu),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function wo({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=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))};fu(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}},du(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 Rg=(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}),Ag=(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},hu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),pu=e=>`gap.${e}`,Lg=(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:Be(e[o-1]),colspan:t-r}),c&&(r=0),n.push(hu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Be(s),colspan:t-r}),n};var Bg=Object.create,gu=Object.defineProperty,Fg=Object.defineProperties,zg=Object.getOwnPropertyDescriptor,Wg=Object.getOwnPropertyDescriptors,Vs=Object.getOwnPropertySymbols,mu=Object.prototype.hasOwnProperty,vu=Object.prototype.propertyIsEnumerable,Ng=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ur=e=>{throw TypeError(e)},_o=(e,t,n)=>t in e?gu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ki=(e,t)=>{for(var n in t||(t={}))mu.call(t,n)&&_o(e,n,t[n]);if(Vs)for(var n of Vs(t))vu.call(t,n)&&_o(e,n,t[n]);return e},Si=(e,t)=>Fg(e,Wg(t)),Gg=(e,t)=>{var n={};for(var r in e)mu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Vs)for(var r of Vs(e))t.indexOf(r)<0&&vu.call(e,r)&&(n[r]=e[r]);return n},Vg=e=>{var t;return[,,,Bg((t=void 0)!=null?t:null)]},yu=["class","method","getter","setter","accessor","field","value","get","set"],fr=e=>e!==void 0&&typeof e!="function"?Ur("Function expected"):e,Ug=(e,t,n,r,s)=>({kind:yu[e],name:t,metadata:r,addInitializer:i=>n._?Ur("Already initialized"):s.push(fr(i||null))}),Hg=(e,t)=>_o(t,Ng("metadata"),e[3]),is=(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},bu=(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=yu[l+5],x=e[p-1]=[],_=e[p]||(e[p]=[]),g=(s=s.prototype,zg({get[n](){return hr(this,i)},set[n](w){return qt(this,i,w)}},n)),y=r.length-1;y>=0;y--)f=Ug(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?fr(a)&&(g[v]=a):typeof a!="object"||a===null?Ur("Object expected"):(fr(o=a.get)&&(g.get=o),fr(o=a.set)&&(g.set=o),fr(o=a.init)&&x.unshift(o));return g&&gu(s,n,g),s},xu=(e,t,n)=>t.has(e)||Ur("Cannot "+n),hr=(e,t,n)=>(xu(e,t,"read from private field"),t.get(e)),Zn=(e,t,n)=>t.has(e)?Ur("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qt=(e,t,n,r)=>(xu(e,t,"write to private field"),t.set(e,n),n);function Yt(e){return e instanceof $a||e instanceof Su}var os=10,qg=class extends Ke{constructor(e){super(e);const t=dt(()=>{const{dragOperation:r}=e;if(Dr(r.activatorEvent)&&Yt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Gr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!Dr(r.nativeEvent)||!Yt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:c}=s,{by:f}=r;if(!f)return;const d=Kg(f),{source:l,target:u}=i,{center:h}=i.shape.current,p=[],v=[];Ee(()=>{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 j=new yt(b.element,{getBoundingClientRect:D=>Cr(D,void 0,.2)});!j.height||!j.width||(d=="down"&&h.y+os<j.center.y||d=="up"&&h.y-os>j.center.y||d=="left"&&h.x-os>j.center.x||d=="right"&&h.x+os<j.center.x)&&(p.push(b),b.shape=j,v.push(()=>b.shape=C))}}),r.preventDefault(),a.disable();const x=a.computeCollisions(p,gp);Ee(()=>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:j,group:D,target:E}=b.sortable,R=y!==j||w!==D,P=R?E:T?.element;if(!P)return;md(P);const A=new yt(P);if(!A)return;const U=bt.delta(A,bt.from(C.current.boundingRectangle),b.alignment);o.move({by:U}),R?o.setDropTarget(b.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Kg(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 Yg=Object.defineProperty,Xg=Object.defineProperties,Qg=Object.getOwnPropertyDescriptors,ll=Object.getOwnPropertySymbols,Zg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,cl=(e,t,n)=>t in e?Yg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,cn=(e,t)=>{for(var n in t||(t={}))Zg.call(t,n)&&cl(e,n,t[n]);if(ll)for(var n of ll(t))Jg.call(t,n)&&cl(e,n,t[n]);return e},dn=(e,t)=>Xg(e,Qg(t));function em(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function as(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function $i(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function tm(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:as(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:as(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=as(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:as(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 nm(e,t){return tm(e,t,em)}function dl(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function ul(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var fl="__default__",rm=class extends Ke{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof $a){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Yt(o)||!Yt(a)||o.sortable===a.sortable)return;const c=t(),f=dl(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(ul(f,c,v))return;const x=o.sortable.element,_=a.sortable.element;if(!_||!x||!d&&a.id===o.sortable.group)return;const g=ls(l),y=d?g:ls(u),w=(h=o.sortable.group)!=null?h:fl,b=(p=a.sortable.group)!=null?p:fl,T={[w]:g,[b]:y},C=nm(T,r);if(T===C)return;const j=C[b].indexOf(o.sortable),D=C[b].indexOf(a.sortable);s.collisionObserver.disable(),hl(x,j,_,D),Ee(()=>{for(const[E,R]of C[w].entries())R.index=E;if(!d)for(const[E,R]of C[b].entries())R.group=a.sortable.group,R.index=E}),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=dl(a),f=a.get(o.sortable.initialGroup);f&&s.renderer.rendering.then(()=>{const d=t();if(ul(c,a,d))return;const l=ls(f),u=ls(f,im),h=o.sortable.element,p=u.indexOf(o.sortable),v=l[p],x=v?.element;!v||!x||!h||(hl(h,v.index,x,o.index),Ee(()=>{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 hl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function sm(e,t){return e.index-t.index}function im(e,t){return e.initialIndex-t.initialIndex}function ls(e,t=sm){return Array.from(e).sort(t)}var pl=[qg,rm],wu={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function gl(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var cs=new Zf,_u,ku,Rt,ka,pr,gr,Sa,bn;ku=[se],_u=[se];var li=class{constructor(e,t){Zn(this,ka,is(Rt,8,this)),is(Rt,11,this),Zn(this,pr),Zn(this,gr),Zn(this,Sa,is(Rt,12,this)),is(Rt,15,this),Zn(this,bn),this.register=()=>(Ee(()=>{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=()=>{Ee(()=>{var p,v;(p=this.manager)==null||p.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Ee(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:c,transition:f=wu,plugins:d}=n,l=Gg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const u=gt(d,pl),h=gl(s);this.droppable=new $a(Si(ki({},l),{disabled:h.droppable}),t,this),this.draggable=new Su(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)&&cs.clear(this.manager),_?.dragging&&cs.set(this.manager,this.id,re(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:p,group:v,manager:x}=this,_=hr(this,gr),g=hr(this,pr);(p!==_||v!==g)&&(qt(this,gr,p),qt(this,pr,v),this.animate())},()=>{var p,v;const{target:x}=this,{isDragSource:_}=this.draggable;((v=(p=this.draggable.pluginConfig(pa))==null?void 0:p.feedback)!=null?v:"default")==="move"&&_&&(this.droppable.disabled=!x)},...r()],type:c,sensors:a}),t,this),qt(this,bn,l.element),this.manager=t,this.index=o,qt(this,gr,o),this.group=i,qt(this,pr,i),this.type=c,this.transition=f}get initialIndex(){var e,t;return(t=(e=cs.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=cs.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){re(()=>{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=Za(s,a,!1),f=Za(s,a);if(o.x||o.y){const d=oa(st(s))?Si(ki({},t),{duration:0}):t;vd({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){Ee(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Ee(()=>{const t=hr(this,bn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),qt(this,bn,e)})}get element(){var e,t;const n=hr(this,bn);if(n)return(t=(e=to.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=gt(e,pl)}set disabled(e){const t=gl(e);Ee(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Ee(()=>{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){Ee(()=>{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=Vg();ka=new WeakMap;pr=new WeakMap;gr=new WeakMap;Sa=new WeakMap;bn=new WeakMap;bu(Rt,4,"index",ku,li,ka);bu(Rt,4,"group",_u,li,Sa);Hg(Rt,li);var Su=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}},$a=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}},om=Object.defineProperty,am=Object.defineProperties,lm=Object.getOwnPropertyDescriptors,ml=Object.getOwnPropertySymbols,cm=Object.prototype.hasOwnProperty,dm=Object.prototype.propertyIsEnumerable,vl=(e,t,n)=>t in e?om(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||(t={}))cm.call(t,n)&&vl(e,n,t[n]);if(ml)for(var n of ml(t))dm.call(t,n)&&vl(e,n,t[n]);return e},um=(e,t)=>am(e,lm(t));function fm(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({},wu),e.transition),_=eu(y=>new li(um(Ti({},e),{transition:x,register:!1,handle:Tn(a),element:Tn(o),target:Tn(h)}),y)),g=Xd(_,hm);return $e(s,()=>_.id=s),Un(()=>{Ee(()=>{_.group=f,_.index=c})},[_,f,c]),$e(p,()=>_.type=p),$e(t,()=>_.accept=t,void 0,ft),$e(i,()=>i&&(_.data=i)),$e(c,()=>{var y;(y=_.manager)!=null&&y.dragOperation.status.idle&&x?.idle&&_.refreshShape()},cg),ws(a,y=>_.handle=y),ws(o,y=>_.element=y),ws(h,y=>_.target=y),$e(d,()=>_.disabled=d??!1,void 0,ft),$e(u,()=>_.sensors=u,void 0,ft),$e(n,()=>_.collisionDetector=n),$e(r,()=>_.collisionPriority=r),$e(v,()=>_.plugins=v,void 0,ft),$e(x,()=>_.transition=x,void 0,ft),$e(l,()=>_.modifiers=l,void 0,ft),$e(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 hm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const ko="tile",$u="gap",pm=[mo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Tu}], ${gm}`)!==null||(mo.defaults.preventActivation?.(e,t)??!1)}),Nd],Tu="data-no-drag",gm=".malloy-render, .malloy-table",mm=e=>[...e,pa.configure({feedback:"clone"})];function vm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=fm({id:e,index:t,type:ko,accept:ko,collisionDetector:la,plugins:mm});return m.jsx(m.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function ym({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Pg({id:e,type:$u,accept:ko,collisionDetector:la,data:{after:t}});return m.jsx(m.Fragment,{children:n({ref:r,isDropTarget:s})})}const Eu=e=>e.ok===!1,Pe=(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=>Pe(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>Pe(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>Pe(e,"VIEW","subQueryDefList"),defDimension:e=>Pe(e,"defList","DIMENSION"),exploreProperties:e=>Pe(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>Pe(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>Pe(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>Pe(e,"WHERE","filterClauseList"),givenDef:e=>Pe(e,"givenNameDef"),givenStatement:e=>Pe(e,"GIVEN","givenDefList"),importStatement:e=>Pe(e,"IMPORT","importURL"),vArrow:e=>Pe(e,"ARROW","vExpr","segExpr"),segRefine:e=>Pe(e,"PLUS","segExpr"),segOps:e=>Pe(e,"queryProperties"),segField:e=>Pe(e,"fieldPath")&&!Pe(e,"segExpr"),segParen:e=>Pe(e,"OPAREN","CPAREN","vExpr"),compare:e=>Pe(e,"fieldExpr","compareOp"),givenRef:e=>Pe(e,"GIVEN_REF")};function bm(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 xm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
68
+ `&&t.push(n+1);return t}function Cu(e,t){const n=[];for(let r=0;r<(t.childCount??0);r++){const s=t.getChild(r);if(!Hn(s))continue;const i=De(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 Ou{constructor(t){this.text=t,this.map=bm(t),this.lineStarts=xm(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 Hr(e,t,n=[]){Hn(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Hr(e.getChild(r),t,n);return n}const wm=e=>Pe(e,"OCURLY","CCURLY");function Rr(e,t){const n=[],r=s=>{if(Hn(s)){if(t(s)){n.push(s);return}if(!wm(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 De=(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 Du(e,t){const n=e.positioned(t);if(!n)return;const r=De(t,"filterClauseList"),s=[];for(const i of r?Bt(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=Hr(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 So(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const f of Rr(t,ke.queryStatement)){const d=e.positioned(f);d&&r.push(d);const l=De(f,"whereStatement");if(l&&ke.whereStatement(l)){const u=Du(e,l);u&&s.push(u)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
69
+ `),c=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:c,oneLine:a}}function Ta(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;o++){if(e.commentLines.has(o)||e.proseLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function km(e,t){const n=De(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=De(n,"queryProperties"),i=s&&So(e,s);return i?{kind:"inline",stage:i,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(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=De(o,"queryProperties"),l=d&&So(e,d);return l?{kind:"reference",from:f,fromSpan:c,refinement:l}:{kind:"reference",from:f,fromSpan:c}}return{kind:"unsupported",why:"a parenthesized expression"}}function Sm(e,t){const n=[];for(const r of Rr(t,ke.defExploreQuery)){const s=e.span(r),i=De(r,"subQueryDefList");if(!s||!i)continue;const o=Bt(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(De(r,"VIEW"));for(const c of o){const f=e.span(c),d=De(c,"exploreQueryNameDef"),l=e.text_(d),u=De(c,"vExpr");!f||!l||!u||n.push({name:l,span:f,line:e.line(f.start),statement:s,tags:Ta(e,s,a?.start??f.start),siblings:o.length,body:km(e,u)})}}return n}function $m(e,t){const n=[];for(const r of Rr(t,ke.defDimension)){const s=e.span(r),i=De(r,"defList");if(!s||!i)continue;const o=e.terminal(De(r,"DIMENSION"));for(const a of Bt(i,"fieldDef")){const c=e.span(a),f=e.text_(De(a,"fieldNameDef"))?.trim(),d=e.text_(De(a,"fieldExpr"))?.trim();!c||!f||d===void 0||n.push({name:f,expression:d,span:c,line:e.line(c.start),statement:s,tags:Ta(e,s,o?.start??c.start)})}}return n}function Tm(e,t){const n=[];for(const r of Hr(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(De(r,"sourceNameDef")),o=De(r,"sqExplore");if(!s||!i||!o)continue;const a=e.span(o),c=a?e.text.slice(a.start,a.end):"",f=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(c)?.[1]??"").trim(),d=Rr(o,ke.exploreProperties)[0],l=d&&So(e,d),u={start:e.lineStarts[e.line(s.start)],end:s.end},h=[];if(d)for(const p of Rr(d,ke.whereStatement)){const v=Du(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?Sm(e,d):[],dimensions:d?$m(e,d):[],wheres:h})}return n}function Em(e,t){const n=[];for(const r of Hr(t,ke.givenStatement)){const s=e.terminal(De(r,"GIVEN")),i=De(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(De(a,"givenNameDef")),d=f&&e.text.slice(f.start,f.end);if(!c||!f||!d)continue;const l={start:f.start,end:c.end},u=e.line(l.start);n.push({name:d,declaration:e.text.slice(l.start,l.end),span:l,line:u,statement:{start:e.lineStarts[u],end:l.end},tags:Ta(e,c,l.start),...o!==void 0&&o!==u?{blockHeader:o}:{}})}}return n}function Cm(e,t){const n=[];for(const r of Hr(t,ke.importStatement)){const s=e.span(r),i=e.text_(De(r,"importURL"));if(!s||i===void 0)continue;const o=De(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 Mu(e){let t;try{t=await Ea(e,"file://dashboard-builder.malloy")}catch(u){return{ok:!1,reason:`Malloy could not read this file: ${u}`}}const n=t.problems.filter(u=>u.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,s=r?.root;if(!s||!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 Ou(e),c=Om(a,i);a.commentLines=c.lines;const f=e.split(`
70
+ `),d=u=>c.lines.has(u);a.proseLines=ge.markdownLines(f,d),a.blocks=ge.blockSpans(f,d).filter(([u])=>!f[u].trimStart().startsWith("##"));const l=Tm(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:Cm(a,s),sources:l,givens:Em(a,s),textBlocks:Mm(a,i),modelNotes:Cu(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=>Dm(a,c.lines,u)}}}async function Ea(e,t){const{MalloyTranslator:n}=await S.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Om(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 Dm(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 Mm(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=ge.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 Iu(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 jm(e,r+i[0].length-1)}}}function jm(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 Im(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
74
74
  `)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const s=e.indexOf(`
75
75
  `,r),i=s===-1?e.length:s;if(e.slice(r,i).trim()===">>>")return i;if(s===-1)return e.length;r=s+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let s=t+3;s<e.length;s++)if(e[s]==="\\")s++;else if(e.startsWith(r,s))return s+3;return e.length}for(let s=t+1;s<e.length;s++)if(e[s]==="\\")s++;else{if(e[s]===n)return s+1;if(e[s]===`
76
- `)return s}return e.length}return t}function Tm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=$m(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const i=e[r];if(/[=[,]/.test(i)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${i}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=i,r+=1}return n}function $a(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(i=>{if(e([i]).log.length===0)return i;const o=Tm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const yl=(e,t)=>{try{return e.text(t)}catch{return}},Om=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Em=e=>`\`kind=${e}\` is no longer read, so this file is not a report. Fix: remove \`kind=${e}\` and write \`layout=grid\` or \`layout=linear\`.`;function Rd(e,t){const n=e.filter(Om).filter(l=>!l.includes("@env.")).map(ge.tagAnnotation),{tag:r,errors:s}=n.length>0?$a(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(ge.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=yl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=yl(i,"layout");return a==="grid"||a==="linear"?{status:"report",layout:a}:i.has("tiles")||r?.tag("dashboard")!==void 0?{status:"report",layout:"grid"}:{status:"report",layout:"linear"}}async function Cm(e){const{parseAnnotation:t}=await O.loadMalloyTag();let n=[];try{const r=(await Wr(e,"file://report.malloy")).parse?.root;r&&en(r)&&typeof r.getChild=="function"&&(n=Dd(new ri(e),r))}catch{n=[]}return Rd(n,t)}const Er=e=>e.ok===!1;function Br(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Fs=e=>e.map(t=>t.text);function bl(e){const t=Fs(e),n=um(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:dm(t)}:{chart:n}}function Im(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:ge.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Am(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Dm(n(Fs(Br(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Dm(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...s===void 0?{}:{rangeMax:s}}}function _i(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const Mm=/^"((?:[^"\\]|\\.)+)"$/,Pm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Cr(e,t,n=!1){try{return await jm(e)}catch(r){return{ok:!1,reason:`A value in this file's tags cannot be read (${r instanceof Error?r.message:String(r)}), so it cannot be opened in the builder.`}}}async function jm(e){const{parseAnnotation:t}=await O.loadMalloyTag(),n=ge.splitSourceLines(e),r=await Pd(e);if(Ad(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=ge.descriptionNotes(n).text,o=Rd(s.modelNotes,t);if(o.status==="none")return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(o.status==="unparsed")return{ok:!1,reason:`The \`## artifact\` tag does not parse${o.errors[0]?`: ${o.errors[0]}`:"."}`};if(o.status==="kind-removed")return{ok:!1,reason:Em(o.kind)};const a=o.layout,l=ge.artifactTag(n);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ge.artifactLeads(l.text))return{ok:!1,reason:ge.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:d,errors:c}=$a(t,[ge.tagAnnotation(l.text)]),u=d?.tag("artifact"),f=Sa(l.text);if(f===void 0)return c.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${c[0]}`}:a==="linear"?{ok:!1,legacyNotebook:!0,reason:"This report is in the cell format, with no `tiles=[…]` list."}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const h=s.imports.map(S=>S.names?{kind:"names",names:S.names,from:S.from}:{kind:"all",from:S.from}),p=[],m=[],b=new Map;for(const S of s.sources){const E={name:S.name,base:S.base};S.dimensions.length>0&&(E.dimensions=S.dimensions.map(T=>({name:T.name,expression:T.expression})));const D=new Set(S.wheres.flatMap(T=>T.clauses.flatMap(A=>A.givens)));D.size>0&&(E.scopedBy=Array.from(D)),p.push(E);for(const T of S.dimensions){const A=t(Fs(Br(s,n,T.line).tags)).tag?.tag("drill");if(!A)continue;const q=A.textArray("to")??[A.text("to")??""];m.push({source:S.name,name:T.name,expression:T.expression,to:q.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}b.set(S.name,new Map(S.views.map(T=>[T.name,T])))}const x=[];for(const{text:S}of f.entries){const E=Mm.exec(S),D=E?void 0:Pm.exec(S)?.[1];if(D!==void 0){const J=t([`# ${S}`]).tag?.tag(D);if(J?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${S}\` is neither a quoted \`source -> view\` expression nor a \`${D} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(x.some(de=>je(de)&&de.name===D))return{ok:!1,reason:`Two text tiles are named \`${D}\`, so the builder cannot tell them apart.`};const ie=_i(J,"colspan");x.push({kind:"text",name:D,markdown:s.textBlocks.find(de=>de.name===D)?.body??"",...ie===void 0?{}:{colspan:ie},...J.has("break")?{break:!0}:{}});continue}const T=E?.[1]??S,A=E?ge.tileSteps(T):void 0;if(!A)return{ok:!1,reason:`The tile \`${T}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:q,view:P}=A,z=b.get(q)?.get(P);if(z===void 0){x.push({name:P,source:q,declaration:{kind:"inherited"}});continue}const U=t(Fs(z.tags)).tag,K=z.body.kind==="reference"?{kind:"reference",from:z.body.from}:z.body.kind==="inline"?{kind:"inline"}:void 0;if(K===void 0){x.push({name:P,source:q,declaration:{kind:"opaque",why:z.body.kind==="unsupported"?z.body.why:"unreadable"},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}});continue}const Z=Im(z.body.kind==="reference"?z.body.refinement:z.body.kind==="inline"?z.body.stage:void 0);x.push({name:P,source:q,declaration:K,...Z?{filters:Z}:{},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(z.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}})}const v=Am(s,n,t),g={},y=u?.tag("givens");for(const S of Object.keys(y?.dict??{})){const E=y?.text(S);E!==void 0&&(g[S]=E)}const _=d?.tag("dashboard")?.has("columns")?_i(d.tag("dashboard"),"columns"):u?.array("tiles")?_i(u,"dashboard_columns"):void 0;return{ok:!0,document:{layout:a,title:u?.text("title")??"",...i?{description:i}:{},..._===void 0?{}:{columns:_},...u?.has("autorun")?{autorun:u.isTrue("autorun")}:{},imports:h,sources:p,...v?{localGivens:v}:{},...Object.keys(g).length>0?{startingGivens:g}:{},...m.length>0?{drills:m}:{},tiles:x}}}const zs=e=>e.ok===!1;async function xl(e){const{problems:t}=await Wr(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function _e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Ld(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Rm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
- `&&t.push(n+1);return t}function Lm(e,t){let n=e;const r=t.map((s,i)=>({edit:s,index:i}));for(const{edit:s}of r.sort((i,o)=>o.edit.start-i.edit.start||o.edit.end-i.edit.end||o.index-i.index))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}const Nd=e=>e==="none"||ni(e)?e:void 0;function Fd(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${at(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${at(e.subtitle)}`);const r=t?Nd(e.chart):void 0;return r!==void 0&&n.push(wn(r,e.chartCarried)),n}function bs(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Nm=new Set(["colspan","break","borderless","label","subtitle"]),Fm=new Set(["label","description","control","suggest","range_min","range_max"]);function wl(e){const t=[];if(e.label!==void 0&&t.push(`label=${at(e.label)}`),e.description!==void 0&&t.push(`description=${at(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${at(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${at(e.suggest.dimension)} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const _l=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function zm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function kl(e){const t=r=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)?r:at(r);return`# drill { to=${e.to.length===1?t(e.to[0]):`[${e.to.map(at).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ws=e=>`${e.source}.${e.name}`,at=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,xo=e=>je(e)?_e(["text",e.name]):_e([e.name,e.source,e.declaration]),tt=xo,Sl=e=>_e(e.tiles.map(tt));function Wm(e,t,n){const r=new Set(e.tiles.map(tt)),s=new Set(t.tiles.map(tt)),i=e.tiles.filter(h=>!s.has(tt(h))),o=t.tiles.filter(h=>!r.has(tt(h))),l=i.length>0||o.length>0||Sl(e)!==Sl(t);for(const h of o)if(xe(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(h=>[h.name,h])),c=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)c.add(h.base);const u=t.imports.some(h=>h.kind==="all"),f=t.sources.filter(h=>!d.has(h.name));for(const h of e.sources){const p=t.sources.find(m=>m.name===h.name);if(!p||p.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of f){if(!o.some(p=>xe(p)&&p.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!c.has(h.base)&&!u&&!n?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:r,nextKeys:s,removedTiles:i,addedTiles:o,newSources:f,currentSources:d,reordered:l}}const $l=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Bm(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Ir(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Tl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Bm(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=d=>{const c=d.exec(o);c&&(i=i.slice(0,c.index)+i.slice(c.index+c[0].length),o=o.slice(0,c.index)+o.slice(c.index+c[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const l=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${l.join(" ")} }${t.slice(s+1)}`}function Gm(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:l}=e,d=new Map(r.tiles.filter(je).map(v=>[v.name,v])),c=s.tiles.filter(je).some(v=>{const g=d.get(v.name);return g!==void 0&&$l(g,v)});if(!i&&!c)return;const u=ge.artifactTag(t);if(!u)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=u.text,h=Sa(f);if(!h)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A grid report with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const p=new Map;for(const{text:v}of h.entries){const g=/^"((?:[^"\\]|\\.)+)"$/.exec(v);if(g){const _=g[1].split("->").map(S=>S.trim());_.length===2&&p.set(`${_[0]}->${_[1]}`,v);continue}const y=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(v)?.[1];y!==void 0&&p.set(`text.${y}`,v)}const m=s.tiles.map(v=>{const g=!o.has(tt(v));if(je(v)){const y=p.get(`text.${v.name}`);return y!==void 0?d.has(v.name)&&!$l(d.get(v.name),v)?y:Tl(v,y):g?Tl(v):void 0}return p.get(`${v.source}->${v.name}`)??(g?`"${v.source} -> ${v.name}"`:void 0)});if(m.some(v=>v===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const b=f.slice(0,h.open).search(/tiles\s*=\s*$/),x=`${f.slice(0,b)}tiles=[${qm(f,h,m)}]${f.slice(h.close+1)}`;x!==f&&l.push({...zd(n,u),text:`${x}
78
- `})}function zd(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function qm(e,t,n){const r=t.entries[0],s=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const i=e.slice(t.open+1,r.span.start),o=e.slice(s.span.end,t.close),a=i.slice(i.lastIndexOf(`
79
- `)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
80
- `)?a:" "}`;return`${i}${n.join(l)}${o}`}function Km(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Ir(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,l=e[a]==='"'?Ir(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),d=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,d)+e.slice(l)}}return e}function Vm(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Ir(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Ir(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Ir(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Um(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||_e(r.startingGivens)!==_e(s.startingGivens)){const o=ge.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=zd(n,o),l=i.find(g=>g.start===a.start&&g.end===a.end);let d=l?l.text.replace(/\n$/,""):o.text;const c=r.layout!==s.layout,u=d.indexOf("artifact"),f=d.indexOf("{",u);let h=0,p=-1;for(let g=f;g<d.length;g++)if(d[g]==="{")h++;else if(d[g]==="}"&&--h===0){p=g;break}if(f<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let m=d.slice(f+1,p);const b=o.block?`
81
- ${/\n([ \t]+)\S/.exec(m)?.[1]??" "}`:" ",x=g=>o.block?`${m.trimEnd()}${b}${g}
82
- `:`${m.trimEnd()} ${g} `,v=(g,y)=>{const _=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${g}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(y===void 0){const S=new RegExp(`
83
- ${_.source}[ \\t]*(?=
84
- )`);m=m.replace(o.block&&S.test(m)?S:_,"")}else _.test(m)?m=m.replace(_,S=>`${o.block?S.slice(0,S.length-S.trimStart().length):" "}${g}=${y}`):m=x(`${g}=${y}`)};if(c&&v("layout",s.layout),r.title!==s.title&&v("title",s.title?at(s.title):void 0),r.autorun!==s.autorun&&v("autorun",s.autorun===void 0?void 0:String(s.autorun)),_e(r.startingGivens)!==_e(s.startingGivens)){m=m.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const g=Object.entries(s.startingGivens??{});g.length>0&&(m=x(`givens { ${g.map(([y,_])=>`${y}=${at(_)}`).join(" ")} }`))}o.block?d=`${d.slice(0,f+1)}${m}${d.slice(p)}`:(m=m.replace(/\s{2,}/g," "),d=`${d.slice(0,f+1)}${m.startsWith(" ")?m:` ${m}`}${m.endsWith(" ")?"":" "}${d.slice(p)}`),r.columns!==s.columns&&(d=Km(d,"dashboard_columns"),d=Vm(d),s.columns!==void 0&&(d=`${d.trimEnd()} dashboard { columns=${s.columns} }`)),l?l.text=`${d}
85
- `:i.push({...a,text:`${d}
86
- `})}if(r.description!==s.description){const{read:o,blankAbove:a,below:l,belowBlock:d,inBlock:c}=ge.descriptionNotes(t);if(c||s.description===void 0&&d)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const u=Ld(s.description??"").split(`
87
- `).map(m=>m.trim()===""?'##"':`##" ${m.trim()}`).join(`
88
- `),f=o.length>0&&o[0]<ge.artifactLine(t),h=s.description===void 0,p=f?[...o.slice(1),...h?l:[]]:[...o,...a];for(const m of p)i.push({...n(m),text:""});if(f)i.push({...n(o[0]),text:s.description===void 0?"":`${u}
89
- `});else if(s.description!==void 0){const m=n(ge.artifactLine(t)).start;i.push({start:m,end:m,text:`${u}
90
- `})}}}function Hm(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.localGivens??[]).map(h=>[h.name,h])),d=new Map((i.localGivens??[]).map(h=>[h.name,h])),c=new Map(a.givens.map(h=>[h.name,h])),u=new Set;for(const[h,p]of l){const m=d.get(h);if(m!==void 0&&_e(m)===_e(p))continue;const b=c.get(h);if(b===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:x,prose:v}=Br(a,t,b.line),y=[...(m===void 0?x:x.filter(A=>{const q=bs(A.text);return q!==void 0&&Fm.has(q)})).map(A=>A.line),...m===void 0?v:[]];for(const A of y)o.push({...n(A),text:""}),u.add(A);const _=xt(a,b.span.end-1);if(m===void 0){o.push({start:n(b.line).start,end:n(_).end,text:""});for(let K=b.line;K<=_;K++)u.add(K);const A=Math.min(b.line,...y),q=b.blockHeader??A,P=(t[_+1]??"x").trim()==="",z=q===0||t[q-1].trim()==="",U=b.blockHeader===void 0||![...c.values()].some(K=>K.blockHeader===b.blockHeader&&K.line>b.line&&d.has([...c.entries()].find(([,Z])=>Z===K)?.[0]??""));P&&z&&U&&!u.has(_+1)&&(o.push({...n(_+1),text:""}),u.add(_+1));continue}const S=r(b.line),E=wl(m),T=m.type!==p.type||m.default!==p.default?b.blockHeader===void 0?_l(m):`${m.name} :: ${m.type} is ${m.default}`:t.slice(b.line,_+1).join(`
91
- `).trim();o.push({start:n(b.line).start,end:n(_).end,text:(E?`${S}${E}
92
- `:"")+`${S}${T}
93
- `})}for(const[h,p]of c){if(p.blockHeader===void 0||d.has(h))continue;![...c.values()].some(b=>b.blockHeader===p.blockHeader&&!u.has(b.line))&&!u.has(p.blockHeader)&&(o.push({...n(p.blockHeader),text:""}),u.add(p.blockHeader))}const f=[...d.values()].filter(h=>!l.has(h.name));if(f.length>0){const h=Math.max(-1,...[...c.values()].map(g=>g.line)),p=(()=>{let g=-1;for(let y=0;y<t.length;y++){const _=t[y].trim();(_.startsWith("import ")||g>=0&&/^}\s*from\s/.test(_))&&(g=y)}return g})(),m=h>=0?h:p,b=f.map(g=>{const y=wl(g);return(y?`${y}
94
- `:"")+`${_l(g)}
76
+ `)return s}return e.length}return t}function Pm(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Im(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 Pu(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=Pm(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const yl=(e,t)=>{try{return e.text(t)}catch{return}},Rm=e=>/^##\|?(?:[ \t\r\n]|$)/.test(e),Am=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\`.`,Lm=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=[…]\`.`,Bm="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 Ru(e,t){const n=e.filter(Rm).filter(d=>!d.includes("@env.")).map(ge.tagAnnotation),{tag:r,errors:s}=n.length>0?Pu(t,n):{tag:void 0,errors:[]},i=r?.tag("artifact");if(!i)return e.some(ge.setsArtifactProperty)?{status:"unparsed",errors:s}:{status:"none"};const o=yl(i,"kind");if(o!==void 0)return{status:"kind-removed",kind:o};const a=yl(i,"layout"),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 Fm(e){const{parseAnnotation:t}=await S.loadMalloyTag();let n=[];try{const r=(await Ea(e,"file://report.malloy")).parse?.root;r&&Hn(r)&&typeof r.getChild=="function"&&(n=Cu(new Ou(e),r))}catch{n=[]}return Ru(n,t)}const Us=e=>e.ok===!1;function qr(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const Hs=e=>e.map(t=>t.text);function bl(e){const t=Hs(e),n=S.chartStateOfTagLines(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:S.chartLinesOf(t)}:{chart:n}}function zm(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:ge.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Wm(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(),...Nm(n(Hs(qr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Nm(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 Gm=/^"((?:[^"\\]|\\.)+)"$/,Vm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function qs(e,t,n=!1){try{return await Um(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 Um(e){const{parseAnnotation:t}=await S.loadMalloyTag(),n=ge.splitSourceLines(e),r=await Mu(e);if(Eu(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const s=r.parsed,i=ge.descriptionNotes(n).text,o=Ru(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:Am(o.kind)};if(o.status==="cells-removed")return{ok:!1,reason:o.unknownLayout!==void 0?Lm(o.unknownLayout):Bm};const a=o.layout,c=ge.artifactTag(n);if(c===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a report."};if(!ge.artifactLeads(c.text))return{ok:!1,reason:ge.ARTIFACT_NOT_FIRST,line:c.from+1};const{tag:f,errors:d}=Pu(t,[ge.tagAnnotation(c.text)]),l=f?.tag("artifact"),u=Iu(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(D=>({name:D.name,expression:D.expression})));const j=new Set(T.wheres.flatMap(D=>D.clauses.flatMap(E=>E.givens)));j.size>0&&(C.scopedBy=Array.from(j)),p.push(C);for(const D of T.dimensions){const E=t(Hs(qr(s,n,D.line).tags)).tag?.tag("drill");if(!E)continue;const R=E.textArray("to")??[E.text("to")??""];v.push({source:T.name,name:D.name,expression:D.expression,to:R.filter(Boolean),...E.text("given")?{given:E.text("given")}:{}})}x.set(T.name,new Map(T.views.map(D=>[D.name,D])))}const _=[];for(const{text:T}of u.entries){const C=Gm.exec(T),j=C?void 0:Vm.exec(T)?.[1];if(j!==void 0){const M=t([`# ${T}`]).tag?.tag(j);if(M?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${j} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(_.some(H=>Me(H)&&H.name===j))return{ok:!1,reason:`Two text tiles are named \`${j}\`, so the builder cannot tell them apart.`};const F=Ei(M,"colspan");_.push({kind:"text",name:j,markdown:s.textBlocks.find(H=>H.name===j)?.body??"",...F===void 0?{}:{colspan:F},...M.has("break")?{break:!0}:{}});continue}const D=C?.[1]??T,E=C?ge.tileSteps(D):void 0;if(!E)return{ok:!1,reason:`The tile \`${D}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:R,view:P}=E,A=x.get(R)?.get(P);if(A===void 0){_.push({name:P,source:R,declaration:{kind:"inherited"}});continue}const U=t(Hs(A.tags)).tag,z=A.body.kind==="reference"?{kind:"reference",from:A.body.from}:A.body.kind==="inline"?{kind:"inline"}:void 0;if(z===void 0){_.push({name:P,source:R,declaration:{kind:"opaque",why:A.body.kind==="unsupported"?A.body.why:"unreadable"},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(A.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}});continue}const q=zm(A.body.kind==="reference"?A.body.refinement:A.body.kind==="inline"?A.body.stage:void 0);_.push({name:P,source:R,declaration:z,...q?{filters:q}:{},...U?.text("label")?{label:U.text("label")}:{},...U?.text("subtitle")?{subtitle:U.text("subtitle")}:{},...U?.numeric("colspan")!==void 0?{colspan:U.numeric("colspan")}:{},...bl(A.tags),...U?.has("break")?{break:!0}:{},...U?.has("borderless")?{borderless:!0}:{}})}const g=Wm(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 Ks=e=>e.ok===!1;async function xl(e){const{problems:t}=await Ea(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function be(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function Au(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Hm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
77
+ `&&t.push(n+1);return t}function qm(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 Lu=e=>e==="none"||S.isChartPick(e)?e:void 0;function Bu(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?Lu(e.chart):void 0;return r!==void 0&&n.push(S.chartLineText(r,e.chartCarried)),n}function ks(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Km=new Set(["colspan","break","borderless","label","subtitle"]),Ym=new Set(["label","description","control","suggest","range_min","range_max"]);function wl(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 _l=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Xm(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: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,'\\"')}"`,$o=e=>Me(e)?be(["text",e.name]):be([e.name,e.source,e.declaration]),lt=$o,Sl=e=>be(e.tiles.map(lt));function Qm(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||Sl(e)!==Sl(t);for(const h of o)if(le(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=>le(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 $l=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Zm(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Ar(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Tl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Zm(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 Jm(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(Me).map(g=>[g.name,g])),d=s.tiles.filter(Me).some(g=>{const y=f.get(g.name);return y!==void 0&&$l(y,g)});if(!i&&!d)return;const l=ge.artifactTag(t);if(!l)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=l.text,h=Iu(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(Me(g)){const w=p.get(`text.${g.name}`);return w!==void 0?f.has(g.name)&&!$l(f.get(g.name),g)?w:Tl(g,w):y?Tl(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=[${ev(u,h,v)}]${u.slice(h.close+1)}`;_!==u&&c.push({...Fu(n,l),text:`${_}
78
+ `})}function Fu(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function ev(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 tv(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Ar(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,c=e[a]==='"'?Ar(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),f=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,f)+e.slice(c)}}return e}function nv(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Ar(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Ar(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Ar(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function rv(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(r.layout!==s.layout||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||be(r.startingGivens)!==be(s.startingGivens)){const o=ge.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Fu(n,o),c=i.find(y=>y.start===a.start&&y.end===a.end);let f=c?c.text.replace(/\n$/,""):o.text;const d=r.layout!==s.layout,l=f.indexOf("artifact"),u=f.indexOf("{",l);let h=0,p=-1;for(let y=u;y<f.length;y++)if(f[y]==="{")h++;else if(f[y]==="}"&&--h===0){p=y;break}if(u<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let v=f.slice(u+1,p);const x=o.block?`
81
+ ${/\n([ \t]+)\S/.exec(v)?.[1]??" "}`:" ",_=y=>o.block?`${v.trimEnd()}${x}${y}
82
+ `:`${v.trimEnd()} ${y} `,g=(y,w)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${y}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(w===void 0){const T=new RegExp(`
83
+ ${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)),be(r.startingGivens)!==be(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=tv(f,"dashboard_columns"),f=nv(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}=ge.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=Au(s.description??"").split(`
87
+ `).map(v=>v.trim()===""?'##"':`##" ${v.trim()}`).join(`
88
+ `),u=o.length>0&&o[0]<ge.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(ge.artifactLine(t)).start;i.push({start:v,end:v,text:`${l}
90
+ `})}}}function sv(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&&be(v)===be(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}=qr(a,t,x.line),w=[...(v===void 0?_:_.filter(E=>{const R=ks(E.text);return R!==void 0&&Ym.has(R)})).map(E=>E.line),...v===void 0?g:[]];for(const E of w)o.push({...n(E),text:""}),l.add(E);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 z=x.line;z<=b;z++)l.add(z);const E=Math.min(x.line,...w),R=x.blockHeader??E,P=(t[b+1]??"x").trim()==="",A=R===0||t[R-1].trim()==="",U=x.blockHeader===void 0||![...d.values()].some(z=>z.blockHeader===x.blockHeader&&z.line>x.line&&f.has([...d.entries()].find(([,q])=>q===z)?.[0]??""));P&&A&&U&&!l.has(b+1)&&(o.push({...n(b+1),text:""}),l.add(b+1));continue}const T=r(x.line),C=wl(v),D=v.type!==p.type||v.default!==p.default?x.blockHeader===void 0?_l(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}${D}
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=wl(y);return(w?`${w}
94
+ `:"")+`${_l(y)}
95
95
  `}).join(`
96
- `),x=m>=0?n(m).end:n(0).end;o.push({start:x,end:x,text:`
97
- ${b}`}),t.some(g=>g.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
98
- `})}}const Ol=(e,t)=>`import { ${e.join(", ")} } from ${at(t)}`;function Xm(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=u=>_e(u.imports.flatMap(f=>f.kind==="all"?[f.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(_e(n.imports)===_e(r.imports))return;const a=r.imports.flatMap(u=>u.kind==="names"?[{...u,claimed:!1}]:[]),l=new Set([...r.sources.map(u=>u.base),...r.tiles.filter(xe).map(u=>u.source)]),d=t.imports.map((u,f)=>({statement:u,entry:n.imports[f]}));for(const{statement:u,entry:f}of d){if(!f||f.kind!=="names")continue;const h=a.find(g=>!g.claimed&&g.from===f.from);h&&(h.claimed=!0);const p=h?.names??[],b=f.names.filter(g=>!p.includes(g)).find(g=>l.has(g));if(b!==void 0)return{ok:!1,reason:`\`${b}\` is still read by a tile, so its import cannot be removed.`};if(_e(p)===_e(f.names))continue;const x=p.length===0?Ta(t,u.statement):u.statement,v=t.commentIn(x);if(v)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(v.start,v.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({...x,text:p.length===0?"":Ol(p,f.from)})}const c=a.filter(u=>!u.claimed);if(c.length>0){const u=t.imports.at(-1);if(!u)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=i(xt(t,u.statement.end-1)).end;s.push({start:f,end:f,text:c.map(h=>`${Ol(h.names,h.from)}
99
- `).join("")})}}function Ym(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.drills??[]).map(c=>[Ws(c),c])),d=new Map((i.drills??[]).map(c=>[Ws(c),c]));for(const c of new Set([...l.keys(),...d.keys()])){const u=l.get(c),f=d.get(c);if(u&&f&&_e(u)===_e(f))continue;const h=f??u;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const p=a.sources.find(v=>v.name===h.source)?.dimensions.find(v=>v.name===h.name);if(p===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:m}=Br(a,t,p.line),b=m.find(v=>/^#\s*drill\b/.test(v.text)),x=r(p.line);if(f===void 0)b&&o.push({...n(b.line),text:""});else if(b)o.push({...n(b.line),text:`${x}${kl(f)}
100
- `});else{const v=n(p.line).start;o.push({start:v,end:v,text:`${x}${kl(f)}
101
- `})}}}function Zm(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(je(o)||o.declaration.kind==="inherited")continue;const a=Wd(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const l=xt(i,a.statement.start),d=xt(i,a.statement.end-1),c=i.trailingComment(d),u=c&&c.start>=a.statement.end?c.end:a.statement.end;if(i.text.slice(i.lineStarts[l],a.statement.start).trim()!==""||i.text.slice(u,n(d).end).trim()!==""){s.push({...Ta(i,a.statement),text:""});continue}s.push({start:i.lineStarts[l],end:n(d).end,text:""});const h=l===0?"":t[l-1].trim();(t[d+1]??"x").trim()===""&&(l===0||h===""||h.endsWith("{"))&&s.push({...n(d+1),text:""})}}function Qm(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:l}=e,d=new Map;for(const f of s){if(je(f))continue;const h=d.get(f.source)??[];h.push(f),d.set(f.source,h)}const c=(f,h)=>{const p=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(b=>`where: ${ge.malloyPath(b.field)} ${b.op??"~"} $${b.given}`).join(", ");return[...Fd(f).map(b=>`${h}${b}`),`${h}view: ${f.name} is ${p}${m?` + { ${m} }`:""}`].join(`
102
- `)};let u=-1;for(const f of l.sources)u=Math.max(u,xt(l,f.span.end-1));for(const[f,h]of d)if(o.has(f)){const p=l.sources.find(y=>y.name===f);if(!p)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const m=p.line,b=xt(l,p.properties.closeStart);let x=" ";for(let y=m+1;y<b;y++){const _=/^(\s+)view:/.exec(n[y]);if(_){x=_[1];break}}const v=r(b).start,g=(n[b-1]??"").trim()==="";a.push({start:v,end:v,text:(g?"":`
103
- `)+h.map(y=>c(y,x)).join(`
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 El=(e,t)=>`import { ${e.join(", ")} } from ${pt(t)}`;function iv(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=l=>be(l.imports.flatMap(u=>u.kind==="all"?[u.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(be(n.imports)===be(r.imports))return;const a=r.imports.flatMap(l=>l.kind==="names"?[{...l,claimed:!1}]:[]),c=new Set([...r.sources.map(l=>l.base),...r.tiles.filter(le).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(be(p)===be(u.names))continue;const _=p.length===0?Ca(t,l.statement):l.statement,g=t.commentIn(_);if(g)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(g.start,g.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({..._,text:p.length===0?"":El(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=>`${El(h.names,h.from)}
99
+ `).join("")})}}function ov(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&&be(l)===be(u))continue;const h=u??l;if(u&&u.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const p=a.sources.find(g=>g.name===h.source)?.dimensions.find(g=>g.name===h.name);if(p===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:v}=qr(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:`${_}${kl(u)}
100
+ `});else{const g=n(p.line).start;o.push({start:g,end:g,text:`${_}${kl(u)}
101
+ `})}}}function av(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(Me(o)||o.declaration.kind==="inherited")continue;const a=zu(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({...Ca(i,a.statement),text:""});continue}s.push({start:i.lineStarts[c],end:n(f).end,text:""});const h=c===0?"":t[c-1].trim();(t[f+1]??"x").trim()===""&&(c===0||h===""||h.endsWith("{"))&&s.push({...n(f+1),text:""})}}function lv(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(Me(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: ${ge.malloyPath(x.field)} ${x.op??"~"} $${x.given}`).join(", ");return[...Bu(u).map(x=>`${h}${x}`),`${h}view: ${u.name} is ${p}${v?` + { ${v} }`:""}`].join(`
102
+ `)};let l=-1;for(const u of c.sources)l=Math.max(l,Tt(c,u.span.end-1));for(const[u,h]of f)if(o.has(u)){const p=c.sources.find(w=>w.name===u);if(!p)return{ok:!1,reason:`Could not find where the source \`${u}\` is declared.`};if(!p.properties)return{ok:!1,reason:`\`${u}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=p.line,x=Tt(c,p.properties.closeStart);let _=" ";for(let w=v+1;w<x;w++){const b=/^(\s+)view:/.exec(n[w]);if(b){_=b[1];break}}const g=r(x).start,y=(n[x-1]??"").trim()==="";a.push({start:g,end:g,text:(y?"":`
103
+ `)+h.map(w=>d(w,_)).join(`
104
104
 
105
105
  `)+`
106
- `})}else{const p=i.find(g=>g.name===f);if(!p)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const m=`
106
+ `})}else{const p=i.find(y=>y.name===u);if(!p)return{ok:!1,reason:`The tile's source \`${u}\` is not declared.`};const v=`
107
107
  source: ${p.name} is ${p.base} extend {
108
- `+h.map(g=>c(g," ")).join(`
108
+ `+h.map(y=>d(y," ")).join(`
109
109
 
110
110
  `)+`
111
111
  }
112
- `;let b=u;if(b<0)for(let g=0;g<n.length;g++){const y=n[g].trim();(/^(import\s|given:|}\s*from\s)/.test(y)||/^[A-Z_]+\s*::/.test(y))&&(b=g)}const x=b>=0?r(b).end:t.length,v=x===t.length&&!t.endsWith(`
112
+ `;let x=l;if(x<0)for(let y=0;y<n.length;y++){const w=n[y].trim();(/^(import\s|given:|}\s*from\s)/.test(w)||/^[A-Z_]+\s*::/.test(w))&&(x=y)}const _=x>=0?r(x).end:t.length,g=_===t.length&&!t.endsWith(`
113
113
  `)?`
114
- `:"";a.push({start:x,end:x,text:v+m}),u=b}}function Jm(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:l}=e,d=new Map(i.tiles.map(c=>[tt(c),c]));for(const c of o.tiles){const u=d.get(tt(c));if(u===void 0||je(c)||je(u)||_e(Bs(u))===_e(Bs(c)))continue;if(c.declaration.kind==="inherited")return{ok:!1,reason:`\`${c.source} -> ${c.name}\` is declared on its source, not in this report, so its presentation cannot be changed here.`};const f=zm(l,c.source,c.name);if(f<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:h}=Br(l,t,f),p=s(f),m=Fd(c,!1),b=new Map(m.map(T=>[bs(T)??T,T])),x=new Set,v=Nd(c.chart),g=El(u)!==El(c);if(g){const T=h.filter(P=>Tr(P.text)),A=h.filter(P=>At(P.text)),q=u.chart==="custom"?h.filter(P=>At(P.text)||Tr(P.text)):T.length>0?T:A.length>1?A:[];if(q.length>0)return{ok:!1,reason:`\`${c.source} -> ${c.name}\` has a chart line the builder does not model (${q.map(P=>P.text).join(" and ")}), so its chart cannot be changed here.`}}let y=!1;for(const T of h){if(g&&At(T.text)){v===void 0?a.push({...r(T.line),text:""}):T.text!==wn(v,c.chartCarried)&&a.push({...r(T.line),text:`${p}${wn(v,c.chartCarried)}
115
- `}),y=!0;continue}const A=bs(T.text);if(A===void 0||!Nm.has(A))continue;const q=b.get(A);if(q===void 0){a.push({...r(T.line),text:""});continue}x.add(A),q!==T.text&&a.push({...r(T.line),text:`${p}${q}
116
- `})}const _=m.filter(T=>!x.has(bs(T)??T));if(g&&v!==void 0&&!y&&_.push(wn(v,c.chartCarried)),_.length>0){const T=n[f];a.push({start:T,end:T,text:_.map(A=>`${p}${A}
117
- `).join("")})}if(_e(u.filters)===_e(c.filters))continue;const S=Wd(e,c);if(!S)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(S.body.kind==="reference"){const T=ov(e,c,S);if(T)return T;continue}if(S.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${S.body.why}, so there is no single first stage to write its filter into.`};const E=Bd(c.filters,S.body.stage);if(E)return Gd(c.name,E.given);const D=qd(e,c,S.body.stage);if(D)return D}}const El=e=>e.chart==="default"?void 0:e.chart,Bs=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function ev(e,t){const n=new Map(e.tiles.map(r=>[tt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(tt(r));return xe(r)&&r.chart===void 0&&s&&xe(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function xs(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function tv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!ge.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=xs(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const ki=e=>`##|(markdown) ${e.name}
114
+ `:"";a.push({start:_,end:_,text:g+v}),l=x}}function cv(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||Me(d)||Me(l)||be(Xs(l))===be(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=Xm(c,d.source,d.name);if(u<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:h}=qr(c,t,u),p=s(u),v=Bu(d,!1),x=new Map(v.map(D=>[ks(D)??D,D])),_=new Set,g=Lu(d.chart),y=Cl(l)!==Cl(d);if(y){const D=h.filter(P=>S.mentionsChartTag(P.text)),E=h.filter(P=>S.parseChartLine(P.text)),R=l.chart==="custom"?h.filter(P=>S.parseChartLine(P.text)||S.mentionsChartTag(P.text)):D.length>0?D:E.length>1?E:[];if(R.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${R.map(P=>P.text).join(" and ")}), so its chart cannot be changed here.`}}let w=!1;for(const D of h){if(y&&S.parseChartLine(D.text)){g===void 0?a.push({...r(D.line),text:""}):D.text!==S.chartLineText(g,d.chartCarried)&&a.push({...r(D.line),text:`${p}${S.chartLineText(g,d.chartCarried)}
115
+ `}),w=!0;continue}const E=ks(D.text);if(E===void 0||!Km.has(E))continue;const R=x.get(E);if(R===void 0){a.push({...r(D.line),text:""});continue}_.add(E),R!==D.text&&a.push({...r(D.line),text:`${p}${R}
116
+ `})}const b=v.filter(D=>!_.has(ks(D)??D));if(y&&g!==void 0&&!w&&b.push(S.chartLineText(g,d.chartCarried)),b.length>0){const D=n[u];a.push({start:D,end:D,text:b.map(E=>`${p}${E}
117
+ `).join("")})}if(be(l.filters)===be(d.filters))continue;const T=zu(e,d);if(!T)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(T.body.kind==="reference"){const D=mv(e,d,T);if(D)return D;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=Wu(d.filters,T.body.stage);if(C)return Nu(d.name,C.given);const j=Gu(e,d,T.body.stage);if(j)return j}}const Cl=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 dv(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 le(r)&&r.chart===void 0&&s&&le(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function Ss(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 uv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!ge.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=Ss(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const Ci=e=>`##|(markdown) ${e.name}
118
118
  ${e.markdown===""?"":`${e.markdown}
119
119
  `}|##
120
- `;function nv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,l=new Map(s.tiles.filter(je).map(h=>[h.name,h])),d=i.tiles.filter(je),c=h=>o.textBlocks.find(p=>p.name===h),u=new Set(d.map(h=>h.name));for(const h of l.keys()){const p=u.has(h)?void 0:c(h);if(!p)continue;const m=xt(o,p.span.end-1);a.push({...p.span,text:""});const b=r(m+1),x=p.line===0||n[p.line-1].trim()==="";b.end>b.start&&n[m+1].trim()===""&&x?a.push({...b,text:""}):p.line>0&&x&&t.slice(p.span.end).trim()===""&&a.push({...r(p.line-1),text:""})}const f=[];for(const h of d){const p=l.get(h.name),m=c(h.name);if(p===void 0){if(m)return{ok:!1,reason:`A block named \`${h.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(ki(h))}else p.markdown!==h.markdown&&(m?a.push({...m.span,text:ki(h)}):f.push(ki(h)))}if(f.length>0){const h=o.textBlocks.filter(v=>v.name===void 0||u.has(v.name)),p=h[h.length-1],m=o.sources.find(v=>v.name.endsWith("_tiles"));if(p){const v=p.span.end,g=t.slice(v);a.push({start:v,end:v,text:`
121
- ${f.join(`
122
- `)}${g===""||g.startsWith(`
120
+ `;function fv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,c=new Map(s.tiles.filter(Me).map(h=>[h.name,h])),f=i.tiles.filter(Me),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(`
123
123
  `)?"":`
124
- `}`});return}if(m){const v=e.starts[o.blockStart(m.line)],g=v===0||t.slice(0,v).endsWith(`
124
+ `}`});return}if(v){const g=e.starts[o.blockStart(v.line)],y=g===0||t.slice(0,g).endsWith(`
125
125
 
126
- `);a.push({start:v,end:v,text:`${g?"":`
127
- `}${f.join(`
126
+ `);a.push({start:g,end:g,text:`${y?"":`
127
+ `}${u.join(`
128
128
  `)}
129
- `});return}const b=t.length,x=t===""||t.endsWith(`
129
+ `});return}const x=t.length,_=t===""||t.endsWith(`
130
130
 
131
131
  `)?"":t.endsWith(`
132
132
  `)?`
133
133
  `:`
134
134
 
135
- `;a.push({start:b,end:b,text:x+f.join(`
136
- `)})}}const ns=(e,t=ge.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function rv(e,t){const n=new Map(e.tiles.map(o=>[tt(o),o]));if(t.layout==="linear"&&t.columns!==void 0&&t.columns!==e.columns)return"A linear report is one column, so its width is not written.";const r=new Set;for(const o of t.tiles){const a=n.get(tt(o));if(je(o)){const u=tv(o,a&&je(a)?a:void 0,r);if(u)return u;continue}const l=a&&xe(a)?a:void 0;if(a&&!l)continue;const d=o.chart;if(d!==void 0&&d!=="default"&&d!=="none"&&!ni(d)&&!(d==="custom"&&l?.chart==="custom"))return`"${String(d)}" is not a chart this editor writes.`;const c=new Set(l?.filters?.map(u=>u.field));for(const u of o.filters??[])if(!c.has(u.field)&&/[\r\n]/.test(u.field))return"A filter field is one line.";if(a===void 0){const u=[o.name,o.source];o.declaration.kind==="reference"&&u.push(o.declaration.from);for(const f of u){const h=ns(f);if(h)return h}}for(const u of["label","subtitle"]){const f=o[u];if(f===void 0||f===l?.[u])continue;const h=O.annotationTextProblem(`tile ${u}`,f);if(h)return h}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const l=ns(a);if(l)return l}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=O.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=O.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const d=ns(o.name,ge.isStrictName);if(d)return d}const l=o.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const d=ns(l);if(d)return`The suggest source is not a name. ${d}`}for(const d of["query","dimension"]){const c=o.suggest?.[d];if(c===void 0||c===a?.suggest?.[d])continue;const u=O.annotationTextProblem(`suggest ${d}`,c);if(u)return u}for(const d of["label","description"]){const c=o[d];if(c===void 0||c===i.get(o.name)?.[d])continue;const u=O.annotationTextProblem(`given ${d}`,c);if(u)return u}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const l=O.annotationTextProblem(`starting value for ${o}`,a);if(l)return l}}const xt=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Wd(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Bd(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Gd(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const ws=e=>`where: ${ge.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Cl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function sv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(xt(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function iv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Ta(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
- `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function qd(e,t,n){const{parsed:r,edits:s}=e,i=new Map((t.filters??[]).map(f=>[f.given,f])),o=new Set;let a;for(const f of n.wheres){const h=f.clauses.map((m,b)=>({clause:m,index:b})).filter(({clause:m})=>m.binding!==void 0);if(h.length===0)continue;const p=h.filter(({clause:m})=>i.has(m.binding.given));for(const{clause:m}of h)o.add(m.binding.given);if(p.length===0&&h.length===f.clauses.length){const m=Ta(r,f.span),b=sv(r,f.span,m);if(b)return Cl(t.name,r,b);s.push({...m,text:""});continue}p.length>0&&(a=f.span);for(let m=h.length-1;m>=0;m--){const{clause:b,index:x}=h[m],v=i.get(b.binding.given);if(!v){const y=iv(f.clauses,x),_=r.commentIn(y);if(_)return Cl(t.name,r,_);s.push({...y,text:""});continue}const g=ws(v).replace(/^where:\s*/,"");g!==r.text.slice(b.span.start,b.span.end)&&s.push({...b.span,text:g})}}const l=(t.filters??[]).filter(f=>!o.has(f.given));if(l.length===0)return;let d=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const f=r.trailingComment(xt(r,d));f&&f.start>=d&&(d=f.end)}const c=a!==void 0&&!/,\s*$/.test(r.text.slice(0,d))?", ":" ",u=n.oneLine?`${c}${l.map(ws).join(", ")}`:l.map(f=>`
138
- ${n.indent}${ws(f)}`).join("");s.push({start:d,end:d,text:u})}function ov(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Bd(t.filters,i);if(o)return Gd(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const c=` + { ${a.map(ws).join(", ")} }`;r.push({start:s.end,end:s.end,text:c});return}const l=i.wheres.some(c=>c.clauses.some(u=>!u.binding)),d=i.statements.some(c=>!i.wheres.some(u=>u.span.start===c.span.start));if(a.length===0&&!l&&!d){const c={start:s.end,end:i.span.end},u=e.parsed.commentIn(c);if(u)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(u.start,u.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...c,text:""});return}return qd(e,t,i)}async function Kd(e,t,n={}){if(!(e.includes(`\r
139
- `)&&!/(?<!\r)\n/.test(e)))return Il(e,t,n);const s=await Il(e.replace(/\r\n/g,`
140
- `),t,n);return zs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
- `)}}async function Il(e,t,n){const r=await Cr(e);if(Er(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=ev(s,t),o=Wm(s,i,n.visibleSources);if("reason"in o)return o;const a=rv(s,i);if(a)return{ok:!1,reason:a};const l=await Pd(e);if(Ad(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const d=e.split(`
142
- `),c=Rm(e),u=v=>({start:c[v],end:v+1<c.length?c[v+1]:e.length}),f=v=>/^\s*/.exec(d[v])?.[0]??"",h=[],p={...o,sourceText:e,parsed:l.parsed,lines:d,starts:c,wholeLine:u,indentOf:f,current:s,next:i,edits:h};for(const v of[Gm,Um,Xm,Hm,Ym,Zm,Qm,Jm,nv]){const g=v(p);if(g)return g}const m=v=>{const{drills:g,localGivens:y,description:_,...S}=v,E=v.tiles.map(D=>{if(je(D))return D;if(D.filters?.length)return Bs(D);const{filters:T,...A}=D;return Bs(A)});return{...S,..._===void 0?{}:{description:Ld(_)},tiles:E,...g?.length?{drills:[...g].sort((D,T)=>Ws(D).localeCompare(Ws(T)))}:{},...y?.length?{localGivens:y}:{}}};if(h.length===0)return _e(m(s))!==_e(m(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const b=Lm(e,h);if((await xl(e)).length===0){const v=await xl(b);if(v.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${v[0]}). Your changes are still here.`}}const x=await Cr(b);return Er(x)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${x.reason}`}:_e(m(x.document))!==_e(m(i))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:b}}function Vd({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Be.usePublisherTheme(),[i,o]=k.useState(!1),a=k.useMemo(()=>i?{text:e}:void 0,[i,e]),{draft:l,patch:d,close:c,discard:u}=Vl(a,i,g=>n(g.text),()=>o(!1)),f=i&&l!==void 0&&l.text!==e,h=l!==void 0&&l.text!==e?xs(l.text):void 0;pd(f,()=>h!==void 0?!1:(c(),!0));const p=k.useRef(null),m=k.useRef(!1);k.useEffect(()=>{i||(m.current=!1)},[i]);const b=k.useCallback(g=>{!g||m.current||(m.current=!0,g.setSelectionRange(g.value.length,g.value.length))},[]);if(!i||l===void 0){const g=e.trim()?xs(e):void 0;return w.jsxs($.Box,{role:"button",tabIndex:0,onClick:y=>{y.target.closest("a")?y.preventDefault():o(!0)},onKeyDown:y=>{y.target===y.currentTarget&&(y.key!=="Enter"&&y.key!==" "||(y.preventDefault(),o(!0)))},sx:[{minHeight:24},fd(s,"prose")],children:[e.trim()?w.jsx(O.Prose,{variant:r,children:e}):w.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),g&&w.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:g})]})}const x=l.text!==e?xs(l.text):void 0,v=()=>{x===void 0&&c()};return w.jsxs($.Stack,{spacing:1,children:[w.jsx($.TextField,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:x!==void 0,helperText:x,inputRef:b,inputProps:{"aria-label":"Markdown"},onChange:g=>d(y=>{y.text=g.target.value}),onKeyDown:g=>{g.key==="Escape"?v():g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&(g.preventDefault(),v())},onBlur:g=>{g.relatedTarget instanceof Node&&p.current?.contains(g.relatedTarget)||c()}}),w.jsxs($.Stack,{ref:p,direction:"row",spacing:1,children:[w.jsx($.Button,{size:"small",variant:"outlined",disabled:x!==void 0,onClick:v,children:"Done"}),w.jsx($.Button,{size:"small",onMouseDown:g=>g.preventDefault(),onClick:()=>{u(),o(!1)},children:"Cancel"})]})]})}const av="Write markdown: # heading, **bold**, - list";function lv({tile:e,onChange:t,chrome:n="card"}){return w.jsx(O.TileCard,{chrome:n,kind:"text",children:w.jsx(Vd,{markdown:e.markdown,placeholder:av,onCommit:t})})}const Gs=e=>e.label??O.tileTitle(`${e.source} -> ${e.name}`);function cv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:l,resizing:d=!1,width:c,onResizeStart:u,onResizeMove:f,onResizeEnd:h,children:p}){const{theme:m}=Be.usePublisherTheme();return w.jsx(om,{id:Fe(e),index:t,children:({ref:b,handleRef:x})=>w.jsxs($.Box,{ref:b,onClick:a,onPointerDown:v=>{v.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ud(m,{selected:n,flash:r,bare:i}),"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:m.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${m.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[p,w.jsx($.Box,{ref:x,"aria-label":`Move ${Kr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),w.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Kr(e)}`,onClick:v=>{v.stopPropagation(),l(v.currentTarget)},sx:{position:"absolute",top:`${-((i?O.BARE_RING_OFFSET_PX+1:0)+12)}px`,right:i?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||s?.9:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover":{opacity:1,bgcolor:m.tile}},children:w.jsx(hv,{})}),u&&w.jsx($.Box,{className:"builder-affordance",[Ed]:"",role:"separator",tabIndex:c?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Kr(e)}`,...c?{"aria-valuenow":c.span,"aria-valuemin":1,"aria-valuemax":c.columns,"aria-valuetext":`${c.span} of ${c.columns} columns`}:{},onKeyDown:v=>{if(!c)return;const g=v.key==="ArrowRight"?c.span+1:v.key==="ArrowLeft"?c.span-1:v.key==="Home"?1:v.key==="End"?c.columns:void 0;g!==void 0&&(v.preventDefault(),v.stopPropagation(),c.onStep(Math.min(Math.max(g,1),c.columns)))},onPointerDown:u,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onClick:v=>v.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:d||n?1:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${m.accent}`,outlineOffset:1,borderRadius:"3px"},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:m.accent}}}),o&&w.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Kr(e)}`,onClick:v=>{v.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(i?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX)/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:m.tileTitle,bgcolor:m.tile,border:m.cardBorder,opacity:0,transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:w.jsx(O.AddIcon,{sx:{fontSize:14}})})]})})}const Si=4,Ud=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const s=t||n?e.accent:"transparent",i=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${O.MOTION_FAST}, border-color ${O.MOTION_FAST}, opacity ${O.MOTION_FAST}, box-shadow ${O.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-O.BARE_RING_OFFSET_PX}px`,borderRadius:1,border:`2px solid ${s}`,pointerEvents:"none",transition:o,...O.reducedMotionSx},"&:hover::before":{borderColor:i}}:{borderRadius:1,outline:`2px solid ${s}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...O.reducedMotionSx,"&:hover":{outlineColor:i,boxShadow:e.shadow.lift}}};function uv({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Be.usePublisherTheme();return w.jsxs(O.TileCard,{chrome:r,children:[w.jsx(O.TileHeading,{title:t?.title??Gs(e),subtitle:t?t.subtitle:e.subtitle}),n&&w.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),w.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function dv({after:e}){const{theme:t}=Be.usePublisherTheme();return w.jsx(am,{id:md(e),after:e,children:({ref:n,isDropTarget:r})=>w.jsx($.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${O.MOTION_FAST}, background-color ${O.MOTION_FAST}`,...O.reducedMotionSx}})})}function fv({columns:e}){const{theme:t}=Be.usePublisherTheme();return w.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${O.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>w.jsx($.Box,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function hv(){return w.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[w.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),w.jsx("circle",{cx:"12",cy:"12",r:"2"}),w.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function pv({editor:e,reorder:t,resizing:n,gridBox:r,columns:s,notebook:i,chrome:o,canAdd:a,selected:l,flash:d,menuIndex:c,onSelect:u,onOpenMenu:f,openAdd:h,editTile:p,renderTile:m}){const{dragging:b,preview:x,onDragStart:v,onDragOver:g,onDragEnd:y}=t,{resize:_,startResize:S,onResize:E,endResize:D}=n,T=_!==void 0?e.document.tiles.map((z,U)=>U===_.index?{...z,colspan:_.span}:z):x??e.document.tiles,A=e.document.tiles.length===0,q=b||_!==void 0?Og(T,s):T.map(gd),P=z=>gv(z,Gs(z),p);return w.jsxs(w.Fragment,{children:[w.jsx(lg,{sensors:sm,onDragStart:v,onDragOver:g,onDragEnd:y,children:w.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[!i&&(b||_!==void 0)&&w.jsx(fv,{columns:s}),w.jsx(O.DashboardGrid,{tiles:q,columns:s,rowGapPx:o==="none"?O.NOTEBOOK_GAP_PX:O.GRID_GAP_PX,keyOf:z=>z.kind==="gap"?md(z.after):Fe(z.tile),renderTile:z=>{if(z.kind==="gap")return w.jsx(dv,{after:z.after});const{tile:U,index:K}=z;return w.jsx(cv,{tile:U,index:K,selected:K===l,flash:Fe(U)===d,menuOpen:c===K,bare:o==="none",...i&&a&&K<e.document.tiles.length-1?{onInsertAfter:()=>h(K+1)}:{},...s>1&&mv(U)?{resizing:_?.index===K,width:{span:U.colspan??1,columns:s,onStep:Z=>{Z!==(U.colspan??1)&&e.update(J=>{const ie=J.tiles[K];ie&&(ie.colspan=Z)})}},onResizeStart:Z=>S(Z,K),onResizeMove:E,onResizeEnd:D}:{},onSelect:()=>u(K),onOpenMenu:Z=>f(Z,K),children:je(U)?w.jsx(lv,{tile:U,chrome:o,onChange:Z=>p(Fe(U),J=>{je(J)&&(J.markdown=Z)})}):m&&!e.pendingOpen?m(U,P(U),o):w.jsx(uv,{tile:U,chrome:o,heading:P(U),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),i&&a&&!A&&w.jsx($.Button,{size:"small",startIcon:w.jsx(O.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>h(),sx:{alignSelf:"center"},children:"Add tile"})]})}const gv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{xe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:w.jsx(go,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:w.jsx(go,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},mv=e=>je(e)||e.declaration.kind!=="inherited";function vv({editor:e,documentSlug:t,chrome:n,actions:r,descriptionSelected:s,selectDescription:i}){const{theme:o}=Be.usePublisherTheme();return w.jsxs(w.Fragment,{children:[w.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:2},children:[w.jsx($.Typography,{variant:"h5",sx:{flex:1,minWidth:0},children:w.jsx(go,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:a=>e.update(l=>{l.title=a})})}),w.jsx($.Box,{sx:{my:"-4px"},children:r})]}),w.jsx($.Box,{role:"group","aria-label":"Description","aria-current":s,onPointerDown:i,onFocus:i,sx:n==="none"?{my:`${O.BARE_DESCRIPTION_MARGIN_PX}px`}:void 0,children:w.jsx(O.TileCard,{chrome:n,kind:"text",sx:{position:"relative",overflow:"visible",...Ud(o,{selected:s,bare:n==="none"})},children:w.jsx(Vd,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:a=>e.update(l=>{a.trim()===""?delete l.description:l.description=a})})})})]})}const yv=({size:e,path:t,layout:n,savesTo:r,onEvent:s})=>{const{emit:i}=O.reportEmitter({path:t,layout:n},s);return{size:e,saved:({size:o,structural:a,durationMs:l,fromOpen:d})=>i({type:"report.saved",tiles:o,structural:a,...d?{converted:!0}:{},where:r,durationMs:l}),refused:o=>i({type:"report.save_refused",reason:o}),undone:({size:o,structural:a,durationMs:l})=>i({type:"report.save_undone",tiles:o,structural:a,where:r,durationMs:l}),undoRefused:o=>i({type:"report.save_undo_refused",reason:o})}},bv=O.createSvgIcon(w.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),xv=O.createSvgIcon(w.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),wo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),$i=wo?"⌘":"Ctrl+",Al=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},Ti=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function wv(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=wo?i.metaKey:i.ctrlKey,l=i.key.toLowerCase();if(i.key==="Escape"){if(Al(i.target)||Ti(i.target))return;o.escape();return}if(Al(i.target)){if(a&&l==="s"){if(i.preventDefault(),!o.save||Ti(i.target))return;i.target.blur(),r(!0)}return}if(Ti(i.target)){a&&l==="s"&&i.preventDefault();return}if(a&&l==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!wo&&a&&l==="y"){i.preventDefault(),o.redo();return}if(a&&l==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Dl={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function _v({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:l,saveButton:d,actions:c,onAddTile:u,onExit:f,layout:h,onLayoutChange:p}){return w.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[h&&p&&w.jsxs(w.Fragment,{children:[w.jsx($.Tooltip,{title:"Layout: tiles side by side, or one after another",children:w.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:h,"aria-label":"Layout",onChange:(m,b)=>{b&&b!==h&&p(b)},sx:{"& .MuiToggleButton-root":{py:.25,px:1}},children:[w.jsx($.ToggleButton,{value:"linear","aria-label":"Linear layout",children:"Linear"}),w.jsx($.ToggleButton,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}})]}),u&&w.jsx($.Button,{startIcon:w.jsx(O.AddIcon,{}),onClick:u,"aria-label":"Add tile",children:"Tile"}),u&&w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),w.jsx($.Tooltip,{title:`Undo (${$i}Z)`,children:w.jsx("span",{children:w.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:w.jsx(xv,{fontSize:"small"})})})}),w.jsx($.Tooltip,{title:`Redo (${$i}⇧Z)`,children:w.jsx("span",{children:w.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:w.jsx(bv,{fontSize:"small"})})})}),(c||o||f)&&w.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),c,o?w.jsx($.Tooltip,{title:s?`Save (${$i}S) · ${l??Dl[a]}`:l??Dl[a],children:w.jsx("span",{children:w.jsx($.Button,{ref:d,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{minWidth:124},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&w.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),f&&w.jsx(O.SecondaryButton,{label:"Close",icon:w.jsx(O.CheckIcon,{}),onClick:f})]})}const kv=O.createSvgIcon(w.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),Sv=O.createSvgIcon(w.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function $v({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:s,addDisabledReason:i,onRemove:o,sticky:a=!0,children:l}){const{theme:d}=Be.usePublisherTheme();return w.jsx(w.Fragment,{children:w.jsx(O.StickyControls,{sticky:a,children:w.jsxs($.Stack,{sx:{gap:1},children:[w.jsx($.Stack,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:w.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[w.jsx(Sv,{sx:{fontSize:18,color:d.tileTitle,opacity:.7}}),w.jsx($.Typography,{variant:"subtitle2",sx:{color:d.tileTitle,mr:.5},children:"Filters"}),e.length===0&&w.jsx($.Typography,{variant:"body2",sx:{color:d.tileTitle,opacity:.8},children:"None yet."}),e.map(c=>{const u=n(c.name,c.type);return w.jsx($.Tooltip,{title:u.length>0?`$${c.name} · cannot filter on: ${u.join(", ")}`:`$${c.name} · ${c.origin==="dashboard"?"declared here":"from the model"} · ${c.boundTiles} of ${t} tiles`,children:w.jsx($.Chip,{size:"small",label:`${c.label??c.name}${c.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${c.name}`,color:u.length>0?"warning":"default",variant:c.origin==="dashboard"?"filled":"outlined",onClick:()=>r(c),onDelete:()=>o(c.name),deleteIcon:w.jsx(kv,{"aria-label":`Remove filter ${c.name}`}),sx:{opacity:c.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${O.MOTION_FAST}`,...O.reducedMotionSx}})},c.name)}),w.jsx($.Tooltip,{title:i??"",children:w.jsx("span",{children:w.jsx($.Chip,{component:"button",size:"small",variant:"outlined",icon:w.jsx(O.AddIcon,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:i!==void 0,onClick:()=>s(),sx:{cursor:"pointer",color:d.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),l]})})})}function Tv(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Ov({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(m=>r(b=>typeof b=="object"&&b.tile===m?b:{tile:m}),[]),a=k.useCallback(()=>r(m=>m==="description"?m:void 0),[]),l=k.useCallback(()=>r("description"),[]),d=k.useCallback(()=>r(void 0),[]),[c,u]=k.useState(void 0),f=k.useRef(!1),h=k.useRef(e.document);k.useEffect(()=>{const m=h.current;if(h.current=e.document,!f.current)return;f.current=!1;const b=Tv(m,e.document);if(b===void 0)return;u(b),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===b)?.scrollIntoView?.({block:"nearest",behavior:O.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(c===void 0)return;const m=setTimeout(()=>u(void 0),1500);return()=>clearTimeout(m)},[c]);const p=k.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:l,clearSelection:d,flash:c,stepEditor:p}}function Ev({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,l]=k.useState(!1),d=k.useRef(r);d.current=r;const c=k.useRef(s);c.current=s;const u=k.useRef(0),f=k.useCallback(async()=>{const p=++u.current;l(!1),o("saving");try{await d.current()}catch{u.current===p&&o("idle");return}u.current===p&&l(!0)},[]);return k.useEffect(()=>{if(i==="waiting"){if(t)return;e?f():(o("idle"),c.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||c.current()}},[i,a,t,e,f]),{requestExit:k.useCallback(()=>{i==="idle"&&(e?o("asking"):c.current())},[i,e]),dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),c.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):f())}}}}function Cv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,report:o,unit:a,prepare:l,shortcuts:d}){const[c,u]=k.useState(!1),[f,h]=k.useState(!1),p=k.useRef(null),m=k.useRef(o);m.current=o;const b=e.dirty||i,x=(e.edited??e.dirty)||i;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(x)},[x,n]);const v=k.useRef(n);v.current=n,k.useEffect(()=>()=>v.current?.(!1),[]);const g=k.useRef(a);g.current=a,k.useEffect(()=>{h(!1)},[e.document]);const y=k.useCallback(()=>{u(!0),h(!1);const K=O.now(),{structural:Z}=e,J=e.pendingOpen??!1,ie=m.current.size;return e.save().then(de=>{de.ok===!0?m.current.saved({size:ie,structural:Z,fromOpen:J,durationMs:O.now()-K}):m.current.refused(de.reason)}).finally(()=>u(!1))},[e]),_=k.useRef(!1),S=k.useRef(!1);k.useEffect(()=>{!S.current||c||(S.current=!1,p.current?.focus())},[f,c]);const E=k.useCallback(()=>{if(!t||c||_.current||!e.canUndoSave)return;_.current=!0,u(!0);const K=O.now(),Z=e.lastSave?.structural??!1,J=m.current.size;return e.undoSave().then(ie=>{ie.ok===!0?(S.current=!0,h(!0),m.current.undone({size:J,structural:Z,fromOpen:!1,durationMs:O.now()-K})):m.current.undoRefused(ie.reason)}).finally(()=>{_.current=!1,u(!1)})},[t,c,e]),D=k.useCallback(()=>{if(!(!t||!e.dirty||c))return y()},[t,e,c,y]),T=k.useRef(D);T.current=D;const A=k.useCallback(()=>{const K=()=>T.current();return l?l(K):K()},[l]),q=Ev({dirty:x,saving:c,canSave:!!t,save:A,onExit:()=>r?.()});wv(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:A}:{},paused:q.dialog.open}),[d,e,t,A,q.dialog.open]));const P=!!t&&!c&&e.canUndoSave,z=e.lastSave,U={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:b,saving:c,saveButton:p,...t?{onSave:A}:{},...r?{onExit:q.requestExit}:{}};return{saving:c,save:A,exitGuard:q,undoSave:E,canUndoSave:P,lastSave:z,toolbarProps:U}}function rs(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Ml(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&Cd.includes(n))return n}}const Iv=1;function Hd(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Hd(a,`${t}${i}.`,n-1))}}}return r}function Av(e){const t=new Map;for(const n of Xd(e))t.set(n.name,Hd(n.schema?.fields,"",Iv));return t}function Xd(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Dv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&rf.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Mv(e){const t=new Map;for(const n of Xd(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Dv)&&r.add(s.name)}t.set(n.name,r)}return t}function Pl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const jl=(e,t)=>e!==void 0&&t.has(e),Rl=e=>e.modelPath??e.path??"";function Yd(e,t=new Set){const n=[],r=new Set,s=new Map,i=new Map,o=new Map;for(const a of e){const l=Rl(a);if(jl(l,t))continue;const d=O.exportedSources(a.modelInfo);i.set(a,d);for(const{name:c}of a.sources??[])c&&o.set(c,[...o.get(c)??[],l]);for(const c of d)s.set(c,[...s.get(c)??[],l])}for(const a of e){const l=Rl(a);if(jl(l,t))continue;const d=Av(a),c=Mv(a);for(const u of a.sources??[]){const f=u.name;if(!f||!i.get(a)?.has(f)||r.has(f))continue;r.add(f);const h=(u.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");n.push({name:f,modelPath:l,exporters:s.get(f)??[l],visibleIn:o.get(f)??[l],...rs(u.annotations)?{description:rs(u.annotations)}:{},views:(u.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...rs(p.annotations)?{description:rs(p.annotations)}:{},...Ml(p.annotations)?{chart:Ml(p.annotations)}:{},...c.get(f)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:h,fields:d.get(f)??[]})}}return{sources:n}}function Pv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const p=new Set((t.localGivens??[]).map(m=>m.name));return(n??[]).filter(m=>!p.has(m.name))},[t,n]),a=k.useMemo(()=>uf(e.document,o),[e.document,o]),l=k.useMemo(()=>new Map(e.document.sources.map(p=>[p.name,Pl(r,p.base)])),[r,e.document.sources]),d=k.useCallback(p=>l.get(p.source)??Pl(r,p.source),[l,r]),c=(p,m)=>{const b=[];for(const x of e.document.tiles){if(!xe(x))continue;const v=d(x);if(!v)continue;const g=new Map(v.map(y=>[y.name,y.type]));for(const y of x.filters??[])y.given===p&&(!g.has(y.field)||!as(m,g.get(y.field)))&&b.push(`${y.field} on ${x.label??x.name} (${e.document.sources.find(_=>_.name===x.source)?.base??x.source})`)}return b},u=k.useMemo(()=>a.filter(p=>p.origin==="model"&&p.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:d,unknownFieldsOf:c,available:u,applyFilter:(p,m,b)=>{i(void 0),e.update(x=>{b&&vf(x,b),mf(x,p,m)})},dropControl:p=>{i(void 0),e.update(m=>yf(m,p))}}}function jv({pendingOpen:e,prepare:t}){const[n,r]=k.useState(void 0),s=k.useRef(e);s.current=e;const i=k.useCallback(o=>s.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:i}}function Rv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s,opensDirty:i=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,d]=k.useState(e.source),[c,u]=k.useState(void 0),[f,h]=k.useState(e.document),[p,m]=k.useState(i),[b,x]=k.useState(e.replaces),[v,g]=k.useState(!1),y=o.stack[o.index],_=k.useRef(o);_.current=o;const S=k.useRef(!1),[E,D]=k.useState(!1),T=j=>{S.current=j,D(j)},[A,q]=k.useState(void 0),P=k.useCallback(j=>{u(void 0),a(G=>{const ne=structuredClone(G.stack[G.index]);if(j(ne),JSON.stringify(ne)===JSON.stringify(G.stack[G.index]))return G;const H=[...G.stack.slice(0,G.index+1),ne].slice(-100);return{stack:H,index:H.length-1}})},[]),z=k.useCallback(()=>{u(void 0),a(j=>j.index>0?{...j,index:j.index-1}:j)},[]),U=k.useCallback(()=>{u(void 0),a(j=>j.index<j.stack.length-1?{...j,index:j.index+1}:j)},[]),K=k.useCallback(async(j,G)=>{try{return await t(j,G)}catch(ne){return{ok:!1,reason:`Could not build the file: ${ne instanceof Error?ne.message:String(ne)}`}}},[t]),Z=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};const j={source:l,saved:f,history:_.current,pendingOpen:p,replacing:b,unwritten:v},G=s?.(f,y)??!1,ne=r?.(f,y)??!1;T(!0);try{const Y=await K(l,y);if(zs(Y))return u(Y.reason),{ok:!1,reason:Y.reason};try{await n?.(Y.source,{purpose:"save",document:y})}catch(L){const C=`Could not save: ${L instanceof Error?L.message:String(L)}`;return u(C),{ok:!1,reason:C}}d(Y.source),h(y),m(!1),x(void 0),g(!1);const H=G?{stack:[y],index:0}:j.history;return a(L=>L===j.history?H:G?{stack:[L.stack[L.index]],index:0}:L),q(n?{before:j,after:H,lastSave:{before:b??l,after:Y.source,structural:ne,clearsHistory:G}}:void 0),u(void 0),{ok:!0}}finally{T(!1)}},[y,K,n,l,f,p,b,v,s,r]),J=k.useCallback(async()=>{if(S.current)return{ok:!1,reason:"A save is still being written."};if(!n||A===void 0||A.after!==_.current)return{ok:!1,reason:"There is no save to undo."};const{before:j}=A;T(!0);try{await n(j.replacing??j.source,{purpose:"undo",document:j.saved})}catch(G){const ne=`Could not undo the save: ${G instanceof Error?G.message:String(G)}`;return u(ne),{ok:!1,reason:ne}}finally{T(!1)}return d(j.source),h(j.saved),m(j.pendingOpen),x(j.replacing),g(j.unwritten||j.replacing!==void 0),a(G=>G===A.after?j.history:G),q(void 0),u(void 0),{ok:!0}},[n,A]),ie=k.useMemo(()=>v||JSON.stringify(y)!==JSON.stringify(f),[y,f,v]),de=k.useMemo(()=>r?.(f,y)??!1,[y,f,r]),I=k.useMemo(()=>s?.(f,y)??!1,[y,f,s]),V=A!==void 0&&A.after===o,B=k.useCallback(async()=>{const j=await K(l,y);return zs(j)?{ok:!1,reason:j.reason}:{ok:!0,source:j.source}},[y,K,l]);return{document:y,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:ie||p,edited:ie,pendingOpen:p,...c===void 0?{}:{error:c},update:P,undo:z,redo:U,save:Z,preview:B,structural:de,clearsHistory:I,canUndoSave:V&&!E&&n!==void 0,...V?{lastSave:A.lastSave}:{},undoSave:J}}const Lv=(e,t)=>{const n=new Set(e.tiles.map(xo)),r=new Set(t.tiles.map(xo));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Nv(e){const{conversion:t,visibleSources:n,...r}=e,s=t?.from,i=t?.to,o=k.useCallback((a,l)=>Kd(s!==void 0&&a===s?i:a,l,n?{visibleSources:n}:{}),[s,i,n]);return Rv({...r,splice:o,structural:Lv,opensDirty:t!==void 0})}function Fv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}function zv(e,t,{modelPath:n,textHeld:r,notebook:s,insertAt:i}){t.modelPath&&!r&&(e.imports=O.withSource(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(d=>d.base===t.base);if(!o){const d=new Set(e.sources.map(u=>u.name));let c=`${t.base}_tiles`;for(let u=2;d.has(c);u++)c=`${t.base}_tiles_${u}`;o={name:c,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(xe).filter(d=>d.source===o.name).map(d=>d.name));let l=`${t.view}_tile`;for(let d=2;a.has(l);d++)l=`${t.view}_tile_${d}`;e.tiles.splice(i??e.tiles.length,0,{name:l,source:o.name,declaration:{kind:"reference",from:t.view},...s?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function Wv({editor:e,notebook:t,columns:n,modelPath:r,textHeld:s,selectTile:i,deselectTile:o}){const[a,l]=k.useState(void 0),[d,c]=k.useState(!1),[u,f]=k.useState(void 0);return{menu:a,setMenu:l,addingTile:d,openAdd:g=>{f(g),c(!0)},closeAdd:()=>c(!1),addTile:g=>{c(!1),e.update(y=>zv(y,g,{modelPath:r,textHeld:s,notebook:t,insertAt:u})),i(u??e.document.tiles.length)},addText:()=>{c(!1),e.update(g=>{const y=new Set(g.tiles.filter(je).map(S=>S.name));let _=1;for(;y.has(`text_${_}`);)_++;g.tiles.splice(u??g.tiles.length,0,{kind:"text",name:`text_${_}`,markdown:"",...t?{}:{colspan:n}})}),i(u??e.document.tiles.length)},editTile:(g,y)=>e.update(_=>{const S=_.tiles.find(E=>Fe(E)===g);S&&y(S)}),removeTile:g=>{l(void 0),o(),e.update(y=>{y.tiles.splice(g,1)})}}}var Bv=Object.defineProperty,Gv=Object.defineProperties,qv=Object.getOwnPropertyDescriptors,Ll=Object.getOwnPropertySymbols,Kv=Object.prototype.hasOwnProperty,Vv=Object.prototype.propertyIsEnumerable,Nl=(e,t,n)=>t in e?Bv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t)=>{for(var n in t||(t={}))Kv.call(t,n)&&Nl(e,n,t[n]);if(Ll)for(var n of Ll(t))Vv.call(t,n)&&Nl(e,n,t[n]);return e},ln=(e,t)=>Gv(e,qv(t));function Uv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function ss(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Oi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Hv(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,y)=>g===y||g!==null&&typeof g=="object"&&"id"in g&&g.id===y;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),y=e.findIndex(_=>l(_,o.id));if(g===-1||y===-1){if(Oi(i)){const _=i.initialIndex,S=i.index;return _===S||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,S)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,y)}const d=Object.entries(e);let c=-1,u,f=-1,h;for(const[g,y]of d)if(c===-1&&(c=y.findIndex(_=>l(_,i.id)),c!==-1&&(u=g)),f===-1&&(f=y.findIndex(_=>l(_,o.id)),f!==-1&&(h=g)),c!==-1&&f!==-1)break;if(c===-1&&Oi(i)){const g=i.initialGroup==null?void 0:ss(e,i.initialGroup),y=i.initialIndex,_=i.group==null?void 0:ss(e,i.group),S=i.index;if(g==null||_==null||g===_&&y===S)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return ln(an({},e),{[g]:n(e[g],y,S)});const E=e[g][y];return ln(an({},e),{[g]:[...e[g].slice(0,y),...e[g].slice(y+1)],[_]:[...e[_].slice(0,S),E,...e[_].slice(S)]})}if(!i.manager)return e;const{dragOperation:p}=i.manager,m=(s=(r=p.shape)==null?void 0:r.current.center)!=null?s:p.position.current;if(h==null){const g=ss(e,o.id);if(g!=null){const y=o.shape&&m.y>o.shape.center.y?e[g].length:0;h=g,f=y}}if(u==null||h==null||u===h&&c===f){if(u!=null&&u===h&&c===f&&Oi(i)){const g=i.group==null?void 0:ss(e,i.group),y=i.group!=null&&g!==u,_=i.index!==c;if(y||_){const S=i.group==null?u:g;if(S!=null){if(u===S)return ln(an({},e),{[u]:n(e[u],c,i.index)});const E=e[u][c];return ln(an({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[S]:[...e[S].slice(0,i.index),E,...e[S].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(u===h)return ln(an({},e),{[u]:n(e[u],c,f)});const x=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[u][c];return ln(an({},e),{[u]:[...e[u].slice(0,c),...e[u].slice(c+1)],[h]:[...e[h].slice(0,f+x),v,...e[h].slice(f+x)]})}function Xv(e,t){return Hv(e,t,Uv)}function Yv({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:u=>{const{source:f,target:h}=u.operation;if(!f||!h)return;const p=i.current??e;let m;if(h.type===Od){const{after:b}=h.data,x=p.findIndex(y=>Fe(y)===f.id);if(x<0||b===f.id)return;const g=p.filter((y,_)=>_!==x).findIndex(y=>Fe(y)===b)+1;m=Tg(p,x,g)}else{const b=p.map(Fe),x=Xv(b,u);if(x.every((g,y)=>g===b[y]))return;const v=new Map(p.map(g=>[Fe(g),g]));m=$g(x.map(g=>v.get(g)),e.map(g=>g.break??!1))}i.current=m,s(m)},onDragEnd:u=>{a(!1);const f=i.current;if(i.current=void 0,s(void 0),u.canceled||!f)return;t(f);const h=f.findIndex(p=>Fe(p)===u.operation.source?.id);h>=0&&n(h)}}}const Ei=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Zv({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),l=f=>{a.current=f,o(f)};return k.useEffect(()=>()=>Ei(!1),[]),{resize:i,startResize:(f,h)=>{const p=n.current?.getBoundingClientRect(),m=f.currentTarget.parentElement?.getBoundingClientRect();if(!p||!m)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),Ei(!0),r(h);const b=e[h]?.colspan??1;l({index:h,span:b,from:b,left:m.left,track:(p.width-O.GRID_GAP_PX*(t-1))/t})},onResize:f=>{const h=a.current;if(!h)return;const p=f.clientX-h.left,m=Math.round((p+O.GRID_GAP_PX)/(h.track+O.GRID_GAP_PX)),b=Math.min(Math.max(m,1),t);b!==h.span&&l({...h,span:b})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),Ei(!1);const h=a.current;if(!h)return;const{index:p,span:m,from:b}=h;l(void 0),!(f.type==="pointercancel"||m===b)&&s(p,m)}}}function Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,allowLayoutChange:o=!0,renderTile:a,controls:l,givens:d,catalog:c,toolbar:u,dashboards:f,onEvent:h,conversion:p,savesTo:m="package",saveLabel:b,replaces:x,modelPath:v,visibleSources:g,addFilterDisabledReason:y}){const _=Nv({source:e,document:t,...n?{onSave:n}:{},...p?{conversion:p}:{},...x!==void 0?{replaces:x}:{},...g?{visibleSources:g}:{}}),S=k.useRef(null),{selected:E,descriptionSelected:D,selectTile:T,deselectTile:A,selectDescription:q,clearSelection:P,flash:z,stepEditor:U}=Ov({editor:_,gridBox:S}),K=_.document.layout==="linear",Z=K?1:_.document.columns??O.DEFAULT_COLUMNS,J=K?"none":"card",ie=v?.split("/").at(-1)?.replace(/\.malloy$/,""),de=Yv({tiles:_.document.tiles,commit:te=>_.update(R=>{R.tiles=te}),onLanded:T}),{dragging:I}=de,V=Zv({tiles:_.document.tiles,columns:Z,gridBox:S,onStart:T,commit:(te,R)=>_.update(F=>{const re=F.tiles[te];re&&(re.colspan=R)})}),B=Wv({editor:_,notebook:K,columns:Z,modelPath:v,textHeld:g!==void 0,selectTile:T,deselectTile:A}),{menu:j,addingTile:G,openAdd:ne}=B,Y=Pv({editor:_,opened:t,givens:d,catalog:c}),{filterDialog:H,setFilterDialog:L}=Y,[C,W]=k.useState(void 0),{draftDirty:M,openDraft:ee,prepare:X}=Fv({editorDirty:_.dirty}),{confirmConversion:le,prepareSave:ce}=jv({pendingOpen:_.pendingOpen,prepare:X}),N=k.useMemo(()=>({escape:()=>{!j&&!H&&!G&&C===void 0&&le===void 0&&P()},nudge:te=>{if(I||E===void 0||K)return;const R=_.document.tiles[E];if(!R||xe(R)&&R.declaration.kind==="inherited")return;const F=O.nudgedSpan(R.colspan??1,te,Z);F!==(R.colspan??1)&&_.update(re=>{re.tiles[E].colspan=F})}}),[_,j,H,G,C,le,P,E,Z,K,I]),Q=Cv({editor:U,extraDirty:M,prepare:ce,unit:{name:"tile",count:te=>te.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:N,report:yv({size:_.document.tiles.length,path:v??"",layout:_.document.layout,savesTo:m,onEvent:h})}),me=_.document.tiles.length===0,se=w.jsx(_v,{...Q.toolbarProps,...u?{actions:u}:{},...c?{onAddTile:()=>ne()}:{},savesTo:m,...b?{saveLabel:b}:{},...g===void 0&&o?{layout:_.document.layout,onLayoutChange:te=>{const R=_.document.layout;te!==R&&(_.update(F=>{F.layout=te}),O.reportEmitter({path:v??"",layout:te},h).emit({type:"report.layout_changed",from:R,to:te}))}}:{}});return w.jsx(hd.Provider,{value:ee,children:w.jsx($.Stack,{sx:{gap:0,mx:`-${Si}px`},children:w.jsxs($.Stack,{sx:{gap:2,px:`${Si}px`,pb:`${Si}px`},children:[_.pendingOpen&&w.jsx($.Alert,{severity:"info",children:"This report is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view."}),w.jsx(vv,{editor:_,notebook:K,documentSlug:ie,chrome:J,actions:se,descriptionSelected:D,selectDescription:q}),me?w.jsx(w.Fragment,{children:w.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[w.jsx($.Typography,{variant:"body2",children:"This report is not served until it has a tile."}),c&&w.jsx($.Button,{size:"small",startIcon:w.jsx(O.AddIcon,{}),onClick:()=>ne(),children:"Add tile"})]})}):w.jsx($v,{sticky:!K,controls:Y.controlList,tileCount:_.document.tiles.length,unknownFieldsOf:Y.unknownFieldsOf,onEdit:te=>L({control:te}),onAdd:()=>L({}),...y?{addDisabledReason:y}:{},onRemove:Y.dropControl,children:l}),_.error&&w.jsx($.Alert,{severity:"warning",children:_.error}),w.jsx(pv,{editor:_,reorder:de,resizing:V,gridBox:S,columns:Z,notebook:K,chrome:J,canAdd:!!c,selected:E,flash:z,menuIndex:j?.index,onSelect:T,onOpenMenu:(te,R)=>{T(R),B.setMenu({anchor:te,index:R})},openAdd:ne,editTile:B.editTile,...a?{renderTile:a}:{}}),w.jsx($f,{editor:_,catalog:c,columns:Z,dashboards:f,bindings:Y,tiles:B,drillSource:C,setDrillSource:W,confirmConversion:le,exitDialog:Q.exitGuard.dialog})]})})})}function Qv(e,t){const n=new Set;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.add(o.given);const r=[],s=new Set;for(const i of e.localGivens??[])n.has(i.name)&&(s.add(i.name),r.push(Jv(i)));for(const i of t)i.name===void 0||s.has(i.name)||!n.has(i.name)||(s.add(i.name),r.push(i));return r}function Jv(e){const t=ey(e);return{name:e.name,type:e.type,...t===void 0?{}:{default:t},...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function ey(e){if(!e.type?.startsWith("filter<"))return e.default;const t=e.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];return t===void 0?e.default:t===""?void 0:t}function ty(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function is(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function ny(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),l=e.sources.find(m=>m.name===i)?.scopedBy??[],d=new Set([...l,...s??[]].filter(m=>n.has(m))),c=new Set([...l,...s??[]]),u=[];for(const m of t.filters??[]){const b=`where: ${ge.malloyPath(m.field)} ${m.op??"~"}`;if(n.has(m.given)){d.add(m.given),c.add(m.given),u.push(`${b} $${m.given}`);continue}if(!a.has(m.given))continue;c.add(m.given);const x=O.malloyLiteral(r.get(m.given),a.get(m.given));x!==void 0&&u.push(`${b} ${x}`)}const f=u.join(", "),h=t.chart,p=h==="none"||ni(h)?wn(h,t.chartCarried):h==="custom"&&t.chartLines?.length?t.chartLines.join(`
143
- `):h==="default"&&ty(t.declaration)?wn("none"):void 0;return{...p?{annotation:p}:{},expression:`${i} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(d),reads:s||c.size>0?Array.from(c):void 0}}function ry({environmentName:e,packageName:t,versionId:n,modelPath:r,reports:s,reportsSettled:i}){const{apiClients:o,server:a}=Be.useServer(),{data:l}=O.useQueryWithApiError({queryKey:["report-editor-models",e,t,n],queryFn:async()=>(await o.models.listModels(e,t,n)).data.flatMap(p=>p.path&&!p.error?[p.path]:[])}),d=k.useMemo(()=>new Set([r,...s.flatMap(p=>p.path?[p.path]:[])]),[s,r]),c=k.useMemo(()=>i?(l??[]).filter(p=>!d.has(p)):[],[l,d,i]),u=ql.useQueries({queries:c.map(p=>({queryKey:["report-editor-model",e,t,p,n,a],queryFn:async()=>(await o.models.getModel(e,t,p,n)).data,retry:!1}))}),f=l!==void 0&&i&&u.every(p=>p.isSuccess||p.isError),h=u.map(p=>p.dataUpdatedAt).join();return k.useMemo(()=>f?Yd(u.flatMap(p=>p.data?[p.data]:[]),d):void 0,[f,c,h,d])}const sy={};function iy({textSource:e,modelGivens:t,environmentName:n,packageName:r,modelPath:s,versionId:i,opened:o,replaces:a,onSave:l,onDirtyChange:d,onExit:c,allowLayoutChange:u,onEvent:f,savesTo:h,saveLabel:p,note:m}){const{apiClients:b}=Be.useServer(),[x,v]=k.useState(o.document.tiles.length>0);k.useEffect(()=>v(o.document.tiles.length>0),[o.generation,o.document]);const{data:g,isSuccess:y,isError:_}=O.useQueryWithApiError({queryKey:["dashboard-editor-manifest",n,r,s,i],queryFn:async()=>{const N=(await b.reports.getReport(n,r,s,i)).data;return N.notebook?{...N.notebook.startingGivens?{startingGivens:N.notebook.startingGivens}:{},...N.notebook.autorun===void 0?{}:{autorun:N.notebook.autorun}}:N},enabled:x&&!e}),S=e?.modelPath??s,E=O.useCompiledDocument({environmentName:n,packageName:r,modelPath:S,source:o.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0}),D=E.data?.document,T=e?E.isSuccess?D?.manifest??sy:void 0:g,A=e?E.isSuccess:y,q=e?E.isError:_,P=e?O.documentPreamble(D?.cells):void 0,z=(E.data?.result.problems??[]).filter(N=>N.severity==="error"),U=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),K=e?.givens,Z=k.useMemo(()=>new Set((T?.tiles??[]).flatMap(N=>N.restricted&&N.query?[is(N.query)]:[])),[T]),{reports:J,settled:ie}=O.useReportListing(n,r,i),de=k.useMemo(()=>J.map(N=>N.path).filter(N=>!!N&&N!==s&&N.endsWith(".malloy")).map(N=>N.replace(/\.malloy$/,"")),[J,s]),I=ry({environmentName:n,packageName:r,...i!==void 0?{versionId:i}:{},modelPath:s,reports:J,reportsSettled:ie}),V=k.useMemo(()=>e?(I?.sources??[]).filter(N=>(N.visibleIn??N.exporters??[N.modelPath]).includes(S)).map(N=>N.name):void 0,[I,e,S]),B=k.useMemo(()=>I&&V?{sources:I.sources.filter(N=>V.includes(N.name))}:I,[I,V]),[j,G]=k.useState(o.document);k.useEffect(()=>G(o.document),[o.document]);const ne=k.useMemo(()=>l&&(async(N,Q)=>{await l(N,Q.document.layout),h==="package"&&v(Q.document.tiles.length>0)}),[l,h]),Y=k.useMemo(()=>(T?.givens??(o.conversion?t??[]:[])).filter(N=>!(e&&N.secure===!0)&&!(N.name!==void 0&&U.has(N.name))),[T,o.conversion,t,U,e]),H=k.useMemo(()=>new Set([...Y.map(N=>N.name).filter(N=>N!==void 0),...Object.keys(K??{})]),[Y,K]),L=k.useMemo(()=>Qv(j,Y),[j,Y]),{declaredTypes:C,applied:W,panel:M}=O.useDocumentControls({specs:L,loaded:A,startingValues:T?.startingGivens,documentKey:`${n}/${r}/${i??""}/${s}/edit`,autorun:T?.autorun!==!1,environmentName:n,packageName:r,modelPath:e?S:T?.path,versionId:i,documentName:s,...P!==void 0?{preamble:P}:{},...K?{hostGivens:K}:{}}),ee=k.useMemo(()=>Object.fromEntries(Object.entries(K??{}).filter(([N])=>!C.has(N))),[K,C]),X=!x||A||q,le=k.useMemo(()=>new Map((T?.tiles??[]).flatMap(N=>N.kind!=="text"&&N.query&&N.givenNames?[[is(N.query),N.givenNames]]:[])),[T]),ce=k.useMemo(()=>function(Q,me,se="card"){if(!X)return w.jsxs(O.TileCard,{chrome:se,children:[w.jsx(O.TileHeading,{title:me?.title??Gs(Q),subtitle:me?me.subtitle:Q.subtitle}),w.jsx(O.Loading,{text:"Running…"})]});const te=ny(j,Q,H,W,le.get(is(`${Q.source} -> ${Q.name}`)));return w.jsx(O.DashboardTile,{environmentName:n,packageName:r,versionId:i,modelPath:S,...P!==void 0?{preamble:P}:{},...Z.has(is(`${Q.source} -> ${Q.name}`))?{restricted:!0}:{},tile:te.expression,...te.annotation?{annotation:te.annotation}:{},label:Gs(Q),chrome:se,subtitle:Q.subtitle,...me?{heading:me}:{},borderless:Q.borderless,givens:W,hostGivens:ee,declaredTypes:C,givenNames:te.givenNames,ignoredFilters:O.tileIgnoredFilterLabels(te.reads,L),height:O.TILE_MAX_HEIGHT})},[j,X,H,le,n,r,i,S,P,Z,W,ee,C,L]);return w.jsxs($.Stack,{sx:{gap:1},children:[e&&z.length>0&&w.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",z.map(N=>N.message).join("; ")]}),e&&E.isError&&w.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),w.jsx(Oa,{...e?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:o.source,document:o.document,renderTile:ce,givens:L.filter(N=>N.name!==void 0).map(N=>({name:N.name,...N.label?{label:N.label}:{},...N.type?{type:N.type}:{},...N.suggest?.dimension?{field:N.suggest.dimension}:{}})),onChange:G,onDirtyChange:d,...c?{onExit:c}:{},...u!==void 0?{allowLayoutChange:u}:{},...o.conversion?{conversion:o.conversion}:{},...B?{catalog:B}:{},dashboards:de,...f?{onEvent:f}:{},controls:A?w.jsx(O.GivensPanel,{...M,layout:j.layout==="linear"?"panel":"bar"}):void 0,...ne?{onSave:ne}:{},savesTo:h,...p?{saveLabel:p}:{},...a!==void 0?{replaces:a}:{},modelPath:s,...e?{visibleSources:V}:{}}),w.jsx($.Box,{sx:{px:.5},children:w.jsx($.Typography,{variant:"caption",sx:{opacity:.7},children:m})})]})}function oy({storage:e,layout:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[l,d]=k.useState(void 0),[c,u]=k.useState(e===void 0),[f,h]=k.useState(!1),[p,m]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let b=!1;return m(void 0),(async()=>{try{const x=O.chooseWorkspace(await e.listWorkspaces(!1));if(b)return;if(a(x),x!==void 0&&(!n||x.authoritative)){const v=await e.getDocument(O.locatorFor(t,x.name,r,s,i)).catch(g=>{if(!O.isDocumentNotFound(g))throw g});if(b)return;d(v),h(v!==void 0)}}catch(x){if(b)return;m(O.storageErrorMessage(x))}b||u(!0)})(),()=>{b=!0}},[e,t,n,r,s,i]),{workspace:o,draft:l,setDraft:d,draftChecked:c,offered:f,setOffered:h,readFailure:p}}const ay=e=>e.ok===!1,Un=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},ly=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],cy=/^[A-Za-z_][A-Za-z0-9_]*$/,uy="file:///publisher-notebook-builder/notebook.malloy",os=e=>e.replace(/\r\n?/g,`
144
- `);async function dy(e){const t=(I,V)=>({ok:!1,refused:`Line ${I+1}: ${V}`,line:I+1}),n=/\r(?!\n)/.exec(e);if(n)return t(e.slice(0,n.index).split(`
145
- `).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,s;try{r=await Wr(e,uy),s=await O.loadMalloy()}catch(I){return t(0,`Malloy could not read this notebook: ${I}`)}const i=r.problems.find(I=>I.code==="syntax-error");if(i)return t(i.at?.range?.start?.line??0,`Malloy could not parse this notebook (${i.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,l=a?.tokenSource?.vocabulary,d=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!d||typeof l?.getSymbolicName!="function"||d.length===0&&e.trim()!=="")return{ok:!1,refused:"This build of Malloy does not expose a parse tree and token stream the notebook builder can read, so editing is off."};const c=I=>l.getSymbolicName(I.type),u=I=>s.routeOf({value:I.trimStart()}),f=I=>s.payloadOf({value:I}),h=I=>I==="markdown"||I==='"'||I==="text",p=I=>os(f(I)).replace(/\n$/,""),m=(I,V)=>{const B=f(I).trim(),j=u(I)!=='"'&&cy.test(B)?"":B;return os([j&&`${j}
146
- `,...V].join("")).replace(/\n$/,"")},b=new ri(e),x=ka(b,a),v=I=>e.slice(b.utf16(I.startIndex),b.utf16(I.stopIndex+1)),g=I=>{const V=I.start?.startIndex,B=I.stop?.stopIndex,j=b.span(I);if(V===void 0||B===void 0||!j)return;let G=j.end;for(;G>j.start&&(e[G-1]===`
147
- `||e[G-1]==="\r");)G--;return{startCp:V,stopCp:B,...j,startLine:b.line(j.start),endLine:b.line(Math.max(j.start,G-1))}},y=I=>{let V=0,B=d.length;for(;V<B;){const j=V+B>>1;d[j].startIndex<I?V=j+1:B=j}return V},_=(I,V)=>{const B=[],j=[],G={lines:[],insertAt:b.utf16(I)};let ne=-2;for(let Y=y(I);Y<d.length;Y++){const H=d[Y];if(H.startIndex>V)break;if(H.channel!==0)continue;const L=c(H);if(L!=="ANNOTATION"&&L!=="BLOCK_ANNOTATION_BEGIN"){G.insertAt=b.lineStarts[b.line(b.utf16(H.startIndex))];break}const C=os(v(H)),W=[];if(L==="BLOCK_ANNOTATION_BEGIN"){for(;c(d[Y+1]??H)==="BLOCK_ANNOTATION_TEXT";)W.push(v(d[++Y]));c(d[Y+1]??H)==="BLOCK_ANNOTATION_END"&&Y++}if(h(u(C))){const M=b.utf16(H.startIndex),ee=b.lineStarts[b.line(M)],X=/^[ \t]*$/.test(e.slice(ee,M));j.push({start:X?ee:M,end:b.utf16(d[Y].stopIndex+1)})}if(L==="ANNOTATION"){const M=C.replace(/\n$/,"");if(At(M)){const ee=b.utf16(H.startIndex),X=b.lineStarts[b.line(ee)];G.lines.push({span:{start:/^[ \t]*$/.test(e.slice(X,ee))?X:ee,end:b.utf16(H.stopIndex+1)},text:M})}else Tr(M)&&G.unmodelled===void 0&&(G.unmodelled=M.trim())}if(u(C)!=="markdown")ne=-2;else if(L==="BLOCK_ANNOTATION_BEGIN")B.push(m(C,W)),ne=-2;else{const M=p(C);H.line===ne+1?B[B.length-1]+=`
148
- ${M}`:B.push(M),ne=H.line}}return{markdown:B.length>0?B.join(`
149
-
150
- `):void 0,prose:j,chart:G}},S=[],E=[],D=(I,V,B="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(I,`${V}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${B}`);for(let I=0;I<(o.childCount??0);I++){const V=o.getChild(I);if(!en(V)){const H=V?.symbol,L=H?c(H):void 0;if(H&&L==="EOF")continue;if(H&&L==="SEMI"){S.push([H.startIndex,H.stopIndex]);continue}return D((H?.line??1)-1,"a token outside any statement")}const B=g(V);if(!B)return D(0,"a statement with no readable range");const j=ly.find(([H])=>Un(V,H)!==void 0);if(!j&&Un(V,"ignoredObjectAnnotations"))return D(B.startLine,"a # tag that annotates no statement","move the tag directly above its run:, or write trailing prose as a `##(markdown)` note.");if(!j){const H=e.slice(B.start,B.end).split(`
151
- `)[0];return D(B.startLine,`\`${H.trim()}\` is a statement the notebook reader does not recognize`)}S.push([B.startCp,B.stopCp]);const[G,ne]=j;if(ne!=="notes"){const{markdown:H,prose:L,chart:C}=_(B.startCp,B.stopCp);E.push({kind:"statement",run:ne==="run",...H!==void 0&&{markdown:H},prose:L,chart:C,startLine:B.startLine,endLine:B.endLine});continue}const Y=Un(V,G);for(const H of Un(Y,"docAnnotation")??[]){const L=g(H);if(!L)return D(B.startLine,"a note with no readable range");const C=Un(H,"docBlockAnnotation")!==void 0,W=d.filter(N=>N.startIndex>=L.startCp&&N.stopIndex<=L.stopCp),M=W.filter(N=>c(N)==="BLOCK_ANNOTATION_TEXT"),ee=M[M.length-1]??W[0],X=os(C&&ee?e.slice(L.start,b.utf16(ee.stopIndex+1)).replace(/\r?\n$/,""):e.slice(L.start,L.end)),le=u(X),ce=h(le)?C?m(X.split(`
152
- `,1)[0],M.map(v)):p(X):void 0;E.push({kind:"note",note:{text:X,route:le,...ce!==void 0&&{body:ce},block:C,startLine:L.startLine,endLine:L.endLine}})}}for(const I of d){if(c(I)!=="BLOCK_ANNOTATION_END")continue;const V=v(I).trimStart().replace(/^\|#{1,2}/,"").trim();if(V)return t(I.line-1,`the text after a block's closer (\`${V}\`) is not part of any cell, so the notebook cannot be edited here. Fix: put it on its own line, or inside the block.`)}let T=0;for(const I of d){if(I.channel!==0||c(I)==="EOF")continue;for(;T<S.length&&S[T][1]<I.startIndex;)T++;const[V,B]=S[T]??[1/0,-1/0];if(I.startIndex<V||I.stopIndex>B)return D(I.line-1,"a token outside any statement")}const A=E.findIndex(I=>I.kind==="note"&&ge.setsArtifactProperty(I.note.text));if(A<0)return t(0,"this file has no ## artifact note, so it is not a notebook the builder can edit. Fix: add `## artifact { layout=linear }` after the ##! line.");const q=E.findIndex((I,V)=>V<A&&I.kind==="statement");if(q>=0)return t(E[q].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let I=1;I<E.length;I++){const V=E[I-1],B=E[I],j=V.kind==="note"?V.note.endLine:V.endLine,G=B.kind==="note"?B.note.startLine:B.startLine;if(G<=j)return D(G,"a line holding two statements or notes","put each statement and note on its own line.")}const P=I=>b.lineStarts[I+1]??e.length,z=[];let U=-1,K=!0,Z;E.forEach((I,V)=>{if(I.kind==="statement"){K=!1,Z=void 0,z.push({cell:{kind:I.run?"query":"definition",...I.markdown!==void 0&&{markdown:I.markdown},...I.prose.length>0&&{prose:I.prose},...I.run&&{chart:I.chart},id:""},startLine:I.startLine,endLine:I.endLine});return}const{note:B}=I;if(!(V>A&&B.body!==void 0)){K&&(U=B.endLine),Z=void 0;return}if(K=!1,!B.block&&Z&&Z.endLine+1===B.startLine){Z.cell.markdown+=`
153
- ${B.body}`,Z.endLine=B.endLine;return}const G={cell:{kind:"markdown",markdown:B.body,id:""},startLine:B.startLine,endLine:B.endLine};z.push(G),Z=B.block?void 0:G});const J={start:0,end:P(U)};let ie=U;const de=z.map(({cell:I,startLine:V,endLine:B},j)=>{let G=V;for(;G-1>ie&&x.lines.has(G-1);)G--;return ie=B,{...I,span:{start:b.lineStarts[G],end:P(B)},id:String(j)}});for(const I of[J,...de.map(V=>V.span)]){const V=x.all.find(B=>B.start<I.start&&B.end>I.start||B.start<I.end&&B.end>I.end);if(V)return D(b.line(V.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:J,cells:de}}}const fy=e=>e.ok===!1,hy=/^[A-Za-z_][A-Za-z0-9_]*$/,Fl=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,zl=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function Ci(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const s=e.indexOf(`
154
- `,n),i=s<0?e.length:s;t+=" ".repeat(i-n),n=i}else if(r==="/*"){const s=e.indexOf("*/",n+2),i=s<0?e.length:s+2;t+=e.slice(n,i).replace(/[^\n]/g," "),n=i}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const s=e[n];let i=n+1;for(;i<e.length&&e[i]!==s;)i+=e[i]==="\\"?2:1;const o=Math.min(i,e.length);t+=s+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=s),n=o+1}else t+=e[n],n++}return t}function Wl(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const s=e[r];s==="{"||s==="("||s==="["?n++:s==="}"||s===")"||s==="]"?n--:n===0&&s==="-"&&e[r+1]===">"&&t.push(r)}return t}function Bl(e,t,n){let r=e;for(const s of[...n].sort((i,o)=>o.start-i.start))r=r.slice(0,s.start-t)+r.slice(s.end-t);return r}function Gl(e,t){const n=t.split(`
155
- `).map(r=>r.startsWith("|##")?` ${r}`:r).join(`
156
- `);return`##|(markdown) ${e}
157
- ${n===""?"":`${n}
158
- `}|##
159
- `}function py(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function gy(e){const t=(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),n=t.length>40?t.lastIndexOf("_",40):t.length,r=t.slice(0,n>0?n:40);return/^[a-z]/.test(r)&&ge.isBareName(r)?r:void 0}async function my(e){const t=await dy(e);if(ay(t))return{ok:!1,refused:t.refused,line:t.line};const{header:n,cells:r}=t.source,s=(C,W)=>({ok:!1,refused:`Line ${C+1}: ${W}`,line:C+1}),i=e.slice(n.start,n.end).split(`
160
- `),o=ge.artifactTag(i);if(o&&!ge.artifactLeads(o.text))return s(o.from,ge.ARTIFACT_NOT_FIRST);if(!o||Sa(o.text))return s(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const l=(await Wr(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,d=l?.tokenSource?.vocabulary,c=l?.getTokens?.()??[];if(typeof d?.getSymbolicName!="function")return s(0,"Malloy's token stream is not available.");const u=await O.loadMalloy(),{parseAnnotation:f}=await O.loadMalloyTag(),h=C=>d.getSymbolicName(C.type),p=new ri(e),m=ka(p,l),b=C=>e.slice(p.utf16(C.startIndex),p.utf16(C.stopIndex+1)),x=C=>u.routeOf({value:C.trimStart()}),v=C=>u.payloadOf({value:C}),g=C=>C.replace(/\r\n?/g,`
161
- `),y=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),_=C=>{let W=C;for(let M=2;y.has(W);M++)W=`${C}_${M}`;return y.add(W),W},S=C=>{const W=c.filter(Q=>Q.channel===0&&p.utf16(Q.startIndex)>=C.span.start&&p.utf16(Q.stopIndex+1)<=C.span.end),M=[],ee=[],X=[];let le;for(let Q=0;Q<W.length;Q++){const me=h(W[Q]);if(me!=="ANNOTATION"&&me!=="BLOCK_ANNOTATION_BEGIN"){le=W[Q];break}let se=Q;const te=[];if(me==="BLOCK_ANNOTATION_BEGIN"){for(;h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_TEXT";)te.push(b(W[++se]));h(W[se+1]??W[Q])==="BLOCK_ANNOTATION_END"&&se++}const R=g(b(W[Q])),F=x(R),re=p.utf16(W[Q].startIndex),ue=p.lineStarts[p.line(re)],Re={start:/^[ \t]*$/.test(e.slice(ue,re))?ue:re,end:p.utf16(W[se].stopIndex+1)};F==="markdown"?M.push(Re):F==='"'&&(ee.push(Re),X.push(me==="ANNOTATION"?g(v(R)).replace(/\n$/,"").trim():[g(v(R.split(`
162
- `,1)[0])),...te.map(g)].map(jt=>jt.trim()).filter(Boolean).join(" "))),Q=se}if(!le)return;const ce=p.utf16(le.startIndex),N=e.slice(C.span.start,C.span.end);return{cell:C,above:Bl(e.slice(C.span.start,ce),C.span.start,(C.kind==="query"?[...M,...ee]:M).filter(Q=>Q.end<=ce)),statement:e.slice(ce,C.span.end).trimEnd(),kept:Bl(N,C.span.start,M),...C.kind==="query"&&X.length>0&&{caption:X.join(" ")},line:p.line(ce)}},E=new Map,D=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown")continue;const M=S(W);if(!M)return s(p.line(W.span.start),"a cell with no statement the converter can place.");D.set(C,M);const ee=Fl.exec(M.statement);W.kind==="definition"&&ee&&E.set(ee[1],{expression:M.statement.slice(ee[0].length).trim(),cell:C})}const T=C=>{const W=/^run\s*:\s*/.exec(C.statement);if(!W)return s(C.line,"a run that is not `run: <query>`.");let M=C.statement.slice(W[0].length).trim();const ee=[];for(let Q=0;Q<10;Q++){const me=Ci(M),se=/^[A-Za-z_][A-Za-z0-9_]*/.exec(me)?.[0],te=se?E.get(se):void 0;if(!se||!te)break;const R=M.slice(se.length).trim(),F=me.slice(se.length).trim();if(F!==""&&!F.startsWith("->")&&!F.startsWith("+"))break;if(F.startsWith("+")&&Wl(Ci(te.expression)).length!==1)return s(C.line,`\`${se} + { … }\` refines a query with more than one stage, which cannot become one view.`);ee.push(se);const re=/(\/\/|--)[^\n]*$/.test(te.expression)?`
163
- `:" ";M=`${te.expression}${R===""?"":`${re}${R}`}`}const X=Ci(M);if(E.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(X)?.[0]??""))return s(C.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const le=Wl(X);if(le.length===0)return s(C.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const ce=M.slice(0,le[0]).trim();if(/\bextend\b/.test(X.slice(0,le[0])))return s(C.line,"this run extends its source inline before `->`, so it cannot become a tile. Fix: declare the extension with a `source:` statement and run that.");if(!hy.test(ce)&&!/^`[^`]+`$/.test(ce))return s(C.line,"the source of this run is not a name, so it cannot become a tile. Fix: name it with a `source:` statement and run that.");const N=M.slice(le[0]+2).trim();return N===""?s(C.line,"this run has nothing after `->`."):{source:ce,body:N,used:ee}},A=new Map,q=[],P=new Set,z=new Map;let U=0,K=0;const Z=new Map;for(const C of D.values()){if(C.cell.kind!=="query")continue;const W=T(C);if("ok"in W)return W;for(const M of W.used)Z.set(M,(Z.get(M)??0)+1)}const J=C=>Z.get(C)===1&&(e.match(new RegExp(`\\b${C}\\b`,"g"))??[]).length===2,ie=new Map;for(const[C,W]of r.entries()){if(W.kind==="markdown"){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`);const re=m.all.filter(ue=>ue.start>=W.span.start&&ue.end<=W.span.end).map(ue=>`${e.slice(ue.start,ue.end)}
164
- `).join("");z.set(C,re+Gl(F,W.markdown??""));continue}const M=D.get(C);let ee="";if(W.markdown!==void 0){const F=_(`text_${++U}`);q.push(`${F} { kind=text }`),ee=`${Gl(F,W.markdown)}
165
- `}if(W.kind==="definition"){const F=Fl.exec(M.statement)?.[1];if(F&&J(F)){P.add(C),ie.set(F,M.above.split(`
166
- `).filter(re=>re.trim()!=="")),ee&&z.set(C,ee.replace(/\n$/,""));continue}z.set(C,`${ee}${M.kept}`);continue}const X=T(M),le=X.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let ce=A.get(X.source);ce||(ce={name:_(`${le}_tiles`),base:X.source,views:[]},A.set(X.source,ce));const N=[...X.used.flatMap(F=>ie.get(F)??[]),...M.above.split(`
167
- `)].filter(F=>F.trim()!==""),Q=N.filter(F=>/^\s*#(?!["(|])/.test(F)),me=Q.length>0?$a(f,Q).tag:void 0,se=_(gy(me?.text("label")??M.caption)??`tile_${K+1}`);K++,q.push(`"${ce.name} -> ${se}"`);const te=N.map(py);if(M.caption!==void 0){const F=O.annotationTextProblem("caption",M.caption)===void 0;F&&!me?.has("label")?te.push(` # label=${zl(M.caption)}`):F&&!me?.has("subtitle")?te.push(` # subtitle=${zl(M.caption)}`):te.push(` #" ${M.caption}`)}const R=X.body.split(`
168
- `).map((F,re)=>re===0||F.trim()===""?F:` ${F}`).join(`
169
- `);ce.views.push([...te,` view: ${se} is ${R}`].join(`
170
- `)),P.add(C),ee&&z.set(C,ee.replace(/\n$/,""))}const de=(()=>{let C=0;const W=o.text;for(let M=W.indexOf("{");M<W.length;M++)if(W[M]==='"')for(M++;M<W.length&&W[M]!=='"';M++)W[M]==="\\"&&M++;else if(W[M]==="{")C++;else if(W[M]==="}"&&--C===0)return M;return-1})();if(de<0)return s(o.from,"the `## artifact { … }` tag never closes.");const I=q.length===0?`
171
- tiles=[]
172
- `:`
173
- tiles=[
174
- ${q.map(C=>` ${C}`).join(`,
175
- `)}
176
- ]
177
- `,B=`${o.text.slice(0,de).replace(/[ \t]*\blayout\s*=\s*(?:"(?:[^"\\]|\\.)*"|[^\s}]+)/g,"").replace(/\bartifact\s*\{/,C=>`${C} layout=linear`).trimEnd().replace(/^##(?!\|)/,"##|")}${I}${o.text.slice(de)}`;i.splice(o.from,o.block?o.to-o.from:1,...(o.block?B:`${B}
178
- |##`).split(`
179
- `));const j=C=>{const W=C.text.split(`
180
- `),M=W.pop(),ee=[];let X=0;for(const le of W){const ce=C.at[X]??-1,N=m.all.some(Q=>ce>=Q.start&&ce<Q.end);(le.trim()!==""||ee.at(-1)?.trim()!==""||N)&&ee.push(le),X+=le.length+1}return ee.map(le=>`${le}
181
- `).join("")+M},G={text:"",at:[]},ne=(C,W)=>{G.text+=e.slice(C,W);for(let M=C;M<W;M++)G.at.push(M)};let Y=i.join(`
182
- `),H=n.end;for(const[C,W]of r.entries()){ne(H,W.span.start),H=W.span.end;const M=z.get(C);M!==void 0&&(Y+=j(G)+(M.endsWith(`
183
- `)?M:`${M}
184
- `),G.text="",G.at=[])}ne(H,e.length),Y=`${Y.trimEnd()}
185
- `+(G.text.trim()===""?"":j(G)),Y=`${Y.trimEnd()}
186
- `;const L=[...A.values()].map(C=>`source: ${C.name} is ${C.base} extend {
187
- ${C.views.join(`
188
-
189
- `)}
190
- }
191
- `);return L.length>0&&(Y+=`
192
- ${L.join(`
193
- `)}`),e.includes(`\r
194
- `)&&(Y=Y.replace(/\r?\n/g,`\r
195
- `)),{ok:!0,text:Y,tiles:q.length}}const Ii=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function vy(e){const t=await Cr(e);if(!Er(t))return{ok:!0,document:t.document};if(!t.legacyNotebook)return{ok:!1,reason:Ii(t.reason,t.line)};const n=await my(e);if(fy(n))return{ok:!1,reason:Ii(n.refused,n.line)};const r=await Cr(n.text);return Er(r)?{ok:!1,reason:`The converted notebook cannot be opened: ${Ii(r.reason,r.line)}`}:{ok:!0,document:r.document,conversion:{from:e,to:n.text}}}const yy="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` report to edit it here.",by="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function xy({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,layout:l,notebook:d,noun:c,legacyFormat:u,textHeld:f,startedAt:h,onEventRef:p}){const m=k.useRef({path:a,layout:l});m.current={path:a,layout:l};const b=k.useRef((N,Q)=>{try{p.current?.(O.withReportContext(N,{...m.current,...Q?{layout:Q}:{}}))}catch{}}),x=e?.authoritative===!0,v=x&&r!==void 0,[g,y]=k.useState(void 0),_=(x||g===!0)&&t!==void 0,[S,E]=k.useState(void 0),[D,T]=k.useState(u?yy:void 0),A=k.useRef(void 0),q=k.useRef(void 0),[P,z]=k.useState(void 0),U=k.useRef(i);U.current=i;const K=P!==void 0&&P.onFetch===i?P.text:s,Z=k.useRef(K);Z.current=K;const J=_?t:K,[ie,de]=k.useState(!1),[I,V]=k.useState(void 0),[B,j]=k.useState(void 0),G=J!==void 0&&J!==B,ne=S?.source,H=G&&(ie||!x&&t!==void 0&&ne===t&&t!==K)&&ne!==void 0&&J!==I,L=H?ne:G?J:ne??J,C=H?J:void 0,W=k.useRef(ne);W.current=ne;const M=k.useRef(J);M.current=J;const ee=k.useRef("package");ee.current=_?x?"record":"draft":"package",k.useEffect(()=>{if(L===void 0||!n||v||L===W.current)return;let N=!1;const Q=Z.current,me=M.current;return vy(L).then(se=>{if(!N){if(se.ok===!1){T(se.reason),b.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}T(void 0),A.current=void 0,q.current=Q,z(void 0),V(void 0),j(me),E(te=>({source:L,document:se.document,...se.conversion?{conversion:se.conversion}:{},...Q!==void 0?{packageText:Q}:{},generation:(te?.generation??0)+1})),b.current({type:"report.opened",surface:"edit",from:ee.current,tiles:se.document.tiles.length,durationMs:O.now()-h.current},se.document.layout)}}).catch(se=>{if(N)return;const te=`Could not read the ${c}: ${se instanceof Error?se.message:String(se)}`;T(te),b.current({type:"report.load_failed",surface:"edit",category:O.failureCategory(se)})}),()=>{N=!0}},[L,a,n,v,d,c,f,h]),k.useEffect(()=>{u&&b.current({type:"report.load_failed",surface:"edit",category:"unsupported"})},[u]),k.useEffect(()=>{!f||!n||S||r!==void 0||(x?t===void 0&&T("the host's storage has no document at this location."):T("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,S,r,x,t]);const X=d&&!f&&!S&&n&&!_&&o&&s===void 0;return k.useEffect(()=>{X&&(T(by),b.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[X]),{authoritative:x,blockedOnRecord:v,resume:g,setResume:y,fromDraft:_,opened:S,setOpened:E,openError:D,savedHashRef:A,packageBaseRef:q,setWrote:z,fetchedAtRef:U,setDirty:de,setSeen:j,held:C,choose:N=>{h.current=O.now(),V(N?t:K),y(N)},acceptHeld:()=>{h.current=O.now(),V(C)}}}function wy({storage:e,workspace:t,layout:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:l,queryClient:d,mutable:c,textHeld:u,readFailure:f,authoritative:h,resume:p,setResume:m,setOpened:b,setDraft:x,setOffered:v,setSeen:g,setWrote:y,savedHashRef:_,packageBaseRef:S,fetchedAtRef:E}){const D=k.useCallback(I=>t===void 0?void 0:O.locatorFor(I,t.name,s,i,o),[t,s,i,o]),T=D(n),A=k.useCallback(async(I,V=n)=>{const B=D(V);if(!e||!B)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(B,I),b(j=>j&&{...j,source:I}),x(I),(h||p===!0)&&g(I),h||m(j=>j??!1)},[e,D,n,h,p,b,x,g,m]),[q,P]=k.useState(void 0),z=k.useCallback(async I=>{const V=await O.expectedHashFor(_.current,S.current);if(V===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",s,i,o,a,r];await O.writePackageFile({apiClients:l,queryClient:d,environmentName:s,packageName:i,modelPath:o,source:I,expectedHash:V,invalidateOnError:[B],afterWrite:async j=>{if(b(G=>G&&{...G,source:I}),y({text:I,onFetch:E.current}),g(I),_.current=j,P(void 0),e&&T)try{await e.deleteDocument(T),x(void 0),v(!1)}catch(G){O.isDocumentNotFound(G)?(x(void 0),v(!1)):P(O.storageErrorMessage(G))}m(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:O.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]}]}),O.invalidateReportQueries(d,s,i,o)},[l,s,i,o,a,r,e,T,d,_,S,E,b,y,g,x,v,m]),U=t?.writeable===!0,K=c===!0&&!u,{savesTo:Z,pinnedPackageSave:J,writer:ie}=O.saveTarget({authoritative:h,mutable:K,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!T&&U&&(!r||h),readFailed:f!==void 0});return{save:ie==="storage"?A:ie==="package"?z:void 0,savesTo:Z,writer:ie,pinnedPackageSave:J,takesWrites:K,supersedeFailure:q}}function Ea(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:s,path:i,textSource:o,allowLayoutChange:a}=e,l=e.layout??(s?O.layoutOfKind(s):"grid"),d=l==="linear",c=o!==void 0,{environmentName:u,packageName:f,versionId:h,namesBoth:p}=O.resolveEditorTarget(e),b=("resourceUri"in e?e.dashboard:e.dashboardName)??O.documentSlug(i)??"",x="report",{apiClients:v,mutable:g,isLoadingStatus:y}=Be.useServer(),_=ql.useQueryClient(),S=k.useRef(O.now()),E=k.useRef(t);E.current=t;const D=k.useRef(n);D.current=n;const T=O.useOptionalDocumentStorage()?.documentStorage,A=i??O.legacyNamedPath(s??"dashboard",b),q=/\.malloynb$/i.test(A)||d&&/\.malloynb$/i.test(b),P=O.useQueryWithApiError({queryKey:["dashboard-editor-model",u,f,A,h,d],queryFn:()=>v.models.getModel(u,f,A,h,d?!0:void 0),enabled:p&&!q&&!c}),z=P.data?.data?.sourceText,{workspace:U,draft:K,setDraft:Z,draftChecked:J,offered:ie,setOffered:de,readFailure:I}=oy({storage:T,layout:l,notebook:d,environmentName:u,packageName:f,modelPath:A}),{authoritative:V,blockedOnRecord:B,resume:j,setResume:G,fromDraft:ne,opened:Y,setOpened:H,openError:L,savedHashRef:C,packageBaseRef:W,setWrote:M,fetchedAtRef:ee,setDirty:X,setSeen:le,held:ce,choose:N,acceptHeld:Q}=xy({workspace:U,draft:K,draftChecked:J,readFailure:I,packageText:z,fetchedAt:P.dataUpdatedAt,packageSettled:P.isSuccess&&!P.isFetching,modelPath:A,layout:l,notebook:d,noun:x,legacyFormat:q,textHeld:c,startedAt:S,onEventRef:E}),{save:me,savesTo:se,writer:te,pinnedPackageSave:R,takesWrites:F,supersedeFailure:re}=wy({storage:T,workspace:U,layout:l,notebook:d,environmentName:u,packageName:f,modelPath:A,versionId:h,apiClients:v,queryClient:_,mutable:g,textHeld:c,readFailure:I,authoritative:V,resume:j,setResume:G,setOpened:H,setDraft:Z,setOffered:de,setSeen:le,setWrote:M,savedHashRef:C,packageBaseRef:W,fetchedAtRef:ee}),ue=U?.name,Re=k.useCallback(Rt=>{E.current?.(O.withWorkspace(Rt,ue))},[ue]),jt=P.isError&&!Y,ut=k.useRef(!1);k.useEffect(()=>{!jt||ut.current||(ut.current=!0,O.reportEmitter({path:A,layout:l},E.current).emit({type:"report.load_failed",surface:"edit",category:O.failureCategory(P.error)}))},[jt,P.error,A,l]);const zn=k.useCallback(Rt=>{X(Rt),D.current?.(Rt)},[X]),_t=se==="host"&&U?.description?U.description:void 0,Wn=!V&&!c&&g===void 0?y?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":O.saveCaption({authoritative:V,mutable:F,pinnedPackageSave:R,...U?{workspace:U}:{},...I!==void 0?{readFailure:I}:{},...h!==void 0?{versionId:h}:{}}),Gr=Wn===_t?"":Wn;if(!p&&"resourceUri"in e)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",x," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(L)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened in the builder: ",L]});if(P.isError&&!Y)return w.jsx(O.ApiErrorDisplay,{error:P.error,context:`Opening the ${x}`});if(!Y&&(!(c||z)||!J))return w.jsx(O.Loading,{text:`Opening the ${x}…`});if(B)return w.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",x," cannot be opened: ",I]});const Bn=K!==void 0&&K!==z;return w.jsxs($.Stack,{sx:{gap:2},children:[P.isError&&w.jsxs($.Alert,{severity:"warning",children:["The ",x," could not be re-read from the server:"," ",P.error?.message,". Your edits are still here."]}),!d&&!V&&ie&&Bn&&j===void 0&&w.jsx($.Alert,{severity:"info",action:w.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[w.jsx($.Button,{size:"small",onClick:()=>N(!0),children:"Resume"}),w.jsx($.Button,{size:"small",onClick:()=>N(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),ce!==void 0&&w.jsx($.Alert,{severity:"warning",action:w.jsx($.Button,{size:"small",onClick:Q,children:"Load it"}),children:se==="package"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":se==="host"?"This report changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this report changed since you opened it. Your edits are still here; loading the new version replaces them."}),re!==void 0&&w.jsxs($.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",re]}),Y&&w.jsx(iy,{environmentName:u,packageName:f,modelPath:A,...o?{textSource:o}:{},slug:b,modelGivens:P.data?.data?.givens,...h!==void 0?{versionId:h}:{},opened:Y,...ne&&te==="package"&&Y.packageText!==void 0?{replaces:Y.packageText}:{},onSave:me,onDirtyChange:zn,...r?{onExit:r}:{},...a!==void 0?{allowLayoutChange:a}:{},savesTo:se,..._t?{saveLabel:_t}:{},...t?{onEvent:Re}:{},note:Gr},Y.generation)]})}const _y=Ea,ky=Oa;function Sy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return w.jsx(Ea,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=O.MAX_SLUG_ATTEMPTS;exports.createDocument=O.createDocument;exports.createRoute=O.createRoute;exports.locatorFor=O.locatorFor;exports.newDashboardSource=O.newDashboardSource;exports.newDocumentProblem=O.newDocumentProblem;exports.newNotebookSource=O.newNotebookSource;exports.reportPathFor=O.reportPathFor;exports.reportPathForTitle=O.reportPathForTitle;exports.slugFor=O.slugFor;exports.slugOrFallback=O.slugOrFallback;exports.useDocumentChoices=O.useDocumentChoices;exports.DashboardBuilder=ky;exports.DashboardEditor=_y;exports.NotebookEditor=Sy;exports.ReportBuilder=Oa;exports.ReportEditor=Ea;exports.buildCatalog=Yd;exports.readDashboardDocument=Cr;exports.readFailed=Er;exports.readReportTagOfText=Cm;exports.spliceDashboardDocument=Kd;exports.spliceFailed=zs;
135
+ `;a.push({start:x,end:x,text:_+u.join(`
136
+ `)})}}const ds=(e,t=ge.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function hv(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(Me(o)){const l=uv(o,a&&Me(a)?a:void 0,r);if(l)return l;continue}const c=a&&le(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=ds(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=ds(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=ds(o.name,ge.isStrictName);if(f)return f}const c=o.suggest?.source;if(c!==void 0&&c!==a?.suggest?.source){const f=ds(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 zu(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function Wu(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 Nu(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 $s=e=>`where: ${ge.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function Ol(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 pv(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 gv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Ca(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
137
+ `,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Gu(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=Ca(r,u.span),x=pv(r,u.span,v);if(x)return Ol(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=gv(u.clauses,_),b=r.commentIn(w);if(b)return Ol(t.name,r,b);s.push({...w,text:""});continue}const y=$s(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($s).join(", ")}`:c.map(u=>`
138
+ ${n.indent}${$s(u)}`).join("");s.push({start:f,end:f,text:l})}function mv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=Wu(t.filters,i);if(o)return Nu(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const d=` + { ${a.map($s).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 Gu(e,t,i)}async function Vu(e,t,n={}){if(!(e.includes(`\r
139
+ `)&&!/(?<!\r)\n/.test(e)))return Dl(e,t,n);const s=await Dl(e.replace(/\r\n/g,`
140
+ `),t,n);return Ks(s)?s:{...s,source:s.source.replace(/\n/g,`\r
141
+ `)}}async function Dl(e,t,n){const r=await qs(e);if(Us(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=dv(s,t),o=Qm(s,i,n.visibleSources);if("reason"in o)return o;const a=hv(s,i);if(a)return{ok:!1,reason:a};const c=await Mu(e);if(Eu(c))return{ok:!1,reason:`Cannot edit a file that will not open: ${c.reason}`};const f=e.split(`
142
+ `),d=Hm(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[Jm,rv,iv,sv,ov,av,lv,cv,fv]){const y=g(p);if(y)return y}const v=g=>{const{drills:y,localGivens:w,description:b,...T}=g,C=g.tiles.map(j=>{if(Me(j))return j;if(j.filters?.length)return Xs(j);const{filters:D,...E}=j;return Xs(E)});return{...T,...b===void 0?{}:{description:Au(b)},tiles:C,...y?.length?{drills:[...y].sort((j,D)=>Ys(j).localeCompare(Ys(D)))}:{},...w?.length?{localGivens:w}:{}}};if(h.length===0)return be(v(s))!==be(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=qm(e,h);if((await xl(e)).length===0){const g=await xl(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 qs(x);return Us(_)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${_.reason}`}:be(v(_.document))!==be(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 Uu({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}=Vl(f,a,w=>n(w.text),()=>c(!1)),p=a&&d!==void 0&&d.text!==e,v=d!==void 0&&d.text!==e?Ss(d.text):void 0;fu(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()?Ss(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},du(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?Ss(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 vv="Write markdown: # heading, **bold**, - list";function yv({tile:e,onChange:t}){return m.jsx(S.TextTileFrame,{sx:{overflow:"visible"},children:m.jsx(Uu,{markdown:e.markdown,placeholder:vv,onCommit:t})})}const bv={"1/2":"Half","1/3":"A third","2/3":"Two-thirds","1/4":"A quarter","3/4":"Three-quarters"},Hu=(e,t)=>t===0?e:Hu(t,e%t);function xv(e,t){const n=`${e} of ${t}`;if(e>=t)return`${n} · Full width`;const r=Hu(e,t),s=bv[`${e/r}/${t/r}`];return s?`${n} · ${s}`:n}function wv({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(vm,{id:Be(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":Be(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 ${Xn(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),m.jsx(S.RemoveBadge,{label:`Remove ${Xn(e)}`,onRemove:f,...d?{disabledReason:d}:{},inset:i?S.BARE_RING_OFFSET_PX:0}),!Me(e)&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Xn(e)}`,onClick:b=>{b.stopPropagation(),c(b.currentTarget)},sx:{position:"absolute",top:i?0:`${Ml}px`,right:i?0:`${Ml}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($v,{})}),h&&m.jsx($.Box,{className:`builder-affordance ${S.reportClasses.widthHandle}`,[Tu]:"",role:"separator",tabIndex:u?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Xn(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:xv(u.span,u.columns)})}),o&&m.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Xn(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 Ml=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:`${-s}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 kv({after:e}){const{theme:t}=Se.usePublisherTheme();return m.jsx(ym,{id:pu(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 Sv({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 $v(){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 Tv({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:j,onResize:D,endResize:E}=n,R=q=>q.colspan===void 0?{...q,colspan:s}:q,P=(C!==void 0?e.document.tiles.map((q,M)=>M===C.index?{...q,colspan:C.span}:q):g??e.document.tiles).map(R),A=e.document.tiles.length===0,U=_||C!==void 0?Lg(P,T):P.map(hu),z=q=>Ev(q,kn(q),v);return m.jsxs(m.Fragment,{children:[m.jsx(yg,{sensors:pm,onDragStart:y,onDragOver:w,onDragEnd:b,children:m.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[i.widths&&(_||C!==void 0)&&m.jsx(Sv,{columns:T}),m.jsx(S.DashboardGrid,{tiles:U,columns:T,rowGapPx:S.GRID_GAP_PX,keyOf:q=>q.kind==="gap"?pu(q.after):Be(q.tile),renderTile:q=>{if(q.kind==="gap")return m.jsx(kv,{after:q.after});const{tile:M,index:F}=q;return m.jsx(wv,{tile:M,index:F,selected:F===a,flash:Be(M)===c,menuOpen:f===F,bare:Me(M),...i.insertBetween&&o&&F<e.document.tiles.length-1?{onInsertAfter:()=>p(F+1)}:{},...i.widths&&Cv(M)?{resizing:C?.index===F,width:{span:M.colspan??1,columns:T,onStep:H=>{H!==(M.colspan??1)&&e.update(B=>{const W=B.tiles[F];W&&(W.colspan=H)})}},onResizeStart:H=>j(H,F),onResizeMove:D,onResizeEnd:E}:{},onSelect:()=>d(F),onOpenMenu:H=>l(H,F),onRemove:()=>u(F),...h?{removeBlocked:h}:{},children:Me(M)?m.jsx(yv,{tile:M,onChange:H=>v(Be(M),B=>{Me(B)&&(B.markdown=H)})}):x?x(M,z(M),"card"):m.jsx(_v,{tile:M,heading:z(M)})})}})]})}),i.insertBetween&&o&&!A&&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 Ev=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Be(e),s=i=>o=>n(r,a=>{le(a)&&(o===""?delete a[i]:a[i]=o)});return{title:m.jsx(wo,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:m.jsx(wo,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},Cv=e=>Me(e)||e.declaration.kind!=="inherited",Ov=12;function Dv({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(wo,{value:e.document.title,placeholder:t??"Untitled report",ariaLabel:"Report title",onCommit:o=>e.update(a=>{a.title=o})}),description:m.jsx($.Box,{role:"group","aria-label":"Description","aria-current":r,onPointerDown:s,onFocus:s,children:m.jsx(S.TextTileFrame,{sx:{position:"relative",overflow:"visible",...qu(i,{selected:r,bare:!0,ringOffset:Ov})},children:m.jsx(Uu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:o=>e.update(a=>{o.trim()===""?delete a.description:a.description=o})})})})})}const Mv=({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 jv(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(),setLayout:b=>n.current.layout?.set(b),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?.()}),[]),{status:i,saveTarget:o,canUndo:a,canRedo:c,add:{filterUnavailable:f}}=t,d=t.save!==void 0,l=t.layout?.value,u=t.add.tile!==void 0,h=t.add.text!==void 0,p=t.add.filter!==void 0,v=t.exit!==void 0,x=t.done!==void 0,_=t.discard!==void 0,{draftKeptAt:g}=t,y=k.useMemo(()=>({status:i,saveTarget:o,...d?{save:s.save}:{},canUndo:a,undo:s.undo,canRedo:c,redo:s.redo,...l!==void 0?{layout:{value:l,set:s.setLayout}}:{},add:{...u?{tile:s.addTile}:{},...h?{text:s.addText}:{},...p?{filter:s.addFilter}:{},...f!==void 0?{filterUnavailable:f}:{}},...v?{exit:s.exit}:{},...x?{done:s.done}:{},...g!==void 0?{draftKeptAt:g}:{},..._?{discard:s.discard}:{}}),[s,i,o,d,a,c,l,u,h,p,f,v,x,g,_]),w=e!==void 0;k.useEffect(()=>{r.current?.(y)},[y,w]),k.useEffect(()=>()=>r.current?.(void 0),[])}function Iv({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 Pv(e,t){const n=new Map(e.tiles.map((r,s)=>[Be(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Be(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Be(s)}}function Rv({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(Av)===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 _=Pv(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 Av=["[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 Lv({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 Bv({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 M=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()-M}):x.current.refused(B.reason)}).finally(()=>u(!1))},[e]),C=k.useRef(!1),j=k.useRef(!1);k.useEffect(()=>{!j.current||l||(j.current=!1,v.current?.focus())},[h,l]);const D=k.useCallback(()=>{if(!t||l||C.current||!e.canUndoSave)return;C.current=!0,u(!0);const M=S.now(),F=e.lastSave?.structural??!1,H=x.current.size;return e.undoSave().then(B=>{B.ok===!0?(j.current=!0,p(!0),x.current.undone({size:H,structural:F,durationMs:S.now()-M})):x.current.undoRefused(B.reason)}).finally(()=>{C.current=!1,u(!1)})},[t,l,e]),E=k.useCallback(()=>{if(!(!t||!e.dirty||l))return T()},[t,e,l,T]),R=k.useRef(E);R.current=E;const P=k.useCallback(()=>{const M=()=>R.current();return f?f(M):M()},[f]),A=Lv({dirty:g,saving:l,canSave:!!t,save:P,onExit:()=>r?.()});ef(k.useMemo(()=>({...d,undo:e.undo,redo:e.redo,...t?{save:P}:{},paused:A.dialog.open}),[d,e,t,P,A.dialog.open]));const U=!!t&&!l&&e.canUndoSave,z=e.lastSave,q={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:_,saving:l,saveButton:v,...t?{onSave:P}:{},...r?{onExit:A.requestExit}:{}};return{saving:l,save:P,exitGuard:A,...r?{done:A.saveAndExit}:{},undoSave:D,canUndoSave:U,lastSave:z,toolbarProps:q}}const Fv=1;function Ku(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(...Ku(a,`${t}${i}.`,n-1))}}}return r}function zv(e){const t=new Map;for(const n of Yu(e))t.set(n.name,Ku(n.schema?.fields,"",Fv));return t}function Yu(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 Wv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&Ju.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Nv(e){const t=new Map;for(const n of Yu(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(Wv)&&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 Il=(e,t)=>e!==void 0&&t.has(e),Pl=e=>e.path||e.modelPath||"";function Xu(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=Pl(a);if(Il(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=Pl(a);if(Il(c,t))continue;const f=zv(a),d=Nv(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 Gv({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(()=>mf(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(!le(_))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)||!yr(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&&Sf(_,x),kf(_,p,v)})},dropControl:p=>{i(void 0),e.update(v=>$f(v,p))}}}function Vv(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,j]=k.useState(void 0),D=k.useCallback(B=>{d(void 0),o(W=>{const Q=structuredClone(W.stack[W.index]);if(B(Q),JSON.stringify(Q)===JSON.stringify(W.stack[W.index]))return W;const ee=[...W.stack.slice(0,W.index+1),Q].slice(-100);return{stack:ee,index:ee.length-1}})},[]),E=k.useCallback(()=>{d(void 0),o(B=>B.index>0?{...B,index:B.index-1}:B)},[]),R=k.useCallback(()=>{d(void 0),o(B=>B.index<B.stack.length-1?{...B,index:B.index+1}:B)},[]),P=k.useCallback(async(B,W)=>{try{return await t(B,W)}catch(Q){return{ok:!1,reason:`Could not build the file: ${Q instanceof Error?Q.message:String(Q)}`}}},[t]),A=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},W=s?.(l,_)??!1,Q=r?.(l,_)??!1;T(!0);try{const J=await P(a,_);if(Ks(J))return d(J.reason),{ok:!1,reason:J.reason};try{await n?.(J.source,{purpose:"save",document:_})}catch(te){const Z=`Could not save: ${te instanceof Error?te.message:String(te)}`;return d(Z),{ok:!1,reason:Z}}c(J.source),u(_),p(void 0),x(!1);const ee=W?{stack:[_],index:0}:B.history;return o(te=>te===B.history?ee:W?{stack:[te.stack[te.index]],index:0}:te),j(n?{before:B,after:ee,lastSave:{before:h??a,after:J.source,structural:Q,clearsHistory:W}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[_,P,n,a,l,h,v,s,r]),U=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(W){const Q=`Could not undo the save: ${W instanceof Error?W.message:String(W)}`;return d(Q),{ok:!1,reason:Q}}finally{T(!1)}return c(B.source),u(B.saved),p(B.replacing),x(B.unwritten||B.replacing!==void 0),o(W=>W===C.after?B.history:W),j(void 0),d(void 0),{ok:!0}},[n,C]),z=k.useMemo(()=>v||JSON.stringify(_)!==JSON.stringify(l),[_,l,v]),q=k.useMemo(()=>r?.(l,_)??!1,[_,l,r]),M=k.useMemo(()=>s?.(l,_)??!1,[_,l,s]),F=C!==void 0&&C.after===i,H=k.useCallback(async()=>{const B=await P(a,_);return Ks(B)?{ok:!1,reason:B.reason}:{ok:!0,source:B.source}},[_,P,a]);return{document:_,saved:l,source:a,canUndo:i.index>0,canRedo:i.index<i.stack.length-1,dirty:z,edited:z,...f===void 0?{}:{error:f},update:D,undo:E,redo:R,save:A,preview:H,structural:q,clearsHistory:M,canUndoSave:F&&!w&&n!==void 0,...F?{lastSave:C.lastSave}:{},undoSave:U}}const Uv=(e,t)=>{const n=new Set(e.tiles.map($o)),r=new Set(t.tiles.map($o));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Hv(e){const{visibleSources:t,...n}=e,r=k.useCallback((s,i)=>Vu(s,i,t?{visibleSources:t}:{}),[t]);return Vv({...n,splice:r,structural:Uv})}function qv({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 Kv({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=>of(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(Me).map(D=>D.name));let j=1;for(;C.has(`text_${j}`);)j++;T.tiles.splice(b??T.tiles.length,0,{kind:"text",name:`text_${j}`,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 j=C.tiles.find(D=>Be(D)===b);j&&T(j)}),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&&le(T)&&Es(T)===void 0?b+1:void 0;e.update(j=>{af(j,b)}),C!==void 0&&s(C)}}}var Yv=Object.defineProperty,Xv=Object.defineProperties,Qv=Object.getOwnPropertyDescriptors,Rl=Object.getOwnPropertySymbols,Zv=Object.prototype.hasOwnProperty,Jv=Object.prototype.propertyIsEnumerable,Al=(e,t,n)=>t in e?Yv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,un=(e,t)=>{for(var n in t||(t={}))Zv.call(t,n)&&Al(e,n,t[n]);if(Rl)for(var n of Rl(t))Jv.call(t,n)&&Al(e,n,t[n]);return e},fn=(e,t)=>Xv(e,Qv(t));function ey(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function us(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 ty(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:us(e,i.initialGroup),w=i.initialIndex,b=i.group==null?void 0:us(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=us(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:us(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 ny(e,t){return ty(e,t,ey)}function ry({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===$u){const{after:x}=h.data,_=p.findIndex(w=>Be(w)===u.id);if(_<0||x===u.id)return;const y=p.filter((w,b)=>b!==_).findIndex(w=>Be(w)===x)+1;v=Ag(p,_,y)}else{const x=p.map(Be),_=ny(x,l);if(_.every((y,w)=>y===x[w]))return;const g=new Map(p.map(y=>[Be(y),y]));v=Rg(_.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=>Be(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 sy({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 Oa({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,allowLayoutChange:o=!0,renderTile:a,renderViewPreview:c,controls:f,givens:d,catalog:l,toolbar:u,dashboards:h,onEvent:p,savesTo:v="package",saveLabel:x,replaces:_,modelPath:g,visibleSources:y,addFilterDisabledReason:w,fixedFilters:b,onOpenModel:T,takenGivenNames:C,onControlsChange:j,draftKey:D}){const E=Hv({source:e,document:t,...n?{onSave:n}:{},..._!==void 0?{replaces:_}:{},...y?{visibleSources:y}:{}}),R=S.useReportDraft(D,E,e),P=k.useRef(null),{selected:A,descriptionSelected:U,selectTile:z,deselectTile:q,selectDescription:M,clearSelection:F,flash:H,stepEditor:B}=Rv({editor:E,gridBox:P}),W=S.layoutRules(E.document.layout,E.document.columns),{columns:Q}=W,J=g?.split("/").at(-1)?.replace(/\.malloy$/,""),ee=ry({tiles:E.document.tiles,commit:G=>E.update(ne=>{ne.tiles=G}),onLanded:z}),{dragging:te}=ee,Z=S.useDefaultTileSpan(P,Q),xe=k.useMemo(()=>E.document.tiles.map(G=>G.colspan===void 0?{...G,colspan:Z}:G),[E.document.tiles,Z]),Re=sy({tiles:xe,columns:Q,gridBox:P,onStart:z,commit:(G,ne)=>E.update(ve=>{const ae=ve.tiles[G];ae&&(ae.colspan=ne)})}),ue=Kv({editor:E,rules:W,modelPath:g,textHeld:y!==void 0,selectTile:z,deselectTile:q}),{menu:we,addingTile:fe,openAdd:_e}=ue,X=Gv({editor:E,opened:t,givens:d,catalog:l}),{filterDialog:Ue,setFilterDialog:he}=X,[oe,Ae]=k.useState(void 0),{draftDirty:ze,openDraft:pe,prepare:We}=qv({editorDirty:E.dirty}),He=k.useMemo(()=>({escape:()=>{!we&&!Ue&&!fe&&oe===void 0&&F()},nudge:G=>{if(te||A===void 0||!W.widths)return;const ne=E.document.tiles[A];if(!ne||le(ne)&&ne.declaration.kind==="inherited")return;const ve=S.nudgedSpan(ne.colspan??Z,G,Q);ve!==(ne.colspan??Z)&&E.update(ae=>{ae.tiles[A].colspan=ve})}}),[Z,E,we,Ue,fe,oe,F,A,Q,W,te]),O=Bv({editor:B,extraDirty:ze,keepsEdits:D!==void 0&&R.keeping,prepare:We,unit:{name:"tile",count:G=>G.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:He,report:Mv({size:E.document.tiles.length,path:g??"",layout:E.document.layout,savesTo:v,onEvent:p})}),L=E.document.tiles.length===0,N=y===void 0&&o?{layout:E.document.layout,onLayoutChange:G=>{const ne=E.document.layout;G!==ne&&(E.update(ve=>{ve.layout=G}),S.reportEmitter({path:g??"",layout:G},p).emit({type:"report.layout_changed",from:ne,to:G}))}}:void 0,{toolbarProps:I}=O;jv(j,{status:O.saving?"saving":I.dirty?"unsaved":"saved",saveTarget:x??Pi[v],...I.onSave?{save:I.onSave}:{},canUndo:I.canUndo,undo:I.onUndo,canRedo:I.canRedo,redo:I.onRedo,...N?{layout:{value:N.layout,set:N.onLayoutChange}}:{},add:{...l?{tile:()=>ue.openAdd()}:{},text:ue.appendText,...w!==void 0?{filterUnavailable:w}:L?{filterUnavailable:"Add a tile before a filter."}:{filter:()=>he({})}},...I.onExit?{exit:I.onExit}:{},...O.done?{done:O.done}:{},...R.keptAt!==void 0?{draftKeptAt:R.keptAt}:{},...I.dirty&&D!==void 0?{discard:R.discard}:{}});const V=j?void 0:m.jsx(tf,{...O.toolbarProps,...u?{actions:u}:{},...l?{onAddTile:()=>_e()}:{},savesTo:v,...x?{saveLabel:x}:{},...N??{}});return m.jsx(uu.Provider,{value:pe,children:m.jsx($.Stack,{className:S.reportClasses.builder,"data-saves-to":v,sx:{gap:0,mx:`-${Oi}px`},children:m.jsxs(S.ReportPage,{layout:W.layout,sx:{px:`${Oi}px`,pb:`${Oi}px`},header:m.jsx(Dv,{editor:E,documentSlug:J,actions:V,descriptionSelected:U,selectDescription:M}),controls:L?void 0:m.jsx(Iv,{controls:X.controlList,unknownFieldsOf:X.unknownFieldsOf,onEdit:G=>he({control:G}),onAdd:()=>he({}),...w?{addDisabledReason:w}:{},onRemove:X.dropControl,...b?{fixedFilters:b}:{},...T?{onOpenModel:T}:{},...E.document.startingGivens?{startingValues:E.document.startingGivens}:{},onStartingValue:(G,ne)=>E.update(ve=>{const ae={...ve.startingGivens??{}};ne===void 0?delete ae[G]:ae[G]=ne,Object.keys(ae).length>0?ve.startingGivens=ae:delete ve.startingGivens}),children:f}),children:[L&&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."}),l&&m.jsx($.Button,{size:"small",startIcon:m.jsx(S.AddIcon,{}),onClick:()=>_e(),children:"Add tile"})]}),R.restored&&m.jsx($.Alert,{severity:R.restored.pending?"warning":"info",onClose:R.dismissRestored,action:R.restored.pending?m.jsxs(m.Fragment,{children:[m.jsx($.Button,{color:"inherit",size:"small",onClick:R.restoreOffered,children:"Restore them"}),m.jsx($.Button,{color:"inherit",size:"small",onClick:R.discard,children:"Discard"})]}):m.jsx($.Button,{color:"inherit",size:"small",onClick:R.discard,children:"Discard edits"}),children:R.restored.pending?`You have unsaved edits from ${Ll(R.restored.savedAt)}, made before this report changed. Restoring them replaces the current version.`:`Restored your unsaved edits from ${Ll(R.restored.savedAt)}.`}),E.error&&m.jsx($.Alert,{severity:"warning",children:E.error}),m.jsx(Tv,{editor:E,reorder:ee,resizing:Re,gridBox:P,defaultSpan:Z,rules:W,canAdd:!!l,selected:A,flash:H,menuIndex:we?.index,onSelect:z,onOpenMenu:(G,ne)=>{z(ne),ue.setMenu({anchor:G,index:ne})},onRemove:ue.removeTile,...E.document.tiles.length===1&&E.saved.tiles.length>0?{removeBlocked:"A saved report needs at least one tile."}:{},openAdd:_e,editTile:ue.editTile,...a?{renderTile:a}:{}}),m.jsx(Rf,{editor:E,catalog:l,columns:Q,dashboards:h,bindings:X,tiles:ue,drillSource:oe,setDrillSource:Ae,exitDialog:O.exitGuard.dialog,...c?{renderViewPreview:c}:{},...C?{takenGivenNames:C}:{}})]})})})}function Ll(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 iy=S.createSvgIcon(m.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"})),oy=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"})),ay=S.createSvgIcon(m.jsx("path",{d:"M3 18h12v-2H3zM3 6v2h18V6zm0 7h18v-2H3z"})),ly=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 cy({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(dy,{controls: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:Ts(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:Ts(s.ui),children:m.jsx(zl,{fontSize:"small"})})})}),(e.layout||h)&&m.jsx($.Divider,{orientation:"vertical",sx:vr}),e.layout&&m.jsx($.Tooltip,{title:"Layout: tiles side by side, or one after another",children:m.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:e.layout.value,"aria-label":"Layout",onChange:(v,x)=>{x&&x!==e.layout?.value&&e.layout?.set(x)},sx:En(i,s.ui),children:[m.jsx($.ToggleButton,{value:"linear","aria-label":"Linear layout",children:"Linear"}),m.jsx($.ToggleButton,{value:"grid","aria-label":"Grid layout",children:"Grid"})]})}),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:{...mr(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(ji,{icon:m.jsx(oy,{}),title:"Tile",detail:"A view from the model",onClick:p(u.tile)}),u?.text&&m.jsx(ji,{icon:m.jsx(ay,{}),title:"Text",detail:"Prose between the tiles",onClick:p(u.text)}),(u?.filter||u?.filterUnavailable)&&m.jsx(ji,{icon:m.jsx(iy,{}),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:vr}),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:{...mr(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:{...mr(i,o,s.ui),minWidth:72},children:e.status==="saving"?"Saving…":"Save"})})})]})}function dy({controls:e}){const{theme:t}=Se.usePublisherTheme(),n=t.ui,[r,s]=k.useState(null),{status:i,draftKeptAt:o,discard:a}=e,c=i==="saved"?"Saved":i==="saving"?"Saving…":o!==void 0?"Draft saved":"Unsaved changes",f=i==="unsaved"&&o!==void 0?"Your edits are kept in this browser. Done saves them to the report.":e.saveTarget,d=a!==void 0&&i==="unsaved",l=p=>({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"?p.palette.text.secondary:p.palette.text.primary,transition:`color ${S.MOTION_FAST}, background-color ${S.MOTION_FAST}`,...d?{"&:hover":{bgcolor:p.palette.action.hover}}:{}}),u=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",sx:p=>({width:7,height:7,borderRadius:"50%",bgcolor:i==="saving"||o!==void 0?p.palette.text.disabled:p.palette.warning.main})})}),m.jsx($.Box,{component:"span","aria-hidden":!0,children:c}),m.jsx(S.ExpandMoreIcon,{"aria-hidden":!0,sx:{fontSize:16,ml:-.25,visibility:d?"visible":"hidden"}})]}),h=m.jsx($.Box,{component:"span",role:"status","aria-live":"polite",sx:uy,children:c});return m.jsxs(m.Fragment,{children:[h,m.jsx($.Tooltip,{title:f,describeChild:!0,children:d?m.jsx($.ButtonBase,{className:S.reportClasses.saveStatus,"aria-label":c,"aria-haspopup":"menu","aria-expanded":r!==null,onClick:p=>s(p.currentTarget),sx:l,children:u}):m.jsx($.Box,{component:"span",className:S.reportClasses.saveStatus,sx:l,children:u})}),m.jsxs($.Menu,{className:S.reportClasses.menu,anchorEl:r,open:r!==null,onClose:()=>s(null),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:[o!==void 0&&m.jsxs($.Box,{component:"li",role:"presentation",sx:{px:1.75,pt:.75,pb:1,...n.type.caption,color:"text.secondary"},children:["Kept in this browser at"," ",new Date(o).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),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(ly,{fontSize:"small"}),"Discard edits"]})]})]})}const uy={position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},fy=(e,t)=>({minWidth:260,mt:.5,borderRadius:t.radius.menu,border:`1px solid ${e}`,boxShadow:t.shadow.menu});function ji({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 le(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)le(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(!le(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: ${ge.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?Xu(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,opened:i,replaces:o,onSave:a,onDirtyChange:c,onExit:f,onOpenModel:d,onControlsChange:l,draftKey:u,allowLayoutChange:h,onEvent:p,savesTo:v,saveLabel:x,note:_}){const{apiClients:g}=Se.useServer(),[y,w]=k.useState(i.document.tiles.length>0);k.useEffect(()=>w(i.document.tiles.length>0),[i.generation,i.document]);const{data:b,isSuccess:T,isError:C}=S.useQueryWithApiError({...S.reportQueryOptions(g,{environmentName:t,packageName:n,path:r,versionId:s},S.BUILDER_HANDOFF_STALE_MS),enabled:y&&!e}),j=e?.modelPath??r,D=_y(i.source,e?.compileSource),E=S.useCompiledDocument({environmentName:t,packageName:n,modelPath:j,source:D.text??i.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0&&D.text!==void 0}),R=E.data?.document,P=e?E.isSuccess?R?.manifest??by:void 0:b,A=e?E.isSuccess:T,U=e?E.isError||D.problem!==void 0:C,z=e?S.documentPreamble(R?.cells):void 0,q=(E.data?.result.problems??[]).filter(I=>I.severity==="error"),M=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),F=e?.givens,H=k.useMemo(()=>new Set((P?.tiles??[]).flatMap(I=>I.restricted&&I.query?[_n(I.query)]:[])),[P]),{reports:B,settled:W}=S.useReportListing(t,n,s),Q=k.useMemo(()=>B.map(I=>I.path).filter(I=>!!I&&I!==r&&I.endsWith(".malloy")).map(I=>I.replace(/\.malloy$/,"")),[B,r]),J=yy({environmentName:t,packageName:n,...s!==void 0?{versionId:s}:{},modelPath:r,reports:B,reportsSettled:W}),ee=k.useMemo(()=>e?(J?.sources??[]).filter(I=>(I.visibleIn??I.exporters??[I.modelPath]).includes(j)).map(I=>I.name):void 0,[J,e,j]),te=k.useMemo(()=>J&&ee?{sources:J.sources.filter(I=>ee.includes(I.name))}:J,[J,ee]),[Z,xe]=k.useState(i.document);k.useEffect(()=>xe(i.document),[i.document]);const Re=k.useMemo(()=>a&&(async(I,V)=>{await a(I,V.document.layout),v==="package"&&w(V.document.tiles.length>0)}),[a,v]),ue=k.useMemo(()=>(P?.givens??[]).filter(I=>!(e&&I.secure===!0)&&!(I.name!==void 0&&M.has(I.name))),[P,M,e]),we=k.useMemo(()=>new Set([...ue.map(I=>I.name).filter(I=>I!==void 0),...Object.keys(F??{})]),[ue,F]),fe=k.useMemo(()=>new Map((P?.tiles??[]).flatMap(I=>I.kind!=="text"&&I.query&&I.givenNames?[[_n(I.query),I.givenNames]]:[])),[P]),_e=k.useMemo(()=>py(Z,i.document,fe),[Z,i.document,fe]),X=k.useMemo(()=>hy(Z,ue,_e),[Z,ue,_e]),Ue=k.useMemo(()=>{const I=new Set(Z.tiles.flatMap(ae=>le(ae)?(ae.filters??[]).map(Ne=>Ne.given):[])),V=new Set((Z.localGivens??[]).map(ae=>ae.name)),G=[...new Set(Z.imports.map(ae=>ae.from))],ne=G.length===1?ky(r,G[0]):G.length===0&&e?e.modelPath:void 0,ve=ae=>{const Ne=Z.sources.filter(et=>et.scopedBy?.includes(ae)).map(et=>et.name);return Ne.length>0?{reason:`Applied to every tile on ${Ne.join(", ")} by this report's own source. Edit the file to change it.`}:V.has(ae)?{reason:"Read by a query in this report the builder cannot edit. Edit the file to change it."}:ne!==void 0?{reason:`Set in the model ${ne}. Edit the model to change it.`,modelPath:ne}:{reason:"Set in a model this report imports. Edit the model to change it."}};return new Map([..._e].filter(ae=>!I.has(ae)).map(ae=>[ae,ve(ae)]))},[Z,_e,e,r]),{declaredTypes:he,applied:oe,panel:Ae}=S.useDocumentControls({specs:X,loaded:A,startingValues:P?.startingGivens,documentKey:`${t}/${n}/${s??""}/${r}/edit`,autorun:P?.autorun!==!1,environmentName:t,packageName:n,modelPath:e?j:P?.path,versionId:s,documentName:r,...z!==void 0?{preamble:z}:{},...F?{hostGivens:F}:{}}),ze=k.useMemo(()=>S.missingRequiredGivens(X,oe,F),[X,oe,F]),pe=k.useMemo(()=>Object.fromEntries(Object.entries(F??{}).filter(([I])=>!he.has(I))),[F,he]),We=!y||A||U,He=e!==void 0&&(D.problem!==void 0||E.isError||q.length>0),O=k.useMemo(()=>new Map(i.document.tiles.map(I=>[Be(I),I])),[i.document]),L=k.useMemo(()=>function(V,G,ne="card"){if(He)return m.jsxs(S.TileCard,{chrome:ne,children:[m.jsx(S.TileHeading,{title:G?.title??kn(V),subtitle:G?G.subtitle:V.subtitle}),m.jsx($.Typography,{variant:"body2",sx:{color:"text.secondary",py:1},children:"Not run: this document did not compile."})]});if(!We)return m.jsxs(S.TileCard,{chrome:ne,children:[m.jsx(S.TileHeading,{title:G?.title??kn(V),subtitle:G?G.subtitle:V.subtitle}),m.jsx(S.Loading,{text:"Running…"})]});const ve=fe.get(_n(`${V.source} -> ${V.name}`)),Ne=z===void 0&&ve!==void 0&&wy(O.get(Be(V)),V)?{expression:`${V.source} -> ${V.name}`,givenNames:[...ve],reads:[...ve]}:vy(Z,V,we,oe,ve);return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:j,...z!==void 0?{preamble:z}:{},...H.has(_n(`${V.source} -> ${V.name}`))?{restricted:!0}:{},tile:Ne.expression,...Ne.annotation?{annotation:Ne.annotation}:{},label:kn(V),chrome:ne,subtitle:V.subtitle,...G?{heading:G}:{},borderless:V.borderless,givens:oe,hostGivens:pe,declaredTypes:he,givenNames:Ne.givenNames,...(()=>{const et=S.waitingOn(ze,Ne.reads??Ne.givenNames);return et.length>0?{waitingFor:S.waitingText(et)}:{}})(),ignoredFilters:S.tileIgnoredFilterLabels(Ne.reads,X),height:S.TILE_MAX_HEIGHT})},[Z,O,We,He,ze,we,fe,t,n,s,j,z,H,oe,pe,he,X]),N=k.useMemo(()=>function(V){return m.jsx(S.DashboardTile,{environmentName:t,packageName:n,versionId:s,modelPath:V.modelPath,tile:`${V.base} -> ${V.view}`,...V.chart?{annotation:S.chartLineText(V.chart,V.chartCarried)}:{},label:V.label,borderless:!0,givens:oe,hostGivens:pe,declaredTypes:he,givenNames:V.givens,height:200})},[t,n,s,oe,pe,he]);return m.jsxs($.Stack,{sx:{gap:1},children:[e&&q.length>0&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",q.map(I=>I.message).join("; ")]}),ze.length>0&&!He&&m.jsx($.Alert,{severity:"info",children:S.requiredPrompt(ze)}),e&&D.problem!==void 0&&m.jsxs($.Alert,{severity:"error",children:["This document could not be prepared to compile:"," ",D.problem]}),e&&E.isError&&m.jsxs($.Alert,{severity:"error",children:["The server could not compile this document:"," ",E.error?.message]}),m.jsx(Oa,{...e&&!e.compileSource?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:i.source,document:i.document,fixedFilters:Ue,...e?.takenGivenNames?{takenGivenNames:e.takenGivenNames}:{},renderTile:L,renderViewPreview:N,givens:X.filter(I=>I.name!==void 0).map(I=>({name:I.name,...I.label?{label:I.label}:{},...I.type?{type:I.type}:{},...I.suggest?.dimension?{field:I.suggest.dimension}:{}})),onChange:xe,onDirtyChange:c,...f?{onExit:f}:{},...d?{onOpenModel:d}:{},...l?{onControlsChange:l}:{},...u!==void 0?{draftKey:u}:{},...h!==void 0?{allowLayoutChange:h}:{},...te?{catalog:te}:{},dashboards:Q,...p?{onEvent:p}:{},controls:A?m.jsx(S.GivensPanel,{...Ae,layout:"bar"}):void 0,...Re?{onSave:Re}:{},savesTo:v,...x?{saveLabel:x}:{},...o!==void 0?{replaces:o}:{},modelPath:r,...e?{visibleSources:ee}:{}}),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 qs(e);return Us(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((oe,Ae)=>{try{p.current?.(S.withReportContext(oe,{...v.current,...Ae?{layout:Ae}:{}}))}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),[j,D]=k.useState(l?Ey:void 0),E=k.useRef(void 0),R=k.useRef(void 0),[P,A]=k.useState(void 0),U=k.useRef(i);U.current=i;const z=P!==void 0&&P.onFetch===i?P.text:s,q=k.useRef(z);q.current=z;const M=b?t:z,[F,H]=k.useState(!1),[B,W]=k.useState(void 0),[Q,J]=k.useState(void 0),ee=M!==void 0&&M!==Q,te=T?.source,xe=ee&&(F||!_&&t!==void 0&&te===t&&t!==z)&&te!==void 0&&M!==B,Re=xe?te:ee?M:te??M,ue=xe?M:void 0,we=k.useRef(te);we.current=te;const fe=k.useRef(M);fe.current=M;const _e=k.useRef("package");_e.current=b?_?"record":"draft":"package",k.useEffect(()=>{if(Re===void 0||!n||g||Re===we.current)return;let oe=!1;const Ae=q.current,ze=fe.current;return Ty(Re).then(pe=>{if(!oe){if(pe.ok===!1){D(pe.reason),x.current({type:"report.load_failed",surface:"edit",category:"invalid"});return}D(void 0),E.current=void 0,R.current=Ae,A(void 0),W(void 0),J(ze),C(We=>({source:Re,document:pe.document,...Ae!==void 0?{packageText:Ae}:{},generation:(We?.generation??0)+1})),x.current({type:"report.opened",surface:"edit",from:_e.current,tiles:pe.document.tiles.length,durationMs:S.now()-h.current},pe.document.layout)}}).catch(pe=>{if(oe)return;const We=`Could not read the ${d}: ${pe instanceof Error?pe.message:String(pe)}`;D(We),x.current({type:"report.load_failed",surface:"edit",category:S.failureCategory(pe)})}),()=>{oe=!0}},[Re,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&&D("the host's storage has no document at this location."):D("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 X=f&&!u&&!T&&n&&!b&&o&&s===void 0;return k.useEffect(()=>{X&&(D(Cy),x.current({type:"report.load_failed",surface:"edit",category:"forbidden"}))},[X]),{authoritative:_,blockedOnRecord:g,resume:y,setResume:w,fromDraft:b,opened:T,setOpened:C,openError:j,savedHashRef:E,packageBaseRef:R,setWrote:A,fetchedAtRef:U,setDirty:H,setSeen:J,held:ue,choose:oe=>{h.current=S.now(),W(oe?t:z),w(oe)},acceptHeld:()=>{h.current=S.now(),W(ue)}}}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 j=k.useCallback(B=>t===void 0?void 0:S.locatorFor(B,t.name,s,i,o),[t,s,i,o]),D=j(n),E=k.useCallback(async(B,W=n)=>{const Q=j(W);if(!e||!Q)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(Q,B),x(J=>J&&{...J,source:B}),_(B),(h||p===!0)&&y(B),h||v(J=>J??!1)},[e,j,n,h,p,x,_,y,v]),[R,P]=k.useState(void 0),A=k.useCallback(async B=>{const W=await S.expectedHashFor(b.current,T.current);if(W===void 0)throw new Error("The package file is still loading; try again.");const Q=["dashboard-editor-model",s,i,o,a,r];await S.writePackageFile({apiClients:c,queryClient:f,environmentName:s,packageName:i,modelPath:o,source:B,expectedHash:W,invalidateOnError:[Q],afterWrite:async J=>{if(x(ee=>ee&&{...ee,source:B}),w({text:B,onFetch:C.current}),y(B),b.current=J,P(void 0),e&&D)try{await e.deleteDocument(D),_(void 0),g(!1)}catch(ee){S.isDocumentNotFound(ee)?(_(void 0),g(!1)):P(S.storageErrorMessage(ee))}v(!1)},invalidate:[{queryKey:Q,wait:!0},{queryKey:S.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})}]}),S.invalidateReportQueries(f,s,i,o)},[c,s,i,o,a,r,e,D,f,b,T,C,x,w,y,_,g,v]),U=t?.writeable===!0,z=d===!0&&!l,{savesTo:q,pinnedPackageSave:M,writer:F}=S.saveTarget({authoritative:h,mutable:z,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!D&&U&&(!r||h),readFailed:u!==void 0});return{save:F==="storage"?E:F==="package"?A:void 0,savesTo:q,writer:F,pinnedPackageSave:M,takesWrites:z,supersedeFailure:R}}function Da(e){const{onEvent:t,loading:n,onDirtyChange:r,onExit:s,onOpenModel:i,onControlsChange:o,keepDraft:a,kind:c,path:f,textSource:d,allowLayoutChange: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:j,server:D}=Se.useServer(),E=Fl.useQueryClient(),R=k.useRef(S.now()),P=k.useRef(t);P.current=t;const A=k.useRef(r);A.current=r;const U=S.useOptionalDocumentStorage()?.documentStorage,z=f??S.legacyNamedPath(c??"dashboard",w),q=/\.malloynb$/i.test(z)||h&&/\.malloynb$/i.test(w),M=S.useQueryWithApiError({queryKey:["dashboard-editor-model",v,x,z,_,h],queryFn:()=>T.models.getModel(v,x,z,_,h?!0:void 0),enabled:g&&!q&&!p}),F=M.data?.data?.sourceText,{workspace:H,draft:B,setDraft:W,draftChecked:Q,offered:J,setOffered:ee,readFailure:te}=Sy({storage:U,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:z}),{authoritative:Z,blockedOnRecord:xe,resume:Re,setResume:ue,fromDraft:we,opened:fe,setOpened:_e,openError:X,savedHashRef:Ue,packageBaseRef:he,setWrote:oe,fetchedAtRef:Ae,setDirty:ze,setSeen:pe,held:We,choose:He,acceptHeld:O}=Oy({workspace:H,draft:B,draftChecked:Q,readFailure:te,packageText:F,fetchedAt:M.dataUpdatedAt,packageSettled:M.isSuccess&&!M.isFetching,modelPath:z,layout:u,notebook:h,noun:b,legacyFormat:q,textHeld:p,startedAt:R,onEventRef:P}),{save:L,savesTo:N,writer:I,pinnedPackageSave:V,takesWrites:G,supersedeFailure:ne}=Dy({storage:U,workspace:H,layout:u,notebook:h,environmentName:v,packageName:x,modelPath:z,versionId:_,apiClients:T,queryClient:E,mutable:C,textHeld:p,readFailure:te,authoritative:Z,resume:Re,setResume:ue,setOpened:_e,setDraft:W,setOffered:ee,setSeen:pe,setWrote:oe,savedHashRef:Ue,packageBaseRef:he,fetchedAtRef:Ae}),ve=H?.name,ae=k.useCallback(qn=>{P.current?.(S.withWorkspace(qn,ve))},[ve]),Ne=M.isError&&!fe,et=k.useRef(!1);k.useEffect(()=>{!Ne||et.current||(et.current=!0,S.reportEmitter({path:z,layout:u},P.current).emit({type:"report.load_failed",surface:"edit",category:S.failureCategory(M.error)}))},[Ne,M.error,z,u]);const Kr=k.useCallback((qn,ce)=>{ze(qn),A.current?.(ce)},[ze]),rn=a?S.reportDraftKey({server:D,environmentName:v,packageName:x,versionId:_,path:f??w}):void 0,sn=N==="host"&&H?.description?H.description:void 0,Yr=!Z&&!p&&C===void 0?j?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":S.saveCaption({authoritative:Z,mutable:G,pinnedPackageSave:V,...H?{workspace:H}:{},...te!==void 0?{readFailure:te}:{},..._!==void 0?{versionId:_}:{}}),ci=N==="package"&&G===!0&&!V&&te===void 0||Yr===sn?"":Yr;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(X)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened in the builder: ",X]});if(M.isError&&!fe)return m.jsx(S.ApiErrorDisplay,{error:M.error,context:`Opening the ${b}`});if(!fe&&(!(p||F)||!Q))return n??m.jsx(S.Loading,{text:`Opening the ${b}…`});if(xe)return m.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",b," cannot be opened: ",te]});const Qr=B!==void 0&&B!==F;return m.jsxs($.Stack,{sx:{gap:2},children:[M.isError&&m.jsxs($.Alert,{severity:"warning",children:["The ",b," could not be re-read from the server:"," ",M.error?.message,". Your edits are still here."]}),!h&&!Z&&J&&Qr&&Re===void 0&&m.jsx($.Alert,{severity:"info",action:m.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[m.jsx($.Button,{size:"small",onClick:()=>He(!0),children:"Resume"}),m.jsx($.Button,{size:"small",onClick:()=>He(!1),children:"Start from the package"})]}),children:"You have edits to this report saved in this browser that the package does not have."}),We!==void 0&&m.jsx($.Alert,{severity:"warning",action:m.jsx($.Button,{size:"small",onClick:()=>{rn!==void 0&&S.clearReportDraft(rn),O()},children:"Load it"}),children:N==="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.":N==="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."}),ne!==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:"," ",ne]}),!fe&&(n??m.jsx(S.Loading,{text:`Opening the ${b}…`})),fe&&m.jsx(xy,{environmentName:v,packageName:x,modelPath:z,...d?{textSource:d}:{},slug:w,..._!==void 0?{versionId:_}:{},opened:fe,...we&&I==="package"&&fe.packageText!==void 0?{replaces:fe.packageText}:{},onSave:L,onDirtyChange:Kr,...s?{onExit:s}:{},...i?{onOpenModel:i}:{},...o?{onControlsChange:o}:{},...rn!==void 0?{draftKey:rn}:{},...l!==void 0?{allowLayoutChange:l}:{},savesTo:N,...sn?{saveLabel:sn}:{},...t?{onEvent:ae}:{},note:ci},fe.generation)]})}const My=Da,jy=Oa;function Iy(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return m.jsx(Da,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=S.MAX_SLUG_ATTEMPTS;exports.createDocument=S.createDocument;exports.createRoute=S.createRoute;exports.locatorFor=S.locatorFor;exports.newDashboardSource=S.newDashboardSource;exports.newDocumentProblem=S.newDocumentProblem;exports.newNotebookSource=S.newNotebookSource;exports.reportPathFor=S.reportPathFor;exports.reportPathForTitle=S.reportPathForTitle;exports.slugFor=S.slugFor;exports.slugOrFallback=S.slugOrFallback;exports.useDocumentChoices=S.useDocumentChoices;exports.BuilderBar=cy;exports.DashboardBuilder=jy;exports.DashboardEditor=My;exports.NotebookEditor=Iy;exports.ReportBuilder=Oa;exports.ReportEditor=Da;exports.buildCatalog=Xu;exports.readDashboardDocument=qs;exports.readFailed=Us;exports.readReportTagOfText=Fm;exports.spliceDashboardDocument=Vu;exports.spliceFailed=Ks;