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 { 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 /> }
/> />
</> </>

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