From 93d4863cfc37d6e13444d848529248bb0820cd8f Mon Sep 17 00:00:00 2001 From: agent Date: Mon, 26 Oct 2026 13:32:43 +0000 Subject: [PATCH 1/4] Admin: one image picker everywhere, with paste and drag-and-drop 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 Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW --- AGENTS.md | 1 + .../src/lib/admin/editors/BlockEditor.svelte | 8 +- .../lib/admin/editors/EmailBlockEditor.svelte | 4 +- .../src/lib/admin/editors/ImagePicker.svelte | 181 ++++++++++++++++++ .../lib/admin/editors/ImageUploader.svelte | 107 ----------- app-admin/src/lib/pb.ts | 9 +- app-admin/src/routes/globals/+page.svelte | 4 +- app-admin/src/routes/items/+page.svelte | 42 +--- 8 files changed, 200 insertions(+), 156 deletions(-) create mode 100644 app-admin/src/lib/admin/editors/ImagePicker.svelte delete mode 100644 app-admin/src/lib/admin/editors/ImageUploader.svelte diff --git a/AGENTS.md b/AGENTS.md index 633aaa9..96d0823 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -146,6 +146,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type - Section card: `rounded-box bg-base-100 p-5 shadow` with an `h2.text-2xl.font-bold` title (see Site design / globals). - Form field: ``; hints in ``. - Setting rows in editors: `SegmentedControl` (choices) and `ColorField` (colours) — label column on the left, like the block Background picker. + - Images: always `$lib/admin/editors/ImagePicker.svelte` (choose, drag in or paste an image; address and alt text). It uploads to `media` through `/api/upload`; `withUrl={false}` + `altHint=""` + the `id` from `onChange` where a field stores a media relation (Services & products). Store only `url`/`alt` from `onChange` elsewhere. - Create/edit forms open in `$lib/admin/Modal.svelte`; destructive submits use `confirmSubmit()` from `$lib/admin/confirm` (returning `false` from a handler does not cancel). - Server actions wrap PocketBase writes in `attempt()` from `$lib/server/actions` so failures show as an error banner, not a 500. - Editors with unsaved state use `use:enhance` + `warnOnUnsavedChanges()`. diff --git a/app-admin/src/lib/admin/editors/BlockEditor.svelte b/app-admin/src/lib/admin/editors/BlockEditor.svelte index d0a1f42..09787fc 100644 --- a/app-admin/src/lib/admin/editors/BlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/BlockEditor.svelte @@ -2,7 +2,7 @@ import type { BlockType, ContentBlock } from '$lib/types'; import { blockLabels } from '$lib/admin/blockDefaults'; import RichTextEditor from './RichTextEditor.svelte'; - import ImageUploader from './ImageUploader.svelte'; + import ImagePicker from './ImagePicker.svelte'; import SegmentedControl from './SegmentedControl.svelte'; import ColorField from './ColorField.svelte'; import ShopBlockEditor from './ShopBlockEditor.svelte'; @@ -94,7 +94,7 @@ {:else if block.type === 'image_text'}
- updateData(image)} /> + updateData({ url: image.url, alt: image.alt })} /> updateData({ imagePosition: v })} /> updateData({ content })} />
@@ -199,7 +199,7 @@ {#if block.data.style !== 'numbered'} - updateArray('items', i, { imageUrl: image.url, imageAlt: image.alt })} /> + updateArray('items', i, { imageUrl: image.url, imageAlt: image.alt })} /> {/if}
{@render field('Title', card.title || '', (title) => updateArray('items', i, { title }))} @@ -255,7 +255,7 @@ {#if block.data._background?.type === 'color'} updateBackground({ color })} /> {:else if block.data._background?.type === 'image'} - updateBackground({ imageUrl: image.url, imageAlt: image.alt })} /> + updateBackground({ imageUrl: image.url, imageAlt: image.alt })} /> updateBackground({ attachment })} /> Use placeholders like {'{{customer_first_name}}'} — see the list above.

{:else if block.type === 'image'}
- updateData(image)} /> + updateData({ url: image.url, alt: image.alt })} /> updateData({ width: v })} formatLabel={(v) => `${v}%`} /> updateData({ alignment: v })} />
- {#if uploadError}{uploadError}{/if} + (draft = { ...draft, image: image.id ?? draft.image, imageUrl: image.url })} /> + The shop uses the name as the image’s alt text.