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
|
|
@ -43,6 +43,34 @@
|
|||
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) {
|
||||
const to = index + delta;
|
||||
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
|
||||
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)}
|
||||
<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'}"
|
||||
|
|
@ -78,7 +106,18 @@
|
|||
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
|
||||
type="button"
|
||||
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}
|
||||
|
||||
<div class="mt-6 space-y-3 rounded-box border border-base-300 p-4">
|
||||
<label class="flex items-center gap-3">
|
||||
<span class="w-28 shrink-0 text-sm font-bold">Anchor</span>
|
||||
<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) })} />
|
||||
</label>
|
||||
<div class="@container">
|
||||
<label class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||
<span class="shrink-0 text-sm font-bold @sm:w-28">Anchor</span>
|
||||
<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" />
|
||||
|
||||
|
|
@ -257,13 +259,17 @@
|
|||
{: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 })} />
|
||||
<SegmentedControl label="Attachment" options={['scroll', 'fixed']} value={block.data._background?.attachment || 'scroll'} onChange={(attachment) => updateBackground({ attachment })} />
|
||||
<SegmentedControl
|
||||
label="Overlay"
|
||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
||||
value={block.data._background?.overlay ? (block.data._background?.overlayOpacity ?? 40) : 0}
|
||||
onChange={(v) => updateBackground({ overlay: Number(v) > 0, overlayOpacity: Number(v) })}
|
||||
formatLabel={(v) => (Number(v) === 0 ? 'None' : `${v}%`)}
|
||||
/>
|
||||
{@const overlay = block.data._background?.overlay ? (block.data._background?.overlayOpacity ?? 40) : 0}
|
||||
<!-- A slider: ten buttons don't fit a phone. -->
|
||||
<div class="@container">
|
||||
<label class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||
<span class="shrink-0 text-sm font-medium @sm:w-28">Overlay</span>
|
||||
<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}
|
||||
|
||||
<hr class="border-base-300" />
|
||||
|
|
|
|||
|
|
@ -19,19 +19,22 @@
|
|||
const isHex = (v: string) => /^#[0-9a-f]{6}$/i.test(v);
|
||||
</script>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="w-28 shrink-0 text-sm font-medium">{label}</span>
|
||||
<div class="join flex-1">
|
||||
<input
|
||||
class="input join-item w-12 cursor-pointer p-1"
|
||||
type="color"
|
||||
aria-label="{label} picker"
|
||||
value={isHex(value) ? value : fallback}
|
||||
oninput={(e) => onChange(e.currentTarget.value)}
|
||||
/>
|
||||
<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 value}
|
||||
<button class="btn join-item" type="button" aria-label="Reset {label} to default" title="Reset to default" onclick={() => onChange('')}>✕</button>
|
||||
{/if}
|
||||
<!-- Label above the field in a narrow row, like SegmentedControl. -->
|
||||
<div class="@container">
|
||||
<div class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3">
|
||||
<span class="shrink-0 text-sm font-medium @sm:w-28">{label}</span>
|
||||
<div class="join flex-1">
|
||||
<input
|
||||
class="input join-item w-12 cursor-pointer p-1"
|
||||
type="color"
|
||||
aria-label="{label} picker"
|
||||
value={isHex(value) ? value : fallback}
|
||||
oninput={(e) => onChange(e.currentTarget.value)}
|
||||
/>
|
||||
<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 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>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
// 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).
|
||||
let {
|
||||
label,
|
||||
|
|
@ -25,22 +25,25 @@
|
|||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="flex items-center gap-3 {className}" role="group" aria-label={label}>
|
||||
{#if label}
|
||||
<span class="w-28 shrink-0 text-sm" class:font-bold={strong} class:font-medium={!strong}>{label}</span>
|
||||
{/if}
|
||||
<div class="join grid flex-1" style="grid-template-columns: repeat({options.length}, minmax(0, 1fr))">
|
||||
{#each options as option}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm join-item px-1"
|
||||
class:btn-active={value === option}
|
||||
class:btn-primary={value === option}
|
||||
aria-pressed={value === option}
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
<!-- In a narrow row (a phone) the label goes above the buttons, so they keep room for their text. -->
|
||||
<div class="@container {className}">
|
||||
<div class="flex flex-col gap-1 @sm:flex-row @sm:items-center @sm:gap-3" role="group" aria-label={label}>
|
||||
{#if label}
|
||||
<span class="shrink-0 text-sm @sm:w-28" class:font-bold={strong} class:font-medium={!strong}>{label}</span>
|
||||
{/if}
|
||||
<div class="join grid flex-1" style="grid-template-columns: repeat({options.length}, minmax(0, 1fr))">
|
||||
{#each options as option}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm join-item px-1"
|
||||
class:btn-active={value === option}
|
||||
class:btn-primary={value === option}
|
||||
aria-pressed={value === option}
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import BlockList from '$lib/admin/BlockList.svelte';
|
||||
import SaveStatus from '$lib/admin/SaveStatus.svelte';
|
||||
import EmailBlockEditor from '$lib/admin/editors/EmailBlockEditor.svelte';
|
||||
import { createEmailBlock, emailBlockLabels, emailBlockTypes } from '$lib/admin/emailBlockDefaults';
|
||||
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
||||
|
|
@ -95,9 +96,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if form?.action === 'save' && form.message}
|
||||
<div class="alert" class:alert-success={form.ok} class:alert-error={!form.ok}>{form.message}</div>
|
||||
{/if}
|
||||
<SaveStatus result={form?.action === 'save' ? form : null} />
|
||||
|
||||
<div class="space-y-2 rounded-box bg-base-100 p-5 shadow">
|
||||
<label class="label cursor-pointer gap-3 text-base-content">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import BlockList from '$lib/admin/BlockList.svelte';
|
||||
import SaveStatus from '$lib/admin/SaveStatus.svelte';
|
||||
import { blockLabels, blockTypes, createBlock } from '$lib/admin/blockDefaults';
|
||||
import BlockEditor from '$lib/admin/editors/BlockEditor.svelte';
|
||||
import { warnOnUnsavedChanges } from '$lib/admin/unsaved.svelte';
|
||||
|
|
@ -106,9 +107,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if form?.message}
|
||||
<div class="alert" class:alert-success={form.ok} class:alert-error={!form.ok} role="status">{form.message}</div>
|
||||
{/if}
|
||||
<SaveStatus result={form} />
|
||||
|
||||
<div class="grid gap-4 rounded-box bg-base-100 p-5 shadow md:grid-cols-2">
|
||||
<label class="fieldset py-0">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue