-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds all allowed innerblocks to the inspector animation experiment (#…
…47834) * adds all allowed innerblocks to the inspector animation experiment * don't animate unless we're in a navigation block * make the nav block a config * Update packages/block-editor/src/components/block-inspector/index.js Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * remove redundant comment * be more clear block animation is temporary --------- Co-authored-by: scruffian <ben@scruffian.com>
- Loading branch information
1 parent
f83d85c
commit 67ce029
Showing
3 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/block-editor/src/components/block-inspector/useBlockInspectorAnimationSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters