@marimo-team/frontend 0.19.7-dev31 → 0.19.7-dev34

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 (42) hide show
  1. package/dist/assets/{JsonOutput-CaYsBlIL.js → JsonOutput-DvKIRGOg.js} +10 -10
  2. package/dist/assets/{add-cell-with-ai-DGWXuion.js → add-cell-with-ai-BHgqYu8P.js} +1 -1
  3. package/dist/assets/{agent-panel-C_CZ3wsS.js → agent-panel-C9codfcr.js} +1 -1
  4. package/dist/assets/{cell-editor-DrfE1YS-.js → cell-editor-BxhibLVM.js} +1 -1
  5. package/dist/assets/{chat-display-BIHBJe4Q.js → chat-display-B0625p01.js} +1 -1
  6. package/dist/assets/{chat-panel-C4V8R2vf.js → chat-panel-CkHdco_X.js} +1 -1
  7. package/dist/assets/{column-preview-DfgAxcnz.js → column-preview-C6jEPj3t.js} +1 -1
  8. package/dist/assets/{command-palette-D4dxpptj.js → command-palette-D1g3pU47.js} +1 -1
  9. package/dist/assets/{dependency-graph-panel-BbRSXJOA.js → dependency-graph-panel-BWvUSpJI.js} +1 -1
  10. package/dist/assets/{download-Cphyle83.js → download-vBVDTXQk.js} +2 -2
  11. package/dist/assets/{edit-page-BiEfjNLG.js → edit-page-UqaWbc_J.js} +3 -3
  12. package/dist/assets/{file-explorer-panel-Dkqk7q5V.js → file-explorer-panel-y7F8Uqi-.js} +1 -1
  13. package/dist/assets/hooks-D_OOStv3.js +1 -0
  14. package/dist/assets/html-to-image-Cdx1xsbU.js +2 -0
  15. package/dist/assets/{index-0-J_BSHl.js → index-BSBPZDCV.js} +3 -3
  16. package/dist/assets/index-DmMvDRRC.css +2 -0
  17. package/dist/assets/{layout-BJ9AHITN.js → layout-Xf51uwDc.js} +1 -1
  18. package/dist/assets/{markdown-renderer-aprG4bjs.js → markdown-renderer-DSY-ElEE.js} +1 -1
  19. package/dist/assets/{panels-DDBrdHNH.js → panels-D-yo_63g.js} +1 -1
  20. package/dist/assets/{readonly-python-code-BwtDUnWb.js → readonly-python-code-B1UBDfCT.js} +1 -1
  21. package/dist/assets/{run-page-BS9QQKCJ.js → run-page-CoCql9Xm.js} +1 -1
  22. package/dist/assets/{scratchpad-panel-_4qqJHnW.js → scratchpad-panel-DPnpCcOn.js} +1 -1
  23. package/dist/assets/{session-panel-sueNTZq5.js → session-panel-CjoiPf6W.js} +1 -1
  24. package/dist/assets/{useAddCell-B7_Lgd-h.js → useAddCell-M6_IuI4C.js} +1 -1
  25. package/dist/assets/{useCellActionButton-BxQHrbUZ.js → useCellActionButton-Ddy42rre.js} +1 -1
  26. package/dist/assets/{useDependencyPanelTab-oTszzY42.js → useDependencyPanelTab-RSRpRVKD.js} +1 -1
  27. package/dist/assets/{useNotebookActions-DFKZ18Bu.js → useNotebookActions-XKe-QMLa.js} +1 -1
  28. package/dist/assets/{utilities.esm-BeoTGe8r.js → utilities.esm-mPQPstBT.js} +1 -1
  29. package/dist/index.html +12 -12
  30. package/package.json +1 -1
  31. package/src/components/editor/Output.tsx +6 -10
  32. package/src/components/editor/actions/useNotebookActions.tsx +2 -2
  33. package/src/core/export/__tests__/hooks.test.ts +72 -33
  34. package/src/core/export/hooks.ts +17 -8
  35. package/src/utils/__tests__/download.test.tsx +18 -18
  36. package/src/utils/__tests__/mime-types.test.ts +326 -0
  37. package/src/utils/download.ts +9 -11
  38. package/src/utils/html-to-image.ts +139 -0
  39. package/src/utils/mime-types.ts +181 -0
  40. package/dist/assets/hooks-COmcm0X5.js +0 -1
  41. package/dist/assets/html-to-image-DiZMGN_d.js +0 -2
  42. package/dist/assets/index-DHsXOI_M.css +0 -2
@@ -102,8 +102,8 @@ describe("useEnrichCellOutputs", () => {
102
102
 
103
103
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
104
104
 
105
- const enrichCellOutputs = result.current;
106
- const output = await enrichCellOutputs(progress);
105
+ const takeScreenshots = result.current;
106
+ const output = await takeScreenshots({ progress, snappy: false });
107
107
 
108
108
  expect(output).toEqual({});
109
109
  expect(document.getElementById).not.toHaveBeenCalled();
@@ -134,8 +134,8 @@ describe("useEnrichCellOutputs", () => {
134
134
 
135
135
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
136
136
 
137
- const enrichCellOutputs = result.current;
138
- const output = await enrichCellOutputs(progress);
137
+ const takeScreenshots = result.current;
138
+ const output = await takeScreenshots({ progress, snappy: false });
139
139
 
140
140
  expect(document.getElementById).toHaveBeenCalledWith(
141
141
  CellOutputId.create(cellId),
@@ -152,6 +152,50 @@ describe("useEnrichCellOutputs", () => {
152
152
  });
153
153
  });
154
154
 
155
+ it("should pass snappy=true to toPng with includeStyleProperties", async () => {
156
+ const cellId = "cell-1" as CellId;
157
+ const mockElement = document.createElement("div");
158
+ const mockDataUrl = "data:image/png;base64,mockImageData";
159
+
160
+ // Mock document.getElementById
161
+ vi.spyOn(document, "getElementById").mockReturnValue(mockElement);
162
+ vi.mocked(toPng).mockResolvedValue(mockDataUrl);
163
+
164
+ setCellsRuntime(
165
+ createMockCellRuntimes({
166
+ [cellId]: {
167
+ output: {
168
+ channel: "output",
169
+ mimetype: "text/html",
170
+ data: "<div>Chart</div>",
171
+ timestamp: 0,
172
+ },
173
+ },
174
+ }),
175
+ );
176
+
177
+ const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
178
+
179
+ const takeScreenshots = result.current;
180
+ const output = await takeScreenshots({ progress, snappy: true });
181
+
182
+ expect(document.getElementById).toHaveBeenCalledWith(
183
+ CellOutputId.create(cellId),
184
+ );
185
+ // When snappy=true, includeStyleProperties should be set
186
+ expect(toPng).toHaveBeenCalledWith(
187
+ mockElement,
188
+ expect.objectContaining({
189
+ filter: expect.any(Function),
190
+ onImageErrorHandler: expect.any(Function),
191
+ includeStyleProperties: expect.any(Array),
192
+ }),
193
+ );
194
+ expect(output).toEqual({
195
+ [cellId]: ["image/png", mockDataUrl],
196
+ });
197
+ });
198
+
155
199
  it("should skip cells where output has not changed", async () => {
156
200
  const cellId = "cell-1" as CellId;
157
201
  const mockElement = document.createElement("div");
@@ -179,8 +223,8 @@ describe("useEnrichCellOutputs", () => {
179
223
  });
180
224
 
181
225
  // First call - should capture
182
- let enrichCellOutputs = result.current;
183
- let output = await enrichCellOutputs(progress);
226
+ let takeScreenshots = result.current;
227
+ let output = await takeScreenshots({ progress, snappy: false });
184
228
  expect(output).toEqual({ [cellId]: ["image/png", mockDataUrl] });
185
229
  expect(toPng).toHaveBeenCalledTimes(1);
186
230
 
@@ -188,8 +232,8 @@ describe("useEnrichCellOutputs", () => {
188
232
  rerender();
189
233
 
190
234
  // Second call with same output - should not capture again
191
- enrichCellOutputs = result.current;
192
- output = await enrichCellOutputs(progress);
235
+ takeScreenshots = result.current;
236
+ output = await takeScreenshots({ progress, snappy: false });
193
237
  expect(output).toEqual({}); // Empty because output hasn't changed
194
238
  expect(toPng).toHaveBeenCalledTimes(1); // Still only 1 call
195
239
  });
@@ -217,8 +261,8 @@ describe("useEnrichCellOutputs", () => {
217
261
 
218
262
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
219
263
 
220
- const enrichCellOutputs = result.current;
221
- const output = await enrichCellOutputs(progress);
264
+ const takeScreenshots = result.current;
265
+ const output = await takeScreenshots({ progress, snappy: false });
222
266
 
223
267
  expect(output).toEqual({}); // Failed screenshot should be filtered out
224
268
  expect(Logger.error).toHaveBeenCalledWith(
@@ -247,8 +291,8 @@ describe("useEnrichCellOutputs", () => {
247
291
 
248
292
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
249
293
 
250
- const enrichCellOutputs = result.current;
251
- const output = await enrichCellOutputs(progress);
294
+ const takeScreenshots = result.current;
295
+ const output = await takeScreenshots({ progress, snappy: false });
252
296
 
253
297
  expect(output).toEqual({});
254
298
  expect(Logger.error).toHaveBeenCalledWith(
@@ -296,8 +340,8 @@ describe("useEnrichCellOutputs", () => {
296
340
 
297
341
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
298
342
 
299
- const enrichCellOutputs = result.current;
300
- const output = await enrichCellOutputs(progress);
343
+ const takeScreenshots = result.current;
344
+ const output = await takeScreenshots({ progress, snappy: false });
301
345
 
302
346
  expect(output).toEqual({
303
347
  [cell1]: ["image/png", mockDataUrl1],
@@ -342,8 +386,8 @@ describe("useEnrichCellOutputs", () => {
342
386
 
343
387
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
344
388
 
345
- const enrichCellOutputs = result.current;
346
- const output = await enrichCellOutputs(progress);
389
+ const takeScreenshots = result.current;
390
+ const output = await takeScreenshots({ progress, snappy: false });
347
391
 
348
392
  // Only the successful screenshot should be in the result
349
393
  expect(output).toEqual({
@@ -384,14 +428,14 @@ describe("useEnrichCellOutputs", () => {
384
428
  });
385
429
 
386
430
  // First screenshot
387
- let enrichCellOutputs = result.current;
388
- let output = await enrichCellOutputs(progress);
431
+ let takeScreenshots = result.current;
432
+ let output = await takeScreenshots({ progress, snappy: false });
389
433
  expect(output).toEqual({ [cellId]: ["image/png", mockDataUrl1] });
390
434
 
391
435
  // Second call - same output, should not be captured
392
436
  rerender();
393
- enrichCellOutputs = result.current;
394
- output = await enrichCellOutputs(progress);
437
+ takeScreenshots = result.current;
438
+ output = await takeScreenshots({ progress, snappy: false });
395
439
  expect(output).toEqual({});
396
440
 
397
441
  // Third call - output changed, should be captured
@@ -409,8 +453,8 @@ describe("useEnrichCellOutputs", () => {
409
453
  );
410
454
 
411
455
  rerender();
412
- enrichCellOutputs = result.current;
413
- output = await enrichCellOutputs(progress);
456
+ takeScreenshots = result.current;
457
+ output = await takeScreenshots({ progress, snappy: false });
414
458
  expect(output).toEqual({ [cellId]: ["image/png", mockDataUrl2] });
415
459
  expect(toPng).toHaveBeenCalledTimes(2);
416
460
  });
@@ -449,8 +493,8 @@ describe("useEnrichCellOutputs", () => {
449
493
 
450
494
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
451
495
 
452
- const enrichCellOutputs = result.current;
453
- const output = await enrichCellOutputs(progress);
496
+ const takeScreenshots = result.current;
497
+ const output = await takeScreenshots({ progress, snappy: false });
454
498
 
455
499
  // None of these should trigger screenshots
456
500
  expect(output).toEqual({});
@@ -474,8 +518,8 @@ describe("useEnrichCellOutputs", () => {
474
518
 
475
519
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
476
520
 
477
- const enrichCellOutputs = result.current;
478
- const output = await enrichCellOutputs(progress);
521
+ const takeScreenshots = result.current;
522
+ const output = await takeScreenshots({ progress, snappy: false });
479
523
 
480
524
  expect(output).toEqual({});
481
525
  expect(document.getElementById).not.toHaveBeenCalled();
@@ -506,8 +550,8 @@ describe("useEnrichCellOutputs", () => {
506
550
 
507
551
  const { result } = renderHook(() => useEnrichCellOutputs(), { wrapper });
508
552
 
509
- const enrichCellOutputs = result.current;
510
- const output = await enrichCellOutputs(progress);
553
+ const takeScreenshots = result.current;
554
+ const output = await takeScreenshots({ progress, snappy: false });
511
555
 
512
556
  // Verify the exact return type structure
513
557
  expect(output).toHaveProperty(cellId);
@@ -539,7 +583,6 @@ describe("updateCellOutputsWithScreenshots", () => {
539
583
  const updateCellOutputs = vi.fn().mockResolvedValue(null);
540
584
 
541
585
  await updateCellOutputsWithScreenshots({
542
- progress,
543
586
  takeScreenshots,
544
587
  updateCellOutputs,
545
588
  });
@@ -556,7 +599,6 @@ describe("updateCellOutputsWithScreenshots", () => {
556
599
  const updateCellOutputs = vi.fn().mockResolvedValue(null);
557
600
 
558
601
  await updateCellOutputsWithScreenshots({
559
- progress,
560
602
  takeScreenshots,
561
603
  updateCellOutputs,
562
604
  });
@@ -583,7 +625,6 @@ describe("updateCellOutputsWithScreenshots", () => {
583
625
  const updateCellOutputs = vi.fn().mockResolvedValue(null);
584
626
 
585
627
  await updateCellOutputsWithScreenshots({
586
- progress,
587
628
  takeScreenshots,
588
629
  updateCellOutputs,
589
630
  });
@@ -600,7 +641,6 @@ describe("updateCellOutputsWithScreenshots", () => {
600
641
 
601
642
  // Should not throw - errors are caught and shown via toast
602
643
  await updateCellOutputsWithScreenshots({
603
- progress,
604
644
  takeScreenshots,
605
645
  updateCellOutputs,
606
646
  });
@@ -633,7 +673,6 @@ describe("updateCellOutputsWithScreenshots", () => {
633
673
 
634
674
  // Should not throw - errors are caught and shown via toast
635
675
  await updateCellOutputsWithScreenshots({
636
- progress,
637
676
  takeScreenshots,
638
677
  updateCellOutputs,
639
678
  });
@@ -64,9 +64,13 @@ export function useAutoExport() {
64
64
 
65
65
  useInterval(
66
66
  async () => {
67
+ const screenshotFn = () =>
68
+ takeScreenshots({
69
+ progress: ProgressState.indeterminate(),
70
+ snappy: true,
71
+ });
67
72
  await updateCellOutputsWithScreenshots({
68
- progress: ProgressState.indeterminate(),
69
- takeScreenshots,
73
+ takeScreenshots: screenshotFn,
70
74
  updateCellOutputs,
71
75
  });
72
76
  await autoExportAsIPYNB({
@@ -107,7 +111,13 @@ export function useEnrichCellOutputs() {
107
111
  const [richCellsOutput, setRichCellsOutput] = useAtom(richCellsToOutputAtom);
108
112
  const cellRuntimes = useAtomValue(cellsRuntimeAtom);
109
113
 
110
- return async (progress: ProgressState): Promise<ScreenshotResults> => {
114
+ return async ({
115
+ progress,
116
+ snappy,
117
+ }: {
118
+ progress: ProgressState;
119
+ snappy: boolean;
120
+ }): Promise<ScreenshotResults> => {
111
121
  const trackedCellsOutput: Record<CellId, unknown> = {};
112
122
 
113
123
  const cellsToCaptureScreenshot: [CellId, unknown][] = [];
@@ -138,7 +148,7 @@ export function useEnrichCellOutputs() {
138
148
  const results: ScreenshotResults = {};
139
149
  for (const [cellId] of cellsToCaptureScreenshot) {
140
150
  try {
141
- const dataUrl = await getImageDataUrlForCell(cellId, false);
151
+ const dataUrl = await getImageDataUrlForCell(cellId, snappy);
142
152
  if (!dataUrl) {
143
153
  Logger.error(`Failed to capture screenshot for cell ${cellId}`);
144
154
  continue;
@@ -159,13 +169,12 @@ export function useEnrichCellOutputs() {
159
169
  * Utility function to take screenshots of cells with HTML outputs and update the cell outputs.
160
170
  */
161
171
  export async function updateCellOutputsWithScreenshots(opts: {
162
- progress: ProgressState;
163
- takeScreenshots: (progress: ProgressState) => Promise<ScreenshotResults>;
172
+ takeScreenshots: () => Promise<ScreenshotResults>;
164
173
  updateCellOutputs: (request: UpdateCellOutputsRequest) => Promise<null>;
165
174
  }) {
166
- const { progress, takeScreenshots, updateCellOutputs } = opts;
175
+ const { takeScreenshots, updateCellOutputs } = opts;
167
176
  try {
168
- const cellIdsToOutput = await takeScreenshots(progress);
177
+ const cellIdsToOutput = await takeScreenshots();
169
178
  if (Objects.size(cellIdsToOutput) > 0) {
170
179
  await updateCellOutputs({ cellIdsToOutput });
171
180
  }
@@ -166,7 +166,7 @@ describe("getImageDataUrlForCell", () => {
166
166
  );
167
167
  });
168
168
 
169
- it("should add printing classes before capture when enablePrintMode is true", async () => {
169
+ it("should add printing classes before capture when snappy is false", async () => {
170
170
  vi.mocked(toPng).mockImplementation(async () => {
171
171
  // Check classes are applied during capture
172
172
  expect(mockElement.classList.contains("printing-output")).toBe(true);
@@ -175,36 +175,36 @@ describe("getImageDataUrlForCell", () => {
175
175
  return mockDataUrl;
176
176
  });
177
177
 
178
- await getImageDataUrlForCell("cell-1" as CellId, true);
178
+ await getImageDataUrlForCell("cell-1" as CellId, false);
179
179
  });
180
180
 
181
- it("should remove printing classes after capture when enablePrintMode is true", async () => {
181
+ it("should remove printing classes after capture when snappy is false", async () => {
182
182
  vi.mocked(toPng).mockResolvedValue(mockDataUrl);
183
183
 
184
- await getImageDataUrlForCell("cell-1" as CellId, true);
184
+ await getImageDataUrlForCell("cell-1" as CellId, false);
185
185
 
186
186
  expect(mockElement.classList.contains("printing-output")).toBe(false);
187
187
  expect(document.body.classList.contains("printing")).toBe(false);
188
188
  });
189
189
 
190
- it("should add printing-output but NOT body.printing when enablePrintMode is false", async () => {
190
+ it("should add printing-output but NOT body.printing when snappy is true", async () => {
191
191
  vi.mocked(toPng).mockImplementation(async () => {
192
192
  // printing-output should still be added to the element
193
193
  expect(mockElement.classList.contains("printing-output")).toBe(true);
194
- // but body.printing should NOT be added
194
+ // but body.printing should NOT be added when snappy mode is on
195
195
  expect(document.body.classList.contains("printing")).toBe(false);
196
196
  expect(mockElement.style.overflow).toBe("auto");
197
197
  return mockDataUrl;
198
198
  });
199
199
 
200
- await getImageDataUrlForCell("cell-1" as CellId, false);
200
+ await getImageDataUrlForCell("cell-1" as CellId, true);
201
201
  });
202
202
 
203
- it("should cleanup printing-output when enablePrintMode is false", async () => {
203
+ it("should cleanup printing-output when snappy is true", async () => {
204
204
  mockElement.style.overflow = "hidden";
205
205
  vi.mocked(toPng).mockResolvedValue(mockDataUrl);
206
206
 
207
- await getImageDataUrlForCell("cell-1" as CellId, false);
207
+ await getImageDataUrlForCell("cell-1" as CellId, true);
208
208
 
209
209
  expect(mockElement.classList.contains("printing-output")).toBe(false);
210
210
  expect(document.body.classList.contains("printing")).toBe(false);
@@ -239,7 +239,7 @@ describe("getImageDataUrlForCell", () => {
239
239
  expect(mockElement.style.overflow).toBe("scroll");
240
240
  });
241
241
 
242
- it("should maintain body.printing during concurrent captures when enablePrintMode is true", async () => {
242
+ it("should maintain body.printing during concurrent captures when snappy is false", async () => {
243
243
  // Create a second element
244
244
  const mockElement2 = document.createElement("div");
245
245
  mockElement2.id = CellOutputId.create("cell-2" as CellId);
@@ -273,9 +273,9 @@ describe("getImageDataUrlForCell", () => {
273
273
  return mockDataUrl;
274
274
  });
275
275
 
276
- // Start both captures concurrently with enablePrintMode = true
277
- const capture1 = getImageDataUrlForCell("cell-1" as CellId, true);
278
- const capture2 = getImageDataUrlForCell("cell-2" as CellId, true);
276
+ // Start both captures concurrently with snappy = false (body.printing should be added)
277
+ const capture1 = getImageDataUrlForCell("cell-1" as CellId, false);
278
+ const capture2 = getImageDataUrlForCell("cell-2" as CellId, false);
279
279
 
280
280
  // Let second capture complete first
281
281
  resolveSecond!();
@@ -297,21 +297,21 @@ describe("getImageDataUrlForCell", () => {
297
297
  mockElement2.remove();
298
298
  });
299
299
 
300
- it("should not interfere with body.printing during concurrent captures when enablePrintMode is false", async () => {
300
+ it("should not interfere with body.printing during concurrent captures when snappy is true", async () => {
301
301
  // Create a second element
302
302
  const mockElement2 = document.createElement("div");
303
303
  mockElement2.id = CellOutputId.create("cell-2" as CellId);
304
304
  document.body.append(mockElement2);
305
305
 
306
306
  vi.mocked(toPng).mockImplementation(async () => {
307
- // body.printing should never be added when enablePrintMode is false
307
+ // body.printing should never be added when snappy is true
308
308
  expect(document.body.classList.contains("printing")).toBe(false);
309
309
  return mockDataUrl;
310
310
  });
311
311
 
312
- // Start both captures concurrently with enablePrintMode = false
313
- const capture1 = getImageDataUrlForCell("cell-1" as CellId, false);
314
- const capture2 = getImageDataUrlForCell("cell-2" as CellId, false);
312
+ // Start both captures concurrently with snappy = true (body.printing should NOT be added)
313
+ const capture1 = getImageDataUrlForCell("cell-1" as CellId, true);
314
+ const capture2 = getImageDataUrlForCell("cell-2" as CellId, true);
315
315
 
316
316
  await Promise.all([capture1, capture2]);
317
317