@malloy-publisher/sdk 0.9.15 → 0.9.16

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 (65) hide show
  1. package/dist/{RenderedResult-BClN_PG6.cjs.js → RenderedResult-5hOs5XnV.cjs.js} +21 -4
  2. package/dist/{RenderedResult-YBzVMVH2.es.js → RenderedResult-DxmHGZNQ.es.js} +204 -187
  3. package/dist/builder/index.cjs.js +75 -75
  4. package/dist/builder/index.es.js +5329 -5193
  5. package/dist/builder-entry.d.ts +1 -1
  6. package/dist/client/api.d.ts +1 -1
  7. package/dist/components/Dashboard/DashboardGrid.d.ts +2 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
  9. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  10. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  11. package/dist/components/RenderedResult/resultSizing.d.ts +5 -0
  12. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  13. package/dist/components/ReportBuilder/BuilderGrid.d.ts +5 -7
  14. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  15. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  16. package/dist/components/ReportBuilder/TileFrame.d.ts +34 -22
  17. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  18. package/dist/components/ReportBuilder/placement.d.ts +48 -2
  19. package/dist/components/ReportBuilder/sortable.d.ts +9 -0
  20. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  21. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  22. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  23. package/dist/components/ReportBuilder/useTileReorder.d.ts +3 -0
  24. package/dist/index.cjs.js +5 -5
  25. package/dist/index.es.js +489 -488
  26. package/dist/theme/classes.d.ts +1 -1
  27. package/dist/{useCompiledDocument-BGk38oaW.es.js → useCompiledDocument-CaYP_OYG.es.js} +4021 -4007
  28. package/dist/{useCompiledDocument-D9t5ry_t.cjs.js → useCompiledDocument-zYEfLogf.cjs.js} +32 -32
  29. package/package.json +1 -1
  30. package/src/builder-entry.ts +1 -0
  31. package/src/components/Dashboard/DashboardGrid.tsx +2 -0
  32. package/src/components/Dashboard/DashboardTile.tsx +4 -0
  33. package/src/components/Dashboard/DashboardView.tsx +1 -0
  34. package/src/components/RenderedResult/RenderedResult.tsx +18 -0
  35. package/src/components/RenderedResult/ResultContainer.tsx +39 -3
  36. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  37. package/src/components/RenderedResult/resultSizing.ts +6 -0
  38. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  39. package/src/components/ReportBuilder/BuilderBar.tsx +4 -0
  40. package/src/components/ReportBuilder/BuilderDialogs.tsx +8 -1
  41. package/src/components/ReportBuilder/BuilderGrid.tsx +61 -60
  42. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  43. package/src/components/ReportBuilder/EditorSurface.tsx +9 -2
  44. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +99 -0
  45. package/src/components/ReportBuilder/ReportBuilder.tsx +110 -30
  46. package/src/components/ReportBuilder/TileFrame.tsx +261 -310
  47. package/src/components/ReportBuilder/builderControls.ts +34 -0
  48. package/src/components/ReportBuilder/placement.spec.ts +208 -0
  49. package/src/components/ReportBuilder/placement.ts +175 -9
  50. package/src/components/ReportBuilder/readDocument.spec.ts +7 -17
  51. package/src/components/ReportBuilder/readDocument.ts +3 -6
  52. package/src/components/ReportBuilder/sortable.tsx +26 -2
  53. package/src/components/ReportBuilder/spliceDocument.spec.ts +0 -40
  54. package/src/components/ReportBuilder/spliceDocument.ts +0 -39
  55. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  56. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  57. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  58. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  59. package/src/components/ReportBuilder/useTileReorder.ts +1 -1
  60. package/src/theme/classes.ts +1 -1
  61. package/dist/components/ReportBuilder/useTileHeight.d.ts +0 -39
  62. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -40
  63. package/src/components/ReportBuilder/useTileHeight.ts +0 -149
  64. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  65. package/src/components/ReportBuilder/useTileResize.ts +0 -148
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.9.15",
4
+ "version": "0.9.16",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -28,6 +28,7 @@ export {
28
28
  type BuilderBarProps,
29
29
  } from "./components/ReportBuilder/BuilderBar";
30
30
  export type {
31
+ ArrangeActions,
31
32
  BuilderControls,
32
33
  BuilderControlsHandler,
33
34
  } from "./components/ReportBuilder/builderControls";
@@ -62,6 +62,8 @@ export const TILE_ROW_PX = 80;
62
62
  * heading and axes, and the renderer failed on it. Prose fits in one.
63
63
  */
64
64
  export const MIN_TILE_ROWS = 3;
65
+ /** A query tile that draws no chart (value cards, a table) goes down to two rows. */
66
+ export const MIN_VALUE_TILE_ROWS = 2;
65
67
  export const MIN_TEXT_TILE_ROWS = 1;
66
68
  export const MAX_TILE_ROWS = 16;
67
69
 
@@ -73,6 +73,8 @@ export interface DashboardTileProps {
73
73
  height: number | undefined;
74
74
  /** A further cap when the result is a table, past which it scrolls under its pinned header. */
75
75
  tableMaxHeight?: number;
76
+ /** The tile has a set height (rows of its own): a result taller than it is drawn compact. */
77
+ fixedHeight?: boolean;
76
78
  maxResultSize?: number;
77
79
  /** Cell clicks and their affordance, for the dashboard's `# drill`. */
78
80
  drill?: DrillBinding;
@@ -146,6 +148,7 @@ export function DashboardTile({
146
148
  givenNames,
147
149
  height,
148
150
  tableMaxHeight,
151
+ fixedHeight,
149
152
  maxResultSize,
150
153
  drill,
151
154
  onExplore,
@@ -272,6 +275,7 @@ export function DashboardTile({
272
275
  context={tile ?? queryName ?? modelPath}
273
276
  maxHeight={height}
274
277
  tableMaxHeight={tableMaxHeight}
278
+ compactToFit={fixedHeight}
275
279
  // Uncapped in a linear report, a tile would first paint at the
276
280
  // 2000px default and collapse once measured. A grid tile's cap
277
281
  // is a sound first guess for every tile.
@@ -389,6 +389,7 @@ export function DashboardView({
389
389
  : tileMaxHeight
390
390
  }
391
391
  tableMaxHeight={tableMaxHeight}
392
+ fixedHeight={tile.rowspan !== undefined || placed}
392
393
  maxResultSize={maxResultSize}
393
394
  drill={drillFor(tile.query)}
394
395
  ignoredFilters={tileIgnoredFilterLabels(
@@ -24,6 +24,7 @@ import {
24
24
  remeasuresAfterReady,
25
25
  resultSizing,
26
26
  type ResultSizing,
27
+ TIGHT_ATTR,
27
28
  } from "./resultSizing";
28
29
  import { readChartAnnotations } from "../../theme/readChartAnnotations";
29
30
  import { chartThemeLayer, resolveTheme } from "../../theme/resolveTheme";
@@ -315,6 +316,23 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
315
316
  width: auto;
316
317
  max-width: none;
317
318
  }
319
+ /* Compact, in a tile set shorter than its cards (ResultContainer marks it tight): smaller values,
320
+ tighter cards and a 190px floor, which a 22px value still fits in, so five cards share a row of
321
+ about a thousand pixels instead of wrapping into rows the tile has no room for. */
322
+ [${TIGHT_ATTR}] .malloy-render .malloy-big-value:not(.malloy-big-value--embedded) {
323
+ grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
324
+ gap: 8px;
325
+ padding: 8px;
326
+ }
327
+ [${TIGHT_ATTR}] .malloy-render .malloy-big-value-card:not(.malloy-big-value-card--embedded) {
328
+ padding: 9px 14px;
329
+ }
330
+ [${TIGHT_ATTR}] .malloy-render .malloy-big-value-value {
331
+ font-size: 22px;
332
+ }
333
+ [${TIGHT_ATTR}] .malloy-render .malloy-big-value-label {
334
+ font-size: 11px;
335
+ }
318
336
  .malloy-render .malloy-dashboard .dashboard-row-header-separator {
319
337
  background: var(--malloy-render--table-border) !important;
320
338
  }
@@ -22,6 +22,7 @@ import {
22
22
  resolveResultHeight,
23
23
  resultCap,
24
24
  type ResultSizing,
25
+ TIGHT_ATTR,
25
26
  } from "./resultSizing";
26
27
 
27
28
  /** The box a dashboard tile's result scrolls in when it is taller than its cap. */
@@ -64,6 +65,13 @@ interface ResultContainerProps {
64
65
  * tile's card is. Leave it off wherever the result sets the surface's height.
65
66
  */
66
67
  fill?: boolean;
68
+ /**
69
+ * The cell's height is set (a tile given rows), not its content's: only
70
+ * then is a result taller than it drawn compact to fit. A cell that grows
71
+ * with its content is briefly shorter than a result that just grew, and
72
+ * compact there would be a mistake that never undoes itself.
73
+ */
74
+ compactToFit?: boolean;
67
75
  }
68
76
 
69
77
  // ResultContainer is a component that renders a result, with a toggle button to expand/collapse the result.
@@ -79,6 +87,7 @@ export default function ResultContainer({
79
87
  renderLogs,
80
88
  drill,
81
89
  fill = false,
90
+ compactToFit = false,
82
91
  }: ResultContainerProps) {
83
92
  const containerRef = useRef<HTMLDivElement>(null);
84
93
  // A result is here: start the renderer download if no panel already has.
@@ -107,13 +116,37 @@ export default function ResultContainer({
107
116
  useEffect(() => {
108
117
  const box = containerRef.current;
109
118
  if (!fill || !box) return;
110
- const observer = new ResizeObserver(([entry]) =>
111
- setCellHeight(Math.round(entry.contentRect.height)),
112
- );
119
+ const observer = new ResizeObserver(([entry]) => {
120
+ setCellHeight(Math.round(entry.contentRect.height));
121
+ setCellWidth(Math.round(entry.contentRect.width));
122
+ });
113
123
  observer.observe(box);
114
124
  return () => observer.disconnect();
115
125
  }, [fill, hasResult, userAcknowledged]);
116
126
 
127
+ // Tight: a content-sized result taller than the cell it fills (value cards
128
+ // in a tile set shorter than they are), drawn compact so it fits rather
129
+ // than scrolls. Held at the height it needed at full size, and let go only
130
+ // once the cell is that tall again: let go as soon as the compact result
131
+ // fit, it would grow back past the cell and the two would flicker.
132
+ const [tightFrom, setTightFrom] = useState<number | undefined>(undefined);
133
+ const [cellWidth, setCellWidth] = useState<number | undefined>(undefined);
134
+ const mayTighten = fill && compactToFit && sizing === "content";
135
+ // A new result, or a cell of another width, may fit at full size where the
136
+ // last one did not: let go and measure again, rather than stay compact on
137
+ // the strength of a height measured for something else.
138
+ useEffect(() => {
139
+ setTightFrom(undefined);
140
+ }, [result, cellWidth, mayTighten]);
141
+ useEffect(() => {
142
+ if (!mayTighten) return;
143
+ if (cellHeight === undefined || contentHeight === undefined) return;
144
+ if (tightFrom === undefined && contentHeight > cellHeight + 1)
145
+ setTightFrom(contentHeight);
146
+ else if (tightFrom !== undefined && cellHeight >= tightFrom)
147
+ setTightFrom(undefined);
148
+ }, [mayTighten, cellHeight, contentHeight, tightFrom]);
149
+
117
150
  if (!result) {
118
151
  return null;
119
152
  }
@@ -205,6 +238,9 @@ export default function ResultContainer({
205
238
  // scrolls inside itself, under its own pinned header.
206
239
  <Box
207
240
  className={RESULT_SCROLLER_CLASS}
241
+ {...(mayTighten && tightFrom !== undefined
242
+ ? { [TIGHT_ATTR]: "" }
243
+ : {})}
208
244
  sx={{
209
245
  position: "absolute",
210
246
  inset: 0,
@@ -26,6 +26,8 @@ export interface ResultPanelProps {
26
26
  drill?: DrillBinding;
27
27
  /** See `ResultContainer`: stretch the result to its cell. */
28
28
  fill?: boolean;
29
+ /** The cell has a set height: a result taller than it is drawn compact (see `ResultContainer`). */
30
+ compactToFit?: boolean;
29
31
  /**
30
32
  * Rewrites the result before it is rendered — a dashboard tile promotes a
31
33
  * one-row measure result to KPI cards this way. Memoized on the result
@@ -55,6 +57,7 @@ export function ResultPanel({
55
57
  maxResultSize,
56
58
  drill,
57
59
  fill,
60
+ compactToFit,
58
61
  transform,
59
62
  }: ResultPanelProps) {
60
63
  const { data, isSuccess, isError, error, fetchStatus, isPlaceholderData } =
@@ -108,6 +111,7 @@ export function ResultPanel({
108
111
  renderLogs={data.data.renderLogs}
109
112
  drill={drill}
110
113
  fill={fill}
114
+ compactToFit={compactToFit}
111
115
  />
112
116
  );
113
117
  // The previous answer, while the new one runs: it stays where it is, eased
@@ -371,3 +371,9 @@ export function resolveResultHeight({
371
371
  : Math.min(maxHeight, contentHeight);
372
372
  return fillHeight === undefined ? own : Math.max(own, fillHeight);
373
373
  }
374
+
375
+ /**
376
+ * On a result's box while it is drawn compact to fit a cell shorter than it
377
+ * (`ResultContainer` sets it); the renderer overrides in `RenderedResult` read it.
378
+ */
379
+ export const TIGHT_ATTR = "data-publisher-tight";
@@ -0,0 +1,80 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
5
+ import {
6
+ IconButton,
7
+ ListItemText,
8
+ Menu,
9
+ MenuItem,
10
+ Tooltip,
11
+ } from "@mui/material";
12
+ import { useState } from "react";
13
+ import { usePublisherTheme } from "../../theme/ThemeContext";
14
+ import { edgeColor } from "../controlTokens";
15
+ import { iconControlSx } from "./BuilderToolbar";
16
+
17
+ import type { ArrangeActions } from "./builderControls";
18
+
19
+ /**
20
+ * The layout of a placed grid report as a whole: closing its gaps, or letting
21
+ * its tiles flow again. One menu shared by the builder's own toolbar and the
22
+ * bar a host draws, so the two cannot offer different things.
23
+ */
24
+ export function ArrangeMenu({ arrange }: { arrange: ArrangeActions }) {
25
+ const { theme } = usePublisherTheme();
26
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
27
+ const pick = (action: (() => void) | undefined) => () => {
28
+ setAnchor(null);
29
+ action?.();
30
+ };
31
+ return (
32
+ <>
33
+ <Tooltip title="Arrange tiles">
34
+ <IconButton
35
+ aria-label="Arrange tiles"
36
+ aria-haspopup="menu"
37
+ aria-expanded={anchor !== null}
38
+ onClick={(event) => setAnchor(event.currentTarget)}
39
+ sx={iconControlSx(theme.ui)}
40
+ >
41
+ <DashboardOutlinedIcon fontSize="small" />
42
+ </IconButton>
43
+ </Tooltip>
44
+ <Menu
45
+ anchorEl={anchor}
46
+ open={anchor !== null}
47
+ onClose={() => setAnchor(null)}
48
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
49
+ transformOrigin={{ vertical: -6, horizontal: "right" }}
50
+ slotProps={{
51
+ paper: {
52
+ sx: {
53
+ minWidth: 260,
54
+ borderRadius: theme.ui.radius.menu,
55
+ border: `1px solid ${edgeColor(theme.cardBorder)}`,
56
+ boxShadow: theme.ui.shadow.menu,
57
+ },
58
+ },
59
+ }}
60
+ >
61
+ <MenuItem disabled={!arrange.pack} onClick={pick(arrange.pack)}>
62
+ <ListItemText
63
+ primary="Pack tiles upward"
64
+ secondary={
65
+ arrange.pack
66
+ ? "Close every gap above a tile"
67
+ : "There are no gaps to close"
68
+ }
69
+ />
70
+ </MenuItem>
71
+ <MenuItem onClick={pick(arrange.flow)}>
72
+ <ListItemText
73
+ primary="Let tiles flow"
74
+ secondary="Clear each tile's place; keep its size"
75
+ />
76
+ </MenuItem>
77
+ </Menu>
78
+ </>
79
+ );
80
+ }
@@ -27,6 +27,7 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
27
27
  import { edgeColor, hoverEdgeColor } from "../controlTokens";
28
28
  import type { BuilderControls } from "./builderControls";
29
29
  import { controlSx, dividerSx, iconControlSx } from "./BuilderToolbar";
30
+ import { ArrangeMenu } from "./ArrangeMenu";
30
31
  import { SaveStatus } from "./SaveStatus";
31
32
  import { MOD } from "./useBuilderShortcuts";
32
33
 
@@ -118,6 +119,9 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
118
119
  </IconButton>
119
120
  </span>
120
121
  </Tooltip>
122
+ {controls.arrange && (
123
+ <ArrangeMenu arrange={controls.arrange} />
124
+ )}
121
125
  {canAdd && (
122
126
  <Divider orientation="vertical" sx={dividerSx} />
123
127
  )}
@@ -1,6 +1,8 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { isPlaced } from "../Dashboard/DashboardGrid";
5
+ import { holdChartRows, settle } from "./placement";
4
6
  import { useState, type ComponentProps, type ReactNode } from "react";
5
7
  import { UnsavedChangesDialog } from "../UnsavedChangesDialog";
6
8
  import { AddTileDialog, type ViewPreview } from "./AddTileDialog";
@@ -111,8 +113,13 @@ export function BuilderDialogs({
111
113
  onCommit={(next) => {
112
114
  const at = menu?.index;
113
115
  if (at === undefined) return;
116
+ // A chart picked on a tile too short to plot it raises the
117
+ // tile to a chart's rows, pushing down what it now covers.
118
+ const held = holdChartRows(next);
114
119
  editor.update((draft) => {
115
- draft.tiles[at] = next;
120
+ draft.tiles[at] = held;
121
+ if (held !== next && isPlaced(draft.tiles))
122
+ draft.tiles = settle(draft.tiles, columns, at);
116
123
  });
117
124
  }}
118
125
  view={menuView}
@@ -23,8 +23,8 @@ import {
23
23
  } from "./document";
24
24
  import { InlineText } from "./InlineText";
25
25
  import { gapId, tileEntry, withGaps } from "./layout";
26
- import { minRowsOf, rowsOf } from "./placement";
27
- import { builderSensors } from "./sortable";
26
+ import { minRowsOf, rowsOf, settle, widestFrom } from "./placement";
27
+ import { builderSensors, EscapeCancelsDrag } from "./sortable";
28
28
  import { TextTileBody } from "./TextTileBody";
29
29
  import {
30
30
  GapTarget,
@@ -36,19 +36,17 @@ import {
36
36
  import { tileDisplayTitle } from "./tileDisplayTitle";
37
37
  import type { ReportEditorHandle } from "./useReportEditor";
38
38
  import type { useTileReorder } from "./useTileReorder";
39
- import type { useTileHeight } from "./useTileHeight";
40
- import { widestFrom, type useTileResize } from "./useTileResize";
39
+ import { shapeLabel, withShape, type useEdgeResize } from "./useEdgeResize";
41
40
 
42
41
  /**
43
42
  * The builder's tiles, on the SAME grid the dashboard renders on, each drawn
44
43
  * by the caller's `renderTile` inside a `TileFrame` that carries the
45
- * affordances: selection, the grip and menu, the width handle.
44
+ * affordances: selection, the menu, and its edges and corners.
46
45
  */
47
46
  export function BuilderGrid({
48
47
  editor,
49
48
  reorder,
50
- resizing,
51
- sizing,
49
+ edging,
52
50
  place = (tiles) => tiles,
53
51
  arrange = true,
54
52
  gridBox,
@@ -68,9 +66,8 @@ export function BuilderGrid({
68
66
  }: {
69
67
  editor: ReportEditorHandle;
70
68
  reorder: ReturnType<typeof useTileReorder>;
71
- resizing: ReturnType<typeof useTileResize>;
72
- /** The bottom edges: a tile's height, dragged in whole rows. */
73
- sizing?: ReturnType<typeof useTileHeight>;
69
+ /** Every edge and corner of a tile, dragged to resize it. */
70
+ edging: ReturnType<typeof useEdgeResize>;
74
71
  /**
75
72
  * The tiles after the one at `index` changed size: on a placed report,
76
73
  * whatever it now covers pushed down. Identity elsewhere.
@@ -109,8 +106,7 @@ export function BuilderGrid({
109
106
  const { dragging, preview, onDragStart, onDragMove, onDragOver, onDragEnd } =
110
107
  reorder;
111
108
  const { columns } = rules;
112
- const { resize, startResize, onResize, endResize } = resizing;
113
- const tall = sizing?.height;
109
+ const edge = edging.drag;
114
110
  // What the grid lays out: the document, except mid-gesture, where it is
115
111
  // the preview — the tile being resized at its previewed width, or the tiles
116
112
  // in their previewed order. So the row reflows under the pointer exactly as
@@ -118,35 +114,38 @@ export function BuilderGrid({
118
114
  const drawn = (tile: DashboardTile): DashboardTile =>
119
115
  tile.colspan === undefined ? { ...tile, colspan: defaultSpan } : tile;
120
116
  const shown = (
121
- resize !== undefined
122
- ? place(
123
- editor.document.tiles.map((each, index) =>
124
- index === resize.index
125
- ? { ...each, colspan: resize.span }
117
+ edge !== undefined
118
+ ? (() => {
119
+ // The tiles as the resize would leave them: the one tile with
120
+ // the edges it moved, and on a placed report everything it now
121
+ // covers pushed down.
122
+ const base = edge.placedHere ? edge.base : editor.document.tiles;
123
+ const tile = base[edge.index];
124
+ if (!tile) return base;
125
+ const resized = base.map((each, index) =>
126
+ index === edge.index
127
+ ? withShape(each, edge.shape, edge.edges, edge.placed)
126
128
  : each,
127
- ),
128
- resize.index,
129
- )
130
- : tall !== undefined
131
- ? place(
132
- editor.document.tiles.map((each, index) =>
133
- index === tall.index ? withRowspan(each, tall.rows) : each,
134
- ),
135
- tall.index,
136
- )
137
- : (preview ?? editor.document.tiles)
129
+ );
130
+ return edge.placed
131
+ ? settle(resized, columns, edge.index)
132
+ : resized;
133
+ })()
134
+ : (preview ?? editor.document.tiles)
138
135
  ).map(drawn);
139
136
  // Placed, every cell is somewhere to drop, so there are no row ends to offer.
140
137
  const placed = isPlaced(shown);
138
+ const gesture = dragging || edge !== undefined;
139
+ // Faintly, while a tile of a placed report is selected and nothing is
140
+ // dragged: the empty cells read as places a tile can go before any drag.
141
+ const resting = !gesture && placed && arrange && selected !== undefined;
141
142
  // And, while a drag is live, the empty end of every row as a drop target.
142
143
  // While an edge is dragged too: narrowing a tile frees columns its row-mate
143
144
  // does not take, and an undrawn hole there read as a broken layout rather
144
145
  // than room to fill. Not otherwise: a gap is only shown mid-gesture.
145
146
  const empty = editor.document.tiles.length === 0;
146
147
  const entries =
147
- (dragging || resize !== undefined) && !placed
148
- ? withGaps(shown, columns)
149
- : shown.map(tileEntry);
148
+ gesture && !placed ? withGaps(shown, columns) : shown.map(tileEntry);
150
149
  const heading = (tile: QueryTile) =>
151
150
  headingOf(tile, tileDisplayTitle(tile), editTile);
152
151
  return (
@@ -158,17 +157,20 @@ export function BuilderGrid({
158
157
  onDragOver={onDragOver}
159
158
  onDragEnd={onDragEnd}
160
159
  >
160
+ <EscapeCancelsDrag active={dragging} />
161
161
  <Box ref={gridBox} sx={{ position: "relative" }}>
162
- {rules.widths && (dragging || resize !== undefined) && (
163
- <GridGuides columns={columns} />
164
- )}
165
- {tall !== undefined ? (
166
- <RowGuides top={tall.guideTop} />
167
- ) : (
168
- // Placed, a move snaps to rows as well as columns.
169
- placed &&
170
- (dragging || resize !== undefined) && <RowGuides top={0} />
162
+ {rules.widths && (gesture || resting) && (
163
+ <GridGuides columns={columns} faint={!gesture} />
171
164
  )}
165
+ {edge !== undefined && !edge.placed
166
+ ? (edge.edges.s || edge.edges.n) && (
167
+ <RowGuides top={edge.guideTop} />
168
+ )
169
+ : // Placed, a move snaps to rows as well as columns.
170
+ placed &&
171
+ (gesture || resting) && (
172
+ <RowGuides top={0} faint={!gesture} />
173
+ )}
172
174
 
173
175
  <DashboardGrid
174
176
  tiles={entries}
@@ -208,9 +210,25 @@ export function BuilderGrid({
208
210
  }
209
211
  : {})}
210
212
  fixed={!arrange}
213
+ {...(rules.widths
214
+ ? {
215
+ edges: {
216
+ // Left and top move a place, so they
217
+ // need the grid drawn as a grid.
218
+ all: arrange,
219
+ right: arrange,
220
+ start: (event, edges) =>
221
+ edging.start(event, index, edges),
222
+ move: edging.move,
223
+ end: edging.end,
224
+ ...(edge?.index === index
225
+ ? { label: shapeLabel(edge, columns) }
226
+ : {}),
227
+ },
228
+ }
229
+ : {})}
211
230
  {...(rules.widths && arrange
212
231
  ? {
213
- resizing: resize?.index === index,
214
232
  width: {
215
233
  span: each.colspan ?? 1,
216
234
  columns,
@@ -238,22 +256,14 @@ export function BuilderGrid({
238
256
  });
239
257
  },
240
258
  },
241
- onResizeStart: (event) =>
242
- startResize(event, index),
243
- onResizeMove: onResize,
244
- onResizeEnd: endResize,
245
259
  }
246
260
  : {})}
247
- {...(rules.widths && sizing
261
+ {...(rules.widths
248
262
  ? {
249
263
  heightEdge: {
250
264
  rows: each.rowspan,
251
- dragging: tall?.index === index,
252
265
  min: minRowsOf(each),
253
- onStart: (event) =>
254
- sizing.startHeight(event, index),
255
- onMove: sizing.onHeight,
256
- onEnd: sizing.endHeight,
266
+ minFor: (frame) => minRowsOf(each, frame),
257
267
  onStep: (to) =>
258
268
  editor.update((draft) => {
259
269
  if (
@@ -318,15 +328,6 @@ export function BuilderGrid({
318
328
  );
319
329
  }
320
330
 
321
- /** A tile at a dragged height: its rows, or auto with no `rowspan` at all. */
322
- const withRowspan = (
323
- tile: DashboardTile,
324
- rows: number | undefined,
325
- ): DashboardTile => {
326
- const { rowspan: _rowspan, ...rest } = tile;
327
- return rows === undefined ? rest : { ...rest, rowspan: rows };
328
- };
329
-
330
331
  /** A query tile's title and subtitle as fields on the tile, unless the model owns them. */
331
332
  const headingOf = (
332
333
  tile: QueryTile,
@@ -135,6 +135,8 @@ export interface BuilderToolbarProps {
135
135
  actions?: ReactNode;
136
136
  /** Open the add-tile picker. Absent when the host passed no catalog to pick from. */
137
137
  onAddTile?: () => void;
138
+ /** The arrange menu, on a report whose tiles are placed; drawn before Tile. */
139
+ arrange?: ReactNode;
138
140
  /**
139
141
  * Leave the builder: draws Close after Save, for a host that opts in. The
140
142
  * Console leaves from its own header and passes nothing.
@@ -161,6 +163,7 @@ export function BuilderToolbar({
161
163
  saveButton,
162
164
  actions,
163
165
  onAddTile,
166
+ arrange,
164
167
  onExit,
165
168
  saveStatus,
166
169
  }: BuilderToolbarProps) {
@@ -180,6 +183,7 @@ export function BuilderToolbar({
180
183
  "& .MuiButton-root": { whiteSpace: "nowrap" },
181
184
  }}
182
185
  >
186
+ {arrange}
183
187
  {/* What the page is made of. */}
184
188
  {onAddTile && (
185
189
  <Button
@@ -19,6 +19,7 @@ import { documentPreamble } from "../Dashboard/textSource";
19
19
  import { GivensPanel } from "../given";
20
20
  import { Loading } from "../Loading";
21
21
  import {
22
+ isPlaced,
22
23
  PLACED_DEFAULT_ROWSPAN,
23
24
  tileHeightPx,
24
25
  } from "../Dashboard/DashboardGrid";
@@ -560,15 +561,21 @@ export function EditorSurface({
560
561
  })()}
561
562
  ignoredFilters={tileIgnoredFilterLabels(query.reads, specs)}
562
563
  // Its own rows when it has them (a rowspan, or a placed
563
- // report's fixed rows); otherwise the layout's cap.
564
+ // report's fixed rows, placed yet or not); otherwise the
565
+ // layout's cap.
564
566
  height={
565
- tile.rowspan !== undefined || tile.row !== undefined
567
+ tile.rowspan !== undefined || isPlaced(doc.tiles)
566
568
  ? tileHeightPx(
567
569
  tile.rowspan ?? PLACED_DEFAULT_ROWSPAN.query,
568
570
  )
569
571
  : rules.tileMaxHeight
570
572
  }
571
573
  tableMaxHeight={rules.tableMaxHeight}
574
+ // As the reader does: every tile of a placed report sits
575
+ // in fixed rows, placed yet or not.
576
+ fixedHeight={
577
+ tile.rowspan !== undefined || isPlaced(doc.tiles)
578
+ }
572
579
  />
573
580
  );
574
581
  },