Skip to content

Commit de44b9f

Browse files
committed
feat 5834: add outline - mo.outline()
1 parent 14bc619 commit de44b9f

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed
Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
2+
import { Provider } from "jotai";
3+
import { useAtomValue } from "jotai";
24
import type { JSX } from "react";
35
import { z } from "zod";
46
import { notebookOutline } from "@/core/cells/cells";
@@ -14,6 +16,36 @@ interface Data {
1416
label?: string;
1517
}
1618

19+
const OutlineContent: React.FC<{ label?: string }> = ({ label }) => {
20+
const { items } = useAtomValue(notebookOutline);
21+
const headerElements = findOutlineElements(items);
22+
const { activeHeaderId, activeOccurrences } = useActiveOutline(headerElements);
23+
24+
if (items.length === 0) {
25+
return (
26+
<div className="text-muted-foreground text-sm p-4 border border-dashed border-border rounded-lg">
27+
No outline found. Add markdown headings to your notebook to create an outline.
28+
</div>
29+
);
30+
}
31+
32+
return (
33+
<div className="border border-border rounded-lg">
34+
{label && (
35+
<div className="px-4 py-2 border-b border-border font-medium text-sm">
36+
{label}
37+
</div>
38+
)}
39+
<OutlineList
40+
className="max-h-[400px]"
41+
items={items}
42+
activeHeaderId={activeHeaderId}
43+
activeOccurrences={activeOccurrences}
44+
/>
45+
</div>
46+
);
47+
};
48+
1749
export class OutlinePlugin implements IStatelessPlugin<Data> {
1850
tagName = "marimo-outline";
1951

@@ -23,33 +55,11 @@ export class OutlinePlugin implements IStatelessPlugin<Data> {
2355

2456
render(props: IStatelessPluginProps<Data>): JSX.Element {
2557
const { label } = props.data;
26-
const { items } = store.get(notebookOutline);
27-
const headerElements = findOutlineElements(items);
28-
29-
const { activeHeaderId, activeOccurrences } = useActiveOutline(headerElements);
30-
31-
if (items.length === 0) {
32-
return (
33-
<div className="text-muted-foreground text-sm p-4 border border-dashed border-border rounded-lg">
34-
No outline found. Add markdown headings to your notebook to create an outline.
35-
</div>
36-
);
37-
}
3858

3959
return (
40-
<div className="border border-border rounded-lg">
41-
{label && (
42-
<div className="px-4 py-2 border-b border-border font-medium text-sm">
43-
{label}
44-
</div>
45-
)}
46-
<OutlineList
47-
className="max-h-[400px]"
48-
items={items}
49-
activeHeaderId={activeHeaderId}
50-
activeOccurrences={activeOccurrences}
51-
/>
52-
</div>
60+
<Provider store={store}>
61+
<OutlineContent label={label} />
62+
</Provider>
5363
);
5464
}
5565
}

0 commit comments

Comments
 (0)