@malloy-publisher/sdk 0.2.7 → 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 (221) hide show
  1. package/README.md +180 -204
  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-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
  7. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
  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/api.d.ts +13 -1
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  16. package/dist/components/Dashboard/Dashboard.d.ts +23 -16
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  18. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  19. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  20. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  21. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  22. package/dist/components/Dashboard/index.d.ts +2 -0
  23. package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
  24. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  25. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  26. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  27. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  28. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  29. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  30. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  31. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  32. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  33. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  34. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  35. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  36. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  37. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  38. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  39. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  40. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  41. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  42. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  43. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  44. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  45. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  46. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  47. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  48. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  49. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  50. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  51. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  52. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  53. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  54. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  55. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
  56. package/dist/components/DocumentStorage/index.d.ts +3 -0
  57. package/dist/components/FloatingIconButton.d.ts +16 -0
  58. package/dist/components/Model/index.d.ts +0 -1
  59. package/dist/components/Prose.d.ts +46 -0
  60. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  61. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  62. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  63. package/dist/components/RenderedResult/index.d.ts +2 -0
  64. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  65. package/dist/components/drill/index.d.ts +2 -1
  66. package/dist/components/drill/resolveDrill.d.ts +22 -0
  67. package/dist/components/drill/useDrill.d.ts +11 -2
  68. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  69. package/dist/components/given/filterValue.d.ts +63 -0
  70. package/dist/components/given/index.d.ts +1 -0
  71. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  72. package/dist/components/index.d.ts +3 -3
  73. package/dist/components/styles.d.ts +3 -7
  74. package/dist/core-8NVBCLZh.cjs.js +148 -0
  75. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  76. package/dist/hooks/index.d.ts +3 -1
  77. package/dist/hooks/useDocumentControls.d.ts +70 -0
  78. package/dist/hooks/useQueryResult.d.ts +40 -0
  79. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  80. package/dist/index.cjs.js +34 -1
  81. package/dist/index.es.js +21487 -79
  82. package/dist/sdk.css +1 -1
  83. package/dist/styles.css +0 -1
  84. package/dist/utils/malloyLiteral.d.ts +11 -0
  85. package/package.json +25 -14
  86. package/src/builder-entry.ts +55 -0
  87. package/src/components/ApiErrorDisplay.tsx +1 -1
  88. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  89. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  90. package/src/components/Dashboard/Dashboard.tsx +184 -229
  91. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  92. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  93. package/src/components/Dashboard/DashboardTile.tsx +67 -101
  94. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  95. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  96. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  97. package/src/components/Dashboard/TileCard.tsx +120 -0
  98. package/src/components/Dashboard/index.ts +2 -0
  99. package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
  100. package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
  101. package/src/components/Dashboard/telemetry.ts +44 -0
  102. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  103. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  104. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  105. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  106. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  107. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  108. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  109. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  110. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  111. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  112. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  113. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  114. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  115. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  116. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  117. package/src/components/DashboardBuilder/catalog.ts +225 -0
  118. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  119. package/src/components/DashboardBuilder/controls.ts +398 -0
  120. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  121. package/src/components/DashboardBuilder/diff.ts +93 -0
  122. package/src/components/DashboardBuilder/document.ts +209 -0
  123. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  124. package/src/components/DashboardBuilder/layout.ts +143 -0
  125. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  126. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  127. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  128. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  129. package/src/components/DashboardBuilder/preview.ts +172 -0
  130. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  131. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  132. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  133. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  134. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  135. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  136. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  137. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  138. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  139. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  140. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  141. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  142. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  143. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  144. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  145. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  146. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  147. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  148. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  149. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  150. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
  151. package/src/components/DocumentStorage/index.ts +16 -0
  152. package/src/components/Environment/About.tsx +4 -36
  153. package/src/components/FloatingIconButton.tsx +41 -0
  154. package/src/components/Model/Model.tsx +6 -23
  155. package/src/components/Model/ModelCell.tsx +34 -72
  156. package/src/components/Model/index.ts +0 -1
  157. package/src/components/Notebook/Notebook.tsx +27 -156
  158. package/src/components/Notebook/NotebookCell.tsx +37 -191
  159. package/src/components/Prose.spec.tsx +85 -0
  160. package/src/components/Prose.tsx +179 -0
  161. package/src/components/QueryResult/QueryResult.tsx +15 -43
  162. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  163. package/src/components/RenderedResult/ResultContainer.tsx +25 -36
  164. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  165. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  166. package/src/components/RenderedResult/index.ts +16 -0
  167. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  168. package/src/components/RenderedResult/resultSizing.ts +308 -0
  169. package/src/components/ResultsDialog.tsx +2 -1
  170. package/src/components/drill/index.ts +6 -0
  171. package/src/components/drill/resolveDrill.ts +22 -1
  172. package/src/components/drill/useDrill.spec.tsx +94 -0
  173. package/src/components/drill/useDrill.tsx +52 -12
  174. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  175. package/src/components/drill/useDrillSelf.ts +110 -0
  176. package/src/components/given/GivenInput.spec.tsx +196 -2
  177. package/src/components/given/GivenInput.tsx +300 -25
  178. package/src/components/given/GivensPanel.tsx +1 -1
  179. package/src/components/given/filterValue.spec.ts +112 -0
  180. package/src/components/given/filterValue.ts +188 -0
  181. package/src/components/given/index.ts +4 -0
  182. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  183. package/src/components/given/useGivenUrlParams.ts +87 -0
  184. package/src/components/index.ts +11 -3
  185. package/src/components/styles.ts +0 -37
  186. package/src/hooks/index.ts +13 -1
  187. package/src/hooks/useDocumentControls.ts +170 -0
  188. package/src/hooks/useGivensState.spec.ts +158 -0
  189. package/src/hooks/useGivensState.ts +114 -23
  190. package/src/hooks/useQueryResult.ts +82 -0
  191. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  192. package/src/hooks/useSuggestOptions.ts +94 -51
  193. package/src/utils/malloyLiteral.spec.ts +43 -0
  194. package/src/utils/malloyLiteral.ts +76 -0
  195. package/vite.config.ts +5 -1
  196. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  197. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  198. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  199. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  200. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  201. package/dist/components/Workbook/Workbook.d.ts +0 -7
  202. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  203. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  204. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  205. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  206. package/dist/components/Workbook/index.d.ts +0 -7
  207. package/dist/core-CWKmWEg2.cjs.js +0 -148
  208. package/dist/index-B0WyZAUA.es.js +0 -66412
  209. package/dist/index-kxVD1RjY.cjs.js +0 -356
  210. package/dist/markdown-editor.css +0 -341
  211. package/src/components/AnalyzePackageButton.tsx +0 -319
  212. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  213. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  214. package/src/components/Workbook/ModelPicker.tsx +0 -134
  215. package/src/components/Workbook/MutableCell.tsx +0 -458
  216. package/src/components/Workbook/Workbook.tsx +0 -501
  217. package/src/components/Workbook/WorkbookList.tsx +0 -110
  218. package/src/components/Workbook/WorkbookManager.ts +0 -214
  219. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  220. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  221. package/src/components/Workbook/index.ts +0 -10
@@ -0,0 +1,125 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import AddIcon from "@mui/icons-material/Add";
5
+ import FilterListIcon from "@mui/icons-material/FilterList";
6
+ import { Button, Chip, Stack, Tooltip, Typography } from "@mui/material";
7
+ import type { ReactNode } from "react";
8
+ import { usePublisherTheme } from "../../theme/ThemeContext";
9
+ import type { BuilderControl } from "./controls";
10
+
11
+ /**
12
+ * The strip under the header where the dashboard's controls are configured —
13
+ * the ONE place: a chip per control opens its window, and "Add filter"
14
+ * declares a new one. The live control row the host renders sits under it.
15
+ */
16
+ export function FilterStrip({
17
+ controls: controlList,
18
+ tileCount,
19
+ unknownFieldsOf,
20
+ onEdit,
21
+ onAdd,
22
+ children,
23
+ }: {
24
+ controls: BuilderControl[];
25
+ tileCount: number;
26
+ /** Bindings a control has that its tiles' sources cannot take. */
27
+ unknownFieldsOf: (name: string, type: string | undefined) => string[];
28
+ onEdit: (control: BuilderControl) => void;
29
+ onAdd: () => void;
30
+ /** The host's live control row. */
31
+ children?: ReactNode;
32
+ }) {
33
+ const { theme } = usePublisherTheme();
34
+ return (
35
+ <>
36
+ {/* The filter band, as every dashboard builder has one. The header is the
37
+ dashboard's controls as this FILE has them: a chip per control,
38
+ which opens its window — the one place a control is edited, bound
39
+ or removed, so the consequences are in view when it happens. A ×
40
+ on the chip was a second place, with none of them. The live control row the caller
41
+ passes in sits directly under, showing the same controls as a
42
+ reader gets them — from the saved file. */}
43
+ <Stack sx={{ gap: 1 }}>
44
+ <Stack
45
+ direction="row"
46
+ aria-label="Filters"
47
+ sx={{
48
+ gap: 1,
49
+ alignItems: "center",
50
+ flexWrap: "wrap",
51
+ minHeight: 32,
52
+ }}
53
+ >
54
+ <FilterListIcon
55
+ sx={{ fontSize: 18, color: theme.tileTitle, opacity: 0.7 }}
56
+ />
57
+ <Typography
58
+ variant="subtitle2"
59
+ sx={{ color: theme.tileTitle, mr: 0.5 }}
60
+ >
61
+ Filters
62
+ </Typography>
63
+ {controlList.length === 0 && (
64
+ <Typography
65
+ variant="body2"
66
+ sx={{ color: theme.tileTitle, opacity: 0.8 }}
67
+ >
68
+ None yet.
69
+ </Typography>
70
+ )}
71
+ {controlList.map((control) => {
72
+ const unknown = unknownFieldsOf(control.name, control.type);
73
+ return (
74
+ <Tooltip
75
+ key={control.name}
76
+ title={
77
+ unknown.length > 0
78
+ ? `$${control.name} · cannot filter on: ${unknown.join(", ")}`
79
+ : `$${control.name} · ${
80
+ control.origin === "dashboard"
81
+ ? "declared here"
82
+ : "from the model"
83
+ } · ${control.boundTiles} of ${tileCount} tiles`
84
+ }
85
+ >
86
+ <Chip
87
+ size="small"
88
+ label={control.label ?? control.name}
89
+ aria-label={`Edit filter ${control.name}`}
90
+ // Warning where a binding names a field the source
91
+ // does not have: the package would refuse the file.
92
+ color={unknown.length > 0 ? "warning" : "default"}
93
+ variant={
94
+ control.origin === "dashboard"
95
+ ? "filled"
96
+ : "outlined"
97
+ }
98
+ onClick={() => onEdit(control)}
99
+ sx={{
100
+ // Faint when nothing binds it: declared, but not yet a
101
+ // control a reader would see.
102
+ opacity: control.boundTiles === 0 ? 0.6 : 1,
103
+ cursor: "pointer",
104
+ transition: "opacity 120ms",
105
+ }}
106
+ />
107
+ </Tooltip>
108
+ );
109
+ })}
110
+ <Button
111
+ size="small"
112
+ variant="outlined"
113
+ startIcon={<AddIcon fontSize="small" />}
114
+ onClick={() => onAdd()}
115
+ sx={{ ml: "auto" }}
116
+ >
117
+ Add filter
118
+ </Button>
119
+ </Stack>
120
+
121
+ {children}
122
+ </Stack>
123
+ </>
124
+ );
125
+ }
@@ -0,0 +1,168 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ FormControlLabel,
6
+ MenuItem,
7
+ Popover,
8
+ Stack,
9
+ Switch,
10
+ TextField,
11
+ Typography,
12
+ } from "@mui/material";
13
+ import { useDraft } from "./useDraft";
14
+ import { usePublisherTheme } from "../../theme/ThemeContext";
15
+ import type { DashboardDocument } from "./document";
16
+
17
+ /**
18
+ * The page's own settings, off the edit bar: its title, the markdown
19
+ * description under it, the grid's width, and whether controls run as they
20
+ * change or behind an Apply button. Edits commit on close (`useDraft`).
21
+ */
22
+ export interface PageSettings {
23
+ title: string;
24
+ description?: string;
25
+ columns?: number;
26
+ autorun?: boolean;
27
+ }
28
+
29
+ export const settingsOf = (document: DashboardDocument): PageSettings => ({
30
+ title: document.title,
31
+ ...(document.description === undefined
32
+ ? {}
33
+ : { description: document.description }),
34
+ ...(document.columns === undefined ? {} : { columns: document.columns }),
35
+ ...(document.autorun === undefined ? {} : { autorun: document.autorun }),
36
+ });
37
+
38
+ /** The widths a grid is usually given; the file may say any other. */
39
+ const WIDTHS = [2, 3, 4, 6, 8, 12, 16, 24];
40
+
41
+ export function SettingsPopover({
42
+ anchor,
43
+ settings,
44
+ onClose,
45
+ onCommit,
46
+ }: {
47
+ anchor: HTMLElement | null;
48
+ settings: PageSettings;
49
+ onClose: () => void;
50
+ /** Called once, on close, only when something changed. */
51
+ onCommit: (next: PageSettings) => void;
52
+ }) {
53
+ const { theme } = usePublisherTheme();
54
+ const { draft, patch, close } = useDraft(
55
+ settings,
56
+ anchor !== null,
57
+ onCommit,
58
+ onClose,
59
+ );
60
+
61
+ const widths =
62
+ draft?.columns !== undefined && !WIDTHS.includes(draft.columns)
63
+ ? [...WIDTHS, draft.columns].sort((a, b) => a - b)
64
+ : WIDTHS;
65
+
66
+ return (
67
+ <Popover
68
+ open={anchor !== null && draft !== undefined}
69
+ anchorEl={anchor}
70
+ onClose={close}
71
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
72
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
73
+ slotProps={{ paper: { sx: { width: 380, p: 2 } } }}
74
+ >
75
+ {draft && (
76
+ <Stack sx={{ gap: 1.5 }}>
77
+ <Typography
78
+ variant="overline"
79
+ sx={{ color: theme.tileTitle, lineHeight: 1.5 }}
80
+ >
81
+ Dashboard
82
+ </Typography>
83
+ <TextField
84
+ size="small"
85
+ label="Title"
86
+ value={draft.title}
87
+ autoFocus
88
+ inputProps={{ "aria-label": "Dashboard title" }}
89
+ onChange={(event) =>
90
+ patch((s) => {
91
+ s.title = event.target.value;
92
+ })
93
+ }
94
+ />
95
+ <TextField
96
+ size="small"
97
+ label="Description"
98
+ multiline
99
+ minRows={3}
100
+ maxRows={10}
101
+ value={draft.description ?? ""}
102
+ helperText="Markdown. A blank line starts a new paragraph."
103
+ inputProps={{ "aria-label": "Dashboard description" }}
104
+ onChange={(event) =>
105
+ patch((s) => {
106
+ const v = event.target.value;
107
+ if (v.trim() === "") delete s.description;
108
+ else s.description = v;
109
+ })
110
+ }
111
+ />
112
+ <TextField
113
+ select
114
+ size="small"
115
+ label="Grid width"
116
+ value={draft.columns ?? ""}
117
+ helperText="Columns across the page. Tiles are placed in these."
118
+ inputProps={{ "aria-label": "Grid width" }}
119
+ onChange={(event) =>
120
+ patch((s) => {
121
+ const v = Number(event.target.value);
122
+ if (!v) delete s.columns;
123
+ else s.columns = v;
124
+ })
125
+ }
126
+ >
127
+ <MenuItem value="">Default (2)</MenuItem>
128
+ {widths.map((w) => (
129
+ <MenuItem key={w} value={w}>
130
+ {w}
131
+ </MenuItem>
132
+ ))}
133
+ </TextField>
134
+ <FormControlLabel
135
+ control={
136
+ <Switch
137
+ size="small"
138
+ checked={draft.autorun !== false}
139
+ slotProps={{
140
+ input: { "aria-label": "Run as controls change" },
141
+ }}
142
+ onChange={(event) =>
143
+ patch((s) => {
144
+ if (event.target.checked) delete s.autorun;
145
+ else s.autorun = false;
146
+ })
147
+ }
148
+ />
149
+ }
150
+ label={
151
+ <Typography variant="body2">
152
+ Run as controls change
153
+ <Typography
154
+ component="span"
155
+ variant="caption"
156
+ sx={{ display: "block", opacity: 0.7 }}
157
+ >
158
+ Off, readers press Apply. For a page whose queries
159
+ are slow.
160
+ </Typography>
161
+ </Typography>
162
+ }
163
+ />
164
+ </Stack>
165
+ )}
166
+ </Popover>
167
+ );
168
+ }
@@ -0,0 +1,380 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import DragIndicatorIcon from "@mui/icons-material/DragIndicator";
5
+ import MoreVertIcon from "@mui/icons-material/MoreVert";
6
+ import { Box, IconButton, Typography } from "@mui/material";
7
+ import type { PointerEvent, ReactNode } from "react";
8
+ import { usePublisherTheme } from "../../theme/ThemeContext";
9
+ import { GRID_GAP_PX } from "../Dashboard/DashboardGrid";
10
+ import { TileCard, TileHeading } from "../Dashboard/TileCard";
11
+ import { tileKey, type DashboardTile } from "./document";
12
+ import { gapId } from "./layout";
13
+ import { GapDroppable, TileSortable } from "./sortable";
14
+
15
+ /**
16
+ * Everything the builder draws AROUND a tile: the selection outline, the grip,
17
+ * the menu button, the resize badge and the handle at the right edge. The tile
18
+ * itself is `children` — the host's real `DashboardTile`, or a placeholder
19
+ * saying what the tile will run.
20
+ */
21
+ export function TileFrame({
22
+ tile,
23
+ index,
24
+ selected,
25
+ menuOpen,
26
+ resizeSpan,
27
+ columns,
28
+ onSelect,
29
+ onOpenMenu,
30
+ onResizeStart,
31
+ onResizeMove,
32
+ onResizeEnd,
33
+ children,
34
+ }: {
35
+ tile: DashboardTile;
36
+ index: number;
37
+ selected: boolean;
38
+ /** Whether this tile's menu is open, which keeps its button showing. */
39
+ menuOpen: boolean;
40
+ /** The width being previewed while THIS tile is resized. */
41
+ resizeSpan: number | undefined;
42
+ columns: number;
43
+ onSelect: () => void;
44
+ onOpenMenu: (anchor: HTMLElement) => void;
45
+ onResizeStart: (event: PointerEvent<HTMLDivElement>) => void;
46
+ onResizeMove: (event: PointerEvent<HTMLDivElement>) => void;
47
+ onResizeEnd: (event: PointerEvent<HTMLDivElement>) => void;
48
+ children: ReactNode;
49
+ }) {
50
+ const { theme } = usePublisherTheme();
51
+ return (
52
+ <TileSortable id={tileKey(tile)} index={index}>
53
+ {({ ref, handleRef, isDragSource }) => (
54
+ <Box
55
+ ref={ref}
56
+ onClick={onSelect}
57
+ // Selected on the press, so a tile reads as
58
+ // held the moment it is. The drag itself is
59
+ // the sensor's — see `sortable.tsx`.
60
+ onPointerDown={(event) => {
61
+ if (event.button === 0) onSelect();
62
+ }}
63
+ aria-label={`Tile ${tile.name}`}
64
+ aria-current={selected}
65
+ sx={{
66
+ // Anchors the resize and drag handles to
67
+ // this tile.
68
+ position: "relative",
69
+ // Same again: this wrapper sits BETWEEN
70
+ // the grid item and the tile, so it has to
71
+ // pass the height on rather than shrink to
72
+ // the tile.
73
+ display: "grid",
74
+ // And the WIDTH the other way: it must
75
+ // follow the grid item down when a tile is
76
+ // narrowed, not stay as wide as the chart
77
+ // it holds. See the `minWidth: 0` note in
78
+ // `DashboardGrid`; this is the next link in
79
+ // that chain.
80
+ minWidth: 0,
81
+ // Says the card can be picked up. Content
82
+ // with a cursor of its own — a drill link,
83
+ // a scrollbar — still wins over its own
84
+ // pixels.
85
+ cursor: "grab",
86
+ borderRadius: 1,
87
+ // An outline rather than a border, and
88
+ // outside the tile rather than on it: the
89
+ // tile already has an edge of its own, and
90
+ // an outline neither doubles that edge nor
91
+ // takes up space, so selecting a tile
92
+ // cannot shift the layout being arranged.
93
+ outline: selected
94
+ ? `2px solid ${theme.drillLink}`
95
+ : `2px solid transparent`,
96
+ outlineOffset: 2,
97
+ transition:
98
+ "outline-color 120ms, opacity 120ms, box-shadow 120ms",
99
+ // The handles, grip and menu are invisible
100
+ // until wanted, and wanted is: the pointer
101
+ // over the tile, or the tile selected. A
102
+ // hover rule on the WRAPPER, so all three
103
+ // appear together rather than as the
104
+ // pointer finds tile.
105
+ // The library marks the tile in hand
106
+ // `data-dnd-dragging` and the copy it leaves
107
+ // in the flow `data-dnd-placeholder`, and
108
+ // mirrors every class and style of the one
109
+ // onto the other — so styling driven by
110
+ // React state landed on BOTH, and the tile
111
+ // under the pointer was as faded and dashed
112
+ // as the slot it was leaving. Styled by the
113
+ // attributes instead: the tile in hand is
114
+ // solid and lifted; the slot it will land
115
+ // in is the faded, dashed one — the pair every
116
+ // drag-and-drop grid draws. Doubled so they outrank
117
+ // the hover rule below on the tile in hand.
118
+ "&&[data-dnd-dragging]": {
119
+ opacity: 1,
120
+ outline: "none",
121
+ boxShadow: "0 12px 32px rgba(0, 0, 0, 0.22)",
122
+ },
123
+ "&&[data-dnd-placeholder]": {
124
+ opacity: 0.45,
125
+ outline: `2px dashed ${theme.drillLink}`,
126
+ boxShadow: "none",
127
+ },
128
+ "&:hover .builder-affordance, &:focus-within .builder-affordance":
129
+ { opacity: 1 },
130
+ // A hovered tile lifts, as a card does in any
131
+ // builder's edit mode: the one card that
132
+ // will respond to the pointer, told apart
133
+ // from the ones that will not.
134
+ "&:hover": {
135
+ outlineColor: selected ? theme.drillLink : theme.border,
136
+ boxShadow: "0 2px 10px rgba(0, 0, 0, 0.10)",
137
+ },
138
+ }}
139
+ >
140
+ {children}
141
+
142
+ {/* The grip. On every tile, including an
143
+ inherited one — order is this file's
144
+ `tiles=[…]` array, not anything on the view.
145
+ The whole card starts a pointer drag; the grip
146
+ is the sign of it and the library's HANDLE,
147
+ where keyboard focus and the screen-reader
148
+ instructions land: Space picks the tile up,
149
+ the arrows move it, Escape puts it back. */}
150
+ <Box
151
+ ref={handleRef}
152
+ className="builder-affordance"
153
+ aria-label={`Move ${tile.label ?? tile.name}`}
154
+ sx={{
155
+ position: "absolute",
156
+ top: "2px",
157
+ left: "2px",
158
+ display: "grid",
159
+ placeItems: "center",
160
+ width: "22px",
161
+ height: "22px",
162
+ borderRadius: "4px",
163
+ cursor: "grab",
164
+ touchAction: "none",
165
+ zIndex: 2,
166
+ color: theme.tileTitle,
167
+ bgcolor: theme.tile,
168
+ opacity: isDragSource || selected ? 0.9 : 0,
169
+ transition: "opacity 120ms",
170
+ "&:hover": { opacity: 1 },
171
+ "&:active": { cursor: "grabbing" },
172
+ "&:focus-visible": {
173
+ opacity: 1,
174
+ outline: `2px solid ${theme.drillLink}`,
175
+ outlineOffset: 1,
176
+ },
177
+ }}
178
+ >
179
+ <DragIndicatorIcon sx={{ fontSize: 16 }} />
180
+ </Box>
181
+
182
+ {/* The tile's menu: its title and subtitle.
183
+ Hidden while a resize badge sits in the same
184
+ corner. A press here is never the start of a
185
+ drag: the sensor refuses to activate from a
186
+ button. */}
187
+ {resizeSpan === undefined && (
188
+ <IconButton
189
+ className="builder-affordance"
190
+ size="small"
191
+ aria-label={`Settings for ${tile.label ?? tile.name}`}
192
+ onClick={(event) => {
193
+ event.stopPropagation();
194
+ onOpenMenu(event.currentTarget);
195
+ }}
196
+ sx={{
197
+ position: "absolute",
198
+ top: "2px",
199
+ right: "2px",
200
+ width: 22,
201
+ height: 22,
202
+ zIndex: 2,
203
+ color: theme.tileTitle,
204
+ bgcolor: theme.tile,
205
+ opacity: selected || menuOpen ? 0.9 : 0,
206
+ transition: "opacity 120ms",
207
+ "&:hover": {
208
+ opacity: 1,
209
+ bgcolor: theme.tile,
210
+ },
211
+ }}
212
+ >
213
+ <MoreVertIcon sx={{ fontSize: 16 }} />
214
+ </IconButton>
215
+ )}
216
+
217
+ {/* A tile's width and share of the dashboard,
218
+ reported while you drag it, as the best builders do.
219
+ Height is not ours to show, but the span and
220
+ its share are exactly what a flow grid leaves
221
+ you guessing at. */}
222
+ {resizeSpan !== undefined && (
223
+ <Box
224
+ aria-hidden
225
+ sx={{
226
+ position: "absolute",
227
+ top: "6px",
228
+ right: "6px",
229
+ px: 0.75,
230
+ py: 0.25,
231
+ borderRadius: "4px",
232
+ bgcolor: theme.drillLink,
233
+ color: theme.tile,
234
+ fontSize: 11,
235
+ fontVariantNumeric: "tabular-nums",
236
+ zIndex: 4,
237
+ pointerEvents: "none",
238
+ }}
239
+ >
240
+ {resizeSpan} of {columns} ·{" "}
241
+ {Math.round((resizeSpan / columns) * 100)}%
242
+ </Box>
243
+ )}
244
+
245
+ {/* The right edge, draggable — but only on a
246
+ tile whose tags this file owns. An inherited
247
+ tile's tags live on the model's view, which
248
+ the builder does not write, so a drag here
249
+ could not be saved. Its own pointer handling
250
+ stops the press reaching the sortable, and
251
+ the sensor refuses a separator regardless. */}
252
+ {tile.declaration.kind !== "inherited" && (
253
+ <Box
254
+ className="builder-affordance"
255
+ role="separator"
256
+ aria-orientation="vertical"
257
+ aria-label={`Resize ${tile.label ?? tile.name}`}
258
+ onPointerDown={onResizeStart}
259
+ onPointerMove={onResizeMove}
260
+ onPointerUp={onResizeEnd}
261
+ onPointerCancel={onResizeEnd}
262
+ sx={{
263
+ position: "absolute",
264
+ top: 0,
265
+ bottom: 0,
266
+ // Straddles the edge, so the target
267
+ // is a usable width without eating
268
+ // into the tile's content.
269
+ right: "-5px",
270
+ width: "10px",
271
+ cursor: "col-resize",
272
+ touchAction: "none",
273
+ zIndex: 1,
274
+ // Invisible until wanted: a rule down
275
+ // every tile edge would read as a
276
+ // table, and the tile already draws
277
+ // an edge of its own.
278
+ opacity: resizeSpan !== undefined || selected ? 1 : 0,
279
+ transition: "opacity 120ms",
280
+ "&:hover": { opacity: 1 },
281
+ "&::after": {
282
+ content: '""',
283
+ position: "absolute",
284
+ top: "50%",
285
+ left: "50%",
286
+ transform: "translate(-50%, -50%)",
287
+ width: "4px",
288
+ height: "28px",
289
+ borderRadius: "2px",
290
+ bgcolor: theme.drillLink,
291
+ },
292
+ }}
293
+ />
294
+ )}
295
+ </Box>
296
+ )}
297
+ </TileSortable>
298
+ );
299
+ }
300
+
301
+ /**
302
+ * No host-supplied tile: say what this one will run, so the surface is still
303
+ * legible without a server.
304
+ */
305
+ export function TilePlaceholder({ tile }: { tile: DashboardTile }) {
306
+ const { theme } = usePublisherTheme();
307
+ return (
308
+ <TileCard sx={{ minHeight: 140 }}>
309
+ <TileHeading
310
+ title={tile.label ?? tile.name}
311
+ subtitle={tile.subtitle}
312
+ />
313
+ <Typography
314
+ variant="caption"
315
+ sx={{ display: "block", color: theme.tileTitle, opacity: 0.7 }}
316
+ >
317
+ {tile.source} → {tile.name}
318
+ </Typography>
319
+ </TileCard>
320
+ );
321
+ }
322
+
323
+ /** The empty end of a row, made a drop target while a drag is live. */
324
+ export function GapTarget({ after }: { after: string }) {
325
+ const { theme } = usePublisherTheme();
326
+ return (
327
+ <GapDroppable id={gapId(after)} after={after}>
328
+ {({ ref, isDropTarget }) => (
329
+ <Box
330
+ ref={ref}
331
+ aria-hidden
332
+ sx={{
333
+ minHeight: 48,
334
+ borderRadius: 1,
335
+ border: `1px dashed ${theme.drillLink}`,
336
+ bgcolor: isDropTarget ? theme.tile : "transparent",
337
+ opacity: isDropTarget ? 0.95 : 0.4,
338
+ transition: "opacity 120ms, background-color 120ms",
339
+ }}
340
+ />
341
+ )}
342
+ </GapDroppable>
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Column guides, drawn only during a gesture: a flow grid is invisible until
348
+ * you are trying to land on it.
349
+ */
350
+ export function GridGuides({ columns }: { columns: number }) {
351
+ const { theme } = usePublisherTheme();
352
+ return (
353
+ <Box
354
+ aria-hidden
355
+ sx={{
356
+ position: "absolute",
357
+ inset: 0,
358
+ pointerEvents: "none",
359
+ zIndex: 3,
360
+ display: "grid",
361
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
362
+ gap: `${GRID_GAP_PX}px`,
363
+ }}
364
+ >
365
+ {Array.from({ length: columns }, (_, column) => (
366
+ <Box
367
+ key={column}
368
+ sx={{
369
+ borderLeft: `1px dashed ${theme.drillLink}`,
370
+ borderRight:
371
+ column === columns - 1
372
+ ? `1px dashed ${theme.drillLink}`
373
+ : "none",
374
+ opacity: 0.35,
375
+ }}
376
+ />
377
+ ))}
378
+ </Box>
379
+ );
380
+ }