#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(desktop): slide the tool view instead of using a View Transition (#8680)
EthanHealy0194d9c2fb8646
diff --git a/frontend/src/editor/core/components/tools/RightSidebar.tsx b/frontend/src/editor/core/components/tools/RightSidebar.tsxindex 12a8a656f9..a9d4ee77ce 100644--- a/frontend/src/editor/core/components/tools/RightSidebar.tsx+++ b/frontend/src/editor/core/components/tools/RightSidebar.tsx@@ -1,6 +1,9 @@-import { useState } from "react";+import { useRef, useState } from "react";+import { Transition, useDirection } from "@mantine/core";+import { useReducedMotion } from "@mantine/hooks";import { useTranslation } from "react-i18next";import { useToolWorkflow } from "@editor/contexts/ToolWorkflowContext";+import { useNavigationActions } from "@editor/contexts/NavigationContext";import { useSidebarContext } from "@editor/contexts/SidebarContext";import { useIsMobile } from "@editor/hooks/useIsMobile";import ToolPanel from "@editor/components/tools/ToolPanel";@@ -9,7 +12,6 @@ import { EditorPipelinesPanel } from "@editor/components/policies/EditorPipelineimport { ToolIcon } from "@editor/components/shared/ToolIcon";import { ToolPanelHeader } from "@editor/components/shared/ToolPanelHeader";import { ActionIcon } from "@editor/ui/ActionIcon";-import { withViewTransition } from "@editor/utils/viewTransition";import { Icon } from "@editor/ui/Icon";import { ToolId } from "@editor/types/toolId";import type { ToolRegistryEntry } from "@editor/data/toolsTaxonomy";@@ -50,40 +52,58 @@ export default function RightSidebar() {const [allToolsView, setAllToolsView] = useState(false);- const handleShowAllTools = () => {- withViewTransition(() => setAllToolsView(true));- };+ const handleShowAllTools = () => setAllToolsView(true);const handleBackToDefault = () => {- withViewTransition(() => {- setAllToolsView(false);- setSearchQuery("");- });+ setAllToolsView(false);+ setSearchQuery("");};- // The header shows [back] [search] when we have somewhere to go back to —- // i.e. the user is in a specific tool, or already in the all-tools/search view.const inToolView = leftPanelView !== "toolPicker";- // Show X (close) button only when there's somewhere to go back to.- const showCloseButton = inToolView || allToolsView;-- const handleHeaderBack = () => {- if (inToolView) {- withViewTransition(() => handleBackToTools());- } else {- handleBackToDefault();- }- };-- const handleToolSelectWithTransition = (id: ToolId) => {- withViewTransition(() => handleToolSelect(id));- };const activeTool: ToolRegistryEntry | null =inToolView && selectedToolKey? (toolRegistry[selectedToolKey] ?? null): null;+ // A CSS slide: startViewTransition() segfaults WebKitGTK (WebKit bug 324730).+ // The tool stays selected until it has slid out, or its mount effects rerun.+ const [closing, setClosing] = useState(false);+ const closingRef = useRef(false);+ const toolLayerMounted = inToolView && !closing;+ // Unmount the covered picker so the page never has two copies of a tool link.+ const [toolLayerCovers, setToolLayerCovers] = useState(toolLayerMounted);+ if (toolLayerCovers && !toolLayerMounted) setToolLayerCovers(false);+ const { actions: navigationActions } = useNavigationActions();+ // Ask before the slide. The prompt resolves the edits, so handleBackToTools+ // passes its own guard once the tool has left.+ const handleClose = () => {+ navigationActions.requestNavigation(() => {+ closingRef.current = true;+ setClosing(true);+ });+ };+ const handleToolLayerExited = () => {+ if (!closingRef.current) return;+ closingRef.current = false;+ setClosing(false);+ handleBackToTools();+ };+ const handlePickerSelect = (id: ToolId) => {+ closingRef.current = false;+ setClosing(false);+ handleToolSelect(id);+ };+ const { dir } = useDirection();+ const reduceMotion = useReducedMotion();+ const slideFromTrailingEdge = {+ in: { transform: "translateX(0)" },+ out: {+ transform: dir === "rtl" ? "translateX(-100%)" : "translateX(100%)",+ },+ transitionProperty: "transform",+ };+const expandedWidth = "18.5rem";return (@@ -114,58 +134,79 @@ export default function RightSidebar() {><>{policiesEnabled && <EditorPipelinesPanel />}- {activeTool ? (- <ToolPanelHeader- icon={- <ToolIcon- icon={activeTool.icon}- marginRight="0"- color="currentColor"+ <div className="tool-panel__stage">+ {!toolLayerCovers && (+ <div+ className="tool-panel__picker-layer"+ inert={toolLayerMounted}+ >+ {allToolsView && (+ <div className="tool-panel__compact-header">+ <span className="tool-panel__compact-title">+ {t("toolPanel.pdfTools", "PDF Tools")}+ </span>+ <div className="tool-panel__compact-header-actions">+ <ActionIcon+ variant="tertiary"+ size="md"+ shape="circle"+ onClick={handleBackToDefault}+ aria-label={t("toolPanel.goBack", "Go back")}+ className="tool-panel__expand-btn"+ >+ <Icon name="x" size={"1.1rem"} />+ </ActionIcon>+ </div>+ </div>+ )}+ <ToolPanel+ view="toolPicker"+ allToolsView={allToolsView}+ onShowAllTools={handleShowAllTools}+ onToolSelect={handlePickerSelect}+ compact={false}+ /* Mobile keeps the workbench bar - and with it the super search -+ on the other slide, so the list needs its own filter. */+ showSearch={isMobile}/>- }- title={activeTool.name}- onClose={handleHeaderBack}- closeLabel={- inToolView- ? t("toolPanel.backToAllTools", "Back to all tools")- : t("toolPanel.goBack", "Go back")- }- />- ) : showCloseButton ? (- /* Closing a tool, not the panel: the panel itself is fixed open, so- with nothing to leave there is no header to show. */- <div className="tool-panel__compact-header">- <span className="tool-panel__compact-title">- {t("toolPanel.pdfTools", "PDF Tools")}- </span>- <div className="tool-panel__compact-header-actions">- <ActionIcon- variant="tertiary"- size="md"- shape="circle"- onClick={handleHeaderBack}- aria-label={- inToolView- ? t("toolPanel.backToAllTools", "Back to all tools")- : t("toolPanel.goBack", "Go back")- }- className="tool-panel__expand-btn"- >- <Icon name="x" size={"1.1rem"} />- </ActionIcon></div>- </div>- ) : null}-- <ToolPanel- allToolsView={allToolsView}- onShowAllTools={handleShowAllTools}- onToolSelect={handleToolSelectWithTransition}- compact={false}- /* Mobile keeps the workbench bar - and with it the super search -- on the other slide, so the list needs its own filter. */- showSearch={isMobile}- />+ )}+ <Transition+ mounted={toolLayerMounted}+ transition={slideFromTrailingEdge}+ onEntered={() => setToolLayerCovers(true)}+ onExited={handleToolLayerExited}+ duration={reduceMotion ? 0 : 220}+ timingFunction="ease"+ >+ {(styles) => (+ <div className="tool-panel__tool-layer" style={styles}>+ {activeTool && (+ <ToolPanelHeader+ icon={+ <ToolIcon+ icon={activeTool.icon}+ marginRight="0"+ color="currentColor"+ />+ }+ title={activeTool.name}+ onClose={handleClose}+ closeLabel={t(+ "toolPanel.backToAllTools",+ "Back to all tools",+ )}+ />+ )}+ <ToolPanel+ view="toolContent"+ allToolsView={false}+ onShowAllTools={handleShowAllTools}+ />+ </div>+ )}+ </Transition>+ </div></></div>)}diff --git a/frontend/src/editor/core/components/tools/ToolPanel.css b/frontend/src/editor/core/components/tools/ToolPanel.cssindex c81f4d733c..6a46d8bdc5 100644--- a/frontend/src/editor/core/components/tools/ToolPanel.css+++ b/frontend/src/editor/core/components/tools/ToolPanel.css@@ -15,7 +15,6 @@transition:width 0.3s ease,max-width 0.3s ease;- view-transition-name: tool-rail;user-select: none;}@@ -195,39 +194,41 @@margin-bottom: 0;}-/* Slightly recessed search field so it reads as distinct from the panel. */-.tool-panel__between-search input {- background-color: var(--c-surface-sunken);-}--::view-transition-old(tool-rail) {- animation: vt-rail-fade-out 180ms ease-out forwards;+/* Everything under the processor bar. The picker is the floor; the tool view+ is a layer over it that slides in from the trailing edge and back out. */+.tool-panel__stage {+ position: relative;+ flex: 1;+ min-height: 0;+ display: flex;+ flex-direction: column;+ overflow: hidden;}-::view-transition-new(tool-rail) {- animation: vt-rail-fade-in 220ms ease-in forwards;+.tool-panel__picker-layer,+.tool-panel__tool-layer {+ display: flex;+ flex-direction: column;+ min-height: 0;}-@keyframes vt-rail-fade-out {- to {- opacity: 0;- }+/* The picker's own stacking context, so its sticky headers and the search+ field's dropdown z-index cannot paint through the tool view above it. */+.tool-panel__picker-layer {+ flex: 1;+ isolation: isolate;}-@keyframes vt-rail-fade-in {- from {- opacity: 0;- }- to {- opacity: 1;- }+.tool-panel__tool-layer {+ position: absolute;+ inset: 0;+ z-index: 1;+ background: var(--c-surface);}-@media (prefers-reduced-motion: reduce) {- ::view-transition-old(tool-rail),- ::view-transition-new(tool-rail) {- animation-duration: 1ms !important;- }+/* Slightly recessed search field so it reads as distinct from the panel. */+.tool-panel__between-search input {+ background-color: var(--c-surface-sunken);}.tool-panel__mode-toggle {diff --git a/frontend/src/editor/core/components/tools/ToolPanel.tsx b/frontend/src/editor/core/components/tools/ToolPanel.tsxindex 8e5ded1790..a2d05cc362 100644--- a/frontend/src/editor/core/components/tools/ToolPanel.tsx+++ b/frontend/src/editor/core/components/tools/ToolPanel.tsx@@ -16,12 +16,13 @@ interface ToolPanelProps {allToolsView: boolean;/** Trigger to enter the all-tools view (from the "View all tools" button). */onShowAllTools: () => void;+ /** Tool-selection handler; falls back to the workflow context's handler. */+ onToolSelect?: (id: ToolId) => void;/**- * Tool-selection handler injected by {@code RightSidebar} so the click can- * be wrapped in a View Transition (the tool card morphs into the header- * pill). Falls back to the workflow context's handler when not provided.+ * Which view to render, overriding the workflow context. RightSidebar renders+ * both while the tool view slides over the picker or off it.*/- onToolSelect?: (id: ToolId) => void;+ view?: "toolPicker" | "toolContent";/** Whether to render the compact (favourites + recommended only) view. */compact?: boolean;/**@@ -39,6 +40,7 @@ export default function ToolPanel({onToolSelect,compact: compactProp,showSearch = false,+ view,}: ToolPanelProps) {const { t } = useTranslation();const {@@ -56,7 +58,7 @@ export default function ToolPanel({// Only offer the filter over the list itself; once a tool is open the panel// belongs to that tool. Deriving the results branch from the same flag keeps// the input and what it filters from drifting apart.- const onPicker = leftPanelView === "toolPicker";+ const onPicker = (view ?? leftPanelView) === "toolPicker";const panelSearch = showSearch && onPicker;const searching = searchQuery.trim().length > 0;@@ -84,7 +86,7 @@ export default function ToolPanel({searchQuery={searchQuery}/></div>- ) : leftPanelView === "toolPicker" ? (+ ) : onPicker ? (<div className="flex-1 flex flex-col overflow-auto"><ToolPickerselectedToolKey={selectedToolKey}diff --git a/frontend/src/editor/core/styles/theme.css b/frontend/src/editor/core/styles/theme.cssindex d43d6b4dc7..ce5de820d2 100644--- a/frontend/src/editor/core/styles/theme.css+++ b/frontend/src/editor/core/styles/theme.css@@ -888,15 +888,6 @@fill-opacity: 1;}-/* Snappier View-Transitions for FileEditor card reordering. Each thumbnail- * is tagged with `view-transition-name: file-card-<id>` (see- * FileEditorThumbnail.tsx); the browser FLIPs it between old and new- * positions on reorder. Override the sluggish 250ms default. */-::view-transition-group(*) {- animation-duration: 160ms;- animation-timing-function: cubic-bezier(0.2, 0, 0.2, 1);-}-/* Mantine animates a button's background-color and its text/icon colour on* separate transitions, so when a filled button flips state (selected ↔* unselected, enabled ↔ disabled) you briefly see e.g. a blue backgrounddiff --git a/frontend/src/editor/core/tests/stubbed/pdf-text-editor-unsaved-guard.spec.ts b/frontend/src/editor/core/tests/stubbed/pdf-text-editor-unsaved-guard.spec.tsindex 7ae0c0998b..24cd812db2 100644--- a/frontend/src/editor/core/tests/stubbed/pdf-text-editor-unsaved-guard.spec.ts+++ b/frontend/src/editor/core/tests/stubbed/pdf-text-editor-unsaved-guard.spec.ts@@ -160,4 +160,44 @@ test.describe("PDF text editor - unsaved-changes guard", () => {"a dropped file must not discard edits without asking",).toBeVisible({ timeout: 10_000 });});++ test("closing the tool asks before the tool view slides away", async ({+ page,+ }) => {+ test.setTimeout(180_000);+ await openEditorWithTwoFiles(page);+ await makeAnEdit(page);+ await page.evaluate(() => {+ const w = window as unknown as { __toolLayerLeft: boolean };+ w.__toolLayerLeft = false;+ new MutationObserver(() => {+ if (!document.querySelector(".tool-panel__tool-layer")) {+ w.__toolLayerLeft = true;+ }+ }).observe(document.body, { childList: true, subtree: true });+ });++ const close = page.getByRole("button", { name: "Back to all tools" });+ await close.click();+ await expect(page.getByTestId("unsaved-discard")).toBeVisible();+ await page.getByRole("button", { name: "Keep Working" }).click();++ await expect(page.getByTestId("unsaved-discard")).toBeHidden();+ await expect(page.getByTestId("pdf-editor-dirty-dot")).toBeVisible();+ expect(+ await page.evaluate(+ () =>+ (window as unknown as { __toolLayerLeft: boolean }).__toolLayerLeft,+ ),+ "the tool view must not leave before the user answers",+ ).toBe(false);++ await close.click();+ await page.getByTestId("unsaved-discard").click();+ await expect(+ page.locator('[data-tour="tool-button-compress"]'),+ ).toBeVisible();+ await expect(page.locator(".tool-panel__tool-layer")).toHaveCount(0);+ await expect(page.getByTestId("unsaved-discard")).toBeHidden();+ });});diff --git a/frontend/src/editor/core/ui/PanelHeader.tsx b/frontend/src/editor/core/ui/PanelHeader.tsxindex 6ba6d96177..d0c69eba15 100644--- a/frontend/src/editor/core/ui/PanelHeader.tsx+++ b/frontend/src/editor/core/ui/PanelHeader.tsx@@ -40,7 +40,7 @@ export interface PanelHeaderProps {/** Right-aligned content rendered inside the header bar, after the title* (e.g. a status badge). */actions?: ReactNode;- /** Applied to the inner header element — e.g. to set a view-transition-name. */+ /** Applied to the inner header element. */barClassName?: string;/** Applied to the outer header container. */className?: string;diff --git a/frontend/src/editor/core/utils/viewTransition.test.ts b/frontend/src/editor/core/utils/viewTransition.test.tsdeleted file mode 100644index 33ce1be268..0000000000--- a/frontend/src/editor/core/utils/viewTransition.test.ts+++ /dev/null@@ -1,63 +0,0 @@-import { describe, it, expect, vi, afterEach } from "vitest";-import { withViewTransition } from "@editor/utils/viewTransition";--// The stub carries only the field the helper reads, hence the cast through unknown.-type MutableDoc = { startViewTransition?: unknown };-const doc = document as unknown as MutableDoc;--function stubApi(): ReturnType<typeof vi.fn> {- const start = vi.fn((cb: () => void) => {- cb();- return { finished: Promise.resolve() };- });- doc.startViewTransition = start;- return start;-}--function stubReducedMotion(reduced: boolean): void {- vi.stubGlobal("matchMedia", (query: string) => ({- matches: reduced && query.includes("prefers-reduced-motion"),- media: query,- addEventListener: () => {},- removeEventListener: () => {},- }));-}--afterEach(() => {- delete doc.startViewTransition;- vi.unstubAllGlobals();-});--describe("withViewTransition", () => {- it("runs the update inside a transition when one is possible", async () => {- const start = stubApi();- stubReducedMotion(false);- const update = vi.fn();-- await withViewTransition(update);-- expect(start).toHaveBeenCalledTimes(1);- expect(update).toHaveBeenCalledTimes(1);- });-- it("skips the transition when the user asked for less motion", async () => {- // The state change must still happen - only the animation is dropped.- const start = stubApi();- stubReducedMotion(true);- const update = vi.fn();-- await withViewTransition(update);-- expect(start).not.toHaveBeenCalled();- expect(update).toHaveBeenCalledTimes(1);- });-- it("still applies the update where the API is unavailable", async () => {- stubReducedMotion(false);- const update = vi.fn();-- await withViewTransition(update);-- expect(update).toHaveBeenCalledTimes(1);- });-});diff --git a/frontend/src/editor/core/utils/viewTransition.ts b/frontend/src/editor/core/utils/viewTransition.tsdeleted file mode 100644index 85a05ca78d..0000000000--- a/frontend/src/editor/core/utils/viewTransition.ts+++ /dev/null@@ -1,25 +0,0 @@-import { flushSync } from "react-dom";--type ViewTransitionDoc = Document & {- startViewTransition?: (cb: () => void) => { finished: Promise<void> };-};--/** Runs a state update in a View Transition, plainly where that is unavailable. */-export function withViewTransition(update: () => void): Promise<void> {- if (typeof document === "undefined") {- update();- return Promise.resolve();- }- // Callers don't each check: reduced motion still gets the state change.- const reduced =- typeof window !== "undefined" &&- typeof window.matchMedia === "function" &&- window.matchMedia("(prefers-reduced-motion: reduce)").matches;-- const doc = document as ViewTransitionDoc;- if (doc.startViewTransition && !reduced) {- return doc.startViewTransition(() => flushSync(update)).finished;- }- update();- return Promise.resolve();-}