@malloy-publisher/sdk 0.9.13 → 0.9.15

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 (148) hide show
  1. package/dist/RenderedResult-BClN_PG6.cjs.js +154 -0
  2. package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
  3. package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
  4. package/dist/ServerProvider-e2369oom.cjs.js +1 -0
  5. package/dist/builder/index.cjs.js +80 -79
  6. package/dist/builder/index.es.js +7430 -6548
  7. package/dist/client/api.d.ts +30 -6
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
  11. package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
  12. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  13. package/dist/components/Dashboard/index.d.ts +1 -1
  14. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  15. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
  18. package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
  19. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  20. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  21. package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
  22. package/dist/components/Report/Report.d.ts +7 -1
  23. package/dist/components/Report/ReportPage.d.ts +7 -0
  24. package/dist/components/Report/layoutRules.d.ts +45 -0
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  26. package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
  27. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  28. package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
  29. package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
  30. package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
  31. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  32. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  33. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  34. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  35. package/dist/components/ReportBuilder/document.d.ts +53 -5
  36. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  37. package/dist/components/ReportBuilder/placement.d.ts +75 -0
  38. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  39. package/dist/components/ReportBuilder/sortable.d.ts +3 -1
  40. package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
  41. package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
  42. package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
  43. package/dist/index.cjs.js +7 -7
  44. package/dist/index.es.js +3328 -3287
  45. package/dist/text/index.es.js +1 -1
  46. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  47. package/dist/theme/resolveTheme.d.ts +15 -0
  48. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
  49. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
  50. package/dist/utils/blankQuoted.d.ts +15 -0
  51. package/package.json +1 -1
  52. package/src/components/Dashboard/DashboardGrid.tsx +127 -10
  53. package/src/components/Dashboard/DashboardTile.tsx +11 -1
  54. package/src/components/Dashboard/DashboardView.tsx +63 -10
  55. package/src/components/Dashboard/TileCard.tsx +6 -0
  56. package/src/components/Dashboard/index.ts +1 -0
  57. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  58. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  59. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  60. package/src/components/Dashboard/useStuck.ts +76 -28
  61. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  62. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  63. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  64. package/src/components/RenderedResult/RenderedResult.tsx +21 -6
  65. package/src/components/RenderedResult/ResultContainer.tsx +60 -7
  66. package/src/components/RenderedResult/ResultPanel.tsx +21 -1
  67. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  68. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  69. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  70. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  71. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  72. package/src/components/RenderedResult/resultSizing.ts +65 -11
  73. package/src/components/Report/Report.spec.tsx +19 -0
  74. package/src/components/Report/Report.tsx +8 -1
  75. package/src/components/Report/ReportPage.tsx +13 -1
  76. package/src/components/Report/layoutRules.spec.ts +43 -3
  77. package/src/components/Report/layoutRules.ts +70 -0
  78. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  79. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  80. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  81. package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
  82. package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
  83. package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
  84. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  85. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  86. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  87. package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
  88. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  89. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  90. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  91. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  92. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  93. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
  94. package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
  95. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  96. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  97. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
  98. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  99. package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
  100. package/src/components/ReportBuilder/TileFrame.tsx +251 -6
  101. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  102. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  103. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  104. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  105. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  106. package/src/components/ReportBuilder/catalog.ts +90 -37
  107. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  108. package/src/components/ReportBuilder/chartLine.ts +80 -2
  109. package/src/components/ReportBuilder/controls.ts +4 -3
  110. package/src/components/ReportBuilder/document.ts +65 -7
  111. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  112. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  113. package/src/components/ReportBuilder/imports.ts +1 -1
  114. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  115. package/src/components/ReportBuilder/layout.ts +3 -0
  116. package/src/components/ReportBuilder/placement.spec.ts +193 -0
  117. package/src/components/ReportBuilder/placement.ts +250 -0
  118. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  119. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  120. package/src/components/ReportBuilder/preview.ts +203 -40
  121. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  122. package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
  123. package/src/components/ReportBuilder/readDocument.ts +194 -23
  124. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  125. package/src/components/ReportBuilder/sortable.tsx +4 -0
  126. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  127. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  128. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  129. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
  130. package/src/components/ReportBuilder/spliceDocument.ts +139 -52
  131. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  132. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  133. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  134. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  135. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  136. package/src/components/ReportBuilder/useTileHeight.ts +149 -0
  137. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  138. package/src/components/ReportBuilder/useTileResize.ts +16 -1
  139. package/src/components/given/FilterButton.spec.tsx +27 -11
  140. package/src/components/given/FilterButton.tsx +19 -6
  141. package/src/theme/resolveTheme.spec.ts +72 -1
  142. package/src/theme/resolveTheme.ts +43 -0
  143. package/src/utils/blankQuoted.spec.ts +50 -0
  144. package/src/utils/blankQuoted.ts +32 -0
  145. package/src/utils/malloyText.ts +2 -1
  146. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  147. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  148. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
@@ -4,46 +4,94 @@
4
4
  import { useCallback, useRef, useState } from "react";
5
5
 
6
6
  /**
7
- * How far above the scroller's edge a pinned bar sits: one pixel, so the bar
8
- * is clipped by exactly that pixel while pinned and whole while it is not,
9
- * which is what {@link useStuck} observes.
7
+ * How far above its pinning line a pinned bar sits: one pixel, so the bar's
8
+ * edge meets whatever is pinned above it (the scroller's edge, or a host's own
9
+ * pinned bar) with no hairline of content showing between them.
10
10
  */
11
11
  export const STUCK_TOP_PX = -1;
12
12
 
13
13
  /**
14
- * Whether a `position: sticky` bar (pinned at `top: {@link STUCK_TOP_PX}px`)
15
- * is currently pinned, so it can draw an edge only while content scrolls under
16
- * it. Unpinned, the bar sits in the flow and an edge would be a stray line
17
- * between it and the first tile.
14
+ * The nearest ancestor that scrolls, or undefined when the page itself does.
18
15
  *
19
- * Observes the bar itself: pinned, its top pixel is clipped by the scroller,
20
- * so less than all of it is visible. No sentinel element, which as a sibling
21
- * in a `gap` layout cost the page a gap of its own above the bar. No explicit
22
- * root, so it works whichever ancestor scrolls: an observer with the implicit
23
- * root counts clipping by every scrolling ancestor, not just the viewport.
16
+ * Stops below `body`. A host's `html { overflow-y: scroll }` or
17
+ * `body { overflow-x: hidden }` (which computes `overflow-y: auto`) makes
18
+ * either look like a scroller, but the page's scroll events fire on the
19
+ * document and neither element's `scrollTop` moves, so the bar would never
20
+ * count as pinned.
21
+ */
22
+ function scrollerOf(node: HTMLElement): HTMLElement | undefined {
23
+ const page = node.ownerDocument;
24
+ for (
25
+ let at = node.parentElement;
26
+ at && at !== page.body && at !== page.documentElement;
27
+ at = at.parentElement
28
+ ) {
29
+ if (/(auto|scroll|overlay)/.test(getComputedStyle(at).overflowY))
30
+ return at;
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ /**
36
+ * Whether a `position: sticky` bar is pinned now: the content under it has
37
+ * scrolled, and the bar sits at its pinning line (its computed `top`, below the
38
+ * scroller's top edge) rather than lower down in the flow.
39
+ */
40
+ export function isPinned(
41
+ node: HTMLElement,
42
+ scroller: HTMLElement | undefined,
43
+ ): boolean {
44
+ const scrolled = scroller ? scroller.scrollTop : window.scrollY;
45
+ if (scrolled <= 0) return false;
46
+ const top = parseFloat(getComputedStyle(node).top);
47
+ if (Number.isNaN(top)) return false;
48
+ const edge = scroller
49
+ ? scroller.getBoundingClientRect().top + scroller.clientTop
50
+ : 0;
51
+ return node.getBoundingClientRect().top - edge <= top + 0.5;
52
+ }
53
+
54
+ /**
55
+ * Whether a `position: sticky` bar is currently pinned, so it can draw a fill
56
+ * and an edge only while content scrolls under it. Unpinned, the bar sits in
57
+ * the flow and an edge would be a stray line between it and the first tile.
58
+ *
59
+ * Measured on scroll, against the bar's own pinning line. It used to watch for
60
+ * the bar's top pixel being clipped by the scroller, which holds only for a bar
61
+ * pinned at the scroller's edge: a host that pins its own bar above the report
62
+ * (`--publisher-sticky-top`) pins this one lower, where nothing clips it. The
63
+ * bar then never counted as pinned, stayed transparent, and its controls were
64
+ * drawn over the tile titles scrolling under it.
24
65
  */
25
66
  export function useStuck(): {
26
67
  stickyRef: (node: HTMLElement | null) => void;
27
68
  stuck: boolean;
28
69
  } {
29
70
  const [stuck, setStuck] = useState(false);
30
- const observer = useRef<IntersectionObserver | null>(null);
71
+ const detach = useRef<(() => void) | null>(null);
31
72
  const stickyRef = useCallback((node: HTMLElement | null) => {
32
- observer.current?.disconnect();
33
- observer.current = null;
34
- if (!node || typeof IntersectionObserver === "undefined") return;
35
- observer.current = new IntersectionObserver(
36
- ([entry]) => {
37
- if (!entry) return;
38
- // Partly hidden BELOW the fold is not pinned: only clipped at the top.
39
- const atTop =
40
- entry.boundingClientRect.top <
41
- (entry.rootBounds?.height ?? window.innerHeight) / 2;
42
- setStuck(entry.intersectionRatio < 1 && atTop);
43
- },
44
- { threshold: [1] },
45
- );
46
- observer.current.observe(node);
73
+ detach.current?.();
74
+ detach.current = null;
75
+ if (!node || typeof window === "undefined") return;
76
+ const scroller = scrollerOf(node);
77
+ const target: HTMLElement | Window = scroller ?? window;
78
+ let frame = 0;
79
+ const measure = () => {
80
+ frame = 0;
81
+ setStuck(isPinned(node, scroller));
82
+ };
83
+ // One measurement a frame, however many scroll events land in it.
84
+ const schedule = () => {
85
+ if (frame === 0) frame = requestAnimationFrame(measure);
86
+ };
87
+ target.addEventListener("scroll", schedule, { passive: true });
88
+ window.addEventListener("resize", schedule);
89
+ measure();
90
+ detach.current = () => {
91
+ target.removeEventListener("scroll", schedule);
92
+ window.removeEventListener("resize", schedule);
93
+ if (frame !== 0) cancelAnimationFrame(frame);
94
+ };
47
95
  }, []);
48
96
  return { stickyRef, stuck };
49
97
  }
@@ -195,7 +195,9 @@ describe("NewDocumentDialog", () => {
195
195
  onCreated,
196
196
  });
197
197
  await titleFilled("By category");
198
- expect(screen.getByRole("listbox", { name: "Views" })).toBeDefined();
198
+ expect(
199
+ screen.getByRole("listbox", { name: "From the model" }),
200
+ ).toBeDefined();
199
201
 
200
202
  fireEvent.click(screen.getByRole("button", { name: "Create report" }));
201
203
  await waitFor(() => expect(onCreated).toHaveBeenCalledTimes(1));
@@ -345,7 +347,7 @@ describe("NewDocumentDialog", () => {
345
347
  expect(
346
348
  screen
347
349
  .getByRole("button", {
348
- name: "Create report: No model view to start from yet",
350
+ name: "Create report: Nothing in the model to start from yet",
349
351
  })
350
352
  .hasAttribute("disabled"),
351
353
  ).toBe(true);
@@ -494,7 +496,7 @@ describe("NewDocumentDialog: a model it could not read", () => {
494
496
  mount();
495
497
  expect(
496
498
  await screen.findByText(
497
- "Couldn't read storefront.malloy, so its views aren't listed.",
499
+ "Couldn't read storefront.malloy, so nothing from it is listed.",
498
500
  ),
499
501
  ).toBeDefined();
500
502
  expect(
@@ -503,7 +505,7 @@ describe("NewDocumentDialog: a model it could not read", () => {
503
505
  expect(
504
506
  isDisabled(
505
507
  createButton(
506
- "Create report: Couldn't read the model views to start from",
508
+ "Create report: Couldn't read the model to start from",
507
509
  ),
508
510
  ),
509
511
  ).toBe(true);
@@ -520,7 +522,7 @@ describe("NewDocumentDialog: a model it could not read", () => {
520
522
  mount();
521
523
  expect(
522
524
  await screen.findByText(
523
- "Couldn't read storefront.malloy, other.malloy, so their views aren't listed.",
525
+ "Couldn't read storefront.malloy, other.malloy, so nothing from them is listed.",
524
526
  ),
525
527
  ).toBeDefined();
526
528
  });
@@ -535,7 +537,7 @@ describe("NewDocumentDialog: a model it could not read", () => {
535
537
  await titleFilled("By category");
536
538
  expect(
537
539
  await screen.findByText(
538
- "Couldn't read other.malloy, so its views aren't listed.",
540
+ "Couldn't read other.malloy, so nothing from it is listed.",
539
541
  ),
540
542
  ).toBeDefined();
541
543
  expect(isDisabled(createButton("Create report"))).toBe(false);
@@ -563,20 +565,20 @@ describe("NewDocumentDialog: why Create is off", () => {
563
565
  it("while the views load, in its name and its tooltip", async () => {
564
566
  getModel.mockImplementation(() => pending());
565
567
  mount();
566
- const button = createButton("Create report: Loading model views");
568
+ const button = createButton("Create report: Loading the model");
567
569
  expect(isDisabled(button)).toBe(true);
568
570
  fireEvent.mouseOver(button.parentElement!);
569
571
  expect((await screen.findByRole("tooltip")).textContent).toBe(
570
- "Loading model views",
572
+ "Loading the model",
571
573
  );
572
574
  });
573
575
 
574
576
  it("while the host still lists the models, not that the package has none", () => {
575
577
  mount({ models: [], modelsLoading: true });
576
578
  expect(screen.queryByText(/This package has no models yet/)).toBeNull();
577
- expect(
578
- isDisabled(createButton("Create report: Loading model views")),
579
- ).toBe(true);
579
+ expect(isDisabled(createButton("Create report: Loading the model"))).toBe(
580
+ true,
581
+ );
580
582
  });
581
583
 
582
584
  it("when the host could not list the models, with its Retry", () => {
@@ -595,7 +597,7 @@ describe("NewDocumentDialog: why Create is off", () => {
595
597
  expect(
596
598
  isDisabled(
597
599
  createButton(
598
- "Create report: Couldn't read the model views to start from",
600
+ "Create report: Couldn't read the model to start from",
599
601
  ),
600
602
  ),
601
603
  ).toBe(true);
@@ -622,7 +624,7 @@ describe("NewDocumentDialog: why Create is off", () => {
622
624
  expect(
623
625
  isDisabled(
624
626
  createButton(
625
- "Create report: Couldn't read the model views to start from",
627
+ "Create report: Couldn't read the model to start from",
626
628
  ),
627
629
  ),
628
630
  ).toBe(true);
@@ -633,7 +635,9 @@ describe("NewDocumentDialog: why Create is off", () => {
633
635
  await screen.findByText(/no model in this package declares one yet/);
634
636
  expect(
635
637
  isDisabled(
636
- createButton("Create report: No model view to start from yet"),
638
+ createButton(
639
+ "Create report: Nothing in the model to start from yet",
640
+ ),
637
641
  ),
638
642
  ).toBe(true);
639
643
  });
@@ -729,12 +733,12 @@ describe("NewDocumentDialog: the picked view", () => {
729
733
  reread(view, "dropped");
730
734
  expect(
731
735
  await screen.findByText(
732
- "The view you picked is no longer in this model; pick another.",
736
+ "What you picked is no longer in this model; pick something else.",
733
737
  ),
734
738
  ).toBeDefined();
735
739
  expect(pickedView()).not.toContain("by_category");
736
740
  expect(
737
- isDisabled(createButton("Create report: Pick a view to start from")),
741
+ isDisabled(createButton("Create report: Pick what to start from")),
738
742
  ).toBe(true);
739
743
  });
740
744
  });
@@ -281,13 +281,13 @@ export function NewDocumentDialog({
281
281
  const unread = choices.size === 0 && (modelsFailed || failed.length > 0);
282
282
  // Create is off only when nothing typed could make it succeed; the title is checked on press.
283
283
  const blocked = loading
284
- ? "Loading model views"
284
+ ? "Loading the model"
285
285
  : unread
286
- ? "Couldn't read the model views to start from"
286
+ ? "Couldn't read the model to start from"
287
287
  : choices.size === 0
288
- ? "No model view to start from yet"
288
+ ? "Nothing in the model to start from yet"
289
289
  : chosen === undefined
290
- ? "Pick a view to start from"
290
+ ? "Pick what to start from"
291
291
  : undefined;
292
292
  const label = "report";
293
293
  const createLabel = busy ? `Creating ${label}…` : `Create ${label}`;
@@ -342,7 +342,7 @@ export function NewDocumentDialog({
342
342
  // A write in flight is not abandoned by Escape or a backdrop click.
343
343
  onClose={busy ? () => {} : onClose}
344
344
  title={`New ${label}`}
345
- description="A report is a Malloy file in the package that lays out text and queries. Pick the view its first query shows; the rest is the builder."
345
+ description="A report is a Malloy file in the package that lays out text and queries. Pick what its first query shows; the rest is the builder."
346
346
  actions={
347
347
  <>
348
348
  <Button onClick={onClose} disabled={busy}>
@@ -394,9 +394,8 @@ export function NewDocumentDialog({
394
394
  severity="warning"
395
395
  action={canRetry ? retryButton(retry) : undefined}
396
396
  >
397
- Couldn&apos;t read {failed.join(", ")}, so{" "}
398
- {failed.length === 1 ? "its" : "their"} views aren&apos;t
399
- listed.
397
+ Couldn&apos;t read {failed.join(", ")}, so nothing from{" "}
398
+ {failed.length === 1 ? "it" : "them"} is listed.
400
399
  </Alert>
401
400
  ) : (
402
401
  isSuccess &&
@@ -450,7 +449,7 @@ export function NewDocumentDialog({
450
449
  >
451
450
  {loading
452
451
  ? "Reading the package's models…"
453
- : "No view to start from."}
452
+ : "Nothing to start from."}
454
453
  </Typography>
455
454
  }
456
455
  />
@@ -547,8 +546,8 @@ export function NewDocumentDialog({
547
546
  sx={{ color: "text.secondary", m: "auto" }}
548
547
  >
549
548
  {picked
550
- ? "The view you picked is no longer in this model; pick another."
551
- : "Pick a view to start from."}
549
+ ? "What you picked is no longer in this model; pick something else."
550
+ : "Pick what to start from."}
552
551
  </Typography>
553
552
  )}
554
553
  </Box>
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { act, render, waitFor } from "@testing-library/react";
5
5
  import { beforeEach, describe, expect, it, mock } from "bun:test";
6
+ import { resolveTheme } from "../../theme/resolveTheme";
6
7
 
7
8
  /**
8
9
  * The renderer's STAGE LIFECYCLE, which is the part of this component that has
@@ -31,8 +32,17 @@ import { beforeEach, describe, expect, it, mock } from "bun:test";
31
32
  * test's control so a render can be held mid-flight.
32
33
  */
33
34
 
35
+ /** What the fake renderer reports the root draws as; undefined reports no metadata. */
36
+ let rootRenderAs: string | undefined;
37
+
34
38
  /** Every viz the component has created, in order. */
35
39
  const vizzes: FakeViz[] = [];
40
+ /** The options each renderer was built with, in order. */
41
+ const rendererOptions: Array<{
42
+ vegaConfigOverride?: (chartType: string) => {
43
+ range?: { category?: string[] };
44
+ };
45
+ }> = [];
36
46
 
37
47
  class FakeViz {
38
48
  /** The stage it was told to paint into. */
@@ -43,7 +53,11 @@ class FakeViz {
43
53
  paint() {
44
54
  this.ready?.();
45
55
  }
46
- setResult() {}
56
+ /** What the component handed the renderer. */
57
+ result: unknown;
58
+ setResult(result: unknown) {
59
+ this.result = result;
60
+ }
47
61
  render(element: HTMLElement) {
48
62
  this.stage = element;
49
63
  const painted = document.createElement("div");
@@ -57,7 +71,13 @@ class FakeViz {
57
71
  this.ready = callback;
58
72
  }
59
73
  getMetadata() {
60
- return null;
74
+ const renderAs = rootRenderAs;
75
+ return renderAs === undefined
76
+ ? null
77
+ : {
78
+ getRootField: () => ({ key: "root", renderAs: () => renderAs }),
79
+ getPluginsForField: () => [],
80
+ };
61
81
  }
62
82
  getDrillMetadata() {
63
83
  return null;
@@ -66,6 +86,9 @@ class FakeViz {
66
86
 
67
87
  mock.module("@malloydata/render", () => ({
68
88
  MalloyRenderer: class {
89
+ constructor(options: (typeof rendererOptions)[number]) {
90
+ rendererOptions.push(options);
91
+ }
69
92
  createViz() {
70
93
  const viz = new FakeViz();
71
94
  vizzes.push(viz);
@@ -75,6 +98,9 @@ mock.module("@malloydata/render", () => ({
75
98
  }));
76
99
 
77
100
  const RenderedResult = (await import("./RenderedResult")).default;
101
+ const { INITIAL_RENDER_HEIGHT, LINEAR_TABLE_MAX_HEIGHT } = await import(
102
+ "./resultSizing"
103
+ );
78
104
 
79
105
  /** A minimal result payload; the fake renderer never reads it. */
80
106
  const RESULT = JSON.stringify({ tag: "a" });
@@ -91,6 +117,8 @@ const stagesIn = (container: HTMLElement): Element[] => {
91
117
 
92
118
  beforeEach(() => {
93
119
  vizzes.length = 0;
120
+ rendererOptions.length = 0;
121
+ rootRenderAs = undefined;
94
122
  });
95
123
 
96
124
  describe("RenderedResult: the stage lifecycle", () => {
@@ -196,3 +224,140 @@ describe("RenderedResult: the stage lifecycle", () => {
196
224
  expect(vizzes[0].removed).toBe(true);
197
225
  });
198
226
  });
227
+
228
+ describe("RenderedResult: how a chart reads", () => {
229
+ const barResult = (rows: number) =>
230
+ JSON.stringify({
231
+ annotations: [{ value: "# bar_chart\n" }],
232
+ schema: {
233
+ fields: [
234
+ { kind: "dimension", name: "carrier", annotations: [] },
235
+ { kind: "dimension", name: "flight_count", annotations: [] },
236
+ ],
237
+ },
238
+ data: {
239
+ kind: "array_cell",
240
+ array_value: Array.from({ length: rows }),
241
+ },
242
+ });
243
+
244
+ it("hands the renderer a chart whose unlabelled fields are titled", async () => {
245
+ rootRenderAs = "bar";
246
+ render(<RenderedResult result={barResult(3)} />);
247
+ await waitFor(() => expect(vizzes).toHaveLength(1));
248
+ await waitFor(() => expect(vizzes[0].result).toBeDefined());
249
+ const fields = (
250
+ vizzes[0].result as {
251
+ schema: {
252
+ fields: Array<{ annotations: Array<{ value: string }> }>;
253
+ };
254
+ }
255
+ ).schema.fields;
256
+ expect(fields[1].annotations[0].value).toBe('# label="Flight count"\n');
257
+ });
258
+
259
+ it("draws a many-bar chart wide enough for every bar, scrolling sideways", async () => {
260
+ rootRenderAs = "bar";
261
+ const view = render(<RenderedResult result={barResult(80)} />);
262
+ await waitFor(() => expect(vizzes).toHaveLength(1));
263
+ await waitFor(() => expect(vizzes[0].stage).not.toBeNull());
264
+ const stage = vizzes[0].stage!;
265
+ expect(parseInt(stage.style.minWidth, 10)).toBeGreaterThanOrEqual(640);
266
+ const box = view.container.firstElementChild as HTMLElement;
267
+ expect(box.style.overflowX).toBe("auto");
268
+ });
269
+
270
+ it("leaves a table's width to its box", async () => {
271
+ rootRenderAs = "table";
272
+ const view = render(<RenderedResult result={barResult(80)} />);
273
+ await waitFor(() => expect(vizzes).toHaveLength(1));
274
+ await waitFor(() => expect(vizzes[0].stage).not.toBeNull());
275
+ expect(vizzes[0].stage!.style.minWidth).toBe("");
276
+ const box = view.container.firstElementChild as HTMLElement;
277
+ expect(box.style.overflowX).toBe("");
278
+ });
279
+ });
280
+
281
+ describe("RenderedResult: a chart's own colour", () => {
282
+ // The builder's Color item writes one colour above the view. A bar and line
283
+ // chart draws its line from the second series colour, so a one-colour list
284
+ // painted the line the same colour as the bars.
285
+ it("sets the first series and keeps the second distinct", async () => {
286
+ const combo = JSON.stringify({
287
+ annotations: [
288
+ { value: "# combo_chart\n" },
289
+ { value: '# theme.palette.series=["#7f9862"]\n' },
290
+ ],
291
+ schema: { fields: [] },
292
+ data: { kind: "array_cell", array_value: [] },
293
+ });
294
+ render(<RenderedResult result={combo} />);
295
+ await waitFor(() => expect(rendererOptions).toHaveLength(1));
296
+ const category =
297
+ rendererOptions[0].vegaConfigOverride?.("combo_chart")?.range
298
+ ?.category;
299
+ expect(category?.[0]).toBe("#7f9862");
300
+ expect(category?.[1]).toBeDefined();
301
+ expect(category?.[1]).not.toBe("#7f9862");
302
+ });
303
+
304
+ // The builder previews a tile set back to Theme by running its saved view,
305
+ // which still carries the colour it was saved with, under a line that takes
306
+ // that colour off. The chart must draw the theme's own series.
307
+ it("draws the theme's series when a later line takes a saved colour off", async () => {
308
+ const combo = JSON.stringify({
309
+ annotations: [
310
+ { value: '# theme.palette.series=["#7f9862"]\n' },
311
+ { value: "# combo_chart\n" },
312
+ { value: "# -theme.palette.series\n" },
313
+ ],
314
+ schema: { fields: [] },
315
+ data: { kind: "array_cell", array_value: [] },
316
+ });
317
+ render(<RenderedResult result={combo} />);
318
+ await waitFor(() => expect(rendererOptions).toHaveLength(1));
319
+ const category =
320
+ rendererOptions[0].vegaConfigOverride?.("combo_chart")?.range
321
+ ?.category;
322
+ expect(category).toEqual(resolveTheme([], "light").series);
323
+ });
324
+ });
325
+
326
+ // Through `ResultContainer`, which lazy-loads this same faked module. The box
327
+ // the renderer paints into is what a long table scrolls inside, under its
328
+ // pinned header row, so its height is the cap a reader sees.
329
+ describe("ResultContainer: a linear report's table cap", () => {
330
+ const paintedHeight = async (renderAs: string) => {
331
+ rootRenderAs = renderAs;
332
+ const ResultContainer = (await import("./ResultContainer")).default;
333
+ const view = render(
334
+ <ResultContainer
335
+ result={RESULT}
336
+ fill
337
+ tableMaxHeight={LINEAR_TABLE_MAX_HEIGHT}
338
+ />,
339
+ );
340
+ // The cap applies once the renderer has said what the root is, which
341
+ // it publishes on the stage.
342
+ const stage = () =>
343
+ view.container.querySelector(
344
+ `[data-malloy-render-as="${renderAs}"]`,
345
+ ) as HTMLElement | null;
346
+ await waitFor(() => expect(stage()).not.toBeNull());
347
+ await act(async () => vizzes.at(-1)!.paint());
348
+ const height = (stage()!.parentElement as HTMLElement).style.height;
349
+ view.unmount();
350
+ return height;
351
+ };
352
+
353
+ it("holds a table to the cap", async () => {
354
+ expect(await paintedHeight("table")).toBe(`${LINEAR_TABLE_MAX_HEIGHT}px`);
355
+ });
356
+
357
+ // A KPI row that wraps one card per line must still show every card.
358
+ it("lets a KPI row grow past it", async () => {
359
+ expect(await paintedHeight("big_value")).toBe(
360
+ `${INITIAL_RENDER_HEIGHT}px`,
361
+ );
362
+ });
363
+ });
@@ -26,9 +26,10 @@ import {
26
26
  type ResultSizing,
27
27
  } from "./resultSizing";
28
28
  import { readChartAnnotations } from "../../theme/readChartAnnotations";
29
- import { resolveTheme } from "../../theme/resolveTheme";
29
+ import { chartThemeLayer, resolveTheme } from "../../theme/resolveTheme";
30
30
  import { usePublisherTheme } from "../../theme/ThemeContext";
31
31
  import { loadMalloyRenderer } from "./loadRenderer";
32
+ import { chartMinWidth, labelChartFields } from "./chartPresentation";
32
33
  import type { ResolvedTheme } from "../../theme/types";
33
34
  import {
34
35
  DRILL_CELL_CLASS,
@@ -99,9 +100,10 @@ interface RenderedResultProps {
99
100
  /**
100
101
  * Which sizing rule the rendered root follows, as soon as the renderer's
101
102
  * metadata says. Lets a caller stop treating its cap as a height for a
102
- * result that will never report one.
103
+ * result that will never report one. `renderAs` is the root's render type,
104
+ * which tells a caller with a table-only cap whether it applies.
103
105
  */
104
- onSizing?: (sizing: ResultSizing) => void;
106
+ onSizing?: (sizing: ResultSizing, renderAs: string | undefined) => void;
105
107
  /**
106
108
  * Makes `# drill` cells clickable, and makes them look it. From `useDrill`
107
109
  * on the host surface, which decides where a click may go; omitted where
@@ -565,7 +567,7 @@ function RenderedResultInner({
565
567
 
566
568
  const perChart = await extractChartThemeOverride(parsed);
567
569
  const effectiveTheme = perChart
568
- ? resolveTheme([...layers, perChart], mode)
570
+ ? resolveTheme([...layers, chartThemeLayer(layers, perChart)], mode)
569
571
  : baseTheme;
570
572
 
571
573
  if (!isCurrent()) return;
@@ -663,7 +665,9 @@ function RenderedResultInner({
663
665
  try {
664
666
  // The renderer accepts a Malloy Result; we don't import that type
665
667
  // in the SDK to avoid pinning to the malloy core types here.
666
- viz.setResult(parsed);
668
+ // A chart's unlabelled fields titled the way a reader says them;
669
+ // see `chartPresentation`.
670
+ viz.setResult(labelChartFields(parsed));
667
671
  // Read the root's render type before painting, so the first
668
672
  // measurement already knows whether it is worth taking. Metadata is
669
673
  // complete as soon as the result is set; the DOM is not.
@@ -683,7 +687,7 @@ function RenderedResultInner({
683
687
  renderAs = undefined;
684
688
  strategy = undefined;
685
689
  }
686
- onSizing?.(resultSizing(renderAs, strategy));
690
+ onSizing?.(resultSizing(renderAs, strategy), renderAs);
687
691
  // Published on the stage because every sizing decision keys off it
688
692
  // and nothing else in the DOM says what it was. A panel at an
689
693
  // unexpected height is otherwise a guessing game about which rule
@@ -691,6 +695,17 @@ function RenderedResultInner({
691
695
  // — that the rendered markup does not spell out anywhere.
692
696
  stage.dataset.malloyRenderAs = renderAs ?? "unknown";
693
697
  stage.dataset.malloySizing = resultSizing(renderAs, strategy);
698
+ // A plotted chart is drawn no narrower than it reads, and its
699
+ // panel scrolls sideways past that, rather than squeezing it until
700
+ // the renderer drops bars under "Showing limited results".
701
+ const minWidth = chartMinWidth(renderAs, parsed);
702
+ stage.style.minWidth =
703
+ minWidth === undefined ? "" : `${minWidth}px`;
704
+ // Only a chart scrolls here, and only sideways: anything taller
705
+ // than its box is the panel's to scroll, which an overflow set on
706
+ // this box would take over on both axes.
707
+ element.style.overflowX = minWidth === undefined ? "" : "auto";
708
+ element.style.overflowY = minWidth === undefined ? "" : "hidden";
694
709
  viz.render(stage);
695
710
 
696
711
  // Mark the cells a `# drill` makes clickable, so they read as