Admin UI consistency: DaisyUI 5 forms, shared modal and setting rows
- Migrate all DaisyUI 4 form markup (form-control, label-text, *-bordered — removed in v5) to v5 fieldset/legend; labels sat inline beside inputs and inputs fell back to a fixed 20rem width. - One Modal component (native <dialog>: Escape, focus trap) for page, event, item and slot editors; destructive actions confirmed everywhere. The page Delete confirm was ignored — returning false from onsubmit doesn't cancel — so Cancel still deleted the page. - Block editor follows the background-picker style throughout: SegmentedControl rows (title-cased options, clearer selected state) and a new ColorField row with reset; image position is Left/Right like the alignment controls. - Globals keep their layout; readable field labels, save feedback without reload, hints wrap. - Pages list: fixed broken Preview link (VITE_PUBLIC_SITE_URL was undefined → "undefined/slug"), shown for published pages only; action column no longer breaks row alignment; empty states on all tables. - Items: image picker instead of a raw media-id field, upload errors shown (were swallowed), prices in the shop currency instead of hard-coded EUR. - Slots/orders/calendar: times shown in the site timezone with a fixed locale (server and browser render the same text). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
cfe4e2062d
commit
af7b4af5de
16 changed files with 1237 additions and 1211 deletions
33
app-admin/src/lib/admin/Modal.svelte
Normal file
33
app-admin/src/lib/admin/Modal.svelte
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
// Shared dialog for create/edit forms, on the native <dialog> (Escape and
|
||||
// focus trapping for free). No click-outside-to-close: these hold forms,
|
||||
// and a stray click shouldn't throw away what was typed.
|
||||
let {
|
||||
open = $bindable(false),
|
||||
title,
|
||||
wide = false,
|
||||
children
|
||||
}: { open?: boolean; title: string; wide?: boolean; children: Snippet } = $props();
|
||||
|
||||
let dialog: HTMLDialogElement | undefined = $state();
|
||||
|
||||
$effect(() => {
|
||||
if (!dialog) return;
|
||||
if (open && !dialog.open) dialog.showModal();
|
||||
if (!open && dialog.open) dialog.close();
|
||||
});
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog} class="modal modal-bottom sm:modal-middle" onclose={() => (open = false)}>
|
||||
<div class={['modal-box', wide && 'sm:max-w-2xl']}>
|
||||
<div class="mb-4 flex items-start justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{title}</h2>
|
||||
<button class="btn btn-circle btn-ghost btn-sm" type="button" aria-label="Close" onclick={() => (open = false)}>✕</button>
|
||||
</div>
|
||||
{#if open}
|
||||
{@render children()}
|
||||
{/if}
|
||||
</div>
|
||||
</dialog>
|
||||
13
app-admin/src/lib/admin/confirm.ts
Normal file
13
app-admin/src/lib/admin/confirm.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* `onsubmit` / `onclick` handler that asks for confirmation and cancels the
|
||||
* submit if declined. (Returning `false` from a handler does NOT cancel the
|
||||
* event — it has to call preventDefault.)
|
||||
*
|
||||
* <form onsubmit={confirmSubmit('Delete this page?')}>
|
||||
* <button formaction="?/delete" onclick={confirmSubmit('Delete this event?')}>
|
||||
*/
|
||||
export function confirmSubmit(message: string) {
|
||||
return (event: Event) => {
|
||||
if (!confirm(message)) event.preventDefault();
|
||||
};
|
||||
}
|
||||
|
|
@ -1,301 +1,196 @@
|
|||
<script lang="ts">
|
||||
import type { BlockType, ContentBlock } from '$lib/types';
|
||||
import { blockLabels } from '$lib/admin/blockDefaults';
|
||||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import ShopBlockEditor from './ShopBlockEditor.svelte';
|
||||
import CheckoutBlockEditor from './CheckoutBlockEditor.svelte';
|
||||
|
||||
let { block, eventCategories = [], items = [], onChange = (block: ContentBlock) => {} } = $props<{
|
||||
block: ContentBlock | null;
|
||||
eventCategories?: string[];
|
||||
items?: { id: string; name: string; type: string }[];
|
||||
onChange?: (block: ContentBlock) => void;
|
||||
}>();
|
||||
|
||||
function updateData(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
block = { ...block, data: { ...block.data, ...patch } };
|
||||
onChange(block);
|
||||
}
|
||||
|
||||
function updateArray(key: string, index: number, patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
const items = [...(block.data[key] || [])];
|
||||
items[index] = { ...items[index], ...patch };
|
||||
updateData({ [key]: items });
|
||||
}
|
||||
|
||||
function addArrayItem(key: string, item: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ [key]: [...(block.data[key] || []), item] });
|
||||
}
|
||||
|
||||
function removeArrayItem(key: string, index: number) {
|
||||
if (!block) return;
|
||||
updateData({ [key]: (block.data[key] || []).filter((_: unknown, i: number) => i !== index) });
|
||||
}
|
||||
|
||||
function toggleCategory(category: string) {
|
||||
if (!block) return;
|
||||
const categories = block.data.categories || [];
|
||||
updateData({
|
||||
categories: categories.includes(category)
|
||||
? categories.filter((item: string) => item !== category)
|
||||
: [...categories, category]
|
||||
});
|
||||
}
|
||||
|
||||
function titleCase(value: string | number) {
|
||||
const text = String(value);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if !block}
|
||||
<div class="rounded-box bg-base-100 p-8 text-center text-base-content/60 shadow">Select a block to edit.</div>
|
||||
{:else}
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<h2 class="mb-4 text-2xl font-bold">{blockLabels[block.type as BlockType]}</h2>
|
||||
|
||||
{#if block.type === 'text'}
|
||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||
{:else if block.type === 'image_text'}
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<div class="form-control mt-3">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<span class="label-text">Image position</span>
|
||||
<input type="checkbox" class="toggle toggle-primary" checked={block.data.imagePosition === 'right'} onchange={(e) => updateData({ imagePosition: e.currentTarget.checked ? 'right' : 'left' })} />
|
||||
<span class="text-sm text-base-content/60">{block.data.imagePosition === 'right' ? 'Right' : 'Left'}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-3"><RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} /></div>
|
||||
{:else if block.type === 'timeline'}
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box mb-3 border border-base-300 p-3">
|
||||
<input class="input input-bordered mb-2 w-full" placeholder="Title" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
<textarea class="textarea textarea-bordered w-full" placeholder="Description" value={item.description} oninput={(e) => updateArray('items', i, { description: e.currentTarget.value })}></textarea>
|
||||
<button class="btn btn-error btn-sm mt-2" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { title: '', description: '' })}>Add item</button>
|
||||
{:else if block.type === 'hero'}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Heading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Subheading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.subheading || ''} oninput={(e) => updateData({ subheading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonLabel || ''} oninput={(e) => updateData({ buttonLabel: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button URL</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonUrl || ''} oninput={(e) => updateData({ buttonUrl: e.currentTarget.value })} />
|
||||
</label>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">URL</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<div class="form-control mt-5">
|
||||
<SegmentedControl
|
||||
label="Variant"
|
||||
options={['primary', 'secondary']}
|
||||
value={block.data.variant || 'primary'}
|
||||
onChange={(v) => updateData({ variant: v })}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<SegmentedControl
|
||||
label="Alignment"
|
||||
options={['left', 'center', 'right']}
|
||||
value={block.data.alignment || 'left'}
|
||||
onChange={(v) => updateData({ alignment: v })}
|
||||
formatLabel={titleCase}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<SegmentedControl
|
||||
label="Size"
|
||||
options={['xs', 'sm', 'md', 'lg']}
|
||||
value={block.data.size || 'md'}
|
||||
onChange={(v) => updateData({ size: v })}
|
||||
formatLabel={(v) => String({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[String(v)] || v)}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Color</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data.color || 'var(--color-primary)'} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
<input class="input input-bordered flex-1" placeholder="Leave empty to use global primary" value={block.data.color || ''} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Height (px)</span></div>
|
||||
<input type="number" class="input input-bordered w-full" value={block.data.height || 64} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 64 })} />
|
||||
</label>
|
||||
</div>
|
||||
{:else if block.type === 'testimonials'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box mb-3 border border-base-300 p-4">
|
||||
<textarea
|
||||
class="textarea textarea-bordered w-full mb-2"
|
||||
placeholder="Testimonial text"
|
||||
rows="3"
|
||||
value={item.text}
|
||||
oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}
|
||||
></textarea>
|
||||
<input
|
||||
class="input input-bordered w-full"
|
||||
placeholder="Author name"
|
||||
value={item.title}
|
||||
oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })}
|
||||
/>
|
||||
<button class="btn btn-error btn-sm mt-2" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { text: '', title: '' })}>Add testimonial</button>
|
||||
</div>
|
||||
{:else if block.type === 'upcoming_calendar'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4">
|
||||
<div class="mb-3">
|
||||
<h3 class="font-semibold">Category filters</h3>
|
||||
<p class="text-sm text-base-content/60">Choose categories to show in this block. Leave all unchecked to show every published event.</p>
|
||||
</div>
|
||||
{#if eventCategories?.length}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each eventCategories as category}
|
||||
<label class="btn btn-sm" class:btn-primary={(block.data.categories || []).includes(category)}>
|
||||
<input class="hidden" type="checkbox" checked={(block.data.categories || []).includes(category)} onchange={() => toggleCategory(category)} />
|
||||
{category}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-base-content/60">No event categories exist yet. Create events in the Calendar admin page first.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{:else if block.type === 'shop'}
|
||||
<ShopBlockEditor {block} {items} {onChange} />
|
||||
{:else if block.type === 'checkout'}
|
||||
<CheckoutBlockEditor {block} {onChange} />
|
||||
{/if}
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4 mt-4">
|
||||
|
||||
<!-- Background Type Selector -->
|
||||
<div class="mb-4">
|
||||
<SegmentedControl
|
||||
label="Background"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['none', 'color', 'image']}
|
||||
value={block.data._background?.type || 'none'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), type: v } })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if block.data._background?.type === 'color'}
|
||||
<div class="space-y-3">
|
||||
<label class="form-control">
|
||||
<span class="label-text text-sm">Color</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<input class="input input-bordered w-12 h-10 p-1 cursor-pointer" type="color" value={block.data._background?.color || '#66755d'} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#66755d or sage" value={block.data._background?.color || ''} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if block.data._background?.type === 'image'}
|
||||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateData({ _background: { ...(block.data._background || {}), imageUrl: image.url, imageAlt: image.alt } })} />
|
||||
|
||||
<SegmentedControl
|
||||
label="Attachment"
|
||||
options={['scroll', 'fixed']}
|
||||
value={block.data._background?.attachment || 'scroll'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), attachment: v } })}
|
||||
/>
|
||||
|
||||
<SegmentedControl
|
||||
label="Overlay"
|
||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
||||
value={block.data._background?.overlayOpacity ?? 0}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), overlay: true, overlayOpacity: v } })}
|
||||
formatLabel={(v) => `${v}%`}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<hr class="border-base-content/10 my-4" />
|
||||
|
||||
<SegmentedControl
|
||||
label="Foreground"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['default', 'custom']}
|
||||
value={block.data._foreground?.mode || 'default'}
|
||||
onChange={(v) => updateData({ _foreground: { ...(block.data._foreground || {}), mode: v } })}
|
||||
/>
|
||||
|
||||
{#if block.data._foreground?.mode === 'custom'}
|
||||
<div class="mt-4 space-y-3">
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Heading</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.headingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.headingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Sub heading</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.subheadingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.subheadingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Text</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.textColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.textColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<script lang="ts">
|
||||
import type { BlockType, ContentBlock } from '$lib/types';
|
||||
import { blockLabels } from '$lib/admin/blockDefaults';
|
||||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import ColorField from './ColorField.svelte';
|
||||
import ShopBlockEditor from './ShopBlockEditor.svelte';
|
||||
import CheckoutBlockEditor from './CheckoutBlockEditor.svelte';
|
||||
|
||||
let { block, eventCategories = [], items = [], onChange = (block: ContentBlock) => {} } = $props<{
|
||||
block: ContentBlock | null;
|
||||
eventCategories?: string[];
|
||||
items?: { id: string; name: string; type: string }[];
|
||||
onChange?: (block: ContentBlock) => void;
|
||||
}>();
|
||||
|
||||
function updateData(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
block = { ...block, data: { ...block.data, ...patch } };
|
||||
onChange(block);
|
||||
}
|
||||
|
||||
function updateArray(key: string, index: number, patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
const items = [...(block.data[key] || [])];
|
||||
items[index] = { ...items[index], ...patch };
|
||||
updateData({ [key]: items });
|
||||
}
|
||||
|
||||
function addArrayItem(key: string, item: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ [key]: [...(block.data[key] || []), item] });
|
||||
}
|
||||
|
||||
function removeArrayItem(key: string, index: number) {
|
||||
if (!block) return;
|
||||
updateData({ [key]: (block.data[key] || []).filter((_: unknown, i: number) => i !== index) });
|
||||
}
|
||||
|
||||
function toggleCategory(category: string) {
|
||||
if (!block) return;
|
||||
const categories = block.data.categories || [];
|
||||
updateData({
|
||||
categories: categories.includes(category)
|
||||
? categories.filter((item: string) => item !== category)
|
||||
: [...categories, category]
|
||||
});
|
||||
}
|
||||
|
||||
function updateBackground(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ _background: { ...(block.data._background || {}), ...patch } });
|
||||
}
|
||||
|
||||
function updateForeground(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ _foreground: { ...(block.data._foreground || {}), ...patch } });
|
||||
}
|
||||
|
||||
const sizeLabels: Record<string, string> = { xs: 'XS', sm: 'Small', md: 'Medium', lg: 'Large' };
|
||||
</script>
|
||||
|
||||
{#snippet field(label: string, value: string, onInput: (value: string) => void, placeholder = '')}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">{label}</span>
|
||||
<input class="input w-full" {placeholder} {value} oninput={(e) => onInput(e.currentTarget.value)} />
|
||||
</label>
|
||||
{/snippet}
|
||||
|
||||
{#if !block}
|
||||
<div class="rounded-box bg-base-100 p-8 text-center text-base-content/60 shadow">Select a block to edit.</div>
|
||||
{:else}
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<h2 class="mb-4 text-2xl font-bold">{blockLabels[block.type as BlockType]}</h2>
|
||||
|
||||
{#if block.type === 'text'}
|
||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||
{:else if block.type === 'image_text'}
|
||||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<SegmentedControl label="Image position" options={['left', 'right']} value={block.data.imagePosition === 'right' ? 'right' : 'left'} onChange={(v) => updateData({ imagePosition: v })} />
|
||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||
</div>
|
||||
{:else if block.type === 'timeline'}
|
||||
<div class="space-y-3">
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box border border-base-300 p-3">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-base-content/60">Item {i + 1}</span>
|
||||
<button class="btn btn-ghost btn-xs text-error" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
<input class="input mb-2 w-full" aria-label="Title" placeholder="Title" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
<textarea class="textarea w-full" aria-label="Description" placeholder="Description" value={item.description} oninput={(e) => updateArray('items', i, { description: e.currentTarget.value })}></textarea>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn btn-sm" type="button" onclick={() => addArrayItem('items', { title: '', description: '' })}>Add item</button>
|
||||
</div>
|
||||
{:else if block.type === 'hero'}
|
||||
{@render field('Heading', block.data.heading || '', (heading) => updateData({ heading }))}
|
||||
{@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))}
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
{@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))}
|
||||
{@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), '/page or https://…')}
|
||||
</div>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
{@render field('Button label', block.data.label || '', (label) => updateData({ label }))}
|
||||
{@render field('URL', block.data.href || '', (href) => updateData({ href }), '/page or https://…')}
|
||||
</div>
|
||||
<div class="mt-4 space-y-3">
|
||||
<SegmentedControl label="Variant" options={['primary', 'secondary']} value={block.data.variant || 'primary'} onChange={(v) => updateData({ variant: v })} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'left'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<SegmentedControl label="Size" options={['xs', 'sm', 'md', 'lg']} value={block.data.size || 'md'} onChange={(v) => updateData({ size: v })} formatLabel={(v) => sizeLabels[String(v)] || String(v)} />
|
||||
<ColorField label="Color" value={block.data.color || ''} fallback="#8a9a7b" placeholder="Site primary color" onChange={(color) => updateData({ color })} />
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Height (px)</span>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="8"
|
||||
class="input w-full"
|
||||
value={block.data.height ?? 64}
|
||||
oninput={(e) => {
|
||||
const height = parseInt(e.currentTarget.value, 10);
|
||||
if (!Number.isNaN(height) && height >= 0) updateData({ height });
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
{:else if block.type === 'testimonials'}
|
||||
{@render field('Section title', block.data.title || '', (title) => updateData({ title }))}
|
||||
<div class="mt-3 space-y-3">
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box border border-base-300 p-3">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-base-content/60">Testimonial {i + 1}</span>
|
||||
<button class="btn btn-ghost btn-xs text-error" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
<textarea class="textarea mb-2 w-full" aria-label="Testimonial text" placeholder="Testimonial text" rows="3" value={item.text} oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}></textarea>
|
||||
<input class="input w-full" aria-label="Author name" placeholder="Author name" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn btn-sm" type="button" onclick={() => addArrayItem('items', { text: '', title: '' })}>Add testimonial</button>
|
||||
</div>
|
||||
{:else if block.type === 'upcoming_calendar'}
|
||||
{@render field('Section title', block.data.title || '', (title) => updateData({ title }))}
|
||||
<div class="mt-3 rounded-box border border-base-300 p-4">
|
||||
<h3 class="font-semibold">Category filters</h3>
|
||||
<p class="mb-3 text-sm text-base-content/60">Choose categories to show in this block. Leave all unselected to show every published event.</p>
|
||||
{#if eventCategories?.length}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each eventCategories as category}
|
||||
<button type="button" class="btn btn-xs" class:btn-primary={(block.data.categories || []).includes(category)} aria-pressed={(block.data.categories || []).includes(category)} onclick={() => toggleCategory(category)}>{category}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-base-content/60">No event categories exist yet. Add categories to events in Calendar first.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if block.type === 'shop'}
|
||||
<ShopBlockEditor {block} {items} {onChange} />
|
||||
{:else if block.type === 'checkout'}
|
||||
<CheckoutBlockEditor {block} {onChange} />
|
||||
{/if}
|
||||
|
||||
<div class="mt-6 space-y-3 rounded-box border border-base-300 p-4">
|
||||
<SegmentedControl label="Background" strong options={['none', 'color', 'image']} value={block.data._background?.type || 'none'} onChange={(type) => updateBackground({ type })} />
|
||||
|
||||
{#if block.data._background?.type === 'color'}
|
||||
<ColorField label="Color" value={block.data._background?.color || ''} fallback="#66755d" placeholder="#66755d" onChange={(color) => updateBackground({ color })} />
|
||||
{:else if block.data._background?.type === 'image'}
|
||||
<ImageUploader 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}%`)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<hr class="border-base-300" />
|
||||
|
||||
<SegmentedControl label="Foreground" strong options={['default', 'custom']} value={block.data._foreground?.mode || 'default'} onChange={(mode) => updateForeground({ mode })} />
|
||||
|
||||
{#if block.data._foreground?.mode === 'custom'}
|
||||
<ColorField label="Heading" value={block.data._foreground?.headingColor || ''} fallback="#2c2c2c" onChange={(headingColor) => updateForeground({ headingColor })} />
|
||||
<ColorField label="Subheading" value={block.data._foreground?.subheadingColor || ''} fallback="#4a4a4a" onChange={(subheadingColor) => updateForeground({ subheadingColor })} />
|
||||
<ColorField label="Text" value={block.data._foreground?.textColor || ''} fallback="#2c2c2c" onChange={(textColor) => updateForeground({ textColor })} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@
|
|||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Title</span>
|
||||
<input class="input w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Heading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Heading</span>
|
||||
<input class="input w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Notes label</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="Notes or special requests" value={block.data.notesLabel || ''} oninput={(e) => updateData({ notesLabel: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Notes label</span>
|
||||
<input class="input w-full" placeholder="Notes or special requests" value={block.data.notesLabel || ''} oninput={(e) => updateData({ notesLabel: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">Customer fields (name, email, phone, notes) and the payment flow are fixed and cannot be changed here.</p>
|
||||
</div>
|
||||
|
|
|
|||
37
app-admin/src/lib/admin/editors/ColorField.svelte
Normal file
37
app-admin/src/lib/admin/editors/ColorField.svelte
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script lang="ts">
|
||||
// Colour setting row: label column, swatch picker, free-text value (hex or
|
||||
// any CSS colour) and a clear button. Empty = "use the default".
|
||||
let {
|
||||
label,
|
||||
value = '',
|
||||
fallback = '#000000',
|
||||
placeholder = 'Default',
|
||||
onChange
|
||||
}: {
|
||||
label: string;
|
||||
value?: string;
|
||||
/** Swatch colour shown while the value is empty or not a hex colour. */
|
||||
fallback?: string;
|
||||
placeholder?: string;
|
||||
onChange: (value: string) => void;
|
||||
} = $props();
|
||||
|
||||
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}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import ColorField from './ColorField.svelte';
|
||||
|
||||
let { block, primaryColor = '#8a9a7b', onChange = (block: EmailBlock) => {} } = $props<{
|
||||
block: EmailBlock | null;
|
||||
|
|
@ -17,11 +18,6 @@
|
|||
onChange(block);
|
||||
}
|
||||
|
||||
function titleCase(value: string | number) {
|
||||
const text = String(value);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
const autoFilled: Record<string, string> = {
|
||||
booking_details: 'Filled in automatically with the booked services, date and time, prices and the total paid.',
|
||||
customer_details: "Filled in automatically with the customer's name, email, phone and checkout notes.",
|
||||
|
|
@ -42,46 +38,38 @@
|
|||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<SegmentedControl label="Width" options={[100, 75, 50, 25]} value={Number(block.data.width) || 100} onChange={(v) => updateData({ width: v })} formatLabel={(v) => `${v}%`} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} formatLabel={titleCase} />
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Link (optional)</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="https://… or /page" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Link (optional)</span>
|
||||
<input class="input w-full" placeholder="https://… or /page" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">Images load from the public media server, so they only appear in real inboxes once the site runs on a public domain.</p>
|
||||
</div>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Button label</span>
|
||||
<input class="input w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">URL</span></div>
|
||||
<input class="input input-bordered w-full" placeholder={'https://…, /page or {{site_url}}'} value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">URL</span>
|
||||
<input class="input w-full" placeholder={'https://…, /page or {{site_url}}'} value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} formatLabel={titleCase} />
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Color</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered h-10 w-10 cursor-pointer p-1" type="color" value={block.data.color || primaryColor} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
<input class="input input-bordered flex-1" placeholder="Leave empty to use global primary" value={block.data.color || ''} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<ColorField label="Color" value={block.data.color || ''} fallback={primaryColor} placeholder="Site primary color" onChange={(color) => updateData({ color })} />
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Height (px)</span></div>
|
||||
<input type="number" min="0" class="input input-bordered w-full" value={block.data.height ?? 24} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 0 })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Height (px)</span>
|
||||
<input type="number" min="0" class="input w-full" value={block.data.height ?? 24} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 0 })} />
|
||||
</label>
|
||||
{:else if block.type === 'divider'}
|
||||
<p class="text-base-content/60">A thin horizontal line. No settings.</p>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section title</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="Leave empty for no title" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Section title</span>
|
||||
<input class="input w-full" placeholder="Leave empty for no title" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">{autoFilled[block.type]}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,105 +1,107 @@
|
|||
<script lang="ts">
|
||||
import { uploadMedia } from '$lib/pb';
|
||||
|
||||
let { url: urlProp = '', alt: altProp = '', onChange = (value: { url: string; alt: string }) => {} } = $props<{
|
||||
url?: string;
|
||||
alt?: string;
|
||||
onChange?: (value: { url: string; alt: string }) => void;
|
||||
}>();
|
||||
|
||||
let uploading = $state(false);
|
||||
let error = $state('');
|
||||
let fileInput = $state<HTMLInputElement>();
|
||||
|
||||
// Local state synced from props so reactivity works reliably in Svelte 5
|
||||
let localUrl = $state(urlProp);
|
||||
let localAlt = $state(altProp);
|
||||
|
||||
$effect(() => { localUrl = urlProp; });
|
||||
$effect(() => { localAlt = altProp; });
|
||||
|
||||
function emitChange() {
|
||||
onChange({ url: localUrl, alt: localAlt });
|
||||
}
|
||||
|
||||
async function handleFile(event: Event) {
|
||||
const file = (event.currentTarget as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
uploading = true;
|
||||
error = '';
|
||||
try {
|
||||
const result = await uploadMedia(file);
|
||||
localUrl = result.url;
|
||||
emitChange();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'Upload failed';
|
||||
console.error('Image upload error:', e);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function removeImage() {
|
||||
localUrl = '';
|
||||
localAlt = '';
|
||||
emitChange();
|
||||
if (fileInput) fileInput.value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="grid grid-cols-[1fr_1.5fr] gap-4">
|
||||
<!-- Drop zone / upload area -->
|
||||
<div
|
||||
class="flex h-32 cursor-pointer flex-col items-center justify-center rounded-box border-2 border-dashed p-3 transition-colors hover:border-primary {localUrl ? 'border-success/40' : 'border-base-300'}"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => fileInput?.click()}
|
||||
onkeydown={(e) => e.key === 'Enter' && fileInput?.click()}
|
||||
>
|
||||
{#if uploading}
|
||||
<span class="loading loading-spinner loading-lg text-primary"></span>
|
||||
<p class="mt-3 text-sm text-base-content/60">Uploading…</p>
|
||||
{:else if localUrl}
|
||||
<div class="relative w-full">
|
||||
<img class="max-h-28 w-full rounded-box object-cover shadow" src={localUrl} alt={localAlt} />
|
||||
<button
|
||||
class="btn btn-circle btn-error btn-outline btn-xs absolute right-1 top-1"
|
||||
type="button"
|
||||
onclick={(e) => { e.stopPropagation(); removeImage(); }}
|
||||
title="Remove image"
|
||||
>✕</button>
|
||||
</div>
|
||||
{:else}
|
||||
<svg class="mb-2 size-8 text-base-content/40" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />
|
||||
</svg>
|
||||
<p class="text-center text-sm font-medium text-base-content/70">Upload image</p>
|
||||
<p class="text-xs text-base-content/40">PNG, JPG, WebP</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="alert alert-error col-span-full text-sm">{error}</div>
|
||||
{/if}
|
||||
|
||||
<input
|
||||
class="hidden"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onchange={handleFile}
|
||||
disabled={uploading}
|
||||
bind:this={fileInput}
|
||||
/>
|
||||
|
||||
<!-- URL & Alt fields -->
|
||||
<div class="space-y-3">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Image URL</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={localUrl} oninput={() => emitChange()} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Alt text</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={localAlt} oninput={() => emitChange()} />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<script lang="ts">
|
||||
import { uploadMedia } from '$lib/pb';
|
||||
|
||||
let { url: urlProp = '', alt: altProp = '', onChange = (value: { url: string; alt: string }) => {} } = $props<{
|
||||
url?: string;
|
||||
alt?: string;
|
||||
onChange?: (value: { url: string; alt: string }) => void;
|
||||
}>();
|
||||
|
||||
let uploading = $state(false);
|
||||
let error = $state('');
|
||||
let fileInput = $state<HTMLInputElement>();
|
||||
|
||||
// Local state synced from props so reactivity works reliably in Svelte 5
|
||||
let localUrl = $state(urlProp);
|
||||
let localAlt = $state(altProp);
|
||||
|
||||
$effect(() => { localUrl = urlProp; });
|
||||
$effect(() => { localAlt = altProp; });
|
||||
|
||||
function emitChange() {
|
||||
onChange({ url: localUrl, alt: localAlt });
|
||||
}
|
||||
|
||||
async function handleFile(event: Event) {
|
||||
const file = (event.currentTarget as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
uploading = true;
|
||||
error = '';
|
||||
try {
|
||||
const result = await uploadMedia(file);
|
||||
localUrl = result.url;
|
||||
// Keep a hand-written alt text; otherwise use the one derived from the filename.
|
||||
if (!localAlt) localAlt = result.record?.alt || '';
|
||||
emitChange();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'Upload failed';
|
||||
console.error('Image upload error:', e);
|
||||
} finally {
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function removeImage() {
|
||||
localUrl = '';
|
||||
localAlt = '';
|
||||
emitChange();
|
||||
if (fileInput) fileInput.value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="grid grid-cols-[1fr_1.5fr] gap-4">
|
||||
<!-- Drop zone / upload area -->
|
||||
<div
|
||||
class="flex h-32 cursor-pointer flex-col items-center justify-center rounded-box border-2 border-dashed p-3 transition-colors hover:border-primary {localUrl ? 'border-success/40' : 'border-base-300'}"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => fileInput?.click()}
|
||||
onkeydown={(e) => e.key === 'Enter' && fileInput?.click()}
|
||||
>
|
||||
{#if uploading}
|
||||
<span class="loading loading-spinner loading-lg text-primary"></span>
|
||||
<p class="mt-3 text-sm text-base-content/60">Uploading…</p>
|
||||
{:else if localUrl}
|
||||
<div class="relative w-full">
|
||||
<img class="max-h-28 w-full rounded-box object-cover shadow" src={localUrl} alt={localAlt} />
|
||||
<button
|
||||
class="btn btn-circle btn-error btn-outline btn-xs absolute right-1 top-1"
|
||||
type="button"
|
||||
onclick={(e) => { e.stopPropagation(); removeImage(); }}
|
||||
title="Remove image"
|
||||
>✕</button>
|
||||
</div>
|
||||
{:else}
|
||||
<svg class="mb-2 size-8 text-base-content/40" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />
|
||||
</svg>
|
||||
<p class="text-center text-sm font-medium text-base-content/70">Upload image</p>
|
||||
<p class="text-xs text-base-content/40">PNG, JPG, WebP</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
<div class="alert alert-error col-span-full text-sm">{error}</div>
|
||||
{/if}
|
||||
|
||||
<input
|
||||
class="hidden"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onchange={handleFile}
|
||||
disabled={uploading}
|
||||
bind:this={fileInput}
|
||||
/>
|
||||
|
||||
<!-- URL & Alt fields -->
|
||||
<div>
|
||||
<label class="fieldset pt-0">
|
||||
<span class="fieldset-legend">Image URL</span>
|
||||
<input class="input w-full" bind:value={localUrl} oninput={() => emitChange()} />
|
||||
</label>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Alt text</span>
|
||||
<input class="input w-full" bind:value={localAlt} oninput={() => emitChange()} />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,46 @@
|
|||
<script lang="ts">
|
||||
let {
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
formatLabel = (v: string | number) => String(v),
|
||||
labelStyle = '',
|
||||
class: className = ''
|
||||
}: {
|
||||
label?: string;
|
||||
options: (string | number)[];
|
||||
value: string | number;
|
||||
onChange: (value: string | number) => void;
|
||||
formatLabel?: (value: string | number) => string;
|
||||
labelStyle?: string;
|
||||
class?: string;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="form-control {className}">
|
||||
<div class="flex items-center justify-between">
|
||||
{#if label}
|
||||
<span class="label-text w-24" style={labelStyle}>{label}</span>
|
||||
{/if}
|
||||
<div class="grid flex-1" style="grid-template-columns: repeat({options.length}, 1fr)">
|
||||
{#each options as option, i}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm {i === 0 ? 'rounded-r-none' : ''} {i === options.length - 1 ? 'rounded-l-none' : ''} {value === option ? 'btn-active' : ''}"
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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
|
||||
// ColorField for the colour variant; both share the label column width).
|
||||
let {
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
formatLabel = (v: string | number) => {
|
||||
const text = String(v);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
},
|
||||
strong = false,
|
||||
class: className = ''
|
||||
}: {
|
||||
label?: string;
|
||||
options: (string | number)[];
|
||||
value: string | number;
|
||||
onChange: (value: string | number) => void;
|
||||
formatLabel?: (value: string | number) => string;
|
||||
/** Bold label, for section-level settings like Background/Foreground. */
|
||||
strong?: boolean;
|
||||
class?: string;
|
||||
} = $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}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@
|
|||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Title</span>
|
||||
<input class="input w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<SegmentedControl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue