Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 12, 2022
1 parent 4de8480 commit afd99e4
Show file tree
Hide file tree
Showing 49 changed files with 713 additions and 715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
/**
* Internal dependencies
*/
import { Routes } from '../components/routes';
import Layout from './layout';
import { Routes } from '../routes';
import Layout from '../layout';

export default function App() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
*/
import { store as editSiteStore } from '../../store';
import { STORE_NAME } from '../../store/constants';
import { SIDEBAR_BLOCK } from '../sidebar/constants';
import { SIDEBAR_BLOCK } from '../sidebar-edit-mode/constants';

export default function BlockInspectorButton( { onClick = () => {} } ) {
const { shortcut, isBlockInspectorOpen } = useSelect(
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
*/
import TemplatePartConverter from '../template-part-converter';
import NavigateToLink from '../navigate-to-link';
import { SidebarInspectorFill } from '../sidebar';
import { SidebarInspectorFill } from '../sidebar-edit-mode';
import { store as editSiteStore } from '../../store';
import BlockInspectorButton from './block-inspector-button';
import BackButton from './back-button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
*/
import { store as editSiteStore } from '../../store';
import Header from '../header';
import BlockEditor from '../../components/block-editor';
import CodeEditor from '../../components/code-editor';
import KeyboardShortcuts from '../../components/keyboard-shortcuts';
import useInitEditedEntityFromURL from '../../components/use-init-edited-entity-from-url';
import GlobalStylesRenderer from '../../components/global-styles-renderer';
import { GlobalStylesProvider } from '../../components/global-styles/global-styles-provider';
import ListViewSidebar from '../../components/secondary-sidebar/list-view-sidebar';
import InserterSidebar from '../../components/secondary-sidebar/inserter-sidebar';
import { SidebarComplementaryAreaFills } from '../../components/sidebar';
import WelcomeGuide from '../../components/welcome-guide';
import BlockEditor from '../block-editor';
import CodeEditor from '../code-editor';
import KeyboardShortcuts from '../keyboard-shortcuts';
import useInitEditedEntityFromURL from '../use-init-edited-entity-from-url';
import GlobalStylesRenderer from '../global-styles-renderer';
import { GlobalStylesProvider } from '../global-styles/global-styles-provider';
import ListViewSidebar from '../secondary-sidebar/list-view-sidebar';
import InserterSidebar from '../secondary-sidebar/inserter-sidebar';
import { SidebarComplementaryAreaFills } from '../sidebar-edit-mode';
import WelcomeGuide from '../welcome-guide';

const interfaceLabels = {
/* translators: accessibility text for the editor top bar landmark region. */
Expand Down
285 changes: 285 additions & 0 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { useCallback, useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import {
ToolSelector,
__experimentalPreviewOptions as PreviewOptions,
NavigableToolbar,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { PinnedItems } from '@wordpress/interface';
import { _x, __ } from '@wordpress/i18n';
import { listView, plus, external, chevronUpDown } from '@wordpress/icons';
import {
Button,
ToolbarItem,
MenuGroup,
MenuItem,
VisuallyHidden,
} from '@wordpress/components';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import MoreMenu from './more-menu';
import SaveButton from '../save-button';
import UndoButton from './undo-redo/undo';
import RedoButton from './undo-redo/redo';
import DocumentActions from './document-actions';
import TemplateDetails from '../template-details';
import { store as editSiteStore } from '../../store';

const preventDefault = ( event ) => {
event.preventDefault();
};

export default function Header() {
const inserterButton = useRef();
const {
deviceType,
entityTitle,
template,
templateType,
isInserterOpen,
isListViewOpen,
listViewShortcut,
isLoaded,
isVisualMode,
settings,
blockEditorMode,
showIconLabels,
} = useSelect( ( select ) => {
const {
__experimentalGetPreviewDeviceType,
getEditedPostType,
getEditedPostId,
isInserterOpened,
isListViewOpened,
getEditorMode,
getSettings,
} = select( editSiteStore );
const { getEditedEntityRecord } = select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
select( editorStore );
const { getShortcutRepresentation } = select( keyboardShortcutsStore );
const { __unstableGetEditorMode } = select( blockEditorStore );

const postType = getEditedPostType();
const postId = getEditedPostId();
const record = getEditedEntityRecord( 'postType', postType, postId );
const _isLoaded = !! postId;

return {
deviceType: __experimentalGetPreviewDeviceType(),
entityTitle: getTemplateInfo( record ).title,
isLoaded: _isLoaded,
template: record,
templateType: postType,
isInserterOpen: isInserterOpened(),
isListViewOpen: isListViewOpened(),
listViewShortcut: getShortcutRepresentation(
'core/edit-site/toggle-list-view'
),
isVisualMode: getEditorMode() === 'visual',
settings: getSettings(),
blockEditorMode: __unstableGetEditorMode(),
showIconLabels: select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
),
};
}, [] );

const {
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
setIsInserterOpened,
setIsListViewOpened,
} = useDispatch( editSiteStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const isLargeViewport = useViewportMatch( 'medium' );

const openInserter = useCallback( () => {
if ( isInserterOpen ) {
// Focusing the inserter button closes the inserter popover.
inserterButton.current.focus();
} else {
setIsInserterOpened( true );
}
}, [ isInserterOpen, setIsInserterOpened ] );

const toggleListView = useCallback(
() => setIsListViewOpened( ! isListViewOpen ),
[ setIsListViewOpened, isListViewOpen ]
);

const isFocusMode = templateType === 'wp_template_part';

/* translators: button label text should, if possible, be under 16 characters. */
const longLabel = _x(
'Toggle block inserter',
'Generic label for block inserter button'
);
const shortLabel = ! isInserterOpen ? __( 'Add' ) : __( 'Close' );

const isZoomedOutViewExperimentEnabled =
window?.__experimentalEnableZoomedOutView && isVisualMode;
const isZoomedOutView = blockEditorMode === 'zoom-out';

return (
<div
className={ classnames( 'edit-site-header-edit-mode', {
'show-icon-labels': showIconLabels,
} ) }
>
<NavigableToolbar
className="edit-site-header-edit-mode__start"
aria-label={ __( 'Document tools' ) }
>
<div className="edit-site-header-edit-mode__toolbar">
<ToolbarItem
ref={ inserterButton }
as={ Button }
className="edit-site-header-edit-mode-toolbar__inserter-toggle"
variant="primary"
isPressed={ isInserterOpen }
onMouseDown={ preventDefault }
onClick={ openInserter }
disabled={ ! isVisualMode }
icon={ plus }
label={ showIconLabels ? shortLabel : longLabel }
showTooltip={ ! showIconLabels }
/>
{ isLargeViewport && (
<>
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
disabled={ ! isVisualMode }
/>
<ToolbarItem
as={ UndoButton }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
/>
<ToolbarItem
as={ RedoButton }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
/>
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode-toolbar__list-view-toggle"
disabled={ ! isVisualMode && isZoomedOutView }
icon={ listView }
isPressed={ isListViewOpen }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'List View' ) }
onClick={ toggleListView }
shortcut={ listViewShortcut }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
/>
{ isZoomedOutViewExperimentEnabled && (
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode-toolbar__zoom-out-view-toggle"
icon={ chevronUpDown }
isPressed={ isZoomedOutView }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Zoom-out View' ) }
onClick={ () => {
setPreviewDeviceType( 'desktop' );
__unstableSetEditorMode(
isZoomedOutView
? 'edit'
: 'zoom-out'
);
} }
/>
) }
</>
) }
</div>
</NavigableToolbar>

<div className="edit-site-header-edit-mode__center">
<DocumentActions
entityTitle={ entityTitle }
entityLabel={
templateType === 'wp_template_part'
? 'template part'
: 'template'
}
isLoaded={ isLoaded }
showIconLabels={ showIconLabels }
>
{ ( { onClose } ) => (
<TemplateDetails
template={ template }
onClose={ onClose }
/>
) }
</DocumentActions>
</div>

<div className="edit-site-header-edit-mode__end">
<div className="edit-site-header-edit-mode__actions">
{ ! isFocusMode && (
<div
className={ classnames(
'edit-site-header-edit-mode__actions__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
>
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
>
<MenuGroup>
<MenuItem
href={ settings?.siteUrl }
target="_blank"
icon={ external }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
</PreviewOptions>
</div>
) }
<SaveButton />
<PinnedItems.Slot scope="core/edit-site" />
<MoreMenu showIconLabels={ showIconLabels } />
</div>
</div>
</div>
);
}
Loading

0 comments on commit afd99e4

Please sign in to comment.