@marimo-team/islands 0.26.1-dev105 → 0.26.1-dev108

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 (97) hide show
  1. package/dist/{ConnectedDataExplorerComponent-C6dY5fiI.js → ConnectedDataExplorerComponent-DQaiOY7w.js} +15 -15
  2. package/dist/{ErrorBoundary-Bn664FZa.js → ErrorBoundary-BW4TciqU.js} +19 -19
  3. package/dist/{abnfDiagram-VCTEODGH-Ba0MYVW8.js → abnfDiagram-VCTEODGH-Df80tEYq.js} +2 -2
  4. package/dist/{any-language-editor-BNe8do3C.js → any-language-editor-BW-gNmbk.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-7MqAehef.js → architectureDiagram-5GKGNRK7-DNNMvKkY.js} +1 -1
  6. package/dist/{assertNever-5vhHGKOK.js → assertNever-B9_7z-dW.js} +13 -13
  7. package/dist/{chat-ui-zGgiq5zN.js → chat-ui-Be9X-W22.js} +49 -49
  8. package/dist/{check-DUIc04aK.js → check-BqF09bSG.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-CAWA0HGB.js → chunk-IMKFNOWR-pXqnQ_fj.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-BIwVQjG5.js → chunk-SHT3W25Y-BWrxB3I2.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-Cux251TB.js → chunk-SVP7TREG-CPdQP8_U.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-DJVQ6khO.js → chunk-TICWLB2K-C5MYCwBz.js} +1 -1
  13. package/dist/{circle-question-mark-evCnVIut.js → circle-question-mark-YmLYXyvS.js} +1 -1
  14. package/dist/{classDiagram-ZZMXUADV-Cwve77ev.js → classDiagram-ZZMXUADV-Ba0SRm01.js} +2 -2
  15. package/dist/{classDiagram-v2-VYDZK3BY-BAeHKXmD.js → classDiagram-v2-VYDZK3BY-DSSzL_Dk.js} +2 -2
  16. package/dist/{code-visibility-CMgSFUs7.js → code-visibility-BKmktPMd.js} +18 -18
  17. package/dist/{common-DWnR77Qk.js → common-CSJAjJGa.js} +168 -168
  18. package/dist/{copy-icon-CmNLxT5_.js → copy-icon-zP4__HPI.js} +2 -2
  19. package/dist/{createReducer-m7yAXmDu.js → createReducer-CArOwUaJ.js} +1 -1
  20. package/dist/{cynefinDiagram-5FMLGOSQ-t4eEkPJh.js → cynefinDiagram-5FMLGOSQ-BOtNvA04.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-IuZuI28B.js → dagre-GXQ25YYZ-FpCEOTxX.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-zS1h3iMI.js → data-grid-overlay-editor-DTibdR4H.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-D8R5Q_ok.js → diagram-S7CK7UJ4-Cm1HaBuu.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-BGuMPsr-.js → diagram-UQ7AKVKN-D1lA7Ggu.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-BkTtpO8P.js → diagram-VX7I27RA-BX3e-Rue.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-C0__Mxfm.js → diagram-Z3DM3KII-Dgoj7bPf.js} +1 -1
  27. package/dist/{dialog-BvjfalZ9.js → dialog-DfKgafXJ.js} +30 -30
  28. package/dist/{dropdown-menu-D0DeN-aL.js → dropdown-menu-Dge_SmqE.js} +168 -168
  29. package/dist/{ebnfDiagram-PWID7BFC-CSESPZoz.js → ebnfDiagram-PWID7BFC-B0xWiXrz.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-DsDTtabH.js → erDiagram-RLTQ6QDP-Cm-GO31-.js} +1 -1
  31. package/dist/{error-banner-CXLjTW24.js → error-banner-CfYrJaIb.js} +91 -91
  32. package/dist/{error-entries-DVclFjaE.js → error-entries-23Z_1oDM.js} +584 -590
  33. package/dist/{export-context-CkgZeARR.js → export-context-B1jdxzHF.js} +21 -21
  34. package/dist/{feedback-button-BMGqp8Ff.js → feedback-button-CPu5SV3b.js} +72 -72
  35. package/dist/{flowDiagram-HODETNUW-qxDPYbfV.js → flowDiagram-HODETNUW-CH6xMlW_.js} +2 -2
  36. package/dist/{formats-CcQrzFo8.js → formats-Y52bg800.js} +1 -1
  37. package/dist/{glide-data-editor-Bra6h4KB.js → glide-data-editor-CC9_NDNi.js} +11 -11
  38. package/dist/{glide-utils-CD8BaFTm.js → glide-utils-BRcuSTCx.js} +2 -2
  39. package/dist/{globals-_bXqC0R8.js → globals-BFlYTNoR.js} +3 -3
  40. package/dist/{html-to-image-Cst4BlIm.js → html-to-image-Cw7o1IbE.js} +5073 -5076
  41. package/dist/{infoDiagram-27XIBGKW-B5hq8RM_.js → infoDiagram-27XIBGKW-DbUO63CX.js} +1 -1
  42. package/dist/{ishikawaDiagram-5VMMS53U-DkHc_9ET.js → ishikawaDiagram-5VMMS53U-CfQrrELH.js} +1 -1
  43. package/dist/{kanban-definition-UXKFOSKX-CqkTFXmU.js → kanban-definition-UXKFOSKX-C5SJcu1W.js} +1 -1
  44. package/dist/{loader-CGrYn73j.js → loader-C9-qRO3m.js} +2 -2
  45. package/dist/main.js +6696 -6602
  46. package/dist/{mermaid-pmVHDUQA.js → mermaid-C2alqcd8.js} +34 -34
  47. package/dist/{mindmap-definition-YA3MSWOX-D6cNa__z.js → mindmap-definition-YA3MSWOX-ByVHE0Ax.js} +1 -1
  48. package/dist/{number-overlay-editor-XLUhOVa7.js → number-overlay-editor-qDcRKPE0.js} +1 -1
  49. package/dist/{pegDiagram-XKGWAZYB-CmWJX_s1.js → pegDiagram-XKGWAZYB-DF5FBKZi.js} +2 -2
  50. package/dist/{pencil-CxMgOe04.js → pencil-D7jyZPnP.js} +1 -1
  51. package/dist/{pieDiagram-E7YTZNPT-CAQAxHah.js → pieDiagram-E7YTZNPT-B5n9nBQN.js} +1 -1
  52. package/dist/{process-output-DizFa5IE.js → process-output-DdBM0lmd.js} +4 -4
  53. package/dist/{railroadDiagram-O6MQD6OU-jlSsiQg3.js → railroadDiagram-O6MQD6OU-r5t7OYNE.js} +2 -2
  54. package/dist/{requirementDiagram-BXWQKSXE-DkDjfPhn.js → requirementDiagram-BXWQKSXE-D4QtEyZQ.js} +1 -1
  55. package/dist/{reveal-component-llpC324_.js → reveal-component-BE1xhtNc.js} +1008 -1008
  56. package/dist/{select-CEnB18uc.js → select-Buk3aXi1.js} +341 -341
  57. package/dist/{sequenceDiagram-WJ2MYXX4-DLywsGCW.js → sequenceDiagram-WJ2MYXX4-CK3Atn-z.js} +1 -1
  58. package/dist/{spec-Dz-Avv1m.js → spec-BEp9O9dy.js} +4 -4
  59. package/dist/{stateDiagram-D77RDMKH-DUmlKwYU.js → stateDiagram-D77RDMKH-C1SxRI8V.js} +2 -2
  60. package/dist/{stateDiagram-v2-MP3YSRHH-D646KiXs.js → stateDiagram-v2-MP3YSRHH-DK5X6bsr.js} +2 -2
  61. package/dist/{static-state-iw0PrHK4.js → static-state-D-aT9dOr.js} +9 -9
  62. package/dist/{swimlanes-42K2YHIH-L7B1GphF.js → swimlanes-42K2YHIH-DdH5TZdu.js} +1 -1
  63. package/dist/{swimlanesDiagram-VR7AAH4N-DEu2wxtC.js → swimlanesDiagram-VR7AAH4N-CWBIvzgR.js} +2 -2
  64. package/dist/{timeline-definition-24CTP7MA-DDPyx1yG.js → timeline-definition-24CTP7MA-DE7-o2zU.js} +1 -1
  65. package/dist/{toast-BTjH6fIf.js → toast-b3k4YxaT.js} +54 -54
  66. package/dist/{tooltip-DyLdBIM4.js → tooltip-D-9pDheN.js} +62 -62
  67. package/dist/{use-restore-focus-DJ_-uSn_.js → use-restore-focus-CCfk-ey2.js} +1 -1
  68. package/dist/{useDateFormatter-HpKD0jEC.js → useDateFormatter-DH0uFwfL.js} +2 -2
  69. package/dist/{useDeepCompareMemoize-CHx-NxMl.js → useDeepCompareMemoize-Dn-ZJVTd.js} +1 -1
  70. package/dist/{useLifecycle-tPpAt-OE.js → useLifecycle-yjK7JsRL.js} +1 -1
  71. package/dist/{vega-component-BzNDFvQf.js → vega-component-BIq0qzhQ.js} +8 -8
  72. package/dist/{vennDiagram-4TSXK5OY-CRwWeb7g.js → vennDiagram-4TSXK5OY-D7yfNz0d.js} +1 -1
  73. package/dist/{wardleyDiagram-VM6X3IG4-DVlG9eoq.js → wardleyDiagram-VM6X3IG4-m5Jcz26Z.js} +1 -1
  74. package/dist/{xychartDiagram-S5SC5T6Z-CM32AISp.js → xychartDiagram-S5SC5T6Z-CA3zV3RW.js} +1 -1
  75. package/package.json +1 -1
  76. package/src/__mocks__/intersection-observer.ts +13 -12
  77. package/src/components/editor/Output.tsx +1 -1
  78. package/src/components/editor/__tests__/cell-renders.test.tsx +17 -1
  79. package/src/components/editor/chrome/panels/outline/__tests__/outline-keyboard.test.tsx +517 -68
  80. package/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.ts +17 -5
  81. package/src/components/editor/chrome/panels/outline/floating-outline.tsx +29 -59
  82. package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +333 -133
  83. package/src/components/editor/chrome/panels/outline-panel.tsx +5 -19
  84. package/src/components/editor/notebook-cell.tsx +263 -267
  85. package/src/core/cells/__tests__/layout.test.ts +1 -1
  86. package/src/core/cells/__tests__/notebook-outline.test.ts +31 -3
  87. package/src/core/cells/cells.ts +21 -14
  88. package/src/core/cells/outline.ts +8 -8
  89. package/src/core/codemirror/language/extension.ts +6 -3
  90. package/src/core/codemirror/language/panel/panel.test.tsx +144 -0
  91. package/src/core/codemirror/language/panel/panel.tsx +9 -6
  92. package/src/core/codemirror/react-dom/createPanel.tsx +15 -15
  93. package/src/core/dom/__tests__/outline.test.ts +29 -170
  94. package/src/core/dom/outline.ts +21 -61
  95. package/src/core/executions/atoms.ts +12 -4
  96. package/src/core/islands/components/output-wrapper.tsx +7 -2
  97. package/src/plugins/layout/OutlinePlugin.tsx +5 -17
@@ -7,6 +7,7 @@ import { MockNotebook } from "@/__mocks__/notebook";
7
7
  import { cellId } from "@/__tests__/branded";
8
8
  import { CONFIG } from "@/core/notebook/document/__tests__/fixtures";
9
9
  import {
10
+ cellOutlinesAtom,
10
11
  createNotebookActions,
11
12
  notebookAtom,
12
13
  notebookOutline,
@@ -21,8 +22,8 @@ function showed(id: string, html: string) {
21
22
  return MockExecutions.shown(id, { mimetype: "text/html", data: html });
22
23
  }
23
24
 
24
- const firstItem = { name: "First", level: 1, by: { id: "first" } };
25
- const secondItem = { name: "Second", level: 2, by: { id: "second" } };
25
+ const firstItem = { name: "First", level: 1, id: "first", cellId: first };
26
+ const secondItem = { name: "Second", level: 2, id: "second", cellId: second };
26
27
 
27
28
  function setup() {
28
29
  const store = createStore();
@@ -56,6 +57,33 @@ describe("notebookOutline", () => {
56
57
  });
57
58
  });
58
59
 
60
+ it("keeps each store's outline identities independent", () => {
61
+ const firstNotebook = setup();
62
+ const secondNotebook = setup();
63
+ const outlines = firstNotebook.store.get(cellOutlinesAtom);
64
+ const outline = firstNotebook.store.get(notebookOutline);
65
+ expect(secondNotebook.store.get(cellOutlinesAtom)).toEqual(outlines);
66
+ expect(secondNotebook.store.get(cellOutlinesAtom)).not.toBe(outlines);
67
+
68
+ secondNotebook.report([showed(first, "<h1>Different heading</h1>")]);
69
+
70
+ expect(firstNotebook.store.get(cellOutlinesAtom)).toBe(outlines);
71
+ expect(firstNotebook.store.get(notebookOutline)).toBe(outline);
72
+ expect(
73
+ secondNotebook.store.get(notebookOutline).items.map(({ name }) => name),
74
+ ).toEqual(["Different heading"]);
75
+ });
76
+
77
+ it("returns an empty outline in a runtime without DOMParser", () => {
78
+ vi.stubGlobal("DOMParser", undefined);
79
+ try {
80
+ const { store } = setup();
81
+ expect(store.get(notebookOutline)).toEqual({ items: [] });
82
+ } finally {
83
+ vi.unstubAllGlobals();
84
+ }
85
+ });
86
+
59
87
  it("does not notify outline subscribers when cell code changes", () => {
60
88
  const { store } = setup();
61
89
  const initial = store.get(notebookOutline);
@@ -83,7 +111,7 @@ describe("notebookOutline", () => {
83
111
  showed(second, '<h2 id="second">Second</h2>'),
84
112
  ]);
85
113
  expect(store.get(notebookOutline)).toEqual({
86
- items: [{ name: "Updated", level: 1, by: { id: "updated" } }, secondItem],
114
+ items: [{ ...firstItem, name: "Updated", id: "updated" }, secondItem],
87
115
  });
88
116
 
89
117
  report([showed(second, '<h2 id="second">Second</h2>')]);
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type { EditorView } from "@codemirror/view";
4
4
  import type * as Protocol from "@marimo-team/client/protocol";
5
+ import { dequal } from "dequal";
5
6
  import { type Atom, atom, useAtom, useAtomValue } from "jotai";
6
7
  import { atomFamily, selectAtom, splitAtom } from "jotai/utils";
7
8
  import { createRef, type ReducerWithoutAction } from "react";
@@ -17,6 +18,7 @@ import {
17
18
  releaseCellOutputAtoms,
18
19
  } from "@/core/executions";
19
20
  import type { CellColumnId } from "./layout";
21
+ import { Functions } from "@/utils/functions";
20
22
  import { invariant } from "@/utils/invariant";
21
23
  import { Logger } from "@/utils/Logger";
22
24
  import { Objects } from "@/utils/objects";
@@ -25,7 +27,6 @@ import { createReducerAndAtoms } from "../../utils/createReducer";
25
27
  import { foldAllBulk, unfoldAllBulk } from "../codemirror/editing/commands";
26
28
  import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
27
29
  import type { SerializedEditorState } from "../codemirror/types";
28
- import { mergeOutlines } from "../dom/outline";
29
30
  import { activeNotebookFrameAtom } from "../session/active-notebook";
30
31
  import { isErrorMime } from "../mime";
31
32
  import { createDeepEqualAtom, store } from "../state/jotai";
@@ -40,7 +41,7 @@ import { applyDocument } from "./document";
40
41
  import { isCodeHidden, shownHiddenCodeAtom } from "./editor";
41
42
  import { type CellId, SCRATCH_CELL_ID } from "./ids";
42
43
  import { type CellLog, getCellLogsForMessage } from "./logs";
43
- import type { Outline } from "./outline";
44
+ import type { NotebookOutlineItem, Outline } from "./outline";
44
45
  import { focusAndScrollCellIntoView } from "./scrollCellIntoView";
45
46
  import {
46
47
  type CellData,
@@ -475,28 +476,34 @@ export const cellErrorsAtom = atom((get) => {
475
476
  return errors;
476
477
  });
477
478
 
478
- /**
479
- * The outline of each cell whose output has a heading. Compared by value, so
480
- * readers are left alone by the runs that change no heading.
481
- */
482
- export const cellOutlinesAtom = createDeepEqualAtom(
479
+ // Layout needs lookup by cell ID. Navigation needs the same headings in document order.
480
+ const orderedCellOutlines = selectAtom(
483
481
  atom((get) => {
484
- const outlines: Partial<Record<CellId, Outline>> = {};
482
+ const entries: [CellId, Outline][] = [];
485
483
  for (const cellId of get(cellIdsAtom)) {
486
484
  const outline = get(cellOutlineAtom(cellId));
487
- if (outline !== null && outline.items.length > 0) {
488
- outlines[cellId] = outline;
485
+ if (outline && outline.items.length > 0) {
486
+ entries.push([cellId, outline]);
489
487
  }
490
488
  }
491
- return outlines;
489
+ return entries;
492
490
  }),
491
+ Functions.identity,
492
+ dequal,
493
493
  );
494
494
 
495
- /** The notebook's table of contents, in document order. */
496
- export const notebookOutline = atom((get) =>
497
- mergeOutlines(get(cellIdsAtom).map((cellId) => get(cellOutlineAtom(cellId)))),
495
+ export const cellOutlinesAtom = selectAtom(
496
+ orderedCellOutlines,
497
+ (entries): Partial<Record<CellId, Outline>> => Object.fromEntries(entries),
498
+ dequal,
498
499
  );
499
500
 
501
+ export const notebookOutline = selectAtom(orderedCellOutlines, (entries) => ({
502
+ items: entries.flatMap<NotebookOutlineItem>(([cellId, outline]) =>
503
+ outline.items.map((item) => ({ ...item, cellId })),
504
+ ),
505
+ }));
506
+
500
507
  export const cellErrorCount = atom((get) => get(cellErrorsAtom).length);
501
508
 
502
509
  export const cellIdToNamesMap = createDeepEqualAtom(
@@ -1,5 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import type { CellId } from "./ids";
4
+
3
5
  /**
4
6
  * Table of contents outline.
5
7
  */
@@ -14,14 +16,8 @@ export interface OutlineItem {
14
16
  * render this instead of the plain-text `name`.
15
17
  */
16
18
  html?: string;
17
- /**
18
- * Locator of the item.
19
- *
20
- * If `id` is provided, the item is located by #id.
21
- *
22
- * If `path` is provided, the item is located by xpath.
23
- */
24
- by: { id: string } | { path: string };
19
+ /** The heading's ID, if present. Otherwise, match by name and level. */
20
+ id?: string;
25
21
  /**
26
22
  * The level of the item.
27
23
  * h1 -> 1
@@ -34,3 +30,7 @@ export interface OutlineItem {
34
30
  export interface Outline {
35
31
  items: OutlineItem[];
36
32
  }
33
+
34
+ export interface NotebookOutlineItem extends OutlineItem {
35
+ cellId: CellId;
36
+ }
@@ -33,7 +33,10 @@ import { getLanguageAdapters, LanguageAdapters } from "./LanguageAdapters";
33
33
  import { sqlDialectEffect } from "./languages/sql/sql";
34
34
  import type { LanguageMetadata } from "./metadata";
35
35
  import { languageMetadataField, setLanguageMetadata } from "./metadata";
36
- import { LanguagePanelComponent } from "./panel/panel";
36
+ import {
37
+ LanguagePanelComponent,
38
+ languagePanelInputsChanged,
39
+ } from "./panel/panel";
37
40
  import type { LanguageAdapter } from "./types";
38
41
  import { getEditorCodeAsPython } from "./utils";
39
42
 
@@ -89,13 +92,13 @@ export const languageAdapterState = StateField.define<LanguageAdapter>({
89
92
  }
90
93
  return value;
91
94
  },
92
- // Only show the panel if the language is not python
93
95
  provide: (field) =>
94
96
  showPanel.from(field, (value) => {
95
97
  if (value.type === "python") {
96
98
  return null;
97
99
  }
98
- return (view) => createPanel(view, LanguagePanelComponent);
100
+ return (view) =>
101
+ createPanel(view, LanguagePanelComponent, languagePanelInputsChanged);
99
102
  }),
100
103
  });
101
104
 
@@ -0,0 +1,144 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { Compartment } from "@codemirror/state";
4
+ import { EditorView } from "@codemirror/view";
5
+ import { act, fireEvent, within } from "@testing-library/react";
6
+ import type { createRoot, Root } from "react-dom/client";
7
+ import { describe, expect, it, onTestFinished, vi } from "vitest";
8
+ import { DATA_FOR_CELL_ID } from "@/components/data-table/cell-utils";
9
+ import { CellId } from "@/core/cells/ids";
10
+ import { cellIdState } from "@/core/codemirror/cells/state";
11
+ import { cellConfigExtension } from "@/core/codemirror/config/extension";
12
+ import { defaultUserConfig } from "@/core/config/config-schema";
13
+ import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
14
+ import { adaptiveLanguageConfiguration, switchLanguage } from "../extension";
15
+ import { languageMetadataField, updateLanguageMetadata } from "../metadata";
16
+
17
+ const trackRoot = vi.hoisted(() => vi.fn<(root: Root) => void>());
18
+
19
+ vi.mock("react-dom/client", async (importOriginal) => {
20
+ const original = await importOriginal<typeof import("react-dom/client")>();
21
+ return {
22
+ ...original,
23
+ createRoot: (...args: Parameters<typeof createRoot>) => {
24
+ const root = original.createRoot(...args);
25
+ vi.spyOn(root, "render");
26
+ vi.spyOn(root, "unmount");
27
+ trackRoot(root);
28
+ return root;
29
+ },
30
+ };
31
+ });
32
+
33
+ vi.mock("@/components/editor/connections/components", () => ({
34
+ useAddDetectedDataSource: () => vi.fn(),
35
+ }));
36
+
37
+ const config = defaultUserConfig();
38
+ const options = {
39
+ cellId: CellId.create(),
40
+ completionConfig: config.completion,
41
+ lspConfig: config.language_servers,
42
+ diagnosticsConfig: config.diagnostics,
43
+ hotkeys: new OverridingHotkeyProvider({}),
44
+ placeholderType: "marimo-import" as const,
45
+ };
46
+
47
+ const cellId = new Compartment();
48
+
49
+ async function mountPanel(language: "markdown" | "sql") {
50
+ const view = new EditorView({
51
+ parent: document.body,
52
+ doc:
53
+ language === "markdown" ? 'mo.md(r"hello")' : 'df = mo.sql("select 1")',
54
+ extensions: [
55
+ cellConfigExtension(options),
56
+ cellId.of(cellIdState.of(options.cellId)),
57
+ adaptiveLanguageConfiguration(options),
58
+ ],
59
+ });
60
+ onTestFinished(() => act(() => view.destroy()));
61
+ await act(() => switchLanguage(view, { language }));
62
+ const [root] = trackRoot.mock.calls[0];
63
+ return { view, root, panel: within(view.dom) };
64
+ }
65
+
66
+ describe("language panel renders", () => {
67
+ it.each(["markdown", "sql"] as const)(
68
+ "renders %s once across selection and document edits",
69
+ async (language) => {
70
+ const { view, root } = await mountPanel(language);
71
+ expect(root.render).toHaveBeenCalledTimes(1);
72
+
73
+ await act(() => {
74
+ view.dispatch({ selection: { anchor: 1 } });
75
+ view.dispatch({ changes: { from: 0, insert: "x" } });
76
+ });
77
+
78
+ expect(trackRoot).toHaveBeenCalledTimes(1);
79
+ expect(root.render).toHaveBeenCalledTimes(1);
80
+ },
81
+ );
82
+
83
+ it("updates the Markdown prefix when the checkbox changes", async () => {
84
+ const { view, panel } = await mountPanel("markdown");
85
+ const checkbox = panel.getByRole("checkbox", { name: "Toggle f-string" });
86
+ expect(checkbox).not.toBeChecked();
87
+ fireEvent.click(checkbox);
88
+ expect(view.state.field(languageMetadataField).quotePrefix).toContain("f");
89
+ expect(checkbox).toBeChecked();
90
+ });
91
+
92
+ it("defaults a missing Markdown prefix to raw", async () => {
93
+ const { view, panel } = await mountPanel("markdown");
94
+ await act(() =>
95
+ view.dispatch({
96
+ effects: updateLanguageMetadata.of({ quotePrefix: undefined }),
97
+ }),
98
+ );
99
+ expect(view.state.field(languageMetadataField).quotePrefix).toBe("r");
100
+ expect(
101
+ panel.getByRole("checkbox", { name: "Toggle raw string" }),
102
+ ).toBeChecked();
103
+ });
104
+
105
+ it("updates the SQL hide-output control when metadata changes", async () => {
106
+ const { view, panel } = await mountPanel("sql");
107
+ const output = panel.getByRole("checkbox", { name: "Hide output" });
108
+ expect(output).not.toBeChecked();
109
+ await act(() =>
110
+ view.dispatch({
111
+ effects: updateLanguageMetadata.of({ showOutput: false }),
112
+ }),
113
+ );
114
+ expect(output).toBeChecked();
115
+ });
116
+
117
+ it("updates the SQL engine selector when only the cell ID changes", async () => {
118
+ const { view, panel } = await mountPanel("sql");
119
+ const selector = panel.getByRole("combobox");
120
+ expect(selector).toHaveAttribute(DATA_FOR_CELL_ID, options.cellId);
121
+ const nextId = CellId.create();
122
+ await act(() =>
123
+ view.dispatch({
124
+ effects: cellId.reconfigure(cellIdState.of(nextId)),
125
+ }),
126
+ );
127
+ expect(selector).toHaveAttribute(DATA_FOR_CELL_ID, nextId);
128
+ });
129
+
130
+ it("replaces the SQL panel for Markdown and removes it for Python", async () => {
131
+ const { view, root, panel } = await mountPanel("sql");
132
+ await act(() => switchLanguage(view, { language: "markdown" }));
133
+ expect(root.unmount).toHaveBeenCalledTimes(1);
134
+ expect(trackRoot).toHaveBeenCalledTimes(2);
135
+ expect(
136
+ panel.getByRole("checkbox", { name: "Toggle f-string" }),
137
+ ).toBeInTheDocument();
138
+
139
+ const [markdownRoot] = trackRoot.mock.calls[1];
140
+ await act(() => switchLanguage(view, { language: "python" }));
141
+ expect(markdownRoot.unmount).toHaveBeenCalledTimes(1);
142
+ expect(view.dom.querySelector(".cm-panel")).toBeNull();
143
+ });
144
+ });
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
- import type { EditorView } from "@codemirror/view";
2
+ import type { EditorView, ViewUpdate } from "@codemirror/view";
3
3
  import type { QuotePrefixKind } from "@marimo-team/smart-cells";
4
4
  import { InfoIcon, PaintRollerIcon } from "lucide-react";
5
5
  import { Button } from "@/components/ui/button";
@@ -25,6 +25,14 @@ import type { LanguageMetadataOf } from "../types";
25
25
  import { getQuotePrefix, MarkdownQuotePrefixTooltip } from "./markdown";
26
26
  import { SQLEngineSelect, SQLModeSelect } from "./sql";
27
27
 
28
+ export function languagePanelInputsChanged(update: ViewUpdate): boolean {
29
+ return (
30
+ update.startState.field(languageMetadataField) !==
31
+ update.state.field(languageMetadataField) ||
32
+ update.startState.facet(cellIdState) !== update.state.facet(cellIdState)
33
+ );
34
+ }
35
+
28
36
  const Divider = () => <div className="h-4 border-r border-border" />;
29
37
 
30
38
  export const LanguagePanelComponent: React.FC<{
@@ -58,7 +66,6 @@ export const LanguagePanelComponent: React.FC<{
58
66
  const sanitizeAndTriggerUpdate = (
59
67
  e: React.SyntheticEvent<HTMLInputElement>,
60
68
  ) => {
61
- // Normalize the name to a valid variable name
62
69
  const name = normalizeName(e.currentTarget.value, false);
63
70
  e.currentTarget.value = name;
64
71
 
@@ -79,9 +86,6 @@ export const LanguagePanelComponent: React.FC<{
79
86
  <input
80
87
  {...inputProps}
81
88
  defaultValue={metadata.dataframeName}
82
- onChange={(e) => {
83
- inputProps.onChange?.(e);
84
- }}
85
89
  onBlur={sanitizeAndTriggerUpdate}
86
90
  onKeyDown={(e) => {
87
91
  if (e.key === "Enter" && e.shiftKey) {
@@ -136,7 +140,6 @@ export const LanguagePanelComponent: React.FC<{
136
140
  const metadata = view.state.field(languageMetadataField) as Metadata2;
137
141
  let { quotePrefix } = metadata;
138
142
 
139
- // Handle the case where the quote prefix is not set
140
143
  if (quotePrefix === undefined) {
141
144
  quotePrefix = "r";
142
145
  triggerUpdate<Metadata2>({ quotePrefix });
@@ -1,36 +1,36 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import type { EditorView, Panel } from "@codemirror/view";
3
+ import type { EditorView, Panel, ViewUpdate } from "@codemirror/view";
4
4
  import { Provider } from "jotai";
5
5
  import { createRoot, type Root } from "react-dom/client";
6
6
  import { store } from "@/core/state/jotai";
7
7
 
8
- /**
9
- * Bridge between Codemirror panels and React
10
- */
11
8
  export function createPanel(
12
9
  view: EditorView,
13
10
  Component: React.ComponentType<{ view: EditorView }>,
11
+ shouldRender: (update: ViewUpdate) => boolean = () => true,
14
12
  ): Panel {
15
13
  const dom = document.createElement("div");
16
14
  let root: Root | undefined;
17
15
 
16
+ const render = () => {
17
+ root?.render(
18
+ <Provider store={store}>
19
+ <Component view={view} />
20
+ </Provider>,
21
+ );
22
+ };
23
+
18
24
  return {
19
25
  dom,
20
26
  mount() {
21
27
  root = createRoot(dom);
22
- root.render(
23
- <Provider store={store}>
24
- <Component view={view} />
25
- </Provider>,
26
- );
28
+ render();
27
29
  },
28
- update() {
29
- root?.render(
30
- <Provider store={store}>
31
- <Component view={view} />
32
- </Provider>,
33
- );
30
+ update(update) {
31
+ if (shouldRender(update)) {
32
+ render();
33
+ }
34
34
  },
35
35
  destroy() {
36
36
  root?.unmount();