feat: Presets als Stapel, Gruppen-Presets und clear_overrides im Composer
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
fafa140546
commit
be6ca5bee0
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Support;
|
||||
|
||||
use Closure;
|
||||
use LIT\MCP\Integrations\Divi\Compose\AttrWriter;
|
||||
use LIT\MCP\Integrations\Divi\Compose\Composer;
|
||||
use LIT\MCP\Integrations\Divi\Compose\LinkTargets;
|
||||
@@ -15,6 +16,8 @@ use LIT\MCP\Integrations\Divi\Compose\ValueCleaner;
|
||||
use LIT\MCP\Integrations\Divi\Compose\ValueSanitizer;
|
||||
use LIT\MCP\Integrations\Divi\Compose\VariableRef;
|
||||
use LIT\MCP\Integrations\Divi\Design\DesignSystem;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetAssignment;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetBook;
|
||||
|
||||
/**
|
||||
* Compose classes wired with the real Divi 5.2.1 sample catalog, the sample design system and
|
||||
@@ -193,10 +196,17 @@ final class ComposeFixture
|
||||
/**
|
||||
* Builder version 5.2.1. $design replaces the sample design system (one Placeholders, one
|
||||
* VariableRef and one ValueCleaner shared by AttrWriter, ShortformWriter and Composer, like the
|
||||
* live wiring – ruling S31).
|
||||
* live wiring – ruling S31). The presets come from $book (default: the presets of $design, see
|
||||
* bookOf()); $groupsOf names the option groups per module (default: none).
|
||||
*
|
||||
* @param (Closure(string): array<string, string>)|null $groupsOf
|
||||
*/
|
||||
public static function composer(bool $unfiltered = false, ?DesignSystem $design = null): Composer
|
||||
{
|
||||
public static function composer(
|
||||
bool $unfiltered = false,
|
||||
?DesignSystem $design = null,
|
||||
?PresetBook $book = null,
|
||||
?Closure $groupsOf = null
|
||||
): Composer {
|
||||
$design ??= DiviFixtures::designSystem();
|
||||
$placeholders = new Placeholders($design);
|
||||
$cleaner = new ValueCleaner(DiviFixtures::catalog(), new VariableRef($design), self::sanitizer($unfiltered));
|
||||
@@ -208,8 +218,52 @@ final class ComposeFixture
|
||||
new ShortformWriter($placeholders, self::media(), $cleaner),
|
||||
$attrWriter,
|
||||
$cleaner,
|
||||
$design,
|
||||
self::presetAssignment($book, $groupsOf, $design, $cleaner),
|
||||
'5.2.1'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The presets of $design in Divi's stored format (ids, names, defaults; no attrs) as a PresetBook – so the tests
|
||||
* that hand a DesignSystem to composer() keep their presets.
|
||||
*/
|
||||
public static function bookOf(DesignSystem $design): PresetBook
|
||||
{
|
||||
$raw = ['module' => [], 'group' => []];
|
||||
foreach ($design->presets() as $preset) {
|
||||
$raw[$preset['kind']][$preset['module']] ??= ['default' => '', 'items' => []];
|
||||
$raw[$preset['kind']][$preset['module']]['items'][$preset['id']] = [
|
||||
'id' => $preset['id'],
|
||||
'name' => $preset['name'],
|
||||
$preset['kind'] === 'module' ? 'moduleName' : 'groupName' => $preset['module'],
|
||||
];
|
||||
if ($preset['default']) {
|
||||
$raw[$preset['kind']][$preset['module']]['default'] = $preset['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return PresetBook::fromDivi($raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* PresetAssignment as the live wiring builds it: the book is $book (default: bookOf($design), else of the sample
|
||||
* design system), the id check is the cleaner's keepsId().
|
||||
*
|
||||
* @param (Closure(string): array<string, string>)|null $groupsOf
|
||||
*/
|
||||
public static function presetAssignment(
|
||||
?PresetBook $book = null,
|
||||
?Closure $groupsOf = null,
|
||||
?DesignSystem $design = null,
|
||||
?ValueCleaner $cleaner = null
|
||||
): PresetAssignment {
|
||||
$book ??= self::bookOf($design ?? DiviFixtures::designSystem());
|
||||
$cleaner ??= self::cleaner();
|
||||
|
||||
return new PresetAssignment(
|
||||
static fn (): PresetBook => $book,
|
||||
$groupsOf ?? static fn (string $module): array => [],
|
||||
$cleaner->keepsId(...)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user