@malloy-publisher/sdk 0.9.15 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{RenderedResult-BClN_PG6.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +21 -4
- package/dist/{RenderedResult-YBzVMVH2.es.js → RenderedResult-DiDsN6JE.es.js} +204 -187
- package/dist/builder/index.cjs.js +75 -75
- package/dist/builder/index.es.js +5304 -5156
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +2 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +5 -0
- package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +5 -7
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
- package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
- package/dist/components/ReportBuilder/TileFrame.d.ts +34 -22
- package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
- package/dist/components/ReportBuilder/placement.d.ts +48 -2
- package/dist/components/ReportBuilder/sortable.d.ts +9 -0
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
- package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
- package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +3 -0
- package/dist/components/legacy/malloynb/CellRunnerView.d.ts +6 -6
- package/dist/hooks/useSettled.d.ts +5 -8
- package/dist/hooks/useSettledDraft.d.ts +33 -0
- package/dist/index.cjs.js +10 -10
- package/dist/index.es.js +3861 -3870
- package/dist/theme/classes.d.ts +1 -1
- package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
- package/dist/{useCompiledDocument-BGk38oaW.es.js → useCompiledDocument-CRmmbUza.es.js} +6426 -6257
- package/dist/utils/malloyLiteral.d.ts +2 -0
- package/package.json +11 -16
- package/src/builder-entry.ts +1 -0
- package/src/components/Dashboard/DashboardGrid.tsx +2 -0
- package/src/components/Dashboard/DashboardTile.tsx +4 -0
- package/src/components/Dashboard/DashboardView.tsx +1 -0
- package/src/components/RenderedResult/RenderedResult.tsx +18 -0
- package/src/components/RenderedResult/ResultContainer.tsx +39 -3
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.ts +6 -0
- package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
- package/src/components/ReportBuilder/BuilderBar.tsx +4 -0
- package/src/components/ReportBuilder/BuilderDialogs.tsx +8 -1
- package/src/components/ReportBuilder/BuilderGrid.tsx +62 -60
- package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
- package/src/components/ReportBuilder/EditorSurface.tsx +9 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +99 -0
- package/src/components/ReportBuilder/ReportBuilder.tsx +110 -30
- package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
- package/src/components/ReportBuilder/TileFrame.tsx +261 -310
- package/src/components/ReportBuilder/builderControls.ts +34 -0
- package/src/components/ReportBuilder/placement.spec.ts +235 -0
- package/src/components/ReportBuilder/placement.ts +179 -9
- package/src/components/ReportBuilder/readDocument.spec.ts +7 -17
- package/src/components/ReportBuilder/readDocument.ts +3 -6
- package/src/components/ReportBuilder/sortable.tsx +26 -2
- package/src/components/ReportBuilder/spliceDocument.spec.ts +0 -40
- package/src/components/ReportBuilder/spliceDocument.ts +0 -39
- package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
- package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
- package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
- package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
- package/src/components/ReportBuilder/useTileReorder.ts +1 -1
- package/src/components/given/GivenInput.spec.tsx +447 -2
- package/src/components/given/GivenInput.tsx +192 -80
- package/src/components/given/GivensPanel.spec.tsx +59 -0
- package/src/components/given/GivensPanel.tsx +14 -2
- package/src/components/legacy/malloynb/CellRunnerView.tsx +6 -6
- package/src/hooks/useDimensionFilters.ts +1 -35
- package/src/hooks/useDimensionFiltersQuery.ts +2 -36
- package/src/hooks/useDimensionalFilterRangeData.ts +1 -35
- package/src/hooks/useGivensState.spec.ts +106 -1
- package/src/hooks/useGivensState.ts +48 -13
- package/src/hooks/useSettled.ts +5 -8
- package/src/hooks/useSettledDraft.ts +127 -0
- package/src/theme/classes.ts +1 -1
- package/src/utils/malloyLiteral.spec.ts +12 -1
- package/src/utils/malloyLiteral.ts +32 -0
- package/vite.config.ts +0 -2
- package/.eslintrc +0 -36
- package/dist/components/DOMElement/DOMElement.d.ts +0 -5
- package/dist/components/DOMElement/index.d.ts +0 -1
- package/dist/components/Package/FileTreeView.d.ts +0 -9
- package/dist/components/ReportBuilder/useTileHeight.d.ts +0 -39
- package/dist/components/ReportBuilder/useTileResize.d.ts +0 -40
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +0 -142
- package/src/components/DOMElement/DOMElement.tsx +0 -22
- package/src/components/DOMElement/index.ts +0 -4
- package/src/components/Package/FileTreeView.tsx +0 -244
- package/src/components/ReportBuilder/useTileHeight.ts +0 -149
- package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
- package/src/components/ReportBuilder/useTileResize.ts +0 -148
|
@@ -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
|
|
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 {
|
|
12
|
+
import { hoverEdgeColor } from "../controlTokens";
|
|
12
13
|
import {
|
|
13
14
|
REMOVE_BADGE_CLASS,
|
|
14
15
|
RemoveBadge,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
BARE_RING_OFFSET_PX,
|
|
21
22
|
GRID_GAP_PX,
|
|
22
23
|
MAX_TILE_ROWS,
|
|
24
|
+
MIN_TILE_ROWS,
|
|
23
25
|
TILE_ROW_PX,
|
|
24
26
|
} from "../Dashboard/DashboardGrid";
|
|
25
27
|
import {
|
|
@@ -39,12 +41,12 @@ import {
|
|
|
39
41
|
type QueryTile,
|
|
40
42
|
} from "./document";
|
|
41
43
|
import { gapId } from "./layout";
|
|
44
|
+
import { edgeCursor, type Edges } from "./useEdgeResize";
|
|
42
45
|
import { GapDroppable, NO_DRAG, TileSortable } from "./sortable";
|
|
43
|
-
import { widthLabel } from "./widthLabel";
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* Everything the builder draws AROUND a tile: the selection outline, the menu
|
|
47
|
-
* button, the
|
|
49
|
+
* button, the resize edges and corners and, in a notebook, the insert button. The tile
|
|
48
50
|
* itself is `children` — the host's real `DashboardTile`, or a placeholder
|
|
49
51
|
* saying what the tile will run.
|
|
50
52
|
*/
|
|
@@ -60,11 +62,8 @@ export function TileFrame({
|
|
|
60
62
|
onOpenMenu,
|
|
61
63
|
onRemove,
|
|
62
64
|
removeBlocked,
|
|
63
|
-
resizing = false,
|
|
64
65
|
width,
|
|
65
|
-
|
|
66
|
-
onResizeMove,
|
|
67
|
-
onResizeEnd,
|
|
66
|
+
edges,
|
|
68
67
|
heightEdge,
|
|
69
68
|
fixed = false,
|
|
70
69
|
children,
|
|
@@ -90,13 +89,23 @@ export function TileFrame({
|
|
|
90
89
|
onRemove: () => void;
|
|
91
90
|
/** Why it cannot be removed (a saved report keeps one tile); the × says so instead. */
|
|
92
91
|
removeBlocked?: string;
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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. */
|
|
100
109
|
width?: {
|
|
101
110
|
span: number;
|
|
102
111
|
columns: number;
|
|
@@ -104,23 +113,20 @@ export function TileFrame({
|
|
|
104
113
|
max?: number;
|
|
105
114
|
onStep: (to: number) => void;
|
|
106
115
|
};
|
|
107
|
-
/**
|
|
108
|
-
* The bottom edge, which sets the height in grid rows: dragged, or focused
|
|
109
|
-
* and stepped with the arrow keys. Delete or a double-click puts the tile
|
|
110
|
-
* back to fitting its content. Absent, the tile has no bottom handle.
|
|
111
|
-
*/
|
|
112
116
|
/** The tile cannot be moved now (the grid is drawn as one column). */
|
|
113
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
|
+
*/
|
|
114
123
|
heightEdge?: {
|
|
115
124
|
/** Its rows: the set height, or the drag's preview; absent on auto, as tall as its row. */
|
|
116
125
|
rows: number | undefined;
|
|
117
|
-
/**
|
|
118
|
-
dragging: boolean;
|
|
119
|
-
/** The fewest rows offered: a chart's floor, or prose's. */
|
|
126
|
+
/** The fewest rows offered before anything is known of what the tile draws. */
|
|
120
127
|
min: number;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
onEnd: (event: PointerEvent<HTMLDivElement>) => void;
|
|
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;
|
|
124
130
|
/** A keyboard step, or `undefined` to fit the content again. */
|
|
125
131
|
onStep: (to: number | undefined) => void;
|
|
126
132
|
};
|
|
@@ -181,7 +187,7 @@ export function TileFrame({
|
|
|
181
187
|
// pixels.
|
|
182
188
|
cursor: "grab",
|
|
183
189
|
...selectionSx(theme, { selected, flash, bare }),
|
|
184
|
-
// The
|
|
190
|
+
// The resize edges and menu are invisible
|
|
185
191
|
// until wanted, and wanted is: the pointer
|
|
186
192
|
// over the tile, or the tile selected. A
|
|
187
193
|
// hover rule on the WRAPPER, so all three
|
|
@@ -285,7 +291,9 @@ export function TileFrame({
|
|
|
285
291
|
borderRadius: ui.radius.control,
|
|
286
292
|
width: 28,
|
|
287
293
|
height: 28,
|
|
288
|
-
|
|
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,
|
|
289
297
|
color: "text.secondary",
|
|
290
298
|
bgcolor: "action.hover",
|
|
291
299
|
opacity: selected || menuOpen ? 1 : 0,
|
|
@@ -301,166 +309,15 @@ export function TileFrame({
|
|
|
301
309
|
</IconButton>
|
|
302
310
|
)}
|
|
303
311
|
|
|
304
|
-
{/*
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
{
|
|
312
|
-
role="separator"
|
|
313
|
-
tabIndex={width ? 0 : -1}
|
|
314
|
-
aria-orientation="vertical"
|
|
315
|
-
aria-label={`Width of ${tileLabel(tile)}`}
|
|
316
|
-
{...(width
|
|
317
|
-
? {
|
|
318
|
-
"aria-valuenow": width.span,
|
|
319
|
-
"aria-valuemin": 1,
|
|
320
|
-
"aria-valuemax": width.max ?? width.columns,
|
|
321
|
-
"aria-valuetext": `${width.span} of ${width.columns} columns`,
|
|
322
|
-
}
|
|
323
|
-
: {})}
|
|
324
|
-
onKeyDown={(event) => {
|
|
325
|
-
if (!width) return;
|
|
326
|
-
const to =
|
|
327
|
-
event.key === "ArrowRight"
|
|
328
|
-
? width.span + 1
|
|
329
|
-
: event.key === "ArrowLeft"
|
|
330
|
-
? width.span - 1
|
|
331
|
-
: event.key === "Home"
|
|
332
|
-
? 1
|
|
333
|
-
: event.key === "End"
|
|
334
|
-
? (width.max ?? width.columns)
|
|
335
|
-
: undefined;
|
|
336
|
-
if (to === undefined) return;
|
|
337
|
-
// The builder's own arrow-key nudge must not step it again.
|
|
338
|
-
event.preventDefault();
|
|
339
|
-
event.stopPropagation();
|
|
340
|
-
width.onStep(
|
|
341
|
-
Math.min(
|
|
342
|
-
Math.max(to, 1),
|
|
343
|
-
width.max ?? width.columns,
|
|
344
|
-
),
|
|
345
|
-
);
|
|
346
|
-
}}
|
|
347
|
-
onPointerDown={onResizeStart}
|
|
348
|
-
onPointerMove={onResizeMove}
|
|
349
|
-
onPointerUp={onResizeEnd}
|
|
350
|
-
onPointerCancel={onResizeEnd}
|
|
351
|
-
onClick={(event) => event.stopPropagation()}
|
|
352
|
-
sx={(mui) => ({
|
|
353
|
-
position: "absolute",
|
|
354
|
-
top: 0,
|
|
355
|
-
bottom: 0,
|
|
356
|
-
// Straddles the edge, so the target is a usable width
|
|
357
|
-
// without eating into the tile's content; wide enough
|
|
358
|
-
// for the knob at its middle.
|
|
359
|
-
right: "-8px",
|
|
360
|
-
width: "16px",
|
|
361
|
-
cursor: "col-resize",
|
|
362
|
-
touchAction: "none",
|
|
363
|
-
zIndex: 2,
|
|
364
|
-
// Invisible until wanted: a rule down every tile edge
|
|
365
|
-
// would read as a table.
|
|
366
|
-
opacity: resizing || selected ? 1 : 0,
|
|
367
|
-
transition: `opacity ${MOTION_FAST}`,
|
|
368
|
-
...reducedMotionSx,
|
|
369
|
-
"&:hover": { opacity: 1 },
|
|
370
|
-
"&:focus-visible": {
|
|
371
|
-
opacity: 1,
|
|
372
|
-
outline: `2px solid ${theme.accent}`,
|
|
373
|
-
outlineOffset: 1,
|
|
374
|
-
borderRadius: "3px",
|
|
375
|
-
},
|
|
376
|
-
// A grip tab at the middle of the edge: the shape a
|
|
377
|
-
// splitter's handle has, so it reads as "drag sideways"
|
|
378
|
-
// without a word. The whole edge strip still takes the
|
|
379
|
-
// drag; the tab is where the eye goes.
|
|
380
|
-
"&::before": {
|
|
381
|
-
content: '""',
|
|
382
|
-
position: "absolute",
|
|
383
|
-
top: "50%",
|
|
384
|
-
left: "50%",
|
|
385
|
-
transform: "translate(-50%, -50%)",
|
|
386
|
-
width: "12px",
|
|
387
|
-
height: "40px",
|
|
388
|
-
boxSizing: "border-box",
|
|
389
|
-
borderRadius: ui.radius.control,
|
|
390
|
-
border: `1px solid ${
|
|
391
|
-
resizing
|
|
392
|
-
? theme.accent
|
|
393
|
-
: edgeColor(theme.cardBorder)
|
|
394
|
-
}`,
|
|
395
|
-
bgcolor: mui.palette.background.paper,
|
|
396
|
-
boxShadow:
|
|
397
|
-
"0 1px 2px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.08)",
|
|
398
|
-
transition: `border-color ${MOTION_FAST}`,
|
|
399
|
-
},
|
|
400
|
-
// Its two grip lines.
|
|
401
|
-
"&::after": {
|
|
402
|
-
content: '""',
|
|
403
|
-
position: "absolute",
|
|
404
|
-
top: "50%",
|
|
405
|
-
left: "50%",
|
|
406
|
-
transform: "translate(-50%, -50%)",
|
|
407
|
-
width: "5px",
|
|
408
|
-
height: "16px",
|
|
409
|
-
borderLeft: `1.5px solid ${
|
|
410
|
-
resizing
|
|
411
|
-
? theme.accent
|
|
412
|
-
: mui.palette.text.secondary
|
|
413
|
-
}`,
|
|
414
|
-
borderRight: `1.5px solid ${
|
|
415
|
-
resizing
|
|
416
|
-
? theme.accent
|
|
417
|
-
: mui.palette.text.secondary
|
|
418
|
-
}`,
|
|
419
|
-
boxSizing: "border-box",
|
|
420
|
-
opacity: resizing ? 1 : 0.7,
|
|
421
|
-
},
|
|
422
|
-
"&:hover::before": { borderColor: theme.accent },
|
|
423
|
-
"&:hover::after": {
|
|
424
|
-
borderColor: theme.accent,
|
|
425
|
-
opacity: 1,
|
|
426
|
-
},
|
|
427
|
-
})}
|
|
428
|
-
>
|
|
429
|
-
{/* While dragging, the width it will snap to, in words. The
|
|
430
|
-
separator's own value text says the same to a screen reader. */}
|
|
431
|
-
{resizing && width && (
|
|
432
|
-
<Box
|
|
433
|
-
aria-hidden
|
|
434
|
-
sx={(mui) => ({
|
|
435
|
-
position: "absolute",
|
|
436
|
-
top: "50%",
|
|
437
|
-
// Set against the edge, inside the tile: centred
|
|
438
|
-
// on it, half the label hung past the grid's right
|
|
439
|
-
// edge for a tile that reaches it, where a
|
|
440
|
-
// scrolling host cuts it off.
|
|
441
|
-
right: "50%",
|
|
442
|
-
transform: "translateY(calc(-100% - 28px))",
|
|
443
|
-
px: 1,
|
|
444
|
-
py: 0.5,
|
|
445
|
-
borderRadius: ui.radius.control,
|
|
446
|
-
bgcolor: mui.palette.text.primary,
|
|
447
|
-
color: mui.palette.background.paper,
|
|
448
|
-
...ui.type.label,
|
|
449
|
-
whiteSpace: "nowrap",
|
|
450
|
-
pointerEvents: "none",
|
|
451
|
-
})}
|
|
452
|
-
>
|
|
453
|
-
{widthLabel(width.span, width.columns)}
|
|
454
|
-
</Box>
|
|
455
|
-
)}
|
|
456
|
-
</Box>
|
|
457
|
-
)}
|
|
458
|
-
|
|
459
|
-
{heightEdge && (
|
|
460
|
-
<HeightEdge
|
|
461
|
-
edge={heightEdge}
|
|
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}
|
|
462
320
|
label={tileLabel(tile)}
|
|
463
|
-
selected={selected}
|
|
464
321
|
/>
|
|
465
322
|
)}
|
|
466
323
|
|
|
@@ -676,7 +533,14 @@ export function GapTarget({ after }: { after: string }) {
|
|
|
676
533
|
* Column guides, drawn only during a gesture: a flow grid is invisible until
|
|
677
534
|
* you are trying to land on it.
|
|
678
535
|
*/
|
|
679
|
-
export function GridGuides({
|
|
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
|
+
}) {
|
|
680
544
|
const { theme } = usePublisherTheme();
|
|
681
545
|
return (
|
|
682
546
|
<Box
|
|
@@ -699,7 +563,7 @@ export function GridGuides({ columns }: { columns: number }) {
|
|
|
699
563
|
sx={{
|
|
700
564
|
// A faint band per column: the tracks a width snaps to.
|
|
701
565
|
bgcolor: theme.accent,
|
|
702
|
-
opacity: 0.06,
|
|
566
|
+
opacity: faint ? 0.03 : 0.06,
|
|
703
567
|
borderRadius: "3px",
|
|
704
568
|
}}
|
|
705
569
|
/>
|
|
@@ -715,7 +579,14 @@ export function GridGuides({ columns }: { columns: number }) {
|
|
|
715
579
|
* tile's top, since tiles flow and the grid has no row lines of its own.
|
|
716
580
|
* Behind the tiles and held inside the grid.
|
|
717
581
|
*/
|
|
718
|
-
export function RowGuides({
|
|
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
|
+
}) {
|
|
719
590
|
const { theme } = usePublisherTheme();
|
|
720
591
|
const step = TILE_ROW_PX + GRID_GAP_PX;
|
|
721
592
|
// From the first whole row above the canvas's top edge to well past its
|
|
@@ -742,7 +613,7 @@ export function RowGuides({ top }: { top: number }) {
|
|
|
742
613
|
right: 0,
|
|
743
614
|
height: TILE_ROW_PX,
|
|
744
615
|
bgcolor: theme.accent,
|
|
745
|
-
opacity: 0.06,
|
|
616
|
+
opacity: faint ? 0.03 : 0.06,
|
|
746
617
|
borderRadius: "3px",
|
|
747
618
|
}}
|
|
748
619
|
/>
|
|
@@ -765,136 +636,215 @@ function SpreadDotsIcon() {
|
|
|
765
636
|
);
|
|
766
637
|
}
|
|
767
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
|
+
|
|
768
677
|
/**
|
|
769
|
-
* A tile's
|
|
770
|
-
*
|
|
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.
|
|
771
683
|
*/
|
|
772
|
-
function
|
|
773
|
-
|
|
684
|
+
function TileEdges({
|
|
685
|
+
edges,
|
|
686
|
+
width,
|
|
687
|
+
heightEdge,
|
|
774
688
|
label,
|
|
775
|
-
selected,
|
|
776
689
|
}: {
|
|
777
|
-
|
|
690
|
+
edges: NonNullable<Parameters<typeof TileFrame>[0]["edges"]>;
|
|
691
|
+
width: Parameters<typeof TileFrame>[0]["width"];
|
|
692
|
+
heightEdge: Parameters<typeof TileFrame>[0]["heightEdge"];
|
|
778
693
|
label: string;
|
|
779
|
-
selected: boolean;
|
|
780
694
|
}) {
|
|
781
695
|
const { theme } = usePublisherTheme();
|
|
782
696
|
const ui = theme.ui;
|
|
783
|
-
|
|
784
|
-
|
|
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
|
+
};
|
|
785
713
|
return (
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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
|
+
);
|
|
888
837
|
})}
|
|
889
|
-
|
|
890
|
-
|
|
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.
|
|
891
842
|
<Box
|
|
892
843
|
aria-hidden
|
|
893
844
|
sx={(mui) => ({
|
|
894
845
|
position: "absolute",
|
|
895
|
-
|
|
896
|
-
bottom:
|
|
897
|
-
transform: "translate(32px, 50%)",
|
|
846
|
+
right: 12,
|
|
847
|
+
bottom: 12,
|
|
898
848
|
px: 1,
|
|
899
849
|
py: 0.5,
|
|
900
850
|
borderRadius: ui.radius.control,
|
|
@@ -903,15 +853,16 @@ function HeightEdge({
|
|
|
903
853
|
...ui.type.label,
|
|
904
854
|
whiteSpace: "nowrap",
|
|
905
855
|
pointerEvents: "none",
|
|
856
|
+
zIndex: 4,
|
|
906
857
|
})}
|
|
907
858
|
>
|
|
908
|
-
{
|
|
859
|
+
{edges.label}
|
|
909
860
|
</Box>
|
|
910
861
|
)}
|
|
911
|
-
|
|
862
|
+
</>
|
|
912
863
|
);
|
|
913
864
|
}
|
|
914
865
|
|
|
915
|
-
/** A height in words, for the
|
|
866
|
+
/** A height in words, for the label and a screen reader. */
|
|
916
867
|
const heightLabel = (rows: number | undefined) =>
|
|
917
868
|
rows === undefined ? "Auto height" : `${rows} rows tall`;
|