diff --git a/packages/block-library/src/file/edit.tsx b/packages/block-library/src/file/edit.tsx index d014cb9b6611cb..061b7b304c4248 100644 --- a/packages/block-library/src/file/edit.tsx +++ b/packages/block-library/src/file/edit.tsx @@ -4,11 +4,14 @@ import { __unstableGetAnimateClassName as getAnimateClassName, ResizableBox, ToolbarButton, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { BlockControls, BlockIcon, + InspectorControls, MediaPlaceholder, MediaReplaceFlow, RichText, @@ -27,12 +30,16 @@ import type { BlockEditProps } from '@wordpress/blocks'; import FileBlockInspector from './inspector'; import { browserSupportsPdfs } from './utils'; import removeAnchorTag from '../utils/remove-anchor-tag'; -import { useUploadMediaFromBlobURL } from '../utils/hooks'; +import { + useUploadMediaFromBlobURL, + useToolsPanelDropdownMenuProps, +} from '../utils/hooks'; import type { ClipboardToolbarButtonProps, FileAttributes, MediaFile, } from './types'; +import { MediaControl } from '../utils/media-control'; export const MIN_PREVIEW_HEIGHT = 200; export const MAX_PREVIEW_HEIGHT = 2000; @@ -96,6 +103,7 @@ function FileEdit( { const { createErrorNotice } = useDispatch( noticesStore ); const { toggleSelection } = useDispatch( blockEditorStore ); + const dropdownMenuProps = useToolsPanelDropdownMenuProps(); useUploadMediaFromBlobURL( { url: temporaryURL, @@ -211,22 +219,75 @@ function FileEdit( { const displayPreviewInEditor = browserSupportsPdfs() && displayPreview; + /* + * Rendered whether or not a file has been set, so that a file block in its + * setup state can be given media from the toolbar and the inspector as well + * as from the placeholder. The settings in `FileBlockInspector` stay behind + * their own condition, having nothing to configure until there is a file. + */ + const mediaToolbar = ( + + onSelectFile( undefined ) } + name={ href ? __( 'Replace' ) : __( 'Add file' ) } + /> + + ); + + const mediaInspectorPanel = isSelected && ( + + onSelectFile( undefined ) } + dropdownMenuProps={ dropdownMenuProps } + > + !! href } + onDeselect={ () => onSelectFile( undefined ) } + isShownByDefault + > + onSelectFile( undefined ) } + isUploading={ !! temporaryURL } + emptyLabel={ __( 'Add file' ) } + /> + + + + ); + if ( ! href && ! temporaryURL ) { return ( -
- } - labels={ { - title: __( 'File' ), - instructions: __( - 'Drag and drop a file, upload, or choose from your library.' - ), - } } - onSelect={ onSelectFile } - onError={ onUploadError } - accept="*" - /> -
+ <> + { mediaToolbar } + { mediaInspectorPanel } +
+ } + labels={ { + title: __( 'File' ), + instructions: __( + 'Drag and drop a file, upload, or choose from your library.' + ), + } } + onSelect={ onSelectFile } + onError={ onUploadError } + accept="*" + /> +
+ ); } @@ -250,15 +311,9 @@ function FileEdit( { changePreviewHeight, } } /> + { mediaToolbar } + { mediaInspectorPanel } - onSelectFile( undefined ) } - />