@marimo-team/islands 0.26.1-dev42 → 0.26.1-dev46
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/{ConnectedDataExplorerComponent-BVMWCBON.js → ConnectedDataExplorerComponent-yQVBQBUW.js} +16 -16
- package/dist/{ErrorBoundary-BzyGrUMt.js → ErrorBoundary-i7VCVA53.js} +18 -18
- package/dist/{abnfDiagram-VCTEODGH-BRj77JhY.js → abnfDiagram-VCTEODGH-Ck_lXwQR.js} +2 -2
- package/dist/{any-language-editor-BQ9dhxg5.js → any-language-editor-Cx4idbgX.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-CDnAsvE1.js → architectureDiagram-5GKGNRK7-XeVhic7Z.js} +1 -1
- package/dist/{assertNever-DeSqnr83.js → assertNever-473SFxLt.js} +2 -2
- package/dist/{chat-ui-CXyZb62N.js → chat-ui-6qTQeEIx.js} +870 -870
- package/dist/{check-COXd6cXw.js → check-DmTIavbZ.js} +1 -1
- package/dist/{chunk-IMKFNOWR-BFtu1O6j.js → chunk-IMKFNOWR-DdQni67K.js} +1 -1
- package/dist/{chunk-SHT3W25Y-B9zWo9Da.js → chunk-SHT3W25Y-BdK-vMct.js} +1 -1
- package/dist/{chunk-SVP7TREG-kKS-I24p.js → chunk-SVP7TREG-cpFZk4Ca.js} +1 -1
- package/dist/{chunk-TICWLB2K-EY3w5-eg.js → chunk-TICWLB2K-DDgQFRgT.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-BR66X7fj.js → classDiagram-ZZMXUADV-DeojX9X4.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-DPcxw_9g.js → classDiagram-v2-VYDZK3BY-DPfTAiQ6.js} +2 -2
- package/dist/{code-visibility-DcxCjPS7.js → code-visibility-DNUnnMY_.js} +27 -27
- package/dist/{common-CA3E-SaD.js → common-CXvbAyqO.js} +4892 -4900
- package/dist/{config-DE3A8m65.js → config-D-lhQq-h.js} +3 -3
- package/dist/{copy-icon-gSCLWI50.js → copy-icon-DuxRkh7T.js} +2 -2
- package/dist/{createReducer-BFfuVhJG.js → createReducer-D3pBhIVD.js} +5 -5
- package/dist/{cynefinDiagram-5FMLGOSQ-B9kG0Adl.js → cynefinDiagram-5FMLGOSQ-DyY9TvuI.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-ClnyHQzL.js → dagre-GXQ25YYZ-BPCOgtKg.js} +1 -1
- package/dist/{data-grid-overlay-editor-DjSnRyGz.js → data-grid-overlay-editor-_B2yWrZg.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-afCjSSlp.js → diagram-S7CK7UJ4-KaF-C6kd.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-BCHefG5P.js → diagram-UQ7AKVKN-DkeqoSvK.js} +1 -1
- package/dist/{diagram-VX7I27RA-9jXA0khj.js → diagram-VX7I27RA-DExolTAf.js} +1 -1
- package/dist/{diagram-Z3DM3KII-C8tsbK7Q.js → diagram-Z3DM3KII-BioFuBF3.js} +1 -1
- package/dist/{dialog-Dn_UHaEl.js → dialog-CvyFEwby.js} +28 -28
- package/dist/{dropdown-menu-D0nePAlm.js → dropdown-menu-BiXHfje7.js} +651 -651
- package/dist/{ebnfDiagram-PWID7BFC-It0ZS33j.js → ebnfDiagram-PWID7BFC-BSb9k1ed.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-Z0Qfo02H.js → erDiagram-RLTQ6QDP-PWA30a_r.js} +1 -1
- package/dist/{error-banner-DChjSagB.js → error-banner-B9HQMSaH.js} +70 -70
- package/dist/{error-entries-DYoi03MZ.js → error-entries-8CPw0aYH.js} +812 -698
- package/dist/{feedback-button-DeA5LGUm.js → feedback-button-BOJ6pfBP.js} +52 -52
- package/dist/{flowDiagram-HODETNUW-8DeXLUFK.js → flowDiagram-HODETNUW-BPtD__Zz.js} +2 -2
- package/dist/{formats-6QF5hRsy.js → formats-BF95BoCT.js} +1 -1
- package/dist/{glide-data-editor-DD03A2zN.js → glide-data-editor-oQ3lCfvU.js} +11 -11
- package/dist/{glide-utils-B7gy9Her.js → glide-utils-iHKKQPJ8.js} +2 -2
- package/dist/{globals-CXh7buzB.js → globals-a3k2q2j7.js} +3 -3
- package/dist/{html-to-image-CUFNjxtw.js → html-to-image-BIom70fW.js} +404 -404
- package/dist/{infoDiagram-27XIBGKW-B5wmzeRz.js → infoDiagram-27XIBGKW-SJuilBEE.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-BcbPwik7.js → ishikawaDiagram-5VMMS53U-DjzyxMr8.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-AfQmkIoH.js → kanban-definition-UXKFOSKX-D2_qopGt.js} +1 -1
- package/dist/main.js +5811 -5766
- package/dist/{mermaid-az53hfgW.js → mermaid-DcowNmCx.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-B7eBrMap.js → mindmap-definition-YA3MSWOX-pEra10M0.js} +1 -1
- package/dist/{number-overlay-editor-DJFSx1CC.js → number-overlay-editor-CUwIpUt4.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-BwjpXSLR.js → pegDiagram-XKGWAZYB-CHOPKVOf.js} +2 -2
- package/dist/{pencil-pQhLU2Up.js → pencil-FAv6JUvp.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-D5AyRqAQ.js → pieDiagram-E7YTZNPT-yGDhsyEN.js} +1 -1
- package/dist/{process-output-DMMs8Ywh.js → process-output-ns7N5ovS.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-Hhrla0Qq.js → railroadDiagram-O6MQD6OU-CeKEPdyc.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-MgDRuFUM.js → requirementDiagram-BXWQKSXE-DSAbAzKe.js} +1 -1
- package/dist/{reveal-component-DwB1-KYy.js → reveal-component-BAhQeB3o.js} +7 -7
- package/dist/{select-C4rPKgSx.js → select-BszV-bbI.js} +307 -307
- package/dist/{sequenceDiagram-WJ2MYXX4-xZYdOGbe.js → sequenceDiagram-WJ2MYXX4-DVhWj_9H.js} +1 -1
- package/dist/{spec-BsiCag5K.js → spec-CRfw-lOm.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-DdhE3Yx9.js → stateDiagram-D77RDMKH-CDQ2MltG.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-DENKYVKr.js → stateDiagram-v2-MP3YSRHH-BQmvwBaz.js} +2 -2
- package/dist/{static-state-CNnjDcOR.js → static-state-BtDNJuc2.js} +5 -5
- package/dist/{swimlanes-42K2YHIH-Bw7xuGAn.js → swimlanes-42K2YHIH-DLOUTCEL.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-L91TUeh5.js → swimlanesDiagram-VR7AAH4N-BVKrkNJ6.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-BeGrmws1.js → timeline-definition-24CTP7MA-Cb2JoCSd.js} +1 -1
- package/dist/{toast-qyBwbZJ0.js → toast-QsOAIPfq.js} +192 -192
- package/dist/{tooltip-COQxCMLx.js → tooltip-BQZ-Bm6h.js} +76 -76
- package/dist/{use-restore-focus-D5-Hgr1l.js → use-restore-focus-DT1TZACX.js} +1167 -1167
- package/dist/{useDateFormatter-L8edl513.js → useDateFormatter-D3gyMY-g.js} +2 -2
- package/dist/{useDeepCompareMemoize-B6yhm6sM.js → useDeepCompareMemoize-CO6rO5Mq.js} +1 -1
- package/dist/{useLifecycle-Dnxradbp.js → useLifecycle-C9UTzCY8.js} +1 -1
- package/dist/{vega-component-CWKS3tOU.js → vega-component-i5lZ23n7.js} +17 -17
- package/dist/{vennDiagram-4TSXK5OY-fknCUyJ2.js → vennDiagram-4TSXK5OY-Cm3EcCcP.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-DvoVMCdj.js → wardleyDiagram-VM6X3IG4-DjlUs2CC.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-0TYtO6UV.js → xychartDiagram-S5SC5T6Z-DxNDul9l.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/animation-frames.ts +31 -0
- package/src/__mocks__/executions.ts +6 -1
- package/src/components/editor/cell/collapse.tsx +6 -3
- package/src/components/editor/header/status.tsx +5 -2
- package/src/components/scratchpad/scratchpad.tsx +2 -2
- package/src/core/cells/cells.ts +24 -16
- package/src/core/cells/execution-console.ts +7 -2
- package/src/core/executions/__tests__/atoms.test.ts +204 -1
- package/src/core/executions/__tests__/output-lifecycle.test.ts +20 -3
- package/src/core/executions/__tests__/select.test.ts +32 -1
- package/src/core/executions/atoms.ts +245 -81
- package/src/core/executions/hooks.ts +15 -59
- package/src/core/executions/index.ts +2 -0
- package/src/core/executions/output.ts +34 -14
- package/src/core/executions/select.ts +70 -25
- package/src/core/islands/bootstrap.ts +7 -2
- package/src/core/notebook/replica/__tests__/executions.test.ts +8 -12
- package/src/core/notebook/replica/__tests__/frame.test.ts +206 -0
- package/src/core/notebook/replica/__tests__/once-per-frame.test.ts +95 -0
- package/src/core/notebook/replica/__tests__/results.test.ts +3 -9
- package/src/core/notebook/replica/frame.ts +54 -0
- package/src/core/notebook/replica/index.ts +1 -0
- package/src/core/notebook/replica/once-per-frame.ts +60 -0
- package/src/core/notebook/replica/resources/executions.ts +0 -2
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +53 -7
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +29 -7
- package/src/core/session/active-notebook.ts +4 -1
- package/src/core/session/useNotebookReplica.ts +14 -1
- package/src/core/state/__tests__/atom-with-selected-inputs.test.ts +48 -0
- package/src/core/state/__tests__/create-keyed-selector-hook.test.tsx +16 -7
- package/src/core/state/atom-with-selected-inputs.ts +24 -0
- package/src/core/state/create-keyed-atom-hook.ts +18 -0
- package/src/core/state/create-keyed-selector-hook.ts +5 -9
- package/src/core/wasm/__tests__/bridge.test.ts +73 -1
- package/src/utils/arrays.ts +4 -1
|
@@ -5,14 +5,21 @@ import type { NotebookTransport } from "@marimo-team/client";
|
|
|
5
5
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
6
6
|
import { createStore } from "jotai";
|
|
7
7
|
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
|
8
|
+
import { mockAnimationFrames } from "@/__mocks__/animation-frames";
|
|
8
9
|
import { MockExecutions } from "@/__mocks__/executions";
|
|
9
10
|
import { cellId, runId } from "@/__tests__/branded";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
createNotebookReplica,
|
|
13
|
+
createReplicaFrame,
|
|
14
|
+
} from "@/core/notebook/replica";
|
|
11
15
|
import {
|
|
12
16
|
fakeBackend,
|
|
13
17
|
fixtureMessages,
|
|
14
18
|
} from "@/core/notebook/replica/__tests__/fixtures";
|
|
15
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
activeNotebookReplicaAtom,
|
|
21
|
+
activeNotebookFrameAtom,
|
|
22
|
+
} from "@/core/session/active-notebook";
|
|
16
23
|
import { Deferred } from "@/utils/Deferred";
|
|
17
24
|
import {
|
|
18
25
|
acceptRun,
|
|
@@ -48,12 +55,22 @@ async function setup() {
|
|
|
48
55
|
}),
|
|
49
56
|
});
|
|
50
57
|
const store = createStore();
|
|
58
|
+
const advanceFrame = mockAnimationFrames();
|
|
59
|
+
const lifetime = new AbortController();
|
|
60
|
+
onTestFinished(() => lifetime.abort());
|
|
51
61
|
const replica = createNotebookReplica(store);
|
|
62
|
+
store.set(
|
|
63
|
+
activeNotebookFrameAtom,
|
|
64
|
+
createReplicaFrame(store, replica, { signal: lifetime.signal }),
|
|
65
|
+
);
|
|
52
66
|
store.set(activeNotebookReplicaAtom, replica);
|
|
53
67
|
const disconnect = replica.connect(backend, { onNotification: vi.fn() });
|
|
54
68
|
onTestFinished(disconnect);
|
|
55
69
|
let attempt = await opened.promise;
|
|
56
|
-
const message: Attempt["message"] = (frame) =>
|
|
70
|
+
const message: Attempt["message"] = (frame) => {
|
|
71
|
+
attempt.message(frame);
|
|
72
|
+
advanceFrame();
|
|
73
|
+
};
|
|
57
74
|
const reconnect = async () => {
|
|
58
75
|
opened = new Deferred<Attempt>();
|
|
59
76
|
attempt.drop();
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
4
|
+
import { Time } from "@/utils/time";
|
|
3
5
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { describe, expect, it, vi, onTestFinished } from "vitest";
|
|
5
7
|
import { cell, CONFIG } from "@/core/notebook/document/__tests__/fixtures";
|
|
6
8
|
import type { Execution, Executions, Results } from "@/core/notebook/replica";
|
|
7
9
|
import {
|
|
@@ -415,3 +417,32 @@ describe("notebook-level views", () => {
|
|
|
415
417
|
expect(queuedOrRunningCount(scratch)).toBe(1);
|
|
416
418
|
});
|
|
417
419
|
});
|
|
420
|
+
|
|
421
|
+
it("parses timestamps once per immutable execution record", () => {
|
|
422
|
+
const record = MockExecutions.completed(C1);
|
|
423
|
+
const inputs = MockExecutions.inputs([record]);
|
|
424
|
+
const parse = vi.spyOn(Time, "parse");
|
|
425
|
+
onTestFinished(() => {
|
|
426
|
+
parse.mockRestore();
|
|
427
|
+
});
|
|
428
|
+
expect(cellExecutionView(inputs, C1).duration).toBe(1500);
|
|
429
|
+
expect(parse).toHaveBeenCalledTimes(2);
|
|
430
|
+
for (let i = 0; i < 100; i++) {
|
|
431
|
+
cellExecutionView(inputs, C1);
|
|
432
|
+
}
|
|
433
|
+
expect(parse).toHaveBeenCalledTimes(2);
|
|
434
|
+
const updated = {
|
|
435
|
+
...record,
|
|
436
|
+
state: {
|
|
437
|
+
status: "completed" as const,
|
|
438
|
+
started_at: "2026-10-01T09:20:11Z",
|
|
439
|
+
completed_at: "2026-10-01T09:20:14Z",
|
|
440
|
+
depends_on: {},
|
|
441
|
+
outcome: { kind: "succeeded" as const },
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
expect(cellExecutionView(MockExecutions.inputs([updated]), C1).duration).toBe(
|
|
445
|
+
3000,
|
|
446
|
+
);
|
|
447
|
+
expect(parse).toHaveBeenCalledTimes(4);
|
|
448
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
6
6
|
import { dequal } from "dequal";
|
|
7
|
-
import { atom, type createStore } from "jotai";
|
|
7
|
+
import { atom, type Atom, type createStore } from "jotai";
|
|
8
8
|
import { atomFamily, selectAtom } from "jotai/utils";
|
|
9
9
|
import type { CellId } from "@/core/cells/ids";
|
|
10
10
|
import type { Outline } from "@/core/cells/outline";
|
|
@@ -13,22 +13,32 @@ import {
|
|
|
13
13
|
ConnectionState,
|
|
14
14
|
type Executions,
|
|
15
15
|
type NotebookReplica,
|
|
16
|
+
type ReplicaFrame,
|
|
16
17
|
type Results,
|
|
17
18
|
} from "@/core/notebook/replica";
|
|
18
|
-
import {
|
|
19
|
+
import { atomWithSelectedInputs } from "@/core/state/atom-with-selected-inputs";
|
|
20
|
+
import { arrayShallowEquals } from "@/utils/arrays";
|
|
21
|
+
import {
|
|
22
|
+
activeNotebookReplicaAtom,
|
|
23
|
+
activeNotebookFrameAtom,
|
|
24
|
+
} from "@/core/session/active-notebook";
|
|
19
25
|
import { type CellFreshnessInputs, freshnessOf } from "./freshness";
|
|
20
26
|
import {
|
|
21
|
-
type CellOutput,
|
|
22
27
|
type CellOutputInputs,
|
|
23
28
|
type ClearedOutput,
|
|
24
|
-
|
|
29
|
+
type CellOutput,
|
|
30
|
+
resultOutput,
|
|
31
|
+
shownCellExecution,
|
|
25
32
|
shownExecution,
|
|
33
|
+
scratchOutputView,
|
|
26
34
|
} from "./output";
|
|
27
35
|
import {
|
|
28
36
|
anyRunning,
|
|
29
37
|
blockedDescendants,
|
|
30
38
|
type CellExecutionInputs,
|
|
31
39
|
queuedOrRunningCount,
|
|
40
|
+
executionView,
|
|
41
|
+
awaitingRun,
|
|
32
42
|
} from "./select";
|
|
33
43
|
import { shown } from "@/core/notebook/replica";
|
|
34
44
|
|
|
@@ -102,76 +112,125 @@ function current<T>(marks: Marks<T>, shown: ShownNotebook | null, empty: T): T {
|
|
|
102
112
|
: empty;
|
|
103
113
|
}
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
type ReplicaSource = Atom<ReplicaFrame | null>;
|
|
116
|
+
|
|
117
|
+
function createShownNotebookAtom(source: ReplicaSource) {
|
|
118
|
+
return atom((get): ShownNotebook | null => {
|
|
119
|
+
const replica = get(activeNotebookReplicaAtom);
|
|
120
|
+
const state = get(source);
|
|
121
|
+
if (replica === null || state === null) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const notebook = get(state.notebookAtom);
|
|
125
|
+
return notebook === null
|
|
126
|
+
? null
|
|
127
|
+
: { replica, id: notebook.id, generation: get(state.generationAtom) };
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const shownNotebookAtom = createShownNotebookAtom(activeNotebookReplicaAtom);
|
|
112
132
|
|
|
113
133
|
/** Whether the request still belongs to the current stream. */
|
|
114
134
|
export function isCurrent(store: Store, request: RunRequest): boolean {
|
|
115
135
|
return sameNotebook(request.notebook, store.get(shownNotebookAtom));
|
|
116
136
|
}
|
|
117
137
|
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
get(requestsAtom),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
function createExecutionInputsAtom(source: ReplicaSource) {
|
|
139
|
+
const notebookAtom = createShownNotebookAtom(source);
|
|
140
|
+
const requestedCellsAtom = atom((get) => {
|
|
141
|
+
const requests = current(get(requestsAtom), get(notebookAtom), NO_REQUESTS);
|
|
142
|
+
return requests.size === 0
|
|
143
|
+
? NO_REQUESTED
|
|
144
|
+
: new Set([...requests].flatMap((request) => request.cells));
|
|
145
|
+
});
|
|
146
|
+
const blockedCellsAtom = atom((get) => {
|
|
147
|
+
const replica = get(source);
|
|
148
|
+
const view = replica && get(replica.analysisAtom);
|
|
149
|
+
const shownBlocked = view
|
|
150
|
+
? blockedDescendants(view.analysis, view.document.cells.values())
|
|
151
|
+
: NO_BLOCKED;
|
|
152
|
+
return {
|
|
153
|
+
shownBlocked,
|
|
154
|
+
blocked: view?.freshness === "current" ? shownBlocked : NO_BLOCKED,
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
return atom((get): CellExecutionInputs => {
|
|
158
|
+
const replica = get(source);
|
|
159
|
+
const document = replica === null ? null : get(replica.shownDocumentAtom);
|
|
160
|
+
return {
|
|
161
|
+
executions:
|
|
162
|
+
replica === null ? NO_EXECUTIONS : get(replica.executionsAtom),
|
|
163
|
+
results: replica === null ? NO_RESULTS : get(replica.resultsAtom),
|
|
164
|
+
cells: document?.cells ?? NO_CELLS,
|
|
165
|
+
requested: get(requestedCellsAtom),
|
|
166
|
+
...get(blockedCellsAtom),
|
|
167
|
+
runtimeId:
|
|
168
|
+
replica === null ? null : (get(replica.runtimeAtom)?.id ?? null),
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
129
172
|
|
|
130
|
-
/**
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
shownBlocked,
|
|
139
|
-
blocked: view?.freshness === "current" ? shownBlocked : NO_BLOCKED,
|
|
140
|
-
};
|
|
141
|
-
});
|
|
173
|
+
/** Current received state for commands and runtime gates. */
|
|
174
|
+
export const cellExecutionInputsAtom = createExecutionInputsAtom(
|
|
175
|
+
activeNotebookReplicaAtom,
|
|
176
|
+
);
|
|
177
|
+
/** Display state for cell views. */
|
|
178
|
+
export const frameCellExecutionInputsAtom = createExecutionInputsAtom(
|
|
179
|
+
activeNotebookFrameAtom,
|
|
180
|
+
);
|
|
142
181
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
182
|
+
function createFreshnessAtom(source: ReplicaSource) {
|
|
183
|
+
const inputsAtom = selectAtom(
|
|
184
|
+
atom((get): CellFreshnessInputs => {
|
|
185
|
+
const replica = get(source);
|
|
186
|
+
const document = replica === null ? null : get(replica.shownDocumentAtom);
|
|
187
|
+
// Snapshot results may arrive before their document.
|
|
188
|
+
if (replica === null || document === null) {
|
|
189
|
+
return {
|
|
190
|
+
cells: NO_CELLS,
|
|
191
|
+
executions: NO_EXECUTIONS,
|
|
192
|
+
results: NO_RESULTS,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
cells: document.cells,
|
|
197
|
+
executions: get(replica.executionsAtom),
|
|
198
|
+
results: get(replica.resultsAtom),
|
|
199
|
+
};
|
|
200
|
+
}),
|
|
201
|
+
(inputs) => inputs,
|
|
202
|
+
(a, b) =>
|
|
203
|
+
a.cells === b.cells &&
|
|
204
|
+
a.executions.variables === b.executions.variables &&
|
|
205
|
+
a.executions.latest === b.executions.latest &&
|
|
206
|
+
sameRecords(a.executions.executions, b.executions.executions) &&
|
|
207
|
+
sameRecords(a.results, b.results),
|
|
208
|
+
);
|
|
209
|
+
return atom((get) => freshnessOf(get(inputsAtom)));
|
|
210
|
+
}
|
|
156
211
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return { cells: NO_CELLS, executions: NO_EXECUTIONS, results: NO_RESULTS };
|
|
212
|
+
function sameRecords<
|
|
213
|
+
K,
|
|
214
|
+
V extends { readonly record: Protocol.ExecutionOutput } | null,
|
|
215
|
+
>(a: ReadonlyMap<K, V>, b: ReadonlyMap<K, V>): boolean {
|
|
216
|
+
if (a === b) {
|
|
217
|
+
return true;
|
|
164
218
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
219
|
+
if (a.size !== b.size) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
for (const [id, value] of a) {
|
|
223
|
+
if (!b.has(id) || value?.record !== b.get(id)?.record) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
171
229
|
|
|
172
230
|
/** Freshness by cell id, indexed once per change to its inputs. */
|
|
173
|
-
export const cellFreshnessAtom =
|
|
174
|
-
|
|
231
|
+
export const cellFreshnessAtom = createFreshnessAtom(activeNotebookReplicaAtom);
|
|
232
|
+
export const frameCellFreshnessAtom = createFreshnessAtom(
|
|
233
|
+
activeNotebookFrameAtom,
|
|
175
234
|
);
|
|
176
235
|
|
|
177
236
|
/** What each cell showed when this browser cleared it. */
|
|
@@ -180,48 +239,151 @@ const clearedOutputsAtom =
|
|
|
180
239
|
|
|
181
240
|
const displayedNotebookAtom = atom((get): ShownNotebook | null => {
|
|
182
241
|
const replica = get(activeNotebookReplicaAtom);
|
|
183
|
-
const
|
|
184
|
-
|
|
242
|
+
const frame = get(activeNotebookFrameAtom);
|
|
243
|
+
const document = frame === null ? null : get(frame.shownDocumentAtom);
|
|
244
|
+
return replica === null || frame === null || document === null
|
|
185
245
|
? null
|
|
186
246
|
: {
|
|
187
247
|
replica,
|
|
188
248
|
id: document.revision.notebook_id,
|
|
189
|
-
generation: get(
|
|
249
|
+
generation: get(frame.generationAtom),
|
|
190
250
|
};
|
|
191
251
|
});
|
|
192
252
|
|
|
193
253
|
/** What every cell's output derives from. Pair with `cellOutputView`. */
|
|
194
254
|
export const cellOutputInputsAtom = atom((get): CellOutputInputs => {
|
|
195
|
-
const
|
|
255
|
+
const frame = get(activeNotebookFrameAtom);
|
|
196
256
|
return {
|
|
197
|
-
executions:
|
|
198
|
-
results:
|
|
257
|
+
executions: frame === null ? NO_EXECUTIONS : get(frame.executionsAtom),
|
|
258
|
+
results: frame === null ? NO_RESULTS : get(frame.resultsAtom),
|
|
199
259
|
cleared: current(
|
|
200
260
|
get(clearedOutputsAtom),
|
|
201
261
|
get(displayedNotebookAtom),
|
|
202
262
|
NO_CLEARED,
|
|
203
263
|
),
|
|
204
264
|
cells:
|
|
205
|
-
|
|
206
|
-
? NO_CELLS
|
|
207
|
-
: (get(replica.documentAtom)?.cells ?? NO_CELLS),
|
|
265
|
+
frame === null ? NO_CELLS : (get(frame.documentAtom)?.cells ?? NO_CELLS),
|
|
208
266
|
};
|
|
209
267
|
});
|
|
210
268
|
|
|
211
269
|
/** What every cell shows, by cell id. Pair with `cellOutputAtom` for one cell. */
|
|
212
|
-
|
|
213
|
-
|
|
270
|
+
const outputCellIdsAtom = selectAtom(
|
|
271
|
+
cellOutputInputsAtom,
|
|
272
|
+
(inputs) => [
|
|
273
|
+
...new Set([...inputs.results.keys(), ...inputs.executions.latest.keys()]),
|
|
274
|
+
],
|
|
275
|
+
arrayShallowEquals,
|
|
214
276
|
);
|
|
215
277
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
278
|
+
export const cellOutputsAtom = atom((get) => {
|
|
279
|
+
const outputs = new Map<CellId, CellOutput>();
|
|
280
|
+
for (const id of get(outputCellIdsAtom)) {
|
|
281
|
+
const output = get(cellOutputAtom(id));
|
|
282
|
+
if (output !== null) {
|
|
283
|
+
outputs.set(id, output);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return outputs;
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
function latestFor(executions: Executions, id: Protocol.CellId) {
|
|
290
|
+
const latest = executions.latest.get(id);
|
|
291
|
+
return latest === undefined ? undefined : executions.executions.get(latest);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export const cellExecutionAtom = atomFamily((id: Protocol.CellId) => {
|
|
295
|
+
const view = atomWithSelectedInputs(
|
|
296
|
+
frameCellExecutionInputsAtom,
|
|
297
|
+
(inputs) =>
|
|
298
|
+
[
|
|
299
|
+
latestFor(inputs.executions, id)?.record,
|
|
300
|
+
inputs.results.get(id)?.record,
|
|
301
|
+
inputs.cells.get(id),
|
|
302
|
+
inputs.requested.has(id),
|
|
303
|
+
inputs.blocked.has(id),
|
|
304
|
+
inputs.shownBlocked.has(id),
|
|
305
|
+
inputs.runtimeId,
|
|
306
|
+
inputs.executions.runs,
|
|
307
|
+
] as const,
|
|
308
|
+
([
|
|
309
|
+
record,
|
|
310
|
+
result,
|
|
311
|
+
cell,
|
|
312
|
+
requested,
|
|
313
|
+
blocked,
|
|
314
|
+
shownBlocked,
|
|
315
|
+
runtimeId,
|
|
316
|
+
runs,
|
|
317
|
+
]) => {
|
|
318
|
+
return executionView({
|
|
319
|
+
latest: record ?? null,
|
|
320
|
+
result: result ?? null,
|
|
321
|
+
blocked,
|
|
322
|
+
shownBlocked,
|
|
323
|
+
runtimeId,
|
|
324
|
+
queued:
|
|
325
|
+
cell !== undefined &&
|
|
326
|
+
!cell.config.disabled &&
|
|
327
|
+
!blocked &&
|
|
328
|
+
(requested ||
|
|
329
|
+
awaitingRun(runs, id, record?.run_id ?? result?.run_id)),
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
);
|
|
333
|
+
return selectAtom(view, (execution) => execution, dequal);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
/** One cell's output, derived only when its display inputs change. */
|
|
337
|
+
export const cellOutputAtom = atomFamily((id: CellId) => {
|
|
338
|
+
const view = atomWithSelectedInputs(
|
|
339
|
+
cellOutputInputsAtom,
|
|
340
|
+
(inputs) => {
|
|
341
|
+
const latest = latestFor(inputs.executions, id);
|
|
342
|
+
return [
|
|
343
|
+
latest?.record,
|
|
344
|
+
latest?.output,
|
|
345
|
+
latest?.outputVersion,
|
|
346
|
+
inputs.results.get(id),
|
|
347
|
+
inputs.cleared.get(id),
|
|
348
|
+
inputs.cells.get(id),
|
|
349
|
+
] as const;
|
|
350
|
+
},
|
|
351
|
+
([record, output, outputVersion, result, cleared, cell]) => {
|
|
352
|
+
const showing = shownCellExecution(
|
|
353
|
+
record
|
|
354
|
+
? {
|
|
355
|
+
record,
|
|
356
|
+
output: output ?? null,
|
|
357
|
+
outputVersion: outputVersion ?? 0,
|
|
358
|
+
}
|
|
359
|
+
: undefined,
|
|
360
|
+
result ?? null,
|
|
361
|
+
);
|
|
362
|
+
return resultOutput(showing, cell, cleared);
|
|
363
|
+
},
|
|
364
|
+
);
|
|
365
|
+
return selectAtom(view, (output) => output, dequal);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
/** Shared by scratchpad consumers; cell output and console updates leave it alone. */
|
|
369
|
+
export const scratchOutputAtom = selectAtom(
|
|
370
|
+
atomWithSelectedInputs(
|
|
371
|
+
cellOutputInputsAtom,
|
|
372
|
+
({ executions }) => [executions.scratch, executions.scratchFailure],
|
|
373
|
+
([scratch, scratchFailure]) =>
|
|
374
|
+
scratchOutputView({ scratch, scratchFailure }),
|
|
375
|
+
),
|
|
376
|
+
(output) => output,
|
|
377
|
+
dequal,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
export const cellFreshnessForAtom = atomFamily((id: Protocol.CellId) =>
|
|
221
381
|
selectAtom(
|
|
222
|
-
|
|
223
|
-
(
|
|
224
|
-
|
|
382
|
+
frameCellFreshnessAtom,
|
|
383
|
+
(freshness) => freshness(id),
|
|
384
|
+
(a, b) =>
|
|
385
|
+
a.sourceChanged === b.sourceChanged &&
|
|
386
|
+
a.inputsChanged === b.inputsChanged,
|
|
225
387
|
),
|
|
226
388
|
);
|
|
227
389
|
|
|
@@ -233,6 +395,8 @@ export const cellOutlineAtom = atomFamily((cellId: CellId) =>
|
|
|
233
395
|
/** Drop the cached atoms of a cell that left the document. */
|
|
234
396
|
export function releaseCellOutputAtoms(cellId: CellId): void {
|
|
235
397
|
cellOutputAtom.remove(cellId);
|
|
398
|
+
cellExecutionAtom.remove(cellId);
|
|
399
|
+
cellFreshnessForAtom.remove(cellId);
|
|
236
400
|
cellOutlineAtom.remove(cellId);
|
|
237
401
|
}
|
|
238
402
|
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
|
-
import { dequal } from "dequal";
|
|
5
4
|
import { useAtomValue } from "jotai";
|
|
6
|
-
import { selectAtom } from "jotai/utils";
|
|
7
|
-
import { useMemo } from "react";
|
|
8
5
|
import { autoRunOnChangeAtom } from "@/core/config/config";
|
|
9
6
|
import { useDelayElapsed } from "@/hooks/useDelayElapsed";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
7
|
+
import { createKeyedAtomHook } from "@/core/state/create-keyed-atom-hook";
|
|
8
|
+
import { createKeyedSelectorHook } from "@/core/state/create-keyed-selector-hook";
|
|
12
9
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
cellExecutionAtom,
|
|
11
|
+
cellFreshnessForAtom,
|
|
15
12
|
cellOutlineAtom,
|
|
16
13
|
cellOutputAtom,
|
|
17
14
|
cellOutputInputsAtom,
|
|
15
|
+
scratchOutputAtom,
|
|
18
16
|
} from "./atoms";
|
|
19
|
-
import type { CellFreshness } from "./freshness";
|
|
20
|
-
import { type CellOutput, scratchOutputView } from "./output";
|
|
21
|
-
import { type CellExecutionView, cellExecutionView } from "./select";
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
19
|
* A cell's status, timing, and how it last ended.
|
|
@@ -26,20 +21,7 @@ import { type CellExecutionView, cellExecutionView } from "./select";
|
|
|
26
21
|
* Host executions describe the run, document analysis identifies blocked
|
|
27
22
|
* cells, and local requests account for runs the host has yet to plan.
|
|
28
23
|
*/
|
|
29
|
-
export
|
|
30
|
-
// One atom per mounted cell, kept for its subscription and compared by
|
|
31
|
-
// value so the cell renders only when its own view changes.
|
|
32
|
-
const cellAtom = useMemo(
|
|
33
|
-
() =>
|
|
34
|
-
selectAtom(
|
|
35
|
-
cellExecutionInputsAtom,
|
|
36
|
-
(inputs) => cellExecutionView(inputs, id),
|
|
37
|
-
dequal,
|
|
38
|
-
),
|
|
39
|
-
[id],
|
|
40
|
-
);
|
|
41
|
-
return useAtomValue(cellAtom);
|
|
42
|
-
}
|
|
24
|
+
export const useCellExecution = createKeyedAtomHook(cellExecutionAtom);
|
|
43
25
|
|
|
44
26
|
/**
|
|
45
27
|
* Whether a cell's result is current, by the host protocol's rules.
|
|
@@ -47,13 +29,7 @@ export function useCellExecution(id: Protocol.CellId): CellExecutionView {
|
|
|
47
29
|
* The comparison reads the confirmed document, so an edit counts once the
|
|
48
30
|
* host has it, not on the keystroke.
|
|
49
31
|
*/
|
|
50
|
-
export
|
|
51
|
-
const cellAtom = useMemo(
|
|
52
|
-
() => selectAtom(cellFreshnessAtom, (freshness) => freshness(id), dequal),
|
|
53
|
-
[id],
|
|
54
|
-
);
|
|
55
|
-
return useAtomValue(cellAtom);
|
|
56
|
-
}
|
|
32
|
+
export const useCellFreshness = createKeyedAtomHook(cellFreshnessForAtom);
|
|
57
33
|
|
|
58
34
|
/** A variable revision can arrive just before the host queues its readers. */
|
|
59
35
|
export function useShowChangedInputs(changed: boolean): boolean {
|
|
@@ -78,42 +54,22 @@ export function useCellPresentation(id: Protocol.CellId) {
|
|
|
78
54
|
}
|
|
79
55
|
|
|
80
56
|
/** What the cell shows: its running value so far, else its result's outcome. */
|
|
81
|
-
export
|
|
82
|
-
return useAtomValue(cellOutputAtom(id));
|
|
83
|
-
}
|
|
57
|
+
export const useCellOutput = createKeyedAtomHook(cellOutputAtom);
|
|
84
58
|
|
|
85
59
|
/**
|
|
86
60
|
* Whether the cell has completed an execution, even one that shows nothing.
|
|
87
61
|
*
|
|
88
62
|
* Tells a cell that ran and has no output from one that has not run yet.
|
|
89
63
|
*/
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cellOutputInputsAtom,
|
|
95
|
-
(inputs) => inputs.results.get(id) != null,
|
|
96
|
-
),
|
|
97
|
-
[id],
|
|
98
|
-
);
|
|
99
|
-
return useAtomValue(cellAtom);
|
|
100
|
-
}
|
|
64
|
+
export const useCellHasResult = createKeyedSelectorHook(
|
|
65
|
+
cellOutputInputsAtom,
|
|
66
|
+
(inputs, id: Protocol.CellId) => inputs.results.get(id) != null,
|
|
67
|
+
);
|
|
101
68
|
|
|
102
69
|
/** The headings in the cell's output, for the table of contents. */
|
|
103
|
-
export
|
|
104
|
-
return useAtomValue(cellOutlineAtom(id));
|
|
105
|
-
}
|
|
70
|
+
export const useCellOutline = createKeyedAtomHook(cellOutlineAtom);
|
|
106
71
|
|
|
107
72
|
/** What the scratchpad shows, from its latest scratch execution. */
|
|
108
|
-
export function useScratchOutput()
|
|
109
|
-
|
|
110
|
-
() =>
|
|
111
|
-
selectAtom(
|
|
112
|
-
cellOutputInputsAtom,
|
|
113
|
-
(inputs) => scratchOutputView(inputs.executions),
|
|
114
|
-
dequal,
|
|
115
|
-
),
|
|
116
|
-
[],
|
|
117
|
-
);
|
|
118
|
-
return useAtomValue(scratchAtom);
|
|
73
|
+
export function useScratchOutput() {
|
|
74
|
+
return useAtomValue(scratchOutputAtom);
|
|
119
75
|
}
|