@marimo-team/islands 0.26.1-dev1 → 0.26.1-dev15

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 (142) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DtwVgVpX.js → ConnectedDataExplorerComponent-CR9WyiEc.js} +11 -11
  2. package/dist/{ErrorBoundary-CnVR4XMW.js → ErrorBoundary-BQXI85CA.js} +7 -7
  3. package/dist/{abnfDiagram-VCTEODGH-BbZOIueZ.js → abnfDiagram-VCTEODGH-DGAbsdXT.js} +2 -2
  4. package/dist/{any-language-editor-yG-YmLaK.js → any-language-editor-DzGF1ll-.js} +5 -5
  5. package/dist/{architectureDiagram-5GKGNRK7-qjLjxapm.js → architectureDiagram-5GKGNRK7-D4DnIo7R.js} +1 -1
  6. package/dist/{assertNever-DywGMo-S.js → assertNever-CqwxSD_2.js} +3 -3
  7. package/dist/{button-qQhINE7z.js → button-Z2R2272J.js} +34 -31
  8. package/dist/{capabilities-DKqMqBzm.js → capabilities-ba3Dyv8n.js} +1 -1
  9. package/dist/{chat-ui-D5YPIONI.js → chat-ui-b1ERxzeA.js} +17 -17
  10. package/dist/{check-jchHMCfs.js → check-D9vf6LYF.js} +1 -1
  11. package/dist/{chunk-IMKFNOWR-BzDY1_I7.js → chunk-IMKFNOWR-Bc_i6jWx.js} +1 -1
  12. package/dist/{chunk-SHT3W25Y-DbHsMKdo.js → chunk-SHT3W25Y-CGML5pnF.js} +1 -1
  13. package/dist/{chunk-SVP7TREG-CtwnwAE6.js → chunk-SVP7TREG-ZpeFKfFT.js} +1 -1
  14. package/dist/{chunk-TICWLB2K-C5Z5QMbO.js → chunk-TICWLB2K-C6cLmcg8.js} +1 -1
  15. package/dist/{classDiagram-ZZMXUADV-B8E5Hn78.js → classDiagram-ZZMXUADV--q40NTXr.js} +2 -2
  16. package/dist/{classDiagram-v2-VYDZK3BY-DeGsK9bT.js → classDiagram-v2-VYDZK3BY-Dt_Pp94L.js} +2 -2
  17. package/dist/{code-visibility-Cs-o5weM.js → code-visibility-B_n3GMdg.js} +6 -6
  18. package/dist/{common-C92_m-1k.js → common-BPgO2zo6.js} +41 -41
  19. package/dist/{config-qTaTHnpE.js → config-B8JCQMby.js} +4 -4
  20. package/dist/{copy-icon-BI7vZHEW.js → copy-icon-BLig0ZKb.js} +3 -3
  21. package/dist/{createReducer-DdSLRfBT.js → createReducer-BIUQ3TbG.js} +2 -2
  22. package/dist/{cynefinDiagram-5FMLGOSQ-NDedRwsw.js → cynefinDiagram-5FMLGOSQ-2FtF_-cc.js} +1 -1
  23. package/dist/{dagre-GXQ25YYZ-De0sSZO7.js → dagre-GXQ25YYZ-Cymu2SPS.js} +1 -1
  24. package/dist/{data-grid-overlay-editor-D32Gn15n.js → data-grid-overlay-editor-B5aHiI2o.js} +5 -5
  25. package/dist/{data-grid-types-DIX_pCco.js → data-grid-types-DBNnjiYJ.js} +2 -2
  26. package/dist/{diagram-S7CK7UJ4-wBtVl61y.js → diagram-S7CK7UJ4-OwDa8kAa.js} +1 -1
  27. package/dist/{diagram-UQ7AKVKN-CKWE3c1T.js → diagram-UQ7AKVKN-CzRDwZwd.js} +1 -1
  28. package/dist/{diagram-VX7I27RA-D2Ac5198.js → diagram-VX7I27RA-XRIcgMDs.js} +1 -1
  29. package/dist/{diagram-Z3DM3KII-CYaFOQcI.js → diagram-Z3DM3KII-DdRDYAs6.js} +1 -1
  30. package/dist/{dialog-Ic6dh09m.js → dialog-DGh2HNAO.js} +3 -3
  31. package/dist/{dist-BvZpdAuG.js → dist-6B1_Ttbh.js} +1 -1
  32. package/dist/{dist-D1D56-GS.js → dist-B28poF32.js} +2 -2
  33. package/dist/{dist-BozTF_gH.js → dist-BBZ7lnMw.js} +2 -2
  34. package/dist/{dist-BfrgytDR.js → dist-BD8ZKF5t.js} +3 -3
  35. package/dist/{dist-DNkrY12t.js → dist-BG-7Qpaj.js} +3 -3
  36. package/dist/{dist-D92tYjLc.js → dist-BIaGGUbU.js} +13 -11
  37. package/dist/{dist-BagHbFqG.js → dist-BR5PU2Ph.js} +3 -3
  38. package/dist/{dist-DpYpG8Yc.js → dist-BidYR5m4.js} +3 -3
  39. package/dist/{dist-D95Cd4xm.js → dist-BkGYCvFX.js} +3 -3
  40. package/dist/{dist-DneeBk3K.js → dist-BmEyXT7K.js} +2 -2
  41. package/dist/{dist-BdUitvVW.js → dist-Bt0Wt6m9.js} +2 -2
  42. package/dist/{dist-CEomphG1.js → dist-CG2Sl0D4.js} +2 -2
  43. package/dist/{dist-BMz__bo5.js → dist-CQfpgadU.js} +3 -3
  44. package/dist/{dist-BreKIQqQ.js → dist-CVOPvfzN.js} +3 -3
  45. package/dist/{dist-BEcpQbZa.js → dist-Cm0iCeQQ.js} +3 -3
  46. package/dist/{dist-CDVvitRS.js → dist-Cnc14jEq.js} +2 -2
  47. package/dist/{dist-ChcBm3jk.js → dist-D3KPC38e.js} +4 -4
  48. package/dist/{dist-B1qu3Bez.js → dist-D7BXk27E.js} +3 -3
  49. package/dist/{dist-BsE4gQHj.js → dist-D9Qhvxvg.js} +1 -1
  50. package/dist/{dist-OmeAz0fR.js → dist-DJKajXDB.js} +3 -3
  51. package/dist/{dist-ObeTgSmf.js → dist-DYbNRTYG.js} +4 -4
  52. package/dist/{dist-Cshl6jBw.js → dist-DhtDWnzK.js} +2 -2
  53. package/dist/{dist-BunZKA_9.js → dist-_x2Jks2R.js} +2 -2
  54. package/dist/{dist-MggMo7OR.js → dist-m0MWV-aw.js} +1 -1
  55. package/dist/{dist-TGSwzj8a.js → dist-pPbYNVjd.js} +4 -4
  56. package/dist/{dropdown-menu-Dhv4fcNl.js → dropdown-menu-ChH3oiqI.js} +6 -6
  57. package/dist/{ebnfDiagram-PWID7BFC-Ds7f42dj.js → ebnfDiagram-PWID7BFC-CZMNMGNP.js} +2 -2
  58. package/dist/{erDiagram-RLTQ6QDP-b58Sz2Mc.js → erDiagram-RLTQ6QDP-ByxHAN4b.js} +1 -1
  59. package/dist/{error-banner-CJVLr5_a.js → error-banner-BvRaQnGH.js} +22 -22
  60. package/dist/{error-entries-BKlEsuk4.js → error-entries-Bl8fzLQc.js} +11 -11
  61. package/dist/{esm-B9n0caHs.js → esm-DY8dGAjJ.js} +23 -23
  62. package/dist/{esm-Bwp_FHP0.js → esm-Dw2ZydG_.js} +3 -3
  63. package/dist/{feedback-button-HXizISwe.js → feedback-button-C5zljLS1.js} +8 -8
  64. package/dist/{flowDiagram-HODETNUW-BH9U7VZK.js → flowDiagram-HODETNUW-BQpzWx5O.js} +2 -2
  65. package/dist/{formats-BLNFWWhV.js → formats-BxP8k8Un.js} +3 -3
  66. package/dist/{glide-data-editor-Cha2TqyF.js → glide-data-editor-Cy67HDvb.js} +59 -59
  67. package/dist/{glide-utils-Cn2_NadX.js → glide-utils-bKdvDwwo.js} +4 -4
  68. package/dist/{globals-C4qZtAQ0.js → globals-CXef1w1d.js} +3 -3
  69. package/dist/{html-to-image-CNM0ZSFD.js → html-to-image-D6A1lg0A.js} +3471 -3367
  70. package/dist/{infoDiagram-27XIBGKW-xbjwrcNi.js → infoDiagram-27XIBGKW-C9EWHkak.js} +1 -1
  71. package/dist/{ishikawaDiagram-5VMMS53U-DKtukhGS.js → ishikawaDiagram-5VMMS53U-D67SGFvp.js} +1 -1
  72. package/dist/{kanban-definition-UXKFOSKX-BEhlkZBb.js → kanban-definition-UXKFOSKX-CTMTiazR.js} +1 -1
  73. package/dist/{loader-Bin_dutt.js → loader-qPmiRXZd.js} +1 -1
  74. package/dist/main.js +5808 -5783
  75. package/dist/{mermaid-D1CZDNoB.js → mermaid-DE_tvTGF.js} +35 -35
  76. package/dist/{mindmap-definition-YA3MSWOX-DQcnJPcV.js → mindmap-definition-YA3MSWOX-LzNgDy8O.js} +1 -1
  77. package/dist/{number-overlay-editor-BVmdbAY7.js → number-overlay-editor-CxhKunPL.js} +3 -3
  78. package/dist/{pegDiagram-XKGWAZYB-BFQuPYfI.js → pegDiagram-XKGWAZYB-DFMS6feI.js} +2 -2
  79. package/dist/{pencil-DVYzq-iR.js → pencil-CHkdsX07.js} +1 -1
  80. package/dist/{pieDiagram-E7YTZNPT-l7aqNrem.js → pieDiagram-E7YTZNPT-C0MSBop-.js} +1 -1
  81. package/dist/{process-output-DthYR2Te.js → process-output-w5omHedc.js} +4 -4
  82. package/dist/{railroadDiagram-O6MQD6OU-6R3C1lwQ.js → railroadDiagram-O6MQD6OU-mbdav2pV.js} +2 -2
  83. package/dist/{requirementDiagram-BXWQKSXE-DdWYu8fn.js → requirementDiagram-BXWQKSXE-C1HNBBO6.js} +1 -1
  84. package/dist/{reveal-component-B8gTDFli.js → reveal-component-CWzW-8vE.js} +20 -20
  85. package/dist/{select-CDUxhHZg.js → select-CvorIE3l.js} +35 -35
  86. package/dist/{sequenceDiagram-WJ2MYXX4-Dzp0dgRc.js → sequenceDiagram-WJ2MYXX4-D6gBHifq.js} +1 -1
  87. package/dist/{spec-ZAt4P01J.js → spec-ayzaXGVq.js} +4 -4
  88. package/dist/{stateDiagram-D77RDMKH-BGnTUhFJ.js → stateDiagram-D77RDMKH-Bx-fTtRZ.js} +2 -2
  89. package/dist/{stateDiagram-v2-MP3YSRHH-DsJbmDf1.js → stateDiagram-v2-MP3YSRHH-Cec8T2yO.js} +2 -2
  90. package/dist/{static-state-C4bAlKTU.js → static-state-CqwW3B_X.js} +1 -1
  91. package/dist/{swimlanes-42K2YHIH-Bd4Bzh9r.js → swimlanes-42K2YHIH-C2bAgnov.js} +1 -1
  92. package/dist/{swimlanesDiagram-VR7AAH4N-BlY12Jf6.js → swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js} +2 -2
  93. package/dist/{swiper-component-DTdNB9wg.js → swiper-component-B2O8hF7b.js} +2 -2
  94. package/dist/{timeline-definition-24CTP7MA-m0LanyCH.js → timeline-definition-24CTP7MA-DTJ0Rx8X.js} +1 -1
  95. package/dist/{toast-U3NpO2x3.js → toast-6V8Og7d5.js} +11 -11
  96. package/dist/{tooltip-UzJukb3F.js → tooltip-D0h-ZJ6j.js} +2 -2
  97. package/dist/{use-restore-focus-DaTVz6S6.js → use-restore-focus-BFvwj2Hj.js} +1884 -1861
  98. package/dist/{useDateFormatter-LQNtoXyh.js → useDateFormatter-D6o9PsWt.js} +2 -2
  99. package/dist/{useDeepCompareMemoize-CmNbQ9TT.js → useDeepCompareMemoize-D-Pbv7dN.js} +1 -1
  100. package/dist/{useIframeCapabilities-HTZiVlGV.js → useIframeCapabilities-_0KX0nu_.js} +1 -1
  101. package/dist/{useLifecycle-DTMczKkf.js → useLifecycle-CE0yGTMF.js} +2 -2
  102. package/dist/{vega-component-ZTdbCcwI.js → vega-component-DTf7GHQe.js} +8 -8
  103. package/dist/{vennDiagram-4TSXK5OY-BJ7vqDmn.js → vennDiagram-4TSXK5OY-lIM3SAjl.js} +1 -1
  104. package/dist/{wardleyDiagram-VM6X3IG4-D5kWacsn.js → wardleyDiagram-VM6X3IG4-Bw_t7uvA.js} +1 -1
  105. package/dist/{xychartDiagram-S5SC5T6Z-gr15Ws_z.js → xychartDiagram-S5SC5T6Z-BXwkLYKj.js} +1 -1
  106. package/package.json +3 -3
  107. package/src/components/editor/cell/CreateCellButton.tsx +69 -40
  108. package/src/components/editor/cell/__tests__/CreateCellButton.test.tsx +49 -0
  109. package/src/components/editor/cell/__tests__/cell-context-menu.test.tsx +126 -0
  110. package/src/components/editor/cell/cell-context-menu.tsx +202 -111
  111. package/src/components/editor/cell/code/cell-editor.tsx +5 -2
  112. package/src/components/editor/cell/code/code-placeholder.tsx +5 -3
  113. package/src/components/editor/output/console/ConsoleOutput.tsx +77 -50
  114. package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +28 -0
  115. package/src/components/editor/renderers/cells-renderer.tsx +3 -2
  116. package/src/components/ui/__tests__/button-shortcut.test.tsx +22 -0
  117. package/src/components/ui/__tests__/fullscreen.test.tsx +23 -1
  118. package/src/components/ui/button.tsx +5 -1
  119. package/src/components/ui/fullscreen.tsx +8 -39
  120. package/src/core/codemirror/__tests__/debounced-editor-update.test.ts +72 -0
  121. package/src/core/codemirror/__tests__/setup.test.ts +61 -1
  122. package/src/core/codemirror/cells/debugger-decorations.ts +22 -18
  123. package/src/core/codemirror/cells/line-timing-decorations.ts +13 -11
  124. package/src/core/codemirror/cells/traceback-decorations.ts +10 -11
  125. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +31 -0
  126. package/src/core/codemirror/code-lens/extension.ts +21 -13
  127. package/src/core/codemirror/debounced-editor-update.ts +41 -0
  128. package/src/core/codemirror/go-to-definition/__tests__/underline.test.ts +58 -0
  129. package/src/core/codemirror/go-to-definition/extension.ts +9 -7
  130. package/src/core/codemirror/go-to-definition/underline.ts +39 -48
  131. package/src/core/codemirror/language/__tests__/sql.test.ts +36 -0
  132. package/src/core/codemirror/language/languages/sql/sql.ts +3 -0
  133. package/src/core/codemirror/placeholder/extensions.ts +26 -24
  134. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +60 -0
  135. package/src/core/codemirror/reactive-references/extension.ts +30 -21
  136. package/src/core/islands/__tests__/bridge.test.ts +1 -1
  137. package/src/core/islands/bootstrap.ts +0 -3
  138. package/src/core/notebook/replica/__tests__/replica.test.ts +7 -7
  139. package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +2 -2
  140. package/src/core/session/useNotebookSession.tsx +0 -8
  141. package/src/utils/__tests__/shared-resource.test.ts +107 -0
  142. package/src/utils/shared-resource.ts +59 -0
@@ -9,6 +9,8 @@ import {
9
9
  SearchIcon,
10
10
  } from "lucide-react";
11
11
  import React, { Fragment } from "react";
12
+ import { Slot } from "radix-ui";
13
+ import useEvent from "react-use-event-hook";
12
14
  import { renderMinimalShortcut } from "@/components/shortcuts/renderShortcut";
13
15
  import {
14
16
  ContextMenu,
@@ -48,12 +50,124 @@ interface Props extends Pick<
48
50
  disabled?: boolean;
49
51
  }
50
52
 
53
+ type ActiveCell = Pick<Props, "cellId" | "getEditorView"> & {
54
+ imageRightClicked?: HTMLImageElement;
55
+ };
56
+
57
+ const CellMenuContext = React.createContext<
58
+ ((cell: ActiveCell) => void) | null
59
+ >(null);
60
+
61
+ // Only events handled by a cell should reach the shared Radix trigger.
62
+ const cellMenuEvents = new WeakSet<Event>();
63
+
64
+ export const NotebookContextMenu = ({ children }: React.PropsWithChildren) => {
65
+ const [activeCell, setActiveCell] = React.useState<ActiveCell>();
66
+ const restoreFocus = useRestoreFocus();
67
+ const openRef = React.useRef(false);
68
+ return (
69
+ <CellMenuContext.Provider value={setActiveCell}>
70
+ <ContextMenu
71
+ onOpenChange={(open) => {
72
+ openRef.current = open;
73
+ if (open) {
74
+ restoreFocus.onOpenAutoFocus();
75
+ }
76
+ }}
77
+ >
78
+ <ContextMenuTrigger asChild={true}>
79
+ <div
80
+ className="contents"
81
+ onPointerUp={() => {
82
+ if (!openRef.current) {
83
+ setActiveCell(undefined);
84
+ }
85
+ }}
86
+ onPointerCancel={() => {
87
+ if (!openRef.current) {
88
+ setActiveCell(undefined);
89
+ }
90
+ }}
91
+ >
92
+ <div
93
+ className="contents"
94
+ onContextMenu={(event) => {
95
+ if (!cellMenuEvents.has(event.nativeEvent)) {
96
+ event.stopPropagation();
97
+ }
98
+ }}
99
+ onPointerDown={(event) => {
100
+ if (
101
+ event.pointerType !== "mouse" &&
102
+ !cellMenuEvents.has(event.nativeEvent)
103
+ ) {
104
+ event.stopPropagation();
105
+ }
106
+ }}
107
+ >
108
+ {children}
109
+ </div>
110
+ </div>
111
+ </ContextMenuTrigger>
112
+ {activeCell && (
113
+ <CellMenuContent
114
+ key={activeCell.cellId}
115
+ {...activeCell}
116
+ restoreFocus={restoreFocus}
117
+ onClosed={() => setActiveCell(undefined)}
118
+ />
119
+ )}
120
+ </ContextMenu>
121
+ </CellMenuContext.Provider>
122
+ );
123
+ };
124
+
51
125
  export const CellActionsContextMenu = ({
52
126
  children,
53
127
  cellId,
54
128
  getEditorView,
55
129
  disabled,
56
130
  }: Props) => {
131
+ const setActiveCell = React.useContext(CellMenuContext);
132
+ const activateCell = (event: React.MouseEvent | React.PointerEvent) => {
133
+ cellMenuEvents.add(event.nativeEvent);
134
+ setActiveCell?.({
135
+ cellId,
136
+ getEditorView,
137
+ imageRightClicked:
138
+ event.target instanceof HTMLImageElement ? event.target : undefined,
139
+ });
140
+ };
141
+ return (
142
+ <Slot.Root
143
+ onPointerDown={(evt: React.PointerEvent) => {
144
+ if (evt.pointerType === "mouse" || disabled) {
145
+ return;
146
+ }
147
+ activateCell(evt);
148
+ }}
149
+ onContextMenu={(evt: React.MouseEvent) => {
150
+ if (disabled || evt.defaultPrevented) {
151
+ return;
152
+ }
153
+ activateCell(evt);
154
+ }}
155
+ >
156
+ {children}
157
+ </Slot.Root>
158
+ );
159
+ };
160
+
161
+ const CellMenuContent = ({
162
+ cellId,
163
+ getEditorView,
164
+ imageRightClicked,
165
+ restoreFocus,
166
+ onClosed,
167
+ }: ActiveCell & {
168
+ restoreFocus: ReturnType<typeof useRestoreFocus>;
169
+ onClosed: () => void;
170
+ }) => {
57
171
  const cellData = useCellData(cellId);
58
172
  const cellRuntime = useCellRuntime(cellId);
59
173
  const execution = useCellExecution(cellId);
@@ -70,12 +184,17 @@ export const CellActionsContextMenu = ({
70
184
  getEditorView,
71
185
  },
72
186
  });
73
- const [imageRightClicked, setImageRightClicked] =
74
- React.useState<HTMLImageElement>();
75
187
  const suppressCloseAutoFocus = React.useRef(false);
76
188
  const pendingAction = React.useRef<(() => void) | null>(null);
77
- const restoreFocus = useRestoreFocus();
78
-
189
+ const navigateToDefinition = useEvent(() => {
190
+ const editorView = getEditorView();
191
+ if (editorView) {
192
+ // Only suppress focus restoration when we actually navigated;
193
+ // otherwise let Radix return focus to the trigger cell.
194
+ suppressCloseAutoFocus.current =
195
+ goToDefinitionWithLspFallback(editorView);
196
+ }
197
+ });
79
198
  const DEFAULT_CONTEXT_MENU_ITEMS: ActionButton[] = [
80
199
  {
81
200
  label: "Copy",
@@ -177,15 +296,7 @@ export const CellActionsContextMenu = ({
177
296
  {
178
297
  label: "Go to Definition",
179
298
  icon: <SearchIcon size={13} strokeWidth={1.5} />,
180
- handle: () => {
181
- const editorView = getEditorView();
182
- if (editorView) {
183
- // Only suppress focus restoration when we actually navigated;
184
- // otherwise let Radix return focus to the trigger cell.
185
- suppressCloseAutoFocus.current =
186
- goToDefinitionWithLspFallback(editorView);
187
- }
188
- },
299
+ handle: navigateToDefinition,
189
300
  },
190
301
  ];
191
302
 
@@ -198,110 +309,90 @@ export const CellActionsContextMenu = ({
198
309
  .filter((group) => group.length > 0);
199
310
 
200
311
  return (
201
- <ContextMenu
202
- onOpenChange={(open) => {
203
- if (open) {
204
- restoreFocus.onOpenAutoFocus();
312
+ <ContextMenuContent
313
+ className="w-[300px]"
314
+ scrollable={true}
315
+ onCloseAutoFocus={(evt) => {
316
+ onClosed();
317
+ const action = pendingAction.current;
318
+ pendingAction.current = null;
319
+ if (action) {
320
+ restoreFocus.onCloseAutoFocus(evt);
321
+ evt.preventDefault();
322
+ action();
323
+ }
324
+ if (suppressCloseAutoFocus.current) {
325
+ evt.preventDefault();
326
+ suppressCloseAutoFocus.current = false;
205
327
  }
206
328
  }}
207
329
  >
208
- <ContextMenuTrigger
209
- disabled={disabled}
210
- onContextMenu={(evt) => {
211
- if (evt.target instanceof HTMLImageElement) {
212
- setImageRightClicked(evt.target);
213
- } else {
214
- setImageRightClicked(undefined);
215
- }
216
- }}
217
- asChild={true}
218
- >
219
- {children}
220
- </ContextMenuTrigger>
221
- <ContextMenuContent
222
- className="w-[300px]"
223
- scrollable={true}
224
- onCloseAutoFocus={(evt) => {
225
- const action = pendingAction.current;
226
- pendingAction.current = null;
227
- if (action) {
228
- restoreFocus.onCloseAutoFocus(evt);
229
- evt.preventDefault();
230
- action();
231
- }
232
- if (suppressCloseAutoFocus.current) {
233
- evt.preventDefault();
234
- suppressCloseAutoFocus.current = false;
235
- }
236
- }}
237
- >
238
- {visibleActions.map((group, i) => (
239
- <Fragment key={i}>
240
- {group.map((action) => {
241
- let body = (
242
- <div className="flex items-center flex-1">
243
- {action.icon && (
244
- <div className="mr-2 w-5 text-muted-foreground">
245
- {action.icon}
246
- </div>
247
- )}
248
- <div className="flex-1">{action.label}</div>
249
- <div className="shrink-0 text-sm">
250
- {action.hotkey && renderMinimalShortcut(action.hotkey)}
251
- {action.rightElement}
252
- </div>
330
+ {visibleActions.flatMap((group, i) => [
331
+ ...group.map((action) => {
332
+ let body = (
333
+ <div className="flex items-center flex-1">
334
+ {action.icon && (
335
+ <div className="mr-2 w-5 text-muted-foreground">
336
+ {action.icon}
253
337
  </div>
254
- );
338
+ )}
339
+ <div className="flex-1">{action.label}</div>
340
+ <div className="shrink-0 text-sm">
341
+ {action.hotkey && renderMinimalShortcut(action.hotkey)}
342
+ {action.rightElement}
343
+ </div>
344
+ </div>
345
+ );
346
+
347
+ if (action.tooltip) {
348
+ body = (
349
+ <Tooltip delayDuration={100} content={action.tooltip}>
350
+ {body}
351
+ </Tooltip>
352
+ );
353
+ }
255
354
 
256
- if (action.tooltip) {
257
- body = (
258
- <Tooltip delayDuration={100} content={action.tooltip}>
355
+ return (
356
+ <Fragment key={action.label}>
357
+ {
358
+ // Set disableClick items such as cell name input
359
+ // to div to prevent roving focus
360
+ action.disableClick ? (
361
+ <div
362
+ className={menuItemVariants({
363
+ className: action.disabled ? "opacity-50!" : "",
364
+ variant: action.variant,
365
+ })}
366
+ onKeyDown={(evt) => {
367
+ evt.stopPropagation();
368
+ }}
369
+ // Prevent keydown propagation, that focus does not jump to shortcut which start with same letter
370
+ // e.g. input "C", then focus jump to "Copy"
371
+ >
259
372
  {body}
260
- </Tooltip>
261
- );
373
+ </div>
374
+ ) : (
375
+ <ContextMenuItem
376
+ className={action.disabled ? "opacity-50!" : ""}
377
+ onSelect={(evt) => {
378
+ if (action.disableClick || action.disabled) {
379
+ return;
380
+ }
381
+ pendingAction.current = () => action.handle(evt);
382
+ }}
383
+ variant={action.variant}
384
+ >
385
+ {body}
386
+ </ContextMenuItem>
387
+ )
262
388
  }
263
-
264
- return (
265
- <Fragment key={action.label}>
266
- {
267
- // Set disableClick items such as cell name input
268
- // to div to prevent roving focus
269
- action.disableClick ? (
270
- <div
271
- className={menuItemVariants({
272
- className: action.disabled ? "opacity-50!" : "",
273
- variant: action.variant,
274
- })}
275
- onKeyDown={(evt) => {
276
- evt.stopPropagation();
277
- }}
278
- // Prevent keydown propagation, that focus does not jump to shortcut which start with same letter
279
- // e.g. input "C", then focus jump to "Copy"
280
- >
281
- {body}
282
- </div>
283
- ) : (
284
- <ContextMenuItem
285
- className={action.disabled ? "opacity-50!" : ""}
286
- onSelect={(evt) => {
287
- if (action.disableClick || action.disabled) {
288
- return;
289
- }
290
- pendingAction.current = () => action.handle(evt);
291
- }}
292
- variant={action.variant}
293
- >
294
- {body}
295
- </ContextMenuItem>
296
- )
297
- }
298
- </Fragment>
299
- );
300
- })}
301
- {i < visibleActions.length - 1 && <ContextMenuSeparator />}
302
- </Fragment>
303
- ))}
304
- </ContextMenuContent>
305
- </ContextMenu>
389
+ </Fragment>
390
+ );
391
+ }),
392
+ i < visibleActions.length - 1 && (
393
+ <ContextMenuSeparator key={`separator-${group[0].label}`} />
394
+ ),
395
+ ])}
396
+ </ContextMenuContent>
306
397
  );
307
398
  };
@@ -447,8 +447,9 @@ const CellEditorInternal = ({
447
447
 
448
448
  const navigationProps = useCellEditorNavigationProps(cellId, editorViewRef);
449
449
 
450
+ const isCollapsed = isMarkdown && hidden && hasOutput;
450
451
  let editorClassName = "";
451
- if (isMarkdown && hidden && hasOutput) {
452
+ if (isCollapsed) {
452
453
  editorClassName = "h-0 overflow-hidden";
453
454
  } else if (hidden) {
454
455
  // Shortens the editor and hides the cell panels
@@ -503,7 +504,9 @@ const CellEditorInternal = ({
503
504
  showHiddenCode={showHiddenCode}
504
505
  />
505
506
  ) : (
506
- <CodePlaceholder code={code} className={editorClassName} />
507
+ !isCollapsed && (
508
+ <CodePlaceholder code={code} className={editorClassName} />
509
+ )
507
510
  )}
508
511
  {!hidden && showLanguageToggles && (
509
512
  <div className="absolute top-1 right-5">
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import "./code-placeholder.css";
3
- import { Skeleton } from "@/components/ui/skeleton";
4
3
  import { cn } from "@/utils/cn";
5
4
 
6
5
  interface CodePlaceholderProps {
@@ -20,6 +19,9 @@ function getLineWidthCh(length: number): number {
20
19
  /**
21
20
  * Stand-in shown while a cell's CodeMirror editor has not been built yet.
22
21
  * one skeleton bar per code line, so the final render doesn't cause a big jump.
22
+ *
23
+ * The bars are static: a large notebook shows thousands of them at once, and
24
+ * animating each one makes every stylesheet change restyle all of them.
23
25
  */
24
26
  export const CodePlaceholder = ({ code, className }: CodePlaceholderProps) => {
25
27
  const lines = code.split("\n", MAX_LINES);
@@ -34,8 +36,8 @@ export const CodePlaceholder = ({ code, className }: CodePlaceholderProps) => {
34
36
  return (
35
37
  <div key={index} className="mo-code-placeholder-line">
36
38
  {length > 0 && (
37
- <Skeleton
38
- className="mo-code-placeholder-bar"
39
+ <div
40
+ className="mo-code-placeholder-bar rounded-md"
39
41
  style={{ width: `${getLineWidthCh(length)}ch` }}
40
42
  />
41
43
  )}
@@ -83,13 +83,13 @@ interface Props {
83
83
  onSubmitDebugger: (text: string, inputId?: string) => void;
84
84
  }
85
85
 
86
- export const ConsoleOutput = (props: Props) => {
86
+ export const ConsoleOutput = React.memo((props: Props) => {
87
87
  return (
88
88
  <ErrorBoundary>
89
89
  <ConsoleOutputInternal {...props} />
90
90
  </ErrorBoundary>
91
91
  );
92
- };
92
+ });
93
93
 
94
94
  const ConsoleOutputInternal = (props: Props): React.ReactNode => {
95
95
  const ref = React.useRef<HTMLDivElement>(null);
@@ -133,7 +133,7 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
133
133
  // always work perfectly when moved form the bottom and back.
134
134
  useLayoutEffect(() => {
135
135
  const el = ref.current;
136
- if (!el) {
136
+ if (!el || !hasOutputs) {
137
137
  return;
138
138
  }
139
139
  // N.B. This won't handle large jumps in the scroll position
@@ -146,7 +146,7 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
146
146
  if (distanceFromBottom < threshold) {
147
147
  el.scrollTop = scrollOffset;
148
148
  }
149
- });
149
+ }, [consoleOutputs, hasOutputs, pdbInput, isExpanded, wrapText]);
150
150
 
151
151
  if (!hasOutputs && isInternalCellName(cellName)) {
152
152
  return null;
@@ -164,55 +164,17 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
164
164
  (output) => output.channel === "stdin",
165
165
  );
166
166
 
167
- const getOutputString = (): string => {
168
- const text = consoleOutputs
169
- .filter((output) => output.channel !== "pdb")
170
- .map((output) => processOutput(output))
171
- .join("\n");
172
- return text;
173
- };
174
-
175
167
  return (
176
168
  <div className="relative group">
177
169
  {hasOutputs && (
178
- <div className="absolute top-1 right-4 z-10 opacity-0 group-hover:opacity-100 flex items-center gap-1 print:hidden">
179
- <CopyClipboardIcon
180
- tooltip="Copy console output"
181
- value={getOutputString}
182
- className="h-4 w-4"
183
- />
184
- <Tooltip content={wrapText ? "Disable wrap text" : "Wrap text"}>
185
- <span>
186
- <ToggleButton
187
- aria-label="Toggle text wrapping"
188
- className="p-1 rounded bg-transparent text-muted-foreground data-hovered:text-foreground data-selected:text-foreground"
189
- isSelected={wrapText}
190
- onChange={setWrapText}
191
- >
192
- <WrapTextIcon className="h-4 w-4" />
193
- </ToggleButton>
194
- </span>
195
- </Tooltip>
196
- {(isOverflowing || isExpanded) && (
197
- <Button
198
- aria-label={isExpanded ? "Collapse output" : "Expand output"}
199
- className="p-0 mb-px"
200
- onClick={() => setIsExpanded(!isExpanded)}
201
- size="xs"
202
- variant={null}
203
- >
204
- {isExpanded ? (
205
- <Tooltip content="Collapse output">
206
- <ChevronsDownUpIcon className="h-4 w-4" />
207
- </Tooltip>
208
- ) : (
209
- <Tooltip content="Expand output">
210
- <ChevronsUpDownIcon className="h-4 w-4 " />
211
- </Tooltip>
212
- )}
213
- </Button>
214
- )}
215
- </div>
170
+ <ConsoleOutputToolbar
171
+ consoleOutputs={consoleOutputs}
172
+ wrapText={wrapText}
173
+ setWrapText={setWrapText}
174
+ isExpanded={isExpanded}
175
+ setIsExpanded={setIsExpanded}
176
+ isOverflowing={isOverflowing}
177
+ />
216
178
  )}
217
179
  <div
218
180
  title={stale ? "This console output is stale" : undefined}
@@ -313,6 +275,71 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
313
275
  );
314
276
  };
315
277
 
278
+ const ConsoleOutputToolbar = ({
279
+ consoleOutputs,
280
+ wrapText,
281
+ setWrapText,
282
+ isExpanded,
283
+ setIsExpanded,
284
+ isOverflowing,
285
+ }: {
286
+ consoleOutputs: ConsoleOutputMessage[];
287
+ wrapText: boolean;
288
+ setWrapText: (wrap: boolean) => void;
289
+ isExpanded: boolean;
290
+ setIsExpanded: (expanded: boolean) => void;
291
+ isOverflowing: boolean;
292
+ }) => {
293
+ const getOutputString = (): string => {
294
+ const text = consoleOutputs
295
+ .filter((output) => output.channel !== "pdb")
296
+ .map((output) => processOutput(output))
297
+ .join("\n");
298
+ return text;
299
+ };
300
+
301
+ return (
302
+ <div className="absolute top-1 right-4 z-10 opacity-0 group-hover:opacity-100 flex items-center gap-1 print:hidden">
303
+ <CopyClipboardIcon
304
+ tooltip="Copy console output"
305
+ value={getOutputString}
306
+ className="h-4 w-4"
307
+ />
308
+ <Tooltip content={wrapText ? "Disable wrap text" : "Wrap text"}>
309
+ <span>
310
+ <ToggleButton
311
+ aria-label="Toggle text wrapping"
312
+ className="p-1 rounded bg-transparent text-muted-foreground data-hovered:text-foreground data-selected:text-foreground"
313
+ isSelected={wrapText}
314
+ onChange={setWrapText}
315
+ >
316
+ <WrapTextIcon className="h-4 w-4" />
317
+ </ToggleButton>
318
+ </span>
319
+ </Tooltip>
320
+ {(isOverflowing || isExpanded) && (
321
+ <Button
322
+ aria-label={isExpanded ? "Collapse output" : "Expand output"}
323
+ className="p-0 mb-px"
324
+ onClick={() => setIsExpanded(!isExpanded)}
325
+ size="xs"
326
+ variant={null}
327
+ >
328
+ {isExpanded ? (
329
+ <Tooltip content="Collapse output">
330
+ <ChevronsDownUpIcon className="h-4 w-4" />
331
+ </Tooltip>
332
+ ) : (
333
+ <Tooltip content="Expand output">
334
+ <ChevronsUpDownIcon className="h-4 w-4 " />
335
+ </Tooltip>
336
+ )}
337
+ </Button>
338
+ )}
339
+ </div>
340
+ );
341
+ };
342
+
316
343
  const StdInput = (props: {
317
344
  onSubmit: (text: string) => void;
318
345
  onClear?: () => void;
@@ -48,6 +48,34 @@ describe("ConsoleOutput integration", () => {
48
48
  },
49
49
  };
50
50
 
51
+ it("measures scrolling only when console content changes", () => {
52
+ const outputs = [createOutput("hello")];
53
+ const ui = (stale: boolean, consoleOutputs = outputs) => (
54
+ <Provider store={store}>
55
+ <DocumentProvider model={model}>
56
+ <TooltipProvider>
57
+ <ConsoleOutput
58
+ {...defaultProps}
59
+ stale={stale}
60
+ consoleOutputs={consoleOutputs}
61
+ />
62
+ </TooltipProvider>
63
+ </DocumentProvider>
64
+ </Provider>
65
+ );
66
+ const { rerender } = render(ui(false));
67
+ const area = screen.getByTestId("console-output-area");
68
+ const measure = vi.fn(() => 100);
69
+ Object.defineProperty(area, "scrollHeight", {
70
+ configurable: true,
71
+ get: measure,
72
+ });
73
+ rerender(ui(true));
74
+ expect(measure).not.toHaveBeenCalled();
75
+ rerender(ui(true, [...outputs, createOutput("world")]));
76
+ expect(measure).toHaveBeenCalled();
77
+ });
78
+
51
79
  it("should render console output with clickable URLs", () => {
52
80
  const props = {
53
81
  ...defaultProps,
@@ -12,6 +12,7 @@ import {
12
12
  useLayoutState,
13
13
  } from "@/core/layout/state";
14
14
  import { type AppMode, kioskModeAtom } from "@/core/mode";
15
+ import { NotebookContextMenu } from "../cell/cell-context-menu";
15
16
  import { cellRendererPlugins } from "./plugins";
16
17
  import type { ICellRendererPlugin } from "./types";
17
18
 
@@ -33,7 +34,7 @@ export const CellsRenderer: React.FC<PropsWithChildren<Props>> = memo(
33
34
  !kioskMode &&
34
35
  (mode === "edit" || (mode === "present" && selectedLayout === "vertical"))
35
36
  ) {
36
- return children;
37
+ return <NotebookContextMenu>{children}</NotebookContextMenu>;
37
38
  }
38
39
 
39
40
  // We allow overriding the layout type by url params when in 'read' mode,
@@ -49,7 +50,7 @@ export const CellsRenderer: React.FC<PropsWithChildren<Props>> = memo(
49
50
 
50
51
  // Just render children if there is no plugin
51
52
  if (!plugin) {
52
- return children;
53
+ return <NotebookContextMenu>{children}</NotebookContextMenu>;
53
54
  }
54
55
 
55
56
  return (
@@ -0,0 +1,22 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { fireEvent, render } from "@testing-library/react";
3
+ import { expect, it, vi } from "vitest";
4
+ import { Button } from "../button";
5
+
6
+ it("subscribes only while a shortcut is configured", () => {
7
+ const add = vi.spyOn(document, "addEventListener");
8
+ const remove = vi.spyOn(document, "removeEventListener");
9
+ const onClick = vi.fn();
10
+ const { rerender, unmount } = render(<Button onClick={onClick} />);
11
+ expect(add.mock.calls.filter(([name]) => name === "keydown")).toHaveLength(0);
12
+ rerender(<Button keyboardShortcut="shift-k" onClick={onClick} />);
13
+ expect(add.mock.calls.filter(([name]) => name === "keydown")).toHaveLength(1);
14
+ fireEvent.keyDown(document.body, { key: "k", shiftKey: true });
15
+ expect(onClick).toHaveBeenCalledOnce();
16
+ rerender(<Button onClick={onClick} />);
17
+ expect(remove.mock.calls.filter(([name]) => name === "keydown")).toHaveLength(
18
+ 1,
19
+ );
20
+ unmount();
21
+ vi.restoreAllMocks();
22
+ });