feat: Outline und Knoten zeigen Gruppen-Presets mit Namen

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-18 16:41:42 +02:00
co-authored by Claude Haiku 5.5
parent ca3bbf5ad1
commit c3f08e2d33
7 changed files with 308 additions and 21 deletions
@@ -84,14 +84,37 @@ final class NodeSummary
/** @return list<string> */
public static function presetIds(Block $block): array
{
$presets = $block->attrs()['modulePreset'] ?? [];
if (is_string($presets)) {
$presets = [$presets];
return self::idList($block->attrs()['modulePreset'] ?? []);
}
/**
* Option group presets of the block (formats §3 "Verweise in Blöcken"): groupPreset.<groupId> holds
* {presetId: [id, …], groupName: "divi/<group>"}. Empty IDs are dropped; an entry without a valid
* groupName or without any ID is left out.
*
* @return array<string, array{groupName: string, presetIds: list<string>}> groupId => entry
*/
public static function groupPresets(Block $block): array
{
$entries = $block->attrs()['groupPreset'] ?? [];
if (! is_array($entries)) {
return [];
}
return is_array($presets)
? array_values(array_filter($presets, static fn (mixed $id): bool => is_string($id) && $id !== ''))
: [];
$groups = [];
foreach ($entries as $groupId => $entry) {
if (! is_array($entry)) {
continue;
}
$name = $entry['groupName'] ?? null;
$ids = self::idList($entry['presetId'] ?? []);
if (is_string($name) && $name !== '' && $ids !== []) {
$groups[(string) $groupId] = ['groupName' => $name, 'presetIds' => $ids];
}
}
return $groups;
}
/** Layout facts: section type, column widths of a row (e.g. "8_24+16_24"). */
@@ -162,6 +185,22 @@ final class NodeSummary
return trim((string) preg_replace('/\s+/u', ' ', $text));
}
/**
* Preset IDs as Divi stores them: a list, or a single string (legacy).
*
* @return list<string>
*/
private static function idList(mixed $ids): array
{
if (is_string($ids)) {
$ids = [$ids];
}
return is_array($ids)
? array_values(array_filter($ids, static fn (mixed $id): bool => is_string($id) && $id !== ''))
: [];
}
private static function rank(string $path): int
{
$index = array_search(explode('.', $path)[0], self::PRIORITY, true);
+35 -8
View File
@@ -62,8 +62,8 @@ final class Outline
/**
* @return list<array{id: string, type: string, label: string, excerpt: string, info: string,
* presets: list<string>, children: int, editable: bool, depth: int, truncated: bool,
* global_id: ?string}>
* presets: list<string>, group_presets: list<string>, children: int, editable: bool, depth: int,
* truncated: bool, global_id: ?string}>
*/
public function rows(NodeIndex $index, ?string $rootId = null, ?int $maxDepth = null, ?int $limit = null): array
{
@@ -121,6 +121,8 @@ final class Outline
$line .= ($row['global_id'] ?? null) !== null ? ' [global ' . $row['global_id'] . ']' : '';
$line .= $row['info'] !== '' ? ' [' . $row['info'] . ']' : '';
$line .= $row['presets'] !== [] ? ' {Preset: ' . implode(', ', $row['presets']) . '}' : '';
$groupPresets = $row['group_presets'] ?? [];
$line .= $groupPresets !== [] ? ' {Gruppen-Presets: ' . implode('; ', $groupPresets) . '}' : '';
$line .= $row['excerpt'] !== '' ? ' – ' . $row['excerpt'] : '';
$line .= $row['editable'] ? '' : ' (nur lesbar)';
$line .= ($row['truncated'] ?? false) ? ' (weitere Kinder abgeschnitten)' : '';
@@ -132,8 +134,8 @@ final class Outline
/**
* @return array{id: string, type: string, label: string, excerpt: string, info: string,
* presets: list<string>, children: int, editable: bool, depth: int, truncated: bool,
* global_id: ?string}
* presets: list<string>, group_presets: list<string>, children: int, editable: bool, depth: int,
* truncated: bool, global_id: ?string}
*/
private function row(Block $block, string $id, int $depth): array
{
@@ -152,10 +154,8 @@ final class Outline
'label' => NodeSummary::label($block),
'excerpt' => NodeSummary::excerpt($block),
'info' => $editable ? NodeSummary::info($block) : '',
'presets' => array_map(
fn (string $presetId): string => $this->presetNames[$presetId] ?? $presetId,
NodeSummary::presetIds($block)
),
'presets' => $this->namesOf(NodeSummary::presetIds($block)),
'group_presets' => $this->groupPresetLines($block),
'children' => $editable ? count($block->children()) : 0,
'editable' => $editable,
'depth' => $depth,
@@ -163,4 +163,31 @@ final class Outline
'global_id' => $this->globalIds ? ($global['id'] ?? null) : null,
];
}
/**
* One entry per option group: "<short group name>: <preset name>[, <preset name>]", e.g.
* "font-body: Fließtext" (the short name is the key "group_presets" of the write tools takes).
*
* @return list<string>
*/
private function groupPresetLines(Block $block): array
{
$lines = [];
foreach (NodeSummary::groupPresets($block) as $group) {
$name = $group['groupName'];
$short = str_starts_with($name, 'divi/') ? substr($name, 5) : $name;
$lines[] = $short . ': ' . implode(', ', $this->namesOf($group['presetIds']));
}
return $lines;
}
/**
* @param list<string> $presetIds
* @return list<string> The preset names, the ID where the name is unknown.
*/
private function namesOf(array $presetIds): array
{
return array_map(fn (string $presetId): string => $this->presetNames[$presetId] ?? $presetId, $presetIds);
}
}