Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6269d3302c
commit
f3987e8386
328 changed files with 10618 additions and 389 deletions
51
resources/js/pagebuilder/editor/BlockPalette.vue
Normal file
51
resources/js/pagebuilder/editor/BlockPalette.vue
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
import { VueDraggable } from 'vue-draggable-plus';
|
||||
import { blockIcon } from './icons';
|
||||
import { createBlock } from './tree';
|
||||
|
||||
/**
|
||||
* Auswahl der Blockarten, nach Gruppen. Anklicken fügt ein, Ziehen legt an
|
||||
* beliebiger Stelle im Inhalt ab.
|
||||
*/
|
||||
defineProps({
|
||||
compact: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const emit = defineEmits(['pick']);
|
||||
const editor = inject('pagebuilder:editor');
|
||||
|
||||
const groups = computed(() => Object.entries(editor.groups)
|
||||
.map(([key, label]) => ({ key, label, types: Object.values(editor.types).filter((type) => type.group === key) }))
|
||||
.filter((group) => group.types.length));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid gap-4">
|
||||
<section v-for="group in groups" :key="group.key">
|
||||
<h3 class="mb-2 text-xs font-semibold tracking-wide text-muted-foreground uppercase">{{ group.label }}</h3>
|
||||
<VueDraggable
|
||||
:model-value="group.types"
|
||||
:group="{ name: 'pagebuilder', pull: 'clone', put: false }"
|
||||
:clone="(type) => createBlock(type)"
|
||||
:sort="false"
|
||||
:disabled="compact || editor.readOnly.value"
|
||||
class="grid grid-cols-2 gap-2"
|
||||
>
|
||||
<button
|
||||
v-for="type in group.types"
|
||||
:key="type.key"
|
||||
type="button"
|
||||
class="flex items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-[13px] font-medium transition-colors hover:border-brand-300 hover:bg-brand-soft/60"
|
||||
:class="compact ? '' : 'cursor-grab active:cursor-grabbing'"
|
||||
:title="type.description || type.label"
|
||||
:disabled="editor.readOnly.value"
|
||||
@click="emit('pick', type)"
|
||||
>
|
||||
<component :is="blockIcon(type.icon)" class="size-4 shrink-0 text-brand-text" />
|
||||
<span class="truncate">{{ type.label }}</span>
|
||||
</button>
|
||||
</VueDraggable>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
135
resources/js/pagebuilder/editor/BlockSettings.vue
Normal file
135
resources/js/pagebuilder/editor/BlockSettings.vue
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<script setup>
|
||||
import { computed, inject, watch } from 'vue';
|
||||
import { ArrowDown, ArrowUp, EyeOff, Plus, Trash2 } from '@lucide/vue';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import FieldInput from './FieldInput.vue';
|
||||
import { blockIcon } from './icons';
|
||||
import { syncColumns, uid } from './tree';
|
||||
|
||||
const props = defineProps({
|
||||
block: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const editor = inject('pagebuilder:editor');
|
||||
const type = computed(() => editor.types[props.block.type]);
|
||||
|
||||
// Formatierter Text wird direkt im Block bearbeitet.
|
||||
const fields = computed(() => (type.value?.fields ?? []).filter((field) => field.type !== 'html'));
|
||||
|
||||
watch(() => props.block.data.layout, () => {
|
||||
if (props.block.type === 'columns') syncColumns(props.block);
|
||||
});
|
||||
|
||||
function addItem() {
|
||||
props.block.items.push({ id: uid(), title: `${type.value.container.label} ${props.block.items.length + 1}`, blocks: [] });
|
||||
}
|
||||
|
||||
function moveItem(index, direction) {
|
||||
const items = props.block.items;
|
||||
const target = index + direction;
|
||||
|
||||
if (target >= 0 && target < items.length) {
|
||||
[items[index], items[target]] = [items[target], items[index]];
|
||||
}
|
||||
}
|
||||
|
||||
function removeItem(index) {
|
||||
const item = props.block.items[index];
|
||||
|
||||
if (item.blocks.length && !window.confirm(`„${item.title || type.value.container.label}“ enthält Inhalte. Trotzdem entfernen?`)) return;
|
||||
|
||||
props.block.items.splice(index, 1);
|
||||
}
|
||||
|
||||
// Sichtbarkeit einzelner Blöcke
|
||||
const visibility = computed(() => props.block.visibility ?? {});
|
||||
const restricted = computed(() => Object.values(visibility.value).some((values) => values?.length));
|
||||
|
||||
function toggleRule(rule, value) {
|
||||
const current = new Set(visibility.value[rule] ?? []);
|
||||
current.has(value) ? current.delete(value) : current.add(value);
|
||||
props.block.visibility = { ...visibility.value, [rule]: [...current] };
|
||||
}
|
||||
|
||||
const ruleGroups = computed(() => [
|
||||
{ key: 'role', label: 'Rollen', options: editor.audienceOptions.role },
|
||||
{ key: 'department', label: 'Abteilungen', options: editor.audienceOptions.department.map((value) => ({ value, label: value })) },
|
||||
{ key: 'location', label: 'Standorte', options: editor.audienceOptions.location.map((value) => ({ value, label: value })) },
|
||||
].filter((group) => group.options.length));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="type" class="grid gap-5">
|
||||
<header class="flex items-start gap-3">
|
||||
<span class="grid size-9 shrink-0 place-items-center rounded-md bg-brand-soft text-brand-text"><component :is="blockIcon(type.icon)" class="size-4.5" /></span>
|
||||
<div class="min-w-0">
|
||||
<h2 class="font-semibold">{{ type.label }}</h2>
|
||||
<p v-if="type.description" class="text-xs text-muted-foreground">{{ type.description }}</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<p v-if="type.fields.some((field) => field.type === 'html')" class="rounded-md bg-muted px-3 py-2 text-xs text-muted-foreground">
|
||||
Den Text bearbeiten Sie direkt im Block. Markieren Sie Text für Fettdruck, Links und Listen.
|
||||
</p>
|
||||
|
||||
<FieldInput
|
||||
v-for="field in fields"
|
||||
:id="`field-${block.id}-${field.name}`"
|
||||
:key="`${block.id}-${field.name}`"
|
||||
v-model="block.data[field.name]"
|
||||
:field="field"
|
||||
/>
|
||||
|
||||
<section v-if="type.container && type.container.max > 1 && type.key !== 'columns'" class="grid gap-2">
|
||||
<h3 class="text-[13px] font-medium">{{ type.container.label }}s</h3>
|
||||
<div v-for="(item, index) in block.items" :key="item.id" class="flex items-center gap-1">
|
||||
<Input v-if="type.container.titled" v-model="item.title" class="h-8" :aria-label="`Titel ${index + 1}`" maxlength="120" />
|
||||
<span v-else class="flex-1 text-[13px]">{{ type.container.label }} {{ index + 1 }}</span>
|
||||
<button type="button" class="grid size-7 shrink-0 place-items-center rounded hover:bg-accent" title="Nach oben" @click="moveItem(index, -1)"><ArrowUp class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-7 shrink-0 place-items-center rounded hover:bg-accent" title="Nach unten" @click="moveItem(index, 1)"><ArrowDown class="size-3.5" /></button>
|
||||
<button
|
||||
type="button"
|
||||
class="grid size-7 shrink-0 place-items-center rounded text-destructive hover:bg-destructive/10 disabled:opacity-30"
|
||||
title="Entfernen"
|
||||
:disabled="block.items.length <= type.container.min"
|
||||
@click="removeItem(index)"
|
||||
>
|
||||
<Trash2 class="size-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
v-if="block.items.length < type.container.max"
|
||||
type="button"
|
||||
class="flex h-8 items-center justify-center gap-1.5 rounded-md border border-dashed text-[13px] font-medium text-muted-foreground hover:border-brand-300 hover:text-foreground"
|
||||
@click="addItem"
|
||||
>
|
||||
<Plus class="size-3.5" /> {{ type.container.label }} hinzufügen
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<details v-if="ruleGroups.length" class="rounded-md border" :open="restricted">
|
||||
<summary class="flex cursor-pointer items-center gap-2 px-3 py-2 text-[13px] font-medium">
|
||||
<EyeOff class="size-4 text-muted-foreground" />
|
||||
Sichtbarkeit
|
||||
<span v-if="restricted" class="ml-auto rounded bg-amber-100 px-1.5 py-0.5 text-[11px] text-amber-800 dark:bg-amber-900/50 dark:text-amber-200">eingeschränkt</span>
|
||||
</summary>
|
||||
<div class="grid gap-3 border-t px-3 py-3">
|
||||
<p class="text-xs text-muted-foreground">Leer = für alle, die die Seite sehen. Sonst nur für Personen, die mindestens eine Angabe erfüllen.</p>
|
||||
<fieldset v-for="group in ruleGroups" :key="group.key" class="grid gap-1">
|
||||
<legend class="mb-1 text-xs font-semibold text-muted-foreground">{{ group.label }}</legend>
|
||||
<div class="grid max-h-36 gap-0.5 overflow-y-auto">
|
||||
<label v-for="option in group.options" :key="option.value" class="flex items-center gap-2 rounded px-1 py-0.5 text-[13px] hover:bg-accent">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="size-4 accent-[var(--brand)]"
|
||||
:checked="(visibility[group.key] ?? []).includes(option.value)"
|
||||
@change="toggleRule(group.key, option.value)"
|
||||
/>
|
||||
{{ option.label }}
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</template>
|
||||
57
resources/js/pagebuilder/editor/EditorBlock.vue
Normal file
57
resources/js/pagebuilder/editor/EditorBlock.vue
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
import { ChevronDown, ChevronUp, Copy, EyeOff, GripVertical, Trash2 } from '@lucide/vue';
|
||||
import { blockComponent } from '../registry';
|
||||
import { blockIcon } from './icons';
|
||||
|
||||
const props = defineProps({
|
||||
block: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const editor = inject('pagebuilder:editor');
|
||||
|
||||
const type = computed(() => editor.types[props.block.type]);
|
||||
const selected = computed(() => editor.selectedId.value === props.block.id);
|
||||
const hovered = computed(() => editor.hoveredId.value === props.block.id);
|
||||
const restricted = computed(() => Object.values(props.block.visibility ?? {}).some((values) => values?.length));
|
||||
|
||||
// Dynamische Daten (Bild-URLs, aktuelle Beiträge …) kommen aus der Vorschau des Servers.
|
||||
const view = computed(() => ({ ...props.block, props: editor.previews[props.block.id] ?? props.block.props }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="relative rounded-md outline-offset-4 transition-[outline-color]"
|
||||
:class="[
|
||||
selected ? 'outline-2 outline-brand-500' : hovered ? 'outline-1 outline-brand-300' : 'outline-1 outline-transparent',
|
||||
type ? '' : 'opacity-60',
|
||||
]"
|
||||
:data-block-id="block.id"
|
||||
@click.stop="editor.select(block.id)"
|
||||
@mouseover.stop="editor.hoveredId.value = block.id"
|
||||
@mouseleave="editor.hoveredId.value === block.id && (editor.hoveredId.value = null)"
|
||||
>
|
||||
<div
|
||||
v-if="(selected || hovered) && !editor.readOnly.value"
|
||||
class="absolute -top-3.5 right-2 z-20 flex items-center gap-0.5 rounded-md border bg-card px-1 py-0.5 text-xs shadow-sm"
|
||||
@click.stop
|
||||
>
|
||||
<span class="pb-handle flex cursor-grab items-center gap-1 rounded px-1 py-0.5 font-medium text-muted-foreground active:cursor-grabbing" title="Ziehen zum Verschieben">
|
||||
<GripVertical class="size-3.5" />
|
||||
<component :is="blockIcon(type?.icon)" class="size-3.5" />
|
||||
{{ type?.label ?? block.type }}
|
||||
</span>
|
||||
<EyeOff v-if="restricted" class="mx-1 size-3.5 text-amber-600" title="Nur für bestimmte Personen sichtbar" />
|
||||
<span class="mx-0.5 h-4 w-px bg-border" />
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach oben" @click="editor.move(block.id, -1)"><ChevronUp class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach unten" @click="editor.move(block.id, 1)"><ChevronDown class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Duplizieren" @click="editor.duplicate(block.id)"><Copy class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded text-destructive hover:bg-destructive/10" title="Entfernen" @click="editor.remove(block.id)"><Trash2 class="size-3.5" /></button>
|
||||
</div>
|
||||
|
||||
<component :is="blockComponent(type.component)" v-if="type && blockComponent(type.component)" :block="view" />
|
||||
<div v-else class="rounded-md border border-dashed p-4 text-sm text-muted-foreground">
|
||||
Dieser Block ({{ block.type }}) ist nicht verfügbar – vermutlich ist das zugehörige Plugin deaktiviert. Er wird nicht angezeigt.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
62
resources/js/pagebuilder/editor/EditorBlockList.vue
Normal file
62
resources/js/pagebuilder/editor/EditorBlockList.vue
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
import { VueDraggable } from 'vue-draggable-plus';
|
||||
import { Plus } from '@lucide/vue';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import BlockPalette from './BlockPalette.vue';
|
||||
import EditorBlock from './EditorBlock.vue';
|
||||
|
||||
/**
|
||||
* Bearbeitbare Blockliste: Ziehen und Ablegen (auch zwischen Bereichen),
|
||||
* Hinzufügen per „+“. Wird von Container-Blöcken über inject('pagebuilder:list') genutzt.
|
||||
*/
|
||||
const props = defineProps({
|
||||
item: { type: Object, required: true },
|
||||
root: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const editor = inject('pagebuilder:editor');
|
||||
|
||||
const parentActive = computed(() => props.root || editor.containsActive(props.item));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid" :class="root ? 'gap-6' : 'gap-4'">
|
||||
<VueDraggable
|
||||
v-model="item.blocks"
|
||||
:group="{ name: 'pagebuilder' }"
|
||||
handle=".pb-handle"
|
||||
:animation="150"
|
||||
:disabled="editor.readOnly.value"
|
||||
ghost-class="pb-ghost"
|
||||
class="grid min-h-6"
|
||||
:class="[root ? 'gap-6' : 'gap-4', item.blocks.length ? '' : 'rounded-md border border-dashed border-border bg-muted/40 p-3']"
|
||||
@add="(event) => editor.select(item.blocks[event.newIndex]?.id)"
|
||||
>
|
||||
<EditorBlock v-for="block in item.blocks" :key="block.id" :block="block" />
|
||||
<p v-if="!item.blocks.length" class="pointer-events-none text-center text-xs text-muted-foreground">
|
||||
{{ root ? 'Noch keine Inhalte. Blöcke aus der rechten Spalte hierher ziehen oder hinzufügen.' : 'Blöcke hierher ziehen' }}
|
||||
</p>
|
||||
</VueDraggable>
|
||||
|
||||
<Popover v-if="!editor.readOnly.value && (parentActive || !item.blocks.length)">
|
||||
<PopoverTrigger
|
||||
class="flex h-8 items-center justify-center gap-1.5 rounded-md border border-dashed text-xs font-medium text-muted-foreground transition-colors hover:border-brand-300 hover:bg-brand-soft hover:text-brand-soft-foreground"
|
||||
@click.stop
|
||||
>
|
||||
<Plus class="size-3.5" /> Block hinzufügen
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="max-h-[70vh] w-[22rem] overflow-y-auto p-3" align="center" @click.stop>
|
||||
<BlockPalette compact @pick="(type) => editor.insert(item.blocks, item.blocks.length, type)" />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.pb-ghost {
|
||||
opacity: 0.4;
|
||||
outline: 2px dashed var(--brand-400);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
</style>
|
||||
314
resources/js/pagebuilder/editor/FieldInput.vue
Normal file
314
resources/js/pagebuilder/editor/FieldInput.vue
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
<script setup>
|
||||
import { computed, inject, ref, watch } from 'vue';
|
||||
import { ArrowDown, ArrowUp, FileDown, ImagePlus, LoaderCircle, Plus, Search, Trash2, Upload, X } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import RichTextEditor from '@/components/RichTextEditor.vue';
|
||||
import { quickLinkIcons } from '@/lib/icons';
|
||||
import { http } from '@/lib/http';
|
||||
|
||||
/**
|
||||
* Eingabefeld für ein Blockfeld – erzeugt aus der Feldbeschreibung des Servers
|
||||
* (App\Pagebuilder\Field). Plugin-Blöcke bekommen so ihr Formular geschenkt.
|
||||
*/
|
||||
const props = defineProps({
|
||||
field: { type: Object, required: true },
|
||||
id: { type: String, required: true },
|
||||
});
|
||||
|
||||
const model = defineModel({ default: null });
|
||||
const editor = inject('pagebuilder:editor');
|
||||
const emit = defineEmits(['image-uploaded']);
|
||||
|
||||
// Bild
|
||||
const uploading = ref(false);
|
||||
const imageInput = ref(null);
|
||||
|
||||
async function uploadImage(event) {
|
||||
const file = event.target.files?.[0];
|
||||
event.target.value = '';
|
||||
|
||||
if (!file) return;
|
||||
|
||||
uploading.value = true;
|
||||
|
||||
try {
|
||||
const result = await editor.uploadImage(file);
|
||||
model.value = result.path;
|
||||
emit('image-uploaded', result);
|
||||
} catch (error) {
|
||||
toast.error(error.fieldErrors?.image ?? error.message);
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Personen
|
||||
const peopleQuery = ref('');
|
||||
const peopleResults = ref([]);
|
||||
const peopleCache = editor.peopleCache;
|
||||
let searchTimer;
|
||||
|
||||
watch(peopleQuery, (query) => {
|
||||
clearTimeout(searchTimer);
|
||||
|
||||
if (query.trim().length < 2) {
|
||||
peopleResults.value = [];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
searchTimer = setTimeout(async () => {
|
||||
const data = await http.get(`/personen/suche?q=${encodeURIComponent(query.trim())}`);
|
||||
data.people.forEach((person) => (peopleCache[person.id] = person));
|
||||
peopleResults.value = data.people.filter((person) => !(model.value ?? []).includes(person.id));
|
||||
}, 250);
|
||||
});
|
||||
|
||||
if (props.field.type === 'people' && (model.value ?? []).some((id) => !peopleCache[id])) {
|
||||
const missing = model.value.filter((id) => !peopleCache[id]);
|
||||
http.get(`/personen/suche?${missing.map((id) => `ids[]=${id}`).join('&')}`).then((data) => data.people.forEach((person) => (peopleCache[person.id] = person)));
|
||||
}
|
||||
|
||||
function addPerson(person) {
|
||||
model.value = [...(model.value ?? []), person.id];
|
||||
peopleQuery.value = '';
|
||||
peopleResults.value = [];
|
||||
}
|
||||
|
||||
// Listen (Wiederholer, Personen, Dateien)
|
||||
function moveItem(list, index, direction) {
|
||||
const target = index + direction;
|
||||
|
||||
if (target < 0 || target >= list.length) return;
|
||||
|
||||
const copy = [...list];
|
||||
[copy[index], copy[target]] = [copy[target], copy[index]];
|
||||
model.value = copy;
|
||||
}
|
||||
|
||||
function removeItem(index) {
|
||||
model.value = model.value.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function addRepeaterItem() {
|
||||
const item = Object.fromEntries(props.field.fields.map((sub) => [sub.name, structuredClone(sub.default ?? (sub.type === 'toggle' ? false : sub.type === 'repeater' ? [] : ''))]));
|
||||
model.value = [...(model.value ?? []), item];
|
||||
}
|
||||
|
||||
// Tabelle
|
||||
const table = computed(() => model.value ?? [['']]);
|
||||
|
||||
function updateCell(row, col, value) {
|
||||
const copy = table.value.map((r) => [...r]);
|
||||
copy[row][col] = value;
|
||||
model.value = copy;
|
||||
}
|
||||
|
||||
function addRow() {
|
||||
model.value = [...table.value, Array(table.value[0]?.length ?? 1).fill('')];
|
||||
}
|
||||
|
||||
function addColumn() {
|
||||
model.value = table.value.map((row) => [...row, '']);
|
||||
}
|
||||
|
||||
function removeRow(index) {
|
||||
if (table.value.length > 1) model.value = table.value.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function removeColumn(index) {
|
||||
if ((table.value[0]?.length ?? 1) > 1) model.value = table.value.map((row) => row.filter((_, i) => i !== index));
|
||||
}
|
||||
|
||||
// Dateien (Downloads)
|
||||
const fileInput = ref(null);
|
||||
const files = computed(() => Object.fromEntries(editor.files.value.map((file) => [file.id, file])));
|
||||
|
||||
async function uploadFiles(event) {
|
||||
const chosen = [...(event.target.files ?? [])];
|
||||
event.target.value = '';
|
||||
uploading.value = true;
|
||||
|
||||
try {
|
||||
for (const file of chosen) {
|
||||
const result = await editor.uploadFile(file);
|
||||
model.value = [...(model.value ?? []), result.id];
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(error.fieldErrors?.file ?? error.message);
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const availableFiles = computed(() => editor.files.value.filter((file) => !(model.value ?? []).includes(file.id)));
|
||||
|
||||
const formatSize = (bytes) => (bytes > 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
||||
|
||||
const iconOptions = computed(() => (props.field.choices ?? []).map((choice) => ({ ...choice, icon: quickLinkIcons[choice.value] })));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid gap-1.5">
|
||||
<label v-if="field.type !== 'toggle'" :for="id" class="text-[13px] font-medium">{{ field.label }}</label>
|
||||
|
||||
<Input v-if="field.type === 'text'" :id="id" v-model="model" :maxlength="field.max" :placeholder="field.placeholder ?? ''" />
|
||||
<Input v-else-if="field.type === 'url'" :id="id" v-model="model" type="text" inputmode="url" placeholder="https://… oder /seiten/…" />
|
||||
<Textarea v-else-if="field.type === 'textarea'" :id="id" v-model="model" :maxlength="field.max" rows="3" />
|
||||
<RichTextEditor v-else-if="field.type === 'html'" v-model="model" bordered min-height="[&_.tiptap]:min-h-24" />
|
||||
<Input v-else-if="field.type === 'number'" :id="id" v-model.number="model" type="number" :min="field.min" :max="field.max" />
|
||||
<NativeSelect v-else-if="field.type === 'select'" :id="id" v-model="model" :options="field.choices" />
|
||||
|
||||
<label v-else-if="field.type === 'toggle'" :for="id" class="flex items-center justify-between gap-3 py-0.5 text-[13px] font-medium">
|
||||
{{ field.label }}
|
||||
<Switch :id="id" v-model="model" />
|
||||
</label>
|
||||
|
||||
<div v-else-if="field.type === 'icon'" class="grid grid-cols-6 gap-1.5">
|
||||
<button
|
||||
v-for="option in iconOptions"
|
||||
:key="option.value"
|
||||
type="button"
|
||||
class="grid aspect-square place-items-center rounded-md border transition-colors"
|
||||
:class="model === option.value ? 'border-brand-400 bg-brand-soft text-brand-soft-foreground' : 'text-muted-foreground hover:bg-accent'"
|
||||
:title="option.label"
|
||||
:aria-pressed="model === option.value"
|
||||
@click="model = option.value"
|
||||
>
|
||||
<component :is="option.icon" class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="field.type === 'image'" class="grid gap-2">
|
||||
<div v-if="model" class="relative overflow-hidden rounded-md border bg-muted">
|
||||
<img :src="editor.imageUrl(model)" alt="" class="aspect-video w-full object-cover" />
|
||||
<button type="button" class="absolute top-1.5 right-1.5 grid size-7 place-items-center rounded-md bg-card/90 shadow-sm hover:bg-card" title="Bild entfernen" @click="model = null">
|
||||
<X class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-9 items-center justify-center gap-2 rounded-md border border-dashed text-[13px] font-medium text-muted-foreground hover:border-brand-300 hover:text-foreground"
|
||||
:disabled="uploading"
|
||||
@click="imageInput?.click()"
|
||||
>
|
||||
<LoaderCircle v-if="uploading" class="size-4 animate-spin" />
|
||||
<ImagePlus v-else class="size-4" />
|
||||
{{ model ? 'Anderes Bild wählen' : 'Bild hochladen' }}
|
||||
</button>
|
||||
<input ref="imageInput" type="file" accept="image/jpeg,image/png,image/webp,image/gif" class="hidden" @change="uploadImage" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="field.type === 'people'" class="grid gap-2">
|
||||
<ul v-if="(model ?? []).length" class="grid gap-1">
|
||||
<li v-for="(personId, index) in model" :key="personId" class="flex items-center gap-2 rounded-md border bg-card px-2 py-1.5">
|
||||
<PersonAvatar v-if="peopleCache[personId]" :person="peopleCache[personId]" class="size-7 text-[10px]" />
|
||||
<span class="min-w-0 flex-1 truncate text-[13px]">{{ peopleCache[personId]?.name ?? '…' }}</span>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach oben" @click="moveItem(model, index, -1)"><ArrowUp class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Entfernen" @click="removeItem(index)"><X class="size-3.5" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="relative">
|
||||
<Search class="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input :id="id" v-model="peopleQuery" class="pl-8" placeholder="Person suchen …" autocomplete="off" />
|
||||
<ul v-if="peopleResults.length" class="absolute inset-x-0 top-full z-30 mt-1 max-h-60 overflow-y-auto rounded-md border bg-popover p-1 shadow-md">
|
||||
<li v-for="person in peopleResults" :key="person.id">
|
||||
<button type="button" class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[13px] hover:bg-accent" @click="addPerson(person)">
|
||||
<PersonAvatar :person="person" class="size-7 text-[10px]" />
|
||||
<span class="min-w-0"><span class="block truncate font-medium">{{ person.name }}</span><span class="block truncate text-xs text-muted-foreground">{{ person.job_title }}</span></span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="field.type === 'table'" class="grid gap-2">
|
||||
<div class="overflow-x-auto rounded-md border">
|
||||
<table class="w-full text-[13px]">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in table" :key="rowIndex" class="border-b last:border-0">
|
||||
<td v-for="(cell, colIndex) in row" :key="colIndex" class="border-r p-0 last:border-r-0">
|
||||
<input
|
||||
:value="cell"
|
||||
class="h-8 w-full min-w-20 bg-transparent px-2 focus:bg-brand-soft/50 focus:outline-none"
|
||||
:aria-label="`Zeile ${rowIndex + 1}, Spalte ${colIndex + 1}`"
|
||||
@input="updateCell(rowIndex, colIndex, $event.target.value)"
|
||||
/>
|
||||
</td>
|
||||
<td class="w-7 p-0 text-center"><button type="button" class="grid size-7 place-items-center text-muted-foreground hover:text-destructive" title="Zeile entfernen" @click="removeRow(rowIndex)"><X class="size-3.5" /></button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td v-for="(_, colIndex) in table[0]" :key="colIndex" class="p-0 text-center">
|
||||
<button type="button" class="mx-auto grid size-7 place-items-center text-muted-foreground hover:text-destructive" title="Spalte entfernen" @click="removeColumn(colIndex)"><X class="size-3.5" /></button>
|
||||
</td>
|
||||
<td />
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button type="button" class="inline-flex items-center gap-1 text-[13px] font-medium text-brand-text hover:underline" @click="addRow"><Plus class="size-3.5" /> Zeile</button>
|
||||
<button type="button" class="inline-flex items-center gap-1 text-[13px] font-medium text-brand-text hover:underline" @click="addColumn"><Plus class="size-3.5" /> Spalte</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="field.type === 'repeater'" class="grid gap-2">
|
||||
<details v-for="(entry, index) in model ?? []" :key="index" class="group rounded-md border bg-card" :open="index === (model ?? []).length - 1">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 px-3 py-2 text-[13px] font-medium">
|
||||
<span class="min-w-0 flex-1 truncate">{{ entry.label || entry.title || entry.alt || `${field.itemLabel} ${index + 1}` }}</span>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach oben" @click.prevent="moveItem(model, index, -1)"><ArrowUp class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach unten" @click.prevent="moveItem(model, index, 1)"><ArrowDown class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded text-destructive hover:bg-destructive/10" title="Entfernen" @click.prevent="removeItem(index)"><Trash2 class="size-3.5" /></button>
|
||||
</summary>
|
||||
<div class="grid gap-3 border-t px-3 py-3">
|
||||
<FieldInput v-for="sub in field.fields" :id="`${id}-${index}-${sub.name}`" :key="sub.name" v-model="entry[sub.name]" :field="sub" />
|
||||
</div>
|
||||
</details>
|
||||
<button
|
||||
v-if="(model ?? []).length < field.max"
|
||||
type="button"
|
||||
class="flex h-8 items-center justify-center gap-1.5 rounded-md border border-dashed text-[13px] font-medium text-muted-foreground hover:border-brand-300 hover:text-foreground"
|
||||
@click="addRepeaterItem"
|
||||
>
|
||||
<Plus class="size-3.5" /> {{ field.itemLabel }} hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="field.type === 'ids' && field.kind === 'page-file'" class="grid gap-2">
|
||||
<ul v-if="(model ?? []).length" class="grid gap-1">
|
||||
<li v-for="(fileId, index) in model" :key="fileId" class="flex items-center gap-2 rounded-md border bg-card px-2 py-1.5 text-[13px]">
|
||||
<FileDown class="size-4 shrink-0 text-muted-foreground" />
|
||||
<span class="min-w-0 flex-1 truncate">{{ files[fileId]?.name ?? 'Datei nicht mehr vorhanden' }}</span>
|
||||
<span v-if="files[fileId]" class="shrink-0 text-xs text-muted-foreground">{{ formatSize(files[fileId].size) }}</span>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Nach oben" @click="moveItem(model, index, -1)"><ArrowUp class="size-3.5" /></button>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" title="Entfernen" @click="removeItem(index)"><X class="size-3.5" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-9 items-center justify-center gap-2 rounded-md border border-dashed text-[13px] font-medium text-muted-foreground hover:border-brand-300 hover:text-foreground"
|
||||
:disabled="uploading"
|
||||
@click="fileInput?.click()"
|
||||
>
|
||||
<LoaderCircle v-if="uploading" class="size-4 animate-spin" />
|
||||
<Upload v-else class="size-4" />
|
||||
Dateien hochladen
|
||||
</button>
|
||||
<input ref="fileInput" type="file" multiple class="hidden" @change="uploadFiles" />
|
||||
<NativeSelect
|
||||
v-if="availableFiles.length"
|
||||
:model-value="null"
|
||||
:options="availableFiles.map((file) => ({ value: file.id, label: file.name }))"
|
||||
placeholder="Bereits hochgeladene Datei wählen …"
|
||||
@update:model-value="(value) => value && (model = [...(model ?? []), value])"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p v-if="field.help" class="text-xs text-muted-foreground">{{ field.help }}</p>
|
||||
</div>
|
||||
</template>
|
||||
58
resources/js/pagebuilder/editor/icons.js
Normal file
58
resources/js/pagebuilder/editor/icons.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import {
|
||||
Box,
|
||||
Columns3,
|
||||
Contact,
|
||||
FileDown,
|
||||
FolderTree,
|
||||
Heading,
|
||||
Image,
|
||||
Images,
|
||||
ListChecks,
|
||||
ListCollapse,
|
||||
MessageSquareWarning,
|
||||
Minus,
|
||||
MousePointerClick,
|
||||
MoveVertical,
|
||||
Newspaper,
|
||||
PanelTop,
|
||||
GalleryHorizontalEnd,
|
||||
Play,
|
||||
Quote,
|
||||
SquareDashed,
|
||||
Table,
|
||||
Text,
|
||||
CalendarDays,
|
||||
} from '@lucide/vue';
|
||||
|
||||
/**
|
||||
* Symbole der Blockarten (Namen aus App\Pagebuilder\Blocks, Lucide-Schreibweise).
|
||||
* Unbekannte Symbole von Plugin-Blöcken fallen auf „box“ zurück.
|
||||
*/
|
||||
const icons = {
|
||||
'square-dashed': SquareDashed,
|
||||
'columns-3': Columns3,
|
||||
'panel-top': PanelTop,
|
||||
'list-collapse': ListCollapse,
|
||||
'message-square-warning': MessageSquareWarning,
|
||||
heading: Heading,
|
||||
text: Text,
|
||||
quote: Quote,
|
||||
'mouse-pointer-click': MousePointerClick,
|
||||
'list-checks': ListChecks,
|
||||
table: Table,
|
||||
minus: Minus,
|
||||
'move-vertical': MoveVertical,
|
||||
image: Image,
|
||||
images: Images,
|
||||
play: Play,
|
||||
panorama: GalleryHorizontalEnd,
|
||||
contact: Contact,
|
||||
'file-down': FileDown,
|
||||
'folder-tree': FolderTree,
|
||||
newspaper: Newspaper,
|
||||
'calendar-days': CalendarDays,
|
||||
};
|
||||
|
||||
export function blockIcon(name) {
|
||||
return icons[name] ?? Box;
|
||||
}
|
||||
86
resources/js/pagebuilder/editor/tree.js
Normal file
86
resources/js/pagebuilder/editor/tree.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* Hilfsfunktionen für den Blockbaum im Editor.
|
||||
*/
|
||||
export function uid() {
|
||||
return Math.random().toString(36).slice(2, 8) + Date.now().toString(36).slice(-6);
|
||||
}
|
||||
|
||||
export function clone(value) {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
function itemCount(type, data) {
|
||||
if (!type.container) return 0;
|
||||
if (type.key === 'columns') return (data.layout ?? '1-1').split('-').length;
|
||||
if (type.key === 'tabs') return 2;
|
||||
if (type.key === 'accordion') return 3;
|
||||
|
||||
return type.container.min;
|
||||
}
|
||||
|
||||
export function createBlock(type) {
|
||||
const data = clone(type.defaults ?? {});
|
||||
const block = { id: uid(), type: type.key, data };
|
||||
|
||||
if (type.container) {
|
||||
block.items = Array.from({ length: itemCount(type, data) }, (_, index) => ({
|
||||
id: uid(),
|
||||
title: type.container.titled ? `${type.container.label} ${index + 1}` : undefined,
|
||||
blocks: [],
|
||||
}));
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/** Kopie mit neuen IDs (Duplizieren, Vorlagen). */
|
||||
export function duplicate(block) {
|
||||
const copy = clone(block);
|
||||
const renew = (b) => {
|
||||
b.id = uid();
|
||||
(b.items ?? []).forEach((item) => {
|
||||
item.id = uid();
|
||||
item.blocks.forEach(renew);
|
||||
});
|
||||
};
|
||||
renew(copy);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/** Block im Baum finden: liefert Block, Liste und Position. */
|
||||
export function locate(blocks, id, parent = null) {
|
||||
for (let index = 0; index < blocks.length; index++) {
|
||||
const block = blocks[index];
|
||||
|
||||
if (block.id === id) return { block, list: blocks, index, parent };
|
||||
|
||||
for (const item of block.items ?? []) {
|
||||
const found = locate(item.blocks, id, block);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function walk(blocks, callback) {
|
||||
for (const block of blocks) {
|
||||
callback(block);
|
||||
(block.items ?? []).forEach((item) => walk(item.blocks, callback));
|
||||
}
|
||||
}
|
||||
|
||||
/** Anzahl der Spalten an die Aufteilung anpassen, ohne Inhalte zu verlieren. */
|
||||
export function syncColumns(block) {
|
||||
const count = (block.data.layout ?? '1-1').split('-').length;
|
||||
|
||||
while (block.items.length < count) {
|
||||
block.items.push({ id: uid(), blocks: [] });
|
||||
}
|
||||
|
||||
if (block.items.length > count) {
|
||||
const overflow = block.items.splice(count).flatMap((item) => item.blocks);
|
||||
block.items[count - 1].blocks.push(...overflow);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue