@malloy-publisher/sdk 0.3.0 → 0.4.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/README.md +22 -9
- package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
- package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
- package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9482 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/api.d.ts +100 -42
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +30 -0
- package/dist/components/BackLink.d.ts +32 -0
- package/dist/components/Dashboard/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +48 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/ItemRow.d.ts +38 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
- package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
- package/dist/components/Materializations/Materializations.d.ts +7 -3
- package/dist/components/Materializations/ScopeButton.d.ts +18 -0
- package/dist/components/Materializations/SectionLabel.d.ts +7 -4
- package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
- package/dist/components/Materializations/index.d.ts +0 -1
- package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
- package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
- package/dist/components/Package/index.d.ts +0 -1
- package/dist/components/PackageSection.d.ts +23 -0
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/buttons.d.ts +53 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +6 -0
- package/dist/components/styles.d.ts +49 -44
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +22 -273
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +16888 -44451
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- package/src/components/AppDialog.tsx +115 -0
- package/src/components/BackLink.tsx +83 -0
- package/src/components/Connections/AddConnectionDialog.tsx +50 -70
- package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
- package/src/components/Connections/EditConnectionDialog.tsx +54 -73
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- package/src/components/Dashboard/telemetry.ts +51 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +16 -62
- package/src/components/Environment/AddPackageDialog.tsx +85 -154
- package/src/components/Environment/Connections.tsx +125 -205
- package/src/components/Environment/DeletePackageDialog.tsx +32 -77
- package/src/components/Environment/EditPackageDialog.tsx +46 -58
- package/src/components/Environment/Environment.tsx +34 -36
- package/src/components/Environment/Packages.tsx +63 -128
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
- package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
- package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
- package/src/components/Home/Home.tsx +101 -214
- package/src/components/ItemRow.tsx +165 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
- package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
- package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
- package/src/components/Materializations/Materializations.tsx +137 -140
- package/src/components/Materializations/ScopeButton.tsx +85 -0
- package/src/components/Materializations/SectionLabel.tsx +7 -4
- package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
- package/src/components/Materializations/TriggerLabel.tsx +36 -0
- package/src/components/Materializations/cron.spec.ts +113 -0
- package/src/components/Materializations/index.ts +0 -1
- package/src/components/Materializations/utils.spec.ts +182 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
- package/src/components/Package/ContentTypeIcon.tsx +10 -12
- package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
- package/src/components/Package/NewDashboardDialog.tsx +265 -0
- package/src/components/Package/Package.tsx +179 -238
- package/src/components/Package/index.ts +0 -1
- package/src/components/PackageSection.tsx +85 -0
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- package/src/components/RenderedResult/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- package/src/components/ResultsDialog.tsx +8 -32
- package/src/components/buttons.tsx +114 -0
- package/src/components/designSystem.spec.tsx +316 -0
- package/src/components/drill/index.ts +1 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +16 -0
- package/src/components/styles.ts +49 -122
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/index.ts +9 -0
- package/src/telemetry/consoleEvents.spec.ts +130 -0
- package/src/telemetry/consoleEvents.ts +124 -0
- package/src/theme/defaults.ts +34 -23
- package/src/theme/resolveTheme.spec.ts +9 -4
- package/src/theme/resolveTheme.ts +12 -8
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
- package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
- package/dist/components/Materializations/TriggerChip.d.ts +0 -10
- package/dist/components/Package/Models.d.ts +0 -6
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
- package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
- package/src/components/Materializations/ScheduleCard.tsx +0 -231
- package/src/components/Materializations/TriggerChip.tsx +0 -44
- package/src/components/Package/Models.tsx +0 -71
|
@@ -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
|
+
}
|