fix: Insert entscheidet fail closed auf den komponierten Blöcken statt auf Client-Text; Update warnt bei Wechsel der Schleifen-Art unter unveränderten Kindern (X3)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
dadc1f3ec4
commit
5b52e18a31
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Integrations\Divi\Compose;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Block;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
@@ -63,6 +64,42 @@ final class LoopContext
|
||||
return LoopScope::none();
|
||||
}
|
||||
|
||||
/**
|
||||
* The loop_* options $block and its descendants reference in their (canonical) attrs. Opaque blocks are not
|
||||
* entered; $stopAtLoops leaves out descendants that run a loop of their own (their content has its own scope).
|
||||
* A reference that is no clean whole value but names a loop_ option counts as "loop_?" (fail closed).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function optionsIn(Block $block, bool $stopAtLoops): array
|
||||
{
|
||||
if ($block->isOpaque()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$names = [];
|
||||
$attrs = $block->attrs();
|
||||
array_walk_recursive($attrs, static function (mixed $value) use (&$names): void {
|
||||
if (! is_string($value)) {
|
||||
return;
|
||||
}
|
||||
$name = VariableRef::nameOf($value);
|
||||
if ($name === null && VariableRef::contains($value) && str_contains($value, 'loop_')) {
|
||||
$name = 'loop_?';
|
||||
}
|
||||
if ($name !== null && str_starts_with($name, 'loop_')) {
|
||||
$names[] = $name;
|
||||
}
|
||||
});
|
||||
foreach ($block->children() as $child) {
|
||||
if (! ($stopAtLoops && self::enabled($child->attrs()))) {
|
||||
array_push($names, ...self::optionsIn($child, $stopAtLoops));
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($names));
|
||||
}
|
||||
|
||||
/** The loop of the node $nodeId (path ID) or its nearest ancestor; none() for an unknown ID. */
|
||||
public static function of(NodeIndex $index, string $nodeId): LoopScope
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user