Werkstatt-App: öffentliche PWA und Redaktions-Backend
Werbefreie, barrierearme Info-App für Werkstätten (WfbM) auf Basis von SvelteKit, Tailwind, SQLite/Drizzle: - App: Startseite mit Kacheln, Meldungen, Seitenbaum, Termine inkl. Schließzeiten und iCal-Abo, Ansprechpartner, Suche, Kontaktformular, Merkliste, Vorlesen, Leichte Sprache, Schriftgrößen, Hell/Dunkel, PWA - Redaktion: Dashboard, Meldungen, Seiten, Termine, Kacheln, Ansprechpartner, Mediathek mit Bildoptimierung, Postfach, Benutzer mit Rollen, Einstellungen (Name, Logo, Farbe, Rechtstexte) - Demo-Seed, CLI zum Anlegen von Benutzern, Dockerfile und Compose Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4f145116d8
commit
bef8574e07
143 changed files with 13518 additions and 1 deletions
42
src/lib/admin/AttachmentsField.svelte
Normal file
42
src/lib/admin/AttachmentsField.svelte
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import Paperclip from '@lucide/svelte/icons/paperclip';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import FileText from '@lucide/svelte/icons/file-text';
|
||||
import MediaPicker from './MediaPicker.svelte';
|
||||
import type { AttachmentItem } from '$lib/types';
|
||||
|
||||
let { name, value = [] }: { name: string; value?: AttachmentItem[] } = $props();
|
||||
let items = $state(untrack(() => value).map((a) => ({ title: a.title, file: a.file })));
|
||||
let open = $state(false);
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<span class="label">Dateien zum Herunterladen</span>
|
||||
<input type="hidden" {name} value={JSON.stringify(items.map((a) => ({ mediaId: a.file.id, title: a.title })))} />
|
||||
{#if items.length}
|
||||
<ul class="space-y-2 mb-2">
|
||||
{#each items as a, i (a.file.id)}
|
||||
<li class="flex items-center gap-2 rounded-xl border border-line p-2">
|
||||
<FileText class="size-5 text-ink-3 shrink-0 ml-1" />
|
||||
<input bind:value={items[i].title} class="field min-h-9 py-1" placeholder="Titel" aria-label="Titel der Datei" />
|
||||
<span class="text-xs text-ink-3 truncate max-w-32 hidden sm:block">{a.file.name}</span>
|
||||
<button type="button" class="btn btn-ghost btn-icon btn-sm" aria-label="Entfernen" onclick={() => (items = items.filter((x) => x !== a))}><X class="size-4" /></button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
<button type="button" class="btn btn-soft btn-sm" onclick={() => (open = true)}><Paperclip class="size-4" />Datei anhängen</button>
|
||||
<p class="hint">z. B. Speiseplan, Werkstattordnung oder Flyer als PDF.</p>
|
||||
</div>
|
||||
|
||||
<MediaPicker
|
||||
bind:open
|
||||
type="any"
|
||||
multiple
|
||||
onselect={(sel) =>
|
||||
(items = [
|
||||
...items,
|
||||
...sel.filter((s) => !items.some((i) => i.file.id === s.id)).map((file) => ({ file, title: file.name.replace(/\.[^.]+$/, '') }))
|
||||
])}
|
||||
/>
|
||||
52
src/lib/admin/ContactsField.svelte
Normal file
52
src/lib/admin/ContactsField.svelte
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
|
||||
type Option = { id: number; name: string; role: string };
|
||||
let { name, options, value = [] }: { name: string; options: Option[]; value?: number[] } = $props();
|
||||
|
||||
let selected = $state<number[]>(untrack(() => value));
|
||||
let adding = $state('');
|
||||
|
||||
const byId = $derived(new Map(options.map((o) => [o.id, o])));
|
||||
const available = $derived(options.filter((o) => !selected.includes(o.id)));
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<span class="label">Ansprechpartner</span>
|
||||
<input type="hidden" {name} value={JSON.stringify(selected)} />
|
||||
{#if selected.length}
|
||||
<ul class="flex flex-wrap gap-2 mb-2">
|
||||
{#each selected as id (id)}
|
||||
{@const c = byId.get(id)}
|
||||
{#if c}
|
||||
<li class="inline-flex items-center gap-2 rounded-full bg-brand-soft text-brand-ink pl-3 pr-1 py-1 text-sm font-semibold">
|
||||
{c.name}
|
||||
<button type="button" class="grid place-items-center size-6 rounded-full hover:bg-white/60" aria-label="{c.name} entfernen" onclick={() => (selected = selected.filter((x) => x !== id))}><X class="size-3.5" /></button>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
{#if available.length}
|
||||
<div class="flex gap-2">
|
||||
<select bind:value={adding} class="field min-h-10 py-1.5" aria-label="Ansprechpartner hinzufügen">
|
||||
<option value="">Ansprechpartner hinzufügen …</option>
|
||||
{#each available as o (o.id)}<option value={String(o.id)}>{o.name}{o.role ? ` – ${o.role}` : ''}</option>{/each}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-soft btn-sm btn-icon shrink-0 self-center"
|
||||
aria-label="Hinzufügen"
|
||||
disabled={!adding}
|
||||
onclick={() => {
|
||||
selected = [...selected, Number(adding)];
|
||||
adding = '';
|
||||
}}><Plus class="size-4" /></button
|
||||
>
|
||||
</div>
|
||||
{:else if !options.length}
|
||||
<p class="hint">Lege zuerst unter „Ansprechpartner“ Personen an.</p>
|
||||
{/if}
|
||||
</div>
|
||||
28
src/lib/admin/EasyLanguageField.svelte
Normal file
28
src/lib/admin/EasyLanguageField.svelte
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import BookHeart from '@lucide/svelte/icons/book-heart';
|
||||
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
||||
import RichEditor from './RichEditor.svelte';
|
||||
|
||||
let { value = '' }: { value?: string } = $props();
|
||||
let open = $state(untrack(() => !!value));
|
||||
</script>
|
||||
|
||||
<section class="card overflow-hidden tone-emerald">
|
||||
<button type="button" class="w-full flex items-center gap-3 p-5 text-left" onclick={() => (open = !open)} aria-expanded={open}>
|
||||
<span class="grid place-items-center size-10 rounded-xl bg-tone-soft text-tone-ink"><BookHeart class="size-5" /></span>
|
||||
<span class="flex-1">
|
||||
<span class="block font-display text-lg font-bold">Leichte Sprache</span>
|
||||
<span class="block text-sm text-ink-3">Optional: eine einfache Fassung des Textes. Wird angezeigt, wenn Leser „Leichte Sprache“ einschalten.</span>
|
||||
</span>
|
||||
<ChevronDown class="size-5 text-ink-3 transition-transform {open ? 'rotate-180' : ''}" />
|
||||
</button>
|
||||
<div class="px-5 pb-5" hidden={!open}>
|
||||
<RichEditor
|
||||
name="contentEasy"
|
||||
{value}
|
||||
label="Text in Leichter Sprache"
|
||||
hint="Tipps: kurze Sätze, ein Gedanke pro Satz, bekannte Wörter, lange Wörter mit Medio·punkt trennen."
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
62
src/lib/admin/EditForm.svelte
Normal file
62
src/lib/admin/EditForm.svelte
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import { enhance } from '$app/forms';
|
||||
import Save from '@lucide/svelte/icons/save';
|
||||
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
|
||||
import { toasts } from './toast.svelte';
|
||||
|
||||
let {
|
||||
children,
|
||||
aside,
|
||||
canDelete = false,
|
||||
deleteLabel = 'Löschen',
|
||||
deleteConfirm = 'Wirklich löschen? Das kann nicht rückgängig gemacht werden.',
|
||||
saveLabel = 'Speichern'
|
||||
}: {
|
||||
children: Snippet;
|
||||
aside?: Snippet;
|
||||
canDelete?: boolean;
|
||||
deleteLabel?: string;
|
||||
deleteConfirm?: string;
|
||||
saveLabel?: string;
|
||||
} = $props();
|
||||
|
||||
let busy = $state(false);
|
||||
</script>
|
||||
|
||||
<form
|
||||
method="POST"
|
||||
action="?/save"
|
||||
use:enhance={({ submitter, cancel }) => {
|
||||
if (submitter?.getAttribute('formaction')?.includes('delete') && !confirm(deleteConfirm)) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
return async ({ result, update }) => {
|
||||
busy = false;
|
||||
if (result.type === 'failure') toasts.show(String(result.data?.error ?? 'Bitte Eingaben prüfen.'), 'error');
|
||||
else if (result.type === 'error') toasts.show(result.error?.message ?? 'Fehler beim Speichern.', 'error');
|
||||
else if (result.type === 'success') toasts.show('Gespeichert');
|
||||
await update({ reset: false });
|
||||
};
|
||||
}}
|
||||
>
|
||||
<div class="grid xl:grid-cols-[1fr_20rem] gap-6 items-start">
|
||||
<div class="space-y-6 min-w-0">{@render children()}</div>
|
||||
{#if aside}<aside class="space-y-6 xl:sticky xl:top-6">{@render aside()}</aside>{/if}
|
||||
</div>
|
||||
|
||||
<div class="sticky bottom-0 -mx-4 sm:-mx-8 mt-8 px-4 sm:px-8 py-3 bg-bg/85 backdrop-blur border-t border-line flex items-center gap-2 z-20">
|
||||
<button class="btn btn-primary" disabled={busy}>
|
||||
{#if busy}<LoaderCircle class="size-4 animate-spin" />{:else}<Save class="size-4" />{/if}
|
||||
{saveLabel}
|
||||
</button>
|
||||
{#if canDelete}
|
||||
<button class="btn btn-danger ml-auto" formaction="?/delete" formnovalidate disabled={busy}>
|
||||
<Trash2 class="size-4" />{deleteLabel}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</form>
|
||||
48
src/lib/admin/GalleryField.svelte
Normal file
48
src/lib/admin/GalleryField.svelte
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import Plus from '@lucide/svelte/icons/plus';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
||||
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
||||
import MediaPicker from './MediaPicker.svelte';
|
||||
import type { MediaItem } from '$lib/types';
|
||||
|
||||
let { name, value = [] }: { name: string; value?: MediaItem[] } = $props();
|
||||
let items = $state(untrack(() => value));
|
||||
let open = $state(false);
|
||||
|
||||
function move(i: number, d: number) {
|
||||
const next = [...items];
|
||||
[next[i], next[i + d]] = [next[i + d], next[i]];
|
||||
items = next;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<span class="label">Bildergalerie</span>
|
||||
<input type="hidden" {name} value={JSON.stringify(items.map((i) => i.id))} />
|
||||
<div class="grid grid-cols-3 sm:grid-cols-5 gap-2">
|
||||
{#each items as img, i (img.id)}
|
||||
<div class="relative group aspect-square rounded-xl overflow-hidden bg-surface-2">
|
||||
<img src={img.thumb} alt="" class="size-full object-cover" />
|
||||
<div class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition flex items-end justify-between p-1.5">
|
||||
<span class="flex gap-1">
|
||||
{#if i > 0}<button type="button" class="grid place-items-center size-7 rounded-full bg-white/90 text-ink" aria-label="Nach vorne" onclick={() => move(i, -1)}><ChevronLeft class="size-4" /></button>{/if}
|
||||
{#if i < items.length - 1}<button type="button" class="grid place-items-center size-7 rounded-full bg-white/90 text-ink" aria-label="Nach hinten" onclick={() => move(i, 1)}><ChevronRight class="size-4" /></button>{/if}
|
||||
</span>
|
||||
<button type="button" class="grid place-items-center size-7 rounded-full bg-white/90 text-danger" aria-label="Entfernen" onclick={() => (items = items.filter((x) => x.id !== img.id))}><X class="size-4" /></button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
<button type="button" onclick={() => (open = true)} class="aspect-square rounded-xl border-2 border-dashed border-line hover:border-brand text-ink-3 hover:text-brand-ink grid place-items-center">
|
||||
<Plus class="size-7" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MediaPicker
|
||||
bind:open
|
||||
type="image"
|
||||
multiple
|
||||
onselect={(sel) => (items = [...items, ...sel.filter((s) => !items.some((i) => i.id === s.id))])}
|
||||
/>
|
||||
57
src/lib/admin/IconTonePicker.svelte
Normal file
57
src/lib/admin/IconTonePicker.svelte
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<script lang="ts">
|
||||
import Icon from '$lib/components/Icon.svelte';
|
||||
import { ICONS } from '$lib/icons';
|
||||
import { TONES, toneNames } from '$lib/palette';
|
||||
|
||||
let { icon = $bindable('star'), color = $bindable('sky'), label = '' }: { icon?: string; color?: string; label?: string } = $props();
|
||||
let showAll = $state(false);
|
||||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<input type="hidden" name="icon" value={icon} />
|
||||
<input type="hidden" name="color" value={color} />
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="tone-{color} flex items-center gap-3 rounded-2xl bg-tone-soft p-3 pr-5">
|
||||
<span class="grid place-items-center size-12 rounded-2xl bg-tone text-white"><Icon name={icon} class="size-6" /></span>
|
||||
<span class="font-display font-bold text-tone-ink">{label || 'Vorschau'}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend class="label">Farbe</legend>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each toneNames as t (t)}
|
||||
<button
|
||||
type="button"
|
||||
class="tone-{t} size-9 rounded-full bg-tone ring-offset-2 ring-offset-surface transition {color === t ? 'ring-3 ring-tone' : 'hover:scale-110'}"
|
||||
title={TONES[t]}
|
||||
aria-label={TONES[t]}
|
||||
aria-pressed={color === t}
|
||||
onclick={() => (color = t)}
|
||||
></button>
|
||||
{/each}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend class="label">Symbol</legend>
|
||||
<div class="grid grid-cols-8 sm:grid-cols-11 gap-1.5 {showAll ? '' : 'max-h-[5.8rem] overflow-hidden'}">
|
||||
{#each Object.entries(ICONS) as [key, def] (key)}
|
||||
<button
|
||||
type="button"
|
||||
class="tone-{color} grid place-items-center aspect-square rounded-xl transition {icon === key ? 'bg-tone text-white' : 'bg-surface-2 text-ink-2 hover:bg-tone-soft hover:text-tone-ink'}"
|
||||
title={def.label}
|
||||
aria-label={def.label}
|
||||
aria-pressed={icon === key}
|
||||
onclick={() => (icon = key)}
|
||||
>
|
||||
<Icon name={key} class="size-5" />
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<button type="button" class="text-sm font-semibold text-brand-ink mt-2" onclick={() => (showAll = !showAll)}>
|
||||
{showAll ? 'Weniger anzeigen' : 'Alle Symbole anzeigen'}
|
||||
</button>
|
||||
</fieldset>
|
||||
</div>
|
||||
37
src/lib/admin/ImageField.svelte
Normal file
37
src/lib/admin/ImageField.svelte
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import ImagePlus from '@lucide/svelte/icons/image-plus';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import Replace from '@lucide/svelte/icons/replace';
|
||||
import MediaPicker from './MediaPicker.svelte';
|
||||
import type { MediaItem } from '$lib/types';
|
||||
|
||||
let { name, value = null, label = 'Bild', aspect = 'aspect-video' }: { name: string; value?: MediaItem | null; label?: string; aspect?: string } = $props();
|
||||
|
||||
let current = $state(untrack(() => value));
|
||||
let open = $state(false);
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<span class="label">{label}</span>
|
||||
<input type="hidden" {name} value={current?.id ?? ''} />
|
||||
{#if current}
|
||||
<div class="relative group rounded-2xl overflow-hidden bg-surface-2 {aspect}">
|
||||
<img src={current.thumb} alt="" class="size-full object-cover" />
|
||||
<div class="absolute inset-x-0 bottom-0 p-2 flex gap-2 justify-end bg-gradient-to-t from-black/50">
|
||||
<button type="button" class="btn btn-sm bg-white/90 text-ink hover:bg-white" onclick={() => (open = true)}><Replace class="size-4" />Ändern</button>
|
||||
<button type="button" class="btn btn-sm btn-icon bg-white/90 text-danger hover:bg-white" aria-label="Bild entfernen" onclick={() => (current = null)}><X class="size-4" /></button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => (open = true)}
|
||||
class="w-full {aspect} rounded-2xl border-2 border-dashed border-line hover:border-brand hover:bg-brand-soft/50 text-ink-3 hover:text-brand-ink grid place-items-center transition"
|
||||
>
|
||||
<span class="flex flex-col items-center gap-1"><ImagePlus class="size-8" /><span class="text-sm font-semibold">Bild wählen</span></span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<MediaPicker bind:open type="image" onselect={(items) => (current = items[0] ?? current)} />
|
||||
156
src/lib/admin/MediaPicker.svelte
Normal file
156
src/lib/admin/MediaPicker.svelte
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<script lang="ts">
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import Upload from '@lucide/svelte/icons/upload';
|
||||
import Search from '@lucide/svelte/icons/search';
|
||||
import FileText from '@lucide/svelte/icons/file-text';
|
||||
import Check from '@lucide/svelte/icons/check';
|
||||
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
|
||||
import type { MediaItem } from '$lib/types';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
type = 'any',
|
||||
multiple = false,
|
||||
onselect
|
||||
}: {
|
||||
open: boolean;
|
||||
type?: 'image' | 'document' | 'any';
|
||||
multiple?: boolean;
|
||||
onselect: (items: MediaItem[]) => void;
|
||||
} = $props();
|
||||
|
||||
let dialog: HTMLDialogElement;
|
||||
let items = $state<MediaItem[]>([]);
|
||||
let selected = $state<MediaItem[]>([]);
|
||||
let q = $state('');
|
||||
let loading = $state(false);
|
||||
let uploading = $state(false);
|
||||
let errorMsg = $state('');
|
||||
|
||||
const accept = $derived(type === 'image' ? 'image/*' : type === 'document' ? '.pdf,.doc,.docx,.xls,.xlsx,.mp3,.m4a,.mp4,.txt' : '');
|
||||
|
||||
async function load() {
|
||||
loading = true;
|
||||
const params = new URLSearchParams({ type, q });
|
||||
const res = await fetch(`/admin/api/media?${params}`);
|
||||
items = res.ok ? await res.json() : [];
|
||||
loading = false;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (open && !dialog.open) {
|
||||
selected = [];
|
||||
errorMsg = '';
|
||||
dialog.showModal();
|
||||
load();
|
||||
}
|
||||
if (!open && dialog.open) dialog.close();
|
||||
});
|
||||
|
||||
async function upload(e: Event) {
|
||||
const input = e.currentTarget as HTMLInputElement;
|
||||
if (!input.files?.length) return;
|
||||
uploading = true;
|
||||
errorMsg = '';
|
||||
const body = new FormData();
|
||||
for (const f of input.files) body.append('files', f);
|
||||
const res = await fetch('/admin/api/media', { method: 'POST', body });
|
||||
uploading = false;
|
||||
input.value = '';
|
||||
if (!res.ok) {
|
||||
errorMsg = (await res.json().catch(() => null))?.message ?? 'Hochladen fehlgeschlagen.';
|
||||
return;
|
||||
}
|
||||
const added: MediaItem[] = await res.json();
|
||||
items = [...added, ...items];
|
||||
selected = multiple ? [...selected, ...added] : added.slice(0, 1);
|
||||
}
|
||||
|
||||
function toggle(item: MediaItem) {
|
||||
const isSel = selected.some((s) => s.id === item.id);
|
||||
if (multiple) selected = isSel ? selected.filter((s) => s.id !== item.id) : [...selected, item];
|
||||
else selected = isSel ? [] : [item];
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
onselect(selected);
|
||||
open = false;
|
||||
}
|
||||
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
const onSearch = () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(load, 250);
|
||||
};
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
bind:this={dialog}
|
||||
onclose={() => (open = false)}
|
||||
class="m-auto w-[min(56rem,calc(100vw-2rem))] h-[min(44rem,calc(100dvh-2rem))] rounded-3xl bg-surface text-ink p-0 shadow-float backdrop:bg-black/40 backdrop:backdrop-blur-sm"
|
||||
>
|
||||
<div class="flex flex-col h-full">
|
||||
<header class="flex items-center gap-3 px-5 py-4 border-b border-line">
|
||||
<h2 class="font-display text-xl font-bold mr-auto">
|
||||
{type === 'image' ? 'Bild' : type === 'document' ? 'Datei' : 'Medium'} auswählen
|
||||
</h2>
|
||||
<label class="btn btn-primary btn-sm cursor-pointer">
|
||||
{#if uploading}<LoaderCircle class="size-4 animate-spin" />{:else}<Upload class="size-4" />{/if}
|
||||
Hochladen
|
||||
<input type="file" class="sr-only" {accept} multiple onchange={upload} disabled={uploading} />
|
||||
</label>
|
||||
<button type="button" class="btn btn-ghost btn-icon" aria-label="Schließen" onclick={() => (open = false)}><X class="size-5" /></button>
|
||||
</header>
|
||||
|
||||
<div class="px-5 py-3 border-b border-line">
|
||||
<label class="relative block">
|
||||
<Search class="size-4 text-ink-3 absolute left-3 top-1/2 -translate-y-1/2" />
|
||||
<input bind:value={q} oninput={onSearch} type="search" placeholder="Suchen …" class="field pl-9 min-h-10 py-1.5" />
|
||||
</label>
|
||||
{#if errorMsg}<p class="text-danger text-sm mt-2 font-semibold">{errorMsg}</p>{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-5">
|
||||
{#if loading && !items.length}
|
||||
<p class="text-ink-3">Lädt …</p>
|
||||
{:else if !items.length}
|
||||
<div class="h-full grid place-items-center text-center text-ink-3">
|
||||
<p>Noch keine Dateien.<br />Lade oben rechts etwas hoch.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-3">
|
||||
{#each items as item (item.id)}
|
||||
{@const isSel = selected.some((s) => s.id === item.id)}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => toggle(item)}
|
||||
ondblclick={() => {
|
||||
selected = [item];
|
||||
confirm();
|
||||
}}
|
||||
class="relative text-left rounded-2xl overflow-hidden border-2 transition {isSel ? 'border-brand ring-4 ring-brand/20' : 'border-transparent hover:border-line'}"
|
||||
>
|
||||
<div class="aspect-square bg-surface-2 grid place-items-center">
|
||||
{#if item.isImage}
|
||||
<img src={item.thumb} alt={item.alt} class="size-full object-cover" loading="lazy" />
|
||||
{:else}
|
||||
<FileText class="size-10 text-ink-3" />
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-xs px-2 py-1.5 truncate">{item.name}</p>
|
||||
{#if isSel}
|
||||
<span class="absolute top-2 right-2 grid place-items-center size-6 rounded-full bg-brand text-white"><Check class="size-4" /></span>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<footer class="flex items-center justify-end gap-2 px-5 py-4 border-t border-line">
|
||||
<span class="text-sm text-ink-3 mr-auto">{selected.length ? `${selected.length} ausgewählt` : ''}</span>
|
||||
<button type="button" class="btn btn-ghost" onclick={() => (open = false)}>Abbrechen</button>
|
||||
<button type="button" class="btn btn-primary" disabled={!selected.length} onclick={confirm}>Übernehmen</button>
|
||||
</footer>
|
||||
</div>
|
||||
</dialog>
|
||||
18
src/lib/admin/MoveButtons.svelte
Normal file
18
src/lib/admin/MoveButtons.svelte
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import ChevronUp from '@lucide/svelte/icons/chevron-up';
|
||||
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
||||
|
||||
/** Pfeile zum Umsortieren – ruft die Action ?/move mit id & Richtung auf */
|
||||
let { id, first, last }: { id: number; first: boolean; last: boolean } = $props();
|
||||
</script>
|
||||
|
||||
<form method="POST" action="?/move" use:enhance class="flex flex-col">
|
||||
<input type="hidden" name="id" value={id} />
|
||||
<button name="dir" value="-1" class="grid place-items-center size-7 rounded-lg text-ink-3 hover:bg-surface-2 hover:text-ink disabled:opacity-30" disabled={first} aria-label="Nach oben">
|
||||
<ChevronUp class="size-4" />
|
||||
</button>
|
||||
<button name="dir" value="1" class="grid place-items-center size-7 rounded-lg text-ink-3 hover:bg-surface-2 hover:text-ink disabled:opacity-30" disabled={last} aria-label="Nach unten">
|
||||
<ChevronDown class="size-4" />
|
||||
</button>
|
||||
</form>
|
||||
19
src/lib/admin/PageHeader.svelte
Normal file
19
src/lib/admin/PageHeader.svelte
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import ArrowLeft from '@lucide/svelte/icons/arrow-left';
|
||||
|
||||
let { title, description = '', back = '', actions }: { title: string; description?: string; back?: string; actions?: Snippet } = $props();
|
||||
</script>
|
||||
|
||||
<div class="mb-7">
|
||||
{#if back}
|
||||
<a href={back} class="inline-flex items-center gap-1.5 text-sm font-semibold text-ink-3 hover:text-ink mb-3"><ArrowLeft class="size-4" />Zurück</a>
|
||||
{/if}
|
||||
<div class="flex flex-wrap items-end justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h1 class="font-display text-[1.75rem] font-extrabold leading-tight">{title}</h1>
|
||||
{#if description}<p class="text-ink-2 mt-1">{description}</p>{/if}
|
||||
</div>
|
||||
{#if actions}<div class="flex flex-wrap gap-2">{@render actions()}</div>{/if}
|
||||
</div>
|
||||
</div>
|
||||
14
src/lib/admin/Panel.svelte
Normal file
14
src/lib/admin/Panel.svelte
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
let { title = '', description = '', children }: { title?: string; description?: string; children: Snippet } = $props();
|
||||
</script>
|
||||
|
||||
<section class="card p-5 sm:p-6 space-y-5">
|
||||
{#if title}
|
||||
<header>
|
||||
<h2 class="font-display text-lg font-bold">{title}</h2>
|
||||
{#if description}<p class="text-sm text-ink-3 mt-0.5">{description}</p>{/if}
|
||||
</header>
|
||||
{/if}
|
||||
{@render children()}
|
||||
</section>
|
||||
148
src/lib/admin/RichEditor.svelte
Normal file
148
src/lib/admin/RichEditor.svelte
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<script lang="ts">
|
||||
import { onMount, onDestroy, untrack } from 'svelte';
|
||||
import { Editor } from '@tiptap/core';
|
||||
import StarterKit from '@tiptap/starter-kit';
|
||||
import Image from '@tiptap/extension-image';
|
||||
import Bold from '@lucide/svelte/icons/bold';
|
||||
import Italic from '@lucide/svelte/icons/italic';
|
||||
import Underline from '@lucide/svelte/icons/underline';
|
||||
import Heading2 from '@lucide/svelte/icons/heading-2';
|
||||
import Heading3 from '@lucide/svelte/icons/heading-3';
|
||||
import List from '@lucide/svelte/icons/list';
|
||||
import ListOrdered from '@lucide/svelte/icons/list-ordered';
|
||||
import Quote from '@lucide/svelte/icons/quote';
|
||||
import Link from '@lucide/svelte/icons/link';
|
||||
import Unlink from '@lucide/svelte/icons/unlink';
|
||||
import ImagePlus from '@lucide/svelte/icons/image-plus';
|
||||
import Minus from '@lucide/svelte/icons/minus';
|
||||
import Undo2 from '@lucide/svelte/icons/undo-2';
|
||||
import Redo2 from '@lucide/svelte/icons/redo-2';
|
||||
import MediaPicker from './MediaPicker.svelte';
|
||||
|
||||
let {
|
||||
name,
|
||||
value = '',
|
||||
label = 'Text',
|
||||
hint = '',
|
||||
minHeight = '14rem'
|
||||
}: { name: string; value?: string; label?: string; hint?: string; minHeight?: string } = $props();
|
||||
|
||||
let element: HTMLDivElement;
|
||||
let editor = $state<Editor | null>(null);
|
||||
let html = $state(untrack(() => value));
|
||||
let tick = $state(0); // löst Neuzeichnen der Toolbar aus
|
||||
let pickerOpen = $state(false);
|
||||
|
||||
onMount(() => {
|
||||
editor = new Editor({
|
||||
element,
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
heading: { levels: [2, 3] },
|
||||
code: false,
|
||||
codeBlock: false,
|
||||
link: { openOnClick: false, autolink: true, defaultProtocol: 'https' }
|
||||
}),
|
||||
Image
|
||||
],
|
||||
content: value,
|
||||
editorProps: {
|
||||
attributes: { class: 'rich focus:outline-none px-4 py-3', style: `min-height:${minHeight}` }
|
||||
},
|
||||
onTransaction: () => tick++,
|
||||
onUpdate: ({ editor }) => {
|
||||
html = editor.isEmpty ? '' : editor.getHTML();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onDestroy(() => editor?.destroy());
|
||||
|
||||
const active = (n: string, attrs?: Record<string, unknown>) => {
|
||||
void tick;
|
||||
return editor?.isActive(n, attrs) ?? false;
|
||||
};
|
||||
|
||||
function setLink() {
|
||||
if (!editor) return;
|
||||
const prev = editor.getAttributes('link').href ?? '';
|
||||
const url = prompt('Link-Adresse (z. B. https://… oder mailto:…)', prev);
|
||||
if (url === null) return;
|
||||
if (url === '') editor.chain().focus().unsetLink().run();
|
||||
else editor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();
|
||||
}
|
||||
|
||||
type Btn = { icon: typeof Bold; label: string; run: () => void; on?: () => boolean };
|
||||
const groups: Btn[][] = [
|
||||
[
|
||||
{ icon: Bold, label: 'Fett', run: () => editor?.chain().focus().toggleBold().run(), on: () => active('bold') },
|
||||
{ icon: Italic, label: 'Kursiv', run: () => editor?.chain().focus().toggleItalic().run(), on: () => active('italic') },
|
||||
{ icon: Underline, label: 'Unterstrichen', run: () => editor?.chain().focus().toggleUnderline().run(), on: () => active('underline') }
|
||||
],
|
||||
[
|
||||
{ icon: Heading2, label: 'Überschrift', run: () => editor?.chain().focus().toggleHeading({ level: 2 }).run(), on: () => active('heading', { level: 2 }) },
|
||||
{ icon: Heading3, label: 'Zwischenüberschrift', run: () => editor?.chain().focus().toggleHeading({ level: 3 }).run(), on: () => active('heading', { level: 3 }) }
|
||||
],
|
||||
[
|
||||
{ icon: List, label: 'Aufzählung', run: () => editor?.chain().focus().toggleBulletList().run(), on: () => active('bulletList') },
|
||||
{ icon: ListOrdered, label: 'Nummerierte Liste', run: () => editor?.chain().focus().toggleOrderedList().run(), on: () => active('orderedList') },
|
||||
{ icon: Quote, label: 'Zitat', run: () => editor?.chain().focus().toggleBlockquote().run(), on: () => active('blockquote') },
|
||||
{ icon: Minus, label: 'Trennlinie', run: () => editor?.chain().focus().setHorizontalRule().run() }
|
||||
],
|
||||
[
|
||||
{ icon: Link, label: 'Link', run: setLink, on: () => active('link') },
|
||||
{ icon: Unlink, label: 'Link entfernen', run: () => editor?.chain().focus().unsetLink().run() },
|
||||
{ icon: ImagePlus, label: 'Bild einfügen', run: () => (pickerOpen = true) }
|
||||
],
|
||||
[
|
||||
{ icon: Undo2, label: 'Rückgängig', run: () => editor?.chain().focus().undo().run() },
|
||||
{ icon: Redo2, label: 'Wiederholen', run: () => editor?.chain().focus().redo().run() }
|
||||
]
|
||||
];
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<span class="label">{label}</span>
|
||||
<input type="hidden" {name} value={html} />
|
||||
<div class="rounded-2xl border-[1.5px] border-line bg-surface focus-within:border-brand focus-within:ring-4 focus-within:ring-brand/15 transition">
|
||||
<div class="flex flex-wrap items-center gap-1 px-2 py-1.5 border-b border-line sticky top-0 bg-surface rounded-t-2xl z-10" role="toolbar" aria-label="Textformatierung">
|
||||
{#each groups as group, gi (gi)}
|
||||
{#if gi > 0}<span class="w-px h-6 bg-line mx-1"></span>{/if}
|
||||
{#each group as b (b.label)}
|
||||
{@const on = b.on?.() ?? false}
|
||||
<button
|
||||
type="button"
|
||||
class="grid place-items-center size-9 rounded-lg transition {on ? 'bg-brand-soft text-brand-ink' : 'text-ink-2 hover:bg-surface-2'}"
|
||||
title={b.label}
|
||||
aria-label={b.label}
|
||||
aria-pressed={b.on ? on : undefined}
|
||||
onclick={b.run}
|
||||
>
|
||||
<b.icon class="size-[1.1rem]" />
|
||||
</button>
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
<div bind:this={element}></div>
|
||||
</div>
|
||||
{#if hint}<p class="hint">{hint}</p>{/if}
|
||||
</div>
|
||||
|
||||
<MediaPicker
|
||||
bind:open={pickerOpen}
|
||||
type="image"
|
||||
onselect={(items) => {
|
||||
const img = items[0];
|
||||
if (img) editor?.chain().focus().setImage({ src: img.url, alt: img.alt }).run();
|
||||
}}
|
||||
/>
|
||||
|
||||
<style>
|
||||
:global(.ProseMirror p.is-editor-empty:first-child::before) {
|
||||
content: attr(data-placeholder);
|
||||
color: var(--ink-3);
|
||||
float: left;
|
||||
pointer-events: none;
|
||||
height: 0;
|
||||
}
|
||||
</style>
|
||||
39
src/lib/admin/Switch.svelte
Normal file
39
src/lib/admin/Switch.svelte
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<script lang="ts">
|
||||
let { name, checked = false, label, hint = '' }: { name: string; checked?: boolean; label: string; hint?: string } = $props();
|
||||
</script>
|
||||
|
||||
<label class="flex items-start gap-3 cursor-pointer">
|
||||
<input type="checkbox" {name} {checked} class="switch mt-0.5" />
|
||||
<span>
|
||||
<span class="block font-semibold">{label}</span>
|
||||
{#if hint}<span class="block text-sm text-ink-3">{hint}</span>{/if}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<style>
|
||||
.switch {
|
||||
appearance: none;
|
||||
flex-shrink: 0;
|
||||
width: 2.75rem;
|
||||
height: 1.6rem;
|
||||
border-radius: 999px;
|
||||
background: var(--line);
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.switch::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0.2rem;
|
||||
left: 0.2rem;
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
border-radius: 999px;
|
||||
background: white;
|
||||
box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
.switch:checked { background: var(--brand); }
|
||||
.switch:checked::after { transform: translateX(1.15rem); }
|
||||
</style>
|
||||
18
src/lib/admin/Toaster.svelte
Normal file
18
src/lib/admin/Toaster.svelte
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<script lang="ts">
|
||||
import CircleCheck from '@lucide/svelte/icons/circle-check';
|
||||
import CircleAlert from '@lucide/svelte/icons/circle-alert';
|
||||
import { toasts } from './toast.svelte';
|
||||
import { fly } from 'svelte/transition';
|
||||
</script>
|
||||
|
||||
<div class="fixed bottom-4 right-4 z-[100] flex flex-col gap-2 items-end" aria-live="polite">
|
||||
{#each toasts.items as t (t.id)}
|
||||
<div
|
||||
transition:fly={{ y: 20, duration: 200 }}
|
||||
class="flex items-center gap-2 rounded-2xl px-4 py-3 shadow-float font-semibold {t.kind === 'ok' ? 'bg-ink text-bg' : 'bg-danger text-white'}"
|
||||
>
|
||||
{#if t.kind === 'ok'}<CircleCheck class="size-5" />{:else}<CircleAlert class="size-5" />{/if}
|
||||
{t.text}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
13
src/lib/admin/toast.svelte.ts
Normal file
13
src/lib/admin/toast.svelte.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** Kleine Erfolgs-/Fehlermeldungen unten rechts im Admin. */
|
||||
class Toasts {
|
||||
items = $state<{ id: number; text: string; kind: 'ok' | 'error' }[]>([]);
|
||||
#id = 0;
|
||||
|
||||
show(text: string, kind: 'ok' | 'error' = 'ok') {
|
||||
const id = ++this.#id;
|
||||
this.items = [...this.items, { id, text, kind }];
|
||||
setTimeout(() => (this.items = this.items.filter((t) => t.id !== id)), 3500);
|
||||
}
|
||||
}
|
||||
|
||||
export const toasts = new Toasts();
|
||||
Loading…
Add table
Add a link
Reference in a new issue