-
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.
Add block inspector to the widget screen (#16203)
- Loading branch information
1 parent
9b8714e
commit 64a8a7c
Showing
7 changed files
with
119 additions
and
9 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
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
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
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 |
---|---|---|
|
@@ -39,4 +39,8 @@ | |
background: $light-gray-200; | ||
} | ||
} | ||
|
||
.block-editor-block-inspector__card { | ||
margin: 0; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
packages/edit-widgets/src/components/widget-area/selection-observer.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,54 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* Component which calls onBlockSelected prop when a block becomes selected. It | ||
* can be used to ensuring that only one block appears as selected | ||
* when multiple editors exist in a page. | ||
* | ||
* @type {WPComponent} | ||
*/ | ||
|
||
class SelectionObserver extends Component { | ||
componentDidUpdate( prevProps ) { | ||
const { | ||
hasSelectedBlock, | ||
onBlockSelected, | ||
isSelectedArea, | ||
clearSelectedBlock, | ||
} = this.props; | ||
|
||
if ( hasSelectedBlock && ! prevProps.hasSelectedBlock ) { | ||
onBlockSelected(); | ||
} | ||
|
||
if ( ! isSelectedArea && prevProps.isSelectedArea ) { | ||
clearSelectedBlock(); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const { hasSelectedBlock } = select( 'core/block-editor' ); | ||
|
||
return { | ||
hasSelectedBlock: hasSelectedBlock(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
const { clearSelectedBlock } = dispatch( 'core/block-editor' ); | ||
|
||
return { | ||
clearSelectedBlock, | ||
}; | ||
} ), | ||
] )( SelectionObserver ); |
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