Vereinfache die Abschnittsabstände auf oben, unten und Widget-Abstand.
Die Abschnittshülle Version 2 kennt genau drei unabhängige Abstände mit denselben Stufen (Kein Abstand, Kompakt, Normal, Großzügig): - spacing_top / spacing_bottom: Innenabstand des Abschnitts; zwischen zwei Abschnitten addieren sich unten und oben (0 + 0 = 0). - gap: Abstand zwischen den Plätzen des Rasters, nebeneinander und gestapelt. Widget-Innenabstände bleiben im Widget. Entfallen sind „Abstand oben und unten“, die Abweichung „Abstand oben“ (same/small/none), die versteckte Regel, die oben zwischen zwei Abschnitten ohne Fläche auf null setzte, und der Trenner „Zusätzlicher Abstand“. Hüllen der Version 1 werden beim Lesen ohne Layoutänderung übersetzt (SectionStyle::migrateSpacing); gespeicherte Revisionen bleiben. Einzige Abweichung: „Gering“ hat keine eigene Stufe mehr und wird „Kompakt“. Tests bewusst angepasst (Hüllenversion 2, neue Klassen, Prüfung freier Werte über die neuen Schlüssel); neue Tests für Addition, Vorgaben und die Übersetzung aller Fälle der Version 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f4d225d0b2
commit
f511ad10de
10 files changed
+238
-94
No files matched your search
@@ -11,14 +11,17 @@
|
||||
* Abschnitts- und Slotmodell einer Seite: Seite → Abschnitte → Slots → Widget-Instanzen.
|
||||
*
|
||||
* Gespeicherte Hülle eines Abschnitts (Version 1):
|
||||
* {id, v, layout, style: {background, image, focus, overlay, width, spacing, spacing_top, divider}, slots: [Widget-Hülle|null, …]}
|
||||
* {id, v, layout, style: {background, image, focus, overlay, width, spacing_top, spacing_bottom, gap, divider}, slots: [Widget-Hülle|null, …]}
|
||||
*
|
||||
* Version 2 (Abstände): oben, unten und Widget-Abstand sind drei unabhängige Werte. Hüllen der Version 1 werden beim
|
||||
* Lesen übersetzt (SectionStyle::migrateSpacing), ohne die Darstellung zu ändern; gespeicherte Revisionen bleiben.
|
||||
*
|
||||
* Jeder Slot enthält höchstens ein Widget aus dem zentralen Widget-Register. Abschnitte sind nicht verschachtelbar.
|
||||
* Revisionen ohne Abschnitte (Bestand vor dieser Fassung) werden beim Lesen als einspaltige Abschnitte gelesen.
|
||||
*/
|
||||
class PageSections
|
||||
{
|
||||
public const VERSION = 1;
|
||||
public const VERSION = 2;
|
||||
|
||||
public const MAX_SECTIONS = 30;
|
||||
|
||||
@@ -41,10 +44,8 @@ public function read(?array $sections, ?array $blocks = null): array
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach (array_values($sections) as $section) {
|
||||
if (is_array($section)) {
|
||||
$result[] = $this->upcastSection($section);
|
||||
}
|
||||
foreach (SectionStyle::migrateSpacing(array_values(array_filter($sections, 'is_array')), byVersion: true) as $section) {
|
||||
$result[] = $this->upcastSection($section);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -74,6 +75,12 @@ public function normalize(array $content): array
|
||||
$seenWidgetIds = [];
|
||||
$widgetCount = 0;
|
||||
|
||||
// Eingaben mit Abständen der Version 1 (zum Beispiel ältere Aufrufer) werden wie beim Lesen übersetzt.
|
||||
$migrated = SectionStyle::migrateSpacing(array_map(
|
||||
fn ($item) => is_array($item) && array_key_exists('slots', $item) ? $item : ['style' => [], 'slots' => [$item]],
|
||||
$items,
|
||||
));
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
if (! is_array($item)) {
|
||||
$errors["sections.$index"] = ['Ein Abschnitt ist unvollständig.'];
|
||||
@@ -83,6 +90,8 @@ public function normalize(array $content): array
|
||||
|
||||
if (! array_key_exists('slots', $item)) {
|
||||
$item = ['id' => null, 'layout' => SectionLayouts::DEFAULT, 'style' => [], 'slots' => [$item]];
|
||||
} else {
|
||||
$item['style'] = $migrated[$index]['style'] ?? ($item['style'] ?? []);
|
||||
}
|
||||
|
||||
$sections[] = $this->normalizeSection($item, $index, $errors, $seenSectionIds, $seenWidgetIds, $widgetCount);
|
||||
@@ -164,13 +173,14 @@ private function wrapWidgets(array $blocks): array
|
||||
{
|
||||
$sections = [];
|
||||
|
||||
foreach ($this->widgets->read($blocks) as $widget) {
|
||||
foreach ($this->widgets->read($blocks) as $position => $widget) {
|
||||
$sections[] = [
|
||||
'id' => null,
|
||||
'v' => self::VERSION,
|
||||
'layout' => SectionLayouts::DEFAULT,
|
||||
// Bestand vor dem Raster stand in einem durchgehenden Blatt: kompakte Abstände kommen dem am nächsten.
|
||||
'style' => ['spacing' => 'compact'] + SectionStyle::DEFAULTS,
|
||||
// Bestand vor dem Raster stand in einem durchgehenden Blatt: kompakte Abstände, zwischen den Widgets
|
||||
// nur einmal (oben kein Abstand ab dem zweiten), wie bisher.
|
||||
'style' => ['spacing_top' => $position === 0 ? 'compact' : 'none', 'spacing_bottom' => 'compact', 'gap' => 'normal'] + SectionStyle::DEFAULTS,
|
||||
'slots' => [$widget],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -81,8 +81,9 @@ private function renderSection(array $section, array $cells, int $index): string
|
||||
'page-section',
|
||||
'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])),
|
||||
'section-width-'.$style['width'],
|
||||
'section-space-'.$style['spacing'],
|
||||
...($style['spacing_top'] !== 'same' ? ['section-space-top-'.$style['spacing_top']] : []),
|
||||
'section-space-top-'.$style['spacing_top'],
|
||||
'section-space-bottom-'.$style['spacing_bottom'],
|
||||
'section-gap-'.$style['gap'],
|
||||
'section-layout-'.str_replace('_', '-', $section['layout']),
|
||||
];
|
||||
|
||||
@@ -102,10 +103,6 @@ private function renderSection(array $section, array $cells, int $index): string
|
||||
$classes[] = $scope;
|
||||
}
|
||||
|
||||
if ($style['divider'] === 'space') {
|
||||
$classes[] = 'section-divider-space';
|
||||
}
|
||||
|
||||
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
|
||||
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domain\Cms\Sections;
|
||||
|
||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||
|
||||
/**
|
||||
* Semantische Abschnittsgestaltung. Jeder Wert ist eine Aufzählung, die auf zentrale Design-Tokens
|
||||
* abgebildet wird (resources/css/app.css, Abschnitt „Abschnitte“). Keine freie CSS- oder Farbangabe.
|
||||
@@ -25,29 +27,27 @@ final class SectionStyle
|
||||
'full' => 'Vollbreite',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
/**
|
||||
* Gemeinsame Stufen der drei Abstände eines Abschnitts (Hülle Version 2):
|
||||
* - spacing_top: Abstand vor dem Inhalt (oben),
|
||||
* - spacing_bottom: Abstand nach dem Inhalt (unten),
|
||||
* - gap: Abstand zwischen den Plätzen im Abschnittsraster, nebeneinander und gestapelt.
|
||||
* Zwischen zwei Abschnitten addieren sich „unten“ des ersten und „oben“ des zweiten; es gibt keine weitere
|
||||
* versteckte Vorgabe. Liegt eine eigene Fläche (Hintergrund) vor, liegen oben und unten innerhalb dieser Fläche.
|
||||
* Werte: resources/css/tokens.css (--section-space-*, --section-gap-*).
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const SPACINGS = [
|
||||
'none' => 'Kein Abstand',
|
||||
'compact' => 'Kompakt',
|
||||
'normal' => 'Normal',
|
||||
'large' => 'Großzügig',
|
||||
];
|
||||
|
||||
/**
|
||||
* Abweichender Abstand oben, zum Beispiel damit ein Einstieg direkt unter der Kopfzeile beginnt.
|
||||
* Ergänzt „Abstand oben und unten“, ersetzt ihn nicht; der Abstand unten bleibt unverändert.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const SPACINGS_TOP = [
|
||||
'same' => 'Wie „Abstand oben und unten“',
|
||||
'small' => 'Gering',
|
||||
'none' => 'Kein Abstand',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
public const DIVIDERS = [
|
||||
'none' => 'Kein Trenner',
|
||||
'space' => 'Zusätzlicher Abstand',
|
||||
'line' => 'Dezente Linie',
|
||||
'accent' => 'Markenakzent',
|
||||
];
|
||||
@@ -91,8 +91,9 @@ final class SectionStyle
|
||||
'focus' => 'center',
|
||||
'overlay' => 'light',
|
||||
'width' => 'standard',
|
||||
'spacing' => 'normal',
|
||||
'spacing_top' => 'same',
|
||||
'spacing_top' => 'compact',
|
||||
'spacing_bottom' => 'compact',
|
||||
'gap' => 'normal',
|
||||
'divider' => 'none',
|
||||
];
|
||||
|
||||
@@ -108,8 +109,9 @@ public static function enums(): array
|
||||
'focus' => self::FOCUS,
|
||||
'overlay' => self::OVERLAYS,
|
||||
'width' => self::WIDTHS,
|
||||
'spacing' => self::SPACINGS,
|
||||
'spacing_top' => self::SPACINGS_TOP,
|
||||
'spacing_top' => self::SPACINGS,
|
||||
'spacing_bottom' => self::SPACINGS,
|
||||
'gap' => self::SPACINGS,
|
||||
'divider' => self::DIVIDERS,
|
||||
];
|
||||
}
|
||||
@@ -118,7 +120,7 @@ public static function enums(): array
|
||||
* Lesepfad: gespeicherte Werte; Unbekanntes fällt auf die Vorgabe zurück, damit alte oder fremde Daten
|
||||
* nie eine Seite brechen.
|
||||
*
|
||||
* @return array{background: string, image: ?string, focus: string, overlay: string, width: string, spacing: string, spacing_top: string, divider: string}
|
||||
* @return array{background: string, image: ?string, focus: string, overlay: string, width: string, spacing_top: string, spacing_bottom: string, gap: string, divider: string}
|
||||
*/
|
||||
public static function fromStored(mixed $style): array
|
||||
{
|
||||
@@ -151,12 +153,13 @@ public static function summary(array $style): string
|
||||
$parts[] = self::WIDTHS[$style['width']];
|
||||
}
|
||||
|
||||
if ($style['spacing'] !== 'normal') {
|
||||
$parts[] = 'Abstand '.mb_strtolower(self::SPACINGS[$style['spacing']]);
|
||||
if ($style['spacing_top'] !== self::DEFAULTS['spacing_top'] || $style['spacing_bottom'] !== self::DEFAULTS['spacing_bottom']) {
|
||||
$parts[] = 'Abstand oben '.mb_strtolower(self::SPACINGS[$style['spacing_top']])
|
||||
.', unten '.mb_strtolower(self::SPACINGS[$style['spacing_bottom']]);
|
||||
}
|
||||
|
||||
if ($style['spacing_top'] !== 'same') {
|
||||
$parts[] = 'oben '.mb_strtolower(self::SPACINGS_TOP[$style['spacing_top']]);
|
||||
if ($style['gap'] !== 'normal') {
|
||||
$parts[] = 'Widget-Abstand '.mb_strtolower(self::SPACINGS[$style['gap']]);
|
||||
}
|
||||
|
||||
if ($style['divider'] !== 'none') {
|
||||
@@ -165,4 +168,77 @@ public static function summary(array $style): string
|
||||
|
||||
return implode(' · ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob eine gespeicherte Gestaltung noch die Abstände der Hülle Version 1 trägt
|
||||
* („Abstand oben und unten“ spacing, Abweichung „Abstand oben“ same/small/none).
|
||||
*
|
||||
* @param array<string, mixed> $style
|
||||
*/
|
||||
public static function hasLegacySpacing(array $style): bool
|
||||
{
|
||||
return array_key_exists('spacing', $style)
|
||||
|| in_array($style['spacing_top'] ?? null, ['same', 'small'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersetzt die Abstände der Hülle Version 1 in die drei Werte der Version 2, ohne die Darstellung zu ändern.
|
||||
*
|
||||
* Version 1 rechnete so: jeder Abschnitt oben und unten „spacing“ (Vorgabe normal); die Abweichung
|
||||
* „Abstand oben“ ersetzte nur oben (small/none); und eine versteckte Regel setzte oben auf null, wenn ein Abschnitt
|
||||
* ohne eigene Fläche direkt auf einen Abschnitt ohne eigene Fläche folgte (ohne Linien- oder Akzenttrenner dazwischen).
|
||||
* Diese Regel wird hier als „oben: kein Abstand“ ausgeschrieben. „Gering“ hat keine eigene Stufe mehr und wird
|
||||
* „Kompakt“ (dokumentierte Abweichung). Der Widget-Abstand entspricht dem bisherigen festen Rasterabstand („normal“).
|
||||
*
|
||||
* @param list<array<string, mixed>> $sections Abschnitte in Lesereihenfolge (mit style und slots)
|
||||
* @param bool $byVersion true: jede Hülle mit v < 2 gilt als Version 1 (Lesepfad gespeicherter Revisionen);
|
||||
* false: nur Gestaltungen mit alten Schlüsseln (Eingaben ohne Versionsangabe)
|
||||
* @return list<array<string, mixed>> dieselben Abschnitte mit übersetzter Gestaltung
|
||||
*/
|
||||
public static function migrateSpacing(array $sections, bool $byVersion = false): array
|
||||
{
|
||||
$previous = null;
|
||||
|
||||
foreach ($sections as $index => $section) {
|
||||
$style = is_array($section['style'] ?? null) ? $section['style'] : [];
|
||||
$rendered = is_array($section['slots'] ?? null) && array_filter($section['slots'], 'is_array') !== [];
|
||||
|
||||
$background = is_string($style['background'] ?? null) && isset(self::BACKGROUNDS[$style['background']]) ? $style['background'] : 'default';
|
||||
if ($background === 'image' && ! PublicMedia::isPublicPath($style['image'] ?? null)) {
|
||||
$background = 'default';
|
||||
}
|
||||
$divider = in_array($style['divider'] ?? null, ['line', 'accent'], true) ? $style['divider'] : 'none';
|
||||
|
||||
$legacy = $byVersion ? (int) ($section['v'] ?? 1) < 2 : self::hasLegacySpacing($style);
|
||||
|
||||
if ($legacy) {
|
||||
$level = in_array($style['spacing'] ?? null, ['compact', 'normal', 'large'], true) ? $style['spacing'] : 'normal';
|
||||
$override = $style['spacing_top'] ?? 'same';
|
||||
$collapsed = $background === 'default' && $previous !== null && $previous['background'] === 'default' && ! in_array($previous['divider'], ['line', 'accent'], true);
|
||||
|
||||
$style['spacing_top'] = match (true) {
|
||||
$override === 'none' => 'none',
|
||||
$override === 'small' => 'compact',
|
||||
$collapsed => 'none',
|
||||
default => $level,
|
||||
};
|
||||
$style['spacing_bottom'] = $level;
|
||||
$style['gap'] = 'normal';
|
||||
|
||||
// Trenner „Zusätzlicher Abstand“ (Version 1) fügte unten noch einmal den Abschnittsabstand an.
|
||||
if (($style['divider'] ?? null) === 'space') {
|
||||
$style['spacing_bottom'] = ['compact' => 'normal', 'normal' => 'large', 'large' => 'large'][$level];
|
||||
$style['divider'] = 'none';
|
||||
}
|
||||
unset($style['spacing']);
|
||||
$sections[$index]['style'] = $style;
|
||||
}
|
||||
|
||||
if ($rendered) {
|
||||
$previous = ['background' => $background, 'divider' => $divider];
|
||||
}
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user