@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
|
@@ -7,6 +7,7 @@ import { MockNotebook } from "@/__mocks__/notebook";
|
|
|
7
7
|
import { cellId } from "@/__tests__/branded";
|
|
8
8
|
import { CONFIG } from "@/core/notebook/document/__tests__/fixtures";
|
|
9
9
|
import {
|
|
10
|
+
cellOutlinesAtom,
|
|
10
11
|
createNotebookActions,
|
|
11
12
|
notebookAtom,
|
|
12
13
|
notebookOutline,
|
|
@@ -21,8 +22,8 @@ function showed(id: string, html: string) {
|
|
|
21
22
|
return MockExecutions.shown(id, { mimetype: "text/html", data: html });
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const firstItem = { name: "First", level: 1,
|
|
25
|
-
const secondItem = { name: "Second", level: 2,
|
|
25
|
+
const firstItem = { name: "First", level: 1, id: "first", cellId: first };
|
|
26
|
+
const secondItem = { name: "Second", level: 2, id: "second", cellId: second };
|
|
26
27
|
|
|
27
28
|
function setup() {
|
|
28
29
|
const store = createStore();
|
|
@@ -56,6 +57,33 @@ describe("notebookOutline", () => {
|
|
|
56
57
|
});
|
|
57
58
|
});
|
|
58
59
|
|
|
60
|
+
it("keeps each store's outline identities independent", () => {
|
|
61
|
+
const firstNotebook = setup();
|
|
62
|
+
const secondNotebook = setup();
|
|
63
|
+
const outlines = firstNotebook.store.get(cellOutlinesAtom);
|
|
64
|
+
const outline = firstNotebook.store.get(notebookOutline);
|
|
65
|
+
expect(secondNotebook.store.get(cellOutlinesAtom)).toEqual(outlines);
|
|
66
|
+
expect(secondNotebook.store.get(cellOutlinesAtom)).not.toBe(outlines);
|
|
67
|
+
|
|
68
|
+
secondNotebook.report([showed(first, "<h1>Different heading</h1>")]);
|
|
69
|
+
|
|
70
|
+
expect(firstNotebook.store.get(cellOutlinesAtom)).toBe(outlines);
|
|
71
|
+
expect(firstNotebook.store.get(notebookOutline)).toBe(outline);
|
|
72
|
+
expect(
|
|
73
|
+
secondNotebook.store.get(notebookOutline).items.map(({ name }) => name),
|
|
74
|
+
).toEqual(["Different heading"]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("returns an empty outline in a runtime without DOMParser", () => {
|
|
78
|
+
vi.stubGlobal("DOMParser", undefined);
|
|
79
|
+
try {
|
|
80
|
+
const { store } = setup();
|
|
81
|
+
expect(store.get(notebookOutline)).toEqual({ items: [] });
|
|
82
|
+
} finally {
|
|
83
|
+
vi.unstubAllGlobals();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
59
87
|
it("does not notify outline subscribers when cell code changes", () => {
|
|
60
88
|
const { store } = setup();
|
|
61
89
|
const initial = store.get(notebookOutline);
|
|
@@ -83,7 +111,7 @@ describe("notebookOutline", () => {
|
|
|
83
111
|
showed(second, '<h2 id="second">Second</h2>'),
|
|
84
112
|
]);
|
|
85
113
|
expect(store.get(notebookOutline)).toEqual({
|
|
86
|
-
items: [{ name: "Updated",
|
|
114
|
+
items: [{ ...firstItem, name: "Updated", id: "updated" }, secondItem],
|
|
87
115
|
});
|
|
88
116
|
|
|
89
117
|
report([showed(second, '<h2 id="second">Second</h2>')]);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { fireEvent, render, renderHook } from "@testing-library/react";
|
|
3
|
+
import { createStore, Provider } from "jotai";
|
|
4
|
+
import type { PropsWithChildren } from "react";
|
|
5
|
+
import { afterEach, expect, it } from "vitest";
|
|
6
|
+
import { cellId } from "@/__tests__/branded";
|
|
7
|
+
import { useCellActions } from "../actions";
|
|
8
|
+
import { useReducerActions } from "../cells";
|
|
9
|
+
import { setupNotebook } from "./harness";
|
|
10
|
+
|
|
11
|
+
const stops: Array<() => void> = [];
|
|
12
|
+
afterEach(() => stops.splice(0).forEach((stop) => stop()));
|
|
13
|
+
|
|
14
|
+
it("shares cell actions across consumers of the same store", () => {
|
|
15
|
+
const store = createStore();
|
|
16
|
+
const wrapper = ({ children }: PropsWithChildren) => (
|
|
17
|
+
<Provider store={store}>{children}</Provider>
|
|
18
|
+
);
|
|
19
|
+
const first = renderHook(useCellActions, { wrapper });
|
|
20
|
+
const second = renderHook(useCellActions, { wrapper });
|
|
21
|
+
const session = renderHook(useReducerActions, { wrapper });
|
|
22
|
+
expect(second.result.current).toBe(first.result.current);
|
|
23
|
+
expect(first.result.current.clearLogs).toBe(session.result.current.clearLogs);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("writes to the current notebook when the Provider switches stores", () => {
|
|
27
|
+
const first = setupNotebook(stops);
|
|
28
|
+
const second = setupNotebook(stops);
|
|
29
|
+
const id = cellId("new-cell");
|
|
30
|
+
function CreateCellButton() {
|
|
31
|
+
const { createCell } = useCellActions();
|
|
32
|
+
return (
|
|
33
|
+
<button type="button" onClick={() => createCell({ id, focus: false })}>
|
|
34
|
+
Add cell
|
|
35
|
+
</button>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const buttonIn = (store: typeof first.store) => (
|
|
39
|
+
<Provider store={store}>
|
|
40
|
+
<CreateCellButton />
|
|
41
|
+
</Provider>
|
|
42
|
+
);
|
|
43
|
+
const view = render(buttonIn(first.store));
|
|
44
|
+
view.rerender(buttonIn(second.store));
|
|
45
|
+
fireEvent.click(view.getByRole("button", { name: "Add cell" }));
|
|
46
|
+
expect(second.order()).toContain(id);
|
|
47
|
+
expect(first.order()).not.toContain(id);
|
|
48
|
+
});
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
/** Notebook operations that edit the document and then adjust the editor. */
|
|
4
4
|
|
|
5
5
|
import { historyField } from "@codemirror/commands";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
atom,
|
|
8
|
+
type Getter,
|
|
9
|
+
type Setter,
|
|
10
|
+
useStore,
|
|
11
|
+
type WritableAtom,
|
|
12
|
+
} from "jotai";
|
|
8
13
|
import { scrollAndHighlightCell } from "@/components/editor/links/cell-link";
|
|
9
14
|
import {
|
|
10
15
|
cellExecutionInputsAtom,
|
|
@@ -20,7 +25,7 @@ import { splitEditor } from "../codemirror/language/utils";
|
|
|
20
25
|
import type { SerializedEditorState } from "../codemirror/types";
|
|
21
26
|
import { canCollapseOutline } from "../dom/outline";
|
|
22
27
|
import type { CellConfig } from "../network/types";
|
|
23
|
-
import { store } from "../state/jotai";
|
|
28
|
+
import { type JotaiStore, store } from "../state/jotai";
|
|
24
29
|
import {
|
|
25
30
|
addColumnAtom,
|
|
26
31
|
addColumnBreakpointAtom,
|
|
@@ -39,10 +44,10 @@ import {
|
|
|
39
44
|
} from "./arrange";
|
|
40
45
|
import {
|
|
41
46
|
type DeletedCell,
|
|
47
|
+
getNotebookActionsForStore,
|
|
42
48
|
notebookAtom,
|
|
43
49
|
notebookReducer,
|
|
44
50
|
releaseCellAtoms,
|
|
45
|
-
useReducerActions,
|
|
46
51
|
} from "./cells";
|
|
47
52
|
import { resolveColumns } from "./columns";
|
|
48
53
|
import { consoleExecution } from "./execution-console";
|
|
@@ -646,98 +651,72 @@ export const undoDeleteCellAtom = atom(null, (get, set): void => {
|
|
|
646
651
|
}));
|
|
647
652
|
});
|
|
648
653
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
// notebook through `useReducerActions`; components get the operations.
|
|
654
|
+
function bindCellActions(store: JotaiStore) {
|
|
655
|
+
const bind =
|
|
656
|
+
<Value, Args extends unknown[], Result>(
|
|
657
|
+
atom: WritableAtom<Value, Args, Result>,
|
|
658
|
+
) =>
|
|
659
|
+
(...args: Args) =>
|
|
660
|
+
store.set(atom, ...args);
|
|
661
|
+
|
|
658
662
|
const {
|
|
659
663
|
addLogs: _addLogs,
|
|
660
664
|
reconcileDocument: _reconcileDocument,
|
|
661
665
|
resetCellRuntimes: _resetCellRuntimes,
|
|
662
666
|
...operations
|
|
663
|
-
} =
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
()
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
splitCell,
|
|
702
|
-
undoSplitCell,
|
|
703
|
-
addColumn,
|
|
704
|
-
addColumnBreakpoint,
|
|
705
|
-
deleteColumn,
|
|
706
|
-
mergeAllColumns,
|
|
707
|
-
compactColumns,
|
|
708
|
-
moveColumn,
|
|
709
|
-
moveCell,
|
|
710
|
-
moveCellToIndex,
|
|
711
|
-
moveCellsRelativeTo,
|
|
712
|
-
dropCellOverCell,
|
|
713
|
-
dropCellOverColumn,
|
|
714
|
-
sendToTop,
|
|
715
|
-
sendToBottom,
|
|
716
|
-
createCell,
|
|
717
|
-
moveToNextCell,
|
|
718
|
-
addSetupCell,
|
|
719
|
-
addOrAppendSetupCell,
|
|
720
|
-
deleteCells,
|
|
721
|
-
undoDeleteCell,
|
|
722
|
-
focusCell,
|
|
723
|
-
focusTopCell,
|
|
724
|
-
focusBottomCell,
|
|
725
|
-
collapseCell,
|
|
726
|
-
expandCell,
|
|
727
|
-
collapseAllCells,
|
|
728
|
-
expandAllCells,
|
|
729
|
-
clearCellOutput,
|
|
730
|
-
clearCellConsoleOutput,
|
|
731
|
-
clearAllCellOutputs,
|
|
732
|
-
showCellIfHidden,
|
|
733
|
-
}),
|
|
734
|
-
// The reducer's actions and the atom setters are stable for the store's lifetime.
|
|
735
|
-
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
736
|
-
[],
|
|
737
|
-
);
|
|
667
|
+
} = getNotebookActionsForStore(store);
|
|
668
|
+
|
|
669
|
+
return {
|
|
670
|
+
...operations,
|
|
671
|
+
createCell: bind(createCellAtom),
|
|
672
|
+
moveToNextCell: bind(moveToNextCellAtom),
|
|
673
|
+
addSetupCell: bind(addSetupCellAtom),
|
|
674
|
+
addOrAppendSetupCell: bind(addOrAppendSetupCellAtom),
|
|
675
|
+
deleteCells: bind(deleteCellsAtom),
|
|
676
|
+
undoDeleteCell: bind(undoDeleteCellAtom),
|
|
677
|
+
focusCell: bind(focusCellAtom),
|
|
678
|
+
focusTopCell: bind(focusTopCellAtom),
|
|
679
|
+
focusBottomCell: bind(focusBottomCellAtom),
|
|
680
|
+
collapseCell: bind(collapseCellAtom),
|
|
681
|
+
expandCell: bind(expandCellAtom),
|
|
682
|
+
collapseAllCells: bind(collapseAllCellsAtom),
|
|
683
|
+
expandAllCells: bind(expandAllCellsAtom),
|
|
684
|
+
clearCellOutput: bind(clearCellOutputAtom),
|
|
685
|
+
clearCellConsoleOutput: bind(clearCellConsoleOutputAtom),
|
|
686
|
+
clearAllCellOutputs: bind(clearAllCellOutputsAtom),
|
|
687
|
+
showCellIfHidden: bind(showCellIfHiddenAtom),
|
|
688
|
+
moveCell: bind(moveCellAtom),
|
|
689
|
+
moveCellToIndex: bind(moveCellToIndexAtom),
|
|
690
|
+
moveCellsRelativeTo: bind(moveCellsRelativeToAtom),
|
|
691
|
+
dropCellOverCell: bind(dropCellOverCellAtom),
|
|
692
|
+
dropCellOverColumn: bind(dropCellOverColumnAtom),
|
|
693
|
+
sendToTop: bind(sendToTopAtom),
|
|
694
|
+
sendToBottom: bind(sendToBottomAtom),
|
|
695
|
+
addColumn: bind(addColumnAtom),
|
|
696
|
+
addColumnBreakpoint: bind(addColumnBreakpointAtom),
|
|
697
|
+
deleteColumn: bind(deleteColumnAtom),
|
|
698
|
+
mergeAllColumns: bind(mergeAllColumnsAtom),
|
|
699
|
+
compactColumns: bind(compactColumnsAtom),
|
|
700
|
+
moveColumn: bind(moveColumnAtom),
|
|
701
|
+
setCellCode: bind(setCellCodeAtom),
|
|
702
|
+
splitCell: bind(splitCellAtom),
|
|
703
|
+
undoSplitCell: bind(undoSplitCellAtom),
|
|
704
|
+
};
|
|
738
705
|
}
|
|
739
706
|
|
|
740
|
-
export type CellActions = ReturnType<typeof
|
|
707
|
+
export type CellActions = ReturnType<typeof bindCellActions>;
|
|
708
|
+
const actionsByStore = new WeakMap<JotaiStore, CellActions>();
|
|
709
|
+
|
|
710
|
+
/** Notebook operations shared by components using the same store. */
|
|
711
|
+
export function useCellActions(): CellActions {
|
|
712
|
+
const store = useStore();
|
|
713
|
+
let actions = actionsByStore.get(store);
|
|
714
|
+
if (!actions) {
|
|
715
|
+
actions = bindCellActions(store);
|
|
716
|
+
actionsByStore.set(store, actions);
|
|
717
|
+
}
|
|
718
|
+
return actions;
|
|
719
|
+
}
|
|
741
720
|
|
|
742
721
|
/** Scroll to the first cell that is currently running. */
|
|
743
722
|
export function notebookScrollToRunning() {
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { EditorView } from "@codemirror/view";
|
|
4
4
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
5
|
+
import { dequal } from "dequal";
|
|
5
6
|
import { type Atom, atom, useAtom, useAtomValue } from "jotai";
|
|
6
7
|
import { atomFamily, selectAtom, splitAtom } from "jotai/utils";
|
|
7
8
|
import { createRef, type ReducerWithoutAction } from "react";
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
releaseCellOutputAtoms,
|
|
18
19
|
} from "@/core/executions";
|
|
19
20
|
import type { CellColumnId } from "./layout";
|
|
21
|
+
import { Functions } from "@/utils/functions";
|
|
20
22
|
import { invariant } from "@/utils/invariant";
|
|
21
23
|
import { Logger } from "@/utils/Logger";
|
|
22
24
|
import { Objects } from "@/utils/objects";
|
|
@@ -25,7 +27,6 @@ import { createReducerAndAtoms } from "../../utils/createReducer";
|
|
|
25
27
|
import { foldAllBulk, unfoldAllBulk } from "../codemirror/editing/commands";
|
|
26
28
|
import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
|
|
27
29
|
import type { SerializedEditorState } from "../codemirror/types";
|
|
28
|
-
import { mergeOutlines } from "../dom/outline";
|
|
29
30
|
import { activeNotebookFrameAtom } from "../session/active-notebook";
|
|
30
31
|
import { isErrorMime } from "../mime";
|
|
31
32
|
import { createDeepEqualAtom, store } from "../state/jotai";
|
|
@@ -40,7 +41,7 @@ import { applyDocument } from "./document";
|
|
|
40
41
|
import { isCodeHidden, shownHiddenCodeAtom } from "./editor";
|
|
41
42
|
import { type CellId, SCRATCH_CELL_ID } from "./ids";
|
|
42
43
|
import { type CellLog, getCellLogsForMessage } from "./logs";
|
|
43
|
-
import type { Outline } from "./outline";
|
|
44
|
+
import type { NotebookOutlineItem, Outline } from "./outline";
|
|
44
45
|
import { focusAndScrollCellIntoView } from "./scrollCellIntoView";
|
|
45
46
|
import {
|
|
46
47
|
type CellData,
|
|
@@ -167,6 +168,7 @@ export function initialNotebookState(): NotebookState {
|
|
|
167
168
|
const {
|
|
168
169
|
reducer,
|
|
169
170
|
createActions,
|
|
171
|
+
getActionsForStore,
|
|
170
172
|
useActions,
|
|
171
173
|
valueAtom: notebookAtom,
|
|
172
174
|
} = createReducerAndAtoms(initialNotebookState, {
|
|
@@ -404,6 +406,7 @@ function updateCellRuntimeState({
|
|
|
404
406
|
|
|
405
407
|
export {
|
|
406
408
|
createActions as createNotebookActions,
|
|
409
|
+
getActionsForStore as getNotebookActionsForStore,
|
|
407
410
|
reducer as notebookReducer,
|
|
408
411
|
notebookAtom,
|
|
409
412
|
};
|
|
@@ -473,28 +476,34 @@ export const cellErrorsAtom = atom((get) => {
|
|
|
473
476
|
return errors;
|
|
474
477
|
});
|
|
475
478
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
* readers are left alone by the runs that change no heading.
|
|
479
|
-
*/
|
|
480
|
-
export const cellOutlinesAtom = createDeepEqualAtom(
|
|
479
|
+
// Layout needs lookup by cell ID. Navigation needs the same headings in document order.
|
|
480
|
+
const orderedCellOutlines = selectAtom(
|
|
481
481
|
atom((get) => {
|
|
482
|
-
const
|
|
482
|
+
const entries: [CellId, Outline][] = [];
|
|
483
483
|
for (const cellId of get(cellIdsAtom)) {
|
|
484
484
|
const outline = get(cellOutlineAtom(cellId));
|
|
485
|
-
if (outline
|
|
486
|
-
|
|
485
|
+
if (outline && outline.items.length > 0) {
|
|
486
|
+
entries.push([cellId, outline]);
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
-
return
|
|
489
|
+
return entries;
|
|
490
490
|
}),
|
|
491
|
+
Functions.identity,
|
|
492
|
+
dequal,
|
|
491
493
|
);
|
|
492
494
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
495
|
+
export const cellOutlinesAtom = selectAtom(
|
|
496
|
+
orderedCellOutlines,
|
|
497
|
+
(entries): Partial<Record<CellId, Outline>> => Object.fromEntries(entries),
|
|
498
|
+
dequal,
|
|
496
499
|
);
|
|
497
500
|
|
|
501
|
+
export const notebookOutline = selectAtom(orderedCellOutlines, (entries) => ({
|
|
502
|
+
items: entries.flatMap<NotebookOutlineItem>(([cellId, outline]) =>
|
|
503
|
+
outline.items.map((item) => ({ ...item, cellId })),
|
|
504
|
+
),
|
|
505
|
+
}));
|
|
506
|
+
|
|
498
507
|
export const cellErrorCount = atom((get) => get(cellErrorsAtom).length);
|
|
499
508
|
|
|
500
509
|
export const cellIdToNamesMap = createDeepEqualAtom(
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import type { CellId } from "./ids";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Table of contents outline.
|
|
5
7
|
*/
|
|
@@ -14,14 +16,8 @@ export interface OutlineItem {
|
|
|
14
16
|
* render this instead of the plain-text `name`.
|
|
15
17
|
*/
|
|
16
18
|
html?: string;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* If `id` is provided, the item is located by #id.
|
|
21
|
-
*
|
|
22
|
-
* If `path` is provided, the item is located by xpath.
|
|
23
|
-
*/
|
|
24
|
-
by: { id: string } | { path: string };
|
|
19
|
+
/** The heading's ID, if present. Otherwise, match by name and level. */
|
|
20
|
+
id?: string;
|
|
25
21
|
/**
|
|
26
22
|
* The level of the item.
|
|
27
23
|
* h1 -> 1
|
|
@@ -34,3 +30,7 @@ export interface OutlineItem {
|
|
|
34
30
|
export interface Outline {
|
|
35
31
|
items: OutlineItem[];
|
|
36
32
|
}
|
|
33
|
+
|
|
34
|
+
export interface NotebookOutlineItem extends OutlineItem {
|
|
35
|
+
cellId: CellId;
|
|
36
|
+
}
|
|
@@ -33,7 +33,10 @@ import { getLanguageAdapters, LanguageAdapters } from "./LanguageAdapters";
|
|
|
33
33
|
import { sqlDialectEffect } from "./languages/sql/sql";
|
|
34
34
|
import type { LanguageMetadata } from "./metadata";
|
|
35
35
|
import { languageMetadataField, setLanguageMetadata } from "./metadata";
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
LanguagePanelComponent,
|
|
38
|
+
languagePanelInputsChanged,
|
|
39
|
+
} from "./panel/panel";
|
|
37
40
|
import type { LanguageAdapter } from "./types";
|
|
38
41
|
import { getEditorCodeAsPython } from "./utils";
|
|
39
42
|
|
|
@@ -89,13 +92,13 @@ export const languageAdapterState = StateField.define<LanguageAdapter>({
|
|
|
89
92
|
}
|
|
90
93
|
return value;
|
|
91
94
|
},
|
|
92
|
-
// Only show the panel if the language is not python
|
|
93
95
|
provide: (field) =>
|
|
94
96
|
showPanel.from(field, (value) => {
|
|
95
97
|
if (value.type === "python") {
|
|
96
98
|
return null;
|
|
97
99
|
}
|
|
98
|
-
return (view) =>
|
|
100
|
+
return (view) =>
|
|
101
|
+
createPanel(view, LanguagePanelComponent, languagePanelInputsChanged);
|
|
99
102
|
}),
|
|
100
103
|
});
|
|
101
104
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { Compartment } from "@codemirror/state";
|
|
4
|
+
import { EditorView } from "@codemirror/view";
|
|
5
|
+
import { act, fireEvent, within } from "@testing-library/react";
|
|
6
|
+
import type { createRoot, Root } from "react-dom/client";
|
|
7
|
+
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
|
8
|
+
import { DATA_FOR_CELL_ID } from "@/components/data-table/cell-utils";
|
|
9
|
+
import { CellId } from "@/core/cells/ids";
|
|
10
|
+
import { cellIdState } from "@/core/codemirror/cells/state";
|
|
11
|
+
import { cellConfigExtension } from "@/core/codemirror/config/extension";
|
|
12
|
+
import { defaultUserConfig } from "@/core/config/config-schema";
|
|
13
|
+
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
14
|
+
import { adaptiveLanguageConfiguration, switchLanguage } from "../extension";
|
|
15
|
+
import { languageMetadataField, updateLanguageMetadata } from "../metadata";
|
|
16
|
+
|
|
17
|
+
const trackRoot = vi.hoisted(() => vi.fn<(root: Root) => void>());
|
|
18
|
+
|
|
19
|
+
vi.mock("react-dom/client", async (importOriginal) => {
|
|
20
|
+
const original = await importOriginal<typeof import("react-dom/client")>();
|
|
21
|
+
return {
|
|
22
|
+
...original,
|
|
23
|
+
createRoot: (...args: Parameters<typeof createRoot>) => {
|
|
24
|
+
const root = original.createRoot(...args);
|
|
25
|
+
vi.spyOn(root, "render");
|
|
26
|
+
vi.spyOn(root, "unmount");
|
|
27
|
+
trackRoot(root);
|
|
28
|
+
return root;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
vi.mock("@/components/editor/connections/components", () => ({
|
|
34
|
+
useAddDetectedDataSource: () => vi.fn(),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const config = defaultUserConfig();
|
|
38
|
+
const options = {
|
|
39
|
+
cellId: CellId.create(),
|
|
40
|
+
completionConfig: config.completion,
|
|
41
|
+
lspConfig: config.language_servers,
|
|
42
|
+
diagnosticsConfig: config.diagnostics,
|
|
43
|
+
hotkeys: new OverridingHotkeyProvider({}),
|
|
44
|
+
placeholderType: "marimo-import" as const,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const cellId = new Compartment();
|
|
48
|
+
|
|
49
|
+
async function mountPanel(language: "markdown" | "sql") {
|
|
50
|
+
const view = new EditorView({
|
|
51
|
+
parent: document.body,
|
|
52
|
+
doc:
|
|
53
|
+
language === "markdown" ? 'mo.md(r"hello")' : 'df = mo.sql("select 1")',
|
|
54
|
+
extensions: [
|
|
55
|
+
cellConfigExtension(options),
|
|
56
|
+
cellId.of(cellIdState.of(options.cellId)),
|
|
57
|
+
adaptiveLanguageConfiguration(options),
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
onTestFinished(() => act(() => view.destroy()));
|
|
61
|
+
await act(() => switchLanguage(view, { language }));
|
|
62
|
+
const [root] = trackRoot.mock.calls[0];
|
|
63
|
+
return { view, root, panel: within(view.dom) };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe("language panel renders", () => {
|
|
67
|
+
it.each(["markdown", "sql"] as const)(
|
|
68
|
+
"renders %s once across selection and document edits",
|
|
69
|
+
async (language) => {
|
|
70
|
+
const { view, root } = await mountPanel(language);
|
|
71
|
+
expect(root.render).toHaveBeenCalledTimes(1);
|
|
72
|
+
|
|
73
|
+
await act(() => {
|
|
74
|
+
view.dispatch({ selection: { anchor: 1 } });
|
|
75
|
+
view.dispatch({ changes: { from: 0, insert: "x" } });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(trackRoot).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(root.render).toHaveBeenCalledTimes(1);
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
it("updates the Markdown prefix when the checkbox changes", async () => {
|
|
84
|
+
const { view, panel } = await mountPanel("markdown");
|
|
85
|
+
const checkbox = panel.getByRole("checkbox", { name: "Toggle f-string" });
|
|
86
|
+
expect(checkbox).not.toBeChecked();
|
|
87
|
+
fireEvent.click(checkbox);
|
|
88
|
+
expect(view.state.field(languageMetadataField).quotePrefix).toContain("f");
|
|
89
|
+
expect(checkbox).toBeChecked();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("defaults a missing Markdown prefix to raw", async () => {
|
|
93
|
+
const { view, panel } = await mountPanel("markdown");
|
|
94
|
+
await act(() =>
|
|
95
|
+
view.dispatch({
|
|
96
|
+
effects: updateLanguageMetadata.of({ quotePrefix: undefined }),
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
expect(view.state.field(languageMetadataField).quotePrefix).toBe("r");
|
|
100
|
+
expect(
|
|
101
|
+
panel.getByRole("checkbox", { name: "Toggle raw string" }),
|
|
102
|
+
).toBeChecked();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("updates the SQL hide-output control when metadata changes", async () => {
|
|
106
|
+
const { view, panel } = await mountPanel("sql");
|
|
107
|
+
const output = panel.getByRole("checkbox", { name: "Hide output" });
|
|
108
|
+
expect(output).not.toBeChecked();
|
|
109
|
+
await act(() =>
|
|
110
|
+
view.dispatch({
|
|
111
|
+
effects: updateLanguageMetadata.of({ showOutput: false }),
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
expect(output).toBeChecked();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("updates the SQL engine selector when only the cell ID changes", async () => {
|
|
118
|
+
const { view, panel } = await mountPanel("sql");
|
|
119
|
+
const selector = panel.getByRole("combobox");
|
|
120
|
+
expect(selector).toHaveAttribute(DATA_FOR_CELL_ID, options.cellId);
|
|
121
|
+
const nextId = CellId.create();
|
|
122
|
+
await act(() =>
|
|
123
|
+
view.dispatch({
|
|
124
|
+
effects: cellId.reconfigure(cellIdState.of(nextId)),
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
expect(selector).toHaveAttribute(DATA_FOR_CELL_ID, nextId);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("replaces the SQL panel for Markdown and removes it for Python", async () => {
|
|
131
|
+
const { view, root, panel } = await mountPanel("sql");
|
|
132
|
+
await act(() => switchLanguage(view, { language: "markdown" }));
|
|
133
|
+
expect(root.unmount).toHaveBeenCalledTimes(1);
|
|
134
|
+
expect(trackRoot).toHaveBeenCalledTimes(2);
|
|
135
|
+
expect(
|
|
136
|
+
panel.getByRole("checkbox", { name: "Toggle f-string" }),
|
|
137
|
+
).toBeInTheDocument();
|
|
138
|
+
|
|
139
|
+
const [markdownRoot] = trackRoot.mock.calls[1];
|
|
140
|
+
await act(() => switchLanguage(view, { language: "python" }));
|
|
141
|
+
expect(markdownRoot.unmount).toHaveBeenCalledTimes(1);
|
|
142
|
+
expect(view.dom.querySelector(".cm-panel")).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import type { EditorView } from "@codemirror/view";
|
|
2
|
+
import type { EditorView, ViewUpdate } from "@codemirror/view";
|
|
3
3
|
import type { QuotePrefixKind } from "@marimo-team/smart-cells";
|
|
4
4
|
import { InfoIcon, PaintRollerIcon } from "lucide-react";
|
|
5
5
|
import { Button } from "@/components/ui/button";
|
|
@@ -25,6 +25,14 @@ import type { LanguageMetadataOf } from "../types";
|
|
|
25
25
|
import { getQuotePrefix, MarkdownQuotePrefixTooltip } from "./markdown";
|
|
26
26
|
import { SQLEngineSelect, SQLModeSelect } from "./sql";
|
|
27
27
|
|
|
28
|
+
export function languagePanelInputsChanged(update: ViewUpdate): boolean {
|
|
29
|
+
return (
|
|
30
|
+
update.startState.field(languageMetadataField) !==
|
|
31
|
+
update.state.field(languageMetadataField) ||
|
|
32
|
+
update.startState.facet(cellIdState) !== update.state.facet(cellIdState)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
const Divider = () => <div className="h-4 border-r border-border" />;
|
|
29
37
|
|
|
30
38
|
export const LanguagePanelComponent: React.FC<{
|
|
@@ -58,7 +66,6 @@ export const LanguagePanelComponent: React.FC<{
|
|
|
58
66
|
const sanitizeAndTriggerUpdate = (
|
|
59
67
|
e: React.SyntheticEvent<HTMLInputElement>,
|
|
60
68
|
) => {
|
|
61
|
-
// Normalize the name to a valid variable name
|
|
62
69
|
const name = normalizeName(e.currentTarget.value, false);
|
|
63
70
|
e.currentTarget.value = name;
|
|
64
71
|
|
|
@@ -79,9 +86,6 @@ export const LanguagePanelComponent: React.FC<{
|
|
|
79
86
|
<input
|
|
80
87
|
{...inputProps}
|
|
81
88
|
defaultValue={metadata.dataframeName}
|
|
82
|
-
onChange={(e) => {
|
|
83
|
-
inputProps.onChange?.(e);
|
|
84
|
-
}}
|
|
85
89
|
onBlur={sanitizeAndTriggerUpdate}
|
|
86
90
|
onKeyDown={(e) => {
|
|
87
91
|
if (e.key === "Enter" && e.shiftKey) {
|
|
@@ -136,7 +140,6 @@ export const LanguagePanelComponent: React.FC<{
|
|
|
136
140
|
const metadata = view.state.field(languageMetadataField) as Metadata2;
|
|
137
141
|
let { quotePrefix } = metadata;
|
|
138
142
|
|
|
139
|
-
// Handle the case where the quote prefix is not set
|
|
140
143
|
if (quotePrefix === undefined) {
|
|
141
144
|
quotePrefix = "r";
|
|
142
145
|
triggerUpdate<Metadata2>({ quotePrefix });
|