@malloy-publisher/sdk 0.9.10 → 0.9.12

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 (263) hide show
  1. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-CDiXJAh9.es.js} +102 -102
  2. package/dist/RenderedResult-De51QvsZ.cjs.js +153 -0
  3. package/dist/ServerProvider-DKrBcXL7.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-RvKSbvnL.es.js} +622 -587
  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 +72 -23
  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/Connections/common.d.ts +11 -3
  13. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  14. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  15. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  16. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  17. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  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 -8
  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 +12 -9
  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 +8418 -7722
  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-BMPDvdFx.es.js → useCompiledDocument-Bf4RSfB6.es.js} +8669 -7851
  92. package/dist/useCompiledDocument-XsQz85Ri.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/Connections/AddConnectionDialog.tsx +34 -2
  97. package/src/components/Connections/EditConnectionDialog.tsx +45 -3
  98. package/src/components/Connections/common.spec.ts +69 -0
  99. package/src/components/Connections/common.ts +132 -0
  100. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  101. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  102. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  103. package/src/components/Dashboard/DashboardView.tsx +137 -155
  104. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  105. package/src/components/Dashboard/TileCard.tsx +28 -10
  106. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  107. package/src/components/Dashboard/useStuck.ts +28 -17
  108. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  109. package/src/components/Environment/Connections.tsx +1 -0
  110. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  111. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  112. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  113. package/src/components/Package/Package.create.spec.tsx +7 -6
  114. package/src/components/Package/Package.tsx +10 -7
  115. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  116. package/src/components/Package/PackageProblems.tsx +95 -0
  117. package/src/components/Prose.tsx +12 -7
  118. package/src/components/RemoveBadge.tsx +94 -0
  119. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  120. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  121. package/src/components/Report/Report.spec.tsx +50 -32
  122. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  123. package/src/components/Report/Report.tsx +45 -77
  124. package/src/components/Report/ReportPage.tsx +168 -0
  125. package/src/components/Report/layoutRules.spec.ts +35 -0
  126. package/src/components/Report/layoutRules.ts +55 -0
  127. package/src/components/Report/reportQuery.ts +53 -0
  128. package/src/components/Report/telemetry.ts +0 -2
  129. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  130. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  131. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  132. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  133. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  134. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  135. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  136. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  137. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  138. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  139. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  140. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  141. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  142. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  143. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  144. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  145. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  146. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  147. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  148. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  149. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  150. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  151. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  152. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  153. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  154. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  155. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  156. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  157. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  158. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  159. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  160. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  161. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  162. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  163. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  164. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  165. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  166. package/src/components/ReportBuilder/builderControls.ts +164 -0
  167. package/src/components/ReportBuilder/builderReport.ts +1 -2
  168. package/src/components/ReportBuilder/catalog.ts +10 -26
  169. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  170. package/src/components/ReportBuilder/localGiven.ts +56 -0
  171. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  172. package/src/components/ReportBuilder/preview.ts +60 -44
  173. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  174. package/src/components/ReportBuilder/readDocument.ts +14 -11
  175. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  176. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  177. package/src/components/ReportBuilder/reportTag.ts +28 -7
  178. package/src/components/ReportBuilder/sortable.tsx +15 -7
  179. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  180. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  181. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  182. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  183. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  184. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  185. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  186. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  187. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  188. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  189. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  190. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  191. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  192. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  193. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  194. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  195. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  196. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  197. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  198. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  199. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  200. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  201. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  202. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  203. package/src/components/ServerProvider.tsx +11 -0
  204. package/src/components/controlTokens.ts +47 -0
  205. package/src/components/drill/markDrillableCells.ts +2 -1
  206. package/src/components/given/FilterButton.spec.tsx +143 -0
  207. package/src/components/given/FilterButton.tsx +478 -0
  208. package/src/components/given/GivenInput.spec.tsx +47 -0
  209. package/src/components/given/GivenInput.tsx +20 -2
  210. package/src/components/given/GivensPanel.spec.tsx +11 -3
  211. package/src/components/given/GivensPanel.tsx +45 -44
  212. package/src/components/given/filterEditing.ts +60 -0
  213. package/src/components/given/filterSummary.spec.ts +108 -0
  214. package/src/components/given/filterSummary.ts +109 -0
  215. package/src/components/given/paramCodec.ts +1 -1
  216. package/src/components/given/required.spec.ts +60 -0
  217. package/src/components/given/required.ts +78 -0
  218. package/src/components/index.ts +9 -0
  219. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  220. package/src/components/legacy/index.ts +1 -1
  221. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  222. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  223. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  224. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  225. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  226. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  227. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  228. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  229. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  230. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  231. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  232. package/src/components/styles.ts +0 -18
  233. package/src/hooks/useGivensState.ts +7 -3
  234. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  235. package/src/hooks/useQueryResult.ts +26 -1
  236. package/src/theme/ThemeContext.tsx +21 -1
  237. package/src/theme/classes.ts +52 -0
  238. package/src/theme/index.ts +8 -0
  239. package/src/theme/resolveTheme.ts +3 -0
  240. package/src/theme/types.ts +7 -0
  241. package/src/theme/ui.spec.tsx +91 -0
  242. package/src/theme/ui.ts +115 -0
  243. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  244. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  245. package/dist/components/Notebook/cellKind.d.ts +0 -20
  246. package/dist/components/Report/LinearReport.d.ts +0 -18
  247. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  248. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  249. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  250. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  251. package/src/components/Notebook/cellKind.spec.ts +0 -199
  252. package/src/components/Notebook/cellKind.ts +0 -74
  253. package/src/components/Report/LinearReport.tsx +0 -71
  254. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  255. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  256. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  257. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  258. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  259. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  260. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  261. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  262. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  263. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -1,186 +1,165 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import AddIcon from "@mui/icons-material/Add";
5
- import CancelIcon from "@mui/icons-material/Cancel";
6
- import FilterListIcon from "@mui/icons-material/FilterList";
7
- import { Chip, Stack, Tooltip, Typography } from "@mui/material";
8
- import type { ReactNode } from "react";
9
- import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
10
- import { StickyControls } from "../Dashboard/DashboardView";
11
- import { usePublisherTheme } from "../../theme/ThemeContext";
4
+ import { Stack } from "@mui/material";
5
+ import { useMemo, type ReactNode } from "react";
6
+ import { StickyControls } from "../Report/ReportPage";
7
+ import {
8
+ FilterEditingContext,
9
+ type FilterEditing,
10
+ } from "../given/filterEditing";
11
+ import { AddFilterButton, FilterSettingsButton } from "../given/FilterButton";
12
12
  import type { BuilderControl } from "./controls";
13
13
 
14
14
  /**
15
- * The strip where the dashboard's controls are configured — the ONE place: a
16
- * chip per control opens its window, and "Add filter" beside them declares a
17
- * new one. The live control row the host renders sits under it.
15
+ * The builder's filter row: the ONE place a report's filters are used and
16
+ * configured. It is the reader's own row of filter buttons (the host's
17
+ * `children`), with the builder's editing added through
18
+ * {@link FilterEditingContext}: a remove badge on each button's corner, its
19
+ * settings from its popover, and "+ Filter" at the end. A filter no tile reads
20
+ * yet has no control in the reader's row, so it is drawn after the row's own,
21
+ * dashed and marked unused, and opens its settings.
22
+ *
23
+ * There used to be a second row above this one: a chip per filter, naming the
24
+ * same filters again, which is where they were edited. Two rows of look-alike
25
+ * things, each doing half the job, read as a duplicate.
26
+ *
27
+ * Without a live row (no server to run the controls), every filter is drawn
28
+ * as a settings button, so the file's filters can still be edited.
18
29
  */
30
+ /** A filter the builder shows and sets but cannot change: why, and the model that sets it, if one does. */
31
+ export interface FixedFilter {
32
+ reason: string;
33
+ /** The model's package path, for "Open the model". */
34
+ modelPath?: string;
35
+ }
36
+
19
37
  export function FilterStrip({
20
38
  controls: controlList,
21
- tileCount,
22
39
  unknownFieldsOf,
23
40
  onEdit,
24
41
  onAdd,
25
42
  addDisabledReason,
26
43
  onRemove,
27
- sticky = true,
44
+ fixedFilters,
45
+ onOpenModel,
46
+ startingValues,
47
+ onStartingValue,
28
48
  children,
29
49
  }: {
30
50
  controls: BuilderControl[];
31
- tileCount: number;
32
51
  /** Bindings a control has that its tiles' sources cannot take. */
33
52
  unknownFieldsOf: (name: string, type: string | undefined) => string[];
34
53
  onEdit: (control: BuilderControl) => void;
35
54
  onAdd: () => void;
36
- /** Why adding is off; set, the chip is disabled and its tooltip says why. */
55
+ /** Why adding is off; set, the add button is disabled and says why. */
37
56
  addDisabledReason?: string;
38
57
  /** Take a control off the dashboard, as its window's Remove does. */
39
58
  onRemove: (name: string) => void;
40
- /** Pin the strip to the top of the scroller: a grid's, not a linear report's. */
41
- sticky?: boolean;
59
+ /** Filters a tile reads other than through a binding, by name: why they are fixed here, and the model that sets one. */
60
+ fixedFilters?: ReadonlyMap<string, FixedFilter>;
61
+ /** Open a model by its package path, when the host can. */
62
+ onOpenModel?: (modelPath: string) => void;
63
+ /** The report's starting values (`givens { … }`), as the file spells them. */
64
+ startingValues?: Readonly<Record<string, string>>;
65
+ /** Set a filter's starting value, or drop it with undefined. */
66
+ onStartingValue?: (name: string, text: string | undefined) => void;
42
67
  /** The host's live control row. */
43
68
  children?: ReactNode;
44
69
  }) {
45
- const { theme } = usePublisherTheme();
70
+ const live = children !== undefined && children !== null;
71
+ const editing = useMemo<FilterEditing>(() => {
72
+ const byName = new Map(controlList.map((c) => [c.name, c]));
73
+ return {
74
+ stateOf: (name) => {
75
+ // Read other than through a binding the builder writes: fixed
76
+ // here, whatever the builder knows of it.
77
+ const fixed = fixedFilters?.get(name);
78
+ if (fixed !== undefined) {
79
+ const { modelPath } = fixed;
80
+ return {
81
+ origin: "model",
82
+ fixed: fixed.reason,
83
+ ...(modelPath !== undefined && onOpenModel
84
+ ? { openModel: () => onOpenModel(modelPath) }
85
+ : {}),
86
+ };
87
+ }
88
+ const control = byName.get(name);
89
+ if (!control) return undefined;
90
+ const unknown = unknownFieldsOf(control.name, control.type);
91
+ return {
92
+ origin: control.origin,
93
+ ...(unknown.length > 0
94
+ ? {
95
+ problem: `Cannot filter on ${unknown.join(", ")}: a tile it applies to has no such field.`,
96
+ }
97
+ : {}),
98
+ };
99
+ },
100
+ // The reader's row draws a control only for a filter some tile
101
+ // reads, so the rest are drawn here.
102
+ unrendered: live
103
+ ? controlList
104
+ // A fixed filter has its control in the row already.
105
+ .filter(
106
+ (c) => c.boundTiles === 0 && !fixedFilters?.has(c.name),
107
+ )
108
+ .map((c) => ({ name: c.name, label: c.label ?? c.name }))
109
+ : [],
110
+ onEdit: (name) => {
111
+ const control = byName.get(name);
112
+ if (control) onEdit(control);
113
+ },
114
+ onRemove,
115
+ onAdd,
116
+ ...(addDisabledReason !== undefined ? { addDisabledReason } : {}),
117
+ ...(onStartingValue
118
+ ? {
119
+ startingValueOf: (name: string) => startingValues?.[name],
120
+ setStartingValue: onStartingValue,
121
+ }
122
+ : {}),
123
+ };
124
+ }, [
125
+ controlList,
126
+ unknownFieldsOf,
127
+ live,
128
+ onEdit,
129
+ onRemove,
130
+ onAdd,
131
+ addDisabledReason,
132
+ fixedFilters,
133
+ onOpenModel,
134
+ startingValues,
135
+ onStartingValue,
136
+ ]);
46
137
  return (
47
- <>
48
- {/* The filter band, as every dashboard builder has one. The header is the
49
- dashboard's controls as this FILE has them: a chip per control,
50
- which opens its window; the × on a chip removes it, as the window's
51
- Remove does. The live control row the caller
52
- passes in sits directly under, showing the same controls as a
53
- reader gets them — from the saved file. */}
54
- {/* Pinned the way the reader's control row is, and only where the
55
- reader pins it: in a grid. */}
56
- <StickyControls sticky={sticky}>
57
- <Stack sx={{ gap: 1 }}>
138
+ // Pinned as the reader's control row is.
139
+ <StickyControls>
140
+ <FilterEditingContext.Provider value={editing}>
141
+ {live ? (
142
+ children
143
+ ) : (
58
144
  <Stack
59
145
  direction="row"
60
- sx={{ gap: 2, alignItems: "center", minHeight: 32 }}
146
+ role="group"
147
+ aria-label="Filters"
148
+ useFlexGap
149
+ sx={{ flexWrap: "wrap", alignItems: "center", gap: 1 }}
61
150
  >
62
- <Stack
63
- direction="row"
64
- // A named group, so the label is announced.
65
- role="group"
66
- aria-label="Filters"
67
- sx={{
68
- gap: 1,
69
- alignItems: "center",
70
- flexWrap: "wrap",
71
- flex: 1,
72
- minWidth: 0,
73
- }}
74
- >
75
- <FilterListIcon
76
- sx={{
77
- fontSize: 18,
78
- color: theme.tileTitle,
79
- opacity: 0.7,
80
- }}
151
+ {controlList.map((control) => (
152
+ <FilterSettingsButton
153
+ key={control.name}
154
+ name={control.name}
155
+ label={control.label ?? control.name}
156
+ unused={control.boundTiles === 0}
81
157
  />
82
- <Typography
83
- variant="subtitle2"
84
- sx={{ color: theme.tileTitle, mr: 0.5 }}
85
- >
86
- Filters
87
- </Typography>
88
- {controlList.length === 0 && (
89
- <Typography
90
- variant="body2"
91
- sx={{ color: theme.tileTitle, opacity: 0.8 }}
92
- >
93
- None yet.
94
- </Typography>
95
- )}
96
- {controlList.map((control) => {
97
- const unknown = unknownFieldsOf(
98
- control.name,
99
- control.type,
100
- );
101
- return (
102
- <Tooltip
103
- key={control.name}
104
- title={
105
- unknown.length > 0
106
- ? `$${control.name} · cannot filter on: ${unknown.join(", ")}`
107
- : `$${control.name} · ${
108
- control.origin === "dashboard"
109
- ? "declared here"
110
- : "from the model"
111
- } · ${control.boundTiles} of ${tileCount} tiles`
112
- }
113
- >
114
- <Chip
115
- size="small"
116
- // Unused says so in words, not only by fading:
117
- // the state survives colour and touch.
118
- label={`${control.label ?? control.name}${control.boundTiles === 0 ? " · unused" : ""}`}
119
- aria-label={`Edit filter ${control.name}`}
120
- // Warning where a binding names a field the source
121
- // does not have: the package would refuse the file.
122
- color={
123
- unknown.length > 0 ? "warning" : "default"
124
- }
125
- variant={
126
- control.origin === "dashboard"
127
- ? "filled"
128
- : "outlined"
129
- }
130
- onClick={() => onEdit(control)}
131
- onDelete={() => onRemove(control.name)}
132
- deleteIcon={
133
- <CancelIcon
134
- aria-label={`Remove filter ${control.name}`}
135
- />
136
- }
137
- sx={{
138
- // Faint when nothing binds it: declared, but not yet a
139
- // control a reader would see.
140
- opacity: control.boundTiles === 0 ? 0.6 : 1,
141
- cursor: "pointer",
142
- transition: `opacity ${MOTION_FAST}`,
143
- ...reducedMotionSx,
144
- }}
145
- />
146
- </Tooltip>
147
- );
148
- })}
149
- {/* Beside the chips and shaped like one, as the next filter
150
- would be: outlined where they are filled, so it reads as the
151
- empty slot rather than another filter. */}
152
- {/* A disabled button takes no pointer events, so the tooltip
153
- saying why sits on a wrapper. */}
154
- <Tooltip title={addDisabledReason ?? ""}>
155
- <span>
156
- <Chip
157
- component="button"
158
- size="small"
159
- variant="outlined"
160
- icon={<AddIcon />}
161
- label="Filter"
162
- aria-label="Add filter"
163
- aria-haspopup="dialog"
164
- disabled={addDisabledReason !== undefined}
165
- onClick={() => onAdd()}
166
- sx={{
167
- cursor: "pointer",
168
- color: theme.tileTitle,
169
- borderStyle: "dashed",
170
- "& .MuiChip-icon": {
171
- color: "inherit",
172
- fontSize: 16,
173
- },
174
- }}
175
- />
176
- </span>
177
- </Tooltip>
178
- </Stack>
158
+ ))}
159
+ <AddFilterButton />
179
160
  </Stack>
180
-
181
- {children}
182
- </Stack>
183
- </StickyControls>
184
- </>
161
+ )}
162
+ </FilterEditingContext.Provider>
163
+ </StickyControls>
185
164
  );
186
165
  }
@@ -1,9 +1,18 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { Box, Button, Stack, TextField, Typography } from "@mui/material";
4
+ import { Box, InputBase, Typography } from "@mui/material";
5
5
  import { editableSx } from "./inlineEdit";
6
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
+ import { PROSE_MAX_WIDTH } from "../controlTokens";
7
+ import { MOD } from "./useBuilderShortcuts";
8
+ import {
9
+ useCallback,
10
+ useEffect,
11
+ useId,
12
+ useMemo,
13
+ useRef,
14
+ useState,
15
+ } from "react";
7
16
  import { usePublisherTheme } from "../../theme/ThemeContext";
8
17
  import { Prose, type ProseVariant } from "../Prose";
9
18
  import { useReportOpenDraft } from "./openDraft";
@@ -14,10 +23,10 @@ import { useDraft } from "./useDraft";
14
23
  * Markdown that is edited where it is read: it draws as prose, a click on it
15
24
  * opens a textarea, and what was typed commits once, when the field closes.
16
25
  *
17
- * Escape and Cmd or Ctrl+Enter are Done, which holds on a draft the writer
18
- * would refuse and says why; leaving the field commits, so the closed prose
19
- * keeps saying what Save will refuse. Links stay inert: a click on one is not
20
- * a way out of the builder, and not an edit either.
26
+ * Cmd or Ctrl+Enter finishes, holding on a draft the writer would refuse and
27
+ * saying why; Escape drops the edit; leaving the field commits, so the closed
28
+ * prose keeps saying what Save will refuse. Links stay inert: a click on one
29
+ * is not a way out of the builder, and not an edit either.
21
30
  */
22
31
  export function InlineMarkdown({
23
32
  markdown,
@@ -33,6 +42,9 @@ export function InlineMarkdown({
33
42
  variant?: ProseVariant;
34
43
  }) {
35
44
  const { theme } = usePublisherTheme();
45
+ const ui = theme.ui;
46
+ // The keys the field takes, read out with it.
47
+ const hintId = useId();
36
48
  const [editing, setEditing] = useState(false);
37
49
  // One object per value, or the draft would reset on every render while open.
38
50
  const value = useMemo(
@@ -55,7 +67,6 @@ export function InlineMarkdown({
55
67
  close();
56
68
  return true;
57
69
  });
58
- const actions = useRef<HTMLDivElement>(null);
59
70
  const caretPlaced = useRef(false);
60
71
  useEffect(() => {
61
72
  if (!editing) caretPlaced.current = false;
@@ -118,27 +129,46 @@ export function InlineMarkdown({
118
129
  if (problem === undefined) close();
119
130
  };
120
131
  return (
121
- <Stack spacing={1}>
122
- <TextField
132
+ // The text in place, in the page's own prose type: no box inside the
133
+ // tile, no buttons under it, so the tile keeps its size as it opens. No
134
+ // ring of its own either: it opens only on something already selected,
135
+ // and a second ring inside the selection's read as a box in a box.
136
+ // Leaving it or ⌘/Ctrl+Enter keeps the edit; Escape drops it, as a
137
+ // title's Escape does.
138
+ <Box
139
+ sx={{
140
+ position: "relative",
141
+ mx: "-10px",
142
+ px: "10px",
143
+ my: "-6px",
144
+ py: "6px",
145
+ }}
146
+ >
147
+ <InputBase
123
148
  multiline
124
149
  autoFocus
125
- minRows={3}
126
- maxRows={14}
150
+ minRows={2}
127
151
  fullWidth
128
152
  value={draft.text}
129
153
  placeholder={placeholder}
130
154
  error={problem !== undefined}
131
- helperText={problem}
132
155
  inputRef={placeCaret}
133
- inputProps={{ "aria-label": "Markdown" }}
156
+ inputProps={{
157
+ "aria-label": "Markdown",
158
+ "aria-describedby": hintId,
159
+ ...(problem !== undefined ? { "aria-invalid": true } : {}),
160
+ }}
134
161
  onChange={(event) =>
135
162
  patch((next) => {
136
163
  next.text = event.target.value;
137
164
  })
138
165
  }
139
166
  onKeyDown={(event) => {
140
- if (event.key === "Escape") finish();
141
- else if (
167
+ if (event.key === "Escape") {
168
+ event.preventDefault();
169
+ discard();
170
+ setEditing(false);
171
+ } else if (
142
172
  event.key === "Enter" &&
143
173
  (event.metaKey || event.ctrlKey)
144
174
  ) {
@@ -146,37 +176,33 @@ export function InlineMarkdown({
146
176
  finish();
147
177
  }
148
178
  }}
149
- // Moving to Done or Cancel is not leaving the edit.
150
- onBlur={(event) => {
151
- if (
152
- event.relatedTarget instanceof Node &&
153
- actions.current?.contains(event.relatedTarget)
154
- )
155
- return;
156
- close();
179
+ onBlur={() => close()}
180
+ sx={{
181
+ p: 0,
182
+ ...ui.type.prose,
183
+ color: "inherit",
184
+ maxWidth: PROSE_MAX_WIDTH,
185
+ "& textarea": { p: 0 },
157
186
  }}
158
187
  />
159
- <Stack ref={actions} direction="row" spacing={1}>
160
- <Button
161
- size="small"
162
- variant="outlined"
163
- disabled={problem !== undefined}
164
- onClick={finish}
165
- >
166
- Done
167
- </Button>
168
- <Button
169
- size="small"
170
- // Keeps focus in the field, whose blur would otherwise commit the draft Cancel is dropping.
171
- onMouseDown={(event) => event.preventDefault()}
172
- onClick={() => {
173
- discard();
174
- setEditing(false);
175
- }}
176
- >
177
- Cancel
178
- </Button>
179
- </Stack>
180
- </Stack>
188
+ {problem !== undefined && (
189
+ <Typography variant="caption" color="error" role="alert">
190
+ {problem}
191
+ </Typography>
192
+ )}
193
+ <Typography
194
+ id={hintId}
195
+ variant="caption"
196
+ sx={{
197
+ display: "block",
198
+ textAlign: "right",
199
+ mt: 0.5,
200
+ color: "text.secondary",
201
+ pointerEvents: "none",
202
+ }}
203
+ >
204
+ Markdown · {MOD}↩ done · Esc cancels
205
+ </Typography>
206
+ </Box>
181
207
  );
182
208
  }
@@ -12,7 +12,7 @@ import { describe, expect, it } from "bun:test";
12
12
  import { chartLineText } from "./chartLine";
13
13
  import { ReportBuilder } from "./ReportBuilder";
14
14
  import { openDocument } from "./testing/fixtures";
15
- import { closeMenu, editInline } from "./testing/inline";
15
+ import { closeMenu, editInline, viewOption } from "./testing/inline";
16
16
 
17
17
  const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
18
18
  import { scoped_orders } from "../data_app.malloy"
@@ -56,21 +56,26 @@ const mount = async (onSave?: (source: string) => void) => {
56
56
  );
57
57
  };
58
58
 
59
- const chartPicker = (name: string) =>
60
- screen.getByRole("combobox", { name: `Viz type, ${name}`, hidden: true });
61
- const optionsOf = (name: string) => {
62
- fireEvent.mouseDown(chartPicker(name));
63
- const menu = screen.getAllByRole("listbox", { hidden: true }).at(-1)!;
64
- return within(menu).getAllByRole("option", { hidden: true });
59
+ /** The open tile menu's Chart submenu: its choices, by their label. */
60
+ const primary = (item: HTMLElement) =>
61
+ item.querySelector(".MuiListItemText-primary")?.textContent;
62
+ const chartItems = () => {
63
+ fireEvent.click(
64
+ screen.getByRole("menuitem", { name: /^Chart/, hidden: true }),
65
+ );
66
+ const menu = screen.getByRole("menu", { name: "Chart", hidden: true });
67
+ return within(menu).getAllByRole("menuitemradio", { hidden: true });
65
68
  };
66
- const enabledNames = (name: string) =>
67
- optionsOf(name)
69
+ const enabledCharts = () =>
70
+ chartItems()
68
71
  .filter((o) => o.getAttribute("aria-disabled") !== "true")
69
- .map((o) => o.textContent);
70
- const choose = (name: string, option: string) =>
72
+ .map(primary);
73
+ const pickChart = (option: string) =>
71
74
  fireEvent.click(
72
- optionsOf(name).find((o) => o.textContent === option) as HTMLElement,
75
+ chartItems().find((o) => primary(o) === option) as HTMLElement,
73
76
  );
77
+ const chartItem = () =>
78
+ screen.getByRole("menuitem", { name: /^Chart/, hidden: true });
74
79
 
75
80
  describe("ReportBuilder: charts", () => {
76
81
  it("sets a tile's chart from its menu and writes the one line", async () => {
@@ -79,7 +84,7 @@ describe("ReportBuilder: charts", () => {
79
84
  written = source;
80
85
  });
81
86
  fireEvent.click(screen.getByLabelText("Settings for by_cat"));
82
- const names = enabledNames("a by_cat");
87
+ const names = enabledCharts();
83
88
  // The wrapper's view `by_category` carries a shape map, so it is enabled; the rest are listed disabled.
84
89
  expect(names).toEqual([
85
90
  "From the view",
@@ -89,7 +94,7 @@ describe("ReportBuilder: charts", () => {
89
94
  "Scatter",
90
95
  "Shape map",
91
96
  ]);
92
- choose("a by_cat", "Line");
97
+ pickChart("Line");
93
98
  closeMenu();
94
99
  fireEvent.click(
95
100
  screen.getByRole("button", { name: "Save", hidden: true }),
@@ -106,8 +111,8 @@ describe("ReportBuilder: charts", () => {
106
111
  written = source;
107
112
  });
108
113
  fireEvent.click(screen.getByLabelText("Settings for by_cat"));
109
- choose("a by_cat", "Bar");
110
- choose("a by_cat", "From the view");
114
+ pickChart("Bar");
115
+ pickChart("From the view");
111
116
  closeMenu();
112
117
  const save = screen.queryByRole("button", {
113
118
  name: "Save",
@@ -123,14 +128,7 @@ describe("ReportBuilder: charts", () => {
123
128
  written = source;
124
129
  });
125
130
  fireEvent.click(screen.getByLabelText("Settings for by_brand"));
126
- expect(
127
- screen
128
- .getByRole("combobox", {
129
- name: "Viz type, a by_brand",
130
- hidden: true,
131
- })
132
- .getAttribute("aria-disabled"),
133
- ).toBe("true");
131
+ expect(chartItem().getAttribute("aria-disabled")).toBe("true");
134
132
  expect(screen.getByText(/is not one the builder models/)).toBeDefined();
135
133
  closeMenu();
136
134
  editInline("By brand", "Tile title", "Brands");
@@ -147,14 +145,7 @@ describe("ReportBuilder: charts", () => {
147
145
  const document = await openDocument(source);
148
146
  render(<ReportBuilder source={source} document={document} />);
149
147
  fireEvent.click(screen.getByLabelText("Settings for by_brand"));
150
- expect(
151
- screen
152
- .getByRole("combobox", {
153
- name: "Viz type, orders by_brand",
154
- hidden: true,
155
- })
156
- .getAttribute("aria-disabled"),
157
- ).toBe("true");
148
+ expect(chartItem().getAttribute("aria-disabled")).toBe("true");
158
149
  expect(
159
150
  screen.getByText(/so its chart is set in the model/),
160
151
  ).toBeDefined();
@@ -168,16 +159,20 @@ describe("ReportBuilder: charts", () => {
168
159
  fireEvent.click(
169
160
  screen.getByRole("button", { name: "Add tile", hidden: true }),
170
161
  );
171
- fireEvent.click(screen.getByLabelText("View table_view"));
172
- expect(enabledNames("new tile")).not.toContain("Big value");
162
+ // The chart choices are only the ones the picked view can take.
163
+ const chartChoicesShown = () =>
164
+ within(screen.getByRole("group", { name: "Chart", hidden: true }))
165
+ .getAllByRole("button", { hidden: true })
166
+ .map((b) => b.textContent);
167
+ fireEvent.click(viewOption("table_view"));
168
+ expect(chartChoicesShown()).not.toContain("Big value");
169
+ fireEvent.click(viewOption("kpis"));
170
+ expect(chartChoicesShown()).toContain("Big value");
173
171
  fireEvent.click(
174
172
  within(
175
- screen.getAllByRole("listbox", { hidden: true }).at(-1)!,
176
- ).getByRole("option", { name: "From the view", hidden: true }),
173
+ screen.getByRole("group", { name: "Chart", hidden: true }),
174
+ ).getByRole("button", { name: "Big value", hidden: true }),
177
175
  );
178
- fireEvent.click(screen.getByLabelText("View kpis"));
179
- expect(enabledNames("new tile")).toContain("Big value");
180
- choose("new tile", "Big value");
181
176
  fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
182
177
  fireEvent.click(
183
178
  screen.getByRole("button", { name: "Save", hidden: true }),
@@ -193,7 +188,7 @@ describe("ReportBuilder: charts", () => {
193
188
  fireEvent.click(
194
189
  screen.getByRole("button", { name: "Add tile", hidden: true }),
195
190
  );
196
- fireEvent.click(screen.getByLabelText("View odd view"));
191
+ fireEvent.click(viewOption("odd view"));
197
192
  expect(
198
193
  screen.getByText(/"odd view" is not a plain Malloy name/),
199
194
  ).toBeDefined();