Image block: style fields, float alignment, coupling, and linking - #167
Merged
Merged
Conversation
* main: Release @plone/plate 1.0.0-alpha.15 Fix release @plone/plate (#166)
Migrate the image block's alignment and size to schema-driven style fields and finish the block's styling story: - Deliver the block CSS as a CSS module (no global side-effect import), following the slots pattern. - Float left/right aligned images so surrounding content wraps around them, keep the gap for wrapping text and list markers, and keep floated images selectable in the editor (raise them, drop the collapsed selection outline). - Couple alignment with size and block width via a new, generic `onChangeSideEffects` tap point in the block settings form: floated images fix the width to default and drop the large size; centering restores both. - Render the image through the shared Image component in both edit and view, and wrap it in a link when the block has an href. Add unit and acceptance coverage and a how-to guide for onChangeSideEffects.
Following review feedback, remove the alignment↔size/width coupling from the image block so left/right, size and block width are independent controls again: - Left/right alignment floats the image at any size; the floated width is capped (`--block-float-max-size`, default 66%) so even the large size floats with room for content to wrap. - The block width control stays editable while floated, and every image size stays available. - The generic `onChangeSideEffects` tap point remains in the block settings form for future use; the how-to guide now presents it with an illustrative example instead of the (removed) image block coupling. Expand the acceptance suite to cover the combinations end to end: the size scale while floated, block width independence, a single sequential walkthrough of every alignment/size combination, and a render-on-save round trip.
The sequential walkthrough flaked in CI: changing a style field re-renders and deselects the block asynchronously, and the previous `ensureSelected` helper could observe the still-open sidebar during that transition, skip re-selecting, then fail when the next radio had disappeared. Replace it with a retrying `selectBlock` (open the sidebar, retried) and `setRadio` (select-then-click as one retried unit), so a pending deselect no longer races the next interaction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Standardizes the image block's size and alignment on Aurora's schema-driven style fields, and completes the block's styling and interaction story on top of the concepts explored in #147 (this is a clean take rather than a continuation of that branch).
Key points:
styleFields resolved fromconfig.blocks.alignments/config.blocks.sizes, consistent withblockWidth.ImageBlock.module.css) — no global side-effectimport './ImageBlock.css', matching the slots pattern.Imagecomponent in both edit and view, and is wrapped in a link when the block has anhref.What changed
Style fields for size & alignment
alignandsizemarkedstyleField: true;config.blocks.alignments/config.blocks.sizesprovide the definitions and utilities (packages/blocks/index.ts).alignments?/sizes?inBlocksConfigtypes.CSS module (no side-effect import)
ImageBlock.module.cssreplaces the globalImageBlock.css. Because Tailwind's preflight/utilities and the editor selection outline live in a stronger cascade layer (cmsui), the block's own layout rules are intentionally unlayered so they win (documented inline).Float-based alignment + wrapping
left/rightinject--block-float+--block-margin; the module consumes them so following content (text and list markers) wraps with a proper gap.max-width: var(--block-float-max-size, 66%), so even the large size floats with room for content to wrap. Centered images are unaffected (large stays full width).position: relative; z-index) and the stray collapsed selection outline / spacing are suppressed — scoped to floated states via thedata-style-alignattribute.list-style-position: insidesooutsidemarkers don't hang onto the image (a marker gutter can't fix this given Plate's per-item<ol>structure — see the inline note).Independent controls (no coupling)
onChangeSideEffects(value, nextData)tap point is available inBlockSettingsFormfor blocks that do want cross-field reactions in the future; the image block no longer uses it. Documented in the new how-to with an illustrative example.Rendering + linking
ImageBlockEdit/ImageBlockViewsharegetImageBlockItem/getImageBlockSrc(responsive scales when available, legacy@@images/ external URL fallback otherwise).ImageBlockViewwraps the image inLink(@plone/components) whenhrefis set, honoringopenLinkInNewTab(target/rel). Aurora has noUniversalLink;Linkis the pattern used by Teaser and the slots.Image widget fix
image_fieldandimage_scalesfrom the object-browser selection (previously onlytitle), so picked images render responsive scales.Testing
packages/blocks): schema style-field marks, alignment/size definitions, and that the fields stay independent (no coupling).packages/cmsui/acceptance/tests/image-block-style-fields.test.ts, 8 tests):<a target="_blank" rel="noopener…">.block-width.test.tslocator (.image.align.block→.block-image) after the class refactor, and addedtestIgnorefor.codex/**/node_modulesinplaywright.config.tsso ephemeral git worktrees aren't collected.Docs
New how-to guide Couple block schema fields documenting
onChangeSideEffectswith an illustrative example (no shipped block enables the coupling today).