@marimo-team/islands 0.23.16-dev4 → 0.23.16-dev6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.16-dev4",
3
+ "version": "0.23.16-dev6",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -0,0 +1,198 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { act, render, screen } from "@testing-library/react";
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
+ import {
6
+ shouldShowScrollHint,
7
+ SlideScrollContainer,
8
+ } from "../slide-scroll-hint";
9
+
10
+ describe("shouldShowScrollHint", () => {
11
+ it("shows when content overflows and scroll is at the top", () => {
12
+ expect(
13
+ shouldShowScrollHint({
14
+ scrollHeight: 800,
15
+ clientHeight: 400,
16
+ scrollTop: 0,
17
+ }),
18
+ ).toBe(true);
19
+ });
20
+
21
+ it("hides when content fits", () => {
22
+ expect(
23
+ shouldShowScrollHint({
24
+ scrollHeight: 300,
25
+ clientHeight: 400,
26
+ scrollTop: 0,
27
+ }),
28
+ ).toBe(false);
29
+ });
30
+
31
+ it("hides after the user scrolls down", () => {
32
+ expect(
33
+ shouldShowScrollHint({
34
+ scrollHeight: 800,
35
+ clientHeight: 400,
36
+ scrollTop: 40,
37
+ }),
38
+ ).toBe(false);
39
+ });
40
+
41
+ it("ignores sub-pixel overflow", () => {
42
+ expect(
43
+ shouldShowScrollHint({
44
+ scrollHeight: 401,
45
+ clientHeight: 400,
46
+ scrollTop: 0,
47
+ }),
48
+ ).toBe(false);
49
+ });
50
+
51
+ it("still shows within the top threshold", () => {
52
+ expect(
53
+ shouldShowScrollHint({
54
+ scrollHeight: 800,
55
+ clientHeight: 400,
56
+ scrollTop: 8,
57
+ }),
58
+ ).toBe(true);
59
+ });
60
+ });
61
+
62
+ describe("SlideScrollContainer", () => {
63
+ const resizeObservers: Array<{
64
+ callback: ResizeObserverCallback;
65
+ observe: ReturnType<typeof vi.fn>;
66
+ disconnect: ReturnType<typeof vi.fn>;
67
+ }> = [];
68
+
69
+ beforeEach(() => {
70
+ resizeObservers.length = 0;
71
+ vi.stubGlobal("requestAnimationFrame", (cb: FrameRequestCallback) => {
72
+ cb(0);
73
+ return 0;
74
+ });
75
+ vi.stubGlobal("cancelAnimationFrame", vi.fn());
76
+ vi.stubGlobal(
77
+ "ResizeObserver",
78
+ class MockResizeObserver {
79
+ callback: ResizeObserverCallback;
80
+ observe = vi.fn();
81
+ unobserve = vi.fn();
82
+ disconnect = vi.fn();
83
+
84
+ constructor(callback: ResizeObserverCallback) {
85
+ this.callback = callback;
86
+ resizeObservers.push(this);
87
+ }
88
+ },
89
+ );
90
+ vi.stubGlobal(
91
+ "MutationObserver",
92
+ class MockMutationObserver {
93
+ observe = vi.fn();
94
+ disconnect = vi.fn();
95
+ takeRecords = vi.fn(() => []);
96
+ },
97
+ );
98
+ });
99
+
100
+ afterEach(() => {
101
+ vi.unstubAllGlobals();
102
+ });
103
+
104
+ function stubOverflow(
105
+ el: HTMLElement,
106
+ metrics: {
107
+ scrollHeight: number;
108
+ clientHeight: number;
109
+ scrollTop?: number;
110
+ },
111
+ ) {
112
+ Object.defineProperty(el, "scrollHeight", {
113
+ configurable: true,
114
+ get: () => metrics.scrollHeight,
115
+ });
116
+ Object.defineProperty(el, "clientHeight", {
117
+ configurable: true,
118
+ get: () => metrics.clientHeight,
119
+ });
120
+ Object.defineProperty(el, "scrollTop", {
121
+ configurable: true,
122
+ get: () => metrics.scrollTop ?? 0,
123
+ set: (value: number) => {
124
+ metrics.scrollTop = value;
125
+ },
126
+ });
127
+ }
128
+
129
+ it("renders a scroll hint when content overflows", () => {
130
+ render(
131
+ <SlideScrollContainer>
132
+ <div>tall content</div>
133
+ </SlideScrollContainer>,
134
+ );
135
+
136
+ const container = screen.getByTestId("slide-scroll-container");
137
+ stubOverflow(container, { scrollHeight: 900, clientHeight: 400 });
138
+
139
+ act(() => {
140
+ for (const observer of resizeObservers) {
141
+ observer.callback([], observer as unknown as ResizeObserver);
142
+ }
143
+ });
144
+
145
+ expect(screen.getByTestId("slide-scroll-hint")).toBeTruthy();
146
+ expect(screen.getByText("Scroll for more")).toBeTruthy();
147
+ });
148
+
149
+ it("hides the hint after scrolling", () => {
150
+ const metrics = {
151
+ scrollHeight: 900,
152
+ clientHeight: 400,
153
+ scrollTop: 0,
154
+ };
155
+
156
+ render(
157
+ <SlideScrollContainer>
158
+ <div>tall content</div>
159
+ </SlideScrollContainer>,
160
+ );
161
+
162
+ const container = screen.getByTestId("slide-scroll-container");
163
+ stubOverflow(container, metrics);
164
+
165
+ act(() => {
166
+ for (const observer of resizeObservers) {
167
+ observer.callback([], observer as unknown as ResizeObserver);
168
+ }
169
+ });
170
+ expect(screen.getByTestId("slide-scroll-hint")).toBeTruthy();
171
+
172
+ act(() => {
173
+ metrics.scrollTop = 50;
174
+ container.dispatchEvent(new Event("scroll"));
175
+ });
176
+
177
+ expect(screen.queryByTestId("slide-scroll-hint")).toBeNull();
178
+ });
179
+
180
+ it("does not show a hint when content fits", () => {
181
+ render(
182
+ <SlideScrollContainer>
183
+ <div>short content</div>
184
+ </SlideScrollContainer>,
185
+ );
186
+
187
+ const container = screen.getByTestId("slide-scroll-container");
188
+ stubOverflow(container, { scrollHeight: 200, clientHeight: 400 });
189
+
190
+ act(() => {
191
+ for (const observer of resizeObservers) {
192
+ observer.callback([], observer as unknown as ResizeObserver);
193
+ }
194
+ });
195
+
196
+ expect(screen.queryByTestId("slide-scroll-hint")).toBeNull();
197
+ });
198
+ });
@@ -14,6 +14,7 @@ import { CodeIcon, ExpandIcon, EyeOffIcon } from "lucide-react";
14
14
  import { Deck, Fragment, Slide, Stack } from "@revealjs/react";
15
15
  import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
16
16
  import { Slide as CellOutputSlide } from "@/components/slides/slide";
17
+ import { SlideScrollContainer } from "@/components/slides/slide-scroll-hint";
17
18
  import { Button } from "@/components/ui/button";
18
19
  import { useFullScreenElement } from "@/components/ui/fullscreen";
19
20
  import { Tooltip } from "@/components/ui/tooltip";
@@ -327,7 +328,7 @@ const SubslideView = ({
327
328
 
328
329
  return (
329
330
  <Slide>
330
- <div className="h-full w-full overflow-auto flex">
331
+ <SlideScrollContainer>
331
332
  <div
332
333
  className={
333
334
  anyCodeShown
@@ -367,7 +368,7 @@ const SubslideView = ({
367
368
  return <ReactFragment key={i}>{rendered}</ReactFragment>;
368
369
  })}
369
370
  </div>
370
- </div>
371
+ </SlideScrollContainer>
371
372
  {/* Outside any `.fragment`: shown only before any fragment is revealed. */}
372
373
  {slideLevel && <NotesAside text={slideLevel} />}
373
374
  </Slide>
@@ -0,0 +1,161 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { ChevronDownIcon } from "lucide-react";
4
+ import {
5
+ type ReactNode,
6
+ type RefObject,
7
+ useEffect,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+ import { cn } from "@/utils/cn";
12
+
13
+ /** Pixels of scroll before the hint is considered dismissed. */
14
+ const TOP_THRESHOLD_PX = 8;
15
+ /** Ignore sub-pixel overflow from rounding / borders. */
16
+ const OVERFLOW_TOLERANCE_PX = 1;
17
+
18
+ /**
19
+ * Whether a scroll container should show a "more content below" affordance.
20
+ * Visible only when content overflows and the viewport is still near the top.
21
+ */
22
+ export function shouldShowScrollHint(options: {
23
+ scrollHeight: number;
24
+ clientHeight: number;
25
+ scrollTop: number;
26
+ }): boolean {
27
+ const { scrollHeight, clientHeight, scrollTop } = options;
28
+ const overflowing = scrollHeight > clientHeight + OVERFLOW_TOLERANCE_PX;
29
+ const atTop = scrollTop <= TOP_THRESHOLD_PX;
30
+ return overflowing && atTop;
31
+ }
32
+
33
+ /**
34
+ * Measure only up to the first unrevealed fragment so
35
+ * the hint reflects currently revealed content, not future fragment steps.
36
+ */
37
+ function measureRevealedHeight(el: HTMLElement): number {
38
+ const firstUnrevealed = el.querySelector<HTMLElement>(
39
+ ".fragment:not(.visible)",
40
+ );
41
+ if (!firstUnrevealed) {
42
+ return el.scrollHeight;
43
+ }
44
+ const fragmentTop = firstUnrevealed.getBoundingClientRect().top;
45
+ return fragmentTop - el.getBoundingClientRect().top + el.scrollTop;
46
+ }
47
+
48
+ /**
49
+ * Tracks whether a scroll container is overflowing at the top, so we can
50
+ * surface a scroll affordance.
51
+ */
52
+ function useScrollHint(
53
+ scrollRef: RefObject<HTMLElement | null>,
54
+ contentRef: RefObject<HTMLElement | null>,
55
+ ): boolean {
56
+ const [showHint, setShowHint] = useState(false);
57
+
58
+ useEffect(() => {
59
+ const el = scrollRef.current;
60
+ const content = contentRef.current;
61
+ if (!el || !content) {
62
+ return;
63
+ }
64
+
65
+ let frame = 0;
66
+ const update = () => {
67
+ cancelAnimationFrame(frame);
68
+ frame = requestAnimationFrame(() => {
69
+ setShowHint(
70
+ shouldShowScrollHint({
71
+ scrollHeight: measureRevealedHeight(el),
72
+ clientHeight: el.clientHeight,
73
+ scrollTop: el.scrollTop,
74
+ }),
75
+ );
76
+ });
77
+ };
78
+
79
+ update();
80
+
81
+ const resizeObserver = new ResizeObserver(update);
82
+ resizeObserver.observe(el);
83
+ resizeObserver.observe(content);
84
+
85
+ // Fragments reveal via class changes (opacity/visibility, no layout shift),
86
+ // which the ResizeObserver can't see, so re-check on class mutations. Only
87
+ // attach on slides that have fragments to avoid reacting to unrelated class
88
+ // churn (e.g. animating widgets) on the common non-fragment slide.
89
+ const fragmentObserver = content.querySelector(".fragment")
90
+ ? new MutationObserver(update)
91
+ : null;
92
+ fragmentObserver?.observe(content, {
93
+ subtree: true,
94
+ attributes: true,
95
+ attributeFilter: ["class"],
96
+ });
97
+
98
+ el.addEventListener("scroll", update, { passive: true });
99
+
100
+ return () => {
101
+ cancelAnimationFrame(frame);
102
+ resizeObserver.disconnect();
103
+ fragmentObserver?.disconnect();
104
+ el.removeEventListener("scroll", update);
105
+ };
106
+ }, [scrollRef, contentRef]);
107
+
108
+ return showHint;
109
+ }
110
+
111
+ const ScrollHintOverlay = ({ className }: { className?: string }) => {
112
+ return (
113
+ <div
114
+ className={cn(
115
+ "pointer-events-none absolute inset-x-0 bottom-0 z-10 flex flex-col items-center",
116
+ "animate-in fade-in-0 duration-200",
117
+ className,
118
+ )}
119
+ data-testid="slide-scroll-hint"
120
+ aria-hidden={true}
121
+ >
122
+ <div className="h-16 w-full bg-linear-to-t from-background via-background/80 to-transparent" />
123
+ <div className="absolute bottom-3 flex items-center gap-1 rounded-full border border-border/60 bg-background/90 px-2.5 py-1 text-xs text-muted-foreground shadow-sm backdrop-blur-sm">
124
+ <ChevronDownIcon className="h-3.5 w-3.5" />
125
+ <span>Scroll for more</span>
126
+ </div>
127
+ </div>
128
+ );
129
+ };
130
+
131
+ /**
132
+ * Full-height scroll container for a slide. Shows a dismissible "Scroll for
133
+ * more" cue when content overflows the frame (easy to miss in fullscreen when
134
+ * OS overlay scrollbars are hidden).
135
+ */
136
+ export const SlideScrollContainer = ({
137
+ children,
138
+ className,
139
+ }: {
140
+ children: ReactNode;
141
+ className?: string;
142
+ }) => {
143
+ const scrollRef = useRef<HTMLDivElement>(null);
144
+ const contentRef = useRef<HTMLDivElement>(null);
145
+ const showHint = useScrollHint(scrollRef, contentRef);
146
+
147
+ return (
148
+ <div className={cn("relative h-full w-full", className)}>
149
+ <div
150
+ ref={scrollRef}
151
+ className="h-full w-full overflow-auto"
152
+ data-testid="slide-scroll-container"
153
+ >
154
+ <div ref={contentRef} className="flex w-full min-h-full">
155
+ {children}
156
+ </div>
157
+ </div>
158
+ {showHint && <ScrollHintOverlay />}
159
+ </div>
160
+ );
161
+ };