@marimo-team/islands 0.26.1-dev104 → 0.26.1-dev108
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-BJBdnd0O.js → ConnectedDataExplorerComponent-DQaiOY7w.js} +15 -15
- package/dist/{ErrorBoundary-DLR6xE2E.js → ErrorBoundary-BW4TciqU.js} +19 -19
- package/dist/{abnfDiagram-VCTEODGH-Ba0MYVW8.js → abnfDiagram-VCTEODGH-Df80tEYq.js} +2 -2
- package/dist/{any-language-editor-BNe8do3C.js → any-language-editor-BW-gNmbk.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-7MqAehef.js → architectureDiagram-5GKGNRK7-DNNMvKkY.js} +1 -1
- package/dist/{assertNever-5vhHGKOK.js → assertNever-B9_7z-dW.js} +13 -13
- package/dist/{chat-ui-Bs3rgm2m.js → chat-ui-Be9X-W22.js} +49 -49
- package/dist/{check-DUIc04aK.js → check-BqF09bSG.js} +1 -1
- package/dist/{chunk-IMKFNOWR-CAWA0HGB.js → chunk-IMKFNOWR-pXqnQ_fj.js} +1 -1
- package/dist/{chunk-SHT3W25Y-BIwVQjG5.js → chunk-SHT3W25Y-BWrxB3I2.js} +1 -1
- package/dist/{chunk-SVP7TREG-Cux251TB.js → chunk-SVP7TREG-CPdQP8_U.js} +1 -1
- package/dist/{chunk-TICWLB2K-DJVQ6khO.js → chunk-TICWLB2K-C5MYCwBz.js} +1 -1
- package/dist/{circle-question-mark-evCnVIut.js → circle-question-mark-YmLYXyvS.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-Cwve77ev.js → classDiagram-ZZMXUADV-Ba0SRm01.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-BAeHKXmD.js → classDiagram-v2-VYDZK3BY-DSSzL_Dk.js} +2 -2
- package/dist/{code-visibility-BhWW3jkv.js → code-visibility-BKmktPMd.js} +18 -18
- package/dist/{common-i4mVHMGl.js → common-CSJAjJGa.js} +169 -169
- package/dist/{copy-icon-CmNLxT5_.js → copy-icon-zP4__HPI.js} +2 -2
- package/dist/{createReducer-BUQhgLOI.js → createReducer-CArOwUaJ.js} +16 -19
- package/dist/{cynefinDiagram-5FMLGOSQ-t4eEkPJh.js → cynefinDiagram-5FMLGOSQ-BOtNvA04.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-IuZuI28B.js → dagre-GXQ25YYZ-FpCEOTxX.js} +1 -1
- package/dist/{data-grid-overlay-editor-7durYJXa.js → data-grid-overlay-editor-DTibdR4H.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-D8R5Q_ok.js → diagram-S7CK7UJ4-Cm1HaBuu.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-BGuMPsr-.js → diagram-UQ7AKVKN-D1lA7Ggu.js} +1 -1
- package/dist/{diagram-VX7I27RA-BkTtpO8P.js → diagram-VX7I27RA-BX3e-Rue.js} +1 -1
- package/dist/{diagram-Z3DM3KII-C0__Mxfm.js → diagram-Z3DM3KII-Dgoj7bPf.js} +1 -1
- package/dist/{dialog-BvjfalZ9.js → dialog-DfKgafXJ.js} +30 -30
- package/dist/{dropdown-menu-D0DeN-aL.js → dropdown-menu-Dge_SmqE.js} +168 -168
- package/dist/{ebnfDiagram-PWID7BFC-CSESPZoz.js → ebnfDiagram-PWID7BFC-B0xWiXrz.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-DsDTtabH.js → erDiagram-RLTQ6QDP-Cm-GO31-.js} +1 -1
- package/dist/{error-banner-CXLjTW24.js → error-banner-CfYrJaIb.js} +91 -91
- package/dist/{error-entries-BcAyFIeh.js → error-entries-23Z_1oDM.js} +586 -595
- package/dist/{export-context-CkgZeARR.js → export-context-B1jdxzHF.js} +21 -21
- package/dist/{feedback-button-CeuzSBrq.js → feedback-button-CPu5SV3b.js} +72 -72
- package/dist/{flowDiagram-HODETNUW-qxDPYbfV.js → flowDiagram-HODETNUW-CH6xMlW_.js} +2 -2
- package/dist/{formats-CcQrzFo8.js → formats-Y52bg800.js} +1 -1
- package/dist/{glide-data-editor-BLGr2vQF.js → glide-data-editor-CC9_NDNi.js} +11 -11
- package/dist/{glide-utils-CD8BaFTm.js → glide-utils-BRcuSTCx.js} +2 -2
- package/dist/{globals-DorvG5dC.js → globals-BFlYTNoR.js} +3 -3
- package/dist/{html-to-image-BmLTjaGw.js → html-to-image-Cw7o1IbE.js} +4300 -4296
- package/dist/{infoDiagram-27XIBGKW-B5hq8RM_.js → infoDiagram-27XIBGKW-DbUO63CX.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DkHc_9ET.js → ishikawaDiagram-5VMMS53U-CfQrrELH.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-CqkTFXmU.js → kanban-definition-UXKFOSKX-C5SJcu1W.js} +1 -1
- package/dist/{loader-CGrYn73j.js → loader-C9-qRO3m.js} +2 -2
- package/dist/main.js +6698 -6604
- package/dist/{mermaid-pmVHDUQA.js → mermaid-C2alqcd8.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-D6cNa__z.js → mindmap-definition-YA3MSWOX-ByVHE0Ax.js} +1 -1
- package/dist/{number-overlay-editor-DQAdvZrn.js → number-overlay-editor-qDcRKPE0.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-CmWJX_s1.js → pegDiagram-XKGWAZYB-DF5FBKZi.js} +2 -2
- package/dist/{pencil-CxMgOe04.js → pencil-D7jyZPnP.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-CAQAxHah.js → pieDiagram-E7YTZNPT-B5n9nBQN.js} +1 -1
- package/dist/{process-output-CcNpl5Qu.js → process-output-DdBM0lmd.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-jlSsiQg3.js → railroadDiagram-O6MQD6OU-r5t7OYNE.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-DkDjfPhn.js → requirementDiagram-BXWQKSXE-D4QtEyZQ.js} +1 -1
- package/dist/{reveal-component-B6xeeht1.js → reveal-component-BE1xhtNc.js} +1008 -1008
- package/dist/{select-CEnB18uc.js → select-Buk3aXi1.js} +341 -341
- package/dist/{sequenceDiagram-WJ2MYXX4-DLywsGCW.js → sequenceDiagram-WJ2MYXX4-CK3Atn-z.js} +1 -1
- package/dist/{spec-Dz-Avv1m.js → spec-BEp9O9dy.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-DUmlKwYU.js → stateDiagram-D77RDMKH-C1SxRI8V.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-D646KiXs.js → stateDiagram-v2-MP3YSRHH-DK5X6bsr.js} +2 -2
- package/dist/{static-state-iw0PrHK4.js → static-state-D-aT9dOr.js} +9 -9
- package/dist/{swimlanes-42K2YHIH-L7B1GphF.js → swimlanes-42K2YHIH-DdH5TZdu.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-DEu2wxtC.js → swimlanesDiagram-VR7AAH4N-CWBIvzgR.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-DDPyx1yG.js → timeline-definition-24CTP7MA-DE7-o2zU.js} +1 -1
- package/dist/{toast-BTjH6fIf.js → toast-b3k4YxaT.js} +54 -54
- package/dist/{tooltip-DyLdBIM4.js → tooltip-D-9pDheN.js} +62 -62
- package/dist/{use-restore-focus-DJ_-uSn_.js → use-restore-focus-CCfk-ey2.js} +1 -1
- package/dist/{useDateFormatter-HpKD0jEC.js → useDateFormatter-DH0uFwfL.js} +2 -2
- package/dist/{useDeepCompareMemoize-CHx-NxMl.js → useDeepCompareMemoize-Dn-ZJVTd.js} +1 -1
- package/dist/{useLifecycle-tPpAt-OE.js → useLifecycle-yjK7JsRL.js} +1 -1
- package/dist/{vega-component-BzNDFvQf.js → vega-component-BIq0qzhQ.js} +8 -8
- package/dist/{vennDiagram-4TSXK5OY-CRwWeb7g.js → vennDiagram-4TSXK5OY-D7yfNz0d.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-DVlG9eoq.js → wardleyDiagram-VM6X3IG4-m5Jcz26Z.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-CM32AISp.js → xychartDiagram-S5SC5T6Z-CA3zV3RW.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/intersection-observer.ts +13 -12
- package/src/components/editor/Output.tsx +1 -1
- package/src/components/editor/__tests__/cell-renders.test.tsx +17 -1
- package/src/components/editor/cell/__tests__/cell-actions.test.tsx +74 -0
- package/src/components/editor/cell/cell-action-body.tsx +28 -0
- package/src/components/editor/cell/cell-actions.tsx +60 -72
- package/src/components/editor/cell/cell-context-menu.tsx +36 -62
- package/src/components/editor/chrome/panels/outline/__tests__/outline-keyboard.test.tsx +517 -68
- package/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.ts +17 -5
- package/src/components/editor/chrome/panels/outline/floating-outline.tsx +29 -59
- package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +333 -133
- package/src/components/editor/chrome/panels/outline-panel.tsx +5 -19
- package/src/components/editor/navigation/navigation.ts +1 -1
- package/src/components/editor/notebook-cell.tsx +263 -267
- package/src/core/cells/__tests__/layout.test.ts +1 -1
- package/src/core/cells/__tests__/notebook-outline.test.ts +31 -3
- package/src/core/cells/__tests__/use-cell-actions.test.tsx +48 -0
- package/src/core/cells/actions.ts +68 -89
- package/src/core/cells/cells.ts +23 -14
- package/src/core/cells/outline.ts +8 -8
- package/src/core/codemirror/language/extension.ts +6 -3
- package/src/core/codemirror/language/panel/panel.test.tsx +144 -0
- package/src/core/codemirror/language/panel/panel.tsx +9 -6
- package/src/core/codemirror/react-dom/createPanel.tsx +15 -15
- package/src/core/dom/__tests__/outline.test.ts +29 -170
- package/src/core/dom/outline.ts +21 -61
- package/src/core/executions/atoms.ts +12 -4
- package/src/core/islands/components/output-wrapper.tsx +7 -2
- package/src/plugins/layout/OutlinePlugin.tsx +5 -17
- package/src/utils/__tests__/createReducer.test.tsx +4 -3
- package/src/utils/createReducer.ts +19 -12
|
@@ -1,84 +1,533 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { createStore, Provider, useAtomValue } from "jotai";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
7
|
+
import { mockIntersectionObservers } from "@/__mocks__/intersection-observer";
|
|
8
|
+
import { MockNotebook } from "@/__mocks__/notebook";
|
|
9
|
+
import { cellId } from "@/__tests__/branded";
|
|
10
|
+
import { OutputArea } from "@/components/editor/Output";
|
|
11
|
+
import { cellIdsAtom, notebookAtom, notebookOutline } from "@/core/cells/cells";
|
|
12
|
+
import type { CellId } from "@/core/cells/ids";
|
|
13
|
+
import { cellOutlineAtom, cellOutputAtom } from "@/core/executions";
|
|
14
|
+
import { useCellOutput } from "@/core/executions/hooks";
|
|
15
|
+
import OutlinePanel from "../../outline-panel";
|
|
16
|
+
import { FloatingOutline } from "../floating-outline";
|
|
8
17
|
|
|
9
|
-
vi.mock("
|
|
18
|
+
vi.mock("@/core/mode", async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<typeof import("@/core/mode")>()),
|
|
20
|
+
getInitialAppMode: () => "read",
|
|
21
|
+
}));
|
|
10
22
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
{ name: "Second", html: "<em>Second</em>", level: 2, by: { id: "second" } },
|
|
14
|
-
];
|
|
23
|
+
const first = cellId("first");
|
|
24
|
+
const second = cellId("second");
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
activeHeaderId: undefined,
|
|
31
|
-
activeOccurrences: undefined,
|
|
32
|
-
};
|
|
33
|
-
const { rerender } = render(<Component {...props} items={initial} />);
|
|
34
|
-
const focused = screen.getByRole(role, { name: "Repeated second" });
|
|
35
|
-
focused.focus();
|
|
36
|
-
|
|
37
|
-
for (const by of [{ id: "inserted" }, { path: "second" }]) {
|
|
38
|
-
const inserted: OutlineItem = { name: "Inserted", level: 1, by };
|
|
39
|
-
rerender(<Component {...props} items={[inserted, ...initial]} />);
|
|
40
|
-
expect(screen.getByRole(role, { name: "Repeated second" })).toBe(
|
|
41
|
-
focused,
|
|
42
|
-
);
|
|
43
|
-
expect(focused).toHaveFocus();
|
|
44
|
-
}
|
|
26
|
+
function Output({ id }: { id: CellId }) {
|
|
27
|
+
const output = useCellOutput(id);
|
|
28
|
+
return (
|
|
29
|
+
<div data-testid={id}>
|
|
30
|
+
<OutputArea
|
|
31
|
+
cellId={id}
|
|
32
|
+
output={output}
|
|
33
|
+
stale={false}
|
|
34
|
+
loading={false}
|
|
35
|
+
allowExpand={false}
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
function Notebook({
|
|
42
|
+
folded,
|
|
43
|
+
showPanel,
|
|
44
|
+
}: {
|
|
45
|
+
folded?: CellId;
|
|
46
|
+
showPanel?: boolean;
|
|
47
|
+
}) {
|
|
48
|
+
const ids = useAtomValue(cellIdsAtom);
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<FloatingOutline />
|
|
52
|
+
{showPanel && <OutlinePanel />}
|
|
53
|
+
{ids
|
|
54
|
+
.filter((id) => id !== folded)
|
|
55
|
+
.map((id) => (
|
|
56
|
+
<Output key={id} id={id} />
|
|
57
|
+
))}
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function mountOutline(
|
|
63
|
+
firstHtml: string,
|
|
64
|
+
secondHtml = "",
|
|
65
|
+
options: { showPanel?: boolean; folded?: CellId } = {},
|
|
66
|
+
) {
|
|
67
|
+
const store = createStore();
|
|
68
|
+
store.set(
|
|
69
|
+
notebookAtom,
|
|
70
|
+
MockNotebook.notebookState({ cellData: { [first]: {}, [second]: {} } }),
|
|
54
71
|
);
|
|
72
|
+
const executions = (a: string, b: string, elapsedMs = 1500) => {
|
|
73
|
+
const execution = MockExecutions.took(first, elapsedMs);
|
|
74
|
+
return [
|
|
75
|
+
[
|
|
76
|
+
execution,
|
|
77
|
+
MockExecutions.output(execution, {
|
|
78
|
+
mimetype: "text/markdown",
|
|
79
|
+
data: a,
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
MockExecutions.shown(second, { mimetype: "text/html", data: b }),
|
|
83
|
+
];
|
|
84
|
+
};
|
|
85
|
+
const replica = MockExecutions.seed(store, executions(firstHtml, secondHtml));
|
|
86
|
+
|
|
87
|
+
const notebook = (props: typeof options) => (
|
|
88
|
+
<Provider store={store}>
|
|
89
|
+
<Notebook {...props} />
|
|
90
|
+
</Provider>
|
|
91
|
+
);
|
|
92
|
+
const view = render(notebook(options));
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
store,
|
|
96
|
+
unmount: view.unmount,
|
|
97
|
+
async rerender(props: typeof options) {
|
|
98
|
+
await act(() => view.rerender(notebook(props)));
|
|
99
|
+
},
|
|
100
|
+
async show(a: string, b = secondHtml, elapsedMs = 1500) {
|
|
101
|
+
const next = MockExecutions.inputs(executions(a, b, elapsedMs));
|
|
102
|
+
await act(() => {
|
|
103
|
+
store.set(replica.executionsAtom, next.executions);
|
|
104
|
+
store.set(replica.resultsAtom, next.results);
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
async moveSecondBeforeFirst() {
|
|
108
|
+
await act(() => {
|
|
109
|
+
store.set(notebookAtom, (state) => ({
|
|
110
|
+
...state,
|
|
111
|
+
cellIds: [second, first],
|
|
112
|
+
}));
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function trackPageSearches() {
|
|
119
|
+
const cssAll = vi.spyOn(document, "querySelectorAll");
|
|
120
|
+
const css = vi.spyOn(document, "querySelector");
|
|
121
|
+
const id = vi.spyOn(document, "getElementById");
|
|
122
|
+
const xpath = vi.spyOn(document, "evaluate");
|
|
123
|
+
|
|
124
|
+
return (expected: number) => {
|
|
125
|
+
expect(cssAll.mock.calls.length + css.mock.calls.length).toBe(expected);
|
|
126
|
+
expect(id).not.toHaveBeenCalled();
|
|
127
|
+
expect(xpath).not.toHaveBeenCalled();
|
|
128
|
+
cssAll.mockClear();
|
|
129
|
+
css.mockClear();
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
afterEach(() => {
|
|
134
|
+
vi.restoreAllMocks();
|
|
135
|
+
vi.unstubAllGlobals();
|
|
136
|
+
vi.useRealTimers();
|
|
137
|
+
});
|
|
55
138
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
139
|
+
describe("floating outline", () => {
|
|
140
|
+
it("keeps duplicate targets with their output when a cell folds", async () => {
|
|
141
|
+
const observers = mockIntersectionObservers();
|
|
142
|
+
vi.useFakeTimers();
|
|
143
|
+
const chrome = document.createElement("section");
|
|
144
|
+
chrome.innerHTML = '<h2>Results</h2><h2 id="results">Chrome</h2>';
|
|
145
|
+
document.body.append(chrome);
|
|
146
|
+
try {
|
|
147
|
+
const html = '<h2>Results</h2><h2 id="results">With ID</h2>';
|
|
148
|
+
const expectSearches = trackPageSearches();
|
|
149
|
+
const notebook = mountOutline(html, html, { folded: first });
|
|
150
|
+
expectSearches(1);
|
|
151
|
+
const [textTarget, idTarget] = screen
|
|
152
|
+
.getByTestId(second)
|
|
153
|
+
.querySelectorAll("h2");
|
|
154
|
+
expect(observers[0].observe.mock.calls.flat()).toEqual([
|
|
155
|
+
textTarget,
|
|
156
|
+
idTarget,
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const [, , textButton, idButton] = screen.getAllByRole("button");
|
|
160
|
+
textTarget.scrollIntoView = vi.fn();
|
|
161
|
+
idTarget.scrollIntoView = vi.fn();
|
|
162
|
+
fireEvent.click(textButton);
|
|
163
|
+
fireEvent.click(idButton);
|
|
164
|
+
expect(textTarget.scrollIntoView).toHaveBeenCalledOnce();
|
|
165
|
+
expect(idTarget.scrollIntoView).toHaveBeenCalledOnce();
|
|
166
|
+
act(() => observers[0].emit(idTarget, true));
|
|
167
|
+
expect(idButton).toHaveClass("bg-foreground");
|
|
168
|
+
expect(screen.getAllByRole("button")[1]).not.toHaveClass("bg-foreground");
|
|
169
|
+
expectSearches(0);
|
|
170
|
+
|
|
171
|
+
await notebook.rerender({});
|
|
172
|
+
expectSearches(1);
|
|
173
|
+
const firstTargets = screen.getByTestId(first).querySelectorAll("h2");
|
|
174
|
+
expect(observers[1].observe.mock.calls.flat()).toEqual([
|
|
175
|
+
...firstTargets,
|
|
176
|
+
textTarget,
|
|
177
|
+
idTarget,
|
|
178
|
+
]);
|
|
179
|
+
expect(idButton).toHaveClass("bg-foreground");
|
|
180
|
+
} finally {
|
|
181
|
+
chrome.remove();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("ignores rich outline labels that repeat a heading ID inside an output", async () => {
|
|
186
|
+
const observers = mockIntersectionObservers();
|
|
187
|
+
const expectSearches = trackPageSearches();
|
|
188
|
+
mountOutline(
|
|
189
|
+
'<h1 id="chapter-1"><em id="chapter-1">Heading</em></h1>',
|
|
190
|
+
"",
|
|
191
|
+
{
|
|
192
|
+
showPanel: true,
|
|
193
|
+
},
|
|
63
194
|
);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
195
|
+
expectSearches(1);
|
|
196
|
+
const heading = screen.getByRole("heading", { name: "Heading" });
|
|
197
|
+
const link = screen.getByRole("link", { name: "Heading" });
|
|
198
|
+
expect(link.querySelector("em")).toHaveAttribute("id", "chapter-1");
|
|
199
|
+
const list = link.parentElement!;
|
|
200
|
+
// mo.outline() can place the same rich labels inside the source output.
|
|
201
|
+
const embeddedList = list.cloneNode(true);
|
|
202
|
+
await act(() => {
|
|
203
|
+
heading.before(embeddedList);
|
|
204
|
+
});
|
|
205
|
+
expectSearches(0);
|
|
206
|
+
const replacement = document.createElement("h1");
|
|
207
|
+
replacement.id = heading.id;
|
|
208
|
+
replacement.innerHTML = heading.innerHTML;
|
|
209
|
+
await act(() => {
|
|
210
|
+
heading.replaceWith(replacement);
|
|
69
211
|
});
|
|
212
|
+
expectSearches(1);
|
|
213
|
+
expect(observers.at(-1)?.observe.mock.calls.flat()).toEqual([replacement]);
|
|
214
|
+
replacement.scrollIntoView = vi.fn();
|
|
215
|
+
fireEvent.click(link);
|
|
216
|
+
expect(replacement.scrollIntoView).toHaveBeenCalledOnce();
|
|
70
217
|
});
|
|
71
218
|
|
|
72
|
-
it("
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
219
|
+
it("shares scans and active tracking with the panel until the last view unmounts", async () => {
|
|
220
|
+
const observers = mockIntersectionObservers();
|
|
221
|
+
const expectSearches = trackPageSearches();
|
|
222
|
+
const notebook = mountOutline("<h1>First</h1><h2>Second</h2>", "", {
|
|
223
|
+
showPanel: true,
|
|
224
|
+
});
|
|
225
|
+
expectSearches(1);
|
|
226
|
+
expect(observers).toHaveLength(1);
|
|
227
|
+
|
|
228
|
+
await notebook.show("<h1>First</h1><h2>Updated</h2>");
|
|
229
|
+
expectSearches(1);
|
|
230
|
+
expect(observers).toHaveLength(2);
|
|
231
|
+
const updated = screen.getByText("Updated", { selector: "h2" });
|
|
232
|
+
act(() => observers[1].emit(updated, true));
|
|
233
|
+
expect(
|
|
234
|
+
screen
|
|
235
|
+
.getAllByRole("link", { name: "Updated" })
|
|
236
|
+
.map((link) => link.classList.contains("text-accent-foreground")),
|
|
237
|
+
).toEqual([true, true]);
|
|
238
|
+
expect(screen.getByRole("button", { name: "Updated" })).toHaveClass(
|
|
239
|
+
"bg-foreground",
|
|
79
240
|
);
|
|
241
|
+
|
|
242
|
+
await notebook.rerender({});
|
|
243
|
+
expectSearches(0);
|
|
244
|
+
expect(observers[1].disconnect).not.toHaveBeenCalled();
|
|
245
|
+
notebook.unmount();
|
|
246
|
+
expect(observers[1].disconnect).toHaveBeenCalledOnce();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("rebinds targets on in-place text and ID changes", async () => {
|
|
250
|
+
const observers = mockIntersectionObservers();
|
|
251
|
+
const expectSearches = trackPageSearches();
|
|
252
|
+
mountOutline('<h2><em>Results</em></h2><h2 id="study">Study</h2>');
|
|
253
|
+
expectSearches(1);
|
|
254
|
+
const [textTarget, idTarget] = screen
|
|
255
|
+
.getByTestId(first)
|
|
256
|
+
.querySelectorAll("h2");
|
|
257
|
+
const text = textTarget.querySelector("em")?.firstChild;
|
|
258
|
+
expect(text).toBeInstanceOf(Text);
|
|
259
|
+
|
|
260
|
+
await act(() => {
|
|
261
|
+
text!.nodeValue = "Another title";
|
|
262
|
+
idTarget.id = "another-id";
|
|
263
|
+
});
|
|
264
|
+
expectSearches(1);
|
|
265
|
+
expect(observers[0].disconnect).toHaveBeenCalledOnce();
|
|
266
|
+
expect(observers).toHaveLength(1);
|
|
267
|
+
|
|
268
|
+
await act(() => {
|
|
269
|
+
text!.nodeValue = "Results";
|
|
270
|
+
idTarget.id = "study";
|
|
271
|
+
});
|
|
272
|
+
expectSearches(1);
|
|
273
|
+
expect(observers[1].observe.mock.calls.flat()).toEqual([
|
|
274
|
+
textTarget,
|
|
275
|
+
idTarget,
|
|
276
|
+
]);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("reuses heading values and targets after a timestamp-only rerun", async () => {
|
|
280
|
+
const observers = mockIntersectionObservers();
|
|
281
|
+
const html = "<h1>First</h1><h2>Second</h2>";
|
|
282
|
+
const expectSearches = trackPageSearches();
|
|
283
|
+
const { store, show } = mountOutline(html);
|
|
284
|
+
expectSearches(1);
|
|
285
|
+
|
|
286
|
+
const initialOutput = store.get(cellOutputAtom(first));
|
|
287
|
+
const initialCell = store.get(cellOutlineAtom(first));
|
|
288
|
+
const initialNotebook = store.get(notebookOutline);
|
|
289
|
+
const parseHtml = vi.spyOn(DOMParser.prototype, "parseFromString");
|
|
290
|
+
const heading = screen.getByText("Second", { selector: "h2" });
|
|
80
291
|
const button = screen.getByRole("button", { name: "Second" });
|
|
81
|
-
|
|
82
|
-
|
|
292
|
+
const [observer] = observers;
|
|
293
|
+
|
|
294
|
+
await show(html, "", 3000);
|
|
295
|
+
|
|
296
|
+
expect(store.get(cellOutputAtom(first))).toEqual({
|
|
297
|
+
...initialOutput,
|
|
298
|
+
timestamp: Date.parse(MockExecutions.T0) / 1000 + 3,
|
|
299
|
+
});
|
|
300
|
+
expect(store.get(cellOutlineAtom(first))).toBe(initialCell);
|
|
301
|
+
expect(store.get(notebookOutline)).toBe(initialNotebook);
|
|
302
|
+
expect(parseHtml).not.toHaveBeenCalled();
|
|
303
|
+
expect(screen.getByText("Second", { selector: "h2" })).toBe(heading);
|
|
304
|
+
expect(observers).toEqual([observer]);
|
|
305
|
+
expectSearches(0);
|
|
306
|
+
|
|
307
|
+
fireEvent.mouseEnter(button);
|
|
308
|
+
act(() => button.focus());
|
|
309
|
+
await act(() => observer.emitBatch([[heading, true]]));
|
|
310
|
+
expect(button).toHaveClass("bg-foreground");
|
|
311
|
+
expectSearches(0);
|
|
312
|
+
|
|
313
|
+
await show(`${html}<p>New paragraph</p>`);
|
|
314
|
+
expect(screen.getByText("New paragraph")).toBeInTheDocument();
|
|
315
|
+
expect(store.get(cellOutlineAtom(first))).toBe(initialCell);
|
|
316
|
+
expect(store.get(notebookOutline)).toBe(initialNotebook);
|
|
317
|
+
expect(observers).toEqual([observer]);
|
|
318
|
+
expectSearches(0);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("updates a rich label without resolving its unchanged ID target", async () => {
|
|
322
|
+
const observers = mockIntersectionObservers();
|
|
323
|
+
const html = '<h1>First</h1><h2 id="study"><em>Before</em></h2>';
|
|
324
|
+
const expectSearches = trackPageSearches();
|
|
325
|
+
const { show } = mountOutline(html);
|
|
326
|
+
expectSearches(1);
|
|
327
|
+
const target = screen.getByText("Before", {
|
|
328
|
+
selector: "h2 em",
|
|
329
|
+
}).parentElement!;
|
|
330
|
+
act(() => observers[0].emit(target, true));
|
|
331
|
+
|
|
332
|
+
await show(html.replace("Before", "After"));
|
|
333
|
+
|
|
334
|
+
expect(screen.getByText("After", { selector: "h2 em" }).parentElement).toBe(
|
|
335
|
+
target,
|
|
336
|
+
);
|
|
337
|
+
expect(screen.getByRole("button", { name: "After" })).toHaveClass(
|
|
338
|
+
"bg-foreground",
|
|
339
|
+
);
|
|
340
|
+
expect(observers).toHaveLength(1);
|
|
341
|
+
expectSearches(0);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("refreshes navigation and active tracking after an identical subtree replacement", async () => {
|
|
345
|
+
vi.useFakeTimers();
|
|
346
|
+
const observers = mockIntersectionObservers();
|
|
347
|
+
const expectSearches = trackPageSearches();
|
|
348
|
+
const { store, unmount } = mountOutline(
|
|
349
|
+
"<h2><em>Results</em></h2>",
|
|
350
|
+
"<h2><em>Results</em></h2>",
|
|
351
|
+
);
|
|
352
|
+
expectSearches(1);
|
|
353
|
+
|
|
354
|
+
const initial = store.get(notebookOutline);
|
|
355
|
+
const [firstHeading, oldHeading] = screen
|
|
356
|
+
.getAllByText("Results", {
|
|
357
|
+
selector: "h2 em",
|
|
358
|
+
})
|
|
359
|
+
.map((label) => label.parentElement!);
|
|
360
|
+
const oldScroll = vi.fn();
|
|
361
|
+
oldHeading.scrollIntoView = oldScroll;
|
|
362
|
+
const replacement = document.createElement("h2");
|
|
363
|
+
replacement.innerHTML = oldHeading.innerHTML;
|
|
364
|
+
const newScroll = vi.fn();
|
|
365
|
+
replacement.scrollIntoView = newScroll;
|
|
366
|
+
const wrapper = document.createElement("section");
|
|
367
|
+
wrapper.append(replacement);
|
|
368
|
+
const [oldObserver] = observers;
|
|
369
|
+
const [firstButton, secondButton] = screen.getAllByRole("button");
|
|
370
|
+
fireEvent.mouseEnter(secondButton);
|
|
371
|
+
const [, secondLink] = screen.getAllByRole("link");
|
|
372
|
+
act(() => secondLink.focus());
|
|
373
|
+
act(() => oldObserver.emitBatch([[firstHeading, true]]));
|
|
374
|
+
expect(firstButton).toHaveClass("bg-foreground");
|
|
375
|
+
expectSearches(0);
|
|
376
|
+
|
|
377
|
+
await act(async () => oldHeading.replaceWith(wrapper));
|
|
378
|
+
|
|
379
|
+
expect(store.get(notebookOutline)).toBe(initial);
|
|
380
|
+
expectSearches(1);
|
|
381
|
+
const [, newObserver] = observers;
|
|
382
|
+
expect(oldObserver.disconnect).toHaveBeenCalledOnce();
|
|
383
|
+
expect(newObserver.observe.mock.calls.flat()).toEqual([
|
|
384
|
+
firstHeading,
|
|
385
|
+
replacement,
|
|
386
|
+
]);
|
|
387
|
+
expect(secondLink).toHaveFocus();
|
|
388
|
+
|
|
389
|
+
fireEvent.click(secondButton);
|
|
390
|
+
fireEvent.click(secondLink);
|
|
391
|
+
fireEvent.keyDown(secondLink, { key: "Enter" });
|
|
392
|
+
expect(newScroll).toHaveBeenCalledTimes(3);
|
|
393
|
+
expect(oldScroll).not.toHaveBeenCalled();
|
|
394
|
+
|
|
395
|
+
act(() => newObserver.emitBatch([[replacement, true]]));
|
|
396
|
+
act(() => oldObserver.emitBatch([[firstHeading, true]]));
|
|
397
|
+
expect(secondButton).toHaveClass("bg-foreground");
|
|
398
|
+
expect(secondLink).toHaveClass("text-accent-foreground");
|
|
399
|
+
expect(firstButton).not.toHaveClass("bg-foreground");
|
|
400
|
+
expectSearches(0);
|
|
401
|
+
|
|
402
|
+
unmount();
|
|
403
|
+
expect(newObserver.disconnect).toHaveBeenCalledOnce();
|
|
404
|
+
await act(() => replacement.remove());
|
|
405
|
+
expectSearches(0);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it("uses the same exact, ordered targets for navigation and active tracking", () => {
|
|
409
|
+
vi.useFakeTimers();
|
|
410
|
+
const observers = mockIntersectionObservers();
|
|
411
|
+
const expectSearches = trackPageSearches();
|
|
412
|
+
mountOutline(
|
|
413
|
+
`
|
|
414
|
+
<marimo-tabs><h2>Results</h2><h2 id="1:"shared">Hidden</h2></marimo-tabs>
|
|
415
|
+
<h2>Early Results</h2>
|
|
416
|
+
<h2>Results</h2>
|
|
417
|
+
<h3>Results</h3>
|
|
418
|
+
<h2><em>Results</em></h2>
|
|
419
|
+
<h3>The painter's <em>"Study"</em></h3>
|
|
420
|
+
<h2 id="1:"shared">First ID</h2>
|
|
421
|
+
<h3 id="1:"shared">Second ID</h3>
|
|
422
|
+
`,
|
|
423
|
+
);
|
|
424
|
+
expectSearches(1);
|
|
425
|
+
|
|
426
|
+
const names = [
|
|
427
|
+
"Early Results",
|
|
428
|
+
"Results",
|
|
429
|
+
"Results",
|
|
430
|
+
"Results",
|
|
431
|
+
`The painter's "Study"`,
|
|
432
|
+
"First ID",
|
|
433
|
+
"Second ID",
|
|
434
|
+
];
|
|
435
|
+
const [, , ...targets] = screen
|
|
436
|
+
.getByTestId(first)
|
|
437
|
+
.querySelectorAll("h2, h3");
|
|
438
|
+
const buttons = screen.getAllByRole("button");
|
|
439
|
+
fireEvent.mouseEnter(buttons[0]);
|
|
440
|
+
fireEvent.focus(buttons[0]);
|
|
441
|
+
const links = screen.getAllByRole("link");
|
|
442
|
+
const [observer] = observers;
|
|
443
|
+
|
|
444
|
+
expect(buttons.map((button) => button.getAttribute("aria-label"))).toEqual(
|
|
445
|
+
names,
|
|
446
|
+
);
|
|
447
|
+
expect(links.map((link) => link.textContent?.trim())).toEqual(names);
|
|
448
|
+
expect(links[3].querySelector("em")).toHaveTextContent("Results");
|
|
449
|
+
expect(observer?.observe.mock.calls.flat()).toEqual(targets);
|
|
450
|
+
|
|
451
|
+
const scrolls = targets.map((target) => {
|
|
452
|
+
const scroll = vi.fn();
|
|
453
|
+
target.scrollIntoView = scroll;
|
|
454
|
+
return scroll;
|
|
455
|
+
});
|
|
456
|
+
let previous: Element | undefined;
|
|
457
|
+
for (const [index, target] of targets.entries()) {
|
|
458
|
+
const scroll = scrolls[index];
|
|
459
|
+
fireEvent.click(buttons[index]);
|
|
460
|
+
fireEvent.click(links[index]);
|
|
461
|
+
fireEvent.keyDown(links[index], { key: "Enter" });
|
|
462
|
+
expect(scroll).toHaveBeenCalledTimes(3);
|
|
463
|
+
expect(scroll).toHaveBeenLastCalledWith({
|
|
464
|
+
behavior: "smooth",
|
|
465
|
+
block: "start",
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
const changes: [Element, boolean][] = [[target, true]];
|
|
469
|
+
if (previous) {
|
|
470
|
+
changes.push([previous, false]);
|
|
471
|
+
}
|
|
472
|
+
act(() => observer?.emitBatch(changes));
|
|
473
|
+
expect(
|
|
474
|
+
links.filter((link) =>
|
|
475
|
+
link.classList.contains("text-accent-foreground"),
|
|
476
|
+
),
|
|
477
|
+
).toEqual([links[index]]);
|
|
478
|
+
expect(
|
|
479
|
+
buttons.filter((button) => button.classList.contains("bg-foreground")),
|
|
480
|
+
).toEqual([buttons[index]]);
|
|
481
|
+
previous = target;
|
|
482
|
+
}
|
|
483
|
+
expect(scrolls.map((scroll) => scroll.mock.calls.length)).toEqual(
|
|
484
|
+
names.map(() => 3),
|
|
485
|
+
);
|
|
486
|
+
expectSearches(0);
|
|
83
487
|
});
|
|
488
|
+
|
|
489
|
+
it.each([
|
|
490
|
+
{ count: 0, role: "link" },
|
|
491
|
+
{ count: 100, role: "button" },
|
|
492
|
+
])(
|
|
493
|
+
"resolves added, renamed, reordered, and removed headings in one pass with $count extra headings",
|
|
494
|
+
async ({ count, role }) => {
|
|
495
|
+
const observers = mockIntersectionObservers();
|
|
496
|
+
const extra = Array.from({ length: count }, (_, i) => `Extra ${i}`);
|
|
497
|
+
const extraHtml = extra.map((name) => `<h4>${name}</h4>`).join("");
|
|
498
|
+
const shared =
|
|
499
|
+
'<h2 id="shared">First ID</h2><h2 id="shared">Second ID</h2>';
|
|
500
|
+
const expectSearches = trackPageSearches();
|
|
501
|
+
const notebook = mountOutline(`<h1>Initial</h1>${extraHtml}`, shared);
|
|
502
|
+
const expectOrder = (expected: string[]) => {
|
|
503
|
+
const names = screen
|
|
504
|
+
.getAllByRole("button")
|
|
505
|
+
.map((button) => button.getAttribute("aria-label"));
|
|
506
|
+
const targets = observers.at(-1)?.observe.mock.calls.flat();
|
|
507
|
+
expect(names).toEqual(expected);
|
|
508
|
+
expect(targets?.map((target) => target.textContent)).toEqual(expected);
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
expectSearches(1);
|
|
512
|
+
expectOrder(["Initial", ...extra, "First ID", "Second ID"]);
|
|
513
|
+
fireEvent.mouseEnter(screen.getByRole("button", { name: "Second ID" }));
|
|
514
|
+
const focused = screen.getByRole(role, { name: "Second ID" });
|
|
515
|
+
act(() => focused.focus());
|
|
516
|
+
|
|
517
|
+
await notebook.show(`<h1>Renamed</h1><h2>Added</h2>${extraHtml}`);
|
|
518
|
+
expectSearches(1);
|
|
519
|
+
expectOrder(["Renamed", "Added", ...extra, "First ID", "Second ID"]);
|
|
520
|
+
expect(focused).toHaveFocus();
|
|
521
|
+
|
|
522
|
+
await notebook.moveSecondBeforeFirst();
|
|
523
|
+
expectSearches(1);
|
|
524
|
+
expectOrder(["First ID", "Second ID", "Renamed", "Added", ...extra]);
|
|
525
|
+
|
|
526
|
+
await notebook.show(`<h1>Renamed</h1>${extraHtml}`);
|
|
527
|
+
expectSearches(1);
|
|
528
|
+
expectOrder(["First ID", "Second ID", "Renamed", ...extra]);
|
|
529
|
+
expect(screen.getByRole(role, { name: "Second ID" })).toBe(focused);
|
|
530
|
+
expect(focused).toHaveFocus();
|
|
531
|
+
},
|
|
532
|
+
);
|
|
84
533
|
});
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { cellId } from "@/__tests__/branded";
|
|
4
|
+
import { CellOutputId } from "@/core/cells/ids";
|
|
3
5
|
import { parseOutline } from "@/core/dom/outline";
|
|
4
|
-
import {
|
|
6
|
+
import { outlineLocators, resolveOutlineTargets } from "../useActiveOutline";
|
|
5
7
|
|
|
6
|
-
describe("
|
|
8
|
+
describe("resolveOutlineTargets", () => {
|
|
7
9
|
it.each([
|
|
8
10
|
"Design from the portfolio",
|
|
9
11
|
'Decorative Art of "Spanish California"',
|
|
10
12
|
`The painter's "Study"`,
|
|
11
13
|
])("finds an id-less heading named %s", (name) => {
|
|
12
14
|
const html = `<h3>${name}</h3>`;
|
|
13
|
-
|
|
15
|
+
const id = cellId("test");
|
|
16
|
+
const output = document.createElement("div");
|
|
17
|
+
output.id = CellOutputId.create(id);
|
|
18
|
+
output.dataset.cellRole = "output";
|
|
19
|
+
output.innerHTML = html;
|
|
20
|
+
document.body.append(output);
|
|
14
21
|
|
|
15
22
|
const outline = parseOutline({
|
|
16
23
|
mimetype: "text/html",
|
|
@@ -20,7 +27,12 @@ describe("findOutlineElements", () => {
|
|
|
20
27
|
});
|
|
21
28
|
|
|
22
29
|
expect(
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
resolveOutlineTargets(
|
|
31
|
+
outlineLocators(
|
|
32
|
+
outline?.items.map((item) => ({ ...item, cellId: id })) ?? [],
|
|
33
|
+
),
|
|
34
|
+
).map(({ element }) => element),
|
|
35
|
+
).toEqual([output.firstElementChild]);
|
|
36
|
+
output.remove();
|
|
25
37
|
});
|
|
26
38
|
});
|