Add the side bar with all the “complementary area” added complexity
This commit is contained in:
parent
79bdee916b
commit
9916afc768
|
@ -1,17 +1,37 @@
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { InterfaceSkeleton, FullscreenMode } from '@wordpress/interface';
|
import { useEffect } from '@wordpress/element';
|
||||||
|
import { InterfaceSkeleton, FullscreenMode, ComplementaryArea, store as interfaceStore } from '@wordpress/interface';
|
||||||
import { BlockBreadcrumb, BlockCanvas, store as blockEditorStore } from '@wordpress/block-editor';
|
import { BlockBreadcrumb, BlockCanvas, store as blockEditorStore } from '@wordpress/block-editor';
|
||||||
|
|
||||||
|
import Sidebar from './Sidebar';
|
||||||
|
|
||||||
export default function BlockEditor() {
|
export default function BlockEditor() {
|
||||||
const styles = useSelect(( select ) => {
|
const { styles, sidebarIsOpen, hasBlockSelected } = useSelect(( select ) => {
|
||||||
const { getSettings } = select( blockEditorStore );
|
const { getSettings, getBlockSelectionStart } = select( blockEditorStore );
|
||||||
return getSettings().styles;
|
const { getActiveComplementaryArea } = select( interfaceStore );
|
||||||
|
return {
|
||||||
|
styles: getSettings().styles,
|
||||||
|
hasBlockSelected: !!getBlockSelectionStart(),
|
||||||
|
sidebarIsOpen: !!getActiveComplementaryArea( 'tipus/editor' )
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const { enableComplementaryArea, disableComplementaryArea } = useDispatch( interfaceStore );
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasBlockSelected) {
|
||||||
|
enableComplementaryArea( 'tipus/editor', 'edit-post/block' );
|
||||||
|
} else {
|
||||||
|
disableComplementaryArea( 'tipus/editor' );
|
||||||
|
}
|
||||||
|
}, [ hasBlockSelected ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FullscreenMode isActive={ true } />
|
<FullscreenMode isActive={ true } />
|
||||||
|
<Sidebar />
|
||||||
<InterfaceSkeleton
|
<InterfaceSkeleton
|
||||||
content={ <BlockCanvas height="100%" styles={styles} /> }
|
content={ <BlockCanvas height="100%" styles={styles} /> }
|
||||||
|
sidebar={ sidebarIsOpen && <ComplementaryArea.Slot scope="tipus/editor" /> }
|
||||||
footer={ <BlockBreadcrumb /> }
|
footer={ <BlockBreadcrumb /> }
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
|
import { ComplementaryArea, store as interfaceStore } from '@wordpress/interface';
|
||||||
|
import { Panel } from '@wordpress/components';
|
||||||
|
import { BlockInspector } from '@wordpress/block-editor';
|
||||||
|
|
||||||
|
export default function Sidebar () {
|
||||||
|
return (
|
||||||
|
<ComplementaryArea
|
||||||
|
scope="tipus/editor"
|
||||||
|
identifier="edit-post/block"
|
||||||
|
>
|
||||||
|
<Panel>
|
||||||
|
<BlockInspector />
|
||||||
|
</Panel>
|
||||||
|
</ComplementaryArea>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue