@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,20 +1,26 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { reportClasses } from "../../theme/classes";
4
5
  import AddIcon from "@mui/icons-material/Add";
5
6
  import { Alert, Button, Stack, Typography } from "@mui/material";
6
7
  import { useMemo, useRef, useState, type ReactNode } from "react";
7
- import { DEFAULT_COLUMNS, nudgedSpan } from "../Dashboard/DashboardGrid";
8
+ import { nudgedSpan, useDefaultTileSpan } from "../Dashboard/DashboardGrid";
8
9
  import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
9
10
  import type { ReportLayout } from "../Package/documentLocation";
10
11
  import type { SavesTo } from "./documentSession";
11
12
  import { reportEmitter, type ReportEventHandler } from "../Report/telemetry";
12
13
  import type { BuilderGiven } from "./controls";
13
14
  import { BuilderDialogs } from "./BuilderDialogs";
15
+ import type { ViewPreview } from "./AddTileDialog";
14
16
  import { BuilderGrid } from "./BuilderGrid";
15
17
  import { BuilderHeader } from "./BuilderHeader";
16
18
  import { builderReport } from "./builderReport";
17
- import { BuilderToolbar } from "./BuilderToolbar";
19
+ import { BuilderToolbar, SAVE_TARGET } from "./BuilderToolbar";
20
+ import {
21
+ useReportControls,
22
+ type BuilderControlsHandler,
23
+ } from "./builderControls";
18
24
  import { OpenDraftContext } from "./openDraft";
19
25
  import type { PackageCatalog } from "./catalog";
20
26
  import {
@@ -22,18 +28,20 @@ import {
22
28
  type DashboardDocument,
23
29
  type QueryTile,
24
30
  } from "./document";
25
- import { FilterStrip } from "./FilterStrip";
31
+ import { FilterStrip, type FixedFilter } from "./FilterStrip";
26
32
  import { SELECTION_RING_PX } from "./TileFrame";
27
33
  import { useBuilderSelection } from "./useBuilderSelection";
28
34
  import { useBuilderSession } from "./useBuilderSession";
29
35
  import { useControlBindings } from "./useControlBindings";
30
- import { useConversionConfirm } from "./useConversionConfirm";
36
+ import { useReportDraft } from "./useReportDraft";
31
37
  import { useReportEditor } from "./useReportEditor";
32
38
  import type { SaveHandler } from "./useDocumentEditor";
33
39
  import { useOpenDraftCommit } from "./useOpenDraftCommit";
34
40
  import { useTileEditing } from "./useTileEditing";
35
41
  import { useTileReorder } from "./useTileReorder";
36
42
  import { useTileResize } from "./useTileResize";
43
+ import { layoutRules } from "../Report/layoutRules";
44
+ import { ReportPage } from "../Report/ReportPage";
37
45
 
38
46
  export type { BuilderGiven } from "./controls";
39
47
 
@@ -101,9 +109,11 @@ export interface ReportBuilderProps {
101
109
  renderTile?: (
102
110
  tile: QueryTile,
103
111
  heading?: TileHeadingSlots,
104
- /** The document's tile chrome — bare on a notebook — so the live tile reads as the reader's. */
112
+ /** Always `card`, in either layout; kept for hosts written against it. */
105
113
  chrome?: TileChrome,
106
114
  ) => ReactNode;
115
+ /** A view picked in Add a tile, run as the tile it would add; absent, the picker says what will run. */
116
+ renderViewPreview?: (view: ViewPreview) => ReactNode;
107
117
  /**
108
118
  * The control row, in the slot the reader puts it — this is where a real
109
119
  * `GivensPanel` goes.
@@ -150,12 +160,6 @@ export interface ReportBuilderProps {
150
160
  * was given none) and the document's layout as it stands.
151
161
  */
152
162
  onEvent?: ReportEventHandler;
153
- /**
154
- * The document is a conversion of a cell-format notebook: `from` is the text
155
- * on disk, `to` the layout text it converts to. Save writes `to` with the
156
- * edits spliced in, and Undo save puts `from` back.
157
- */
158
- conversion?: { from: string; to: string };
159
163
  /**
160
164
  * Whether the document differs from what was last saved, on every change
161
165
  * and on mount.
@@ -165,8 +169,13 @@ export interface ReportBuilderProps {
165
169
  * cannot answer that: the saved baseline lives in this hook, so a parent
166
170
  * comparing the document it is handed against the one it passed in reads
167
171
  * dirty immediately after a successful save.
172
+ *
173
+ * The second argument is whether leaving now would LOSE edits: the same,
174
+ * unless a draft is kept (`draftKey`), when it is only text still being
175
+ * typed into an open field. A leave guard reads that one; anything
176
+ * deciding whether to replace the document reads the first.
168
177
  */
169
- onDirtyChange?: (dirty: boolean) => void;
178
+ onDirtyChange?: (dirty: boolean, wouldLose: boolean) => void;
170
179
  /**
171
180
  * Where `onSave` puts the file, for the event it reports. The builder
172
181
  * cannot tell — it is handed a function — and a save into the package, into
@@ -188,6 +197,24 @@ export interface ReportBuilderProps {
188
197
  * be bound, from the chips.
189
198
  */
190
199
  addFilterDisabledReason?: string;
200
+ /**
201
+ * Filters in the row a tile reads other than through a binding the
202
+ * builder writes (the model's own `where:`, or this report's own
203
+ * `source:`), each with why it cannot be changed here. They can be set,
204
+ * as in the reader, but not removed or configured.
205
+ */
206
+ fixedFilters?: ReadonlyMap<string, FixedFilter>;
207
+ /**
208
+ * Open a model by its package path: offered as "Open the model" on a filter
209
+ * the model sets. Omitted, the filter only says where it is set.
210
+ */
211
+ onOpenModel?: (modelPath: string) => void;
212
+ /**
213
+ * Names a filter the builder adds must not take, beyond the givens on the
214
+ * page: a host that resolves held text itself passes every given the model
215
+ * declares, so a new filter never takes a model given's name.
216
+ */
217
+ takenGivenNames?: readonly string[];
191
218
  /**
192
219
  * The host's own extra actions for the edit bar, rendered beside undo, redo
193
220
  * and save.
@@ -195,6 +222,24 @@ export interface ReportBuilderProps {
195
222
  toolbar?: ReactNode;
196
223
  /** Leave the builder, opted into: draws Close, which asks first when edits are unsaved. */
197
224
  onExit?: () => void;
225
+ /**
226
+ * Take over the page-level controls (save status and Save, undo and redo,
227
+ * the layout switch, and adding a tile, text or filter): the builder hands
228
+ * them over as `BuilderControls` whenever they change, and draws no
229
+ * toolbar of its own. Draw them with `BuilderBar`, or place each in
230
+ * the host's own chrome. `undefined` is handed over when the builder goes.
231
+ */
232
+ onControlsChange?: BuilderControlsHandler;
233
+ /**
234
+ * Keep unsaved edits in this browser under this key, and put them back
235
+ * when the builder next opens on the same key: so leaving never loses work,
236
+ * and a host can offer one way out, `done` (write, then leave), with no
237
+ * "leave with unsaved changes?" on the way. `onDirtyChange`'s second
238
+ * argument then reports only what a draft cannot hold, text still being
239
+ * typed into an open field.
240
+ * One key per report and place it is saved to. Absent, nothing is kept.
241
+ */
242
+ draftKey?: string;
198
243
  /**
199
244
  * Whether the toolbar offers the Linear / Grid layout switch. Default
200
245
  * true. A host that files a report by its layout passes false, so an
@@ -213,28 +258,33 @@ export function ReportBuilder({
213
258
  onExit,
214
259
  allowLayoutChange = true,
215
260
  renderTile,
261
+ renderViewPreview,
216
262
  controls,
217
263
  givens,
218
264
  catalog,
219
265
  toolbar,
220
266
  dashboards,
221
267
  onEvent,
222
- conversion,
223
268
  savesTo = "package",
224
269
  saveLabel,
225
270
  replaces,
226
271
  modelPath,
227
272
  visibleSources,
228
273
  addFilterDisabledReason,
274
+ fixedFilters,
275
+ onOpenModel,
276
+ takenGivenNames,
277
+ onControlsChange,
278
+ draftKey,
229
279
  }: ReportBuilderProps) {
230
280
  const editor = useReportEditor({
231
281
  source,
232
282
  document,
233
283
  ...(onSave ? { onSave } : {}),
234
- ...(conversion ? { conversion } : {}),
235
284
  ...(replaces !== undefined ? { replaces } : {}),
236
285
  ...(visibleSources ? { visibleSources } : {}),
237
286
  });
287
+ const draft = useReportDraft(draftKey, editor, source);
238
288
  const gridBox = useRef<HTMLDivElement>(null);
239
289
  const {
240
290
  selected,
@@ -246,13 +296,9 @@ export function ReportBuilder({
246
296
  flash,
247
297
  stepEditor,
248
298
  } = useBuilderSelection({ editor, gridBox });
249
- // A linear report is one column whatever the file says, and the builder never writes its width.
250
- const notebook = editor.document.layout === "linear";
251
- const columns = notebook ? 1 : (editor.document.columns ?? DEFAULT_COLUMNS);
252
- // The reader's tile chrome for this document: cards on a dashboard, bare
253
- // flow on a notebook. Every tile, text block and the description take it,
254
- // so editing a document draws it the way reading it does.
255
- const chrome: TileChrome = notebook ? "none" : "card";
299
+ // What the layout decides: how tiles are arranged, never how they look.
300
+ const rules = layoutRules(editor.document.layout, editor.document.columns);
301
+ const { columns } = rules;
256
302
  // The name a reader's view titles an untitled document with.
257
303
  const documentSlug = modelPath
258
304
  ?.split("/")
@@ -268,8 +314,22 @@ export function ReportBuilder({
268
314
  });
269
315
  const { dragging } = reorder;
270
316
  // Dragging a tile's right edge sets its width, written once on release.
317
+ // A tile with no `# colspan` is drawn as the reader draws it, at least
318
+ // MIN_TILE_PX wide, rather than one column: the width handle and the row
319
+ // arithmetic start from that span. Only drawn; nothing is written until
320
+ // the author sets a width.
321
+ const defaultSpan = useDefaultTileSpan(gridBox, columns);
322
+ const laidOut = useMemo(
323
+ () =>
324
+ editor.document.tiles.map((tile) =>
325
+ tile.colspan === undefined
326
+ ? { ...tile, colspan: defaultSpan }
327
+ : tile,
328
+ ),
329
+ [editor.document.tiles, defaultSpan],
330
+ );
271
331
  const resizing = useTileResize({
272
- tiles: editor.document.tiles,
332
+ tiles: laidOut,
273
333
  columns,
274
334
  gridBox,
275
335
  onStart: selectTile,
@@ -281,8 +341,7 @@ export function ReportBuilder({
281
341
  });
282
342
  const tiles = useTileEditing({
283
343
  editor,
284
- notebook,
285
- columns,
344
+ rules,
286
345
  modelPath,
287
346
  textHeld: visibleSources !== undefined,
288
347
  selectTile,
@@ -303,10 +362,6 @@ export function ReportBuilder({
303
362
  const { draftDirty, openDraft, prepare } = useOpenDraftCommit({
304
363
  editorDirty: editor.dirty,
305
364
  });
306
- const { confirmConversion, prepareSave } = useConversionConfirm({
307
- pendingOpen: editor.pendingOpen,
308
- prepare,
309
- });
310
365
 
311
366
  const shortcuts = useMemo(
312
367
  () => ({
@@ -318,45 +373,51 @@ export function ReportBuilder({
318
373
  !menu &&
319
374
  !filterDialog &&
320
375
  !addingTile &&
321
- drillSource === undefined &&
322
- confirmConversion === undefined
376
+ drillSource === undefined
323
377
  )
324
378
  clearSelection();
325
379
  },
326
380
  nudge: (delta: 1 | -1) => {
327
381
  // The drag's keyboard sensor also reads the arrows, and a drop would write the drag-start width back.
328
- if (dragging || selected === undefined || notebook) return;
382
+ if (dragging || selected === undefined || !rules.widths) return;
329
383
  const tile = editor.document.tiles[selected];
330
384
  if (
331
385
  !tile ||
332
386
  (isQueryTile(tile) && tile.declaration.kind === "inherited")
333
387
  )
334
388
  return;
335
- const span = nudgedSpan(tile.colspan ?? 1, delta, columns);
336
- if (span === (tile.colspan ?? 1)) return;
389
+ const span = nudgedSpan(
390
+ tile.colspan ?? defaultSpan,
391
+ delta,
392
+ columns,
393
+ );
394
+ if (span === (tile.colspan ?? defaultSpan)) return;
337
395
  editor.update((draft) => {
338
396
  draft.tiles[selected].colspan = span;
339
397
  });
340
398
  },
341
399
  }),
342
400
  [
401
+ defaultSpan,
343
402
  editor,
344
403
  menu,
345
404
  filterDialog,
346
405
  addingTile,
347
406
  drillSource,
348
- confirmConversion,
349
407
  clearSelection,
350
408
  selected,
351
409
  columns,
352
- notebook,
410
+ rules,
353
411
  dragging,
354
412
  ],
355
413
  );
356
414
  const session = useBuilderSession<DashboardDocument>({
357
415
  editor: stepEditor,
358
416
  extraDirty: draftDirty,
359
- prepare: prepareSave,
417
+ // Only while the browser is actually holding them: a refused write
418
+ // means leaving would lose the edits, and the host's guard must ask.
419
+ keepsEdits: draftKey !== undefined && draft.keeping,
420
+ prepare,
360
421
  unit: { name: "tile", count: (document) => document.tiles.length },
361
422
  onSave,
362
423
  onDirtyChange,
@@ -373,32 +434,73 @@ export function ReportBuilder({
373
434
  });
374
435
 
375
436
  const empty = editor.document.tiles.length === 0;
437
+ // A text-held document's layout is the host's record, so only a file gets
438
+ // the switch, and only when the host allows it.
439
+ const layoutSwitch =
440
+ visibleSources === undefined && allowLayoutChange
441
+ ? {
442
+ layout: editor.document.layout,
443
+ onLayoutChange: (next: ReportLayout) => {
444
+ const from = editor.document.layout;
445
+ if (next === from) return;
446
+ editor.update((draft) => {
447
+ draft.layout = next;
448
+ });
449
+ reportEmitter(
450
+ { path: modelPath ?? "", layout: next },
451
+ onEvent,
452
+ ).emit({ type: "report.layout_changed", from, to: next });
453
+ },
454
+ }
455
+ : undefined;
456
+ const { toolbarProps } = session;
457
+ useReportControls(onControlsChange, {
458
+ status: session.saving
459
+ ? "saving"
460
+ : toolbarProps.dirty
461
+ ? "unsaved"
462
+ : "saved",
463
+ saveTarget: saveLabel ?? SAVE_TARGET[savesTo],
464
+ ...(toolbarProps.onSave ? { save: toolbarProps.onSave } : {}),
465
+ canUndo: toolbarProps.canUndo,
466
+ undo: toolbarProps.onUndo,
467
+ canRedo: toolbarProps.canRedo,
468
+ redo: toolbarProps.onRedo,
469
+ ...(layoutSwitch
470
+ ? {
471
+ layout: {
472
+ value: layoutSwitch.layout,
473
+ set: layoutSwitch.onLayoutChange,
474
+ },
475
+ }
476
+ : {}),
477
+ add: {
478
+ ...(catalog ? { tile: () => tiles.openAdd() } : {}),
479
+ text: tiles.appendText,
480
+ // A filter is declared for the tiles to read, so there has to be one.
481
+ ...(addFilterDisabledReason !== undefined
482
+ ? { filterUnavailable: addFilterDisabledReason }
483
+ : empty
484
+ ? { filterUnavailable: "Add a tile before a filter." }
485
+ : { filter: () => setFilterDialog({}) }),
486
+ },
487
+ ...(toolbarProps.onExit ? { exit: toolbarProps.onExit } : {}),
488
+ ...(session.done ? { done: session.done } : {}),
489
+ ...(draft.keptAt !== undefined ? { draftKeptAt: draft.keptAt } : {}),
490
+ ...(toolbarProps.dirty && draftKey !== undefined
491
+ ? { discard: draft.discard }
492
+ : {}),
493
+ });
376
494
  // The builder's actions: on the title's line, at the right, above the
377
495
  // description.
378
- const actions = (
496
+ const actions = onControlsChange ? undefined : (
379
497
  <BuilderToolbar
380
498
  {...session.toolbarProps}
381
499
  {...(toolbar ? { actions: toolbar } : {})}
382
500
  {...(catalog ? { onAddTile: () => openAdd() } : {})}
383
501
  savesTo={savesTo}
384
502
  {...(saveLabel ? { saveLabel } : {})}
385
- {...(visibleSources === undefined && allowLayoutChange
386
- ? {
387
- // A text-held document's layout is the host's record, so only a file gets the switch, and only when the host allows it.
388
- layout: editor.document.layout,
389
- onLayoutChange: (next: ReportLayout) => {
390
- const from = editor.document.layout;
391
- if (next === from) return;
392
- editor.update((draft) => {
393
- draft.layout = next;
394
- });
395
- reportEmitter(
396
- { path: modelPath ?? "", layout: next },
397
- onEvent,
398
- ).emit({ type: "report.layout_changed", from, to: next });
399
- },
400
- }
401
- : {})}
503
+ {...(layoutSwitch ?? {})}
402
504
  />
403
505
  );
404
506
  return (
@@ -415,76 +517,127 @@ export function ReportBuilder({
415
517
  {/* Pulled out by the ring's inset, so the content inside it lands on
416
518
  the same edges as the reader's view: editing and reading are the same
417
519
  page, and the margins must not move between them. */}
418
- <Stack sx={{ gap: 0, mx: `-${SELECTION_RING_PX}px` }}>
419
- {/* The ring's inset, minus the top: nothing at the top of this stack
420
- can be selected (the prose and the control row are not tiles). */}
421
- <Stack
520
+ <Stack
521
+ // Where Save writes, for a host or a test to read: the words are
522
+ // the status's tooltip, not a line on the page.
523
+ className={reportClasses.builder}
524
+ data-saves-to={savesTo}
525
+ sx={{ gap: 0, mx: `-${SELECTION_RING_PX}px` }}
526
+ >
527
+ {/* The reader's page, with the ring's inset (minus the top:
528
+ nothing at the top of the page can be selected). */}
529
+ <ReportPage
530
+ layout={rules.layout}
422
531
  sx={{
423
- gap: 2,
424
532
  px: `${SELECTION_RING_PX}px`,
425
533
  pb: `${SELECTION_RING_PX}px`,
426
534
  }}
535
+ header={
536
+ <BuilderHeader
537
+ editor={editor}
538
+ documentSlug={documentSlug}
539
+ actions={actions}
540
+ descriptionSelected={descriptionSelected}
541
+ selectDescription={selectDescription}
542
+ />
543
+ }
544
+ controls={
545
+ empty ? undefined : (
546
+ <FilterStrip
547
+ controls={bindings.controlList}
548
+ unknownFieldsOf={bindings.unknownFieldsOf}
549
+ onEdit={(control) => setFilterDialog({ control })}
550
+ onAdd={() => setFilterDialog({})}
551
+ {...(addFilterDisabledReason
552
+ ? { addDisabledReason: addFilterDisabledReason }
553
+ : {})}
554
+ onRemove={bindings.dropControl}
555
+ {...(fixedFilters ? { fixedFilters } : {})}
556
+ {...(onOpenModel ? { onOpenModel } : {})}
557
+ {...(editor.document.startingGivens
558
+ ? { startingValues: editor.document.startingGivens }
559
+ : {})}
560
+ onStartingValue={(name, text) =>
561
+ editor.update((draft) => {
562
+ const next = { ...(draft.startingGivens ?? {}) };
563
+ if (text === undefined) delete next[name];
564
+ else next[name] = text;
565
+ if (Object.keys(next).length > 0)
566
+ draft.startingGivens = next;
567
+ else delete draft.startingGivens;
568
+ })
569
+ }
570
+ >
571
+ {controls}
572
+ </FilterStrip>
573
+ )
574
+ }
427
575
  >
428
- {editor.pendingOpen && (
429
- <Alert severity="info">
430
- This report is in the cell format. Saving rewrites it as a
431
- layout notebook, and a named query run once becomes that
432
- tile&apos;s view.
433
- </Alert>
576
+ {empty && (
577
+ <Stack
578
+ sx={{
579
+ alignItems: "flex-start",
580
+ gap: 1,
581
+ py: 3,
582
+ px: 2,
583
+ border: 1,
584
+ borderStyle: "dashed",
585
+ borderColor: "divider",
586
+ borderRadius: 1,
587
+ }}
588
+ >
589
+ <Typography variant="body2">
590
+ This report is not served until it has a tile.
591
+ </Typography>
592
+ {catalog && (
593
+ <Button
594
+ size="small"
595
+ startIcon={<AddIcon />}
596
+ onClick={() => openAdd()}
597
+ >
598
+ Add tile
599
+ </Button>
600
+ )}
601
+ </Stack>
434
602
  )}
435
- <BuilderHeader
436
- editor={editor}
437
- notebook={notebook}
438
- documentSlug={documentSlug}
439
- chrome={chrome}
440
- actions={actions}
441
- descriptionSelected={descriptionSelected}
442
- selectDescription={selectDescription}
443
- />
444
603
 
445
- {empty ? (
446
- <>
447
- <Stack
448
- sx={{
449
- alignItems: "flex-start",
450
- gap: 1,
451
- py: 3,
452
- px: 2,
453
- border: 1,
454
- borderStyle: "dashed",
455
- borderColor: "divider",
456
- borderRadius: 1,
457
- }}
458
- >
459
- <Typography variant="body2">
460
- This report is not served until it has a tile.
461
- </Typography>
462
- {catalog && (
604
+ {draft.restored && (
605
+ <Alert
606
+ severity={draft.restored.pending ? "warning" : "info"}
607
+ onClose={draft.dismissRestored}
608
+ action={
609
+ draft.restored.pending ? (
610
+ <>
611
+ <Button
612
+ color="inherit"
613
+ size="small"
614
+ onClick={draft.restoreOffered}
615
+ >
616
+ Restore them
617
+ </Button>
618
+ <Button
619
+ color="inherit"
620
+ size="small"
621
+ onClick={draft.discard}
622
+ >
623
+ Discard
624
+ </Button>
625
+ </>
626
+ ) : (
463
627
  <Button
628
+ color="inherit"
464
629
  size="small"
465
- startIcon={<AddIcon />}
466
- onClick={() => openAdd()}
630
+ onClick={draft.discard}
467
631
  >
468
- Add tile
632
+ Discard edits
469
633
  </Button>
470
- )}
471
- </Stack>
472
- </>
473
- ) : (
474
- <FilterStrip
475
- sticky={!notebook}
476
- controls={bindings.controlList}
477
- tileCount={editor.document.tiles.length}
478
- unknownFieldsOf={bindings.unknownFieldsOf}
479
- onEdit={(control) => setFilterDialog({ control })}
480
- onAdd={() => setFilterDialog({})}
481
- {...(addFilterDisabledReason
482
- ? { addDisabledReason: addFilterDisabledReason }
483
- : {})}
484
- onRemove={bindings.dropControl}
634
+ )
635
+ }
485
636
  >
486
- {controls}
487
- </FilterStrip>
637
+ {draft.restored.pending
638
+ ? `You have unsaved edits from ${clockTime(draft.restored.savedAt)}, made before this report changed. Restoring them replaces the current version.`
639
+ : `Restored your unsaved edits from ${clockTime(draft.restored.savedAt)}.`}
640
+ </Alert>
488
641
  )}
489
642
 
490
643
  {editor.error && (
@@ -498,9 +651,8 @@ export function ReportBuilder({
498
651
  reorder={reorder}
499
652
  resizing={resizing}
500
653
  gridBox={gridBox}
501
- columns={columns}
502
- notebook={notebook}
503
- chrome={chrome}
654
+ defaultSpan={defaultSpan}
655
+ rules={rules}
504
656
  canAdd={!!catalog}
505
657
  selected={selected}
506
658
  flash={flash}
@@ -510,6 +662,14 @@ export function ReportBuilder({
510
662
  selectTile(index);
511
663
  tiles.setMenu({ anchor, index });
512
664
  }}
665
+ onRemove={tiles.removeTile}
666
+ {...(editor.document.tiles.length === 1 &&
667
+ editor.saved.tiles.length > 0
668
+ ? {
669
+ removeBlocked:
670
+ "A saved report needs at least one tile.",
671
+ }
672
+ : {})}
513
673
  openAdd={openAdd}
514
674
  editTile={tiles.editTile}
515
675
  {...(renderTile ? { renderTile } : {})}
@@ -523,11 +683,26 @@ export function ReportBuilder({
523
683
  tiles={tiles}
524
684
  drillSource={drillSource}
525
685
  setDrillSource={setDrillSource}
526
- confirmConversion={confirmConversion}
527
686
  exitDialog={session.exitGuard.dialog}
687
+ {...(renderViewPreview ? { renderViewPreview } : {})}
688
+ {...(takenGivenNames ? { takenGivenNames } : {})}
528
689
  />
529
- </Stack>
690
+ </ReportPage>
530
691
  </Stack>
531
692
  </OpenDraftContext.Provider>
532
693
  );
533
694
  }
695
+
696
+ /** A time of day, or a date and time when not today: when a draft was kept. */
697
+ function clockTime(at: number): string {
698
+ const when = new Date(at);
699
+ const today = new Date().toDateString() === when.toDateString();
700
+ return today
701
+ ? when.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })
702
+ : when.toLocaleString([], {
703
+ month: "short",
704
+ day: "numeric",
705
+ hour: "numeric",
706
+ minute: "2-digit",
707
+ });
708
+ }
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { findViewOption } from "./testing/inline";
4
5
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
5
6
  import { beforeEach, describe, expect, it, mock } from "bun:test";
6
7
  import {
@@ -138,7 +139,7 @@ describe("ReportEditor, starting empty", () => {
138
139
  })
139
140
  )[0],
140
141
  );
141
- fireEvent.click(await screen.findByLabelText("View by_brand"));
142
+ fireEvent.click(await findViewOption("by_brand"));
142
143
  fireEvent.click(screen.getByRole("button", { name: "Add tile" }));
143
144
  fireEvent.click(
144
145
  screen.getByRole("button", { name: "Save", hidden: true }),