Add instructions slide (#11710)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-03-11 08:31:21 -04:00
1 parent e913075d75
commit fee9791cc9
2 files changed
+71 -5

No files matched your search

@@ -33,7 +33,8 @@ type Slide =
icon?: string | null;
iconColor?: string | null;
}
| { type: "content"; content: ProsemirrorData[] };
| { type: "content"; content: ProsemirrorData[] }
| { type: "instructions" };
interface Props {
/** The document title. */
@@ -48,6 +49,19 @@ interface Props {
onClose: () => void;
}
/**
* Returns true if the given content nodes contain no meaningful text or elements.
*
* @param nodes the prosemirror content nodes.
* @returns true when every node is an empty paragraph.
*/
function isContentEmpty(nodes: ProsemirrorData[]): boolean {
return nodes.every(
(node) =>
node.type === "paragraph" && (!node.content || node.content.length === 0)
);
}
/**
* Splits a ProseMirror document into slides based on heading and divider nodes.
* A dedicated title slide is prepended. Each h1/h2 heading or horizontal rule
@@ -114,10 +128,21 @@ function PresentationMode({ title, icon, iconColor, data, onClose }: Props) {
const [isFullscreen, setIsFullscreen] = React.useState(false);
const isIdle = useIdle(3000, idleEvents);
const slides = React.useMemo(
() => splitIntoSlides(data, title, icon, iconColor),
[data, title, icon, iconColor]
);
const slides = React.useMemo(() => {
const result = splitIntoSlides(data, title, icon, iconColor);
const contentSlides = result.filter((s) => s.type === "content");
const hasContent =
contentSlides.length > 0 &&
contentSlides.some(
(s) => s.type === "content" && !isContentEmpty(s.content)
);
if (!hasContent) {
return [result[0], { type: "instructions" as const }];
}
return result;
}, [data, title, icon, iconColor]);
const totalSlides = slides.length;
@@ -300,6 +325,24 @@ function PresentationMode({ title, icon, iconColor, data, onClose }: Props) {
)}
<TitleText>{slide.title}</TitleText>
</TitleSlide>
) : slide.type === "instructions" ? (
<InstructionSlide>
<InstructionHeading>
{t("Create your presentation")}
</InstructionHeading>
<InstructionBody>
{t(
"Add content to your document, then use headings or dividers to separate it into slides."
)}{" "}
<a
href="https://docs.getoutline.com/s/guide/doc/present-mode-yMGzaY7A9L"
target="_blank"
>
{t("Learn more")}
</a>
.
</InstructionBody>
</InstructionSlide>
) : slideData ? (
<Editor
key={currentSlide}
@@ -423,4 +466,24 @@ const Button = styled(NudeButton).attrs({ size: 32 })`
}
`;
const InstructionSlide = styled(TitleSlide)`
gap: 16px;
max-width: 560px;
margin: 0 auto;
`;
const InstructionHeading = styled.h2`
font-size: 2em;
font-weight: 600;
margin: 0;
color: ${s("text")};
`;
const InstructionBody = styled.p`
font-size: 1.2em;
line-height: 1.6;
margin: 0;
color: ${s("textSecondary")};
`;
export default PresentationMode;
@@ -841,6 +841,9 @@
"Previous slide": "Previous slide",
"Next slide": "Next slide",
"Toggle fullscreen": "Toggle fullscreen",
"Create your presentation": "Create your presentation",
"Add content to your document, then use headings or dividers to separate it into slides.": "Add content to your document, then use headings or dividers to separate it into slides.",
"Learn more": "Learn more",
"Backlinks": "Backlinks",
"This document is large which may affect performance": "This document is large which may affect performance",
"Are you sure about that? Deleting the <em>{{ documentTitle }}</em> document will delete all of its history</em>.": "Are you sure about that? Deleting the <em>{{ documentTitle }}</em> document will delete all of its history</em>.",