@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.
- package/dist/RenderedResult-5hOs5XnV.cjs.js +171 -0
- package/dist/RenderedResult-DxmHGZNQ.es.js +671 -0
- package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
- package/dist/ServerProvider-e2369oom.cjs.js +1 -0
- package/dist/builder/index.cjs.js +80 -79
- package/dist/builder/index.es.js +7732 -6717
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +31 -7
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +51 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +7 -2
- package/dist/components/Dashboard/DashboardView.d.ts +9 -2
- package/dist/components/Dashboard/index.d.ts +1 -1
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
- package/dist/components/Dashboard/useStuck.d.ts +18 -12
- package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
- package/dist/components/RenderedResult/ResultContainer.d.ts +18 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +7 -1
- package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
- package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +47 -6
- package/dist/components/Report/Report.d.ts +7 -1
- package/dist/components/Report/ReportPage.d.ts +7 -0
- package/dist/components/Report/layoutRules.d.ts +45 -0
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
- package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +15 -4
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +10 -1
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
- package/dist/components/ReportBuilder/TileFrame.d.ts +54 -10
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
- package/dist/components/ReportBuilder/catalog.d.ts +23 -0
- package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
- package/dist/components/ReportBuilder/controls.d.ts +2 -2
- package/dist/components/ReportBuilder/document.d.ts +53 -5
- package/dist/components/ReportBuilder/imports.d.ts +7 -0
- package/dist/components/ReportBuilder/placement.d.ts +121 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +12 -1
- 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 +30 -3
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3349 -3307
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
- package/dist/theme/classes.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-CaYP_OYG.es.js} +6353 -6047
- package/dist/useCompiledDocument-zYEfLogf.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/builder-entry.ts +1 -0
- package/src/components/Dashboard/DashboardGrid.tsx +129 -10
- package/src/components/Dashboard/DashboardTile.tsx +15 -1
- package/src/components/Dashboard/DashboardView.tsx +64 -10
- package/src/components/Dashboard/TileCard.tsx +6 -0
- package/src/components/Dashboard/index.ts +1 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
- package/src/components/Dashboard/tileHeight.spec.ts +72 -0
- package/src/components/Dashboard/useStuck.ts +76 -28
- package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
- package/src/components/Package/NewDocumentDialog.tsx +10 -11
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
- package/src/components/RenderedResult/RenderedResult.tsx +39 -6
- package/src/components/RenderedResult/ResultContainer.tsx +99 -10
- package/src/components/RenderedResult/ResultPanel.tsx +25 -1
- package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
- package/src/components/RenderedResult/chartPresentation.ts +166 -0
- package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
- package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
- package/src/components/RenderedResult/resultSizing.ts +71 -11
- package/src/components/Report/Report.spec.tsx +19 -0
- package/src/components/Report/Report.tsx +8 -1
- package/src/components/Report/ReportPage.tsx +13 -1
- package/src/components/Report/layoutRules.spec.ts +43 -3
- package/src/components/Report/layoutRules.ts +70 -0
- package/src/components/Report/tileOverflow.spec.tsx +162 -0
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
- package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
- package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
- package/src/components/ReportBuilder/BuilderBar.tsx +5 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -1
- package/src/components/ReportBuilder/BuilderGrid.tsx +142 -35
- package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
- package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
- package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
- package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
- package/src/components/ReportBuilder/EditorSurface.tsx +101 -20
- package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
- package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +242 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +161 -27
- package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +13 -0
- package/src/components/ReportBuilder/TileFrame.tsx +366 -170
- package/src/components/ReportBuilder/TileMenu.tsx +259 -20
- package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
- package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
- package/src/components/ReportBuilder/builderControls.ts +34 -0
- package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
- package/src/components/ReportBuilder/catalog.ts +90 -37
- package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
- package/src/components/ReportBuilder/chartLine.ts +80 -2
- package/src/components/ReportBuilder/controls.ts +4 -3
- package/src/components/ReportBuilder/document.ts +65 -7
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
- package/src/components/ReportBuilder/imports.ts +1 -1
- package/src/components/ReportBuilder/invariants.spec.ts +18 -10
- package/src/components/ReportBuilder/layout.ts +3 -0
- package/src/components/ReportBuilder/placement.spec.ts +401 -0
- package/src/components/ReportBuilder/placement.ts +416 -0
- package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
- package/src/components/ReportBuilder/preview.spec.ts +151 -11
- package/src/components/ReportBuilder/preview.ts +203 -40
- package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
- package/src/components/ReportBuilder/readDocument.spec.ts +53 -19
- package/src/components/ReportBuilder/readDocument.ts +197 -29
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +30 -2
- package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
- package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
- package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
- package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -58
- package/src/components/ReportBuilder/spliceDocument.ts +139 -91
- package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
- package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
- package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
- package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
- 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/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/classes.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +72 -1
- package/src/theme/resolveTheme.ts +43 -0
- package/src/utils/blankQuoted.spec.ts +50 -0
- package/src/utils/blankQuoted.ts +32 -0
- package/src/utils/malloyText.ts +2 -1
- package/dist/RenderedResult-DnBtf-cI.es.js +0 -593
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/components/ReportBuilder/useTileResize.d.ts +0 -32
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
- package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
- package/src/components/ReportBuilder/useTileResize.ts +0 -133
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { act, renderHook } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import type { PointerEvent } from "react";
|
|
7
|
+
import { GRID_GAP_PX, TILE_ROW_PX } from "../Dashboard/DashboardGrid";
|
|
8
|
+
import type { DashboardTile } from "./document";
|
|
9
|
+
import {
|
|
10
|
+
edgeCursor,
|
|
11
|
+
useEdgeResize,
|
|
12
|
+
withShape,
|
|
13
|
+
type EdgeResult,
|
|
14
|
+
type Edges,
|
|
15
|
+
} from "./useEdgeResize";
|
|
16
|
+
|
|
17
|
+
const COLUMNS = 12;
|
|
18
|
+
const TRACK = 100;
|
|
19
|
+
const COL = TRACK + GRID_GAP_PX;
|
|
20
|
+
const ROW = TILE_ROW_PX + GRID_GAP_PX;
|
|
21
|
+
const GRID_WIDTH = COLUMNS * TRACK + (COLUMNS - 1) * GRID_GAP_PX;
|
|
22
|
+
|
|
23
|
+
const tile = (layout: Partial<DashboardTile> = {}): DashboardTile =>
|
|
24
|
+
({
|
|
25
|
+
name: "a",
|
|
26
|
+
source: "s",
|
|
27
|
+
declaration: { kind: "reference", from: "x" },
|
|
28
|
+
...layout,
|
|
29
|
+
}) as DashboardTile;
|
|
30
|
+
|
|
31
|
+
/** A pointer event on an edge whose tile's box is `box`, in grid coordinates (the grid sits at 0,0). */
|
|
32
|
+
const pointer = (
|
|
33
|
+
clientX: number,
|
|
34
|
+
clientY: number,
|
|
35
|
+
box = {
|
|
36
|
+
left: 0,
|
|
37
|
+
top: 0,
|
|
38
|
+
width: 6 * COL - GRID_GAP_PX,
|
|
39
|
+
height: 3 * ROW - GRID_GAP_PX,
|
|
40
|
+
},
|
|
41
|
+
type = "pointermove",
|
|
42
|
+
) => {
|
|
43
|
+
const edge = document.createElement("div");
|
|
44
|
+
const frame = document.createElement("div");
|
|
45
|
+
frame.appendChild(edge);
|
|
46
|
+
frame.getBoundingClientRect = () => box as DOMRect;
|
|
47
|
+
let captured = false;
|
|
48
|
+
Object.assign(edge, {
|
|
49
|
+
setPointerCapture: () => {
|
|
50
|
+
captured = true;
|
|
51
|
+
},
|
|
52
|
+
hasPointerCapture: () => captured,
|
|
53
|
+
releasePointerCapture: () => {
|
|
54
|
+
captured = false;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
type,
|
|
59
|
+
button: 0,
|
|
60
|
+
clientX,
|
|
61
|
+
clientY,
|
|
62
|
+
pointerId: 1,
|
|
63
|
+
currentTarget: edge,
|
|
64
|
+
stopPropagation: mock(() => {}),
|
|
65
|
+
preventDefault: mock(() => {}),
|
|
66
|
+
} as unknown as PointerEvent<HTMLElement>;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const mount = (tiles: DashboardTile[]) => {
|
|
70
|
+
const commit = mock((_result: EdgeResult) => {});
|
|
71
|
+
const grid = document.createElement("div");
|
|
72
|
+
grid.getBoundingClientRect = () =>
|
|
73
|
+
({ left: 0, top: 0, width: GRID_WIDTH, height: 2000 }) as DOMRect;
|
|
74
|
+
// Each tile drawn in the grid, as placing a report that flows measures
|
|
75
|
+
// them: six columns wide and three rows tall at the top left.
|
|
76
|
+
for (const each of tiles) {
|
|
77
|
+
const frame = document.createElement("div");
|
|
78
|
+
frame.dataset.tileKey = `${(each as { source: string }).source}.${each.name}`;
|
|
79
|
+
frame.getBoundingClientRect = () =>
|
|
80
|
+
({
|
|
81
|
+
left: 0,
|
|
82
|
+
top: 0,
|
|
83
|
+
width: 6 * COL - GRID_GAP_PX,
|
|
84
|
+
height: 3 * ROW - GRID_GAP_PX,
|
|
85
|
+
}) as DOMRect;
|
|
86
|
+
grid.appendChild(frame);
|
|
87
|
+
}
|
|
88
|
+
const gridBox = { current: grid as HTMLDivElement | null };
|
|
89
|
+
const view = renderHook(() =>
|
|
90
|
+
useEdgeResize({
|
|
91
|
+
tiles,
|
|
92
|
+
columns: COLUMNS,
|
|
93
|
+
gridBox,
|
|
94
|
+
onStart: () => {},
|
|
95
|
+
commit,
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
const drag = (
|
|
99
|
+
edges: Edges,
|
|
100
|
+
x: number,
|
|
101
|
+
y: number,
|
|
102
|
+
box?: Parameters<typeof pointer>[2],
|
|
103
|
+
) => {
|
|
104
|
+
act(() => view.result.current.start(pointer(0, 0, box), 0, edges));
|
|
105
|
+
act(() => view.result.current.move(pointer(x, y, box)));
|
|
106
|
+
const shape = view.result.current.drag?.shape;
|
|
107
|
+
act(() => view.result.current.end(pointer(x, y, box, "pointerup")));
|
|
108
|
+
return shape;
|
|
109
|
+
};
|
|
110
|
+
return { view, commit, drag };
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
describe("useEdgeResize on a placed report", () => {
|
|
114
|
+
const placed = () => [tile({ row: 3, col: 4, colspan: 4, rowspan: 4 })];
|
|
115
|
+
// The tile's box: columns 4-7, rows 3-6.
|
|
116
|
+
const box = {
|
|
117
|
+
left: 3 * COL,
|
|
118
|
+
top: 2 * ROW,
|
|
119
|
+
width: 4 * COL - GRID_GAP_PX,
|
|
120
|
+
height: 4 * ROW - GRID_GAP_PX,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
it("moves the left edge and keeps the right one", () => {
|
|
124
|
+
const { commit, drag } = mount(placed());
|
|
125
|
+
// The pointer at the start of column 2.
|
|
126
|
+
expect(drag({ w: true }, 1 * COL + 4, 0, box)).toMatchObject({
|
|
127
|
+
col: 2,
|
|
128
|
+
colspan: 6,
|
|
129
|
+
});
|
|
130
|
+
expect(commit.mock.calls[0]?.[0]).toMatchObject({
|
|
131
|
+
edges: { w: true },
|
|
132
|
+
placed: true,
|
|
133
|
+
shape: { col: 2, colspan: 6 },
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("moves the top edge and keeps the bottom one", () => {
|
|
138
|
+
const { drag } = mount(placed());
|
|
139
|
+
// The pointer at the top of row 1.
|
|
140
|
+
expect(drag({ n: true }, 0, 4, box)).toMatchObject({
|
|
141
|
+
row: 1,
|
|
142
|
+
rowspan: 6,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("holds the top edge to the fewest rows a tile is offered", () => {
|
|
147
|
+
const { drag } = mount(placed());
|
|
148
|
+
// Pulled far below its own bottom: three rows are the floor, ending at row 6.
|
|
149
|
+
expect(drag({ n: true }, 0, 40 * ROW, box)).toMatchObject({
|
|
150
|
+
row: 4,
|
|
151
|
+
rowspan: 3,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("never puts a tile shorter than its floor above row 1 from the top edge", () => {
|
|
156
|
+
// Two rows at the top, where a chart's floor is three.
|
|
157
|
+
const { commit, drag } = mount([
|
|
158
|
+
tile({ row: 1, col: 1, colspan: 4, rowspan: 2 }),
|
|
159
|
+
]);
|
|
160
|
+
const short = {
|
|
161
|
+
left: 0,
|
|
162
|
+
top: 0,
|
|
163
|
+
width: 4 * COL - GRID_GAP_PX,
|
|
164
|
+
height: 2 * ROW - GRID_GAP_PX,
|
|
165
|
+
};
|
|
166
|
+
// A small press and nudge: it changes nothing, so nothing is written.
|
|
167
|
+
drag({ n: true }, 0, 5, short);
|
|
168
|
+
expect(commit).not.toHaveBeenCalled();
|
|
169
|
+
// Pulled up past the grid's top: still row 1.
|
|
170
|
+
expect(drag({ n: true }, 0, -3 * ROW, short)).toMatchObject({
|
|
171
|
+
row: 1,
|
|
172
|
+
rowspan: 2,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("moves two edges at once from a corner", () => {
|
|
177
|
+
const { drag } = mount(placed());
|
|
178
|
+
// Bottom-right corner to the end of column 9, row 8.
|
|
179
|
+
expect(
|
|
180
|
+
drag(
|
|
181
|
+
{ s: true, e: true },
|
|
182
|
+
9 * COL - GRID_GAP_PX,
|
|
183
|
+
8 * ROW - GRID_GAP_PX,
|
|
184
|
+
box,
|
|
185
|
+
),
|
|
186
|
+
).toMatchObject({
|
|
187
|
+
row: 3,
|
|
188
|
+
col: 4,
|
|
189
|
+
colspan: 6,
|
|
190
|
+
rowspan: 6,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("measures the bottom edge from the tile as drawn, wherever its row is", () => {
|
|
195
|
+
// A placed tile drawn somewhere its row does not say (stacked in one
|
|
196
|
+
// column on a narrow screen): 4 rows tall at y = 1000.
|
|
197
|
+
const stacked = { ...box, top: 1000 };
|
|
198
|
+
const { drag } = mount(placed());
|
|
199
|
+
expect(
|
|
200
|
+
drag({ s: true }, 0, 1000 + 6 * ROW - GRID_GAP_PX, stacked),
|
|
201
|
+
).toMatchObject({ row: 3, rowspan: 6 });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("stops the right edge at the grid's edge, never moving the left", () => {
|
|
205
|
+
const { drag } = mount(placed());
|
|
206
|
+
expect(drag({ e: true }, 50 * COL, 0, box)).toMatchObject({
|
|
207
|
+
col: 4,
|
|
208
|
+
colspan: 9,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe("useEdgeResize on a tile a placed report leaves to the grid", () => {
|
|
214
|
+
it("places that tile where it is drawn when its left edge is pulled", () => {
|
|
215
|
+
const tiles = [
|
|
216
|
+
tile({ colspan: 6 }),
|
|
217
|
+
tile({
|
|
218
|
+
name: "b",
|
|
219
|
+
row: 9,
|
|
220
|
+
col: 1,
|
|
221
|
+
colspan: 6,
|
|
222
|
+
rowspan: 3,
|
|
223
|
+
} as Partial<DashboardTile>),
|
|
224
|
+
];
|
|
225
|
+
const { commit, drag } = mount(tiles);
|
|
226
|
+
drag({ w: true }, 1 * COL + 4, 0);
|
|
227
|
+
const result = commit.mock.calls[0]?.[0];
|
|
228
|
+
expect(result?.placed).toBe(true);
|
|
229
|
+
expect(result?.placedAll?.[0]).toMatchObject({ row: 1, col: 1 });
|
|
230
|
+
expect(result?.shape).toMatchObject({ col: 2, colspan: 5 });
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("useEdgeResize on a report that flows", () => {
|
|
235
|
+
it("sets a width from the right edge, and only a width", () => {
|
|
236
|
+
const { commit, drag } = mount([tile({ colspan: 6 })]);
|
|
237
|
+
drag({ e: true }, 4 * COL - GRID_GAP_PX, 0);
|
|
238
|
+
const result = commit.mock.calls[0]?.[0];
|
|
239
|
+
expect(result).toMatchObject({ placed: false, shape: { colspan: 4 } });
|
|
240
|
+
expect(result?.placedAll).toBeUndefined();
|
|
241
|
+
expect(
|
|
242
|
+
withShape(tile({ colspan: 6 }), result!.shape, result!.edges, false),
|
|
243
|
+
).toEqual(tile({ colspan: 4 }));
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("sets a height from the bottom edge, and leaves the width it is drawn at alone", () => {
|
|
247
|
+
const { commit, drag } = mount([tile({ colspan: 6 })]);
|
|
248
|
+
drag({ s: true }, 0, 5 * ROW - GRID_GAP_PX);
|
|
249
|
+
const result = commit.mock.calls[0]?.[0];
|
|
250
|
+
expect(result?.shape.rowspan).toBe(5);
|
|
251
|
+
// Written on a tile with no colspan, a height drag adds none.
|
|
252
|
+
expect(withShape(tile(), result!.shape, result!.edges, false)).toEqual(
|
|
253
|
+
tile({ rowspan: 5 }),
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("places the report when a left edge is pulled, so the edge has a column to move", () => {
|
|
258
|
+
const { commit, drag } = mount([tile({ colspan: 6 })]);
|
|
259
|
+
drag({ w: true }, 1 * COL + 4, 0);
|
|
260
|
+
const result = commit.mock.calls[0]?.[0];
|
|
261
|
+
expect(result?.placed).toBe(true);
|
|
262
|
+
// Placed where it was drawn (columns 1-6), then its left edge moved to 2.
|
|
263
|
+
expect(result?.placedAll?.[0]).toMatchObject({
|
|
264
|
+
row: 1,
|
|
265
|
+
col: 1,
|
|
266
|
+
colspan: 6,
|
|
267
|
+
});
|
|
268
|
+
expect(result?.shape).toMatchObject({ col: 2, colspan: 5 });
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("writes nothing, and places nothing, for a press that changes nothing", () => {
|
|
272
|
+
const { commit, view } = mount([tile({ colspan: 6 })]);
|
|
273
|
+
act(() => view.result.current.start(pointer(0, 0), 0, { w: true }));
|
|
274
|
+
act(() => view.result.current.end(pointer(0, 0, undefined, "pointerup")));
|
|
275
|
+
expect(commit).not.toHaveBeenCalled();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("puts the tile back when the gesture is cancelled", () => {
|
|
279
|
+
const { commit, view } = mount([tile({ colspan: 6 })]);
|
|
280
|
+
act(() => view.result.current.start(pointer(0, 0), 0, { e: true }));
|
|
281
|
+
act(() => view.result.current.move(pointer(2 * COL, 0)));
|
|
282
|
+
act(() =>
|
|
283
|
+
view.result.current.end(
|
|
284
|
+
pointer(2 * COL, 0, undefined, "pointercancel"),
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
expect(commit).not.toHaveBeenCalled();
|
|
288
|
+
expect(view.result.current.drag).toBeUndefined();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("puts the tile back, and writes nothing, when Escape is pressed mid-drag", () => {
|
|
292
|
+
const { commit, view } = mount([tile({ colspan: 6 })]);
|
|
293
|
+
act(() => view.result.current.start(pointer(0, 0), 0, { e: true }));
|
|
294
|
+
act(() => view.result.current.move(pointer(2 * COL, 0)));
|
|
295
|
+
expect(view.result.current.drag).toBeDefined();
|
|
296
|
+
const escape = new KeyboardEvent("keydown", {
|
|
297
|
+
key: "Escape",
|
|
298
|
+
cancelable: true,
|
|
299
|
+
});
|
|
300
|
+
act(() => {
|
|
301
|
+
window.dispatchEvent(escape);
|
|
302
|
+
});
|
|
303
|
+
expect(escape.defaultPrevented).toBe(true);
|
|
304
|
+
expect(view.result.current.drag).toBeUndefined();
|
|
305
|
+
// The pointer let go after Escape: still nothing written.
|
|
306
|
+
act(() =>
|
|
307
|
+
view.result.current.end(pointer(2 * COL, 0, undefined, "pointerup")),
|
|
308
|
+
);
|
|
309
|
+
expect(commit).not.toHaveBeenCalled();
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("edgeCursor", () => {
|
|
314
|
+
it("is a two-headed arrow on an edge and a diagonal one on a corner", () => {
|
|
315
|
+
expect(edgeCursor({ e: true })).toBe("ew-resize");
|
|
316
|
+
expect(edgeCursor({ w: true })).toBe("ew-resize");
|
|
317
|
+
expect(edgeCursor({ n: true })).toBe("ns-resize");
|
|
318
|
+
expect(edgeCursor({ s: true })).toBe("ns-resize");
|
|
319
|
+
expect(edgeCursor({ n: true, w: true })).toBe("nwse-resize");
|
|
320
|
+
expect(edgeCursor({ s: true, e: true })).toBe("nwse-resize");
|
|
321
|
+
expect(edgeCursor({ n: true, e: true })).toBe("nesw-resize");
|
|
322
|
+
expect(edgeCursor({ s: true, w: true })).toBe("nesw-resize");
|
|
323
|
+
});
|
|
324
|
+
});
|