Add the side bar with all the “complementary area” added complexity

This commit is contained in:
jordi fita mas 2024-06-14 20:36:37 +02:00
parent 79bdee916b
commit 9916afc768
2 changed files with 42 additions and 5 deletions

View File

@ -1,17 +1,37 @@
import { useSelect } from '@wordpress/data';
import { InterfaceSkeleton, FullscreenMode } from '@wordpress/interface';
import { useSelect, useDispatch } from '@wordpress/data';
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 Sidebar from './Sidebar';
export default function BlockEditor() {
const styles = useSelect(( select ) => {
const { getSettings } = select( blockEditorStore );
return getSettings().styles;
const { styles, sidebarIsOpen, hasBlockSelected } = useSelect(( select ) => {
const { getSettings, getBlockSelectionStart } = select( blockEditorStore );
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 (
<>
<FullscreenMode isActive={ true } />
<Sidebar />
<InterfaceSkeleton
content={ <BlockCanvas height="100%" styles={styles} /> }
sidebar={ sidebarIsOpen && <ComplementaryArea.Slot scope="tipus/editor" /> }
footer={ <BlockBreadcrumb /> }
/>
</>

17
editor/Sidebar.jsx Normal file
View File

@ -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>
);
}