@marimo-team/islands 0.23.10-dev18 → 0.23.10-dev20

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.
@@ -1,7 +1,7 @@
1
1
  import { s as __toESM } from "./chunk-BNovOVIE.js";
2
2
  import { t as require_react } from "./react-DA-nE2FX.js";
3
3
  import { u as createLucideIcon } from "./dist-C1BYNeCR.js";
4
- import { T as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7 } from "./strings-Bu3vlb6W.js";
4
+ import { E as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7 } from "./strings-GCJA9n6d.js";
5
5
  var ChartPie = createLucideIcon("chart-pie", [["path", {
6
6
  d: "M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",
7
7
  key: "pzmjnu"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.10-dev18",
3
+ "version": "0.23.10-dev20",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -0,0 +1,166 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { fireEvent, render, screen } from "@testing-library/react";
4
+ import { beforeAll, describe, expect, it, vi } from "vitest";
5
+ import { cellId } from "@/__tests__/branded";
6
+ import { TooltipProvider } from "@/components/ui/tooltip";
7
+ import type { CellId } from "@/core/cells/ids";
8
+ import type { CellData, CellRuntimeState } from "@/core/cells/types";
9
+ import { MultiColumn } from "@/utils/id-tree";
10
+ import { SlidesMinimap } from "../minimap";
11
+
12
+ const A = cellId("a");
13
+ const B = cellId("b");
14
+
15
+ // Spies shared with the hoisted module mocks below.
16
+ const { createNewCell, deleteCell, moveCellToIndex } = vi.hoisted(() => ({
17
+ createNewCell: vi.fn(),
18
+ deleteCell: vi.fn(),
19
+ moveCellToIndex: vi.fn(),
20
+ }));
21
+
22
+ vi.mock("@/core/cells/cells", async (importOriginal) => {
23
+ const actual = await importOriginal<typeof import("@/core/cells/cells")>();
24
+ return {
25
+ ...actual,
26
+ useCellActions: () => ({ moveCellToIndex, createNewCell }),
27
+ useCellIds: () => MultiColumn.from([[A, B]]),
28
+ };
29
+ });
30
+
31
+ vi.mock("@/components/editor/cell/useDeleteCell", () => ({
32
+ useDeleteCellCallback: () => deleteCell,
33
+ }));
34
+
35
+ beforeAll(() => {
36
+ // jsdom doesn't implement these; radix menus poke at them.
37
+ global.HTMLElement.prototype.scrollIntoView = () => {
38
+ /* noop */
39
+ };
40
+ if (!global.HTMLElement.prototype.hasPointerCapture) {
41
+ global.HTMLElement.prototype.hasPointerCapture = () => false;
42
+ }
43
+ if (!global.HTMLElement.prototype.releasePointerCapture) {
44
+ global.HTMLElement.prototype.releasePointerCapture = () => {
45
+ /* noop */
46
+ };
47
+ }
48
+ global.IntersectionObserver ??= class {
49
+ observe() {
50
+ /* noop */
51
+ }
52
+ unobserve() {
53
+ /* noop */
54
+ }
55
+ disconnect() {
56
+ /* noop */
57
+ }
58
+ takeRecords() {
59
+ return [];
60
+ }
61
+ root = null;
62
+ rootMargin = "";
63
+ thresholds = [];
64
+ } as unknown as typeof IntersectionObserver;
65
+ });
66
+
67
+ // The minimap only reads `id`/`code`/`status`/`output`, so a minimal stub is
68
+ // enough; the cast is confined to this helper.
69
+ function makeCell(id: CellId): CellRuntimeState & CellData {
70
+ return {
71
+ id,
72
+ code: `print("${id}")`,
73
+ output: null,
74
+ status: "idle",
75
+ } as unknown as CellRuntimeState & CellData;
76
+ }
77
+
78
+ function renderMinimap() {
79
+ const onSlideClick = vi.fn();
80
+ const utils = render(
81
+ <TooltipProvider>
82
+ <SlidesMinimap
83
+ cells={[makeCell(A), makeCell(B)]}
84
+ thumbnailWidth={200}
85
+ canReorder={false}
86
+ activeCellId={null}
87
+ onSlideClick={onSlideClick}
88
+ />
89
+ </TooltipProvider>,
90
+ );
91
+ return { ...utils, onSlideClick };
92
+ }
93
+
94
+ const EMPTY_CELL = { code: "", autoFocus: false } as const;
95
+
96
+ describe("SlidesMinimap insert lines", () => {
97
+ it("inserts a blank cell above the first row and below any row", () => {
98
+ renderMinimap();
99
+ // First row exposes both an above and a below line; later rows only below.
100
+ // DOM order: [A-above, A-below, B-below].
101
+ const inserts = screen.getAllByTestId("minimap-insert-cell");
102
+ expect(inserts).toHaveLength(3);
103
+
104
+ fireEvent.click(inserts[0]);
105
+ expect(createNewCell).toHaveBeenLastCalledWith({
106
+ cellId: A,
107
+ before: true,
108
+ ...EMPTY_CELL,
109
+ });
110
+
111
+ fireEvent.click(inserts[1]);
112
+ expect(createNewCell).toHaveBeenLastCalledWith({
113
+ cellId: A,
114
+ before: false,
115
+ ...EMPTY_CELL,
116
+ });
117
+
118
+ fireEvent.click(inserts[2]);
119
+ expect(createNewCell).toHaveBeenLastCalledWith({
120
+ cellId: B,
121
+ before: false,
122
+ ...EMPTY_CELL,
123
+ });
124
+ });
125
+ });
126
+
127
+ describe("SlidesMinimap context menu", () => {
128
+ const openRowMenu = (container: HTMLElement, id: CellId) => {
129
+ const row = container.querySelector<HTMLElement>(`[data-cell-id="${id}"]`);
130
+ expect(row).not.toBeNull();
131
+ fireEvent.contextMenu(row!);
132
+ };
133
+
134
+ it('"Add cell" inserts a blank cell below the row', () => {
135
+ const { container } = renderMinimap();
136
+ openRowMenu(container, A);
137
+ fireEvent.click(screen.getByText("Add cell"));
138
+ expect(createNewCell).toHaveBeenCalledWith({
139
+ cellId: A,
140
+ before: false,
141
+ ...EMPTY_CELL,
142
+ });
143
+ });
144
+
145
+ it('"Delete cell" deletes the row\'s cell', () => {
146
+ const { container } = renderMinimap();
147
+ openRowMenu(container, B);
148
+ fireEvent.click(screen.getByText("Delete cell"));
149
+ expect(deleteCell).toHaveBeenCalledWith({ cellId: B });
150
+ });
151
+ });
152
+
153
+ describe("SlidesMinimap keyboard activation", () => {
154
+ it("activates the row on Enter but ignores Space (reserved by reveal.js)", () => {
155
+ const { container, onSlideClick } = renderMinimap();
156
+ const row = container.querySelector<HTMLElement>(`[data-cell-id="${A}"]`);
157
+ expect(row).not.toBeNull();
158
+
159
+ fireEvent.keyDown(row!, { key: "Enter" });
160
+ expect(onSlideClick).toHaveBeenCalledWith(0);
161
+
162
+ onSlideClick.mockClear();
163
+ fireEvent.keyDown(row!, { key: " " });
164
+ expect(onSlideClick).not.toHaveBeenCalled();
165
+ });
166
+ });
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import { useDeleteCellCallback } from "@/components/editor/cell/useDeleteCell";
3
4
  import { useCellActions, useCellIds } from "@/core/cells/cells";
4
5
  import type { CellId } from "@/core/cells/ids";
5
6
  import type { CellColumnId } from "@/utils/id-tree";
@@ -31,9 +32,17 @@ import {
31
32
  } from "@dnd-kit/sortable";
32
33
  import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
33
34
  import { cn } from "@/utils/cn";
35
+ import { Events } from "@/utils/events";
34
36
  import { Slide } from "./slide";
35
- import { InfoIcon, type LucideIcon } from "lucide-react";
37
+ import { InfoIcon, type LucideIcon, PlusIcon, Trash2Icon } from "lucide-react";
36
38
  import { Tooltip } from "@/components/ui/tooltip";
39
+ import {
40
+ ContextMenu,
41
+ ContextMenuContent,
42
+ ContextMenuItem,
43
+ ContextMenuSeparator,
44
+ ContextMenuTrigger,
45
+ } from "@/components/ui/context-menu";
37
46
  import { Logger } from "@/utils/Logger";
38
47
  import { SLIDE_TYPE_OPTIONS_BY_VALUE } from "./slide-form";
39
48
 
@@ -71,7 +80,7 @@ interface SlideThumbnailCardProps extends React.HTMLAttributes<HTMLDivElement> {
71
80
  ref?: React.Ref<HTMLDivElement>;
72
81
  }
73
82
 
74
- interface SlideThumbnailRowProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
83
+ interface SlideThumbnailRowProps extends React.HTMLAttributes<HTMLDivElement> {
75
84
  cell: SlideCell;
76
85
  dimensions: ThumbnailDimensions;
77
86
  isActiveSlide?: boolean;
@@ -80,7 +89,10 @@ interface SlideThumbnailRowProps extends React.ButtonHTMLAttributes<HTMLButtonEl
80
89
  isVisible?: boolean;
81
90
  isNoOutput?: boolean;
82
91
  slideType?: SlideType;
83
- ref?: React.Ref<HTMLButtonElement>;
92
+ onInsertAbove?: () => void;
93
+ onInsertBelow?: () => void;
94
+ onDelete?: () => void;
95
+ ref?: React.Ref<HTMLDivElement>;
84
96
  }
85
97
 
86
98
  interface SlidesMinimapProps {
@@ -216,7 +228,8 @@ export const SlidesMinimap = ({
216
228
  onSlideClick,
217
229
  }: SlidesMinimapProps) => {
218
230
  const cellIds = useCellIds();
219
- const { moveCellToIndex } = useCellActions();
231
+ const { moveCellToIndex, createNewCell } = useCellActions();
232
+ const deleteCell = useDeleteCellCallback();
220
233
  const containerRef = useRef<HTMLDivElement>(null);
221
234
  const visibleIds = useVisibleCellIds(containerRef);
222
235
  const [activeId, setActiveId] = useState<CellId | null>(null);
@@ -225,6 +238,10 @@ export const SlidesMinimap = ({
225
238
  );
226
239
  const dimensions = computeThumbnailDimensions(thumbnailWidth);
227
240
 
241
+ const insertCell = (cellId: CellId, before: boolean) => {
242
+ createNewCell({ cellId, before, code: "", autoFocus: false });
243
+ };
244
+
228
245
  useEffect(() => {
229
246
  if (!activeCellId || !containerRef.current) {
230
247
  return;
@@ -310,6 +327,11 @@ export const SlidesMinimap = ({
310
327
  slideTypes,
311
328
  skippedIds,
312
329
  })}
330
+ onInsertAbove={
331
+ index === 0 ? () => insertCell(cell.id, true) : undefined
332
+ }
333
+ onInsertBelow={() => insertCell(cell.id, false)}
334
+ onDelete={() => deleteCell({ cellId: cell.id })}
313
335
  onClick={() => onSlideClick(index)}
314
336
  />
315
337
  ))}
@@ -353,6 +375,11 @@ export const SlidesMinimap = ({
353
375
  ? dropTarget.position
354
376
  : null
355
377
  }
378
+ onInsertAbove={
379
+ index === 0 ? () => insertCell(cell.id, true) : undefined
380
+ }
381
+ onInsertBelow={() => insertCell(cell.id, false)}
382
+ onDelete={() => deleteCell({ cellId: cell.id })}
356
383
  onClick={() => onSlideClick(index)}
357
384
  />
358
385
  ))}
@@ -399,6 +426,9 @@ interface SortableSlideThumbnailProps {
399
426
  isVisible?: boolean;
400
427
  isNoOutput?: boolean;
401
428
  slideType?: SlideType;
429
+ onInsertAbove?: () => void;
430
+ onInsertBelow?: () => void;
431
+ onDelete?: () => void;
402
432
  onClick?: () => void;
403
433
  }
404
434
 
@@ -411,6 +441,9 @@ const SortableSlideThumbnail = ({
411
441
  isVisible,
412
442
  isNoOutput,
413
443
  slideType,
444
+ onInsertAbove,
445
+ onInsertBelow,
446
+ onDelete,
414
447
  onClick,
415
448
  }: SortableSlideThumbnailProps) => {
416
449
  const { attributes, listeners, setNodeRef } = useSortable({
@@ -428,6 +461,9 @@ const SortableSlideThumbnail = ({
428
461
  isVisible={isVisible}
429
462
  isNoOutput={isNoOutput}
430
463
  slideType={slideType}
464
+ onInsertAbove={onInsertAbove}
465
+ onInsertBelow={onInsertBelow}
466
+ onDelete={onDelete}
431
467
  onClick={onClick}
432
468
  {...attributes}
433
469
  {...listeners}
@@ -446,6 +482,9 @@ const SlideThumbnailRow = ({
446
482
  isVisible,
447
483
  isNoOutput,
448
484
  slideType,
485
+ onInsertAbove,
486
+ onInsertBelow,
487
+ onDelete,
449
488
  onClick,
450
489
  ref,
451
490
  ...props
@@ -456,10 +495,23 @@ const SlideThumbnailRow = ({
456
495
  ...style,
457
496
  };
458
497
 
459
- return (
460
- <button
498
+ // Space is ignored as Reveal.js listens for Space on `document` to advance
499
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
500
+ if (event.target === event.currentTarget && event.key === "Enter") {
501
+ event.preventDefault();
502
+ event.stopPropagation();
503
+ event.currentTarget.click();
504
+ }
505
+ };
506
+
507
+ const row = (
508
+ <div
461
509
  ref={ref}
462
- type="button"
510
+ // A real <button> can't host the nested insert <button>s (invalid HTML),
511
+ // so we keep button semantics via role + keyboard handling below.
512
+ // eslint-disable-next-line jsx-a11y/prefer-tag-over-role
513
+ role="button"
514
+ tabIndex={0}
463
515
  data-cell-id={cell.id}
464
516
  className={cn(
465
517
  "relative shrink-0 appearance-none text-left p-0 bg-transparent outline-none",
@@ -467,6 +519,7 @@ const SlideThumbnailRow = ({
467
519
  )}
468
520
  style={rowStyle}
469
521
  onClick={onClick}
522
+ onKeyDown={handleKeyDown}
470
523
  {...props}
471
524
  >
472
525
  {dropIndicator && (
@@ -479,6 +532,9 @@ const SlideThumbnailRow = ({
479
532
  )}
480
533
  />
481
534
  )}
535
+ {onInsertAbove && (
536
+ <InsertCellLine position="above" onInsert={onInsertAbove} />
537
+ )}
482
538
  <SlideThumbnailCard
483
539
  cell={cell}
484
540
  dimensions={dimensions}
@@ -488,7 +544,68 @@ const SlideThumbnailRow = ({
488
544
  isNoOutput={isNoOutput}
489
545
  slideType={slideType}
490
546
  />
491
- </button>
547
+ {onInsertBelow && (
548
+ <InsertCellLine position="below" onInsert={onInsertBelow} />
549
+ )}
550
+ </div>
551
+ );
552
+
553
+ if (!onInsertBelow && !onDelete) {
554
+ return row;
555
+ }
556
+
557
+ return (
558
+ <ContextMenu>
559
+ <ContextMenuTrigger asChild={true}>{row}</ContextMenuTrigger>
560
+ <ContextMenuContent>
561
+ {onInsertBelow && (
562
+ <ContextMenuItem onSelect={onInsertBelow}>
563
+ <PlusIcon className="mr-2 h-3.5 w-3.5" />
564
+ Add cell
565
+ </ContextMenuItem>
566
+ )}
567
+ <ContextMenuSeparator />
568
+ {onDelete && (
569
+ <ContextMenuItem variant="danger" onSelect={onDelete}>
570
+ <Trash2Icon className="mr-2 h-3.5 w-3.5" />
571
+ Delete cell
572
+ </ContextMenuItem>
573
+ )}
574
+ </ContextMenuContent>
575
+ </ContextMenu>
576
+ );
577
+ };
578
+
579
+ const InsertCellLine = ({
580
+ position,
581
+ onInsert,
582
+ }: {
583
+ position: "above" | "below";
584
+ onInsert: () => void;
585
+ }) => {
586
+ return (
587
+ <Tooltip content="Add Python cell">
588
+ <button
589
+ type="button"
590
+ aria-label="Add Python cell"
591
+ data-testid="minimap-insert-cell"
592
+ className={cn(
593
+ "absolute left-0 right-0 z-30 flex h-3 items-center justify-center",
594
+ "opacity-0 transition-opacity hover:opacity-80 focus-visible:opacity-100 focus:outline-none",
595
+ position === "below"
596
+ ? "bottom-0 translate-y-1/2"
597
+ : "top-0 -translate-y-1/2",
598
+ )}
599
+ // Stop the pointer event from reaching the row's drag sensor / click.
600
+ onPointerDown={Events.stopPropagation()}
601
+ onClick={Events.stopPropagation(onInsert)}
602
+ >
603
+ <span className="absolute left-2 right-2 h-px rounded-full bg-blue-500" />
604
+ <span className="relative flex h-3 w-3 items-center justify-center rounded-full bg-blue-500 text-background shadow-xs">
605
+ <PlusIcon className="h-2 w-2" strokeWidth={3} />
606
+ </span>
607
+ </button>
608
+ </Tooltip>
492
609
  );
493
610
  };
494
611
 
@@ -529,10 +646,10 @@ const SlideThumbnailCard = ({
529
646
  <div
530
647
  ref={ref}
531
648
  className={cn(
532
- "border-2 shrink-0 rounded-md relative select-none bg-background cursor-pointer active:cursor-grabbing overflow-hidden",
649
+ "border-2 shrink-0 rounded-md relative select-none bg-background cursor-pointer active:cursor-grabbing overflow-hidden transition-colors",
533
650
  isActiveSlide || isActiveDragSource || isOverlay
534
651
  ? "border-blue-500"
535
- : "border-border",
652
+ : "border-border hover:border-blue-500/50",
536
653
  isActiveDragSource && !isOverlay && "opacity-35",
537
654
  isOverlay && "opacity-95 shadow-lg",
538
655
  className,