From d6f7eb11c3b5f156f76efcd8cb6bd246225495c2 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Sun, 26 Jan 2025 14:40:04 -0800 Subject: [PATCH] Move provider up/out to wrap mobile area --- .../edit-site/src/components/layout/index.js | 145 +++++++++++------- .../edit-site/src/components/sidebar/index.js | 44 +----- 2 files changed, 94 insertions(+), 95 deletions(-) diff --git a/packages/edit-site/src/components/layout/index.js b/packages/edit-site/src/components/layout/index.js index a5e14f0be8281..0a132819f3c1e 100644 --- a/packages/edit-site/src/components/layout/index.js +++ b/packages/edit-site/src/components/layout/index.js @@ -44,7 +44,7 @@ import { unlock } from '../../lock-unlock'; import SaveKeyboardShortcut from '../save-keyboard-shortcut'; import { useIsSiteEditorLoading } from './hooks'; import useMovingAnimation from './animation'; -import SidebarContent from '../sidebar'; +import SidebarContent, { SidebarNavigationContext } from '../sidebar'; import SaveHub from '../save-hub'; import SavePanel from '../save-panel'; @@ -55,6 +55,30 @@ const { useLocation } = unlock( routerPrivateApis ); const ANIMATION_DURATION = 0.3; +// Navigation state that is updated when navigating back or forward. Helps us +// manage the animations and also focus. +function createNavState() { + let state = { + direction: null, + focusSelector: null, + }; + + return { + get() { + return state; + }, + navigate( direction, focusSelector = null ) { + state = { + direction, + focusSelector: + direction === 'forward' && focusSelector + ? focusSelector + : state.focusSelector, + }; + }, + }; +} + function Layout() { const { query, name: routeKey, areas, widths } = useLocation(); const { canvas = 'view' } = query; @@ -90,6 +114,8 @@ function Layout() { // Should not depend on the previous canvas mode value but the next. }, [ canvas ] ); + const [ navState ] = useState( createNavState ); + return ( <> @@ -108,75 +134,76 @@ function Layout() { ) } >
- { /* + + { /* The NavigableRegion must always be rendered and not use `inert` otherwise `useNavigateRegions` will fail. */ } - { ( ! isMobileViewport || ! areas.mobile ) && ( - - - { canvas === 'view' && ( - - + + { canvas === 'view' && ( + + + + + { areas.sidebar } + + + + + + ) } + + + ) } + + { isMobileViewport && areas.mobile && ( +
+ { canvas !== 'edit' && ( + + - - - { areas.sidebar } - - - - - + ) } - - - ) } - + { areas.mobile } +
+ ) } +
- { isMobileViewport && areas.mobile && ( -
- { canvas !== 'edit' && ( - - - - ) } - { areas.mobile } -
- ) } - { ! isMobileViewport && areas.content && canvas !== 'edit' && ( diff --git a/packages/edit-site/src/components/sidebar/index.js b/packages/edit-site/src/components/sidebar/index.js index 7ecd24719a47b..aa2e455699974 100644 --- a/packages/edit-site/src/components/sidebar/index.js +++ b/packages/edit-site/src/components/sidebar/index.js @@ -31,30 +31,6 @@ function focusSidebarElement( el, direction, focusSelector ) { elementToFocus?.focus(); } -// Navigation state that is updated when navigating back or forward. Helps us -// manage the animations and also focus. -function createNavState() { - let state = { - direction: null, - focusSelector: null, - }; - - return { - get() { - return state; - }, - navigate( direction, focusSelector = null ) { - state = { - direction, - focusSelector: - direction === 'forward' && focusSelector - ? focusSelector - : state.focusSelector, - }; - }, - }; -} - function SidebarContentWrapper( { children, shouldAnimate } ) { const navState = useContext( SidebarNavigationContext ); const wrapperRef = useRef(); @@ -92,18 +68,14 @@ export default function SidebarContent( { shouldAnimate, children, } ) { - const [ navState ] = useState( createNavState ); - return ( - -
- - { children } - -
-
+
+ + { children } + +
); }