@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
@@ -0,0 +1,164 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { useEffect, useMemo, useRef } from "react";
5
+ import type { ReportLayout } from "../Package/documentLocation";
6
+
7
+ /**
8
+ * The builder's page-level controls, as state and actions rather than as a
9
+ * toolbar, so a host can put each one where its own chrome has room: in its
10
+ * header, in its "⋯" menu, or in the SDK's own {@link BuilderBar}. Everything
11
+ * that acts on a tile, a filter or the text stays on the page itself.
12
+ *
13
+ * The actions are stable across renders: a host may keep the object in state
14
+ * and call them later. A new object is handed over only when something a host
15
+ * would draw has changed.
16
+ */
17
+ export interface BuilderControls {
18
+ /** Whether the file holds every edit: for a status line. */
19
+ status: "saved" | "unsaved" | "saving";
20
+ /** Where Save writes, in words: "Saves to the package file". */
21
+ saveTarget: string;
22
+ /** Save the edits. Absent when the builder has nowhere to save. */
23
+ save?: () => void;
24
+ canUndo: boolean;
25
+ undo: () => void;
26
+ canRedo: boolean;
27
+ redo: () => void;
28
+ /** The layout and its switch. Absent when the layout cannot be changed here. */
29
+ layout?: {
30
+ value: ReportLayout;
31
+ set: (layout: ReportLayout) => void;
32
+ };
33
+ /** What can be added to the page. A missing entry is not offered. */
34
+ add: {
35
+ /** Open the picker of views for a query tile. */
36
+ tile?: () => void;
37
+ /** Append an empty text tile and select it. */
38
+ text?: () => void;
39
+ /** Open the window that declares a filter. */
40
+ filter?: () => void;
41
+ /** Why a filter cannot be added here, when it cannot; `filter` is then absent. */
42
+ filterUnavailable?: string;
43
+ };
44
+ /** Leave the builder: asks first when edits are unsaved. Absent unless the host passed `onExit`. */
45
+ exit?: () => void;
46
+ /**
47
+ * Write the edits, then leave — once the write has landed; a refused write
48
+ * keeps the builder open with its reason. The one way out a host needs when
49
+ * the builder keeps a draft. Absent unless the host passed `onExit`.
50
+ */
51
+ done?: () => void;
52
+ /** When unsaved edits were last kept in this browser (`draftKey`); absent when there are none to keep. */
53
+ draftKeptAt?: number;
54
+ /** Put the report back to the file's, as one undoable edit, and drop the draft. Absent with nothing to discard. */
55
+ discard?: () => void;
56
+ }
57
+
58
+ /** What a host passes to take over the builder's page-level controls. */
59
+ export type BuilderControlsHandler = (
60
+ controls: BuilderControls | undefined,
61
+ ) => void;
62
+
63
+ /**
64
+ * Hand the host the builder's controls whenever what they show changes, and
65
+ * `undefined` when the builder goes away. The actions forward to the latest
66
+ * render's, so their identity never changes and a host keeping the object in
67
+ * state cannot loop on it.
68
+ */
69
+ export function useReportControls(
70
+ onControls: BuilderControlsHandler | undefined,
71
+ controls: BuilderControls,
72
+ ): void {
73
+ const latest = useRef(controls);
74
+ latest.current = controls;
75
+ const handlerRef = useRef(onControls);
76
+ handlerRef.current = onControls;
77
+
78
+ // Stable forwarders, made once.
79
+ const actions = useMemo(
80
+ () => ({
81
+ save: () => latest.current.save?.(),
82
+ undo: () => latest.current.undo(),
83
+ redo: () => latest.current.redo(),
84
+ setLayout: (layout: ReportLayout) =>
85
+ latest.current.layout?.set(layout),
86
+ addTile: () => latest.current.add.tile?.(),
87
+ addText: () => latest.current.add.text?.(),
88
+ addFilter: () => latest.current.add.filter?.(),
89
+ exit: () => latest.current.exit?.(),
90
+ done: () => latest.current.done?.(),
91
+ discard: () => latest.current.discard?.(),
92
+ }),
93
+ [],
94
+ );
95
+
96
+ const {
97
+ status,
98
+ saveTarget,
99
+ canUndo,
100
+ canRedo,
101
+ add: { filterUnavailable },
102
+ } = controls;
103
+ const hasSave = controls.save !== undefined;
104
+ const layout = controls.layout?.value;
105
+ const hasTile = controls.add.tile !== undefined;
106
+ const hasText = controls.add.text !== undefined;
107
+ const hasFilter = controls.add.filter !== undefined;
108
+ const hasExit = controls.exit !== undefined;
109
+ const hasDone = controls.done !== undefined;
110
+ const hasDiscard = controls.discard !== undefined;
111
+ const { draftKeptAt } = controls;
112
+
113
+ const shown = useMemo<BuilderControls>(
114
+ () => ({
115
+ status,
116
+ saveTarget,
117
+ ...(hasSave ? { save: actions.save } : {}),
118
+ canUndo,
119
+ undo: actions.undo,
120
+ canRedo,
121
+ redo: actions.redo,
122
+ ...(layout !== undefined
123
+ ? { layout: { value: layout, set: actions.setLayout } }
124
+ : {}),
125
+ add: {
126
+ ...(hasTile ? { tile: actions.addTile } : {}),
127
+ ...(hasText ? { text: actions.addText } : {}),
128
+ ...(hasFilter ? { filter: actions.addFilter } : {}),
129
+ ...(filterUnavailable !== undefined ? { filterUnavailable } : {}),
130
+ },
131
+ ...(hasExit ? { exit: actions.exit } : {}),
132
+ ...(hasDone ? { done: actions.done } : {}),
133
+ ...(draftKeptAt !== undefined ? { draftKeptAt } : {}),
134
+ ...(hasDiscard ? { discard: actions.discard } : {}),
135
+ }),
136
+ [
137
+ actions,
138
+ status,
139
+ saveTarget,
140
+ hasSave,
141
+ canUndo,
142
+ canRedo,
143
+ layout,
144
+ hasTile,
145
+ hasText,
146
+ hasFilter,
147
+ filterUnavailable,
148
+ hasExit,
149
+ hasDone,
150
+ draftKeptAt,
151
+ hasDiscard,
152
+ ],
153
+ );
154
+
155
+ // Also when a handler arrives after the builder has mounted: it takes the
156
+ // inline toolbar away at once, so it has to be handed the controls at once
157
+ // too, not on the next change.
158
+ const hasHandler = onControls !== undefined;
159
+ useEffect(() => {
160
+ handlerRef.current?.(shown);
161
+ }, [shown, hasHandler]);
162
+ // Gone with the builder, so a host does not draw controls for nothing.
163
+ useEffect(() => () => handlerRef.current?.(undefined), []);
164
+ }
@@ -29,12 +29,11 @@ export const builderReport = ({
29
29
  const { emit } = reportEmitter({ path, layout }, onEvent);
30
30
  return {
31
31
  size,
32
- saved: ({ size, structural, durationMs, fromOpen }) =>
32
+ saved: ({ size, structural, durationMs }) =>
33
33
  emit({
34
34
  type: "report.saved",
35
35
  tiles: size,
36
36
  structural,
37
- ...(fromOpen ? { converted: true } : {}),
38
37
  where: savesTo,
39
38
  durationMs,
40
39
  }),
@@ -5,6 +5,9 @@ import { parseTag } from "@malloydata/malloy-tag";
5
5
  import type { CompiledModel } from "../../client";
6
6
  import { exportedSources } from "../DocumentCreate/exportedSources";
7
7
  import { CHART_TAGS } from "./chartLine";
8
+ import { chartOf, docOf } from "./viewAnnotations";
9
+
10
+ export { chartOf, docOf };
8
11
 
9
12
  export { CHART_TAGS };
10
13
 
@@ -63,25 +66,6 @@ export interface PackageCatalog {
63
66
  sources: CatalogSource[];
64
67
  }
65
68
 
66
- /** `#(doc) Revenue by product category\n` -> `Revenue by product category`. */
67
- export function docOf(annotations: string[] | undefined): string | undefined {
68
- for (const raw of annotations ?? []) {
69
- const m = /^#\(doc\)\s*(.*)$/s.exec(raw.trim());
70
- if (m) return m[1].trim();
71
- }
72
- return undefined;
73
- }
74
-
75
- /** `# bar_chart\n` -> `bar_chart`. Only the renderer's own chart tags count. */
76
- export function chartOf(annotations: string[] | undefined): string | undefined {
77
- for (const raw of annotations ?? []) {
78
- // A `-name` removes a tag, so it is never the chart the view declares.
79
- const name = /^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(raw.trim())?.[1];
80
- if (name && CHART_TAGS.includes(name)) return name;
81
- }
82
- return undefined;
83
- }
84
-
85
69
  /**
86
70
  * How far into a source's joins the field list reaches. One level:
87
71
  * `products.category` is a field people filter on; `products.supplier.region`
@@ -207,16 +191,16 @@ export const isReportModel = (
207
191
  ) => path !== undefined && reportPaths.has(path);
208
192
 
209
193
  /**
210
- * The model's own path.
194
+ * The model's own path: `path`, the field the API declares.
211
195
  *
212
- * Two spellings, and the generated client only knows one: the models LIST
213
- * returns `path`, while a single model returns `modelPath`. Reading `path`
214
- * alone yields an empty string against the real server, which silently disables
215
- * the report exclusion below and leaves a preview with nothing to run
216
- * against.
196
+ * A server before this release names a single model's path only as
197
+ * `modelPath`, which the spec never declared, so it is still read when `path`
198
+ * is missing. An empty path silently disables the report exclusion below and
199
+ * leaves a preview with nothing to run against, so `useEditorCatalog` sets
200
+ * `path` itself, from the path it asked for.
217
201
  */
218
202
  const pathOf = (model: CompiledModel): string =>
219
- (model as { modelPath?: string }).modelPath ?? model.path ?? "";
203
+ model.path || (model as { modelPath?: string }).modelPath || "";
220
204
 
221
205
  export function buildCatalog(
222
206
  models: CompiledModel[],
@@ -6,73 +6,41 @@ import type { SystemStyleObject } from "@mui/system";
6
6
  import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
7
7
  import type { ResolvedTheme } from "../../theme/types";
8
8
 
9
- /** A thin pencil, drawn as a mask so it takes the text's own colour. */
10
- const PENCIL = `url("data:image/svg+xml;utf8,${encodeURIComponent(
11
- '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',
12
- )}")`;
13
-
14
- /** Where the pencil goes: after a line of text, or after the first block of prose. */
9
+ /** What kind of text is edited: a line (a title, a subtitle) or a block of prose. */
15
10
  export type PencilAt = "line" | "prose";
16
11
 
17
12
  /**
18
- * How text that is edited where it is read says so: a thin pencil straight
19
- * after the text, in the text's own colour and in proportion to its size,
20
- * faint at rest and clearer under the pointer. The same mark in the same place
21
- * for every field — a title, a subtitle, a description — and nothing else: no
22
- * wash, no outline, no gutter. The keyboard gets a focus ring, since a pencil
23
- * does not say where focus is.
13
+ * How text that is edited where it is read says so: a faint wash behind it
14
+ * under the pointer, in the page's hover colour, and nothing at rest, so the
15
+ * page reads as the report until the pointer reaches something editable. The
16
+ * wash is padded out into the text's own margin (an equal negative margin
17
+ * takes the padding back), so it never moves the text or its neighbours. The
18
+ * keyboard gets a focus ring, since a wash does not say where focus is.
24
19
  *
25
- * Drawn as a pseudo-element, so it adds no node and moves no layout; for prose
26
- * it follows the first paragraph or heading, which is the line the reader is
27
- * looking at when they reach for it.
20
+ * A line gets a tight wash; a block of prose a roomier one, the size of the
21
+ * paragraph it covers.
28
22
  */
29
23
  export const editableSx = (
30
24
  theme: ResolvedTheme,
31
25
  at: PencilAt = "line",
32
26
  ): SystemStyleObject<Theme> => {
33
- // The pseudo-element's selector, at rest and while the field is hovered
34
- // or focused: on the field itself for a line; for prose, on its first
35
- // paragraph or heading, or on the lone span markdown renders a single line
36
- // of prose as, with no paragraph around it.
37
- const blocks = [
38
- ":is(p, h1, h2, h3, h4, h5, h6):first-child::after",
39
- "> * > span:only-child::after",
40
- ];
41
- const within = (prefix: string) =>
42
- blocks.map((block) => `${prefix} ${block}`).join(", ");
43
- const host = at === "line" ? "&::after" : within("&");
44
- const lit =
45
- at === "line"
46
- ? "&:hover::after, &:focus-visible::after"
47
- : `${within("&:hover")}, ${within("&:focus-visible")}`;
27
+ const [x, y] = at === "line" ? ["6px", "2px"] : ["10px", "6px"];
48
28
  return {
49
29
  cursor: "text",
50
- borderRadius: "2px",
51
- [host]: {
52
- content: '""',
53
- display: "inline-block",
54
- width: "0.8em",
55
- height: "0.8em",
56
- ml: "0.4em",
57
- verticalAlign: "-0.05em",
58
- backgroundColor: "currentColor",
59
- maskImage: PENCIL,
60
- WebkitMaskImage: PENCIL,
61
- maskSize: "contain",
62
- WebkitMaskSize: "contain",
63
- maskRepeat: "no-repeat",
64
- WebkitMaskRepeat: "no-repeat",
65
- opacity: 0.35,
66
- transition: `opacity ${MOTION_FAST}`,
67
- ...reducedMotionSx,
68
- pointerEvents: "none",
69
- },
70
- [lit]: {
71
- opacity: 0.8,
72
- },
30
+ borderRadius: at === "line" ? "4px" : "6px",
31
+ mx: `-${x}`,
32
+ px: x,
33
+ my: `-${y}`,
34
+ py: y,
35
+ transition: `background-color ${MOTION_FAST}`,
36
+ ...reducedMotionSx,
37
+ "&:hover": { bgcolor: "action.hover" },
73
38
  "&:focus-visible": {
74
39
  outline: `2px solid ${theme.accent}`,
75
- outlineOffset: 2,
40
+ // Inside the element: the wash already reaches past the text by
41
+ // negative margins, and a ring outside that was cut off by a card
42
+ // or frame that clips (a borderless tile's title, the description).
43
+ outlineOffset: -2,
76
44
  },
77
45
  };
78
46
  };
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { Given } from "../../client";
5
+ import type { LocalGiven } from "./document";
6
+
7
+ /**
8
+ * A `given:` a report declares itself, as the `Given` spec its filter control
9
+ * is drawn from: the spec the server would publish for the same declaration
10
+ * once the report is served.
11
+ *
12
+ * Exported for a host that holds a report as text and draws its controls
13
+ * itself, so a filter it declares looks and behaves as it will once the
14
+ * report is published.
15
+ */
16
+ export function localGivenSpec(local: LocalGiven): Given {
17
+ const shown = displayDefault(local);
18
+ return {
19
+ name: local.name,
20
+ type: local.type,
21
+ ...(shown === undefined ? {} : { default: shown }),
22
+ ...(local.label === undefined ? {} : { label: local.label }),
23
+ ...(local.description === undefined
24
+ ? {}
25
+ : { description: local.description }),
26
+ ...(local.control === undefined
27
+ ? {}
28
+ : { control: local.control as Given["control"] }),
29
+ ...(local.suggest
30
+ ? {
31
+ suggest: {
32
+ ...(local.suggest.source === undefined
33
+ ? {}
34
+ : { source: local.suggest.source }),
35
+ ...(local.suggest.query === undefined
36
+ ? {}
37
+ : { query: local.suggest.query }),
38
+ dimension: local.suggest.dimension,
39
+ },
40
+ }
41
+ : {}),
42
+ ...(local.rangeMin === undefined ? {} : { rangeMin: local.rangeMin }),
43
+ ...(local.rangeMax === undefined ? {} : { rangeMax: local.rangeMax }),
44
+ };
45
+ }
46
+
47
+ /**
48
+ * The default the server would publish: it unwraps a filter's `f'…'`, so an
49
+ * empty one is `""` (filters nothing, shows no caption). Never undefined for a
50
+ * declaration with a default: an absent `default` means the given is required.
51
+ */
52
+ function displayDefault(local: LocalGiven): string | undefined {
53
+ if (!local.type?.startsWith("filter<")) return local.default;
54
+ const body = local.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];
55
+ return body ?? local.default;
56
+ }
@@ -5,7 +5,12 @@ import { describe, expect, it } from "bun:test";
5
5
  import type { GivenValue } from "../../hooks/givenValue";
6
6
  import type { DashboardDocument, QueryTile } from "./document";
7
7
  import { queryTile } from "./testing/fixtures";
8
- import { previewGivens, previewTileQuery, tileExpressionKey } from "./preview";
8
+ import {
9
+ givensReadThroughModel,
10
+ previewGivens,
11
+ previewTileQuery,
12
+ tileExpressionKey,
13
+ } from "./preview";
9
14
 
10
15
  const tile = (
11
16
  name: string,
@@ -65,7 +70,7 @@ describe("previewGivens", () => {
65
70
  });
66
71
  });
67
72
 
68
- it("shows a filter default as the server publishes it: unwrapped, and none when empty", () => {
73
+ it("shows a filter default as the server publishes it: unwrapped, and empty when empty", () => {
69
74
  const filtered: DashboardDocument = {
70
75
  ...document,
71
76
  localGivens: [
@@ -80,7 +85,9 @@ describe("previewGivens", () => {
80
85
  ],
81
86
  };
82
87
  const [empty, state] = previewGivens(filtered, []);
83
- expect(empty.default).toBeUndefined();
88
+ // As the server publishes it: "", which filters nothing (absent would
89
+ // read as no default declared).
90
+ expect(empty.default).toBe("");
84
91
  expect(state.default).toBe("WN");
85
92
  // The document keeps the literal the file is written from.
86
93
  expect(filtered.localGivens?.[1].default).toBe("f'WN'");
@@ -105,6 +112,114 @@ describe("previewGivens", () => {
105
112
  });
106
113
  });
107
114
 
115
+ describe("givens read through the model", () => {
116
+ // The auto_recalls shape: the report binds nothing; the model's source
117
+ // filters itself by four givens in its own `where:`.
118
+ const recalls: DashboardDocument = {
119
+ layout: "grid",
120
+ title: "Recalls",
121
+ imports: [{ kind: "all", from: "auto_recalls.malloy" }],
122
+ sources: [{ name: "recalls_tiles", base: "recalls" }],
123
+ tiles: [
124
+ { ...tile("by_year", "by_year"), source: "recalls_tiles" },
125
+ { ...tile("by_maker", "by_maker"), source: "recalls_tiles" },
126
+ ],
127
+ };
128
+ const MODEL = [
129
+ { name: "manufacturer_filter", type: "filter<string>" },
130
+ { name: "subject_filter", type: "filter<string>" },
131
+ { name: "major_recall_filter", type: "boolean" },
132
+ { name: "recall_date_filter", type: "filter<date>" },
133
+ ];
134
+ const served = new Map([
135
+ [
136
+ "recalls_tiles -> by_year",
137
+ ["manufacturer_filter", "recall_date_filter", "major_recall_filter"],
138
+ ],
139
+ ["recalls_tiles -> by_maker", ["manufacturer_filter", "subject_filter"]],
140
+ ]);
141
+
142
+ it("shows a given only the model reads, in the manifest's order", () => {
143
+ const reads = givensReadThroughModel(recalls, recalls, served);
144
+ expect(
145
+ previewGivens(recalls, MODEL, reads).map((spec) => spec.name),
146
+ ).toEqual(MODEL.map((spec) => spec.name));
147
+ // Without the reads, the row the builder drew before: empty.
148
+ expect(previewGivens(recalls, MODEL)).toEqual([]);
149
+ });
150
+
151
+ it("leaves out what this file bound, so a removed binding takes its control", () => {
152
+ const bound: DashboardDocument = {
153
+ ...recalls,
154
+ tiles: [
155
+ {
156
+ ...tile("by_year", "by_year", [
157
+ { field: "category", given: "CATEGORY" },
158
+ ]),
159
+ source: "recalls_tiles",
160
+ },
161
+ ],
162
+ };
163
+ const reads = givensReadThroughModel(
164
+ bound,
165
+ bound,
166
+ new Map([
167
+ ["recalls_tiles -> by_year", ["CATEGORY", "manufacturer_filter"]],
168
+ ]),
169
+ );
170
+ expect([...reads]).toEqual(["manufacturer_filter"]);
171
+ });
172
+
173
+ it("puts this file's bound declarations first, then the model's", () => {
174
+ const mixed: DashboardDocument = {
175
+ ...recalls,
176
+ localGivens: [{ name: "SINCE", type: "date", default: "@2020-01-01" }],
177
+ tiles: [
178
+ {
179
+ ...tile("by_year", "by_year", [
180
+ { field: "recall_date", given: "SINCE", op: ">=" },
181
+ ]),
182
+ source: "recalls_tiles",
183
+ },
184
+ ],
185
+ };
186
+ const reads = givensReadThroughModel(mixed, mixed, served);
187
+ expect(
188
+ previewGivens(mixed, MODEL, reads).map((spec) => spec.name),
189
+ ).toEqual([
190
+ "SINCE",
191
+ "manufacturer_filter",
192
+ "major_recall_filter",
193
+ "recall_date_filter",
194
+ ]);
195
+ });
196
+
197
+ it("reads a new tile by a served tile of the same expression, and nothing otherwise", () => {
198
+ const added: DashboardDocument = {
199
+ ...recalls,
200
+ tiles: [
201
+ ...recalls.tiles,
202
+ { ...tile("by_maker", "by_maker"), source: "recalls_tiles" },
203
+ { ...tile("fresh", "fresh"), source: "recalls_tiles" },
204
+ ],
205
+ };
206
+ expect(
207
+ [
208
+ ...givensReadThroughModel(added, { ...recalls, tiles: [] }, served),
209
+ ].sort(),
210
+ ).toEqual(
211
+ [
212
+ "major_recall_filter",
213
+ "manufacturer_filter",
214
+ "recall_date_filter",
215
+ "subject_filter",
216
+ ].sort(),
217
+ );
218
+ const onlyNew = { ...recalls, tiles: [added.tiles[3]!] };
219
+ expect(givensReadThroughModel(onlyNew, recalls, served).size).toBe(0);
220
+ });
221
+ });
222
+
108
223
  describe("previewTileQuery", () => {
109
224
  const runnable = new Set(["CATEGORY", "SINCE"]);
110
225
 
@@ -201,9 +316,14 @@ describe("previewTileQuery", () => {
201
316
  expect(q.givenNames).toEqual(["CATEGORY"]);
202
317
  });
203
318
 
204
- it("leaves out an unsent given with no value yet, and one nobody declares", () => {
319
+ it("applies an unsent given's declared default until a value is set, and skips one nobody declares", () => {
320
+ // No value set: SINCE's default applies, as the server applies a
321
+ // given's default once the report is saved; CATEGORY's default is an
322
+ // empty filter, which filters nothing, so it adds no clause.
205
323
  const q = previewTileQuery(document, queryTile(document, 0), new Set());
206
- expect(q.expression).toBe("overview -> key_figures");
324
+ expect(q.expression).toBe(
325
+ "overview -> key_figures + { where: created_at >= @2023-01-01 }",
326
+ );
207
327
  expect(q.givenNames).toEqual([]);
208
328
  const stray: QueryTile = tile("t", "v", [
209
329
  { field: "x", given: "NOBODY" },