@malloy-publisher/sdk 0.9.14 → 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 (164) hide show
  1. package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
  2. package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
  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 +7732 -6717
  7. package/dist/builder-entry.d.ts +1 -1
  8. package/dist/client/api.d.ts +31 -7
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
  12. package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
  13. package/dist/components/Dashboard/DashboardView.d.ts +9 -2
  14. package/dist/components/Dashboard/index.d.ts +1 -1
  15. package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
  16. package/dist/components/Dashboard/useStuck.d.ts +18 -12
  17. package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
  18. package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
  19. package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
  20. package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
  21. package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
  22. package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
  23. package/dist/components/Report/Report.d.ts +7 -1
  24. package/dist/components/Report/ReportPage.d.ts +7 -0
  25. package/dist/components/Report/layoutRules.d.ts +45 -0
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
  27. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
  29. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  30. package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
  31. package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
  32. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  33. package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
  34. package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
  35. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  36. package/dist/components/ReportBuilder/catalog.d.ts +23 -0
  37. package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
  38. package/dist/components/ReportBuilder/controls.d.ts +2 -2
  39. package/dist/components/ReportBuilder/document.d.ts +53 -5
  40. package/dist/components/ReportBuilder/imports.d.ts +7 -0
  41. package/dist/components/ReportBuilder/placement.d.ts +121 -0
  42. package/dist/components/ReportBuilder/preview.d.ts +59 -10
  43. package/dist/components/ReportBuilder/sortable.d.ts +12 -1
  44. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  45. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  46. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  47. package/dist/components/ReportBuilder/useTileReorder.d.ts +30 -3
  48. package/dist/index.cjs.js +7 -7
  49. package/dist/index.es.js +3349 -3307
  50. package/dist/text/index.es.js +1 -1
  51. package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
  52. package/dist/theme/classes.d.ts +1 -1
  53. package/dist/theme/resolveTheme.d.ts +15 -0
  54. package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
  55. package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
  56. package/dist/utils/blankQuoted.d.ts +15 -0
  57. package/package.json +1 -1
  58. package/src/builder-entry.ts +1 -0
  59. package/src/components/Dashboard/DashboardGrid.tsx +129 -10
  60. package/src/components/Dashboard/DashboardTile.tsx +15 -1
  61. package/src/components/Dashboard/DashboardView.tsx +64 -10
  62. package/src/components/Dashboard/TileCard.tsx +6 -0
  63. package/src/components/Dashboard/index.ts +1 -0
  64. package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
  65. package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
  66. package/src/components/Dashboard/tileHeight.spec.ts +72 -0
  67. package/src/components/Dashboard/useStuck.ts +76 -28
  68. package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
  69. package/src/components/Package/NewDocumentDialog.tsx +10 -11
  70. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
  71. package/src/components/RenderedResult/RenderedResult.tsx +39 -6
  72. package/src/components/RenderedResult/ResultContainer.tsx +99 -10
  73. package/src/components/RenderedResult/ResultPanel.tsx +25 -1
  74. package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
  75. package/src/components/RenderedResult/chartPresentation.ts +166 -0
  76. package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
  77. package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
  78. package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
  79. package/src/components/RenderedResult/resultSizing.ts +71 -11
  80. package/src/components/Report/Report.spec.tsx +19 -0
  81. package/src/components/Report/Report.tsx +8 -1
  82. package/src/components/Report/ReportPage.tsx +13 -1
  83. package/src/components/Report/layoutRules.spec.ts +43 -3
  84. package/src/components/Report/layoutRules.ts +70 -0
  85. package/src/components/Report/tileOverflow.spec.tsx +162 -0
  86. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
  87. package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
  88. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  89. package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
  90. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
  91. package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
  92. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  93. package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
  94. package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
  95. package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
  96. package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
  97. package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
  98. package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
  99. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
  100. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
  101. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
  102. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
  103. package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
  104. package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
  105. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
  106. package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
  107. package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
  108. package/src/components/ReportBuilder/TileFrame.tsx +366 -170
  109. package/src/components/ReportBuilder/TileMenu.tsx +259 -20
  110. package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
  111. package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
  112. package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
  113. package/src/components/ReportBuilder/builderControls.ts +34 -0
  114. package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
  115. package/src/components/ReportBuilder/catalog.ts +90 -37
  116. package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
  117. package/src/components/ReportBuilder/chartLine.ts +80 -2
  118. package/src/components/ReportBuilder/controls.ts +4 -3
  119. package/src/components/ReportBuilder/document.ts +65 -7
  120. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  121. package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
  122. package/src/components/ReportBuilder/imports.ts +1 -1
  123. package/src/components/ReportBuilder/invariants.spec.ts +18 -10
  124. package/src/components/ReportBuilder/layout.ts +3 -0
  125. package/src/components/ReportBuilder/placement.spec.ts +401 -0
  126. package/src/components/ReportBuilder/placement.ts +416 -0
  127. package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
  128. package/src/components/ReportBuilder/preview.spec.ts +151 -11
  129. package/src/components/ReportBuilder/preview.ts +203 -40
  130. package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
  131. package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
  132. package/src/components/ReportBuilder/readDocument.ts +197 -29
  133. package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
  134. package/src/components/ReportBuilder/sortable.tsx +30 -2
  135. package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
  136. package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
  137. package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
  138. package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
  139. package/src/components/ReportBuilder/spliceDocument.ts +139 -91
  140. package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
  141. package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
  142. package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
  143. package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
  144. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  145. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  146. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  147. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  148. package/src/components/ReportBuilder/useTileEditing.ts +16 -3
  149. package/src/components/ReportBuilder/useTileReorder.ts +143 -6
  150. package/src/components/given/FilterButton.spec.tsx +27 -11
  151. package/src/components/given/FilterButton.tsx +19 -6
  152. package/src/theme/classes.ts +1 -1
  153. package/src/theme/resolveTheme.spec.ts +72 -1
  154. package/src/theme/resolveTheme.ts +43 -0
  155. package/src/utils/blankQuoted.spec.ts +50 -0
  156. package/src/utils/blankQuoted.ts +32 -0
  157. package/src/utils/malloyText.ts +2 -1
  158. package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
  159. package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
  160. package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
  161. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
  162. package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
  163. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  164. package/src/components/ReportBuilder/useTileResize.ts +0 -133
@@ -4,11 +4,12 @@
4
4
  import { reportClasses } from "../../theme/classes";
5
5
  import AddIcon from "@mui/icons-material/Add";
6
6
  import { Box, IconButton, SvgIcon, Typography } from "@mui/material";
7
- import type { PointerEvent, ReactNode } from "react";
7
+ import { useState } from "react";
8
+ import type { FocusEvent, KeyboardEvent, PointerEvent, ReactNode } from "react";
8
9
  import type { Theme } from "@mui/material";
9
10
  import type { SystemStyleObject } from "@mui/system";
10
11
  import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
11
- import { edgeColor, hoverEdgeColor } from "../controlTokens";
12
+ import { hoverEdgeColor } from "../controlTokens";
12
13
  import {
13
14
  REMOVE_BADGE_CLASS,
14
15
  RemoveBadge,
@@ -16,7 +17,13 @@ import {
16
17
  } from "../RemoveBadge";
17
18
  import { usePublisherTheme } from "../../theme/ThemeContext";
18
19
  import type { ResolvedTheme } from "../../theme/types";
19
- import { BARE_RING_OFFSET_PX, GRID_GAP_PX } from "../Dashboard/DashboardGrid";
20
+ import {
21
+ BARE_RING_OFFSET_PX,
22
+ GRID_GAP_PX,
23
+ MAX_TILE_ROWS,
24
+ MIN_TILE_ROWS,
25
+ TILE_ROW_PX,
26
+ } from "../Dashboard/DashboardGrid";
20
27
  import {
21
28
  TILE_HEADING_CLASS,
22
29
  TileCard,
@@ -27,18 +34,19 @@ import {
27
34
  import { tileDisplayTitle } from "./tileDisplayTitle";
28
35
  import {
29
36
  isTextTile,
37
+ tileExpression,
30
38
  tileKey,
31
39
  tileLabel,
32
40
  type DashboardTile,
33
41
  type QueryTile,
34
42
  } from "./document";
35
43
  import { gapId } from "./layout";
44
+ import { edgeCursor, type Edges } from "./useEdgeResize";
36
45
  import { GapDroppable, NO_DRAG, TileSortable } from "./sortable";
37
- import { widthLabel } from "./widthLabel";
38
46
 
39
47
  /**
40
48
  * Everything the builder draws AROUND a tile: the selection outline, the menu
41
- * button, the handle at the right edge and, in a notebook, the insert button. The tile
49
+ * button, the resize edges and corners and, in a notebook, the insert button. The tile
42
50
  * itself is `children` — the host's real `DashboardTile`, or a placeholder
43
51
  * saying what the tile will run.
44
52
  */
@@ -54,11 +62,10 @@ export function TileFrame({
54
62
  onOpenMenu,
55
63
  onRemove,
56
64
  removeBlocked,
57
- resizing = false,
58
65
  width,
59
- onResizeStart,
60
- onResizeMove,
61
- onResizeEnd,
66
+ edges,
67
+ heightEdge,
68
+ fixed = false,
62
69
  children,
63
70
  }: {
64
71
  tile: DashboardTile;
@@ -82,24 +89,53 @@ export function TileFrame({
82
89
  onRemove: () => void;
83
90
  /** Why it cannot be removed (a saved report keeps one tile); the × says so instead. */
84
91
  removeBlocked?: string;
85
- /** This tile's edge is being dragged. */
86
- resizing?: boolean;
87
- /** Dragging the right edge sets the width; absent, the tile has no edge handle (one column, or tags the file does not own). */
88
- onResizeStart?: (event: PointerEvent<HTMLDivElement>) => void;
89
- onResizeMove?: (event: PointerEvent<HTMLDivElement>) => void;
90
- onResizeEnd?: (event: PointerEvent<HTMLDivElement>) => void;
91
- /** The tile's width and the grid's, and a step of one column: the edge's keyboard route. */
92
+ /**
93
+ * The tile's edges and corners, dragged to resize it. Nothing is drawn on
94
+ * them: the cursor turns to a two-headed arrow over an edge and a diagonal
95
+ * one over a corner. Absent, the tile cannot be resized by pointer.
96
+ */
97
+ edges?: {
98
+ /** The right edge (and its corners): off while the grid is one column. */
99
+ right: boolean;
100
+ /** The left and top edges too, which move a place: a grid drawn as a grid. */
101
+ all: boolean;
102
+ start: (event: PointerEvent<HTMLElement>, edges: Edges) => void;
103
+ move: (event: PointerEvent<HTMLElement>) => void;
104
+ end: (event: PointerEvent<HTMLElement>) => void;
105
+ /** What the drag would make the tile, in words, while this tile is resized. */
106
+ label?: string;
107
+ };
108
+ /** The tile's width and the grid's, and a step of one column: the right edge's keyboard route. */
92
109
  width?: {
93
110
  span: number;
94
111
  columns: number;
112
+ /** The widest it may go, when that is less than the grid: a placed tile stops at the right edge. */
113
+ max?: number;
95
114
  onStep: (to: number) => void;
96
115
  };
116
+ /** The tile cannot be moved now (the grid is drawn as one column). */
117
+ fixed?: boolean;
118
+ /**
119
+ * The bottom edge's keyboard route: focused, the arrow keys step the height
120
+ * a row at a time, and Delete puts the tile back to auto height, as a
121
+ * double-click on the edge does.
122
+ */
123
+ heightEdge?: {
124
+ /** Its rows: the set height, or the drag's preview; absent on auto, as tall as its row. */
125
+ rows: number | undefined;
126
+ /** The fewest rows offered before anything is known of what the tile draws. */
127
+ min: number;
128
+ /** The fewest rows offered for what the tile draws now: two for cards or a table, three for a chart. */
129
+ minFor?: (frame: Element | null) => number;
130
+ /** A keyboard step, or `undefined` to fit the content again. */
131
+ onStep: (to: number | undefined) => void;
132
+ };
97
133
  children: ReactNode;
98
134
  }) {
99
135
  const { theme } = usePublisherTheme();
100
136
  const ui = theme.ui;
101
137
  return (
102
- <TileSortable id={tileKey(tile)} index={index}>
138
+ <TileSortable id={tileKey(tile)} index={index} disabled={fixed}>
103
139
  {({ ref, handleRef }) => (
104
140
  <Box
105
141
  ref={ref}
@@ -130,6 +166,14 @@ export function TileFrame({
130
166
  // pass the height on rather than shrink to
131
167
  // the tile.
132
168
  display: "grid",
169
+ // A set height holds the row too, so the tile
170
+ // shrinks to it rather than the row growing to
171
+ // the tile's content.
172
+ ...((tile.rowspan !== undefined ||
173
+ tile.row !== undefined) && {
174
+ gridTemplateRows: "minmax(0, 1fr)",
175
+ minHeight: 0,
176
+ }),
133
177
  // And the WIDTH the other way: it must
134
178
  // follow the grid item down when a tile is
135
179
  // narrowed, not stay as wide as the chart
@@ -143,7 +187,7 @@ export function TileFrame({
143
187
  // pixels.
144
188
  cursor: "grab",
145
189
  ...selectionSx(theme, { selected, flash, bare }),
146
- // The edge handle and menu are invisible
190
+ // The resize edges and menu are invisible
147
191
  // until wanted, and wanted is: the pointer
148
192
  // over the tile, or the tile selected. A
149
193
  // hover rule on the WRAPPER, so all three
@@ -247,7 +291,9 @@ export function TileFrame({
247
291
  borderRadius: ui.radius.control,
248
292
  width: 28,
249
293
  height: 28,
250
- zIndex: 2,
294
+ // Over the edge and corner zones (z 1 and 2), so the corner
295
+ // zone around it never takes a click meant for the menu.
296
+ zIndex: 3,
251
297
  color: "text.secondary",
252
298
  bgcolor: "action.hover",
253
299
  opacity: selected || menuOpen ? 1 : 0,
@@ -263,154 +309,16 @@ export function TileFrame({
263
309
  </IconButton>
264
310
  )}
265
311
 
266
- {/* The right edge, which sets the width: dragged, or focused and
267
- stepped with the arrow keys a column at a time (Home and End go
268
- to one column and the full grid). Marked so the move sensor
269
- never takes a press on it. */}
270
- {onResizeStart && (
271
- <Box
272
- className={`builder-affordance ${reportClasses.widthHandle}`}
273
- {...{ [NO_DRAG]: "" }}
274
- role="separator"
275
- tabIndex={width ? 0 : -1}
276
- aria-orientation="vertical"
277
- aria-label={`Width of ${tileLabel(tile)}`}
278
- {...(width
279
- ? {
280
- "aria-valuenow": width.span,
281
- "aria-valuemin": 1,
282
- "aria-valuemax": width.columns,
283
- "aria-valuetext": `${width.span} of ${width.columns} columns`,
284
- }
285
- : {})}
286
- onKeyDown={(event) => {
287
- if (!width) return;
288
- const to =
289
- event.key === "ArrowRight"
290
- ? width.span + 1
291
- : event.key === "ArrowLeft"
292
- ? width.span - 1
293
- : event.key === "Home"
294
- ? 1
295
- : event.key === "End"
296
- ? width.columns
297
- : undefined;
298
- if (to === undefined) return;
299
- // The builder's own arrow-key nudge must not step it again.
300
- event.preventDefault();
301
- event.stopPropagation();
302
- width.onStep(Math.min(Math.max(to, 1), width.columns));
303
- }}
304
- onPointerDown={onResizeStart}
305
- onPointerMove={onResizeMove}
306
- onPointerUp={onResizeEnd}
307
- onPointerCancel={onResizeEnd}
308
- onClick={(event) => event.stopPropagation()}
309
- sx={(mui) => ({
310
- position: "absolute",
311
- top: 0,
312
- bottom: 0,
313
- // Straddles the edge, so the target is a usable width
314
- // without eating into the tile's content; wide enough
315
- // for the knob at its middle.
316
- right: "-8px",
317
- width: "16px",
318
- cursor: "col-resize",
319
- touchAction: "none",
320
- zIndex: 2,
321
- // Invisible until wanted: a rule down every tile edge
322
- // would read as a table.
323
- opacity: resizing || selected ? 1 : 0,
324
- transition: `opacity ${MOTION_FAST}`,
325
- ...reducedMotionSx,
326
- "&:hover": { opacity: 1 },
327
- "&:focus-visible": {
328
- opacity: 1,
329
- outline: `2px solid ${theme.accent}`,
330
- outlineOffset: 1,
331
- borderRadius: "3px",
332
- },
333
- // A grip tab at the middle of the edge: the shape a
334
- // splitter's handle has, so it reads as "drag sideways"
335
- // without a word. The whole edge strip still takes the
336
- // drag; the tab is where the eye goes.
337
- "&::before": {
338
- content: '""',
339
- position: "absolute",
340
- top: "50%",
341
- left: "50%",
342
- transform: "translate(-50%, -50%)",
343
- width: "12px",
344
- height: "40px",
345
- boxSizing: "border-box",
346
- borderRadius: ui.radius.control,
347
- border: `1px solid ${
348
- resizing
349
- ? theme.accent
350
- : edgeColor(theme.cardBorder)
351
- }`,
352
- bgcolor: mui.palette.background.paper,
353
- boxShadow:
354
- "0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",
355
- transition: `border-color ${MOTION_FAST}`,
356
- },
357
- // Its two grip lines.
358
- "&::after": {
359
- content: '""',
360
- position: "absolute",
361
- top: "50%",
362
- left: "50%",
363
- transform: "translate(-50%, -50%)",
364
- width: "5px",
365
- height: "16px",
366
- borderLeft: `1.5px solid ${
367
- resizing
368
- ? theme.accent
369
- : mui.palette.text.secondary
370
- }`,
371
- borderRight: `1.5px solid ${
372
- resizing
373
- ? theme.accent
374
- : mui.palette.text.secondary
375
- }`,
376
- boxSizing: "border-box",
377
- opacity: resizing ? 1 : 0.7,
378
- },
379
- "&:hover::before": { borderColor: theme.accent },
380
- "&:hover::after": {
381
- borderColor: theme.accent,
382
- opacity: 1,
383
- },
384
- })}
385
- >
386
- {/* While dragging, the width it will snap to, in words. The
387
- separator's own value text says the same to a screen reader. */}
388
- {resizing && width && (
389
- <Box
390
- aria-hidden
391
- sx={(mui) => ({
392
- position: "absolute",
393
- top: "50%",
394
- // Set against the edge, inside the tile: centred
395
- // on it, half the label hung past the grid's right
396
- // edge for a tile that reaches it, where a
397
- // scrolling host cuts it off.
398
- right: "50%",
399
- transform: "translateY(calc(-100% - 28px))",
400
- px: 1,
401
- py: 0.5,
402
- borderRadius: ui.radius.control,
403
- bgcolor: mui.palette.text.primary,
404
- color: mui.palette.background.paper,
405
- ...ui.type.label,
406
- whiteSpace: "nowrap",
407
- pointerEvents: "none",
408
- })}
409
- >
410
- {widthLabel(width.span, width.columns)}
411
- </Box>
412
- )}
413
- </Box>
312
+ {/* Every edge and corner resizes the tile; nothing is drawn on
313
+ them but the cursor. The right and bottom edges are also the
314
+ keyboard's: focused, the arrows step width and height. */}
315
+ {edges && (
316
+ <TileEdges
317
+ edges={edges}
318
+ width={width}
319
+ heightEdge={heightEdge}
320
+ label={tileLabel(tile)}
321
+ />
414
322
  )}
415
323
 
416
324
  {onInsertAfter && (
@@ -584,7 +492,7 @@ export function TilePlaceholder({
584
492
  variant="caption"
585
493
  sx={{ display: "block", color: theme.tileTitle, opacity: 0.7 }}
586
494
  >
587
- {tile.source} → {tile.name}
495
+ {tileExpression(tile).replace("->", "→")}
588
496
  </Typography>
589
497
  </TileCard>
590
498
  );
@@ -625,7 +533,14 @@ export function GapTarget({ after }: { after: string }) {
625
533
  * Column guides, drawn only during a gesture: a flow grid is invisible until
626
534
  * you are trying to land on it.
627
535
  */
628
- export function GridGuides({ columns }: { columns: number }) {
536
+ export function GridGuides({
537
+ columns,
538
+ faint = false,
539
+ }: {
540
+ columns: number;
541
+ /** Drawn fainter, as a hint while nothing is dragged. */
542
+ faint?: boolean;
543
+ }) {
629
544
  const { theme } = usePublisherTheme();
630
545
  return (
631
546
  <Box
@@ -648,7 +563,57 @@ export function GridGuides({ columns }: { columns: number }) {
648
563
  sx={{
649
564
  // A faint band per column: the tracks a width snaps to.
650
565
  bgcolor: theme.accent,
651
- opacity: 0.06,
566
+ opacity: faint ? 0.03 : 0.06,
567
+ borderRadius: "3px",
568
+ }}
569
+ />
570
+ ))}
571
+ </Box>
572
+ );
573
+ }
574
+
575
+ /**
576
+ * The rows a height snaps to, drawn while a tile's bottom edge is dragged: a
577
+ * faint band per row across the whole canvas, the way {@link GridGuides}
578
+ * draws the columns a width snaps to. Rows are counted from the dragged
579
+ * tile's top, since tiles flow and the grid has no row lines of its own.
580
+ * Behind the tiles and held inside the grid.
581
+ */
582
+ export function RowGuides({
583
+ top,
584
+ faint = false,
585
+ }: {
586
+ top: number;
587
+ /** Drawn fainter, as a hint while nothing is dragged. */
588
+ faint?: boolean;
589
+ }) {
590
+ const { theme } = usePublisherTheme();
591
+ const step = TILE_ROW_PX + GRID_GAP_PX;
592
+ // From the first whole row above the canvas's top edge to well past its
593
+ // bottom; the container clips what overshoots.
594
+ const first = -Math.ceil(top / step);
595
+ return (
596
+ <Box
597
+ aria-hidden
598
+ sx={{
599
+ position: "absolute",
600
+ inset: 0,
601
+ overflow: "hidden",
602
+ pointerEvents: "none",
603
+ zIndex: 0,
604
+ }}
605
+ >
606
+ {Array.from({ length: -first + 4 * MAX_TILE_ROWS }, (_, n) => (
607
+ <Box
608
+ key={n}
609
+ sx={{
610
+ position: "absolute",
611
+ top: top + (first + n) * step,
612
+ left: 0,
613
+ right: 0,
614
+ height: TILE_ROW_PX,
615
+ bgcolor: theme.accent,
616
+ opacity: faint ? 0.03 : 0.06,
652
617
  borderRadius: "3px",
653
618
  }}
654
619
  />
@@ -670,3 +635,234 @@ function SpreadDotsIcon() {
670
635
  </SvgIcon>
671
636
  );
672
637
  }
638
+
639
+ /** Where each edge and corner's zone sits, straddling the tile's border. */
640
+ const ZONES: ReadonlyArray<{ edges: Edges; sx: Record<string, string> }> = [
641
+ {
642
+ edges: { n: true },
643
+ sx: { top: "-6px", left: "12px", right: "12px", height: "12px" },
644
+ },
645
+ {
646
+ edges: { s: true },
647
+ sx: { bottom: "-6px", left: "12px", right: "12px", height: "12px" },
648
+ },
649
+ {
650
+ edges: { e: true },
651
+ sx: { right: "-6px", top: "12px", bottom: "12px", width: "12px" },
652
+ },
653
+ {
654
+ edges: { w: true },
655
+ sx: { left: "-6px", top: "12px", bottom: "12px", width: "12px" },
656
+ },
657
+ {
658
+ edges: { n: true, w: true },
659
+ sx: { top: "-8px", left: "-8px", width: "20px", height: "20px" },
660
+ },
661
+ {
662
+ // Larger than the other corners: the tile's × sits on this one, and the
663
+ // L of corner around it is what still takes a diagonal resize.
664
+ edges: { n: true, e: true },
665
+ sx: { top: "-8px", right: "-8px", width: "32px", height: "32px" },
666
+ },
667
+ {
668
+ edges: { s: true, w: true },
669
+ sx: { bottom: "-8px", left: "-8px", width: "20px", height: "20px" },
670
+ },
671
+ {
672
+ edges: { s: true, e: true },
673
+ sx: { bottom: "-8px", right: "-8px", width: "20px", height: "20px" },
674
+ },
675
+ ];
676
+
677
+ /**
678
+ * A tile's edges and corners as resize targets. Each is an invisible strip
679
+ * along the border whose cursor says what it does: a two-headed arrow on an
680
+ * edge, a diagonal one on a corner. Nothing is drawn, so a tile carries no
681
+ * handles; the selection ring is its outline. The right and bottom strips
682
+ * are also the keyboard's separators, which show a ring only when focused.
683
+ */
684
+ function TileEdges({
685
+ edges,
686
+ width,
687
+ heightEdge,
688
+ label,
689
+ }: {
690
+ edges: NonNullable<Parameters<typeof TileFrame>[0]["edges"]>;
691
+ width: Parameters<typeof TileFrame>[0]["width"];
692
+ heightEdge: Parameters<typeof TileFrame>[0]["heightEdge"];
693
+ label: string;
694
+ }) {
695
+ const { theme } = usePublisherTheme();
696
+ const ui = theme.ui;
697
+ // The floor the keyboard and a screen reader get, read off what the tile
698
+ // draws when the bottom edge is reached, since a chart and a row of cards
699
+ // have different ones and only the drawn result says which this is.
700
+ const [floor, setFloor] = useState<number | undefined>(undefined);
701
+ const minRows = floor ?? heightEdge?.min ?? MIN_TILE_ROWS;
702
+ const readFloor = (frame: Element | null) =>
703
+ heightEdge && setFloor(heightEdge.minFor?.(frame) ?? heightEdge.min);
704
+ const offered = (zone: Edges) =>
705
+ (!(zone.n || zone.w) || edges.all) && (!zone.e || edges.right);
706
+ const focusRing = {
707
+ "&:focus-visible": {
708
+ outline: `2px solid ${theme.accent}`,
709
+ outlineOffset: -4,
710
+ borderRadius: "3px",
711
+ },
712
+ };
713
+ return (
714
+ <>
715
+ {ZONES.filter((zone) => offered(zone.edges)).map((zone) => {
716
+ const key = Object.keys(zone.edges).join("");
717
+ const isRight = key === "e";
718
+ const isBottom = key === "s";
719
+ const keyboard =
720
+ isRight && width
721
+ ? {
722
+ role: "separator",
723
+ tabIndex: 0,
724
+ "aria-orientation": "vertical" as const,
725
+ "aria-label": `Width of ${label}`,
726
+ "aria-valuenow": width.span,
727
+ "aria-valuemin": 1,
728
+ "aria-valuemax": width.max ?? width.columns,
729
+ "aria-valuetext": `${width.span} of ${width.columns} columns`,
730
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
731
+ // Option/Alt and an arrow moves the tile: the
732
+ // builder's shortcut, not this edge's.
733
+ if (event.altKey) return;
734
+ const max = width.max ?? width.columns;
735
+ const to =
736
+ event.key === "ArrowRight"
737
+ ? width.span + 1
738
+ : event.key === "ArrowLeft"
739
+ ? width.span - 1
740
+ : event.key === "Home"
741
+ ? 1
742
+ : event.key === "End"
743
+ ? max
744
+ : undefined;
745
+ if (to === undefined) return;
746
+ // The builder's own arrow-key nudge must not step it again.
747
+ event.preventDefault();
748
+ event.stopPropagation();
749
+ width.onStep(Math.min(Math.max(to, 1), max));
750
+ },
751
+ }
752
+ : isBottom && heightEdge
753
+ ? {
754
+ role: "separator",
755
+ tabIndex: 0,
756
+ "aria-orientation": "horizontal" as const,
757
+ "aria-label": `Height of ${label}`,
758
+ "aria-valuemin": minRows,
759
+ onFocus: (event: FocusEvent<HTMLElement>) =>
760
+ readFloor(event.currentTarget.parentElement),
761
+ onPointerEnter: (event: PointerEvent<HTMLElement>) =>
762
+ readFloor(event.currentTarget.parentElement),
763
+ "aria-valuemax": MAX_TILE_ROWS,
764
+ ...(heightEdge.rows === undefined
765
+ ? {}
766
+ : { "aria-valuenow": heightEdge.rows }),
767
+ "aria-valuetext": heightLabel(heightEdge.rows),
768
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
769
+ if (event.altKey) return;
770
+ const rows = heightEdge.rows;
771
+ const now = rows ?? minRows;
772
+ const to =
773
+ event.key === "ArrowDown"
774
+ ? now + 1
775
+ : event.key === "ArrowUp"
776
+ ? now - 1
777
+ : event.key === "Home"
778
+ ? minRows
779
+ : event.key === "End"
780
+ ? MAX_TILE_ROWS
781
+ : event.key === "Delete" ||
782
+ event.key === "Backspace"
783
+ ? null
784
+ : undefined;
785
+ if (to === undefined) return;
786
+ event.preventDefault();
787
+ event.stopPropagation();
788
+ if (to === null) {
789
+ if (rows !== undefined)
790
+ heightEdge.onStep(undefined);
791
+ return;
792
+ }
793
+ const held = Math.min(
794
+ Math.max(to, minRows),
795
+ MAX_TILE_ROWS,
796
+ );
797
+ if (held !== rows) heightEdge.onStep(held);
798
+ },
799
+ }
800
+ : { "aria-hidden": true };
801
+ return (
802
+ <Box
803
+ key={key}
804
+ className={`builder-affordance${isRight ? ` ${reportClasses.widthHandle}` : ""}`}
805
+ {...{ [NO_DRAG]: "" }}
806
+ {...keyboard}
807
+ data-edge={key}
808
+ onPointerDown={(event) => {
809
+ if (event.button !== 0) return;
810
+ edges.start(event, zone.edges);
811
+ }}
812
+ onPointerMove={edges.move}
813
+ onPointerUp={edges.end}
814
+ onPointerCancel={edges.end}
815
+ onClick={(event) => event.stopPropagation()}
816
+ onDoubleClick={(event) => {
817
+ // A double-click on the bottom edge puts the tile back
818
+ // to auto height.
819
+ if (!zone.edges.s || zone.edges.e || zone.edges.w) return;
820
+ event.stopPropagation();
821
+ if (heightEdge && heightEdge.rows !== undefined)
822
+ heightEdge.onStep(undefined);
823
+ }}
824
+ sx={{
825
+ position: "absolute",
826
+ ...zone.sx,
827
+ cursor: edgeCursor(zone.edges),
828
+ touchAction: "none",
829
+ // Corners over edges, both over the tile's content and
830
+ // under its × (z 3), so the top-right corner never takes
831
+ // a click meant for remove.
832
+ zIndex: Object.keys(zone.edges).length > 1 ? 2 : 1,
833
+ ...focusRing,
834
+ }}
835
+ />
836
+ );
837
+ })}
838
+ {edges.label && (
839
+ // While a resize is live, what it would make the tile, in words,
840
+ // at the tile's lower right. The separators' value text says the
841
+ // same to a screen reader.
842
+ <Box
843
+ aria-hidden
844
+ sx={(mui) => ({
845
+ position: "absolute",
846
+ right: 12,
847
+ bottom: 12,
848
+ px: 1,
849
+ py: 0.5,
850
+ borderRadius: ui.radius.control,
851
+ bgcolor: mui.palette.text.primary,
852
+ color: mui.palette.background.paper,
853
+ ...ui.type.label,
854
+ whiteSpace: "nowrap",
855
+ pointerEvents: "none",
856
+ zIndex: 4,
857
+ })}
858
+ >
859
+ {edges.label}
860
+ </Box>
861
+ )}
862
+ </>
863
+ );
864
+ }
865
+
866
+ /** A height in words, for the label and a screen reader. */
867
+ const heightLabel = (rows: number | undefined) =>
868
+ rows === undefined ? "Auto height" : `${rows} rows tall`;