diff --git a/AGENTS.md b/AGENTS.md index d34dda3..d9a3db9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,7 +14,7 @@ packages/shared/src/ # Shared code (types, calendar utils, blocks, pb, app-admin/ # SvelteKit admin app (serves admin.) ├── src/ │ ├── lib/ -│ │ ├── admin/ # Admin UI components (BlockList, editors) +│ │ ├── admin/ # Admin UI components (BlockList, Modal, editors, confirm/unsaved helpers) │ │ ├── blocks/ # Re-exports from $shared/blocks (block renderers live in shared) │ │ ├── pb.ts # Re-exports from $shared/pb + app-specific uploadMedia │ │ ├── types.ts # Re-exports from $shared @@ -22,17 +22,18 @@ app-admin/ # SvelteKit admin app (serves admin.) │ │ ├── scrollReveal.ts # Re-exports from $shared │ │ ├── stripe-client.ts # Re-exports from $shared │ │ ├── basket.svelte.ts # Re-exports from $shared -│ │ └── server/ # Re-exports from $shared/server (pb-admin, basket) +│ │ └── server/ # Re-exports from $shared/server + admin helpers (actions.ts, pages.ts) │ ├── routes/ -│ │ ├── +layout.svelte # Root layout (admin shell: navbar, export/import, logout) +│ │ ├── +layout.svelte # Root layout (admin shell: grouped sidebar; bare on /login and /preview) │ │ ├── login/ # Admin login │ │ ├── pages/ # Page CRUD + block editor -│ │ ├── calendar/ # Event CRUD -│ │ ├── items/ # Service/product CRUD +│ │ ├── calendar/ # Event CRUD (menu label: Events) +│ │ ├── items/ # Service/product CRUD (menu label: Services & products) │ │ ├── slots/ # Bookable time slot CRUD │ │ ├── orders/ # Order list + booking-email status/resend │ │ ├── emails/ # Block-based booking email editor (live preview, test send) -│ │ ├── globals/ # Header/footer/colors editor +│ │ ├── globals/ # Header/footer/colors editor (menu label: Site design) +│ │ ├── backup/ # Export/import UI (calls api/export, api/import) │ │ ├── preview/ # Draft preview via sessionStorage (same-origin) │ │ └── api/ # upload, export, import endpoints │ ├── hooks.server.ts # Auth guard — all routes except /login @@ -67,7 +68,7 @@ app-public/ # SvelteKit public app (serves *.) ├── svelte.config.js # Adapter-node, runes mode forced, $shared alias ├── vite.config.ts # Tailwind v4 + SvelteKit plugins └── package.json -pocketbase/pb_data/ # PocketBase data (volume-mounted) +pocketbase/pb_migrations/ # JS migrations, mounted at /pb_migrations; applied on PocketBase start docker-compose.yml # app-admin + app-public + pocketbase + caddy services Caddyfile # Subdomain-based routing ``` @@ -124,14 +125,24 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type - `$lib/pb.ts` exports `createPocketBase()`, `getFileUrl()`, `uploadMedia()` - Collections: `pages` (slug, title, blocks[], published), `globals` (key, data), `media` (file, alt), `email_templates` (key, subject, blocks[], recipients, enabled) - Server load functions use `locals.pb.collection('pages').getFirstListItem()` +- **Always build filters with `pb.filter('slug = {:slug}', { slug })`** — never interpolate values into filter strings (quotes break them). +- **Schema changes**: add a migration to `pocketbase/pb_migrations/` (runs once, on the next PocketBase start) **and** mirror it in `pb_schema.json` (fresh installs import that after the migrations have already run). Migrations must skip missing collections and must not throw for data problems — a failing migration stops PocketBase from starting. +- **API rules**: CMS collections require `@request.auth.id != ''`, so `users` must never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, baskets, basket_lines) are superuser-only; the public app does them server-side via `getAdminPb()`. ### Styling - **Public site**: Custom theme via `@theme` in `app.css` — colors: `warm`, `charcoal`, `sage`, `sage-dark`, `terracotta`. Fonts: `DM Sans` (body), `Playfair Display` (headings). -- **Admin area**: DaisyUI utility classes (`btn`, `card`, `input`, `select`, `rounded-box`, etc.) +- **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). The admin has its own fixed theme in `app.css`; the site's Globals colours are applied only inside `/preview` (their CSS variables collide with DaisyUI's `--color-primary`/`--color-accent`). Conventions: + - 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. + - 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()`. +- **Dates/times in admin**: entered and displayed in `SITE_TIMEZONE` (layout data `timezone`), via `toZonedDatetimeInput`, `zonedInputToIso`, `formatDateTime` in `$shared/calendar`. Never `new Date(localInput)` on the server — the container runs in UTC. - **Prose**: `.prose-wellness` class for rich text content styling ### Routing -- **Admin app** (`app-admin`): All routes except `/login` are auth-guarded in `hooks.server.ts`. The root layout renders the admin shell (navbar, export/import, logout). The `/preview` route reads `sessionStorage` set by the page editor (same-origin, so it works). +- **Admin app** (`app-admin`): All routes except `/login` are auth-guarded in `hooks.server.ts` (which also refreshes the token per request and sets the cookie's `Secure` flag from the real scheme). The root layout renders the admin shell (grouped sidebar) except on `/login` and `/preview`. The `/preview` route reads `sessionStorage` set by the page editor (same-origin, so it works). - **Public app** (`app-public`): No auth guard. The root layout always renders Header/Footer. `+layout.server.ts` fetches header/footer/colors globals + basket/items/slots for every page. - `+page.server.ts` for home fetches `slug = "home" && published = true` - `[slug]/+page.server.ts` fetches by dynamic slug diff --git a/README.md b/README.md index 103a542..8ab361c 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ The app containers use two PocketBase URLs: If the `globals` records do not exist, the app falls back to safe defaults and the admin globals page will create them. +### Migrations + +`pocketbase/pb_migrations/` is mounted into the PocketBase container, which applies any new migration once when it starts (`docker compose up` / restart). The first one (`1791244800_lock_rules_dates_unique.js`) closes public sign-up on the `users` collection, makes order/basket writes superuser-only, adds `created`/`updated` dates and unique slug/key indexes. On an existing install, check the PocketBase log after restarting — if duplicate page slugs or global keys exist, the unique index is skipped with a log line. + +> **Security:** every CMS collection allows writes to *any* signed-in user, so the `users` collection must not allow public sign-up. The migration enforces this; if you manage PocketBase by hand, keep `users` → API rules → Create set to superuser-only. + ### Manual collection fields fallback If schema import fails because of a PocketBase version mismatch, create these collections manually: diff --git a/app-admin/src/app.css b/app-admin/src/app.css index 84c1665..dd8a76b 100644 --- a/app-admin/src/app.css +++ b/app-admin/src/app.css @@ -1,140 +1,157 @@ -@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap'); -@import 'tailwindcss'; -@plugin 'daisyui' { - themes: light --default; -} - -@theme { - --font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif; - --font-serif: 'Playfair Display', Georgia, serif; - --color-warm: var(--color-bg, #faf8f5); - --color-charcoal: var(--color-heading, #2c2c2c); - --color-sage: var(--color-primary, #8a9a7b); - --color-sage-dark: color-mix(in srgb, var(--color-primary, #8a9a7b) 80%, #000); - --color-terracotta: var(--color-accent, #c9825f); -} - -@keyframes shrink { - from { scale: 0 1; } - to { scale: 1 1; } -} - -.delete-fill { - position: absolute; - inset: 0; - background: transparent; - transform-origin: left; -} - -.delete-fill.animating { - animation: shrink 1s ease-in-out forwards; - background: var(--error, #f43f5e); -} - -.btn.delete-holding { - color: white !important; -} - -.btn.delete-holding .text-error { - color: white !important; -} - -:root { - --fg-heading: var(--color-heading, #2c2c2c); - --fg-subheading: var(--color-subheading, #4a4a4a); - --fg-body: var(--color-text, #2c2c2c); - background: var(--color-bg, #faf8f5); - color: var(--fg-body); - font-family: 'DM Sans', ui-sans-serif, system-ui, sans-serif; -} - -/* ── Foreground colour utilities (set per-block via BackgroundWrapper) ── */ -.text-fg-body { color: var(--fg-body, #2c2c2c); } -.text-fg-body\/85 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 85%, transparent); } -.text-fg-body\/80 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 80%, transparent); } -.text-fg-body\/75 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 75%, transparent); } -.text-fg-body\/70 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 70%, transparent); } -.text-fg-body\/60 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 60%, transparent); } -.text-fg-heading { color: var(--fg-heading, #2c2c2c); } -.text-fg-subheading { color: var(--fg-subheading, #4a4a4a); } -.text-fg-subheading\/85 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 85%, transparent); } -.text-fg-subheading\/80 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 80%, transparent); } -.text-fg-subheading\/75 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 75%, transparent); } -.text-fg-subheading\/70 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 70%, transparent); } -.text-fg-subheading\/60 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 60%, transparent); } - -body { - min-height: 100vh; - margin: 0; - background: - radial-gradient(circle at top left, rgba(var(--color-accent-rgb, 201, 130, 95), 0.1), transparent 36rem), - var(--color-bg, #faf8f5); -} - -h1, -h2, -h3, -h4 { - font-family: 'Playfair Display', Georgia, serif; - color: var(--fg-heading, #2c2c2c); -} - -.prose-wellness p { - margin: 0.75rem 0; - line-height: 1.8; -} - -.prose-wellness h2 { - margin: 1.25rem 0 0.5rem; - font-size: clamp(2rem, 4vw, 3.25rem); - line-height: 1.05; -} - -.prose-wellness h3 { - margin: 1rem 0 0.5rem; - font-size: 1.6rem; -} - -.prose-wellness ul { - list-style: disc; - padding-left: 1.5rem; -} - -.prose-wellness a { - color: color-mix(in srgb, var(--color-primary, #8a9a7b) 90%, #000); - text-decoration: underline; - text-underline-offset: 3px; -} - -/* ── Scroll-reveal animations ── */ -.reveal { - opacity: 0; - transform: translateY(30px); - transition: - opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1), - transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1); -} - -.reveal-visible { - opacity: 1; - transform: translateY(0); -} - -/* ── Hero fade-in stagger ── */ -.animate-fade-in { - opacity: 0; - transform: translateY(20px); - animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards; -} - -@keyframes fadeInUp { - to { - opacity: 1; - transform: translateY(0); - } -} - -/* ── Smooth scroll ── */ -html { - scroll-behavior: smooth; -} +@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@600;700&display=swap'); +@import 'tailwindcss'; +@plugin 'daisyui' { + themes: light --default; +} + +/* Admin UI theme: DaisyUI light with a fixed sage primary. Deliberately NOT + tied to the site's colours (Site design → Colors) (those only apply inside /preview), so + a light brand colour can't make admin buttons unreadable. #647556 on white + text is ~5:1 contrast (WCAG AA). */ +@plugin 'daisyui/theme' { + name: 'light'; + default: true; + --color-primary: #647556; + --color-primary-content: #ffffff; +} + +/* Hint text under form fields: DaisyUI's .label is nowrap, which stretched + fields to fit long hints. */ +.fieldset .label { + white-space: normal; +} + +@theme { + --font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif; + --font-serif: 'Playfair Display', Georgia, serif; + --color-warm: var(--color-bg, #faf8f5); + --color-charcoal: var(--color-heading, #2c2c2c); + --color-sage: var(--color-primary, #8a9a7b); + --color-sage-dark: color-mix(in srgb, var(--color-primary, #8a9a7b) 80%, #000); + --color-terracotta: var(--color-accent, #c9825f); +} + +@keyframes shrink { + from { scale: 0 1; } + to { scale: 1 1; } +} + +.delete-fill { + position: absolute; + inset: 0; + background: transparent; + transform-origin: left; +} + +.delete-fill.animating { + animation: shrink 1s ease-in-out forwards; + background: var(--error, #f43f5e); +} + +.btn.delete-holding { + color: white !important; +} + +.btn.delete-holding .text-error { + color: white !important; +} + +:root { + --fg-heading: var(--color-heading, #2c2c2c); + --fg-subheading: var(--color-subheading, #4a4a4a); + --fg-body: var(--color-text, #2c2c2c); + background: var(--color-bg, #faf8f5); + color: var(--fg-body); + font-family: 'DM Sans', ui-sans-serif, system-ui, sans-serif; +} + +/* ── Foreground colour utilities (set per-block via BackgroundWrapper) ── */ +.text-fg-body { color: var(--fg-body, #2c2c2c); } +.text-fg-body\/85 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 85%, transparent); } +.text-fg-body\/80 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 80%, transparent); } +.text-fg-body\/75 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 75%, transparent); } +.text-fg-body\/70 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 70%, transparent); } +.text-fg-body\/60 { color: color-mix(in srgb, var(--fg-body, #2c2c2c) 60%, transparent); } +.text-fg-heading { color: var(--fg-heading, #2c2c2c); } +.text-fg-subheading { color: var(--fg-subheading, #4a4a4a); } +.text-fg-subheading\/85 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 85%, transparent); } +.text-fg-subheading\/80 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 80%, transparent); } +.text-fg-subheading\/75 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 75%, transparent); } +.text-fg-subheading\/70 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 70%, transparent); } +.text-fg-subheading\/60 { color: color-mix(in srgb, var(--fg-subheading, #4a4a4a) 60%, transparent); } + +body { + min-height: 100vh; + margin: 0; + background: + radial-gradient(circle at top left, rgba(var(--color-accent-rgb, 201, 130, 95), 0.1), transparent 36rem), + var(--color-bg, #faf8f5); +} + +h1, +h2, +h3, +h4 { + font-family: 'Playfair Display', Georgia, serif; + color: var(--fg-heading, #2c2c2c); +} + +.prose-wellness p { + margin: 0.75rem 0; + line-height: 1.8; +} + +.prose-wellness h2 { + margin: 1.25rem 0 0.5rem; + font-size: clamp(2rem, 4vw, 3.25rem); + line-height: 1.05; +} + +.prose-wellness h3 { + margin: 1rem 0 0.5rem; + font-size: 1.6rem; +} + +.prose-wellness ul { + list-style: disc; + padding-left: 1.5rem; +} + +.prose-wellness a { + color: color-mix(in srgb, var(--color-primary, #8a9a7b) 90%, #000); + text-decoration: underline; + text-underline-offset: 3px; +} + +/* ── Scroll-reveal animations ── */ +.reveal { + opacity: 0; + transform: translateY(30px); + transition: + opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1), + transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1); +} + +.reveal-visible { + opacity: 1; + transform: translateY(0); +} + +/* ── Hero fade-in stagger ── */ +.animate-fade-in { + opacity: 0; + transform: translateY(20px); + animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards; +} + +@keyframes fadeInUp { + to { + opacity: 1; + transform: translateY(0); + } +} + +/* ── Smooth scroll ── */ +html { + scroll-behavior: smooth; +} diff --git a/app-admin/src/hooks.server.ts b/app-admin/src/hooks.server.ts index ed21553..fcc88a5 100644 --- a/app-admin/src/hooks.server.ts +++ b/app-admin/src/hooks.server.ts @@ -7,6 +7,18 @@ export const handle: Handle = async ({ event, resolve }) => { event.request.headers.get('cookie') ?? '', env.POCKETBASE_INTERNAL_URL ); + + // `isValid` only checks the token's expiry locally. Refresh it against + // PocketBase so a revoked token (deleted user, changed password) logs the + // user out instead of failing later as a 500, and so active sessions slide. + if (event.locals.pb.authStore.isValid) { + const collection = event.locals.pb.authStore.record?.collectionName || '_superusers'; + try { + await event.locals.pb.collection(collection).authRefresh(); + } catch { + event.locals.pb.authStore.clear(); + } + } event.locals.user = event.locals.pb.authStore.record; const path = event.url.pathname; @@ -17,11 +29,17 @@ export const handle: Handle = async ({ event, resolve }) => { throw redirect(303, '/login'); } - if (isLoginRoute && isAuthed) { + if (isLoginRoute && isAuthed && event.request.method === 'GET') { throw redirect(303, '/pages'); } const response = await resolve(event); - response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({ sameSite: 'lax' }, 'pb_auth')); + // The SDK defaults to `Secure`, which browsers drop over plain HTTP — that + // would make login impossible with CADDY_SCHEME=http. Match the real scheme + // (event.url comes from ORIGIN behind the proxy). + response.headers.append( + 'set-cookie', + event.locals.pb.authStore.exportToCookie({ sameSite: 'lax', secure: event.url.protocol === 'https:' }, 'pb_auth') + ); return response; }; diff --git a/app-admin/src/lib/admin/BlockList.svelte b/app-admin/src/lib/admin/BlockList.svelte index 761a929..3054347 100644 --- a/app-admin/src/lib/admin/BlockList.svelte +++ b/app-admin/src/lib/admin/BlockList.svelte @@ -1,64 +1,115 @@ - - -
- {#each blocks as block, i (block.id)} -
onSelect(block.id)} - ondragstart={() => (dragIndex = i)} - ondragover={(e) => e.preventDefault()} - ondrop={() => { if (dragIndex !== null && dragIndex !== i) onMove(dragIndex, i); dragIndex = null; }} - > -
- ☰ -
{labels[block.type] ?? block.type}
- -
-
- {/each} -
+ + +
    + {#each blocks as block, i (block.id)} +
  • { + dragIndex = i; + // Firefox won't start a drag without data. + e.dataTransfer?.setData('text/plain', block.id); + if (e.dataTransfer) e.dataTransfer.effectAllowed = 'move'; + }} + ondragover={(e) => { + e.preventDefault(); + dropIndex = i; + }} + ondragleave={() => dropIndex === i && (dropIndex = null)} + ondrop={(e) => { + e.preventDefault(); + drop(i); + }} + ondragend={() => { + dragIndex = null; + dropIndex = null; + }} + > + + + +
  • + {:else} +
  • No blocks yet — use “Add block”.
  • + {/each} +
diff --git a/app-admin/src/lib/admin/Modal.svelte b/app-admin/src/lib/admin/Modal.svelte new file mode 100644 index 0000000..ab0bbac --- /dev/null +++ b/app-admin/src/lib/admin/Modal.svelte @@ -0,0 +1,33 @@ + + + (open = false)}> +
+
+

{title}

+ +
+ {#if open} + {@render children()} + {/if} +
+
diff --git a/app-admin/src/lib/admin/confirm.ts b/app-admin/src/lib/admin/confirm.ts new file mode 100644 index 0000000..1a10435 --- /dev/null +++ b/app-admin/src/lib/admin/confirm.ts @@ -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.) + * + *
+ * - - {/each} - - {:else if block.type === 'hero'} - - - - - {:else if block.type === 'button'} -
- - -
- updateData({ variant: v })} - /> -
-
- updateData({ alignment: v })} - formatLabel={titleCase} - /> -
-
- updateData({ size: v })} - formatLabel={(v) => String({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[String(v)] || v)} - /> -
-
-
- Color -
- updateData({ color: e.currentTarget.value })} /> - updateData({ color: e.currentTarget.value })} /> -
-
-
-
- {:else if block.type === 'spacer'} -
- -
- {:else if block.type === 'testimonials'} -
- - - {#each block.data.items || [] as item, i} -
- - updateArray('items', i, { title: e.currentTarget.value })} - /> - -
- {/each} - -
- {:else if block.type === 'upcoming_calendar'} -
- - -
-
-

Category filters

-

Choose categories to show in this block. Leave all unchecked to show every published event.

-
- {#if eventCategories?.length} -
- {#each eventCategories as category} - - {/each} -
- {:else} -

No event categories exist yet. Create events in the Calendar admin page first.

- {/if} -
-
- {:else if block.type === 'shop'} - - {:else if block.type === 'checkout'} - - {/if} - -
- - -
- updateData({ _background: { ...(block.data._background || {}), type: v } })} - /> -
- - {#if block.data._background?.type === 'color'} -
- -
- {/if} - - {#if block.data._background?.type === 'image'} -
- updateData({ _background: { ...(block.data._background || {}), imageUrl: image.url, imageAlt: image.alt } })} /> - - updateData({ _background: { ...(block.data._background || {}), attachment: v } })} - /> - - updateData({ _background: { ...(block.data._background || {}), overlay: true, overlayOpacity: v } })} - formatLabel={(v) => `${v}%`} - /> -
- {/if} - -
- - updateData({ _foreground: { ...(block.data._foreground || {}), mode: v } })} - /> - - {#if block.data._foreground?.mode === 'custom'} -
-
-
- Heading -
- updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} /> -
-
-
-
-
- Sub heading -
- updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} /> -
-
-
-
-
- Text -
- updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} /> -
-
-
-
- {/if} -
- -{/if} + + +{#snippet field(label: string, value: string, onInput: (value: string) => void, placeholder = '')} + +{/snippet} + +{#if !block} +
Select a block to edit.
+{:else} +
+

{blockLabels[block.type as BlockType]}

+ + {#if block.type === 'text'} + updateData({ content })} /> + {:else if block.type === 'image_text'} +
+ updateData(image)} /> + updateData({ imagePosition: v })} /> + updateData({ content })} /> +
+ {:else if block.type === 'timeline'} +
+ {#each block.data.items || [] as item, i} +
+
+ Item {i + 1} + +
+ updateArray('items', i, { title: e.currentTarget.value })} /> + +
+ {/each} + +
+ {:else if block.type === 'hero'} + {@render field('Heading', block.data.heading || '', (heading) => updateData({ heading }))} + {@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))} +
+ {@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))} + {@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), '/page or https://…')} +
+ {:else if block.type === 'button'} +
+ {@render field('Button label', block.data.label || '', (label) => updateData({ label }))} + {@render field('URL', block.data.href || '', (href) => updateData({ href }), '/page or https://…')} +
+
+ updateData({ variant: v })} /> + updateData({ alignment: v })} /> + updateData({ size: v })} formatLabel={(v) => sizeLabels[String(v)] || String(v)} /> + updateData({ color })} /> +
+ {:else if block.type === 'spacer'} + + {:else if block.type === 'testimonials'} + {@render field('Section title', block.data.title || '', (title) => updateData({ title }))} +
+ {#each block.data.items || [] as item, i} +
+
+ Testimonial {i + 1} + +
+ + updateArray('items', i, { title: e.currentTarget.value })} /> +
+ {/each} + +
+ {:else if block.type === 'upcoming_calendar'} + {@render field('Section title', block.data.title || '', (title) => updateData({ title }))} +
+

Category filters

+

Choose categories to show in this block. Leave all unselected to show every published event.

+ {#if eventCategories?.length} +
+ {#each eventCategories as category} + + {/each} +
+ {:else} +

No event categories exist yet. Add categories to events under Events first.

+ {/if} +
+ {:else if block.type === 'shop'} + + {:else if block.type === 'checkout'} + + {/if} + +
+ updateBackground({ type })} /> + + {#if block.data._background?.type === 'color'} + updateBackground({ color })} /> + {:else if block.data._background?.type === 'image'} + updateBackground({ imageUrl: image.url, imageAlt: image.alt })} /> + updateBackground({ attachment })} /> + updateBackground({ overlay: Number(v) > 0, overlayOpacity: Number(v) })} + formatLabel={(v) => (Number(v) === 0 ? 'None' : `${v}%`)} + /> + {/if} + +
+ + updateForeground({ mode })} /> + + {#if block.data._foreground?.mode === 'custom'} + updateForeground({ headingColor })} /> + updateForeground({ subheadingColor })} /> + updateForeground({ textColor })} /> + {/if} +
+
+{/if} diff --git a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte index 5ecd756..a5874d1 100644 --- a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte @@ -15,17 +15,17 @@
-
diff --git a/app-admin/src/lib/admin/editors/ColorField.svelte b/app-admin/src/lib/admin/editors/ColorField.svelte new file mode 100644 index 0000000..c25f331 --- /dev/null +++ b/app-admin/src/lib/admin/editors/ColorField.svelte @@ -0,0 +1,37 @@ + + +
+ {label} +
+ onChange(e.currentTarget.value)} + /> + onChange(e.currentTarget.value.trim())} /> + {#if value} + + {/if} +
+
diff --git a/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte b/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte index 1b5a424..1c31d5e 100644 --- a/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte @@ -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,15 +18,10 @@ onChange(block); } - function titleCase(value: string | number) { - const text = String(value); - return text.charAt(0).toUpperCase() + text.slice(1); - } - const autoFilled: Record = { 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.", - contact_info: 'Filled in automatically from the business name, address, phone and email in Globals → Footer.' + contact_info: 'Filled in automatically from the business name, address, phone and email in Site design → Footer.' }; @@ -42,46 +38,38 @@
updateData(image)} /> updateData({ width: v })} formatLabel={(v) => `${v}%`} /> - updateData({ alignment: v })} formatLabel={titleCase} /> -
{:else if block.type === 'button'}
-
{:else if block.type === 'spacer'} -