@marimo-team/islands 0.23.15-dev2 → 0.23.15-dev21

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/{chat-ui-DinOvbWu.js → chat-ui-FiwuOgQU.js} +3094 -3094
  2. package/dist/{code-visibility-B-sydhvS.js → code-visibility-Bqg6aos7.js} +925 -842
  3. package/dist/{html-to-image-_wGfk8V-.js → html-to-image-JXL8cvmt.js} +2218 -2205
  4. package/dist/main.js +1066 -1073
  5. package/dist/{process-output-Mh4UrjwM.js → process-output-CnDIXtM-.js} +1 -1
  6. package/dist/{reveal-component-MK2nUbwt.js → reveal-component-BzkgqXit.js} +614 -602
  7. package/dist/style.css +1 -1
  8. package/package.json +1 -1
  9. package/src/components/chat/__tests__/chat-utils.test.ts +244 -1
  10. package/src/components/chat/__tests__/message-queue.test.tsx +121 -0
  11. package/src/components/chat/chat-panel.tsx +196 -67
  12. package/src/components/chat/chat-utils.ts +111 -2
  13. package/src/components/editor/SortableCell.tsx +6 -2
  14. package/src/components/editor/__tests__/output-persistence.test.tsx +241 -0
  15. package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +153 -0
  16. package/src/components/editor/actions/pair-with-agent-commands.ts +109 -0
  17. package/src/components/editor/actions/pair-with-agent-modal.tsx +20 -64
  18. package/src/components/editor/cell/cell-context-menu.tsx +7 -0
  19. package/src/components/editor/chrome/panels/packages-panel.tsx +11 -1
  20. package/src/components/editor/columns/__tests__/cell-column.test.tsx +105 -0
  21. package/src/components/editor/columns/cell-column.tsx +34 -4
  22. package/src/components/editor/columns/sortable-column.tsx +24 -4
  23. package/src/components/editor/notebook-cell.tsx +203 -106
  24. package/src/components/editor/renderers/__tests__/cells-renderer.test.tsx +66 -0
  25. package/src/components/editor/renderers/cell-array.tsx +26 -13
  26. package/src/components/editor/renderers/cells-renderer.tsx +8 -2
  27. package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +29 -0
  28. package/src/components/editor/renderers/slides-layout/types.ts +4 -0
  29. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +19 -19
  30. package/src/components/slides/reveal-component.tsx +33 -4
  31. package/src/components/slides/slide-form.tsx +72 -0
  32. package/src/core/cells/__tests__/utils.test.ts +59 -0
  33. package/src/core/cells/utils.ts +51 -0
  34. package/src/css/app/Cell.css +10 -0
  35. package/src/hooks/__tests__/useHotkey.test.tsx +88 -0
  36. package/src/hooks/useHotkey.ts +29 -4
  37. package/src/plugins/impl/anywidget/__tests__/host.test.ts +6 -9
  38. package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +22 -61
  39. package/src/plugins/impl/anywidget/model-proxy.ts +0 -13
  40. package/src/plugins/impl/anywidget/widget-binding.ts +4 -34
  41. package/src/plugins/impl/matplotlib/__tests__/matplotlib-renderer.test.ts +71 -3
  42. package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +1 -0
@@ -33,11 +33,14 @@ import { getReadonlyCodeDisplay } from "@/core/cells/readonly-code-display";
33
33
  import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
34
34
  import { useResolvedMarimoConfig } from "@/core/config/config";
35
35
  import { CSSClasses, KnownQueryParams } from "@/core/constants";
36
- import type { MarimoError, OutputMessage } from "@/core/kernel/messages";
36
+ import type { OutputMessage } from "@/core/kernel/messages";
37
37
  import { kernelStateAtom } from "@/core/kernel/state";
38
38
  import { useNotebookCodeAvailable } from "@/core/meta/code-visibility";
39
39
  import { showCodeInRunModeAtom } from "@/core/meta/state";
40
- import { isErrorMime } from "@/core/mime";
40
+ import {
41
+ publishedCellClasses,
42
+ shouldHidePublishedCell,
43
+ } from "@/core/cells/utils";
41
44
  import { type AppMode, kioskModeAtom } from "@/core/mode";
42
45
  import { useRequestClient } from "@/core/network/requests";
43
46
  import type { CellConfig } from "@/core/network/types";
@@ -362,12 +365,13 @@ const VerticalCell = memo(
362
365
  const className = cn(
363
366
  "marimo-cell",
364
367
  "hover-actions-parent empty:invisible",
365
- {
366
- published: published,
367
- "has-error": errored,
368
- stopped: stopped,
369
- borderless: isPureMarkdown && !published,
370
- },
368
+ published
369
+ ? publishedCellClasses({ errored, stopped })
370
+ : {
371
+ "has-error": errored,
372
+ stopped: stopped,
373
+ borderless: isPureMarkdown,
374
+ },
371
375
  );
372
376
 
373
377
  // Read mode and show code
@@ -419,19 +423,15 @@ const VerticalCell = memo(
419
423
  );
420
424
  }
421
425
 
422
- const outputIsError = isErrorMime(output?.mimetype);
423
426
  // When show_tracebacks is enabled, show error outputs inline
424
427
  // instead of hiding them
425
- const hasTraceback =
426
- showErrorTracebacks &&
427
- outputIsError &&
428
- Array.isArray(output?.data) &&
429
- output.data.some(
430
- (e: MarimoError) =>
431
- e.type === "exception" && "traceback" in e && e.traceback,
432
- );
433
- const hidden =
434
- (errored || interrupted || stopped || outputIsError) && !hasTraceback;
428
+ const hidden = shouldHidePublishedCell({
429
+ errored,
430
+ interrupted,
431
+ stopped,
432
+ output,
433
+ showErrorTracebacks,
434
+ });
435
435
  if (hidden) {
436
436
  return null;
437
437
  }
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import {
4
+ type CSSProperties,
4
5
  startTransition,
5
6
  useEffect,
6
7
  useMemo,
@@ -26,6 +27,7 @@ import { Logger } from "@/utils/Logger";
26
27
  import "./slides.css";
27
28
  import "./reveal-slides.css";
28
29
  import type {
30
+ DeckVerticalAlign,
29
31
  SlideConfig,
30
32
  SlidesLayout,
31
33
  SlideType,
@@ -39,6 +41,7 @@ import {
39
41
  type ComposedSubslide,
40
42
  } from "./compose-slides";
41
43
  import {
44
+ DEFAULT_DECK_VERTICAL_ALIGN,
42
45
  DEFAULT_DECK_TRANSITION,
43
46
  DEFAULT_SLIDE_TYPE,
44
47
  SlideSidebar,
@@ -292,16 +295,38 @@ export function useParkedPreview(options: {
292
295
  };
293
296
  }
294
297
 
298
+ /**
299
+ * Margin style that positions a slide's content vertically within the
300
+ * full-height slide. The content is a flex item, so the vertical margins decide
301
+ * where the free space lands: `auto` on both sides centers it, while pinning one
302
+ * side to `0` pushes content to the top or bottom. The horizontal `20px` keeps
303
+ * content off the slide edges regardless of alignment.
304
+ */
305
+ function resolveSlideContentStyle(
306
+ verticalAlign: DeckVerticalAlign | undefined,
307
+ ): CSSProperties {
308
+ switch (verticalAlign ?? DEFAULT_DECK_VERTICAL_ALIGN) {
309
+ case "top":
310
+ return { margin: "0 20px auto" };
311
+ case "bottom":
312
+ return { margin: "auto 20px 0" };
313
+ default:
314
+ return { margin: "auto 20px" };
315
+ }
316
+ }
317
+
295
318
  const SubslideView = ({
296
319
  subslide,
297
320
  resolveShowCode,
298
321
  isEditable,
299
322
  slideConfigs,
323
+ contentStyle,
300
324
  }: {
301
325
  subslide: ComposedSubslide<RuntimeCell>;
302
326
  resolveShowCode: (cellId: CellId) => boolean;
303
327
  isEditable: boolean;
304
328
  slideConfigs: ReadonlyMap<CellId, SlideConfig>;
329
+ contentStyle: CSSProperties;
305
330
  }) => {
306
331
  const { slideLevel, cumulativeByBlock } = buildSubslideNotes(
307
332
  subslide,
@@ -321,9 +346,7 @@ const SubslideView = ({
321
346
  ? "mo-slide-content flex flex-col gap-3"
322
347
  : "mo-slide-content"
323
348
  }
324
- style={{
325
- margin: "auto 20px",
326
- }}
349
+ style={contentStyle}
327
350
  >
328
351
  {subslide.blocks.map((block, i) => {
329
352
  const rendered = block.cells.map((cell) => {
@@ -514,6 +537,10 @@ const RevealSlidesComponent = ({
514
537
  );
515
538
 
516
539
  const deckTransition = layout.deck?.transition ?? DEFAULT_DECK_TRANSITION;
540
+ const slideContentStyle = resolveSlideContentStyle(
541
+ layout.deck?.verticalAlign,
542
+ );
543
+
517
544
  // Reveal's Notes plugin iframes the deck for the current/upcoming-slide
518
545
  // previews. We load the same URL but as a read-only kiosk client with the
519
546
  // app chrome hidden, which `<SlidesLayoutRenderer>` interprets the same as
@@ -704,6 +731,7 @@ const RevealSlidesComponent = ({
704
731
  resolveShowCode={resolveShowCode}
705
732
  isEditable={isEditable}
706
733
  slideConfigs={layout.cells}
734
+ contentStyle={slideContentStyle}
707
735
  />
708
736
  );
709
737
  }
@@ -717,6 +745,7 @@ const RevealSlidesComponent = ({
717
745
  resolveShowCode={resolveShowCode}
718
746
  isEditable={isEditable}
719
747
  slideConfigs={layout.cells}
748
+ contentStyle={slideContentStyle}
720
749
  />
721
750
  );
722
751
  })}
@@ -743,7 +772,7 @@ const RevealSlidesComponent = ({
743
772
  ? "mo-slide-content flex flex-col gap-3"
744
773
  : "mo-slide-content"
745
774
  }
746
- style={{ margin: "auto 20px" }}
775
+ style={slideContentStyle}
747
776
  >
748
777
  <ParkedPreviewContent
749
778
  cell={parkedPreviewCell}
@@ -23,6 +23,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
23
23
  import type { CellId } from "@/core/cells/ids";
24
24
  import { cn } from "@/utils/cn";
25
25
  import type {
26
+ DeckVerticalAlign,
26
27
  DeckTransition,
27
28
  SlidesLayout,
28
29
  SlideType,
@@ -37,6 +38,7 @@ import { jotaiJsonStorage } from "@/utils/storage/jotai";
37
38
 
38
39
  export const DEFAULT_SLIDE_TYPE: SlideType = "slide";
39
40
  export const DEFAULT_DECK_TRANSITION: DeckTransition = "slide";
41
+ export const DEFAULT_DECK_VERTICAL_ALIGN: DeckVerticalAlign = "center";
40
42
  const COLLAPSED_CONFIG_WIDTH = 36;
41
43
  const slideConfigOpenAtom = atomWithStorage<boolean>(
42
44
  "marimo:slides:config-open",
@@ -118,6 +120,30 @@ const DECK_TRANSITION_OPTIONS: DeckTransitionOption[] = [
118
120
  { value: "zoom", label: "Zoom", description: "Zoom into the next slide." },
119
121
  ];
120
122
 
123
+ interface DeckVerticalAlignOption {
124
+ value: DeckVerticalAlign;
125
+ label: string;
126
+ description: string;
127
+ }
128
+
129
+ const DECK_VERTICAL_ALIGN_OPTIONS: DeckVerticalAlignOption[] = [
130
+ {
131
+ value: "center",
132
+ label: "Center",
133
+ description: "Vertically center each slide's content.",
134
+ },
135
+ {
136
+ value: "top",
137
+ label: "Top",
138
+ description: "Align content to the top, like the cell view.",
139
+ },
140
+ {
141
+ value: "bottom",
142
+ label: "Bottom",
143
+ description: "Align content to the bottom of each slide.",
144
+ },
145
+ ];
146
+
121
147
  const SlidesForm = ({
122
148
  layout,
123
149
  setLayout,
@@ -300,6 +326,12 @@ const DeckConfigForm = ({
300
326
  (opt) => opt.value === currentTransition,
301
327
  )?.description;
302
328
 
329
+ const currentVerticalAlign: DeckVerticalAlign =
330
+ layout.deck?.verticalAlign ?? DEFAULT_DECK_VERTICAL_ALIGN;
331
+ const activeVerticalAlignDescription = DECK_VERTICAL_ALIGN_OPTIONS.find(
332
+ (opt) => opt.value === currentVerticalAlign,
333
+ )?.description;
334
+
303
335
  const handleTransitionChange = (value: DeckTransition) => {
304
336
  setLayout({
305
337
  ...layout,
@@ -307,6 +339,13 @@ const DeckConfigForm = ({
307
339
  });
308
340
  };
309
341
 
342
+ const handleVerticalAlignChange = (value: DeckVerticalAlign) => {
343
+ setLayout({
344
+ ...layout,
345
+ deck: { ...layout.deck, verticalAlign: value },
346
+ });
347
+ };
348
+
310
349
  return (
311
350
  <div className="flex flex-col gap-3">
312
351
  <div className="flex flex-col gap-1.5">
@@ -337,6 +376,39 @@ const DeckConfigForm = ({
337
376
  <p className="text-xs text-foreground/70">{activeDescription}</p>
338
377
  )}
339
378
  </div>
379
+ <div className="flex flex-col gap-1.5">
380
+ <label
381
+ htmlFor="deck-vertical-align"
382
+ className="font-semibold text-sm text-foreground"
383
+ >
384
+ Vertical alignment
385
+ </label>
386
+ <Select
387
+ value={currentVerticalAlign}
388
+ onValueChange={(value) =>
389
+ handleVerticalAlignChange(value as DeckVerticalAlign)
390
+ }
391
+ >
392
+ <SelectTrigger
393
+ id="deck-vertical-align"
394
+ aria-label="Vertical alignment"
395
+ >
396
+ <SelectValue />
397
+ </SelectTrigger>
398
+ <SelectContent>
399
+ {DECK_VERTICAL_ALIGN_OPTIONS.map(({ value, label }) => (
400
+ <SelectItem key={value} value={value}>
401
+ {label}
402
+ </SelectItem>
403
+ ))}
404
+ </SelectContent>
405
+ </Select>
406
+ {activeVerticalAlignDescription && (
407
+ <p className="text-xs text-foreground/70">
408
+ {activeVerticalAlignDescription}
409
+ </p>
410
+ )}
411
+ </div>
340
412
  </div>
341
413
  );
342
414
  };
@@ -8,11 +8,13 @@ import {
8
8
  } from "@/core/cells/cells";
9
9
  import { CellId } from "@/core/cells/ids";
10
10
  import type { CellData, CellRuntimeState } from "@/core/cells/types";
11
+ import type { OutputMessage } from "@/core/kernel/messages";
11
12
  import { MultiColumn } from "@/utils/id-tree";
12
13
  import {
13
14
  disabledCellIds,
14
15
  enabledCellIds,
15
16
  isUninstantiated,
17
+ shouldHidePublishedCell,
16
18
  staleCellIds,
17
19
  } from "../utils";
18
20
 
@@ -426,3 +428,60 @@ describe("enabledCellIds", () => {
426
428
  expect(result).toEqual([cellId2, cellId3]);
427
429
  });
428
430
  });
431
+
432
+ describe("shouldHidePublishedCell", () => {
433
+ const base = {
434
+ errored: false,
435
+ interrupted: false,
436
+ stopped: false,
437
+ output: null,
438
+ showErrorTracebacks: false,
439
+ };
440
+ const errorOutput = (traceback?: string): OutputMessage => ({
441
+ channel: "marimo-error",
442
+ mimetype: "application/vnd.marimo+error",
443
+ data: [
444
+ { type: "exception", exception_type: "ValueError", msg: "!", traceback },
445
+ ],
446
+ timestamp: 0,
447
+ });
448
+
449
+ it("does not hide a healthy cell", () => {
450
+ expect(shouldHidePublishedCell(base)).toBe(false);
451
+ });
452
+
453
+ it.each(["errored", "interrupted", "stopped"] as const)(
454
+ "hides a %s cell",
455
+ (key) => {
456
+ expect(shouldHidePublishedCell({ ...base, [key]: true })).toBe(true);
457
+ },
458
+ );
459
+
460
+ it("hides error outputs", () => {
461
+ expect(shouldHidePublishedCell({ ...base, output: errorOutput() })).toBe(
462
+ true,
463
+ );
464
+ });
465
+
466
+ it("shows error outputs with a traceback when show_tracebacks is enabled", () => {
467
+ expect(
468
+ shouldHidePublishedCell({
469
+ ...base,
470
+ errored: true,
471
+ output: errorOutput("Traceback (most recent call last) ..."),
472
+ showErrorTracebacks: true,
473
+ }),
474
+ ).toBe(false);
475
+ });
476
+
477
+ it("hides error outputs without a traceback even when show_tracebacks is enabled", () => {
478
+ expect(
479
+ shouldHidePublishedCell({
480
+ ...base,
481
+ errored: true,
482
+ output: errorOutput(),
483
+ showErrorTracebacks: true,
484
+ }),
485
+ ).toBe(true);
486
+ });
487
+ });
@@ -2,6 +2,8 @@
2
2
 
3
3
  import type { EditorView } from "@codemirror/view";
4
4
  import { Objects } from "@/utils/objects";
5
+ import type { MarimoError, OutputMessage } from "../kernel/messages";
6
+ import { isErrorMime } from "../mime";
5
7
  import type { RuntimeState } from "../network/types";
6
8
  import type { NotebookState } from "./cells";
7
9
  import type { CellId } from "./ids";
@@ -196,3 +198,52 @@ export function cellStatusClasses({
196
198
  stale: status === "disabled-transitively",
197
199
  };
198
200
  }
201
+
202
+ /**
203
+ * Status classes for a published cell (read or present mode, output only).
204
+ */
205
+ export function publishedCellClasses({
206
+ errored,
207
+ stopped,
208
+ }: {
209
+ errored: boolean;
210
+ stopped: boolean;
211
+ }) {
212
+ return {
213
+ published: true,
214
+ "has-error": errored,
215
+ stopped: stopped,
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Whether a published cell (read or present mode) should be hidden.
221
+ *
222
+ * Errored, interrupted, and stopped cells (and error outputs) are hidden in
223
+ * published views, unless `show_tracebacks` is enabled and the output carries
224
+ * an exception traceback to display inline.
225
+ */
226
+ export function shouldHidePublishedCell({
227
+ errored,
228
+ interrupted,
229
+ stopped,
230
+ output,
231
+ showErrorTracebacks,
232
+ }: {
233
+ errored: boolean;
234
+ interrupted: boolean;
235
+ stopped: boolean;
236
+ output: OutputMessage | null;
237
+ showErrorTracebacks: boolean;
238
+ }): boolean {
239
+ const outputIsError = isErrorMime(output?.mimetype);
240
+ const hasTraceback =
241
+ showErrorTracebacks &&
242
+ outputIsError &&
243
+ Array.isArray(output?.data) &&
244
+ output.data.some(
245
+ (e: MarimoError) =>
246
+ e.type === "exception" && "traceback" in e && e.traceback,
247
+ );
248
+ return (errored || interrupted || stopped || outputIsError) && !hasTraceback;
249
+ }
@@ -255,6 +255,12 @@
255
255
  border: none;
256
256
  box-shadow: none;
257
257
 
258
+ /* No dividers between sections. Tailwind v4's divide-y is structural
259
+ * (`> :not(:last-child)`), so hidden-but-mounted children (e.g. the tray
260
+ * while presenting) still count as siblings and would otherwise draw a
261
+ * stray rule under the output. */
262
+ @apply divide-y-0;
263
+
258
264
  .output-area {
259
265
  /* flow-root interferes with margin collapsing, but appears to be unneeded
260
266
  * when cell outlines are hidden; clear:both is sufficient.
@@ -443,6 +449,10 @@
443
449
  /* Set a fixed gutter width to ensure the hover area is always wide enough */
444
450
  /* And make the gutter bigger when the window is super wide */
445
451
  --gutter-width: 100px;
452
+
453
+ /* Vertical gap between notebook cells (gap-5). Overridable via custom css;
454
+ * zeroed while presenting, when published cells flow together. */
455
+ --notebook-cell-gap: 1.25rem;
446
456
  }
447
457
 
448
458
  /* ------------------------ CodeMirror Editor ----------------------------- */
@@ -0,0 +1,88 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { renderHook } from "@testing-library/react";
3
+ import { createStore, Provider } from "jotai";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { Functions } from "@/utils/functions";
6
+ import { useHotkey } from "../useHotkey";
7
+
8
+ // global.hideCode is bound to "Mod-." by default; "mod" accepts ctrl or meta.
9
+ const SHORTCUT = "global.hideCode";
10
+
11
+ function createWrapper() {
12
+ const store = createStore();
13
+ return ({ children }: { children: React.ReactNode }) => (
14
+ <Provider store={store}>{children}</Provider>
15
+ );
16
+ }
17
+
18
+ function press() {
19
+ const event = new KeyboardEvent("keydown", {
20
+ key: ".",
21
+ ctrlKey: true,
22
+ cancelable: true,
23
+ bubbles: true,
24
+ });
25
+ document.dispatchEvent(event);
26
+ return event;
27
+ }
28
+
29
+ describe("useHotkey", () => {
30
+ it("invokes the callback and prevents default", () => {
31
+ const callback = vi.fn();
32
+ renderHook(() => useHotkey(SHORTCUT, callback), {
33
+ wrapper: createWrapper(),
34
+ });
35
+
36
+ const event = press();
37
+ expect(callback).toHaveBeenCalledOnce();
38
+ expect(event.defaultPrevented).toBe(true);
39
+ });
40
+
41
+ it("does not prevent default when the callback returns false", () => {
42
+ const callback = vi.fn(() => false);
43
+ renderHook(() => useHotkey(SHORTCUT, callback), {
44
+ wrapper: createWrapper(),
45
+ });
46
+
47
+ const event = press();
48
+ expect(callback).toHaveBeenCalledOnce();
49
+ expect(event.defaultPrevented).toBe(false);
50
+ });
51
+
52
+ it("still swallows the keystroke for NOOP catch-all handlers", () => {
53
+ renderHook(() => useHotkey(SHORTCUT, Functions.NOOP), {
54
+ wrapper: createWrapper(),
55
+ });
56
+
57
+ const event = press();
58
+ expect(event.defaultPrevented).toBe(true);
59
+ });
60
+
61
+ it("neither runs the callback nor prevents default when disabled", () => {
62
+ const callback = vi.fn();
63
+ renderHook(() => useHotkey(SHORTCUT, callback, { disabled: true }), {
64
+ wrapper: createWrapper(),
65
+ });
66
+
67
+ const event = press();
68
+ expect(callback).not.toHaveBeenCalled();
69
+ expect(event.defaultPrevented).toBe(false);
70
+ });
71
+
72
+ it("re-enables when disabled flips back to false", () => {
73
+ const callback = vi.fn();
74
+ const { rerender } = renderHook(
75
+ ({ disabled }: { disabled: boolean }) =>
76
+ useHotkey(SHORTCUT, callback, { disabled }),
77
+ { wrapper: createWrapper(), initialProps: { disabled: true } },
78
+ );
79
+
80
+ press();
81
+ expect(callback).not.toHaveBeenCalled();
82
+
83
+ rerender({ disabled: false });
84
+ const event = press();
85
+ expect(callback).toHaveBeenCalledOnce();
86
+ expect(event.defaultPrevented).toBe(true);
87
+ });
88
+ });
@@ -17,13 +17,31 @@ type HotkeyHandler = (
17
17
  // oxlint-disable-next-line typescript/no-invalid-void-type
18
18
  ) => boolean | void | undefined | Promise<void>;
19
19
 
20
+ interface HotkeyOptions {
21
+ /**
22
+ * If true, the hotkey is not handled at all: the callback does not run, the
23
+ * event's default is not prevented, and the action is not registered in the
24
+ * shortcut registry.
25
+ *
26
+ * This differs from passing `Functions.NOOP` as the callback, which still
27
+ * swallows the keystroke (preventDefault) to suppress native browser/OS
28
+ * behavior.
29
+ */
30
+ disabled?: boolean;
31
+ }
32
+
20
33
  /**
21
34
  * Registers a hotkey listener for the given shortcut.
22
35
  *
23
36
  * @param callback The callback to run when the shortcut is pressed. It does not need to be memoized as this hook will always use the latest callback.
24
37
  * If the callback returns false, preventDefault will not be called on the event.
25
38
  */
26
- export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
39
+ export function useHotkey(
40
+ shortcut: HotkeyAction,
41
+ callback: HotkeyHandler,
42
+ options: HotkeyOptions = {},
43
+ ) {
44
+ const { disabled = false } = options;
27
45
  const { registerAction, unregisterAction } = useSetRegisteredAction();
28
46
  const hotkeys = useAtomValue(hotkeysAtom);
29
47
 
@@ -31,7 +49,7 @@ export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
31
49
  const memoizeCallback = useEvent((evt?: KeyboardEvent) => callback(evt));
32
50
 
33
51
  const listener = useEvent((e: KeyboardEvent) => {
34
- if (e.defaultPrevented) {
52
+ if (disabled || e.defaultPrevented) {
35
53
  return;
36
54
  }
37
55
 
@@ -51,11 +69,18 @@ export function useHotkey(shortcut: HotkeyAction, callback: HotkeyHandler) {
51
69
 
52
70
  // Register with the shortcut registry
53
71
  useEffect(() => {
54
- if (!isNOOP) {
72
+ if (!isNOOP && !disabled) {
55
73
  registerAction(shortcut, memoizeCallback);
56
74
  return () => unregisterAction(shortcut);
57
75
  }
58
- }, [memoizeCallback, shortcut, isNOOP, registerAction, unregisterAction]);
76
+ }, [
77
+ memoizeCallback,
78
+ shortcut,
79
+ isNOOP,
80
+ disabled,
81
+ registerAction,
82
+ unregisterAction,
83
+ ]);
59
84
  }
60
85
 
61
86
  /**
@@ -277,25 +277,22 @@ describe("WidgetBinding receives a host in render props", () => {
277
277
  });
278
278
  });
279
279
 
280
- describe("host-mounted views hydrate like display-mounted ones", () => {
281
- it("replays current state to a child's render listeners", async () => {
282
- const childId = asModelId("host-hydration-child");
280
+ describe("host-mounted views", () => {
281
+ it("render with the child's current model state", async () => {
282
+ const childId = asModelId("host-child-state");
283
283
  const parentController = new AbortController();
284
284
  const getModuleSpy = vi.spyOn(WIDGET_DEF_REGISTRY, "getModule");
285
285
  try {
286
286
  const childWidget = {
287
287
  render: vi.fn(({ model, el }) => {
288
- el.textContent = "count is 5";
289
- model.on("change:count", () => {
290
- el.textContent = `count is ${model.get("count")}`;
291
- });
288
+ el.textContent = `count is ${model.get("count")}`;
292
289
  }),
293
290
  };
294
291
  const childModel = new Model<ModelState>({ count: 8 }, createMockComm());
295
292
  WIDGET_REGISTRY.setModel(childId, childModel);
296
293
  WIDGET_REGISTRY.setSpec(childId, {
297
- url: "./@file/10-host-hydration-child.js",
298
- hash: "hash-host-hydration-child",
294
+ url: "./@file/10-host-child-state.js",
295
+ hash: "hash-host-child-state",
299
296
  });
300
297
  getModuleSpy.mockResolvedValue({ default: childWidget });
301
298