@malloy-publisher/sdk 0.3.0 → 0.3.1

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.
Files changed (156) hide show
  1. package/README.md +8 -0
  2. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
  3. package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
  4. package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
  5. package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
  6. package/dist/ServerProvider-CH71GsoL.cjs.js +1 -0
  7. package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-X2Ma0HRs.es.js} +486 -521
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9561 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.es.js +1 -1
  14. package/dist/components/Dashboard/Dashboard.d.ts +19 -14
  15. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  16. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  17. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  18. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  20. package/dist/components/Dashboard/index.d.ts +2 -0
  21. package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
  22. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  25. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  26. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  27. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  28. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  31. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  32. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  33. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  34. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  35. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  36. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  37. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  38. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  39. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  40. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  41. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  42. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  43. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  44. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  45. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  46. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  47. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  48. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  49. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  50. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  51. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
  52. package/dist/components/DocumentStorage/index.d.ts +1 -1
  53. package/dist/components/FloatingIconButton.d.ts +16 -0
  54. package/dist/components/Prose.d.ts +46 -0
  55. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  56. package/dist/components/RenderedResult/index.d.ts +1 -0
  57. package/dist/components/drill/index.d.ts +1 -1
  58. package/dist/components/drill/resolveDrill.d.ts +22 -0
  59. package/dist/components/drill/useDrill.d.ts +11 -2
  60. package/dist/components/index.d.ts +1 -0
  61. package/dist/components/styles.d.ts +0 -4
  62. package/dist/hooks/index.d.ts +2 -0
  63. package/dist/hooks/useDocumentControls.d.ts +70 -0
  64. package/dist/hooks/useQueryResult.d.ts +40 -0
  65. package/dist/index.cjs.js +23 -270
  66. package/dist/index.es.js +16977 -41293
  67. package/dist/utils/malloyLiteral.d.ts +11 -0
  68. package/package.json +24 -9
  69. package/src/builder-entry.ts +55 -0
  70. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  71. package/src/components/Dashboard/Dashboard.tsx +165 -175
  72. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  73. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  74. package/src/components/Dashboard/DashboardTile.tsx +66 -123
  75. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  76. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  77. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  78. package/src/components/Dashboard/TileCard.tsx +120 -0
  79. package/src/components/Dashboard/index.ts +2 -0
  80. package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
  81. package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
  82. package/src/components/Dashboard/telemetry.ts +44 -0
  83. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  84. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  85. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  86. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  87. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  88. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  89. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  90. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  91. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  92. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  93. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  94. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  95. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  96. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  97. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  98. package/src/components/DashboardBuilder/catalog.ts +225 -0
  99. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  100. package/src/components/DashboardBuilder/controls.ts +398 -0
  101. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  102. package/src/components/DashboardBuilder/diff.ts +93 -0
  103. package/src/components/DashboardBuilder/document.ts +209 -0
  104. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  105. package/src/components/DashboardBuilder/layout.ts +143 -0
  106. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  107. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  108. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  109. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  110. package/src/components/DashboardBuilder/preview.ts +172 -0
  111. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  112. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  113. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  114. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  115. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  116. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  117. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  118. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  119. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  120. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  121. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  122. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  123. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  124. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  125. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  126. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  127. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  128. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
  129. package/src/components/DocumentStorage/index.ts +1 -0
  130. package/src/components/Environment/About.tsx +4 -36
  131. package/src/components/FloatingIconButton.tsx +41 -0
  132. package/src/components/Model/Model.tsx +6 -23
  133. package/src/components/Model/ModelCell.tsx +33 -72
  134. package/src/components/Notebook/Notebook.tsx +25 -88
  135. package/src/components/Notebook/NotebookCell.tsx +35 -183
  136. package/src/components/Prose.spec.tsx +85 -0
  137. package/src/components/Prose.tsx +179 -0
  138. package/src/components/QueryResult/QueryResult.tsx +15 -43
  139. package/src/components/RenderedResult/ResultContainer.tsx +4 -12
  140. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  141. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  142. package/src/components/RenderedResult/index.ts +1 -0
  143. package/src/components/drill/index.ts +1 -0
  144. package/src/components/drill/resolveDrill.ts +22 -1
  145. package/src/components/drill/useDrill.spec.tsx +94 -0
  146. package/src/components/drill/useDrill.tsx +52 -12
  147. package/src/components/given/GivensPanel.tsx +1 -1
  148. package/src/components/index.ts +6 -0
  149. package/src/components/styles.ts +0 -37
  150. package/src/hooks/index.ts +13 -0
  151. package/src/hooks/useDocumentControls.ts +170 -0
  152. package/src/hooks/useQueryResult.ts +82 -0
  153. package/src/utils/malloyLiteral.spec.ts +43 -0
  154. package/src/utils/malloyLiteral.ts +76 -0
  155. package/vite.config.ts +5 -0
  156. package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
@@ -0,0 +1,249 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ Box,
6
+ Button,
7
+ Chip,
8
+ Dialog,
9
+ DialogActions,
10
+ DialogContent,
11
+ DialogTitle,
12
+ List,
13
+ ListItemButton,
14
+ ListItemText,
15
+ MenuItem,
16
+ Stack,
17
+ TextField,
18
+ Typography,
19
+ } from "@mui/material";
20
+ import { useEffect, useMemo, useState } from "react";
21
+ import { usePublisherTheme } from "../../theme/ThemeContext";
22
+ import type { CatalogSource, PackageCatalog } from "./catalog";
23
+ import type { DashboardDocument } from "./document";
24
+
25
+ /**
26
+ * What a new tile is: a view, picked from the package, on a source this file
27
+ * can reach.
28
+ *
29
+ * The picker is what makes a tile expression correct BY CONSTRUCTION. Every
30
+ * `source -> view` it offers came from the catalog, so the builder never emits
31
+ * a tile that does not resolve — which is why saving needs no compile step
32
+ * beyond the reader's own round-trip.
33
+ *
34
+ * "Can reach" is the rule the writer enforces and the reason some sources are
35
+ * not offered: a tile's view is declared in an extension of a model source, and
36
+ * that source has to be in this file's scope. The builder never adds an
37
+ * import, so a model source is offered only when the file already extends it,
38
+ * or imports it BY NAME. A bare `import "../m.malloy"` may well bring it in,
39
+ * but the file cannot say so, and a guess here fails the whole package load.
40
+ */
41
+ export interface NewTile {
42
+ /** The model source the view lives on. */
43
+ base: string;
44
+ /** The view, as the catalog names it. */
45
+ view: string;
46
+ label?: string;
47
+ colspan: number;
48
+ }
49
+
50
+ export interface AddTileDialogProps {
51
+ open: boolean;
52
+ document: DashboardDocument;
53
+ catalog: PackageCatalog | undefined;
54
+ columns: number;
55
+ onClose: () => void;
56
+ onAdd: (tile: NewTile) => void;
57
+ }
58
+
59
+ /** The catalog sources this file can put a tile on; see the note above. */
60
+ function reachableSources(
61
+ document: DashboardDocument,
62
+ catalog: PackageCatalog | undefined,
63
+ ): CatalogSource[] {
64
+ if (!catalog) return [];
65
+ const reachable = new Set<string>();
66
+ for (const source of document.sources) reachable.add(source.base);
67
+ for (const imported of document.imports)
68
+ if (imported.kind === "names")
69
+ for (const name of imported.names) reachable.add(name);
70
+ return catalog.sources.filter((source) => reachable.has(source.name));
71
+ }
72
+
73
+ export function AddTileDialog({
74
+ open,
75
+ document,
76
+ catalog,
77
+ columns,
78
+ onClose,
79
+ onAdd,
80
+ }: AddTileDialogProps) {
81
+ const { theme } = usePublisherTheme();
82
+ const sources = useMemo(
83
+ () => reachableSources(document, catalog),
84
+ [document, catalog],
85
+ );
86
+ const [base, setBase] = useState<string>("");
87
+ const [view, setView] = useState<string>("");
88
+ const [label, setLabel] = useState("");
89
+ const [colspan, setColspan] = useState<number>(Math.ceil(columns / 2));
90
+
91
+ useEffect(() => {
92
+ if (!open) return;
93
+ // Open on the source the tiles already read, so the common case is one
94
+ // click on a view.
95
+ setBase(document.sources[0]?.base ?? sources[0]?.name ?? "");
96
+ setView("");
97
+ setLabel("");
98
+ setColspan(Math.ceil(columns / 2));
99
+ }, [open, document, sources, columns]);
100
+
101
+ const source = sources.find((s) => s.name === base);
102
+ const canAdd = base !== "" && view !== "";
103
+
104
+ return (
105
+ <Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth>
106
+ <DialogTitle sx={{ pb: 0.5 }}>Add a tile</DialogTitle>
107
+ <DialogContent>
108
+ <Stack sx={{ gap: 2, pt: 1 }}>
109
+ {sources.length === 0 ? (
110
+ <Typography variant="body2" sx={{ color: theme.tileTitle }}>
111
+ {catalog
112
+ ? "This dashboard imports no source by name, so there is nothing to put a tile on. Import a source in the file first."
113
+ : "The package's sources are still loading."}
114
+ </Typography>
115
+ ) : (
116
+ <>
117
+ <TextField
118
+ select
119
+ size="small"
120
+ label="Source"
121
+ value={base}
122
+ onChange={(event) => {
123
+ setBase(event.target.value);
124
+ setView("");
125
+ }}
126
+ inputProps={{ "aria-label": "Source" }}
127
+ >
128
+ {sources.map((s) => (
129
+ <MenuItem key={s.name} value={s.name}>
130
+ {s.name}
131
+ {s.description && (
132
+ <Typography
133
+ component="span"
134
+ variant="caption"
135
+ sx={{ ml: 1, opacity: 0.6 }}
136
+ >
137
+ {s.description}
138
+ </Typography>
139
+ )}
140
+ </MenuItem>
141
+ ))}
142
+ </TextField>
143
+ <Box>
144
+ <Typography variant="subtitle2" sx={{ mb: 0.5 }}>
145
+ View
146
+ </Typography>
147
+ <List
148
+ dense
149
+ disablePadding
150
+ aria-label="Views"
151
+ sx={{
152
+ maxHeight: 280,
153
+ overflowY: "auto",
154
+ border: theme.border,
155
+ borderRadius: 1,
156
+ }}
157
+ >
158
+ {(source?.views ?? []).map((v) => (
159
+ <ListItemButton
160
+ key={v.name}
161
+ selected={view === v.name}
162
+ onClick={() => setView(v.name)}
163
+ aria-label={`View ${v.name}`}
164
+ >
165
+ <ListItemText
166
+ primary={v.name}
167
+ secondary={v.description}
168
+ primaryTypographyProps={{
169
+ fontFamily: "ui-monospace, monospace",
170
+ fontSize: 13,
171
+ }}
172
+ />
173
+ {v.chart && (
174
+ <Chip
175
+ size="small"
176
+ variant="outlined"
177
+ label={v.chart.replace(/_chart$/, "")}
178
+ />
179
+ )}
180
+ </ListItemButton>
181
+ ))}
182
+ {source && source.views.length === 0 && (
183
+ <Typography
184
+ variant="body2"
185
+ sx={{ p: 1.5, color: theme.tileTitle }}
186
+ >
187
+ This source declares no views.
188
+ </Typography>
189
+ )}
190
+ </List>
191
+ </Box>
192
+ <Stack direction="row" sx={{ gap: 1.5 }}>
193
+ <TextField
194
+ size="small"
195
+ label="Title"
196
+ placeholder="Uses the view's name"
197
+ value={label}
198
+ onChange={(event) => setLabel(event.target.value)}
199
+ inputProps={{ "aria-label": "Tile title" }}
200
+ sx={{ flex: 1 }}
201
+ />
202
+ <TextField
203
+ size="small"
204
+ type="number"
205
+ label={`Width (of ${columns})`}
206
+ value={colspan}
207
+ onChange={(event) =>
208
+ setColspan(
209
+ Math.min(
210
+ Math.max(
211
+ Number(event.target.value) || 1,
212
+ 1,
213
+ ),
214
+ columns,
215
+ ),
216
+ )
217
+ }
218
+ inputProps={{
219
+ min: 1,
220
+ max: columns,
221
+ "aria-label": "Tile width",
222
+ }}
223
+ sx={{ width: 140 }}
224
+ />
225
+ </Stack>
226
+ </>
227
+ )}
228
+ </Stack>
229
+ </DialogContent>
230
+ <DialogActions sx={{ px: 3, py: 1.5 }}>
231
+ <Button onClick={onClose}>Cancel</Button>
232
+ <Button
233
+ variant="contained"
234
+ disabled={!canAdd}
235
+ onClick={() =>
236
+ onAdd({
237
+ base,
238
+ view,
239
+ ...(label.trim() ? { label: label.trim() } : {}),
240
+ colspan,
241
+ })
242
+ }
243
+ >
244
+ Add tile
245
+ </Button>
246
+ </DialogActions>
247
+ </Dialog>
248
+ );
249
+ }
@@ -0,0 +1,270 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import AddIcon from "@mui/icons-material/Add";
5
+ import CheckIcon from "@mui/icons-material/Check";
6
+ import GridViewIcon from "@mui/icons-material/GridView";
7
+ import TuneIcon from "@mui/icons-material/Tune";
8
+ import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
9
+ import RedoIcon from "@mui/icons-material/Redo";
10
+ import UndoIcon from "@mui/icons-material/Undo";
11
+ import {
12
+ Button,
13
+ Chip,
14
+ Divider,
15
+ IconButton,
16
+ ListItemIcon,
17
+ ListItemText,
18
+ Menu,
19
+ MenuItem,
20
+ Stack,
21
+ Tooltip,
22
+ Typography,
23
+ } from "@mui/material";
24
+ import { useState, type ReactNode } from "react";
25
+ import { usePublisherTheme } from "../../theme/ThemeContext";
26
+ import { MOD } from "./useBuilderShortcuts";
27
+
28
+ /**
29
+ * The edit bar across the top of the builder, in the shape every builder has
30
+ * settled on: that you are editing on the left, what you can do about it on
31
+ * the right.
32
+ *
33
+ * Sticky, so undo and save stay in reach on a long dashboard; the reader's own
34
+ * header (title and description) stays in the page below it rather than being
35
+ * repeated here.
36
+ */
37
+ export interface BuilderToolbarProps {
38
+ canUndo: boolean;
39
+ canRedo: boolean;
40
+ onUndo: () => void;
41
+ onRedo: () => void;
42
+ dirty: boolean;
43
+ saving: boolean;
44
+ /** Absent when the builder has nowhere to save: no Save, no unsaved marker. */
45
+ onSave?: () => void;
46
+ /** The host's actions, beside the builder's own: Export, Done. */
47
+ actions?: ReactNode;
48
+ /** Open the add-tile picker. Absent when the host passed no catalog to pick from. */
49
+ onAddTile?: () => void;
50
+ /** Open the page's settings, anchored to the button that asked. */
51
+ onSettings: (anchor: HTMLElement) => void;
52
+ /** Quick layout: every tile this file owns to one width. */
53
+ onQuickLayout: (share: 1 | 2 | 3 | 4) => void;
54
+ }
55
+
56
+ export function BuilderToolbar({
57
+ canUndo,
58
+ canRedo,
59
+ onUndo,
60
+ onRedo,
61
+ dirty,
62
+ saving,
63
+ onSave,
64
+ actions,
65
+ onAddTile,
66
+ onSettings,
67
+ onQuickLayout,
68
+ }: BuilderToolbarProps) {
69
+ const { theme } = usePublisherTheme();
70
+ const [layoutMenu, setLayoutMenu] = useState<HTMLElement | null>(null);
71
+ return (
72
+ <Stack
73
+ direction="row"
74
+ sx={{
75
+ position: "sticky",
76
+ top: 0,
77
+ zIndex: 5,
78
+ alignItems: "center",
79
+ gap: 1,
80
+ px: 1.5,
81
+ py: 1,
82
+ // Its own ground, so the tiles scrolling under it do not show
83
+ // through, and an edge so it reads as a bar rather than a row.
84
+ // The Publisher theme's ground and edge, like every other surface
85
+ // here — MUI's own palette would not follow an instance theme or
86
+ // its dark mode.
87
+ bgcolor: theme.background,
88
+ borderBottom: theme.border,
89
+ borderRadius: 1,
90
+ }}
91
+ >
92
+ <Chip
93
+ size="small"
94
+ icon={<EditOutlinedIcon sx={{ fontSize: 14 }} />}
95
+ label="Editing"
96
+ sx={{
97
+ fontWeight: 500,
98
+ bgcolor: theme.drillLink,
99
+ color: theme.tile,
100
+ "& .MuiChip-icon": { color: "inherit" },
101
+ }}
102
+ />
103
+ <Typography
104
+ variant="body2"
105
+ sx={{
106
+ color: theme.tileTitle,
107
+ display: { xs: "none", md: "block" },
108
+ }}
109
+ >
110
+ Drag a tile to move it, its right edge to resize it, or into the
111
+ empty end of a row to move it up.
112
+ </Typography>
113
+
114
+ <Stack
115
+ direction="row"
116
+ sx={{
117
+ ml: "auto",
118
+ alignItems: "center",
119
+ gap: 0.5,
120
+ // The hint beside the chip is what gives way when the bar is
121
+ // narrow; a button's label never wraps onto a second line.
122
+ flexShrink: 0,
123
+ "& .MuiButton-root": { whiteSpace: "nowrap" },
124
+ }}
125
+ >
126
+ {onAddTile && (
127
+ <Button
128
+ size="small"
129
+ startIcon={<AddIcon fontSize="small" />}
130
+ onClick={onAddTile}
131
+ >
132
+ Add tile
133
+ </Button>
134
+ )}
135
+ <Button
136
+ size="small"
137
+ startIcon={<GridViewIcon fontSize="small" />}
138
+ onClick={(event) => setLayoutMenu(event.currentTarget)}
139
+ aria-haspopup="menu"
140
+ >
141
+ Layout
142
+ </Button>
143
+ <Menu
144
+ anchorEl={layoutMenu}
145
+ open={layoutMenu !== null}
146
+ onClose={() => setLayoutMenu(null)}
147
+ >
148
+ <Typography
149
+ variant="caption"
150
+ sx={{
151
+ px: 2,
152
+ py: 0.5,
153
+ display: "block",
154
+ color: theme.tileTitle,
155
+ }}
156
+ >
157
+ Set every tile to
158
+ </Typography>
159
+ {(
160
+ [
161
+ ["Full width", 1],
162
+ ["Half width", 2],
163
+ ["A third", 3],
164
+ ["A quarter", 4],
165
+ ] as const
166
+ ).map(([label, share]) => (
167
+ <MenuItem
168
+ key={share}
169
+ onClick={() => {
170
+ setLayoutMenu(null);
171
+ onQuickLayout(share);
172
+ }}
173
+ >
174
+ <ListItemIcon>
175
+ <GridViewIcon fontSize="small" />
176
+ </ListItemIcon>
177
+ <ListItemText>{label}</ListItemText>
178
+ </MenuItem>
179
+ ))}
180
+ </Menu>
181
+ <Button
182
+ size="small"
183
+ startIcon={<TuneIcon fontSize="small" />}
184
+ onClick={(event) => onSettings(event.currentTarget)}
185
+ >
186
+ Settings
187
+ </Button>
188
+ {actions && (
189
+ <>
190
+ {actions}
191
+ <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
192
+ </>
193
+ )}
194
+ <Tooltip title={`Undo (${MOD}Z)`}>
195
+ {/* A span, because a disabled button dispatches no events and a
196
+ tooltip on one would never show. */}
197
+ <span>
198
+ <IconButton
199
+ aria-label="Undo"
200
+ size="small"
201
+ disabled={!canUndo}
202
+ onClick={onUndo}
203
+ >
204
+ <UndoIcon fontSize="small" />
205
+ </IconButton>
206
+ </span>
207
+ </Tooltip>
208
+ <Tooltip title={`Redo (${MOD}⇧Z)`}>
209
+ <span>
210
+ <IconButton
211
+ aria-label="Redo"
212
+ size="small"
213
+ disabled={!canRedo}
214
+ onClick={onRedo}
215
+ >
216
+ <RedoIcon fontSize="small" />
217
+ </IconButton>
218
+ </span>
219
+ </Tooltip>
220
+ {onSave && (
221
+ <>
222
+ <Divider orientation="vertical" flexItem sx={{ mx: 0.5 }} />
223
+ {/* "Unsaved changes" beside Save: the button's label alone
224
+ reads as a command, not as a state. */}
225
+ <Typography
226
+ variant="caption"
227
+ aria-live="polite"
228
+ sx={{
229
+ color: theme.tileTitle,
230
+ minWidth: 108,
231
+ textAlign: "right",
232
+ // Room between the state and the button that acts on
233
+ // it: at the row's 4px gap the two read as one label.
234
+ mr: 1.5,
235
+ opacity: dirty && !saving ? 1 : 0,
236
+ transition: "opacity 120ms",
237
+ }}
238
+ >
239
+ Unsaved changes
240
+ </Typography>
241
+ <Tooltip title={dirty ? `Save (${MOD}S)` : ""}>
242
+ <span>
243
+ <Button
244
+ variant={dirty ? "contained" : "outlined"}
245
+ size="small"
246
+ disabled={!dirty || saving}
247
+ onClick={onSave}
248
+ startIcon={
249
+ !dirty && !saving ? (
250
+ <CheckIcon fontSize="small" />
251
+ ) : undefined
252
+ }
253
+ sx={{ minWidth: 124 }}
254
+ >
255
+ {/* Says what will happen, then that it is happening,
256
+ then what did. */}
257
+ {saving
258
+ ? "Saving…"
259
+ : dirty
260
+ ? "Save changes"
261
+ : "Saved"}
262
+ </Button>
263
+ </span>
264
+ </Tooltip>
265
+ </>
266
+ )}
267
+ </Stack>
268
+ </Stack>
269
+ );
270
+ }