@malloy-publisher/sdk 0.9.0 → 0.9.2

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 (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +82 -48
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -2,17 +2,25 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { DragDropProvider } from "@dnd-kit/react";
5
- import { Alert, Box, Stack } from "@mui/material";
5
+ import AddIcon from "@mui/icons-material/Add";
6
+ import { Alert, Box, Button, Stack, Typography } from "@mui/material";
6
7
  import {
7
8
  useCallback,
8
9
  useEffect,
9
10
  useMemo,
11
+ useRef,
10
12
  useState,
11
13
  type ReactNode,
12
14
  } from "react";
13
- import { DashboardProse } from "../Dashboard/Dashboard";
14
- import { DashboardGrid, DEFAULT_COLUMNS } from "../Dashboard/DashboardGrid";
15
- import { now, type DashboardEventHandler } from "../Dashboard/telemetry";
15
+ import {
16
+ DashboardGrid,
17
+ DEFAULT_COLUMNS,
18
+ nudgedSpan,
19
+ } from "../Dashboard/DashboardGrid";
20
+ import { tileTitle } from "../Dashboard/DashboardTile";
21
+ import type { TileHeadingSlots } from "../Dashboard/TileCard";
22
+ import type { SavesTo } from "./documentSession";
23
+ import type { BuilderEvent } from "./telemetry";
16
24
  import {
17
25
  acceptsField,
18
26
  applyMapping,
@@ -23,16 +31,24 @@ import {
23
31
  type BuilderGiven,
24
32
  type MappingRow,
25
33
  } from "./controls";
34
+ import { UnsavedChangesDialog } from "../UnsavedChangesDialog";
26
35
  import { BuilderToolbar } from "./BuilderToolbar";
36
+ import { changedTileKey } from "./changedTile";
37
+ import { InlineMarkdown } from "./InlineMarkdown";
38
+ import { InlineText } from "./InlineText";
39
+ import { OpenDraftContext, type OpenDraftSink } from "./openDraft";
27
40
  import { filterableFields, type PackageCatalog } from "./catalog";
28
41
  import {
42
+ isQueryTile,
43
+ isTextTile,
29
44
  tileKey,
30
45
  type DashboardDocument,
31
46
  type DashboardTile,
32
47
  type LocalGiven,
48
+ type QueryTile,
33
49
  } from "./document";
34
50
  import { AddTileDialog, type NewTile } from "./AddTileDialog";
35
- import { DiffDialog } from "./DiffDialog";
51
+ import { SaveNotice } from "./SaveNotice";
36
52
  import { DrillDialog } from "./DrillDialog";
37
53
  import { FilterDialog } from "./FilterDialog";
38
54
  import { SettingsPopover, settingsOf } from "./SettingsPopover";
@@ -40,11 +56,12 @@ import { FilterStrip } from "./FilterStrip";
40
56
  import { gapId, tileEntry, withGaps } from "./layout";
41
57
  import { builderSensors } from "./sortable";
42
58
  import { GapTarget, GridGuides, TileFrame, TilePlaceholder } from "./TileFrame";
59
+ import { TextTileBody } from "./TextTileBody";
43
60
  import { useTileReorder } from "./useTileReorder";
44
- import { useTileResize } from "./useTileResize";
45
61
  import { TileMenu } from "./TileMenu";
46
- import { useBuilderShortcuts } from "./useBuilderShortcuts";
62
+ import { useBuilderSession } from "./useBuilderSession";
47
63
  import { useDashboardEditor } from "./useDashboardEditor";
64
+ import type { SaveHandler } from "./useDocumentEditor";
48
65
 
49
66
  export type { BuilderGiven } from "./controls";
50
67
 
@@ -64,30 +81,33 @@ export type { BuilderGiven } from "./controls";
64
81
  * draws its own card AND its own heading. Nesting one inside a card of ours
65
82
  * would show a card in a card under two titles — which is precisely not what a
66
83
  * reader sees. So every affordance is drawn AROUND whatever the caller renders:
67
- * an outline for selection, a grip and a menu in the corners, a handle at the
68
- * edge.
84
+ * an outline for selection, a grip and a menu in the corners.
69
85
  *
70
- * **Everything here is on the thing it changes.** Drag a tile's right edge to
71
- * set its width, and the tile itself to reorder — into the empty end of a row
72
- * to change which row it is in. The tile's own menu holds its title and
73
- * subtitle. FILTERS are configured in exactly one place, the strip under the
86
+ * **Everything here is on the thing it changes.** Set a tile's width from its menu, and drag
87
+ * the tile itself to reorder — into the empty end of a row
88
+ * to change which row it is in. Click a title, subtitle, description or text
89
+ * tile to edit it where it stands. FILTERS are configured in exactly one place, the strip under the
74
90
  * header: each chip opens the tiles-to-update window for that control,
75
91
  * which is where a tile is bound or unbound, and "Add filter" declares a new
76
92
  * one in this file — the convention {@link LocalGiven} describes — or binds one
77
93
  * the model offers. Nothing about filters is on the tiles themselves: a second
78
94
  * place to edit the same binding is a second place for it to be wrong.
79
95
  *
80
- * Tiles are added from the package's catalog and removed from their menu; a
81
- * save that adds or removes one shows the file's diff first, because those
82
- * moves relocate declarations and the comments beside them.
96
+ * Tiles are added from the package's catalog and removed from their menu.
83
97
  */
84
98
  export interface DashboardBuilderProps {
85
99
  /** The file being edited. */
86
100
  source: string;
87
101
  /** The document that file produced. */
88
102
  document: DashboardDocument;
89
- /** Persist the patched file. Left out, the builder edits without saving. */
90
- onSave?: (source: string) => Promise<void> | void;
103
+ /**
104
+ * Persist the patched file. Left out, the builder edits without saving.
105
+ * Undo save calls it too, with `purpose: "undo"` and the text from before
106
+ * the save, so it must write through the same channel and checks.
107
+ */
108
+ onSave?: SaveHandler<DashboardDocument>;
109
+ /** Whether the save notice (View change, Undo save) is showing, for a host that must not replace the document under it. */
110
+ onSaveNoticeChange?: (showing: boolean) => void;
91
111
  /**
92
112
  * The document as it stands, on every edit — including the first render.
93
113
  *
@@ -102,8 +122,13 @@ export interface DashboardBuilderProps {
102
122
  /**
103
123
  * Renders a tile, card and heading included — this is where a real
104
124
  * `DashboardTile` goes. Without it, tiles show what they will run.
125
+ *
126
+ * `heading` is the tile's title and subtitle as fields edited in place;
127
+ * absent for a tile whose title the model owns. A host that draws the
128
+ * heading itself passes it on (`DashboardTile`'s `heading`), or the tile
129
+ * cannot be retitled on the page.
105
130
  */
106
- renderTile?: (tile: DashboardTile) => ReactNode;
131
+ renderTile?: (tile: QueryTile, heading?: TileHeadingSlots) => ReactNode;
107
132
  /**
108
133
  * The control row, in the slot the reader puts it — this is where a real
109
134
  * `GivensPanel` goes.
@@ -144,8 +169,14 @@ export interface DashboardBuilderProps {
144
169
  * go. Absent, a drill can only filter this dashboard.
145
170
  */
146
171
  dashboards?: string[];
147
- /** Saves and refusals, for the host to log; see `DashboardEvent`. */
148
- onEvent?: DashboardEventHandler;
172
+ /** Saves and refusals, for the host to log; see `DashboardEvent`. A notebook-kind document reports `NotebookEvent`s instead. */
173
+ onEvent?: (event: BuilderEvent) => void;
174
+ /**
175
+ * The document is a conversion of a cell-format notebook: `from` is the text
176
+ * on disk, `to` the layout text it converts to. Save writes `to` with the
177
+ * edits spliced in, and Undo save puts `from` back.
178
+ */
179
+ conversion?: { from: string; to: string };
149
180
  /**
150
181
  * Whether the document differs from what was last saved, on every change
151
182
  * and on mount.
@@ -163,13 +194,20 @@ export interface DashboardBuilderProps {
163
194
  * this browser, and into a host store that holds the record are not the
164
195
  * same event.
165
196
  */
166
- savesTo?: "package" | "browser" | "host";
197
+ savesTo?: SavesTo;
198
+ /** The backend's own words for where Save writes, in place of the generic line for `savesTo`. */
199
+ saveLabel?: string;
200
+ /** The file a save overwrites when `source` is a draft of it, so Undo save restores that file rather than the draft. */
201
+ replaces?: string;
202
+ /** The document's file within the package, so a kind switch tags what its folder would otherwise misread. */
203
+ modelPath?: string;
167
204
  /**
168
- * The host's own actions for the edit bar — Done — rendered beside
169
- * undo, redo and save. The builder owns the edits; where the file goes
170
- * afterwards is the host's, so its buttons sit in the host's slot.
205
+ * The host's own extra actions for the edit bar, rendered beside undo, redo
206
+ * and save. Leaving is `onExit`, not this: the builder draws Done itself.
171
207
  */
172
208
  toolbar?: ReactNode;
209
+ /** Leave the builder: renders "Close", which asks first when there are unsaved edits. */
210
+ onExit?: () => void;
173
211
  }
174
212
 
175
213
  export function DashboardBuilder({
@@ -178,32 +216,38 @@ export function DashboardBuilder({
178
216
  onSave,
179
217
  onChange,
180
218
  onDirtyChange,
219
+ onSaveNoticeChange,
181
220
  renderTile,
182
221
  controls,
183
222
  givens,
184
223
  catalog,
185
224
  toolbar,
225
+ onExit,
186
226
  dashboards,
187
227
  onEvent,
228
+ conversion,
188
229
  savesTo = "package",
230
+ saveLabel,
231
+ replaces,
232
+ modelPath,
189
233
  }: DashboardBuilderProps) {
190
234
  const editor = useDashboardEditor({
191
235
  source,
192
236
  document,
193
237
  ...(onSave ? { onSave } : {}),
238
+ ...(conversion ? { conversion } : {}),
239
+ ...(replaces !== undefined ? { replaces } : {}),
240
+ ...(modelPath !== undefined ? { modelPath } : {}),
194
241
  });
195
242
  const [selected, setSelected] = useState<number | undefined>(undefined);
196
- const [saving, setSaving] = useState(false);
197
- const columns = editor.document.columns ?? DEFAULT_COLUMNS;
198
- const { resize, gridBox, startResize, onResize, endResize } = useTileResize({
199
- tiles: editor.document.tiles,
200
- columns,
201
- onStart: setSelected,
202
- commit: (index, span) =>
203
- editor.update((draft) => {
204
- draft.tiles[index].colspan = span;
205
- }),
206
- });
243
+ // Undo and redo point at the tile they changed: lit briefly, and scrolled to.
244
+ const [flash, setFlash] = useState<string | undefined>(undefined);
245
+ const stepping = useRef(false);
246
+ const lastDocument = useRef(editor.document);
247
+ // A notebook is one column whatever the file says, and the builder never writes its width.
248
+ const notebook = editor.document.kind === "notebook";
249
+ const columns = notebook ? 1 : (editor.document.columns ?? DEFAULT_COLUMNS);
250
+ const gridBox = useRef<HTMLDivElement>(null);
207
251
  const { dragging, preview, onDragStart, onDragOver, onDragEnd } =
208
252
  useTileReorder({
209
253
  tiles: editor.document.tiles,
@@ -221,8 +265,14 @@ export function DashboardBuilder({
221
265
  const [menu, setMenu] = useState<
222
266
  { anchor: HTMLElement; index: number } | undefined
223
267
  >(undefined);
224
- // The add-tile picker, and the diff a structural save shows first.
268
+ // The add-tile picker.
225
269
  const [addingTile, setAddingTile] = useState(false);
270
+ // Where the next added tile lands; undefined appends.
271
+ const [insertAt, setInsertAt] = useState<number | undefined>(undefined);
272
+ const openAdd = (at?: number) => {
273
+ setInsertAt(at);
274
+ setAddingTile(true);
275
+ };
226
276
  // The clickable-cells window, for one tile's source.
227
277
  const [drillSource, setDrillSource] = useState<string | undefined>(
228
278
  undefined,
@@ -231,18 +281,6 @@ export function DashboardBuilder({
231
281
  const [settingsAnchor, setSettingsAnchor] = useState<HTMLElement | null>(
232
282
  null,
233
283
  );
234
- const [pendingSave, setPendingSave] = useState<
235
- { before: string; after: string } | undefined
236
- >(undefined);
237
-
238
- useEffect(() => {
239
- onChange?.(editor.document);
240
- }, [editor.document, onChange]);
241
- // Also on mount, so a host that remounted the builder on new text is told
242
- // the slate is clean rather than carrying the previous mount's answer.
243
- useEffect(() => {
244
- onDirtyChange?.(editor.dirty);
245
- }, [editor.dirty, onDirtyChange]);
246
284
  // One object per document, or the popover's draft would reset on every
247
285
  // render of the builder while it is open.
248
286
  const settings = useMemo(
@@ -250,6 +288,16 @@ export function DashboardBuilder({
250
288
  [editor.document],
251
289
  );
252
290
 
291
+ // Imported sources a tile or extension reads, which the settings cannot take off.
292
+ const sourcesInUse = useMemo(
293
+ () =>
294
+ new Set([
295
+ ...editor.document.sources.map((source) => source.base),
296
+ ...editor.document.tiles.filter(isQueryTile).map((t) => t.source),
297
+ ]),
298
+ [editor.document],
299
+ );
300
+
253
301
  // The givens the MODEL offers: the caller's list, less any the opened file
254
302
  // declared itself. A caller gets that list from the server's manifest, which
255
303
  // resolves givens across the file and its imports without saying which is
@@ -284,13 +332,31 @@ export function DashboardBuilder({
284
332
  [catalog, editor.document.sources],
285
333
  );
286
334
  const fieldsFor = useCallback(
287
- (tile: DashboardTile) =>
335
+ (tile: QueryTile) =>
288
336
  fieldsBySource.get(tile.source) ??
289
337
  // A tile on an imported source with no extension of its own: its
290
338
  // source IS a model source, and may be in the catalog directly.
291
339
  filterableFields(catalog, tile.source),
292
340
  [fieldsBySource, catalog],
293
341
  );
342
+ // The catalog's view behind the tile whose menu is open, for the charts the
343
+ // picker may offer: a reference tile's base view, else a view of the tile's own name.
344
+ const menuAt =
345
+ menu === undefined ? undefined : editor.document.tiles[menu.index];
346
+ const menuTile = menuAt && isQueryTile(menuAt) ? menuAt : undefined;
347
+ const menuView = (() => {
348
+ if (!menuTile || !catalog) return undefined;
349
+ const base =
350
+ editor.document.sources.find((s) => s.name === menuTile.source)
351
+ ?.base ?? menuTile.source;
352
+ const viewName =
353
+ menuTile.declaration.kind === "reference"
354
+ ? menuTile.declaration.from
355
+ : menuTile.name;
356
+ return catalog.sources
357
+ .find((s) => s.name === base)
358
+ ?.views.find((v) => v.name === viewName);
359
+ })();
294
360
  // Bindings a tile's source cannot take, per control — a field it does not
295
361
  // have, or one of a type the given cannot compare: marked on the chip, so a
296
362
  // broken binding is seen before the package refuses it.
@@ -300,6 +366,7 @@ export function DashboardBuilder({
300
366
  ): string[] => {
301
367
  const out: string[] = [];
302
368
  for (const tile of editor.document.tiles) {
369
+ if (!isQueryTile(tile)) continue;
303
370
  const known = fieldsFor(tile);
304
371
  if (!known) continue;
305
372
  const types = new Map(known.map((field) => [field.name, field.type]));
@@ -326,45 +393,155 @@ export function DashboardBuilder({
326
393
  [controlList],
327
394
  );
328
395
 
329
- const commitSave = useCallback(() => {
330
- setPendingSave(undefined);
331
- setSaving(true);
332
- const started = now();
333
- const { structural } = editor;
334
- const tiles = editor.document.tiles.length;
335
- void editor
336
- .save()
337
- .then((outcome) => {
338
- if (outcome.ok === true)
339
- onEvent?.({
340
- type: "dashboard.saved",
341
- tiles,
342
- structural,
343
- where: savesTo,
344
- durationMs: now() - started,
345
- });
346
- else
347
- onEvent?.({
348
- type: "dashboard.save_refused",
349
- reason: outcome.reason,
350
- });
351
- })
352
- .finally(() => setSaving(false));
353
- }, [editor, onEvent, savesTo]);
354
- const save = useCallback(() => {
355
- if (!onSave || !editor.dirty || saving) return;
356
- if (!editor.structural) {
357
- commitSave();
358
- return;
359
- }
360
- // A tile was added or removed: show what that does to the file first.
361
- void editor.preview().then((result) => {
362
- if (result.ok)
363
- setPendingSave({ before: editor.source, after: result.source });
364
- // A refusal surfaces through the same path a save's would.
365
- else commitSave();
366
- });
367
- }, [onSave, editor, saving, commitSave]);
396
+ const shortcuts = useMemo(
397
+ () => ({
398
+ // Escape drops the selection — unless the menu or the filter window is open, in which case the key is theirs and they close on it themselves.
399
+ escape: () => {
400
+ if (!menu && !filterDialog) setSelected(undefined);
401
+ },
402
+ nudge: (delta: 1 | -1) => {
403
+ // The drag's keyboard sensor also reads the arrows, and a drop would write the drag-start width back.
404
+ if (dragging || selected === undefined || notebook) return;
405
+ const tile = editor.document.tiles[selected];
406
+ if (
407
+ !tile ||
408
+ (isQueryTile(tile) && tile.declaration.kind === "inherited")
409
+ )
410
+ return;
411
+ const span = nudgedSpan(tile.colspan ?? 1, delta, columns);
412
+ if (span === (tile.colspan ?? 1)) return;
413
+ editor.update((draft) => {
414
+ draft.tiles[selected].colspan = span;
415
+ });
416
+ },
417
+ }),
418
+ [editor, menu, filterDialog, selected, columns, notebook, dragging],
419
+ );
420
+ useEffect(() => {
421
+ const before = lastDocument.current;
422
+ lastDocument.current = editor.document;
423
+ if (!stepping.current) return;
424
+ stepping.current = false;
425
+ const key = changedTileKey(before, editor.document);
426
+ if (key === undefined) return;
427
+ setFlash(key);
428
+ const target = Array.from(
429
+ gridBox.current?.querySelectorAll<HTMLElement>("[data-tile-key]") ??
430
+ [],
431
+ ).find((element) => element.dataset.tileKey === key);
432
+ // jsdom has no layout, so no scrollIntoView.
433
+ target?.scrollIntoView?.({ block: "nearest", behavior: "smooth" });
434
+ }, [editor.document, gridBox]);
435
+ useEffect(() => {
436
+ if (flash === undefined) return;
437
+ const timer = setTimeout(() => setFlash(undefined), 1500);
438
+ return () => clearTimeout(timer);
439
+ }, [flash]);
440
+ const stepEditor = useMemo(
441
+ () => ({
442
+ ...editor,
443
+ undo: () => {
444
+ stepping.current = true;
445
+ editor.undo();
446
+ },
447
+ redo: () => {
448
+ stepping.current = true;
449
+ editor.redo();
450
+ },
451
+ }),
452
+ [editor],
453
+ );
454
+ const [draftDirty, setDraftDirty] = useState(false);
455
+ const draftCommit = useRef<(() => boolean) | undefined>(undefined);
456
+ const afterCommit = useRef<(() => void) | undefined>(undefined);
457
+ const openDraft = useMemo<OpenDraftSink>(
458
+ () => ({ setDirty: setDraftDirty, commitRef: draftCommit }),
459
+ [],
460
+ );
461
+ // A save reads the committed document, so an open draft is committed first and the save runs once that has rendered.
462
+ const prepare = useCallback(
463
+ (run: () => Promise<void> | void): Promise<void> | void => {
464
+ if (!draftCommit.current) return run();
465
+ if (!draftCommit.current()) return;
466
+ return new Promise<void>((resolve) => {
467
+ afterCommit.current = () => resolve(run());
468
+ });
469
+ },
470
+ [],
471
+ );
472
+ useEffect(() => {
473
+ if (draftDirty || !afterCommit.current) return;
474
+ const run = afterCommit.current;
475
+ afterCommit.current = undefined;
476
+ run();
477
+ }, [draftDirty, editor.dirty]);
478
+ const session = useBuilderSession<DashboardDocument>({
479
+ editor: stepEditor,
480
+ extraDirty: draftDirty,
481
+ prepare,
482
+ unit: { name: "tile", count: (document) => document.tiles.length },
483
+ onSave,
484
+ onExit,
485
+ onDirtyChange,
486
+ onSaveNoticeChange,
487
+ onChange,
488
+ shortcuts,
489
+ report: {
490
+ size: editor.document.tiles.length,
491
+ // A notebook-kind document keeps the `notebook.*` names hosts already count.
492
+ saved: ({ size, structural, durationMs, fromOpen }) =>
493
+ onEvent?.(
494
+ notebook
495
+ ? {
496
+ type: "notebook.saved",
497
+ cells: size,
498
+ structural,
499
+ converted: fromOpen,
500
+ where: savesTo,
501
+ durationMs,
502
+ }
503
+ : {
504
+ type: "dashboard.saved",
505
+ tiles: size,
506
+ structural,
507
+ where: savesTo,
508
+ durationMs,
509
+ },
510
+ ),
511
+ refused: (reason) =>
512
+ onEvent?.({
513
+ type: notebook
514
+ ? "notebook.save_refused"
515
+ : "dashboard.save_refused",
516
+ reason,
517
+ }),
518
+ undone: ({ size, structural, durationMs }) =>
519
+ onEvent?.(
520
+ notebook
521
+ ? {
522
+ type: "notebook.save_undone",
523
+ cells: size,
524
+ structural,
525
+ where: savesTo,
526
+ durationMs,
527
+ }
528
+ : {
529
+ type: "dashboard.save_undone",
530
+ tiles: size,
531
+ structural,
532
+ where: savesTo,
533
+ durationMs,
534
+ },
535
+ ),
536
+ undoRefused: (reason) =>
537
+ onEvent?.({
538
+ type: notebook
539
+ ? "notebook.save_undo_refused"
540
+ : "dashboard.save_undo_refused",
541
+ reason,
542
+ }),
543
+ },
544
+ });
368
545
 
369
546
  /** A tile from the picker: on the extension of its source, or a new one. */
370
547
  const addTile = (tile: NewTile) => {
@@ -386,20 +563,83 @@ export function DashboardBuilder({
386
563
  // one under the same name; then kept distinct from its siblings.
387
564
  const used = new Set(
388
565
  draft.tiles
566
+ .filter(isQueryTile)
389
567
  .filter((t) => t.source === extension!.name)
390
568
  .map((t) => t.name),
391
569
  );
392
570
  let name = `${tile.view}_tile`;
393
571
  for (let n = 2; used.has(name); n++) name = `${tile.view}_tile_${n}`;
394
- draft.tiles.push({
572
+ draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
395
573
  name,
396
574
  source: extension.name,
397
575
  declaration: { kind: "reference", from: tile.view },
398
- colspan: tile.colspan,
576
+ ...(notebook ? {} : { colspan: tile.colspan }),
399
577
  ...(tile.label ? { label: tile.label } : {}),
578
+ ...(tile.chart ? { chart: tile.chart } : {}),
579
+ ...(tile.chartCarried ? { chartCarried: tile.chartCarried } : {}),
580
+ });
581
+ });
582
+ setSelected(insertAt ?? editor.document.tiles.length);
583
+ };
584
+
585
+ /** An empty text tile at the end, named for the first free `text_N`. */
586
+ const addText = () => {
587
+ setAddingTile(false);
588
+ editor.update((draft) => {
589
+ const taken = new Set(
590
+ draft.tiles.filter(isTextTile).map((t) => t.name),
591
+ );
592
+ let n = 1;
593
+ while (taken.has(`text_${n}`)) n++;
594
+ draft.tiles.splice(insertAt ?? draft.tiles.length, 0, {
595
+ kind: "text",
596
+ name: `text_${n}`,
597
+ markdown: "",
598
+ ...(notebook ? {} : { colspan: columns }),
400
599
  });
401
600
  });
402
- setSelected(editor.document.tiles.length);
601
+ setSelected(insertAt ?? editor.document.tiles.length);
602
+ };
603
+
604
+ /** Change one tile where it stands, found by key so a preview order cannot misdirect it. */
605
+ const editTile = (key: string, change: (tile: DashboardTile) => void) =>
606
+ editor.update((draft) => {
607
+ const tile = draft.tiles.find((each) => tileKey(each) === key);
608
+ if (tile) change(tile);
609
+ });
610
+
611
+ /** A query tile's title and subtitle as fields on the tile, unless the model owns them. */
612
+ const headingOf = (
613
+ tile: QueryTile,
614
+ fallback: string,
615
+ ): TileHeadingSlots | undefined => {
616
+ if (tile.declaration.kind === "inherited") return undefined;
617
+ const key = tileKey(tile);
618
+ const set = (field: "label" | "subtitle") => (next: string) =>
619
+ editTile(key, (each) => {
620
+ if (!isQueryTile(each)) return;
621
+ if (next === "") delete each[field];
622
+ else each[field] = next;
623
+ });
624
+ return {
625
+ title: (
626
+ <InlineText
627
+ value={tile.label ?? ""}
628
+ placeholder={fallback}
629
+ ariaLabel="Tile title"
630
+ onCommit={set("label")}
631
+ />
632
+ ),
633
+ subtitle: (
634
+ <InlineText
635
+ value={tile.subtitle ?? ""}
636
+ placeholder="Add a subtitle"
637
+ ariaLabel="Tile subtitle"
638
+ faintWhenEmpty
639
+ onCommit={set("subtitle")}
640
+ />
641
+ ),
642
+ };
403
643
  };
404
644
 
405
645
  const removeTile = (index: number) => {
@@ -410,38 +650,6 @@ export function DashboardBuilder({
410
650
  });
411
651
  };
412
652
 
413
- useBuilderShortcuts(
414
- // One handlers object per change of what they read, so the key listener
415
- // is not torn down and re-bound on every render.
416
- useMemo(
417
- () => ({
418
- undo: editor.undo,
419
- redo: editor.redo,
420
- ...(onSave ? { save } : {}),
421
- // Escape drops the selection — unless the menu or the filter
422
- // window is open, in which case the key is theirs and they close
423
- // on it themselves.
424
- escape: () => {
425
- if (!menu && !filterDialog) setSelected(undefined);
426
- },
427
- nudge: (delta: 1 | -1) => {
428
- if (selected === undefined) return;
429
- const tile = editor.document.tiles[selected];
430
- if (!tile || tile.declaration.kind === "inherited") return;
431
- const span = Math.min(
432
- Math.max((tile.colspan ?? 1) + delta, 1),
433
- columns,
434
- );
435
- if (span === (tile.colspan ?? 1)) return;
436
- editor.update((draft) => {
437
- draft.tiles[selected].colspan = span;
438
- });
439
- },
440
- }),
441
- [editor, onSave, save, menu, filterDialog, selected, columns],
442
- ),
443
- );
444
-
445
653
  /** The filter window's result: bind, and declare when it is new or retagged. */
446
654
  const applyFilter = (
447
655
  given: string,
@@ -463,19 +671,12 @@ export function DashboardBuilder({
463
671
  };
464
672
 
465
673
  // What the grid lays out: the document, except mid-gesture, where it is
466
- // the preview — the tile being resized at its previewed width, or the tiles
467
- // in their previewed order. So the row reflows under the pointer exactly as
468
- // it will once the edit lands.
469
- const shown = (() => {
470
- const tiles = editor.document.tiles;
471
- if (resize !== undefined)
472
- return tiles.map((each, index) =>
473
- index === resize.index ? { ...each, colspan: resize.span } : each,
474
- );
475
- return preview ?? tiles;
476
- })();
674
+ // the preview — the tiles in their previewed order. So the row reflows under
675
+ // the pointer exactly as it will once the edit lands.
676
+ const shown = preview ?? editor.document.tiles;
477
677
  // And, while a drag is live, the empty end of every row as a drop target.
478
678
  // Not otherwise: a gap is only a place to land while something is in hand.
679
+ const empty = editor.document.tiles.length === 0;
479
680
  const entries = dragging ? withGaps(shown, columns) : shown.map(tileEntry);
480
681
  return (
481
682
  // The padding is for the SELECTION RING. An outline is painted outside
@@ -489,196 +690,290 @@ export function DashboardBuilder({
489
690
  // plus its 2px width.
490
691
  // The bar carries its own gap to what it sits over, so the surface adds
491
692
  // none between the two.
492
- <Stack sx={{ gap: 0 }}>
493
- {/* Outside the ring's inset, so the bar lines up to the pixel with the
693
+ <OpenDraftContext.Provider value={openDraft}>
694
+ <Stack sx={{ gap: 0 }}>
695
+ {/* Outside the ring's inset, so the bar lines up to the pixel with the
494
696
  reader's — the whole point of it being the same bar. */}
495
- <BuilderToolbar
496
- canUndo={editor.canUndo}
497
- canRedo={editor.canRedo}
498
- onUndo={editor.undo}
499
- onRedo={editor.redo}
500
- dirty={editor.dirty}
501
- saving={saving}
502
- {...(onSave ? { onSave: save } : {})}
503
- {...(toolbar ? { actions: toolbar } : {})}
504
- {...(catalog ? { onAddTile: () => setAddingTile(true) } : {})}
505
- onSettings={setSettingsAnchor}
506
- />
697
+ <BuilderToolbar
698
+ {...session.toolbarProps}
699
+ {...(toolbar ? { actions: toolbar } : {})}
700
+ {...(catalog ? { onAddTile: () => openAdd() } : {})}
701
+ onSettings={setSettingsAnchor}
702
+ savesTo={savesTo}
703
+ {...(saveLabel ? { saveLabel } : {})}
704
+ />
507
705
 
508
- {/* The ring's inset, minus the top: nothing at the top of this stack
706
+ {/* The ring's inset, minus the top: nothing at the top of this stack
509
707
  can be selected (the prose and the control row are not tiles), and
510
708
  4px there would put the title 4px further from the bar than the
511
709
  reader's is. */}
512
- <Stack sx={{ gap: 2, px: "4px", pb: "4px" }}>
513
- <DashboardProse
514
- title={editor.document.title || "Untitled dashboard"}
515
- {...(editor.document.description
516
- ? { description: editor.document.description }
517
- : {})}
518
- />
710
+ <Stack sx={{ gap: 2, px: "4px", pb: "4px" }}>
711
+ {editor.pendingOpen && (
712
+ <Alert severity="info">
713
+ This notebook is in the cell format. Saving rewrites it as
714
+ a layout notebook, and a named query run once becomes that
715
+ tile&apos;s view; Undo save puts it back.
716
+ </Alert>
717
+ )}
718
+ <SaveNotice {...session.notice} />
719
+ <Box>
720
+ <Typography variant="h5" sx={{ fontWeight: 600 }}>
721
+ <InlineText
722
+ value={editor.document.title}
723
+ placeholder={
724
+ notebook ? "Untitled notebook" : "Untitled dashboard"
725
+ }
726
+ ariaLabel={
727
+ notebook ? "Notebook title" : "Dashboard title"
728
+ }
729
+ onCommit={(next) =>
730
+ editor.update((draft) => {
731
+ draft.title = next;
732
+ })
733
+ }
734
+ />
735
+ </Typography>
736
+ <InlineMarkdown
737
+ variant="caption"
738
+ markdown={editor.document.description ?? ""}
739
+ placeholder="Add a description"
740
+ onCommit={(next) =>
741
+ editor.update((draft) => {
742
+ if (next.trim() === "") delete draft.description;
743
+ else draft.description = next;
744
+ })
745
+ }
746
+ />
747
+ </Box>
519
748
 
520
- <FilterStrip
521
- controls={controlList}
522
- tileCount={editor.document.tiles.length}
523
- unknownFieldsOf={unknownFieldsOf}
524
- onEdit={(control) => setFilterDialog({ control })}
525
- onAdd={() => setFilterDialog({})}
526
- >
527
- {controls}
528
- </FilterStrip>
749
+ {empty ? (
750
+ <Stack
751
+ sx={{
752
+ alignItems: "flex-start",
753
+ gap: 1,
754
+ py: 3,
755
+ px: 2,
756
+ border: 1,
757
+ borderStyle: "dashed",
758
+ borderColor: "divider",
759
+ borderRadius: 1,
760
+ }}
761
+ >
762
+ <Typography variant="body2">
763
+ This {notebook ? "notebook" : "dashboard"} is not served
764
+ until it has a tile.
765
+ </Typography>
766
+ {catalog && (
767
+ <Button
768
+ size="small"
769
+ variant="contained"
770
+ onClick={() => openAdd()}
771
+ >
772
+ Add tile
773
+ </Button>
774
+ )}
775
+ </Stack>
776
+ ) : (
777
+ <FilterStrip
778
+ controls={controlList}
779
+ tileCount={editor.document.tiles.length}
780
+ unknownFieldsOf={unknownFieldsOf}
781
+ onEdit={(control) => setFilterDialog({ control })}
782
+ onAdd={() => setFilterDialog({})}
783
+ onRemove={dropControl}
784
+ >
785
+ {controls}
786
+ </FilterStrip>
787
+ )}
529
788
 
530
- {editor.error && (
531
- // The edit is still here; the message says what stopped it reaching
532
- // the file, which is a different thing from losing the work.
533
- <Alert severity="warning">{editor.error}</Alert>
534
- )}
789
+ {editor.error && (
790
+ // The edit is still here; the message says what stopped it reaching
791
+ // the file, which is a different thing from losing the work.
792
+ <Alert severity="warning">{editor.error}</Alert>
793
+ )}
535
794
 
536
- <DragDropProvider
537
- sensors={builderSensors}
538
- onDragStart={onDragStart}
539
- onDragOver={onDragOver}
540
- onDragEnd={onDragEnd}
541
- >
542
- <Box ref={gridBox} sx={{ position: "relative" }}>
543
- {(resize !== undefined || dragging) && (
544
- <GridGuides columns={columns} />
545
- )}
795
+ <DragDropProvider
796
+ sensors={builderSensors}
797
+ onDragStart={onDragStart}
798
+ onDragOver={onDragOver}
799
+ onDragEnd={onDragEnd}
800
+ >
801
+ <Box ref={gridBox} sx={{ position: "relative" }}>
802
+ {!notebook && dragging && <GridGuides columns={columns} />}
546
803
 
547
- <DashboardGrid
548
- tiles={entries}
549
- columns={columns}
550
- keyOf={(entry) =>
551
- entry.kind === "gap"
552
- ? gapId(entry.after)
553
- : tileKey(entry.tile)
554
- }
555
- renderTile={(entry) => {
556
- if (entry.kind === "gap")
557
- return <GapTarget after={entry.after} />;
558
- const { tile: each, index } = entry;
559
- return (
560
- <TileFrame
561
- tile={each}
562
- index={index}
563
- selected={index === selected}
564
- menuOpen={menu?.index === index}
565
- resizeSpan={
566
- resize?.index === index
567
- ? resize.span
568
- : undefined
569
- }
570
- columns={columns}
571
- onSelect={() => setSelected(index)}
572
- onOpenMenu={(anchor) => {
573
- setSelected(index);
574
- setMenu({ anchor, index });
575
- }}
576
- onResizeStart={(event) =>
577
- startResize(event, index)
578
- }
579
- onResizeMove={onResize}
580
- onResizeEnd={endResize}
581
- >
582
- {renderTile ? (
583
- renderTile(each)
584
- ) : (
585
- <TilePlaceholder tile={each} />
586
- )}
587
- </TileFrame>
588
- );
589
- }}
590
- />
591
- </Box>
592
- </DragDropProvider>
593
- <FilterDialog
594
- open={filterDialog !== undefined}
595
- document={editor.document}
596
- {...(filterDialog?.control
597
- ? { control: filterDialog.control }
598
- : {})}
599
- available={available}
600
- {...(catalog ? { fieldsFor } : {})}
601
- onClose={() => setFilterDialog(undefined)}
602
- onApply={applyFilter}
603
- onRemove={dropControl}
604
- />
605
- <TileMenu
606
- anchor={menu?.anchor ?? null}
607
- tile={
608
- menu === undefined
609
- ? undefined
610
- : editor.document.tiles[menu.index]
611
- }
612
- onClose={() => setMenu(undefined)}
613
- onCommit={(next) => {
614
- const at = menu?.index;
615
- if (at === undefined) return;
616
- editor.update((draft) => {
617
- draft.tiles[at] = next;
618
- });
619
- }}
620
- onRemove={() => {
621
- if (menu !== undefined) removeTile(menu.index);
622
- }}
623
- columns={columns}
624
- onDrills={() => {
625
- if (menu !== undefined)
626
- setDrillSource(editor.document.tiles[menu.index]?.source);
627
- }}
628
- />
629
- <DrillDialog
630
- open={drillSource !== undefined}
631
- document={editor.document}
632
- source={editor.document.sources.find(
633
- (s) => s.name === drillSource,
804
+ <DashboardGrid
805
+ tiles={entries}
806
+ columns={columns}
807
+ keyOf={(entry) =>
808
+ entry.kind === "gap"
809
+ ? gapId(entry.after)
810
+ : tileKey(entry.tile)
811
+ }
812
+ renderTile={(entry) => {
813
+ if (entry.kind === "gap")
814
+ return <GapTarget after={entry.after} />;
815
+ const { tile: each, index } = entry;
816
+ return (
817
+ <TileFrame
818
+ tile={each}
819
+ index={index}
820
+ selected={index === selected}
821
+ flash={tileKey(each) === flash}
822
+ menuOpen={menu?.index === index}
823
+ {...(notebook && catalog
824
+ ? {
825
+ onInsertAfter: () =>
826
+ openAdd(index + 1),
827
+ }
828
+ : {})}
829
+ onSelect={() => setSelected(index)}
830
+ onOpenMenu={(anchor) => {
831
+ setSelected(index);
832
+ setMenu({ anchor, index });
833
+ }}
834
+ >
835
+ {isTextTile(each) ? (
836
+ <TextTileBody
837
+ tile={each}
838
+ onChange={(markdown) =>
839
+ editTile(tileKey(each), (tile) => {
840
+ if (isTextTile(tile))
841
+ tile.markdown = markdown;
842
+ })
843
+ }
844
+ />
845
+ ) : renderTile && !editor.pendingOpen ? (
846
+ // Until the conversion is saved the package has none of its views to run.
847
+ renderTile(
848
+ each,
849
+ headingOf(
850
+ each,
851
+ tileTitle(
852
+ `${each.source} -> ${each.name}`,
853
+ ),
854
+ ),
855
+ )
856
+ ) : (
857
+ <TilePlaceholder
858
+ tile={each}
859
+ heading={headingOf(each, each.name)}
860
+ {...(editor.pendingOpen
861
+ ? {
862
+ note: "Preview appears after you Save",
863
+ }
864
+ : {})}
865
+ />
866
+ )}
867
+ </TileFrame>
868
+ );
869
+ }}
870
+ />
871
+ </Box>
872
+ </DragDropProvider>
873
+ {notebook && catalog && !empty && (
874
+ <Button
875
+ size="small"
876
+ startIcon={<AddIcon />}
877
+ aria-label="Add tile at the end"
878
+ onClick={() => openAdd()}
879
+ sx={{ alignSelf: "center" }}
880
+ >
881
+ Add tile
882
+ </Button>
634
883
  )}
635
- givenNames={controlList.map((c) => c.name)}
636
- dashboards={dashboards ?? []}
637
- onClose={() => setDrillSource(undefined)}
638
- onApply={(drills) =>
639
- editor.update((draft) => {
640
- const kept = (draft.drills ?? []).filter(
641
- (d) => d.source !== drillSource,
642
- );
643
- const next = [...kept, ...drills];
644
- if (next.length === 0) delete draft.drills;
645
- else draft.drills = next;
646
- })
647
- }
648
- />
649
- <SettingsPopover
650
- anchor={settingsAnchor}
651
- settings={settings}
652
- onClose={() => setSettingsAnchor(null)}
653
- onCommit={(next) =>
654
- editor.update((draft) => {
655
- draft.title = next.title;
656
- if (next.description === undefined)
657
- delete draft.description;
658
- else draft.description = next.description;
659
- if (next.columns === undefined) delete draft.columns;
660
- else draft.columns = next.columns;
661
- if (next.autorun === undefined) delete draft.autorun;
662
- else draft.autorun = next.autorun;
663
- })
664
- }
665
- />
666
- <AddTileDialog
667
- open={addingTile}
668
- document={editor.document}
669
- catalog={catalog}
670
- columns={columns}
671
- onClose={() => setAddingTile(false)}
672
- onAdd={addTile}
673
- />
674
- <DiffDialog
675
- open={pendingSave !== undefined}
676
- before={pendingSave?.before ?? ""}
677
- after={pendingSave?.after ?? ""}
678
- onConfirm={commitSave}
679
- onClose={() => setPendingSave(undefined)}
680
- />
884
+ <FilterDialog
885
+ open={filterDialog !== undefined}
886
+ document={editor.document}
887
+ {...(filterDialog?.control
888
+ ? { control: filterDialog.control }
889
+ : {})}
890
+ available={available}
891
+ {...(catalog ? { fieldsFor } : {})}
892
+ onClose={() => setFilterDialog(undefined)}
893
+ onApply={applyFilter}
894
+ onRemove={dropControl}
895
+ />
896
+ <TileMenu
897
+ anchor={menu?.anchor ?? null}
898
+ tile={
899
+ menu === undefined
900
+ ? undefined
901
+ : editor.document.tiles[menu.index]
902
+ }
903
+ onClose={() => setMenu(undefined)}
904
+ onCommit={(next) => {
905
+ const at = menu?.index;
906
+ if (at === undefined) return;
907
+ editor.update((draft) => {
908
+ draft.tiles[at] = next;
909
+ });
910
+ }}
911
+ onRemove={() => {
912
+ if (menu !== undefined) removeTile(menu.index);
913
+ }}
914
+ {...(editor.document.tiles.length === 1 &&
915
+ editor.saved.tiles.length > 0
916
+ ? {
917
+ removeBlocked:
918
+ "A saved dashboard needs at least one tile.",
919
+ }
920
+ : {})}
921
+ columns={columns}
922
+ view={menuView}
923
+ onDrills={() => {
924
+ setDrillSource(menuTile?.source);
925
+ }}
926
+ />
927
+ <DrillDialog
928
+ open={drillSource !== undefined}
929
+ document={editor.document}
930
+ source={editor.document.sources.find(
931
+ (s) => s.name === drillSource,
932
+ )}
933
+ givenNames={controlList.map((c) => c.name)}
934
+ dashboards={dashboards ?? []}
935
+ onClose={() => setDrillSource(undefined)}
936
+ onApply={(drills) =>
937
+ editor.update((draft) => {
938
+ const kept = (draft.drills ?? []).filter(
939
+ (d) => d.source !== drillSource,
940
+ );
941
+ const next = [...kept, ...drills];
942
+ if (next.length === 0) delete draft.drills;
943
+ else draft.drills = next;
944
+ })
945
+ }
946
+ />
947
+ <SettingsPopover
948
+ anchor={settingsAnchor}
949
+ settings={settings}
950
+ catalog={catalog}
951
+ inUse={sourcesInUse}
952
+ onClose={() => setSettingsAnchor(null)}
953
+ onCommit={(next) =>
954
+ editor.update((draft) => {
955
+ if (next.kind === undefined) delete draft.kind;
956
+ else draft.kind = next.kind;
957
+ if (next.columns === undefined) delete draft.columns;
958
+ else draft.columns = next.columns;
959
+ if (next.autorun === undefined) delete draft.autorun;
960
+ else draft.autorun = next.autorun;
961
+ draft.imports = next.imports;
962
+ })
963
+ }
964
+ />
965
+ <AddTileDialog
966
+ open={addingTile}
967
+ document={editor.document}
968
+ catalog={catalog}
969
+ columns={columns}
970
+ onClose={() => setAddingTile(false)}
971
+ onAdd={addTile}
972
+ onAddText={addText}
973
+ />
974
+ <UnsavedChangesDialog {...session.exitGuard.dialog} />
975
+ </Stack>
681
976
  </Stack>
682
- </Stack>
977
+ </OpenDraftContext.Provider>
683
978
  );
684
979
  }