diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js index 20ef22b5f0eb2..88d0cd1588f03 100644 --- a/packages/edit-post/src/components/layout/index.js +++ b/packages/edit-post/src/components/layout/index.js @@ -31,6 +31,7 @@ import { useRef, useState, } from '@wordpress/element'; +import { chevronDown, chevronUp } from '@wordpress/icons'; import { store as noticesStore } from '@wordpress/notices'; import { store as preferencesStore } from '@wordpress/preferences'; import { @@ -43,6 +44,7 @@ import { addQueryArgs } from '@wordpress/url'; import { decodeEntities } from '@wordpress/html-entities'; import { store as coreStore } from '@wordpress/core-data'; import { + Icon, ResizableBox, SlotFillProvider, Tooltip, @@ -76,7 +78,7 @@ import useNavigateToEntityRecord from '../../hooks/use-navigate-to-entity-record const { getLayoutStyles } = unlock( blockEditorPrivateApis ); const { useCommands } = unlock( coreCommandsPrivateApis ); const { useCommandContext } = unlock( commandsPrivateApis ); -const { Editor, FullscreenMode } = unlock( editorPrivateApis ); +const { Editor, FullscreenMode, NavigableRegion } = unlock( editorPrivateApis ); const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis ); const DESIGN_POST_TYPES = [ 'wp_template', @@ -163,7 +165,7 @@ function MetaBoxesMain( { isLegacy } ) { ]; }, [] ); const { set: setPreference } = useDispatch( preferencesStore ); - const resizableBoxRef = useRef(); + const metaBoxesMainRef = useRef(); const isShort = useMediaQuery( '(max-height: 549px)' ); const [ { min, max }, setHeightConstraints ] = useState( () => ( {} ) ); @@ -178,9 +180,9 @@ function MetaBoxesMain( { isLegacy } ) { ':scope > .components-notice-list' ); const resizeHandle = container.querySelector( - '.edit-post-meta-boxes-main__resize-handle' + '.edit-post-meta-boxes-main__presenter' ); - const actualize = () => { + const deriveConstraints = () => { const fullHeight = container.offsetHeight; let nextMax = fullHeight; for ( const element of noticeLists ) { @@ -189,7 +191,7 @@ function MetaBoxesMain( { isLegacy } ) { const nextMin = resizeHandle.offsetHeight; setHeightConstraints( { min: nextMin, max: nextMax } ); }; - const observer = new window.ResizeObserver( actualize ); + const observer = new window.ResizeObserver( deriveConstraints ); observer.observe( container ); for ( const element of noticeLists ) { observer.observe( element ); @@ -201,12 +203,33 @@ function MetaBoxesMain( { isLegacy } ) { const separatorHelpId = useId(); const [ isUntouched, setIsUntouched ] = useState( true ); + const applyHeight = ( candidateHeight, isPersistent, isInstant ) => { + const nextHeight = Math.min( max, Math.max( min, candidateHeight ) ); + if ( isPersistent ) { + setPreference( + 'core/edit-post', + 'metaBoxesMainOpenHeight', + nextHeight + ); + } else { + separatorRef.current.ariaValueNow = getAriaValueNow( nextHeight ); + } + if ( isInstant ) { + metaBoxesMainRef.current.updateSize( { + height: nextHeight, + // Oddly, when the event that triggered this was not from the mouse (e.g. keydown), + // if `width` is left unspecified a subsequent drag gesture applies a fixed + // width and the pane fails to widen/narrow with parent width changes from + // sidebars opening/closing or window resizes. + width: 'auto', + } ); + } + }; if ( ! hasAnyVisible ) { return; } - const className = 'edit-post-meta-boxes-main'; const contents = (