From acda73e0c65f7650a573f65fce44fd2bb79c1fa6 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 9 Sep 2024 14:38:24 +0100 Subject: [PATCH] Implement in editor package --- packages/editor/src/hooks/block-toolbar.js | 75 ++++++++++++++++++++++ packages/editor/src/hooks/index.js | 1 + 2 files changed, 76 insertions(+) create mode 100644 packages/editor/src/hooks/block-toolbar.js diff --git a/packages/editor/src/hooks/block-toolbar.js b/packages/editor/src/hooks/block-toolbar.js new file mode 100644 index 00000000000000..881b4073aaaf04 --- /dev/null +++ b/packages/editor/src/hooks/block-toolbar.js @@ -0,0 +1,75 @@ +/** + * WordPress dependencies + */ +import { addFilter } from '@wordpress/hooks'; +import { createHigherOrderComponent } from '@wordpress/compose'; +import { __unstableBlockToolbarLastItem as BlockToolbarLastItem } from '@wordpress/block-editor'; +import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; +import { settings as settingsIcon } from '@wordpress/icons'; +import { store as interfaceStore } from '@wordpress/interface'; +import { useDispatch, useSelect } from '@wordpress/data'; +import { __ } from '@wordpress/i18n'; + +/** + * Override the default edit UI to include a new block inspector control for + * assigning a partial syncing controls to supported blocks in the pattern editor. + * Currently, only the `core/paragraph` block is supported. + * + * @param {Component} BlockEdit Original component. + * + * @return {Component} Wrapped component. + */ +const withBlockToolbar = createHigherOrderComponent( + ( BlockEdit ) => ( props ) => { + return ( + <> + + { props.isSelected && } + + ); + }, + 'withBlockToolbar' +); + +const BlockSidebarToggle = () => { + const { enableComplementaryArea, disableComplementaryArea } = + useDispatch( interfaceStore ); + + const isSelected = useSelect( + ( select ) => + select( interfaceStore ).getActiveComplementaryArea( 'core' ) === + 'edit-post/block', + [] + ); + + return ( + + + { + if ( isSelected ) { + disableComplementaryArea( + 'core', + 'edit-post/block' + ); + } else { + enableComplementaryArea( + 'core', + 'edit-post/block' + ); + } + } } + /> + + + ); +}; + +addFilter( + 'editor.BlockEdit', + 'core/editor/with-block-toolbar', + withBlockToolbar +); diff --git a/packages/editor/src/hooks/index.js b/packages/editor/src/hooks/index.js index 6001d53f65c103..2bcb13000c9904 100644 --- a/packages/editor/src/hooks/index.js +++ b/packages/editor/src/hooks/index.js @@ -5,3 +5,4 @@ import './custom-sources-backwards-compatibility'; import './default-autocompleters'; import './media-upload'; import './pattern-overrides'; +import './block-toolbar';