#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
Add search buttons to PDF Library and Tools panes (#8156)
James Bruntonf40cff1b3cf5
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex 2e22a037a7..eab7d7d35e 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -4453,6 +4453,7 @@ openFromComputer = "Open from computer"openSettings = "Open settings"other = "Other"recent = "Recent"+searchFiles = "Search files"uploadFailedBody = "Could not add the selected files."uploadFailedTitle = "Upload failed"viewAll = "View all {{count}} files"@@ -12320,6 +12321,7 @@ goBack = "Go back"pdfTools = "PDF Tools"placeholder = "Choose a tool to get started"premiumFeature = "Premium feature:"+searchTools = "Search tools"toolsHeader = "Tools"viewAllTools = "View all tools"diff --git a/frontend/editor/src/core/components/shared/FileSidebar.css b/frontend/editor/src/core/components/shared/FileSidebar.cssindex 3af15cc149..85cd2a599c 100644--- a/frontend/editor/src/core/components/shared/FileSidebar.css+++ b/frontend/editor/src/core/components/shared/FileSidebar.css@@ -515,6 +515,13 @@padding: 0 6px 2px 6px;margin: 0;flex-shrink: 0;+ /* Ruled only once files scroll beneath it. */+ border-bottom: 1px solid transparent;+ transition: border-color 0.12s ease;+}++.file-sidebar-section-header[data-scrolled] {+ border-bottom-color: var(--c-border-subtle);}.file-sidebar-section-label {@@ -606,15 +613,11 @@pointer-events: auto;}-/* Whichever add control comes first takes the gap, so the pair stays together- at the end of the header row. */-.file-sidebar-section-btn-drive,-.file-sidebar-section-btn-add {+/* Search leads the trailing cluster and takes the gap, so it and the add+ controls stay together at the end of the header row. */+.file-sidebar-section-btn-search {margin-left: auto;}-.file-sidebar-section-btn-drive + .file-sidebar-section-btn-add {- margin-left: 0;-}/* Rows are conditionally rendered, so they fade in with an animation rather thana transition, which has nothing to run from. */diff --git a/frontend/editor/src/core/components/shared/FileSidebar.tsx b/frontend/editor/src/core/components/shared/FileSidebar.tsxindex f2def18eff..9ed868c4f5 100644--- a/frontend/editor/src/core/components/shared/FileSidebar.tsx+++ b/frontend/editor/src/core/components/shared/FileSidebar.tsx@@ -57,9 +57,11 @@ import {import { fileStorage, onRecordUnreadable } from "@app/services/fileStorage";import { downloadFileWithPolicy } from "@app/services/exportWithPolicy";import { useOpenInNewWindow } from "@app/extensions/openInNewWindow";+import { openSuperSearch } from "@app/components/shared/superSearch/openSuperSearch";import { alert } from "@app/components/toast";import { useBulkAddProgress } from "@app/services/bulkAddProgress";import { useFolderMembership } from "@app/hooks/useFolderMembership";+import { useIsScrolled } from "@app/hooks/useIsScrolled";import { useAllWatchedFolders } from "@app/hooks/useAllWatchedFolders";import { usePolicyFileBadges } from "@app/hooks/usePolicyFileBadges";import {@@ -185,6 +187,8 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(const [pendingViewFileId, setPendingViewFileId] = useState<string | null>(null,);+ const { scrolled: fileListScrolled, scrollRef: fileListScrollRef } =+ useIsScrolled();const { config } = useAppConfig();const {@@ -1071,7 +1075,10 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>({currentWorkbench !== "myFiles" && (<div className="file-sidebar-files-section sidebar-content-fade">- <div className="file-sidebar-section-header">+ <div+ className="file-sidebar-section-header"+ data-scrolled={fileListScrolled || undefined}+ ><span className="file-sidebar-section-label">{t("fileSidebar.library", "PDF Library")}</span>@@ -1092,6 +1099,16 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(><Icon name="maximize-2" size={"1rem"} /></ActionIcon>+ <ActionIcon+ variant="quiet"+ className="file-sidebar-section-btn file-sidebar-section-btn-search"+ onClick={() => openSuperSearch(["files"])}+ title={t("fileSidebar.searchFiles", "Search files")}+ aria-label={t("fileSidebar.searchFiles", "Search files")}+ data-testid="file-sidebar-search"+ >+ <Icon name="search" size={"1rem"} />+ </ActionIcon>{importActions}</div>@@ -1102,7 +1119,10 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(<Loader size="sm" color="var(--c-text-subtle)" /></div>) : allFileStubs.length > 0 ? (- <div className="file-sidebar-file-list">+ <div+ className="file-sidebar-file-list"+ ref={fileListScrollRef}+ >{fileGroups ? (<>{fileGroups.map((group) => {diff --git a/frontend/editor/src/core/components/shared/superSearch/SuperSearch.test.tsx b/frontend/editor/src/core/components/shared/superSearch/SuperSearch.test.tsxindex 931c87197f..c551878ea5 100644--- a/frontend/editor/src/core/components/shared/superSearch/SuperSearch.test.tsx+++ b/frontend/editor/src/core/components/shared/superSearch/SuperSearch.test.tsx@@ -1,6 +1,12 @@import { useEffect, useState } from "react";import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";-import { fireEvent, render, screen, waitFor } from "@testing-library/react";+import {+ act,+ fireEvent,+ render,+ screen,+ waitFor,+} from "@testing-library/react";import { MantineProvider } from "@mantine/core";vi.mock("@app/hooks/useSuperSearch", () => ({@@ -16,6 +22,7 @@ vi.mock("@app/utils/hotkeys", () => ({}));import SuperSearch from "@app/components/shared/superSearch/SuperSearch";+import { openSuperSearch } from "@app/components/shared/superSearch/openSuperSearch";import type {SuperSearchQueryOptions,SuperSearchScope,@@ -328,6 +335,39 @@ describe("SuperSearch", () => {});});+ it("opens on request with the requested scopes preselected", async () => {+ // jsdom lays nothing out, so every element would read as off-screen.+ vi.spyOn(HTMLElement.prototype, "offsetParent", "get").mockReturnValue(+ document.body,+ );+ const useResults = vi.fn<TestUseResultsHook>(() => ({+ groups: [],+ flatResults: [],+ loadingFiles: false,+ }));++ renderSearch(useResults, TEST_SCOPES);++ const input = screen.getByRole("combobox");+ act(() => openSuperSearch(["portal-pipelines"]));++ await waitFor(() => {+ expect(input).toHaveFocus();+ expect(input).toHaveAttribute("aria-expanded", "true");+ });+ expect(screen.getByRole("button", { name: "Pipelines" })).toHaveAttribute(+ "aria-pressed",+ "true",+ );+ expect(screen.getByRole("button", { name: "Policies" })).toHaveAttribute(+ "aria-pressed",+ "false",+ );+ expect(useResults).toHaveBeenLastCalledWith("", true, {+ scopeIds: ["portal-pipelines"],+ });+ });+it("shows no-results below scoped filters before typing", async () => {const useResults: TestUseResultsHook = () => ({groups: [],diff --git a/frontend/editor/src/core/components/shared/superSearch/SuperSearch.tsx b/frontend/editor/src/core/components/shared/superSearch/SuperSearch.tsxindex 80161240bc..d917f3f3fd 100644--- a/frontend/editor/src/core/components/shared/superSearch/SuperSearch.tsx+++ b/frontend/editor/src/core/components/shared/superSearch/SuperSearch.tsx@@ -25,6 +25,10 @@ import {parseSuperSearchQuery,rebuildSuperSearchQuery,} from "@app/components/shared/superSearch/superSearchFilters";+import {+ SUPER_SEARCH_FOCUS_EVENT,+ type SuperSearchFocusDetail,+} from "@app/components/shared/superSearch/openSuperSearch";import "@app/components/shared/superSearch/SuperSearch.css";import { Icon } from "@app/ui/Icon";@@ -280,7 +284,7 @@ export default function SuperSearch({// Leave the shortcut alone while a modal owns the screen — focusing an// input underneath the overlay would strand keyboard focus. Modals that// want to cede to the search (the settings modal does) close themselves- // and dispatch "superSearch:focus" instead.+ // and call openSuperSearch() instead.const target = e.target as HTMLElement | null;if (target?.closest('[role="dialog"]')) return;e.preventDefault();@@ -288,16 +292,26 @@ export default function SuperSearch({inputRef.current?.focus();inputRef.current?.select();};- // Focus handover from a closing dialog. Only the on-screen instance- // responds (offsetParent is null while a host is display:none / unmounted).- const onFocusRequest = () => {+ // Focus handover from a closing dialog or a search button elsewhere. Only+ // the on-screen instance responds (offsetParent is null while a host is+ // display:none / unmounted).+ const onFocusRequest = (e: Event) => {const input = inputRef.current;if (!input || input.offsetParent === null) return;+ const detail: SuperSearchFocusDetail | null =+ e instanceof CustomEvent ? e.detail : null;+ if (detail?.scopeIds) setManualScopeIds([...detail.scopeIds]);setOpen(true);+ // Skips when already focused: re-selecting would let the next keystroke+ // replace whatever was typed since the first grab.const grab = () => {+ if (document.activeElement === input) return;input.focus();input.select();};+ // Immediately, so typing straight after a button click lands in the+ // input rather than on the button.+ grab();requestAnimationFrame(() =>requestAnimationFrame(() => {grab();@@ -312,10 +326,10 @@ export default function SuperSearch({);};window.addEventListener("keydown", onKeyDown);- window.addEventListener("superSearch:focus", onFocusRequest);+ window.addEventListener(SUPER_SEARCH_FOCUS_EVENT, onFocusRequest);return () => {window.removeEventListener("keydown", onKeyDown);- window.removeEventListener("superSearch:focus", onFocusRequest);+ window.removeEventListener(SUPER_SEARCH_FOCUS_EVENT, onFocusRequest);};}, []);diff --git a/frontend/editor/src/core/components/shared/superSearch/openSuperSearch.ts b/frontend/editor/src/core/components/shared/superSearch/openSuperSearch.tsnew file mode 100644index 0000000000..ba01559bc8--- /dev/null+++ b/frontend/editor/src/core/components/shared/superSearch/openSuperSearch.ts@@ -0,0 +1,18 @@+export const SUPER_SEARCH_FOCUS_EVENT = "superSearch:focus";++export interface SuperSearchFocusDetail {+ /** Scope chips to preselect, replacing any the user had picked. */+ scopeIds?: readonly string[];+}++/**+ * Opens and focuses whichever super search is on screen. A no-op when none is,+ * so only call it from surfaces that sit alongside one.+ */+export function openSuperSearch(scopeIds?: readonly string[]) {+ window.dispatchEvent(+ new CustomEvent<SuperSearchFocusDetail>(SUPER_SEARCH_FOCUS_EVENT, {+ detail: { scopeIds },+ }),+ );+}diff --git a/frontend/editor/src/core/components/tools/ToolPanel.css b/frontend/editor/src/core/components/tools/ToolPanel.cssindex a6322ef0fc..c81f4d733c 100644--- a/frontend/editor/src/core/components/tools/ToolPanel.css+++ b/frontend/editor/src/core/components/tools/ToolPanel.css@@ -158,6 +158,24 @@margin: 0;}+/* Title inset matches the section headings' text below it. */+.tool-panel__list-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 0.5rem;+ flex-shrink: 0;+ padding: 0.5rem var(--mantine-spacing-sm) 0.25rem+ calc(var(--mantine-spacing-sm) + 0.5rem);+}++.tool-panel__list-title {+ font-size: 0.875rem;+ font-weight: 600;+ letter-spacing: -0.01em;+ color: var(--c-text);+}+.tool-panel__compact-header-actions {display: flex;align-items: center;diff --git a/frontend/editor/src/core/components/tools/ToolPanel.tsx b/frontend/editor/src/core/components/tools/ToolPanel.tsxindex d51ec9e0bf..0f04e2f2b2 100644--- a/frontend/editor/src/core/components/tools/ToolPanel.tsx+++ b/frontend/editor/src/core/components/tools/ToolPanel.tsx@@ -6,6 +6,9 @@ import SearchResults from "@app/components/tools/SearchResults";import ToolRenderer from "@app/components/tools/ToolRenderer";import ToolSearch from "@app/components/tools/toolPicker/ToolSearch";import { ToolPanelViewerBar } from "@app/components/tools/ToolPanelViewerBar";+import { openSuperSearch } from "@app/components/shared/superSearch/openSuperSearch";+import { ActionIcon } from "@app/ui/ActionIcon";+import { Icon } from "@app/ui/Icon";import { ToolId } from "@app/types/toolId";interface ToolPanelProps {@@ -23,7 +26,8 @@ interface ToolPanelProps {compact?: boolean;/*** Render a tool filter at the head of the panel. Set where the workbench- * bar's super search is out of reach, so the list stays searchable in place.+ * bar's super search is out of reach, so the list stays searchable in place;+ * otherwise the head is a header whose button opens the super search on tools.*/showSearch?: boolean;}@@ -52,7 +56,8 @@ 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 panelSearch = showSearch && leftPanelView === "toolPicker";+ const onPicker = leftPanelView === "toolPicker";+ const panelSearch = showSearch && onPicker;const searching = searchQuery.trim().length > 0;return (@@ -88,6 +93,26 @@ export default function ToolPanel({isSearching={searching}compact={compactProp ?? !allToolsView}onShowAllTools={onShowAllTools}+ header={+ !showSearch && (+ <div className="tool-panel__list-header">+ <span className="tool-panel__list-title">+ {t("toolPanel.toolsHeader", "Tools")}+ </span>+ <ActionIcon+ variant="quiet"+ accent="neutral"+ size="sm"+ onClick={() => openSuperSearch(["tools"])}+ title={t("toolPanel.searchTools", "Search tools")}+ aria-label={t("toolPanel.searchTools", "Search tools")}+ data-testid="tool-panel-search"+ >+ <Icon name="search" size="1rem" />+ </ActionIcon>+ </div>+ )+ }/></div>) : (diff --git a/frontend/editor/src/core/components/tools/ToolPicker.tsx b/frontend/editor/src/core/components/tools/ToolPicker.tsxindex 5c5ce0e261..b3a48c386a 100644--- a/frontend/editor/src/core/components/tools/ToolPicker.tsx+++ b/frontend/editor/src/core/components/tools/ToolPicker.tsx@@ -1,4 +1,4 @@-import React, { useMemo, useRef } from "react";+import React, { useMemo } from "react";import { Box, Stack } from "@mantine/core";import { useTranslation } from "react-i18next";import { Button } from "@app/ui/Button";@@ -12,6 +12,7 @@ import { renderToolButtons } from "@app/components/tools/shared/renderToolButtonimport ToolButton from "@app/components/tools/toolPicker/ToolButton";import { useToolWorkflowData } from "@app/contexts/ToolWorkflowContext";import { useSigningBadgeCount } from "@app/hooks/signing/useSigningBadgeCount";+import { useIsScrolled } from "@app/hooks/useIsScrolled";import { ToolId } from "@app/types/toolId";import { getSubcategoryLabel } from "@app/data/toolsTaxonomy";import { ToolPickerFooterExtensions } from "@app/components/tools/toolPicker/ToolPickerFooterExtensions";@@ -28,6 +29,8 @@ interface ToolPickerProps {compact?: boolean;/** Called when the user clicks "View all tools" in compact mode. */onShowAllTools?: () => void;+ /** Pinned above the list; gains a rule once rows scroll beneath it. */+ header?: React.ReactNode;}const EMPTY_FILTERED_TOOLS: ToolPickerProps["filteredTools"] = [];@@ -65,10 +68,11 @@ const ToolPicker = ({isSearching = false,compact = false,onShowAllTools,+ header,}: ToolPickerProps) => {const { t } = useTranslation();- const scrollableRef = useRef<HTMLDivElement>(null);+ const { scrolled, scrollRef } = useIsScrolled();const { sections: visibleSections } = useToolSections(filteredTools);const { favoriteTools, toolRegistry } = useToolWorkflowData();@@ -116,8 +120,16 @@ const ToolPicker = ({return (<Box h="100%" style={CONTAINER_STYLE}>+ {header && (+ <div+ className="tool-picker__header"+ data-scrolled={scrolled || undefined}+ >+ {header}+ </div>+ )}<Box- ref={scrollableRef}+ ref={scrollRef}style={SCROLLABLE_STYLE}className="tool-picker-scrollable">diff --git a/frontend/editor/src/core/components/tools/toolPicker/ToolPicker.css b/frontend/editor/src/core/components/tools/toolPicker/ToolPicker.cssindex b3b8fe3a2b..607c18e62a 100644--- a/frontend/editor/src/core/components/tools/toolPicker/ToolPicker.css+++ b/frontend/editor/src/core/components/tools/toolPicker/ToolPicker.css@@ -135,3 +135,19 @@.tool-picker__view-all {margin-top: 0.75rem;}++/* The rule only appears once rows scroll beneath the header, so a list at+ rest has no line separating nothing. Stacked over the scroller, whose+ negative top margin would otherwise paint rows over the rule. */+.tool-picker__header {+ position: relative;+ z-index: 1;+ flex-shrink: 0;+ background: var(--c-surface);+ border-bottom: 1px solid transparent;+ transition: border-color 0.12s ease;+}++.tool-picker__header[data-scrolled] {+ border-bottom-color: var(--c-border-subtle);+}diff --git a/frontend/editor/src/core/components/viewer/readerRail/ReaderSuperSearch.tsx b/frontend/editor/src/core/components/viewer/readerRail/ReaderSuperSearch.tsxindex 53584f738c..026741aabe 100644--- a/frontend/editor/src/core/components/viewer/readerRail/ReaderSuperSearch.tsx+++ b/frontend/editor/src/core/components/viewer/readerRail/ReaderSuperSearch.tsx@@ -1,6 +1,7 @@import { useCallback, useEffect, useRef, useState } from "react";import SuperSearch from "@app/components/shared/superSearch/SuperSearch";+import { openSuperSearch } from "@app/components/shared/superSearch/openSuperSearch";import { useEditorSearchScopes } from "@app/hooks/useSuperSearch";import "@app/components/viewer/readerRail/ReaderSuperSearch.css";@@ -35,9 +36,7 @@ export function ReaderSuperSearch() {// once it has a box on screen to be focused in.useEffect(() => {if (!open) return;- const handoff = requestAnimationFrame(() =>- window.dispatchEvent(new Event("superSearch:focus")),- );+ const handoff = requestAnimationFrame(() => openSuperSearch());return () => cancelAnimationFrame(handoff);}, [open]);diff --git a/frontend/editor/src/core/hooks/useIsScrolled.test.tsx b/frontend/editor/src/core/hooks/useIsScrolled.test.tsxnew file mode 100644index 0000000000..4aa6459cf1--- /dev/null+++ b/frontend/editor/src/core/hooks/useIsScrolled.test.tsx@@ -0,0 +1,44 @@+import { describe, expect, it } from "vitest";+import { fireEvent, render, screen } from "@testing-library/react";+import { useIsScrolled } from "@app/hooks/useIsScrolled";++function Harness({ mounted }: { mounted: boolean }) {+ const { scrolled, scrollRef } = useIsScrolled();+ return (+ <>+ <span data-testid="scrolled">{String(scrolled)}</span>+ {mounted && <div data-testid="scroller" ref={scrollRef} />}+ </>+ );+}++function scrollTo(el: HTMLElement, top: number) {+ Object.defineProperty(el, "scrollTop", { value: top, configurable: true });+ fireEvent.scroll(el);+}++describe("useIsScrolled", () => {+ it("tracks whether the scroller is off its top", () => {+ render(<Harness mounted />);+ const scroller = screen.getByTestId("scroller");+ expect(screen.getByTestId("scrolled")).toHaveTextContent("false");++ scrollTo(scroller, 40);+ expect(screen.getByTestId("scrolled")).toHaveTextContent("true");++ scrollTo(scroller, 0);+ expect(screen.getByTestId("scrolled")).toHaveTextContent("false");+ });++ it("resets when the scroller detaches, so a remount starts unruled", () => {+ const { rerender } = render(<Harness mounted />);+ scrollTo(screen.getByTestId("scroller"), 40);+ expect(screen.getByTestId("scrolled")).toHaveTextContent("true");++ rerender(<Harness mounted={false} />);+ expect(screen.getByTestId("scrolled")).toHaveTextContent("false");++ rerender(<Harness mounted />);+ expect(screen.getByTestId("scrolled")).toHaveTextContent("false");+ });+});diff --git a/frontend/editor/src/core/hooks/useIsScrolled.ts b/frontend/editor/src/core/hooks/useIsScrolled.tsnew file mode 100644index 0000000000..a440eda50d--- /dev/null+++ b/frontend/editor/src/core/hooks/useIsScrolled.ts@@ -0,0 +1,22 @@+import { useCallback, useState } from "react";++/**+ * Whether a scroller has moved off its top, for a header pinned above it to+ * show a divider. Attach `scrollRef` to the scroller. Detaching it resets to+ * false, so a list that unmounts and comes back at the top does not inherit a+ * stale divider from its last visit.+ */+export function useIsScrolled() {+ const [scrolled, setScrolled] = useState(false);+ const scrollRef = useCallback((el: HTMLElement | null) => {+ if (!el) return;+ const update = () => setScrolled(el.scrollTop > 0);+ update();+ el.addEventListener("scroll", update, { passive: true });+ return () => {+ el.removeEventListener("scroll", update);+ setScrolled(false);+ };+ }, []);+ return { scrolled, scrollRef };+}diff --git a/frontend/editor/src/core/tests/stubbed/super-search.spec.ts b/frontend/editor/src/core/tests/stubbed/super-search.spec.tsindex d91e074bae..374d4c428d 100644--- a/frontend/editor/src/core/tests/stubbed/super-search.spec.ts+++ b/frontend/editor/src/core/tests/stubbed/super-search.spec.ts@@ -201,7 +201,9 @@ test.describe("Super search — user without Processor access", () => {const input = await openSearch(page);// Chip row: the editor lanes only. No Processor lanes of any kind.- await expect(page.getByRole("button", { name: "Tools" })).toBeVisible();+ await expect(+ page.getByRole("button", { name: "Tools", exact: true }),+ ).toBeVisible();for (const lane of ["Pages","Users",