@malloy-publisher/sdk 0.0.46 → 0.0.49

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.0.46",
4
+ "version": "0.0.49",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -0,0 +1,185 @@
1
+ import { Add, Launch } from "@mui/icons-material";
2
+ import {
3
+ Button,
4
+ Menu,
5
+ MenuItem,
6
+ ListItemIcon,
7
+ ListItemText,
8
+ Typography,
9
+ Dialog,
10
+ DialogTitle,
11
+ DialogContent,
12
+ FormControl,
13
+ TextField,
14
+ } from "@mui/material";
15
+ import {
16
+ NotebookStorageProvider,
17
+ BrowserNotebookStorage,
18
+ MutableNotebookList,
19
+ } from "./MutableNotebook";
20
+ import React from "react";
21
+ import { useRouterClickHandler } from "./click_helper";
22
+
23
+ export interface AnalyzePackageButtonProps {
24
+ projectName: string;
25
+ packageName: string;
26
+ }
27
+
28
+ export function AnalyzePackageButton({
29
+ projectName,
30
+ packageName,
31
+ }: AnalyzePackageButtonProps) {
32
+ const [workbookName, setWorkbookName] = React.useState("");
33
+ const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
34
+ const [newDialogOpen, setNewDialogOpen] = React.useState(false);
35
+ const [openDialogOpen, setOpenDialogOpen] = React.useState(false);
36
+ const navigate = useRouterClickHandler();
37
+
38
+ const open = Boolean(anchorEl);
39
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
40
+ setAnchorEl(event.currentTarget);
41
+ };
42
+ const handleMenuClose = () => {
43
+ setAnchorEl(null);
44
+ };
45
+ const handleOpenDialogClose = () => {
46
+ setOpenDialogOpen(false);
47
+ };
48
+ const handleNewDialogClose = () => {
49
+ setNewDialogOpen(false);
50
+ };
51
+
52
+ const handleNotebookClick = (notebook: string, event: React.MouseEvent) => {
53
+ setOpenDialogOpen(false);
54
+ // Navigate to the ScratchNotebookPage with anchor text for notebookPath
55
+ navigate(
56
+ `/${projectName}/${packageName}/scratchNotebook/${encodeURIComponent(notebook)}`,
57
+ event,
58
+ );
59
+ };
60
+
61
+ const createNotebookClick = (event?: React.MouseEvent) => {
62
+ setNewDialogOpen(false);
63
+ // Navigate to the ScratchNotebookPage with anchor text for notebookPath
64
+ navigate(
65
+ `/${projectName}/${packageName}/scratchNotebook/${encodeURIComponent(workbookName)}`,
66
+ event,
67
+ );
68
+ setWorkbookName("");
69
+ };
70
+
71
+ return (
72
+ <>
73
+ <Button
74
+ aria-controls={open ? "basic-menu" : undefined}
75
+ aria-haspopup="true"
76
+ aria-expanded={open ? "true" : undefined}
77
+ onClick={handleClick}
78
+ sx={{ height: "40px" }}
79
+ >
80
+ Analyze Package
81
+ </Button>
82
+ <Menu
83
+ id="basic-menu"
84
+ anchorEl={anchorEl}
85
+ open={open}
86
+ onClose={handleMenuClose}
87
+ slotProps={{
88
+ list: {
89
+ "aria-labelledby": "basic-button",
90
+ },
91
+ }}
92
+ >
93
+ <MenuItem
94
+ onClick={() => {
95
+ setNewDialogOpen(true);
96
+ handleMenuClose();
97
+ }}
98
+ >
99
+ <ListItemIcon>
100
+ <Add fontSize="small" />
101
+ </ListItemIcon>
102
+ <ListItemText>
103
+ <Typography variant="body2">New Workbook</Typography>
104
+ </ListItemText>
105
+ </MenuItem>
106
+ <MenuItem
107
+ onClick={() => {
108
+ setOpenDialogOpen(true);
109
+ handleMenuClose();
110
+ }}
111
+ >
112
+ <ListItemIcon>
113
+ <Launch fontSize="small" />
114
+ </ListItemIcon>
115
+ <ListItemText>
116
+ <Typography variant="body2">Open Workbook</Typography>
117
+ </ListItemText>
118
+ </MenuItem>
119
+ </Menu>
120
+ <Dialog
121
+ open={newDialogOpen}
122
+ onClose={handleNewDialogClose}
123
+ sx={{
124
+ "& .MuiDialog-paper": {
125
+ width: "100%",
126
+ maxWidth: "300px",
127
+ },
128
+ }}
129
+ >
130
+ <DialogTitle variant="subtitle1" sx={{ fontWeight: "medium" }}>
131
+ Create Workbook
132
+ </DialogTitle>
133
+ <DialogContent>
134
+ <FormControl
135
+ sx={{
136
+ width: "100%",
137
+ display: "flex",
138
+ alignItems: "center",
139
+ gap: 2,
140
+ }}
141
+ >
142
+ <TextField
143
+ label="Workbook Name"
144
+ value={workbookName}
145
+ onChange={(e) => setWorkbookName(e.target.value)}
146
+ sx={{
147
+ width: "100%",
148
+ maxWidth: "400px",
149
+ mt: 1,
150
+ }}
151
+ />
152
+ <Button onClick={(event) => createNotebookClick(event)}>
153
+ Create
154
+ </Button>
155
+ </FormControl>
156
+ </DialogContent>
157
+ </Dialog>
158
+ <Dialog
159
+ open={openDialogOpen}
160
+ onClose={handleOpenDialogClose}
161
+ sx={{
162
+ "& .MuiDialog-paper": {
163
+ width: "100%",
164
+ maxWidth: "300px",
165
+ },
166
+ }}
167
+ >
168
+ <DialogTitle variant="subtitle1" sx={{ fontWeight: "medium" }}>
169
+ Open Workbook
170
+ </DialogTitle>
171
+ <DialogContent>
172
+ <NotebookStorageProvider
173
+ notebookStorage={new BrowserNotebookStorage()}
174
+ userContext={{
175
+ project: projectName,
176
+ package: packageName,
177
+ }}
178
+ >
179
+ <MutableNotebookList onNotebookClick={handleNotebookClick} />
180
+ </NotebookStorageProvider>
181
+ </DialogContent>
182
+ </Dialog>
183
+ </>
184
+ );
185
+ }
@@ -0,0 +1,69 @@
1
+ import { Box, Divider, List, ListItem, ListItemText } from "@mui/material";
2
+ import React from "react";
3
+ import { useNotebookStorage } from "./NotebookStorageProvider";
4
+
5
+ interface MutableNotebookListProps {
6
+ onNotebookClick: (notebook: string, event: React.MouseEvent) => void;
7
+ }
8
+
9
+ export function MutableNotebookList({
10
+ onNotebookClick,
11
+ }: MutableNotebookListProps) {
12
+ const { notebookStorage, userContext } = useNotebookStorage();
13
+ const [notebooks, setNotebooks] = React.useState<string[]>([]);
14
+
15
+ React.useEffect(() => {
16
+ if (notebookStorage && userContext) {
17
+ setNotebooks(notebookStorage.listNotebooks(userContext));
18
+ }
19
+ }, [notebookStorage, userContext]);
20
+
21
+ return (
22
+ <>
23
+ <Divider />
24
+ <Box
25
+ sx={{
26
+ maxHeight: "300px",
27
+ overflow: "auto",
28
+ "&::-webkit-scrollbar": {
29
+ width: "8px",
30
+ },
31
+ "&::-webkit-scrollbar-track": {
32
+ background: "transparent",
33
+ },
34
+ "&::-webkit-scrollbar-thumb": {
35
+ background: "rgba(0,0,0,0.2)",
36
+ borderRadius: "4px",
37
+ },
38
+ }}
39
+ >
40
+ <List dense>
41
+ {notebooks.length === 0 && (
42
+ <ListItem>
43
+ <ListItemText
44
+ primary="No notebooks found."
45
+ sx={{ textAlign: "center" }}
46
+ />
47
+ </ListItem>
48
+ )}
49
+ {notebooks.map((notebook) => (
50
+ <ListItem
51
+ key={notebook}
52
+ onClick={(event: React.MouseEvent) =>
53
+ onNotebookClick(notebook, event)
54
+ }
55
+ sx={{
56
+ cursor: "pointer",
57
+ "&:hover": {
58
+ backgroundColor: "action.hover",
59
+ },
60
+ }}
61
+ >
62
+ <ListItemText primary={notebook} />
63
+ </ListItem>
64
+ ))}
65
+ </List>
66
+ </Box>
67
+ </>
68
+ );
69
+ }
@@ -1,8 +1,8 @@
1
1
  export { BrowserNotebookStorage } from "./BrowserNotebookStorage";
2
2
  export { default as MutableNotebook } from "./MutableNotebook";
3
3
  export type { NotebookStorage, UserContext } from "./NotebookStorage";
4
+ export { MutableNotebookList } from "./MutableNotebookList";
4
5
  export {
5
- default as NotebookStorageProvider,
6
- useNotebookStorage
6
+ default as NotebookStorageProvider,
7
+ useNotebookStorage,
7
8
  } from "./NotebookStorageProvider";
8
-
@@ -9,3 +9,4 @@ export * from "./Loading";
9
9
  export { useRouterClickHandler } from "./click_helper";
10
10
  export { ServerProvider, useServer } from "./ServerProvider";
11
11
  export type { ServerContextValue, ServerProviderProps } from "./ServerProvider";
12
+ export { AnalyzePackageButton } from "./AnalyzePackageButton";
package/vite.config.ts CHANGED
@@ -7,7 +7,9 @@ import { peerDependencies } from "./package.json";
7
7
  export default ({ mode }) => {
8
8
  return defineConfig({
9
9
  define: {
10
- "process.env": JSON.stringify(mode),
10
+ "process.env.NODE_ENV": JSON.stringify(mode),
11
+ "process.env.NODE_DEBUG": mode === "development",
12
+ "process.env.VSCODE_TEXTMATE_DEBUG": false,
11
13
  },
12
14
  build: {
13
15
  minify: mode === "production",