@marimo-team/islands 0.23.10-dev1 → 0.23.10-dev12

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 (32) hide show
  1. package/dist/{any-language-editor-DfdpyDv_.js → any-language-editor-CiES2a2h.js} +2 -2
  2. package/dist/{chat-ui-ChD4VvCo.js → chat-ui-K84W5ecY.js} +5 -5
  3. package/dist/{code-visibility-B3oOX_TK.js → code-visibility-DK0V-P30.js} +1036 -882
  4. package/dist/{copy-BuQpJEzp.js → copy-5jQ_kGE1.js} +32 -32
  5. package/dist/{esm-BfhQmZjp.js → esm-CCuYCd3R.js} +1 -1
  6. package/dist/{extends-BgdxCfYu.js → extends-CkydH1Q5.js} +1 -1
  7. package/dist/{glide-data-editor-BOmK9ETQ.js → glide-data-editor-CgIxTzAP.js} +1 -1
  8. package/dist/{html-to-image-BHv7CEU_.js → html-to-image-B93KtAVY.js} +2135 -2118
  9. package/dist/main.js +10 -10
  10. package/dist/{process-output-BvySRgli.js → process-output-BOXi9fnS.js} +1 -1
  11. package/dist/{reveal-component-Dj4x14QX.js → reveal-component-DLdvi2qq.js} +2 -2
  12. package/package.json +1 -1
  13. package/src/components/data-table/__tests__/data-table.test.tsx +154 -12
  14. package/src/components/data-table/hover-tooltip/__tests__/content.test.ts +60 -0
  15. package/src/components/data-table/hover-tooltip/content.ts +44 -0
  16. package/src/components/data-table/hover-tooltip/hover-tooltip.tsx +55 -0
  17. package/src/components/data-table/hover-tooltip/use-table-hover-tooltip.ts +159 -0
  18. package/src/components/data-table/renderers.tsx +27 -43
  19. package/src/components/editor/cell/cell-context-menu.tsx +15 -2
  20. package/src/components/ui/__tests__/use-toast.test.ts +75 -0
  21. package/src/components/ui/use-toast.ts +33 -13
  22. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +0 -28
  23. package/src/core/cells/__tests__/cell.test.ts +29 -2
  24. package/src/core/cells/__tests__/document-changes.test.ts +201 -2
  25. package/src/core/cells/cell.ts +5 -1
  26. package/src/core/cells/document-changes.ts +61 -3
  27. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +37 -0
  28. package/src/core/codemirror/go-to-definition/commands.ts +17 -9
  29. package/src/core/codemirror/go-to-definition/utils.ts +1 -0
  30. package/src/core/network/__tests__/requests-static.test.ts +30 -0
  31. package/src/core/network/requests-static.ts +14 -10
  32. package/src/plugins/layout/DownloadPlugin.tsx +1 -1
@@ -16,14 +16,32 @@
16
16
  import { python } from "@codemirror/lang-python";
17
17
  import { EditorState } from "@codemirror/state";
18
18
  import { EditorView } from "@codemirror/view";
19
- import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
19
+ import {
20
+ afterAll,
21
+ afterEach,
22
+ beforeAll,
23
+ beforeEach,
24
+ describe,
25
+ expect,
26
+ it,
27
+ vi,
28
+ } from "vitest";
20
29
  import { cellId } from "@/__tests__/branded";
21
30
  import type { CellHandle } from "@/components/editor/notebook-cell";
22
31
  import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
23
32
  import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
33
+ import { requestClientAtom } from "@/core/network/requests";
34
+ import type { EditRequests, RunRequests } from "@/core/network/types";
35
+ import { store } from "@/core/state/jotai";
24
36
  import { MultiColumn } from "@/utils/id-tree";
25
37
  import { exportedForTesting, type NotebookState } from "../cells";
26
- import { type CellAction, toDocumentChanges } from "../document-changes";
38
+ import {
39
+ type CellAction,
40
+ coalesceChanges,
41
+ type DocumentChange,
42
+ exportedForTesting as middlewareExports,
43
+ toDocumentChanges,
44
+ } from "../document-changes";
27
45
  import { CellId } from "../ids";
28
46
 
29
47
  const { initialNotebookState, reducer } = exportedForTesting;
@@ -584,3 +602,184 @@ describe("toDocumentChanges", () => {
584
602
  });
585
603
  });
586
604
  });
605
+
606
+ describe("coalesceChanges", () => {
607
+ const X = cellId("X");
608
+ const Y = cellId("Y");
609
+ const A = cellId("A");
610
+ const config = { column: null, disabled: false, hide_code: false };
611
+
612
+ it("drops set-code that precedes a delete of the same cell", () => {
613
+ const changes: DocumentChange[] = [
614
+ { type: "set-code", cellId: X, code: "x = 2" },
615
+ { type: "delete-cell", cellId: X },
616
+ ];
617
+ expect(coalesceChanges(changes)).toEqual([
618
+ { type: "delete-cell", cellId: X },
619
+ ]);
620
+ });
621
+
622
+ it("keeps create+delete for a created-then-deleted cell, dropping the edit", () => {
623
+ const changes: DocumentChange[] = [
624
+ { type: "create-cell", cellId: X, code: "", name: "_", config },
625
+ { type: "set-code", cellId: X, code: "x = 1" },
626
+ { type: "delete-cell", cellId: X },
627
+ ];
628
+ expect(coalesceChanges(changes)).toEqual([
629
+ { type: "create-cell", cellId: X, code: "", name: "_", config },
630
+ { type: "delete-cell", cellId: X },
631
+ ]);
632
+ });
633
+
634
+ it("drops set-code, set-name, set-config, and move-cell for a deleted cell", () => {
635
+ const changes: DocumentChange[] = [
636
+ { type: "create-cell", cellId: X, code: "", name: "_", config },
637
+ { type: "set-code", cellId: X, code: "x = 1" },
638
+ { type: "set-name", cellId: X, name: "foo" },
639
+ {
640
+ type: "set-config",
641
+ cellId: X,
642
+ column: null,
643
+ disabled: true,
644
+ hideCode: false,
645
+ },
646
+ { type: "move-cell", cellId: X, after: A },
647
+ { type: "delete-cell", cellId: X },
648
+ ];
649
+ expect(coalesceChanges(changes)).toEqual([
650
+ { type: "create-cell", cellId: X, code: "", name: "_", config },
651
+ { type: "delete-cell", cellId: X },
652
+ ]);
653
+ });
654
+
655
+ it("leaves a plain delete of an unedited cell unchanged", () => {
656
+ const changes: DocumentChange[] = [{ type: "delete-cell", cellId: X }];
657
+ expect(coalesceChanges(changes)).toEqual([
658
+ { type: "delete-cell", cellId: X },
659
+ ]);
660
+ });
661
+
662
+ it("does not touch set-* for cells that are not deleted, preserving order", () => {
663
+ const changes: DocumentChange[] = [
664
+ { type: "set-code", cellId: A, code: "a = 1" },
665
+ { type: "set-code", cellId: Y, code: "y = 1" },
666
+ { type: "delete-cell", cellId: X },
667
+ ];
668
+ expect(coalesceChanges(changes)).toEqual([
669
+ { type: "set-code", cellId: A, code: "a = 1" },
670
+ { type: "set-code", cellId: Y, code: "y = 1" },
671
+ { type: "delete-cell", cellId: X },
672
+ ]);
673
+ });
674
+
675
+ it("collapses repeated set-code for a surviving cell to the last value", () => {
676
+ const changes: DocumentChange[] = [
677
+ { type: "set-code", cellId: X, code: "x = 1" },
678
+ { type: "set-name", cellId: X, name: "foo" },
679
+ { type: "set-code", cellId: X, code: "x = 2" },
680
+ ];
681
+ expect(coalesceChanges(changes)).toEqual([
682
+ { type: "set-name", cellId: X, name: "foo" },
683
+ { type: "set-code", cellId: X, code: "x = 2" },
684
+ ]);
685
+ });
686
+
687
+ it("keeps both creates so a downstream anchor stays resolvable", () => {
688
+ const changes: DocumentChange[] = [
689
+ { type: "create-cell", cellId: X, code: "", name: "_", config, after: A },
690
+ { type: "create-cell", cellId: Y, code: "", name: "_", config, after: X },
691
+ { type: "delete-cell", cellId: X },
692
+ ];
693
+ expect(coalesceChanges(changes)).toEqual([
694
+ { type: "create-cell", cellId: X, code: "", name: "_", config, after: A },
695
+ { type: "create-cell", cellId: Y, code: "", name: "_", config, after: X },
696
+ { type: "delete-cell", cellId: X },
697
+ ]);
698
+ });
699
+ });
700
+
701
+ /**
702
+ * End-to-end of the debounced flush path: dispatch through the real middleware
703
+ * reducer, let the debounce fire, and inspect the batch that reaches
704
+ * sendDocumentTransaction. Coalescing only matters once edits actually share a
705
+ * debounce window, which drainChanges-based tests can't observe.
706
+ */
707
+ describe("flush path coalescing", () => {
708
+ let sent: DocumentChange[][];
709
+
710
+ beforeEach(() => {
711
+ vi.useFakeTimers();
712
+ sent = [];
713
+ middlewareExports.cancelPendingChanges();
714
+ const captureClient: Pick<
715
+ EditRequests & RunRequests,
716
+ "sendDocumentTransaction"
717
+ > = {
718
+ sendDocumentTransaction: async ({ changes }) => {
719
+ sent.push(changes);
720
+ return null;
721
+ },
722
+ };
723
+ store.set(
724
+ requestClientAtom,
725
+ captureClient as unknown as EditRequests & RunRequests,
726
+ );
727
+ });
728
+
729
+ afterEach(() => {
730
+ middlewareExports.cancelPendingChanges();
731
+ store.set(requestClientAtom, null);
732
+ vi.useRealTimers();
733
+ });
734
+
735
+ it("coalesces edit + delete of the same cell within one debounce window", () => {
736
+ setup("x = 1");
737
+ const [x] = state.cellIds.inOrderIds;
738
+ // Discard the create-cell from setup; it would flush as its own batch.
739
+ middlewareExports.cancelPendingChanges();
740
+
741
+ // Same window: edit the cell, then delete it, with no timer advance.
742
+ state = dispatch(state, {
743
+ type: "updateCellCode",
744
+ payload: { cellId: x, code: "x = 2", formattingChange: false },
745
+ });
746
+ state = dispatch(state, {
747
+ type: "deleteCell",
748
+ payload: { cellId: x },
749
+ });
750
+
751
+ // Debounced: nothing on the wire yet.
752
+ expect(sent).toEqual([]);
753
+
754
+ vi.advanceTimersByTime(400);
755
+
756
+ // One transaction, and it is just the delete — the conflicting set-code
757
+ // has been dropped, so the server never sees edit+delete of one cell.
758
+ expect(sent).toHaveLength(1);
759
+ expect(sent[0]).toEqual([{ type: "delete-cell", cellId: x }]);
760
+ });
761
+
762
+ it("sends edit and delete as separate clean transactions across windows", () => {
763
+ setup("x = 1");
764
+ const [x] = state.cellIds.inOrderIds;
765
+ middlewareExports.cancelPendingChanges();
766
+
767
+ state = dispatch(state, {
768
+ type: "updateCellCode",
769
+ payload: { cellId: x, code: "x = 2", formattingChange: false },
770
+ });
771
+ vi.advanceTimersByTime(400);
772
+
773
+ state = dispatch(state, {
774
+ type: "deleteCell",
775
+ payload: { cellId: x },
776
+ });
777
+ vi.advanceTimersByTime(400);
778
+
779
+ // Two separate, individually-valid transactions: neither conflicts, which
780
+ // is why the bug only ever surfaced when both landed in the same window.
781
+ expect(sent).toHaveLength(2);
782
+ expect(sent[0]).toEqual([{ type: "set-code", cellId: x, code: "x = 2" }]);
783
+ expect(sent[1]).toEqual([{ type: "delete-cell", cellId: x }]);
784
+ });
785
+ });
@@ -73,7 +73,11 @@ export function transitionCell(
73
73
  nextCell.output = message.output ?? nextCell.output;
74
74
  nextCell.staleInputs = message.stale_inputs ?? nextCell.staleInputs;
75
75
  nextCell.status = message.status ?? nextCell.status;
76
- nextCell.serialization = message.serialization;
76
+ // Tri-state partial update: an omitted field (undefined) leaves the hint
77
+ // unchanged; null explicitly clears it; a string sets it.
78
+ if (message.serialization !== undefined) {
79
+ nextCell.serialization = message.serialization;
80
+ }
77
81
 
78
82
  let didInterruptFromThisMessage = false;
79
83
 
@@ -568,6 +568,64 @@ export function fromDocumentChanges(
568
568
  return actions;
569
569
  }
570
570
 
571
+ // ---------------------------------------------------------------------------
572
+ // Coalescing: reduce a buffered change sequence to its net effect
573
+ // ---------------------------------------------------------------------------
574
+
575
+ const COLLAPSIBLE_TYPES = new Set(["set-code", "set-name", "set-config"]);
576
+ const DROPPABLE_ON_DELETE = new Set([
577
+ "set-code",
578
+ "set-name",
579
+ "set-config",
580
+ "move-cell",
581
+ ]);
582
+
583
+ /**
584
+ * Reduce a buffered sequence of changes to an equivalent batch that reflects
585
+ * net effect rather than edit history. The server applies a transaction
586
+ * atomically and rejects internally contradictory batches (e.g. updating a
587
+ * cell that is also deleted in the same transaction), so a debounced sequence
588
+ * of edits must be reconciled before it is sent.
589
+ *
590
+ * Two reductions, both order-preserving:
591
+ * - For any cell deleted in the batch, drop its property/move changes. The
592
+ * `create-cell` and `delete-cell` are kept so anchors referencing the cell
593
+ * stay resolvable on the server; create+delete applies to a net no-op.
594
+ * - Collapse repeated `set-code`/`set-name`/`set-config` for a surviving cell
595
+ * to the last occurrence.
596
+ */
597
+ export function coalesceChanges(changes: DocumentChange[]): DocumentChange[] {
598
+ const deletedIds = new Set<CellId>();
599
+ for (const change of changes) {
600
+ if (change.type === "delete-cell") {
601
+ deletedIds.add(change.cellId);
602
+ }
603
+ }
604
+
605
+ const withoutEditsToDeletedCells = changes.filter(
606
+ (change) =>
607
+ !(
608
+ DROPPABLE_ON_DELETE.has(change.type) &&
609
+ "cellId" in change &&
610
+ deletedIds.has(change.cellId)
611
+ ),
612
+ );
613
+
614
+ const lastIndexByKey = new Map<string, number>();
615
+ withoutEditsToDeletedCells.forEach((change, index) => {
616
+ if (COLLAPSIBLE_TYPES.has(change.type) && "cellId" in change) {
617
+ lastIndexByKey.set(`${change.type}:${change.cellId}`, index);
618
+ }
619
+ });
620
+
621
+ return withoutEditsToDeletedCells.filter((change, index) => {
622
+ if (COLLAPSIBLE_TYPES.has(change.type) && "cellId" in change) {
623
+ return lastIndexByKey.get(`${change.type}:${change.cellId}`) === index;
624
+ }
625
+ return true;
626
+ });
627
+ }
628
+
571
629
  // ---------------------------------------------------------------------------
572
630
  // Middleware: debounced change dispatch to the server
573
631
  // ---------------------------------------------------------------------------
@@ -575,11 +633,11 @@ export function fromDocumentChanges(
575
633
  let pendingChanges: DocumentChange[] = [];
576
634
 
577
635
  const flushChanges = debounce(() => {
578
- if (pendingChanges.length === 0) {
636
+ const changes = coalesceChanges(pendingChanges);
637
+ pendingChanges = [];
638
+ if (changes.length === 0) {
579
639
  return;
580
640
  }
581
- const changes = pendingChanges;
582
- pendingChanges = [];
583
641
  void getRequestClient().sendDocumentTransaction({ changes });
584
642
  }, 400);
585
643
 
@@ -39,6 +39,43 @@ afterEach(() => {
39
39
  });
40
40
 
41
41
  describe("goToDefinitionAtCursorPosition", () => {
42
+ test("jumps to a reactive variable definition in another cell", async () => {
43
+ const definingCell = cellId("defining-cell");
44
+ const usageCell = cellId("usage-cell");
45
+ const definingCode = "a = 10";
46
+ const usageCode = "print(a)";
47
+
48
+ const definingView = createEditor(definingCode, definingCode.length);
49
+ const usageView = createEditor(usageCode, usageCode.indexOf("a"));
50
+ views.push(definingView, usageView);
51
+
52
+ const notebook = initialNotebookState();
53
+ notebook.cellHandles[definingCell] = {
54
+ current: { editorView: definingView, editorViewOrNull: definingView },
55
+ };
56
+ notebook.cellHandles[usageCell] = {
57
+ current: { editorView: usageView, editorViewOrNull: usageView },
58
+ };
59
+
60
+ store.set(notebookAtom, notebook);
61
+ store.set(variablesAtom, {
62
+ [variableName("a")]: {
63
+ dataType: "int",
64
+ declaredBy: [definingCell],
65
+ name: variableName("a"),
66
+ usedBy: [usageCell],
67
+ value: "10",
68
+ },
69
+ });
70
+
71
+ const result = goToDefinitionAtCursorPosition(usageView);
72
+
73
+ expect(result).toBe(true);
74
+ await tick();
75
+ expect(definingView.state.selection.main.head).toBe(0);
76
+ expect(usageView.state.selection.main.head).toBe(usageCode.indexOf("a"));
77
+ });
78
+
42
79
  test("prefers the current-cell local definition over a reactive global", async () => {
43
80
  const globalCell = cellId("global-cell");
44
81
  const localCell = cellId("local-cell");
@@ -28,10 +28,11 @@ interface VariableDeclaration {
28
28
  }
29
29
 
30
30
  function goToPosition(view: EditorView, from: number): void {
31
- view.focus();
32
- // Wait for the next frame, otherwise codemirror will
33
- // add a cursor from a pointer click.
31
+ // Focus on the next frame: a synchronous focus is a no-op while a Radix
32
+ // context menu still owns focus, and codemirror would otherwise add a
33
+ // cursor from the pointer click.
34
34
  requestAnimationFrame(() => {
35
+ view.focus();
35
36
  view.dispatch({
36
37
  selection: {
37
38
  anchor: from,
@@ -403,22 +404,29 @@ function findScopedDefinitionPosition(
403
404
  }
404
405
 
405
406
  /**
406
- * This function will select the first occurrence of the given variable name,
407
- * for a given editor view.
407
+ * This function selects a scoped definition for the given variable name, when
408
+ * a usage position is available, or optionally falls back to the first matching
409
+ * variable name in the given editor view.
408
410
  * @param view The editor view which contains the variable name.
409
411
  * @param variableName The name of the variable to select, if found in the editor.
410
412
  * @param usagePosition The position of the variable usage, if available.
413
+ * @param fallbackToFirstMatch Whether to fall back to the first matching
414
+ * variable name when no scoped definition is found. Defaults to true.
411
415
  */
412
416
  export function goToVariableDefinition(
413
417
  view: EditorView,
414
418
  variableName: string,
415
419
  usagePosition?: number,
420
+ fallbackToFirstMatch = true,
416
421
  ): boolean {
417
422
  const { state } = view;
418
- const from =
419
- (usagePosition !== undefined
420
- ? findScopedDefinitionPosition(state, variableName, usagePosition)
421
- : null) ?? findFirstMatchingVariable(state, variableName);
423
+ let from: number | null = null;
424
+ if (usagePosition !== undefined) {
425
+ from = findScopedDefinitionPosition(state, variableName, usagePosition);
426
+ }
427
+ if (from === null && fallbackToFirstMatch) {
428
+ from = findFirstMatchingVariable(state, variableName);
429
+ }
422
430
 
423
431
  if (from === null) {
424
432
  return false;
@@ -82,6 +82,7 @@ export function goToDefinition(
82
82
  view,
83
83
  variableName,
84
84
  usagePosition,
85
+ false,
85
86
  );
86
87
  if (foundLocally) {
87
88
  return true;
@@ -0,0 +1,30 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { toast } from "@/components/ui/use-toast";
4
+ import { createStaticRequests } from "../requests-static";
5
+
6
+ vi.mock("@/components/ui/use-toast", () => ({ toast: vi.fn() }));
7
+
8
+ describe("createStaticRequests static-notebook toast", () => {
9
+ beforeEach(() => {
10
+ vi.mocked(toast).mockClear();
11
+ });
12
+
13
+ it("requests a once-toast with a stable id on component value updates", async () => {
14
+ const requests = createStaticRequests();
15
+ await requests.sendComponentValues({} as never);
16
+
17
+ expect(toast).toHaveBeenCalledWith(
18
+ expect.objectContaining({ id: "static-notebook", once: true }),
19
+ );
20
+ });
21
+
22
+ it("uses the same once-toast for function requests", async () => {
23
+ const requests = createStaticRequests();
24
+ await requests.sendFunctionRequest({} as never);
25
+
26
+ expect(toast).toHaveBeenCalledWith(
27
+ expect.objectContaining({ id: "static-notebook", once: true }),
28
+ );
29
+ });
30
+ });
@@ -3,6 +3,18 @@ import { toast } from "@/components/ui/use-toast";
3
3
  import { Logger } from "@/utils/Logger";
4
4
  import type { EditRequests, RunRequests } from "./types";
5
5
 
6
+ const STATIC_NOTEBOOK_TOAST_ID = "static-notebook";
7
+
8
+ function showStaticNotebookToast() {
9
+ toast({
10
+ id: STATIC_NOTEBOOK_TOAST_ID,
11
+ once: true,
12
+ title: "Static notebook",
13
+ description:
14
+ "This notebook is not connected to a kernel. Any interactive elements will not work.",
15
+ });
16
+ }
17
+
6
18
  export function createStaticRequests(): EditRequests & RunRequests {
7
19
  const throwNotInEditMode = () => {
8
20
  throw new Error("Unreachable. Expected to be in run mode");
@@ -10,11 +22,7 @@ export function createStaticRequests(): EditRequests & RunRequests {
10
22
 
11
23
  return {
12
24
  sendComponentValues: async () => {
13
- toast({
14
- title: "Static notebook",
15
- description:
16
- "This notebook is not connected to a kernel. Any interactive elements will not work.",
17
- });
25
+ showStaticNotebookToast();
18
26
  Logger.log("Updating UI elements is not supported in static mode");
19
27
  return null;
20
28
  },
@@ -27,11 +35,7 @@ export function createStaticRequests(): EditRequests & RunRequests {
27
35
  return null;
28
36
  },
29
37
  sendFunctionRequest: async () => {
30
- toast({
31
- title: "Static notebook",
32
- description:
33
- "This notebook is not connected to a kernel. Any interactive elements will not work.",
34
- });
38
+ showStaticNotebookToast();
35
39
  Logger.log("Function requests are not supported in static mode");
36
40
  return null;
37
41
  },
@@ -98,7 +98,7 @@ const DownloadButton = ({
98
98
  try {
99
99
  const loadedData = await load({});
100
100
  downloadByURL(
101
- loadedData.data,
101
+ loadedData.data || data.data,
102
102
  loadedData.filename ?? data.filename ?? undefined,
103
103
  );
104
104
  } catch (error) {