|
|
|
@@ -11,6 +11,8 @@
|
|
|
|
|
use Filament\Forms\Components\Hidden;
|
|
|
|
|
use Filament\Forms\Components\Repeater;
|
|
|
|
|
use Filament\Forms\Components\Select;
|
|
|
|
|
use Filament\Forms\Components\TextInput;
|
|
|
|
|
use Filament\Forms\Components\Toggle;
|
|
|
|
|
use Filament\Forms\Components\ToggleButtons;
|
|
|
|
|
use Filament\Notifications\Notification;
|
|
|
|
|
use Filament\Schemas\Components\Group;
|
|
|
|
@@ -27,7 +29,7 @@
|
|
|
|
|
* Rasterverhältnis) → je Platz ein Widget (Builder mit höchstens einem Eintrag, Auswahl aus dem Widget-Register).
|
|
|
|
|
* Abschnittseinstellungen stehen im Abschnitt, Widget-Einstellungen im Widget-Dialog: eine Dialogebene.
|
|
|
|
|
*
|
|
|
|
|
* Formularzustand eines Abschnitts: {id, layout, style: {...}, slots: {uuid: {widget: {uuid: Builder-Eintrag}}}}.
|
|
|
|
|
* Formularzustand eines Abschnitts: {id, name, anchor, hidden, layout, style: {...}, slots: {uuid: {widget: {uuid: Builder-Eintrag}}}}.
|
|
|
|
|
*/
|
|
|
|
|
class SectionEditor
|
|
|
|
|
{
|
|
|
|
@@ -91,6 +93,7 @@ private static function sectionSchema(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
Hidden::make('id'),
|
|
|
|
|
self::labelSection(),
|
|
|
|
|
// Abschnittsgestaltung in drei Gruppen. Im Seiten-Arbeitsplatz nur im Kontext „Abschnitt gestalten“
|
|
|
|
|
// sichtbar und dort offen; beim Anlegen einer Seite an jedem Abschnitt, eingeklappt.
|
|
|
|
|
Section::make('Raster und Breite')
|
|
|
|
@@ -154,6 +157,67 @@ private static function sectionSchema(): array
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name, Sprungmarke und Sichtbarkeit: stehen im Seitenaufbau am Abschnitt, damit man sie beim Ordnen der Seite sieht.
|
|
|
|
|
*/
|
|
|
|
|
private static function labelSection(): Section
|
|
|
|
|
{
|
|
|
|
|
return Section::make('Name, Sprungmarke und Sichtbarkeit')
|
|
|
|
|
->columnSpanFull()
|
|
|
|
|
->compact()
|
|
|
|
|
->collapsible()
|
|
|
|
|
->collapsed(fn (Get $get): bool => blank($get('name')) && blank($get('anchor')) && ! $get('hidden'))
|
|
|
|
|
->extraAttributes(['class' => 'luf-abschnitt-bezeichnung'])
|
|
|
|
|
->schema([
|
|
|
|
|
TextInput::make('name')
|
|
|
|
|
->label('Name des Abschnitts')
|
|
|
|
|
->placeholder('Zum Beispiel „Kursübersicht“')
|
|
|
|
|
->maxLength(PageSections::MAX_NAME)
|
|
|
|
|
->live(onBlur: true)
|
|
|
|
|
->hintIcon('heroicon-m-information-circle', tooltip: 'Nur zur Orientierung im Seitenaufbau und in der Linkauswahl. Der Name erscheint nie auf der Website.')
|
|
|
|
|
->hintColor('gray'),
|
|
|
|
|
TextInput::make('anchor')
|
|
|
|
|
->label('Sprungmarke')
|
|
|
|
|
->prefix('#')
|
|
|
|
|
->placeholder('zum-beispiel-kurse')
|
|
|
|
|
->maxLength(PageSections::MAX_ANCHOR)
|
|
|
|
|
->live(onBlur: true)
|
|
|
|
|
->afterStateUpdated(function (?string $state, Set $set): void {
|
|
|
|
|
$set('anchor', filled($state) ? Str::slug($state, '-', 'de') : null);
|
|
|
|
|
})
|
|
|
|
|
->suffixAction(Action::make('anchorFromName')
|
|
|
|
|
->icon('heroicon-o-sparkles')
|
|
|
|
|
->tooltip('Aus dem Namen vorschlagen')
|
|
|
|
|
->action(fn (Get $get, Set $set) => $set('anchor', Str::limit(Str::slug((string) $get('name'), '-', 'de'), PageSections::MAX_ANCHOR, ''))))
|
|
|
|
|
->hintIcon('heroicon-m-information-circle', tooltip: 'Macht den Abschnitt zum Ziel eines Links. Auf derselben Seite genügt „#marke“, von anderen Seiten und von außen „Adresse der Seite#marke“. Nur Kleinbuchstaben, Ziffern und Bindestriche; jede Marke einmal je Seite.')
|
|
|
|
|
->hintColor('gray')
|
|
|
|
|
->helperText(fn (Get $get, $livewire): ?string => self::anchorLinkText($get('anchor'), $livewire)),
|
|
|
|
|
Toggle::make('hidden')
|
|
|
|
|
->label('Auf der Website ausblenden')
|
|
|
|
|
->live()
|
|
|
|
|
->hintIcon('heroicon-m-information-circle', tooltip: 'Der Abschnitt bleibt im Entwurf erhalten, erscheint aber nicht auf der Website. Auch eine Sprungmarke dieses Abschnitts führt dann ins Leere. In der Seitenvorschau steht an seiner Stelle ein Hinweis.')
|
|
|
|
|
->hintColor('gray')
|
|
|
|
|
->columnSpanFull(),
|
|
|
|
|
])
|
|
|
|
|
->columns(['default' => 1, 'md' => 2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vollständiger Link zur Sprungmarke (für Verweise von außen); eine neue Seite hat noch keine Adresse.
|
|
|
|
|
*/
|
|
|
|
|
private static function anchorLinkText(mixed $anchor, mixed $livewire): ?string
|
|
|
|
|
{
|
|
|
|
|
if (! is_string($anchor) || $anchor === '') {
|
|
|
|
|
return 'Ohne Sprungmarke ist der Abschnitt kein Linkziel.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = is_object($livewire) && property_exists($livewire, 'record') && is_object($livewire->record ?? null) ? ($livewire->record->path ?? null) : null;
|
|
|
|
|
|
|
|
|
|
return is_string($path) && $path !== ''
|
|
|
|
|
? 'Link von anderen Seiten: '.($path === '/' ? '' : $path).'#'.$anchor.' · von außen: '.url($path === '/' ? '/' : $path).'#'.$anchor
|
|
|
|
|
: 'Link auf dieser Seite: #'.$anchor.'. Die Adresse für Verweise von außen steht nach dem ersten Speichern fest.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function onWorkplace(mixed $livewire): bool
|
|
|
|
|
{
|
|
|
|
|
return is_object($livewire) && method_exists($livewire, 'openAbschnitt');
|
|
|
|
@@ -257,6 +321,9 @@ public static function toEditorState(array $sections): array
|
|
|
|
|
|
|
|
|
|
$state[] = [
|
|
|
|
|
'id' => $section['id'] ?? (string) Str::uuid(),
|
|
|
|
|
'name' => $section['name'] ?? null,
|
|
|
|
|
'anchor' => $section['anchor'] ?? null,
|
|
|
|
|
'hidden' => (bool) ($section['hidden'] ?? false),
|
|
|
|
|
'layout' => $section['layout'],
|
|
|
|
|
'style' => SectionStyle::fromStored($section['style'] ?? []),
|
|
|
|
|
'slots' => $slots,
|
|
|
|
@@ -289,6 +356,9 @@ public static function fromEditorState(?array $state): array
|
|
|
|
|
|
|
|
|
|
$sections[] = [
|
|
|
|
|
'id' => $section['id'] ?? null,
|
|
|
|
|
'name' => is_string($section['name'] ?? null) ? $section['name'] : null,
|
|
|
|
|
'anchor' => is_string($section['anchor'] ?? null) ? $section['anchor'] : null,
|
|
|
|
|
'hidden' => (bool) ($section['hidden'] ?? false),
|
|
|
|
|
'layout' => $section['layout'] ?? SectionLayouts::DEFAULT,
|
|
|
|
|
'style' => is_array($section['style'] ?? null) ? $section['style'] : [],
|
|
|
|
|
'slots' => $slots,
|
|
|
|
@@ -484,7 +554,12 @@ public static function insertCopyAfter(array $items, string $key, string $newKey
|
|
|
|
|
foreach ($items as $itemKey => $item) {
|
|
|
|
|
$result[$itemKey] = $item;
|
|
|
|
|
if ((string) $itemKey === $key) {
|
|
|
|
|
$result[$newKey] = $item;
|
|
|
|
|
// Eine Sprungmarke gibt es je Seite nur einmal: Die Kopie bekommt keine, der Name wird kenntlich gemacht.
|
|
|
|
|
$copy = is_array($item) ? $item : [];
|
|
|
|
|
$copy['anchor'] = null;
|
|
|
|
|
$name = is_string($copy['name'] ?? null) ? trim($copy['name']) : '';
|
|
|
|
|
$copy['name'] = $name !== '' ? Str::limit($name, PageSections::MAX_NAME - 9, '').' (Kopie)' : null;
|
|
|
|
|
$result[$newKey] = $copy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -562,13 +637,25 @@ private static function sectionLabel(array $state, ?int $index): HtmlString
|
|
|
|
|
$meta[] = 'noch leer';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = 'Abschnitt '.(($index ?? 0) + 1);
|
|
|
|
|
$number = 'Abschnitt '.(($index ?? 0) + 1);
|
|
|
|
|
$given = PageSections::cleanName($state['name'] ?? null);
|
|
|
|
|
$anchor = PageSections::cleanAnchor($state['anchor'] ?? null);
|
|
|
|
|
$hidden = (bool) ($state['hidden'] ?? false);
|
|
|
|
|
$full = 'Raster '.SectionLayouts::short($layout).' · '.SectionStyle::summary($style)
|
|
|
|
|
.($names === [] ? ' · noch leer' : ' · '.implode(', ', $names));
|
|
|
|
|
|
|
|
|
|
return new HtmlString('<span class="luf-abschnitt" title="'.e($full).'"><span class="luf-abschnitt-nr">'.e($name).'</span>'
|
|
|
|
|
// Der Name steht vorn; die Nummer bleibt als Orientierung daneben. Sprungmarke und „Ausgeblendet“ sind auch
|
|
|
|
|
// für Screenreader lesbar, die Nummer und die Rastermeta nicht doppelt.
|
|
|
|
|
$text = $given !== null ? $given : $number;
|
|
|
|
|
$badges = ($anchor !== null ? '<span class="luf-abschnitt-marke" title="Sprungmarke">#'.e($anchor).'</span>' : '')
|
|
|
|
|
.($hidden ? '<span class="luf-abschnitt-aus" title="Auf der Website ausgeblendet">Ausgeblendet</span>' : '');
|
|
|
|
|
$spoken = ($given !== null ? $number.': ' : '').($anchor !== null ? 'Sprungmarke '.$anchor.'. ' : '').($hidden ? 'Auf der Website ausgeblendet. ' : '').$full;
|
|
|
|
|
|
|
|
|
|
return new HtmlString('<span class="luf-abschnitt'.($hidden ? ' is-ausgeblendet' : '').'" title="'.e(($given !== null ? $number.' · ' : '').$full).'"><span class="luf-abschnitt-nr">'.e($text).'</span>'
|
|
|
|
|
.($given !== null ? '<span class="luf-abschnitt-nummer" aria-hidden="true">'.e($number).'</span>' : '')
|
|
|
|
|
.$badges
|
|
|
|
|
.'<span class="luf-abschnitt-meta" aria-hidden="true">'.e(implode(' · ', $meta)).'</span>'
|
|
|
|
|
.'<span class="vw-sr">: '.e($full).'</span></span>');
|
|
|
|
|
.'<span class="vw-sr">: '.e($spoken).'</span></span>');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|