feat: per-subName attribute-path kinds for composite Divi paths

lit/divi-catalog's path_kinds previously named one kind per whole attribute
path, built from Divi's metadata component name alone. For a composite path
(Divi groups several named sub-fields, "subName", under one path – e.g.
buttonOne.innerContent holds "text" and "linkUrl") that was wrong: the whole
path got one guessed kind (or none), even though the sub-fields can differ
(fullwidth-header's buttonOne/buttonTwo.innerContent -> "text", though it
also carries a "linkUrl"; image.innerContent -> "image", though the value
also carries alt/id/titleText the metadata never names on its own).

AttrPathIndex::kinds() now resolves a composite path to a map
subName => kind instead, preferring Divi's features.dynamicContent.type over
the (often shared/generic) field component for a named sub-field – this is
what tells a button's plain text sub-field apart from its linkUrl sub-field,
both of which use the same generic "divi/text" component. A plain (non-
composite) path is unaffected. Any subName the metadata never names (or that
disagrees between candidates) is therefore simply absent from the map, and
ModuleCatalog::pathKind() defaults it, like every unresolved path, to
"unknown" - the strictest routing for 2b's sanitizer, never a guess.

ModuleCatalog::pathKind() gains an optional $subName parameter to read a
composite path's map. docs/guides/divi-attrs.md documents the new shape and
that lit-divi-catalog without `module` lists all modules.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 13:12:49 +02:00
co-authored by Claude Opus 5.5
parent 4137882008
commit 73433ae862
6 changed files with 179 additions and 36 deletions
+18 -6
View File
@@ -17,7 +17,7 @@ final class ModuleCatalog
/** @var array<string, list<string>> */
private array $paths = [];
/** @var array<string, array<string, string>> */
/** @var array<string, array<string, string|array<string, string>>> */
private array $kinds = [];
/** @var callable(string): array<string, mixed> */
@@ -118,9 +118,12 @@ final class ModuleCatalog
/**
* Known attribute path => value kind for this module (spec §5.6, ruling R3), wherever
* Divi's metadata names an unambiguous field component; not every known path resolves.
* Divi's metadata names an unambiguous field component – or, for a composite path (several
* named sub-fields under one path, e.g. buttonOne.innerContent's "text"/"linkUrl"), a map
* subName => kind (see AttrPathIndex::kinds()). Not every known path, or every sub-field of
* a composite one, resolves.
*
* @return array<string, string>
* @return array<string, string|array<string, string>>
*/
public function kinds(string $name): array
{
@@ -132,10 +135,19 @@ final class ModuleCatalog
return $this->kinds[$name];
}
/** Value kind of one path, "unknown" if Divi's metadata does not resolve one (spec §5.6). */
public function pathKind(string $name, string $path): string
/**
* Value kind of one path, or of one named sub-field ($subName) of a composite path;
* "unknown" if Divi's metadata does not resolve one (spec §5.6) – including a composite
* path asked about without a $subName, or for a sub-field the metadata never names.
*/
public function pathKind(string $name, string $path, ?string $subName = null): string
{
return $this->kinds($name)[$path] ?? 'unknown';
$kind = $this->kinds($name)[$path] ?? null;
if (is_string($kind)) {
return $kind;
}
return is_array($kind) && $subName !== null ? ($kind[$subName] ?? 'unknown') : 'unknown';
}
/** @return list<array{name: string, title: string, category: string, children: list<string>}> */