@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,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,10 +43,6 @@ 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
46
  /**
38
47
  * Open the clickable-cells window for this tile's source. Absent when the
39
48
  * source declares no dimension in this file, so there is nothing a drill
@@ -41,6 +50,10 @@ export interface TileMenuProps {
41
50
  * explains why its own Apply is off.
42
51
  */
43
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;
44
57
  /** The catalog's view the tile shows, when the catalog knows it: what decides which charts are offered. */
45
58
  view?: Pick<CatalogView, "chart" | "aggregateOnly">;
46
59
  }
@@ -50,26 +63,30 @@ const customChart = (lines: string[] | undefined) =>
50
63
  ? `This tile's chart line (${lines[0]}) is not one the builder models, so its chart cannot be changed here.`
51
64
  : `This tile has ${lines?.length ?? "several"} chart lines${lines ? ` (${lines.join(" and ")})` : ""}, so its chart cannot be changed here.`;
52
65
  const INHERITED_CHART =
53
- "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.";
54
67
 
55
68
  export function TileMenu({
56
69
  anchor,
57
70
  tile,
58
71
  onClose,
59
72
  onCommit,
60
- onRemove,
61
- removeBlocked,
62
73
  onDrills,
74
+ onDuplicate,
75
+ duplicateBlocked,
63
76
  view,
64
77
  }: TileMenuProps) {
65
- const removeReasonId = useId();
66
78
  const { theme } = usePublisherTheme();
67
- const { draft, apply, close, discard } = useDraft(
79
+ const ui = theme.ui;
80
+ const { draft, apply, close } = useDraft(
68
81
  tile,
69
82
  anchor !== null,
70
83
  onCommit,
71
84
  onClose,
72
85
  );
86
+ // Which submenu is open, anchored to its item.
87
+ const [sub, setSub] = useState<
88
+ { kind: "chart"; anchor: HTMLElement } | undefined
89
+ >(undefined);
73
90
 
74
91
  const query = draft !== undefined && isQueryTile(draft) ? draft : undefined;
75
92
  const editable =
@@ -90,138 +107,222 @@ export function TileMenu({
90
107
  if (opened)
91
108
  openedChart.current =
92
109
  tile && isQueryTile(tile) ? tile.chart : undefined;
110
+ else setSub(undefined);
93
111
  // Only on opening: the tile changes under every pick.
94
112
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
113
  }, [opened]);
96
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
+
97
165
  return (
98
- <Popover
99
- open={anchor !== null && draft !== undefined}
100
- anchorEl={anchor}
101
- onClose={close}
102
- anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
103
- transformOrigin={{ vertical: "top", horizontal: "right" }}
104
- slotProps={{ paper: { sx: { width: 320, p: 2 } } }}
105
- >
106
- {draft && (
107
- <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" && (
108
249
  <Typography
109
- variant="overline"
110
- 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
+ }}
111
257
  >
112
- {query
113
- ? `${query.source} → ${query.name}`
114
- : `Text · ${draft.name}`}
258
+ Its body is {query.declaration.why}, so a filter has no single
259
+ place to go.
115
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>
116
277
 
117
- {query && editable && (
118
- <>
119
- <ChartPicker
120
- state={query.chart ?? "default"}
121
- view={view}
122
- cellLabel={`${query.source} ${query.name}`}
123
- {...(query.chart === "custom"
124
- ? { disabledReason: customChart(query.chartLines) }
125
- : {})}
126
- onChange={(next) =>
127
- applyQuery((t) => {
128
- const was = openedChart.current;
129
- // Back to where it started is no edit, so the draft must not differ from the tile.
130
- if (next === (was ?? "default")) {
131
- if (was === undefined) delete t.chart;
132
- else t.chart = was;
133
- delete t.chartCarried;
134
- } else {
135
- t.chart = next;
136
- if (view)
137
- t.chartCarried = view.chart
138
- ? [view.chart]
139
- : [];
140
- else delete t.chartCarried;
141
- }
142
- })
143
- }
144
- />
145
- </>
146
- )}
147
- {query && !editable && (
148
- <>
149
- <Typography
150
- variant="body2"
151
- sx={{ color: theme.tileTitle }}
152
- >
153
- Declared on its source, so its title and layout are set
154
- in the model. It can still be moved.
155
- </Typography>
156
- <ChartPicker
157
- state="default"
158
- view={view}
159
- cellLabel={`${query.source} ${query.name}`}
160
- disabledReason={INHERITED_CHART}
161
- onChange={() => {}}
162
- />
163
- </>
164
- )}
165
- {query?.declaration.kind === "opaque" && (
166
- <Typography variant="body2" sx={{ color: theme.tileTitle }}>
167
- Its body is {query.declaration.why}, so a filter has no
168
- single place to go. Everything else here is editable.
169
- </Typography>
170
- )}
171
- <Stack direction="row" sx={{ justifyContent: "space-between" }}>
172
- {editable && onDrills ? (
173
- <Button
174
- size="small"
175
- startIcon={<AdsClickIcon />}
176
- aria-haspopup="dialog"
177
- onClick={() => {
178
- close();
179
- onDrills();
180
- }}
181
- >
182
- Drill
183
- </Button>
184
- ) : (
185
- <span />
186
- )}
187
- <Button
188
- color="error"
189
- size="small"
190
- startIcon={<DeleteOutlineIcon />}
191
- // aria-disabled, not disabled, so the reason stays reachable by keyboard.
192
- aria-disabled={removeBlocked !== undefined || undefined}
193
- aria-describedby={
194
- removeBlocked !== undefined ? removeReasonId : undefined
195
- }
196
- disableRipple={removeBlocked !== undefined}
197
- sx={(muiTheme) => ({
198
- // The host's destructive red (its error palette's
199
- // deeper shade), so a host themes it rather than this.
200
- color: dangerTextColor(muiTheme),
201
- ...(removeBlocked !== undefined
202
- ? { opacity: 0.5, cursor: "default" }
203
- : {}),
204
- })}
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}
205
306
  onClick={() => {
206
- if (removeBlocked !== undefined) return;
207
- discard();
208
- onRemove();
307
+ pickChart(choice.value);
308
+ setSub(undefined);
209
309
  }}
210
310
  >
211
- Delete
212
- </Button>
213
- </Stack>
214
- {removeBlocked !== undefined && (
215
- <Typography
216
- id={removeReasonId}
217
- variant="caption"
218
- sx={{ color: theme.tileTitle }}
219
- >
220
- {removeBlocked}
221
- </Typography>
222
- )}
223
- </Stack>
224
- )}
225
- </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
+ </>
226
327
  );
227
328
  }