-
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
Add "Convert to blocks" option in HTML block #7667
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b59f27d
Allow converting core/html block to blocks
oandregal 6fe9878
Add unfiltered_html capability to targetSchema
oandregal 138c7f1
Take capability from _links property in post object
oandregal d0e747e
Add canUserUseUnfilteredHTML selector
oandregal f9ad80b
Remove unused import
oandregal edbf3a3
Add selector tests
oandregal 7a44a2e
Add REST API tests
oandregal 8d79467
Add REST API tests for multisite
oandregal ba4532c
Make php linter happy
oandregal 570aa39
Fix jsdoc comment
oandregal 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { IconButton } from '@wordpress/components'; | ||
import { rawHandler, getBlockContent } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/element'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
export function HTMLConverter( { block, onReplace, small, canUserUseUnfilteredHTML, role } ) { | ||
if ( ! block || block.name !== 'core/html' ) { | ||
return null; | ||
} | ||
|
||
const label = __( 'Convert to blocks' ); | ||
|
||
const convertToBlocks = () => { | ||
onReplace( block.uid, rawHandler( { | ||
HTML: getBlockContent( block ), | ||
mode: 'BLOCKS', | ||
canUserUseUnfilteredHTML, | ||
} ) ); | ||
}; | ||
|
||
return ( | ||
<IconButton | ||
className="editor-block-settings-menu__control" | ||
onClick={ convertToBlocks } | ||
icon="screenoptions" | ||
label={ small ? label : undefined } | ||
role={ role } | ||
> | ||
{ ! small && label } | ||
</IconButton> | ||
); | ||
} | ||
|
||
export default compose( | ||
withSelect( ( select, { uid } ) => { | ||
const { getBlock, getCurrentPostType, canUserUseUnfilteredHTML } = select( 'core/editor' ); | ||
return { | ||
block: getBlock( uid ), | ||
postType: getCurrentPostType(), | ||
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => ( { | ||
onReplace: dispatch( 'core/editor' ).replaceBlocks, | ||
} ) ), | ||
)( HTMLConverter ); |
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
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
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.
Is it possible to move it to
withDispatch
or is there any blocker?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 guess it could be refactored, indeed. I don't mind one-way or the other and did that to mimic what existed in UnknownConverter. I'll leave it as it is, we can always refactor both later if necessary.
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's a leaf component inside the dropdown which is not rendered by default, so this shouldn't impact performance. In general, having a local function inside
render
method isn't expected because it causes unnecessary re-renders.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.
Grzegorz, #7885 follows up the work on this PR and addresses some ideas you mentioned in this thread (share common code, move to
withDispatch
).