feat(presentation): laser pointer and max width (#2561)
* feat: add laser pointer * feat: increase slide max width to 1440px * fix: show presentation errors inside the modal
This commit is contained in:
parent
88e9255e8b
commit
d35e8f0cf9
5 changed files with 229 additions and 36 deletions
|
|
@ -77,6 +77,7 @@
|
|||
"Failed to fetch recent pages": "Failed to fetch recent pages",
|
||||
"Failed to import pages": "Failed to import pages",
|
||||
"Failed to load page. An error occurred.": "Failed to load page. An error occurred.",
|
||||
"Failed to load presentation. An error occurred.": "Failed to load presentation. An error occurred.",
|
||||
"Failed to update data": "Failed to update data",
|
||||
"Failed to create base": "Failed to create base",
|
||||
"Failed to update base": "Failed to update base",
|
||||
|
|
@ -167,6 +168,7 @@
|
|||
"Exit presentation mode": "Exit presentation mode",
|
||||
"Enter fullscreen": "Enter fullscreen",
|
||||
"Exit fullscreen": "Exit fullscreen",
|
||||
"Laser pointer": "Laser pointer",
|
||||
"Slide {{current}} of {{total}}": "Slide {{current}} of {{total}}",
|
||||
"Print PDF": "Print PDF",
|
||||
"Profile": "Profile",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { render } from "@testing-library/react";
|
||||
import LaserPointer from "./laser-pointer";
|
||||
|
||||
type PointerInit = MouseEventInit & { pointerType?: string };
|
||||
|
||||
function dispatchPointer(
|
||||
target: EventTarget,
|
||||
type: "pointermove" | "pointerout",
|
||||
init: PointerInit = {},
|
||||
) {
|
||||
// jsdom has no PointerEvent
|
||||
const event = new MouseEvent(type, { bubbles: true, ...init });
|
||||
Object.defineProperty(event, "pointerType", {
|
||||
value: init.pointerType ?? "mouse",
|
||||
});
|
||||
target.dispatchEvent(event);
|
||||
}
|
||||
|
||||
function renderLaserPointer(enabled = true) {
|
||||
const view = render(<LaserPointer enabled={enabled} />);
|
||||
return { ...view, dot: view.container.firstElementChild as HTMLElement };
|
||||
}
|
||||
|
||||
describe("LaserPointer", () => {
|
||||
it("follows the pointer", () => {
|
||||
const { dot } = renderLaserPointer();
|
||||
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
expect(dot.style.transform).toBe("translate(120px, 80px)");
|
||||
expect(dot.style.visibility).toBe("visible");
|
||||
});
|
||||
|
||||
it("stays hidden while disabled", () => {
|
||||
const { dot } = renderLaserPointer(false);
|
||||
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
expect(dot.hidden).toBe(true);
|
||||
});
|
||||
|
||||
it("shows at the last pointer position once enabled", () => {
|
||||
const { dot, rerender } = renderLaserPointer(false);
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
rerender(<LaserPointer enabled />);
|
||||
|
||||
expect(dot.hidden).toBe(false);
|
||||
expect(dot.style.transform).toBe("translate(120px, 80px)");
|
||||
});
|
||||
|
||||
it("hides for touch input", () => {
|
||||
const { dot } = renderLaserPointer();
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
dispatchPointer(window, "pointermove", { pointerType: "touch" });
|
||||
|
||||
expect(dot.style.visibility).toBe("hidden");
|
||||
});
|
||||
|
||||
it("hides when the pointer leaves the window", () => {
|
||||
const { dot, container } = renderLaserPointer();
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
dispatchPointer(container, "pointerout", { relatedTarget: null });
|
||||
|
||||
expect(dot.style.visibility).toBe("hidden");
|
||||
});
|
||||
|
||||
it("hides when the pointer moves over an embed", () => {
|
||||
const { dot, container } = renderLaserPointer();
|
||||
const embed = container.appendChild(document.createElement("iframe"));
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
dispatchPointer(container, "pointerout", { relatedTarget: embed });
|
||||
|
||||
expect(dot.style.visibility).toBe("hidden");
|
||||
});
|
||||
|
||||
it("stays visible when the pointer moves onto another page element", () => {
|
||||
const { dot, container } = renderLaserPointer();
|
||||
const paragraph = container.appendChild(document.createElement("p"));
|
||||
dispatchPointer(window, "pointermove", { clientX: 120, clientY: 80 });
|
||||
|
||||
dispatchPointer(container, "pointerout", { relatedTarget: paragraph });
|
||||
|
||||
expect(dot.style.visibility).toBe("visible");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import { useRef } from "react";
|
||||
import { useWindowEvent } from "@mantine/hooks";
|
||||
import classes from "./presentation-modal.module.css";
|
||||
|
||||
type LaserPointerProps = {
|
||||
enabled: boolean;
|
||||
};
|
||||
|
||||
export default function LaserPointer({ enabled }: LaserPointerProps) {
|
||||
const dotRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useWindowEvent("pointermove", (event) => {
|
||||
const dot = dotRef.current;
|
||||
if (!dot) return;
|
||||
dot.style.transform = `translate(${event.clientX}px, ${event.clientY}px)`;
|
||||
dot.style.visibility = event.pointerType === "touch" ? "hidden" : "visible";
|
||||
});
|
||||
|
||||
useWindowEvent("pointerout", (event) => {
|
||||
// the page gets no pointer events outside the window or over an embed
|
||||
const leftPage =
|
||||
!event.relatedTarget || event.relatedTarget instanceof HTMLIFrameElement;
|
||||
if (leftPage && dotRef.current) {
|
||||
dotRef.current.style.visibility = "hidden";
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={dotRef}
|
||||
className={classes.laserPointer}
|
||||
hidden={!enabled}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
.editorContainer {
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
max-width: 1440px;
|
||||
margin-block: auto;
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
max-width: 1440px;
|
||||
margin-block: auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
|
@ -132,3 +132,23 @@
|
|||
height: 24px;
|
||||
margin-inline: 4px;
|
||||
}
|
||||
|
||||
/* the dot replaces every cursor, including ones slide content sets */
|
||||
.content:has(.laserPointer:not([hidden])),
|
||||
.content:has(.laserPointer:not([hidden])) * {
|
||||
cursor: none !important;
|
||||
}
|
||||
|
||||
.laserPointer {
|
||||
position: fixed;
|
||||
top: -7px;
|
||||
left: -7px;
|
||||
z-index: 20;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
background-color: color-mix(in srgb, var(--mantine-color-blue-4) 65%, transparent);
|
||||
box-shadow: 0 0 10px 4px color-mix(in srgb, var(--mantine-color-blue-4) 30%, transparent);
|
||||
pointer-events: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import {
|
|||
import {
|
||||
ActionIcon,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Divider,
|
||||
Modal,
|
||||
Title,
|
||||
|
|
@ -20,10 +22,12 @@ import {
|
|||
VisuallyHidden,
|
||||
} from "@mantine/core";
|
||||
import {
|
||||
IconAlertTriangle,
|
||||
IconChevronLeft,
|
||||
IconChevronRight,
|
||||
IconMaximize,
|
||||
IconMinimize,
|
||||
IconPointer,
|
||||
IconX,
|
||||
} from "@tabler/icons-react";
|
||||
import { useFullscreenDocument, useWindowEvent } from "@mantine/hooks";
|
||||
|
|
@ -38,10 +42,13 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|||
import { UniqueID } from "@docmost/editor-ext";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { ErrorBoundary } from "react-error-boundary";
|
||||
import clsx from "clsx";
|
||||
import { EmptyState } from "@/components/ui/empty-state.tsx";
|
||||
import { mainExtensions } from "@/features/editor/extensions/extensions";
|
||||
import { TransclusionLookupProvider } from "@/features/editor/components/transclusion/transclusion-lookup-context";
|
||||
import { extractPageSlugId } from "@/lib";
|
||||
import LaserPointer from "./laser-pointer";
|
||||
import {
|
||||
findSlideIndexForNode,
|
||||
getContentBoxHeight,
|
||||
|
|
@ -130,12 +137,33 @@ export default function PresentationModal({
|
|||
aria-label={t("Presentation mode")}
|
||||
>
|
||||
<Modal.Body className={classes.body}>
|
||||
<PresentationDeck
|
||||
pageId={pageId}
|
||||
title={title}
|
||||
content={content}
|
||||
onClose={onClose}
|
||||
/>
|
||||
<ErrorBoundary
|
||||
fallback={
|
||||
<Center h="100%">
|
||||
<EmptyState
|
||||
icon={IconAlertTriangle}
|
||||
title={t("Failed to load presentation. An error occurred.")}
|
||||
action={
|
||||
<Button
|
||||
variant="default"
|
||||
size="sm"
|
||||
mt="xs"
|
||||
onClick={onClose}
|
||||
>
|
||||
{t("Close")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</Center>
|
||||
}
|
||||
>
|
||||
<PresentationDeck
|
||||
pageId={pageId}
|
||||
title={title}
|
||||
content={content}
|
||||
onClose={onClose}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
</Modal.Body>
|
||||
</Modal.Content>
|
||||
</Modal.Root>
|
||||
|
|
@ -162,6 +190,7 @@ function PresentationDeck({
|
|||
|
||||
const { toggle: toggleFullscreen, fullscreen } = useFullscreenDocument();
|
||||
const canFullscreen = document.fullscreenEnabled;
|
||||
const [laserPointerEnabled, setLaserPointerEnabled] = useState(false);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
|
|
@ -434,36 +463,50 @@ function PresentationDeck({
|
|||
<IconChevronRight size={20} />
|
||||
</ActionIcon>
|
||||
|
||||
<Divider
|
||||
orientation="vertical"
|
||||
aria-orientation="vertical"
|
||||
className={classes.controlDivider}
|
||||
/>
|
||||
|
||||
<Tooltip label={t("Laser pointer")} openDelay={250}>
|
||||
<ActionIcon
|
||||
className={classes.controlButton}
|
||||
variant="subtle"
|
||||
color={laserPointerEnabled ? "blue" : "dark"}
|
||||
size="lg"
|
||||
radius="xl"
|
||||
aria-label={t("Laser pointer")}
|
||||
aria-pressed={laserPointerEnabled}
|
||||
onClick={() => setLaserPointerEnabled((enabled) => !enabled)}
|
||||
>
|
||||
<IconPointer size={20} />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
|
||||
{canFullscreen && (
|
||||
<>
|
||||
<Divider
|
||||
orientation="vertical"
|
||||
aria-orientation="vertical"
|
||||
className={classes.controlDivider}
|
||||
/>
|
||||
<Tooltip
|
||||
label={fullscreen ? t("Exit fullscreen") : t("Enter fullscreen")}
|
||||
openDelay={250}
|
||||
<Tooltip
|
||||
label={fullscreen ? t("Exit fullscreen") : t("Enter fullscreen")}
|
||||
openDelay={250}
|
||||
>
|
||||
<ActionIcon
|
||||
className={classes.controlButton}
|
||||
variant="subtle"
|
||||
color="dark"
|
||||
size="lg"
|
||||
radius="xl"
|
||||
aria-label={
|
||||
fullscreen ? t("Exit fullscreen") : t("Enter fullscreen")
|
||||
}
|
||||
onClick={handleToggleFullscreen}
|
||||
>
|
||||
<ActionIcon
|
||||
className={classes.controlButton}
|
||||
variant="subtle"
|
||||
color="dark"
|
||||
size="lg"
|
||||
radius="xl"
|
||||
aria-label={
|
||||
fullscreen ? t("Exit fullscreen") : t("Enter fullscreen")
|
||||
}
|
||||
onClick={handleToggleFullscreen}
|
||||
>
|
||||
{fullscreen ? (
|
||||
<IconMinimize size={20} />
|
||||
) : (
|
||||
<IconMaximize size={20} />
|
||||
)}
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</>
|
||||
{fullscreen ? (
|
||||
<IconMinimize size={20} />
|
||||
) : (
|
||||
<IconMaximize size={20} />
|
||||
)}
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
|
@ -474,6 +517,8 @@ function PresentationDeck({
|
|||
})}
|
||||
</VisuallyHidden>
|
||||
</div>
|
||||
|
||||
<LaserPointer enabled={laserPointerEnabled} />
|
||||
</TransclusionLookupProvider>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue