feat: design-system filters and global module ids in node-get/outline (S19)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-27 00:44:58 +02:00
co-authored by Claude Opus 5.5
parent 858aa6a182
commit a3a807051f
8 changed files with 187 additions and 19 deletions
@@ -25,7 +25,10 @@ final class NodeSummary
public static function label(Block $block): string
{
$label = AttrMap::desktop($block->attrs(), 'module.meta.adminLabel');
$attrs = $block->name() === 'divi/global-layout' && is_array($block->attrs()['localAttrs'] ?? null)
? $block->attrs()['localAttrs']
: $block->attrs();
$label = AttrMap::desktop($attrs, 'module.meta.adminLabel');
if (! is_string($label) || $label === '') {
return '';
}
@@ -55,6 +58,29 @@ final class NodeSummary
return '';
}
/**
* Library entry of a global module: a divi/global-layout instance (its root type in blockName)
* or a block that carries globalModule itself (Divi 4 conversions). Null for every other block.
*
* @return array{id: string, block_name: string}|null
*/
public static function globalRef(Block $block): ?array
{
if (! $block->isGlobal()) {
return null;
}
$attrs = $block->attrs();
$id = $attrs['globalModule'] ?? null;
if (! is_string($id) && ! is_int($id)) {
return null;
}
$name = $block->name() === 'divi/global-layout' ? ($attrs['blockName'] ?? '') : $block->name();
return ['id' => (string) $id, 'block_name' => is_string($name) ? $name : ''];
}
/** @return list<string> */
public static function presetIds(Block $block): array
{
+14 -3
View File
@@ -59,7 +59,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}>
* 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
{
@@ -114,6 +115,7 @@ final class Outline
foreach ($rows as $row) {
$line = str_repeat(' ', (int) $row['depth']) . $row['id'] . ' ' . $row['type'];
$line .= $row['label'] !== '' ? ' "' . $row['label'] . '"' : '';
$line .= ($row['global_id'] ?? null) !== null ? ' [global ' . $row['global_id'] . ']' : '';
$line .= $row['info'] !== '' ? ' [' . $row['info'] . ']' : '';
$line .= $row['presets'] !== [] ? ' {Preset: ' . implode(', ', $row['presets']) . '}' : '';
$line .= $row['excerpt'] !== '' ? ' – ' . $row['excerpt'] : '';
@@ -127,15 +129,23 @@ 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}
* presets: list<string>, children: int, editable: bool, depth: int, truncated: bool,
* global_id: ?string}
*/
private function row(Block $block, string $id, int $depth): array
{
$editable = $block->isDivi() && ! $block->isOpaque();
$global = NodeSummary::globalRef($block);
$type = $block->isDivi() ? $block->shortName() : $block->name();
if ($global !== null && $global['block_name'] !== '') {
$type = str_starts_with($global['block_name'], 'divi/')
? substr($global['block_name'], 5)
: $global['block_name'];
}
return [
'id' => $id,
'type' => $block->isDivi() ? $block->shortName() : $block->name(),
'type' => $type,
'label' => NodeSummary::label($block),
'excerpt' => NodeSummary::excerpt($block),
'info' => $editable ? NodeSummary::info($block) : '',
@@ -147,6 +157,7 @@ final class Outline
'editable' => $editable,
'depth' => $depth,
'truncated' => false,
'global_id' => $global['id'] ?? null,
];
}
}