From 57b38fe2c70941f98dc8ab611342a4f9b577e024 Mon Sep 17 00:00:00 2001 From: rehlert Date: Thu, 27 Aug 2026 18:15:22 +0200 Subject: [PATCH] bea settings --- agents.md | 28 +- package.json | 2 +- plan/subdocuments-plan.md | 256 ---------------- pnpm-lock.yaml | 17 +- .../components/BeaWorkspaceControls.svelte | 230 ++++++++++++++ src/lib/components/ZipDropzone.svelte | 3 +- src/lib/components/ZipFilePicker.svelte | 62 ++++ .../alert-dialog/alert-dialog-action.svelte | 27 ++ .../alert-dialog/alert-dialog-cancel.svelte | 27 ++ .../alert-dialog/alert-dialog-content.svelte | 32 ++ .../alert-dialog-description.svelte | 20 ++ .../alert-dialog/alert-dialog-footer.svelte | 23 ++ .../alert-dialog/alert-dialog-header.svelte | 23 ++ .../ui/alert-dialog/alert-dialog-media.svelte | 23 ++ .../alert-dialog/alert-dialog-overlay.svelte | 20 ++ .../alert-dialog/alert-dialog-portal.svelte | 7 + .../ui/alert-dialog/alert-dialog-title.svelte | 20 ++ .../alert-dialog/alert-dialog-trigger.svelte | 7 + .../ui/alert-dialog/alert-dialog.svelte | 7 + src/lib/components/ui/alert-dialog/index.ts | 40 +++ src/lib/components/ui/popover/index.ts | 28 ++ .../ui/popover/popover-close.svelte | 7 + .../ui/popover/popover-content.svelte | 31 ++ .../ui/popover/popover-description.svelte | 20 ++ .../ui/popover/popover-header.svelte | 20 ++ .../ui/popover/popover-portal.svelte | 7 + .../ui/popover/popover-title.svelte | 15 + .../ui/popover/popover-trigger.svelte | 17 ++ src/lib/components/ui/popover/popover.svelte | 7 + src/lib/components/ui/separator/index.ts | 7 + .../components/ui/separator/separator.svelte | 23 ++ src/lib/components/ui/slider/index.ts | 7 + src/lib/components/ui/slider/slider.svelte | 57 ++++ src/lib/zip-selection.ts | 6 + src/routes/tools/bea/+page.svelte | 81 ++--- tests/e2e/toolbox.spec.ts | 280 ++++++++++++++++++ 36 files changed, 1159 insertions(+), 328 deletions(-) delete mode 100644 plan/subdocuments-plan.md create mode 100644 src/lib/components/BeaWorkspaceControls.svelte create mode 100644 src/lib/components/ZipFilePicker.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-action.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-content.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-description.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-header.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-media.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-title.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog-trigger.svelte create mode 100644 src/lib/components/ui/alert-dialog/alert-dialog.svelte create mode 100644 src/lib/components/ui/alert-dialog/index.ts create mode 100644 src/lib/components/ui/popover/index.ts create mode 100644 src/lib/components/ui/popover/popover-close.svelte create mode 100644 src/lib/components/ui/popover/popover-content.svelte create mode 100644 src/lib/components/ui/popover/popover-description.svelte create mode 100644 src/lib/components/ui/popover/popover-header.svelte create mode 100644 src/lib/components/ui/popover/popover-portal.svelte create mode 100644 src/lib/components/ui/popover/popover-title.svelte create mode 100644 src/lib/components/ui/popover/popover-trigger.svelte create mode 100644 src/lib/components/ui/popover/popover.svelte create mode 100644 src/lib/components/ui/separator/index.ts create mode 100644 src/lib/components/ui/separator/separator.svelte create mode 100644 src/lib/components/ui/slider/index.ts create mode 100644 src/lib/components/ui/slider/slider.svelte create mode 100644 src/lib/zip-selection.ts diff --git a/agents.md b/agents.md index f4cdd2d..dfb7a25 100644 --- a/agents.md +++ b/agents.md @@ -67,11 +67,15 @@ src/ │ ├── assets/ # Favicon and local Nunito fonts │ ├── components/ │ │ ├── AttachmentPreview.svelte # Browser-rendered PDF/image thumbnails +│ │ ├── BeaArchiveProcessing.svelte +│ │ ├── BeaWorkspaceControls.svelte # beA workspace toolbar, settings popover, dialogs │ │ ├── ProcessedZipArchiveEditor.svelte │ │ ├── SubDocumentEditor.svelte -│ │ ├── PdfDropzone.svelte # Shared PDF/image/ZIP file picker and drop target +│ │ ├── FileDropzone.svelte # Shared PDF/image/ZIP file picker and drop target +│ │ ├── ZipFilePicker.svelte # Compact ZIP picker button with hidden resettable input │ │ ├── PdfPageGrid.svelte # Accessible PDF thumbnail selection grid -│ │ ├── ZipDropzone.svelte # beA-specific wrapper around PdfDropzone +│ │ ├── RasterizationWarning.svelte +│ │ ├── ZipDropzone.svelte # beA-specific wrapper around FileDropzone │ │ ├── icons/ # Project-specific SVG components │ │ └── ui/ # Local shadcn-svelte component source │ ├── services/ @@ -106,8 +110,26 @@ committed. `/tools/bea`; the file is not uploaded or persisted. - `tools/bea/+page.svelte` owns selected files, processed archives, pending work, and the thumbnail-width preference. Thumbnail width is the only persisted UI setting and uses localStorage. +- The loaded workspace renders `BeaWorkspaceControls.svelte`, a top-aligned toolbar with the + workspace status and two archive lifecycle actions: + - **“Neue ZIP bearbeiten”** (replace) opens a ZIP picker and, after the user confirms the + replacement dialog, calls `replaceWithZipFiles(files)` which resets the workspace and enqueues the + new files against the incremented generation. Files picked for replacement stay in temporary + component state until confirmation; cancelling the picker or the dialog must never mutate the + current workspace. + - **“Weitere ZIP hinzufügen”** (append) lives in the settings popover, uses the plain append path + (`handleFilesSelected`), and never clears current archives. Keep the two labels distinct: + replace is “Neue ZIP bearbeiten”, append is “Weitere ZIP hinzufügen”. +- `BeaWorkspaceControls.svelte` owns only ephemeral UI state (popover/dialog open state and pending + replacement files). The route remains the source of truth for files, jobs, archives, and the + persisted thumbnail width. +- `resetWorkspace()` is the single teardown helper: it increments `archiveGeneration` and clears + selected files, processed archives, and jobs. Never clear those arrays without going through it. +- Accepted ZIP types and the file filter for the dropzone and both compact pickers are centralized in + `src/lib/zip-selection.ts`; `ZipFilePicker.svelte` resets its input after every selection so the + same file can be chosen again. - ZIP files are processed concurrently. `archiveGeneration` prevents results from an old batch from - reappearing after the user deletes all archives. + reappearing after the user deletes all archives **or** confirms a replacement. - `ProcessedZipArchiveEditor.svelte` edits one archive and emits immutable replacements through `onArchiveChange`; the route-level archive array remains the source of truth. - Attachments may remain loose or belong to exactly one sub-document. Drag-and-drop supports diff --git a/package.json b/package.json index f0a6d7f..591b05a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "svelte": "^5.56.1", "svelte-check": "^4.6.0", "tailwind-merge": "3.6.0", - "tailwind-variants": "^3.2.2", + "tailwind-variants": "^3.3.1", "tailwindcss": "^4.3.0", "tw-animate-css": "^1.4.0", "typescript": "^6.0.3", diff --git a/plan/subdocuments-plan.md b/plan/subdocuments-plan.md deleted file mode 100644 index 00da8c3..0000000 --- a/plan/subdocuments-plan.md +++ /dev/null @@ -1,256 +0,0 @@ -# Plan: Sub-documents within a ZIP archive - -## Goal - -For a processed ZIP archive the user can already **reorder** attachments and **export** them as a single merged PDF. This feature adds the ability to: - -1. **Select** some of the archive's attachments and **group them into a "sub-document"** (a named, ordered subset of attachments). -2. **Reorder** attachments *within* a sub-document — and **reorder** the sub-documents themselves — exactly like the parent archive today. -3. **Choose an export mode** for the sub-documents: - - **Separate files** → each sub-document becomes its own downloaded PDF. - - **One PDF** → all sub-documents are merged into a single downloaded PDF (the existing top-level "PDF herunterladen" behaviour, now scoped to sub-documents when they exist). - -The existing flow (no sub-documents created → one merged PDF for the whole archive) stays intact as a fallback. - ---- - -## Open decisions (please confirm before implementation) - -These affect the data model and UI. Default proposals are marked ✅. - -### D1 — Partition model -- ✅ **A. Optional grouping.** Attachments can be "loose" (not part of any sub-document) *or* members of a sub-document. Sub-documents are created on demand by selecting attachments. -- B. **Exclusive partition.** Once the user starts creating sub-documents, every attachment must belong to exactly one. -- C. **Shared/multi-membership.** An attachment can appear in multiple sub-documents (references, not moves). - -> Recommendation: **A**. It is the least disruptive, matches the current "flat list" mental model, and degrades gracefully when the user does nothing. - -### D2 — Selection lifecycle -- ✅ **Selection mode toggle.** A small "Auswählen" button in the archive header switches the editor into selection mode. Only then are checkboxes rendered on each thumbnail; in normal mode the editor looks exactly like today (no permanent checkbox clutter). While in selection mode the user toggles attachments, then clicks "Teildokument erstellen" to consume the selection (which clears the selection but leaves selection mode on, so they can immediately create another sub-document). Exiting selection mode via a "Fertig" button (or Esc) clears any pending selection. -- A sub-document is created from the *current* selection. Afterwards each attachment can be moved into / out of / between sub-documents via drag-drop or a context action. -- Alternative considered: persistent always-visible checkboxes — rejected as visually noisy for the common case where the user only wants to reorder. - -### D3 — Download scope when sub-documents exist -The existing single archive-level "PDF herunterladen" button behaviour needs clarification. Proposed: -- ✅ When **no** sub-documents exist → today's behaviour (merge all attachments into one PDF). -- When sub-documents **do** exist → show a **download mode toggle** offered to the user at export time: - - **Getrennt** (separate): one PDF per sub-document (loose attachments are downloaded individually, matching their kind — PDF passthrough, image as-is or as a tiny PDF — TBD in D4). - - **Eine PDF** (one): all sub-documents (and loose attachments, optionally — see D5) merged in sub-document order, with attachment order preserved inside each. -- ✅ "Separate" downloads are triggered sequentially (same pattern as today's `exportAllZipArchivesAsPdf`). - -### D4 — Format of "separate" downloads -- ✅ Each sub-document is downloaded as a **PDF** (merge its attachments with the existing `mergeProcessedZipArchive` logic, scoped to the sub-document's attachments). Naming: `{archiveName} - {subDocumentName}.pdf`. -- B. Each sub-document is downloaded as a **ZIP** containing its original files. -- C. Mixed: keep each attachment's original format (PDFs passthrough, images as image files). - -> Recommendation: **A** for consistency with the existing PDF-first export. We can revisit if the actual need is "preserve original files." - -### D5 — Treatment of loose (ungrouped) attachments at export -- ✅ When exporting **separate**: loose attachments are downloaded each as their own PDF (or skipped — needs a quick confirm). -- ✅ When exporting **one PDF**: loose attachments are appended at the end (in their existing order) — or skipped. -- B. Ignore loose attachments entirely during export. - -> Recommendation: **include loose attachments** at the end of both modes, so nothing is silently lost. Confirm with user. - -### D6 — Naming of sub-documents -- ✅ A sub-document has a user-editable name (default e.g. `Teildokument 1`, `Teildokument 2`, …) shown next to its attachments, mirroring the archive name input. - -### D7 — Persistence -- ✅ Sub-document structure lives only in component state (same as today's reordering) — no localStorage persistence required for v1. (We already do not persist reordering.) - ---- - -## Data model (`src/lib/zip-processing.ts`) - -Introduce a `SubDocument` type alongside `ZipAttachment` and extend `ProcessedZipArchive`. - -```ts -export type SubDocument = { - id: string; // stable id for keyed {#each} and drag state - name: string; // user-editable - attachments: ZipAttachment[]; -}; - -export type ProcessedZipArchive = { - name: string; - attachments: ZipAttachment[]; // loose attachments (unchanged shape) - subDocuments: SubDocument[]; // NEW — defaults to [] for backward compat -}; -``` - -Notes: -- Attachments inside `SubDocument` reuse the existing `ZipAttachment` type unchanged. -- `extractZipEntries` populates `subDocuments: []`. All existing call sites continue to work. -- A sub-document's `id` is generated with `crypto.randomUUID()` (available in browser + modern Node) — never re-derived from index, so reordering stays stable. - -### New pure helpers (unit-test-friendly, no DOM) - -```ts -// Create a sub-document from a list of attachments. -export const createSubDocument = ( - name: string, - attachments: ZipAttachment[] -): SubDocument => ({ id: crypto.randomUUID(), name, attachments }); - -// Move an attachment from the loose list (or another sub-document) into a sub-document. -export const moveAttachmentIntoSubDocument = ( - archive: ProcessedZipArchive, - attachmentPath: string, - source: { kind: 'loose' } | { kind: 'subDocument'; id: string }, - target: { kind: 'loose'; index: number } | { kind: 'subDocument'; id: string; index: number } -): ProcessedZipArchive => { /* immutable update */ }; - -// Reorder sub-documents (same shape as the existing moveAttachment helper). -export const moveSubDocument = ( - archive: ProcessedZipArchive, - fromIndex: number, - toIndex: number -): ProcessedZipArchive => { /* ... */ }; - -// Flatten the archive into an ordered list of attachments for "one PDF" export. -// sub-document order is preserved; loose attachments appended at the end (per D5). -export const flattenArchiveForMerge = ( - archive: ProcessedZipArchive -): ZipAttachment[] => { - const ordered: ZipAttachment[] = []; - for (const sub of archive.subDocuments) ordered.push(...sub.attachments); - ordered.push(...archive.attachments); - return ordered; -}; - -// Build one merged-PDF byte array per export unit. -// - mode 'single' → returns [ { name, bytes } ] from the whole archive (existing behaviour) -// - mode 'separate' → returns one entry per sub-document (+ loose attachments per D5) -export type ExportUnit = { name: string; bytes: Uint8Array }; -export const buildArchiveExport = async ( - archive: ProcessedZipArchive, - mode: 'single' | 'separate' -): Promise => { /* ... */ }; -``` - -`mergeProcessedZipArchive` is refactored to delegate to a new `mergeAttachments(attachments): Promise` (a thin rename of the existing inner loop) so both "single" and "separate" share the same merging code. - ---- - -## UI - -### `ProcessedZipArchiveEditor.svelte` (main work) - -State additions: -- `subDocuments = $state([])` synced from `archive.subDocuments` in the existing `$effect`. -- `selectionMode = $state(false)` — whether selection checkboxes are currently shown on thumbnails. -- `selectedPaths = $state>([])` — currently selected attachment paths (keyed by `attachment.path`, which is unique within an archive after extraction). Only meaningful while `selectionMode` is on. -- `downloadMode = $state<'single' | 'separate'>('single')` (only shown when sub-documents exist). -- Existing drag handlers generalised to handle three drag sources/targets: - - loose attachment ↔ loose attachment (today's behaviour), - - loose attachment → sub-document, - - sub-document attachment ↔ sub-document attachment, - - sub-document ↔ sub-document (reorder). -- Drag-and-drop is disabled while in selection mode (so a click toggles selection rather than starting a drag). - -Layout: -- Keep the existing horizontal `
    ` for **loose** attachments. -- In the header, add a small toggle button labelled **"Auswählen"** (icon: `IconMenu` or a checkmark lucide icon). When active it reads **"Fertig"** (and selection mode is on). In normal mode thumbnails have no checkbox at all — the editor looks identical to today. -- While in selection mode, each thumbnail card shows a **checkbox** in the top-left corner and the whole card becomes a click target that toggles its membership in `selectedPaths`. Drag-to-reorder is suspended in this mode to avoid click/drag ambiguity. -- A new **inline action bar** appears above the loose-attachment list when `selectionMode && selectedPaths.size > 0`: - - Button **"Teildokument erstellen"** → calls `createSubDocument` with the selected attachments, removes them from the loose list, clears `selectedPaths`, and keeps `selectionMode` on so the user can immediately build the next sub-document. -- `Esc` exits selection mode (clearing `selectedPaths`); the "Fertig" button does the same. -- Below the loose list, render `subDocuments` as a **vertical stack of "sub-document blocks"**. Each block is itself a horizontal reorderable `
      ` of attachments (same `AttachmentPreview`, same drag handle `::`, same thumbnail width). Each block has: - - an editable name input (mirrors archive name input styling), - - a count label, - - a "remove" action that returns its attachments back to the loose list, - - a draggable header (`::`) to reorder the block among its siblings. -- Sub-document blocks are draggable as a whole via their header (HTML5 DnD, mirroring the existing pattern in `handleDragStart/Drop`). - -Export controls (header area): -- If `subDocuments.length === 0` → existing **"PDF herunterladen"** button + behaviour (unchanged). -- If `subDocuments.length > 0` → replace with a **segmented control** (`Eine PDF` / `Getrennt`) plus the download button labeled accordingly: - - `Eine PDF` → `buildArchiveExport(archive, 'single')`, one `downloadPdfBytes` call. - - `Getrennt` → `buildArchiveExport(archive, 'separate')`, sequential `downloadPdfBytes` per unit (matches today's `exportAllZipArchivesAsPdf` loop). - -All state changes flow through `onArchiveChange` (already plumbed to `updateProcessedZipFile` in `+page.svelte`) so the top-level array stays the source of truth. - -### `+page.svelte` -- `exportAllZipArchivesAsPdf` needs to honour per-archive export mode. Two options: - - ✅ Keep it simple: bulk export uses the existing **"single"** mode for every archive (sub-documents flattened). Add a note in the tooltip. - - B. Read each archive's last-chosen mode (requires propagating `downloadMode` up). Defer to a follow-up if desired. -- The settings-drawer bulk export button label stays; behaviour unchanged for v1. - -### No changes required -- `ZipDropzone`, `AttachmentPreview`, services, `xml-reading.service`, `zip-inflating.service`, layout. - ---- - -## Implementation phases - -### Phase 1 — Data model + pure helpers -- Edit `src/lib/zip-processing.ts`: - - Add `SubDocument` type and extend `ProcessedZipArchive` with `subDocuments: SubDocument[]` (default `[]`). - - Set `subDocuments: []` in `extractZipEntries`. - - Extract `mergeAttachments(attachments: ZipAttachment[]): Promise` from `mergeProcessedZipArchive`. - - Add the pure helpers: `createSubDocument`, `moveAttachmentIntoSubDocument`, `moveSubDocument`, `removeAttachmentFromSubDocument` (returns attachments to the loose list), `flattenArchiveForMerge`, `buildArchiveExport`. -- Verification: TypeScript compiles (`pnpm check` / `svelte-check`); existing tests (if any) still pass; existing UI still renders unchanged. - -### Phase 2 — Sub-document block component -- New `src/lib/components/SubDocumentEditor.svelte`: - - Props: `subDocument`, `thumbnailWidth`, `onSubDocumentChange`, `onRemove`, `drag handlers` (or pass a generic reorder callback). - - Renders the editable name, count, remove button, draggable header, horizontal attachment list (reusing `AttachmentPreview` + the same DnD styling). - - Internally mirrors `ProcessedZipArchiveEditor`'s drag logic, scoped to the block. -- Verify: can be unit-rendered in isolation (storybook-equivalent or a throwaway page snippet). - -### Phase 3 — Selection mode + sub-document creation in `ProcessedZipArchiveEditor` -- Add `selectionMode` and `selectedPaths` state and the "Auswählen" / "Fertig" header toggle. -- While `selectionMode` is on, render a checkbox on each loose thumbnail and make the whole card a click-to-toggle target; suspend drag-to-reorder to avoid click/drag ambiguity. -- Add the inline action bar with **"Teildokument erstellen"**, visible when a selection exists. -- On create: call `createSubDocument`, remove the selected attachments from the loose list, clear `selectedPaths`, keep `selectionMode` on, and emit `onArchiveChange`. -- `Esc` / "Fertig" exits selection mode and clears the selection. -- On sub-document removal: push its attachments back into the loose list (appended at the end by default). -- Verify: toggling selection mode shows/hides checkboxes; in normal mode the editor looks identical to today; creating, populating, and removing sub-documents works end-to-end with reordering still working for loose attachments. - -### Phase 4 — Sub-document drag interactions -- Generalise the existing HTML5 DnD handlers to support the three move scenarios listed above. Use the `dataTransfer` payload to encode `{ source: 'loose' | `sub:${id}`, index }`. -- Reorder sub-document blocks via header drag. -- Verify: items can be moved loose↔sub and sub↔sub; sub-document order can be changed; nothing is duplicated or lost (count invariant: `loose.length + Σ sub.attachments.length === total attachments`). - -### Phase 5 — Export modes -- Replace header download button with the segmented control + button when sub-documents exist. -- Wire `buildArchiveExport(archive, mode)` to `downloadPdfBytes` (single) and the sequential loop (separate). -- `+page.svelte`: keep `exportAllZipArchivesAsPdf` in single mode; optionally surface a small hint when an archive has sub-documents. -- Verify: - - No sub-documents → existing single-PDF download unchanged. - - With sub-documents, "Eine PDF" flattens and downloads one PDF. - - With sub-documents, "Getrennt" downloads N files named `{archiveName} - {subName}.pdf`. - -### Phase 6 — Polish -- Empty states (e.g. empty sub-document block, no loose attachments). -- Disable the create-sub-document button when selection is empty. -- Accessible labels + keyboard operability for checkboxes / segmented control (`bits-ui` SegmentedControl if available, otherwise native radio group). -- Update `agents.md` "ZIP/PDF processing details" + "UI/state details" sections to mention sub-documents. -- Manual smoke test on a real `xjustiz` ZIP with nested archives. - ---- - -## Verification checklist (definition of done) - -- [ ] `pnpm check` (or `svelte-check`) passes with no new errors. -- [ ] `pnpm build` succeeds. -- [ ] Loading a ZIP without creating sub-documents produces the exact same merged PDF as today. -- [ ] Toggling "Auswählen" shows checkboxes on thumbnails; toggling "Fertig" (or pressing Esc) hides them and clears the selection. In normal mode the editor looks identical to today (no checkboxes). -- [ ] Selecting ≥1 attachments and clicking "Teildokument erstellen" removes them from the loose list and adds a named sub-document block, then clears the selection while staying in selection mode for the next group. -- [ ] Drag-reordering works for: loose attachments, attachments inside a sub-document, sub-document blocks themselves, and moving an attachment loose↔sub. -- [ ] With sub-documents present: - - "Eine PDF" downloads a single PDF containing every attachment (sub-documents first, then loose). - - "Getrennt" downloads one PDF per sub-document, each correctly named. -- [ ] Removing a sub-document returns its attachments to the loose list; total attachment count is invariant. -- [ ] Bulk "Alle ZIP-Archive als PDF exportieren" still works (single mode). -- [ ] `agents.md` updated. - ---- - -## Out of scope (follow-ups) - -- Persisting sub-document structure to `localStorage`. -- Renaming attachments themselves (only sub-document names are editable in v1). -- Exporting "separate" as ZIPs or original-format files (see D4-C). -- Per-archive export mode remembered by the bulk exporter (D3 follow-up). -- Drag-and-drop between *different archives* in `+page.svelte` (today each editor is self-contained). diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5eef7d0..7b1303d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,8 +82,8 @@ importers: specifier: 3.6.0 version: 3.6.0 tailwind-variants: - specifier: ^3.2.2 - version: 3.2.2(tailwind-merge@3.6.0)(tailwindcss@4.3.0) + specifier: ^3.3.1 + version: 3.3.1(tailwind-merge@3.6.0)(tailwindcss@4.3.0) tailwindcss: specifier: ^4.3.0 version: 4.3.0 @@ -1155,15 +1155,17 @@ packages: tailwind-merge@3.6.0: resolution: {integrity: sha512-uxL7qAVQriqRQPAyK3pj66VqskWqoZ37PW94jwOTwNfq/z9oyu1V+eqrZqtR2+fCiXdYOZe/Modt8GtvqNzu+w==} - tailwind-variants@3.2.2: - resolution: {integrity: sha512-Mi4kHeMTLvKlM98XPnK+7HoBPmf4gygdFmqQPaDivc3DpYS6aIY6KiG/PgThrGvii5YZJqRsPz0aPyhoFzmZgg==} - engines: {node: '>=16.x', pnpm: '>=7.x'} + tailwind-variants@3.3.1: + resolution: {integrity: sha512-4pAvwUtM4HKBiRZftncAbpn6V9Hhwoa5Fl7O2u5zbp7Z5Cvu+/o/6+176WY3WCEES209543quG8zFIcXCsc5Jw==} + engines: {node: '>=16.9.x', pnpm: '>=7.x'} peerDependencies: tailwind-merge: '>=3.0.0' tailwindcss: '*' peerDependenciesMeta: tailwind-merge: optional: true + tailwindcss: + optional: true tailwindcss@4.3.0: resolution: {integrity: sha512-y6nxMGB1nMW9R6k96e5gdIFzcfL/gTJRNaqGes1YvkLnPVXzWgbqFF2yLC0T8G774n24cx3Pe8XrKoniCOAH+Q==} @@ -2102,11 +2104,10 @@ snapshots: tailwind-merge@3.6.0: {} - tailwind-variants@3.2.2(tailwind-merge@3.6.0)(tailwindcss@4.3.0): - dependencies: - tailwindcss: 4.3.0 + tailwind-variants@3.3.1(tailwind-merge@3.6.0)(tailwindcss@4.3.0): optionalDependencies: tailwind-merge: 3.6.0 + tailwindcss: 4.3.0 tailwindcss@4.3.0: {} diff --git a/src/lib/components/BeaWorkspaceControls.svelte b/src/lib/components/BeaWorkspaceControls.svelte new file mode 100644 index 0000000..e183021 --- /dev/null +++ b/src/lib/components/BeaWorkspaceControls.svelte @@ -0,0 +1,230 @@ + + +
      +

      + {statusText} +

      + +
      + (pendingReplacementFiles = files)} + > + + + + + {#snippet child({ props })} + + {/snippet} + + + + Einstellungen + +
      + + Ansicht + +
      + Vorschaugröße + {thumbnailWidth} px +
      + { + if (typeof value === 'number') onThumbnailWidthChange(value); + }} + /> + +
      + +
      + + Archiv-Aktionen + + + + + + {#if processedArchiveCount >= 2} + + {/if} + + + + +
      +
      +
      +
      +
      + + { + if (!open) pendingReplacementFiles = null; + }} +> + + + Aktuelle Bearbeitung ersetzen? + + + Archive und nicht heruntergeladene Änderungen in dieser Ansicht werden entfernt. Bereits + heruntergeladene PDFs bleiben erhalten. + + + Abbrechen + Neue ZIP öffnen + + + + + + + + Aktuelle Bearbeitung leeren? + + + Alle Archive und nicht heruntergeladene Änderungen in dieser Ansicht werden entfernt. Bereits + heruntergeladene PDFs bleiben erhalten. + + + Abbrechen + Bearbeitung leeren + + + diff --git a/src/lib/components/ZipDropzone.svelte b/src/lib/components/ZipDropzone.svelte index d1b6900..bd0a39d 100644 --- a/src/lib/components/ZipDropzone.svelte +++ b/src/lib/components/ZipDropzone.svelte @@ -1,5 +1,6 @@ + + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte new file mode 100644 index 0000000..07b7e00 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-action.svelte @@ -0,0 +1,27 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte new file mode 100644 index 0000000..147f325 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte @@ -0,0 +1,27 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte new file mode 100644 index 0000000..c2aaabd --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-content.svelte @@ -0,0 +1,32 @@ + + + + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte new file mode 100644 index 0000000..9b2dd92 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-description.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte new file mode 100644 index 0000000..1e198ef --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-footer.svelte @@ -0,0 +1,23 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte new file mode 100644 index 0000000..0039ece --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-header.svelte @@ -0,0 +1,23 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-media.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-media.svelte new file mode 100644 index 0000000..8396702 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-media.svelte @@ -0,0 +1,23 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte new file mode 100644 index 0000000..d092476 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte new file mode 100644 index 0000000..dd3ac7d --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte new file mode 100644 index 0000000..21e20e5 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-title.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog-trigger.svelte b/src/lib/components/ui/alert-dialog/alert-dialog-trigger.svelte new file mode 100644 index 0000000..51a3da1 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog-trigger.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/alert-dialog.svelte b/src/lib/components/ui/alert-dialog/alert-dialog.svelte new file mode 100644 index 0000000..cde7911 --- /dev/null +++ b/src/lib/components/ui/alert-dialog/alert-dialog.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/alert-dialog/index.ts b/src/lib/components/ui/alert-dialog/index.ts new file mode 100644 index 0000000..ac7181f --- /dev/null +++ b/src/lib/components/ui/alert-dialog/index.ts @@ -0,0 +1,40 @@ +import Action from './alert-dialog-action.svelte'; +import Cancel from './alert-dialog-cancel.svelte'; +import Content from './alert-dialog-content.svelte'; +import Description from './alert-dialog-description.svelte'; +import Footer from './alert-dialog-footer.svelte'; +import Header from './alert-dialog-header.svelte'; +import Media from './alert-dialog-media.svelte'; +import Overlay from './alert-dialog-overlay.svelte'; +import Portal from './alert-dialog-portal.svelte'; +import Title from './alert-dialog-title.svelte'; +import Trigger from './alert-dialog-trigger.svelte'; +import Root from './alert-dialog.svelte'; + +export { + Root, + Title, + Action, + Cancel, + Portal, + Footer, + Header, + Trigger, + Overlay, + Content, + Description, + Media, + // + Root as AlertDialog, + Title as AlertDialogTitle, + Action as AlertDialogAction, + Cancel as AlertDialogCancel, + Portal as AlertDialogPortal, + Footer as AlertDialogFooter, + Header as AlertDialogHeader, + Trigger as AlertDialogTrigger, + Overlay as AlertDialogOverlay, + Content as AlertDialogContent, + Description as AlertDialogDescription, + Media as AlertDialogMedia +}; diff --git a/src/lib/components/ui/popover/index.ts b/src/lib/components/ui/popover/index.ts new file mode 100644 index 0000000..96de2e0 --- /dev/null +++ b/src/lib/components/ui/popover/index.ts @@ -0,0 +1,28 @@ +import Close from './popover-close.svelte'; +import Content from './popover-content.svelte'; +import Description from './popover-description.svelte'; +import Header from './popover-header.svelte'; +import Portal from './popover-portal.svelte'; +import Title from './popover-title.svelte'; +import Trigger from './popover-trigger.svelte'; +import Root from './popover.svelte'; + +export { + Root, + Content, + Description, + Header, + Title, + Trigger, + Close, + Portal, + // + Root as Popover, + Content as PopoverContent, + Description as PopoverDescription, + Header as PopoverHeader, + Title as PopoverTitle, + Trigger as PopoverTrigger, + Close as PopoverClose, + Portal as PopoverPortal +}; diff --git a/src/lib/components/ui/popover/popover-close.svelte b/src/lib/components/ui/popover/popover-close.svelte new file mode 100644 index 0000000..dc4dec4 --- /dev/null +++ b/src/lib/components/ui/popover/popover-close.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/popover/popover-content.svelte b/src/lib/components/ui/popover/popover-content.svelte new file mode 100644 index 0000000..c91f599 --- /dev/null +++ b/src/lib/components/ui/popover/popover-content.svelte @@ -0,0 +1,31 @@ + + + + + diff --git a/src/lib/components/ui/popover/popover-description.svelte b/src/lib/components/ui/popover/popover-description.svelte new file mode 100644 index 0000000..468181d --- /dev/null +++ b/src/lib/components/ui/popover/popover-description.svelte @@ -0,0 +1,20 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/popover/popover-header.svelte b/src/lib/components/ui/popover/popover-header.svelte new file mode 100644 index 0000000..aa1e1e1 --- /dev/null +++ b/src/lib/components/ui/popover/popover-header.svelte @@ -0,0 +1,20 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/popover/popover-portal.svelte b/src/lib/components/ui/popover/popover-portal.svelte new file mode 100644 index 0000000..25efb87 --- /dev/null +++ b/src/lib/components/ui/popover/popover-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/popover/popover-title.svelte b/src/lib/components/ui/popover/popover-title.svelte new file mode 100644 index 0000000..867f7f7 --- /dev/null +++ b/src/lib/components/ui/popover/popover-title.svelte @@ -0,0 +1,15 @@ + + +
      + {@render children?.()} +
      diff --git a/src/lib/components/ui/popover/popover-trigger.svelte b/src/lib/components/ui/popover/popover-trigger.svelte new file mode 100644 index 0000000..7b4b27f --- /dev/null +++ b/src/lib/components/ui/popover/popover-trigger.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/popover/popover.svelte b/src/lib/components/ui/popover/popover.svelte new file mode 100644 index 0000000..f39b867 --- /dev/null +++ b/src/lib/components/ui/popover/popover.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/separator/index.ts b/src/lib/components/ui/separator/index.ts new file mode 100644 index 0000000..768efac --- /dev/null +++ b/src/lib/components/ui/separator/index.ts @@ -0,0 +1,7 @@ +import Root from './separator.svelte'; + +export { + Root, + // + Root as Separator +}; diff --git a/src/lib/components/ui/separator/separator.svelte b/src/lib/components/ui/separator/separator.svelte new file mode 100644 index 0000000..40dcb92 --- /dev/null +++ b/src/lib/components/ui/separator/separator.svelte @@ -0,0 +1,23 @@ + + + diff --git a/src/lib/components/ui/slider/index.ts b/src/lib/components/ui/slider/index.ts new file mode 100644 index 0000000..f1524fc --- /dev/null +++ b/src/lib/components/ui/slider/index.ts @@ -0,0 +1,7 @@ +import Root from './slider.svelte'; + +export { + Root, + // + Root as Slider +}; diff --git a/src/lib/components/ui/slider/slider.svelte b/src/lib/components/ui/slider/slider.svelte new file mode 100644 index 0000000..692c5fb --- /dev/null +++ b/src/lib/components/ui/slider/slider.svelte @@ -0,0 +1,57 @@ + + + + + {#snippet children({ thumbItems })} + + + + {#each thumbItems as thumb (thumb.index)} + + {/each} + {/snippet} + diff --git a/src/lib/zip-selection.ts b/src/lib/zip-selection.ts new file mode 100644 index 0000000..543bc28 --- /dev/null +++ b/src/lib/zip-selection.ts @@ -0,0 +1,6 @@ +export const ZIP_ACCEPT_TYPES = '.zip,application/zip,application/x-zip-compressed'; + +export const isAcceptedZipFile = (file: File): boolean => { + if (file.name.toLowerCase().endsWith('.zip')) return true; + return ['application/zip', 'application/x-zip-compressed'].includes(file.type.toLowerCase()); +}; diff --git a/src/routes/tools/bea/+page.svelte b/src/routes/tools/bea/+page.svelte index e61e0a2..cb97bf7 100644 --- a/src/routes/tools/bea/+page.svelte +++ b/src/routes/tools/bea/+page.svelte @@ -1,6 +1,6 @@ {#snippet content()} @@ -146,63 +153,19 @@ - {:else} -
      - - Settings - ⚙️ - - -
      -
      -
      - - - -
      - - -
      -
      -
      -
      + {:else if zipJobs.length > 0} +
      + (thumbnailWidth = value)} + onRequestReplacement={replaceWithZipFiles} + onAppendFiles={handleFilesSelected} + onExportAll={exportAllZipArchivesAsPdf} + onClear={resetWorkspace} + />
      {#if processedZipFiles.length === 0} diff --git a/tests/e2e/toolbox.spec.ts b/tests/e2e/toolbox.spec.ts index cf947f9..45bdbd9 100644 --- a/tests/e2e/toolbox.spec.ts +++ b/tests/e2e/toolbox.spec.ts @@ -79,6 +79,39 @@ const pdfDropzone = (page: Page) => page.getByRole('button', { name: 'PDF-Dateie const zipDropzone = (page: Page) => page.getByRole('button', { name: 'beA-ZIP-Dateien hinzufügen' }); +const createZip = async (label: string, pageCount = 1) => + Buffer.from(zipSync({ [`${label}.pdf`]: await createPdf(pageCount, label) })); + +const newZipButton = (page: Page) => page.getByRole('button', { name: 'Neue ZIP bearbeiten' }); +const settingsButton = (page: Page) => + page.getByRole('button', { name: 'Einstellungen', exact: true }); +const replaceZipInput = (page: Page) => page.locator('input[data-zip-picker="replace-zip"]'); +const appendZipInput = (page: Page) => page.locator('input[data-zip-picker="append-zip"]'); +const workspaceStatus = (page: Page, pattern: RegExp) => page.getByText(pattern); + +const waitForLoadedWorkspace = async ( + page: Page, + status: RegExp, + options?: { timeout?: number } +) => { + await expect(newZipButton(page)).toBeVisible(); + await expect(workspaceStatus(page, status)).toBeVisible({ timeout: options?.timeout ?? 15_000 }); +}; + +const replaceThroughDialog = async (page: Page, zip: Buffer, confirm: boolean) => { + await newZipButton(page).click(); + await replaceZipInput(page).setInputFiles([ + { name: 'archiv-b.zip', mimeType: 'application/zip', buffer: zip } + ]); + await expect(page.getByText('Aktuelle Bearbeitung ersetzen?')).toBeVisible(); + if (confirm) { + await page.getByRole('button', { name: 'Neue ZIP öffnen' }).click(); + } else { + await page.getByRole('button', { name: 'Abbrechen' }).click(); + } + await expect(page.getByText('Aktuelle Bearbeitung ersetzen?')).toBeHidden(); +}; + test('start page exposes only working tools and forwards a dropped ZIP to beA', async ({ page }) => { @@ -264,3 +297,250 @@ test('convert bundles a multi-page PDF as a correctly named ZIP', async ({ page expect(download.suggestedFilename()).not.toContain('.pdf'); expect(pageErrors).toEqual([]); }); + +test('cancelling the replacement confirmation keeps the current archive', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + const zipB = await createZip('archiv-b'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await replaceThroughDialog(page, zipB, false); + + await expect(workspaceStatus(page, /1 ZIP · 1 Archiv geöffnet/)).toBeVisible(); + await expect(page.getByText('2 ZIPs')).toHaveCount(0); + expect(pageErrors).toEqual([]); +}); + +test('confirming the replacement opens only the new ZIP and drops stale results', async ({ + page +}) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a', 3); + const zipB = await createZip('archiv-b'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + // Replace while the first ZIP may still be extracting; generation guarding + // must ensure no late result from archiv-a reappears. + await replaceThroughDialog(page, zipB, true); + + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + await expect(page.getByText('1 lose Datei')).toHaveCount(1); + expect(pageErrors).toEqual([]); +}); + +test('cancelling the system file picker leaves the workspace unchanged', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await newZipButton(page).click(); + await replaceZipInput(page).setInputFiles([]); + await expect(page.getByText('Aktuelle Bearbeitung ersetzen?')).toHaveCount(0); + await expect(workspaceStatus(page, /1 ZIP · 1 Archiv geöffnet/)).toBeVisible(); + expect(pageErrors).toEqual([]); +}); + +test('the replacement input accepts the same ZIP twice', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + const zipB = await createZip('archiv-b'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await replaceThroughDialog(page, zipB, true); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await replaceThroughDialog(page, zipB, true); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + await expect(page.getByText('1 lose Datei')).toHaveCount(1); + expect(pageErrors).toEqual([]); +}); + +test('appending a ZIP keeps both archive editors visible', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + const zipB = await createZip('archiv-b'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await settingsButton(page).click(); + await appendZipInput(page).setInputFiles([ + { name: 'archiv-b.zip', mimeType: 'application/zip', buffer: zipB } + ]); + + await waitForLoadedWorkspace(page, /2 ZIPs · 2 Archive geöffnet/); + await expect(page.getByText('1 lose Datei')).toHaveCount(2); + expect(pageErrors).toEqual([]); +}); + +test('bulk export only appears for two or more processed archives', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + const zipB = await createZip('archiv-b'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await settingsButton(page).click(); + await expect( + page.getByRole('button', { name: 'Alle Archive als PDF herunterladen' }) + ).toHaveCount(0); + + await appendZipInput(page).setInputFiles([ + { name: 'archiv-b.zip', mimeType: 'application/zip', buffer: zipB } + ]); + await waitForLoadedWorkspace(page, /2 ZIPs · 2 Archive geöffnet/); + + // The popover stays open, so the new bulk export action appears in place. + const exportButton = page.getByRole('button', { name: 'Alle Archive als PDF herunterladen' }); + await expect(exportButton).toBeVisible(); + + const downloadPromise = page.waitForEvent('download'); + await exportButton.click(); + await expectPdfDownload(await downloadPromise, /\.pdf$/); + expect(pageErrors).toEqual([]); +}); + +test('clearing the workspace requires confirmation and returns to the dropzone', async ({ + page +}) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await settingsButton(page).click(); + await page.getByRole('button', { name: 'Aktuelle Bearbeitung leeren' }).click(); + await expect(page.getByText('Aktuelle Bearbeitung leeren?')).toBeVisible(); + await page.getByRole('button', { name: 'Abbrechen' }).click(); + await expect(workspaceStatus(page, /1 ZIP · 1 Archiv geöffnet/)).toBeVisible(); + + await page.getByRole('button', { name: 'Aktuelle Bearbeitung leeren' }).click(); + await page.getByRole('button', { name: 'Bearbeitung leeren', exact: true }).click(); + await expect(zipDropzone(page)).toBeVisible(); + await expect(newZipButton(page)).toHaveCount(0); + expect(pageErrors).toEqual([]); +}); + +test('the preview-size slider works with arrow keys and survives a reload', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + await expect(page.locator('li[style*="width: 200px"]').first()).toBeVisible(); + + await settingsButton(page).click(); + const slider = page.getByRole('slider', { name: 'Vorschaugröße' }); + await expect(page.getByText('200 px')).toBeVisible(); + await slider.focus(); + await page.keyboard.press('ArrowRight'); + await expect(page.getByText('201 px')).toBeVisible(); + await expect(page.locator('li[style*="width: 201px"]').first()).toBeVisible(); + + await page.reload(); + await page.locator('[data-dropzone-ready="true"]').first().waitFor(); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + await settingsButton(page).click(); + await expect(page.getByText('201 px')).toBeVisible(); + await expect(await page.evaluate(() => localStorage.getItem('thumbnailWidth'))).toBe('201'); + expect(pageErrors).toEqual([]); +}); + +test('settings closes on Escape and outside click and returns focus to its trigger', async ({ + page +}) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await expect(settingsButton(page)).toHaveAccessibleName('Einstellungen'); + await settingsButton(page).click(); + await expect(page.getByText('Vorschaugröße')).toBeVisible(); + await page.keyboard.press('Escape'); + await expect(page.getByText('Vorschaugröße')).toHaveCount(0); + await expect(settingsButton(page)).toBeFocused(); + + await settingsButton(page).click(); + await expect(page.getByText('Vorschaugröße')).toBeVisible(); + await page.getByRole('heading', { name: 'beA-Edit' }).click(); + await expect(page.getByText('Vorschaugröße')).toHaveCount(0); + expect(pageErrors).toEqual([]); +}); + +test('mobile toolbar and settings popover stay inside the viewport', async ({ page }) => { + const pageErrors = trackPageErrors(page); + const zipA = await createZip('archiv-a'); + + await page.setViewportSize({ width: 390, height: 844 }); + await page.goto('/tools/bea'); + await dropFiles(page, zipDropzone(page), [ + { name: 'archiv-a.zip', mimeType: 'application/zip', buffer: zipA } + ]); + await waitForLoadedWorkspace(page, /1 ZIP · 1 Archiv geöffnet/); + + await settingsButton(page).click(); + const popover = page.locator('[data-slot="popover-content"]'); + await expect(popover).toBeVisible(); + await expect(page.getByText('Weitere ZIP hinzufügen')).toBeVisible(); + + const popoverBox = await popover.boundingBox(); + expect(popoverBox).not.toBeNull(); + expect(popoverBox!.x).toBeGreaterThanOrEqual(0); + expect(popoverBox!.x + popoverBox!.width).toBeLessThanOrEqual(390); + expect(popoverBox!.y).toBeGreaterThanOrEqual(0); + expect(popoverBox!.y + popoverBox!.height).toBeLessThanOrEqual(844); + const popoverMetrics = await popover.evaluate((element) => ({ + scrollWidth: element.scrollWidth, + clientWidth: element.clientWidth + })); + expect(popoverMetrics.scrollWidth).toBeLessThanOrEqual(popoverMetrics.clientWidth); + + // The toolbar sits in normal flow, so it must not cover the archive header. + const toolbarBox = await workspaceStatus(page, /1 ZIP · 1 Archiv geöffnet/).boundingBox(); + const archiveHeaderBox = await page.getByText('1 lose Datei').first().boundingBox(); + expect(toolbarBox).not.toBeNull(); + expect(archiveHeaderBox).not.toBeNull(); + expect(toolbarBox!.y + toolbarBox!.height).toBeLessThanOrEqual(archiveHeaderBox!.y); + + expect(pageErrors).toEqual([]); +});