@malloy-publisher/sdk 0.9.9 → 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 (261) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-BHuJpdSn.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 +7440 -6727
  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 -23
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +22 -0
  17. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
  18. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  19. package/dist/components/Package/PackageProblems.d.ts +14 -0
  20. package/dist/components/RemoveBadge.d.ts +40 -0
  21. package/dist/components/Report/Report.d.ts +13 -4
  22. package/dist/components/Report/ReportPage.d.ts +60 -0
  23. package/dist/components/Report/layoutRules.d.ts +32 -0
  24. package/dist/components/Report/reportQuery.d.ts +30 -0
  25. package/dist/components/Report/telemetry.d.ts +0 -2
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  27. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  28. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  29. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  30. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  31. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  32. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  33. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  34. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  35. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -6
  36. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  37. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  38. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  39. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  40. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  41. package/dist/components/ReportBuilder/TileMenu.d.ts +19 -11
  42. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  43. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  44. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  45. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  46. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  47. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  48. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  49. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  50. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  51. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  52. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  53. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  54. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  55. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  56. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  57. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  58. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  59. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  60. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  61. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  62. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  63. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  64. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  65. package/dist/components/ServerProvider.d.ts +9 -0
  66. package/dist/components/controlTokens.d.ts +45 -0
  67. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  68. package/dist/components/given/FilterButton.d.ts +35 -0
  69. package/dist/components/given/GivensPanel.d.ts +2 -1
  70. package/dist/components/given/filterEditing.d.ts +54 -0
  71. package/dist/components/given/filterSummary.d.ts +9 -0
  72. package/dist/components/given/paramCodec.d.ts +11 -0
  73. package/dist/components/given/required.d.ts +25 -0
  74. package/dist/components/index.d.ts +3 -0
  75. package/dist/components/legacy/index.d.ts +1 -1
  76. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  77. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  78. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  79. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  80. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  81. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  82. package/dist/components/styles.d.ts +0 -2
  83. package/dist/hooks/useQueryResult.d.ts +7 -0
  84. package/dist/index.cjs.js +16 -19
  85. package/dist/index.es.js +8324 -7769
  86. package/dist/theme/ThemeContext.d.ts +8 -1
  87. package/dist/theme/classes.d.ts +49 -0
  88. package/dist/theme/index.d.ts +2 -0
  89. package/dist/theme/types.d.ts +7 -0
  90. package/dist/theme/ui.d.ts +75 -0
  91. package/dist/{useCompiledDocument-1dgF5CC9.es.js → useCompiledDocument-7j5cBjQd.es.js} +8768 -7912
  92. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  93. package/package.json +2 -2
  94. package/src/builder-entry.ts +9 -0
  95. package/src/components/AppDialog.tsx +23 -0
  96. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  97. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  98. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  99. package/src/components/Dashboard/DashboardView.tsx +136 -105
  100. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  101. package/src/components/Dashboard/TileCard.tsx +28 -10
  102. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  103. package/src/components/Dashboard/useStuck.ts +49 -0
  104. package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
  105. package/src/components/DocumentCreate/newNotebook.ts +26 -12
  106. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  107. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  108. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  109. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  110. package/src/components/Package/Package.create.spec.tsx +7 -6
  111. package/src/components/Package/Package.tsx +10 -7
  112. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  113. package/src/components/Package/PackageProblems.tsx +95 -0
  114. package/src/components/Prose.tsx +12 -7
  115. package/src/components/RemoveBadge.tsx +94 -0
  116. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  117. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  118. package/src/components/Report/Report.spec.tsx +50 -32
  119. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  120. package/src/components/Report/Report.tsx +45 -77
  121. package/src/components/Report/ReportPage.tsx +168 -0
  122. package/src/components/Report/layoutRules.spec.ts +35 -0
  123. package/src/components/Report/layoutRules.ts +55 -0
  124. package/src/components/Report/reportQuery.ts +53 -0
  125. package/src/components/Report/telemetry.ts +0 -2
  126. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  127. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  128. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  129. package/src/components/ReportBuilder/BuilderDialogs.tsx +30 -39
  130. package/src/components/ReportBuilder/BuilderGrid.tsx +43 -31
  131. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  132. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  133. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  134. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  135. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  136. package/src/components/ReportBuilder/FilterStrip.tsx +129 -150
  137. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  138. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  139. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  140. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  141. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -16
  142. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  143. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  144. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  145. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +41 -36
  146. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  147. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -116
  148. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  149. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  150. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  151. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  152. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  153. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  154. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  155. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  156. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  157. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  158. package/src/components/ReportBuilder/TileMenu.tsx +248 -142
  159. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  160. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  161. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  162. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  163. package/src/components/ReportBuilder/builderControls.ts +164 -0
  164. package/src/components/ReportBuilder/builderReport.ts +1 -2
  165. package/src/components/ReportBuilder/catalog.ts +10 -26
  166. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  167. package/src/components/ReportBuilder/localGiven.ts +56 -0
  168. package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
  169. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  170. package/src/components/ReportBuilder/preview.ts +60 -44
  171. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  172. package/src/components/ReportBuilder/readDocument.ts +14 -11
  173. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  174. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  175. package/src/components/ReportBuilder/reportTag.ts +28 -7
  176. package/src/components/ReportBuilder/sortable.tsx +15 -7
  177. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  178. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  179. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  180. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  181. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  182. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  183. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  184. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  185. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  186. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  187. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  188. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  189. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  190. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  191. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  192. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  193. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  194. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  195. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  196. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  197. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  198. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  199. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  200. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  201. package/src/components/ServerProvider.tsx +11 -0
  202. package/src/components/controlTokens.ts +47 -0
  203. package/src/components/drill/markDrillableCells.ts +2 -1
  204. package/src/components/given/FilterButton.spec.tsx +143 -0
  205. package/src/components/given/FilterButton.tsx +478 -0
  206. package/src/components/given/GivenInput.spec.tsx +47 -0
  207. package/src/components/given/GivenInput.tsx +20 -2
  208. package/src/components/given/GivensPanel.spec.tsx +11 -3
  209. package/src/components/given/GivensPanel.tsx +45 -44
  210. package/src/components/given/filterEditing.ts +60 -0
  211. package/src/components/given/filterSummary.spec.ts +108 -0
  212. package/src/components/given/filterSummary.ts +109 -0
  213. package/src/components/given/paramCodec.ts +1 -1
  214. package/src/components/given/required.spec.ts +60 -0
  215. package/src/components/given/required.ts +78 -0
  216. package/src/components/index.ts +9 -0
  217. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  218. package/src/components/legacy/index.ts +1 -1
  219. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  220. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  221. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  222. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  223. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  224. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  225. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  226. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  227. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  228. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  229. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  230. package/src/components/styles.ts +0 -18
  231. package/src/hooks/useGivensState.ts +7 -3
  232. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  233. package/src/hooks/useQueryResult.ts +26 -1
  234. package/src/theme/ThemeContext.tsx +21 -1
  235. package/src/theme/classes.ts +52 -0
  236. package/src/theme/index.ts +8 -0
  237. package/src/theme/resolveTheme.ts +3 -0
  238. package/src/theme/types.ts +7 -0
  239. package/src/theme/ui.spec.tsx +91 -0
  240. package/src/theme/ui.ts +115 -0
  241. package/dist/RenderedResult-Bw7EQc42.cjs.js +0 -153
  242. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  243. package/dist/components/Notebook/cellKind.d.ts +0 -20
  244. package/dist/components/Report/LinearReport.d.ts +0 -18
  245. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  246. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  247. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  248. package/dist/useCompiledDocument-BKyRnXmA.cjs.js +0 -141
  249. package/src/components/Notebook/cellKind.spec.ts +0 -199
  250. package/src/components/Notebook/cellKind.ts +0 -74
  251. package/src/components/Report/LinearReport.tsx +0 -71
  252. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  253. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  254. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  255. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  256. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  257. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  258. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  259. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  260. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  261. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -1,28 +1,41 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import AdsClickIcon from "@mui/icons-material/AdsClick";
5
- import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
6
- import { Button, Popover, Stack, Typography } from "@mui/material";
7
- import { useEffect, useId, useRef } from "react";
4
+ import { reportClasses } from "../../theme/classes";
5
+ import CheckIcon from "@mui/icons-material/Check";
6
+ import ChevronRightIcon from "@mui/icons-material/ChevronRight";
7
+ import {
8
+ Box,
9
+ Divider,
10
+ ListItemIcon,
11
+ ListItemText,
12
+ Menu,
13
+ MenuItem,
14
+ Typography,
15
+ } from "@mui/material";
16
+ import { useEffect, useRef, useState } from "react";
8
17
  import { useDraft } from "./useDraft";
9
- import { dangerTextColor } from "../../theme/motion";
18
+ import { edgeColor } from "../controlTokens";
10
19
  import { usePublisherTheme } from "../../theme/ThemeContext";
11
20
  import type { CatalogView } from "./catalog";
12
21
  import { isQueryTile, type DashboardTile, type QueryTile } from "./document";
13
- import { ChartPicker } from "./ChartPicker";
22
+ import { chartChoices } from "./ChartPicker";
23
+ import type { ChartState } from "./chartLine";
14
24
 
15
25
  /**
16
- * A tile's own settings, on the tile: a popover off its menu button, so
17
- * editing it never means scrolling away from it. Its chart, clickable cells
18
- * and removal; its width is set by dragging its right edge; its title and subtitle are edited on the tile. Its row is set by dragging it — a drop
26
+ * A tile's own settings, on the tile: a menu off its ⋯ button, so editing it
27
+ * never means scrolling away from it. Its chart (a submenu, each pick drawn at
28
+ * once), its clickable cells, and a copy of it; its title and subtitle are
29
+ * edited on the tile, its width is set by dragging its right edge, and it is
30
+ * removed from the × on its corner. Its row is set by dragging it — a drop
19
31
  * into the empty end of a row is what "start a new row" means — and its card
20
32
  * is the reader's to decide, so neither is a toggle here. Which controls it
21
33
  * answers to is not here either: filters are configured in one place, the
22
34
  * strip under the header. A chart pick commits at once, so the tile redraws
23
35
  * under the open menu (`useDraft`'s `apply`).
24
36
  *
25
- * A text tile has only Remove: its words are written on the tile itself.
37
+ * A text tile has no menu: its words are written on the tile itself, and it is
38
+ * removed from the × on its corner, as every tile is.
26
39
  */
27
40
  export interface TileMenuProps {
28
41
  anchor: HTMLElement | null;
@@ -30,12 +43,17 @@ export interface TileMenuProps {
30
43
  onClose: () => void;
31
44
  /** Apply the edited tile. Called once, on close, only when something changed. */
32
45
  onCommit: (next: DashboardTile) => void;
33
- /** Take the tile off the dashboard. Offered on every tile: order is this file's. */
34
- onRemove: () => void;
35
- /** Why removing is refused, shown beside a Remove that stays focusable; absent when it is allowed. */
36
- removeBlocked?: string;
37
- /** Open the clickable-cells window for this tile's source. */
38
- onDrills: () => void;
46
+ /**
47
+ * Open the clickable-cells window for this tile's source. Absent when the
48
+ * source declares no dimension in this file, so there is nothing a drill
49
+ * could go on: the menu then offers no Drill, rather than a window that
50
+ * explains why its own Apply is off.
51
+ */
52
+ onDrills?: () => void;
53
+ /** Copy the tile, right after it. Absent, the menu offers no Duplicate. */
54
+ onDuplicate?: () => void;
55
+ /** Why the tile cannot be copied, when it cannot: Duplicate is then listed, greyed, with this under it. */
56
+ duplicateBlocked?: string;
39
57
  /** The catalog's view the tile shows, when the catalog knows it: what decides which charts are offered. */
40
58
  view?: Pick<CatalogView, "chart" | "aggregateOnly">;
41
59
  }
@@ -45,26 +63,30 @@ const customChart = (lines: string[] | undefined) =>
45
63
  ? `This tile's chart line (${lines[0]}) is not one the builder models, so its chart cannot be changed here.`
46
64
  : `This tile has ${lines?.length ?? "several"} chart lines${lines ? ` (${lines.join(" and ")})` : ""}, so its chart cannot be changed here.`;
47
65
  const INHERITED_CHART =
48
- "This tile's view is declared on its source, so its chart is set in the model.";
66
+ "Declared on its source, so its chart is set in the model.";
49
67
 
50
68
  export function TileMenu({
51
69
  anchor,
52
70
  tile,
53
71
  onClose,
54
72
  onCommit,
55
- onRemove,
56
- removeBlocked,
57
73
  onDrills,
74
+ onDuplicate,
75
+ duplicateBlocked,
58
76
  view,
59
77
  }: TileMenuProps) {
60
- const removeReasonId = useId();
61
78
  const { theme } = usePublisherTheme();
62
- const { draft, apply, close, discard } = useDraft(
79
+ const ui = theme.ui;
80
+ const { draft, apply, close } = useDraft(
63
81
  tile,
64
82
  anchor !== null,
65
83
  onCommit,
66
84
  onClose,
67
85
  );
86
+ // Which submenu is open, anchored to its item.
87
+ const [sub, setSub] = useState<
88
+ { kind: "chart"; anchor: HTMLElement } | undefined
89
+ >(undefined);
68
90
 
69
91
  const query = draft !== undefined && isQueryTile(draft) ? draft : undefined;
70
92
  const editable =
@@ -85,138 +107,222 @@ export function TileMenu({
85
107
  if (opened)
86
108
  openedChart.current =
87
109
  tile && isQueryTile(tile) ? tile.chart : undefined;
110
+ else setSub(undefined);
88
111
  // Only on opening: the tile changes under every pick.
89
112
  // eslint-disable-next-line react-hooks/exhaustive-deps
90
113
  }, [opened]);
91
114
 
115
+ const chartState: ChartState = query?.chart ?? "default";
116
+ const choices = chartChoices(view, chartState);
117
+ const chartBlocked = !query
118
+ ? undefined
119
+ : !editable
120
+ ? INHERITED_CHART
121
+ : query.chart === "custom"
122
+ ? customChart(query.chartLines)
123
+ : undefined;
124
+ const pickChart = (next: ChartState) =>
125
+ applyQuery((t) => {
126
+ const was = openedChart.current;
127
+ // Back to where it started is no edit, so the draft must not differ from the tile.
128
+ if (next === (was ?? "default")) {
129
+ if (was === undefined) delete t.chart;
130
+ else t.chart = was;
131
+ delete t.chartCarried;
132
+ } else {
133
+ t.chart = next;
134
+ if (view) t.chartCarried = view.chart ? [view.chart] : [];
135
+ else delete t.chartCarried;
136
+ }
137
+ });
138
+
139
+ const drillBlocked = !editable
140
+ ? undefined
141
+ : onDrills
142
+ ? undefined
143
+ : "Its source declares no dimension a click could filter by.";
144
+
145
+ const subOpen = (kind: "chart") => (event: { currentTarget: HTMLElement }) =>
146
+ setSub({ kind, anchor: event.currentTarget });
147
+ const label = (text: string, value?: string, reason?: string) => (
148
+ <>
149
+ <ListItemText
150
+ primary={text}
151
+ {...(reason ? { secondary: reason } : {})}
152
+ // A reason wraps under its item rather than widening the menu.
153
+ secondaryTypographyProps={{
154
+ sx: { whiteSpace: "normal", maxWidth: 240 },
155
+ }}
156
+ />
157
+ {value && (
158
+ <Typography variant="body2" sx={{ color: "text.secondary", ml: 2 }}>
159
+ {value}
160
+ </Typography>
161
+ )}
162
+ </>
163
+ );
164
+
92
165
  return (
93
- <Popover
94
- open={anchor !== null && draft !== undefined}
95
- anchorEl={anchor}
96
- onClose={close}
97
- anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
98
- transformOrigin={{ vertical: "top", horizontal: "right" }}
99
- slotProps={{ paper: { sx: { width: 320, p: 2 } } }}
100
- >
101
- {draft && (
102
- <Stack sx={{ gap: 1.5 }}>
166
+ <>
167
+ <Menu
168
+ className={reportClasses.menu}
169
+ open={anchor !== null && draft !== undefined}
170
+ anchorEl={anchor}
171
+ onClose={close}
172
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
173
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
174
+ MenuListProps={{
175
+ dense: true,
176
+ disabledItemsFocusable: true,
177
+ "aria-label": query ? `${query.source} ${query.name}` : "Tile",
178
+ }}
179
+ // Set like the builder's other menus: a rounded, bordered card.
180
+ slotProps={{
181
+ paper: {
182
+ sx: {
183
+ minWidth: 240,
184
+ mt: 0.5,
185
+ borderRadius: ui.radius.menu,
186
+ border: `1px solid ${edgeColor(theme.cardBorder)}`,
187
+ boxShadow: ui.shadow.menu,
188
+ },
189
+ },
190
+ }}
191
+ >
192
+ {query && (
193
+ <MenuItem
194
+ aria-haspopup="menu"
195
+ aria-expanded={sub?.kind === "chart"}
196
+ disabled={chartBlocked !== undefined}
197
+ onClick={subOpen("chart")}
198
+ onKeyDown={(event) => {
199
+ // Not from a disabled Chart: the keyboard reached a
200
+ // submenu the menu says cannot apply, and a pick there
201
+ // wrote a chart the model owns over its own.
202
+ if (
203
+ event.key === "ArrowRight" &&
204
+ chartBlocked === undefined
205
+ )
206
+ setSub({
207
+ kind: "chart",
208
+ anchor: event.currentTarget,
209
+ });
210
+ }}
211
+ >
212
+ {label(
213
+ "Chart",
214
+ chartBlocked
215
+ ? undefined
216
+ : choices.find((c) => c.value === chartState)?.label,
217
+ chartBlocked,
218
+ )}
219
+ <ChevronRightIcon
220
+ fontSize="small"
221
+ sx={{ ml: 1, color: "text.secondary" }}
222
+ />
223
+ </MenuItem>
224
+ )}
225
+ {editable && (
226
+ <MenuItem
227
+ aria-haspopup="dialog"
228
+ disabled={drillBlocked !== undefined}
229
+ onClick={() => {
230
+ close();
231
+ onDrills?.();
232
+ }}
233
+ >
234
+ {label("Clickable cells…", undefined, drillBlocked)}
235
+ </MenuItem>
236
+ )}
237
+ {query && onDuplicate && (
238
+ <MenuItem
239
+ disabled={duplicateBlocked !== undefined}
240
+ onClick={() => {
241
+ close();
242
+ onDuplicate();
243
+ }}
244
+ >
245
+ {label("Duplicate", undefined, duplicateBlocked)}
246
+ </MenuItem>
247
+ )}
248
+ {query?.declaration.kind === "opaque" && (
103
249
  <Typography
104
- variant="overline"
105
- sx={{ color: theme.tileTitle, lineHeight: 1.5 }}
250
+ variant="body2"
251
+ sx={{
252
+ color: theme.tileTitle,
253
+ px: 2,
254
+ py: 0.75,
255
+ maxWidth: 260,
256
+ }}
106
257
  >
107
- {query
108
- ? `${query.source} → ${query.name}`
109
- : `Text · ${draft.name}`}
258
+ Its body is {query.declaration.why}, so a filter has no single
259
+ place to go.
110
260
  </Typography>
261
+ )}
262
+ {query && <Divider />}
263
+ {query && (
264
+ <Box
265
+ aria-hidden
266
+ sx={{
267
+ px: 2,
268
+ py: 0.5,
269
+ ...ui.type.code,
270
+ color: "text.secondary",
271
+ }}
272
+ >
273
+ {query.source} → {query.name}
274
+ </Box>
275
+ )}
276
+ </Menu>
111
277
 
112
- {query && editable && (
113
- <>
114
- <ChartPicker
115
- state={query.chart ?? "default"}
116
- view={view}
117
- cellLabel={`${query.source} ${query.name}`}
118
- {...(query.chart === "custom"
119
- ? { disabledReason: customChart(query.chartLines) }
120
- : {})}
121
- onChange={(next) =>
122
- applyQuery((t) => {
123
- const was = openedChart.current;
124
- // Back to where it started is no edit, so the draft must not differ from the tile.
125
- if (next === (was ?? "default")) {
126
- if (was === undefined) delete t.chart;
127
- else t.chart = was;
128
- delete t.chartCarried;
129
- } else {
130
- t.chart = next;
131
- if (view)
132
- t.chartCarried = view.chart
133
- ? [view.chart]
134
- : [];
135
- else delete t.chartCarried;
136
- }
137
- })
138
- }
139
- />
140
- </>
141
- )}
142
- {query && !editable && (
143
- <>
144
- <Typography
145
- variant="body2"
146
- sx={{ color: theme.tileTitle }}
147
- >
148
- Declared on its source, so its title and layout are set
149
- in the model. It can still be moved.
150
- </Typography>
151
- <ChartPicker
152
- state="default"
153
- view={view}
154
- cellLabel={`${query.source} ${query.name}`}
155
- disabledReason={INHERITED_CHART}
156
- onChange={() => {}}
157
- />
158
- </>
159
- )}
160
- {query?.declaration.kind === "opaque" && (
161
- <Typography variant="body2" sx={{ color: theme.tileTitle }}>
162
- Its body is {query.declaration.why}, so a filter has no
163
- single place to go. Everything else here is editable.
164
- </Typography>
165
- )}
166
- <Stack direction="row" sx={{ justifyContent: "space-between" }}>
167
- {editable ? (
168
- <Button
169
- size="small"
170
- startIcon={<AdsClickIcon />}
171
- aria-haspopup="dialog"
172
- onClick={() => {
173
- close();
174
- onDrills();
175
- }}
176
- >
177
- Drill
178
- </Button>
179
- ) : (
180
- <span />
181
- )}
182
- <Button
183
- color="error"
184
- size="small"
185
- startIcon={<DeleteOutlineIcon />}
186
- // aria-disabled, not disabled, so the reason stays reachable by keyboard.
187
- aria-disabled={removeBlocked !== undefined || undefined}
188
- aria-describedby={
189
- removeBlocked !== undefined ? removeReasonId : undefined
190
- }
191
- disableRipple={removeBlocked !== undefined}
192
- sx={(muiTheme) => ({
193
- // The host's destructive red (its error palette's
194
- // deeper shade), so a host themes it rather than this.
195
- color: dangerTextColor(muiTheme),
196
- ...(removeBlocked !== undefined
197
- ? { opacity: 0.5, cursor: "default" }
198
- : {}),
199
- })}
278
+ <Menu
279
+ className={reportClasses.menu}
280
+ open={sub?.kind === "chart"}
281
+ anchorEl={sub?.anchor ?? null}
282
+ onClose={() => setSub(undefined)}
283
+ anchorOrigin={{ vertical: "top", horizontal: "left" }}
284
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
285
+ MenuListProps={{
286
+ dense: true,
287
+ disabledItemsFocusable: true,
288
+ "aria-label": "Chart",
289
+ // Back out of the submenu the way into it: the arrow.
290
+ onKeyDown: (event) => {
291
+ if (event.key === "ArrowLeft") {
292
+ event.preventDefault();
293
+ setSub(undefined);
294
+ }
295
+ },
296
+ }}
297
+ >
298
+ {choices
299
+ .filter((choice) => choice.value !== "custom")
300
+ .map((choice) => (
301
+ <MenuItem
302
+ key={choice.value}
303
+ role="menuitemradio"
304
+ aria-checked={choice.value === chartState}
305
+ disabled={choice.disabled === true}
200
306
  onClick={() => {
201
- if (removeBlocked !== undefined) return;
202
- discard();
203
- onRemove();
307
+ pickChart(choice.value);
308
+ setSub(undefined);
204
309
  }}
205
310
  >
206
- Delete
207
- </Button>
208
- </Stack>
209
- {removeBlocked !== undefined && (
210
- <Typography
211
- id={removeReasonId}
212
- variant="caption"
213
- sx={{ color: theme.tileTitle }}
214
- >
215
- {removeBlocked}
216
- </Typography>
217
- )}
218
- </Stack>
219
- )}
220
- </Popover>
311
+ <ListItemText
312
+ primary={choice.label}
313
+ {...(choice.reason ? { secondary: choice.reason } : {})}
314
+ />
315
+ {choice.value === chartState && (
316
+ <ListItemIcon sx={{ minWidth: 0, ml: 2 }}>
317
+ <CheckIcon
318
+ fontSize="small"
319
+ sx={{ color: theme.accent }}
320
+ />
321
+ </ListItemIcon>
322
+ )}
323
+ </MenuItem>
324
+ ))}
325
+ </Menu>
326
+ </>
221
327
  );
222
328
  }