Skip to content

Commit 5a23c0c

Browse files
committed
fix(php-transformer): keep reveal hooks native
Treat presentational animation data selectors as non-runtime DOM targets so static marketing content remains editable native blocks. Refs #487.
1 parent ebc3997 commit 5a23c0c

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

php-transformer/src/HtmlToBlocks/HtmlTransformer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,6 +4348,10 @@ private function isRuntimeDomTarget(DOMElement $element): bool
43484348
}
43494349

43504350
foreach ( array_keys($this->runtimeDomSelectors) as $selector ) {
4351+
if ( $this->isPresentationalAnimationDataSelector((string) $selector) ) {
4352+
continue;
4353+
}
4354+
43514355
if ( $this->elementMatchesRuntimeSelector($element, (string) $selector) ) {
43524356
return true;
43534357
}
@@ -4496,6 +4500,26 @@ private function shouldPreserveDataAttributeRuntimeTarget(DOMElement $element):
44964500

44974501
foreach ( array_keys($this->runtimeDomSelectors) as $selector ) {
44984502
if ( str_contains((string) $selector, '[') && $this->elementMatchesRuntimeSelector($element, (string) $selector) ) {
4503+
if ( $this->isPresentationalAnimationDataSelector((string) $selector) ) {
4504+
continue;
4505+
}
4506+
4507+
return true;
4508+
}
4509+
}
4510+
4511+
return false;
4512+
}
4513+
4514+
private function isPresentationalAnimationDataSelector(string $selector): bool
4515+
{
4516+
if ( ! preg_match('/\[(data-[A-Za-z][A-Za-z0-9_-]*)/', $selector, $match) ) {
4517+
return false;
4518+
}
4519+
4520+
$attribute = strtolower((string) $match[1]);
4521+
foreach ( preg_split('/[^a-z0-9]+/', substr($attribute, 5)) ?: array() as $token ) {
4522+
if ( in_array($token, array( 'animate', 'animation', 'appear', 'delay', 'fade', 'motion', 'parallax', 'reveal', 'scroll', 'transition' ), true) ) {
44994523
return true;
45004524
}
45014525
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"schema": "blocks-engine/php-transformer/parity-fixture/v1",
3+
"name": "html-presentational-data-attributes-native",
4+
"description": "Presentation-only animation data attributes such as data-reveal/data-delay do not force editable text and generic groups into core/html runtime preservation when callers provide matching runtime_dom_selectors.",
5+
"source_reference": {
6+
"repo": "php-transformer",
7+
"path": "tests/fixtures/parity/html-presentational-data-attributes-native.json",
8+
"notes": "Generic regression for static marketing sections that use data-* reveal hooks on labels, headings, paragraphs, and wrappers."
9+
},
10+
"legacy_comparison": {
11+
"skip": true,
12+
"reason": "Covers current PHP transformer generic data-attribute runtime selector behavior; no downstream legacy comparison."
13+
},
14+
"operation": "html_transformer.transform",
15+
"input": {
16+
"content": "<section class=\"feature-section\" aria-label=\"Feature\"><div class=\"feature-header\" data-reveal><span class=\"section-label\" data-reveal>Feature Label</span><h2 class=\"feature-heading\" data-reveal data-delay=\"1\">Built on <em>care</em><br>and craft</h2><p class=\"feature-sub\" data-reveal data-delay=\"2\">Readable source copy.</p></div></section>",
17+
"options": {
18+
"runtime_dom_selectors": ["[data-reveal]", "[data-delay]"]
19+
}
20+
},
21+
"expected_blocks": [
22+
{ "path": "blocks.0", "name": "core/group", "attrs": { "className": "feature-section", "tagName": "section" } },
23+
{ "path": "blocks.0.innerBlocks.0", "name": "core/group", "attrs": { "className": "feature-header" } },
24+
{ "path": "blocks.0.innerBlocks.0.innerBlocks.0", "name": "core/paragraph", "attrs": { "content": "<span class=\"section-label\" data-reveal>Feature Label</span>" } },
25+
{ "path": "blocks.0.innerBlocks.0.innerBlocks.1", "name": "core/heading", "attrs": { "content": "Built on <em>care</em><br>and craft", "level": 2, "className": "feature-heading" } },
26+
{ "path": "blocks.0.innerBlocks.0.innerBlocks.2", "name": "core/paragraph", "attrs": { "content": "Readable source copy.", "className": "feature-sub" } }
27+
],
28+
"expected_fallbacks": [],
29+
"expect": [
30+
{ "path": "status", "assert": "equals", "value": "success" },
31+
{ "path": "blocks", "assert": "count", "count": 1 },
32+
{ "path": "fallbacks", "assert": "count", "count": 0 },
33+
{ "path": "coverage.0.fallback_count", "assert": "equals", "value": 0 },
34+
{ "path": "serialized_blocks", "assert": "not_contains", "value": "<!-- wp:html" },
35+
{ "path": "serialized_blocks", "assert": "contains", "value": "<!-- wp:heading" },
36+
{ "path": "serialized_blocks", "assert": "contains", "value": "<!-- wp:paragraph" }
37+
]
38+
}

0 commit comments

Comments
 (0)