@malloy-publisher/sdk 0.0.42 → 0.0.45

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/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-C7HUzsul.cjs");require("./vendor-hHfbZ4ZT.cjs");exports.BrowserNotebookStorage=e.BrowserNotebookStorage;exports.ConnectionExplorer=e.ConnectionExplorer;exports.Home=e.Home;exports.Loading=e.Loading;exports.Model=e.Model;exports.MutableNotebook=e.MutableNotebook;exports.Notebook=e.Notebook;exports.NotebookStorageProvider=e.NotebookStorageProvider;exports.Package=e.Package;exports.PackageProvider=e.PackageProvider;exports.Project=e.Project;exports.ProjectProvider=e.ProjectProvider;exports.PublisherPackageProvider=e.PackageProvider;exports.QueryResult=e.QueryResult;exports.SourceExplorerComponent=e.SourceExplorerComponent;exports.SourcesExplorer=e.SourcesExplorer;exports.useNotebookStorage=e.useNotebookStorage;exports.usePackage=e.usePackage;exports.useProject=e.useProject;exports.usePublisherPackage=e.usePackage;exports.useRouterClickHandler=e.useRouterClickHandler;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-nsXS-gBw.cjs");require("./vendor-hHfbZ4ZT.cjs");exports.BrowserNotebookStorage=e.BrowserNotebookStorage;exports.ConnectionExplorer=e.ConnectionExplorer;exports.Home=e.Home;exports.Loading=e.Loading;exports.Model=e.Model;exports.MutableNotebook=e.MutableNotebook;exports.Notebook=e.Notebook;exports.NotebookStorageProvider=e.NotebookStorageProvider;exports.Package=e.Package;exports.PackageProvider=e.PackageProvider;exports.Project=e.Project;exports.ProjectProvider=e.ProjectProvider;exports.PublisherPackageProvider=e.PackageProvider;exports.QueryResult=e.QueryResult;exports.SourceExplorerComponent=e.SourceExplorerComponent;exports.SourcesExplorer=e.SourcesExplorer;exports.useNotebookStorage=e.useNotebookStorage;exports.usePackage=e.usePackage;exports.useProject=e.useProject;exports.usePublisherPackage=e.usePackage;exports.useRouterClickHandler=e.useRouterClickHandler;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as r, C as s, H as t, L as P, M as u, b as c, N as k, c as g, P as i, e as l, g as b, h as d, e as n, Q as p, a as N, S, d as j, f as m, j as v, f as x, u as C } from "./index-wBKeSKqo.js";
1
+ import { B as r, C as s, H as t, L as P, M as u, b as c, N as k, c as g, P as i, e as l, g as b, h as d, e as n, Q as p, a as N, S, d as j, f as m, j as v, f as x, u as C } from "./index-ClVlSQMk.js";
2
2
  import "./vendor-BKsYdkmG.js";
3
3
  export {
4
4
  r as BrowserNotebookStorage,
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.42",
4
+ "version": "0.0.45",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -5,7 +5,6 @@ import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
5
5
  import {
6
6
  Box,
7
7
  Button,
8
- CardActions,
9
8
  Collapse,
10
9
  Dialog,
11
10
  DialogActions,
@@ -42,6 +41,7 @@ interface NotebookCellProps {
42
41
  onClose: () => void;
43
42
  onEdit: () => void;
44
43
  onDelete: () => void;
44
+ addButtonCallback: (isMarkdown: boolean) => React.ReactNode;
45
45
  }
46
46
 
47
47
  export function MutableCell({
@@ -56,6 +56,7 @@ export function MutableCell({
56
56
  onClose,
57
57
  onEdit,
58
58
  onDelete,
59
+ addButtonCallback,
59
60
  }: NotebookCellProps) {
60
61
  const [codeExpanded, setCodeExpanded] =
61
62
  React.useState<boolean>(expandCodeCell);
@@ -63,11 +64,11 @@ export function MutableCell({
63
64
  React.useState<boolean>(expandEmbedding);
64
65
  const [highlightedMalloyCode, setHighlightedMalloyCode] =
65
66
  React.useState<string>();
66
- const [highlightedEmbedCode, setHighlightedEmbedCode] =
67
- React.useState<string>();
67
+ const [highlightedEmbedCode] = React.useState<string>();
68
68
  const [query, setQuery] = React.useState<QueryExplorerResult>(
69
69
  emptyQueryExplorerResult(),
70
70
  );
71
+ const [isHovered, setIsHovered] = React.useState<boolean>(false);
71
72
 
72
73
  useEffect(() => {
73
74
  if (!cell.isMarkdown)
@@ -215,78 +216,136 @@ export function MutableCell({
215
216
  </>
216
217
  );
217
218
 
218
- const buttonStack = (
219
- <Stack
219
+ const isEditing = editingMalloy || editingMarkdown;
220
+
221
+ const editingButtons = editingMarkdown ? (
222
+ <Tooltip title="Save">
223
+ <IconButton size="small" onClick={onClose}>
224
+ <CheckIcon />
225
+ </IconButton>
226
+ </Tooltip>
227
+ ) : editingMalloy ? (
228
+ <Tooltip title="Save">
229
+ <IconButton
230
+ size="small"
231
+ onClick={() => {
232
+ saveResult(cell.modelPath, cell.sourceName);
233
+ onClose();
234
+ }}
235
+ >
236
+ <CheckIcon />
237
+ </IconButton>
238
+ </Tooltip>
239
+ ) : null;
240
+
241
+ const hoverButtonBox = isHovered && (
242
+ <Box
220
243
  sx={{
221
- flexDirection: "row",
222
- justifyContent: "right",
223
- mt: "20px",
224
- mb: "5px",
225
- mx: "5px",
244
+ position: "absolute",
245
+ top: "4px",
246
+ right: "4px",
247
+ // transform: "translateX(-50%)",
248
+ display: "flex",
249
+ gap: "8px",
250
+ backgroundColor: "background.paper",
251
+ border: "1px solid",
252
+ borderColor: "divider",
253
+ borderRadius: "8px",
254
+ padding: "2px 4px",
255
+ boxShadow: 1,
256
+ zIndex: 10,
226
257
  }}
227
258
  >
228
- <CardActions>{buttons}</CardActions>
229
- </Stack>
259
+ {(!isEditing && (
260
+ <>
261
+ {addButtonCallback(true)}
262
+ {addButtonCallback(false)}
263
+ {buttons}
264
+ </>
265
+ )) ||
266
+ editingButtons}
267
+ </Box>
230
268
  );
269
+
231
270
  return (
232
- <>
233
- {buttonStack}
271
+ <StyledCard
272
+ sx={{
273
+ position: "relative",
274
+ marginTop: "5px",
275
+ marginBottom: "5px",
276
+ borderWidth: "1.5px",
277
+ backgroundColor: "#fff",
278
+ minHeight: "50px",
279
+ }}
280
+ onMouseEnter={() => setIsHovered(true)}
281
+ onMouseLeave={() => {
282
+ setIsHovered(false);
283
+ }}
284
+ >
285
+ {hoverButtonBox}
234
286
  {cell.isMarkdown ? (
235
287
  <>
236
288
  {editingMarkdown ? (
237
289
  <MDEditor
238
290
  value={value}
239
291
  preview="edit"
292
+ autoFocus
240
293
  onChange={(newValue) => {
241
294
  setValue(newValue);
242
295
  updateMarkdown(newValue);
243
296
  }}
297
+ onBlur={() => {
298
+ saveResult(cell.modelPath, cell.sourceName);
299
+ if (!isHovered) {
300
+ onClose();
301
+ }
302
+ }}
244
303
  />
245
304
  ) : (
246
- <StyledCard variant="outlined" sx={{ borderRadius: 0 }}>
247
- <Box
248
- sx={{
249
- px: 0.5,
250
- pt: 0,
251
- mt: 0,
252
- "& h1, & h2, & h3, & h4, & h5, & h6": {
253
- mt: 0.5,
254
- mb: 0.5,
255
- },
256
- "& p": { mt: 0.5, mb: 0.5 },
257
- "& ul, & ol": { mt: 0.5, mb: 0.5 },
258
- "& li": { mt: 0, mb: 0 },
259
- "& pre, & code": { mt: 0.5, mb: 0.5 },
260
- "& blockquote": { mt: 0.5, mb: 0.5 },
261
- }}
262
- >
263
- {value ? (
305
+ <Box
306
+ sx={{
307
+ px: 0.5,
308
+ pt: 0,
309
+ mt: 0,
310
+ "& h1, & h2, & h3, & h4, & h5, & h6": {
311
+ mt: 0.5,
312
+ mb: 0.5,
313
+ },
314
+ "& p": { mt: 0.5, mb: 0.5 },
315
+ "& ul, & ol": { mt: 0.5, mb: 0.5 },
316
+ "& li": { mt: 0, mb: 0 },
317
+ "& pre, & code": { mt: 0.5, mb: 0.5 },
318
+ "& blockquote": { mt: 0.5, mb: 0.5 },
319
+ }}
320
+ >
321
+ {value ? (
322
+ <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
264
323
  <Markdown>{value}</Markdown>
265
- ) : (
266
- <>
267
- <Typography
268
- sx={{
269
- p: 2,
270
- textAlign: "center",
271
- variant: "subtitle2",
272
- fontWeight: "medium",
273
- }}
274
- >
275
- Markdown is empty
276
- </Typography>
277
- <Typography
278
- sx={{
279
- mb: 2,
280
- textAlign: "center",
281
- variant: "body2",
282
- }}
283
- >
284
- Click the edit button and add some markdown.
285
- </Typography>
286
- </>
287
- )}
288
- </Box>
289
- </StyledCard>
324
+ </Box>
325
+ ) : (
326
+ <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
327
+ <Typography
328
+ sx={{
329
+ p: 2,
330
+ textAlign: "center",
331
+ variant: "subtitle2",
332
+ fontWeight: "medium",
333
+ }}
334
+ >
335
+ Markdown is empty
336
+ </Typography>
337
+ <Typography
338
+ sx={{
339
+ mb: 2,
340
+ textAlign: "center",
341
+ variant: "body2",
342
+ }}
343
+ >
344
+ Click to edit.
345
+ </Typography>
346
+ </Box>
347
+ )}
348
+ </Box>
290
349
  )}
291
350
  </>
292
351
  ) : (
@@ -372,7 +431,7 @@ export function MutableCell({
372
431
  </StyledCard>
373
432
  )}
374
433
  {!editingMalloy && !cell.result && (
375
- <StyledCard variant="outlined" sx={{ borderRadius: 0 }}>
434
+ <Box onClick={onEdit} sx={{ cursor: "pointer" }}>
376
435
  <Typography
377
436
  sx={{
378
437
  p: 2,
@@ -386,15 +445,14 @@ export function MutableCell({
386
445
  <Typography
387
446
  sx={{ mb: 2, textAlign: "center", variant: "body2" }}
388
447
  >
389
- Click the edit button and explore the data in the model
390
- to see results.
448
+ Click to edit.
391
449
  </Typography>
392
- </StyledCard>
450
+ </Box>
393
451
  )}
394
452
  </>
395
453
  )}
396
454
  {deleteDialogOpen && deleteDialog}
397
- </>
455
+ </StyledCard>
398
456
  );
399
457
  }
400
458
 
@@ -204,6 +204,47 @@ export default function MutableNotebook({
204
204
  }
205
205
  return sourceAndPath;
206
206
  };
207
+ const plusButton = (isMarkdown: boolean, index: number) => {
208
+ return (
209
+ <Button
210
+ size="small"
211
+ startIcon={<AddIcon />}
212
+ onClick={() => handleAddCell(isMarkdown, index)}
213
+ variant="contained"
214
+ sx={{
215
+ backgroundColor: "#fff",
216
+ color: (theme) =>
217
+ theme.palette.mode === "dark"
218
+ ? theme.palette.grey[100]
219
+ : theme.palette.grey[700],
220
+ boxShadow: "none",
221
+ "&:hover": {
222
+ backgroundColor: (theme) =>
223
+ theme.palette.mode === "dark"
224
+ ? theme.palette.grey[500]
225
+ : theme.palette.grey[300],
226
+ boxShadow: "none",
227
+ },
228
+ }}
229
+ >
230
+ {isMarkdown ? "Markdown" : "Explore"}
231
+ </Button>
232
+ );
233
+ };
234
+ const addButtonSet = (
235
+ <Box
236
+ sx={{
237
+ display: "flex",
238
+ gap: 1,
239
+ justifyContent: "center",
240
+ flex: 2,
241
+ }}
242
+ >
243
+ {plusButton(false, notebookData.getCells().length)}
244
+ {plusButton(true, notebookData.getCells().length)}
245
+ </Box>
246
+ );
247
+
207
248
  return (
208
249
  <StyledCard variant="outlined">
209
250
  <StyledCardContent>
@@ -315,33 +356,6 @@ export default function MutableNotebook({
315
356
  }}
316
357
  />
317
358
  </Box>
318
- <Box
319
- sx={{
320
- display: "flex",
321
- gap: 1,
322
- justifyContent: "center",
323
- flex: 2,
324
- }}
325
- >
326
- <Button
327
- size="small"
328
- startIcon={<AddIcon />}
329
- onClick={() =>
330
- handleAddCell(false, notebookData.getCells().length)
331
- }
332
- >
333
- Explore
334
- </Button>
335
- <Button
336
- size="small"
337
- startIcon={<AddIcon />}
338
- onClick={() =>
339
- handleAddCell(true, notebookData.getCells().length)
340
- }
341
- >
342
- Markdown
343
- </Button>
344
- </Box>
345
359
  <Box sx={{ flex: 1 }} />
346
360
  </Stack>
347
361
  </StyledCardContent>
@@ -373,6 +387,9 @@ export default function MutableNotebook({
373
387
  >
374
388
  <MutableCell
375
389
  cell={cell}
390
+ addButtonCallback={(isMarkdown) =>
391
+ plusButton(isMarkdown, index)
392
+ }
376
393
  sourceAndPaths={getSourceList(sourceAndPaths)}
377
394
  expandCodeCell={expandCodeCells}
378
395
  expandEmbedding={expandEmbeddings}
@@ -404,6 +421,7 @@ export default function MutableNotebook({
404
421
  />
405
422
  </React.Fragment>
406
423
  ))}
424
+ {addButtonSet}
407
425
  <Menu
408
426
  anchorEl={menuAnchorEl}
409
427
  open={menuOpen}