@malloy-publisher/sdk 0.2.6 → 0.3.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.
Files changed (100) hide show
  1. package/README.md +172 -204
  2. package/dist/ServerProvider-CGnLjzag.cjs.js +1 -0
  3. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-DSK9rfSY.es.js} +245 -245
  4. package/dist/client/api.d.ts +13 -1
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +1 -1
  7. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  8. package/dist/components/Dashboard/Dashboard.d.ts +4 -2
  9. package/dist/components/Dashboard/promoteMeasureRow.d.ts +36 -0
  10. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  11. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  12. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +18 -0
  13. package/dist/components/DocumentStorage/index.d.ts +3 -0
  14. package/dist/components/Model/index.d.ts +0 -1
  15. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  16. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  17. package/dist/components/RenderedResult/index.d.ts +1 -0
  18. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  19. package/dist/components/drill/index.d.ts +1 -0
  20. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  21. package/dist/components/given/filterValue.d.ts +63 -0
  22. package/dist/components/given/index.d.ts +1 -0
  23. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  24. package/dist/components/index.d.ts +2 -3
  25. package/dist/components/styles.d.ts +3 -3
  26. package/dist/core-8NVBCLZh.cjs.js +148 -0
  27. package/dist/{core-xdZbLgaF.es.js → core-B8oMW4sm.es.js} +3540 -2335
  28. package/dist/hooks/index.d.ts +1 -1
  29. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  30. package/dist/index.cjs.js +281 -1
  31. package/dist/index.es.js +45803 -79
  32. package/dist/sdk.css +1 -1
  33. package/dist/styles.css +0 -1
  34. package/package.json +2 -6
  35. package/src/components/ApiErrorDisplay.tsx +1 -1
  36. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  37. package/src/components/Dashboard/Dashboard.tsx +60 -95
  38. package/src/components/Dashboard/DashboardTile.tsx +25 -2
  39. package/src/components/Dashboard/promoteMeasureRow.spec.ts +137 -0
  40. package/src/components/Dashboard/promoteMeasureRow.ts +129 -0
  41. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  42. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  43. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  44. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +46 -0
  45. package/src/components/DocumentStorage/index.ts +15 -0
  46. package/src/components/Environment/Connections.tsx +15 -15
  47. package/src/components/Model/ModelCell.tsx +2 -1
  48. package/src/components/Model/index.ts +0 -1
  49. package/src/components/Notebook/Notebook.tsx +10 -76
  50. package/src/components/Notebook/NotebookCell.tsx +2 -8
  51. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  52. package/src/components/RenderedResult/ResultContainer.tsx +21 -24
  53. package/src/components/RenderedResult/index.ts +15 -0
  54. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  55. package/src/components/RenderedResult/resultSizing.ts +308 -0
  56. package/src/components/ResultsDialog.tsx +2 -1
  57. package/src/components/drill/index.ts +5 -0
  58. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  59. package/src/components/drill/useDrillSelf.ts +110 -0
  60. package/src/components/given/GivenInput.spec.tsx +196 -2
  61. package/src/components/given/GivenInput.tsx +300 -25
  62. package/src/components/given/filterValue.spec.ts +112 -0
  63. package/src/components/given/filterValue.ts +188 -0
  64. package/src/components/given/index.ts +4 -0
  65. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  66. package/src/components/given/useGivenUrlParams.ts +87 -0
  67. package/src/components/index.ts +5 -3
  68. package/src/hooks/index.ts +0 -1
  69. package/src/hooks/useGivensState.spec.ts +158 -0
  70. package/src/hooks/useGivensState.ts +114 -23
  71. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  72. package/src/hooks/useSuggestOptions.ts +94 -51
  73. package/vite.config.ts +0 -1
  74. package/dist/ServerProvider-xXW1HJOJ.cjs.js +0 -1
  75. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  76. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  77. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  78. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  79. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  80. package/dist/components/Workbook/Workbook.d.ts +0 -7
  81. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  82. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  83. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  84. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  85. package/dist/components/Workbook/index.d.ts +0 -7
  86. package/dist/core-RvrkY1Ss.cjs.js +0 -148
  87. package/dist/index-B3scIDRd.cjs.js +0 -356
  88. package/dist/index-Bda7HuZc.es.js +0 -66409
  89. package/dist/markdown-editor.css +0 -341
  90. package/src/components/AnalyzePackageButton.tsx +0 -319
  91. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  92. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  93. package/src/components/Workbook/ModelPicker.tsx +0 -134
  94. package/src/components/Workbook/MutableCell.tsx +0 -458
  95. package/src/components/Workbook/Workbook.tsx +0 -501
  96. package/src/components/Workbook/WorkbookList.tsx +0 -110
  97. package/src/components/Workbook/WorkbookManager.ts +0 -214
  98. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  99. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  100. package/src/components/Workbook/index.ts +0 -10
@@ -1,64 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import type {
5
- WorkbookLocator,
6
- WorkbookStorage,
7
- Workspace,
8
- } from "./WorkbookStorage";
9
-
10
- const LOCAL_WORKSPACE_NAME = "Local";
11
-
12
- export class BrowserWorkbookStorage implements WorkbookStorage {
13
- async listWorkspaces(writeableOnly: boolean): Promise<Workspace[]> {
14
- // Parameters not used in browser storage implementation
15
- void writeableOnly;
16
- return Promise.resolve([
17
- {
18
- name: LOCAL_WORKSPACE_NAME,
19
- description: "Stored locally- only accessible to this browser",
20
- writeable: true,
21
- },
22
- ]);
23
- }
24
-
25
- async listWorkbooks(_workspace: Workspace): Promise<WorkbookLocator[]> {
26
- const keys: WorkbookLocator[] = [];
27
- for (let i = 0; i < localStorage.length; i++) {
28
- const key = localStorage.key(i);
29
- keys.push({ path: key, workspace: LOCAL_WORKSPACE_NAME });
30
- }
31
- return keys;
32
- }
33
-
34
- async getWorkbook(path: WorkbookLocator): Promise<string> {
35
- const notebook = localStorage.getItem(path.path);
36
- if (notebook === null) {
37
- throw new Error(`Notebook not found at path: ${path}`);
38
- }
39
- return notebook;
40
- }
41
-
42
- async deleteWorkbook(path: WorkbookLocator): Promise<void> {
43
- if (localStorage.getItem(path.path) === null) {
44
- throw new Error(`Notebook not found at path: ${path}`);
45
- }
46
- localStorage.removeItem(path.path);
47
- }
48
-
49
- async saveWorkbook(path: WorkbookLocator, notebook: string): Promise<void> {
50
- localStorage.setItem(path.path, notebook);
51
- }
52
-
53
- async moveWorkbook(
54
- from: WorkbookLocator,
55
- to: WorkbookLocator,
56
- ): Promise<void> {
57
- const notebook = localStorage.getItem(from.path);
58
- if (notebook === null) {
59
- throw new Error(`Notebook not found at path: ${from.path}`);
60
- }
61
- localStorage.setItem(to.path, notebook);
62
- localStorage.removeItem(from.path);
63
- }
64
- }
@@ -1,49 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import {
5
- SourceAndPath,
6
- QueryExplorerResult,
7
- SourcesExplorer,
8
- } from "../Model/SourcesExplorer";
9
- import { WorkbookCellValue } from "./WorkbookManager";
10
-
11
- interface EditableMalloyCellProps {
12
- cell: WorkbookCellValue;
13
- sourceAndPaths: SourceAndPath[];
14
- resourceUri: string;
15
- onQueryChange: (query: QueryExplorerResult) => void;
16
- onSourceChange?: (index: number) => void;
17
- }
18
-
19
- export function EditableMalloyCell({
20
- cell,
21
- sourceAndPaths,
22
- resourceUri,
23
- onQueryChange,
24
- onSourceChange,
25
- }: EditableMalloyCellProps) {
26
- const query = {
27
- query: cell.value,
28
- malloyResult: cell.result ? JSON.parse(cell.result) : undefined,
29
- malloyQuery: cell.queryInfo ? JSON.parse(cell.queryInfo) : undefined,
30
- };
31
-
32
- // Find the selected source index based on the cell's source name
33
- const selectedSourceIndex = sourceAndPaths.findIndex(
34
- (sourceAndPath) => sourceAndPath.sourceInfo.name === cell.sourceName,
35
- );
36
-
37
- return (
38
- <SourcesExplorer
39
- resourceUri={resourceUri}
40
- sourceAndPaths={sourceAndPaths}
41
- selectedSourceIndex={
42
- selectedSourceIndex >= 0 ? selectedSourceIndex : 0
43
- }
44
- existingQuery={query}
45
- onQueryChange={onQueryChange}
46
- onSourceChange={onSourceChange}
47
- />
48
- );
49
- }
@@ -1,134 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import CloseIcon from "@mui/icons-material/Close";
5
- import FileUploadOutlinedIcon from "@mui/icons-material/FileUploadOutlined";
6
- import {
7
- Button,
8
- Chip,
9
- Divider,
10
- FormControl,
11
- Menu,
12
- MenuItem,
13
- Stack,
14
- Typography,
15
- } from "@mui/material";
16
- import React from "react";
17
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
18
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
19
- import { parseResourceUri } from "../../utils/formatting";
20
- import { useServer } from "../ServerProvider";
21
-
22
- interface ModelPickerProps {
23
- initialSelectedModels: string[];
24
- onModelChange: (models: string[]) => void;
25
- resourceUri: string;
26
- }
27
-
28
- /**
29
- * Picks Models that are available in the package.
30
- * Only "malloy" model files are shown.
31
- */
32
- export function ModelPicker({
33
- initialSelectedModels,
34
- onModelChange,
35
- resourceUri,
36
- }: ModelPickerProps) {
37
- const {
38
- environmentName: environmentName,
39
- packageName: packageName,
40
- versionId: versionId,
41
- } = parseResourceUri(resourceUri);
42
- const { apiClients } = useServer();
43
-
44
- const { data, isLoading, isSuccess, isError, error } = useQueryWithApiError({
45
- queryKey: ["models", environmentName, packageName, versionId],
46
- queryFn: () =>
47
- apiClients.models.listModels(environmentName, packageName, versionId),
48
- });
49
- const [selectedModels, setSelectedModels] = React.useState<string[]>(
50
- initialSelectedModels || [],
51
- );
52
- const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
53
-
54
- React.useEffect(() => {
55
- setSelectedModels(initialSelectedModels || []);
56
- }, [initialSelectedModels]);
57
-
58
- const handleRemove = (model: string) => {
59
- const newModels = selectedModels.filter((m) => m !== model);
60
- setSelectedModels(newModels);
61
- onModelChange(newModels);
62
- };
63
-
64
- const handleAdd = (model: string) => {
65
- const newModels = [...selectedModels, model];
66
- setSelectedModels(newModels);
67
- onModelChange(newModels);
68
- setAnchorEl(null);
69
- };
70
-
71
- let availableModels: string[] = [];
72
- if (isSuccess && data?.data) {
73
- availableModels = data.data
74
- .filter((model) => !selectedModels.includes(model.path))
75
- .map((model) => model.path);
76
- }
77
-
78
- if (isError) {
79
- return (
80
- <ApiErrorDisplay
81
- error={error}
82
- context={`${environmentName} > ${packageName} > Model Picker`}
83
- />
84
- );
85
- }
86
-
87
- return (
88
- <>
89
- <FormControl fullWidth>
90
- {isLoading && <Typography>Loading...</Typography>}
91
- <Stack direction="row" spacing={1}>
92
- {selectedModels.map((model) => (
93
- <Chip
94
- key={model}
95
- label={model}
96
- onDelete={() => handleRemove(model)}
97
- deleteIcon={<CloseIcon />}
98
- sx={{ marginBottom: "5px" }}
99
- />
100
- ))}
101
- <Button
102
- size="small"
103
- startIcon={<FileUploadOutlinedIcon />}
104
- onClick={(e) => setAnchorEl(e.currentTarget)}
105
- disabled={
106
- isLoading || isError || availableModels.length === 0
107
- }
108
- >
109
- Add Model
110
- </Button>
111
- </Stack>
112
- </FormControl>
113
- <Menu
114
- anchorEl={anchorEl}
115
- open={Boolean(anchorEl)}
116
- onClose={() => setAnchorEl(null)}
117
- >
118
- <Typography variant="subtitle2" sx={{ ml: 1 }}>
119
- Models
120
- </Typography>
121
- <Divider />
122
- {availableModels.length === 0 ? (
123
- <MenuItem disabled>No models available</MenuItem>
124
- ) : (
125
- availableModels.map((model) => (
126
- <MenuItem key={model} onClick={() => handleAdd(model)}>
127
- <Typography variant="body2">{model}</Typography>
128
- </MenuItem>
129
- ))
130
- )}
131
- </Menu>
132
- </>
133
- );
134
- }
@@ -1,458 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import CheckIcon from "@mui/icons-material/Check";
5
- import CodeIcon from "@mui/icons-material/Code";
6
- import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
7
- import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
8
- import {
9
- Box,
10
- Button,
11
- Collapse,
12
- Dialog,
13
- DialogActions,
14
- DialogContent,
15
- DialogTitle,
16
- IconButton,
17
- Stack,
18
- Tooltip,
19
- Typography,
20
- } from "@mui/material";
21
- import MDEditor from "@uiw/react-md-editor/nohighlight";
22
- import Markdown from "markdown-to-jsx";
23
- import React, { useEffect, useState } from "react";
24
- import { usePublisherTheme } from "../../theme/ThemeContext";
25
- import { highlight } from "../highlighter";
26
- import {
27
- emptyQueryExplorerResult,
28
- QueryExplorerResult,
29
- SourceAndPath,
30
- } from "../Model/SourcesExplorer";
31
- import ResultContainer from "../RenderedResult/ResultContainer";
32
- import { StyledCard } from "../styles";
33
- import { EditableMalloyCell } from "./EditableMalloyCell";
34
- import { WorkbookCellValue } from "./WorkbookManager";
35
-
36
- interface NotebookCellProps {
37
- cell: WorkbookCellValue;
38
- editingMalloy?: boolean;
39
- editingMarkdown?: boolean;
40
- sourceAndPaths: SourceAndPath[];
41
- resourceUri: string;
42
- onCellChange: (cell: WorkbookCellValue) => void;
43
- onClose: () => void;
44
- onEdit: () => void;
45
- onDelete: () => void;
46
- addButtonCallback: (isMarkdown: boolean) => React.ReactNode;
47
- }
48
-
49
- export function MutableCell({
50
- cell,
51
- editingMalloy,
52
- editingMarkdown,
53
- sourceAndPaths,
54
- resourceUri,
55
- onCellChange,
56
- onClose,
57
- onEdit,
58
- onDelete,
59
- addButtonCallback,
60
- }: NotebookCellProps) {
61
- const [value, setValue] = useState(cell.value);
62
- const [codeExpanded, setCodeExpanded] = React.useState<boolean>(false);
63
- const [embeddingExpanded, setEmbeddingExpanded] =
64
- React.useState<boolean>(false);
65
- const [highlightedMalloyCode, setHighlightedMalloyCode] =
66
- React.useState<string>();
67
- const [highlightedEmbedCode] = React.useState<string>();
68
- const [query, setQuery] = React.useState<QueryExplorerResult>(
69
- emptyQueryExplorerResult(),
70
- );
71
- const [isHovered, setIsHovered] = React.useState<boolean>(false);
72
- const [selectedSourceIndex, setSelectedSourceIndex] = React.useState<number>(
73
- cell.sourceName
74
- ? sourceAndPaths.findIndex(
75
- (entry) => entry.sourceInfo.name === cell.sourceName,
76
- )
77
- : 0,
78
- );
79
-
80
- const { mode } = usePublisherTheme();
81
- useEffect(() => {
82
- if (!cell.isMarkdown)
83
- highlight(cell.value, "malloy", mode).then((code) => {
84
- setHighlightedMalloyCode(code);
85
- });
86
- }, [cell, mode]);
87
- React.useEffect(() => {
88
- document.documentElement.setAttribute("data-color-mode", "light");
89
- });
90
- const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
91
-
92
- const handleDeleteConfirm = () => {
93
- onDelete();
94
- setDeleteDialogOpen(false);
95
- };
96
- const noSources = sourceAndPaths.length === 0;
97
-
98
- const saveResult = React.useCallback(() => {
99
- // Get the current modelPath and sourceName from the selected source
100
- const currentSource = sourceAndPaths[selectedSourceIndex];
101
- const modelPath = currentSource?.modelPath || cell.modelPath || "";
102
- const sourceName =
103
- currentSource?.sourceInfo.name || cell.sourceName || "";
104
-
105
- // Convert the results of the Query Explorer into
106
- // the stringified JSON objects that are stored in the cell.
107
- onCellChange({
108
- ...cell,
109
- value: cell.isMarkdown ? value : query.query,
110
- result: query.malloyResult
111
- ? JSON.stringify(query.malloyResult)
112
- : undefined,
113
- queryInfo: query.malloyQuery
114
- ? JSON.stringify(query.malloyQuery)
115
- : undefined,
116
- sourceName,
117
- modelPath,
118
- });
119
- }, [cell, value, query, onCellChange, selectedSourceIndex, sourceAndPaths]);
120
-
121
- const deleteButton = (
122
- <Tooltip title="Delete Cell">
123
- <IconButton size="small" onClick={() => setDeleteDialogOpen(true)}>
124
- <svg
125
- width="20"
126
- height="20"
127
- viewBox="0 0 24 24"
128
- fill="none"
129
- xmlns="http://www.w3.org/2000/svg"
130
- >
131
- <path
132
- d="M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m2 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6h14zM10 11v6M14 11v6"
133
- stroke="currentColor"
134
- strokeWidth="2"
135
- strokeLinecap="round"
136
- strokeLinejoin="round"
137
- />
138
- </svg>
139
- </IconButton>
140
- </Tooltip>
141
- );
142
-
143
- const deleteDialog = (
144
- <Dialog
145
- open={deleteDialogOpen}
146
- onClose={() => setDeleteDialogOpen(false)}
147
- >
148
- <DialogTitle>Confirm Delete</DialogTitle>
149
- <DialogContent>
150
- <Typography>Are you sure you want to delete this cell?</Typography>
151
- </DialogContent>
152
- <DialogActions>
153
- <Button onClick={() => setDeleteDialogOpen(false)}>Cancel</Button>
154
- <Button onClick={handleDeleteConfirm} color="error">
155
- Delete
156
- </Button>
157
- </DialogActions>
158
- </Dialog>
159
- );
160
- const saveAndClose = () => {
161
- saveResult();
162
- onClose();
163
- };
164
- const buttons = cell.isMarkdown ? (
165
- <>
166
- {editingMarkdown ? (
167
- <Tooltip title="Save">
168
- <IconButton size="small" onClick={saveAndClose}>
169
- <CheckIcon />
170
- </IconButton>
171
- </Tooltip>
172
- ) : (
173
- <Tooltip title="Edit">
174
- <IconButton size="small" onClick={onEdit}>
175
- <EditOutlinedIcon />
176
- </IconButton>
177
- </Tooltip>
178
- )}
179
- {!editingMarkdown && deleteButton}
180
- </>
181
- ) : (
182
- <>
183
- {!editingMalloy && (
184
- <Tooltip title={codeExpanded ? "Hide Code" : "View Code"}>
185
- <IconButton
186
- size="small"
187
- onClick={() => {
188
- setCodeExpanded(!codeExpanded);
189
- }}
190
- >
191
- <CodeIcon />
192
- </IconButton>
193
- </Tooltip>
194
- )}
195
- {!editingMalloy && cell.result && (
196
- <Tooltip
197
- title={embeddingExpanded ? "Hide Embedding" : "View Embedding"}
198
- >
199
- <IconButton
200
- size="small"
201
- onClick={() => {
202
- setEmbeddingExpanded(!embeddingExpanded);
203
- }}
204
- >
205
- <LinkOutlinedIcon />
206
- </IconButton>
207
- </Tooltip>
208
- )}
209
- {editingMalloy && (
210
- <Tooltip title="Save">
211
- <IconButton size="small" onClick={saveAndClose}>
212
- <CheckIcon />
213
- </IconButton>
214
- </Tooltip>
215
- )}
216
- {!editingMalloy && (
217
- <Tooltip title="Edit">
218
- <IconButton size="small" onClick={onEdit}>
219
- <EditOutlinedIcon />
220
- </IconButton>
221
- </Tooltip>
222
- )}
223
- {!editingMalloy && deleteButton}
224
- </>
225
- );
226
-
227
- const isEditing = editingMalloy || editingMarkdown;
228
- const editingButtons = editingMarkdown ? (
229
- <Tooltip title="Save">
230
- <IconButton size="small" onClick={saveAndClose}>
231
- <CheckIcon />
232
- </IconButton>
233
- </Tooltip>
234
- ) : editingMalloy ? (
235
- <Tooltip title="Save">
236
- <IconButton size="small" onClick={saveAndClose}>
237
- <CheckIcon />
238
- </IconButton>
239
- </Tooltip>
240
- ) : null;
241
-
242
- const hoverButtonBox = isHovered && (
243
- <Box
244
- sx={{
245
- position: "absolute",
246
- top: "4px",
247
- right: "4px",
248
- // transform: "translateX(-50%)",
249
- display: "flex",
250
- gap: "8px",
251
- backgroundColor: "background.paper",
252
- border: "1px solid",
253
- borderColor: "divider",
254
- borderRadius: "8px",
255
- padding: "2px 4px",
256
- boxShadow: 1,
257
- zIndex: 10,
258
- }}
259
- >
260
- {(!isEditing && (
261
- <>
262
- {addButtonCallback(true)}
263
- {addButtonCallback(false)}
264
- {buttons}
265
- </>
266
- )) ||
267
- editingButtons}
268
- </Box>
269
- );
270
-
271
- return (
272
- <StyledCard
273
- sx={(theme) => ({
274
- position: "relative",
275
- marginTop: "5px",
276
- marginBottom: "5px",
277
- borderWidth: "1.5px",
278
- backgroundColor: theme.palette.background.paper,
279
- minHeight: "50px",
280
- })}
281
- onMouseEnter={() => setIsHovered(true)}
282
- onMouseLeave={() => {
283
- setIsHovered(false);
284
- }}
285
- >
286
- {hoverButtonBox}
287
- {cell.isMarkdown ? (
288
- <>
289
- {editingMarkdown ? (
290
- <MDEditor
291
- value={value}
292
- preview="edit"
293
- autoFocus
294
- onChange={(newValue) => {
295
- setValue(newValue);
296
- onCellChange({ ...cell, value: newValue });
297
- }}
298
- onBlur={() => {
299
- saveResult();
300
- if (!isHovered) {
301
- saveAndClose();
302
- }
303
- }}
304
- />
305
- ) : (
306
- <Box
307
- sx={{
308
- px: 0.5,
309
- pt: 0,
310
- mt: 0,
311
- "& h1, & h2, & h3, & h4, & h5, & h6": {
312
- mt: 0.5,
313
- mb: 0.5,
314
- },
315
- "& p": { mt: 0.5, mb: 0.5 },
316
- "& ul, & ol": { mt: 0.5, mb: 0.5 },
317
- "& li": { mt: 0, mb: 0 },
318
- "& pre, & code": { mt: 0.5, mb: 0.5 },
319
- "& blockquote": { mt: 0.5, mb: 0.5 },
320
- }}
321
- >
322
- {cell.value ? (
323
- <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
324
- <Markdown>{cell.value}</Markdown>
325
- </Box>
326
- ) : (
327
- <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
328
- <Typography
329
- sx={{
330
- p: 2,
331
- textAlign: "center",
332
- variant: "subtitle2",
333
- fontWeight: "medium",
334
- }}
335
- >
336
- Markdown is empty
337
- </Typography>
338
- <Typography
339
- sx={{
340
- mb: 2,
341
- textAlign: "center",
342
- variant: "body2",
343
- }}
344
- >
345
- Click to edit.
346
- </Typography>
347
- </Box>
348
- )}
349
- </Box>
350
- )}
351
- </>
352
- ) : (
353
- <>
354
- <Collapse in={embeddingExpanded} timeout="auto" unmountOnExit>
355
- <Stack
356
- sx={{
357
- p: "10px",
358
- borderRadius: 0,
359
- flexDirection: "row",
360
- justifyContent: "space-between",
361
- }}
362
- >
363
- <Typography
364
- component="div"
365
- sx={{
366
- fontSize: "12px",
367
- "& .line": { textWrap: "wrap" },
368
- }}
369
- dangerouslySetInnerHTML={{
370
- __html: highlightedEmbedCode,
371
- }}
372
- />
373
- </Stack>
374
- </Collapse>
375
- <Collapse in={codeExpanded} timeout="auto" unmountOnExit>
376
- <Stack
377
- sx={{
378
- p: "10px",
379
- borderRadius: 0,
380
- flexDirection: "row",
381
- justifyContent: "space-between",
382
- }}
383
- >
384
- <Typography
385
- component="div"
386
- className="content"
387
- sx={{
388
- fontSize: "12px",
389
- "& .line": { textWrap: "wrap" },
390
- }}
391
- dangerouslySetInnerHTML={{
392
- __html: highlightedMalloyCode,
393
- }}
394
- />
395
- </Stack>
396
- </Collapse>
397
- {editingMalloy &&
398
- (noSources ? (
399
- <>
400
- <Typography
401
- sx={{
402
- p: 2,
403
- textAlign: "center",
404
- variant: "subtitle2",
405
- fontWeight: "medium",
406
- }}
407
- >
408
- No Model Imports
409
- </Typography>
410
- <Typography
411
- sx={{ mb: 2, textAlign: "center", variant: "body2" }}
412
- >
413
- Please add a model import above.
414
- </Typography>
415
- </>
416
- ) : (
417
- <EditableMalloyCell
418
- sourceAndPaths={sourceAndPaths}
419
- resourceUri={resourceUri}
420
- onQueryChange={(query) => {
421
- setQuery(query);
422
- }}
423
- onSourceChange={(index) => {
424
- setSelectedSourceIndex(index);
425
- }}
426
- cell={cell}
427
- />
428
- ))}
429
- {!editingMalloy && cell.result && (
430
- <StyledCard variant="outlined" sx={{ borderRadius: 0 }}>
431
- <ResultContainer result={cell.result} maxHeight={800} />
432
- </StyledCard>
433
- )}
434
- {!editingMalloy && !cell.result && (
435
- <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
436
- <Typography
437
- sx={{
438
- p: 2,
439
- textAlign: "center",
440
- variant: "subtitle2",
441
- fontWeight: "medium",
442
- }}
443
- >
444
- Explore is empty
445
- </Typography>
446
- <Typography
447
- sx={{ mb: 2, textAlign: "center", variant: "body2" }}
448
- >
449
- Click to edit.
450
- </Typography>
451
- </Box>
452
- )}
453
- </>
454
- )}
455
- {deleteDialogOpen && deleteDialog}
456
- </StyledCard>
457
- );
458
- }