@marimo-team/islands 0.25.3-dev437 → 0.25.3-dev439
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-CoEU9snz.js → ConnectedDataExplorerComponent-LA5OtjAG.js} +11 -11
- package/dist/{ErrorBoundary-LQpWaaaj.js → ErrorBoundary-B4npV6Uy.js} +18 -18
- package/dist/{abnfDiagram-VCTEODGH-RbfxpmIE.js → abnfDiagram-VCTEODGH-CBntFgCZ.js} +2 -2
- package/dist/{any-language-editor-Cw4VtZvb.js → any-language-editor-gzDRWdCH.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-DzzNVRo4.js → architectureDiagram-5GKGNRK7-Bz6ouXl-.js} +1 -1
- package/dist/{assertNever-ChGm2jYv.js → assertNever-DOTNJ2Y4.js} +2 -2
- package/dist/{chat-ui-BEMyRpmS.js → chat-ui-2c_3M6FX.js} +45 -45
- package/dist/{check-BHRB6N0I.js → check-CApwK1fD.js} +1 -1
- package/dist/{chunk-IMKFNOWR-1Zy6M_oP.js → chunk-IMKFNOWR-DK_M66Dt.js} +1 -1
- package/dist/{chunk-SHT3W25Y-yAttqZEk.js → chunk-SHT3W25Y-C7Cg6zGL.js} +1 -1
- package/dist/{chunk-SVP7TREG-MKJpuJHR.js → chunk-SVP7TREG-K0lWia53.js} +1 -1
- package/dist/{chunk-TICWLB2K-BOC0OebH.js → chunk-TICWLB2K-DiKpryGp.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-BOlD7kH9.js → classDiagram-ZZMXUADV-CXX5eaxi.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-C3p3seuT.js → classDiagram-v2-VYDZK3BY-Bjyy4iKL.js} +2 -2
- package/dist/{code-visibility-Cl2Z5Y2R.js → code-visibility-Dx3sTl1s.js} +17 -17
- package/dist/{common-DVxtA3e0.js → common-Cx3bd6pm.js} +4881 -4842
- package/dist/{config-EJnOxh0i.js → config-C8TXSDmC.js} +18 -18
- package/dist/{copy-icon-Bv5SAA0w.js → copy-icon-CDvvlY90.js} +2 -2
- package/dist/{createReducer-BJJ0K5Tu.js → createReducer-CXqSak4H.js} +1 -1
- package/dist/{cynefinDiagram-5FMLGOSQ-BKnxm64C.js → cynefinDiagram-5FMLGOSQ-C-MlCYj4.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-COBTexAI.js → dagre-GXQ25YYZ-C6e9vEKZ.js} +1 -1
- package/dist/{data-grid-overlay-editor-FI3lYcm3.js → data-grid-overlay-editor-CqMKHPcR.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-Dyt3J6ek.js → diagram-S7CK7UJ4-DgXNq_At.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-CJCsT4fA.js → diagram-UQ7AKVKN-BG5NExCt.js} +1 -1
- package/dist/{diagram-VX7I27RA-BboxCtbh.js → diagram-VX7I27RA-Da7VYCfC.js} +1 -1
- package/dist/{diagram-Z3DM3KII-DfRWWQ5t.js → diagram-Z3DM3KII-DHk6GaR5.js} +1 -1
- package/dist/{dialog-B8vU2hHC.js → dialog-rgayPemF.js} +20 -20
- package/dist/{dropdown-menu-DzhAnAhr.js → dropdown-menu-B12Nf3Zf.js} +703 -703
- package/dist/{ebnfDiagram-PWID7BFC-DYxwv-nl.js → ebnfDiagram-PWID7BFC-DdSjinXr.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-D9e5WUw7.js → erDiagram-RLTQ6QDP-BgcwfZct.js} +1 -1
- package/dist/{error-banner-BRkKwvku.js → error-banner-DXHIN-63.js} +58 -58
- package/dist/{error-entries-BbxtqUQ4.js → error-entries-CNB7O2yS.js} +455 -455
- package/dist/{feedback-button-1MiN6gfS.js → feedback-button-CUPrIFyj.js} +7 -7
- package/dist/{flowDiagram-HODETNUW-tt7EepxX.js → flowDiagram-HODETNUW-CVwzkmUF.js} +2 -2
- package/dist/{formats-HRSqKdFt.js → formats-BWuAsLfw.js} +1 -1
- package/dist/{glide-data-editor-Kt7kYQLq.js → glide-data-editor-T1r8b4Cr.js} +11 -11
- package/dist/{glide-utils-BzjESEmr.js → glide-utils-D1McS0Pn.js} +2 -2
- package/dist/{globals-BjpSYd8i.js → globals-BweO1Da5.js} +3 -3
- package/dist/{html-to-image-DuNAF8H5.js → html-to-image-B0UiwmMu.js} +774 -774
- package/dist/{infoDiagram-27XIBGKW-CpQH_joy.js → infoDiagram-27XIBGKW-CHkU2P-8.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-d-it4xqm.js → ishikawaDiagram-5VMMS53U-B0k5UyY5.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-DItpqTFY.js → kanban-definition-UXKFOSKX-DwQvOV0x.js} +1 -1
- package/dist/main.js +4958 -4980
- package/dist/{mermaid-BugOVfeH.js → mermaid-Bqy6f_NU.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-D6IpF-_J.js → mindmap-definition-YA3MSWOX-CqvvAm8I.js} +1 -1
- package/dist/{number-overlay-editor-BG707U9t.js → number-overlay-editor-eynzhDoK.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-CXUu3QwE.js → pegDiagram-XKGWAZYB-Befnx4Ry.js} +2 -2
- package/dist/{pencil-DWRFEz2B.js → pencil-BC7pOv9g.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-DoUJF0yj.js → pieDiagram-E7YTZNPT-6rYFbF7p.js} +1 -1
- package/dist/{process-output-Cl97_Reh.js → process-output-3Epq3rw6.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-BsGDhtLL.js → railroadDiagram-O6MQD6OU-SSniwYC8.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-BHW0qW2Z.js → requirementDiagram-BXWQKSXE-3L_xNfQr.js} +1 -1
- package/dist/{reveal-component-C8L9okWw.js → reveal-component-C-ZgAhoP.js} +900 -900
- package/dist/{select-Brvb-RwP.js → select-PQHWLm64.js} +99 -99
- package/dist/{sequenceDiagram-WJ2MYXX4-DpgYJzLl.js → sequenceDiagram-WJ2MYXX4-DvzIRlWu.js} +1 -1
- package/dist/{spec-BWpscSQi.js → spec-6shN7lEe.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-Btf1jiYb.js → stateDiagram-D77RDMKH-VsHup-Ig.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-DN9FyEf3.js → stateDiagram-v2-MP3YSRHH-BwIIR8nk.js} +2 -2
- package/dist/{static-state-BhCfPRoz.js → static-state-CWXd6dYX.js} +9 -9
- package/dist/{swimlanes-42K2YHIH-2l_tR9qL.js → swimlanes-42K2YHIH-DhSDCIWI.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-BAkmv8kE.js → swimlanesDiagram-VR7AAH4N-C2WGVm-W.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-AxSxEOhx.js → timeline-definition-24CTP7MA-DhUhNinO.js} +1 -1
- package/dist/{toast-DOWc3HtU.js → toast-BGvv7tKS.js} +153 -153
- package/dist/{tooltip-DsQZP310.js → tooltip-CiJ919pg.js} +62 -62
- package/dist/{use-restore-focus-CTa7IRP6.js → use-restore-focus-BLj45Ibw.js} +75 -75
- package/dist/{useDateFormatter-CRuBYwR6.js → useDateFormatter-C659lkax.js} +2 -2
- package/dist/{useDeepCompareMemoize-B2RNcTmn.js → useDeepCompareMemoize-CDhinwm7.js} +1 -1
- package/dist/{useLifecycle-Bw0JtmoB.js → useLifecycle-mKiMNa4V.js} +1 -1
- package/dist/{vega-component-BV9sYHhU.js → vega-component-CWvQ7wBJ.js} +6 -6
- package/dist/{vennDiagram-4TSXK5OY-oHztO7MH.js → vennDiagram-4TSXK5OY-exvBF8P5.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-DWeEjZSc.js → wardleyDiagram-VM6X3IG4-BFhJmnXo.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-ESBlsY9i.js → xychartDiagram-S5SC5T6Z-D_xAdG6u.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +1 -0
- package/src/components/editor/controls/Controls.tsx +5 -2
- package/src/components/editor/notebook-cell.tsx +7 -21
- package/src/components/editor/renderers/grid-layout/grid-layout.tsx +2 -7
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +2 -4
- package/src/components/slides/minimap.tsx +2 -3
- package/src/components/slides/reveal-component.tsx +2 -3
- package/src/components/slides/slide-cell-view.tsx +5 -12
- package/src/core/cells/__tests__/cell.test.ts +8 -51
- package/src/core/cells/__tests__/utils.test.ts +27 -18
- package/src/core/cells/cell.ts +6 -12
- package/src/core/cells/cells.ts +5 -3
- package/src/core/cells/utils.ts +61 -55
- package/src/core/config/config.ts +4 -0
- package/src/core/executions/__tests__/atoms.test.ts +0 -18
- package/src/core/executions/__tests__/hooks.test.tsx +48 -2
- package/src/core/executions/__tests__/output-lifecycle.test.ts +90 -22
- package/src/core/executions/__tests__/select.test.ts +0 -17
- package/src/core/executions/atoms.ts +51 -65
- package/src/core/executions/hooks.ts +24 -0
- package/src/core/executions/index.ts +2 -0
- package/src/core/executions/select.ts +0 -5
- package/src/core/notebook/replica/replica.ts +8 -0
package/src/core/cells/utils.ts
CHANGED
|
@@ -15,14 +15,7 @@ import { Objects } from "@/utils/objects";
|
|
|
15
15
|
import { isErrorMime } from "../mime";
|
|
16
16
|
import type { NotebookState } from "./cells";
|
|
17
17
|
import type { CellId } from "./ids";
|
|
18
|
-
|
|
19
|
-
export function notebookNeedsRun(
|
|
20
|
-
state: NotebookState,
|
|
21
|
-
executions: CellExecutionInputs,
|
|
22
|
-
freshness: CellFreshnessLookup,
|
|
23
|
-
) {
|
|
24
|
-
return staleCellIds(state, executions, freshness).length > 0;
|
|
25
|
-
}
|
|
18
|
+
import type { CellData } from "./types";
|
|
26
19
|
|
|
27
20
|
export function notebookCells(state: NotebookState) {
|
|
28
21
|
return state.cellIds.map((cellId) => state.cellData[cellId]);
|
|
@@ -103,35 +96,72 @@ export function getDescendantsStatus(
|
|
|
103
96
|
};
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
type RunReason = "not-run" | "source" | "inputs" | "interrupted";
|
|
100
|
+
|
|
101
|
+
export function cellRunReason(
|
|
102
|
+
execution: Pick<CellExecutionView, "status" | "live" | "outcome" | "blocked">,
|
|
103
|
+
freshness: CellFreshness,
|
|
104
|
+
cell: Pick<CellData, "code" | "config">,
|
|
105
|
+
): RunReason | null {
|
|
106
|
+
if (execution.status !== "idle") {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (isUninstantiated(execution) && cell.code.trim()) {
|
|
110
|
+
return "not-run";
|
|
111
|
+
}
|
|
112
|
+
if (freshness.sourceChanged) {
|
|
113
|
+
return "source";
|
|
114
|
+
}
|
|
115
|
+
if (execution.outcome === "interrupted") {
|
|
116
|
+
return "interrupted";
|
|
117
|
+
}
|
|
118
|
+
return freshness.inputsChanged && !cell.config.disabled && !execution.blocked
|
|
119
|
+
? "inputs"
|
|
120
|
+
: null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function* cellsNeedingRun(
|
|
124
|
+
state: NotebookState,
|
|
125
|
+
executions: CellExecutionInputs,
|
|
126
|
+
freshness: CellFreshnessLookup,
|
|
127
|
+
): Generator<[CellId, RunReason]> {
|
|
128
|
+
for (const id of state.cellIds) {
|
|
129
|
+
const view = cellExecutionView(executions, id);
|
|
130
|
+
const changes = freshness(id);
|
|
131
|
+
const reason = cellRunReason(view, changes, state.cellData[id]);
|
|
132
|
+
if (reason !== null) {
|
|
133
|
+
yield [id, reason];
|
|
134
|
+
} else if (changes.sourceChanged && inFlight(executions.executions, id)) {
|
|
135
|
+
// The run action can submit an edit made after the host planned this cell.
|
|
136
|
+
yield [id, "source"];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
109
141
|
export function staleCellIds(
|
|
110
142
|
state: NotebookState,
|
|
111
143
|
executions: CellExecutionInputs,
|
|
112
144
|
freshness: CellFreshnessLookup,
|
|
113
145
|
) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
return Array.from(
|
|
147
|
+
cellsNeedingRun(state, executions, freshness),
|
|
148
|
+
([id]) => id,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function notebookRunReason(
|
|
153
|
+
state: NotebookState,
|
|
154
|
+
executions: CellExecutionInputs,
|
|
155
|
+
freshness: CellFreshnessLookup,
|
|
156
|
+
): RunReason | null {
|
|
157
|
+
let reason: RunReason | null = null;
|
|
158
|
+
for (const [, pending] of cellsNeedingRun(state, executions, freshness)) {
|
|
159
|
+
if (pending !== "inputs") {
|
|
160
|
+
return pending;
|
|
124
161
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
freshness: freshness(cellId),
|
|
129
|
-
interrupted: execution.outcome === "interrupted",
|
|
130
|
-
disabled: cellData[cellId].config.disabled,
|
|
131
|
-
blocked: execution.blocked,
|
|
132
|
-
})
|
|
133
|
-
);
|
|
134
|
-
});
|
|
162
|
+
reason = pending;
|
|
163
|
+
}
|
|
164
|
+
return reason;
|
|
135
165
|
}
|
|
136
166
|
|
|
137
167
|
/** Whether the host holds a planned or started execution of the cell that has not completed. */
|
|
@@ -158,30 +188,6 @@ export function isUninstantiated({
|
|
|
158
188
|
);
|
|
159
189
|
}
|
|
160
190
|
|
|
161
|
-
/**
|
|
162
|
-
* Whether a cell needs to be run: its source changed, its last run was
|
|
163
|
-
* interrupted, or an input changed and the cell can run. A disabled cell,
|
|
164
|
-
* or one blocked by a disabled ancestor, is not flagged for changed inputs
|
|
165
|
-
* until it can run again.
|
|
166
|
-
*/
|
|
167
|
-
export function cellNeedsRun({
|
|
168
|
-
freshness,
|
|
169
|
-
interrupted,
|
|
170
|
-
disabled,
|
|
171
|
-
blocked,
|
|
172
|
-
}: {
|
|
173
|
-
freshness: CellFreshness;
|
|
174
|
-
interrupted: boolean;
|
|
175
|
-
disabled: boolean | undefined;
|
|
176
|
-
blocked: boolean;
|
|
177
|
-
}): boolean {
|
|
178
|
-
return (
|
|
179
|
-
freshness.sourceChanged ||
|
|
180
|
-
interrupted ||
|
|
181
|
-
(freshness.inputsChanged && !(disabled || blocked))
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
191
|
export function cellStatusClasses({
|
|
186
192
|
needsRun,
|
|
187
193
|
errored,
|
|
@@ -71,6 +71,10 @@ export const resolvedMarimoConfigAtom = atom<UserConfig>((get) => {
|
|
|
71
71
|
return mergeConfig(userConfig, overrides);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
+
export const autoRunOnChangeAtom = atom(
|
|
75
|
+
(get) => get(resolvedMarimoConfigAtom).runtime.on_cell_change === "autorun",
|
|
76
|
+
);
|
|
77
|
+
|
|
74
78
|
export const autoInstantiateAtom = atom((get) => {
|
|
75
79
|
return get(resolvedMarimoConfigAtom).runtime.auto_instantiate;
|
|
76
80
|
});
|
|
@@ -233,24 +233,6 @@ describe("acceptRun", () => {
|
|
|
233
233
|
expect(statusOf(store)).toBe("idle");
|
|
234
234
|
});
|
|
235
235
|
|
|
236
|
-
it("keeps waiting while the stream is between a reset and its snapshot", () => {
|
|
237
|
-
const { store, replica } = shown();
|
|
238
|
-
const made = request(store, [C1]);
|
|
239
|
-
acceptRun(store, made, run([C1]));
|
|
240
|
-
|
|
241
|
-
const notebook = store.get(replica.notebookAtom);
|
|
242
|
-
store.set(replica.notebookAtom, null);
|
|
243
|
-
const stream = store.get(replica.executionsAtom);
|
|
244
|
-
store.set(replica.executionsAtom, { ...stream });
|
|
245
|
-
store.set(replica.notebookAtom, notebook);
|
|
246
|
-
expect(requested(store)).toEqual([C1]);
|
|
247
|
-
expect(statusOf(store)).toBe("queued");
|
|
248
|
-
|
|
249
|
-
store.set(replica.executionsAtom, withRuns(stream, [run([C1])]));
|
|
250
|
-
expect(requested(store)).toEqual([]);
|
|
251
|
-
expect(statusOf(store)).toBe("queued");
|
|
252
|
-
});
|
|
253
|
-
|
|
254
236
|
it("drops the request once the replica shows another notebook", () => {
|
|
255
237
|
const { store, replica } = shown();
|
|
256
238
|
const made = request(store, [C1]);
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { act, renderHook } from "@testing-library/react";
|
|
4
4
|
import { createStore, Provider } from "jotai";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
7
|
import { MockExecutions } from "@/__mocks__/executions";
|
|
8
|
+
import { configOverridesAtom } from "@/core/config/config";
|
|
8
9
|
import { cellId } from "@/__tests__/branded";
|
|
9
10
|
import {
|
|
10
11
|
cell,
|
|
@@ -12,7 +13,11 @@ import {
|
|
|
12
13
|
withCells,
|
|
13
14
|
} from "@/core/notebook/document/__tests__/fixtures";
|
|
14
15
|
import { clearCellOutputs } from "../atoms";
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
useCellFreshness,
|
|
18
|
+
useCellOutput,
|
|
19
|
+
useShowChangedInputs,
|
|
20
|
+
} from "../hooks";
|
|
16
21
|
|
|
17
22
|
const C1 = cellId("c1");
|
|
18
23
|
const C2 = cellId("c2");
|
|
@@ -106,6 +111,47 @@ describe("useCellFreshness", () => {
|
|
|
106
111
|
});
|
|
107
112
|
});
|
|
108
113
|
|
|
114
|
+
describe("input-change warnings", () => {
|
|
115
|
+
it("gives autorun time to queue a reader, but exposes an unhandled change", () => {
|
|
116
|
+
vi.useFakeTimers();
|
|
117
|
+
try {
|
|
118
|
+
const { wrapper, store } = setup([]);
|
|
119
|
+
const { result, rerender } = renderHook(
|
|
120
|
+
(changed: boolean) => useShowChangedInputs(changed),
|
|
121
|
+
{
|
|
122
|
+
wrapper,
|
|
123
|
+
initialProps: false,
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
rerender(true);
|
|
127
|
+
expect(result.current).toBe(false);
|
|
128
|
+
// Queued before the warning appeared.
|
|
129
|
+
rerender(false);
|
|
130
|
+
act(() => vi.runAllTimers());
|
|
131
|
+
expect(result.current).toBe(false);
|
|
132
|
+
rerender(true);
|
|
133
|
+
act(() => vi.runAllTimers());
|
|
134
|
+
expect(result.current).toBe(true);
|
|
135
|
+
rerender(false);
|
|
136
|
+
expect(result.current).toBe(false);
|
|
137
|
+
act(() => vi.advanceTimersByTime(50));
|
|
138
|
+
rerender(true);
|
|
139
|
+
act(() => vi.advanceTimersByTime(199));
|
|
140
|
+
expect(result.current).toBe(false);
|
|
141
|
+
act(() => vi.advanceTimersByTime(1));
|
|
142
|
+
expect(result.current).toBe(true);
|
|
143
|
+
rerender(false);
|
|
144
|
+
act(() =>
|
|
145
|
+
store.set(configOverridesAtom, { runtime: { on_cell_change: "lazy" } }),
|
|
146
|
+
);
|
|
147
|
+
rerender(true);
|
|
148
|
+
expect(result.current).toBe(true);
|
|
149
|
+
} finally {
|
|
150
|
+
vi.useRealTimers();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
109
155
|
describe("useCellOutput", () => {
|
|
110
156
|
const shown = (id: string) =>
|
|
111
157
|
MockExecutions.completed(id, {
|
|
@@ -14,7 +14,16 @@ import {
|
|
|
14
14
|
} from "@/core/notebook/replica/__tests__/fixtures";
|
|
15
15
|
import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
|
|
16
16
|
import { Deferred } from "@/utils/Deferred";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
acceptRun,
|
|
19
|
+
cellExecutionInputsAtom,
|
|
20
|
+
cellOutputAtom,
|
|
21
|
+
clearCellOutputs,
|
|
22
|
+
isCurrent,
|
|
23
|
+
observeCellMessage,
|
|
24
|
+
requestRun,
|
|
25
|
+
withdrawRequest,
|
|
26
|
+
} from "../atoms";
|
|
18
27
|
import { scratchOutputView } from "../output";
|
|
19
28
|
|
|
20
29
|
const C1 = cellId("c1");
|
|
@@ -24,12 +33,16 @@ const value = (data: string): Protocol.Outcome => ({
|
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
async function setup() {
|
|
27
|
-
|
|
36
|
+
interface Attempt {
|
|
37
|
+
message: Parameters<NotebookTransport>[1]["message"];
|
|
38
|
+
drop(): void;
|
|
39
|
+
}
|
|
40
|
+
let opened = new Deferred<Attempt>();
|
|
28
41
|
const backend = fakeBackend({
|
|
29
42
|
transport: ({ signal }, handlers) =>
|
|
30
43
|
new Promise<void>((resolve) => {
|
|
31
44
|
handlers.open();
|
|
32
|
-
|
|
45
|
+
opened.resolve({ message: handlers.message, drop: resolve });
|
|
33
46
|
signal.addEventListener("abort", () => resolve(), { once: true });
|
|
34
47
|
}),
|
|
35
48
|
});
|
|
@@ -38,7 +51,14 @@ async function setup() {
|
|
|
38
51
|
store.set(activeNotebookReplicaAtom, replica);
|
|
39
52
|
const disconnect = replica.connect(backend, { onNotification: vi.fn() });
|
|
40
53
|
onTestFinished(disconnect);
|
|
41
|
-
|
|
54
|
+
let attempt = await opened.promise;
|
|
55
|
+
const message: Attempt["message"] = (frame) => attempt.message(frame);
|
|
56
|
+
const reconnect = async () => {
|
|
57
|
+
opened = new Deferred<Attempt>();
|
|
58
|
+
attempt.drop();
|
|
59
|
+
await vi.advanceTimersByTimeAsync(2000);
|
|
60
|
+
attempt = await opened.promise;
|
|
61
|
+
};
|
|
42
62
|
let cursor = 100;
|
|
43
63
|
const emit = (execution: Protocol.Execution) =>
|
|
44
64
|
message({ event: "execution", id: String(++cursor), data: { execution } });
|
|
@@ -65,24 +85,76 @@ async function setup() {
|
|
|
65
85
|
records.forEach(emit);
|
|
66
86
|
message({ event: "ready", id: String(++cursor), data: {} });
|
|
67
87
|
};
|
|
68
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
store,
|
|
90
|
+
replica,
|
|
91
|
+
emit,
|
|
92
|
+
remove,
|
|
93
|
+
snapshot,
|
|
94
|
+
message,
|
|
95
|
+
reconnect,
|
|
96
|
+
};
|
|
69
97
|
}
|
|
70
98
|
|
|
71
99
|
describe("output lifetime", () => {
|
|
72
|
-
it("
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
100
|
+
it.each(["replay", "snapshot", "in-place reset"] as const)(
|
|
101
|
+
"expires editor marks on %s for the same notebook",
|
|
102
|
+
async (recovery) => {
|
|
103
|
+
vi.useFakeTimers();
|
|
104
|
+
onTestFinished(() => {
|
|
105
|
+
vi.useRealTimers();
|
|
106
|
+
});
|
|
107
|
+
const { store, snapshot, message, reconnect } = await setup();
|
|
108
|
+
const result = MockExecutions.completed(C1, { outcome: value("A") });
|
|
109
|
+
snapshot([result]);
|
|
110
|
+
const run: Protocol.Run = {
|
|
111
|
+
id: "missed",
|
|
112
|
+
notebook_id: "n1",
|
|
113
|
+
runtime_id: "r1",
|
|
114
|
+
cells: [C1],
|
|
115
|
+
status: "queued",
|
|
116
|
+
outcome: null,
|
|
117
|
+
started_at: null,
|
|
118
|
+
completed_at: null,
|
|
119
|
+
};
|
|
120
|
+
const pending = requestRun(store, [C1])!;
|
|
121
|
+
acceptRun(store, pending, run);
|
|
122
|
+
const late = requestRun(store, [C1])!;
|
|
123
|
+
observeCellMessage(store, {
|
|
124
|
+
cell_id: C1,
|
|
125
|
+
status: "disabled-transitively",
|
|
126
|
+
timestamp: 1,
|
|
127
|
+
output: null,
|
|
128
|
+
console: null,
|
|
129
|
+
});
|
|
130
|
+
clearCellOutputs(store, [C1]);
|
|
131
|
+
expect(store.get(cellExecutionInputsAtom).blocked.has(C1)).toBe(true);
|
|
132
|
+
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
133
|
+
|
|
134
|
+
if (recovery !== "in-place reset") {
|
|
135
|
+
await reconnect();
|
|
136
|
+
}
|
|
137
|
+
if (recovery !== "replay") {
|
|
138
|
+
snapshot([result]);
|
|
139
|
+
} else {
|
|
140
|
+
message({ event: "ready", id: "120", data: {} });
|
|
141
|
+
}
|
|
142
|
+
const { requested, blocked } = store.get(cellExecutionInputsAtom);
|
|
143
|
+
expect([...requested]).toEqual([]);
|
|
144
|
+
expect([...blocked]).toEqual([]);
|
|
145
|
+
expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
|
|
146
|
+
expect(isCurrent(store, late)).toBe(false);
|
|
147
|
+
|
|
148
|
+
const current = requestRun(store, [C1])!;
|
|
149
|
+
acceptRun(store, late, run);
|
|
150
|
+
withdrawRequest(store, pending);
|
|
151
|
+
expect(isCurrent(store, current)).toBe(true);
|
|
152
|
+
expect([...store.get(cellExecutionInputsAtom).requested]).toEqual([C1]);
|
|
153
|
+
withdrawRequest(store, current);
|
|
154
|
+
expect([...store.get(cellExecutionInputsAtom).requested]).toEqual([]);
|
|
155
|
+
},
|
|
156
|
+
);
|
|
78
157
|
|
|
79
|
-
message({ event: "reset", data: {} });
|
|
80
|
-
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
81
|
-
snapshot([result]);
|
|
82
|
-
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
83
|
-
disconnect();
|
|
84
|
-
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
85
|
-
});
|
|
86
158
|
it("keeps a changed display visible after its execution retires", async () => {
|
|
87
159
|
const { store, replica, emit, remove, snapshot } = await setup();
|
|
88
160
|
const result = MockExecutions.completed(C1, { outcome: value("A") });
|
|
@@ -121,14 +193,10 @@ describe("output lifetime", () => {
|
|
|
121
193
|
};
|
|
122
194
|
emit(completed);
|
|
123
195
|
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
124
|
-
snapshot([completed]);
|
|
125
|
-
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
126
196
|
remove(completed);
|
|
127
197
|
const next = MockExecutions.running(C1);
|
|
128
198
|
emit(next);
|
|
129
199
|
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
130
|
-
snapshot([next]);
|
|
131
|
-
expect(store.get(cellOutputAtom(C1))).toBeNull();
|
|
132
200
|
emit({ ...next, outcome: value("A") });
|
|
133
201
|
expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
|
|
134
202
|
});
|
|
@@ -110,7 +110,6 @@ describe("cellExecutionView", () => {
|
|
|
110
110
|
outcome: null,
|
|
111
111
|
startedAt: null,
|
|
112
112
|
duration: null,
|
|
113
|
-
rendered: false,
|
|
114
113
|
live: true,
|
|
115
114
|
});
|
|
116
115
|
});
|
|
@@ -146,25 +145,10 @@ describe("cellExecutionView", () => {
|
|
|
146
145
|
outcome: null,
|
|
147
146
|
startedAt: Date.parse(T2),
|
|
148
147
|
duration: null,
|
|
149
|
-
rendered: false,
|
|
150
148
|
live: true,
|
|
151
149
|
});
|
|
152
150
|
});
|
|
153
151
|
|
|
154
|
-
it("notes when a running execution has shown a value so far", () => {
|
|
155
|
-
const showing = inputs({
|
|
156
|
-
executions: [
|
|
157
|
-
execution({
|
|
158
|
-
id: "e1",
|
|
159
|
-
status: "running",
|
|
160
|
-
outcome: { kind: "value", display: null },
|
|
161
|
-
completed_at: null,
|
|
162
|
-
}),
|
|
163
|
-
],
|
|
164
|
-
});
|
|
165
|
-
expect(cellExecutionView(showing, "c1").rendered).toBe(true);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
152
|
it("says whether the notebook's runtime produced the cell's result", () => {
|
|
169
153
|
const result = execution({ id: "e1" });
|
|
170
154
|
const produced = (runtimeId: string | null) =>
|
|
@@ -205,7 +189,6 @@ describe("cellExecutionView", () => {
|
|
|
205
189
|
outcome: "value",
|
|
206
190
|
startedAt: Date.parse(T0),
|
|
207
191
|
duration: 1500,
|
|
208
|
-
rendered: false,
|
|
209
192
|
live: true,
|
|
210
193
|
});
|
|
211
194
|
const error = (kind: string): Protocol.Outcome => ({
|
|
@@ -51,15 +51,9 @@ const NO_CLEARED: ReadonlyMap<Protocol.CellId, ClearedOutput> = new Map();
|
|
|
51
51
|
interface ShownNotebook {
|
|
52
52
|
readonly replica: NotebookReplica;
|
|
53
53
|
readonly id: Protocol.NotebookId;
|
|
54
|
+
readonly generation: number;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
/**
|
|
57
|
-
* What the editor marks about cells of one replica's notebook.
|
|
58
|
-
*
|
|
59
|
-
* The marks refer to cells by id, which another notebook, or the same one
|
|
60
|
-
* after a reconnect, reuses with different executions behind it. They
|
|
61
|
-
* therefore count only for the replica and host notebook they belong to.
|
|
62
|
-
*/
|
|
63
57
|
type Marks<T> = {
|
|
64
58
|
readonly notebook: ShownNotebook;
|
|
65
59
|
readonly value: T;
|
|
@@ -96,55 +90,44 @@ const requestsAtom = atom<Marks<ReadonlySet<RunRequest>>>(null);
|
|
|
96
90
|
*/
|
|
97
91
|
const blockedCellsAtom = atom<Marks<ReadonlySet<Protocol.CellId>>>(null);
|
|
98
92
|
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
93
|
+
function sameNotebook(
|
|
94
|
+
marked: ShownNotebook,
|
|
95
|
+
shown: ShownNotebook | null,
|
|
96
|
+
): boolean {
|
|
97
|
+
return (
|
|
98
|
+
shown !== null &&
|
|
99
|
+
marked.replica === shown.replica &&
|
|
100
|
+
marked.id === shown.id &&
|
|
101
|
+
marked.generation === shown.generation
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function current<T>(marks: Marks<T>, shown: ShownNotebook | null, empty: T): T {
|
|
106
|
+
return marks !== null && sameNotebook(marks.notebook, shown)
|
|
108
107
|
? marks.value
|
|
109
108
|
: empty;
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
const replica =
|
|
114
|
-
const notebook = replica === null ? null :
|
|
111
|
+
const shownNotebookAtom = atom((get): ShownNotebook | null => {
|
|
112
|
+
const replica = get(activeNotebookReplicaAtom);
|
|
113
|
+
const notebook = replica === null ? null : get(replica.notebookAtom);
|
|
115
114
|
return replica === null || notebook === null
|
|
116
115
|
? null
|
|
117
|
-
: { replica, id: notebook.id };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function mark<T>(store: Pick<Store, "get">, value: T): Marks<T> {
|
|
121
|
-
const notebook = shownNotebook(store);
|
|
122
|
-
return notebook === null ? null : { notebook, value };
|
|
123
|
-
}
|
|
116
|
+
: { replica, id: notebook.id, generation: get(replica.generationAtom) };
|
|
117
|
+
});
|
|
124
118
|
|
|
125
|
-
/**
|
|
126
|
-
* Whether `request` still belongs to the notebook being shown.
|
|
127
|
-
*
|
|
128
|
-
* Between a reset and the next snapshot the replica has no notebook for a
|
|
129
|
-
* moment. That says nothing about where the request belongs, so it does
|
|
130
|
-
* not count against it. Another replica, or another notebook on the same
|
|
131
|
-
* replica, does.
|
|
132
|
-
*/
|
|
119
|
+
/** Whether the request still belongs to the current stream. */
|
|
133
120
|
export function isCurrent(store: Store, request: RunRequest): boolean {
|
|
134
|
-
|
|
135
|
-
if (replica !== request.notebook.replica) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
const notebook = store.get(replica.notebookAtom);
|
|
139
|
-
return notebook === null || notebook.id === request.notebook.id;
|
|
121
|
+
return sameNotebook(request.notebook, store.get(shownNotebookAtom));
|
|
140
122
|
}
|
|
141
123
|
|
|
142
124
|
/** Cells named by pending requests made in the notebook now shown. */
|
|
143
125
|
const requestedCellsAtom = atom((get) => {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
const requests = current(
|
|
127
|
+
get(requestsAtom),
|
|
128
|
+
get(shownNotebookAtom),
|
|
129
|
+
NO_REQUESTS,
|
|
130
|
+
);
|
|
148
131
|
return requests.size === 0
|
|
149
132
|
? NO_REQUESTED
|
|
150
133
|
: new Set([...requests].flatMap((request) => request.cells));
|
|
@@ -153,15 +136,13 @@ const requestedCellsAtom = atom((get) => {
|
|
|
153
136
|
/** What every cell's view derives from. Pair with `cellExecutionView`. */
|
|
154
137
|
export const cellExecutionInputsAtom = atom((get): CellExecutionInputs => {
|
|
155
138
|
const replica = get(activeNotebookReplicaAtom);
|
|
156
|
-
const notebookId =
|
|
157
|
-
replica === null ? null : (get(replica.notebookAtom)?.id ?? null);
|
|
158
139
|
const document = replica === null ? null : get(replica.shownDocumentAtom);
|
|
159
140
|
return {
|
|
160
141
|
executions: replica === null ? NO_EXECUTIONS : get(replica.executionsAtom),
|
|
161
142
|
results: replica === null ? NO_RESULTS : get(replica.resultsAtom),
|
|
162
143
|
cells: document?.cells ?? NO_CELLS,
|
|
163
144
|
requested: get(requestedCellsAtom),
|
|
164
|
-
blocked: current(get(blockedCellsAtom),
|
|
145
|
+
blocked: current(get(blockedCellsAtom), get(shownNotebookAtom), NO_BLOCKED),
|
|
165
146
|
runtimeId: replica === null ? null : (get(replica.runtimeAtom)?.id ?? null),
|
|
166
147
|
};
|
|
167
148
|
});
|
|
@@ -195,17 +176,24 @@ const displayedNotebookAtom = atom((get): ShownNotebook | null => {
|
|
|
195
176
|
const document = replica === null ? null : get(replica.shownDocumentAtom);
|
|
196
177
|
return replica === null || document === null
|
|
197
178
|
? null
|
|
198
|
-
: {
|
|
179
|
+
: {
|
|
180
|
+
replica,
|
|
181
|
+
id: document.revision.notebook_id,
|
|
182
|
+
generation: get(replica.generationAtom),
|
|
183
|
+
};
|
|
199
184
|
});
|
|
200
185
|
|
|
201
186
|
/** What every cell's output derives from. Pair with `cellOutputView`. */
|
|
202
187
|
export const cellOutputInputsAtom = atom((get): CellOutputInputs => {
|
|
203
188
|
const replica = get(activeNotebookReplicaAtom);
|
|
204
|
-
const notebookId = get(displayedNotebookAtom)?.id ?? null;
|
|
205
189
|
return {
|
|
206
190
|
executions: replica === null ? NO_EXECUTIONS : get(replica.executionsAtom),
|
|
207
191
|
results: replica === null ? NO_RESULTS : get(replica.resultsAtom),
|
|
208
|
-
cleared: current(
|
|
192
|
+
cleared: current(
|
|
193
|
+
get(clearedOutputsAtom),
|
|
194
|
+
get(displayedNotebookAtom),
|
|
195
|
+
NO_CLEARED,
|
|
196
|
+
),
|
|
209
197
|
cells:
|
|
210
198
|
replica === null
|
|
211
199
|
? NO_CELLS
|
|
@@ -347,18 +335,12 @@ export function requestRun(
|
|
|
347
335
|
store: Store,
|
|
348
336
|
cellIds: readonly Protocol.CellId[],
|
|
349
337
|
): RunRequest | null {
|
|
350
|
-
const notebook =
|
|
338
|
+
const notebook = store.get(shownNotebookAtom);
|
|
351
339
|
if (notebook === null) {
|
|
352
340
|
return null;
|
|
353
341
|
}
|
|
354
342
|
const request: RunRequest = { notebook, cells: [...cellIds] };
|
|
355
|
-
const
|
|
356
|
-
const kept =
|
|
357
|
-
marks !== null &&
|
|
358
|
-
marks.notebook.replica === notebook.replica &&
|
|
359
|
-
marks.notebook.id === notebook.id
|
|
360
|
-
? marks.value
|
|
361
|
-
: NO_REQUESTS;
|
|
343
|
+
const kept = current(store.get(requestsAtom), notebook, NO_REQUESTS);
|
|
362
344
|
store.set(requestsAtom, { notebook, value: new Set(kept).add(request) });
|
|
363
345
|
return request;
|
|
364
346
|
}
|
|
@@ -385,13 +367,14 @@ export function acceptRun(
|
|
|
385
367
|
request: RunRequest,
|
|
386
368
|
run: Protocol.Run,
|
|
387
369
|
): void {
|
|
388
|
-
const
|
|
389
|
-
|
|
370
|
+
const waitingAtom = atom(
|
|
371
|
+
(get) =>
|
|
372
|
+
sameNotebook(request.notebook, get(shownNotebookAtom)) &&
|
|
373
|
+
!get(request.notebook.replica.executionsAtom).runs.has(run.id),
|
|
374
|
+
);
|
|
375
|
+
const unsubscribe = store.sub(waitingAtom, check);
|
|
390
376
|
function check() {
|
|
391
|
-
if (
|
|
392
|
-
isCurrent(store, request) &&
|
|
393
|
-
!store.get(replica.executionsAtom).runs.has(run.id)
|
|
394
|
-
) {
|
|
377
|
+
if (store.get(waitingAtom)) {
|
|
395
378
|
return;
|
|
396
379
|
}
|
|
397
380
|
unsubscribe();
|
|
@@ -415,7 +398,10 @@ function setCellBlocked(
|
|
|
415
398
|
} else {
|
|
416
399
|
next.delete(cellId);
|
|
417
400
|
}
|
|
418
|
-
store.
|
|
401
|
+
const notebook = store.get(shownNotebookAtom);
|
|
402
|
+
if (notebook !== null) {
|
|
403
|
+
store.set(blockedCellsAtom, { notebook, value: next });
|
|
404
|
+
}
|
|
419
405
|
}
|
|
420
406
|
|
|
421
407
|
/**
|
|
@@ -5,6 +5,8 @@ import { dequal } from "dequal";
|
|
|
5
5
|
import { useAtomValue } from "jotai";
|
|
6
6
|
import { selectAtom } from "jotai/utils";
|
|
7
7
|
import { useMemo } from "react";
|
|
8
|
+
import { autoRunOnChangeAtom } from "@/core/config/config";
|
|
9
|
+
import { useDelayElapsed } from "@/hooks/useDelayElapsed";
|
|
8
10
|
import type { CellId } from "@/core/cells/ids";
|
|
9
11
|
import type { Outline } from "@/core/cells/outline";
|
|
10
12
|
import {
|
|
@@ -54,6 +56,28 @@ export function useCellFreshness(id: Protocol.CellId): CellFreshness {
|
|
|
54
56
|
return useAtomValue(cellAtom);
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/** A variable revision can arrive just before the host queues its readers. */
|
|
60
|
+
export function useShowChangedInputs(changed: boolean): boolean {
|
|
61
|
+
const autorun = useAtomValue(autoRunOnChangeAtom);
|
|
62
|
+
const delayElapsed = useDelayElapsed(autorun && changed ? 200 : 0);
|
|
63
|
+
return changed && delayElapsed;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function useCellPresentation(id: Protocol.CellId) {
|
|
67
|
+
const execution = useCellExecution(id);
|
|
68
|
+
const actual = useCellFreshness(id);
|
|
69
|
+
const inputsChanged = useShowChangedInputs(
|
|
70
|
+
actual.inputsChanged && execution.status === "idle",
|
|
71
|
+
);
|
|
72
|
+
return {
|
|
73
|
+
execution,
|
|
74
|
+
freshness:
|
|
75
|
+
inputsChanged === actual.inputsChanged
|
|
76
|
+
? actual
|
|
77
|
+
: { ...actual, inputsChanged },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
57
81
|
/** What the cell shows: its running value so far, else its result's outcome. */
|
|
58
82
|
export function useCellOutput(id: CellId): CellOutput | null {
|
|
59
83
|
return useAtomValue(cellOutputAtom(id));
|