Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Unify the more menu #60910

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import { useState, useCallback } from '@wordpress/element';
* Internal dependencies
*/
import FullscreenModeClose from './fullscreen-mode-close';
import MoreMenu from './more-menu';
import PostEditorMoreMenu from './more-menu';
import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
import MainDashboardButton from './main-dashboard-button';
import ContextualToolbar from './contextual-toolbar';
import { store as editPostStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { DocumentTools, PostViewLink, PreviewDropdown, PinnedItems } =
const { DocumentTools, PostViewLink, PreviewDropdown, PinnedItems, MoreMenu } =
unlock( editorPrivateApis );

const slideY = {
Expand Down Expand Up @@ -152,7 +152,8 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
{ ( isWideViewport || ! showIconLabels ) && (
<PinnedItems.Slot scope="core" />
) }
<MoreMenu showIconLabels={ showIconLabels } />
<MoreMenu />
<PostEditorMoreMenu />
</motion.div>
</div>
);
Expand Down
69 changes: 27 additions & 42 deletions packages/edit-post/src/components/header/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,47 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { MenuGroup, DropdownMenu } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { moreVertical } from '@wordpress/icons';
import { PreferenceToggleMenuItem } from '@wordpress/preferences';
import { displayShortcut } from '@wordpress/keycodes';

/**
* Internal dependencies
*/
import PreferencesMenuItem from '../preferences-menu-item';
import ToolsMoreMenuGroup from '../tools-more-menu-group';
import WritingMenu from '../writing-menu';
import { unlock } from '../../../lock-unlock';
import ManagePatternsMenuItem from './manage-patterns-menu-item';
import WelcomeGuideMenuItem from './welcome-guide-menu-item';
import EditPostPreferencesModal from '../../preferences-modal';

const { ModeSwitcher, ActionItem, PinnedItems } = unlock( editorPrivateApis );
const { ToolsMoreMenuGroup, ViewMoreMenuGroup } = unlock( editorPrivateApis );

const MoreMenu = ( { showIconLabels } ) => {
const MoreMenu = () => {
const isLargeViewport = useViewportMatch( 'large' );

return (
<DropdownMenu
icon={ moreVertical }
label={ __( 'Options' ) }
popoverProps={ {
placement: 'bottom-end',
className: 'more-menu-dropdown__content',
} }
toggleProps={ {
...( showIconLabels && { variant: 'tertiary' } ),
tooltipPosition: 'bottom',
showTooltip: ! showIconLabels,
size: 'compact',
} }
>
{ ( { onClose } ) => (
<>
{ showIconLabels && ! isLargeViewport && (
<PinnedItems.Slot
className={ showIconLabels && 'show-icon-labels' }
scope="core"
/>
) }
<WritingMenu />
<ModeSwitcher />
<ActionItem.Slot
name="core/plugin-more-menu"
label={ __( 'Plugins' ) }
as={ MenuGroup }
fillProps={ { onClick: onClose } }
<>
{ isLargeViewport && (
<ViewMoreMenuGroup>
<PreferenceToggleMenuItem
scope="core/edit-post"
name="fullscreenMode"
label={ __( 'Fullscreen mode' ) }
info={ __( 'Show and hide the admin user interface' ) }
messageActivated={ __( 'Fullscreen mode activated' ) }
messageDeactivated={ __(
'Fullscreen mode deactivated'
) }
shortcut={ displayShortcut.secondary( 'f' ) }
/>
<ToolsMoreMenuGroup.Slot fillProps={ { onClose } } />
<MenuGroup>
<PreferencesMenuItem />
</MenuGroup>
</>
</ViewMoreMenuGroup>
) }
</DropdownMenu>
<ToolsMoreMenuGroup>
<ManagePatternsMenuItem />
<WelcomeGuideMenuItem />
</ToolsMoreMenuGroup>
<EditPostPreferencesModal />
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';

function ManagePatternsMenuItem() {
const url = useSelect( ( select ) => {
const { canUser } = select( coreStore );
const { getEditorSettings } = select( editorStore );

const isBlockTheme = getEditorSettings().__unstableIsBlockBasedTheme;
const defaultUrl = addQueryArgs( 'edit.php', {
post_type: 'wp_block',
} );
const patternsUrl = addQueryArgs( 'site-editor.php', {
path: '/patterns',
} );

// The site editor and templates both check whether the user has
// edit_theme_options capabilities. We can leverage that here and not
// display the manage patterns link if the user can't access it.
return canUser( 'read', 'templates' ) && isBlockTheme
? patternsUrl
: defaultUrl;
}, [] );

return (
<MenuItem role="menuitem" href={ url }>
{ __( 'Manage patterns' ) }
</MenuItem>
);
}

export default ManagePatternsMenuItem;

This file was deleted.

73 changes: 0 additions & 73 deletions packages/edit-post/src/components/header/writing-menu/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
import TextEditor from '../text-editor';
import VisualEditor from '../visual-editor';
import EditPostKeyboardShortcuts from '../keyboard-shortcuts';
import EditPostPreferencesModal from '../preferences-modal';
import InitPatternModal from '../init-pattern-modal';
import BrowserURL from '../browser-url';
import Header from '../header';
Expand Down Expand Up @@ -358,7 +357,6 @@ function Layout( { initialPost } ) {
next: nextShortcut,
} }
/>
<EditPostPreferencesModal />
<WelcomeGuide />
<InitPatternModal />
<PluginArea onError={ onPluginAreaError } />
Expand Down
28 changes: 0 additions & 28 deletions packages/edit-post/src/components/preferences-modal/test/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
* Internal dependencies
*/
import './hooks';
import './plugins';
import Editor from './editor';
import { unlock } from './lock-unlock';

Expand Down
29 changes: 0 additions & 29 deletions packages/edit-post/src/plugins/copy-content-menu-item/index.js

This file was deleted.

Loading
Loading