@malloy-publisher/sdk 0.9.13 → 0.9.15
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 +154 -0
- package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
- 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 +7430 -6548
- package/dist/client/api.d.ts +30 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +5 -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 +11 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +5 -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 +42 -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/BuilderGrid.d.ts +14 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
- package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
- package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- 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 +75 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +3 -1
- package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
- package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3328 -3287
- 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/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +127 -10
- package/src/components/Dashboard/DashboardTile.tsx +11 -1
- package/src/components/Dashboard/DashboardView.tsx +63 -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 +21 -6
- package/src/components/RenderedResult/ResultContainer.tsx +60 -7
- package/src/components/RenderedResult/ResultPanel.tsx +21 -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 +65 -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/BuilderBar.tsx +1 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
- package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
- 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 +110 -28
- 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 +143 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
- 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.queryVersion.spec.tsx +292 -0
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
- package/src/components/ReportBuilder/TileFrame.tsx +251 -6
- 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/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 +193 -0
- package/src/components/ReportBuilder/placement.ts +250 -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 +46 -2
- package/src/components/ReportBuilder/readDocument.ts +194 -23
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +4 -0
- 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 -18
- package/src/components/ReportBuilder/spliceDocument.ts +139 -52
- 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/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileHeight.ts +149 -0
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/ReportBuilder/useTileResize.ts +16 -1
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- 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-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
|
@@ -2,12 +2,42 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { move } from "@dnd-kit/helpers";
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
DragEndEvent,
|
|
7
|
+
DragMoveEvent,
|
|
8
|
+
DragOverEvent,
|
|
9
|
+
} from "@dnd-kit/react";
|
|
10
|
+
import { useRef, useState, type RefObject } from "react";
|
|
7
11
|
import { tileKey, type DashboardTile } from "./document";
|
|
8
12
|
import { keepRowStructure, moveIntoGap } from "./layout";
|
|
13
|
+
import {
|
|
14
|
+
cellAt,
|
|
15
|
+
dropAt,
|
|
16
|
+
inReadingOrder,
|
|
17
|
+
placeWhereDrawn,
|
|
18
|
+
trackWidth,
|
|
19
|
+
type Box,
|
|
20
|
+
} from "./placement";
|
|
9
21
|
import { GAP_TYPE, type GapData } from "./sortable";
|
|
10
22
|
|
|
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> {
|
|
25
|
+
const origin = grid.getBoundingClientRect();
|
|
26
|
+
const boxes = new Map<string, Box>();
|
|
27
|
+
for (const frame of grid.querySelectorAll<HTMLElement>("[data-tile-key]")) {
|
|
28
|
+
const key = frame.dataset.tileKey;
|
|
29
|
+
if (!key) continue;
|
|
30
|
+
const box = frame.getBoundingClientRect();
|
|
31
|
+
boxes.set(key, {
|
|
32
|
+
top: box.top - origin.top,
|
|
33
|
+
left: box.left - origin.left,
|
|
34
|
+
width: box.width,
|
|
35
|
+
height: box.height,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return boxes;
|
|
39
|
+
}
|
|
40
|
+
|
|
11
41
|
/**
|
|
12
42
|
* Dragging a tile to reorder it. The gesture is `@dnd-kit/react`'s (see
|
|
13
43
|
* `sortable.tsx`); what is decided here is what a drop means for the file,
|
|
@@ -19,8 +49,19 @@ export function useTileReorder({
|
|
|
19
49
|
tiles,
|
|
20
50
|
commit,
|
|
21
51
|
onLanded,
|
|
52
|
+
placement,
|
|
22
53
|
}: {
|
|
23
54
|
tiles: DashboardTile[];
|
|
55
|
+
/**
|
|
56
|
+
* Set on a grid report, where a move is free placement: the tile lands in
|
|
57
|
+
* the cell under it and anything it covers is pushed down. Absent, a move
|
|
58
|
+
* reorders the tiles, as a linear report's does.
|
|
59
|
+
*/
|
|
60
|
+
placement?: {
|
|
61
|
+
columns: number;
|
|
62
|
+
/** Wraps the grid, so its box is the grid's. */
|
|
63
|
+
gridBox: RefObject<HTMLDivElement | null>;
|
|
64
|
+
};
|
|
24
65
|
/** The order to write when the drag ends somewhere new. */
|
|
25
66
|
commit: (next: DashboardTile[]) => void;
|
|
26
67
|
/** Where the dragged tile came to rest, which the caller selects. */
|
|
@@ -57,12 +98,93 @@ export function useTileReorder({
|
|
|
57
98
|
* rebuilt from the document on each report and written once, on release:
|
|
58
99
|
* ONE history entry for the whole drag, however far it wandered.
|
|
59
100
|
*/
|
|
60
|
-
|
|
101
|
+
// A placement in flight: the tiles placed where they stood when it began,
|
|
102
|
+
// and the moved tile's box then.
|
|
103
|
+
const placing = useRef<
|
|
104
|
+
| {
|
|
105
|
+
base: DashboardTile[];
|
|
106
|
+
index: number;
|
|
107
|
+
from: Box;
|
|
108
|
+
grab: { x: number; y: number };
|
|
109
|
+
}
|
|
110
|
+
| undefined
|
|
111
|
+
>(undefined);
|
|
112
|
+
|
|
113
|
+
const onDragStart = (event?: {
|
|
114
|
+
operation: {
|
|
115
|
+
source: { id: unknown } | null;
|
|
116
|
+
position?: { current: { x: number; y: number } };
|
|
117
|
+
};
|
|
118
|
+
}) => {
|
|
61
119
|
setDragging(true);
|
|
62
120
|
previewRef.current = tiles;
|
|
121
|
+
const grid = placement?.gridBox.current;
|
|
122
|
+
const id = event?.operation.source?.id;
|
|
123
|
+
if (!placement || !grid) return;
|
|
124
|
+
const index = tiles.findIndex((tile) => tileKey(tile) === id);
|
|
125
|
+
const boxes = drawnBoxes(grid);
|
|
126
|
+
const from = boxes.get(String(id));
|
|
127
|
+
if (index < 0 || !from) return;
|
|
128
|
+
// The first move on a report that flows places every tile where it is
|
|
129
|
+
// drawn, so nothing jumps; a placed report keeps what it says.
|
|
130
|
+
const base = placeWhereDrawn(
|
|
131
|
+
tiles,
|
|
132
|
+
tiles.map((tile) => boxes.get(tileKey(tile))),
|
|
133
|
+
placement.columns,
|
|
134
|
+
trackWidth(grid.getBoundingClientRect().width, placement.columns),
|
|
135
|
+
);
|
|
136
|
+
// Where in the tile the pointer took hold, so the tile's corner can be
|
|
137
|
+
// found from the pointer wherever the page has scrolled to since.
|
|
138
|
+
const origin = grid.getBoundingClientRect();
|
|
139
|
+
const pointer = event?.operation.position?.current;
|
|
140
|
+
const grab = pointer
|
|
141
|
+
? {
|
|
142
|
+
x: pointer.x - (origin.left + from.left),
|
|
143
|
+
y: pointer.y - (origin.top + from.top),
|
|
144
|
+
}
|
|
145
|
+
: { x: 0, y: 0 };
|
|
146
|
+
placing.current = { base, index, from, grab };
|
|
147
|
+
previewRef.current = base;
|
|
148
|
+
setPreview(base);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const onDragMove = (event: DragMoveEvent) => {
|
|
152
|
+
const live = placing.current;
|
|
153
|
+
const grid = placement?.gridBox.current;
|
|
154
|
+
if (!live || !placement || !grid) return;
|
|
155
|
+
// The tile's corner against the grid as it is now: from the pointer and
|
|
156
|
+
// the grid's live box, so a page that auto-scrolled during the drag
|
|
157
|
+
// lands the tile under the pointer, not where the pointer was on screen.
|
|
158
|
+
const origin = grid.getBoundingClientRect();
|
|
159
|
+
// A keyboard step reports where it is going (`to`, or `by` from here)
|
|
160
|
+
// before the operation's position catches up; read the position alone
|
|
161
|
+
// and the preview trailed the tile by one key press.
|
|
162
|
+
const now = event.operation.position.current;
|
|
163
|
+
const pointer =
|
|
164
|
+
event.to ??
|
|
165
|
+
(event.by ? { x: now.x + event.by.x, y: now.y + event.by.y } : now);
|
|
166
|
+
const moved = live.base[live.index];
|
|
167
|
+
const cell = cellAt(
|
|
168
|
+
pointer.x - live.grab.x - origin.left,
|
|
169
|
+
pointer.y - live.grab.y - origin.top,
|
|
170
|
+
moved.colspan ?? 1,
|
|
171
|
+
placement.columns,
|
|
172
|
+
trackWidth(grid.getBoundingClientRect().width, placement.columns),
|
|
173
|
+
);
|
|
174
|
+
const current = previewRef.current?.[live.index];
|
|
175
|
+
if (current?.row === cell.row && current.col === cell.col) return;
|
|
176
|
+
const next = dropAt(live.base, live.index, cell, placement.columns);
|
|
177
|
+
previewRef.current = next;
|
|
178
|
+
setPreview(next);
|
|
63
179
|
};
|
|
64
180
|
|
|
65
181
|
const onDragOver = (event: DragOverEvent) => {
|
|
182
|
+
// Placing, where the tile is over says nothing: the cell under it does.
|
|
183
|
+
// Prevented, so the library does not reorder the tiles under it either.
|
|
184
|
+
if (placing.current) {
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
66
188
|
const { source, target } = event.operation;
|
|
67
189
|
if (!source || !target) return;
|
|
68
190
|
const current = previewRef.current ?? tiles;
|
|
@@ -96,10 +218,25 @@ export function useTileReorder({
|
|
|
96
218
|
|
|
97
219
|
const onDragEnd = (event: DragEndEvent) => {
|
|
98
220
|
setDragging(false);
|
|
99
|
-
const
|
|
221
|
+
const live = placing.current;
|
|
222
|
+
const wasPlacing = live !== undefined;
|
|
223
|
+
placing.current = undefined;
|
|
224
|
+
const previewed = previewRef.current;
|
|
225
|
+
// A placing drag that let go in the cell it started from moved nothing:
|
|
226
|
+
// it writes nothing, and a report that flowed keeps flowing rather than
|
|
227
|
+
// being placed (and its heights rounded to rows) by a stray wiggle.
|
|
228
|
+
const stayed =
|
|
229
|
+
live !== undefined &&
|
|
230
|
+
previewed !== undefined &&
|
|
231
|
+
previewed[live.index]?.row === live.base[live.index]?.row &&
|
|
232
|
+
previewed[live.index]?.col === live.base[live.index]?.col;
|
|
233
|
+
// Placed tiles are written in reading order, so the file reads the way
|
|
234
|
+
// the page does and a narrow screen stacks them the same way.
|
|
235
|
+
const next =
|
|
236
|
+
wasPlacing && previewed ? inReadingOrder(previewed) : previewed;
|
|
100
237
|
previewRef.current = undefined;
|
|
101
238
|
setPreview(undefined);
|
|
102
|
-
if (event.canceled || !next) return;
|
|
239
|
+
if (event.canceled || !next || stayed) return;
|
|
103
240
|
// ONE history entry for the whole drag; a drag that ends where it began
|
|
104
241
|
// changes nothing and makes none.
|
|
105
242
|
commit(next);
|
|
@@ -109,5 +246,5 @@ export function useTileReorder({
|
|
|
109
246
|
if (landing >= 0) onLanded(landing);
|
|
110
247
|
};
|
|
111
248
|
|
|
112
|
-
return { dragging, preview, onDragStart, onDragOver, onDragEnd };
|
|
249
|
+
return { dragging, preview, onDragStart, onDragMove, onDragOver, onDragEnd };
|
|
113
250
|
}
|
|
@@ -5,6 +5,17 @@ import { useEffect, useRef, useState, type RefObject } from "react";
|
|
|
5
5
|
import { GRID_GAP_PX } from "../Dashboard/DashboardGrid";
|
|
6
6
|
import type { DashboardTile } from "./document";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The widest a tile may be dragged: the whole grid, or, for a placed tile, up
|
|
10
|
+
* to the grid's right edge from its column. A right edge dragged past the grid
|
|
11
|
+
* stops there; it never moves the tile's left edge.
|
|
12
|
+
*/
|
|
13
|
+
export const widestFrom = (
|
|
14
|
+
tile: DashboardTile | undefined,
|
|
15
|
+
columns: number,
|
|
16
|
+
): number =>
|
|
17
|
+
tile?.col === undefined ? columns : Math.max(1, columns - tile.col + 1);
|
|
18
|
+
|
|
8
19
|
/** A resize in flight: the tile, the width it WOULD be, and the geometry. */
|
|
9
20
|
export interface ResizeState {
|
|
10
21
|
index: number;
|
|
@@ -13,6 +24,8 @@ export interface ResizeState {
|
|
|
13
24
|
from: number;
|
|
14
25
|
left: number;
|
|
15
26
|
track: number;
|
|
27
|
+
/** The widest it may go: to the grid's right edge from the column a placed tile starts in. */
|
|
28
|
+
max: number;
|
|
16
29
|
}
|
|
17
30
|
|
|
18
31
|
/**
|
|
@@ -88,6 +101,7 @@ export function useTileResize({
|
|
|
88
101
|
dragChrome(true);
|
|
89
102
|
onStart(index);
|
|
90
103
|
const from = tiles[index]?.colspan ?? 1;
|
|
104
|
+
const max = widestFrom(tiles[index], columns);
|
|
91
105
|
setResize({
|
|
92
106
|
index,
|
|
93
107
|
span: from,
|
|
@@ -95,6 +109,7 @@ export function useTileResize({
|
|
|
95
109
|
left: tile.left,
|
|
96
110
|
// One column track: the row's width less every gutter in it.
|
|
97
111
|
track: (grid.width - GRID_GAP_PX * (columns - 1)) / columns,
|
|
112
|
+
max,
|
|
98
113
|
});
|
|
99
114
|
};
|
|
100
115
|
|
|
@@ -107,7 +122,7 @@ export function useTileResize({
|
|
|
107
122
|
const span = Math.round(
|
|
108
123
|
(width + GRID_GAP_PX) / (resize.track + GRID_GAP_PX),
|
|
109
124
|
);
|
|
110
|
-
const clamped = Math.min(Math.max(span, 1),
|
|
125
|
+
const clamped = Math.min(Math.max(span, 1), resize.max);
|
|
111
126
|
if (clamped !== resize.span) setResize({ ...resize, span: clamped });
|
|
112
127
|
};
|
|
113
128
|
|
|
@@ -54,12 +54,12 @@ function mount(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
describe("FilterButton's starting value, in the builder", () => {
|
|
57
|
-
it("
|
|
57
|
+
it("makes the current value the report's default, a filter as its text", () => {
|
|
58
58
|
// Not an f'…' literal: the server unwraps one without un-escaping it.
|
|
59
59
|
const { setStartingValue } = mount(BRAND, "O'Brien");
|
|
60
60
|
fireEvent.click(
|
|
61
61
|
screen.getByRole("button", {
|
|
62
|
-
name: "
|
|
62
|
+
name: "Make this the report's default",
|
|
63
63
|
}),
|
|
64
64
|
);
|
|
65
65
|
expect(setStartingValue).toHaveBeenCalledWith("BRAND", "O'Brien");
|
|
@@ -69,24 +69,40 @@ describe("FilterButton's starting value, in the builder", () => {
|
|
|
69
69
|
const { setStartingValue } = mount(SINCE, "2024-03-01");
|
|
70
70
|
fireEvent.click(
|
|
71
71
|
screen.getByRole("button", {
|
|
72
|
-
name: "
|
|
72
|
+
name: "Make this the report's default",
|
|
73
73
|
}),
|
|
74
74
|
);
|
|
75
75
|
expect(setStartingValue).toHaveBeenCalledWith("SINCE", "2024-03-01");
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
it("says
|
|
78
|
+
it("says Report default when it is, and offers the filter's own default for one this report declares", () => {
|
|
79
79
|
const { setStartingValue } = mount(BRAND, "Ford", { start: "f'Ford'" });
|
|
80
|
-
expect(
|
|
81
|
-
screen.getByText("The report opens with this value."),
|
|
82
|
-
).toBeDefined();
|
|
80
|
+
expect(screen.getByText("Report default")).toBeDefined();
|
|
83
81
|
expect(
|
|
84
82
|
screen.queryByRole("button", {
|
|
85
|
-
name: "
|
|
83
|
+
name: "Make this the report's default",
|
|
86
84
|
}),
|
|
87
85
|
).toBeNull();
|
|
86
|
+
expect(
|
|
87
|
+
screen.queryByRole("button", { name: "Use the model's default" }),
|
|
88
|
+
).toBeNull();
|
|
89
|
+
fireEvent.click(
|
|
90
|
+
screen.getByRole("button", { name: "Use the filter's default" }),
|
|
91
|
+
);
|
|
92
|
+
expect(setStartingValue).toHaveBeenCalledWith("BRAND", undefined);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("offers the model's default for a filter the model declares", () => {
|
|
96
|
+
const { setStartingValue } = mount(BRAND, "Ford", {
|
|
97
|
+
start: "f'Ford'",
|
|
98
|
+
state: { origin: "model" },
|
|
99
|
+
});
|
|
100
|
+
expect(screen.getByText("Report default")).toBeDefined();
|
|
101
|
+
expect(
|
|
102
|
+
screen.queryByRole("button", { name: "Use the filter's default" }),
|
|
103
|
+
).toBeNull();
|
|
88
104
|
fireEvent.click(
|
|
89
|
-
screen.getByRole("button", { name: "
|
|
105
|
+
screen.getByRole("button", { name: "Use the model's default" }),
|
|
90
106
|
);
|
|
91
107
|
expect(setStartingValue).toHaveBeenCalledWith("BRAND", undefined);
|
|
92
108
|
});
|
|
@@ -95,7 +111,7 @@ describe("FilterButton's starting value, in the builder", () => {
|
|
|
95
111
|
mount(BRAND, undefined);
|
|
96
112
|
expect(
|
|
97
113
|
screen.queryByRole("button", {
|
|
98
|
-
name: "
|
|
114
|
+
name: "Make this the report's default",
|
|
99
115
|
}),
|
|
100
116
|
).toBeNull();
|
|
101
117
|
});
|
|
@@ -122,7 +138,7 @@ describe("FilterButton for a filter the model sets", () => {
|
|
|
122
138
|
// Where the report opens is still the report's to say.
|
|
123
139
|
expect(
|
|
124
140
|
screen.getByRole("button", {
|
|
125
|
-
name: "
|
|
141
|
+
name: "Make this the report's default",
|
|
126
142
|
}),
|
|
127
143
|
).toBeDefined();
|
|
128
144
|
fireEvent.click(screen.getByRole("button", { name: "Open the model" }));
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { reportClasses } from "../../theme/classes";
|
|
5
5
|
import AddIcon from "@mui/icons-material/Add";
|
|
6
|
+
import CheckIcon from "@mui/icons-material/Check";
|
|
6
7
|
import CloseIcon from "@mui/icons-material/Close";
|
|
7
8
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|
8
9
|
import {
|
|
@@ -256,9 +257,14 @@ function startingComparable(
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
260
|
+
* The report's default for this filter, in the builder: the value the report
|
|
261
|
+
* opens with (`givens { … }`). "Make this the report's default" saves the
|
|
262
|
+
* current value as it; once saved, a quiet "Report default" with a check says
|
|
263
|
+
* so, and the clearing button goes back to the default the filter is declared
|
|
264
|
+
* with: "Use the model's default" for a model's filter, "Use the filter's
|
|
265
|
+
* default" for one this report declares, whose fallback is the default written
|
|
266
|
+
* in the report. Any filter has one, the model's included, since where a
|
|
267
|
+
* report opens is the report's to say.
|
|
262
268
|
*/
|
|
263
269
|
function StartingValue({
|
|
264
270
|
name,
|
|
@@ -275,6 +281,7 @@ function StartingValue({
|
|
|
275
281
|
if (!editing?.setStartingValue) return null;
|
|
276
282
|
const set = editing.setStartingValue;
|
|
277
283
|
const start = startingComparable(editing.startingValueOf?.(name), type);
|
|
284
|
+
const declaredHere = editing.stateOf(name)?.origin === "dashboard";
|
|
278
285
|
const buttonSx = { px: 0.75, minWidth: 0, ...ui.type.control };
|
|
279
286
|
return (
|
|
280
287
|
<>
|
|
@@ -284,14 +291,18 @@ function StartingValue({
|
|
|
284
291
|
...ui.type.caption,
|
|
285
292
|
color: mui.palette.text.secondary,
|
|
286
293
|
px: 0.75,
|
|
294
|
+
display: "flex",
|
|
295
|
+
alignItems: "center",
|
|
296
|
+
gap: 0.5,
|
|
287
297
|
})}
|
|
288
298
|
>
|
|
289
|
-
|
|
299
|
+
<CheckIcon aria-hidden sx={{ fontSize: 14 }} />
|
|
300
|
+
Report default
|
|
290
301
|
</Typography>
|
|
291
302
|
)}
|
|
292
303
|
{text !== undefined && text !== start && (
|
|
293
304
|
<Button size="small" onClick={() => set(name, text)} sx={buttonSx}>
|
|
294
|
-
|
|
305
|
+
Make this the report's default
|
|
295
306
|
</Button>
|
|
296
307
|
)}
|
|
297
308
|
{start !== undefined && (
|
|
@@ -300,7 +311,9 @@ function StartingValue({
|
|
|
300
311
|
onClick={() => set(name, undefined)}
|
|
301
312
|
sx={buttonSx}
|
|
302
313
|
>
|
|
303
|
-
|
|
314
|
+
{declaredHere
|
|
315
|
+
? "Use the filter's default"
|
|
316
|
+
: "Use the model's default"}
|
|
304
317
|
</Button>
|
|
305
318
|
)}
|
|
306
319
|
</>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
-
import { resolveMode, resolveTheme } from "./resolveTheme";
|
|
5
|
+
import { chartThemeLayer, resolveMode, resolveTheme } from "./resolveTheme";
|
|
6
6
|
import type { Theme } from "./types";
|
|
7
7
|
|
|
8
8
|
describe("resolveTheme cascade", () => {
|
|
@@ -243,3 +243,74 @@ describe("resolveTheme series in dark mode", () => {
|
|
|
243
243
|
expect(dark.series[1]).toBe("#60a5fa");
|
|
244
244
|
});
|
|
245
245
|
});
|
|
246
|
+
|
|
247
|
+
describe("a chart's own theme layer", () => {
|
|
248
|
+
const host: Theme = {
|
|
249
|
+
palette: { series: ["#628698", "#8a6a50", "#6f6a8f", "#7f9862"] },
|
|
250
|
+
};
|
|
251
|
+
const drawn = (chart: Theme) =>
|
|
252
|
+
resolveTheme([host, chartThemeLayer([host], chart)], "light").series;
|
|
253
|
+
|
|
254
|
+
// The builder's Color item writes one colour. On a bar and line chart the
|
|
255
|
+
// line is the second series: drawn from a one-colour list it came out the
|
|
256
|
+
// same colour as the bars and vanished against them.
|
|
257
|
+
// A pick changes the bars and not the line: every later series keeps the
|
|
258
|
+
// colour it has with no pick. It used to drop the pick from the host's
|
|
259
|
+
// list and shift the rest up, so the line took the host's FIRST colour.
|
|
260
|
+
it("changes only the first series for a colour on the palette", () => {
|
|
261
|
+
const series = drawn({ palette: { series: ["#7F9862"] } });
|
|
262
|
+
// The slot that held the pick takes the colour the first slot gave up.
|
|
263
|
+
expect(series).toEqual(["#7F9862", "#8a6a50", "#6f6a8f", "#628698"]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("keeps the line's colour whichever colour is picked", () => {
|
|
267
|
+
const theme = resolveTheme([host], "light").series;
|
|
268
|
+
for (const pick of ["#628698", "#6f6a8f", "#7f9862", "#123456"]) {
|
|
269
|
+
const series = drawn({ palette: { series: [pick] } });
|
|
270
|
+
expect(series[0]).toBe(pick);
|
|
271
|
+
expect(series[1]).toBe(theme[1]);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("gives the line the first colour when the pick is the line's own", () => {
|
|
276
|
+
const series = drawn({ palette: { series: ["#8a6a50"] } });
|
|
277
|
+
expect(series).toEqual(["#8a6a50", "#628698", "#6f6a8f", "#7f9862"]);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("keeps the host's later slots after a colour that is not on its palette", () => {
|
|
281
|
+
const series = drawn({ palette: { series: ["#123456"] } });
|
|
282
|
+
expect(series).toEqual(["#123456", "#8a6a50", "#6f6a8f", "#7f9862"]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("draws a one-colour host palette as the second series", () => {
|
|
286
|
+
const one: Theme = { palette: { series: ["#628698"] } };
|
|
287
|
+
const series = resolveTheme(
|
|
288
|
+
[one, chartThemeLayer([one], { palette: { series: ["#123456"] } })],
|
|
289
|
+
"light",
|
|
290
|
+
).series;
|
|
291
|
+
expect(series).toEqual(["#123456", "#628698"]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("falls back to the default series with no host palette", () => {
|
|
295
|
+
const series = resolveTheme(
|
|
296
|
+
[chartThemeLayer([], { palette: { series: ["#123456"] } })],
|
|
297
|
+
"light",
|
|
298
|
+
).series;
|
|
299
|
+
expect(series[0]).toBe("#123456");
|
|
300
|
+
expect(series.slice(1)).toEqual(
|
|
301
|
+
resolveTheme([], "light").series.slice(1),
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("uses a list of two or more colours as written", () => {
|
|
306
|
+
expect(drawn({ palette: { series: ["#111111", "#222222"] } })).toEqual([
|
|
307
|
+
"#111111",
|
|
308
|
+
"#222222",
|
|
309
|
+
]);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("leaves a layer that sets no series alone", () => {
|
|
313
|
+
const chart: Theme = { font: { size: 14 } };
|
|
314
|
+
expect(chartThemeLayer([host], chart)).toBe(chart);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
@@ -158,6 +158,49 @@ export function resolveTheme(
|
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* A chart's own `# theme.*` layer, ready to go on top of `layers`.
|
|
163
|
+
*
|
|
164
|
+
* A one-colour `series` on a chart sets the chart's FIRST series colour (it is
|
|
165
|
+
* what the builder's Color item writes). Taken as the whole list, every series
|
|
166
|
+
* would cycle through that one colour, so a bar and line chart, or any chart
|
|
167
|
+
* with more than one series, would draw them all alike.
|
|
168
|
+
*
|
|
169
|
+
* So only the first slot changes: every other series keeps the colour it has
|
|
170
|
+
* with no pick, which is what makes a pick change the bars and not the line.
|
|
171
|
+
* The one exception is a later slot that holds the picked colour. It takes the
|
|
172
|
+
* colour the first slot gave up, so no two series are drawn alike. A list of
|
|
173
|
+
* two or more colours is the author's whole palette and is used as written.
|
|
174
|
+
*/
|
|
175
|
+
export function chartThemeLayer(
|
|
176
|
+
layers: Array<Theme | undefined>,
|
|
177
|
+
chart: Theme,
|
|
178
|
+
): Theme {
|
|
179
|
+
const own = chart.palette?.series;
|
|
180
|
+
if (!Array.isArray(own) || own.length !== 1) return chart;
|
|
181
|
+
const first = own[0];
|
|
182
|
+
const inherited = layers.reduce<string[]>(
|
|
183
|
+
(series, layer) =>
|
|
184
|
+
Array.isArray(layer?.palette?.series)
|
|
185
|
+
? (layer.palette.series as string[])
|
|
186
|
+
: series,
|
|
187
|
+
(DEFAULT_THEME.palette?.series as string[]) ?? [],
|
|
188
|
+
);
|
|
189
|
+
const same = (color: string) => color.toLowerCase() === first.toLowerCase();
|
|
190
|
+
const [displaced, ...later] = inherited;
|
|
191
|
+
const rest =
|
|
192
|
+
later.length > 0
|
|
193
|
+
? later.map((color) => (same(color) ? displaced : color))
|
|
194
|
+
: // A one-colour host palette has no second slot, so its one colour is the second series.
|
|
195
|
+
[displaced].filter(
|
|
196
|
+
(color): color is string => color !== undefined && !same(color),
|
|
197
|
+
);
|
|
198
|
+
return {
|
|
199
|
+
...chart,
|
|
200
|
+
palette: { ...chart.palette, series: [first, ...rest] },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
161
204
|
/**
|
|
162
205
|
* Pick the active mode for a viewer given the operator's `defaultMode`,
|
|
163
206
|
* any persisted viewer choice, and a snapshot of the OS dark-mode
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { blankQuoted } from "./blankQuoted";
|
|
6
|
+
|
|
7
|
+
describe("blankQuoted", () => {
|
|
8
|
+
it("blanks each quoted value, escapes included", () => {
|
|
9
|
+
expect(blankQuoted('# label="bar_chart" line_chart')).toBe(
|
|
10
|
+
'# label="" line_chart',
|
|
11
|
+
);
|
|
12
|
+
expect(blankQuoted('# a="x \\" y" b="z"')).toBe('# a="" b=""');
|
|
13
|
+
expect(blankQuoted('# a="x\\\\" bar_chart')).toBe('# a="" bar_chart');
|
|
14
|
+
expect(blankQuoted("# bar_chart")).toBe("# bar_chart");
|
|
15
|
+
expect(blankQuoted('""')).toBe('""');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("leaves an unclosed quote and the rest of the line as they are", () => {
|
|
19
|
+
expect(blankQuoted('# a="x" b="bar_chart')).toBe('# a="" b="bar_chart');
|
|
20
|
+
expect(blankQuoted('# "\\"')).toBe('# "\\"');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// The regex it replaces, for lines it reads in linear time.
|
|
24
|
+
const QUOTED = /"(?:[^"\\]|\\.)*"/g;
|
|
25
|
+
it("agrees with the regex it replaces on every short line of quotes, escapes and words", () => {
|
|
26
|
+
const alphabet = ['"', "\\", "a", " "];
|
|
27
|
+
let checked = 0;
|
|
28
|
+
for (let length = 0; length <= 7; length++) {
|
|
29
|
+
const total = alphabet.length ** length;
|
|
30
|
+
for (let n = 0; n < total; n++) {
|
|
31
|
+
let text = "";
|
|
32
|
+
for (let k = 0, rest = n; k < length; k++) {
|
|
33
|
+
text += alphabet[rest % alphabet.length];
|
|
34
|
+
rest = Math.floor(rest / alphabet.length);
|
|
35
|
+
}
|
|
36
|
+
expect(blankQuoted(text)).toBe(text.replace(QUOTED, '""'));
|
|
37
|
+
checked++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
expect(checked).toBe(21845);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("reads a long unclosed line of escaped quotes in linear time", () => {
|
|
44
|
+
// `"` then many `\"`: the shape that made the regex quadratic.
|
|
45
|
+
const hostile = `# "${'\\"'.repeat(200_000)}`;
|
|
46
|
+
const started = performance.now();
|
|
47
|
+
expect(blankQuoted(hostile)).toBe(hostile);
|
|
48
|
+
expect(performance.now() - started).toBeLessThan(250);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `text` with every double-quoted string, escapes included, replaced by `""`,
|
|
6
|
+
* so a tag line can be split into words without a quoted value reading as a
|
|
7
|
+
* tag name: `# label="bar_chart" line_chart` -> `# label="" line_chart`.
|
|
8
|
+
*
|
|
9
|
+
* A quote that never closes is left as it is, along with the rest of the text.
|
|
10
|
+
*
|
|
11
|
+
* A scanner rather than `/"(?:[^"\\]|\\.)*"/g`: annotation text comes from the
|
|
12
|
+
* model, and that regex retries from every quote of an unclosed string, so a
|
|
13
|
+
* line like `"\"\"\"…` took time quadratic in its length. This one reads each
|
|
14
|
+
* character once. It can stop at the first unclosed quote because every quote
|
|
15
|
+
* after it was read as an escaped character, so a scan from any of them sees
|
|
16
|
+
* the same characters and cannot close either.
|
|
17
|
+
*/
|
|
18
|
+
export function blankQuoted(text: string): string {
|
|
19
|
+
let out = "";
|
|
20
|
+
let from = 0;
|
|
21
|
+
for (;;) {
|
|
22
|
+
const open = text.indexOf('"', from);
|
|
23
|
+
if (open < 0) break;
|
|
24
|
+
let at = open + 1;
|
|
25
|
+
while (at < text.length && text[at] !== '"')
|
|
26
|
+
at += text[at] === "\\" ? 2 : 1;
|
|
27
|
+
if (at >= text.length) break;
|
|
28
|
+
out += `${text.slice(from, open)}""`;
|
|
29
|
+
from = at + 1;
|
|
30
|
+
}
|
|
31
|
+
return out + text.slice(from);
|
|
32
|
+
}
|
package/src/utils/malloyText.ts
CHANGED
|
@@ -124,7 +124,8 @@ export function closesBlock(
|
|
|
124
124
|
column: number | undefined,
|
|
125
125
|
closer: "|#" | "|##",
|
|
126
126
|
): boolean {
|
|
127
|
-
|
|
127
|
+
// `[ \t]*` matches every string, so exec never returns null here.
|
|
128
|
+
const indent = /^[ \t]*/.exec(line)![0].length;
|
|
128
129
|
if (column !== undefined && indent !== column) return false;
|
|
129
130
|
const rest = line.slice(indent);
|
|
130
131
|
return (
|