@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
|
@@ -9,3 +9,5 @@
|
|
|
9
9
|
* value, or one the type cannot spell.
|
|
10
10
|
*/
|
|
11
11
|
export declare function malloyLiteral(value: unknown, type?: string): string | undefined;
|
|
12
|
+
/** A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled as a local-time day. */
|
|
13
|
+
export declare function formatMalloyValue(value: string | number | boolean | Date | null | undefined, isDate?: boolean): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloy-publisher/sdk",
|
|
3
3
|
"description": "Malloy Publisher SDK",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
@@ -82,18 +82,17 @@
|
|
|
82
82
|
"generate-api-types": "bunx openapi-generator-cli generate -i ../../api-doc.yaml -g typescript-axios -o src/client/"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"@malloydata/malloy": "^0.0.
|
|
85
|
+
"@malloydata/malloy": "^0.0.436",
|
|
86
86
|
"@malloydata/malloy-explorer": "0.0.338-dev260215172810",
|
|
87
|
-
"@malloydata/malloy-filter": "^0.0.
|
|
88
|
-
"@malloydata/malloy-interfaces": "^0.0.
|
|
89
|
-
"@malloydata/malloy-query-builder": "^0.0.
|
|
90
|
-
"@malloydata/malloy-tag": "^0.0.
|
|
91
|
-
"@malloydata/render": "^0.0.
|
|
87
|
+
"@malloydata/malloy-filter": "^0.0.436",
|
|
88
|
+
"@malloydata/malloy-interfaces": "^0.0.436",
|
|
89
|
+
"@malloydata/malloy-query-builder": "^0.0.436",
|
|
90
|
+
"@malloydata/malloy-tag": "^0.0.436",
|
|
91
|
+
"@malloydata/render": "^0.0.436",
|
|
92
92
|
"@mui/icons-material": ">=7.1.1",
|
|
93
93
|
"@mui/material": ">=7.1.1",
|
|
94
94
|
"@mui/system": ">=7.1.1",
|
|
95
95
|
"@mui/x-date-pickers": ">=7.1.1",
|
|
96
|
-
"@mui/x-tree-view": ">=7.16.0",
|
|
97
96
|
"@tanstack/react-query": ">=5.59.16",
|
|
98
97
|
"axios": ">=1.7.7",
|
|
99
98
|
"react": ">=19.1.0",
|
|
@@ -107,7 +106,6 @@
|
|
|
107
106
|
"@dnd-kit/react": "^0.5.0",
|
|
108
107
|
"@emotion/react": "^11.14.0",
|
|
109
108
|
"@emotion/styled": "^11.14.0",
|
|
110
|
-
"@react-spring/web": "^10.0.1",
|
|
111
109
|
"cron-parser": "^5.6.2",
|
|
112
110
|
"cronstrue": "^2.50.0",
|
|
113
111
|
"dayjs": "^1.11.13",
|
|
@@ -115,25 +113,22 @@
|
|
|
115
113
|
},
|
|
116
114
|
"devDependencies": {
|
|
117
115
|
"@happy-dom/global-registrator": "^20.11.1",
|
|
118
|
-
"@malloydata/malloy": "^0.0.
|
|
116
|
+
"@malloydata/malloy": "^0.0.436",
|
|
119
117
|
"@malloydata/malloy-explorer": "0.0.338-dev260215172810",
|
|
120
|
-
"@malloydata/malloy-filter": "^0.0.
|
|
121
|
-
"@malloydata/malloy-query-builder": "^0.0.
|
|
122
|
-
"@malloydata/malloy-tag": "^0.0.
|
|
118
|
+
"@malloydata/malloy-filter": "^0.0.436",
|
|
119
|
+
"@malloydata/malloy-query-builder": "^0.0.436",
|
|
120
|
+
"@malloydata/malloy-tag": "^0.0.436",
|
|
123
121
|
"@openapitools/openapi-generator-cli": "^2.40.1",
|
|
124
122
|
"@shikijs/langs": "^1.16.3",
|
|
125
123
|
"@shikijs/themes": "^1.16.3",
|
|
126
124
|
"@testing-library/dom": "^10.4.1",
|
|
127
125
|
"@testing-library/react": "^16.3.2",
|
|
128
126
|
"@types/bun": "^1.2.21",
|
|
129
|
-
"@types/k6": "^1.0.2",
|
|
130
127
|
"@types/react": "^19.1.7",
|
|
131
128
|
"@types/react-dom": "^19.1.6",
|
|
132
129
|
"@typescript-eslint/eslint-plugin": "8.16.0",
|
|
133
130
|
"@typescript-eslint/parser": "8.16.0",
|
|
134
131
|
"@vitejs/plugin-react": "^4.4.1",
|
|
135
|
-
"ajv": "^8.12.0",
|
|
136
|
-
"archiver": "^7.0.1",
|
|
137
132
|
"eslint-config-prettier": "9.1.0",
|
|
138
133
|
"eslint-plugin-prettier": "5.2.1",
|
|
139
134
|
"eslint-plugin-react": "7.37.2",
|
package/src/builder-entry.ts
CHANGED
|
@@ -62,6 +62,8 @@ export const TILE_ROW_PX = 80;
|
|
|
62
62
|
* heading and axes, and the renderer failed on it. Prose fits in one.
|
|
63
63
|
*/
|
|
64
64
|
export const MIN_TILE_ROWS = 3;
|
|
65
|
+
/** A query tile that draws no chart (value cards, a table) goes down to two rows. */
|
|
66
|
+
export const MIN_VALUE_TILE_ROWS = 2;
|
|
65
67
|
export const MIN_TEXT_TILE_ROWS = 1;
|
|
66
68
|
export const MAX_TILE_ROWS = 16;
|
|
67
69
|
|
|
@@ -73,6 +73,8 @@ export interface DashboardTileProps {
|
|
|
73
73
|
height: number | undefined;
|
|
74
74
|
/** A further cap when the result is a table, past which it scrolls under its pinned header. */
|
|
75
75
|
tableMaxHeight?: number;
|
|
76
|
+
/** The tile has a set height (rows of its own): a result taller than it is drawn compact. */
|
|
77
|
+
fixedHeight?: boolean;
|
|
76
78
|
maxResultSize?: number;
|
|
77
79
|
/** Cell clicks and their affordance, for the dashboard's `# drill`. */
|
|
78
80
|
drill?: DrillBinding;
|
|
@@ -146,6 +148,7 @@ export function DashboardTile({
|
|
|
146
148
|
givenNames,
|
|
147
149
|
height,
|
|
148
150
|
tableMaxHeight,
|
|
151
|
+
fixedHeight,
|
|
149
152
|
maxResultSize,
|
|
150
153
|
drill,
|
|
151
154
|
onExplore,
|
|
@@ -272,6 +275,7 @@ export function DashboardTile({
|
|
|
272
275
|
context={tile ?? queryName ?? modelPath}
|
|
273
276
|
maxHeight={height}
|
|
274
277
|
tableMaxHeight={tableMaxHeight}
|
|
278
|
+
compactToFit={fixedHeight}
|
|
275
279
|
// Uncapped in a linear report, a tile would first paint at the
|
|
276
280
|
// 2000px default and collapse once measured. A grid tile's cap
|
|
277
281
|
// is a sound first guess for every tile.
|
|
@@ -389,6 +389,7 @@ export function DashboardView({
|
|
|
389
389
|
: tileMaxHeight
|
|
390
390
|
}
|
|
391
391
|
tableMaxHeight={tableMaxHeight}
|
|
392
|
+
fixedHeight={tile.rowspan !== undefined || placed}
|
|
392
393
|
maxResultSize={maxResultSize}
|
|
393
394
|
drill={drillFor(tile.query)}
|
|
394
395
|
ignoredFilters={tileIgnoredFilterLabels(
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
remeasuresAfterReady,
|
|
25
25
|
resultSizing,
|
|
26
26
|
type ResultSizing,
|
|
27
|
+
TIGHT_ATTR,
|
|
27
28
|
} from "./resultSizing";
|
|
28
29
|
import { readChartAnnotations } from "../../theme/readChartAnnotations";
|
|
29
30
|
import { chartThemeLayer, resolveTheme } from "../../theme/resolveTheme";
|
|
@@ -315,6 +316,23 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
|
|
|
315
316
|
width: auto;
|
|
316
317
|
max-width: none;
|
|
317
318
|
}
|
|
319
|
+
/* Compact, in a tile set shorter than its cards (ResultContainer marks it tight): smaller values,
|
|
320
|
+
tighter cards and a 190px floor, which a 22px value still fits in, so five cards share a row of
|
|
321
|
+
about a thousand pixels instead of wrapping into rows the tile has no room for. */
|
|
322
|
+
[${TIGHT_ATTR}] .malloy-render .malloy-big-value:not(.malloy-big-value--embedded) {
|
|
323
|
+
grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
|
|
324
|
+
gap: 8px;
|
|
325
|
+
padding: 8px;
|
|
326
|
+
}
|
|
327
|
+
[${TIGHT_ATTR}] .malloy-render .malloy-big-value-card:not(.malloy-big-value-card--embedded) {
|
|
328
|
+
padding: 9px 14px;
|
|
329
|
+
}
|
|
330
|
+
[${TIGHT_ATTR}] .malloy-render .malloy-big-value-value {
|
|
331
|
+
font-size: 22px;
|
|
332
|
+
}
|
|
333
|
+
[${TIGHT_ATTR}] .malloy-render .malloy-big-value-label {
|
|
334
|
+
font-size: 11px;
|
|
335
|
+
}
|
|
318
336
|
.malloy-render .malloy-dashboard .dashboard-row-header-separator {
|
|
319
337
|
background: var(--malloy-render--table-border) !important;
|
|
320
338
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
resolveResultHeight,
|
|
23
23
|
resultCap,
|
|
24
24
|
type ResultSizing,
|
|
25
|
+
TIGHT_ATTR,
|
|
25
26
|
} from "./resultSizing";
|
|
26
27
|
|
|
27
28
|
/** The box a dashboard tile's result scrolls in when it is taller than its cap. */
|
|
@@ -64,6 +65,13 @@ interface ResultContainerProps {
|
|
|
64
65
|
* tile's card is. Leave it off wherever the result sets the surface's height.
|
|
65
66
|
*/
|
|
66
67
|
fill?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The cell's height is set (a tile given rows), not its content's: only
|
|
70
|
+
* then is a result taller than it drawn compact to fit. A cell that grows
|
|
71
|
+
* with its content is briefly shorter than a result that just grew, and
|
|
72
|
+
* compact there would be a mistake that never undoes itself.
|
|
73
|
+
*/
|
|
74
|
+
compactToFit?: boolean;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
// ResultContainer is a component that renders a result, with a toggle button to expand/collapse the result.
|
|
@@ -79,6 +87,7 @@ export default function ResultContainer({
|
|
|
79
87
|
renderLogs,
|
|
80
88
|
drill,
|
|
81
89
|
fill = false,
|
|
90
|
+
compactToFit = false,
|
|
82
91
|
}: ResultContainerProps) {
|
|
83
92
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
84
93
|
// A result is here: start the renderer download if no panel already has.
|
|
@@ -107,13 +116,37 @@ export default function ResultContainer({
|
|
|
107
116
|
useEffect(() => {
|
|
108
117
|
const box = containerRef.current;
|
|
109
118
|
if (!fill || !box) return;
|
|
110
|
-
const observer = new ResizeObserver(([entry]) =>
|
|
111
|
-
setCellHeight(Math.round(entry.contentRect.height))
|
|
112
|
-
|
|
119
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
120
|
+
setCellHeight(Math.round(entry.contentRect.height));
|
|
121
|
+
setCellWidth(Math.round(entry.contentRect.width));
|
|
122
|
+
});
|
|
113
123
|
observer.observe(box);
|
|
114
124
|
return () => observer.disconnect();
|
|
115
125
|
}, [fill, hasResult, userAcknowledged]);
|
|
116
126
|
|
|
127
|
+
// Tight: a content-sized result taller than the cell it fills (value cards
|
|
128
|
+
// in a tile set shorter than they are), drawn compact so it fits rather
|
|
129
|
+
// than scrolls. Held at the height it needed at full size, and let go only
|
|
130
|
+
// once the cell is that tall again: let go as soon as the compact result
|
|
131
|
+
// fit, it would grow back past the cell and the two would flicker.
|
|
132
|
+
const [tightFrom, setTightFrom] = useState<number | undefined>(undefined);
|
|
133
|
+
const [cellWidth, setCellWidth] = useState<number | undefined>(undefined);
|
|
134
|
+
const mayTighten = fill && compactToFit && sizing === "content";
|
|
135
|
+
// A new result, or a cell of another width, may fit at full size where the
|
|
136
|
+
// last one did not: let go and measure again, rather than stay compact on
|
|
137
|
+
// the strength of a height measured for something else.
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
setTightFrom(undefined);
|
|
140
|
+
}, [result, cellWidth, mayTighten]);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!mayTighten) return;
|
|
143
|
+
if (cellHeight === undefined || contentHeight === undefined) return;
|
|
144
|
+
if (tightFrom === undefined && contentHeight > cellHeight + 1)
|
|
145
|
+
setTightFrom(contentHeight);
|
|
146
|
+
else if (tightFrom !== undefined && cellHeight >= tightFrom)
|
|
147
|
+
setTightFrom(undefined);
|
|
148
|
+
}, [mayTighten, cellHeight, contentHeight, tightFrom]);
|
|
149
|
+
|
|
117
150
|
if (!result) {
|
|
118
151
|
return null;
|
|
119
152
|
}
|
|
@@ -205,6 +238,9 @@ export default function ResultContainer({
|
|
|
205
238
|
// scrolls inside itself, under its own pinned header.
|
|
206
239
|
<Box
|
|
207
240
|
className={RESULT_SCROLLER_CLASS}
|
|
241
|
+
{...(mayTighten && tightFrom !== undefined
|
|
242
|
+
? { [TIGHT_ATTR]: "" }
|
|
243
|
+
: {})}
|
|
208
244
|
sx={{
|
|
209
245
|
position: "absolute",
|
|
210
246
|
inset: 0,
|
|
@@ -26,6 +26,8 @@ export interface ResultPanelProps {
|
|
|
26
26
|
drill?: DrillBinding;
|
|
27
27
|
/** See `ResultContainer`: stretch the result to its cell. */
|
|
28
28
|
fill?: boolean;
|
|
29
|
+
/** The cell has a set height: a result taller than it is drawn compact (see `ResultContainer`). */
|
|
30
|
+
compactToFit?: boolean;
|
|
29
31
|
/**
|
|
30
32
|
* Rewrites the result before it is rendered — a dashboard tile promotes a
|
|
31
33
|
* one-row measure result to KPI cards this way. Memoized on the result
|
|
@@ -55,6 +57,7 @@ export function ResultPanel({
|
|
|
55
57
|
maxResultSize,
|
|
56
58
|
drill,
|
|
57
59
|
fill,
|
|
60
|
+
compactToFit,
|
|
58
61
|
transform,
|
|
59
62
|
}: ResultPanelProps) {
|
|
60
63
|
const { data, isSuccess, isError, error, fetchStatus, isPlaceholderData } =
|
|
@@ -108,6 +111,7 @@ export function ResultPanel({
|
|
|
108
111
|
renderLogs={data.data.renderLogs}
|
|
109
112
|
drill={drill}
|
|
110
113
|
fill={fill}
|
|
114
|
+
compactToFit={compactToFit}
|
|
111
115
|
/>
|
|
112
116
|
);
|
|
113
117
|
// The previous answer, while the new one runs: it stays where it is, eased
|
|
@@ -371,3 +371,9 @@ export function resolveResultHeight({
|
|
|
371
371
|
: Math.min(maxHeight, contentHeight);
|
|
372
372
|
return fillHeight === undefined ? own : Math.max(own, fillHeight);
|
|
373
373
|
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* On a result's box while it is drawn compact to fit a cell shorter than it
|
|
377
|
+
* (`ResultContainer` sets it); the renderer overrides in `RenderedResult` read it.
|
|
378
|
+
*/
|
|
379
|
+
export const TIGHT_ATTR = "data-publisher-tight";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
|
|
5
|
+
import {
|
|
6
|
+
IconButton,
|
|
7
|
+
ListItemText,
|
|
8
|
+
Menu,
|
|
9
|
+
MenuItem,
|
|
10
|
+
Tooltip,
|
|
11
|
+
} from "@mui/material";
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
14
|
+
import { edgeColor } from "../controlTokens";
|
|
15
|
+
import { iconControlSx } from "./BuilderToolbar";
|
|
16
|
+
|
|
17
|
+
import type { ArrangeActions } from "./builderControls";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The layout of a placed grid report as a whole: closing its gaps, or letting
|
|
21
|
+
* its tiles flow again. One menu shared by the builder's own toolbar and the
|
|
22
|
+
* bar a host draws, so the two cannot offer different things.
|
|
23
|
+
*/
|
|
24
|
+
export function ArrangeMenu({ arrange }: { arrange: ArrangeActions }) {
|
|
25
|
+
const { theme } = usePublisherTheme();
|
|
26
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
27
|
+
const pick = (action: (() => void) | undefined) => () => {
|
|
28
|
+
setAnchor(null);
|
|
29
|
+
action?.();
|
|
30
|
+
};
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<Tooltip title="Arrange tiles">
|
|
34
|
+
<IconButton
|
|
35
|
+
aria-label="Arrange tiles"
|
|
36
|
+
aria-haspopup="menu"
|
|
37
|
+
aria-expanded={anchor !== null}
|
|
38
|
+
onClick={(event) => setAnchor(event.currentTarget)}
|
|
39
|
+
sx={iconControlSx(theme.ui)}
|
|
40
|
+
>
|
|
41
|
+
<DashboardOutlinedIcon fontSize="small" />
|
|
42
|
+
</IconButton>
|
|
43
|
+
</Tooltip>
|
|
44
|
+
<Menu
|
|
45
|
+
anchorEl={anchor}
|
|
46
|
+
open={anchor !== null}
|
|
47
|
+
onClose={() => setAnchor(null)}
|
|
48
|
+
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
|
49
|
+
transformOrigin={{ vertical: -6, horizontal: "right" }}
|
|
50
|
+
slotProps={{
|
|
51
|
+
paper: {
|
|
52
|
+
sx: {
|
|
53
|
+
minWidth: 260,
|
|
54
|
+
borderRadius: theme.ui.radius.menu,
|
|
55
|
+
border: `1px solid ${edgeColor(theme.cardBorder)}`,
|
|
56
|
+
boxShadow: theme.ui.shadow.menu,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<MenuItem disabled={!arrange.pack} onClick={pick(arrange.pack)}>
|
|
62
|
+
<ListItemText
|
|
63
|
+
primary="Pack tiles upward"
|
|
64
|
+
secondary={
|
|
65
|
+
arrange.pack
|
|
66
|
+
? "Close every gap above a tile"
|
|
67
|
+
: "There are no gaps to close"
|
|
68
|
+
}
|
|
69
|
+
/>
|
|
70
|
+
</MenuItem>
|
|
71
|
+
<MenuItem onClick={pick(arrange.flow)}>
|
|
72
|
+
<ListItemText
|
|
73
|
+
primary="Let tiles flow"
|
|
74
|
+
secondary="Clear each tile's place; keep its size"
|
|
75
|
+
/>
|
|
76
|
+
</MenuItem>
|
|
77
|
+
</Menu>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -27,6 +27,7 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
|
27
27
|
import { edgeColor, hoverEdgeColor } from "../controlTokens";
|
|
28
28
|
import type { BuilderControls } from "./builderControls";
|
|
29
29
|
import { controlSx, dividerSx, iconControlSx } from "./BuilderToolbar";
|
|
30
|
+
import { ArrangeMenu } from "./ArrangeMenu";
|
|
30
31
|
import { SaveStatus } from "./SaveStatus";
|
|
31
32
|
import { MOD } from "./useBuilderShortcuts";
|
|
32
33
|
|
|
@@ -118,6 +119,9 @@ export function BuilderBar({ controls, onDone: onDoneProp }: BuilderBarProps) {
|
|
|
118
119
|
</IconButton>
|
|
119
120
|
</span>
|
|
120
121
|
</Tooltip>
|
|
122
|
+
{controls.arrange && (
|
|
123
|
+
<ArrangeMenu arrange={controls.arrange} />
|
|
124
|
+
)}
|
|
121
125
|
{canAdd && (
|
|
122
126
|
<Divider orientation="vertical" sx={dividerSx} />
|
|
123
127
|
)}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { isPlaced } from "../Dashboard/DashboardGrid";
|
|
5
|
+
import { holdChartRows, settle } from "./placement";
|
|
4
6
|
import { useState, type ComponentProps, type ReactNode } from "react";
|
|
5
7
|
import { UnsavedChangesDialog } from "../UnsavedChangesDialog";
|
|
6
8
|
import { AddTileDialog, type ViewPreview } from "./AddTileDialog";
|
|
@@ -111,8 +113,13 @@ export function BuilderDialogs({
|
|
|
111
113
|
onCommit={(next) => {
|
|
112
114
|
const at = menu?.index;
|
|
113
115
|
if (at === undefined) return;
|
|
116
|
+
// A chart picked on a tile too short to plot it raises the
|
|
117
|
+
// tile to a chart's rows, pushing down what it now covers.
|
|
118
|
+
const held = holdChartRows(next);
|
|
114
119
|
editor.update((draft) => {
|
|
115
|
-
draft.tiles[at] =
|
|
120
|
+
draft.tiles[at] = held;
|
|
121
|
+
if (held !== next && isPlaced(draft.tiles))
|
|
122
|
+
draft.tiles = settle(draft.tiles, columns, at);
|
|
116
123
|
});
|
|
117
124
|
}}
|
|
118
125
|
view={menuView}
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
} from "./document";
|
|
24
24
|
import { InlineText } from "./InlineText";
|
|
25
25
|
import { gapId, tileEntry, withGaps } from "./layout";
|
|
26
|
-
import { minRowsOf, rowsOf } from "./placement";
|
|
27
|
-
import { builderSensors } from "./sortable";
|
|
26
|
+
import { minRowsOf, rowsOf, settle, widestFrom } from "./placement";
|
|
27
|
+
import { builderSensors, EscapeCancelsDrag } from "./sortable";
|
|
28
28
|
import { TextTileBody } from "./TextTileBody";
|
|
29
29
|
import {
|
|
30
30
|
GapTarget,
|
|
@@ -36,19 +36,17 @@ import {
|
|
|
36
36
|
import { tileDisplayTitle } from "./tileDisplayTitle";
|
|
37
37
|
import type { ReportEditorHandle } from "./useReportEditor";
|
|
38
38
|
import type { useTileReorder } from "./useTileReorder";
|
|
39
|
-
import type
|
|
40
|
-
import { widestFrom, type useTileResize } from "./useTileResize";
|
|
39
|
+
import { shapeLabel, withShape, type useEdgeResize } from "./useEdgeResize";
|
|
41
40
|
|
|
42
41
|
/**
|
|
43
42
|
* The builder's tiles, on the SAME grid the dashboard renders on, each drawn
|
|
44
43
|
* by the caller's `renderTile` inside a `TileFrame` that carries the
|
|
45
|
-
* affordances: selection, the
|
|
44
|
+
* affordances: selection, the menu, and its edges and corners.
|
|
46
45
|
*/
|
|
47
46
|
export function BuilderGrid({
|
|
48
47
|
editor,
|
|
49
48
|
reorder,
|
|
50
|
-
|
|
51
|
-
sizing,
|
|
49
|
+
edging,
|
|
52
50
|
place = (tiles) => tiles,
|
|
53
51
|
arrange = true,
|
|
54
52
|
gridBox,
|
|
@@ -68,9 +66,8 @@ export function BuilderGrid({
|
|
|
68
66
|
}: {
|
|
69
67
|
editor: ReportEditorHandle;
|
|
70
68
|
reorder: ReturnType<typeof useTileReorder>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
sizing?: ReturnType<typeof useTileHeight>;
|
|
69
|
+
/** Every edge and corner of a tile, dragged to resize it. */
|
|
70
|
+
edging: ReturnType<typeof useEdgeResize>;
|
|
74
71
|
/**
|
|
75
72
|
* The tiles after the one at `index` changed size: on a placed report,
|
|
76
73
|
* whatever it now covers pushed down. Identity elsewhere.
|
|
@@ -109,8 +106,7 @@ export function BuilderGrid({
|
|
|
109
106
|
const { dragging, preview, onDragStart, onDragMove, onDragOver, onDragEnd } =
|
|
110
107
|
reorder;
|
|
111
108
|
const { columns } = rules;
|
|
112
|
-
const
|
|
113
|
-
const tall = sizing?.height;
|
|
109
|
+
const edge = edging.drag;
|
|
114
110
|
// What the grid lays out: the document, except mid-gesture, where it is
|
|
115
111
|
// the preview — the tile being resized at its previewed width, or the tiles
|
|
116
112
|
// in their previewed order. So the row reflows under the pointer exactly as
|
|
@@ -118,35 +114,38 @@ export function BuilderGrid({
|
|
|
118
114
|
const drawn = (tile: DashboardTile): DashboardTile =>
|
|
119
115
|
tile.colspan === undefined ? { ...tile, colspan: defaultSpan } : tile;
|
|
120
116
|
const shown = (
|
|
121
|
-
|
|
122
|
-
?
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
edge !== undefined
|
|
118
|
+
? (() => {
|
|
119
|
+
// The tiles as the resize would leave them: the one tile with
|
|
120
|
+
// the edges it moved, and on a placed report everything it now
|
|
121
|
+
// covers pushed down.
|
|
122
|
+
const base = edge.placedHere ? edge.base : editor.document.tiles;
|
|
123
|
+
const tile = base[edge.index];
|
|
124
|
+
if (!tile) return base;
|
|
125
|
+
const resized = base.map((each, index) =>
|
|
126
|
+
index === edge.index
|
|
127
|
+
? withShape(each, edge.shape, edge.edges, edge.placed)
|
|
126
128
|
: each,
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
index === tall.index ? withRowspan(each, tall.rows) : each,
|
|
134
|
-
),
|
|
135
|
-
tall.index,
|
|
136
|
-
)
|
|
137
|
-
: (preview ?? editor.document.tiles)
|
|
129
|
+
);
|
|
130
|
+
return edge.placed
|
|
131
|
+
? settle(resized, columns, edge.index)
|
|
132
|
+
: resized;
|
|
133
|
+
})()
|
|
134
|
+
: (preview ?? editor.document.tiles)
|
|
138
135
|
).map(drawn);
|
|
139
136
|
// Placed, every cell is somewhere to drop, so there are no row ends to offer.
|
|
140
137
|
const placed = isPlaced(shown);
|
|
138
|
+
const gesture = dragging || edge !== undefined;
|
|
139
|
+
// Faintly, while a tile of a placed report is selected and nothing is
|
|
140
|
+
// dragged: the empty cells read as places a tile can go before any drag.
|
|
141
|
+
const resting = !gesture && placed && arrange && selected !== undefined;
|
|
141
142
|
// And, while a drag is live, the empty end of every row as a drop target.
|
|
142
143
|
// While an edge is dragged too: narrowing a tile frees columns its row-mate
|
|
143
144
|
// does not take, and an undrawn hole there read as a broken layout rather
|
|
144
145
|
// than room to fill. Not otherwise: a gap is only shown mid-gesture.
|
|
145
146
|
const empty = editor.document.tiles.length === 0;
|
|
146
147
|
const entries =
|
|
147
|
-
|
|
148
|
-
? withGaps(shown, columns)
|
|
149
|
-
: shown.map(tileEntry);
|
|
148
|
+
gesture && !placed ? withGaps(shown, columns) : shown.map(tileEntry);
|
|
150
149
|
const heading = (tile: QueryTile) =>
|
|
151
150
|
headingOf(tile, tileDisplayTitle(tile), editTile);
|
|
152
151
|
return (
|
|
@@ -158,17 +157,20 @@ export function BuilderGrid({
|
|
|
158
157
|
onDragOver={onDragOver}
|
|
159
158
|
onDragEnd={onDragEnd}
|
|
160
159
|
>
|
|
160
|
+
<EscapeCancelsDrag active={dragging} />
|
|
161
161
|
<Box ref={gridBox} sx={{ position: "relative" }}>
|
|
162
|
-
{rules.widths && (
|
|
163
|
-
<GridGuides columns={columns} />
|
|
164
|
-
)}
|
|
165
|
-
{tall !== undefined ? (
|
|
166
|
-
<RowGuides top={tall.guideTop} />
|
|
167
|
-
) : (
|
|
168
|
-
// Placed, a move snaps to rows as well as columns.
|
|
169
|
-
placed &&
|
|
170
|
-
(dragging || resize !== undefined) && <RowGuides top={0} />
|
|
162
|
+
{rules.widths && (gesture || resting) && (
|
|
163
|
+
<GridGuides columns={columns} faint={!gesture} />
|
|
171
164
|
)}
|
|
165
|
+
{edge !== undefined && !edge.placed
|
|
166
|
+
? (edge.edges.s || edge.edges.n) && (
|
|
167
|
+
<RowGuides top={edge.guideTop} />
|
|
168
|
+
)
|
|
169
|
+
: // Placed, a move snaps to rows as well as columns.
|
|
170
|
+
placed &&
|
|
171
|
+
(gesture || resting) && (
|
|
172
|
+
<RowGuides top={0} faint={!gesture} />
|
|
173
|
+
)}
|
|
172
174
|
|
|
173
175
|
<DashboardGrid
|
|
174
176
|
tiles={entries}
|
|
@@ -208,9 +210,25 @@ export function BuilderGrid({
|
|
|
208
210
|
}
|
|
209
211
|
: {})}
|
|
210
212
|
fixed={!arrange}
|
|
213
|
+
{...(rules.widths
|
|
214
|
+
? {
|
|
215
|
+
edges: {
|
|
216
|
+
// Left and top move a place, so they
|
|
217
|
+
// need the grid drawn as a grid.
|
|
218
|
+
all: arrange,
|
|
219
|
+
right: arrange,
|
|
220
|
+
start: (event, edges) =>
|
|
221
|
+
edging.start(event, index, edges),
|
|
222
|
+
move: edging.move,
|
|
223
|
+
end: edging.end,
|
|
224
|
+
...(edge?.index === index
|
|
225
|
+
? { label: shapeLabel(edge, columns) }
|
|
226
|
+
: {}),
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
: {})}
|
|
211
230
|
{...(rules.widths && arrange
|
|
212
231
|
? {
|
|
213
|
-
resizing: resize?.index === index,
|
|
214
232
|
width: {
|
|
215
233
|
span: each.colspan ?? 1,
|
|
216
234
|
columns,
|
|
@@ -238,22 +256,14 @@ export function BuilderGrid({
|
|
|
238
256
|
});
|
|
239
257
|
},
|
|
240
258
|
},
|
|
241
|
-
onResizeStart: (event) =>
|
|
242
|
-
startResize(event, index),
|
|
243
|
-
onResizeMove: onResize,
|
|
244
|
-
onResizeEnd: endResize,
|
|
245
259
|
}
|
|
246
260
|
: {})}
|
|
247
|
-
{...(rules.widths
|
|
261
|
+
{...(rules.widths
|
|
248
262
|
? {
|
|
249
263
|
heightEdge: {
|
|
250
264
|
rows: each.rowspan,
|
|
251
|
-
dragging: tall?.index === index,
|
|
252
265
|
min: minRowsOf(each),
|
|
253
|
-
|
|
254
|
-
sizing.startHeight(event, index),
|
|
255
|
-
onMove: sizing.onHeight,
|
|
256
|
-
onEnd: sizing.endHeight,
|
|
266
|
+
minFor: (frame) => minRowsOf(each, frame),
|
|
257
267
|
onStep: (to) =>
|
|
258
268
|
editor.update((draft) => {
|
|
259
269
|
if (
|
|
@@ -282,6 +292,7 @@ export function BuilderGrid({
|
|
|
282
292
|
{isTextTile(each) ? (
|
|
283
293
|
<TextTileBody
|
|
284
294
|
tile={each}
|
|
295
|
+
sized={each.rowspan !== undefined || placed}
|
|
285
296
|
onChange={(markdown) =>
|
|
286
297
|
editTile(tileKey(each), (tile) => {
|
|
287
298
|
if (isTextTile(tile))
|
|
@@ -318,15 +329,6 @@ export function BuilderGrid({
|
|
|
318
329
|
);
|
|
319
330
|
}
|
|
320
331
|
|
|
321
|
-
/** A tile at a dragged height: its rows, or auto with no `rowspan` at all. */
|
|
322
|
-
const withRowspan = (
|
|
323
|
-
tile: DashboardTile,
|
|
324
|
-
rows: number | undefined,
|
|
325
|
-
): DashboardTile => {
|
|
326
|
-
const { rowspan: _rowspan, ...rest } = tile;
|
|
327
|
-
return rows === undefined ? rest : { ...rest, rowspan: rows };
|
|
328
|
-
};
|
|
329
|
-
|
|
330
332
|
/** A query tile's title and subtitle as fields on the tile, unless the model owns them. */
|
|
331
333
|
const headingOf = (
|
|
332
334
|
tile: QueryTile,
|
|
@@ -135,6 +135,8 @@ export interface BuilderToolbarProps {
|
|
|
135
135
|
actions?: ReactNode;
|
|
136
136
|
/** Open the add-tile picker. Absent when the host passed no catalog to pick from. */
|
|
137
137
|
onAddTile?: () => void;
|
|
138
|
+
/** The arrange menu, on a report whose tiles are placed; drawn before Tile. */
|
|
139
|
+
arrange?: ReactNode;
|
|
138
140
|
/**
|
|
139
141
|
* Leave the builder: draws Close after Save, for a host that opts in. The
|
|
140
142
|
* Console leaves from its own header and passes nothing.
|
|
@@ -161,6 +163,7 @@ export function BuilderToolbar({
|
|
|
161
163
|
saveButton,
|
|
162
164
|
actions,
|
|
163
165
|
onAddTile,
|
|
166
|
+
arrange,
|
|
164
167
|
onExit,
|
|
165
168
|
saveStatus,
|
|
166
169
|
}: BuilderToolbarProps) {
|
|
@@ -180,6 +183,7 @@ export function BuilderToolbar({
|
|
|
180
183
|
"& .MuiButton-root": { whiteSpace: "nowrap" },
|
|
181
184
|
}}
|
|
182
185
|
>
|
|
186
|
+
{arrange}
|
|
183
187
|
{/* What the page is made of. */}
|
|
184
188
|
{onAddTile && (
|
|
185
189
|
<Button
|