-
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
Improve Custom HTML Block so preview mode persists on save. #46834
base: trunk
Are you sure you want to change the base?
Conversation
Just realized there was an older/abandoned PR for this here: #40913 Reading through some comments I saw there was another thought of making the Raw HTML visible on select and preview visible when not selected. I really like that idea and can adjust my PR to handle it that way if more folks think that is the better approach. Thx! Update: Added a new PR for using on select rather than buttons in case this is the preferred approach: #46836 |
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.
@mauteri This works as described. I really like this solution over the linked PR.
@alexstine anything else needed before this can be merged? The failing pipeline for React Native E2E Tests (Android) isn't required and doesn't appear to be related to my code, but not sure if this is why PR hasn't been merged. Let me know. Thx! |
+1 for this feature. I also prefer |
I can make this change. |
Updated for @kohheepeace suggestion and did small cleanup. Let me know if anyone else has anymore feedback. Thx! |
@carolinan Do you see anything else that should be addressed for this change? I tested the functionality and it works well. I know you have done some work with blocks and this is a newer area of the editor dev for me. Thanks. |
Since there is a change in the attributes, a deprecation of the block necessary in this case isn't it? Just modify I am not completely understand the deprecation of the block, but I am curious about this. |
The PR works well in my test. |
Awesome, thanks @carolinan! |
Maybe one more from @talldan or @tellthemachines ? Not sure how depreciation works in blocks either. |
Hi @alexstine not sure why deprecation would be needed or considered here? Maybe I'm not fully understanding, so if I am please let me know what I'm missing or not understanding. Thx! |
Sorry. I was mistaken. 😿 When I run the following command npm run test:unit test/integration/full-content/ I got a validation error, so I thought I needed a new However, this Validation error was corrected by the following command npm run fixtures:regenerate which updates So, I think this PR is to be merged 🚀🚀🚀🚀 cc: mention to @talldan @glendaviesnz who seems to be familiar with block deprecation just in case. |
Thanks for pinging me. I don't think it requires a deprecation–only changes to block On the feature itself, I'm personally unsure if this should be saved as an attribute. One consideration is that when the Site Editor is in browse mode, the HTML block should now probably always show its preview instead of its code. It might be best to start with that feature first. I'm not sure if there's scope to introduce a browse mode to the post editor too, that's an interesting question. The issue hasn't had much feedback from design contributors, so I'd suggest seeking that first before shipping an implementation. |
Maybe it is as simple as while in preview mode, the text of the other button could be "Edit HTML" instead of "HTML" |
I think that makes is very clear. |
Could be just |
+1 Need this so badly! |
I've been meaning to get back to this! I'll look to continue the effort if someone else doesn't pick it up. |
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @kohheepeace, @wilnau-design, @zachalig. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
Hi, I finally came back to this pull request to hopefully finish things up with the feedback received. In the latest updates I did the following.
|
Hi, I just wanted to follow up on this PR as I made updates some time ago. Is there any additional feedback or could this code be merged? Thanks! |
+1 Would love to see this merged. We have some official HTML footers I have to use on all sites and it would be nice to be able to see them represented properly in the editor. |
Hi @jasmussen I just wanted to bring this PR to your attention again. I added the hover feature like you illustrated above and curious if this is enough approve and merge. Thanks! |
Thanks for the ping again, thanks for the patience. Thanks also for trying the purple hover style. There's still something to that idea, around making editability clearer. However in trying the branch just now, it doesn't feel as consistent or similar with synced patterns and template parts, as I had hoped. So I think we should remove those hover styles again. I don't want to be the blocker for this PR, so I'll defer to others, including @carolinan, on whether this PR can land as-is without that hover style. But the remaining issue I found was with interactivity and links. Quick GIF: Shown here, simple HTML markup in the preview state to show "Hello world". When you click to preview it, and then click the link, the website linked loads inside a tiny sliver of an iframe for rendering the code. Visiting the link both feels a bit unexpected since you're in an editor where that's not what happens with other links, it's especially unexpected when the result loads in a tiny iframe. Finally you could write markup that's just one big link for the whole visible area, and then you wouldn't be able to click the block to select it, you'd instead click the link to go there. The solution I could see here is to wrap the entire preview inside a The tradeoff would be that any interactivity you're building in the custom HTML would only be testable on the frontend. But maybe that would be fine? After all, if you want this feature so you can add a linked SVG logo, I suspect you'd want to be able to click it to select it. Let me know what you think! And thanks for contributing. |
Thanks @jasmussen! I'll review your notes above and make some adjustments. I'll also remove the hover state. Thanks! |
@mauteri @jasmussen Sorry, but please do not use the Thanks. |
Okay, understood. I'm unsure how to move this PR forward, and I'll defer to the rest of you. |
Cool thx @alexstine i'll remove that as well. |
package.json
Outdated
@@ -375,8 +375,7 @@ | |||
"npm run docs:api-ref", | |||
"npm run docs:blocks", | |||
"npm run docs:theme-ref", | |||
"node ./bin/api-docs/are-api-docs-unstaged.js", | |||
"node ./bin/packages/lint-staged-typecheck.js" |
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.
@alexstine @carolinan either of you having issues with lint-staged-typecheck
? I tried everything I can think of and it's failing when I try to commit (in places outside of my code). Any thoughts? Thanks!
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.
Maybe merge upstream trunk into your branch and npm i && npm ci.
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 @alexstine, it was up to date with trunk. I also tried blowing away node_modules and re-installing. I didn't run npm i && npm ci
specifically, but that appeared to work today. 🤷🏻♂️ Thx again.
@alexstine @jasmussen I think this is ready again. Is there anything else preventing this from being merged? Thanks! |
I just tested this and it is working as explained in the testing instructions. However, I am a bit concerned with the overall user experience challenges. The primary goal is to persist the last state for the HTML block that the user saved, either: Preview or HTML. During my testing I utilized the User Switching plugin to test how the state persisted between different users. I edited a post as an Admin and saved the state as 'Preview'. I then switched to an Editor role user, edited the same post, and the 'Preview' state was offered. I was mostly curious how this state might impact different users (and their experiences). It is difficult to assert whether this PR and its primary goal are impacting (positively or negatively) an overall experience in the editorial flow. Ultimately, it does solve the persistence of state for the HTML block, but it could be misleading for users to be unaware that the HTML block is actually editable if always offered the Preview state. I would encourage further insight and user experience feedback from other folks. |
Thanks @colorful-tones for your feedback. It was great chatting with you at WordCamp Montclair yesterday, hope you had a good time.
I could see some initial confusion when content looks like it should be able to be editable while in preview mode. I'm thinking text content in particular. For a person that uses and understands block editor though, selecting the HTML block does clearly mark it as |
What?
This PR is to maintain preview status on HTML Block when saved, so on refresh if the HTML block was saved in preview mode, it will load in preview mode. If it was saved in raw HTML mode, it will load in raw HTML mode.
Addresses #40913
Why?
Raw HTML is sometimes unavoidable and can be scary or jarring to the enduser. In order to maintain a what-you-see-is-what-you-get feel in the block editor, it is important to have the option to see Raw HTML in preview mode where it can look more at home with the rest of the blocks/content in the editor.
How?
This is just a small change to the block making
preview
an attribute of the Custom HTML block. Now its state is saved with the block and can easily be loaded in preview mode or raw HTML mode.Testing Instructions
Testing Instructions for Keyboard
N/A. No changes were made to the general UI of the block.