Admin: one image picker everywhere, with paste, drag-and-drop and a library #12

Merged
reudy merged 4 commits from unified-image-picker into main 2026-10-26 18:01:18 +01:00
Member

Every image field in the admin now uses the same component, and images can be pasted or dragged in.

Why

Image fields looked and behaved differently. Blocks, emails and the logo had one uploader (a box plus URL and alt fields). Services & products had its own small thumbnail with an "Upload image" button. Neither accepted a pasted image, and the box said "drop zone" but did nothing with a dropped file.

What changed

  • ImageUploader.svelte is now ImagePicker.svelte and is used everywhere:
    • Image + Text
    • card images
    • block background images
    • email images
    • the Site design logo
    • Services & products
  • Ways to add an image:
    • click the box
    • Pick from library: the images already uploaded (media), newest first, searchable by alt text or file name, 24 at a time (MediaLibrary.svelte, new admin GET /api/media); a hand-written alt text is kept, otherwise the image's own alt text is used
    • drag an image onto the box
    • paste: Ctrl+V / ⌘V while anything in the picker has focus, or the Paste button where the browser allows reading the clipboard
    • text pasted into the URL or alt field still pastes as usual
  • Pasted images:
    • get a dated name (pasted-20261026133019.png)
    • get no alt text made from "image.png"; when the alt is empty, the Alt text field gets focus so it can be filled in
    • a hand-written alt text is kept
  • Checks before uploading: files the media collection rejects are refused up front with a plain message. That means a type other than JPG/PNG/WebP/GIF/SVG, or a file over 20 MB.
  • Preview: shows the whole image (object-contain), so logos and portrait photos aren't cropped.
  • Layout (from a sketch):
    • the box on the left; Alt text and Image URL on the right, labels above the fields
    • Pick from library and Paste as a full-width row underneath
    • stacked in narrow columns (container query)
    • Remove is a ✕ on the image; hovering an image shows "Click, drop or paste to replace"
    • without fields (Services & products), the hint and the page's own note sit beside the box (children snippet)
  • Services & products: has no URL or alt fields, because it stores a media relation and the shop uses the service name as alt text. Save is still held while an upload runs (bind:uploading).
  • uploadMedia(file, alt?) takes an optional alt text.
  • AGENTS.md documents the convention.

Tested

  • Test stack, Playwright:
    • paste on Site design (logo replaced in the form, not saved)
    • drop, Remove and choose-file on a new service: the hidden image field gets the media id and is cleared by Remove
    • a .txt file is refused with the message
    • screenshots of Image + Text, Cards, block background, Site design at 400 px and the service dialog
    • no page errors
  • svelte-check (admin): 0 errors, 15 warnings (main: 17–18).
  • Library: opened, searched, picked (Site design, and inside the Services dialog: the hidden image field gets the picked media id, the outer dialog stays open).
  • Not tested: the Paste button in a real browser. Headless Chromium has no clipboard to read from. Firefox and Safari always show their own small "Paste" confirmation for it (a page can't read the clipboard without one; Chrome asks once per site), while Ctrl+V pastes straight away, and if the browser refuses, the picker says to use Ctrl+V instead.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW

Every image field in the admin now uses the same component, and images can be pasted or dragged in. ## Why Image fields looked and behaved differently. Blocks, emails and the logo had one uploader (a box plus URL and alt fields). Services & products had its own small thumbnail with an "Upload image" button. Neither accepted a pasted image, and the box said "drop zone" but did nothing with a dropped file. ## What changed - `ImageUploader.svelte` is now `ImagePicker.svelte` and is used everywhere: - Image + Text - card images - block background images - email images - the Site design logo - Services & products - **Ways to add an image:** - click the box - *Pick from library*: the images already uploaded (`media`), newest first, searchable by alt text or file name, 24 at a time (`MediaLibrary.svelte`, new admin `GET /api/media`); a hand-written alt text is kept, otherwise the image's own alt text is used - drag an image onto the box - paste: Ctrl+V / ⌘V while anything in the picker has focus, or the *Paste* button where the browser allows reading the clipboard - text pasted into the URL or alt field still pastes as usual - **Pasted images:** - get a dated name (`pasted-20261026133019.png`) - get no alt text made from "image.png"; when the alt is empty, the Alt text field gets focus so it can be filled in - a hand-written alt text is kept - **Checks before uploading:** files the `media` collection rejects are refused up front with a plain message. That means a type other than JPG/PNG/WebP/GIF/SVG, or a file over 20 MB. - **Preview:** shows the whole image (`object-contain`), so logos and portrait photos aren't cropped. - **Layout** (from a sketch): - the box on the left; *Alt text* and *Image URL* on the right, labels above the fields - *Pick from library* and *Paste* as a full-width row underneath - stacked in narrow columns (container query) - Remove is a ✕ on the image; hovering an image shows "Click, drop or paste to replace" - without fields (Services & products), the hint and the page's own note sit beside the box (`children` snippet) - **Services & products:** has no URL or alt fields, because it stores a media relation and the shop uses the service name as alt text. Save is still held while an upload runs (`bind:uploading`). - `uploadMedia(file, alt?)` takes an optional alt text. - AGENTS.md documents the convention. ## Tested - Test stack, Playwright: - paste on Site design (logo replaced in the form, not saved) - drop, Remove and choose-file on a new service: the hidden `image` field gets the media id and is cleared by Remove - a `.txt` file is refused with the message - screenshots of Image + Text, Cards, block background, Site design at 400 px and the service dialog - no page errors - `svelte-check` (admin): 0 errors, 15 warnings (main: 17–18). - Library: opened, searched, picked (Site design, and inside the Services dialog: the hidden `image` field gets the picked media id, the outer dialog stays open). - Not tested: the Paste button in a real browser. Headless Chromium has no clipboard to read from. Firefox and Safari always show their own small "Paste" confirmation for it (a page can't read the clipboard without one; Chrome asks once per site), while Ctrl+V pastes straight away, and if the browser refuses, the picker says to use Ctrl+V instead. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 1 commit 2026-10-26 14:33:02 +01:00
ImageUploader becomes ImagePicker and replaces the separate image field on
Services & products, so every image (blocks, card images, block backgrounds,
emails, the logo, services) is picked the same way. Besides choosing a file
it takes an image dragged onto the box or pasted (Ctrl+V while the picker
has focus, or the Paste button where the browser allows reading the
clipboard). Pasted images get a dated file name and no alt text made from
"image.png"; files the media collection won't take are refused with a
message before uploading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 1 commit 2026-10-26 14:54:29 +01:00
The box and its Choose/Paste buttons form the left column, so it lines up
with the fields beside it; Remove is a ✕ on the image and hovering an image
says how to replace it. Alt text comes first, the Image URL is smaller and
explained. Without fields (Services & products) the hint and the page's own
note sit beside the box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent changed title from Admin: one image picker everywhere, with paste and drag-and-drop to Admin: one image picker everywhere, with paste, drag-and-drop and a library 2026-10-26 15:21:24 +01:00
agent added 1 commit 2026-10-26 15:21:25 +01:00
"Pick from library" opens the images already in `media` (newest first,
searchable by alt text or file name, 24 at a time) so one can be reused
without uploading it again; it lists them through the new admin
GET /api/media. The layout follows the sketch: box on the left, Alt text and
Image URL with their labels beside them, and Pick from library / Paste as a
full-width row underneath.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 1 commit 2026-10-26 15:29:54 +01:00
reudy merged commit af7f0f261f into main 2026-10-26 18:01:18 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/domaino#12
No description provided.