-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Simplify insertion point #30301
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
Simplify insertion point #30301
Conversation
| Sets the insertion point and shows it to users. | ||
|
|
||
| Components like <Inserter> will default to inserting blocks at this point. | ||
| Returns an action object used in signalling that the insertion point should |
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.
Please note that I did a partial revert of 7f1fac9.
| case 'INSERT_BLOCKS': | ||
| case 'REMOVE_BLOCKS': | ||
| case 'REPLACE_BLOCKS': | ||
| return defaultValue; |
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.
Note that this is no longer needed. The inserter state will be overwritten when the inserter closes or reopens.
|
Size Change: +87 B (0%) Total Size: 1.47 MB
ℹ️ View Unchanged
|
| const onBrowseAll = () => { | ||
| __unstableSetInsertionPoint( rootClientId, blockIndex ); | ||
| setInserterIsOpened( true ); | ||
| setInserterIsOpened( { rootClientId, blockIndex } ); |
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.
Worth noting that this is an experimental API (getSettings().__experimentalSetIsInserterOpened).
|
From memory there's a lot of edge cases here to do with inner blocks and different editor contexts (post editor, site editor, widgets editor). I think that the testing steps I wrote in #26443 covers them. |
1c0334e to
5be76d8
Compare
| // the insertion point can work as expected | ||
| const onBrowseAll = () => { | ||
| __unstableSetInsertionPoint( rootClientId, blockIndex ); | ||
| setInserterIsOpened( true ); |
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 found it also strange that we'd have to set the insertion point, while no insertion point should show. I guess that's why the show/hide actions were added.
|
All tests are passing. I also tested the steps in #26443 and everything works fine. @youknowriad @noisysocks @talldan Could you have another look at this? |
| if ( insertionIndex ) { | ||
| // Insert into a specific index. | ||
| _destinationIndex = insertionIndex; | ||
| } else if ( clientId ) { |
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 at some point it would be nice to clean this up and remove isAppender and clientID in favour of insertionIndex.
| return <InserterSidebar />; | ||
| return ( | ||
| <InserterSidebar | ||
| rootClientId={ isInserterOpen?.rootClientId } |
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 seems weird that isInserterOpen is not a boolean. Can we rename the selectors? Are these stable?
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 setting (action) is exposed as experimental (__experimentalSetIsInserterOpened), but the selector was not. I created a separate experimental selector to get the insertion point and make sure that the isInserterOpen selector remains boolean.
youknowriad
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.
Other than the naming thing, this seems to work well, I tried all the combination I can think of and it works properly.
4a329a6 to
98bb5aa
Compare
Description
Blocking #29933 and #30285.
This PR seeks to undo some of the complexity introduced in #26443 for the insertion point. The insertion point used to be a simple visible indicator for where block will be inserted/dropped etc., but now it is also used for passing context to the main/library inserter, even when the insertion point is not visible.
This new behaviour is getting in the way when trying to use the insertion point action for other things like drop and the in-between inserter. Showing an insertion point at a different position will result in the loss of context for the main block library.
The solution I'm proposing is to pass the position data directly to the main library inserter when opening it.
It's worth noting that there's already a precedent for passing an index to the experimental
<Library>component, which we're reusing here.gutenberg/packages/edit-widgets/src/components/layout/interface.js
Lines 90 to 94 in 3da717b
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.jsfiles for terms that need renaming or removal).