@malloy-publisher/sdk 0.3.0 → 0.4.0

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 (244) hide show
  1. package/README.md +22 -9
  2. package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
  5. package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
  6. package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9482 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +100 -42
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/AppDialog.d.ts +30 -0
  16. package/dist/components/BackLink.d.ts +32 -0
  17. package/dist/components/Dashboard/Dashboard.d.ts +19 -14
  18. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  19. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  20. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  21. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  22. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  23. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  24. package/dist/components/Dashboard/index.d.ts +2 -0
  25. package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
  26. package/dist/components/Dashboard/telemetry.d.ts +48 -0
  27. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  28. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
  29. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
  30. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
  31. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  32. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  33. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  34. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  36. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  37. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  38. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  39. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  40. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  41. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  42. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  43. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  44. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  45. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  46. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  47. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  48. package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
  49. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  50. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  51. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  52. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  53. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  54. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  55. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  56. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
  57. package/dist/components/DocumentStorage/index.d.ts +1 -1
  58. package/dist/components/FloatingIconButton.d.ts +16 -0
  59. package/dist/components/ItemRow.d.ts +38 -0
  60. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  61. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  62. package/dist/components/Materializations/Materializations.d.ts +7 -3
  63. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  64. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  65. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  66. package/dist/components/Materializations/index.d.ts +0 -1
  67. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  68. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  69. package/dist/components/Package/index.d.ts +0 -1
  70. package/dist/components/PackageSection.d.ts +23 -0
  71. package/dist/components/Prose.d.ts +46 -0
  72. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  73. package/dist/components/RenderedResult/index.d.ts +1 -0
  74. package/dist/components/buttons.d.ts +53 -0
  75. package/dist/components/drill/index.d.ts +1 -1
  76. package/dist/components/drill/resolveDrill.d.ts +22 -0
  77. package/dist/components/drill/useDrill.d.ts +11 -2
  78. package/dist/components/index.d.ts +6 -0
  79. package/dist/components/styles.d.ts +49 -44
  80. package/dist/hooks/index.d.ts +2 -0
  81. package/dist/hooks/useCrudMutation.d.ts +42 -0
  82. package/dist/hooks/useDocumentControls.d.ts +70 -0
  83. package/dist/hooks/useQueryResult.d.ts +40 -0
  84. package/dist/index.cjs.js +22 -273
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.es.js +16888 -44451
  87. package/dist/telemetry/consoleEvents.d.ts +60 -0
  88. package/dist/utils/malloyLiteral.d.ts +11 -0
  89. package/dist/utils/sha256.d.ts +2 -0
  90. package/package.json +24 -9
  91. package/src/builder-entry.ts +55 -0
  92. package/src/components/AppDialog.tsx +115 -0
  93. package/src/components/BackLink.tsx +83 -0
  94. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  95. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  96. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  97. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  98. package/src/components/Dashboard/Dashboard.tsx +165 -175
  99. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  100. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  101. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  102. package/src/components/Dashboard/DashboardTile.tsx +66 -123
  103. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  104. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  105. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  106. package/src/components/Dashboard/TileCard.tsx +120 -0
  107. package/src/components/Dashboard/index.ts +2 -0
  108. package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
  109. package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
  110. package/src/components/Dashboard/telemetry.ts +51 -0
  111. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  112. package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
  113. package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
  114. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
  115. package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
  116. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  117. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
  118. package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
  119. package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
  120. package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
  121. package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
  122. package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
  123. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  124. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  125. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  126. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  127. package/src/components/DashboardBuilder/catalog.ts +225 -0
  128. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  129. package/src/components/DashboardBuilder/controls.ts +398 -0
  130. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  131. package/src/components/DashboardBuilder/diff.ts +93 -0
  132. package/src/components/DashboardBuilder/document.ts +209 -0
  133. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  134. package/src/components/DashboardBuilder/layout.ts +143 -0
  135. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  136. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  137. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  138. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  139. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  140. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  141. package/src/components/DashboardBuilder/preview.ts +172 -0
  142. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  143. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  144. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  145. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
  146. package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
  147. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  148. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  149. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
  150. package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
  151. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  152. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  153. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  154. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  155. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  156. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  157. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  158. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  159. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
  160. package/src/components/DocumentStorage/index.ts +1 -0
  161. package/src/components/Environment/About.tsx +16 -62
  162. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  163. package/src/components/Environment/Connections.tsx +125 -205
  164. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  165. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  166. package/src/components/Environment/Environment.tsx +34 -36
  167. package/src/components/Environment/Packages.tsx +63 -128
  168. package/src/components/FloatingIconButton.tsx +41 -0
  169. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  170. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  171. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  172. package/src/components/Home/Home.tsx +101 -214
  173. package/src/components/ItemRow.tsx +165 -0
  174. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  175. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  176. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  177. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  178. package/src/components/Materializations/Materializations.tsx +137 -140
  179. package/src/components/Materializations/ScopeButton.tsx +85 -0
  180. package/src/components/Materializations/SectionLabel.tsx +7 -4
  181. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  182. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  183. package/src/components/Materializations/cron.spec.ts +113 -0
  184. package/src/components/Materializations/index.ts +0 -1
  185. package/src/components/Materializations/utils.spec.ts +182 -0
  186. package/src/components/Model/Model.tsx +6 -23
  187. package/src/components/Model/ModelCell.tsx +33 -72
  188. package/src/components/Notebook/Notebook.tsx +25 -88
  189. package/src/components/Notebook/NotebookCell.tsx +35 -183
  190. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  191. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  192. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  193. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  194. package/src/components/Package/Package.tsx +179 -238
  195. package/src/components/Package/index.ts +0 -1
  196. package/src/components/PackageSection.tsx +85 -0
  197. package/src/components/Prose.spec.tsx +85 -0
  198. package/src/components/Prose.tsx +179 -0
  199. package/src/components/QueryResult/QueryResult.tsx +15 -43
  200. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  201. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  202. package/src/components/RenderedResult/ResultContainer.tsx +4 -12
  203. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  204. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  205. package/src/components/RenderedResult/index.ts +1 -0
  206. package/src/components/ResultsDialog.tsx +8 -32
  207. package/src/components/buttons.tsx +114 -0
  208. package/src/components/designSystem.spec.tsx +316 -0
  209. package/src/components/drill/index.ts +1 -0
  210. package/src/components/drill/resolveDrill.ts +22 -1
  211. package/src/components/drill/useDrill.spec.tsx +94 -0
  212. package/src/components/drill/useDrill.tsx +52 -12
  213. package/src/components/given/GivensPanel.tsx +1 -1
  214. package/src/components/given/paramCodec.spec.ts +1 -1
  215. package/src/components/index.ts +16 -0
  216. package/src/components/styles.ts +49 -122
  217. package/src/hooks/index.ts +13 -0
  218. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  219. package/src/hooks/useCrudMutation.tsx +85 -0
  220. package/src/hooks/useDocumentControls.ts +170 -0
  221. package/src/hooks/useQueryResult.ts +82 -0
  222. package/src/index.ts +9 -0
  223. package/src/telemetry/consoleEvents.spec.ts +130 -0
  224. package/src/telemetry/consoleEvents.ts +124 -0
  225. package/src/theme/defaults.ts +34 -23
  226. package/src/theme/resolveTheme.spec.ts +9 -4
  227. package/src/theme/resolveTheme.ts +12 -8
  228. package/src/utils/malloyLiteral.spec.ts +43 -0
  229. package/src/utils/malloyLiteral.ts +76 -0
  230. package/src/utils/sha256.ts +13 -0
  231. package/test/README.md +1 -1
  232. package/test/serverProvider.tsx +5 -2
  233. package/vite.config.ts +5 -0
  234. package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
  235. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  236. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  237. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  238. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  239. package/dist/components/Package/Models.d.ts +0 -6
  240. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  241. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  242. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  243. package/src/components/Materializations/TriggerChip.tsx +0 -44
  244. package/src/components/Package/Models.tsx +0 -71
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { fireEvent, render, screen } from "@testing-library/react";
5
+ import { describe, expect, it, mock } from "bun:test";
6
+ import { Prose } from "./Prose";
7
+
8
+ // Package content comes from untrusted git and S3 sources, so the one thing
9
+ // every surface that renders it has to agree on is what a link may do. These
10
+ // are that agreement, tested once against the one component that now renders
11
+ // prose everywhere; the notebook cell used to be the only surface that held
12
+ // to it.
13
+
14
+ describe("Prose: links", () => {
15
+ it("refuses a script-bearing href, keeping the text", () => {
16
+ render(
17
+ <Prose>
18
+ {"[run](javascript:alert(1)) and [d](data:text/html,x)"}
19
+ </Prose>,
20
+ );
21
+ expect(screen.getByText("run").getAttribute("href")).toBeNull();
22
+ expect(screen.getByText("d").getAttribute("href")).toBeNull();
23
+ });
24
+
25
+ it("opens an external link in a new tab, disowning the opener", () => {
26
+ render(<Prose>{"[docs](https://example.com/docs)"}</Prose>);
27
+ const a = screen.getByText("docs");
28
+ expect(a.getAttribute("href")).toBe("https://example.com/docs");
29
+ expect(a.getAttribute("target")).toBe("_blank");
30
+ expect(a.getAttribute("rel")).toBe("noopener noreferrer");
31
+ });
32
+
33
+ it("resolves a relative link against the source file, within the package", () => {
34
+ render(
35
+ <Prose
36
+ links={{
37
+ environmentName: "env",
38
+ packageName: "pkg",
39
+ sourcePath: "guides/intro.malloynb",
40
+ }}
41
+ >
42
+ {"[next](../sales.malloynb) [up](../../../etc/passwd)"}
43
+ </Prose>,
44
+ );
45
+ expect(screen.getByText("next").getAttribute("href")).toBe(
46
+ "/env/pkg/sales.malloynb",
47
+ );
48
+ // An escape past the package root is clamped at it, never above.
49
+ expect(screen.getByText("up").getAttribute("href")).toBe(
50
+ "/env/pkg/etc/passwd",
51
+ );
52
+ });
53
+
54
+ it("routes a resolved link through the host when it can", () => {
55
+ const onNavigate = mock((_to: string) => undefined);
56
+ render(
57
+ <Prose
58
+ links={{ environmentName: "env", packageName: "pkg", onNavigate }}
59
+ >
60
+ {"[readme](README.md)"}
61
+ </Prose>,
62
+ );
63
+ fireEvent.click(screen.getByText("readme"));
64
+ expect(onNavigate).toHaveBeenCalledTimes(1);
65
+ expect(onNavigate.mock.calls[0][0]).toBe("/env/pkg/README.md");
66
+ });
67
+
68
+ it("leaves a relative link alone when it has no package to resolve against", () => {
69
+ render(<Prose>{"[here](./notes.md)"}</Prose>);
70
+ expect(screen.getByText("here").getAttribute("href")).toBe("./notes.md");
71
+ });
72
+ });
73
+
74
+ describe("Prose: variants", () => {
75
+ it("renders headings as headings in both, so structure survives", () => {
76
+ render(<Prose variant="document">{"# Title\n\nBody"}</Prose>);
77
+ expect(screen.getByRole("heading", { level: 1 }).textContent).toBe(
78
+ "Title",
79
+ );
80
+ render(<Prose variant="caption">{"## Section\n\nBody"}</Prose>);
81
+ expect(screen.getByRole("heading", { level: 2 }).textContent).toBe(
82
+ "Section",
83
+ );
84
+ });
85
+ });
@@ -0,0 +1,179 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box, type SxProps, type Theme } from "@mui/material";
5
+ import Markdown from "markdown-to-jsx";
6
+ import type { ReactNode } from "react";
7
+ import type { NavigationClick } from "./click_helper";
8
+
9
+ /**
10
+ * Markdown authored inside a package — a dashboard's `##"` description, a
11
+ * notebook's markdown cell, a README — rendered one way.
12
+ *
13
+ * Three surfaces each rendered it with their own style sheet, and only one of
14
+ * them guarded the links. Package content comes from untrusted git and S3
15
+ * sources, so a crafted `javascript:` or `data:` href in a README or a
16
+ * description must never run; the notebook cell knew this and the other two did
17
+ * not. Every link here goes through {@link ProseLink}.
18
+ *
19
+ * Two variants, because the prose plays two roles:
20
+ *
21
+ * - `document`: the prose IS the content — a notebook's markdown cells, read
22
+ * top to bottom. Full-size headings, reading-length lines.
23
+ * - `caption`: the prose sits under a title it must not compete with — a
24
+ * dashboard's description, a package's README card. Body size; headings are
25
+ * section labels within the block, at body size and bold.
26
+ */
27
+ export type ProseVariant = "document" | "caption";
28
+
29
+ /**
30
+ * How a relative link is resolved. Links in package content are authored
31
+ * relative to the SOURCE FILE (`spielberg.malloynb`), and a plain anchor
32
+ * resolves them against the page URL instead, which drops the package segment
33
+ * for a README shown at the package route. With this, a relative link resolves
34
+ * against the file's own directory and routes through the host.
35
+ */
36
+ export interface ProseLinkContext {
37
+ environmentName: string;
38
+ packageName: string;
39
+ /** The file the prose came from, within the package; its directory is the base. */
40
+ sourcePath?: string;
41
+ /**
42
+ * SPA navigation for a resolved link. Omitted, the absolute href navigates on
43
+ * its own, so rendering prose needs no router context.
44
+ */
45
+ onNavigate?: (to: string, event?: NavigationClick) => void;
46
+ }
47
+
48
+ export interface ProseProps {
49
+ children: string;
50
+ variant?: ProseVariant;
51
+ links?: ProseLinkContext;
52
+ sx?: SxProps<Theme>;
53
+ }
54
+
55
+ const SAFE_SCHEME = /^(https?|mailto|tel):/i;
56
+ const HAS_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
57
+
58
+ function ProseLink({
59
+ href,
60
+ title,
61
+ children,
62
+ context,
63
+ }: {
64
+ href?: string;
65
+ title?: string;
66
+ children?: ReactNode;
67
+ context: ProseLinkContext | undefined;
68
+ }) {
69
+ const hasScheme = !!href && HAS_SCHEME.test(href);
70
+ const isRelative =
71
+ !!href && !hasScheme && !href.startsWith("/") && !href.startsWith("#");
72
+
73
+ if (!href || !isRelative || !context) {
74
+ // External, absolute, or hash: a normal anchor — but only over a safe
75
+ // scheme, so a crafted href cannot run script.
76
+ const unsafe = hasScheme && !SAFE_SCHEME.test(href ?? "");
77
+ return (
78
+ <a
79
+ href={unsafe ? undefined : href}
80
+ title={title}
81
+ {...(hasScheme
82
+ ? { target: "_blank", rel: "noopener noreferrer" }
83
+ : {})}
84
+ >
85
+ {children}
86
+ </a>
87
+ );
88
+ }
89
+
90
+ // Resolve against the source file's directory (empty for a package-root
91
+ // README) via a dummy origin, which normalises `./` and `../` and clamps
92
+ // escapes at the package root, then prefix the package path.
93
+ const sourceDir =
94
+ context.sourcePath && context.sourcePath.includes("/")
95
+ ? context.sourcePath.slice(0, context.sourcePath.lastIndexOf("/") + 1)
96
+ : "";
97
+ const resolved = new URL(href, `https://malloy.invalid/${sourceDir}`);
98
+ const packageRelative =
99
+ resolved.pathname.slice(1) + resolved.search + resolved.hash;
100
+ const to = `/${context.environmentName}/${context.packageName}/${packageRelative}`;
101
+ const { onNavigate } = context;
102
+ return (
103
+ <a
104
+ href={to}
105
+ title={title}
106
+ onClick={
107
+ onNavigate
108
+ ? (event) => {
109
+ event.preventDefault();
110
+ onNavigate(to, event);
111
+ }
112
+ : undefined
113
+ }
114
+ >
115
+ {children}
116
+ </a>
117
+ );
118
+ }
119
+
120
+ const STYLES: Record<ProseVariant, SxProps<Theme>> = {
121
+ document: {
122
+ "& h1, & h2, & h3, & h4, & h5, & h6": {
123
+ fontWeight: 600,
124
+ color: "text.primary",
125
+ mb: 1,
126
+ mt: 2,
127
+ },
128
+ "& h1": { fontSize: "28px" },
129
+ "& h2": { fontSize: "24px" },
130
+ "& h3": { fontSize: "20px" },
131
+ "& p, & ul, & ol": {
132
+ color: "text.primary",
133
+ lineHeight: 1.7,
134
+ mb: 1,
135
+ fontSize: "16px",
136
+ },
137
+ "& li": { mb: 0.5 },
138
+ },
139
+ caption: {
140
+ color: "text.secondary",
141
+ typography: "body2",
142
+ // The block starts flush under whatever titles it and ends flush against
143
+ // what follows, so a one-line caption sits where a plain line would and a
144
+ // longer one grows downward rather than pushing its title around.
145
+ "& > :first-of-type": { mt: 0 },
146
+ "& > :last-child": { mb: 0 },
147
+ // Headings in a caption are section labels within the block, not
148
+ // competitors to the title above it, so they stay at body size.
149
+ "& h1, & h2, & h3, & h4, & h5, & h6": {
150
+ fontSize: "inherit",
151
+ fontWeight: 600,
152
+ m: "0.5em 0 0.25em",
153
+ },
154
+ "& p": { m: "0.5em 0" },
155
+ "& ul, & ol": { m: "0.5em 0", pl: 3 },
156
+ "& code": { fontFamily: "monospace", fontSize: "0.9em" },
157
+ },
158
+ };
159
+
160
+ export function Prose({
161
+ children,
162
+ variant = "caption",
163
+ links,
164
+ sx,
165
+ }: ProseProps) {
166
+ return (
167
+ <Box sx={[STYLES[variant], ...(Array.isArray(sx) ? sx : [sx])]}>
168
+ <Markdown
169
+ options={{
170
+ overrides: {
171
+ a: { component: ProseLink, props: { context: links } },
172
+ },
173
+ }}
174
+ >
175
+ {children}
176
+ </Markdown>
177
+ </Box>
178
+ );
179
+ }
@@ -1,14 +1,9 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { Suspense } from "react";
5
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
4
+ import { useQueryResult } from "../../hooks/useQueryResult";
6
5
  import { parseResourceUri } from "../../utils/formatting";
7
- import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
8
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
9
- import { Loading } from "../Loading";
10
- import ResultContainer from "../RenderedResult/ResultContainer";
11
- import { useServer } from "../ServerProvider";
6
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
12
7
 
13
8
  interface QueryResultProps {
14
9
  query?: string;
@@ -72,7 +67,6 @@ export default function QueryResult({
72
67
  }: QueryResultProps) {
73
68
  const { modelPath, environmentName, packageName, versionId } =
74
69
  parseResourceUri(resourceUri);
75
- const { apiClients } = useServer();
76
70
 
77
71
  if (!environmentName || !packageName) {
78
72
  throw new Error(
@@ -80,43 +74,21 @@ export default function QueryResult({
80
74
  );
81
75
  }
82
76
 
83
- const { data, isSuccess, isError, error } = useQueryWithApiError({
84
- queryKey: [resourceUri, query, sourceName, queryName],
85
- queryFn: () =>
86
- apiClients.models.executeQueryModel(
87
- environmentName,
88
- packageName,
89
- modelPath,
90
- {
91
- query: query,
92
- sourceName: sourceName,
93
- queryName: queryName,
94
- versionId: versionId,
95
- },
96
- ),
97
- ...CHART_RESULT_QUERY_OPTIONS,
77
+ const state = useQueryResult({
78
+ environmentName,
79
+ packageName,
80
+ modelPath,
81
+ versionId,
82
+ query,
83
+ sourceName,
84
+ queryName,
98
85
  });
99
86
 
100
87
  return (
101
- <>
102
- {!isSuccess && !isError && (
103
- <Loading text="Fetching Query Results..." />
104
- )}
105
- {isSuccess && (
106
- <Suspense fallback={<div>Loading...</div>}>
107
- <ResultContainer
108
- result={data.data.result}
109
- maxHeight={height}
110
- renderLogs={data.data.renderLogs}
111
- />
112
- </Suspense>
113
- )}
114
- {isError && (
115
- <ApiErrorDisplay
116
- context={`${environmentName} > ${packageName} > ${modelPath}`}
117
- error={error}
118
- />
119
- )}
120
- </>
88
+ <ResultPanel
89
+ state={state}
90
+ context={`${environmentName} > ${packageName} > ${modelPath}`}
91
+ maxHeight={height}
92
+ />
121
93
  );
122
94
  }
@@ -0,0 +1,198 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { act, render, waitFor } from "@testing-library/react";
5
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
6
+
7
+ /**
8
+ * The renderer's STAGE LIFECYCLE, which is the part of this component that has
9
+ * actually broken.
10
+ *
11
+ * `RenderedResult` never paints into its container directly. Each render builds
12
+ * a fresh "stage" div, appends it, renders the chart into it offscreen, and
13
+ * swaps it in only once the chart has painted — so a re-render never blanks the
14
+ * tile. Every defect this file guards is a bookkeeping error in that dance, and
15
+ * none of them is visible in a screenshot of a working chart:
16
+ *
17
+ * - The drag bug: a cleanup disposed the viz but left its stage node in the
18
+ * DOM, so the next render appended a second stage BELOW it, outside the
19
+ * container's clip — the tile drew empty while its rows sat in the DOM the
20
+ * whole time. Reproducing THAT one needs a real drag over a container that
21
+ * outlives the cleanup, so it is pinned in `dashboard-builder.spec.ts`; what
22
+ * is unit-testable here is that unmount takes both, and that a swap leaves
23
+ * exactly one stage behind.
24
+ * - Two charts at once: a promote that adds the new stage without removing
25
+ * what was already there.
26
+ * - A leaked viz: an async render that resolves after a newer one started, or
27
+ * after unmount, and paints anyway.
28
+ *
29
+ * The real renderer is a heavy async chunk that wants a browser; it is faked
30
+ * here down to the five methods this component calls, with `onReady` under the
31
+ * test's control so a render can be held mid-flight.
32
+ */
33
+
34
+ /** Every viz the component has created, in order. */
35
+ const vizzes: FakeViz[] = [];
36
+
37
+ class FakeViz {
38
+ /** The stage it was told to paint into. */
39
+ stage: HTMLElement | null = null;
40
+ removed = false;
41
+ private ready: (() => void) | null = null;
42
+ /** Fire the renderer's "I have painted" signal. */
43
+ paint() {
44
+ this.ready?.();
45
+ }
46
+ setResult() {}
47
+ render(element: HTMLElement) {
48
+ this.stage = element;
49
+ const painted = document.createElement("div");
50
+ painted.className = "malloy-render";
51
+ element.appendChild(painted);
52
+ }
53
+ remove() {
54
+ this.removed = true;
55
+ }
56
+ onReady(callback: () => void) {
57
+ this.ready = callback;
58
+ }
59
+ getMetadata() {
60
+ return null;
61
+ }
62
+ getDrillMetadata() {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ mock.module("@malloydata/render", () => ({
68
+ MalloyRenderer: class {
69
+ createViz() {
70
+ const viz = new FakeViz();
71
+ vizzes.push(viz);
72
+ return viz;
73
+ }
74
+ },
75
+ }));
76
+
77
+ const RenderedResult = (await import("./RenderedResult")).default;
78
+
79
+ /** A minimal result payload; the fake renderer never reads it. */
80
+ const RESULT = JSON.stringify({ tag: "a" });
81
+ const OTHER = JSON.stringify({ tag: "b" });
82
+
83
+ /** The stage divs currently inside the component's container. */
84
+ const stagesIn = (container: HTMLElement): Element[] => {
85
+ const host = container.querySelector("[data-testid], div");
86
+ void host;
87
+ return Array.from(container.querySelectorAll(".malloy-render")).map(
88
+ (n) => n.parentElement as Element,
89
+ );
90
+ };
91
+
92
+ beforeEach(() => {
93
+ vizzes.length = 0;
94
+ });
95
+
96
+ describe("RenderedResult: the stage lifecycle", () => {
97
+ it("paints one chart into one stage", async () => {
98
+ const view = render(<RenderedResult result={RESULT} />);
99
+ await waitFor(() => expect(vizzes).toHaveLength(1));
100
+ act(() => vizzes[0].paint());
101
+ await waitFor(() =>
102
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
103
+ );
104
+ expect(vizzes[0].removed).toBe(false);
105
+ });
106
+
107
+ it("disposes the viz as well as the node when it unmounts", async () => {
108
+ const view = render(<RenderedResult result={RESULT} />);
109
+ await waitFor(() => expect(vizzes).toHaveLength(1));
110
+ act(() => vizzes[0].paint());
111
+ await waitFor(() =>
112
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
113
+ );
114
+ const stage = vizzes[0].stage!;
115
+ view.unmount();
116
+ expect(vizzes[0].removed).toBe(true);
117
+ expect(stage.isConnected).toBe(false);
118
+ });
119
+
120
+ it("keeps the old chart on screen until the new one has painted", async () => {
121
+ // The no-flicker rule: a re-render must never leave the tile empty.
122
+ const view = render(<RenderedResult result={RESULT} />);
123
+ await waitFor(() => expect(vizzes).toHaveLength(1));
124
+ act(() => vizzes[0].paint());
125
+ await waitFor(() =>
126
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
127
+ );
128
+
129
+ view.rerender(<RenderedResult result={OTHER} />);
130
+ await waitFor(() => expect(vizzes).toHaveLength(2));
131
+
132
+ // Both are in the DOM, the outgoing one still painted, and the incoming
133
+ // one hidden and overlaid rather than stacked below it.
134
+ await waitFor(() =>
135
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(2),
136
+ );
137
+ expect(vizzes[0].removed).toBe(false);
138
+ const incoming = vizzes[1].stage as HTMLElement;
139
+ expect(incoming.style.position).toBe("absolute");
140
+ expect(incoming.style.visibility).toBe("hidden");
141
+ });
142
+
143
+ it("sweeps the container on promote, so exactly one stage survives", async () => {
144
+ const view = render(<RenderedResult result={RESULT} />);
145
+ await waitFor(() => expect(vizzes).toHaveLength(1));
146
+ act(() => vizzes[0].paint());
147
+ await waitFor(() =>
148
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
149
+ );
150
+
151
+ view.rerender(<RenderedResult result={OTHER} />);
152
+ await waitFor(() => expect(vizzes).toHaveLength(2));
153
+ act(() => vizzes[1].paint());
154
+
155
+ await waitFor(() =>
156
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
157
+ );
158
+ // The outgoing viz is disposed by the swap, not left to leak.
159
+ expect(vizzes[0].removed).toBe(true);
160
+ expect(vizzes[1].removed).toBe(false);
161
+ // And the survivor is revealed rather than left overlaid.
162
+ const live = vizzes[1].stage as HTMLElement;
163
+ expect(live.style.visibility).toBe("");
164
+ expect(live.style.position).toBe("");
165
+ });
166
+
167
+ it("ignores a stale render that paints after a newer one took over", async () => {
168
+ // A slow chart resolving late must not resurrect itself over the chart
169
+ // that replaced it, nor leave two stages behind.
170
+ const view = render(<RenderedResult result={RESULT} />);
171
+ await waitFor(() => expect(vizzes).toHaveLength(1));
172
+ act(() => vizzes[0].paint());
173
+ await waitFor(() =>
174
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
175
+ );
176
+
177
+ view.rerender(<RenderedResult result={OTHER} />);
178
+ await waitFor(() => expect(vizzes).toHaveLength(2));
179
+ act(() => vizzes[1].paint());
180
+ await waitFor(() =>
181
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1),
182
+ );
183
+
184
+ // The superseded render signals ready late. Nothing should move.
185
+ act(() => vizzes[0].paint());
186
+ expect(stagesIn(view.container as HTMLElement)).toHaveLength(1);
187
+ expect(vizzes[1].removed).toBe(false);
188
+ });
189
+
190
+ it("does not paint at all once it has unmounted", async () => {
191
+ const view = render(<RenderedResult result={RESULT} />);
192
+ await waitFor(() => expect(vizzes).toHaveLength(1));
193
+ view.unmount();
194
+ // A render resolving after unmount must not re-attach anything.
195
+ act(() => vizzes[0].paint());
196
+ expect(vizzes[0].removed).toBe(true);
197
+ });
198
+ });
@@ -418,10 +418,20 @@ function RenderedResultInner({
418
418
  // Dispose the last live viz on unmount only. Deliberately NOT done in the
419
419
  // render effect's cleanup: a re-run must keep the old chart until the new
420
420
  // one has painted, and the new render disposes it during the swap.
421
+ //
422
+ // The NODE goes with the viz, not just the viz. React destroys and
423
+ // re-creates a component's effects without discarding its DOM in several
424
+ // ordinary cases — a Suspense boundary revealing, development's
425
+ // double-invoked mount — and there the container this stage sits in is
426
+ // still on screen afterwards. Disposing the viz alone left an empty stage
427
+ // in it, which the next render then appended BELOW: the chart, pushed out
428
+ // of a clipped box, read as a tile that had lost its content.
421
429
  useEffect(() => {
422
430
  return () => {
423
431
  renderGenRef.current += 1;
424
- liveRef.current?.viz.remove();
432
+ const live = liveRef.current;
433
+ live?.viz.remove();
434
+ live?.node.remove();
425
435
  liveRef.current = null;
426
436
  };
427
437
  }, []);
@@ -545,7 +555,11 @@ function RenderedResultInner({
545
555
  // would repaint the old chart's chrome to the new theme before it is
546
556
  // swapped out. Scoping the vars to this stage keeps each chart stable.
547
557
  applyTableCssVars(stage, effectiveTheme, cardGeometry);
548
- if (previous) {
558
+ // Overlaid whenever the container is not empty, which is the
559
+ // outgoing chart and, defensively, anything an earlier render left
560
+ // behind. A stage appended as a SIBLING in the flow sits below what
561
+ // is already there and falls outside the container's clip.
562
+ if (element.childElementCount > 0) {
549
563
  element.style.position = "relative";
550
564
  stage.style.position = "absolute";
551
565
  stage.style.inset = "0";
@@ -589,12 +603,12 @@ function RenderedResultInner({
589
603
  clearTimeout(readyFallback);
590
604
  readyFallback = null;
591
605
  }
592
- // The new chart has painted; drop the outgoing one now.
593
- if (previous) {
594
- previous.viz.remove();
595
- if (previous.node.parentNode === element) {
596
- element.removeChild(previous.node);
597
- }
606
+ // The new chart has painted; drop the outgoing one now, and with
607
+ // it anything else still in the container, so the promoted stage
608
+ // is the only thing in it.
609
+ previous?.viz.remove();
610
+ for (const node of Array.from(element.children)) {
611
+ if (node !== stageNode) element.removeChild(node);
598
612
  }
599
613
  stageNode.style.position = "";
600
614
  stageNode.style.inset = "";
@@ -3,10 +3,11 @@
3
3
 
4
4
  import { Warning } from "@mui/icons-material";
5
5
  import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
6
- import { Box, Button, IconButton, Tooltip, Typography } from "@mui/material";
6
+ import { Box, Button, Tooltip, Typography } from "@mui/material";
7
7
  import { lazy, Suspense, useRef, useState } from "react";
8
8
  import { LogMessage } from "../../client";
9
9
  import type { DrillBinding } from "../drill/useDrill";
10
+ import { FloatingIconButton } from "../FloatingIconButton";
10
11
  import { Loading } from "../Loading";
11
12
  import { summarizeRenderLogs } from "./renderLogs";
12
13
  import { resolveResultHeight, type ResultSizing } from "./resultSizing";
@@ -134,16 +135,7 @@ export default function ResultContainer({
134
135
  title={renderLogSummary.title}
135
136
  slotProps={{ tooltip: { sx: { whiteSpace: "pre-line" } } }}
136
137
  >
137
- <IconButton
138
- size="small"
139
- aria-label="Render tag warnings"
140
- sx={{
141
- backgroundColor: "rgba(255, 255, 255, 0.9)",
142
- "&:hover": {
143
- backgroundColor: "rgba(255, 255, 255, 1)",
144
- },
145
- }}
146
- >
138
+ <FloatingIconButton aria-label="Render tag warnings">
147
139
  <InfoOutlinedIcon
148
140
  fontSize="small"
149
141
  color={
@@ -152,7 +144,7 @@ export default function ResultContainer({
152
144
  : "warning"
153
145
  }
154
146
  />
155
- </IconButton>
147
+ </FloatingIconButton>
156
148
  </Tooltip>
157
149
  </Box>
158
150
  )}