@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,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 { STICKY_CONTROLS_Z } 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,
44
+ fixedFilters,
45
+ onOpenModel,
46
+ startingValues,
47
+ onStartingValue,
27
48
  children,
28
49
  }: {
29
50
  controls: BuilderControl[];
30
- tileCount: number;
31
51
  /** Bindings a control has that its tiles' sources cannot take. */
32
52
  unknownFieldsOf: (name: string, type: string | undefined) => string[];
33
53
  onEdit: (control: BuilderControl) => void;
34
54
  onAdd: () => void;
35
- /** 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. */
36
56
  addDisabledReason?: string;
37
57
  /** Take a control off the dashboard, as its window's Remove does. */
38
58
  onRemove: (name: string) => void;
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;
39
67
  /** The host's live control row. */
40
68
  children?: ReactNode;
41
69
  }) {
42
- 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
+ ]);
43
137
  return (
44
- <>
45
- {/* The filter band, as every dashboard builder has one. The header is the
46
- dashboard's controls as this FILE has them: a chip per control,
47
- which opens its window; the × on a chip removes it, as the window's
48
- Remove does. The live control row the caller
49
- passes in sits directly under, showing the same controls as a
50
- reader gets them — from the saved file. */}
51
- <Stack
52
- sx={{
53
- gap: 1,
54
- position: "sticky",
55
- // Pinned at the top of the scroller, so the controls stay in
56
- // reach on a long page.
57
- top: 0,
58
- // The page's ground, as the reader's sticky control row uses:
59
- // this bar is page chrome, not the chart canvas.
60
- zIndex: STICKY_CONTROLS_Z,
61
- bgcolor: "background.default",
62
- pb: 1,
63
- }}
64
- >
65
- <Stack
66
- direction="row"
67
- sx={{ gap: 2, alignItems: "center", minHeight: 32 }}
68
- >
138
+ // Pinned as the reader's control row is.
139
+ <StickyControls>
140
+ <FilterEditingContext.Provider value={editing}>
141
+ {live ? (
142
+ children
143
+ ) : (
69
144
  <Stack
70
145
  direction="row"
71
- // A named group, so the label is announced.
72
146
  role="group"
73
147
  aria-label="Filters"
74
- sx={{
75
- gap: 1,
76
- alignItems: "center",
77
- flexWrap: "wrap",
78
- flex: 1,
79
- minWidth: 0,
80
- }}
148
+ useFlexGap
149
+ sx={{ flexWrap: "wrap", alignItems: "center", gap: 1 }}
81
150
  >
82
- <FilterListIcon
83
- sx={{ fontSize: 18, color: theme.tileTitle, opacity: 0.7 }}
84
- />
85
- <Typography
86
- variant="subtitle2"
87
- sx={{ color: theme.tileTitle, mr: 0.5 }}
88
- >
89
- Filters
90
- </Typography>
91
- {controlList.length === 0 && (
92
- <Typography
93
- variant="body2"
94
- sx={{ color: theme.tileTitle, opacity: 0.8 }}
95
- >
96
- None yet.
97
- </Typography>
98
- )}
99
- {controlList.map((control) => {
100
- const unknown = unknownFieldsOf(
101
- control.name,
102
- control.type,
103
- );
104
- return (
105
- <Tooltip
106
- key={control.name}
107
- title={
108
- unknown.length > 0
109
- ? `$${control.name} · cannot filter on: ${unknown.join(", ")}`
110
- : `$${control.name} · ${
111
- control.origin === "dashboard"
112
- ? "declared here"
113
- : "from the model"
114
- } · ${control.boundTiles} of ${tileCount} tiles`
115
- }
116
- >
117
- <Chip
118
- size="small"
119
- // Unused says so in words, not only by fading:
120
- // the state survives colour and touch.
121
- label={`${control.label ?? control.name}${control.boundTiles === 0 ? " · unused" : ""}`}
122
- aria-label={`Edit filter ${control.name}`}
123
- // Warning where a binding names a field the source
124
- // does not have: the package would refuse the file.
125
- color={unknown.length > 0 ? "warning" : "default"}
126
- variant={
127
- control.origin === "dashboard"
128
- ? "filled"
129
- : "outlined"
130
- }
131
- onClick={() => onEdit(control)}
132
- onDelete={() => onRemove(control.name)}
133
- deleteIcon={
134
- <CancelIcon
135
- aria-label={`Remove filter ${control.name}`}
136
- />
137
- }
138
- sx={{
139
- // Faint when nothing binds it: declared, but not yet a
140
- // control a reader would see.
141
- opacity: control.boundTiles === 0 ? 0.6 : 1,
142
- cursor: "pointer",
143
- transition: `opacity ${MOTION_FAST}`,
144
- ...reducedMotionSx,
145
- }}
146
- />
147
- </Tooltip>
148
- );
149
- })}
150
- {/* Beside the chips and shaped like one, as the next filter
151
- would be: outlined where they are filled, so it reads as the
152
- empty slot rather than another filter. */}
153
- {/* A disabled button takes no pointer events, so the tooltip
154
- saying why sits on a wrapper. */}
155
- <Tooltip title={addDisabledReason ?? ""}>
156
- <span>
157
- <Chip
158
- component="button"
159
- size="small"
160
- variant="outlined"
161
- icon={<AddIcon />}
162
- label="Filter"
163
- aria-label="Add filter"
164
- aria-haspopup="dialog"
165
- disabled={addDisabledReason !== undefined}
166
- onClick={() => onAdd()}
167
- sx={{
168
- cursor: "pointer",
169
- color: theme.tileTitle,
170
- borderStyle: "dashed",
171
- "& .MuiChip-icon": {
172
- color: "inherit",
173
- fontSize: 16,
174
- },
175
- }}
176
- />
177
- </span>
178
- </Tooltip>
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}
157
+ />
158
+ ))}
159
+ <AddFilterButton />
179
160
  </Stack>
180
- </Stack>
181
-
182
- {children}
183
- </Stack>
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();