-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try/even better previews #16873
Merged
Merged
Try/even better previews #16873
Changes from 81 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
cdddad0
First stab at a proof of concept.
af648b1
Attempt to programmatically determine dest dimensions
getdave 2cc1264
Add README stub.
jasmussen 3ad0bc1
Updates to use default args for width and height
getdave 3a15d94
Update class namespaces to match package
getdave 167fadb
Add width and height as Effect Hook deps
getdave 68fb82f
Use correct `createRef` from @wordpress/element
getdave 2ae0507
Revert "Update class namespaces to match package"
getdave a920ee5
Migrate to useRef hook
getdave dc8738f
Adds basic unit test
getdave 0f4f105
Refactor to avoid unecessary state and simplify implementation of sca…
getdave 62e1109
Add some padding to the preview
getdave e822ae7
Refactor to utilise JS template strings
getdave 04648b4
WIP: Adds zoom for small individual blocks
getdave a6f6e38
Updates to target block contents more reliably and to calc entire box…
getdave 6f5c06f
block-preview: render scaled preview in a shadow dom
retrofox ff88234
try: setting styles to shadow dom elements
retrofox 770ff2d
Revert "try: setting styles to shadow dom elements"
getdave a55e988
Removes attempt at auto zoom on Block contents
getdave 7755b5b
Updates to remove scale by default in favour of opt in via prop
getdave 94b6e3d
Adds scaleFactor prop to provide control for non dynamically scaled p…
getdave cffd2e8
Adjust scaleFactor for Block Styles preview
getdave 550f99e
Fix to ensure hooks are called unconditionally to obey rules of Hooks
getdave c5c7079
Removes padding and border from preview on designer advice
getdave 1489148
Only apply dimensions to preview content when dynamically scaling
getdave 5649e51
block-preview: a different approach attempt.
retrofox c4d3843
Correct typo in util function name
getdave 0bb1a30
Seek the firstChild of the Block DOM node
getdave 8d77381
Tidy up effect timers and improve comments
getdave 4def132
Dynamically calculate widths and offsets of preview container
getdave ea1d096
Updates to account for widths of all Blocks passed into to preview
getdave 02e69f5
Revert class additions to Blocks
getdave 52084af
Adds optional scope to DOM utils. Use to limit scope in Block width c…
getdave 6d0a85d
Update packages/block-editor/src/components/block-preview/index.js
getdave 3ed1f99
Allow prop based opt out from scaling
getdave 7c86742
Fix to ensure smallest Block is found even if smaller than container
getdave efa2127
Remove unecessary Math.min usage
getdave 595cf03
core/button: adjust dims of button wrapper
retrofox 6941688
apply vertical alignment
retrofox d7e7b4a
set scale factor to 0.9
retrofox 6a7c6d9
rollback testing purpose comment
retrofox 0fab9b2
cpre/button: keep adjusting styles for preview
retrofox 0f0d6b8
rename vars and css class names
retrofox d11b6ab
adjust rebase
retrofox d39c1d7
restore isScaled factor scale
retrofox 55cd662
set the scale adjustment in the proper place
retrofox b942fb9
update README file
retrofox 0ab14f8
core/button: tidy edit preview styles
retrofox c86f750
coer/button: tweak button preview
retrofox 18ded7d
preview-block: ensure make the preview visible.
retrofox 0b7de16
block-preview: hide dropzone
retrofox 354d42c
core/button: adjust preview for thumb and full sizes
retrofox d70011f
core/button: set same width for preview
retrofox 6089478
core/button: because it's !important
retrofox dbbe0bc
core/button: set nowrap button in preview
retrofox 758468c
core/button: set nowrap onlu for button
retrofox 2b71c32
core/quote: adjust quote size
retrofox 65097d0
Make previews overflow to the bottom.
obenland 8bdcb8e
Merge branch 'try/even-better-previews' of https://github.com/WordPre…
obenland 6096c3e
Revert "core/button: set nowrap onlu for button"
obenland e1b9483
Fix unit test
obenland 75d43ce
core/button: apply nowrap only to buttons
retrofox 89f6393
Try a fixed canvas width
youknowriad 5a1e5ad
Fix blocks editor styles
youknowriad 3d47db8
core/button: centering preview
retrofox 27b430f
core/button: adjust only into teh styles preview
retrofox d21df0b
block-preview: remove scaleAdjustment property
retrofox d8212f2
block-preview: hide inserte element in preview
retrofox 2b1a111
block-preview: just pick up the first block to scale
retrofox e50cfcb
block-preview: fix set tall class. X position (wip)
retrofox 5208a03
popover: remove commented lines
retrofox 029e131
Refactor the preview
youknowriad 72c5027
Remove debug code
youknowriad a4958f3
simplify preview resets
youknowriad 22b4d84
Fix the preview recomputing
youknowriad f218f64
Vertical alignining small blocks
youknowriad 835c4ba
block-editor: restore viewportWidth as a property
retrofox 3fe45d7
Update Readme docs
obenland 91f142f
Remove tests for now
obenland 33fb2d9
block-preview: simplify comparision
retrofox 527111e
Merge branch 'try/even-better-previews' of github.com:WordPress/guten…
retrofox 6f29c27
Remove readme updates that break tests
obenland a3bb473
Update docs properly.
obenland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
77 changes: 65 additions & 12 deletions
77
packages/block-editor/src/components/block-preview/style.scss
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
.block-editor-block-preview { | ||
// This is the preview that shows up to the right of the thumbnail when hovering. | ||
.block-editor-block-switcher__preview { | ||
padding: $block-padding; | ||
font-family: $editor-font; | ||
overflow: hidden; | ||
width: 100%; | ||
pointer-events: none; | ||
display: none; | ||
|
||
@include break-medium { | ||
display: block; | ||
} | ||
|
||
.block-editor-block-preview__content { | ||
font-family: $editor-font; | ||
|
||
> div { | ||
font-family: $editor-font; | ||
} | ||
|
||
&:not(.is-tall-preview) { | ||
// Vertical alignment. | ||
margin-top: 50%; | ||
} | ||
} | ||
|
||
.block-editor-block-preview__title { | ||
margin-bottom: 10px; | ||
color: $dark-gray-300; | ||
} | ||
} | ||
|
||
// These rules ensure the preview scales smoothly regardless of the container size. | ||
.block-editor-block-preview__container { | ||
// In the component, a top padding is provided as an inline style to provid an aspect-ratio. | ||
// This positioning enables the content to sit on top of that padding to fit. | ||
position: relative; | ||
|
||
// The preview component measures the pixel width of this item, so as to calculate the scale factor. | ||
// But without this baseline width, it collapses to 0. | ||
width: 100%; | ||
} | ||
|
||
.block-editor-block-preview__content { | ||
// This element receives inline styles for width, height, and transform-scale. | ||
// Those inline styles are calculated to fit a perfect thumbnail. | ||
|
||
// Position above the padding. | ||
position: absolute; | ||
|
||
// Vertical alignment. It works with the transform: translate(-50%, -50%)`, | ||
top: 0; | ||
left: 0; | ||
|
||
// Important to set the origin. | ||
transform-origin: top left; | ||
|
||
// Resetting paddings, margins, and other. | ||
text-align: initial; | ||
margin: 0; | ||
overflow: visible; | ||
min-height: auto; | ||
|
||
// Resetting the block editor paddings and margins | ||
.block-editor-block-list__layout, | ||
.block-editor-block-list__block { | ||
padding: 0; | ||
} | ||
|
||
.editor-block-list__block-edit [data-block] { | ||
margin-top: 0; | ||
margin: 0; | ||
} | ||
|
||
> div section { | ||
height: auto; | ||
} | ||
|
||
> .reusable-block-indicator { | ||
display: none; | ||
&.is-tall-preview { | ||
top: 4px; | ||
} | ||
|
||
.block-editor-block-list__insertion-point, | ||
.block-editor-block-drop-zone, | ||
.reusable-block-indicator, | ||
.block-list-appender { | ||
display: none; | ||
} | ||
|
||
&.is-scaled { | ||
> div { | ||
transform: scale(0.9); | ||
transform-origin: center top; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it was introduced here, but while the preview shows well in most contexts, in the block transform menu, I see horizontal scroll:
From some inspection, it seems to be because of the negative offsets from pseudo-elements surrounding the block in the block list:
gutenberg/packages/block-editor/src/components/block-list/style.scss
Lines 1120 to 1122 in be671ea
I'd think that ideally, we could have some concept of a "read-only" block list rendering, since these previews have no use for all of the extra control elements of a block.
But I comment here because it seems like you had to deal with this anyways. Maybe something we can be addressing with
overflow: hidden
?(Aside: I find it helps to use the "Show Scroll Bars: Always" option in macOS, to help discover these sorts of issues: https://cloudup.com/cqF641QROEe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a good answer here, This was a very complex PR and I know that it can be tricky to get right on all situations.
I see this mentioned over and over and I think we'll probably need that for several things (previews and also some special FSE mode where some blocks are "enabled" while others are not)
This looks specific to the hover and selected styles, so yeah if we can move this out of the flow somehow (overflow: hidden maybe but I'd be very cautious), it could work or just remove the selected/hover styles entirely in preview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Honestly, I don't remember exactly the purposes of introducing these resets here. As Riad mentioned, it's a very complex PR and any modification can affect other instances where the preview is being used. AMost of these resets are usually an attempt to make cross-theme support.
read-only
,view
, etc. have been talked as well. I thought that even we could remove all elements which are not needed just for the preview (appender, drop-zone, etc) in order to make the preview process more efficient.