@malloy-publisher/sdk 0.4.0 → 0.5.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 (72) hide show
  1. package/README.md +19 -0
  2. package/dist/{DocumentStorageProvider-CyOJ0hqf.es.js → DocumentStorage-B04sZ5Ie.es.js} +2307 -2334
  3. package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +20 -20
  4. package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
  5. package/dist/RenderedResult-DVuGhatg.cjs.js +135 -0
  6. package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
  7. package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
  8. package/dist/builder/index.cjs.js +57 -52
  9. package/dist/builder/index.es.js +4421 -3738
  10. package/dist/client/api.d.ts +14 -1
  11. package/dist/client/index.cjs.js +1 -1
  12. package/dist/client/index.es.js +1 -1
  13. package/dist/components/Dashboard/TileCard.d.ts +7 -3
  14. package/dist/components/Dashboard/telemetry.d.ts +20 -8
  15. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +16 -4
  16. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +31 -8
  17. package/dist/components/DashboardBuilder/controls.d.ts +8 -6
  18. package/dist/components/DashboardBuilder/document.d.ts +19 -5
  19. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
  20. package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
  21. package/dist/components/DashboardBuilder/preview.d.ts +17 -0
  22. package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
  23. package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
  24. package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
  25. package/dist/components/DocumentStorage/index.d.ts +1 -0
  26. package/dist/index.cjs.js +9 -9
  27. package/dist/index.es.js +508 -506
  28. package/dist/theme/resolveTheme.d.ts +1 -1
  29. package/dist/theme/types.d.ts +12 -2
  30. package/package.json +1 -1
  31. package/src/components/Dashboard/TileCard.tsx +8 -4
  32. package/src/components/Dashboard/telemetry.ts +20 -8
  33. package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
  34. package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
  35. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
  36. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
  37. package/src/components/DashboardBuilder/DashboardEditor.tsx +468 -103
  38. package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
  39. package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
  40. package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
  41. package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
  42. package/src/components/DashboardBuilder/controls.spec.ts +53 -3
  43. package/src/components/DashboardBuilder/controls.ts +9 -7
  44. package/src/components/DashboardBuilder/document.ts +17 -5
  45. package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
  46. package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
  47. package/src/components/DashboardBuilder/malloyText.ts +4 -109
  48. package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
  49. package/src/components/DashboardBuilder/malloyTree.ts +954 -0
  50. package/src/components/DashboardBuilder/preview.spec.ts +18 -0
  51. package/src/components/DashboardBuilder/preview.ts +24 -6
  52. package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
  53. package/src/components/DashboardBuilder/readDocument.ts +144 -165
  54. package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
  55. package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
  56. package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
  57. package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
  58. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
  59. package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
  60. package/src/components/DocumentStorage/index.ts +1 -0
  61. package/src/components/Package/Package.tsx +12 -7
  62. package/src/components/RenderedResult/RenderedResult.tsx +21 -1
  63. package/src/components/given/GivensPanel.tsx +15 -3
  64. package/src/theme/buildTableCssVars.spec.ts +3 -0
  65. package/src/theme/buildTableCssVars.ts +6 -0
  66. package/src/theme/defaults.ts +16 -12
  67. package/src/theme/resolveTheme.spec.ts +14 -7
  68. package/src/theme/resolveTheme.ts +14 -8
  69. package/src/theme/types.ts +12 -2
  70. package/tsconfig.spec.json +5 -1
  71. package/dist/RenderedResult-Dp22kZsQ.cjs.js +0 -115
  72. package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
@@ -19,10 +19,39 @@
19
19
  * ask for one kind. Everything else a backend may know about a document, who
20
20
  * changed it and when, who may see it, stays with the backend.
21
21
  *
22
+ * A host hands the SDK ONE storage and keeps handing it the same one. What a
23
+ * storage says about its workspaces decides how the editor routes a save, and
24
+ * the editor asks once, when it opens; a host that re-creates its storage mid
25
+ * session leaves the editor routing by the old answer until the new list
26
+ * resolves.
27
+ *
22
28
  * Every method rejects rather than returning a sentinel when the document is
23
- * not there, so a caller can tell "missing" from "empty".
29
+ * not there, so a caller can tell "missing" from "empty". Absence rejects with
30
+ * a {@link DocumentNotFoundError} specifically, so a caller can tell either of
31
+ * those from a backend that could not be reached: a failed read answered with
32
+ * "there is no document" reads as "the package is the only copy", and saving
33
+ * on that belief overwrites the copy that was actually there.
24
34
  */
25
35
 
36
+ /**
37
+ * Absence, and only absence: the document is not at that locator. Every other
38
+ * rejection means the backend could not answer, which is not the same thing and
39
+ * must not be treated as one.
40
+ */
41
+ export class DocumentNotFoundError extends Error {
42
+ constructor(message: string) {
43
+ super(message);
44
+ // Not `instanceof`: the `es` and `cjs` builds carry their own copy of
45
+ // this class, so an error thrown by one fails the check in the other.
46
+ this.name = "DocumentNotFoundError";
47
+ }
48
+ }
49
+
50
+ /** Whether a rejection means absence rather than a backend that could not answer. */
51
+ export const isDocumentNotFound = (error: unknown): boolean =>
52
+ error instanceof DocumentNotFoundError ||
53
+ (error instanceof Error && error.name === "DocumentNotFoundError");
54
+
26
55
  /**
27
56
  * The kinds of document the SDK authors. A `dashboard` is a
28
57
  * `dashboards/<slug>.malloy` file; a `notebook` is a `.malloynb`.
@@ -34,7 +63,33 @@ export interface Workspace {
34
63
  name: string;
35
64
  /** False for a workspace this reader may list and open but not save into. */
36
65
  writeable: boolean;
66
+ /**
67
+ * What this place is, in the backend's own words, for the editor to show a
68
+ * reader rather than guessing on their behalf.
69
+ */
37
70
  description: string;
71
+ /**
72
+ * This workspace holds the package's system of record: what it keeps for a
73
+ * document IS that document, and the package file is a copy of it or a
74
+ * deploy behind it.
75
+ *
76
+ * Left out, the workspace is a place a reader's work is kept beside the
77
+ * package — the Console's browser copy, a scratch space — and the package
78
+ * file is the record.
79
+ *
80
+ * The contract, which the editor relies on and does not police:
81
+ *
82
+ * - At most one workspace of a storage declares itself authoritative. The
83
+ * editor takes the first it is given and does not arbitrate between two.
84
+ * - It is orthogonal to {@link Workspace.writeable} and to the server's
85
+ * `mutable`. A workspace can be the record and still be read-only to this
86
+ * reader, and a server that refuses writes to its own package says
87
+ * nothing about where the record lives.
88
+ * - A host whose authority differs per package mounts one storage per
89
+ * context rather than flipping this between renders; the editor reads it
90
+ * once, when it opens.
91
+ */
92
+ authoritative?: boolean;
38
93
  }
39
94
 
40
95
  /** One document's address: which workspace, which kind, and its path there. */
@@ -59,15 +114,33 @@ export interface DocumentStorage {
59
114
  type?: DocumentType,
60
115
  ): Promise<DocumentLocator[]>;
61
116
 
62
- /** The document's content. Rejects when there is no document there. */
117
+ /**
118
+ * The document's content. Rejects with a {@link DocumentNotFoundError} when
119
+ * there is no document there, and with anything else when the backend could
120
+ * not be asked.
121
+ */
63
122
  getDocument(locator: DocumentLocator): Promise<string>;
64
123
 
65
- /** Write the content, creating the document or replacing it. */
124
+ /**
125
+ * Write the content, creating the document or replacing it.
126
+ *
127
+ * There is no expected-version slot, so this is last writer wins and a
128
+ * caller cannot tell that it overwrote someone. A backend that has to stop
129
+ * two authors clobbering each other enforces that itself, in the backend.
130
+ */
66
131
  saveDocument(locator: DocumentLocator, content: string): Promise<void>;
67
132
 
68
- /** Remove the document. Rejects when there is no document there. */
133
+ /**
134
+ * Remove the document. Rejects with a {@link DocumentNotFoundError} when
135
+ * there is no document there, and with anything else when the backend could
136
+ * not be asked — a caller must not read the second as the first and report
137
+ * the document gone.
138
+ */
69
139
  deleteDocument(locator: DocumentLocator): Promise<void>;
70
140
 
71
- /** Rename or relocate a document, keeping its content. Rejects when `from` is missing. */
141
+ /**
142
+ * Rename or relocate a document, keeping its content. Rejects with a
143
+ * {@link DocumentNotFoundError} when `from` is missing.
144
+ */
72
145
  moveDocument(from: DocumentLocator, to: DocumentLocator): Promise<void>;
73
146
  }
@@ -7,6 +7,7 @@ export type {
7
7
  DocumentType,
8
8
  Workspace,
9
9
  } from "./DocumentStorage";
10
+ export { DocumentNotFoundError, isDocumentNotFound } from "./DocumentStorage";
10
11
  export {
11
12
  DocumentStorageProvider,
12
13
  useDocumentStorage,
@@ -64,21 +64,26 @@ export default function Package({
64
64
  const [schemaDatabase, setSchemaDatabase] = useState<Database | null>(null);
65
65
  const [creating, setCreating] = useState(false);
66
66
 
67
- // Dashboards saved in this browser and not (yet) in the package: the
68
- // builder's drafts, listed so they are found rather than stumbled on.
67
+ // Dashboards the host keeps for this package and the package does not have:
68
+ // the builder's drafts, listed so they are found rather than stumbled on.
69
+ // Each carries the workspace's own description, because where a document is
70
+ // kept is the backend's to say and only one host's answer is "this browser".
69
71
  const storage = useOptionalDocumentStorage()?.documentStorage;
70
- const [drafts, setDrafts] = useState<DocumentLocator[]>([]);
72
+ const [drafts, setDrafts] = useState<
73
+ { locator: DocumentLocator; where: string }[]
74
+ >([]);
71
75
  const draftPrefix = `${environmentName}/${packageName}/dashboards/`;
72
76
  const refreshDrafts = useCallback(async () => {
73
77
  if (!storage) return;
74
78
  const workspaces = await storage.listWorkspaces(true);
75
- const found: DocumentLocator[] = [];
79
+ const found: { locator: DocumentLocator; where: string }[] = [];
76
80
  for (const workspace of workspaces)
77
81
  for (const locator of await storage.listDocuments(
78
82
  workspace,
79
83
  "dashboard",
80
84
  ))
81
- if (locator.path.startsWith(draftPrefix)) found.push(locator);
85
+ if (locator.path.startsWith(draftPrefix))
86
+ found.push({ locator, where: workspace.description });
82
87
  setDrafts(found);
83
88
  }, [storage, draftPrefix]);
84
89
  useEffect(() => {
@@ -391,12 +396,12 @@ export default function Package({
391
396
  )}
392
397
  {drafts.length > 0 && (
393
398
  <PackageSection title="Drafts" count={drafts.length}>
394
- {drafts.map((locator) => (
399
+ {drafts.map(({ locator, where }) => (
395
400
  <PackageItemRow
396
401
  key={locator.path}
397
402
  type="dashboard"
398
403
  label={draftSlug(locator)}
399
- rightLabel="saved in this browser"
404
+ rightLabel={where}
400
405
  onClick={(event) =>
401
406
  onClick(
402
407
  `/${environmentName}/${packageName}/dashboards/${encodeURIComponent(draftSlug(locator))}/edit`,
@@ -276,7 +276,27 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
276
276
  background: var(--malloy-render--tile-background) !important;
277
277
  color: var(--malloy-render--table-body-color) !important;
278
278
  box-shadow: none !important;
279
- border: var(--malloy-render--table-border) !important;
279
+ /* The card edge, not the table gridline: --publisher-dashboard-card-border,
280
+ the same value TileCard paints, so the renderer's card and the composite
281
+ one are outlined identically. */
282
+ border: var(--publisher-dashboard-card-border) !important;
283
+ }
284
+ /* The renderer's big-value card — the small card a "# big_value" measure sits
285
+ in, several to a row inside one tile. (No backticks in here: this is inside
286
+ a template literal.) Its own CSS gives it a 0.55px edge in
287
+ #e5e7eb: a sub-pixel width, and a grey off the slate ramp everything else on
288
+ the page is on. It is a dashboard card like any other, so it takes the card
289
+ edge and stops being the one card outlined in a hairline nobody can see. */
290
+ .malloy-render .malloy-big-value-card {
291
+ border: var(--publisher-dashboard-card-border) !important;
292
+ /* Its shadow is a four-layer Tailwind stack, and only two of those layers
293
+ are a shadow: the other is "0 0 0 1px #e5e7eb", a spread ring drawn as a
294
+ second border OVER the real one. So the border above was landing
295
+ underneath a ring in the renderer's own grey, and the card kept both a
296
+ lifted look the flat cards around it do not have and an edge we did not
297
+ pick. Dropped whole rather than rebuilt layer by layer: the ring's job is
298
+ the border's job, and the border is already doing it. */
299
+ box-shadow: none !important;
280
300
  }
281
301
  .malloy-render .malloy-dashboard .dashboard-row-header-separator {
282
302
  background: var(--malloy-render--table-border) !important;
@@ -5,6 +5,7 @@ import { Box, Button, Paper, Stack, Typography } from "@mui/material";
5
5
  import { Given } from "../../client";
6
6
  import { GivenValue } from "../../hooks/givenValue";
7
7
  import { GivenInput } from "./GivenInput";
8
+ import { usePublisherTheme } from "../../theme/ThemeContext";
8
9
 
9
10
  /**
10
11
  * How the control row is laid out.
@@ -64,6 +65,10 @@ export function GivensPanel({
64
65
  apply,
65
66
  title,
66
67
  }: GivensPanelProps) {
68
+ // Above the early return below, not down at its use site: the bar layout is
69
+ // the only branch that paints a border, but a hook called conditionally is
70
+ // a hook called on some renders and not others.
71
+ const { theme } = usePublisherTheme();
67
72
  if (givens.length === 0) return null;
68
73
  // Some value actually SET, not merely some entry present. `paramsToGivens`
69
74
  // records `?X=` as a null entry, so counting entries offered Reset for a
@@ -126,10 +131,17 @@ export function GivensPanel({
126
131
  elevation={0}
127
132
  sx={{
128
133
  p: 2,
129
- border: 1,
130
- borderColor: "divider",
134
+ // The card edge, not MUI's `divider`: this row IS one of the
135
+ // page's cards as far as a reader is concerned, and on
136
+ // `divider` it stayed at the old hairline weight while the
137
+ // cards under it darkened — the one box on the page outlined
138
+ // differently from everything it sits above.
139
+ border: theme.cardBorder,
131
140
  borderRadius: 1,
132
- backgroundColor: "background.paper",
141
+ // Border only, no raised fill — the same construction the
142
+ // dashboard's cards use, so the control row reads as part of
143
+ // the page rather than as a panel floating above it.
144
+ backgroundColor: "transparent",
133
145
  }}
134
146
  >
135
147
  <Stack
@@ -23,6 +23,9 @@ describe("buildTableCssVars", () => {
23
23
  expect(vars["--malloy-render--table-header-color"]).toBe(t.tableHeader);
24
24
  expect(vars["--malloy-render--table-body-color"]).toBe(t.tableBody);
25
25
  expect(vars["--malloy-render--table-border"]).toBe(t.border);
26
+ // The card edge rides its own var, so darkening a card cannot darken
27
+ // every gridline in the table it holds.
28
+ expect(vars["--publisher-dashboard-card-border"]).toBe(t.cardBorder);
26
29
  // `tile-background` is our custom var for the dashboard tile
27
30
  // container. It's NOT the renderer's `table-pinned-background`
28
31
  // (which now carries `tableHeaderBackground` via the theme prop).
@@ -94,5 +94,11 @@ export function buildTableCssVars(
94
94
  // that route needs no !important.
95
95
  "--publisher-dashboard-card-radius": card.radius,
96
96
  "--publisher-dashboard-card-padding": card.padding,
97
+ // The card's EDGE, separate from --malloy-render--table-border, which
98
+ // is the gridline inside the table a card may hold. Same reason
99
+ // TileCard reads theme.cardBorder: the two weights are answering
100
+ // different questions, and a card outlined at gridline weight on a
101
+ // white page did not read as a card at all.
102
+ "--publisher-dashboard-card-border": theme.cardBorder,
97
103
  };
98
104
  }
@@ -36,12 +36,12 @@ export const DEFAULT_THEME: Required<Theme> = {
36
36
  allowUserToggle: true,
37
37
  palette: {
38
38
  series: DEFAULT_SERIES,
39
+ // The chart canvas. One ground for the whole dashboard in both modes —
40
+ // canvas, card and the panel between cards are all this value, and the
41
+ // borders do the separating. See `tile`.
39
42
  background: {
40
43
  light: "#ffffff",
41
- // Slate to match the Publisher app's sidebar surface so
42
- // rendered charts sit on the same elevation as the chrome
43
- // around them.
44
- dark: "#1e293b",
44
+ dark: "#0f172a",
45
45
  },
46
46
  tableHeader: {
47
47
  light: "#475569",
@@ -58,16 +58,20 @@ export const DEFAULT_THEME: Required<Theme> = {
58
58
  light: "#475569",
59
59
  dark: "#e2e8f0",
60
60
  },
61
- // The padded container that wraps each chart / table in a
62
- // dashboard. Light mode: a faint recess off white; dark mode:
63
- // page-outer slate.
61
+ // The padded container that wraps each chart / table in a dashboard.
62
+ //
63
+ // The SAME value as the canvas it holds and the panel it sits on, in
64
+ // both modes: a card is separated by its border and its radius, not by
65
+ // a wash. A tinted card reads as a recess — something switched off —
66
+ // and stacking card, canvas and panel as three values put three greys
67
+ // on one tile.
64
68
  //
65
- // Neutral slate, not a tint. This was `#f5fafc`, a cyan-cast
66
- // near-white left from the logo palette, and it was the most visible
67
- // survivor of it: every dashboard on the server painted a pale blue
68
- // panel behind its tiles, under charts that were no longer blue-green.
69
+ // Both modes are built the same way on purpose. They used to differ in
70
+ // structure, not just in value — light separated by border, dark by
71
+ // elevation — so a change to how a card reads had to be reasoned about
72
+ // twice and could land correct in one mode and wrong in the other.
69
73
  tile: {
70
- light: "#f8fafc",
74
+ light: "#ffffff",
71
75
  dark: "#0f172a",
72
76
  },
73
77
  tileTitle: {
@@ -87,6 +87,13 @@ describe("resolveTheme cascade", () => {
87
87
  // attempt at whatever the data is painted in.
88
88
  expect(light.border).toBe("1px solid #e2e8f0");
89
89
  expect(dark.border).toBe("1px solid #334155");
90
+ // A card's edge is a step darker than a table's gridline in both modes:
91
+ // the gridline separates rows inside a card, the card edge says where
92
+ // the card stops, and at one weight the second job went undone.
93
+ expect(light.cardBorder).toBe("1px solid #cbd5e1");
94
+ expect(dark.cardBorder).toBe("1px solid #475569");
95
+ expect(light.cardBorder).not.toBe(light.border);
96
+ expect(dark.cardBorder).not.toBe(dark.border);
90
97
  expect(light.foreground).toBe("#0f172a");
91
98
  expect(dark.foreground).toBe("#e2e8f0");
92
99
  expect(light.axisFaint).toBe("#cbd5e1");
@@ -111,10 +118,10 @@ describe("resolveTheme cascade", () => {
111
118
  });
112
119
 
113
120
  it("dashboardRoot is mode-keyed and immune to operator background overrides", () => {
114
- // Light keeps white (no regression on existing installs).
121
+ // The page's own ground in each mode: the panel, the cards on it and
122
+ // the canvases inside them are one surface that borders divide up.
115
123
  expect(resolveTheme([], "light").dashboardRoot).toBe("#ffffff");
116
- // Dark paints slate so the panel doesn't read as a bright box.
117
- expect(resolveTheme([], "dark").dashboardRoot).toBe("#1e293b");
124
+ expect(resolveTheme([], "dark").dashboardRoot).toBe("#0f172a");
118
125
  // An operator picking a bold accent for `background` (the chart
119
126
  // canvas) must NOT bleed into the surrounding panel.
120
127
  const t = resolveTheme(
@@ -122,14 +129,14 @@ describe("resolveTheme cascade", () => {
122
129
  "dark",
123
130
  );
124
131
  expect(t.background).toBe("#ff8800");
125
- expect(t.dashboardRoot).toBe("#1e293b");
132
+ expect(t.dashboardRoot).toBe("#0f172a");
126
133
  });
127
134
 
128
135
  it("tableBackground follows the operator's palette.background", () => {
129
- // Defaults track the per-mode background (white in light, slate
130
- // in dark) so existing installs see no change.
136
+ // Defaults track the per-mode background, which is the page's ground
137
+ // in both modes.
131
138
  expect(resolveTheme([], "light").tableBackground).toBe("#ffffff");
132
- expect(resolveTheme([], "dark").tableBackground).toBe("#1e293b");
139
+ expect(resolveTheme([], "dark").tableBackground).toBe("#0f172a");
133
140
  // An operator accent on palette.background bleeds into the table
134
141
  // interior so charts and tables share a single viz surface
135
142
  // colour. The dashboard panel between tiles stays neutral —
@@ -14,7 +14,7 @@ import type { ResolvedTheme, Theme, ThemeMode } from "./types";
14
14
  * (a layer that sets only `palette.tile.dark` doesn't clobber the
15
15
  * instance-level `palette.tile.light`).
16
16
  *
17
- * The derived fields on ResolvedTheme (border, pinnedBorder,
17
+ * The derived fields on ResolvedTheme (border, cardBorder, pinnedBorder,
18
18
  * valueColor, foreground, axisFaint) are computed once here from the
19
19
  * active mode so the three builders that consume the theme stop
20
20
  * recomputing them with duplicated hex literals.
@@ -88,19 +88,25 @@ export function resolveTheme(
88
88
  // each mode. If a user later asks to customise them, expose them
89
89
  // on the schema and the editor and replace the literals below.
90
90
  border: isDark ? "1px solid #334155" : "1px solid #e2e8f0",
91
+ // A card's edge, one stop darker than a table's gridline on the same
92
+ // slate ramp. See `cardBorder` on ResolvedTheme for why the two are not
93
+ // the same value.
94
+ cardBorder: isDark ? "1px solid #475569" : "1px solid #cbd5e1",
91
95
  // Slate, not the teal-cast `#daedf3` this was: a pinned table header
92
96
  // outlined in a hue no longer anywhere else on the page.
93
97
  pinnedBorder: isDark ? "1px solid #475569" : "1px solid #cbd5e1",
94
98
  valueColor: isDark ? "#f1f5f9" : "#0f172a",
95
99
  foreground: isDark ? "#e2e8f0" : "#0f172a",
96
100
  axisFaint: isDark ? "#475569" : "#cbd5e1",
97
- // Dashboard panel background (area BETWEEN tiles). Light keeps
98
- // white so the page stays visually unchanged. Dark uses slate so
99
- // the panel doesn't read as a bright box against the dark page
100
- // chrome. Intentionally NOT tied to `palette.background`: the
101
- // panel stays neutral so a bold accent on the chart canvas
102
- // doesn't bleed into the surrounding chrome.
103
- dashboardRoot: isDark ? "#1e293b" : "#ffffff",
101
+ // Dashboard panel background (the area BETWEEN tiles). The page's own
102
+ // ground in both modes, so the panel, the cards on it and the canvases
103
+ // inside them are one surface that borders divide up — see
104
+ // `palette.tile`.
105
+ //
106
+ // Still NOT tied to `palette.background`, which an operator may set to
107
+ // a bold accent for the chart canvas. The panel stays the neutral it is
108
+ // here so that accent cannot bleed into the surrounding chrome.
109
+ dashboardRoot: isDark ? "#0f172a" : "#ffffff",
104
110
  // Drill link hover: the palette's anchor blue, so a drill reads as the
105
111
  // same affordance as every other primary action; dark lightens it for
106
112
  // contrast on the slate panel.
@@ -16,8 +16,8 @@ export type ThemeMode = "light" | "dark";
16
16
  *
17
17
  * The seven `palette.*` colour keys are stored per-mode on the raw Theme
18
18
  * (one of light/dark per field) and collapse to the active mode here.
19
- * The five "derived" fields (border, pinnedBorder, valueColor,
20
- * foreground, axisFaint) are computed once from the resolved mode so
19
+ * The six "derived" fields (border, cardBorder, pinnedBorder,
20
+ * valueColor, foreground, axisFaint) are computed once from the resolved mode so
21
21
  * the same hex literal isn't repeated across three builders.
22
22
  */
23
23
  export interface ResolvedTheme {
@@ -43,6 +43,16 @@ export interface ResolvedTheme {
43
43
  mapColor: string;
44
44
 
45
45
  border: string;
46
+ /**
47
+ * The edge of a dashboard CARD, kept off `border` on purpose. `border` is
48
+ * the gridline inside a table, where a hairline is right because there are
49
+ * dozens of them and they only have to separate rows. A card's edge has one
50
+ * job — say where the card stops — and at the gridline's weight, on a page
51
+ * whose ground and tile are both white, it did not do it: the cards read as
52
+ * floating content rather than as cards. A step down the same slate ramp,
53
+ * so the two still read as one system.
54
+ */
55
+ cardBorder: string;
46
56
  pinnedBorder: string;
47
57
  valueColor: string;
48
58
  foreground: string;
@@ -4,7 +4,10 @@
4
4
  // build. But excluded also meant unchecked: `bun test` strips types without
5
5
  // checking them and eslint here is not type-aware, so a type error in a spec
6
6
  // reached no gate. The root `typecheck:sdk` runs this config as its second
7
- // half. Keep the four patterns in step with the exclude list next door.
7
+ // half. Keep these patterns in step with the exclude list next door -- which
8
+ // also excludes `src/**/__test__`, where the helper modules the specs import
9
+ // live. Left out here they would be neither built nor checked, which is the
10
+ // hole this config exists to close.
8
11
  {
9
12
  "extends": "./tsconfig.json",
10
13
  "compilerOptions": {
@@ -16,6 +19,7 @@
16
19
  "src/**/*.test.*",
17
20
  "src/**/*_spec.*",
18
21
  "src/**/*_test.*",
22
+ "src/**/__test__/**/*",
19
23
  "test/**/*"
20
24
  ],
21
25
  "exclude": []
@@ -1,115 +0,0 @@
1
- "use strict";var ve=Object.create;var le=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var Ce=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of we(r))!Re.call(e,o)&&o!==t&&le(e,o,{get:()=>r[o],enumerable:!(n=ge(r,o))||n.enumerable});return e};var G=(e,r,t)=>(t=e!=null?ve(ke(e)):{},Ce(r||!e||!e.__esModule?le(t,"default",{value:e,enumerable:!0}):t,e));const B=require("react/jsx-runtime"),U=require("@mui/material"),p=require("react"),v=require("./DocumentStorageProvider-DGPQEd_l.cjs.js"),X=require("./ServerProvider-Cc489A3f.cjs.js"),g="publisher-drill";function de(e,r){const t=new Set;let n;try{n=e.getMetadata()?.getAllFields()??[]}catch{return t}const o=new Set;for(const a of n)!a||r(a)||a.tag?.tag("hidden")===void 0&&o.add(a.tag?.text("label")??a.name);for(const a of n){if(!a||!r(a))continue;const l=a.tag?.text("label")??a.name;o.has(l)||t.add(l)}return t}function M(e){const r=/^\s*(\d+)/.exec(e.style?.gridColumn??"");return r?r[1]:void 0}function ce(e,r){if(r.size!==0)for(const t of e.querySelectorAll(".malloy-table")){const n=l=>l.closest(".malloy-table")===t,o=new Set;for(const l of t.querySelectorAll(".column-cell.th")){if(!n(l))continue;const s=(l.textContent??"").replace(/\u200b/g,"").trim(),y=M(l);y&&r.has(s)&&o.add(y)}if(o.size===0)continue;const a=new Set;for(const l of t.querySelectorAll(`.${g}[tabindex="0"]`)){if(!n(l))continue;const s=M(l);s&&(a.has(s)?l.tabIndex=-1:a.add(s))}for(const l of t.querySelectorAll(".column-cell.td")){if(!n(l))continue;const s=M(l),y=!l.querySelector(".value-null")&&(l.textContent??"").trim()!=="";if(s&&y&&o.has(s)&&!l.querySelector(".malloy-table")){if(l.classList.add(g),l.tabIndex===0)a.add(s);else{const h=a.has(s);h||a.add(s),l.tabIndex=h?-1:0}l.setAttribute("role","button")}}}}function xe(e){const r=e.closest(".malloy-table"),t=M(e);return!r||!t?[]:Array.from(r.querySelectorAll(`.${g}`)).filter(n=>n.closest(".malloy-table")===r&&M(n)===t)}function ie(e,r){const t=xe(e),n=t.indexOf(e);if(n===-1)return;const o=r==="first"?t[0]:r==="last"?t[t.length-1]:t[Math.min(Math.max(n+r,0),t.length-1)];if(o){for(const a of t)a.tabIndex=a===o?0:-1;return o}}function ue(e){return{background:e.dashboardRoot,tableBackground:e.tableBackground,tableHeaderColor:e.tableHeader,tableBodyColor:e.tableBody,tableBorder:e.border,tablePinnedBackground:e.tableHeaderBackground,tablePinnedBorder:e.pinnedBorder,tableFontSize:`${e.font.size}px`,fontFamily:e.font.family,mapColor:e.mapColor}}function he(e){const{foreground:r,axisFaint:t,font:n}=e,o={background:e.background,font:n.family,title:{color:r,font:n.family},axis:{labelColor:r,titleColor:r,domainColor:t,tickColor:t,gridColor:t,labelFont:n.family,titleFont:n.family},legend:{labelColor:r,titleColor:r,labelFont:n.family,titleFont:n.family},header:{labelColor:r,titleColor:r},range:{category:e.series}};return a=>o}function me(e){if(!e)return;const r=e.tag("theme");if(!r)return;const t={},n=r.tag("palette");if(n){const a={},l=n.textArray("series");l&&l.length>0&&(a.series=l);for(const s of X.PER_MODE_COLOR_KEYS){const y=n.tag(s);if(!y)continue;const h={},k=y.text("light"),E=y.text("dark");k&&(h.light=k),E&&(h.dark=E),Object.keys(h).length>0&&(a[s]=h)}Object.keys(a).length>0&&(t.palette=a)}const o=r.tag("font");if(o){const a={},l=o.text("family");l&&(a.family=l);const s=o.numeric("size");typeof s=="number"&&Number.isFinite(s)&&(a.size=s),Object.keys(a).length>0&&(t.font=a)}return Object.keys(t).length>0?t:void 0}const Ee=async(e,r)=>{if(typeof window>"u")throw new Error("MalloyRenderer can only be used in browser environment");const{MalloyRenderer:t}=await import("@malloydata/render");return new t({onClick:r,vegaConfigOverride:he(e),theme:ue(e),onError:o=>{console.error("Error rendering visualization:",typeof o,o)}}).createViz()};typeof window<"u"&&import("@malloydata/render");async function Se(e){if(!e||typeof e!="object")return;const r=e,t=[...Array.isArray(r.model_annotations)?r.model_annotations:[],...Array.isArray(r.source_annotations)?r.source_annotations:[],...Array.isArray(r.annotations)?r.annotations:[]].map(o=>typeof o?.value=="string"?o.value:void 0).filter(o=>!!o);if(t.length===0)return;let n;try{({parseAnnotation:n}=await import("@malloydata/malloy-tag"))}catch{return}try{const{tag:o}=n(t);return me(o)}catch(o){console.warn("Failed to parse # theme.* annotations; chart will render with the shell theme.",{error:o,lines:t});return}}function Ae(e,r,t){const n=v.buildTableCssVars(r,t);for(const[o,a]of Object.entries(n))e.style.setProperty(o,a)}const De=`
2
- /* Card geometry, through the renderer's OWN theme vars rather than over the top
3
- of them. It declares --malloy-theme--dashboard-* on .malloy-render itself and
4
- passes each through to the --malloy-render--* the card CSS reads, so a value
5
- inherited from our wrapper loses to that declaration however early it is set:
6
- this has to be a rule on the same element, at higher specificity. Doubling the
7
- class does that, and then no !important is needed — which matters, because
8
- !important here also lands on .dashboard-item-borderless and repaints a card
9
- the author asked to have no card. */
10
- .malloy-render.malloy-render {
11
- --malloy-theme--dashboard-card-radius: var(--publisher-dashboard-card-radius);
12
- --malloy-theme--dashboard-card-padding: var(--publisher-dashboard-card-padding);
13
- }
14
- /* dashboard.css hardcodes background: #f7f9fc on .malloy-dashboard
15
- and .dashboard-row-header, which would paint light grey in dark
16
- mode and also bleed an operator-picked palette.background across
17
- the panel chrome in light. Both surfaces use
18
- --malloy-render--background here, which buildMalloyExplicitTheme
19
- wires to dashboardRoot: a mode-keyed neutral that stays decoupled
20
- from palette.background (the chart canvas) on purpose. Selectors
21
- are duplicated at higher specificity to beat the renderer s own
22
- scoped rules. */
23
- .malloy-render .malloy-dashboard,
24
- .malloy-render.malloy-render .malloy-dashboard,
25
- div.malloy-render .malloy-dashboard {
26
- /* --publisher-dashboard-root is set on the outer Publisher wrapper
27
- (see buildTableCssVars) and stays decoupled from
28
- --malloy-render--background, which gets shadowed inside the
29
- renderer when a theme.background annotation is present. The
30
- dedicated var means the panel between tiles always paints the
31
- operator neutral dashboardRoot regardless of annotations. */
32
- background: var(--publisher-dashboard-root) !important;
33
- background-color: var(--publisher-dashboard-root) !important;
34
- color: var(--malloy-render--table-body-color) !important;
35
- }
36
- .malloy-render .malloy-dashboard .dashboard-row,
37
- .malloy-render .malloy-dashboard .dashboard-row-body,
38
- .malloy-render .malloy-dashboard .dashboard-row-header,
39
- .malloy-render.malloy-render .malloy-dashboard .dashboard-row-header,
40
- div.malloy-render .malloy-dashboard .dashboard-row-header {
41
- /* Belt + suspenders: dashboard.css hardcodes .dashboard-row-header
42
- to #f7f9fc, and row / row-body have no explicit background but
43
- get caught in any annotation-driven inline writes. Force all of
44
- them to the neutral panel colour. */
45
- background: var(--publisher-dashboard-root) !important;
46
- background-color: var(--publisher-dashboard-root) !important;
47
- }
48
- .malloy-render .malloy-dashboard .dashboard-item:not(.dashboard-item-borderless) {
49
- /* Tile padding around each chart / table. Uses our custom
50
- --malloy-render--tile-background so the operator can theme the
51
- tile separately from the table header row (which paints from
52
- --malloy-render--table-pinned-background below).
53
-
54
- A flat bordered card rather than the renderer's shadow ring, which is what
55
- makes it match the composite tile's Paper. :not(borderless) because
56
- # borderless asks for no card at all, and an !important background and
57
- border drew one anyway. */
58
- background: var(--malloy-render--tile-background) !important;
59
- color: var(--malloy-render--table-body-color) !important;
60
- box-shadow: none !important;
61
- border: var(--malloy-render--table-border) !important;
62
- }
63
- .malloy-render .malloy-dashboard .dashboard-row-header-separator {
64
- background: var(--malloy-render--table-border) !important;
65
- }
66
- .malloy-render .malloy-table .th.column-cell {
67
- /* Non-pinned tables have no header background in the renderer's
68
- own CSS (only pinned scrolled tables paint the pinned-header
69
- with this var). Force the same value here so every table has a
70
- visible header band reflecting the operator's choice. */
71
- background: var(--malloy-render--table-pinned-background) !important;
72
- }
73
- .malloy-render .dashboard-item-title,
74
- .malloy-render .dashboard-dimension-name {
75
- color: var(--malloy-render--label-color) !important;
76
- }
77
- .malloy-render .dashboard-item-value,
78
- .malloy-render .dashboard-item-value-measure,
79
- .malloy-render .dashboard-dimension-value {
80
- color: var(--malloy-render--value-color) !important;
81
- }
82
- .malloy-render .malloy-table,
83
- .malloy-render .malloy-list {
84
- color: var(--malloy-render--table-body-color) !important;
85
- }
86
- .malloy-render .column-cell.th,
87
- .malloy-render .cell-content.header {
88
- color: var(--malloy-render--table-header-color) !important;
89
- }
90
- /* A cell whose column declares a "# drill" this surface can honor, marked
91
- by markDrillableCells. Ordinary text with a pointer cursor until hovered,
92
- then it reads as a link: the same affordance Malloyyo gives the same tag,
93
- and the only thing that tells a reader a cell navigates. Kept off the
94
- resting state deliberately: a column painted blue competes with the data.
95
- (No backticks in here: this is inside a template literal.) */
96
- .malloy-render .${g} {
97
- cursor: pointer;
98
- }
99
- .malloy-render .${g}:hover > .cell-content {
100
- color: var(--publisher-drill-link) !important;
101
- text-decoration: underline;
102
- }
103
- /* Keyboard focus reads the same as hover, plus a ring: a hover colour is not
104
- something a keyboard user can produce, and a focus ring is not something a
105
- mouse user sees. focus-visible rather than focus, so a click does not leave a
106
- ring behind it. (No backticks in here: this is inside a template literal.) */
107
- .malloy-render .${g}:focus-visible {
108
- outline: 2px solid var(--publisher-drill-link);
109
- outline-offset: -2px;
110
- }
111
- .malloy-render .${g}:focus-visible > .cell-content {
112
- color: var(--publisher-drill-link) !important;
113
- text-decoration: underline;
114
- }
115
- `,se="publisher-malloy-renderer-overrides";function Oe(){if(typeof document>"u"||document.getElementById(se))return;const e=document.createElement("style");e.id=se,e.textContent=De,document.head.appendChild(e)}function Te({result:e,height:r,drill:t,onSizeChange:n,onSizing:o}){const a=p.useRef(null),l=p.useRef(t);l.current=t;const s=p.useCallback(c=>{l.current?.onClick(c)},[]),y=t!==void 0,h=p.useRef(!1),k=p.useRef(null),E=p.useRef(0),{theme:Y,layers:J,mode:W}=X.usePublisherTheme(),Q=U.useTheme().shape.borderRadius,Z=p.useMemo(()=>({radius:`${Q}px`,padding:`${v.DASHBOARD_CARD_PADDING_PX}px`}),[Q]);return p.useEffect(()=>()=>{E.current+=1;const c=k.current;c?.viz.remove(),c?.node.remove(),k.current=null},[]),p.useLayoutEffect(()=>{if(!a.current||!e)return;Oe();const c=a.current,fe=E.current+=1;let P=!1;const q=()=>!P&&fe===E.current;let d,m,I=null,V=0,N=null,j=null,$=null,L=null,_=null,z=null,ee=null,re=0,S=null;h.current=!1;let w,A;const H=R=>{if(P||!R.firstElementChild||v.resultSizing(w,A)==="container")return;const F=v.remeasuresAfterReady(w,A);if(h.current&&!F)return;const C=v.measureContentHeight(R,v.contentNodeDepth(w));C>0&&(h.current=!0,n&&C!==re&&(re=C,n(C)));const D=v.contentNode(R,v.contentNodeDepth(w));F&&D&&ee!==D&&(ee=D,z?.disconnect(),z=new ResizeObserver(()=>H(R)),z.observe(D))};return(async()=>{let R;try{R=JSON.parse(e)}catch(f){console.error("Error parsing visualization result:",f);return}const F=await Se(R),C=F?X.resolveTheme([...J,F],W):Y;if(!q())return;try{m=await Ee(C,s)}catch(f){console.error("Failed to create renderer:",f);return}if(!q()){m.remove(),m=void 0;return}const D=k.current;d=document.createElement("div"),d.style.width="100%",d.style.height="100%",Ae(d,C,Z),c.childElementCount>0&&(c.style.position="relative",d.style.position="absolute",d.style.inset="0",d.style.visibility="hidden"),c.appendChild(d);const u=d;L=new MutationObserver(()=>{_&&clearTimeout(_),_=setTimeout(()=>{H(u),h.current&&L?.disconnect()},100)}),L.observe(d,{childList:!0,subtree:!0,attributes:!0});const ye=m;let te=!1;const oe=()=>{if(!(te||!q())){te=!0,S&&(clearTimeout(S),S=null),D?.viz.remove();for(const f of Array.from(c.children))f!==u&&c.removeChild(f);u.style.position="",u.style.inset="",u.style.visibility="",c.style.position="",k.current={viz:ye,node:u},H(u)}};try{m.setResult(R);try{const x=m.getMetadata(),O=x?.getRootField();w=O?.renderAs(),A=O?x?.getPluginsForField(O.key)?.[0]?.sizingStrategy:void 0}catch{w=void 0,A=void 0}o?.(v.resultSizing(w,A)),d.dataset.malloyRenderAs=w??"unknown",d.dataset.malloySizing=v.resultSizing(w,A),m.render(d);const f=l.current;try{if(f){const x=de(m,f.canDrill),O=()=>{try{ce(u,x)}catch(i){console.warn("Drill affordance skipped:",i)}};O();const ne=i=>{const T=i.querySelector(".cell-content")??i,K=T.getBoundingClientRect();T.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:T.ownerDocument.defaultView,clientX:Math.round(K.left+K.width/2),clientY:Math.round(K.bottom)}))},ae=i=>i.target?.closest?.(`.${g}`)??null,pe=(i,b)=>{ie(i,b)?.focus()};N=i=>{const b=ae(i);if(!b)return;const T=i.key==="ArrowDown"?1:i.key==="ArrowUp"?-1:i.key==="Home"?"first":i.key==="End"?"last":void 0;if(T!==void 0){i.preventDefault(),pe(b,T);return}i.key==="Enter"?(i.preventDefault(),ne(b)):i.key===" "&&i.preventDefault()},j=i=>{if(i.key!==" ")return;const b=ae(i);b&&(i.preventDefault(),ne(b))},$=i=>{const b=i.target?.closest?.(`.${g}`);b&&ie(b,0)},u.addEventListener("keydown",N),u.addEventListener("keyup",j),u.addEventListener("focusin",$),x.size>0&&typeof MutationObserver<"u"&&(I=new MutationObserver(()=>{cancelAnimationFrame(V),V=requestAnimationFrame(O)}),I.observe(u,{childList:!0,subtree:!0}))}}catch(x){console.warn("Drill affordance skipped:",x)}m.onReady(oe),S=setTimeout(oe,1e4)}catch(f){console.error("Error rendering visualization:",f),L?.disconnect(),z?.disconnect(),I?.disconnect(),m.remove(),m=void 0,u.parentNode===c&&c.removeChild(u)}})(),()=>{P=!0,L?.disconnect(),z?.disconnect(),_&&clearTimeout(_),S&&clearTimeout(S),d&&k.current?.node!==d&&(N&&d.removeEventListener("keydown",N),j&&d.removeEventListener("keyup",j),$&&d.removeEventListener("focusin",$),I?.disconnect(),cancelAnimationFrame(V),m?.remove(),d.parentNode===c&&c.removeChild(d),c.style.position="")}},[e,s,y,n,o,Y,J,W,Z]),B.jsx("div",{ref:a,style:{width:"100%",height:r?`${r}px`:"400px"}})}function be(e){return typeof window>"u"?B.jsx(U.Box,{sx:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:"Loading..."}):B.jsx(p.Suspense,{fallback:B.jsx(U.Box,{sx:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:"Loading visualization..."}),children:B.jsx(Te,{...e})})}const Le=Object.freeze(Object.defineProperty({__proto__:null,default:be},Symbol.toStringTag,{value:"Module"}));exports.DRILL_CELL_CLASS=g;exports.RenderedResult=be;exports.RenderedResult$1=Le;exports.buildMalloyExplicitTheme=ue;exports.buildVegaThemeOverride=he;exports.drillableFieldNames=de;exports.markDrillableCells=ce;exports.readChartAnnotations=me;