From e583492de76bcc283def523f97e358170a6b1124 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Thu, 2 Nov 2023 13:53:34 -0500 Subject: [PATCH] Delete unused component --- .../block-tools/selected-block-popover.js | 274 ------------------ 1 file changed, 274 deletions(-) delete mode 100644 packages/block-editor/src/components/block-tools/selected-block-popover.js diff --git a/packages/block-editor/src/components/block-tools/selected-block-popover.js b/packages/block-editor/src/components/block-tools/selected-block-popover.js deleted file mode 100644 index f456d01e267d0..0000000000000 --- a/packages/block-editor/src/components/block-tools/selected-block-popover.js +++ /dev/null @@ -1,274 +0,0 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - -/** - * WordPress dependencies - */ -import { forwardRef, useRef, useEffect } from '@wordpress/element'; -import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { useShortcut } from '@wordpress/keyboard-shortcuts'; - -/** - * Internal dependencies - */ -import BlockSelectionButton from './block-selection-button'; -import BlockContextualToolbar from './block-contextual-toolbar'; -import { store as blockEditorStore } from '../../store'; -import BlockPopover from '../block-popover'; -import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props'; -import Inserter from '../inserter'; -import { useShouldContextualToolbarShow } from '../../utils/use-should-contextual-toolbar-show'; - -function selector( select ) { - const { - __unstableGetEditorMode, - hasMultiSelection, - isTyping, - getLastMultiSelectedBlockClientId, - } = select( blockEditorStore ); - - return { - editorMode: __unstableGetEditorMode(), - hasMultiSelection: hasMultiSelection(), - isTyping: isTyping(), - lastClientId: hasMultiSelection() - ? getLastMultiSelectedBlockClientId() - : null, - }; -} - -function UnforwardSelectedBlockPopover( - { - clientId, - rootClientId, - isEmptyDefaultBlock, - capturingClientId, - __unstablePopoverSlot, - __unstableContentRef, - }, - ref -) { - const { editorMode, hasMultiSelection, isTyping, lastClientId } = useSelect( - selector, - [] - ); - - const isInsertionPointVisible = useSelect( - ( select ) => { - const { - isBlockInsertionPointVisible, - getBlockInsertionPoint, - getBlockOrder, - } = select( blockEditorStore ); - - if ( ! isBlockInsertionPointVisible() ) { - return false; - } - - const insertionPoint = getBlockInsertionPoint(); - const order = getBlockOrder( insertionPoint.rootClientId ); - return order[ insertionPoint.index ] === clientId; - }, - [ clientId ] - ); - const isToolbarForced = useRef( false ); - const { shouldShowContextualToolbar, canFocusHiddenToolbar } = - useShouldContextualToolbarShow(); - - const { stopTyping } = useDispatch( blockEditorStore ); - - const showEmptyBlockSideInserter = - ! isTyping && editorMode === 'edit' && isEmptyDefaultBlock; - const shouldShowBreadcrumb = - ! hasMultiSelection && - ( editorMode === 'navigation' || editorMode === 'zoom-out' ); - - useShortcut( - 'core/block-editor/focus-toolbar', - () => { - isToolbarForced.current = true; - stopTyping( true ); - }, - { - isDisabled: ! canFocusHiddenToolbar, - } - ); - - useEffect( () => { - isToolbarForced.current = false; - } ); - - // Stores the active toolbar item index so the block toolbar can return focus - // to it when re-mounting. - const initialToolbarItemIndexRef = useRef(); - - useEffect( () => { - // Resets the index whenever the active block changes so this is not - // persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169 - initialToolbarItemIndexRef.current = undefined; - }, [ clientId ] ); - - const popoverProps = useBlockToolbarPopoverProps( { - contentElement: __unstableContentRef?.current, - clientId, - } ); - - if ( showEmptyBlockSideInserter ) { - return ( - -
- -
-
- ); - } - - if ( shouldShowBreadcrumb || shouldShowContextualToolbar ) { - return ( - - { shouldShowContextualToolbar && ( - { - initialToolbarItemIndexRef.current = index; - } } - // Resets the index whenever the active block changes so - // this is not persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169 - key={ clientId } - /> - ) } - { shouldShowBreadcrumb && ( - - ) } - - ); - } - - return null; -} - -const SelectedBlockPopover = forwardRef( UnforwardSelectedBlockPopover ); - -function wrapperSelector( select ) { - const { - getSelectedBlockClientId, - getFirstMultiSelectedBlockClientId, - getBlockRootClientId, - getBlock, - getBlockParents, - __experimentalGetBlockListSettingsForBlocks, - } = select( blockEditorStore ); - - const clientId = - getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId(); - - if ( ! clientId ) { - return; - } - - const { name, attributes = {} } = getBlock( clientId ) || {}; - const blockParentsClientIds = getBlockParents( clientId ); - - // Get Block List Settings for all ancestors of the current Block clientId. - const parentBlockListSettings = __experimentalGetBlockListSettingsForBlocks( - blockParentsClientIds - ); - - // Get the clientId of the topmost parent with the capture toolbars setting. - const capturingClientId = blockParentsClientIds.find( - ( parentClientId ) => - parentBlockListSettings[ parentClientId ] - ?.__experimentalCaptureToolbars - ); - - return { - clientId, - rootClientId: getBlockRootClientId( clientId ), - name, - isEmptyDefaultBlock: - name && isUnmodifiedDefaultBlock( { name, attributes } ), - capturingClientId, - }; -} - -function UnforwardWrappedBlockPopover( - { __unstablePopoverSlot, __unstableContentRef }, - ref -) { - const selected = useSelect( wrapperSelector, [] ); - - if ( ! selected ) { - return null; - } - - const { - clientId, - rootClientId, - name, - isEmptyDefaultBlock, - capturingClientId, - } = selected; - - if ( ! name ) { - return null; - } - - return ( - - ); -} - -export default forwardRef( UnforwardWrappedBlockPopover );