-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add UI for unregistered block types #8274
Conversation
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.
Design needs to if possible reflect the proposed design. This seems to add a different style.
d276d2d
to
59811a0
Compare
Thanks for taking a look, @karmatosed.
Yeah, I used the same In a previous comment, you mentioned:
Was this referring to our other notices like this one, and if so, would you be up for pointing me to the other issue that deals with the notice style so I can be sensitive to what we're doing there? Regarding the design you shared above (and in the originating issue):
|
4518c16
to
d7d1b34
Compare
I made some updates in response to another design review with @karmatosed on Friday. We'd like to emphasize that this is a warning and reduce the presence of block UI around the warning. To this end, the latest:
Here's what the latest looks like: Note that the action buttons now run under the bottom of the text as they do for our other warnings when the text is long enough to cause the buttons to move to another flex row. What do you think, @karmatosed? |
There is a CSS outline transition bug that needs fixed and a related |
The outline transition is now fixed. |
@brandonpayton thanks for this iteration, it seems to be getting close! Is there a reason for the uneven spacing around the block? Just going back to the designs, I wonder if we can align more with those? For example do we need ellipsis to remove? Also could we have that layer over the content? |
035b790
to
0064e21
Compare
@karmatosed and I met out of band and discussed her latest feedback. Here's my understanding of the outcome:
|
There has to be an option about not doing anything. If we can map a block with a plugin, we can offer to activate it it. |
Also, if the block has HTML content we should somehow show it as it'd help the user determine what to do — should be similar to the invalid block preview. |
Hi @mtias, thanks for your feedback!
What do you think about looking at this in a follow up PR? This PR contains a change to the blocks API and would be good to get settled soon. Regarding implementation, it seems impossible to reliably map registered blocks to a plugin since blocks may be registered with arbitrary names, and there is no guarantee a
Do you have any thoughts here? Either way, I'm glad to explore this.
Which preview are you referring to? Is this the invalid block message you're talking about? On a related note, I see how the block settings menu nicely aligns with the message above and will look at fixing that for this PR. |
fb979f4
to
2712de7
Compare
Thanks for the work, @brandonpayton. So far this looks pretty good.
|
Noting a bug that is not introduced by this PR, merely highlighted by it: It's an issue in the HTML block and other users of |
attrs: attributes, | ||
innerBlocks = [], | ||
innerHTML, | ||
} = blockNode; | ||
const freeformContentFallbackBlock = getFreeformContentHandlerName(); | ||
const unregisteredFallbackBlock = getUnregisteredTypeHandlerName() || freeformContentFallbackBlock; |
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.
This initially struck me as odd, but upon testing the actual behavior, it's not bad to default to Freeform if Unregistered is not present. 👍 (Although, who'd have one and not the other?)
return ( | ||
<Fragment> | ||
<Warning actions={ actions }> | ||
<span dangerouslySetInnerHTML={ { __html: messageHTML } } /> |
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.
In this case, dangerous is actually dangerous. Localized strings should be considered equivalent to user input for sanitization purposes.
since translations should not be considered trusted strings, be sure to sanitize the result before echoing.
https://codex.wordpress.org/I18n_for_WordPress_Developers#HTML
Related: #9846
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.
Dang, I missed this one. Yes.
Since the only markup in the string is the <code>
tag, we can just drop it. I'll start a branch.
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.
-> #10626
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.
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.
since translations should not be considered trusted strings, be sure to sanitize the result before echoing.
FWIW this isn't entirely accurate. WordPress.org treats stranslations as trusted strings.
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.
FWIW this isn't entirely accurate. WordPress.org treats stranslations as trusted strings.
Is the Codex wrong then? Or is the article not applicable for core development?
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.
Both I guess :-)
|
||
attributes = attributes || {}; | ||
|
||
// Trim content to avoid creation of intermediary freeform segments. | ||
innerHTML = innerHTML.trim(); | ||
const originalUndelimitedContent = innerHTML = innerHTML.trim(); |
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.
This is too clever. I'm still not totally sure I understand why / what we're doing with this line.
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.
Thanks, @aduth. The intent wasn't cleverness, but I see what you mean. We want innerHTML
to be trimmed, and saving its value at that point is a separate concern.
The missing block needs the original undelimited content for determining whether the unregistered block has actual HTML content, for rendering a preview of the block HTML, and for converting to an HTML block. originalUndelimitedContent
exists because this pre-existing line changes the value of innerHTML
to be the delimited HTML content. The delimited content is used in saving the value of the block.
The above approach, which I am responsible for, is a bit weird IMO. It would be more straightforward to:
- Get rid of
originalUndelimitedContent
. - Stop overwriting
innerHTML
with the delimited content. - Add an
originalAttributes
attribute tocore/missing
. - Update
core/missing
to callgetCommentDelimitedContent
withoriginalName
,originalAttributes
andoriginalContent
to create the save content.
If you agree this is cleaner, I can create a follow-up PR to make the change.
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.
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 actually don't have much of a problem with originalUndelimitedContent, I just think we could be clearer / more verbose with how we assign it / document its intent.
✅ thanks
I don't love originalUndelimitedContent
but plan to leave it after documenting its purpose and separating the assignment.
I don't believe this assignment should be creating a global since innerHTML
is declared in the function scope here.
<Warning actions={ actions }> | ||
<span dangerouslySetInnerHTML={ { __html: messageHTML } } /> | ||
</Warning> | ||
<div> |
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.
For what reason do we need the div
?
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.
It isn't necessary. I initially misunderstood how <RawHTML>
worked, but see it adds its own div. I can fix this as part of the PR mentioned above or independently.
One thing I'm noticing in master, @brandonpayton, is how Unregistered blocks are not selectable:
|
Hi @mcsf, thanks for mentioning these.
This behavior was requested by @karmatosed so that the warning block wouldn't feel like a block to the user, but perhaps we can show something other than "No block selected". Do you have any thoughts on this, @karmatosed?
I am able to select both with the mouse and keyboard and can start the selection from a warning, but I see an issue with warning styles. There's a rule that applies a white background color to warnings, and that's overlapping the highlight background we've set for Here's a screen cap of my experience: This is with Chrome. In what browser are you seeing this issue? |
I created #10712 to track the selection highlight bug. |
It would've either been Firefox Developer Edition or Safari, my more commonly used browsers. |
Description
This PR adds UX for unregistered block types found in the post content.
A notice is shown in the place of each unregistered block type, offering the ability to remove the block or leave its content intact. If the core Custom HTML block is present and the unregistered block has HTML content, the notice also offers the opportunity to keep the block HTML as a Custom HTML block.
Contributes to #7811.
How has this been tested?
Unit tests. It has also been manually tested by:
Screenshots
Types of changes
Today, we have an "unknown fallback" that handles both non-block content and unregistered block types. This PR splits the fallback in two, a freeform content fallback and an unregistered type fallback, and deprecates the "unknown fallback".
In discussion with @karmatosed, we want the unregistered block fallback to appear more like a warning than a block, so we hide its block outline and override its block sidebar to appear as if no block is selected.