@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
|
@@ -1,146 +0,0 @@
|
|
|
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 } from "../Dashboard/DashboardGrid";
|
|
8
|
-
import type { DashboardTile } from "./document";
|
|
9
|
-
import { useTileResize } from "./useTileResize";
|
|
10
|
-
|
|
11
|
-
const COLUMNS = 12;
|
|
12
|
-
const GRID_WIDTH = 1200 + GRID_GAP_PX * (COLUMNS - 1);
|
|
13
|
-
const TRACK = 100;
|
|
14
|
-
|
|
15
|
-
const tiles: DashboardTile[] = [
|
|
16
|
-
{
|
|
17
|
-
name: "a",
|
|
18
|
-
source: "s",
|
|
19
|
-
declaration: { kind: "reference", from: "x" },
|
|
20
|
-
colspan: 6,
|
|
21
|
-
},
|
|
22
|
-
{ name: "b", source: "s", declaration: { kind: "inherited" } },
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
/** A pointer event on a handle whose tile starts at `left`, with the grid measured. */
|
|
26
|
-
const pointer = (clientX: number, left = 0) => {
|
|
27
|
-
const handle = document.createElement("div");
|
|
28
|
-
const tile = document.createElement("div");
|
|
29
|
-
tile.appendChild(handle);
|
|
30
|
-
tile.getBoundingClientRect = () =>
|
|
31
|
-
({ left, width: 600, top: 0, height: 100 }) as DOMRect;
|
|
32
|
-
let captured = false;
|
|
33
|
-
Object.assign(handle, {
|
|
34
|
-
setPointerCapture: () => {
|
|
35
|
-
captured = true;
|
|
36
|
-
},
|
|
37
|
-
hasPointerCapture: () => captured,
|
|
38
|
-
releasePointerCapture: () => {
|
|
39
|
-
captured = false;
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
return {
|
|
43
|
-
clientX,
|
|
44
|
-
pointerId: 1,
|
|
45
|
-
currentTarget: handle,
|
|
46
|
-
stopPropagation: mock(() => {}),
|
|
47
|
-
preventDefault: mock(() => {}),
|
|
48
|
-
} as unknown as PointerEvent<HTMLDivElement>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const mount = () => {
|
|
52
|
-
const commit = mock((_index: number, _span: number) => {});
|
|
53
|
-
const onStart = mock((_index: number) => {});
|
|
54
|
-
const grid = document.createElement("div");
|
|
55
|
-
grid.getBoundingClientRect = () =>
|
|
56
|
-
({ left: 0, width: GRID_WIDTH, top: 0, height: 400 }) as DOMRect;
|
|
57
|
-
const gridBox = { current: grid as HTMLDivElement | null };
|
|
58
|
-
const view = renderHook(() =>
|
|
59
|
-
useTileResize({ tiles, columns: COLUMNS, gridBox, onStart, commit }),
|
|
60
|
-
);
|
|
61
|
-
return { view, commit, onStart };
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
describe("useTileResize", () => {
|
|
65
|
-
it("previews the width in whole columns as the edge moves, and writes it once on release", () => {
|
|
66
|
-
const { view, commit, onStart } = mount();
|
|
67
|
-
act(() => view.result.current.startResize(pointer(600), 0));
|
|
68
|
-
expect(onStart).toHaveBeenCalledWith(0);
|
|
69
|
-
expect(view.result.current.resize).toMatchObject({
|
|
70
|
-
index: 0,
|
|
71
|
-
span: 6,
|
|
72
|
-
track: TRACK,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Eight tracks and seven gutters: the edge sits at exactly eight columns.
|
|
76
|
-
act(() =>
|
|
77
|
-
view.result.current.onResize(pointer(8 * TRACK + 7 * GRID_GAP_PX)),
|
|
78
|
-
);
|
|
79
|
-
expect(view.result.current.resize?.span).toBe(8);
|
|
80
|
-
// Part way into the ninth column still rounds to eight; nothing is
|
|
81
|
-
// written yet.
|
|
82
|
-
act(() =>
|
|
83
|
-
view.result.current.onResize(
|
|
84
|
-
pointer(8 * TRACK + 7 * GRID_GAP_PX + TRACK / 3),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
expect(view.result.current.resize?.span).toBe(8);
|
|
88
|
-
expect(commit).not.toHaveBeenCalled();
|
|
89
|
-
|
|
90
|
-
act(() => view.result.current.endResize(pointer(0)));
|
|
91
|
-
expect(commit).toHaveBeenCalledTimes(1);
|
|
92
|
-
expect(commit).toHaveBeenCalledWith(0, 8);
|
|
93
|
-
expect(view.result.current.resize).toBeUndefined();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("clamps the preview to the grid, one column to full width", () => {
|
|
97
|
-
const { view } = mount();
|
|
98
|
-
act(() => view.result.current.startResize(pointer(600), 0));
|
|
99
|
-
act(() => view.result.current.onResize(pointer(-500)));
|
|
100
|
-
expect(view.result.current.resize?.span).toBe(1);
|
|
101
|
-
act(() => view.result.current.onResize(pointer(GRID_WIDTH * 3)));
|
|
102
|
-
expect(view.result.current.resize?.span).toBe(COLUMNS);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("writes nothing for a press that does not change the width", () => {
|
|
106
|
-
const { view, commit } = mount();
|
|
107
|
-
act(() => view.result.current.startResize(pointer(600), 1));
|
|
108
|
-
act(() => view.result.current.endResize(pointer(600)));
|
|
109
|
-
expect(commit).not.toHaveBeenCalled();
|
|
110
|
-
expect(view.result.current.resize).toBeUndefined();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("puts the width back when the gesture is cancelled", () => {
|
|
114
|
-
const { view, commit } = mount();
|
|
115
|
-
act(() => view.result.current.startResize(pointer(600), 0));
|
|
116
|
-
act(() =>
|
|
117
|
-
view.result.current.onResize(pointer(8 * TRACK + 7 * GRID_GAP_PX)),
|
|
118
|
-
);
|
|
119
|
-
expect(view.result.current.resize?.span).toBe(8);
|
|
120
|
-
act(() =>
|
|
121
|
-
view.result.current.endResize({
|
|
122
|
-
...pointer(0),
|
|
123
|
-
type: "pointercancel",
|
|
124
|
-
} as PointerEvent<HTMLDivElement>),
|
|
125
|
-
);
|
|
126
|
-
expect(commit).not.toHaveBeenCalled();
|
|
127
|
-
expect(view.result.current.resize).toBeUndefined();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("does nothing when the grid has not been measured", () => {
|
|
131
|
-
const commit = mock(() => {});
|
|
132
|
-
const view = renderHook(() =>
|
|
133
|
-
useTileResize({
|
|
134
|
-
tiles,
|
|
135
|
-
columns: COLUMNS,
|
|
136
|
-
gridBox: { current: null },
|
|
137
|
-
onStart: () => {},
|
|
138
|
-
commit,
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
141
|
-
act(() => view.result.current.startResize(pointer(600), 0));
|
|
142
|
-
expect(view.result.current.resize).toBeUndefined();
|
|
143
|
-
act(() => view.result.current.endResize(pointer(0)));
|
|
144
|
-
expect(commit).not.toHaveBeenCalled();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { useEffect, useRef, useState, type RefObject } from "react";
|
|
5
|
-
import { GRID_GAP_PX } from "../Dashboard/DashboardGrid";
|
|
6
|
-
import type { DashboardTile } from "./document";
|
|
7
|
-
|
|
8
|
-
/** A resize in flight: the tile, the width it WOULD be, and the geometry. */
|
|
9
|
-
export interface ResizeState {
|
|
10
|
-
index: number;
|
|
11
|
-
span: number;
|
|
12
|
-
/** The width the drag started from, so a release that changed nothing writes nothing. */
|
|
13
|
-
from: number;
|
|
14
|
-
left: number;
|
|
15
|
-
track: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* While a RESIZE is live, the page has to stop behaving like a document:
|
|
20
|
-
* dragging an edge across a dashboard otherwise selects the text it crosses and
|
|
21
|
-
* leaves the cursor as whatever it was over. (A MOVE gets the same from the
|
|
22
|
-
* library's own plugins.)
|
|
23
|
-
*/
|
|
24
|
-
const dragChrome = (on: boolean) => {
|
|
25
|
-
const body = window.document.body;
|
|
26
|
-
body.style.userSelect = on ? "none" : "";
|
|
27
|
-
body.style.cursor = on ? "grabbing" : "";
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Dragging a tile's right edge to set its `colspan`. The width is previewed
|
|
32
|
-
* by the caller from `resize.span` and written ONCE, on release: writing on
|
|
33
|
-
* every pointer move would put a dozen documents in the history for one
|
|
34
|
-
* gesture, and undo would walk back through the drag a column at a time.
|
|
35
|
-
*/
|
|
36
|
-
export function useTileResize({
|
|
37
|
-
tiles,
|
|
38
|
-
columns,
|
|
39
|
-
gridBox,
|
|
40
|
-
onStart,
|
|
41
|
-
commit,
|
|
42
|
-
}: {
|
|
43
|
-
tiles: readonly DashboardTile[];
|
|
44
|
-
columns: number;
|
|
45
|
-
/** Wraps the grid, so its content box IS the grid's: what a dragged edge is measured against to work out a column count. */
|
|
46
|
-
gridBox: RefObject<HTMLDivElement | null>;
|
|
47
|
-
/** The tile a resize begins on, which the caller selects. */
|
|
48
|
-
onStart: (index: number) => void;
|
|
49
|
-
/** The width to write when the drag ends. */
|
|
50
|
-
commit: (index: number, span: number) => void;
|
|
51
|
-
}) {
|
|
52
|
-
const [resize, setResizeState] = useState<ResizeState | undefined>(
|
|
53
|
-
undefined,
|
|
54
|
-
);
|
|
55
|
-
// The gesture as the handlers last left it. A release can arrive before the
|
|
56
|
-
// render for the last move does, and reading state there would write the
|
|
57
|
-
// width one column behind where the pointer let go.
|
|
58
|
-
const live = useRef<ResizeState | undefined>(undefined);
|
|
59
|
-
const setResize = (next: ResizeState | undefined) => {
|
|
60
|
-
live.current = next;
|
|
61
|
-
setResizeState(next);
|
|
62
|
-
};
|
|
63
|
-
// A builder unmounted mid-drag (a route change, say) must not leave the
|
|
64
|
-
// whole page unselectable with a grabbing cursor.
|
|
65
|
-
useEffect(() => () => dragChrome(false), []);
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Width is the ONLY thing a resize can change.
|
|
69
|
-
*
|
|
70
|
-
* The format lays tiles out as a flow — `# colspan` for width, `# break` to
|
|
71
|
-
* start a row — with no row index, no column position and no height. So a
|
|
72
|
-
* right edge maps onto `colspan` and persists; a bottom edge has nothing to
|
|
73
|
-
* be written as, and a left edge would mean placing the tile, which the grid
|
|
74
|
-
* cannot express either. Offering those handles would be offering a drag the
|
|
75
|
-
* writer then refuses, which is worse than not offering it.
|
|
76
|
-
*/
|
|
77
|
-
const startResize = (
|
|
78
|
-
event: React.PointerEvent<HTMLDivElement>,
|
|
79
|
-
index: number,
|
|
80
|
-
) => {
|
|
81
|
-
const grid = gridBox.current?.getBoundingClientRect();
|
|
82
|
-
const tile = event.currentTarget.parentElement?.getBoundingClientRect();
|
|
83
|
-
if (!grid || !tile) return;
|
|
84
|
-
// Stops the tile's own click selecting a second time on release.
|
|
85
|
-
event.stopPropagation();
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
event.currentTarget.setPointerCapture(event.pointerId);
|
|
88
|
-
dragChrome(true);
|
|
89
|
-
onStart(index);
|
|
90
|
-
const from = tiles[index]?.colspan ?? 1;
|
|
91
|
-
setResize({
|
|
92
|
-
index,
|
|
93
|
-
span: from,
|
|
94
|
-
from,
|
|
95
|
-
left: tile.left,
|
|
96
|
-
// One column track: the row's width less every gutter in it.
|
|
97
|
-
track: (grid.width - GRID_GAP_PX * (columns - 1)) / columns,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const onResize = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
102
|
-
const resize = live.current;
|
|
103
|
-
if (!resize) return;
|
|
104
|
-
const width = event.clientX - resize.left;
|
|
105
|
-
// A tile of N tracks is N tracks plus the N-1 gutters between them, so
|
|
106
|
-
// adding one gutter back makes the division land on whole columns.
|
|
107
|
-
const span = Math.round(
|
|
108
|
-
(width + GRID_GAP_PX) / (resize.track + GRID_GAP_PX),
|
|
109
|
-
);
|
|
110
|
-
const clamped = Math.min(Math.max(span, 1), columns);
|
|
111
|
-
if (clamped !== resize.span) setResize({ ...resize, span: clamped });
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const endResize = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
115
|
-
if (event.currentTarget.hasPointerCapture(event.pointerId))
|
|
116
|
-
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
117
|
-
dragChrome(false);
|
|
118
|
-
const resize = live.current;
|
|
119
|
-
if (!resize) return;
|
|
120
|
-
const { index, span, from } = resize;
|
|
121
|
-
setResize(undefined);
|
|
122
|
-
// A cancelled gesture (the browser took the pointer) puts the width back;
|
|
123
|
-
// a press that moved nothing writes nothing, or a tile with no
|
|
124
|
-
// `# colspan` would gain an explicit `colspan=1` from a click.
|
|
125
|
-
if (event.type === "pointercancel" || span === from) return;
|
|
126
|
-
// ONE history entry for the whole drag. Writing on every pointer move
|
|
127
|
-
// would put a dozen documents in the stack for one gesture, and undo
|
|
128
|
-
// would walk back through the drag a column at a time.
|
|
129
|
-
commit(index, span);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return { resize, startResize, onResize, endResize };
|
|
133
|
-
}
|