diff --git a/docs/ABSTRACTIONS.md b/docs/ABSTRACTIONS.md index 6fe73c1e..0d382332 100644 --- a/docs/ABSTRACTIONS.md +++ b/docs/ABSTRACTIONS.md @@ -157,9 +157,9 @@ interface VaultEntry { |---|---|---| | `markdown` or absent | `.md`, `.markdown` | Full Tolaria note model: frontmatter, BlockNote, raw editor, relationships, title sync | | `text` | UTF-8 editable formats such as `.yml`, `.json`, `.ts`, `.py`, `.sh` | Opens through the raw editor without Markdown note semantics | -| `binary` | Images, PDFs, archives, other non-text files | Stays a normal vault file; previewable images open in `FilePreview`, unsupported or broken binaries show an explicit fallback | +| `binary` | Images, PDFs, archives, other non-text files | Stays a normal vault file; previewable images and PDFs open in `FilePreview`, unsupported or broken binaries show an explicit fallback | -Image previewability is inferred in the renderer from the filename extension (`src/utils/filePreview.ts`) rather than stored as a new persisted kind. This keeps the filesystem as source of truth and avoids converting assets into proprietary objects. +Asset previewability is inferred in the renderer from the filename extension (`src/utils/filePreview.ts`) rather than stored as a new persisted kind. Supported images render through `` and supported PDFs render through the webview's PDF object renderer, both backed by Tauri asset URLs. This keeps the filesystem as source of truth and avoids converting assets into proprietary objects. ### Note Content Freshness diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index f10436f0..69861ae6 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -193,8 +193,8 @@ flowchart TD ``` - **Sidebar** (150-400px, resizable): Top-level filters (All Notes, Changes, Pulse), saved Views, collapsible type-based section groups, and a dedicated folder tree. The folder tree shows user-created folders plus default vault folders such as `attachments/` and `views/`; only the dedicated `type/` directory stays hidden because note types already have their own sidebar section. Saved Views persist a top-level YAML `order` field in each view file and use the same ordered-list mental model as Types: pointer users can drag the existing view row, while keyboard users can use command-palette move actions. The folder tree supports inline folder creation and rename, exposes a right-click menu for rename/delete plus filesystem reveal/copy-path actions, and auto-expands ancestor folders when the current selection or rename target is nested. Type sections and folder rows also act as note drop targets: dropping a note on a type updates its `type:` frontmatter, while dropping it on a folder runs the same crash-safe move path as the command palette flow. Each type can have a custom icon, color, sort, and visibility set via its type document in `type/`. -- **Note List / Pulse View** (200-500px, resizable): When a section group, filter, or saved view is selected, shows filtered notes with snippets, modified dates, status indicators, and per-context note-list controls. When `selection.kind === 'entity'`, the same pane enters **Neighborhood** mode: the source note is pinned at the top as a normal active row, outgoing relationship groups render first, inverse/backlink groups follow, empty groups stay visible with `0`, and duplicates across groups are allowed when multiple relationships are true. Plain click / `Enter` open the focused note without replacing the current Neighborhood, while Cmd/Ctrl-click and Cmd/Ctrl-`Enter` pivot the pane into the clicked note's Neighborhood. Folder-backed lists also show non-Markdown files: previewable image binaries get an image indicator and open in the editor pane, while unsupported binaries remain muted instead of auto-launching an external app. Saved views reuse the same sort and visible-column controls as the built-in lists, and those changes persist back into the view `.yml` definition (`sort`, `listPropertiesDisplay`). When Pulse filter is active, shows `PulseView` — a chronological git activity feed grouped by day. -- **Editor** (flex, fills remaining space): Single note open at a time (no tabs — see ADR-0003). Breadcrumb bar with word count and note-layout toggle, BlockNote rich text editor with wikilink support, Markdown-compatible inline/display math rendering, first-class Mermaid diagram blocks, markdown-safe formatting controls, and schema-backed fenced code block highlighting via `@blocknote/code-block`. Can toggle to diff view (modified files), raw CodeMirror view, or a wide-screen left-aligned note column while preserving the same readable max width. Binary image files render through `FilePreview` as ordinary vault files using Tauri asset URLs, with explicit unsupported/broken fallback states and keyboard focus returning to the note list on `Escape`. Decomposed into `Editor` (orchestrator), `EditorContent`, `FilePreview`, `EditorRightPanel`, `SingleEditorView`, with hooks `useDiffMode`, `useEditorFocus`, and `useEditorSave`, plus the `useRawMode`/`RawEditorView` pair for markdown source editing. Rich BlockNote input and raw CodeMirror input both route typed `->`, `<-`, and `<->` through the shared `src/utils/arrowLigatures.ts` resolver so arrow ligatures stay consistent across mode switches while escaped ASCII sequences remain literal. Navigation history (Cmd+[/]) replaces tabs. +- **Note List / Pulse View** (200-500px, resizable): When a section group, filter, or saved view is selected, shows filtered notes with snippets, modified dates, status indicators, and per-context note-list controls. When `selection.kind === 'entity'`, the same pane enters **Neighborhood** mode: the source note is pinned at the top as a normal active row, outgoing relationship groups render first, inverse/backlink groups follow, empty groups stay visible with `0`, and duplicates across groups are allowed when multiple relationships are true. Plain click / `Enter` open the focused note without replacing the current Neighborhood, while Cmd/Ctrl-click and Cmd/Ctrl-`Enter` pivot the pane into the clicked note's Neighborhood. Folder-backed lists also show non-Markdown files: previewable image and PDF binaries get file indicators and open in the editor pane, while unsupported binaries remain muted instead of auto-launching an external app. Saved views reuse the same sort and visible-column controls as the built-in lists, and those changes persist back into the view `.yml` definition (`sort`, `listPropertiesDisplay`). When Pulse filter is active, shows `PulseView` — a chronological git activity feed grouped by day. +- **Editor** (flex, fills remaining space): Single note open at a time (no tabs — see ADR-0003). Breadcrumb bar with word count and note-layout toggle, BlockNote rich text editor with wikilink support, Markdown-compatible inline/display math rendering, first-class Mermaid diagram blocks, markdown-safe formatting controls, and schema-backed fenced code block highlighting via `@blocknote/code-block`. Can toggle to diff view (modified files), raw CodeMirror view, or a wide-screen left-aligned note column while preserving the same readable max width. Binary image and PDF files render through `FilePreview` as ordinary vault files using Tauri asset URLs, with explicit unsupported/broken fallback states and keyboard focus returning to the note list on `Escape`. Decomposed into `Editor` (orchestrator), `EditorContent`, `FilePreview`, `EditorRightPanel`, `SingleEditorView`, with hooks `useDiffMode`, `useEditorFocus`, and `useEditorSave`, plus the `useRawMode`/`RawEditorView` pair for markdown source editing. Rich BlockNote input and raw CodeMirror input both route typed `->`, `<-`, and `<->` through the shared `src/utils/arrowLigatures.ts` resolver so arrow ligatures stay consistent across mode switches while escaped ASCII sequences remain literal. Navigation history (Cmd+[/]) replaces tabs. - **Inspector / AI Agent** (200-500px or 40px collapsed): Toggles between Inspector (frontmatter, relationships, instances, backlinks, git history) and AI Agent panel (the selected CLI agent with tool execution). The Sparkle icon in the breadcrumb bar toggles between them. Per-note `icon` is a suggested Inspector property and the command palette's "Set Note Icon" action opens that field directly. When viewing a Type note, the Inspector shows an **Instances** section listing all notes of that type (sorted by modified_at desc, capped at 50). Panels are separated by `ResizeHandle` components that support drag-to-resize. diff --git a/docs/adr/0098-in-app-image-and-pdf-file-previews.md b/docs/adr/0098-in-app-image-and-pdf-file-previews.md new file mode 100644 index 00000000..6e83cfd9 --- /dev/null +++ b/docs/adr/0098-in-app-image-and-pdf-file-previews.md @@ -0,0 +1,28 @@ +--- +type: ADR +id: "0098" +title: "In-app image and PDF previews for binary vault files" +status: active +date: 2026-04-29 +supersedes: "0086" +--- + +## Context + +ADR-0086 introduced the `FilePreview` path for image binaries while keeping binary files as ordinary `VaultEntry` records. The same file-first model should now cover PDFs, because asset-heavy vaults often mix screenshots, diagrams, and document exports that users need to inspect without leaving Tolaria. + +## Decision + +**Tolaria previews supported image and PDF files in the editor pane while keeping them as ordinary binary vault files.** + +- The scanner keeps the coarse `fileKind: "binary"` representation. Previewability stays a renderer concern inferred from the file extension in `src/utils/filePreview.ts`. +- Supported images render with `` and supported PDFs render with the webview PDF object renderer, both using Tauri asset URLs from `convertFileSrc`. +- PDF preview fallback content lives inside the PDF object so unsupported or failed renderers still expose an explicit "Open in default app" escape hatch. +- Note-list rows for previewable images and PDFs remain clickable and carry file-specific indicators; unsupported binary rows stay muted and non-clickable. +- `Escape` on the preview surface returns keyboard focus to the note list, matching the existing image-preview keyboard behavior. + +## Consequences + +- PDFs do not become notes and do not get Markdown editor semantics. +- The asset preview surface can keep growing to additional safe binary formats without changing the vault scanner or persisted cache shape. +- Broken PDFs may rely on the webview's own renderer failure state, but the surrounding Tolaria preview chrome still provides reveal, copy path, and default-app actions. diff --git a/docs/adr/README.md b/docs/adr/README.md index e53bf792..2ff5fe1f 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -149,3 +149,4 @@ proposed → active → superseded | [0094](0094-gitignored-content-visibility-boundary-filter.md) | Gitignored content visibility as a command-boundary filter | active | | [0095](0095-saved-view-order-field.md) | Saved views use an explicit YAML order field | active | | [0097](0097-gemini-cli-agent-adapter.md) | Gemini CLI agent adapter | active | +| [0098](0098-in-app-image-and-pdf-file-previews.md) | In-app image and PDF previews for binary vault files | active | diff --git a/src/components/Editor.test.tsx b/src/components/Editor.test.tsx index edac9b3a..d3ec3b4e 100644 --- a/src/components/Editor.test.tsx +++ b/src/components/Editor.test.tsx @@ -284,6 +284,28 @@ describe('Editor', () => { expect(screen.queryByTestId('blocknote-view')).not.toBeInTheDocument() }) + it('renders an in-app PDF preview for binary PDF tabs', () => { + const pdfEntry: VaultEntry = { + ...mockEntry, + path: '/vault/assets/report.pdf', + filename: 'report.pdf', + title: 'report.pdf', + fileKind: 'binary', + } + + renderEditor({ + tabs: [{ entry: pdfEntry, content: '' }], + activeTabPath: pdfEntry.path, + entries: [pdfEntry], + }) + + expect(screen.getByTestId('pdf-file-preview')).toHaveAttribute( + 'data', + 'asset://localhost/%2Fvault%2Fassets%2Freport.pdf', + ) + expect(screen.queryByTestId('blocknote-view')).not.toBeInTheDocument() + }) + it('shows a graceful fallback when an image preview fails to render', () => { const imageEntry: VaultEntry = { ...mockEntry, diff --git a/src/components/FilePreview.test.tsx b/src/components/FilePreview.test.tsx index 59bc0872..5ef7d12c 100644 --- a/src/components/FilePreview.test.tsx +++ b/src/components/FilePreview.test.tsx @@ -40,6 +40,12 @@ const imageEntry: VaultEntry = { hasH1: false, fileKind: 'binary', } +const pdfEntry: VaultEntry = { + ...imageEntry, + path: '/vault/Attachments/report.pdf', + filename: 'report.pdf', + title: 'report.pdf', +} describe('FilePreview', () => { it('routes header file actions to the active file path', () => { @@ -64,4 +70,24 @@ describe('FilePreview', () => { expect(onCopyFilePath).toHaveBeenCalledWith('/vault/Attachments/photo.png') expect(onOpenExternalFile).toHaveBeenCalledWith('/vault/Attachments/photo.png') }) + + it('renders supported PDF files through the asset preview path', () => { + render() + + expect(screen.getByTestId('pdf-file-preview')).toHaveAttribute('data', 'asset:///vault/Attachments/report.pdf') + expect(screen.getByText('PDF file')).toBeInTheDocument() + }) + + it('renders supported PDFs when binary metadata is unavailable', () => { + render() + + expect(screen.getByTestId('pdf-file-preview')).toHaveAttribute('data', 'asset:///vault/Attachments/report.pdf') + }) + + it('provides a graceful fallback when a PDF preview cannot render', () => { + render() + + expect(screen.getByTestId('file-preview-fallback')).toHaveTextContent('PDF preview failed') + expect(screen.getByRole('button', { name: 'Open in default app' })).toBeInTheDocument() + }) }) diff --git a/src/components/FilePreview.tsx b/src/components/FilePreview.tsx index 10e02124..3c16562d 100644 --- a/src/components/FilePreview.tsx +++ b/src/components/FilePreview.tsx @@ -1,8 +1,8 @@ import { useCallback, useMemo, useState, type KeyboardEvent } from 'react' import { convertFileSrc } from '@tauri-apps/api/core' -import { ArrowSquareOut, ClipboardText, FileDashed, FolderOpen, ImageSquare, WarningCircle } from '@phosphor-icons/react' +import { ArrowSquareOut, ClipboardText, FileDashed, FilePdf, FolderOpen, ImageSquare, WarningCircle } from '@phosphor-icons/react' import type { VaultEntry } from '../types' -import { isImagePreviewEntry, previewFileTypeLabel } from '../utils/filePreview' +import { filePreviewKind, previewFileTypeLabel, type FilePreviewKind } from '../utils/filePreview' import { focusNoteListContainer } from '../utils/neighborhoodHistory' import { openLocalFile } from '../utils/url' import { Button } from './ui/button' @@ -21,6 +21,42 @@ interface FilePreviewFallbackProps { onOpenExternal: () => void } +function fallbackContentForPreviewKind(previewKind: FilePreviewKind | null): Omit { + if (previewKind === 'image') { + return { + icon: 'warning', + title: 'Image preview failed', + description: 'Tolaria could not render this image file in the preview.', + } + } + + if (previewKind === 'pdf') { + return { + icon: 'warning', + title: 'PDF preview failed', + description: 'Tolaria could not render this PDF file in the preview.', + } + } + + return { + icon: 'file', + title: 'Preview unavailable', + description: 'Tolaria does not have an in-app preview for this file type.', + } +} + +function FilePreviewHeaderIcon({ previewKind }: { previewKind: FilePreviewKind | null }) { + if (previewKind === 'image') { + return