-
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
Adds all allowed innerblocks to the inspector animation experiment #47834
Changes from all commits
8aa958e
a8091a7
d4fa60a
617bfb1
fc8deba
4d6ad96
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
export default function useBlockInspectorAnimationSettings( | ||
blockType, | ||
selectedBlockClientId | ||
) { | ||
return useSelect( | ||
( select ) => { | ||
if ( blockType ) { | ||
const globalBlockInspectorAnimationSettings = | ||
select( blockEditorStore ).getSettings() | ||
.blockInspectorAnimation; | ||
|
||
// Get the name of the block that will allow it's children to be animated. | ||
const animationParent = | ||
globalBlockInspectorAnimationSettings?.animationParent; | ||
|
||
// Determine whether the animationParent block is a parent of the selected block. | ||
const { getSelectedBlockClientId, getBlockParentsByBlockName } = | ||
select( blockEditorStore ); | ||
const _selectedBlockClientId = getSelectedBlockClientId(); | ||
const animationParentBlockClientId = getBlockParentsByBlockName( | ||
_selectedBlockClientId, | ||
animationParent, | ||
true | ||
)[ 0 ]; | ||
|
||
// If the selected block is not a child of the animationParent block, | ||
// and not an animationParent block itself, don't animate. | ||
if ( | ||
! animationParentBlockClientId && | ||
blockType.name !== animationParent | ||
) { | ||
return null; | ||
} | ||
|
||
return globalBlockInspectorAnimationSettings?.[ | ||
blockType.name | ||
]; | ||
} | ||
return null; | ||
}, | ||
[ selectedBlockClientId, blockType ] | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,11 +170,24 @@ export const SETTINGS_DEFAULTS = { | |
__unstableGalleryWithImageBlocks: false, | ||
__unstableIsPreviewMode: false, | ||
|
||
// This setting is `private` now with `lock` API. | ||
// These settings will be completely revamped in the future. | ||
// The goal is to evolve this into an API which will instruct | ||
// the block inspector to animate transitions between what it | ||
// displays based on the relationship between the selected block | ||
// and its parent, and only enable it if the parent is controlling | ||
// its children blocks. | ||
blockInspectorAnimation: { | ||
animationParent: 'core/navigation', | ||
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 haven't dug deep into 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. It's only used for the navigation block at the moment. I am aware that this implementation won't scale well, but since it's locked I wasn't too worried about that. We can improve it when we need it to do 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. If this API is tightly coupled with Navigation block, have you explored a way to handle this 'closer' to the block? Also you have explored and still think it should be here, should we rename to reflect that? 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 APi should work for all blocks that have children which are controlled by the parent in various ways. For now the two examples are navigation block and the pattern block in content only mode. It is not an API specific to the navigation block and it should not be at the block level. @ntsekouras which part do you think should be extracted to a hook? |
||
'core/navigation': { enterDirection: 'leftToRight' }, | ||
'core/navigation-submenu': { enterDirection: 'rightToLeft' }, | ||
'core/navigation-link': { enterDirection: 'rightToLeft' }, | ||
'core/search': { enterDirection: 'rightToLeft' }, | ||
'core/social-links': { enterDirection: 'rightToLeft' }, | ||
'core/page-list': { enterDirection: 'rightToLeft' }, | ||
'core/spacer': { enterDirection: 'rightToLeft' }, | ||
'core/home-link': { enterDirection: 'rightToLeft' }, | ||
'core/site-title': { enterDirection: 'rightToLeft' }, | ||
'core/site-logo': { enterDirection: 'rightToLeft' }, | ||
}, | ||
|
||
generateAnchors: false, | ||
|
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.
This is something exhaustive deps linter complained about, and it was right.