-
Notifications
You must be signed in to change notification settings - Fork 3
Native Inserter: Implement block insertion #199
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
f5a1435 to
a971b45
Compare
| // Capture the selected block ID before showing the inserter | ||
| // (the editor will lose focus when the modal appears) | ||
| Task { @MainActor in | ||
| let selectedBlockID = await getSelectedBlockID() |
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.
The alternative was to memorize the selectedBlockID inside the editor, but I thought it would be more flexible to provide the native side with a capability to get the ID of the currently selected block and a way to insert block at any position.
| if ( isInserterOpened ) { | ||
| setIsInserterOpened( false ); | ||
| } | ||
| onTouchEnd={ ( e ) => { |
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.
Button with onTouchEnd is what works on mobile without losing focus.
d332b04 to
e714b40
Compare
848d34d to
932ffc4
Compare
dcalhoun
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.
Thank you for putting this together. It tested relatively well for me. I left a few comments for us to consider. Curious of your thoughts.
|
I'm putting it back into draft. I've research the existing inserters and they all use the reusable I will also look into a way to better architect the interaction between web and native. On a high level, I want to create all the requires context by the inserter, including the callbacks, and pass it a a separate JS object to the native side that it could invoke (as opposed to defining these methods on cc @dcalhoun – let me know if it sounds like a plan. |
|
@kean overall, that makes sense to me.
Avoiding |
|
I made a significant progress by using ScenariosTop-Level Insertion
Composite Blocks
Contextual Blocks
Known Issues
RecordingScreen.Recording.2025-10-24.at.4.24.04.PM.movCurrent LimitationsThe main challenges I encountered:
I'll might need some help with it. I'm going to wrap up for today.
I decided to keep to simple. If there is more than one scenario where we need a generalized solution, then maybe it would be a good time to consider it. |
c75dc74 to
103d411
Compare
|
I made a couple of small changes:
I think it's now in a mergeable state with a caveat that we need to figure out the best way to use private APIs. I also logged an additional issue: CMM-903: Performance: Inserter recomputes the list of blocks on every change in the editor. |
dcalhoun
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 well from my testing. Code looks good too. I left a few suggestions for your consideration.
* Add support for block variants * Rename BlockType * Capitlize ID * Update src/components/native-block-inserter-button/index.jsx Co-authored-by: David Calhoun <github@davidcalhoun.me> * Native Inserter: Improve ordering of blocks and more (#206) * Add a note about serializeBlocksForNative * Remove now redundant core/missing check * Move ordering to the JS land * Further refactoring * Pass displayName for Text * Localize categories * Extend most used blocks * Add gbk-most-used as a separate section * Add support for disabling blocks * Collapse long sections * Update the order of embeds * Fix linter errors --------- Co-authored-by: David Calhoun <github@davidcalhoun.me>
What?
inserterattributeHow?
(see comments)
Testing Instructions
Note: there may be other scenarios I'm not thinking of, including some of the composite blocks like "Gallery" or "Columns". For "Columns", I already opened CMM-880.
Screenshots or screencast
Screen.Recording.2025-10-22.at.9.12.53.AM.mov