@marimo-team/islands 0.26.1-dev25 → 0.26.1-dev29
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-Bs2ehxEI.js → ErrorBoundary-CPcZlpvU.js} +1 -1
- package/dist/{chat-ui-DOvIzlMA.js → chat-ui-CWmSnBs8.js} +899 -899
- package/dist/{code-visibility-BnMkbydx.js → code-visibility-CHvnQsso.js} +2 -2
- package/dist/{common-CQur5dRA.js → common-9OlCmjdr.js} +6565 -6565
- package/dist/{config-DL9e-OWE.js → config-1ku0tAiU.js} +27 -28
- package/dist/{data-grid-overlay-editor-BXEY35Xl.js → data-grid-overlay-editor-D6x_MBSD.js} +1 -1
- package/dist/{dropdown-menu-DYN2RV5d.js → dropdown-menu-D65ZUqka.js} +1983 -1983
- package/dist/{error-entries-CncQR572.js → error-entries-DFHEq_SO.js} +515 -519
- package/dist/{feedback-button-BAOp7zqu.js → feedback-button-CodkZ3hF.js} +19 -19
- package/dist/{glide-data-editor-Ce94qTW7.js → glide-data-editor-BZxvtSp-.js} +35 -35
- package/dist/{globals-Uqg4j5z5.js → globals-DFf-tSyE.js} +1 -1
- package/dist/{html-to-image-BU7H-AM1.js → html-to-image-D6Gtk5ik.js} +24005 -23992
- package/dist/main.js +864 -864
- package/dist/{number-overlay-editor-Br_Vp3Ws.js → number-overlay-editor-CfwFMv_U.js} +1 -1
- package/dist/{process-output-xJm8T5-E.js → process-output-ZBdibqlG.js} +2 -2
- package/dist/{reveal-component-B7TgfbYJ.js → reveal-component-CDfNuSFv.js} +3 -3
- package/dist/style.css +1 -1
- package/dist/{vega-component-DpTyTrz3.js → vega-component-D61CTW1X.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/intersection-observer.ts +45 -0
- package/src/components/databases/engine-variable.tsx +2 -2
- package/src/components/dependency-graph/panels.tsx +2 -2
- package/src/components/editor/actions/useCellActionButton.tsx +2 -8
- package/src/components/editor/cell/code/__tests__/code-placeholder.test.tsx +40 -0
- package/src/components/editor/cell/code/cell-editor.tsx +41 -104
- package/src/components/editor/cell/code/code-placeholder.css +61 -11
- package/src/components/editor/cell/code/code-placeholder.tsx +52 -29
- package/src/components/editor/cell/useSplitCell.tsx +2 -2
- package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +6 -10
- package/src/components/editor/errors/auto-fix.tsx +8 -7
- package/src/components/editor/navigation/__tests__/navigation.test.ts +3 -12
- package/src/components/editor/navigation/focus-utils.ts +20 -8
- package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +3 -11
- package/src/components/editor/navigation/navigation.ts +2 -2
- package/src/components/editor/notebook-cell.tsx +15 -24
- package/src/components/editor/output/MarimoTracebackOutput.tsx +2 -2
- package/src/components/editor/renderers/vertical-layout/__tests__/useFocusFirstEditor.test.ts +6 -9
- package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +2 -5
- package/src/components/find-replace/find-replace.tsx +3 -7
- package/src/components/variables/__tests__/variables-table.test.tsx +1 -2
- package/src/core/ai/__tests__/staged-cells.test.ts +6 -39
- package/src/core/ai/staged-cells.ts +2 -20
- package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +15 -13
- package/src/core/ai/tools/edit-notebook-tool.ts +13 -8
- package/src/core/cells/__tests__/cell-editor-view.test.ts +44 -0
- package/src/core/cells/__tests__/cells.test.ts +0 -1
- package/src/core/cells/__tests__/focus.test.ts +1 -7
- package/src/core/cells/__tests__/harness.ts +0 -1
- package/src/core/cells/cells.ts +15 -10
- package/src/core/cells/focus.ts +1 -1
- package/src/core/cells/scrollCellIntoView.ts +4 -14
- package/src/core/cells/utils.ts +0 -13
- package/src/core/codemirror/__tests__/cell-documents.test.ts +79 -0
- package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +75 -105
- package/src/core/codemirror/__tests__/format.test.ts +85 -63
- package/src/core/codemirror/__tests__/use-lazy-editor-mount.test.tsx +193 -0
- package/src/core/codemirror/cell-documents.ts +132 -0
- package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +0 -1
- package/src/core/codemirror/copilot/getCodes.ts +3 -14
- package/src/core/codemirror/editor-mount-scheduler.ts +41 -48
- package/src/core/codemirror/extensions.ts +2 -2
- package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +42 -16
- package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +30 -0
- package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +145 -0
- package/src/core/codemirror/find-replace/navigate.ts +88 -129
- package/src/core/codemirror/find-replace/search-highlight.ts +3 -1
- package/src/core/codemirror/find-replace/state.ts +7 -2
- package/src/core/codemirror/format.ts +25 -31
- package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +8 -9
- package/src/core/codemirror/language/cell-code.ts +7 -0
- package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +25 -0
- package/src/core/codemirror/lsp/notebook-lsp.ts +6 -16
- package/src/core/codemirror/use-lazy-editor-mount.ts +67 -0
- package/src/core/codemirror/utils.ts +2 -6
- package/src/utils/__tests__/shared-intersection-observer.test.ts +49 -0
- package/src/utils/shared-intersection-observer.ts +53 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { cellId } from "@/__tests__/branded";
|
|
5
|
+
import { editorMountScheduler } from "@/core/codemirror/editor-mount-scheduler";
|
|
6
|
+
import { store } from "@/core/state/jotai";
|
|
7
|
+
import {
|
|
8
|
+
ensureCellEditorView,
|
|
9
|
+
getCellEditorView,
|
|
10
|
+
initialNotebookState,
|
|
11
|
+
notebookAtom,
|
|
12
|
+
} from "../cells";
|
|
13
|
+
|
|
14
|
+
const id = cellId("cell");
|
|
15
|
+
const view = new EditorView();
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
store.set(notebookAtom, initialNotebookState());
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("returns an editor only once it is built, and building is explicit", () => {
|
|
22
|
+
const handle = { current: { editorView: null } } as {
|
|
23
|
+
current: {
|
|
24
|
+
editorView: EditorView | null;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
store.set(notebookAtom, {
|
|
28
|
+
...initialNotebookState(),
|
|
29
|
+
cellIds: [id],
|
|
30
|
+
cellHandles: { [id]: handle },
|
|
31
|
+
});
|
|
32
|
+
const build = vi.fn(() => {
|
|
33
|
+
handle.current = { editorView: view };
|
|
34
|
+
});
|
|
35
|
+
const release = editorMountScheduler.register(id, build);
|
|
36
|
+
|
|
37
|
+
expect(getCellEditorView(id)).toBeUndefined();
|
|
38
|
+
expect(build).not.toHaveBeenCalled();
|
|
39
|
+
|
|
40
|
+
expect(ensureCellEditorView(id)).toBe(view);
|
|
41
|
+
expect(getCellEditorView(id)).toBe(view);
|
|
42
|
+
expect(build).toHaveBeenCalledTimes(1);
|
|
43
|
+
release();
|
|
44
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type { EditorView } from "@codemirror/view";
|
|
4
3
|
import { createStore } from "jotai";
|
|
5
4
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
5
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
@@ -282,12 +281,7 @@ describe("lastFocusedCellAtom", () => {
|
|
|
282
281
|
const store = createStore();
|
|
283
282
|
const markdownCellId = cellId("markdown");
|
|
284
283
|
|
|
285
|
-
const unmountedEditorHandle: CellHandle = {
|
|
286
|
-
get editorView(): EditorView {
|
|
287
|
-
throw new ReferenceError("Attempting to dereference null object.");
|
|
288
|
-
},
|
|
289
|
-
editorViewOrNull: null,
|
|
290
|
-
};
|
|
284
|
+
const unmountedEditorHandle: CellHandle = { editorView: null };
|
|
291
285
|
|
|
292
286
|
const notebook = MockNotebook.notebookState({
|
|
293
287
|
cellData: {
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import type { EditorView } from "@codemirror/view";
|
|
3
4
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
5
|
import { type Atom, atom, useAtom, useAtomValue } from "jotai";
|
|
5
6
|
import { atomFamily, selectAtom, splitAtom } from "jotai/utils";
|
|
@@ -325,8 +326,9 @@ const {
|
|
|
325
326
|
};
|
|
326
327
|
},
|
|
327
328
|
foldAll: (state) => {
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
// A cell without an editor starts unfolded, so folding needs every editor.
|
|
330
|
+
const targets = Object.keys(state.cellHandles).map((cellId) =>
|
|
331
|
+
ensureCellEditorView(cellId as CellId),
|
|
330
332
|
);
|
|
331
333
|
foldAllBulk(targets);
|
|
332
334
|
return state;
|
|
@@ -614,26 +616,29 @@ export const useCellHandle = (cellId: CellId) =>
|
|
|
614
616
|
useAtomValue(cellHandleAtom(cellId));
|
|
615
617
|
|
|
616
618
|
/**
|
|
617
|
-
* Get
|
|
619
|
+
* Get mounted editor views only. Read cellData for cells without an editor.
|
|
618
620
|
*/
|
|
619
621
|
export const getAllEditorViews = () => {
|
|
620
622
|
const { cellIds, cellHandles } = store.get(notebookAtom);
|
|
621
623
|
return cellIds
|
|
622
|
-
.map((cellId) => cellHandles[cellId]?.current?.
|
|
624
|
+
.map((cellId) => cellHandles[cellId]?.current?.editorView)
|
|
623
625
|
.filter(Boolean);
|
|
624
626
|
};
|
|
625
627
|
|
|
626
|
-
|
|
628
|
+
/** The cell's editor if it has been built; never builds one. */
|
|
629
|
+
export const getCellEditorView = (cellId: CellId): EditorView | undefined => {
|
|
627
630
|
const { cellHandles } = store.get(notebookAtom);
|
|
628
|
-
return cellHandles[cellId]
|
|
631
|
+
return cellHandles[cellId]?.current?.editorView ?? undefined;
|
|
629
632
|
};
|
|
630
633
|
|
|
631
634
|
/**
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
+
* The cell's editor, built synchronously first if it is still dormant. Use it
|
|
636
|
+
* for explicit user actions that target one cell. A freshly built editor is
|
|
637
|
+
* not attached to the page until React renders, so wait before focusing it.
|
|
635
638
|
*/
|
|
636
|
-
export const ensureCellEditorView = (
|
|
639
|
+
export const ensureCellEditorView = (
|
|
640
|
+
cellId: CellId,
|
|
641
|
+
): EditorView | undefined => {
|
|
637
642
|
editorMountScheduler.promote(cellId);
|
|
638
643
|
return getCellEditorView(cellId);
|
|
639
644
|
};
|
package/src/core/cells/focus.ts
CHANGED
|
@@ -110,7 +110,7 @@ function cellFocusDetails(get: Getter, cellId: CellId) {
|
|
|
110
110
|
if (!data || !handle) {
|
|
111
111
|
return null;
|
|
112
112
|
}
|
|
113
|
-
const getEditorView = () => handle.
|
|
113
|
+
const getEditorView = () => handle.editorView;
|
|
114
114
|
const execution = cellExecutionView(get(cellExecutionInputsAtom), cellId);
|
|
115
115
|
|
|
116
116
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import type { RefObject } from "react";
|
|
3
3
|
import {
|
|
4
|
+
focusEditor,
|
|
4
5
|
isAnyCellFocused,
|
|
5
6
|
tryFocus,
|
|
6
7
|
} from "@/components/editor/navigation/focus-utils";
|
|
7
8
|
import type { CellHandle } from "@/components/editor/notebook-cell";
|
|
8
|
-
import { retryWithTimeout } from "@/utils/timeout";
|
|
9
9
|
import { Logger } from "../../utils/Logger";
|
|
10
10
|
import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
|
|
11
11
|
import { scrollActiveLineIntoView } from "../codemirror/extensions";
|
|
@@ -49,8 +49,8 @@ export function focusAndScrollCellIntoView({
|
|
|
49
49
|
// https://github.com/marimo-team/marimo/issues/2940
|
|
50
50
|
tryFocus(element);
|
|
51
51
|
} else {
|
|
52
|
-
// Build this cell's editor now if it is still
|
|
53
|
-
// it instead of the placeholder.
|
|
52
|
+
// Build this cell's editor now if it is still dormant, so focus can land
|
|
53
|
+
// in it instead of the placeholder.
|
|
54
54
|
editorMountScheduler.promote(cellId);
|
|
55
55
|
const editor = cell.current?.editorView;
|
|
56
56
|
if (!editor) {
|
|
@@ -63,17 +63,7 @@ export function focusAndScrollCellIntoView({
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
retryWithTimeout(
|
|
68
|
-
() => {
|
|
69
|
-
editor.focus();
|
|
70
|
-
return editor.hasFocus;
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
retries: 5,
|
|
74
|
-
delay: 20,
|
|
75
|
-
},
|
|
76
|
-
);
|
|
66
|
+
focusEditor(editor);
|
|
77
67
|
|
|
78
68
|
if (codeFocus === "top") {
|
|
79
69
|
// If codeFocus is top, move the cursor to the top of the editor.
|
package/src/core/cells/utils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type { EditorView } from "@codemirror/view";
|
|
4
3
|
import {
|
|
5
4
|
type CellError,
|
|
6
5
|
type CellExecutionInputs,
|
|
@@ -11,7 +10,6 @@ import {
|
|
|
11
10
|
cellExecutionView,
|
|
12
11
|
} from "@/core/executions";
|
|
13
12
|
import type { Executions } from "@/core/notebook/replica";
|
|
14
|
-
import { Objects } from "@/utils/objects";
|
|
15
13
|
import { isErrorMime } from "../mime";
|
|
16
14
|
import type { NotebookState } from "./cells";
|
|
17
15
|
import type { CellId } from "./ids";
|
|
@@ -21,17 +19,6 @@ export function notebookCells(state: NotebookState) {
|
|
|
21
19
|
return state.cellIds.map((cellId) => state.cellData[cellId]);
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export function notebookCellEditorViews({ cellHandles }: NotebookState) {
|
|
25
|
-
const views: Record<CellId, EditorView> = {};
|
|
26
|
-
for (const [cell, ref] of Objects.entries(cellHandles)) {
|
|
27
|
-
if (!ref.current?.editorView) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
views[cell] = ref.current.editorView;
|
|
31
|
-
}
|
|
32
|
-
return views;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
22
|
export function disabledCellIds(state: NotebookState) {
|
|
36
23
|
const { cellIds, cellData } = state;
|
|
37
24
|
const disabledCells: CellId[] = [];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { cellId } from "@/__tests__/branded";
|
|
5
|
+
import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
|
|
6
|
+
import { createCell } from "@/core/cells/types";
|
|
7
|
+
import { store } from "@/core/state/jotai";
|
|
8
|
+
import { getCellDocuments, writeCellCode } from "../cell-documents";
|
|
9
|
+
|
|
10
|
+
const { writes } = vi.hoisted(() => ({ writes: vi.fn() }));
|
|
11
|
+
vi.mock("@/core/cells/actions", async () => {
|
|
12
|
+
const { atom } = await import("jotai");
|
|
13
|
+
return { setCellCodeAtom: atom(null, (_get, _set, w) => writes(w)) };
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const id = cellId("cell");
|
|
17
|
+
|
|
18
|
+
function setNotebook(code: string, view: EditorView | null) {
|
|
19
|
+
store.set(notebookAtom, {
|
|
20
|
+
...initialNotebookState(),
|
|
21
|
+
cellIds: [id],
|
|
22
|
+
cellData: { [id]: createCell({ id, code }) },
|
|
23
|
+
cellHandles: {
|
|
24
|
+
[id]: {
|
|
25
|
+
current: { editorView: view },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
writes.mockClear();
|
|
33
|
+
store.set(notebookAtom, initialNotebookState());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("derives a document from the stored code when the cell has no editor", () => {
|
|
37
|
+
setNotebook('mo.md(r"""# Title""")', null);
|
|
38
|
+
|
|
39
|
+
const [document] = getCellDocuments();
|
|
40
|
+
|
|
41
|
+
expect(document.view).toBeNull();
|
|
42
|
+
expect(document.state.doc.toString()).toBe("# Title");
|
|
43
|
+
expect(document.code).toBe('mo.md(r"""# Title""")');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("reads a mounted editor's document and Python code", () => {
|
|
47
|
+
const view = new EditorView({ doc: "x = 1" });
|
|
48
|
+
setNotebook("x = 1", view);
|
|
49
|
+
|
|
50
|
+
const [document] = getCellDocuments();
|
|
51
|
+
|
|
52
|
+
expect(document.view).toBe(view);
|
|
53
|
+
expect(document.state).toBe(view.state);
|
|
54
|
+
expect(document.code).toBe("x = 1");
|
|
55
|
+
view.destroy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("writes document changes back as the cell's Python code", () => {
|
|
59
|
+
setNotebook('mo.md(r"""# Title""")', null);
|
|
60
|
+
const [document] = getCellDocuments();
|
|
61
|
+
|
|
62
|
+
document.applyChanges({ from: 2, to: 7, insert: "Heading" }, "input");
|
|
63
|
+
|
|
64
|
+
expect(writes).toHaveBeenCalledExactlyOnceWith({
|
|
65
|
+
cellId: id,
|
|
66
|
+
code: expect.stringContaining("# Heading"),
|
|
67
|
+
});
|
|
68
|
+
expect(writes.mock.lastCall?.[0].code).toMatch(/^mo\.md\(/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("does not write code the cell already has", () => {
|
|
72
|
+
setNotebook("x = 1", null);
|
|
73
|
+
|
|
74
|
+
writeCellCode(id, "x = 1");
|
|
75
|
+
expect(writes).not.toHaveBeenCalled();
|
|
76
|
+
|
|
77
|
+
writeCellCode(id, "x = 2");
|
|
78
|
+
expect(writes).toHaveBeenCalledExactlyOnceWith({ cellId: id, code: "x = 2" });
|
|
79
|
+
});
|
|
@@ -2,142 +2,112 @@
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { createEditorMountScheduler } from "../editor-mount-scheduler";
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function setup() {
|
|
6
6
|
let pending: (() => void) | null = null;
|
|
7
|
-
const schedule = (cb: () => void) => {
|
|
8
|
-
pending = cb;
|
|
9
|
-
};
|
|
10
7
|
const flush = () => {
|
|
11
|
-
const
|
|
8
|
+
const task = pending;
|
|
12
9
|
pending = null;
|
|
13
|
-
|
|
10
|
+
task?.();
|
|
14
11
|
};
|
|
15
|
-
|
|
12
|
+
const scheduler = createEditorMountScheduler((task) => {
|
|
13
|
+
pending = task;
|
|
14
|
+
});
|
|
15
|
+
const built: string[] = [];
|
|
16
|
+
const register = (cellId: string) =>
|
|
17
|
+
scheduler.register(cellId, () => built.push(cellId));
|
|
18
|
+
return { scheduler, register, built, flush, hasPending: () => !!pending };
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
describe("createEditorMountScheduler", () => {
|
|
19
|
-
it("
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
flush();
|
|
26
|
-
expect(built).toEqual(["a"]);
|
|
27
|
-
expect(hasPending()).toBe(true);
|
|
28
|
-
flush();
|
|
29
|
-
expect(built).toEqual(["a", "b"]);
|
|
30
|
-
});
|
|
22
|
+
it("keeps registrations dormant until prioritized or promoted", () => {
|
|
23
|
+
const { scheduler, register, built, flush, hasPending } = setup();
|
|
24
|
+
register("a");
|
|
25
|
+
register("b");
|
|
26
|
+
register("c");
|
|
27
|
+
expect(hasPending()).toBe(false);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
const { schedule, flush, hasPending } = makeManualSchedule();
|
|
34
|
-
const built: string[] = [];
|
|
35
|
-
const s = createEditorMountScheduler(schedule);
|
|
36
|
-
s.request("a", () => built.push("a"));
|
|
29
|
+
scheduler.prioritize("b");
|
|
37
30
|
flush();
|
|
38
|
-
expect(built).toEqual(["
|
|
31
|
+
expect(built).toEqual(["b"]);
|
|
39
32
|
expect(hasPending()).toBe(false);
|
|
33
|
+
|
|
34
|
+
scheduler.promote("c");
|
|
35
|
+
scheduler.promote("c");
|
|
36
|
+
expect(built).toEqual(["b", "c"]);
|
|
40
37
|
});
|
|
41
38
|
|
|
42
|
-
it("
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
it("builds prioritized cells one per task, in prioritization order", () => {
|
|
40
|
+
const { scheduler, register, built, flush, hasPending } = setup();
|
|
41
|
+
register("a");
|
|
42
|
+
register("b");
|
|
43
|
+
register("c");
|
|
44
|
+
scheduler.prioritize("c");
|
|
45
|
+
scheduler.prioritize("a");
|
|
46
|
+
flush();
|
|
47
|
+
expect(built).toEqual(["c"]);
|
|
48
|
+
expect(hasPending()).toBe(true);
|
|
50
49
|
flush();
|
|
51
|
-
expect(built).toEqual(["
|
|
50
|
+
expect(built).toEqual(["c", "a"]);
|
|
51
|
+
expect(hasPending()).toBe(false);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it("
|
|
55
|
-
const {
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
it("does not build a cell that was deprioritized or disposed", () => {
|
|
55
|
+
const { scheduler, register, built, flush } = setup();
|
|
56
|
+
register("a");
|
|
57
|
+
const disposeB = register("b");
|
|
58
|
+
scheduler.prioritize("a");
|
|
59
|
+
scheduler.deprioritize("a");
|
|
60
|
+
scheduler.prioritize("b");
|
|
61
|
+
disposeB();
|
|
62
|
+
flush();
|
|
63
|
+
scheduler.promote("b");
|
|
61
64
|
expect(built).toEqual([]);
|
|
62
|
-
});
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
const { schedule, flush } = makeManualSchedule();
|
|
66
|
-
const built: string[] = [];
|
|
67
|
-
const s = createEditorMountScheduler(schedule);
|
|
68
|
-
s.request("a", () => built.push("a"));
|
|
69
|
-
s.request("b", () => built.push("b"));
|
|
70
|
-
s.request("c", () => built.push("c"));
|
|
71
|
-
s.prioritize("c");
|
|
72
|
-
flush();
|
|
66
|
+
scheduler.prioritize("a");
|
|
73
67
|
flush();
|
|
74
|
-
|
|
75
|
-
expect(built).toEqual(["c", "a", "b"]);
|
|
68
|
+
expect(built).toEqual(["a"]);
|
|
76
69
|
});
|
|
77
70
|
|
|
78
|
-
it("
|
|
79
|
-
const {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
s.request("a", () => built.push("a"));
|
|
83
|
-
s.request("b", () => built.push("b"));
|
|
84
|
-
s.request("c", () => built.push("c"));
|
|
85
|
-
s.request("d", () => built.push("d"));
|
|
86
|
-
s.prioritize("d");
|
|
87
|
-
s.prioritize("b");
|
|
88
|
-
flush();
|
|
89
|
-
flush();
|
|
90
|
-
flush();
|
|
91
|
-
flush();
|
|
92
|
-
expect(built).toEqual(["d", "b", "a", "c"]);
|
|
71
|
+
it("ignores prioritize for a cell that is not registered", () => {
|
|
72
|
+
const { scheduler, hasPending } = setup();
|
|
73
|
+
scheduler.prioritize("missing");
|
|
74
|
+
expect(hasPending()).toBe(false);
|
|
93
75
|
});
|
|
94
76
|
|
|
95
|
-
it("
|
|
96
|
-
const {
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
it("lets a stale or repeated disposal leave a replacement registration alone", () => {
|
|
78
|
+
const { scheduler, built, flush } = setup();
|
|
79
|
+
const stale = scheduler.register("a", () => built.push("stale"));
|
|
80
|
+
const current = scheduler.register("a", () => built.push("current"));
|
|
81
|
+
stale();
|
|
82
|
+
stale();
|
|
83
|
+
scheduler.prioritize("a");
|
|
84
|
+
flush();
|
|
85
|
+
current();
|
|
86
|
+
expect(built).toEqual(["current"]);
|
|
103
87
|
});
|
|
104
88
|
|
|
105
|
-
it("
|
|
106
|
-
const {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
flush();
|
|
89
|
+
it("allows a build to register new work for the same cell", () => {
|
|
90
|
+
const { scheduler, built, flush } = setup();
|
|
91
|
+
scheduler.register("a", () => {
|
|
92
|
+
built.push("first");
|
|
93
|
+
scheduler.register("a", () => built.push("second"));
|
|
94
|
+
});
|
|
95
|
+
scheduler.promote("a");
|
|
96
|
+
scheduler.promote("a");
|
|
114
97
|
flush();
|
|
115
|
-
expect(built).toEqual(["
|
|
98
|
+
expect(built).toEqual(["first", "second"]);
|
|
116
99
|
});
|
|
117
100
|
|
|
118
|
-
it("keeps draining
|
|
119
|
-
const {
|
|
120
|
-
|
|
121
|
-
const s = createEditorMountScheduler(schedule);
|
|
122
|
-
s.request("a", () => {
|
|
101
|
+
it("keeps draining prioritized cells after a build throws", () => {
|
|
102
|
+
const { scheduler, register, built, flush } = setup();
|
|
103
|
+
scheduler.register("a", () => {
|
|
123
104
|
throw new Error("boom");
|
|
124
105
|
});
|
|
125
|
-
|
|
106
|
+
register("b");
|
|
107
|
+
scheduler.prioritize("a");
|
|
108
|
+
scheduler.prioritize("b");
|
|
126
109
|
expect(() => flush()).toThrow("boom");
|
|
127
110
|
flush();
|
|
128
111
|
expect(built).toEqual(["b"]);
|
|
129
112
|
});
|
|
130
|
-
|
|
131
|
-
it("cancel removes a prioritized cell", () => {
|
|
132
|
-
const { schedule, flush } = makeManualSchedule();
|
|
133
|
-
const built: string[] = [];
|
|
134
|
-
const s = createEditorMountScheduler(schedule);
|
|
135
|
-
s.request("a", () => built.push("a"));
|
|
136
|
-
s.request("b", () => built.push("b"));
|
|
137
|
-
s.prioritize("b");
|
|
138
|
-
s.cancel("b");
|
|
139
|
-
flush();
|
|
140
|
-
flush();
|
|
141
|
-
expect(built).toEqual(["a"]);
|
|
142
|
-
});
|
|
143
113
|
});
|