This commit is contained in:
Jakub Dorfman 2026-05-18 17:18:09 +02:00
commit b4fbf3e411
59 changed files with 4735 additions and 0 deletions

1
app/.env.example Normal file
View file

@ -0,0 +1 @@
PUBLIC_POCKETBASE_URL=http://localhost:8090

23
app/.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
node_modules
# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build
# OS
.DS_Store
Thumbs.db
# Env
.env
.env.*
!.env.example
!.env.test
# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

1
app/.npmrc Normal file
View file

@ -0,0 +1 @@
engine-strict=true

3
app/.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"recommendations": ["svelte.svelte-vscode"]
}

42
app/README.md Normal file
View file

@ -0,0 +1,42 @@
# sv
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```sh
# create a new project
npx sv create my-app
```
To recreate this project with the same configuration:
```sh
# recreate this project
npx sv@0.15.3 create --template minimal --types ts --install npm app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```sh
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```sh
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

2966
app/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

41
app/package.json Normal file
View file

@ -0,0 +1,41 @@
{
"name": "app",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^7.0.1",
"@sveltejs/kit": "^2.57.0",
"@sveltejs/vite-plugin-svelte": "^7.0.0",
"@types/node": "^25.8.0",
"@types/uuid": "^10.0.0",
"svelte": "^5.55.2",
"svelte-check": "^4.4.6",
"typescript": "^6.0.2",
"vite": "^8.0.7"
},
"dependencies": {
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@sveltejs/adapter-node": "^5.5.4",
"@tailwindcss/vite": "^4.3.0",
"@tiptap/core": "^3.23.4",
"@tiptap/extension-link": "^3.23.4",
"@tiptap/extension-placeholder": "^3.23.4",
"@tiptap/starter-kit": "^3.23.4",
"daisyui": "^5.5.19",
"pocketbase": "^0.26.9",
"svelte-tiptap": "^3.0.1",
"tailwindcss": "^4.3.0",
"uuid": "^14.0.0"
}
}

64
app/src/app.css Normal file
View file

@ -0,0 +1,64 @@
@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: #faf8f5;
--color-charcoal: #2c2c2c;
--color-sage: #8a9a7b;
--color-sage-dark: #66755d;
--color-terracotta: #c9825f;
}
:root {
background: #faf8f5;
color: #2c2c2c;
font-family: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
}
body {
min-height: 100vh;
margin: 0;
background:
radial-gradient(circle at top left, rgba(201, 130, 95, 0.1), transparent 36rem),
#faf8f5;
}
h1,
h2,
h3,
h4 {
font-family: 'Playfair Display', Georgia, serif;
color: #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: #66755d;
text-decoration: underline;
text-underline-offset: 3px;
}

18
app/src/app.d.ts vendored Normal file
View file

@ -0,0 +1,18 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
import type PocketBase from 'pocketbase';
declare global {
namespace App {
// interface Error {}
interface Locals {
pb: PocketBase;
user: import('pocketbase').AuthRecord | null;
}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}
export {};

12
app/src/app.html Normal file
View file

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="text-scale" content="scale" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

28
app/src/hooks.server.ts Normal file
View file

@ -0,0 +1,28 @@
import { redirect, type Handle } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { createPocketBase } from '$lib/pb';
export const handle: Handle = async ({ event, resolve }) => {
event.locals.pb = createPocketBase(
event.request.headers.get('cookie') ?? '',
env.POCKETBASE_INTERNAL_URL || env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090'
);
event.locals.user = event.locals.pb.authStore.record;
const path = event.url.pathname;
const isAdminRoute = path.startsWith('/admin');
const isLoginRoute = path === '/admin/login';
const isAuthed = event.locals.pb.authStore.isValid;
if (isAdminRoute && !isLoginRoute && !isAuthed) {
throw redirect(303, '/admin/login');
}
if (isLoginRoute && isAuthed) {
throw redirect(303, '/admin/pages');
}
const response = await resolve(event);
response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({ sameSite: 'lax' }, 'pb_auth'));
return response;
};

View file

@ -0,0 +1,35 @@
<script lang="ts">
import type { BlockType, ContentBlock } from '$lib/types';
import { blockLabels } from '$lib/admin/blockDefaults';
let { blocks = [], selectedId = '', onSelect = (id: string) => {}, onDelete = (id: string) => {}, onMove = (from: number, to: number) => {} } = $props<{
blocks: ContentBlock[];
selectedId?: string;
onSelect?: (id: string) => void;
onDelete?: (id: string) => void;
onMove?: (from: number, to: number) => void;
}>();
let dragIndex = $state<number | null>(null);
</script>
<div class="space-y-3">
{#each blocks as block, i (block.id)}
<div
role="listitem"
class="rounded-box border bg-base-100 p-3 shadow-sm"
class:border-primary={selectedId === block.id}
draggable="true"
ondragstart={() => (dragIndex = i)}
ondragover={(e) => e.preventDefault()}
ondrop={() => { if (dragIndex !== null && dragIndex !== i) onMove(dragIndex, i); dragIndex = null; }}
>
<div class="flex items-center gap-2">
<span class="cursor-grab text-xl text-base-content/40">☰</span>
<div class="flex-1 font-semibold">{blockLabels[block.type as BlockType]}</div>
<button class="btn btn-xs" type="button" onclick={() => onSelect(block.id)}>Edit</button>
<button class="btn btn-xs btn-error btn-outline" type="button" onclick={() => onDelete(block.id)}>Delete</button>
</div>
</div>
{/each}
</div>

View file

@ -0,0 +1,50 @@
import { v4 as uuid } from 'uuid';
import type { BlockType, ContentBlock } from '$lib/types';
export const blockLabels: Record<BlockType, string> = {
text: 'Text',
image: 'Image',
image_text: 'Image + Text',
timeline: 'Timeline',
testimonials: 'Testimonials',
services: 'Services',
cta: 'Call to Action',
spacer: 'Spacer',
horizontal_cards: 'Horizontal Cards'
};
export const blockTypes = Object.keys(blockLabels) as BlockType[];
export function createBlock(type: BlockType): ContentBlock {
const base = { id: uuid(), type, data: {} as Record<string, any> };
switch (type) {
case 'text':
base.data = { content: '<h2>New text block</h2><p>Add your copy here.</p>' };
break;
case 'image':
base.data = { url: '', alt: '', caption: '' };
break;
case 'image_text':
base.data = { url: '', alt: '', content: '<h2>Image and text</h2><p>Add content here.</p>', imagePosition: 'left' };
break;
case 'timeline':
base.data = { items: [{ year: '2026', title: 'Milestone', description: 'Describe this moment.' }] };
break;
case 'testimonials':
base.data = { items: [{ name: 'Client name', text: 'A beautiful experience.', rating: 5 }] };
break;
case 'services':
base.data = { items: [{ title: 'Massage session', description: 'Describe the service.', duration: '60 min', price: '£70' }] };
break;
case 'cta':
base.data = { heading: 'Ready to book?', subtext: 'Start your next moment of calm.', buttonLabel: 'Book Now', buttonUrl: '/book' };
break;
case 'spacer':
base.data = { size: 'md' };
break;
case 'horizontal_cards':
base.data = { items: [{ title: 'Card title', description: 'Card description', url: '', link: '' }] };
break;
}
return base;
}

View file

@ -0,0 +1,99 @@
<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';
let { block, onChange = (block: ContentBlock) => {} } = $props<{
block: ContentBlock | null;
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) });
}
</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'}
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
<label class="form-control mt-3"><span class="label-text">Caption</span><input class="input input-bordered" value={block.data.caption || ''} oninput={(e) => updateData({ caption: e.currentTarget.value })} /></label>
{:else if block.type === 'image_text'}
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
<label class="form-control mt-3"><span class="label-text">Image position</span><select class="select select-bordered" value={block.data.imagePosition || 'left'} onchange={(e) => updateData({ imagePosition: e.currentTarget.value })}><option value="left">Left</option><option value="right">Right</option></select></label>
<div class="mt-3"><RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} /></div>
{:else if block.type === 'spacer'}
<label class="form-control"><span class="label-text">Size</span><select class="select select-bordered" value={block.data.size || 'md'} onchange={(e) => updateData({ size: e.currentTarget.value })}><option value="sm">Small</option><option value="md">Medium</option><option value="lg">Large</option></select></label>
{:else if block.type === 'cta'}
{#each ['heading', 'subtext', 'buttonLabel', 'buttonUrl'] as field}
<label class="form-control"><span class="label-text capitalize">{field}</span><input class="input input-bordered" value={block.data[field] || ''} oninput={(e) => updateData({ [field]: e.currentTarget.value })} /></label>
{/each}
{: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="Year" value={item.year} oninput={(e) => updateArray('items', i, { year: e.currentTarget.value })} />
<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', { year: '', title: '', description: '' })}>Add item</button>
{:else if block.type === 'testimonials'}
{#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="Name" value={item.name} oninput={(e) => updateArray('items', i, { name: e.currentTarget.value })} />
<textarea class="textarea textarea-bordered mb-2 w-full" placeholder="Text" value={item.text} oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}></textarea>
<input class="input input-bordered w-full" type="number" min="1" max="5" value={item.rating} oninput={(e) => updateArray('items', i, { rating: Number(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', { name: '', text: '', rating: 5 })}>Add testimonial</button>
{:else if block.type === 'services'}
{#each block.data.items || [] as item, i}
<div class="rounded-box mb-3 border border-base-300 p-3">
{#each ['title', 'description', 'duration', 'price'] as field}
<input class="input input-bordered mb-2 w-full" placeholder={field} value={item[field]} oninput={(e) => updateArray('items', i, { [field]: e.currentTarget.value })} />
{/each}
<button class="btn btn-error btn-sm" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
</div>
{/each}
<button class="btn" type="button" onclick={() => addArrayItem('items', { title: '', description: '', duration: '', price: '' })}>Add service</button>
{:else if block.type === 'horizontal_cards'}
{#each block.data.items || [] as item, i}
<div class="rounded-box mb-3 border border-base-300 p-3">
{#each ['title', 'description', 'url', 'link'] as field}
<input class="input input-bordered mb-2 w-full" placeholder={field} value={item[field]} oninput={(e) => updateArray('items', i, { [field]: e.currentTarget.value })} />
{/each}
<button class="btn btn-error btn-sm" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
</div>
{/each}
<button class="btn" type="button" onclick={() => addArrayItem('items', { title: '', description: '', url: '', link: '' })}>Add card</button>
{/if}
</div>
{/if}

View file

@ -0,0 +1,39 @@
<script lang="ts">
import { uploadMedia } from '$lib/pb';
let { url = '', alt = '', onChange = (value: { url: string; alt: string }) => {} } = $props<{
url?: string;
alt?: string;
onChange?: (value: { url: string; alt: string }) => void;
}>();
let uploading = $state(false);
async function handleFile(event: Event) {
const file = (event.currentTarget as HTMLInputElement).files?.[0];
if (!file) return;
uploading = true;
try {
const result = await uploadMedia(file);
url = result.url;
onChange({ url, alt });
} finally {
uploading = false;
}
}
</script>
<div class="space-y-3">
{#if url}
<img class="max-h-56 rounded-box object-cover" src={url} alt={alt} />
{/if}
<input class="file-input file-input-bordered w-full" type="file" accept="image/*" onchange={handleFile} disabled={uploading} />
<label class="form-control">
<span class="label-text">Image URL</span>
<input class="input input-bordered" bind:value={url} oninput={() => onChange({ url, alt })} />
</label>
<label class="form-control">
<span class="label-text">Alt text</span>
<input class="input input-bordered" bind:value={alt} oninput={() => onChange({ url, alt })} />
</label>
{#if uploading}<span class="loading loading-spinner"></span>{/if}
</div>

View file

@ -0,0 +1,59 @@
<script lang="ts">
import { browser } from '$app/environment';
import { onMount } from 'svelte';
let { value = '', onChange = (html: string) => {} } = $props<{ value?: string; onChange?: (html: string) => void }>();
let editorEl: HTMLDivElement | undefined = $state();
let mounted = $state(false);
onMount(() => {
mounted = true;
if (editorEl) {
editorEl.innerHTML = value || '';
}
});
function exec(cmd: string, val?: string) {
if (!browser) return;
editorEl?.focus();
document.execCommand(cmd, false, val);
emit();
}
function emit() {
if (editorEl) onChange(editorEl.innerHTML);
}
function setLink() {
const url = prompt('Link URL', 'https://');
if (url) exec('createLink', url);
}
function handleInput() {
emit();
}
</script>
{#if mounted}
<div class="rounded-box border border-base-300 bg-base-100">
<div class="flex flex-wrap gap-2 border-b border-base-300 p-2">
<button class="btn btn-xs" onclick={() => exec('bold')} type="button"><b>B</b></button>
<button class="btn btn-xs" onclick={() => exec('italic')} type="button"><i>I</i></button>
<button class="btn btn-xs" onclick={() => exec('formatBlock', '<h2>')} type="button">H2</button>
<button class="btn btn-xs" onclick={() => exec('formatBlock', '<h3>')} type="button">H3</button>
<button class="btn btn-xs" onclick={() => exec('insertUnorderedList')} type="button">List</button>
<button class="btn btn-xs" onclick={setLink} type="button">Link</button>
</div>
<div
bind:this={editorEl}
contenteditable
role="textbox"
aria-multiline="true"
class="min-h-40 p-4 outline-none"
oninput={handleInput}
onkeydown={(e) => { if (e.key === 'Tab') { e.preventDefault(); exec('insertHTML', '&emsp;'); } }}
></div>
</div>
{:else}
<div class="rounded-box border border-base-300 bg-base-100 p-4 text-base-content/50">Loading editor…</div>
{/if}

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,36 @@
<script lang="ts">
import type { ContentBlock } from '$lib/types';
import TextBlock from './TextBlock.svelte';
import ImageBlock from './ImageBlock.svelte';
import ImageTextBlock from './ImageTextBlock.svelte';
import TimelineBlock from './TimelineBlock.svelte';
import TestimonialsBlock from './TestimonialsBlock.svelte';
import ServicesBlock from './ServicesBlock.svelte';
import CtaBlock from './CtaBlock.svelte';
import SpacerBlock from './SpacerBlock.svelte';
import HorizontalCardsBlock from './HorizontalCardsBlock.svelte';
let { blocks = [] } = $props<{ blocks: ContentBlock[] }>();
</script>
{#each blocks as block (block.id)}
{#if block.type === 'text'}
<TextBlock data={block.data} />
{:else if block.type === 'image'}
<ImageBlock data={block.data} />
{:else if block.type === 'image_text'}
<ImageTextBlock data={block.data} />
{:else if block.type === 'timeline'}
<TimelineBlock data={block.data} />
{:else if block.type === 'testimonials'}
<TestimonialsBlock data={block.data} />
{:else if block.type === 'services'}
<ServicesBlock data={block.data} />
{:else if block.type === 'cta'}
<CtaBlock data={block.data} />
{:else if block.type === 'spacer'}
<SpacerBlock data={block.data} />
{:else if block.type === 'horizontal_cards'}
<HorizontalCardsBlock data={block.data} />
{/if}
{/each}

View file

@ -0,0 +1,15 @@
<script lang="ts">
let { data } = $props<{
data: { heading?: string; subtext?: string; buttonLabel?: string; buttonUrl?: string };
}>();
</script>
<section class="px-6 py-16 md:py-20">
<div class="mx-auto max-w-5xl rounded-[2.5rem] bg-sage px-8 py-14 text-center text-white shadow-lg md:px-16">
<h2 class="text-4xl text-white md:text-5xl">{data.heading || 'Ready to feel restored?'}</h2>
<p class="mx-auto mt-5 max-w-2xl text-lg leading-8 text-white/85">{data.subtext || 'Book a massage session designed around your body, pace, and needs.'}</p>
{#if data.buttonLabel}
<a class="btn mt-8 rounded-full border-0 bg-white px-8 text-sage-dark hover:bg-warm" href={data.buttonUrl || '/book'}>{data.buttonLabel}</a>
{/if}
</div>
</section>

View file

@ -0,0 +1,27 @@
<script lang="ts">
type Card = { title: string; description: string; url?: string; link?: string };
let { data } = $props<{ data: { items?: Card[] } }>();
let items = $derived(data.items?.length ? data.items : [
{ title: 'Mindful touch', description: 'Create calm content cards for studio highlights.' }
]);
</script>
<section class="mx-auto max-w-6xl px-6 py-16">
<div class="mb-8">
<p class="mb-2 text-sm font-semibold uppercase tracking-[0.25em] text-sage-dark">Explore</p>
<h2 class="text-4xl md:text-5xl">Studio highlights</h2>
</div>
<div class="flex gap-5 overflow-x-auto pb-4 md:grid md:grid-cols-3 md:overflow-visible">
{#each items as item}
<a class="min-w-[18rem] overflow-hidden rounded-[2rem] bg-white/75 shadow-sm ring-1 ring-charcoal/5 transition hover:-translate-y-1 hover:shadow-md md:min-w-0" href={item.link || '#'}>
{#if item.url}
<img class="aspect-[4/3] w-full object-cover" src={item.url} alt="" />
{/if}
<div class="p-6">
<h3 class="text-2xl">{item.title}</h3>
<p class="mt-3 leading-7 text-charcoal/70">{item.description}</p>
</div>
</a>
{/each}
</div>
</section>

View file

@ -0,0 +1,16 @@
<script lang="ts">
let { data } = $props<{ data: { url?: string; alt?: string; caption?: string } }>();
</script>
<section class="mx-auto max-w-5xl px-6 py-10">
<figure class="overflow-hidden rounded-[2rem] bg-white/70 shadow-sm ring-1 ring-charcoal/5">
{#if data.url}
<img class="aspect-[16/10] w-full object-cover" src={data.url} alt={data.alt || ''} />
{:else}
<div class="grid aspect-[16/10] place-items-center bg-sage/10 text-sage-dark">Image coming soon</div>
{/if}
{#if data.caption}
<figcaption class="px-6 py-4 text-center text-sm text-charcoal/60">{data.caption}</figcaption>
{/if}
</figure>
</section>

View file

@ -0,0 +1,20 @@
<script lang="ts">
let { data } = $props<{
data: { url?: string; alt?: string; content?: string; imagePosition?: 'left' | 'right' };
}>();
</script>
<section class="mx-auto max-w-6xl px-6 py-14 md:py-20">
<div class="grid items-center gap-10 md:grid-cols-2">
<div class:md:order-2={data.imagePosition === 'right'} class="overflow-hidden rounded-[2rem] bg-sage/10 shadow-sm">
{#if data.url}
<img class="aspect-[4/5] w-full object-cover" src={data.url} alt={data.alt || ''} />
{:else}
<div class="grid aspect-[4/5] place-items-center text-sage-dark">Upload an image</div>
{/if}
</div>
<div class="prose-wellness text-lg text-charcoal/80">
{@html data.content || '<h2>A gentler rhythm</h2><p>Pair meaningful copy with a calming studio image.</p>'}
</div>
</div>
</section>

View file

@ -0,0 +1,26 @@
<script lang="ts">
type Service = { title: string; description: string; duration: string; price: string };
let { data } = $props<{ data: { items?: Service[] } }>();
let items = $derived(data.items?.length ? data.items : [
{ title: 'Restorative Massage', description: 'A personalized session to ease tension and support deep rest.', duration: '60 min', price: '£70' }
]);
</script>
<section class="mx-auto max-w-6xl px-6 py-16 md:py-20">
<div class="mb-10 text-center">
<p class="mb-2 text-sm font-semibold uppercase tracking-[0.25em] text-sage-dark">Treatments</p>
<h2 class="text-4xl md:text-5xl">Services</h2>
</div>
<div class="grid gap-6 md:grid-cols-2">
{#each items as item}
<article class="group rounded-[2rem] bg-white/75 p-7 shadow-sm ring-1 ring-charcoal/5 transition hover:-translate-y-1 hover:shadow-md">
<div class="flex items-start justify-between gap-4">
<h3 class="text-2xl">{item.title}</h3>
<span class="rounded-full bg-sage/10 px-4 py-2 text-sm font-semibold text-sage-dark">{item.duration}</span>
</div>
<p class="mt-4 leading-7 text-charcoal/70">{item.description}</p>
<p class="mt-6 text-xl font-bold text-terracotta">{item.price}</p>
</article>
{/each}
</div>
</section>

View file

@ -0,0 +1,6 @@
<script lang="ts">
let { data } = $props<{ data: { size?: 'sm' | 'md' | 'lg' } }>();
let height = $derived(data.size === 'lg' ? 'h-24 md:h-36' : data.size === 'sm' ? 'h-8 md:h-12' : 'h-14 md:h-20');
</script>
<div class={height} aria-hidden="true"></div>

View file

@ -0,0 +1,54 @@
<script lang="ts">
import { onMount } from 'svelte';
type Testimonial = { name: string; text: string; rating: number };
let { data } = $props<{ data: { items?: Testimonial[] } }>();
let items = $derived(data.items?.length ? data.items : [
{ name: 'Client', text: 'A calming, thoughtful massage experience.', rating: 5 }
]);
let index = $state(0);
let paused = $state(false);
let interval: ReturnType<typeof setInterval> | undefined;
function next() {
index = (index + 1) % items.length;
}
function prev() {
index = (index - 1 + items.length) % items.length;
}
onMount(() => {
interval = setInterval(() => {
if (!paused && items.length > 1) next();
}, 4000);
return () => interval && clearInterval(interval);
});
</script>
<section class="bg-white/45 py-16 md:py-20" onmouseenter={() => (paused = true)} onmouseleave={() => (paused = false)} role="region" aria-label="Testimonials carousel">
<div class="mx-auto max-w-5xl px-6">
<div class="mb-10 flex flex-col justify-between gap-4 md:flex-row md:items-end">
<div>
<p class="mb-2 text-sm font-semibold uppercase tracking-[0.25em] text-sage-dark">Kind words</p>
<h2 class="text-4xl md:text-5xl">Client experiences</h2>
</div>
<div class="flex gap-3">
<button class="btn btn-circle bg-white text-charcoal hover:bg-sage hover:text-white" onclick={prev} aria-label="Previous testimonial">‹</button>
<button class="btn btn-circle bg-white text-charcoal hover:bg-sage hover:text-white" onclick={next} aria-label="Next testimonial">›</button>
</div>
</div>
<div class="carousel w-full overflow-hidden rounded-[2rem] bg-warm shadow-sm ring-1 ring-charcoal/5">
{#each items as item, i}
<div class="carousel-item w-full transition-transform duration-500" style={`transform: translateX(-${index * 100}%);`}>
<article class="w-full p-8 md:p-12">
<div class="mb-5 text-xl text-terracotta" aria-label={`${item.rating} stars`}>{'★'.repeat(Math.max(1, Math.min(5, item.rating || 5)))}</div>
<p class="text-2xl leading-relaxed text-charcoal/80 md:text-3xl">“{item.text}”</p>
<p class="mt-6 font-semibold text-sage-dark">— {item.name}</p>
</article>
</div>
{/each}
</div>
</div>
</section>

View file

@ -0,0 +1,9 @@
<script lang="ts">
let { data } = $props<{ data: { content?: string } }>();
</script>
<section class="mx-auto max-w-3xl px-6 py-12 md:py-16">
<div class="prose-wellness text-lg text-charcoal/85">
{@html data.content || '<h2>Welcome</h2><p>Add warm, inviting copy in the CMS.</p>'}
</div>
</section>

View file

@ -0,0 +1,26 @@
<script lang="ts">
type TimelineItem = { year: string; title: string; description: string };
let { data } = $props<{ data: { items?: TimelineItem[] } }>();
let items = $derived(data.items?.length ? data.items : [
{ year: 'Now', title: 'Your story here', description: 'Add milestones, training, or the journey behind the practice.' }
]);
</script>
<section class="mx-auto max-w-5xl px-6 py-16">
<div class="mb-12 text-center">
<p class="mb-2 text-sm font-semibold uppercase tracking-[0.25em] text-sage-dark">Journey</p>
<h2 class="text-4xl md:text-5xl">A practice shaped over time</h2>
</div>
<div class="relative md:before:absolute md:before:left-1/2 md:before:top-0 md:before:h-full md:before:w-px md:before:bg-sage/30">
{#each items as item, index}
<div class="relative mb-8 grid gap-4 md:grid-cols-2 md:gap-12">
<div class="hidden md:block" class:md:order-2={index % 2 === 0}></div>
<article class="rounded-3xl bg-white/75 p-6 shadow-sm ring-1 ring-charcoal/5" class:md:text-right={index % 2 === 0}>
<span class="text-sm font-bold uppercase tracking-[0.2em] text-terracotta">{item.year}</span>
<h3 class="mt-2 text-2xl">{item.title}</h3>
<p class="mt-3 leading-7 text-charcoal/70">{item.description}</p>
</article>
</div>
{/each}
</div>
</section>

View file

@ -0,0 +1,26 @@
<script lang="ts">
import type { FooterGlobal } from '$lib/types';
let { footer } = $props<{ footer: FooterGlobal }>();
</script>
<footer class="mt-12 border-t border-charcoal/5 bg-white/45">
<div class="mx-auto grid max-w-6xl gap-10 px-6 py-12 md:grid-cols-[1.2fr_1fr_1fr]">
<div>
<h2 class="text-3xl">{footer.businessName}</h2>
<p class="mt-4 max-w-sm leading-7 text-charcoal/65">{footer.tagline}</p>
</div>
<div class="space-y-2 text-charcoal/70">
{#if footer.address}<p>{footer.address}</p>{/if}
{#if footer.phone}<p><a class="hover:text-sage-dark" href={`tel:${footer.phone}`}>{footer.phone}</a></p>{/if}
{#if footer.email}<p><a class="hover:text-sage-dark" href={`mailto:${footer.email}`}>{footer.email}</a></p>{/if}
</div>
<div class="space-y-3">
{#each footer.socialLinks || [] as link}
{#if link.url}
<a class="block font-semibold capitalize text-sage-dark hover:text-terracotta" href={link.url} target="_blank" rel="noreferrer">{link.platform}</a>
{/if}
{/each}
</div>
</div>
<div class="border-t border-charcoal/5 px-6 py-5 text-center text-sm text-charcoal/55">{footer.copyrightText}</div>
</footer>

View file

@ -0,0 +1,27 @@
<script lang="ts">
import type { HeaderGlobal } from '$lib/types';
let { header } = $props<{ header: HeaderGlobal }>();
</script>
<header class="sticky top-0 z-40 border-b border-charcoal/5 bg-warm/90 backdrop-blur">
<div class="mx-auto flex max-w-6xl items-center justify-between gap-4 px-6 py-4">
<a class="flex items-center gap-3" href="/" aria-label="Home">
{#if header.logo?.url}
<img class="h-12 w-12 rounded-full object-cover" src={header.logo.url} alt={header.logo.alt || ''} />
{:else}
<span class="grid h-12 w-12 place-items-center rounded-full bg-sage text-lg font-bold text-white">ES</span>
{/if}
<span class="font-serif text-xl font-bold">Eva Shafik</span>
</a>
<nav class="hidden items-center gap-7 md:flex" aria-label="Main navigation">
{#each header.navLinks || [] as link}
<a class="text-sm font-semibold text-charcoal/75 transition hover:text-sage-dark" href={link.href}>{link.label}</a>
{/each}
</nav>
{#if header.ctaButton?.label}
<a class="btn rounded-full border-0 bg-sage px-6 text-white hover:bg-sage-dark" href={header.ctaButton.href}>{header.ctaButton.label}</a>
{/if}
</div>
</header>

1
app/src/lib/index.ts Normal file
View file

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

36
app/src/lib/pb.ts Normal file
View file

@ -0,0 +1,36 @@
import PocketBase from 'pocketbase';
import { env } from '$env/dynamic/public';
import { browser } from '$app/environment';
export const pbUrl = env.PUBLIC_POCKETBASE_URL || 'http://localhost:8090';
export function createPocketBase(authCookie?: string, url = pbUrl) {
const pb = new PocketBase(url);
pb.autoCancellation(false);
if (authCookie) {
pb.authStore.loadFromCookie(authCookie, 'pb_auth');
} else if (browser) {
pb.authStore.loadFromCookie(document.cookie, 'pb_auth');
}
return pb;
}
export const pb = createPocketBase();
export function getFileUrl(collectionIdOrName: string, recordId: string, filename: string) {
return `${pbUrl}/api/files/${collectionIdOrName}/${recordId}/${filename}`;
}
export async function uploadMedia(file: File) {
const formData = new FormData();
formData.append('file', file);
formData.append('alt', file.name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
const record = await pb.collection('media').create(formData);
return {
record,
url: getFileUrl(record.collectionId, record.id, record.file)
};
}

60
app/src/lib/types.ts Normal file
View file

@ -0,0 +1,60 @@
export type BlockType =
| 'text'
| 'image'
| 'image_text'
| 'timeline'
| 'testimonials'
| 'services'
| 'cta'
| 'spacer'
| 'horizontal_cards';
export type ContentBlock = {
id: string;
type: BlockType;
data: Record<string, any>;
};
export type PageRecord = {
id: string;
slug: string;
title: string;
blocks: ContentBlock[];
published: boolean;
};
export type HeaderGlobal = {
logo: { url: string; alt: string };
navLinks: { label: string; href: string }[];
ctaButton: { label: string; href: string };
};
export type FooterGlobal = {
businessName: string;
tagline: string;
address: string;
phone: string;
email: string;
socialLinks: { platform: string; url: string }[];
copyrightText: string;
};
export const defaultHeader: HeaderGlobal = {
logo: { url: '', alt: 'Massage studio logo' },
navLinks: [
{ label: 'Home', href: '/' },
{ label: 'About', href: '/about' },
{ label: 'Services', href: '/services' }
],
ctaButton: { label: 'Book Now', href: '/book' }
};
export const defaultFooter: FooterGlobal = {
businessName: 'Eva Shafik Massage',
tagline: 'Warm, restorative massage therapy for everyday wellbeing.',
address: '',
phone: '',
email: '',
socialLinks: [{ platform: 'instagram', url: '' }],
copyrightText: `© ${new Date().getFullYear()} Eva Shafik Massage. All rights reserved.`
};

View file

@ -0,0 +1,20 @@
import { defaultFooter, defaultHeader } from '$lib/types';
import type { LayoutServerLoad } from './$types';
async function getGlobal(pb: App.Locals['pb'], key: string, fallback: unknown) {
try {
const record = await pb.collection('globals').getFirstListItem(`key = "${key}"`);
return record.data || fallback;
} catch {
return fallback;
}
}
export const load: LayoutServerLoad = async ({ locals, url }) => {
const [header, footer] = await Promise.all([
getGlobal(locals.pb, 'header', defaultHeader),
getGlobal(locals.pb, 'footer', defaultFooter)
]);
return { header, footer, user: locals.user, url: { pathname: url.pathname } };
};

View file

@ -0,0 +1,22 @@
<script lang="ts">
import '../app.css';
import favicon from '$lib/assets/favicon.svg';
import Header from '$lib/components/Header.svelte';
import Footer from '$lib/components/Footer.svelte';
let { children, data } = $props();
let isAdmin = $derived(data.url?.pathname?.startsWith('/admin'));
</script>
<svelte:head>
<link rel="icon" href={favicon} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</svelte:head>
{#if isAdmin}
{@render children()}
{:else}
<Header header={data.header} />
<main>{@render children()}</main>
<Footer footer={data.footer} />
{/if}

View file

@ -0,0 +1,11 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ locals }) => {
try {
const page = await locals.pb.collection('pages').getFirstListItem('slug = "home" && published = true');
return { page };
} catch {
throw error(404, 'Page not found');
}
};

View file

@ -0,0 +1,11 @@
<script lang="ts">
import BlockRenderer from '$lib/blocks/BlockRenderer.svelte';
let { data } = $props();
</script>
<svelte:head>
<title>{data.page.title}</title>
</svelte:head>
<BlockRenderer blocks={data.page.blocks || []} />

View file

@ -0,0 +1,13 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, locals }) => {
try {
const page = await locals.pb
.collection('pages')
.getFirstListItem(`slug = "${params.slug}" && published = true`);
return { page };
} catch {
throw error(404, 'Page not found');
}
};

View file

@ -0,0 +1,10 @@
<script lang="ts">
import BlockRenderer from '$lib/blocks/BlockRenderer.svelte';
let { data } = $props();
</script>
<svelte:head>
<title>{data.page.title}</title>
</svelte:head>
<BlockRenderer blocks={data.page.blocks || []} />

View file

@ -0,0 +1,5 @@
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = ({ locals }) => {
return { user: locals.user };
};

View file

@ -0,0 +1,21 @@
<script lang="ts">
let { children } = $props();
</script>
<div class="min-h-screen bg-base-200">
<div class="navbar bg-base-100 shadow-sm">
<div class="flex-1">
<a class="btn btn-ghost text-xl" href="/admin/pages">Massage CMS</a>
</div>
<div class="flex-none gap-2">
<a class="btn btn-ghost" href="/admin/pages">Pages</a>
<a class="btn btn-ghost" href="/admin/globals">Globals</a>
<form method="POST" action="/admin/login?/logout">
<button class="btn btn-outline" type="submit">Logout</button>
</form>
</div>
</div>
<main class="mx-auto max-w-7xl p-4 md:p-8">
{@render children()}
</main>
</div>

View file

@ -0,0 +1,26 @@
import { defaultFooter, defaultHeader } from '$lib/types';
import type { Actions, PageServerLoad } from './$types';
async function getGlobal(pb: App.Locals['pb'], key: string, fallback: unknown) {
try {
return await pb.collection('globals').getFirstListItem(`key = "${key}"`);
} catch {
return await pb.collection('globals').create({ key, data: fallback });
}
}
export const load: PageServerLoad = async ({ locals }) => {
const [header, footer] = await Promise.all([
getGlobal(locals.pb, 'header', defaultHeader),
getGlobal(locals.pb, 'footer', defaultFooter)
]);
return { header, footer };
};
export const actions: Actions = {
save: async ({ request, locals }) => {
const data = await request.formData();
const id = String(data.get('id'));
await locals.pb.collection('globals').update(id, { data: JSON.parse(String(data.get('data'))) });
}
};

View file

@ -0,0 +1,58 @@
<script lang="ts">
import ImageUploader from '$lib/admin/editors/ImageUploader.svelte';
let { data } = $props();
let header = $state(structuredClone(data.header.data));
let footer = $state(structuredClone(data.footer.data));
function addHeaderLink() { header.navLinks = [...(header.navLinks || []), { label: '', href: '' }]; }
function addSocial() { footer.socialLinks = [...(footer.socialLinks || []), { platform: '', url: '' }]; }
</script>
<svelte:head><title>Globals | CMS</title></svelte:head>
<div class="mb-6">
<h1 class="text-3xl font-bold">Global sections</h1>
<p class="text-base-content/60">Edit the site header and footer content.</p>
</div>
<div class="grid gap-6 lg:grid-cols-2">
<form class="rounded-box bg-base-100 p-5 shadow" method="POST" action="?/save">
<input type="hidden" name="id" value={data.header.id} />
<input type="hidden" name="data" value={JSON.stringify(header)} />
<h2 class="mb-4 text-2xl font-bold">Header</h2>
<ImageUploader url={header.logo?.url} alt={header.logo?.alt} onChange={(image) => (header.logo = image)} />
<h3 class="mt-6 font-bold">Navigation</h3>
{#each header.navLinks || [] as link, i}
<div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2">
<input class="input input-bordered" bind:value={link.label} placeholder="Label" />
<input class="input input-bordered" bind:value={link.href} placeholder="Href" />
<button class="btn btn-error btn-outline" type="button" onclick={() => (header.navLinks = header.navLinks.filter((_: unknown, index: number) => index !== i))}>×</button>
</div>
{/each}
<button class="btn btn-sm" type="button" onclick={addHeaderLink}>Add link</button>
<h3 class="mt-6 font-bold">CTA button</h3>
<input class="input input-bordered mb-2 w-full" bind:value={header.ctaButton.label} placeholder="Label" />
<input class="input input-bordered w-full" bind:value={header.ctaButton.href} placeholder="Href" />
<button class="btn btn-primary mt-6" type="submit">Save header</button>
</form>
<form class="rounded-box bg-base-100 p-5 shadow" method="POST" action="?/save">
<input type="hidden" name="id" value={data.footer.id} />
<input type="hidden" name="data" value={JSON.stringify(footer)} />
<h2 class="mb-4 text-2xl font-bold">Footer</h2>
{#each ['businessName', 'tagline', 'address', 'phone', 'email', 'copyrightText'] as field}
<label class="form-control"><span class="label-text">{field}</span><input class="input input-bordered" bind:value={footer[field]} /></label>
{/each}
<h3 class="mt-6 font-bold">Social links</h3>
{#each footer.socialLinks || [] as link, i}
<div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2">
<input class="input input-bordered" bind:value={link.platform} placeholder="Platform" />
<input class="input input-bordered" bind:value={link.url} placeholder="URL" />
<button class="btn btn-error btn-outline" type="button" onclick={() => (footer.socialLinks = footer.socialLinks.filter((_: unknown, index: number) => index !== i))}>×</button>
</div>
{/each}
<button class="btn btn-sm" type="button" onclick={addSocial}>Add social link</button>
<button class="btn btn-primary mt-6 block" type="submit">Save footer</button>
</form>
</div>

View file

@ -0,0 +1,27 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
export const actions: Actions = {
login: async ({ request, locals }) => {
const data = await request.formData();
const email = String(data.get('email') || '');
const password = String(data.get('password') || '');
try {
try {
await locals.pb.admins.authWithPassword(email, password);
} catch {
await locals.pb.collection('users').authWithPassword(email, password);
}
} catch (err) {
console.error('Login failed for', email, err);
return fail(400, { message: 'Invalid email or password.' });
}
throw redirect(303, '/admin/pages');
},
logout: async ({ locals }) => {
locals.pb.authStore.clear();
throw redirect(303, '/admin/login');
}
};

View file

@ -0,0 +1,26 @@
<script lang="ts">
let { form } = $props();
</script>
<svelte:head><title>Admin login</title></svelte:head>
<div class="grid min-h-screen place-items-center bg-base-200 p-6">
<form class="card w-full max-w-md bg-base-100 shadow-xl" method="POST" action="?/login">
<div class="card-body">
<h1 class="card-title text-3xl">Sign in</h1>
<p class="text-base-content/60">Use your PocketBase admin or CMS user credentials.</p>
{#if form?.message}
<div class="alert alert-error mt-4">{form.message}</div>
{/if}
<label class="form-control mt-4">
<span class="label-text">Email</span>
<input class="input input-bordered" name="email" type="email" required />
</label>
<label class="form-control">
<span class="label-text">Password</span>
<input class="input input-bordered" name="password" type="password" required />
</label>
<button class="btn btn-primary mt-4" type="submit">Login</button>
</div>
</form>
</div>

View file

@ -0,0 +1,29 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ locals }) => {
const pages = await locals.pb.collection('pages').getFullList({ sort: 'slug' });
return { pages };
};
export const actions: Actions = {
create: async ({ request, locals }) => {
const data = await request.formData();
const slug = String(data.get('slug') || '').trim().toLowerCase().replace(/[^a-z0-9-]/g, '-');
const title = String(data.get('title') || '').trim();
if (!slug || !title) return fail(400, { message: 'Slug and title are required.' });
await locals.pb.collection('pages').create({ slug, title, blocks: [], published: false });
throw redirect(303, `/admin/pages/${slug}`);
},
toggle: async ({ request, locals }) => {
const data = await request.formData();
await locals.pb.collection('pages').update(String(data.get('id')), {
published: String(data.get('published')) !== 'true'
});
},
delete: async ({ request, locals }) => {
const data = await request.formData();
await locals.pb.collection('pages').delete(String(data.get('id')));
}
};

View file

@ -0,0 +1,65 @@
<script lang="ts">
let { data, form } = $props();
</script>
<svelte:head><title>Pages | CMS</title></svelte:head>
<div class="mb-6 flex flex-col justify-between gap-4 md:flex-row md:items-center">
<div>
<h1 class="text-3xl font-bold">Pages</h1>
<p class="text-base-content/60">Create, edit, preview, and publish website pages.</p>
</div>
<button class="btn btn-primary" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.showModal()}>New page</button>
</div>
{#if form?.message}
<div class="alert alert-error mb-4">{form.message}</div>
{/if}
<div class="overflow-x-auto rounded-box bg-base-100 shadow">
<table class="table">
<thead>
<tr><th>Slug</th><th>Title</th><th>Status</th><th class="text-right">Actions</th></tr>
</thead>
<tbody>
{#each data.pages as page}
<tr>
<td class="font-mono">{page.slug}</td>
<td>{page.title}</td>
<td><span class="badge" class:badge-success={page.published}>{page.published ? 'Published' : 'Draft'}</span></td>
<td class="flex justify-end gap-2">
<a class="btn btn-sm" href={`/admin/pages/${page.slug}`}>Edit</a>
<a class="btn btn-sm" href={page.slug === 'home' ? '/' : `/${page.slug}`} target="_blank">Preview</a>
<form method="POST" action="?/toggle">
<input type="hidden" name="id" value={page.id} />
<input type="hidden" name="published" value={page.published} />
<button class="btn btn-sm btn-outline" type="submit">{page.published ? 'Unpublish' : 'Publish'}</button>
</form>
<form method="POST" action="?/delete" onsubmit={() => confirm('Delete this page?')}>
<input type="hidden" name="id" value={page.id} />
<button class="btn btn-sm btn-error btn-outline" type="submit">Delete</button>
</form>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
<dialog id="new-page" class="modal">
<form class="modal-box" method="POST" action="?/create">
<h2 class="text-2xl font-bold">Create page</h2>
<label class="form-control mt-4">
<span class="label-text">Slug</span>
<input class="input input-bordered" name="slug" placeholder="about" required />
</label>
<label class="form-control">
<span class="label-text">Title</span>
<input class="input input-bordered" name="title" placeholder="About" required />
</label>
<div class="modal-action">
<button class="btn" type="button" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.close()}>Cancel</button>
<button class="btn btn-primary" type="submit">Create</button>
</div>
</form>
</dialog>

View file

@ -0,0 +1,22 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, locals }) => {
const page = await locals.pb.collection('pages').getFirstListItem(`slug = "${params.slug}"`);
return { page };
};
export const actions: Actions = {
save: async ({ request, locals }) => {
const data = await request.formData();
const id = String(data.get('id'));
const slug = String(data.get('slug') || '').trim().toLowerCase().replace(/[^a-z0-9-]/g, '-');
const title = String(data.get('title') || '').trim();
const blocks = JSON.parse(String(data.get('blocks') || '[]'));
const publish = String(data.get('publish')) === 'true';
if (!slug || !title) return fail(400, { message: 'Slug and title are required.' });
await locals.pb.collection('pages').update(id, { slug, title, blocks, ...(publish ? { published: true } : {}) });
throw redirect(303, `/admin/pages/${slug}`);
}
};

View file

@ -0,0 +1,104 @@
<script lang="ts">
import BlockList from '$lib/admin/BlockList.svelte';
import { blockLabels, blockTypes, createBlock } from '$lib/admin/blockDefaults';
import BlockEditor from '$lib/admin/editors/BlockEditor.svelte';
import type { ContentBlock } from '$lib/types';
let { data, form } = $props();
let page = $state(data.page);
let blocks = $state<ContentBlock[]>(structuredClone(data.page.blocks || []));
let selectedId = $state(blocks[0]?.id || '');
let previewMode = $state<'desktop' | 'mobile'>('desktop');
let showPreview = $state(false);
let selectedBlock = $derived(blocks.find((block) => block.id === selectedId) || null);
function addBlock(type: keyof typeof blockLabels) {
const block = createBlock(type);
blocks = [...blocks, block];
selectedId = block.id;
}
function updateBlock(updated: ContentBlock) {
blocks = blocks.map((block) => (block.id === updated.id ? updated : block));
}
function deleteBlock(id: string) {
blocks = blocks.filter((block) => block.id !== id);
if (selectedId === id) selectedId = blocks[0]?.id || '';
}
function moveBlock(from: number, to: number) {
const copy = [...blocks];
const [item] = copy.splice(from, 1);
copy.splice(to, 0, item);
blocks = copy;
}
function openPreview() {
sessionStorage.setItem('cms-preview-blocks', JSON.stringify(blocks));
showPreview = true;
}
function markPublish(event: MouseEvent) {
const form = (event.currentTarget as HTMLButtonElement).form;
const input = form?.querySelector('[name=publish]') as HTMLInputElement | null;
if (input) input.value = 'true';
}
</script>
<svelte:head><title>Edit {page.title} | CMS</title></svelte:head>
<form method="POST" action="?/save" class="space-y-6">
<input type="hidden" name="id" value={page.id} />
<input type="hidden" name="blocks" value={JSON.stringify(blocks)} />
<input type="hidden" name="publish" value="false" />
<div class="flex flex-col justify-between gap-4 md:flex-row md:items-end">
<div>
<h1 class="text-3xl font-bold">Edit page</h1>
<p class="text-base-content/60">Manage blocks, draft previews, and publishing.</p>
</div>
<div class="flex flex-wrap gap-2">
<button class="btn" type="button" onclick={openPreview}>Preview</button>
<button class="btn btn-outline" type="submit">Save draft</button>
<button class="btn btn-primary" type="submit" onclick={markPublish}>Publish</button>
</div>
</div>
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
<div class="grid gap-4 md:grid-cols-2">
<label class="form-control"><span class="label-text">Slug</span><input class="input input-bordered" name="slug" bind:value={page.slug} /></label>
<label class="form-control"><span class="label-text">Title</span><input class="input input-bordered" name="title" bind:value={page.title} /></label>
</div>
<div class="grid gap-6 lg:grid-cols-[22rem_1fr]">
<aside class="space-y-4">
<div class="rounded-box bg-base-100 p-4 shadow">
<div class="dropdown w-full">
<button class="btn btn-primary w-full" type="button" tabindex="0">Add block</button>
<ul class="menu dropdown-content z-10 mt-2 w-full rounded-box bg-base-100 p-2 shadow">
{#each blockTypes as type}
<li><button type="button" onclick={() => addBlock(type)}>{blockLabels[type]}</button></li>
{/each}
</ul>
</div>
</div>
<BlockList {blocks} {selectedId} onSelect={(id) => (selectedId = id)} onDelete={deleteBlock} onMove={moveBlock} />
</aside>
<BlockEditor block={selectedBlock} onChange={updateBlock} />
</div>
</form>
{#if showPreview}
<div class="fixed inset-0 z-50 bg-black/60 p-4">
<div class="mx-auto flex h-full max-w-7xl flex-col rounded-box bg-base-100 p-4 shadow-xl">
<div class="mb-3 flex items-center justify-between gap-3">
<div class="join"><button class="btn join-item" class:btn-active={previewMode === 'desktop'} onclick={() => (previewMode = 'desktop')}>Desktop</button><button class="btn join-item" class:btn-active={previewMode === 'mobile'} onclick={() => (previewMode = 'mobile')}>Mobile</button></div>
<button class="btn" onclick={() => (showPreview = false)}>Close</button>
</div>
<iframe class="mx-auto h-full rounded-box border" class:w-full={previewMode === 'desktop'} style={previewMode === 'mobile' ? 'width: 390px;' : ''} src="/preview" title="Preview"></iframe>
</div>
</div>
{/if}

View file

@ -0,0 +1,25 @@
<script lang="ts">
import { onMount } from 'svelte';
import BlockRenderer from '$lib/blocks/BlockRenderer.svelte';
import type { ContentBlock } from '$lib/types';
let blocks = $state<ContentBlock[]>([]);
onMount(() => {
const raw = sessionStorage.getItem('cms-preview-blocks');
if (raw) blocks = JSON.parse(raw);
});
</script>
<svelte:head>
<title>Preview</title>
</svelte:head>
{#if blocks.length}
<BlockRenderer {blocks} />
{:else}
<section class="mx-auto max-w-3xl px-6 py-20 text-center">
<h1 class="text-4xl">No preview content</h1>
<p class="mt-4 text-charcoal/65">Open preview from the page editor to view the current draft.</p>
</section>
{/if}

3
app/static/robots.txt Normal file
View file

@ -0,0 +1,3 @@
# allow crawling everything by default
User-agent: *
Disallow:

14
app/svelte.config.js Normal file
View file

@ -0,0 +1,14 @@
import adapter from '@sveltejs/adapter-node';
/** @type {import('@sveltejs/kit').Config} */
const config = {
compilerOptions: {
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
runes: ({ filename }) => (filename.split(/[/\\]/).includes('node_modules') ? undefined : true)
},
kit: {
adapter: adapter()
}
};
export default config;

20
app/tsconfig.json Normal file
View file

@ -0,0 +1,20 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"rewriteRelativeImportExtensions": true,
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// To make changes to top-level options such as include and exclude, we recommend extending
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
}

7
app/vite.config.ts Normal file
View file

@ -0,0 +1,7 @@
import { sveltekit } from '@sveltejs/kit/vite';
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [tailwindcss(), sveltekit()]
});