@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
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useEffect, useRef, useState, type RefObject } from "react";
|
|
5
|
+
import {
|
|
6
|
+
GRID_GAP_PX,
|
|
7
|
+
isPlaced,
|
|
8
|
+
MAX_TILE_ROWS,
|
|
9
|
+
rowsForHeight,
|
|
10
|
+
TILE_ROW_PX,
|
|
11
|
+
tileHeightPx,
|
|
12
|
+
} from "../Dashboard/DashboardGrid";
|
|
13
|
+
import { tileKey, type DashboardTile } from "./document";
|
|
14
|
+
import { minRowsOf, placeWhereDrawn, rowsOf, trackWidth } from "./placement";
|
|
15
|
+
import { drawnBoxes } from "./useTileReorder";
|
|
16
|
+
import { widthLabel } from "./widthLabel";
|
|
17
|
+
|
|
18
|
+
/** The edges a resize moves: one for an edge, two for a corner. */
|
|
19
|
+
export interface Edges {
|
|
20
|
+
n?: boolean;
|
|
21
|
+
s?: boolean;
|
|
22
|
+
e?: boolean;
|
|
23
|
+
w?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A tile's place and size, as a resize changes them. `rowspan` absent is auto height. */
|
|
27
|
+
export interface TileShape {
|
|
28
|
+
row?: number;
|
|
29
|
+
col?: number;
|
|
30
|
+
colspan: number;
|
|
31
|
+
rowspan: number | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A resize in flight. */
|
|
35
|
+
export interface EdgeDrag {
|
|
36
|
+
index: number;
|
|
37
|
+
edges: Edges;
|
|
38
|
+
/** The tiles it started from: placed where they were drawn, when a left or top edge needs places. */
|
|
39
|
+
base: DashboardTile[];
|
|
40
|
+
/** Whether this gesture placed them, which the write then has to keep. */
|
|
41
|
+
placedHere: boolean;
|
|
42
|
+
/** Whether the report is placed for this gesture: the edges then move on the grid's own rows. */
|
|
43
|
+
placed: boolean;
|
|
44
|
+
from: TileShape;
|
|
45
|
+
/** The shape the drag began at, as it is drawn: a release here writes nothing. */
|
|
46
|
+
begun: TileShape;
|
|
47
|
+
/** What the tile would be if the pointer let go now. */
|
|
48
|
+
shape: TileShape;
|
|
49
|
+
/** The tile's top against the grid's, where the row guides of a flowing report are drawn from. */
|
|
50
|
+
guideTop: number;
|
|
51
|
+
/** The fewest rows offered, read off what the tile draws when the drag began. */
|
|
52
|
+
min: number;
|
|
53
|
+
/** The tile's top and left on the page when it began, for a flowing report's edges. */
|
|
54
|
+
top: number;
|
|
55
|
+
left: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const ROW_STEP = TILE_ROW_PX + GRID_GAP_PX;
|
|
59
|
+
|
|
60
|
+
/** The cursor an edge, or a corner, takes. */
|
|
61
|
+
export const edgeCursor = (edges: Edges): string =>
|
|
62
|
+
(edges.n && edges.w) || (edges.s && edges.e)
|
|
63
|
+
? "nwse-resize"
|
|
64
|
+
: (edges.n && edges.e) || (edges.s && edges.w)
|
|
65
|
+
? "nesw-resize"
|
|
66
|
+
: edges.n || edges.s
|
|
67
|
+
? "ns-resize"
|
|
68
|
+
: "ew-resize";
|
|
69
|
+
|
|
70
|
+
/** While an edge is dragged the page selects no text and keeps the edge's cursor. */
|
|
71
|
+
const dragChrome = (cursor: string | undefined) => {
|
|
72
|
+
const body = window.document.body;
|
|
73
|
+
body.style.userSelect = cursor ? "none" : "";
|
|
74
|
+
body.style.cursor = cursor ?? "";
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const shapeOf = (tile: DashboardTile): TileShape => ({
|
|
78
|
+
...(tile.row !== undefined ? { row: tile.row } : {}),
|
|
79
|
+
...(tile.col !== undefined ? { col: tile.col } : {}),
|
|
80
|
+
colspan: tile.colspan ?? 1,
|
|
81
|
+
rowspan: tile.rowspan,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const sameShape = (a: TileShape, b: TileShape) =>
|
|
85
|
+
a.row === b.row &&
|
|
86
|
+
a.col === b.col &&
|
|
87
|
+
a.colspan === b.colspan &&
|
|
88
|
+
a.rowspan === b.rowspan;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* `tile` with what a resize of `edges` changed on it, and nothing else: a
|
|
92
|
+
* right or left edge its width (and, placed, its column), a bottom or top
|
|
93
|
+
* edge its height (and, placed, its row). So a height drag never writes the
|
|
94
|
+
* width a tile happens to be drawn at.
|
|
95
|
+
*/
|
|
96
|
+
export function withShape(
|
|
97
|
+
tile: DashboardTile,
|
|
98
|
+
shape: TileShape,
|
|
99
|
+
edges: Edges,
|
|
100
|
+
placed: boolean,
|
|
101
|
+
): DashboardTile {
|
|
102
|
+
const next = { ...tile };
|
|
103
|
+
if (edges.e || edges.w) {
|
|
104
|
+
next.colspan = shape.colspan;
|
|
105
|
+
if (placed && shape.col !== undefined) next.col = shape.col;
|
|
106
|
+
}
|
|
107
|
+
if (edges.n || edges.s) {
|
|
108
|
+
if (shape.rowspan === undefined) delete next.rowspan;
|
|
109
|
+
else next.rowspan = shape.rowspan;
|
|
110
|
+
if (placed && shape.row !== undefined) next.row = shape.row;
|
|
111
|
+
}
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What a resize asks the caller to write. */
|
|
116
|
+
export interface EdgeResult {
|
|
117
|
+
index: number;
|
|
118
|
+
edges: Edges;
|
|
119
|
+
shape: TileShape;
|
|
120
|
+
placed: boolean;
|
|
121
|
+
/** Every tile placed where it was drawn, when this gesture is what placed the report. */
|
|
122
|
+
placedAll?: DashboardTile[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Dragging any edge or corner of a tile. The right edge sets its width and
|
|
127
|
+
* the bottom edge its height, as they always have; the left and top edges
|
|
128
|
+
* move that edge and keep the opposite one where it is, which needs the
|
|
129
|
+
* tile's row and column, so on a report that flows they place every tile
|
|
130
|
+
* where it is drawn first, as a move does. A corner moves its two edges at
|
|
131
|
+
* once. Previewed from `drag.shape` and written ONCE, on release, so one
|
|
132
|
+
* gesture is one undo step.
|
|
133
|
+
*/
|
|
134
|
+
export function useEdgeResize({
|
|
135
|
+
tiles,
|
|
136
|
+
columns,
|
|
137
|
+
gridBox,
|
|
138
|
+
onStart,
|
|
139
|
+
commit,
|
|
140
|
+
}: {
|
|
141
|
+
/** The tiles as drawn: one with no `colspan` carries the span it is drawn at. */
|
|
142
|
+
tiles: readonly DashboardTile[];
|
|
143
|
+
columns: number;
|
|
144
|
+
/** Wraps the grid, so its box is the grid's. */
|
|
145
|
+
gridBox: RefObject<HTMLDivElement | null>;
|
|
146
|
+
/** The tile a drag begins on, which the caller selects. */
|
|
147
|
+
onStart: (index: number) => void;
|
|
148
|
+
/** What to write when the drag ends. */
|
|
149
|
+
commit: (result: EdgeResult) => void;
|
|
150
|
+
}) {
|
|
151
|
+
const [drag, setDragState] = useState<EdgeDrag | undefined>(undefined);
|
|
152
|
+
// The gesture as the handlers last left it: a release can arrive before
|
|
153
|
+
// the render for the last move does.
|
|
154
|
+
const live = useRef<EdgeDrag | undefined>(undefined);
|
|
155
|
+
// A flowing tile that began on auto height: its height then, its row's.
|
|
156
|
+
const startedAuto = useRef<number | undefined>(undefined);
|
|
157
|
+
const setDrag = (next: EdgeDrag | undefined) => {
|
|
158
|
+
live.current = next;
|
|
159
|
+
setDragState(next);
|
|
160
|
+
};
|
|
161
|
+
useEffect(() => () => dragChrome(undefined), []);
|
|
162
|
+
// Escape cancels a resize in flight wherever focus is: the tile goes back
|
|
163
|
+
// to where it began and the release writes nothing.
|
|
164
|
+
const active = drag !== undefined;
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (!active) return;
|
|
167
|
+
const onKey = (event: KeyboardEvent) => {
|
|
168
|
+
if (event.key !== "Escape" || !live.current) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
event.stopPropagation();
|
|
171
|
+
live.current = undefined;
|
|
172
|
+
setDragState(undefined);
|
|
173
|
+
startedAuto.current = undefined;
|
|
174
|
+
dragChrome(undefined);
|
|
175
|
+
};
|
|
176
|
+
window.addEventListener("keydown", onKey, true);
|
|
177
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
178
|
+
}, [active]);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* How tall a flowing tile's row is on auto height: the tallest of the auto
|
|
182
|
+
* tiles beside it, measured now (#1453: a row of auto tiles is rarely a whole number of rows, so auto is a snap
|
|
183
|
+
* point of its own, and what makes a tile reachable level with them).
|
|
184
|
+
*/
|
|
185
|
+
const autoHeight = (state: EdgeDrag): number | undefined => {
|
|
186
|
+
const auto = new Set(
|
|
187
|
+
state.base.filter((tile) => tile.rowspan === undefined).map(tileKey),
|
|
188
|
+
);
|
|
189
|
+
const self = state.base[state.index];
|
|
190
|
+
let tallest = startedAuto.current;
|
|
191
|
+
for (const frame of gridBox.current?.querySelectorAll<HTMLElement>(
|
|
192
|
+
"[data-tile-key]",
|
|
193
|
+
) ?? []) {
|
|
194
|
+
const key = frame.dataset.tileKey;
|
|
195
|
+
if (!key || !auto.has(key) || (self && key === tileKey(self)))
|
|
196
|
+
continue;
|
|
197
|
+
const box = frame.getBoundingClientRect();
|
|
198
|
+
if (Math.abs(box.top - state.top) > 1) continue;
|
|
199
|
+
tallest = Math.max(tallest ?? 0, box.height);
|
|
200
|
+
}
|
|
201
|
+
return tallest;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const start = (
|
|
205
|
+
event: React.PointerEvent<HTMLElement>,
|
|
206
|
+
index: number,
|
|
207
|
+
edges: Edges,
|
|
208
|
+
) => {
|
|
209
|
+
const grid = gridBox.current;
|
|
210
|
+
const gridBoxNow = grid?.getBoundingClientRect();
|
|
211
|
+
const tileBox =
|
|
212
|
+
event.currentTarget.parentElement?.getBoundingClientRect();
|
|
213
|
+
if (!grid || !gridBoxNow || !tileBox || !tiles[index]) return;
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
217
|
+
dragChrome(edgeCursor(edges));
|
|
218
|
+
onStart(index);
|
|
219
|
+
// A left or top edge moves a place, which a flowing report has not got
|
|
220
|
+
// yet, nor has a tile a placed report leaves to the grid: each tile
|
|
221
|
+
// without one is placed where it is drawn, so nothing jumps.
|
|
222
|
+
const needsPlace =
|
|
223
|
+
(edges.n || edges.w) &&
|
|
224
|
+
(!isPlaced(tiles) ||
|
|
225
|
+
tiles[index].row === undefined ||
|
|
226
|
+
tiles[index].col === undefined);
|
|
227
|
+
const base = needsPlace
|
|
228
|
+
? (() => {
|
|
229
|
+
const boxes = drawnBoxes(grid);
|
|
230
|
+
return placeWhereDrawn(
|
|
231
|
+
tiles,
|
|
232
|
+
tiles.map((tile) => boxes.get(tileKey(tile))),
|
|
233
|
+
columns,
|
|
234
|
+
trackWidth(gridBoxNow.width, columns),
|
|
235
|
+
);
|
|
236
|
+
})()
|
|
237
|
+
: [...tiles];
|
|
238
|
+
const placed = isPlaced(base);
|
|
239
|
+
const tile = base[index];
|
|
240
|
+
const from = shapeOf(tile);
|
|
241
|
+
// A flowing tile on auto height starts from the rows it is drawn at,
|
|
242
|
+
// so the edge does not jump when it is first pulled.
|
|
243
|
+
if (!placed && from.rowspan === undefined) {
|
|
244
|
+
startedAuto.current = tileBox.height;
|
|
245
|
+
} else startedAuto.current = undefined;
|
|
246
|
+
const begun = placed ? { ...from, rowspan: rowsOf(tile) } : from;
|
|
247
|
+
setDrag({
|
|
248
|
+
index,
|
|
249
|
+
edges,
|
|
250
|
+
base,
|
|
251
|
+
placedHere: Boolean(needsPlace),
|
|
252
|
+
placed,
|
|
253
|
+
from,
|
|
254
|
+
begun,
|
|
255
|
+
shape: begun,
|
|
256
|
+
guideTop: tileBox.top - gridBoxNow.top,
|
|
257
|
+
min: minRowsOf(tile, event.currentTarget.parentElement),
|
|
258
|
+
top: tileBox.top,
|
|
259
|
+
left: tileBox.left,
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const move = (event: React.PointerEvent<HTMLElement>) => {
|
|
264
|
+
const state = live.current;
|
|
265
|
+
const grid = gridBox.current?.getBoundingClientRect();
|
|
266
|
+
if (!state || !grid) return;
|
|
267
|
+
const tile = state.base[state.index];
|
|
268
|
+
if (!tile) return;
|
|
269
|
+
const track = trackWidth(grid.width, columns);
|
|
270
|
+
const colStep = track + GRID_GAP_PX;
|
|
271
|
+
// The pointer against the grid as it is now, so a page that scrolled
|
|
272
|
+
// during the drag still lands the edge under the pointer.
|
|
273
|
+
const x = event.clientX - grid.left;
|
|
274
|
+
const y = event.clientY - grid.top;
|
|
275
|
+
// The tile's own box as it is drawn now. A bottom or right edge is
|
|
276
|
+
// measured from it, not from the grid's rows: on a narrow screen a
|
|
277
|
+
// placed report stacks in one column, where a tile's row says nothing
|
|
278
|
+
// about where it is, and a page scrolled mid-drag moves it too.
|
|
279
|
+
const own = event.currentTarget.parentElement?.getBoundingClientRect();
|
|
280
|
+
const ownTop = own?.top ?? state.top;
|
|
281
|
+
const ownLeft = own?.left ?? state.left;
|
|
282
|
+
const { min } = state;
|
|
283
|
+
const now = state.shape;
|
|
284
|
+
let { row, col, colspan, rowspan } = now;
|
|
285
|
+
|
|
286
|
+
if (state.placed && col !== undefined && row !== undefined) {
|
|
287
|
+
const from = state.from;
|
|
288
|
+
const firstCol = from.col ?? col;
|
|
289
|
+
const lastCol = firstCol + from.colspan - 1;
|
|
290
|
+
const firstRow = from.row ?? row;
|
|
291
|
+
const fromRows = from.rowspan ?? rowsOf(tile);
|
|
292
|
+
const lastRow = firstRow + fromRows - 1;
|
|
293
|
+
if (state.edges.e) {
|
|
294
|
+
const right = Math.round((x + GRID_GAP_PX) / colStep);
|
|
295
|
+
colspan =
|
|
296
|
+
Math.min(Math.max(right, firstCol), columns) - firstCol + 1;
|
|
297
|
+
col = firstCol;
|
|
298
|
+
}
|
|
299
|
+
if (state.edges.w) {
|
|
300
|
+
const left = Math.round(x / colStep) + 1;
|
|
301
|
+
col = Math.min(Math.max(left, 1), lastCol);
|
|
302
|
+
colspan = lastCol - col + 1;
|
|
303
|
+
}
|
|
304
|
+
if (state.edges.s) {
|
|
305
|
+
// From the tile's top, so it is right in the stacked layout too.
|
|
306
|
+
// A top edge moved in the same gesture (a corner) has moved that
|
|
307
|
+
// top already, so it is measured from the row it started on.
|
|
308
|
+
const top = state.edges.n
|
|
309
|
+
? grid.top + (firstRow - 1) * ROW_STEP
|
|
310
|
+
: ownTop;
|
|
311
|
+
rowspan = rowsForHeight(event.clientY - top, min);
|
|
312
|
+
row = firstRow;
|
|
313
|
+
}
|
|
314
|
+
if (state.edges.n) {
|
|
315
|
+
const top = Math.round(y / ROW_STEP) + 1;
|
|
316
|
+
// A tile already shorter than its floor (a 2-row chart written
|
|
317
|
+
// by hand, or one still loading) holds the rows it has rather
|
|
318
|
+
// than growing upward, which could put its top above row 1.
|
|
319
|
+
const floor = Math.min(min, fromRows);
|
|
320
|
+
row = Math.max(
|
|
321
|
+
1,
|
|
322
|
+
Math.min(
|
|
323
|
+
Math.max(top, lastRow - MAX_TILE_ROWS + 1),
|
|
324
|
+
lastRow - floor + 1,
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
rowspan = lastRow - row + 1;
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
// A report that flows: the right edge is a width and the bottom
|
|
331
|
+
// edge a height, each against the tile's own top left.
|
|
332
|
+
if (state.edges.e) {
|
|
333
|
+
const span = Math.round(
|
|
334
|
+
(event.clientX - ownLeft + GRID_GAP_PX) / colStep,
|
|
335
|
+
);
|
|
336
|
+
colspan = Math.min(Math.max(span, 1), columns);
|
|
337
|
+
}
|
|
338
|
+
if (state.edges.s) {
|
|
339
|
+
const px = event.clientY - ownTop;
|
|
340
|
+
const rows = rowsForHeight(px, min);
|
|
341
|
+
const auto = autoHeight(state);
|
|
342
|
+
// Ties go to rows: a neighbour stretched to the preview is no
|
|
343
|
+
// reason to leave it.
|
|
344
|
+
rowspan =
|
|
345
|
+
auto !== undefined &&
|
|
346
|
+
Math.abs(px - auto) < Math.abs(px - tileHeightPx(rows))
|
|
347
|
+
? undefined
|
|
348
|
+
: rows;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const next: TileShape = {
|
|
352
|
+
...(row !== undefined ? { row } : {}),
|
|
353
|
+
...(col !== undefined ? { col } : {}),
|
|
354
|
+
colspan,
|
|
355
|
+
rowspan,
|
|
356
|
+
};
|
|
357
|
+
if (!sameShape(next, now)) setDrag({ ...state, shape: next });
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const end = (event: React.PointerEvent<HTMLElement>) => {
|
|
361
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId))
|
|
362
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
363
|
+
dragChrome(undefined);
|
|
364
|
+
const state = live.current;
|
|
365
|
+
startedAuto.current = undefined;
|
|
366
|
+
if (!state) return;
|
|
367
|
+
setDrag(undefined);
|
|
368
|
+
// A cancelled gesture puts the tile back, and a press that changed
|
|
369
|
+
// nothing writes nothing: a click on an edge must not place a report
|
|
370
|
+
// that flows, or pin a tile on auto height to the rows it is drawn at.
|
|
371
|
+
if (event.type === "pointercancel" || sameShape(state.shape, state.begun))
|
|
372
|
+
return;
|
|
373
|
+
commit({
|
|
374
|
+
index: state.index,
|
|
375
|
+
edges: state.edges,
|
|
376
|
+
shape: state.shape,
|
|
377
|
+
placed: state.placed,
|
|
378
|
+
...(state.placedHere ? { placedAll: state.base } : {}),
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
return { drag, start, move, end };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** What a resize would make a tile, in words, for the label beside the pointer. */
|
|
386
|
+
export function shapeLabel(drag: EdgeDrag, columns: number): string {
|
|
387
|
+
const parts: string[] = [];
|
|
388
|
+
if (drag.edges.e || drag.edges.w)
|
|
389
|
+
parts.push(widthLabel(drag.shape.colspan, columns));
|
|
390
|
+
if (drag.edges.n || drag.edges.s)
|
|
391
|
+
parts.push(
|
|
392
|
+
drag.shape.rowspan === undefined
|
|
393
|
+
? "Auto height"
|
|
394
|
+
: `${drag.shape.rowspan} rows tall`,
|
|
395
|
+
);
|
|
396
|
+
return parts.join(" · ");
|
|
397
|
+
}
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { GAP_TYPE, type GapData } from "./sortable";
|
|
22
22
|
|
|
23
23
|
/** The boxes of the tiles as drawn, against the grid's top left corner, by tile key. */
|
|
24
|
-
function drawnBoxes(grid: HTMLElement): Map<string, Box> {
|
|
24
|
+
export function drawnBoxes(grid: HTMLElement): Map<string, Box> {
|
|
25
25
|
const origin = grid.getBoundingClientRect();
|
|
26
26
|
const boxes = new Map<string, Box>();
|
|
27
27
|
for (const frame of grid.querySelectorAll<HTMLElement>("[data-tile-key]")) {
|