@malloy-publisher/sdk 0.9.10 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7493 -6769
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -34
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  17. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  18. package/dist/components/Package/PackageProblems.d.ts +14 -0
  19. package/dist/components/RemoveBadge.d.ts +40 -0
  20. package/dist/components/Report/Report.d.ts +13 -4
  21. package/dist/components/Report/ReportPage.d.ts +60 -0
  22. package/dist/components/Report/layoutRules.d.ts +32 -0
  23. package/dist/components/Report/reportQuery.d.ts +30 -0
  24. package/dist/components/Report/telemetry.d.ts +0 -2
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  26. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  27. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  29. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  30. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  31. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  32. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  33. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  34. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
  35. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  36. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  37. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  38. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  39. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  40. package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
  41. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  42. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  43. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  44. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  45. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  46. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  47. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  48. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  49. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  50. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  51. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  52. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  53. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  54. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  55. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  56. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  57. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  58. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  59. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  60. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  61. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  62. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  63. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  64. package/dist/components/ServerProvider.d.ts +9 -0
  65. package/dist/components/controlTokens.d.ts +45 -0
  66. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  67. package/dist/components/given/FilterButton.d.ts +35 -0
  68. package/dist/components/given/GivensPanel.d.ts +2 -1
  69. package/dist/components/given/filterEditing.d.ts +54 -0
  70. package/dist/components/given/filterSummary.d.ts +9 -0
  71. package/dist/components/given/paramCodec.d.ts +11 -0
  72. package/dist/components/given/required.d.ts +25 -0
  73. package/dist/components/index.d.ts +3 -0
  74. package/dist/components/legacy/index.d.ts +1 -1
  75. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  76. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  77. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  78. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  79. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  80. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  81. package/dist/components/styles.d.ts +0 -2
  82. package/dist/hooks/useQueryResult.d.ts +7 -0
  83. package/dist/index.cjs.js +16 -19
  84. package/dist/index.es.js +8324 -7769
  85. package/dist/theme/ThemeContext.d.ts +8 -1
  86. package/dist/theme/classes.d.ts +49 -0
  87. package/dist/theme/index.d.ts +2 -0
  88. package/dist/theme/types.d.ts +7 -0
  89. package/dist/theme/ui.d.ts +75 -0
  90. package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
  91. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  92. package/package.json +2 -2
  93. package/src/builder-entry.ts +9 -0
  94. package/src/components/AppDialog.tsx +23 -0
  95. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  96. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  97. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  98. package/src/components/Dashboard/DashboardView.tsx +137 -155
  99. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  100. package/src/components/Dashboard/TileCard.tsx +28 -10
  101. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  102. package/src/components/Dashboard/useStuck.ts +28 -17
  103. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  104. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  105. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  106. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  107. package/src/components/Package/Package.create.spec.tsx +7 -6
  108. package/src/components/Package/Package.tsx +10 -7
  109. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  110. package/src/components/Package/PackageProblems.tsx +95 -0
  111. package/src/components/Prose.tsx +12 -7
  112. package/src/components/RemoveBadge.tsx +94 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  114. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  115. package/src/components/Report/Report.spec.tsx +50 -32
  116. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  117. package/src/components/Report/Report.tsx +45 -77
  118. package/src/components/Report/ReportPage.tsx +168 -0
  119. package/src/components/Report/layoutRules.spec.ts +35 -0
  120. package/src/components/Report/layoutRules.ts +55 -0
  121. package/src/components/Report/reportQuery.ts +53 -0
  122. package/src/components/Report/telemetry.ts +0 -2
  123. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  124. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  125. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  126. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  127. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  128. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  129. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  130. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  131. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  132. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  133. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  134. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  135. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  136. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  137. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  138. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  139. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  140. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  141. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  142. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  143. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  144. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  145. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  146. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  147. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  148. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  149. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  150. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  151. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  152. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  153. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  154. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  155. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  156. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  157. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  158. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  159. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  160. package/src/components/ReportBuilder/builderControls.ts +164 -0
  161. package/src/components/ReportBuilder/builderReport.ts +1 -2
  162. package/src/components/ReportBuilder/catalog.ts +10 -26
  163. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  164. package/src/components/ReportBuilder/localGiven.ts +56 -0
  165. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  166. package/src/components/ReportBuilder/preview.ts +60 -44
  167. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  168. package/src/components/ReportBuilder/readDocument.ts +14 -11
  169. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  170. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  171. package/src/components/ReportBuilder/reportTag.ts +28 -7
  172. package/src/components/ReportBuilder/sortable.tsx +15 -7
  173. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  174. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  175. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  176. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  177. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  178. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  179. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  180. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  181. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  182. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  183. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  184. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  185. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  186. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  187. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  188. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  189. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  190. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  191. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  192. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  193. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  194. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  195. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  196. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  197. package/src/components/ServerProvider.tsx +11 -0
  198. package/src/components/controlTokens.ts +47 -0
  199. package/src/components/drill/markDrillableCells.ts +2 -1
  200. package/src/components/given/FilterButton.spec.tsx +143 -0
  201. package/src/components/given/FilterButton.tsx +478 -0
  202. package/src/components/given/GivenInput.spec.tsx +47 -0
  203. package/src/components/given/GivenInput.tsx +20 -2
  204. package/src/components/given/GivensPanel.spec.tsx +11 -3
  205. package/src/components/given/GivensPanel.tsx +45 -44
  206. package/src/components/given/filterEditing.ts +60 -0
  207. package/src/components/given/filterSummary.spec.ts +108 -0
  208. package/src/components/given/filterSummary.ts +109 -0
  209. package/src/components/given/paramCodec.ts +1 -1
  210. package/src/components/given/required.spec.ts +60 -0
  211. package/src/components/given/required.ts +78 -0
  212. package/src/components/index.ts +9 -0
  213. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  214. package/src/components/legacy/index.ts +1 -1
  215. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  216. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  217. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  218. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  219. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  220. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  221. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  222. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  223. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  224. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  225. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  226. package/src/components/styles.ts +0 -18
  227. package/src/hooks/useGivensState.ts +7 -3
  228. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  229. package/src/hooks/useQueryResult.ts +26 -1
  230. package/src/theme/ThemeContext.tsx +21 -1
  231. package/src/theme/classes.ts +52 -0
  232. package/src/theme/index.ts +8 -0
  233. package/src/theme/resolveTheme.ts +3 -0
  234. package/src/theme/types.ts +7 -0
  235. package/src/theme/ui.spec.tsx +91 -0
  236. package/src/theme/ui.ts +115 -0
  237. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  238. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  239. package/dist/components/Notebook/cellKind.d.ts +0 -20
  240. package/dist/components/Report/LinearReport.d.ts +0 -18
  241. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  242. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  243. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  244. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  245. package/src/components/Notebook/cellKind.spec.ts +0 -199
  246. package/src/components/Notebook/cellKind.ts +0 -74
  247. package/src/components/Report/LinearReport.tsx +0 -71
  248. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  249. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  250. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  251. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  252. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  253. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  254. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  255. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  256. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  257. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -7,14 +7,14 @@
7
7
  "expected": "grid"
8
8
  },
9
9
  {
10
- "name": "`layout=linear` with no tiles is linear",
10
+ "name": "`layout=linear` with no tiles is the retired cell format: no report",
11
11
  "source": "## artifact { layout=linear }\nsource: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\nrun: s -> v\n",
12
- "expected": "linear"
12
+ "expected": null
13
13
  },
14
14
  {
15
- "name": "a tag naming no layout and listing no tiles is linear by default",
15
+ "name": "a tag naming no layout and listing no tiles is the retired cell format: no report",
16
16
  "source": "## artifact { }\nsource: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\nrun: s -> v\n",
17
- "expected": "linear"
17
+ "expected": null
18
18
  },
19
19
  {
20
20
  "name": "a tiles list with no layout is grid",
@@ -62,9 +62,9 @@
62
62
  "expected": "linear"
63
63
  },
64
64
  {
65
- "name": "an unknown `layout=` with no tiles falls through to linear",
65
+ "name": "an unknown `layout=` with no tiles falls through to linear, and with no tiles is no report",
66
66
  "source": "## artifact { layout=wide }\nsource: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\nrun: s -> v\n",
67
- "expected": "linear"
67
+ "expected": null
68
68
  },
69
69
  {
70
70
  "name": "a `##|` block tag is read like a one-line tag",
@@ -112,14 +112,19 @@
112
112
  "expected": null
113
113
  },
114
114
  {
115
- "name": "a model-level tag naming no layout beside a query-level `# artifact` is linear",
115
+ "name": "a model-level tag naming no layout beside a query-level `# artifact` lists no tiles: no report",
116
116
  "source": "## artifact { }\nsource: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\n# artifact\nquery: q is s -> v\n",
117
- "expected": "linear"
117
+ "expected": null
118
118
  },
119
119
  {
120
120
  "name": "a file with no artifact tag is no report",
121
121
  "source": "source: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\n",
122
122
  "expected": null
123
+ },
124
+ {
125
+ "name": "a `tiles` that is not a list is a tag the reader cannot use: no report",
126
+ "source": "## artifact { layout=linear tiles=foo }\nsource: s is duckdb.sql(\"select 1 as x\") extend { view: v is { group_by: x } }\n",
127
+ "expected": null
123
128
  }
124
129
  ]
125
130
  }
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
+ import { CELLS_REMOVED_REASON } from "./reportTag";
5
6
  import {
6
7
  isQueryTile,
7
8
  isTextTile,
@@ -151,29 +152,29 @@ describe("readDashboardDocument: text tiles and layout", () => {
151
152
  expect(text(await openDocument(source), "outro").markdown).toBe("");
152
153
  });
153
154
 
154
- it("marks a notebook with no tiles list as the cell format", async () => {
155
+ it("refuses a notebook with no tiles list: the cell format is no longer read", async () => {
155
156
  const result = await readDashboardDocument(
156
157
  `## artifact { layout=linear title="Old" }\nimport { a } from "../m.malloy"\n\nrun: a -> v\n`,
157
158
  );
158
159
  if (!readFailed(result)) throw new Error("expected a refusal");
159
- expect(result.legacyNotebook).toBe(true);
160
+ expect(result.reason).toBe(CELLS_REMOVED_REASON);
160
161
  });
161
162
 
162
- it("still refuses a grid report with no tiles list, without the legacy mark", async () => {
163
+ it("refuses a grid report with no tiles list for a missing tile list", async () => {
163
164
  const result = await readDashboardDocument(
164
165
  `## artifact { layout=grid title="D" }\nimport { a } from "../m.malloy"\n`,
165
166
  );
166
167
  if (!readFailed(result)) throw new Error("expected a refusal");
167
- expect(result.legacyNotebook).toBeUndefined();
168
+ expect(result.reason).not.toBe(CELLS_REMOVED_REASON);
168
169
  expect(result.reason).toContain("tiles");
169
170
  });
170
171
 
171
- it("reads a tag with no layout and no tiles as a linear report in the cell format", async () => {
172
+ it("refuses a tag with no layout and no tiles as the retired cell format", async () => {
172
173
  const result = await readDashboardDocument(
173
174
  `## artifact { title="D" }\nimport { a } from "../m.malloy"\n`,
174
175
  );
175
176
  if (!readFailed(result)) throw new Error("expected a refusal");
176
- expect(result.legacyNotebook).toBe(true);
177
+ expect(result.reason).toBe(CELLS_REMOVED_REASON);
177
178
  });
178
179
 
179
180
  it("reads an empty tiles list on a notebook as a layout notebook with no tiles", async () => {
@@ -66,6 +66,24 @@ export function useBuilderSelection({
66
66
  const selectDescription = useCallback(() => setSelection("description"), []);
67
67
  const clearSelection = useCallback(() => setSelection(undefined), []);
68
68
 
69
+ // A press anywhere else clears it: the page, its margins, the header, the
70
+ // sidebar. Not a press on something selectable (it selects itself), nor in
71
+ // a menu, window or popover the selection opened, nor on the builder's own
72
+ // bar, whose Undo and Add act on the page as it stands.
73
+ const anySelected = selection !== undefined;
74
+ useEffect(() => {
75
+ if (!anySelected) return;
76
+ const onPress = (event: PointerEvent) => {
77
+ const target = event.target;
78
+ if (!(target instanceof Element)) return;
79
+ // The page's scrollbar reports the root as the target.
80
+ if (target === document.documentElement) return;
81
+ if (target.closest(KEEPS_SELECTION) === null) clearSelection();
82
+ };
83
+ document.addEventListener("pointerdown", onPress, true);
84
+ return () => document.removeEventListener("pointerdown", onPress, true);
85
+ }, [anySelected, clearSelection]);
86
+
69
87
  // Undo and redo point at the tile they changed: lit briefly, and scrolled to.
70
88
  const [flash, setFlash] = useState<string | undefined>(undefined);
71
89
  const stepping = useRef(false);
@@ -119,3 +137,20 @@ export function useBuilderSelection({
119
137
  stepEditor,
120
138
  };
121
139
  }
140
+
141
+ /** Where a press leaves the selection alone. */
142
+ const KEEPS_SELECTION = [
143
+ "[data-tile-key]",
144
+ '[role="group"][aria-label="Description"]',
145
+ '[role="toolbar"][aria-label="Report builder"]',
146
+ // The inline toolbar, for a host that draws no bar of its own.
147
+ '[aria-label="Builder actions"]',
148
+ ".MuiPopover-root",
149
+ ".MuiPopper-root",
150
+ ".MuiDialog-root",
151
+ ".MuiModal-root",
152
+ '[role="menu"]',
153
+ '[role="dialog"]',
154
+ '[role="listbox"]',
155
+ '[role="tooltip"]',
156
+ ].join(", ");
@@ -145,10 +145,10 @@ describe("useBuilderSession reports", () => {
145
145
  const onDirtyChange = mock((_dirty: boolean) => {});
146
146
  const clean = makeEditor({ dirty: false });
147
147
  const view = mount({ onDirtyChange, extraDirty: true }, clean);
148
- expect(onDirtyChange).toHaveBeenLastCalledWith(true);
148
+ expect(onDirtyChange).toHaveBeenLastCalledWith(true, true);
149
149
  expect(view.result.current.toolbarProps.dirty).toBe(true);
150
150
  view.unmount();
151
- expect(onDirtyChange).toHaveBeenLastCalledWith(false);
151
+ expect(onDirtyChange).toHaveBeenLastCalledWith(false, false);
152
152
  });
153
153
 
154
154
  it("reports the document on mount and when it changes", () => {
@@ -24,11 +24,9 @@ export interface SessionEditor<D, L extends LastSave = LastSave> {
24
24
  /** The document as of the last save (or open). */
25
25
  saved: D;
26
26
  dirty: boolean;
27
- /** Unsaved edits made by a person, when that differs from `dirty` (an open that is unsaved before any edit); absent means `dirty`. */
27
+ /** Unsaved edits made by a person, when that differs from `dirty`; absent means `dirty`. */
28
28
  edited?: boolean;
29
29
  structural: boolean;
30
- /** Whether the document opened unsaved (a conversion); the save that clears it reports so. */
31
- pendingOpen?: boolean;
32
30
  canUndo: boolean;
33
31
  canRedo: boolean;
34
32
  undo: () => void;
@@ -53,20 +51,28 @@ export interface SessionReport {
53
51
  export interface SessionSaveInfo {
54
52
  size: number;
55
53
  structural: boolean;
56
- /** The save wrote a document that opened unsaved. */
57
- fromOpen: boolean;
58
54
  durationMs: number;
59
55
  }
60
56
 
61
57
  export interface BuilderSessionOptions<D, L extends LastSave = LastSave> {
62
58
  editor: SessionEditor<D, L>;
63
59
  onSave?: SaveHandler<D>;
64
- onDirtyChange?: (dirty: boolean) => void;
60
+ /**
61
+ * Whether there are unsaved edits, and (second) whether leaving now would
62
+ * lose any: false while the edits are kept elsewhere (`keepsEdits`).
63
+ */
64
+ onDirtyChange?: (dirty: boolean, wouldLose: boolean) => void;
65
65
  /** The host's way out, opted into: draws Close, which asks first when edits are unsaved. */
66
66
  onExit?: () => void;
67
67
  onChange?: (document: D) => void;
68
68
  /** Unsaved state the editor does not hold, such as an open text draft. */
69
69
  extraDirty?: boolean;
70
+ /**
71
+ * The document's edits are kept elsewhere as they are made (a draft in this
72
+ * browser), so leaving loses only what the editor does not hold yet: the host
73
+ * is told dirty for `extraDirty` alone. Close and Done still see every edit.
74
+ */
75
+ keepsEdits?: boolean;
70
76
  report: SessionReport;
71
77
  /** What the notice counts and calls them: "tile" or "cell". */
72
78
  unit: { name: string; count: (document: D) => number };
@@ -91,6 +97,7 @@ export function useBuilderSession<
91
97
  onExit,
92
98
  onChange,
93
99
  extraDirty = false,
100
+ keepsEdits = false,
94
101
  report,
95
102
  unit,
96
103
  prepare,
@@ -102,8 +109,10 @@ export function useBuilderSession<
102
109
  const reportRef = useRef(report);
103
110
  reportRef.current = report;
104
111
  const dirty = editor.dirty || extraDirty;
105
- // Work to lose: a conversion nobody has touched is rebuilt by opening the file again.
112
+ // Work to lose.
106
113
  const hasEdits = (editor.edited ?? editor.dirty) || extraDirty;
114
+ // What leaving would lose, for the host's leave guard.
115
+ const wouldLose = keepsEdits ? extraDirty : hasEdits;
107
116
 
108
117
  useEffect(() => {
109
118
  onChange?.(editor.document);
@@ -111,12 +120,12 @@ export function useBuilderSession<
111
120
  // Also on mount, so a host that remounted the builder on new text is told the slate is clean rather than carrying the previous mount's answer.
112
121
  // A layout effect, so a host's leave guard sees the flag in the same task as the edit.
113
122
  useLayoutEffect(() => {
114
- onDirtyChange?.(hasEdits);
115
- }, [hasEdits, onDirtyChange]);
123
+ onDirtyChange?.(hasEdits, wouldLose);
124
+ }, [hasEdits, wouldLose, onDirtyChange]);
116
125
  // A host guarding navigation on this must not be left holding a stale "dirty" once the builder is gone.
117
126
  const onDirtyChangeRef = useRef(onDirtyChange);
118
127
  onDirtyChangeRef.current = onDirtyChange;
119
- useEffect(() => () => onDirtyChangeRef.current?.(false), []);
128
+ useEffect(() => () => onDirtyChangeRef.current?.(false, false), []);
120
129
  const unitRef = useRef(unit);
121
130
  unitRef.current = unit;
122
131
  // The line saying the undo happened goes with the next edit or save; leaving it up over new work would say something stale.
@@ -129,7 +138,6 @@ export function useBuilderSession<
129
138
  setUndone(false);
130
139
  const started = now();
131
140
  const { structural } = editor;
132
- const fromOpen = editor.pendingOpen ?? false;
133
141
  const size = reportRef.current.size;
134
142
  return editor
135
143
  .save()
@@ -138,7 +146,6 @@ export function useBuilderSession<
138
146
  reportRef.current.saved({
139
147
  size,
140
148
  structural,
141
- fromOpen,
142
149
  durationMs: now() - started,
143
150
  });
144
151
  } else reportRef.current.refused(outcome.reason);
@@ -172,7 +179,6 @@ export function useBuilderSession<
172
179
  reportRef.current.undone({
173
180
  size,
174
181
  structural,
175
- fromOpen: false,
176
182
  durationMs: now() - started,
177
183
  });
178
184
  } else reportRef.current.undoRefused(outcome.reason);
@@ -246,6 +252,8 @@ export function useBuilderSession<
246
252
  saving,
247
253
  save,
248
254
  exitGuard,
255
+ /** Write the edits, then leave; absent unless the host can be left (`onExit`). */
256
+ ...(onExit ? { done: exitGuard.saveAndExit } : {}),
249
257
  /** Write the file back as it was before the last save, and put the edits back unsaved. */
250
258
  undoSave,
251
259
  canUndoSave,
@@ -253,7 +253,6 @@ describe("useDocumentEditor: undoing a save", () => {
253
253
  expect(view.result.current.dirty).toBe(true);
254
254
  // Work to lose, so a leave guard warns.
255
255
  expect(view.result.current.edited).toBe(true);
256
- expect(view.result.current.pendingOpen).toBe(false);
257
256
  await saveIt(view);
258
257
  expect(view.result.current.dirty).toBe(false);
259
258
  expect(view.result.current.lastSave?.before).toBe("P");
@@ -506,60 +505,3 @@ describe("useDocumentEditor: undoing a save", () => {
506
505
  expect(view.result.current.canUndoSave).toBe(false);
507
506
  });
508
507
  });
509
-
510
- describe("useDocumentEditor: opening unsaved", () => {
511
- const conversion = () => {
512
- const writes: Array<[string, string]> = [];
513
- const view = renderHook(() =>
514
- useDocumentEditor<Doc>({
515
- source: "legacy",
516
- document: { items: ["a"] },
517
- splice: async (_source, doc) => ({
518
- ok: true,
519
- source: doc.items.join(","),
520
- }),
521
- opensDirty: true,
522
- onSave: (source, context) =>
523
- void writes.push([source, context.purpose]),
524
- }),
525
- );
526
- return { view, writes };
527
- };
528
-
529
- it("is dirty before any edit, yet reports no edits", () => {
530
- const { view } = conversion();
531
- expect(view.result.current.dirty).toBe(true);
532
- expect(view.result.current.edited).toBe(false);
533
- expect(view.result.current.pendingOpen).toBe(true);
534
- act(() => view.result.current.update((d) => void d.items.push("b")));
535
- expect(view.result.current.edited).toBe(true);
536
- });
537
-
538
- it("saves the untouched document, and is clean once written", async () => {
539
- const { view, writes } = conversion();
540
- await act(async () => {
541
- expect(await view.result.current.save()).toEqual({ ok: true });
542
- });
543
- expect(writes).toEqual([["a", "save"]]);
544
- expect(view.result.current.dirty).toBe(false);
545
- expect(view.result.current.pendingOpen).toBe(false);
546
- });
547
-
548
- it("returns to unsaved when the save is undone, and writes the file back", async () => {
549
- const { view, writes } = conversion();
550
- await act(async () => {
551
- await view.result.current.save();
552
- });
553
- await act(async () => {
554
- await view.result.current.undoSave();
555
- });
556
- expect(writes).toEqual([
557
- ["a", "save"],
558
- ["legacy", "undo"],
559
- ]);
560
- expect(view.result.current.source).toBe("legacy");
561
- expect(view.result.current.pendingOpen).toBe(true);
562
- expect(view.result.current.dirty).toBe(true);
563
- expect(view.result.current.edited).toBe(false);
564
- });
565
- });
@@ -24,12 +24,10 @@ export interface DocumentEditor<T> {
24
24
  source: string;
25
25
  canUndo: boolean;
26
26
  canRedo: boolean;
27
- /** Whether saving would change the file: the document differs from what was saved, or it opened that way ({@link DocumentEditorOptions.opensDirty}). */
27
+ /** Whether saving would change the file: the document differs from what was saved, or an undone save left its draft text in no file. */
28
28
  dirty: boolean;
29
- /** Whether the document differs from what was saved, or an undone save left its draft text in no file: work to lose, leaving out an `opensDirty` open that nothing has touched. */
29
+ /** The same as `dirty`: work to lose. */
30
30
  edited: boolean;
31
- /** Whether the document opened unsaved and no save has written it since ({@link DocumentEditorOptions.opensDirty}). */
32
- pendingOpen: boolean;
33
31
  /**
34
32
  * Why the last save did not happen. The document is untouched when this is
35
33
  * set: a refused write keeps the reader's work and reports a defect in the
@@ -115,8 +113,6 @@ export interface DocumentEditorOptions<T> {
115
113
  onSave?: SaveHandler<T>;
116
114
  /** Patch the document into the file, or say why that was refused. */
117
115
  splice: (source: string, document: T) => Promise<SpliceResult>;
118
- /** The open is itself unsaved: the document is a conversion of the file, so Save is on before any edit and Undo save returns to it. */
119
- opensDirty?: boolean;
120
116
  /** The file the first save overwrites when it is not `source` (a draft opened over the package's file): what Undo save writes back. */
121
117
  replaces?: string;
122
118
  /** Whether `document` differs structurally from `saved`; omit for never. */
@@ -133,7 +129,6 @@ export function useDocumentEditor<T>(
133
129
  onSave,
134
130
  structural: isStructural,
135
131
  clearsHistory: isClearing,
136
- opensDirty = false,
137
132
  } = options;
138
133
  const [history, setHistory] = useState<History<T>>({
139
134
  stack: [options.document],
@@ -150,8 +145,6 @@ export function useDocumentEditor<T>(
150
145
  // editor reporting unsaved changes it had just written.
151
146
  const [saved, setSaved] = useState(options.document);
152
147
  // Cleared by a save, restored by the undo of that save.
153
- const [pendingOpen, setPendingOpen] = useState(opensDirty);
154
- // Cleared by a save, restored by the undo of that save.
155
148
  const [replacing, setReplacing] = useState(options.replaces);
156
149
  // Undoing a save over a draft writes the package's file back, so the draft text the editor shows is in no file until saved.
157
150
  const [unwritten, setUnwritten] = useState(false);
@@ -174,7 +167,6 @@ export function useDocumentEditor<T>(
174
167
  source: string;
175
168
  saved: T;
176
169
  history: History<T>;
177
- pendingOpen: boolean;
178
170
  replacing: string | undefined;
179
171
  unwritten: boolean;
180
172
  };
@@ -245,7 +237,6 @@ export function useDocumentEditor<T>(
245
237
  source,
246
238
  saved,
247
239
  history: historyRef.current,
248
- pendingOpen,
249
240
  replacing,
250
241
  unwritten,
251
242
  };
@@ -271,7 +262,6 @@ export function useDocumentEditor<T>(
271
262
  // now on disk rather than re-deriving from the text this session opened.
272
263
  setSource(result.source);
273
264
  setSaved(document);
274
- setPendingOpen(false);
275
265
  setReplacing(undefined);
276
266
  setUnwritten(false);
277
267
  const after = clearing
@@ -311,7 +301,6 @@ export function useDocumentEditor<T>(
311
301
  onSave,
312
302
  source,
313
303
  saved,
314
- pendingOpen,
315
304
  replacing,
316
305
  unwritten,
317
306
  isClearing,
@@ -345,7 +334,6 @@ export function useDocumentEditor<T>(
345
334
  // One batch, so no render sees the restored file under the saved history.
346
335
  setSource(before.source);
347
336
  setSaved(before.saved);
348
- setPendingOpen(before.pendingOpen);
349
337
  setReplacing(before.replacing);
350
338
  setUnwritten(before.unwritten || before.replacing !== undefined);
351
339
  // An edit typed during the undo's write is kept, as it is during a save's; it is unsaved against the restored file.
@@ -381,9 +369,8 @@ export function useDocumentEditor<T>(
381
369
  source,
382
370
  canUndo: history.index > 0,
383
371
  canRedo: history.index < history.stack.length - 1,
384
- dirty: edited || pendingOpen,
372
+ dirty: edited,
385
373
  edited,
386
- pendingOpen,
387
374
  ...(error === undefined ? {} : { error }),
388
375
  update,
389
376
  undo,
@@ -111,6 +111,32 @@ describe("useEditorCatalog", () => {
111
111
  expect(getModel).toHaveBeenCalledTimes(2);
112
112
  });
113
113
 
114
+ it("knows each model's path when the body leaves it out", async () => {
115
+ // What a client or proxy that keeps only the spec's fields hands back:
116
+ // `path` null, and the server's undeclared `modelPath` dropped.
117
+ getModel.mockImplementation(
118
+ (_env: string, _pkg: string, path: string) => {
119
+ const { modelPath: _dropped, ...body } = MODELS[path] as {
120
+ modelPath: string;
121
+ };
122
+ return Promise.resolve({ data: { ...body, path: null } });
123
+ },
124
+ );
125
+ try {
126
+ const { result } = mountCatalog({
127
+ modelPath: "a.malloy",
128
+ reports: REPORTS,
129
+ reportsSettled: true,
130
+ });
131
+ await waitFor(() => expect(names(result.current)).toEqual(["orders"]));
132
+ expect(result.current?.sources[0]?.modelPath).toBe("data.malloy");
133
+ } finally {
134
+ getModel.mockImplementation((_env, _pkg, path) =>
135
+ Promise.resolve({ data: MODELS[path] }),
136
+ );
137
+ }
138
+ });
139
+
114
140
  it("leaves each report out of its own catalog from one shared cache", async () => {
115
141
  const first = mountCatalog({
116
142
  modelPath: "a.malloy",
@@ -106,8 +106,13 @@ export function useEditorCatalog({
106
106
  () =>
107
107
  settled
108
108
  ? buildCatalog(
109
- results.flatMap((r) =>
110
- r.data ? [r.data as CompiledModel] : [],
109
+ // Each model under the path it was asked for, not one read
110
+ // back off the body: a client or proxy that keeps only the
111
+ // spec's fields may drop the server's spelling of it.
112
+ results.flatMap((r, i) =>
113
+ r.data
114
+ ? [{ ...(r.data as CompiledModel), path: wanted[i] }]
115
+ : [],
111
116
  ),
112
117
  excluded,
113
118
  )
@@ -65,8 +65,24 @@ export function useExitGuard({
65
65
  else onExitRef.current();
66
66
  }, [phase, dirty]);
67
67
 
68
+ /**
69
+ * Done: write the edits, then leave — only once the write has landed, so a
70
+ * refused save keeps the author here with its reason. With nothing to write
71
+ * it leaves at once; with nowhere to write, it asks, as Close does.
72
+ */
73
+ const saveAndExit = useCallback(() => {
74
+ if (phase !== "idle") return;
75
+ if (!dirty) onExitRef.current();
76
+ else if (!canSave) setPhase("asking");
77
+ else if (saving) setPhase("waiting");
78
+ else void issue();
79
+ }, [phase, dirty, canSave, saving, issue]);
80
+
68
81
  return {
69
82
  requestExit,
83
+ saveAndExit,
84
+ /** Done is writing, or waiting on a write already under way. */
85
+ finishing: phase === "saving" || phase === "waiting",
70
86
  dialog: {
71
87
  open: phase === "asking",
72
88
  canSave,
@@ -68,6 +68,23 @@ describe("useFilterForm: a new control", () => {
68
68
  expect(view.result.current.canApply).toBe(true);
69
69
  });
70
70
 
71
+ it("never takes a name the host says is taken, such as a model given the page does not show", async () => {
72
+ const document = await openDocument(SOURCE);
73
+ const view = renderHook(() =>
74
+ useFilterForm({
75
+ open: true,
76
+ document,
77
+ control: undefined,
78
+ available: [],
79
+ takenNames: ["BRAND"],
80
+ fieldsFor,
81
+ onApply: () => {},
82
+ }),
83
+ );
84
+ act(() => view.result.current.pickField("brand"));
85
+ expect(view.result.current.newName).toBe("BRAND_2");
86
+ });
87
+
71
88
  it("follows the field's type to the kind of control, and the comparison it needs", async () => {
72
89
  const { view } = await form(await openDocument(SOURCE));
73
90
  // A number range is still a filter expression, compared with `~`.
@@ -40,6 +40,7 @@ export function useFilterForm({
40
40
  document,
41
41
  control,
42
42
  available,
43
+ takenNames = [],
43
44
  fieldsFor,
44
45
  onApply,
45
46
  }: {
@@ -47,6 +48,8 @@ export function useFilterForm({
47
48
  document: DashboardDocument;
48
49
  control: BuilderControl | undefined;
49
50
  available: readonly BuilderControl[];
51
+ /** Names a new filter must not take: the model's givens the page does not show, say. */
52
+ takenNames?: readonly string[];
50
53
  fieldsFor?: (tile: QueryTile) => readonly CatalogField[] | undefined;
51
54
  onApply: (given: string, rows: MappingRow[], declare?: LocalGiven) => void;
52
55
  }) {
@@ -120,8 +123,9 @@ export function useFilterForm({
120
123
  () => [
121
124
  ...(document.localGivens ?? []).map((g) => g.name),
122
125
  ...available.map((g) => g.name),
126
+ ...takenNames,
123
127
  ],
124
- [document, available],
128
+ [document, available, takenNames],
125
129
  );
126
130
  const newName = useMemo(
127
131
  () => (field.trim() ? givenNameFor(field.trim(), taken) : ""),
@@ -24,7 +24,6 @@ const WITHHELD_REFUSAL =
24
24
  export interface OpenedDocument {
25
25
  source: string;
26
26
  document: DashboardDocument;
27
- conversion?: { from: string; to: string };
28
27
  /** The package file when this opened, which a draft's save overwrites. */
29
28
  packageText?: string;
30
29
  generation: number;
@@ -220,7 +219,6 @@ export function useOpenedDocument({
220
219
  setOpened((previous) => ({
221
220
  source: opening,
222
221
  document: result.document,
223
- ...(result.conversion ? { conversion: result.conversion } : {}),
224
222
  ...(packageAtOpen !== undefined
225
223
  ? { packageText: packageAtOpen }
226
224
  : {}),