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
27
resources/js/pagebuilder/BlockList.vue
Normal file
27
resources/js/pagebuilder/BlockList.vue
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script setup>
|
||||
import { inject } from 'vue';
|
||||
import { blockComponent } from './registry';
|
||||
|
||||
/**
|
||||
* Anzeige einer Blockliste. Container-Blöcke rendern ihre Bereiche mit der
|
||||
* Komponente aus inject('pagebuilder:list') – im Editor ist das die
|
||||
* bearbeitbare Liste, sonst diese hier.
|
||||
*/
|
||||
defineProps({
|
||||
item: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const types = inject('pagebuilder:types', {});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid gap-6">
|
||||
<template v-for="block in item.blocks" :key="block.id">
|
||||
<component
|
||||
:is="blockComponent(types[block.type]?.component ?? block.component ?? '')"
|
||||
v-if="blockComponent(types[block.type]?.component ?? block.component ?? '')"
|
||||
:block="block"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
27
resources/js/pagebuilder/PageContent.vue
Normal file
27
resources/js/pagebuilder/PageContent.vue
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script setup>
|
||||
import { computed, provide } from 'vue';
|
||||
import BlockList from './BlockList.vue';
|
||||
|
||||
/**
|
||||
* Anzeigefertiger Seiteninhalt (siehe App\Pagebuilder\Content::render).
|
||||
* Die Blöcke reagieren auf die Breite dieses Bereichs (Container Queries) –
|
||||
* so stimmt auch die Geräte-Vorschau im Editor.
|
||||
*/
|
||||
const props = defineProps({
|
||||
content: { type: Object, required: true },
|
||||
types: { type: Object, default: null },
|
||||
});
|
||||
|
||||
provide('pagebuilder:list', BlockList);
|
||||
provide('pagebuilder:editing', false);
|
||||
provide('pagebuilder:types', props.types ?? {});
|
||||
|
||||
const root = computed(() => ({ blocks: props.content.blocks ?? [] }));
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<div class="@container">
|
||||
<BlockList :item="root" />
|
||||
</div>
|
||||
</template>
|
||||
42
resources/js/pagebuilder/blocks/Accordion.vue
Normal file
42
resources/js/pagebuilder/blocks/Accordion.vue
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
import { AccordionContent, AccordionHeader, AccordionItem, AccordionRoot, AccordionTrigger } from 'reka-ui';
|
||||
import { ChevronDown } from '@lucide/vue';
|
||||
|
||||
const props = defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const List = inject('pagebuilder:list');
|
||||
const editing = inject('pagebuilder:editing', false);
|
||||
|
||||
const initial = computed(() => {
|
||||
const first = props.block.items[0]?.id;
|
||||
|
||||
if (props.block.data.multiple) return props.block.data.first_open && first ? [first] : [];
|
||||
|
||||
return props.block.data.first_open ? first : undefined;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AccordionRoot
|
||||
:key="`${block.data.multiple}-${editing}`"
|
||||
:type="block.data.multiple ? 'multiple' : 'single'"
|
||||
:default-value="initial"
|
||||
collapsible
|
||||
class="divide-y rounded-lg border bg-card"
|
||||
>
|
||||
<AccordionItem v-for="(item, index) in block.items" :key="item.id" :value="item.id">
|
||||
<AccordionHeader as="h3">
|
||||
<AccordionTrigger class="group flex w-full items-center justify-between gap-4 px-5 py-4 text-left text-[15px] font-medium hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/30">
|
||||
{{ item.title || `Abschnitt ${index + 1}` }}
|
||||
<ChevronDown class="size-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" />
|
||||
</AccordionTrigger>
|
||||
</AccordionHeader>
|
||||
<AccordionContent class="overflow-hidden data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down">
|
||||
<div class="px-5 pt-1 pb-5">
|
||||
<component :is="List" :item="item" />
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</AccordionRoot>
|
||||
</template>
|
||||
27
resources/js/pagebuilder/blocks/Box.vue
Normal file
27
resources/js/pagebuilder/blocks/Box.vue
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script setup>
|
||||
import { inject } from 'vue';
|
||||
import { CircleAlert, CircleCheck, Info, Lightbulb, Star, TriangleAlert } from '@lucide/vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const List = inject('pagebuilder:list');
|
||||
|
||||
const variants = {
|
||||
info: { icon: Info, class: 'border-sky-200 bg-sky-50 text-sky-950 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-100', iconClass: 'text-sky-600 dark:text-sky-400' },
|
||||
note: { icon: Lightbulb, class: 'border-amber-200 bg-amber-50 text-amber-950 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-100', iconClass: 'text-amber-600 dark:text-amber-400' },
|
||||
warning: { icon: TriangleAlert, class: 'border-red-200 bg-red-50 text-red-950 dark:border-red-900 dark:bg-red-950/40 dark:text-red-100', iconClass: 'text-red-600 dark:text-red-400' },
|
||||
success: { icon: CircleCheck, class: 'border-emerald-200 bg-emerald-50 text-emerald-950 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-100', iconClass: 'text-emerald-600 dark:text-emerald-400' },
|
||||
neutral: { icon: CircleAlert, class: 'border-border bg-muted text-foreground', iconClass: 'text-muted-foreground' },
|
||||
highlight: { icon: Star, class: 'border-brand-200 bg-brand-soft text-foreground', iconClass: 'text-brand-text' },
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="pb-box flex gap-3 rounded-lg border p-4 @xl:p-5" :class="variants[block.data.variant]?.class" :role="block.data.variant === 'warning' ? 'alert' : 'note'">
|
||||
<component :is="variants[block.data.variant]?.icon" v-if="block.data.show_icon" class="mt-0.5 size-5 shrink-0" :class="variants[block.data.variant]?.iconClass" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<p v-if="block.data.title" class="mb-2 font-semibold">{{ block.data.title }}</p>
|
||||
<component :is="List" :item="block.items[0]" />
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
20
resources/js/pagebuilder/blocks/Buttons.vue
Normal file
20
resources/js/pagebuilder/blocks/Buttons.vue
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<script setup>
|
||||
import { ArrowUpRight } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const variants = { primary: 'default', outline: 'outline', link: 'link' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-3" :class="{ 'justify-center': block.data.align === 'center' }">
|
||||
<Button v-for="(button, index) in block.data.buttons" :key="index" :variant="variants[button.variant] ?? 'default'" as-child>
|
||||
<a :href="button.url || '#'" :target="button.new_tab ? '_blank' : undefined" :rel="button.new_tab ? 'noopener' : undefined">
|
||||
{{ button.label || 'Schaltfläche' }}
|
||||
<ArrowUpRight v-if="button.new_tab" />
|
||||
</a>
|
||||
</Button>
|
||||
<p v-if="!block.data.buttons.length" class="text-sm text-muted-foreground">Noch keine Schaltflächen.</p>
|
||||
</div>
|
||||
</template>
|
||||
26
resources/js/pagebuilder/blocks/Columns.vue
Normal file
26
resources/js/pagebuilder/blocks/Columns.vue
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
|
||||
const props = defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const List = inject('pagebuilder:list');
|
||||
|
||||
// Umbruchpunkt als Container Query: die Spalten richten sich nach der Breite des Inhaltsbereichs.
|
||||
const stack = { sm: '@xl:grid-cols-(--cols)', md: '@3xl:grid-cols-(--cols)', lg: '@5xl:grid-cols-(--cols)' };
|
||||
const gaps = { small: 'gap-3', normal: 'gap-6', large: 'gap-10' };
|
||||
const aligns = { start: 'items-start', center: 'items-center', stretch: 'items-stretch' };
|
||||
|
||||
const columns = computed(() => (props.block.data.layout ?? '1-1').split('-').map((part) => `${part}fr`).join(' '));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="grid grid-cols-1"
|
||||
:class="[stack[block.data.stack] ?? stack.md, gaps[block.data.gap] ?? gaps.normal, aligns[block.data.align] ?? aligns.start]"
|
||||
:style="{ '--cols': columns }"
|
||||
>
|
||||
<div v-for="item in block.items" :key="item.id" class="min-w-0">
|
||||
<component :is="List" :item="item" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
32
resources/js/pagebuilder/blocks/Contacts.vue
Normal file
32
resources/js/pagebuilder/blocks/Contacts.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Mail, Phone } from '@lucide/vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h3 v-if="block.data.title" class="mb-3 text-lg font-semibold">{{ block.data.title }}</h3>
|
||||
<div :class="block.data.layout === 'list' ? 'divide-y rounded-lg border bg-card' : 'grid gap-4 @xl:grid-cols-2 @4xl:grid-cols-3'">
|
||||
<div
|
||||
v-for="person in block.props?.people ?? []"
|
||||
:key="person.id"
|
||||
class="flex gap-3"
|
||||
:class="block.data.layout === 'list' ? 'items-center px-4 py-3' : 'rounded-lg border bg-card p-4'"
|
||||
>
|
||||
<PersonAvatar :person="person" class="size-12 shrink-0" />
|
||||
<div class="min-w-0">
|
||||
<Link :href="`/personen/${person.id}`" class="block truncate font-semibold hover:underline">{{ person.name }}</Link>
|
||||
<p v-if="person.job_title" class="truncate text-[13px] text-muted-foreground">{{ person.job_title }}</p>
|
||||
<div class="mt-1.5 flex flex-wrap gap-x-4 gap-y-1 text-[13px]">
|
||||
<a v-if="person.phone" :href="`tel:${person.phone}`" class="inline-flex items-center gap-1 text-brand-text hover:underline"><Phone class="size-3.5" /> {{ person.phone }}</a>
|
||||
<a :href="`mailto:${person.email}`" class="inline-flex min-w-0 items-center gap-1 text-brand-text hover:underline"><Mail class="size-3.5 shrink-0" /> <span class="truncate">{{ person.email }}</span></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="!(block.props?.people ?? []).length" class="text-sm text-muted-foreground">Noch keine Personen ausgewählt.</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
3
resources/js/pagebuilder/blocks/Divider.vue
Normal file
3
resources/js/pagebuilder/blocks/Divider.vue
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<template>
|
||||
<hr class="border-border" />
|
||||
</template>
|
||||
32
resources/js/pagebuilder/blocks/Gallery.vue
Normal file
32
resources/js/pagebuilder/blocks/Gallery.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { ImageIcon } from '@lucide/vue';
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
|
||||
|
||||
const props = defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const columns = { 2: '@xl:grid-cols-2', 3: '@xl:grid-cols-2 @3xl:grid-cols-3', 4: '@xl:grid-cols-3 @3xl:grid-cols-4' };
|
||||
const images = computed(() => props.block.data.images.map((image, index) => ({ ...image, url: props.block.props?.urls?.[index] ?? null })));
|
||||
const open = ref(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-2 gap-3" :class="columns[block.data.columns]">
|
||||
<figure v-for="(image, index) in images" :key="index">
|
||||
<button v-if="image.url" type="button" class="block w-full overflow-hidden rounded-lg focus-visible:ring-3 focus-visible:ring-ring/40 focus-visible:outline-none" @click="open = image">
|
||||
<img :src="image.url" :alt="image.alt" loading="lazy" class="aspect-[4/3] w-full object-cover transition-transform hover:scale-[1.02]" />
|
||||
</button>
|
||||
<div v-else class="grid aspect-[4/3] place-items-center rounded-lg border border-dashed bg-muted text-muted-foreground"><ImageIcon class="size-6" /></div>
|
||||
<figcaption v-if="image.caption" class="mt-1.5 text-xs text-muted-foreground">{{ image.caption }}</figcaption>
|
||||
</figure>
|
||||
<p v-if="!images.length" class="col-span-full text-sm text-muted-foreground">Noch keine Bilder.</p>
|
||||
</div>
|
||||
|
||||
<Dialog :open="!!open" @update:open="(value) => !value && (open = null)">
|
||||
<DialogContent class="max-w-5xl p-2 sm:max-w-5xl">
|
||||
<DialogTitle class="sr-only">{{ open?.alt || 'Bild' }}</DialogTitle>
|
||||
<img v-if="open" :src="open.url" :alt="open.alt" class="max-h-[80vh] w-full rounded-md object-contain" />
|
||||
<p v-if="open?.caption" class="px-2 pb-1 text-sm text-muted-foreground">{{ open.caption }}</p>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
28
resources/js/pagebuilder/blocks/Heading.vue
Normal file
28
resources/js/pagebuilder/blocks/Heading.vue
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<script setup>
|
||||
import { inject } from 'vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const editing = inject('pagebuilder:editing', false);
|
||||
|
||||
const sizes = {
|
||||
2: 'text-2xl font-semibold tracking-tight',
|
||||
3: 'text-xl font-semibold tracking-tight',
|
||||
4: 'text-base font-semibold',
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<input
|
||||
v-if="editing"
|
||||
v-model="block.data.text"
|
||||
class="w-full bg-transparent outline-none placeholder:text-muted-foreground/60"
|
||||
:class="[sizes[block.data.level], block.data.align === 'center' ? 'text-center' : '']"
|
||||
placeholder="Überschrift"
|
||||
maxlength="200"
|
||||
aria-label="Überschrift"
|
||||
/>
|
||||
<component :is="`h${block.data.level}`" v-else-if="block.data.text" :class="[sizes[block.data.level], block.data.align === 'center' ? 'text-center' : '']">
|
||||
{{ block.data.text }}
|
||||
</component>
|
||||
</template>
|
||||
21
resources/js/pagebuilder/blocks/Hero.vue
Normal file
21
resources/js/pagebuilder/blocks/Hero.vue
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<script setup>
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const heights = { small: 'min-h-48', medium: 'min-h-72', large: 'min-h-96' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="relative flex items-end overflow-hidden rounded-lg bg-brand text-white" :class="heights[block.data.height]">
|
||||
<img v-if="block.props?.url" :src="block.props.url" alt="" class="absolute inset-0 size-full object-cover" />
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent" />
|
||||
<div class="relative max-w-2xl p-6 @3xl:p-10">
|
||||
<h2 v-if="block.data.title" class="text-2xl font-semibold tracking-tight @3xl:text-3xl">{{ block.data.title }}</h2>
|
||||
<p v-if="block.data.text" class="mt-2 text-[15px] leading-relaxed text-white/90 @3xl:text-base">{{ block.data.text }}</p>
|
||||
<Button v-if="block.data.button_label && block.data.button_url" as-child class="mt-5 bg-white text-neutral-900 hover:bg-white/90">
|
||||
<a :href="block.data.button_url">{{ block.data.button_label }}</a>
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
27
resources/js/pagebuilder/blocks/IconList.vue
Normal file
27
resources/js/pagebuilder/blocks/IconList.vue
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script setup>
|
||||
import { Link as LinkIcon } from '@lucide/vue';
|
||||
import { quickLinkIcons } from '@/lib/icons';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul :class="block.data.layout === 'grid' ? 'grid gap-4 @xl:grid-cols-2 @4xl:grid-cols-3' : 'grid gap-4'">
|
||||
<li v-for="(item, index) in block.data.items" :key="index">
|
||||
<component
|
||||
:is="item.url ? 'a' : 'div'"
|
||||
:href="item.url || undefined"
|
||||
class="flex gap-4"
|
||||
:class="[block.data.layout === 'grid' ? 'h-full rounded-lg border bg-card p-4' : '', item.url ? 'group' : '']"
|
||||
>
|
||||
<span class="grid size-10 shrink-0 place-items-center rounded-lg bg-brand-soft text-brand-text">
|
||||
<component :is="quickLinkIcons[item.icon] ?? LinkIcon" class="size-5" />
|
||||
</span>
|
||||
<span class="min-w-0">
|
||||
<span class="block font-medium" :class="{ 'group-hover:underline': item.url }">{{ item.title }}</span>
|
||||
<span v-if="item.text" class="mt-0.5 block text-sm leading-relaxed whitespace-pre-line text-muted-foreground">{{ item.text }}</span>
|
||||
</span>
|
||||
</component>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
19
resources/js/pagebuilder/blocks/Image.vue
Normal file
19
resources/js/pagebuilder/blocks/Image.vue
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<script setup>
|
||||
import { ImageIcon } from '@lucide/vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const sizes = { full: 'w-full', medium: 'mx-auto w-full @3xl:w-2/3', small: 'mx-auto w-full @xl:w-1/2 @3xl:w-1/3' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<figure :class="sizes[block.data.size]">
|
||||
<component :is="block.data.url ? 'a' : 'div'" v-if="block.props?.url" :href="block.data.url || undefined">
|
||||
<img :src="block.props.url" :alt="block.data.alt" loading="lazy" class="w-full rounded-lg" />
|
||||
</component>
|
||||
<div v-else class="grid aspect-video place-items-center rounded-lg border border-dashed bg-muted text-muted-foreground">
|
||||
<ImageIcon class="size-8" />
|
||||
</div>
|
||||
<figcaption v-if="block.data.caption" class="mt-2 text-sm text-muted-foreground">{{ block.data.caption }}</figcaption>
|
||||
</figure>
|
||||
</template>
|
||||
10
resources/js/pagebuilder/blocks/Quote.vue
Normal file
10
resources/js/pagebuilder/blocks/Quote.vue
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<script setup>
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<figure class="border-l-4 border-brand-300 py-1 pl-5">
|
||||
<blockquote class="text-lg leading-relaxed whitespace-pre-line">{{ block.data.text || 'Zitat' }}</blockquote>
|
||||
<figcaption v-if="block.data.source" class="mt-2 text-sm text-muted-foreground">– {{ block.data.source }}</figcaption>
|
||||
</figure>
|
||||
</template>
|
||||
22
resources/js/pagebuilder/blocks/Section.vue
Normal file
22
resources/js/pagebuilder/blocks/Section.vue
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<script setup>
|
||||
import { inject } from 'vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const List = inject('pagebuilder:list');
|
||||
|
||||
const backgrounds = {
|
||||
none: '',
|
||||
muted: 'bg-muted',
|
||||
card: 'bg-card border',
|
||||
'brand-soft': 'bg-brand-soft',
|
||||
brand: 'bg-brand text-brand-foreground [&_.prose]:text-brand-foreground [&_a]:text-brand-foreground',
|
||||
};
|
||||
const paddings = { none: '', normal: 'p-5 @3xl:p-8', large: 'p-8 @3xl:p-12' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="rounded-lg" :class="[backgrounds[block.data.background], paddings[block.data.padding]]">
|
||||
<component :is="List" :item="block.items[0]" />
|
||||
</section>
|
||||
</template>
|
||||
9
resources/js/pagebuilder/blocks/Spacer.vue
Normal file
9
resources/js/pagebuilder/blocks/Spacer.vue
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<script setup>
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const sizes = { small: 'h-2', medium: 'h-8', large: 'h-16' };
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="sizes[block.data.size]" aria-hidden="true" />
|
||||
</template>
|
||||
26
resources/js/pagebuilder/blocks/Table.vue
Normal file
26
resources/js/pagebuilder/blocks/Table.vue
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
|
||||
const props = defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const head = computed(() => (props.block.data.header ? props.block.data.rows[0] ?? [] : null));
|
||||
const body = computed(() => (props.block.data.header ? props.block.data.rows.slice(1) : props.block.data.rows));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<figure class="overflow-x-auto rounded-lg border bg-card">
|
||||
<table class="w-full text-left text-sm">
|
||||
<thead v-if="head" class="bg-muted/60">
|
||||
<tr>
|
||||
<th v-for="(cell, index) in head" :key="index" class="px-4 py-2.5 font-semibold whitespace-pre-line">{{ cell }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y">
|
||||
<tr v-for="(row, rowIndex) in body" :key="rowIndex">
|
||||
<td v-for="(cell, index) in row" :key="index" class="px-4 py-2.5 align-top whitespace-pre-line">{{ cell }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<figcaption v-if="block.data.caption" class="border-t px-4 py-2 text-xs text-muted-foreground">{{ block.data.caption }}</figcaption>
|
||||
</figure>
|
||||
</template>
|
||||
32
resources/js/pagebuilder/blocks/Tabs.vue
Normal file
32
resources/js/pagebuilder/blocks/Tabs.vue
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<script setup>
|
||||
import { inject, ref, watch } from 'vue';
|
||||
import { TabsContent, TabsList, TabsRoot, TabsTrigger } from 'reka-ui';
|
||||
|
||||
const props = defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const List = inject('pagebuilder:list');
|
||||
const active = ref(props.block.items[0]?.id);
|
||||
|
||||
// Im Editor können Tabs entfernt werden – dann den ersten zeigen.
|
||||
watch(() => props.block.items.map((item) => item.id), (ids) => {
|
||||
if (!ids.includes(active.value)) active.value = ids[0];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TabsRoot v-model="active">
|
||||
<TabsList class="-mb-px flex gap-1 overflow-x-auto border-b" aria-label="Reiter">
|
||||
<TabsTrigger
|
||||
v-for="(item, index) in block.items"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
class="relative shrink-0 px-4 py-2.5 text-sm font-medium whitespace-nowrap text-muted-foreground transition-colors hover:text-foreground data-[state=active]:text-foreground data-[state=active]:after:absolute data-[state=active]:after:inset-x-2 data-[state=active]:after:bottom-0 data-[state=active]:after:h-[3px] data-[state=active]:after:rounded-t-full data-[state=active]:after:bg-brand"
|
||||
>
|
||||
{{ item.title || `Tab ${index + 1}` }}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent v-for="item in block.items" :key="item.id" :value="item.id" class="pt-5 focus-visible:outline-none">
|
||||
<component :is="List" :item="item" />
|
||||
</TabsContent>
|
||||
</TabsRoot>
|
||||
</template>
|
||||
15
resources/js/pagebuilder/blocks/Text.vue
Normal file
15
resources/js/pagebuilder/blocks/Text.vue
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<script setup>
|
||||
import { defineAsyncComponent, inject } from 'vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
const editing = inject('pagebuilder:editing', false);
|
||||
|
||||
// Der Editor (TipTap) wird nur im Pagebuilder geladen, nicht beim Lesen.
|
||||
const RichTextEditor = defineAsyncComponent(() => import('@/components/RichTextEditor.vue'));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RichTextEditor v-if="editing" v-model="block.data.html" placeholder="Text eingeben …" />
|
||||
<div v-else class="prose prose-neutral max-w-none prose-headings:tracking-tight prose-img:rounded-lg" v-html="block.data.html" />
|
||||
</template>
|
||||
35
resources/js/pagebuilder/blocks/Video.vue
Normal file
35
resources/js/pagebuilder/blocks/Video.vue
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { Play, Video as VideoIcon } from '@lucide/vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
|
||||
// Externe Videos erst nach Klick laden – vorher gehen keine Daten an YouTube oder Vimeo.
|
||||
const loaded = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<figure>
|
||||
<div class="relative aspect-video overflow-hidden rounded-lg bg-neutral-900">
|
||||
<template v-if="block.props?.embed">
|
||||
<video v-if="block.props.embed.provider === 'file'" :src="block.props.embed.src" controls preload="metadata" class="size-full" />
|
||||
<iframe
|
||||
v-else-if="loaded"
|
||||
:src="`${block.props.embed.src}&autoplay=1`"
|
||||
:title="block.data.title || 'Video'"
|
||||
class="size-full"
|
||||
allow="autoplay; fullscreen; picture-in-picture"
|
||||
allowfullscreen
|
||||
/>
|
||||
<button v-else type="button" class="grid size-full place-items-center text-white" @click="loaded = true">
|
||||
<span class="grid justify-items-center gap-3 px-6 text-center">
|
||||
<span class="grid size-16 place-items-center rounded-full bg-white/15 transition-colors hover:bg-white/25"><Play class="size-7 fill-current" /></span>
|
||||
<span class="font-medium">{{ block.data.title || 'Video abspielen' }}</span>
|
||||
<span class="max-w-md text-xs text-white/70">Beim Abspielen wird das Video von {{ block.props.embed.provider }} geladen. Dabei werden Daten an {{ block.props.embed.provider }} übertragen.</span>
|
||||
</span>
|
||||
</button>
|
||||
</template>
|
||||
<div v-else class="grid size-full place-items-center text-white/60"><VideoIcon class="size-8" /></div>
|
||||
</div>
|
||||
</figure>
|
||||
</template>
|
||||
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);
|
||||
}
|
||||
}
|
||||
24
resources/js/pagebuilder/registry.js
Normal file
24
resources/js/pagebuilder/registry.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
|
||||
/**
|
||||
* Vue-Komponenten der Pagebuilder-Blöcke: „Name“ aus resources/js/pagebuilder/blocks,
|
||||
* „<plugin>::Name“ aus plugins-core/<plugin>/resources/js/blocks.
|
||||
* Komponente und Blockart kommen aus der Registry App\Pagebuilder\Blocks.
|
||||
*/
|
||||
const core = import.meta.glob('./blocks/*.vue');
|
||||
const plugins = import.meta.glob('../../../plugins-core/*/resources/js/blocks/*.vue');
|
||||
|
||||
const components = {};
|
||||
|
||||
for (const [path, loader] of Object.entries(core)) {
|
||||
components[path.split('/').pop().replace('.vue', '')] = defineAsyncComponent(loader);
|
||||
}
|
||||
|
||||
for (const [path, loader] of Object.entries(plugins)) {
|
||||
const [, slug] = path.match(/plugins-core\/([^/]+)\//);
|
||||
components[`${slug}::${path.split('/').pop().replace('.vue', '')}`] = defineAsyncComponent(loader);
|
||||
}
|
||||
|
||||
export function blockComponent(name) {
|
||||
return components[name] ?? null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue