@malloy-publisher/sdk 0.0.88 → 0.0.89
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/client/api.d.ts +113 -16
- package/dist/index.cjs.js +28 -28
- package/dist/index.es.js +1852 -1879
- package/package.json +1 -1
- package/src/components/Workbook/MutableCell.tsx +16 -47
- package/src/components/Workbook/Workbook.tsx +33 -13
package/package.json
CHANGED
|
@@ -58,6 +58,7 @@ export function MutableCell({
|
|
|
58
58
|
onDelete,
|
|
59
59
|
addButtonCallback,
|
|
60
60
|
}: NotebookCellProps) {
|
|
61
|
+
const [value, setValue] = useState(cell.value);
|
|
61
62
|
const [codeExpanded, setCodeExpanded] =
|
|
62
63
|
React.useState<boolean>(expandCodeCell);
|
|
63
64
|
const [embeddingExpanded, setEmbeddingExpanded] =
|
|
@@ -83,13 +84,9 @@ export function MutableCell({
|
|
|
83
84
|
setHighlightedMalloyCode(code);
|
|
84
85
|
});
|
|
85
86
|
}, [cell]);
|
|
86
|
-
const [value, setValue] = useState(cell.value);
|
|
87
87
|
React.useEffect(() => {
|
|
88
88
|
document.documentElement.setAttribute("data-color-mode", "light");
|
|
89
89
|
});
|
|
90
|
-
const updateMarkdown = useDebounce((newValue: string) => {
|
|
91
|
-
onCellChange({ ...cell, value: newValue });
|
|
92
|
-
});
|
|
93
90
|
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
|
94
91
|
|
|
95
92
|
const handleDeleteConfirm = () => {
|
|
@@ -98,7 +95,7 @@ export function MutableCell({
|
|
|
98
95
|
};
|
|
99
96
|
const noSources = sourceAndPaths.length === 0;
|
|
100
97
|
|
|
101
|
-
const saveResult = () => {
|
|
98
|
+
const saveResult = React.useCallback(() => {
|
|
102
99
|
// Get the current modelPath and sourceName from the selected source
|
|
103
100
|
const currentSource = sourceAndPaths[selectedSourceIndex];
|
|
104
101
|
const modelPath = currentSource?.modelPath || cell.modelPath || "";
|
|
@@ -109,7 +106,7 @@ export function MutableCell({
|
|
|
109
106
|
// the stringified JSON objects that are stored in the cell.
|
|
110
107
|
onCellChange({
|
|
111
108
|
...cell,
|
|
112
|
-
value: query.query,
|
|
109
|
+
value: cell.isMarkdown ? value : query.query,
|
|
113
110
|
result: query.malloyResult
|
|
114
111
|
? JSON.stringify(query.malloyResult)
|
|
115
112
|
: undefined,
|
|
@@ -119,7 +116,7 @@ export function MutableCell({
|
|
|
119
116
|
sourceName,
|
|
120
117
|
modelPath,
|
|
121
118
|
});
|
|
122
|
-
};
|
|
119
|
+
}, [cell, value, query, onCellChange, selectedSourceIndex, sourceAndPaths]);
|
|
123
120
|
|
|
124
121
|
const deleteButton = (
|
|
125
122
|
<Tooltip title="Delete Cell">
|
|
@@ -160,11 +157,15 @@ export function MutableCell({
|
|
|
160
157
|
</DialogActions>
|
|
161
158
|
</Dialog>
|
|
162
159
|
);
|
|
160
|
+
const saveAndClose = () => {
|
|
161
|
+
saveResult();
|
|
162
|
+
onClose();
|
|
163
|
+
};
|
|
163
164
|
const buttons = cell.isMarkdown ? (
|
|
164
165
|
<>
|
|
165
166
|
{editingMarkdown ? (
|
|
166
167
|
<Tooltip title="Save">
|
|
167
|
-
<IconButton size="small" onClick={
|
|
168
|
+
<IconButton size="small" onClick={saveAndClose}>
|
|
168
169
|
<CheckIcon />
|
|
169
170
|
</IconButton>
|
|
170
171
|
</Tooltip>
|
|
@@ -207,13 +208,7 @@ export function MutableCell({
|
|
|
207
208
|
)}
|
|
208
209
|
{editingMalloy && (
|
|
209
210
|
<Tooltip title="Save">
|
|
210
|
-
<IconButton
|
|
211
|
-
size="small"
|
|
212
|
-
onClick={() => {
|
|
213
|
-
saveResult();
|
|
214
|
-
onClose();
|
|
215
|
-
}}
|
|
216
|
-
>
|
|
211
|
+
<IconButton size="small" onClick={saveAndClose}>
|
|
217
212
|
<CheckIcon />
|
|
218
213
|
</IconButton>
|
|
219
214
|
</Tooltip>
|
|
@@ -230,22 +225,15 @@ export function MutableCell({
|
|
|
230
225
|
);
|
|
231
226
|
|
|
232
227
|
const isEditing = editingMalloy || editingMarkdown;
|
|
233
|
-
|
|
234
228
|
const editingButtons = editingMarkdown ? (
|
|
235
229
|
<Tooltip title="Save">
|
|
236
|
-
<IconButton size="small" onClick={
|
|
230
|
+
<IconButton size="small" onClick={saveAndClose}>
|
|
237
231
|
<CheckIcon />
|
|
238
232
|
</IconButton>
|
|
239
233
|
</Tooltip>
|
|
240
234
|
) : editingMalloy ? (
|
|
241
235
|
<Tooltip title="Save">
|
|
242
|
-
<IconButton
|
|
243
|
-
size="small"
|
|
244
|
-
onClick={() => {
|
|
245
|
-
saveResult();
|
|
246
|
-
onClose();
|
|
247
|
-
}}
|
|
248
|
-
>
|
|
236
|
+
<IconButton size="small" onClick={saveAndClose}>
|
|
249
237
|
<CheckIcon />
|
|
250
238
|
</IconButton>
|
|
251
239
|
</Tooltip>
|
|
@@ -305,12 +293,12 @@ export function MutableCell({
|
|
|
305
293
|
autoFocus
|
|
306
294
|
onChange={(newValue) => {
|
|
307
295
|
setValue(newValue);
|
|
308
|
-
|
|
296
|
+
onCellChange({ ...cell, value: newValue });
|
|
309
297
|
}}
|
|
310
298
|
onBlur={() => {
|
|
311
299
|
saveResult();
|
|
312
300
|
if (!isHovered) {
|
|
313
|
-
|
|
301
|
+
saveAndClose();
|
|
314
302
|
}
|
|
315
303
|
}}
|
|
316
304
|
/>
|
|
@@ -331,9 +319,9 @@ export function MutableCell({
|
|
|
331
319
|
"& blockquote": { mt: 0.5, mb: 0.5 },
|
|
332
320
|
}}
|
|
333
321
|
>
|
|
334
|
-
{value ? (
|
|
322
|
+
{cell.value ? (
|
|
335
323
|
<Box onClick={onEdit} sx={{ cursor: "pointer" }}>
|
|
336
|
-
<Markdown>{value}</Markdown>
|
|
324
|
+
<Markdown>{cell.value}</Markdown>
|
|
337
325
|
</Box>
|
|
338
326
|
) : (
|
|
339
327
|
<Box onClick={onEdit} sx={{ cursor: "pointer" }}>
|
|
@@ -469,22 +457,3 @@ export function MutableCell({
|
|
|
469
457
|
</StyledCard>
|
|
470
458
|
);
|
|
471
459
|
}
|
|
472
|
-
|
|
473
|
-
function useDebounce<T>(callback: (value: T) => void, delay: number = 2000) {
|
|
474
|
-
const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(
|
|
475
|
-
undefined,
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
return React.useCallback(
|
|
479
|
-
(value: T) => {
|
|
480
|
-
if (timeoutRef.current) {
|
|
481
|
-
clearTimeout(timeoutRef.current);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
timeoutRef.current = setTimeout(() => {
|
|
485
|
-
callback(value);
|
|
486
|
-
}, delay);
|
|
487
|
-
},
|
|
488
|
-
[callback, delay],
|
|
489
|
-
);
|
|
490
|
-
}
|
|
@@ -58,6 +58,7 @@ export default function Workbook({
|
|
|
58
58
|
const navigate = useRouterClickHandler();
|
|
59
59
|
const { server, getAccessToken } = useServer();
|
|
60
60
|
const { workbookStorage } = useWorkbookStorage();
|
|
61
|
+
const [success, setSuccess] = React.useState<string | undefined>(undefined);
|
|
61
62
|
const [lastError, setLastError] = React.useState<string | undefined>(
|
|
62
63
|
undefined,
|
|
63
64
|
);
|
|
@@ -88,17 +89,20 @@ export default function Workbook({
|
|
|
88
89
|
setMenuIndex(null);
|
|
89
90
|
};
|
|
90
91
|
const handleAddCell = (isMarkdown: boolean, index: number) => {
|
|
91
|
-
workbookData
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
if (!workbookData) return;
|
|
93
|
+
setWorkbookData(
|
|
94
|
+
workbookData.insertCell(index, {
|
|
95
|
+
isMarkdown,
|
|
96
|
+
value: "",
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
96
99
|
if (isMarkdown) {
|
|
97
100
|
setEditingMarkdownIndex(index);
|
|
98
101
|
} else {
|
|
99
102
|
setEditingMalloyIndex(index);
|
|
100
103
|
}
|
|
101
104
|
handleMenuClose();
|
|
105
|
+
console.log("handleAddCell", isMarkdown, index);
|
|
102
106
|
};
|
|
103
107
|
|
|
104
108
|
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
|
|
@@ -112,9 +116,11 @@ export default function Workbook({
|
|
|
112
116
|
.deleteWorkbook(workbookPath)
|
|
113
117
|
.then(() => {
|
|
114
118
|
setLastError(undefined);
|
|
119
|
+
setSuccess(undefined);
|
|
115
120
|
})
|
|
116
121
|
.catch((error) => {
|
|
117
122
|
setLastError(`Error deleting workbook: ${error.message}`);
|
|
123
|
+
setSuccess(undefined);
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
126
|
setDeleteDialogOpen(false);
|
|
@@ -127,11 +133,17 @@ export default function Workbook({
|
|
|
127
133
|
};
|
|
128
134
|
|
|
129
135
|
const saveWorkbook = React.useCallback(async () => {
|
|
136
|
+
if (!workbookData) {
|
|
137
|
+
console.log("No workbook data ref");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
130
140
|
try {
|
|
131
141
|
setWorkbookData(await workbookData.saveWorkbook());
|
|
132
142
|
setLastError(undefined);
|
|
143
|
+
setSuccess("Workbook saved");
|
|
133
144
|
} catch (error) {
|
|
134
145
|
setLastError(`Error saving workbook: ${error.message}`);
|
|
146
|
+
setSuccess(undefined);
|
|
135
147
|
}
|
|
136
148
|
}, [workbookData]);
|
|
137
149
|
React.useEffect(() => {
|
|
@@ -265,13 +277,21 @@ export default function Workbook({
|
|
|
265
277
|
return (
|
|
266
278
|
<StyledCard variant="outlined">
|
|
267
279
|
<StyledCardContent>
|
|
268
|
-
{
|
|
269
|
-
<Box sx={{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
280
|
+
<Box sx={{ mb: 2 }}>
|
|
281
|
+
<Box sx={{ minHeight: "24px" }}>
|
|
282
|
+
{lastError ? (
|
|
283
|
+
<Typography color="error" variant="body2">
|
|
284
|
+
{lastError}
|
|
285
|
+
</Typography>
|
|
286
|
+
) : success ? (
|
|
287
|
+
<Typography color="success" variant="body2">
|
|
288
|
+
{success}
|
|
289
|
+
</Typography>
|
|
290
|
+
) : (
|
|
291
|
+
<span> </span>
|
|
292
|
+
)}
|
|
273
293
|
</Box>
|
|
274
|
-
|
|
294
|
+
</Box>
|
|
275
295
|
<Stack
|
|
276
296
|
sx={{
|
|
277
297
|
flexDirection: "row",
|
|
@@ -350,7 +370,7 @@ export default function Workbook({
|
|
|
350
370
|
Cancel
|
|
351
371
|
</Button>
|
|
352
372
|
<Button
|
|
353
|
-
onClick={
|
|
373
|
+
onClick={handleDeleteConfirm}
|
|
354
374
|
color="error"
|
|
355
375
|
autoFocus
|
|
356
376
|
size="small"
|
|
@@ -427,7 +447,6 @@ export default function Workbook({
|
|
|
427
447
|
}}
|
|
428
448
|
onCellChange={(cell) => {
|
|
429
449
|
setWorkbookData(workbookData.setCell(index, cell));
|
|
430
|
-
saveWorkbook();
|
|
431
450
|
}}
|
|
432
451
|
onEdit={() => {
|
|
433
452
|
if (cell.isMarkdown) {
|
|
@@ -442,6 +461,7 @@ export default function Workbook({
|
|
|
442
461
|
} else {
|
|
443
462
|
setEditingMalloyIndex(undefined);
|
|
444
463
|
}
|
|
464
|
+
saveWorkbook();
|
|
445
465
|
}}
|
|
446
466
|
/>
|
|
447
467
|
</React.Fragment>
|