@marimo-team/islands 0.26.1-dev108 → 0.26.1-dev118
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/dist/{ErrorBoundary-BW4TciqU.js → ErrorBoundary-Gr2Kt5kj.js} +1 -1
- package/dist/{chat-ui-Be9X-W22.js → chat-ui-CMKYvKUz.js} +3 -3
- package/dist/{code-visibility-BKmktPMd.js → code-visibility-BFFe0rT7.js} +2 -2
- package/dist/{common-CSJAjJGa.js → common-7eNIhSN-.js} +4766 -4747
- package/dist/{data-grid-overlay-editor-DTibdR4H.js → data-grid-overlay-editor-B37-1-8n.js} +1 -1
- package/dist/{error-entries-23Z_1oDM.js → error-entries-B4LgfizR.js} +772 -751
- package/dist/{feedback-button-CPu5SV3b.js → feedback-button-CpQcgVuz.js} +3 -3
- package/dist/{formats-Y52bg800.js → formats-CeuXJ_1f.js} +32 -25
- package/dist/{glide-data-editor-CC9_NDNi.js → glide-data-editor-BxTlDHV5.js} +3 -3
- package/dist/{globals-BFlYTNoR.js → globals-ljOLdTJr.js} +1 -1
- package/dist/{html-to-image-Cw7o1IbE.js → html-to-image-CIkwg7mv.js} +1 -1
- package/dist/main.js +69 -66
- package/dist/{number-overlay-editor-qDcRKPE0.js → number-overlay-editor-DGKTstav.js} +1 -1
- package/dist/{process-output-DdBM0lmd.js → process-output-PS9YSLNu.js} +2 -2
- package/dist/{reveal-component-BE1xhtNc.js → reveal-component-BLJMkx2N.js} +2 -2
- package/dist/{useDeepCompareMemoize-Dn-ZJVTd.js → semaphore-8KhQouXt.js} +5 -15
- package/dist/style.css +1 -1
- package/dist/{vega-component-BIq0qzhQ.js → vega-component-CoJiBCaS.js} +11 -11
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +1 -1
- package/src/__mocks__/intersection-observer.ts +5 -5
- package/src/components/editor/Output.tsx +3 -21
- package/src/components/editor/__tests__/cell-renders.test.tsx +327 -1
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +27 -0
- package/src/components/editor/actions/pair-with-agent-modal.tsx +8 -1
- package/src/components/editor/ai/__tests__/completion-utils.test.ts +12 -20
- package/src/components/editor/ai/ai-completion-editor.tsx +391 -289
- package/src/components/editor/ai/completion-utils.ts +9 -7
- package/src/components/editor/cell/CellDeleteShoulder.tsx +82 -0
- package/src/components/editor/cell/DeleteButton.tsx +11 -2
- package/src/components/editor/cell/__tests__/CellDeleteShoulder.test.tsx +181 -0
- package/src/components/editor/cell/code/cell-editor.tsx +15 -25
- package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +26 -2
- package/src/components/editor/chrome/panels/logs-panel.tsx +27 -11
- package/src/components/editor/notebook-cell.tsx +20 -40
- package/src/components/editor/output/VegaOutput.tsx +35 -0
- package/src/components/find-replace/find-replace.tsx +1 -7
- package/src/core/ai/state.ts +6 -0
- package/src/core/cells/__tests__/cell-errors.test.tsx +179 -0
- package/src/core/cells/__tests__/cells.test.ts +34 -20
- package/src/core/cells/cell-log-chunks.ts +31 -0
- package/src/core/cells/cells.ts +34 -33
- package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +18 -15
- package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +90 -2
- package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +44 -10
- package/src/core/codemirror/find-replace/navigate.ts +4 -1
- package/src/core/codemirror/find-replace/search-highlight.ts +54 -58
- package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +1 -1
- package/src/core/codemirror/lsp/__tests__/transports.test.ts +1 -1
- package/src/core/executions/__tests__/atoms.test.ts +0 -2
- package/src/core/executions/__tests__/output-lifecycle.test.ts +16 -0
- package/src/core/executions/atoms.ts +33 -36
- package/src/core/export/__tests__/output-snapshot.test.tsx +240 -0
- package/src/core/export/__tests__/output-subscription.test.tsx +79 -0
- package/src/core/export/hooks.ts +29 -13
- package/src/core/islands/__tests__/bridge.test.ts +2 -5
- package/src/core/notebook/replica/frame.ts +8 -2
- package/src/core/notebook/replica/index.ts +5 -1
- package/src/core/notebook/replica/once-per-frame.ts +4 -3
- package/src/core/notebook/replica/resources/executions.ts +16 -1
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +10 -1
- package/src/css/common.css +11 -0
- package/src/hooks/useFinePointer.ts +30 -0
- package/src/stories/log-viewer.stories.tsx +48 -44
- package/src/utils/shared-intersection-observer.ts +2 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, render } from "@testing-library/react";
|
|
4
|
+
import { createStore, Provider } from "jotai";
|
|
5
|
+
import { Profiler } from "react";
|
|
6
|
+
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
|
7
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
8
|
+
import { MockRequestClient } from "@/__mocks__/requests";
|
|
9
|
+
import { cellId } from "@/__tests__/branded";
|
|
10
|
+
import { createRenderTracker } from "@/__tests__/render-tracker";
|
|
11
|
+
import { pageAppConfigAtom } from "@/core/config/config";
|
|
12
|
+
import { cellOutputsAtom, releaseCellOutputAtoms } from "@/core/executions";
|
|
13
|
+
import { connectionAtom } from "@/core/network/connection";
|
|
14
|
+
import { requestClientAtom } from "@/core/network/requests";
|
|
15
|
+
import { ConnectionState } from "@/core/session/types";
|
|
16
|
+
import { invariant } from "@/utils/invariant";
|
|
17
|
+
import { useAutoExport } from "../hooks";
|
|
18
|
+
|
|
19
|
+
function AutoExportOwner() {
|
|
20
|
+
useAutoExport();
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe.each([2, 250])("auto-export with %i cells", (size) => {
|
|
25
|
+
it("does no export work when a plain-text output changes", () => {
|
|
26
|
+
const store = createStore();
|
|
27
|
+
const ids = Array.from({ length: size }, (_, i) => cellId(`cell-${i}`));
|
|
28
|
+
const replica = MockExecutions.seed(
|
|
29
|
+
store,
|
|
30
|
+
ids.map((id) =>
|
|
31
|
+
MockExecutions.shown(id, { mimetype: "text/plain", data: id }),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
store.set(requestClientAtom, MockRequestClient.create());
|
|
35
|
+
store.set(connectionAtom, { state: ConnectionState.OPEN });
|
|
36
|
+
store.set(pageAppConfigAtom, { auto_download: [] });
|
|
37
|
+
|
|
38
|
+
const readOutputs = vi.spyOn(cellOutputsAtom, "read");
|
|
39
|
+
const renders = createRenderTracker();
|
|
40
|
+
const { unmount } = render(
|
|
41
|
+
<Provider store={store}>
|
|
42
|
+
<Profiler id="auto-export" onRender={renders.onRender}>
|
|
43
|
+
<AutoExportOwner />
|
|
44
|
+
</Profiler>
|
|
45
|
+
</Provider>,
|
|
46
|
+
);
|
|
47
|
+
onTestFinished(() => {
|
|
48
|
+
unmount();
|
|
49
|
+
readOutputs.mockRestore();
|
|
50
|
+
ids.forEach(releaseCellOutputAtoms);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(renders.counts()["auto-export"]).toBeGreaterThan(0);
|
|
54
|
+
expect.soft(readOutputs).toHaveBeenCalledTimes(0);
|
|
55
|
+
readOutputs.mockClear();
|
|
56
|
+
renders.reset();
|
|
57
|
+
|
|
58
|
+
const [changedCell] = ids;
|
|
59
|
+
act(() => {
|
|
60
|
+
store.set(replica.resultsAtom, (results) => {
|
|
61
|
+
const before = results.get(changedCell);
|
|
62
|
+
invariant(before, "The changed cell has a result");
|
|
63
|
+
return new Map(results).set(changedCell, {
|
|
64
|
+
...before,
|
|
65
|
+
output: MockExecutions.output(before.record, {
|
|
66
|
+
mimetype: "text/plain",
|
|
67
|
+
data: "updated",
|
|
68
|
+
}),
|
|
69
|
+
outputVersion: before.outputVersion + 1,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect({
|
|
75
|
+
aggregateReads: readOutputs.mock.calls.length,
|
|
76
|
+
commits: renders.counts(),
|
|
77
|
+
}).toEqual({ aggregateReads: 0, commits: {} });
|
|
78
|
+
});
|
|
79
|
+
});
|
package/src/core/export/hooks.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import { useAtomValue } from "jotai";
|
|
2
|
+
import { useAtomValue, useStore } from "jotai";
|
|
3
|
+
// Screenshot capture reads the DOM immediately after publishing a pending frame.
|
|
4
|
+
// react-doctor-disable-next-line react-doctor/no-flush-sync
|
|
5
|
+
import { flushSync } from "react-dom";
|
|
3
6
|
import type { MimeType } from "@/components/editor/Output";
|
|
4
7
|
import { toast } from "@/components/ui/use-toast";
|
|
5
8
|
import { appConfigAtom } from "@/core/config/config";
|
|
@@ -9,14 +12,15 @@ import { getImageDataUrlForCell } from "@/utils/download";
|
|
|
9
12
|
import { Logger } from "@/utils/Logger";
|
|
10
13
|
import { Objects } from "@/utils/objects";
|
|
11
14
|
import { ProgressState } from "@/utils/progress";
|
|
12
|
-
import type
|
|
13
|
-
import { cellOutputsAtom } from "../executions";
|
|
15
|
+
import { type CellId, CellOutputId } from "../cells/ids";
|
|
16
|
+
import { type CellOutput, cellOutputsAtom } from "../executions";
|
|
14
17
|
import { getExportLayout } from "./layout";
|
|
15
18
|
import { connectionAtom } from "../network/connection";
|
|
16
19
|
import { useRequestClient } from "../network/requests";
|
|
17
20
|
import type { UpdateCellOutputsRequest } from "../network/types";
|
|
18
21
|
import { VirtualFileTracker } from "../static/virtual-file-tracker";
|
|
19
22
|
import { ConnectionState } from "../session/types";
|
|
23
|
+
import { activeNotebookFrameAtom } from "../session/active-notebook";
|
|
20
24
|
|
|
21
25
|
const DELAY = 5000; // 5 seconds;
|
|
22
26
|
|
|
@@ -91,9 +95,7 @@ export function useAutoExport() {
|
|
|
91
95
|
);
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
const MIME_TYPES_TO_CAPTURE_SCREENSHOTS = new Set<MimeType>([
|
|
96
|
-
"text/html",
|
|
98
|
+
const VEGA_MIME_TYPES = new Set<MimeType>([
|
|
97
99
|
"application/vnd.vegalite.v5+json",
|
|
98
100
|
"application/vnd.vega.v5+json",
|
|
99
101
|
"application/vnd.vegalite.v6+json",
|
|
@@ -122,17 +124,18 @@ interface UseEnrichCellOutputsOptions {
|
|
|
122
124
|
export function useEnrichCellOutputs(): (
|
|
123
125
|
opts: UseEnrichCellOutputsOptions,
|
|
124
126
|
) => Promise<ScreenshotResults> {
|
|
125
|
-
const
|
|
127
|
+
const store = useStore();
|
|
126
128
|
|
|
127
129
|
return async (
|
|
128
130
|
opts: UseEnrichCellOutputsOptions,
|
|
129
131
|
): Promise<ScreenshotResults> => {
|
|
130
132
|
const { progress } = opts;
|
|
133
|
+
const outputs = store.get(cellOutputsAtom);
|
|
131
134
|
|
|
132
135
|
// Prune tracked state for cells that no longer show anything
|
|
133
136
|
captureTracker.prune(new Set(outputs.keys()));
|
|
134
137
|
|
|
135
|
-
const cellsToCaptureScreenshot: [CellId,
|
|
138
|
+
const cellsToCaptureScreenshot: [CellId, CellOutput][] = [];
|
|
136
139
|
const inFlightWaiters: {
|
|
137
140
|
cellId: CellId;
|
|
138
141
|
promise: Promise<ScreenshotResult | undefined>;
|
|
@@ -141,11 +144,12 @@ export function useEnrichCellOutputs(): (
|
|
|
141
144
|
for (const [cellId, output] of outputs) {
|
|
142
145
|
const outputData = output.data;
|
|
143
146
|
if (
|
|
144
|
-
|
|
147
|
+
(output.mimetype === "text/html" ||
|
|
148
|
+
VEGA_MIME_TYPES.has(output.mimetype)) &&
|
|
145
149
|
outputData
|
|
146
150
|
) {
|
|
147
151
|
if (captureTracker.needsCapture(cellId, outputData)) {
|
|
148
|
-
cellsToCaptureScreenshot.push([cellId,
|
|
152
|
+
cellsToCaptureScreenshot.push([cellId, output]);
|
|
149
153
|
} else {
|
|
150
154
|
// If already in-flight with the same value, await its result
|
|
151
155
|
const promise = captureTracker.waitForInFlight(cellId, outputData);
|
|
@@ -160,17 +164,29 @@ export function useEnrichCellOutputs(): (
|
|
|
160
164
|
return {};
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
// Start the progress bar for new captures only
|
|
164
167
|
if (cellsToCaptureScreenshot.length > 0) {
|
|
168
|
+
const frame = store.get(activeNotebookFrameAtom);
|
|
169
|
+
if (frame) {
|
|
170
|
+
flushSync(frame.flush);
|
|
171
|
+
}
|
|
165
172
|
progress.addTotal(cellsToCaptureScreenshot.length);
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
// Capture screenshots — each key gets its own AbortSignal so
|
|
169
176
|
// aborting one cell does not affect the others.
|
|
170
177
|
const results: ScreenshotResults = {};
|
|
171
|
-
for (const [cellId,
|
|
172
|
-
const handle = captureTracker.startCapture(cellId,
|
|
178
|
+
for (const [cellId, output] of cellsToCaptureScreenshot) {
|
|
179
|
+
const handle = captureTracker.startCapture(cellId, output.data);
|
|
173
180
|
try {
|
|
181
|
+
if (
|
|
182
|
+
VEGA_MIME_TYPES.has(output.mimetype) &&
|
|
183
|
+
!document
|
|
184
|
+
.getElementById(CellOutputId.create(cellId))
|
|
185
|
+
?.querySelector("[data-marimo-vega-ready]")
|
|
186
|
+
) {
|
|
187
|
+
handle.markFailed();
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
174
190
|
const dataUrl = await getImageDataUrlForCell(cellId);
|
|
175
191
|
if (handle.signal.aborted) {
|
|
176
192
|
continue;
|
|
@@ -444,11 +444,8 @@ describe("IslandsPyodideBridge", () => {
|
|
|
444
444
|
expect(
|
|
445
445
|
store
|
|
446
446
|
.get(notebookAtom)
|
|
447
|
-
.cellLogs.
|
|
448
|
-
|
|
449
|
-
message,
|
|
450
|
-
source,
|
|
451
|
-
]),
|
|
447
|
+
.cellLogs.flat()
|
|
448
|
+
.map(({ level, message, source }) => [level, message, source]),
|
|
452
449
|
).toEqual([
|
|
453
450
|
["stdout", "hello", { type: "cell", cellId: "c2" }],
|
|
454
451
|
["stderr", "warning", { type: "cell", cellId: "c2" }],
|
|
@@ -4,7 +4,7 @@ import { atom, type createStore } from "jotai/vanilla";
|
|
|
4
4
|
import type { NotebookReplica } from "./replica";
|
|
5
5
|
import { oncePerFrame } from "./once-per-frame";
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type FrameSource = Pick<
|
|
8
8
|
NotebookReplica,
|
|
9
9
|
| "notebookAtom"
|
|
10
10
|
| "generationAtom"
|
|
@@ -16,10 +16,15 @@ export type ReplicaFrame = Pick<
|
|
|
16
16
|
| "runtimeAtom"
|
|
17
17
|
>;
|
|
18
18
|
|
|
19
|
+
export interface ReplicaFrame extends FrameSource {
|
|
20
|
+
/** Publish pending state before an operation reads the rendered notebook. */
|
|
21
|
+
flush(): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
/** The replica's display atoms, republished together once per frame. */
|
|
20
25
|
export function createReplicaFrame(
|
|
21
26
|
store: ReturnType<typeof createStore>,
|
|
22
|
-
replica:
|
|
27
|
+
replica: FrameSource,
|
|
23
28
|
{ signal }: { signal: AbortSignal },
|
|
24
29
|
): ReplicaFrame {
|
|
25
30
|
const currentAtom = atom((get) => ({
|
|
@@ -42,6 +47,7 @@ export function createReplicaFrame(
|
|
|
42
47
|
signal.addEventListener("abort", unsubscribe, { once: true });
|
|
43
48
|
}
|
|
44
49
|
return {
|
|
50
|
+
flush: publish.flush,
|
|
45
51
|
notebookAtom: atom((get) => get(frameAtom).notebook),
|
|
46
52
|
generationAtom: atom((get) => get(frameAtom).generation),
|
|
47
53
|
documentAtom: atom((get) => get(frameAtom).document),
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
/** Backend-confirmed notebook state, independent of React and transports. */
|
|
4
4
|
|
|
5
5
|
export type { NotebookBackend } from "./backend";
|
|
6
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
createReplicaFrame,
|
|
8
|
+
type FrameSource,
|
|
9
|
+
type ReplicaFrame,
|
|
10
|
+
} from "./frame";
|
|
7
11
|
export {
|
|
8
12
|
type CloseDecision,
|
|
9
13
|
ConnectionClosedReason,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export function oncePerFrame(
|
|
5
5
|
publish: () => void,
|
|
6
6
|
{ signal }: { signal: AbortSignal },
|
|
7
|
-
)
|
|
7
|
+
) {
|
|
8
8
|
let generation = 0;
|
|
9
9
|
let cancelScheduled: (() => void) | undefined;
|
|
10
10
|
|
|
@@ -36,7 +36,7 @@ export function oncePerFrame(
|
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
function schedule() {
|
|
40
40
|
if (signal.aborted || cancelScheduled) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -56,5 +56,6 @@ export function oncePerFrame(
|
|
|
56
56
|
const frame = requestAnimationFrame(callback);
|
|
57
57
|
cancelScheduled = () => cancelAnimationFrame(frame);
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
|
+
return Object.assign(schedule, { flush: run });
|
|
60
61
|
}
|
|
@@ -251,7 +251,22 @@ function sameShown(
|
|
|
251
251
|
a: Pick<Result, "record" | "output">,
|
|
252
252
|
b: Pick<Result, "record" | "output">,
|
|
253
253
|
): boolean {
|
|
254
|
-
|
|
254
|
+
const left = shown(a);
|
|
255
|
+
const right = shown(b);
|
|
256
|
+
if (left === right) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (left === null || right === null || left.kind !== right.kind) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
if (left.kind === "output" && right.kind === "output") {
|
|
263
|
+
return (
|
|
264
|
+
left.media === right.media ||
|
|
265
|
+
(left.media?.mimetype === right.media?.mimetype &&
|
|
266
|
+
left.media?.data === right.media?.data)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
255
270
|
}
|
|
256
271
|
|
|
257
272
|
/** Replace an execution and keep its retained copies in step. */
|
|
@@ -1092,6 +1092,12 @@ it.each(["live", "replay", "batched"])(
|
|
|
1092
1092
|
}
|
|
1093
1093
|
});
|
|
1094
1094
|
expect(rows()).toEqual(["ABC"]);
|
|
1095
|
+
const messages = () =>
|
|
1096
|
+
store
|
|
1097
|
+
.get(notebookAtom)
|
|
1098
|
+
.cellLogs.flat()
|
|
1099
|
+
.map((log) => log.message);
|
|
1100
|
+
expect(messages()).toEqual(mode === "replay" ? [] : ["B", "C"]);
|
|
1095
1101
|
act(() => {
|
|
1096
1102
|
conn.receive({ event: "console.removed", data: { id: "line-0" } });
|
|
1097
1103
|
conn.receive({ event: "console.removed", data: { id: "line-1" } });
|
|
@@ -1337,7 +1343,10 @@ it("clears the private debugger prompt and transcript when editing moves to anot
|
|
|
1337
1343
|
});
|
|
1338
1344
|
expect(rows()).toEqual([]);
|
|
1339
1345
|
expect(
|
|
1340
|
-
store
|
|
1346
|
+
store
|
|
1347
|
+
.get(notebookAtom)
|
|
1348
|
+
.cellLogs.flat()
|
|
1349
|
+
.map((log) => log.message),
|
|
1341
1350
|
).not.toContain("private debugger");
|
|
1342
1351
|
expect(store.get(pendingPdbInputAtom)).toBeNull();
|
|
1343
1352
|
});
|
package/src/css/common.css
CHANGED
|
@@ -20,6 +20,17 @@
|
|
|
20
20
|
display: inline-flex !important;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/*
|
|
24
|
+
* Let the cell's delete control take and keep keyboard focus. A hidden
|
|
25
|
+
* control cannot take focus, so the first selector keeps the control visible
|
|
26
|
+
* in the moment when focus leaves the cell and no element holds focus yet.
|
|
27
|
+
* Focus on any other element in the cell does not show the control.
|
|
28
|
+
*/
|
|
29
|
+
.marimo-cell:focus-within:not(:has(:focus)) .shoulder-bottom.hover-action,
|
|
30
|
+
.shoulder-bottom.hover-action:focus-within {
|
|
31
|
+
display: inline-flex !important;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
.hover-actions-parent:hover .hover-action,
|
|
24
35
|
.hover-actions-parent:focus .hover-action {
|
|
25
36
|
display: inline-flex !important;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import { createSharedSubscription } from "@/utils/shared-resource";
|
|
5
|
+
|
|
6
|
+
/** Matches the media query that common.css uses to hide hover actions. */
|
|
7
|
+
const FINE_POINTER_QUERY = "(hover: hover) and (pointer: fine)";
|
|
8
|
+
|
|
9
|
+
function getQuery(): MediaQueryList | undefined {
|
|
10
|
+
return window.matchMedia?.(FINE_POINTER_QUERY);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const subscribeToFinePointer = createSharedSubscription((notify) => {
|
|
14
|
+
const query = getQuery();
|
|
15
|
+
query?.addEventListener("change", notify);
|
|
16
|
+
return () => query?.removeEventListener("change", notify);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function getSnapshot(): boolean {
|
|
20
|
+
return getQuery()?.matches ?? false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether the primary input can hover precisely (mouse or trackpad).
|
|
25
|
+
* Updates when the pointer capabilities change during a session.
|
|
26
|
+
* Environments without `matchMedia` report `false`.
|
|
27
|
+
*/
|
|
28
|
+
export function useFinePointer(): boolean {
|
|
29
|
+
return useSyncExternalStore(subscribeToFinePointer, getSnapshot, () => false);
|
|
30
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
3
|
+
import { appendCellLogs } from "@/core/cells/cell-log-chunks";
|
|
3
4
|
import { cellId } from "@/__tests__/branded";
|
|
4
5
|
import { LogViewer } from "@/components/editor/chrome/panels/logs-panel";
|
|
5
6
|
import { Dialog } from "../components/ui/dialog";
|
|
@@ -19,50 +20,53 @@ export const Primary: Story = {
|
|
|
19
20
|
<Dialog>
|
|
20
21
|
<TooltipProvider>
|
|
21
22
|
<LogViewer
|
|
22
|
-
logs={
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
23
|
+
logs={appendCellLogs(
|
|
24
|
+
[],
|
|
25
|
+
[
|
|
26
|
+
{
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
level: "stdout",
|
|
29
|
+
source: { type: "cell", cellId: cellId("cell1") },
|
|
30
|
+
message: "Hello world!",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
level: "stdout",
|
|
35
|
+
source: { type: "cell", cellId: cellId("cell1") },
|
|
36
|
+
message: "Running cell...",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
level: "stdout",
|
|
41
|
+
source: { type: "cell", cellId: cellId("cell1") },
|
|
42
|
+
message: "Done!",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
level: "stderr",
|
|
47
|
+
source: { type: "cell", cellId: cellId("cell2") },
|
|
48
|
+
message: "Output is too large!",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
level: "stderr",
|
|
53
|
+
source: { type: "cell", cellId: cellId("cell2") },
|
|
54
|
+
message: "String length is too short.".repeat(100),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
level: "stderr",
|
|
59
|
+
source: { type: "lsp", name: "pylsp" },
|
|
60
|
+
message: "Failed to load plugin 'ruff': not installed",
|
|
61
|
+
},
|
|
62
|
+
...Array.from({ length: 100 }).map(() => ({
|
|
63
|
+
timestamp: Date.now(),
|
|
64
|
+
level: "stdout" as const,
|
|
65
|
+
source: { type: "cell", cellId: cellId("cell1") } as const,
|
|
66
|
+
message: "Running cell...",
|
|
67
|
+
})),
|
|
68
|
+
],
|
|
69
|
+
)}
|
|
66
70
|
/>
|
|
67
71
|
</TooltipProvider>
|
|
68
72
|
</Dialog>
|
|
@@ -4,6 +4,7 @@ import { createSharedResource } from "./shared-resource";
|
|
|
4
4
|
/** One observer per options set, with independently disposable subscriptions. */
|
|
5
5
|
export function createSharedIntersectionObserver(
|
|
6
6
|
options: IntersectionObserverInit,
|
|
7
|
+
isVisible = (entry: IntersectionObserverEntry) => entry.isIntersecting,
|
|
7
8
|
) {
|
|
8
9
|
const subscribers = new Map<Element, Set<(visible: boolean) => void>>();
|
|
9
10
|
let observer: IntersectionObserver | undefined;
|
|
@@ -17,7 +18,7 @@ export function createSharedIntersectionObserver(
|
|
|
17
18
|
const snapshot = [...(callbacks ?? [])];
|
|
18
19
|
for (const callback of snapshot) {
|
|
19
20
|
if (callbacks?.has(callback)) {
|
|
20
|
-
callback(entry
|
|
21
|
+
callback(isVisible(entry));
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
}
|