@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
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Alert, Box, Stack, Typography } from "@mui/material";
5
- import { useEffect, useMemo, useState } from "react";
6
- import type { DashboardManifest, Given } from "../../client";
5
+ import { useEffect, useMemo, useRef, useState } from "react";
6
+ import type { DashboardManifest } from "../../client";
7
7
  import { useCompiledDocument } from "../../hooks/useCompiledDocument";
8
8
  import { useDocumentControls } from "../../hooks/useDocumentControls";
9
9
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
@@ -20,17 +20,43 @@ import { GivensPanel } from "../given";
20
20
  import { Loading } from "../Loading";
21
21
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
22
22
  import { useReportListing } from "../Package/useDocumentLocation";
23
+ import {
24
+ BUILDER_HANDOFF_STALE_MS,
25
+ reportQueryOptions,
26
+ } from "../Report/reportQuery";
23
27
  import { useServer } from "../ServerProvider";
24
28
  import { ReportBuilder } from "./ReportBuilder";
29
+ import {
30
+ missingRequiredGivens,
31
+ requiredPrompt,
32
+ waitingOn,
33
+ waitingText,
34
+ } from "../given/required";
35
+ import type { FixedFilter } from "./FilterStrip";
25
36
  import type { ReportLayout } from "../Package/documentLocation";
26
- import type { DashboardDocument, QueryTile } from "./document";
37
+ import {
38
+ isQueryTile,
39
+ tileKey,
40
+ type DashboardDocument,
41
+ type DashboardTile as DocumentTile,
42
+ type QueryTile,
43
+ } from "./document";
27
44
  import type { SavesTo } from "./documentSession";
28
- import { previewGivens, previewTileQuery, tileExpressionKey } from "./preview";
45
+ import {
46
+ givensReadThroughModel,
47
+ previewGivens,
48
+ previewTileQuery,
49
+ tileExpressionKey,
50
+ type PreviewTileQuery,
51
+ } from "./preview";
29
52
  import type { TextSourceOptions } from "./ReportEditor";
30
53
  import type { ReportEventHandler } from "../Report/telemetry";
31
54
  import { tileDisplayTitle } from "./tileDisplayTitle";
55
+ import type { ViewPreview } from "./AddTileDialog";
56
+ import { chartLineText } from "./chartLine";
32
57
  import { useEditorCatalog } from "./useEditorCatalog";
33
58
  import type { SaveContext, SaveHandler } from "./useDocumentEditor";
59
+ import type { BuilderControlsHandler } from "./builderControls";
34
60
 
35
61
  /**
36
62
  * The builder under a real control row, with the controls driving the tiles,
@@ -48,7 +74,6 @@ const NO_MANIFEST: DashboardManifest = {};
48
74
 
49
75
  export function EditorSurface({
50
76
  textSource,
51
- modelGivens,
52
77
  environmentName,
53
78
  packageName,
54
79
  modelPath,
@@ -58,6 +83,9 @@ export function EditorSurface({
58
83
  onSave,
59
84
  onDirtyChange,
60
85
  onExit,
86
+ onOpenModel,
87
+ onControlsChange,
88
+ draftKey,
61
89
  allowLayoutChange,
62
90
  onEvent,
63
91
  savesTo,
@@ -65,8 +93,6 @@ export function EditorSurface({
65
93
  note,
66
94
  }: {
67
95
  textSource?: TextSourceOptions;
68
- /** The model's own givens, for a cell-format notebook whose manifest the server cannot build until it is saved. */
69
- modelGivens?: Given[];
70
96
  environmentName: string;
71
97
  packageName: string;
72
98
  modelPath: string;
@@ -76,14 +102,17 @@ export function EditorSurface({
76
102
  opened: {
77
103
  source: string;
78
104
  document: DashboardDocument;
79
- conversion?: { from: string; to: string };
80
105
  generation: number;
81
106
  };
82
107
  replaces?: string;
83
108
  /** Save the text, with the layout the document has as it is saved. */
84
109
  onSave?: (source: string, layout: ReportLayout) => Promise<void>;
85
- onDirtyChange: (dirty: boolean) => void;
110
+ onDirtyChange: (dirty: boolean, wouldLose: boolean) => void;
86
111
  onExit?: () => void;
112
+ onOpenModel?: (modelPath: string) => void;
113
+ onControlsChange?: BuilderControlsHandler;
114
+ /** Keep unsaved edits in this browser under this key; see `ReportBuilderProps.draftKey`. */
115
+ draftKey?: string;
87
116
  allowLayoutChange?: boolean;
88
117
  onEvent?: ReportEventHandler;
89
118
  savesTo: SavesTo;
@@ -105,48 +134,33 @@ export function EditorSurface({
105
134
  isSuccess: manifestLoaded,
106
135
  isError: manifestFailed,
107
136
  } = useQueryWithApiError({
108
- queryKey: [
109
- "dashboard-editor-manifest",
110
- environmentName,
111
- packageName,
112
- modelPath,
113
- versionId,
114
- ],
115
- // One read for either layout, by path. A report in the cell format has only the tag's starting values until it is saved.
116
- queryFn: async (): Promise<DashboardManifest> => {
117
- const read = (
118
- await apiClients.reports.getReport(
119
- environmentName,
120
- packageName,
121
- modelPath,
122
- versionId,
123
- )
124
- ).data;
125
- if (read.notebook)
126
- return {
127
- ...(read.notebook.startingGivens
128
- ? { startingGivens: read.notebook.startingGivens }
129
- : {}),
130
- ...(read.notebook.autorun === undefined
131
- ? {}
132
- : { autorun: read.notebook.autorun }),
133
- };
134
- return read;
135
- },
137
+ // The reader's read of the same report, so opening the builder from the
138
+ // reader does not read it again.
139
+ ...reportQueryOptions(
140
+ apiClients,
141
+ {
142
+ environmentName,
143
+ packageName,
144
+ path: modelPath,
145
+ versionId,
146
+ },
147
+ BUILDER_HANDOFF_STALE_MS,
148
+ ),
136
149
  // The server does not serve a dashboard with no tiles, so asking would 404.
137
150
  enabled: served && !textSource,
138
151
  });
139
152
  // A text source takes its manifest from compiling the text as the viewer.
140
153
  const runModelPath = textSource?.modelPath ?? modelPath;
154
+ const compileText = useCompileText(opened.source, textSource?.compileSource);
141
155
  const compiled = useCompiledDocument(
142
156
  {
143
157
  environmentName,
144
158
  packageName,
145
159
  modelPath: runModelPath,
146
- source: opened.source,
160
+ source: compileText.text ?? opened.source,
147
161
  ...(textSource?.givens ? { givens: textSource.givens } : {}),
148
162
  },
149
- { enabled: textSource !== undefined },
163
+ { enabled: textSource !== undefined && compileText.text !== undefined },
150
164
  );
151
165
  const compiledDocument = compiled.data?.document;
152
166
  const manifest: DashboardManifest | undefined = textSource
@@ -155,7 +169,9 @@ export function EditorSurface({
155
169
  : undefined
156
170
  : data;
157
171
  const isSuccess = textSource ? compiled.isSuccess : manifestLoaded;
158
- const isError = textSource ? compiled.isError : manifestFailed;
172
+ const isError = textSource
173
+ ? compiled.isError || compileText.problem !== undefined
174
+ : manifestFailed;
159
175
  const preamble = textSource
160
176
  ? documentPreamble(compiledDocument?.cells)
161
177
  : undefined;
@@ -251,15 +267,13 @@ export function EditorSurface({
251
267
  );
252
268
  const modelSpecs = useMemo(
253
269
  () =>
254
- (
255
- manifest?.givens ?? (opened.conversion ? (modelGivens ?? []) : [])
256
- ).filter(
270
+ (manifest?.givens ?? []).filter(
257
271
  // Only a document held as text hides a `#(secure)` given's control; a saved file's givens show as before.
258
272
  (spec) =>
259
273
  !(textSource && spec.secure === true) &&
260
274
  !(spec.name !== undefined && hidden.has(spec.name)),
261
275
  ),
262
- [manifest, opened.conversion, modelGivens, hidden, textSource],
276
+ [manifest, hidden, textSource],
263
277
  );
264
278
  const runnable = useMemo(
265
279
  () =>
@@ -272,10 +286,77 @@ export function EditorSurface({
272
286
  ]),
273
287
  [modelSpecs, hostGivens],
274
288
  );
289
+ // What the saved file's compiled tiles read, keyed as the server keys a tile expression.
290
+ const servedReads = useMemo(
291
+ () =>
292
+ new Map(
293
+ (manifest?.tiles ?? []).flatMap((tile) =>
294
+ tile.kind !== "text" && tile.query && tile.givenNames
295
+ ? [[tileExpressionKey(tile.query), tile.givenNames] as const]
296
+ : [],
297
+ ),
298
+ ),
299
+ [manifest],
300
+ );
301
+ // Givens a tile reads through the model (a source's own `where:`), not a
302
+ // binding in this file: shown, so the row matches the reader's, but the
303
+ // model's to change.
304
+ const modelReads = useMemo(
305
+ () => givensReadThroughModel(doc, opened.document, servedReads),
306
+ [doc, opened.document, servedReads],
307
+ );
275
308
  const specs = useMemo(
276
- () => previewGivens(doc, modelSpecs),
277
- [doc, modelSpecs],
309
+ () => previewGivens(doc, modelSpecs, modelReads),
310
+ [doc, modelSpecs, modelReads],
278
311
  );
312
+ // A filter in the row the builder can show and set but not change: say
313
+ // where it is set instead. Not always the model: a report's own `source:`
314
+ // can apply a given to every tile on it with a `where:` of its own.
315
+ const fixedFilters = useMemo(() => {
316
+ const bound = new Set(
317
+ doc.tiles.flatMap((tile) =>
318
+ isQueryTile(tile) ? (tile.filters ?? []).map((f) => f.given) : [],
319
+ ),
320
+ );
321
+ const declared = new Set((doc.localGivens ?? []).map((g) => g.name));
322
+ const models = [...new Set(doc.imports.map((i) => i.from))];
323
+ // The model by its package path, for "Open the model": an import is
324
+ // relative to the report's own folder.
325
+ const modelFile =
326
+ models.length === 1
327
+ ? packagePathOf(modelPath, models[0]!)
328
+ : models.length === 0 && textSource
329
+ ? textSource.modelPath
330
+ : undefined;
331
+ const reason = (name: string): FixedFilter => {
332
+ const scoping = doc.sources
333
+ .filter((source) => source.scopedBy?.includes(name))
334
+ .map((source) => source.name);
335
+ if (scoping.length > 0)
336
+ return {
337
+ reason: `Applied to every tile on ${scoping.join(", ")} by this report's own source. Edit the file to change it.`,
338
+ };
339
+ if (declared.has(name))
340
+ return {
341
+ reason:
342
+ "Read by a query in this report the builder cannot edit. Edit the file to change it.",
343
+ };
344
+ return modelFile !== undefined
345
+ ? {
346
+ reason: `Set in the model ${modelFile}. Edit the model to change it.`,
347
+ modelPath: modelFile,
348
+ }
349
+ : {
350
+ reason:
351
+ "Set in a model this report imports. Edit the model to change it.",
352
+ };
353
+ };
354
+ return new Map(
355
+ [...modelReads]
356
+ .filter((name) => !bound.has(name))
357
+ .map((name) => [name, reason(name)]),
358
+ );
359
+ }, [doc, modelReads, textSource, modelPath]);
279
360
  const { declaredTypes, applied, panel } = useDocumentControls({
280
361
  specs,
281
362
  loaded: isSuccess,
@@ -291,6 +372,12 @@ export function EditorSurface({
291
372
  ...(preamble !== undefined ? { preamble } : {}),
292
373
  ...(hostGivens ? { hostGivens } : {}),
293
374
  });
375
+ // Required filters with no value yet: as in the reader, a tile that
376
+ // reads one waits, and the page asks for them.
377
+ const missing = useMemo(
378
+ () => missingRequiredGivens(specs, applied, hostGivens),
379
+ [specs, applied, hostGivens],
380
+ );
294
381
  // A given only a gate reads has no control, so the host's value is added; each tile then sends just the names it reads.
295
382
  const tileHostGivens = useMemo(
296
383
  () =>
@@ -303,17 +390,23 @@ export function EditorSurface({
303
390
  );
304
391
 
305
392
  const manifestSettled = !served || isSuccess || isError;
306
- // What the saved file's compiled tiles read, keyed as the server keys a tile expression.
307
- const servedReads = useMemo(
393
+ // Held text that did not compile, or that the host's `compileSource`
394
+ // refused: nothing declares its sources, so a tile run would only fail with
395
+ // "Reference to undefined object". Its tiles are drawn but never run; the
396
+ // problem itself is said once, above the page.
397
+ const notCompiled =
398
+ textSource !== undefined &&
399
+ (compileText.problem !== undefined ||
400
+ compiled.isError ||
401
+ compileErrors.length > 0);
402
+ // The tiles as the file was opened, by key: a tile still equal to its
403
+ // opened self runs exactly as the reader runs it (below).
404
+ const openedTiles = useMemo(
308
405
  () =>
309
406
  new Map(
310
- (manifest?.tiles ?? []).flatMap((tile) =>
311
- tile.kind !== "text" && tile.query && tile.givenNames
312
- ? [[tileExpressionKey(tile.query), tile.givenNames] as const]
313
- : [],
314
- ),
407
+ opened.document.tiles.map((tile) => [tileKey(tile), tile] as const),
315
408
  ),
316
- [manifest],
409
+ [opened.document],
317
410
  );
318
411
  const renderTile = useMemo(
319
412
  () =>
@@ -324,6 +417,21 @@ export function EditorSurface({
324
417
  ) {
325
418
  // The bindings a tile runs with come from the manifest; running before it lands queries every tile once unbound and again bound.
326
419
  // Until then the tile's own card and heading stand, so nothing pops in when it runs.
420
+ if (notCompiled)
421
+ return (
422
+ <TileCard chrome={chrome}>
423
+ <TileHeading
424
+ title={heading?.title ?? tileDisplayTitle(tile)}
425
+ subtitle={heading ? heading.subtitle : tile.subtitle}
426
+ />
427
+ <Typography
428
+ variant="body2"
429
+ sx={{ color: "text.secondary", py: 1 }}
430
+ >
431
+ Not run: this document did not compile.
432
+ </Typography>
433
+ </TileCard>
434
+ );
327
435
  if (!manifestSettled)
328
436
  return (
329
437
  <TileCard chrome={chrome}>
@@ -334,15 +442,25 @@ export function EditorSurface({
334
442
  <Loading text="Running…" />
335
443
  </TileCard>
336
444
  );
337
- const query = previewTileQuery(
338
- doc,
339
- tile,
340
- runnable,
341
- applied,
342
- servedReads.get(
343
- tileExpressionKey(`${tile.source} -> ${tile.name}`),
344
- ),
445
+ const servedReadsOf = servedReads.get(
446
+ tileExpressionKey(`${tile.source} -> ${tile.name}`),
345
447
  );
448
+ // A tile not yet edited runs the served view with the served
449
+ // tile's givens: the request the reader sends, so it shares the
450
+ // reader's cached result and opening the builder re-runs nothing.
451
+ // The preview rebuilds the query from the document so an edit
452
+ // shows before it is saved, which an untouched tile does not need.
453
+ const untouched =
454
+ preamble === undefined &&
455
+ servedReadsOf !== undefined &&
456
+ sameTile(openedTiles.get(tileKey(tile)), tile);
457
+ const query: PreviewTileQuery = untouched
458
+ ? {
459
+ expression: `${tile.source} -> ${tile.name}`,
460
+ givenNames: [...servedReadsOf],
461
+ reads: [...servedReadsOf],
462
+ }
463
+ : previewTileQuery(doc, tile, runnable, applied, servedReadsOf);
346
464
  return (
347
465
  <DashboardTile
348
466
  environmentName={environmentName}
@@ -368,6 +486,15 @@ export function EditorSurface({
368
486
  hostGivens={tileHostGivens}
369
487
  declaredTypes={declaredTypes}
370
488
  givenNames={query.givenNames}
489
+ {...(() => {
490
+ const waiting = waitingOn(
491
+ missing,
492
+ query.reads ?? query.givenNames,
493
+ );
494
+ return waiting.length > 0
495
+ ? { waitingFor: waitingText(waiting) }
496
+ : {};
497
+ })()}
371
498
  ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
372
499
  height={TILE_MAX_HEIGHT}
373
500
  />
@@ -375,7 +502,10 @@ export function EditorSurface({
375
502
  },
376
503
  [
377
504
  doc,
505
+ openedTiles,
378
506
  manifestSettled,
507
+ notCompiled,
508
+ missing,
379
509
  runnable,
380
510
  servedReads,
381
511
  environmentName,
@@ -391,6 +521,47 @@ export function EditorSurface({
391
521
  ],
392
522
  );
393
523
 
524
+ // A view picked in Add a tile, run as the tile it would add: against the
525
+ // model that exports its source, with the page's filters, so the preview is
526
+ // the tile as it will look here.
527
+ const renderViewPreview = useMemo(
528
+ () =>
529
+ function ViewPreviewTile(view: ViewPreview) {
530
+ return (
531
+ <DashboardTile
532
+ environmentName={environmentName}
533
+ packageName={packageName}
534
+ versionId={versionId}
535
+ modelPath={view.modelPath}
536
+ tile={`${view.base} -> ${view.view}`}
537
+ {...(view.chart
538
+ ? {
539
+ annotation: chartLineText(
540
+ view.chart,
541
+ view.chartCarried,
542
+ ),
543
+ }
544
+ : {})}
545
+ label={view.label}
546
+ borderless
547
+ givens={applied}
548
+ hostGivens={tileHostGivens}
549
+ declaredTypes={declaredTypes}
550
+ givenNames={view.givens}
551
+ height={200}
552
+ />
553
+ );
554
+ },
555
+ [
556
+ environmentName,
557
+ packageName,
558
+ versionId,
559
+ applied,
560
+ tileHostGivens,
561
+ declaredTypes,
562
+ ],
563
+ );
564
+
394
565
  return (
395
566
  <Stack sx={{ gap: 1 }}>
396
567
  {textSource && compileErrors.length > 0 && (
@@ -399,6 +570,15 @@ export function EditorSurface({
399
570
  {compileErrors.map((problem) => problem.message).join("; ")}
400
571
  </Alert>
401
572
  )}
573
+ {missing.length > 0 && !notCompiled && (
574
+ <Alert severity="info">{requiredPrompt(missing)}</Alert>
575
+ )}
576
+ {textSource && compileText.problem !== undefined && (
577
+ <Alert severity="error">
578
+ This document could not be prepared to compile:{" "}
579
+ {compileText.problem}
580
+ </Alert>
581
+ )}
402
582
  {textSource && compiled.isError && (
403
583
  <Alert severity="error">
404
584
  The server could not compile this document:{" "}
@@ -406,7 +586,7 @@ export function EditorSurface({
406
586
  </Alert>
407
587
  )}
408
588
  <ReportBuilder
409
- {...(textSource
589
+ {...(textSource && !textSource.compileSource
410
590
  ? {
411
591
  addFilterDisabledReason:
412
592
  "This document holds no given: of its own. Bind a filter the model offers from its chip.",
@@ -414,7 +594,12 @@ export function EditorSurface({
414
594
  : {})}
415
595
  source={opened.source}
416
596
  document={opened.document}
597
+ fixedFilters={fixedFilters}
598
+ {...(textSource?.takenGivenNames
599
+ ? { takenGivenNames: textSource.takenGivenNames }
600
+ : {})}
417
601
  renderTile={renderTile}
602
+ renderViewPreview={renderViewPreview}
418
603
  givens={specs
419
604
  .filter((spec) => spec.name !== undefined)
420
605
  .map((spec) => ({
@@ -428,18 +613,17 @@ export function EditorSurface({
428
613
  onChange={setDoc}
429
614
  onDirtyChange={onDirtyChange}
430
615
  {...(onExit ? { onExit } : {})}
616
+ {...(onOpenModel ? { onOpenModel } : {})}
617
+ {...(onControlsChange ? { onControlsChange } : {})}
618
+ {...(draftKey !== undefined ? { draftKey } : {})}
431
619
  {...(allowLayoutChange !== undefined ? { allowLayoutChange } : {})}
432
- {...(opened.conversion ? { conversion: opened.conversion } : {})}
433
620
  {...(offered ? { catalog: offered } : {})}
434
621
  dashboards={otherDashboards}
435
622
  {...(onEvent ? { onEvent } : {})}
436
623
  controls={
437
624
  isSuccess ? (
438
- // The reader's control layout for the document as it stands: a linear report's panel, a grid's bar.
439
- <GivensPanel
440
- {...panel}
441
- layout={doc.layout === "linear" ? "panel" : "bar"}
442
- />
625
+ // The reader's control row: filter buttons, in either layout.
626
+ <GivensPanel {...panel} layout="bar" />
443
627
  ) : undefined
444
628
  }
445
629
  {...(saveThenServe ? { onSave: saveThenServe } : {})}
@@ -457,3 +641,95 @@ export function EditorSurface({
457
641
  </Stack>
458
642
  );
459
643
  }
644
+
645
+ /** Whether a tile runs as its opened self did: same view, bindings and chart ({@link whatRuns}). */
646
+ function sameTile(
647
+ opened: DocumentTile | undefined,
648
+ now: DocumentTile,
649
+ ): boolean {
650
+ return (
651
+ opened !== undefined &&
652
+ JSON.stringify(whatRuns(opened)) === JSON.stringify(whatRuns(now))
653
+ );
654
+ }
655
+
656
+ /**
657
+ * A tile less what only frames its result: its title, subtitle, width, row
658
+ * and card are drawn by the tile around the result, not sent with the query.
659
+ * Retitling a tile re-ran it before, and its chart blinked as the same rows
660
+ * were drawn again.
661
+ */
662
+ function whatRuns(tile: DocumentTile): DocumentTile {
663
+ const {
664
+ label: _label,
665
+ subtitle: _subtitle,
666
+ colspan: _colspan,
667
+ break: _break,
668
+ borderless: _borderless,
669
+ ...runs
670
+ } = tile as DocumentTile & {
671
+ label?: unknown;
672
+ subtitle?: unknown;
673
+ colspan?: unknown;
674
+ break?: unknown;
675
+ borderless?: unknown;
676
+ };
677
+ return runs as DocumentTile;
678
+ }
679
+
680
+ /**
681
+ * The text a held document is compiled from: its own, or what the host's
682
+ * `compileSource` makes of it. Read once per opened text, so a host passing
683
+ * a new function each render does not recompile.
684
+ */
685
+ function useCompileText(
686
+ source: string,
687
+ compileSource: ((text: string) => string | Promise<string>) | undefined,
688
+ ): { text?: string; problem?: string } {
689
+ const transform = useRef(compileSource);
690
+ transform.current = compileSource;
691
+ const hosted = compileSource !== undefined;
692
+ const [state, setState] = useState<{
693
+ from: string;
694
+ text?: string;
695
+ problem?: string;
696
+ }>();
697
+ useEffect(() => {
698
+ if (!hosted) return;
699
+ let live = true;
700
+ Promise.resolve()
701
+ .then(() => transform.current!(source))
702
+ .then(
703
+ (text) => {
704
+ if (live) setState({ from: source, text });
705
+ },
706
+ (error: unknown) => {
707
+ if (live)
708
+ setState({
709
+ from: source,
710
+ problem:
711
+ error instanceof Error ? error.message : String(error),
712
+ });
713
+ },
714
+ );
715
+ return () => {
716
+ live = false;
717
+ };
718
+ }, [source, hosted]);
719
+ if (!hosted) return { text: source };
720
+ // Until this text is resolved, nothing: never the previous text's result.
721
+ if (state?.from !== source) return {};
722
+ return state.problem !== undefined
723
+ ? { problem: state.problem }
724
+ : { text: state.text };
725
+ }
726
+
727
+ /** An import's path (`../storefront.malloy`) as a package path, from the importing file's own path. */
728
+ function packagePathOf(fromFile: string, imported: string): string {
729
+ const parts = fromFile.split("/").slice(0, -1);
730
+ for (const part of imported.split("/")) {
731
+ if (part === "..") parts.pop();
732
+ else if (part !== "." && part !== "") parts.push(part);
733
+ }
734
+ return parts.join("/");
735
+ }