Loheide-eu-mitarbeiterplatt.../resources/js/pagebuilder/editor/BlockSettings.vue
Friederich Loheide 694ccf6ae0 Mediathek: zentrale Bildverwaltung mit Verwendungsnachweis und Bildauswahl
- Tabellen media und media_usages, Modelle Media/MediaUsage
- App\Media\MediaLibrary (store/register/replace/delete/rebuild) und
  Registry App\Media\MediaUsages (Quellen: Seiten, Neuigkeiten inkl.
  künftiger content-Spalte, Termine, Startseiten-Kacheln), ImagePaths-Extraktor
- Alle Uploads landen in der Mediathek (Seiten-Editor direkt, übrige über
  Beobachter beim Speichern); Daten-Migration und media:rebuild übernehmen
  bestehende Bilder
- Recht media.manage, Zugang media.use für alle Redaktionsbereiche
- /redaktion/mediathek (Suche, Filter, Upload mit Fortschritt, Details,
  Eingebunden in, Ersetzen, Löschen mit Warnung, Mehrfachauswahl),
  Abschnitt in der Redaktion und Menüpunkt im Admin-Bereich
- MediaPicker (Hochladen/Mediathek) im Pagebuilder: Bildfelder und
  Galerie (Mehrfachauswahl), editor.pickMedia im provide-API
- Bild-URLs mit ?v=Änderungszeit, null bei fehlender Datei; Modelle löschen
  geteilte Bilder nicht mehr selbst

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 20:05:50 +00:00

146 lines
7.3 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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);
});
// Bild aus der Mediathek: Alternativtext und Bildunterschrift übernehmen, wenn noch leer.
function fillFromMedia(item) {
const data = props.block.data;
if ('alt' in data && !data.alt && item.alt) data.alt = item.alt;
if ('caption' in data && !data.caption && item.caption) data.caption = item.caption;
}
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 })) },
{ key: 'exclude_role', label: 'Ausgeschlossene Rollen', hint: 'Sehen den Block nie – auch wenn oben etwas passt.', options: editor.audienceOptions.role },
].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"
@image-picked="fillFromMedia"
/>
<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>
<p v-if="group.hint" class="-mt-1 mb-1 text-[11px] text-muted-foreground">{{ group.hint }}</p>
<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>