Repository navigation
Cover block: Block Bindings support for id and url (internal-only) - #2
cbravobernal wants to merge 60 commits into
Conversation
Co-authored-by: jameskoster <jameskoster@git.wordpress.org> Co-authored-by: simison <simison@git.wordpress.org> Co-authored-by: retrofox <retrofox@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org> Co-authored-by: simison <simison@git.wordpress.org> Co-authored-by: retrofox <retrofox@git.wordpress.org>
Pipeline 0-prompt artifact for Cover block bindings (id+url, internal-only). Tracks WordPress#77199. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…d-url-internal Capture the requirements for Cover block bindings (id and url, internal media only) distilled from PR WordPress#74109 / WordPress#74610 review feedback and the existing codebase shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ternal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-internal (iter 2) Address spec-review-1-rejected.md findings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-internal (iter 3) Address spec-review-2-rejected.md findings (Pattern Overrides __default data model). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ndings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…gs-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…77199-cover-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dings-id-url-internal (iter 2) Address design-doc-review-1-rejected.md findings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…77199-cover-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dings-id-url-internal (iter 3) Address design-doc-review-2-rejected.md findings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…199-cover-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rl-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…over-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…d-url-internal (iter 2) Address code-plan-review-1-rejected.md findings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…er-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…l-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…r-bindings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…nder_block_data) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ock filter Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…Edit Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ndings-id-url-internal Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pipeline artifacts belong outside repo. .gitignore already excludes them; they were force-added during the run. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop gutenberg_cover_bindings_expand_bindings — Core's process_block_bindings already expands __default before resolution. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bindingResolvedId and canUserEditBindingValue had no runtime consumer. Restore when actual lock-flag UI is wired. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
22 new tests → 7 covering user-observable invariants and DC contracts. Hook predicate matrix dropped (covered by integration + e2e). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cut verbose docblocks and inline narrative on the Cover bindings compat file. Keep 1-3 line summaries, drop obvious @param/@return blocks, retain only non-obvious-behaviour comments (priority-9 ordering, loose-== rationale). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Inline `relax_dim_class` and the `has_cover_relevant_configuration` predicate into the single render-block call site. `strip_image` keeps two callers and `rewrite_image` is large/cohesive — both remain helpers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract `register_id_url_source()` shortcut and `DEFAULT_SAVED_MARKUP` constant; drop verbose docblocks; collapse multi-paragraph test narratives into one-line AC tags. All 9 acceptance-criterion cases preserved. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collapse verbose narrative on the binding-state hook, the effectiveUrl / effectiveDimRatio derivations, the URL-resolved observer, and the bound <img> branch. Merge the unresolvable/pending Placeholder branches into a single conditional-attribute element. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cut verbose typedef/JSDoc noise, inline the unresolvable-binding flag into a single boolean expression, and shorten the dep-array justification. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop verbose AC annotations and redundant assertions across the four round-trip phases; hoist getCoverBlock / getBlockToolbar helpers to remove repeated locator chains. Keep all four phases, the embed-video carve-out, and the unresolvable affordance. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hoist a shared `useBindingSource` harness used by all four binding describes; remove duplicated source-registration + sourceState boilerplate and the verbose multi-paragraph narrative comments on each test case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collapse the AC-21 + bindings-active early-returns into combined guard clauses, fold the two-step preg_match offset/length plumbing inline, shorten resolved_url/resolved_id variables to url/id, and drop the inline narrative comments. Behaviour is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Shorten the propsRef / effectiveUrl / effectiveDimRatio / observer comments to single-line markers, fold the bindingActive vs isImgElement <img>/<div> branch into one ternary, and compress the unresolvable Placeholder className into a template literal. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Re-applies WordPress#75114 — `dot: true` was dropped during a wp-build refactor. When the repository path contains a dot-prefixed directory (`.worktrees/`, `.claude/worktrees/`, etc.), fast-glob's default dot-filtering skips matches under that path, so `transpilePackage` returns empty file lists and the build silently produces no output. Fixes the regression so builds work from any worktree location. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: -87 B (0%) Total Size: 8.21 MB 📦 View Changed
ℹ️ View Unchanged
|
Replace loose `==` comparison with a recursive canonical-equality helper `gutenberg_cover_bindings_args_equal`. Loose comparisons mask type-juggling bugs and the `phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison` annotation was a smell. Order-insensitive intent is preserved by structural recursion over associative arrays. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lback prepare_block only consumes $parsed_block. Drop the unused $source_block and $parent_block params; declare accepted_args=1 on the filter. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extract the two duplicated saved-markup regexes for the parallax `<div>` and plain `<img>` forms into top-level constants. preg_match itself stays — WP HTML API cannot delete elements or change tag names, and Cover's own index.php uses the same approach. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pattern Overrides — the headline use case — requires the per-instance
Replace control. The binding source intercepts setAttributes({ url, id })
and stores the override. Hiding the toolbar broke that flow.
Mirrors core/image, which gates only on source.canUserEditValue() (false
when the binding source forbids edits, true for Pattern Overrides).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42a079f to
2cf08e1
Compare
…-only
Two real bugs surfaced when testing the PR:
1. Pattern Overrides instance: setBoundAttributes drops non-bound attrs
(backgroundType, focalPoint, etc.) when inside a pattern, so
isImageBackground stays false and the force-img branch never engages.
Fix: derive isImageBackground from bindingActive && bindingResolvedUrl
as a second path.
2. URL-only binding (no id) was treated as unresolvable. Mirrors what
core/image does: a url binding alone is the canonical case.
Drop the same-source / internal-media invariant. id binding is
optional and only enables wp-image-{id} class on the server.
Drops bindingUnresolvable state entirely - url binding always renders.
Server-side is_active relaxed to "url binding present". args_equal
helper removed (no longer needed without same-args check).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers authored without picking media save no `<img>`. When such a Cover is later bound to a URL source, the rewrite path had nothing to mutate and returned the markup unchanged, leaving no image on the front end. Add a third branch: locate the overlay `<span class="wp-block-cover__background">` and prepend a freshly-built `<img>` carrying the bound URL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The stored customOverlayColor was derived from the original image at authoring time. After binding to a different source, the overlay's inline `background-color` no longer matches the bound media (e.g. orange tint from a Charizard cover bleeding into every bound instance). Server-side: remove the inline `style` attribute on the overlay `<span class="wp-block-cover__background">` when bindings are active. Relax dim-class pass merged into the same Tag Processor walk. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Hey @cbravobernal! I saw an older PR from @ockham WordPress#74610 that seems abandoned and then this one, also abandoned. Is there any blocker or issue preventing us from adding binding support to Cover block? I'm asking from WooCommerce perspective as we would definitely see a use cases for it! 🙌 EDIT: Apologies, I didn't realise I comment on your fork. I'm positing the comment in Gutenberg's PR 😅 |
|
@kmanijak Let's close this one. The main limitation is not having CSS selectors to point correctly to the cover background. Apart from the last video background feature that made things even more difficult. Also block bindings to an image is limited only to a WP image, while binding to any external image causes lots of side effects. Happy to be back working on this and get Woo's feedback. |
Summary
Adds Block Bindings support for
core/cover'sidandurlattributes, scoped to internal media-library attachments. Headline use case: Pattern Overrides on Cover blocks.Tracks upstream WordPress/gutenberg#77199. Subsumes #74109 and #74610 with a narrower, mergeable scope.
Scope
In:
id+urlofcore/cover.dimRatioso default100does not produce opaque overlay.Out:
backgroundType: "embed-video"+ bindings (short-circuits).Architecture
cover/edit/index.jsviauseEffectEvent. No scattereduseEffects keyed on user events.Server-side in
lib/compat/wordpress-7.1/block-bindings.php:gutenberg_cover_bindings_is_active— pure helper, expands Pattern Overrides__default, requires same source + same args onidandurl.gutenberg_cover_bindings_prepare_block(render_block_data, prio 10) — forcesuseFeaturedImage=falseBEFORE bindings resolution.gutenberg_cover_bindings_render_block(render_block, prio 9) — rewrites image element, relaxeshas-background-dim-100, strips image when unresolvable.Client-side
packages/block-library/src/cover/edit/use-cover-binding-state.js— singleuseSelect, nouseEffect.Test plan
dimRatio: 100: overlay omitshas-background-dim-100.hasParallax: true: front-end emits<img>, no<div style="background-image">.Internal media required for this binding.placeholder; no front-end<img>.useFeaturedImage: truelegacy + binding: one<img>with bound URL.backgroundType: "embed-video"+ bindings: embed path unchanged.vendor/bin/phpunit phpunit/blocks/render-block-cover-test.php(11 tests).npm run test:unit -- packages/block-library/src/cover/test/edit.js(27 tests).npm run test:e2e -- test/e2e/specs/editor/blocks/cover.spec.js(11 tests).🤖 Generated with Claude Code