Compare commits
No commits in common. "b2ebdc17992c90f6d563cc37d0f39ec06bb8dc50" and "47a1250b46bd09fd3dc390caac26316b5d16bb10" have entirely different histories.
b2ebdc1799
...
47a1250b46
11 changed files with 45 additions and 108 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
- **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc.
|
- **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc.
|
||||||
- **PocketBase** — server pinned to **0.23.12** (`docker-compose.yml`), REST API via the `pocketbase` SDK (v0.26). Auth, DB, and image storage. Bump the server version deliberately (changelog, backup, test migrations).
|
- **PocketBase** — REST API via the `pocketbase` SDK (v0.26). Auth, DB, and image storage.
|
||||||
- **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
|
- **Tailwind CSS v4** + **DaisyUI 5** — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
|
||||||
- **Docker Compose** — four services: `app-admin`, `app-public`, `pocketbase`, and `caddy` (reverse proxy).
|
- **Docker Compose** — four services: `app-admin`, `app-public`, `pocketbase`, and `caddy` (reverse proxy).
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
|
||||||
|
|
||||||
### Styling
|
### Styling
|
||||||
- **Public site**: Custom theme via `@theme` in `app.css` — colors: `warm`, `charcoal`, `sage`, `sage-dark`, `terracotta`. Fonts: `DM Sans` (body), `Playfair Display` (headings).
|
- **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 **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). Colours come from Site design via `$shared/theme`, rendered as a `<style>` in `<head>` (SSR, no flash): the admin gets only DaisyUI primary (= site Primary) and secondary (= site Accent) with auto-contrast text; `/preview` and the public site get all site colour variables. Never use `text-primary`/`text-secondary` for text — a light brand colour is unreadable as text; mark state with a tint/bar instead. Conventions:
|
- **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). 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).
|
- Section card: `rounded-box bg-base-100 p-5 shadow` with an `h2.text-2xl.font-bold` title (see Site design / globals).
|
||||||
- Form field: `<label class="fieldset"><span class="fieldset-legend">Label</span><input class="input w-full" /></label>`; hints in `<span class="label">`.
|
- Form field: `<label class="fieldset"><span class="fieldset-legend">Label</span><input class="input w-full" /></label>`; hints in `<span class="label">`.
|
||||||
- Setting rows in editors: `SegmentedControl` (choices) and `ColorField` (colours) — label column on the left, like the block Background picker.
|
- Setting rows in editors: `SegmentedControl` (choices) and `ColorField` (colours) — label column on the left, like the block Background picker.
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,16 @@
|
||||||
themes: light --default;
|
themes: light --default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Admin primary/secondary come from the site's colours (Site design →
|
/* Admin UI theme: DaisyUI light with a fixed sage primary. Deliberately NOT
|
||||||
Colors) via $shared/theme, rendered in the root layout's <head> with an
|
tied to the site's colours (Site design → Colors) (those only apply inside /preview), so
|
||||||
automatically readable text colour. */
|
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
|
/* Hint text under form fields: DaisyUI's .label is nowrap, which stretched
|
||||||
fields to fit long hints. */
|
fields to fit long hints. */
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,10 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- `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">
|
||||||
{#each blocks as block, i (block.id)}
|
{#each blocks as block, i (block.id)}
|
||||||
<li
|
<li
|
||||||
class="isolate flex items-center gap-2 rounded-box border bg-base-100 p-2 pl-3 shadow-sm transition-colors {selectedId === block.id ? 'border-primary ring-1 ring-primary' : 'border-base-300 hover:border-base-content/30'}"
|
class="flex items-center gap-2 rounded-box border bg-base-100 p-2 pl-3 shadow-sm transition-colors {selectedId === block.id ? 'border-primary ring-1 ring-primary' : 'border-base-300 hover:border-base-content/30'}"
|
||||||
class:opacity-50={dragIndex === i}
|
class:opacity-50={dragIndex === i}
|
||||||
class:border-dashed={dropIndex === i && dragIndex !== i}
|
class:border-dashed={dropIndex === i && dragIndex !== i}
|
||||||
draggable="true"
|
draggable="true"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
import { afterNavigate } from '$app/navigation';
|
import { afterNavigate } from '$app/navigation';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
|
import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
|
||||||
import { brandThemeVars, rootStyleTag } from '$shared/theme';
|
|
||||||
|
|
||||||
let { children, data } = $props();
|
let { children, data } = $props();
|
||||||
|
|
||||||
|
|
@ -13,9 +12,6 @@
|
||||||
const BARE_ROUTES = ['/login', '/preview'];
|
const BARE_ROUTES = ['/login', '/preview'];
|
||||||
let bare = $derived(BARE_ROUTES.includes(page.url.pathname));
|
let bare = $derived(BARE_ROUTES.includes(page.url.pathname));
|
||||||
|
|
||||||
// The active item is marked with a tint + bar in the brand colour, never
|
|
||||||
// brand-coloured text: the site's primary may be too light to read as text.
|
|
||||||
|
|
||||||
// Sidebar navigation, grouped by what the studio is doing. Labels are
|
// Sidebar navigation, grouped by what the studio is doing. Labels are
|
||||||
// user-facing names; hrefs keep the original route names.
|
// user-facing names; hrefs keep the original route names.
|
||||||
const navGroups = [
|
const navGroups = [
|
||||||
|
|
@ -59,8 +55,6 @@
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="icon" href={favicon} />
|
<link rel="icon" href={favicon} />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<!-- Admin buttons/highlights use the site's Primary and Accent colours (sanitised; readable text picked automatically). -->
|
|
||||||
{@html rootStyleTag(brandThemeVars(data.colors))}
|
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if bare}
|
{#if bare}
|
||||||
|
|
@ -92,7 +86,7 @@
|
||||||
<li class="menu-title mt-3 first:mt-0">{group.title}</li>
|
<li class="menu-title mt-3 first:mt-0">{group.title}</li>
|
||||||
{#each group.links as link (link.href)}
|
{#each group.links as link (link.href)}
|
||||||
<li>
|
<li>
|
||||||
<a href={link.href} class={isActive(link.href) ? 'bg-primary/20 font-semibold shadow-[inset_3px_0_0_var(--color-primary)]' : ''} aria-current={isActive(link.href) ? 'page' : undefined}>{link.label}</a>
|
<a href={link.href} class={isActive(link.href) ? 'bg-primary/10 font-semibold text-primary' : ''} aria-current={isActive(link.href) ? 'page' : undefined}>{link.label}</a>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
<div class="grid gap-2 sm:grid-cols-2">
|
<div class="grid gap-2 sm:grid-cols-2">
|
||||||
{#each emailPlaceholders as placeholder}
|
{#each emailPlaceholders as placeholder}
|
||||||
<button type="button" class="btn btn-ghost btn-sm justify-start font-normal" onclick={() => copyPlaceholder(placeholder.key)}>
|
<button type="button" class="btn btn-ghost btn-sm justify-start font-normal" onclick={() => copyPlaceholder(placeholder.key)}>
|
||||||
<code class="font-semibold">{`{{${placeholder.key}}}`}</code>
|
<code class="text-primary">{`{{${placeholder.key}}}`}</code>
|
||||||
<span class="text-base-content/60">{copied === placeholder.key ? 'Copied!' : placeholder.description}</span>
|
<span class="text-base-content/60">{copied === placeholder.key ? 'Copied!' : placeholder.description}</span>
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
@ -142,7 +142,7 @@
|
||||||
<div class="rounded-box bg-base-100 p-4 shadow">
|
<div class="rounded-box bg-base-100 p-4 shadow">
|
||||||
<div class="dropdown w-full">
|
<div class="dropdown w-full">
|
||||||
<button class="btn btn-primary w-full" type="button" tabindex="0">Add block</button>
|
<button class="btn btn-primary w-full" type="button" tabindex="0">Add block</button>
|
||||||
<ul class="menu dropdown-content z-20 mt-2 w-full rounded-box bg-base-100 p-2 shadow-lg">
|
<ul class="menu dropdown-content z-10 mt-2 w-full rounded-box bg-base-100 p-2 shadow">
|
||||||
{#each emailBlockTypes as type}
|
{#each emailBlockTypes as type}
|
||||||
<li><button type="button" onclick={() => addBlock(type)}>{emailBlockLabels[type]}</button></li>
|
<li><button type="button" onclick={() => addBlock(type)}>{emailBlockLabels[type]}</button></li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@
|
||||||
const submit: SubmitFunction = ({ formData }) => {
|
const submit: SubmitFunction = ({ formData }) => {
|
||||||
saving = String(formData.get('section'));
|
saving = String(formData.get('section'));
|
||||||
return async ({ update }) => {
|
return async ({ update }) => {
|
||||||
// Re-run loads so the admin theme picks up saved colours immediately.
|
await update({ reset: false, invalidateAll: false });
|
||||||
await update({ reset: false });
|
|
||||||
saving = '';
|
saving = '';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@
|
||||||
<div class="rounded-box bg-base-100 p-4 shadow">
|
<div class="rounded-box bg-base-100 p-4 shadow">
|
||||||
<div class="dropdown w-full">
|
<div class="dropdown w-full">
|
||||||
<button class="btn btn-primary w-full" type="button" tabindex="0">Add block</button>
|
<button class="btn btn-primary w-full" type="button" tabindex="0">Add block</button>
|
||||||
<ul class="menu dropdown-content z-20 mt-2 w-full rounded-box bg-base-100 p-2 shadow-lg">
|
<ul class="menu dropdown-content z-10 mt-2 w-full rounded-box bg-base-100 p-2 shadow">
|
||||||
{#each blockTypes as type}
|
{#each blockTypes as type}
|
||||||
<li><button type="button" onclick={() => addBlock(type)}>{blockLabels[type]}</button></li>
|
<li><button type="button" onclick={() => addBlock(type)}>{blockLabels[type]}</button></li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,25 @@
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import BlockRenderer from '$shared/blocks/BlockRenderer.svelte';
|
import BlockRenderer from '$shared/blocks/BlockRenderer.svelte';
|
||||||
import type { ContentBlock } from '$lib/types';
|
import type { ContentBlock } from '$lib/types';
|
||||||
import { rootStyleTag, siteThemeVars } from '$shared/theme';
|
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
let blocks = $state<ContentBlock[]>([]);
|
let blocks = $state<ContentBlock[]>([]);
|
||||||
let error = $state('');
|
let error = $state('');
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
// Apply the site's colors so the preview matches the public site. Only
|
||||||
|
// here: these variable names overlap DaisyUI's theme (--color-primary,
|
||||||
|
// --color-accent), so setting them in the admin shell restyled the admin.
|
||||||
|
if (data.colors) {
|
||||||
|
const root = document.documentElement;
|
||||||
|
root.style.setProperty('--color-bg', data.colors.background);
|
||||||
|
root.style.setProperty('--color-heading', data.colors.heading);
|
||||||
|
root.style.setProperty('--color-subheading', data.colors.subheading);
|
||||||
|
root.style.setProperty('--color-text', data.colors.text);
|
||||||
|
root.style.setProperty('--color-primary', data.colors.primary);
|
||||||
|
root.style.setProperty('--color-accent', data.colors.accent);
|
||||||
|
}
|
||||||
|
|
||||||
const raw = sessionStorage.getItem('cms-preview-blocks');
|
const raw = sessionStorage.getItem('cms-preview-blocks');
|
||||||
if (!raw) return;
|
if (!raw) return;
|
||||||
try {
|
try {
|
||||||
|
|
@ -22,8 +34,6 @@
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Preview</title>
|
<title>Preview</title>
|
||||||
<!-- Full site colours so the draft looks like the public site. -->
|
|
||||||
{@html rootStyleTag(siteThemeVars(data.colors))}
|
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if blocks.length}
|
{#if blocks.length}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
import Header from '$lib/components/Header.svelte';
|
import Header from '$lib/components/Header.svelte';
|
||||||
import Footer from '$lib/components/Footer.svelte';
|
import Footer from '$lib/components/Footer.svelte';
|
||||||
import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
|
import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
|
||||||
import { rootStyleTag, siteThemeVars } from '$shared/theme';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
let { children, data } = $props();
|
let { children, data } = $props();
|
||||||
|
|
||||||
|
|
@ -16,14 +16,23 @@
|
||||||
// Keep the store in sync when layout data refreshes (e.g. after checkout
|
// Keep the store in sync when layout data refreshes (e.g. after checkout
|
||||||
// clears the cookie and data.basket becomes null).
|
// clears the cookie and data.basket becomes null).
|
||||||
$effect(() => basketStore.syncFrom(data.basket ?? null));
|
$effect(() => basketStore.syncFrom(data.basket ?? null));
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (data.colors) {
|
||||||
|
const root = document.documentElement;
|
||||||
|
root.style.setProperty('--color-bg', data.colors.background);
|
||||||
|
root.style.setProperty('--color-heading', data.colors.heading);
|
||||||
|
root.style.setProperty('--color-subheading', data.colors.subheading);
|
||||||
|
root.style.setProperty('--color-text', data.colors.text);
|
||||||
|
root.style.setProperty('--color-primary', data.colors.primary);
|
||||||
|
root.style.setProperty('--color-accent', data.colors.accent);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="icon" href={favicon} />
|
<link rel="icon" href={favicon} />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<!-- Site colours, rendered server-side (previously applied in onMount, which
|
|
||||||
flashed the defaults on every page load). Values are sanitised. -->
|
|
||||||
{@html rootStyleTag(siteThemeVars(data.colors))}
|
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Header header={data.header} />
|
<Header header={data.header} />
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
services:
|
services:
|
||||||
pocketbase:
|
pocketbase:
|
||||||
# Pinned: schema (pb_schema.json) and migrations target this version's
|
image: docker.io/spectado/pocketbase:latest
|
||||||
# format/JS API. Upgrade deliberately — read the PocketBase changelog,
|
|
||||||
# back up pb_data, then bump the tag and test migrations locally.
|
|
||||||
image: docker.io/spectado/pocketbase:0.23.12
|
|
||||||
container_name: massage-pocketbase
|
container_name: massage-pocketbase
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
# Internal only — accessed via the caddy reverse proxy
|
# Internal only — accessed via the caddy reverse proxy
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
import { defaultColors, type ColorsGlobal } from './types';
|
|
||||||
|
|
||||||
// Site colours (Site design → Colors) as CSS variables, rendered server-side
|
|
||||||
// into a <style> tag so pages don't flash the default colours on load.
|
|
||||||
//
|
|
||||||
// Mapping onto DaisyUI's theme: primary = site Primary, secondary = site
|
|
||||||
// Accent (so `btn-secondary` follows the site instead of DaisyUI's default
|
|
||||||
// pink), each with a text colour picked for contrast.
|
|
||||||
|
|
||||||
// Colours are admin-entered free text that ends up inside <style>, so only
|
|
||||||
// plain colour values are allowed through.
|
|
||||||
const SAFE_COLOR = /^(#[0-9a-f]{3,8}|[a-z]{3,30}|(rgb|rgba|hsl|hsla|oklch|oklab|lab|lch)\([0-9a-z.,%\s/+-]{1,60}\))$/i;
|
|
||||||
|
|
||||||
export function safeColor(value: unknown, fallback: string): string {
|
|
||||||
const color = String(value ?? '').trim();
|
|
||||||
return SAFE_COLOR.test(color) ? color : fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hexToRgb(hex: string): [number, number, number] | null {
|
|
||||||
let h = hex.replace('#', '');
|
|
||||||
if (h.length === 3 || h.length === 4) h = [...h.slice(0, 3)].map((c) => c + c).join('');
|
|
||||||
if (h.length !== 6 && h.length !== 8) return null;
|
|
||||||
const n = parseInt(h.slice(0, 6), 16);
|
|
||||||
return Number.isNaN(n) ? null : [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
||||||
}
|
|
||||||
|
|
||||||
function luminance([r, g, b]: [number, number, number]) {
|
|
||||||
const lin = (c: number) => {
|
|
||||||
const s = c / 255;
|
|
||||||
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
||||||
};
|
|
||||||
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
const LIGHT_TEXT = '#ffffff';
|
|
||||||
const DARK_TEXT = '#1f2937';
|
|
||||||
|
|
||||||
/** White or dark text, whichever contrasts more with `color` (white if it isn't a hex colour). */
|
|
||||||
export function readableTextOn(color: string): string {
|
|
||||||
const rgb = color.startsWith('#') ? hexToRgb(color) : null;
|
|
||||||
if (!rgb) return LIGHT_TEXT;
|
|
||||||
const l = luminance(rgb);
|
|
||||||
const darkL = luminance(hexToRgb(DARK_TEXT)!);
|
|
||||||
return (1.05 / (l + 0.05)) >= (l + 0.05) / (darkL + 0.05) ? LIGHT_TEXT : DARK_TEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** DaisyUI brand variables only — used by the admin, whose own text/background stay neutral. */
|
|
||||||
export function brandThemeVars(colors: Partial<ColorsGlobal> | null | undefined): Record<string, string> {
|
|
||||||
const primary = safeColor(colors?.primary, defaultColors.primary);
|
|
||||||
const secondary = safeColor(colors?.accent, defaultColors.accent);
|
|
||||||
return {
|
|
||||||
'--color-primary': primary,
|
|
||||||
'--color-primary-content': readableTextOn(primary),
|
|
||||||
'--color-secondary': secondary,
|
|
||||||
'--color-secondary-content': readableTextOn(secondary)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Every site colour variable — public site and the admin preview. */
|
|
||||||
export function siteThemeVars(colors: Partial<ColorsGlobal> | null | undefined): Record<string, string> {
|
|
||||||
return {
|
|
||||||
'--color-bg': safeColor(colors?.background, defaultColors.background),
|
|
||||||
'--color-heading': safeColor(colors?.heading, defaultColors.heading),
|
|
||||||
'--color-subheading': safeColor(colors?.subheading, defaultColors.subheading),
|
|
||||||
'--color-text': safeColor(colors?.text, defaultColors.text),
|
|
||||||
'--color-accent': safeColor(colors?.accent, defaultColors.accent),
|
|
||||||
...brandThemeVars(colors)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** `<style>` element setting `vars` on :root, for `{@html}` in <svelte:head>. Values are already sanitised. */
|
|
||||||
export function rootStyleTag(vars: Record<string, string>): string {
|
|
||||||
const body = Object.entries(vars)
|
|
||||||
.map(([name, value]) => `${name}:${value}`)
|
|
||||||
.join(';');
|
|
||||||
return `<style>:root{${body}}</style>`;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue