-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Inserter: Enable inserting a block using the inserter #407
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
Conversation
555b588 to
6360b52
Compare
editor/components/inserter/menu.js
Outdated
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 was thinking it might be helpful to move this logic into the block API, like:
wp.blocks.createBlock( 'core/text', {
content: 'Hello World'
} );What do you think?
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.
Good idea!! 👍
editor/components/inserter/menu.js
Outdated
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.
Total aside: How do you feel about a keywords property for a block that allows it to be discovered by more than just its title? Do we also want to search slug?
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 agree this is too limited, we need to think more about how we search for blocks. Keywords seem like a good idea, we could consider adding a description to the blocks.
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.
Another note is we should probably extract some of these utilities as standalone functions and unit test them. Fine for another pull request.
editor/components/inserter/menu.js
Outdated
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.
Should we clear the current filter value?
editor/state.js
Outdated
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 not here, but we'll need to consider how to insert a block at a specific index, supporting behavior like in this mockup:
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 think this action can be extended. For example, in #409 I'm adding an option "after" property to this action to insert after a specific block.
|
When inserting a new text block, there's an error logged to the console from TinyMCE: Another oddity which I expect is a consequence of the above error is that it's not possible to unselect the newly added text block. |
6360b52 to
2e0a219
Compare
|
I addressed the feedback in e943478 we now have a new utility |
2e0a219 to
e943478
Compare
- Adding the INSERT_BLOCK action - Simplifying the hovered and selected reducers
9afb8b6 to
98fbaa5
Compare
aduth
left a comment
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.
Works great 👍 Nice work.
| attributes: getBlockAttributes( blockNode, settings ) | ||
| } ); | ||
| memo.push( | ||
| createBlock( blockType, getBlockAttributes( blockNode, settings ) ) |
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.
Cool re-use 👍
editor/components/inserter/menu.js
Outdated
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.
Another note is we should probably extract some of these utilities as standalone functions and unit test them. Fine for another pull request.

In this PR, I'm enabling the possibility to effectively add new blocks using the inserter. In the same time I'm adding the "filtering" logic. You can now filter the inserter by filling the search input.
Also on a technical side: