Skip to content

Commit

Permalink
Move useNavigateRegions to an outermost ancestor.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Sep 17, 2024
1 parent d9b4a42 commit 719f1d3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 59 deletions.
94 changes: 53 additions & 41 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library
import { addQueryArgs } from '@wordpress/url';
import { decodeEntities } from '@wordpress/html-entities';
import { store as coreStore } from '@wordpress/core-data';
import { ResizableBox, SlotFillProvider } from '@wordpress/components';
import {
ResizableBox,
SlotFillProvider,
__unstableUseNavigateRegions as useNavigateRegions,
} from '@wordpress/components';
import { useMediaQuery, useViewportMatch } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -366,6 +370,8 @@ function Layout( {
document.body.classList.remove( 'show-icon-labels' );
}

const navigateRegionsProps = useNavigateRegions();

const className = clsx( 'edit-post-layout', 'is-mode-' + mode, {
'has-metaboxes': hasActiveMetaboxes,
} );
Expand Down Expand Up @@ -451,47 +457,53 @@ function Layout( {
<ErrorBoundary>
<CommandMenu />
<WelcomeGuide postType={ currentPost.postType } />
<Editor
settings={ editorSettings }
initialEdits={ initialEdits }
postType={ currentPost.postType }
postId={ currentPost.postId }
templateId={ templateId }
className={ className }
styles={ styles }
forceIsDirty={ hasActiveMetaboxes }
contentRef={ paddingAppenderRef }
disableIframe={ ! shouldIframe }
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ ! isWelcomeGuideVisible }
onActionPerformed={ onActionPerformed }
extraSidebarPanels={
! isEditingTemplate && <MetaBoxes location="side" />
}
extraContent={
! isDistractionFree &&
showMetaBoxes && (
<MetaBoxesMain isLegacy={ ! shouldIframe } />
)
}
<div
className={ navigateRegionsProps.className }
{ ...navigateRegionsProps }
ref={ navigateRegionsProps.ref }
>
<PostLockedModal />
<EditorInitialization />
<FullscreenMode isActive={ isFullscreenActive } />
<BrowserURL hasHistory={ hasHistory } />
<UnsavedChangesWarning />
<AutosaveMonitor />
<LocalAutosaveMonitor />
<EditPostKeyboardShortcuts />
<EditorKeyboardShortcutsRegister />
<BlockKeyboardShortcuts />
<InitPatternModal />
<PluginArea onError={ onPluginAreaError } />
<PostEditorMoreMenu />
{ backButton }
<EditorSnackbars />
</Editor>
<Editor
settings={ editorSettings }
initialEdits={ initialEdits }
postType={ currentPost.postType }
postId={ currentPost.postId }
templateId={ templateId }
className={ className }
styles={ styles }
forceIsDirty={ hasActiveMetaboxes }
contentRef={ paddingAppenderRef }
disableIframe={ ! shouldIframe }
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ ! isWelcomeGuideVisible }
onActionPerformed={ onActionPerformed }
extraSidebarPanels={
! isEditingTemplate && <MetaBoxes location="side" />
}
extraContent={
! isDistractionFree &&
showMetaBoxes && (
<MetaBoxesMain isLegacy={ ! shouldIframe } />
)
}
>
<PostLockedModal />
<EditorInitialization />
<FullscreenMode isActive={ isFullscreenActive } />
<BrowserURL hasHistory={ hasHistory } />
<UnsavedChangesWarning />
<AutosaveMonitor />
<LocalAutosaveMonitor />
<EditPostKeyboardShortcuts />
<EditorKeyboardShortcutsRegister />
<BlockKeyboardShortcuts />
<InitPatternModal />
<PluginArea onError={ onPluginAreaError } />
<PostEditorMoreMenu />
{ backButton }
<EditorSnackbars />
</Editor>
</div>
</ErrorBoundary>
</SlotFillProvider>
);
Expand Down
25 changes: 17 additions & 8 deletions packages/edit-widgets/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { PluginArea } from '@wordpress/plugins';
import { store as noticesStore } from '@wordpress/notices';
import { __unstableUseNavigateRegions as useNavigateRegions } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -31,17 +32,25 @@ function Layout( { blockEditorSettings } ) {
);
}

const navigateRegionsProps = useNavigateRegions();

return (
<ErrorBoundary>
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
<div
className={ navigateRegionsProps.className }
{ ...navigateRegionsProps }
ref={ navigateRegionsProps.ref }
>
<Interface blockEditorSettings={ blockEditorSettings } />
<Sidebar />
<PluginArea onError={ onPluginAreaError } />
<UnsavedChangesWarning />
<WelcomeGuide />
</WidgetAreasBlockEditorProvider>
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
>
<Interface blockEditorSettings={ blockEditorSettings } />
<Sidebar />
<PluginArea onError={ onPluginAreaError } />
<UnsavedChangesWarning />
<WelcomeGuide />
</WidgetAreasBlockEditorProvider>
</div>
</ErrorBoundary>
);
}
Expand Down
11 changes: 1 addition & 10 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import clsx from 'clsx';
*/
import { forwardRef, useEffect } from '@wordpress/element';
import {
__unstableUseNavigateRegions as useNavigateRegions,
__unstableMotion as motion,
__unstableAnimatePresence as AnimatePresence,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import {
useMergeRefs,
useReducedMotion,
useViewportMatch,
useResizeObserver,
Expand Down Expand Up @@ -85,7 +83,6 @@ function InterfaceSkeleton(
actions,
labels,
className,
enableRegionNavigation = true,
},
ref
) {
Expand All @@ -98,7 +95,6 @@ function InterfaceSkeleton(
duration: disableMotion ? 0 : ANIMATION_DURATION,
ease: [ 0.6, 0, 0.4, 1 ],
};
const navigateRegionsProps = useNavigateRegions();
useHTMLClass( 'interface-interface-skeleton__html-container' );

const defaultLabels = {
Expand All @@ -120,15 +116,10 @@ function InterfaceSkeleton(

return (
<div
{ ...( enableRegionNavigation ? navigateRegionsProps : {} ) }
ref={ useMergeRefs( [
ref,
enableRegionNavigation ? navigateRegionsProps.ref : undefined,
] ) }
ref={ ref }
className={ clsx(
className,
'interface-interface-skeleton',
navigateRegionsProps.className,
!! footer && 'has-footer'
) }
>
Expand Down

0 comments on commit 719f1d3

Please sign in to comment.