Admin on phones: touch dragging, roomier setting rows, fading save banner
- Block list: drag a block by its handle with a finger (phones don't fire HTML drag events); the mouse keeps drag-and-drop on the whole row. - Setting rows (SegmentedControl, ColorField, Anchor) put the label above the choices in a narrow row, so e.g. Shop "Item type" fits. - Background Overlay is a slider instead of ten buttons. - Page and email editors: "Draft saved." fades out like Site design's (new SaveStatus component); errors stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
parent
af7f0f261f
commit
9500f0c07b
8 changed files with 128 additions and 52 deletions
|
|
@ -145,7 +145,8 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
|
||||||
- **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). Colours come from Site design via `$shared/theme`, rendered as a `<style>` in `<head>` (SSR, no flash): the admin gets only DaisyUI primary (= site Primary) and secondary (= site Accent) with auto-contrast text; `/preview` and the public site get all site colour variables. Never use `text-primary`/`text-secondary` for text — a light brand colour is unreadable as text; mark state with a tint/bar instead. Conventions:
|
- **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). Colours come from Site design via `$shared/theme`, rendered as a `<style>` in `<head>` (SSR, no flash): the admin gets only DaisyUI primary (= site Primary) and secondary (= site Accent) with auto-contrast text; `/preview` and the public site get all site colour variables. Never use `text-primary`/`text-secondary` for text — a light brand colour is unreadable as text; mark state with a tint/bar instead. Conventions:
|
||||||
- Section card: `rounded-box bg-base-100 p-5 shadow` with an `h2.text-2xl.font-bold` title (see Site design / globals).
|
- Section card: `rounded-box bg-base-100 p-5 shadow` with an `h2.text-2xl.font-bold` title (see Site design / globals).
|
||||||
- Form field: `<label class="fieldset"><span class="fieldset-legend">Label</span><input class="input w-full" /></label>`; hints in `<span class="label">`.
|
- Form field: `<label class="fieldset"><span class="fieldset-legend">Label</span><input class="input w-full" /></label>`; hints in `<span class="label">`.
|
||||||
- Setting rows in editors: `SegmentedControl` (choices) and `ColorField` (colours) — label column on the left, like the block Background picker.
|
- Setting rows in editors: `SegmentedControl` (choices) and `ColorField` (colours) — label column on the left, like the block Background picker; in a narrow row (a phone) the label goes above (a `@container` query). More than about four choices don't fit a phone: use a slider (like the background Overlay).
|
||||||
|
- Save results in editors: `$lib/admin/SaveStatus.svelte` (success fades out after a moment, an error stays).
|
||||||
- Images: always `$lib/admin/editors/ImagePicker.svelte` (choose, drag in or paste an image, or pick an uploaded one from the library: `MediaLibrary.svelte`, `/api/media`; 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.
|
- Images: always `$lib/admin/editors/ImagePicker.svelte` (choose, drag in or paste an image, or pick an uploaded one from the library: `MediaLibrary.svelte`, `/api/media`; 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).
|
- 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.
|
- Server actions wrap PocketBase writes in `attempt()` from `$lib/server/actions` so failures show as an error banner, not a 500.
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,34 @@
|
||||||
dropIndex = null;
|
dropIndex = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Touch: phones don't fire HTML drag events, so the handle follows the finger with
|
||||||
|
// pointer events instead (the mouse keeps native drag-and-drop on the whole row).
|
||||||
|
let list = $state<HTMLUListElement>();
|
||||||
|
|
||||||
|
function touchDragStart(e: PointerEvent, index: number) {
|
||||||
|
if (e.pointerType === 'mouse') return;
|
||||||
|
e.preventDefault();
|
||||||
|
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
||||||
|
dragIndex = index;
|
||||||
|
dropIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function touchDragMove(e: PointerEvent) {
|
||||||
|
if (dragIndex === null || !list) return;
|
||||||
|
const rows = [...list.children] as HTMLElement[];
|
||||||
|
const over = rows.findIndex((row) => e.clientY < row.getBoundingClientRect().bottom);
|
||||||
|
dropIndex = over === -1 ? rows.length - 1 : over;
|
||||||
|
// The handle blocks scrolling, so scroll for the finger near the screen's edges.
|
||||||
|
if (e.clientY < 64) window.scrollBy(0, -12);
|
||||||
|
else if (e.clientY > window.innerHeight - 64) window.scrollBy(0, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
function touchDragEnd() {
|
||||||
|
if (dragIndex !== null && dropIndex !== null) drop(dropIndex);
|
||||||
|
dragIndex = null;
|
||||||
|
dropIndex = null;
|
||||||
|
}
|
||||||
|
|
||||||
function moveBy(index: number, delta: number) {
|
function moveBy(index: number, delta: number) {
|
||||||
const to = index + delta;
|
const to = index + delta;
|
||||||
if (to >= 0 && to < blocks.length) onMove(index, to);
|
if (to >= 0 && to < blocks.length) onMove(index, to);
|
||||||
|
|
@ -51,7 +79,7 @@
|
||||||
|
|
||||||
<!-- `isolate` on each row: the delete button's z-indexed layers must stay
|
<!-- `isolate` on each row: the delete button's z-indexed layers must stay
|
||||||
inside their row, or they paint over dropdowns like "Add block". -->
|
inside their row, or they paint over dropdowns like "Add block". -->
|
||||||
<ul class="space-y-2">
|
<ul class="space-y-2" bind:this={list}>
|
||||||
{#each blocks as block, i (block.id)}
|
{#each blocks as block, i (block.id)}
|
||||||
<li
|
<li
|
||||||
class="isolate flex items-center gap-2 rounded-box border bg-base-100 p-2 pl-3 shadow-sm transition-colors {selectedId === block.id ? 'border-primary ring-1 ring-primary' : 'border-base-300 hover:border-base-content/30'}"
|
class="isolate flex items-center gap-2 rounded-box border bg-base-100 p-2 pl-3 shadow-sm transition-colors {selectedId === block.id ? 'border-primary ring-1 ring-primary' : 'border-base-300 hover:border-base-content/30'}"
|
||||||
|
|
@ -78,7 +106,18 @@
|
||||||
dropIndex = null;
|
dropIndex = null;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span class="cursor-grab select-none text-lg text-base-content/40" aria-hidden="true" title="Drag to reorder">⠿</span>
|
<span
|
||||||
|
class="-my-2 -ml-2 cursor-grab touch-none select-none px-2 py-2 text-lg text-base-content/40"
|
||||||
|
aria-hidden="true"
|
||||||
|
title="Drag to reorder"
|
||||||
|
onpointerdown={(e) => touchDragStart(e, i)}
|
||||||
|
onpointermove={touchDragMove}
|
||||||
|
onpointerup={touchDragEnd}
|
||||||
|
onpointercancel={() => {
|
||||||
|
dragIndex = null;
|
||||||
|
dropIndex = null;
|
||||||
|
}}
|
||||||
|
>⠿</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="flex-1 truncate py-1 text-left font-semibold"
|
class="flex-1 truncate py-1 text-left font-semibold"
|
||||||
|
|
|
||||||
26
app-admin/src/lib/admin/SaveStatus.svelte
Normal file
26
app-admin/src/lib/admin/SaveStatus.svelte
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { browser } from '$app/environment';
|
||||||
|
import { fly, slide } from 'svelte/transition';
|
||||||
|
|
||||||
|
// The result banner of a save, like Site design's: "Saved." goes away by itself
|
||||||
|
// after a moment; an error stays until the next save. Pass the action's `form`
|
||||||
|
// (or null for results that belong elsewhere); each new result shows again.
|
||||||
|
let { result, class: className = '' } = $props<{ result: { ok?: boolean; message?: string } | null | undefined; class?: string }>();
|
||||||
|
|
||||||
|
let shown = $state(false);
|
||||||
|
$effect(() => {
|
||||||
|
// Not reading `shown` here: that would re-run this when the timer hides it.
|
||||||
|
const message = !!result?.message;
|
||||||
|
shown = message;
|
||||||
|
if (!message || !result?.ok) return;
|
||||||
|
const timer = setTimeout(() => (shown = false), 2500);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
});
|
||||||
|
const motion = (ms: number) => (browser && matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : ms);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if shown && result?.message}
|
||||||
|
<div class="alert {className}" class:alert-success={result.ok} class:alert-error={!result.ok} role="status" in:fly={{ y: 8, duration: motion(200) }} out:slide={{ duration: motion(350) }}>
|
||||||
|
{result.message}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
@ -243,10 +243,12 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="mt-6 space-y-3 rounded-box border border-base-300 p-4">
|
<div class="mt-6 space-y-3 rounded-box border border-base-300 p-4">
|
||||||
<label class="flex items-center gap-3">
|
<div class="@container">
|
||||||
<span class="w-28 shrink-0 text-sm font-bold">Anchor</span>
|
<label class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||||
<input class="input input-sm flex-1" placeholder="e.g. prices — then link to #prices" value={block.data._anchor || ''} onchange={(e) => updateData({ _anchor: toAnchor(e.currentTarget.value) })} />
|
<span class="shrink-0 text-sm font-bold @sm:w-28">Anchor</span>
|
||||||
</label>
|
<input class="input input-sm w-full @sm:flex-1" placeholder="e.g. prices — then link to #prices" value={block.data._anchor || ''} onchange={(e) => updateData({ _anchor: toAnchor(e.currentTarget.value) })} />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr class="border-base-300" />
|
<hr class="border-base-300" />
|
||||||
|
|
||||||
|
|
@ -257,13 +259,17 @@
|
||||||
{:else if block.data._background?.type === 'image'}
|
{:else if block.data._background?.type === 'image'}
|
||||||
<ImagePicker url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateBackground({ imageUrl: image.url, imageAlt: image.alt })} />
|
<ImagePicker url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateBackground({ imageUrl: image.url, imageAlt: image.alt })} />
|
||||||
<SegmentedControl label="Attachment" options={['scroll', 'fixed']} value={block.data._background?.attachment || 'scroll'} onChange={(attachment) => updateBackground({ attachment })} />
|
<SegmentedControl label="Attachment" options={['scroll', 'fixed']} value={block.data._background?.attachment || 'scroll'} onChange={(attachment) => updateBackground({ attachment })} />
|
||||||
<SegmentedControl
|
{@const overlay = block.data._background?.overlay ? (block.data._background?.overlayOpacity ?? 40) : 0}
|
||||||
label="Overlay"
|
<!-- A slider: ten buttons don't fit a phone. -->
|
||||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
<div class="@container">
|
||||||
value={block.data._background?.overlay ? (block.data._background?.overlayOpacity ?? 40) : 0}
|
<label class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||||
onChange={(v) => updateBackground({ overlay: Number(v) > 0, overlayOpacity: Number(v) })}
|
<span class="shrink-0 text-sm font-medium @sm:w-28">Overlay</span>
|
||||||
formatLabel={(v) => (Number(v) === 0 ? 'None' : `${v}%`)}
|
<span class="flex flex-1 items-center gap-3">
|
||||||
/>
|
<input class="range range-sm flex-1" type="range" min="0" max="90" step="10" value={overlay} oninput={(e) => updateBackground({ overlay: Number(e.currentTarget.value) > 0, overlayOpacity: Number(e.currentTarget.value) })} />
|
||||||
|
<span class="w-12 text-right text-sm tabular-nums">{overlay === 0 ? 'None' : `${overlay}%`}</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<hr class="border-base-300" />
|
<hr class="border-base-300" />
|
||||||
|
|
|
||||||
|
|
@ -19,19 +19,22 @@
|
||||||
const isHex = (v: string) => /^#[0-9a-f]{6}$/i.test(v);
|
const isHex = (v: string) => /^#[0-9a-f]{6}$/i.test(v);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex items-center gap-3">
|
<!-- Label above the field in a narrow row, like SegmentedControl. -->
|
||||||
<span class="w-28 shrink-0 text-sm font-medium">{label}</span>
|
<div class="@container">
|
||||||
<div class="join flex-1">
|
<div class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||||
<input
|
<span class="shrink-0 text-sm font-medium @sm:w-28">{label}</span>
|
||||||
class="input join-item w-12 cursor-pointer p-1"
|
<div class="join flex-1">
|
||||||
type="color"
|
<input
|
||||||
aria-label="{label} picker"
|
class="input join-item w-12 cursor-pointer p-1"
|
||||||
value={isHex(value) ? value : fallback}
|
type="color"
|
||||||
oninput={(e) => onChange(e.currentTarget.value)}
|
aria-label="{label} picker"
|
||||||
/>
|
value={isHex(value) ? value : fallback}
|
||||||
<input class="input join-item min-w-0 flex-1 font-mono text-sm" aria-label={label} {placeholder} {value} oninput={(e) => onChange(e.currentTarget.value.trim())} />
|
oninput={(e) => onChange(e.currentTarget.value)}
|
||||||
{#if value}
|
/>
|
||||||
<button class="btn join-item" type="button" aria-label="Reset {label} to default" title="Reset to default" onclick={() => onChange('')}>✕</button>
|
<input class="input join-item min-w-0 flex-1 font-mono text-sm" aria-label={label} {placeholder} {value} oninput={(e) => onChange(e.currentTarget.value.trim())} />
|
||||||
{/if}
|
{#if value}
|
||||||
|
<button class="btn join-item" type="button" aria-label="Reset {label} to default" title="Reset to default" onclick={() => onChange('')}>✕</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// One row of mutually exclusive options with an optional label column on
|
// One row of mutually exclusive options with an optional label column on
|
||||||
// the left — the standard "setting row" in the block editors (see
|
// the left (above it in a narrow row) — the standard "setting row" in the block editors (see
|
||||||
// ColorField for the colour variant; both share the label column width).
|
// ColorField for the colour variant; both share the label column width).
|
||||||
let {
|
let {
|
||||||
label,
|
label,
|
||||||
|
|
@ -25,22 +25,25 @@
|
||||||
} = $props();
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex items-center gap-3 {className}" role="group" aria-label={label}>
|
<!-- In a narrow row (a phone) the label goes above the buttons, so they keep room for their text. -->
|
||||||
{#if label}
|
<div class="@container {className}">
|
||||||
<span class="w-28 shrink-0 text-sm" class:font-bold={strong} class:font-medium={!strong}>{label}</span>
|
<div class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3" role="group" aria-label={label}>
|
||||||
{/if}
|
{#if label}
|
||||||
<div class="join grid flex-1" style="grid-template-columns: repeat({options.length}, minmax(0, 1fr))">
|
<span class="shrink-0 text-sm @sm:w-28" class:font-bold={strong} class:font-medium={!strong}>{label}</span>
|
||||||
{#each options as option}
|
{/if}
|
||||||
<button
|
<div class="join grid flex-1" style="grid-template-columns: repeat({options.length}, minmax(0, 1fr))">
|
||||||
type="button"
|
{#each options as option}
|
||||||
class="btn btn-sm join-item px-1"
|
<button
|
||||||
class:btn-active={value === option}
|
type="button"
|
||||||
class:btn-primary={value === option}
|
class="btn btn-sm join-item px-1"
|
||||||
aria-pressed={value === option}
|
class:btn-active={value === option}
|
||||||
onclick={() => onChange(option)}
|
class:btn-primary={value === option}
|
||||||
>
|
aria-pressed={value === option}
|
||||||
{formatLabel(option)}
|
onclick={() => onChange(option)}
|
||||||
</button>
|
>
|
||||||
{/each}
|
{formatLabel(option)}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import BlockList from '$lib/admin/BlockList.svelte';
|
import BlockList from '$lib/admin/BlockList.svelte';
|
||||||
|
import SaveStatus from '$lib/admin/SaveStatus.svelte';
|
||||||
import EmailBlockEditor from '$lib/admin/editors/EmailBlockEditor.svelte';
|
import EmailBlockEditor from '$lib/admin/editors/EmailBlockEditor.svelte';
|
||||||
import { createEmailBlock, emailBlockLabels, emailBlockTypes } from '$lib/admin/emailBlockDefaults';
|
import { createEmailBlock, emailBlockLabels, emailBlockTypes } from '$lib/admin/emailBlockDefaults';
|
||||||
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
||||||
|
|
@ -95,9 +96,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if form?.action === 'save' && form.message}
|
<SaveStatus result={form?.action === 'save' ? form : null} />
|
||||||
<div class="alert" class:alert-success={form.ok} class:alert-error={!form.ok}>{form.message}</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="space-y-2 rounded-box bg-base-100 p-5 shadow">
|
<div class="space-y-2 rounded-box bg-base-100 p-5 shadow">
|
||||||
<label class="label cursor-pointer gap-3 text-base-content">
|
<label class="label cursor-pointer gap-3 text-base-content">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import BlockList from '$lib/admin/BlockList.svelte';
|
import BlockList from '$lib/admin/BlockList.svelte';
|
||||||
|
import SaveStatus from '$lib/admin/SaveStatus.svelte';
|
||||||
import { blockLabels, blockTypes, createBlock } from '$lib/admin/blockDefaults';
|
import { blockLabels, blockTypes, createBlock } from '$lib/admin/blockDefaults';
|
||||||
import BlockEditor from '$lib/admin/editors/BlockEditor.svelte';
|
import BlockEditor from '$lib/admin/editors/BlockEditor.svelte';
|
||||||
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
||||||
|
|
@ -106,9 +107,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if form?.message}
|
<SaveStatus result={form} />
|
||||||
<div class="alert" class:alert-success={form.ok} class:alert-error={!form.ok} role="status">{form.message}</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="grid gap-4 rounded-box bg-base-100 p-5 shadow md:grid-cols-2">
|
<div class="grid gap-4 rounded-box bg-base-100 p-5 shadow md:grid-cols-2">
|
||||||
<label class="fieldset py-0">
|
<label class="fieldset py-0">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue