-
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
Move insertionPoint state to block-editor store/rename existing insertionPoint to insertionCue #65098
Move insertionPoint state to block-editor store/rename existing insertionPoint to insertionCue #65098
Changes from all commits
3e599d2
458c376
aae2353
269fe53
b17df45
2462257
b06bddd
8136045
a551d83
a1765fe
5959cd8
3705906
72e8309
355a061
136c9a3
867641e
bfff2d4
4f262d1
24a2aec
8d6410c
28e1596
a21fe77
98cf472
d037772
8c48524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,6 +359,20 @@ export function expandBlock( clientId ) { | |
}; | ||
} | ||
|
||
/** | ||
* @param {Object} value | ||
* @param {string} value.rootClientId The root client ID to insert at. | ||
* @param {number} value.index The index to insert at. | ||
* | ||
* @return {Object} Action object. | ||
*/ | ||
export function setInsertionPoint( value ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this different than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so If I'm understand properly we have:
is that correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarifying my understanding more: The "inserter insertion point" state was being set in the "editor" package because the "Inserter" component has a "rootClientId" and "clientId" props, so this one is controlled externally, I guess the idea is that at the same time, you can potentially render different inserters with different default insertion points. The current PR seems to move the state to "block-editor" but the props remain so it's still "externally" controlled right? So why the move to "block-editor" state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, this only shows where the blue line will get shown (what I will now refer to as the insertion cue for clarity). We don't have a true insertion point at the moment other than passing an insertion point to
Exactly. No props were removed and a manually passed insertion point to the inserter will still be respected. We needed to move it to the block-editor state to clear the insertion point when a block is selected. This reverted PR demos more about why we need this. Code-wise, the inserter was built with a static insertion point in mind. Now the inserter can be open with selection on the block canvas happening, meaning the insertion point can be updated while the inserter is still open. The problem with the PR above is that it relied on I wrote an overview of the Insertion API current state here: #65290 |
||
return { | ||
type: 'SET_INSERTION_POINT', | ||
value, | ||
}; | ||
} | ||
|
||
/** | ||
* Temporarily modify/unlock the content-only block for editions. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,3 +698,13 @@ export function getClosestAllowedInsertionPointForPattern( | |
const names = getGrammar( pattern ).map( ( { blockName: name } ) => name ); | ||
return getClosestAllowedInsertionPoint( state, names, clientId ); | ||
} | ||
|
||
/** | ||
* Where the point where the next block will be inserted into. | ||
* | ||
* @param {Object} state | ||
* @return {Object} where the insertion point in the block editor is or null if none is set. | ||
*/ | ||
export function getInsertionPoint( state ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this different than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference for you between "insertion cue" and "insertion position". If we're showing a different insertion cue than the actual insertion point, then we have problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference is that one is an index and the other one is an UI element? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both are state for me. The UI element is just a reflexion of a state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it gets tricky when you include drag and drop. You’re showing an insertion cue at a location that may be different than what is set via selection. If you update that point on hover via drag and drop, this is the correct behavior for the insertion cue/insertion point, but a lot of the things built off using it were not intended to be updating their insertion point that often. So, I think insertion cue of where insertion will happen and should rely on insertion point if set, but the insertion cue should be able to show separate from the insertion point on instances like drag and drop. Hovering the canvas should not be updating the insertion point, it should be updating a cue about where you might be able to insert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree with this, but it doesn't really explain the PR to me. we were using So I'm still not clear what this PR is trying to accomplish aside moving things around and potentially making them more complicated. |
||
return state.insertionPoint; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1601,7 +1601,7 @@ export function blocksMode( state = {}, action ) { | |
* | ||
* @return {Object} Updated state. | ||
*/ | ||
export function insertionPoint( state = null, action ) { | ||
export function insertionCue( state = null, action ) { | ||
switch ( action.type ) { | ||
case 'SHOW_INSERTION_POINT': { | ||
const { | ||
|
@@ -2066,7 +2066,7 @@ export function hoveredBlockClientId( state = false, action ) { | |
* @param {boolean} state Current state. | ||
* @param {Object} action Dispatched action. | ||
* | ||
* @return {boolean} Updated state. | ||
* @return {number} Updated state. | ||
*/ | ||
export function zoomLevel( state = 100, action ) { | ||
switch ( action.type ) { | ||
|
@@ -2079,6 +2079,25 @@ export function zoomLevel( state = 100, action ) { | |
return state; | ||
} | ||
|
||
/** | ||
* Reducer setting the insertion point | ||
* | ||
* @param {boolean} state Current state. | ||
* @param {Object} action Dispatched action. | ||
* | ||
* @return {Object} Updated state. | ||
*/ | ||
export function insertionPoint( state = null, action ) { | ||
switch ( action.type ) { | ||
case 'SET_INSERTION_POINT': | ||
return action.value; | ||
case 'SELECT_BLOCK': | ||
return null; | ||
Comment on lines
+2094
to
+2095
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear the insertion point after a new block selection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my testing, the vertical displacement is still visible after selecting a different block. |
||
} | ||
|
||
return state; | ||
} | ||
|
||
const combinedReducers = combineReducers( { | ||
blocks, | ||
isDragging, | ||
|
@@ -2092,6 +2111,7 @@ const combinedReducers = combineReducers( { | |
blocksMode, | ||
blockListSettings, | ||
insertionPoint, | ||
insertionCue, | ||
template, | ||
settings, | ||
preferences, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
showBlockInterface, | ||
expandBlock, | ||
__experimentalUpdateSettings, | ||
setInsertionPoint, | ||
setOpenedBlockSettingsMenu, | ||
startDragging, | ||
stopDragging, | ||
|
@@ -123,4 +124,18 @@ describe( 'private actions', () => { | |
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'setInsertionPoint', () => { | ||
it( 'should return the SET_INSERTION_POINT action', () => { | ||
expect( | ||
setInsertionPoint( { | ||
rootClientId: '', | ||
index: '123', | ||
} ) | ||
).toEqual( { | ||
type: 'SET_INSERTION_POINT', | ||
value: { rootClientId: '', index: '123' }, | ||
} ); | ||
} ); | ||
} ); | ||
Comment on lines
+128
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test and all the other tests in this file aren't doing anything useful. The important thing for actions is that reducers do things based on them and the selectors read out a specific value. The parts of a store shouldn't be tested in isolation like this. It looks like you're trying to fix the breaking change that may have happened some time earlier, but updating the test and documentation isn't the way to fix it. The prior logic needs to be restored. If the tests were for the store as a whole, maybe this would have been caught. Also, to be clear, I'm suggesting moving the tests, documentation, and fixing the |
||
} ); |
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.
These are not new, just adding the documentation for things already in use.