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

Update: Use single block editor in the widgets screen #22140

Merged
merged 1 commit into from
May 18, 2020
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
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ export default compose( [
getBlockRootClientId,
hasInserterItems,
__experimentalGetAllowedBlocks,
getBlockSelectionEnd,
} = select( 'core/block-editor' );
const { getBlockVariations } = select( 'core/blocks' );

rootClientId =
rootClientId || getBlockRootClientId( clientId ) || undefined;
rootClientId ||
getBlockRootClientId( clientId || getBlockSelectionEnd() ) ||
Copy link
Contributor

@talldan talldan Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#23263 proposes to revert this particular change, as it caused the default root appender to insert blocks wherever selection is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems logical @talldan the widget screen should inject the rootClientId as a prop of the inserter instead.

undefined;

const allowedBlocks = __experimentalGetAllowedBlocks( rootClientId );

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@import "./text-columns/editor.scss";
@import "./verse/editor.scss";
@import "./video/editor.scss";
@import "./widget-area/editor.scss";

/**
* Import styles from internal editor components used by the blocks.
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import * as tagCloud from './tag-cloud';
import * as classic from './classic';
import * as socialLinks from './social-links';
import * as socialLink from './social-link';
import * as widgetArea from './widget-area';

// Full Site Editing Blocks
import * as siteTitle from './site-title';
Expand Down Expand Up @@ -188,6 +189,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
} = settings;

[
widgetArea,
__experimentalEnableLegacyWidgetBlock ? legacyWidget : null,
navigation,
navigationLink,
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/widget-area/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "core/widget-area",
"category": "widgets",
"attributes": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
31 changes: 31 additions & 0 deletions packages/block-library/src/widget-area/edit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { EntityProvider } from '@wordpress/core-data';
import { Panel, PanelBody } from '@wordpress/components';

/**
* Internal dependencies
*/
import WidgetAreaInnerBlocks from './inner-blocks';

export default function WidgetAreaEdit( {
clientId,
className,
attributes: { id, name },
} ) {
const index = useSelect(
( select ) => select( 'core/block-editor' ).getBlockIndex( clientId ),
[ clientId ]
);
return (
<Panel className={ className }>
<PanelBody title={ name } initialOpen={ index === 0 }>
<EntityProvider kind="root" type="widgetArea" id={ id }>
<WidgetAreaInnerBlocks />
</EntityProvider>
</PanelBody>
</Panel>
);
}
21 changes: 21 additions & 0 deletions packages/block-library/src/widget-area/edit/inner-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { useEntityBlockEditor } from '@wordpress/core-data';
import { InnerBlocks } from '@wordpress/block-editor';

export default function WidgetAreaInnerBlocks() {
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'root',
'widgetArea'
);
return (
<InnerBlocks
__experimentalBlocks={ blocks }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to value now that #21368 has been merged

onInput={ onInput }
onChange={ onChange }
templateLock={ false }
renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
);
}
7 changes: 7 additions & 0 deletions packages/block-library/src/widget-area/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.wp-block[data-type="core/widget-area"] {
max-width: $widget-area-width;
}

.wp-block-widget-area > .components-panel__body > .block-editor-inner-blocks {
padding-top: $grid-unit-30;
}
25 changes: 25 additions & 0 deletions packages/block-library/src/widget-area/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import metadata from './block.json';
import edit from './edit';

const { name } = metadata;
export { metadata, name };

export const settings = {
title: __( 'Widget Area' ),
description: __( 'A widget area container.' ),
supports: {
html: false,
inserter: false,
customClassName: false,
},
__experimentalLabel: ( { name: label } ) => label,
edit,
};
1 change: 1 addition & 0 deletions packages/e2e-tests/fixtures/blocks/core__widget-area.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:widget-area /-->
10 changes: 10 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__widget-area.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"clientId": "_clientId_0",
"name": "core/widget-area",
"isValid": true,
"attributes": {},
"innerBlocks": [],
"originalContent": ""
}
]
18 changes: 18 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__widget-area.parsed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"blockName": "core/widget-area",
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:widget-area /-->
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
/**
* WordPress dependencies
*/
import {
SlotFillProvider,
Popover,
navigateRegions,
} from '@wordpress/components';
import { navigateRegions } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import WidgetAreas from '../widget-areas';

import './sync-customizer';
import WidgetAreasBlockEditorProvider from '../widget-areas-block-editor-provider';
import WidgetAreasBlockEditorContent from '../widget-areas-block-editor-content';

function CustomizerEditWidgetsInitializer( { settings } ) {
const [ selectedArea, setSelectedArea ] = useState( null );
return (
<SlotFillProvider>
<WidgetAreasBlockEditorProvider blockEditorSettings={ settings }>
<div
className="edit-widgets-customizer-edit-widgets-initializer__content"
role="region"
aria-label={ __( 'Widgets screen content' ) }
tabIndex="-1"
>
<WidgetAreas
selectedArea={ selectedArea }
setSelectedArea={ setSelectedArea }
blockEditorSettings={ settings }
/>
<WidgetAreasBlockEditorContent />
</div>
<Popover.Slot />
</SlotFillProvider>
</WidgetAreasBlockEditorProvider>
);
}

Expand Down
11 changes: 9 additions & 2 deletions packages/edit-widgets/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
*/
import { __ } from '@wordpress/i18n';
import { NavigableMenu } from '@wordpress/components';
import { BlockNavigationDropdown, Inserter } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import Inserter from '../inserter';
import SaveButton from '../save-button';
import UndoButton from './undo-redo/undo';
import RedoButton from './undo-redo/redo';

const inserterToggleProps = { isPrimary: true };

function Header() {
return (
<div className="edit-widgets-header">
<NavigableMenu>
<Inserter.Slot className="edit-widgets-inserter" />
<Inserter
position="bottom right"
showInserterHelpPanel
toggleProps={ inserterToggleProps }
/>
<UndoButton />
<RedoButton />
<BlockNavigationDropdown />
</NavigableMenu>
<h1 className="edit-widgets-header__title">
{ __( 'Block Areas' ) } { __( '(experimental)' ) }
Expand Down
4 changes: 0 additions & 4 deletions packages/edit-widgets/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
padding: 0 $grid-unit-20;
}

.edit-widgets-inserter {
display: inline-block;
}

.edit-widgets-header__title {
font-size: 16px;
padding: 0 20px;
Expand Down
16 changes: 0 additions & 16 deletions packages/edit-widgets/src/components/inserter/index.js

This file was deleted.

92 changes: 25 additions & 67 deletions packages/edit-widgets/src/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,42 @@
/**
* WordPress dependencies
*/
import {
DropZoneProvider,
Popover,
SlotFillProvider,
FocusReturnProvider,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import {
BlockEditorKeyboardShortcuts,
Inserter as BlockEditorInserter,
} from '@wordpress/block-editor';
import { Popover, Panel } from '@wordpress/components';
import { BlockInspector } from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
import { InterfaceSkeleton } from '@wordpress/interface';

import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import Header from '../header';
import Sidebar from '../sidebar';
import WidgetAreas from '../widget-areas';
import Notices from '../notices';
import KeyboardShortcuts from '../keyboard-shortcuts';
import Inserter from '../inserter';

const disabledInserterToggleProps = { isPrimary: true, disabled: true };
import WidgetAreasBlockEditorProvider from '../widget-areas-block-editor-provider';
import WidgetAreasBlockEditorContent from '../widget-areas-block-editor-content';

function Layout( { blockEditorSettings } ) {
const [ selectedArea, setSelectedArea ] = useState( null );
const isMobile = useViewportMatch( 'medium', '<' );

return (
<>
<BlockEditorKeyboardShortcuts.Register />
<KeyboardShortcuts.Register />
<SlotFillProvider>
<DropZoneProvider>
<FocusReturnProvider>
<InterfaceSkeleton
header={ <Header /> }
sidebar={ ! isMobile && <Sidebar /> }
content={
<>
<KeyboardShortcuts />
<Notices />
<Popover.Slot name="block-toolbar" />
<div
className="edit-widgets-layout__content"
tabIndex="-1"
onFocus={ () => {
setSelectedArea( null );
} }
>
<WidgetAreas
selectedArea={ selectedArea }
setSelectedArea={ setSelectedArea }
blockEditorSettings={
blockEditorSettings
}
/>
</div>
{ selectedArea === null && (
<Inserter>
<BlockEditorInserter
toggleProps={
disabledInserterToggleProps
}
/>
</Inserter>
) }
</>
}
/>

<Popover.Slot />
</FocusReturnProvider>
</DropZoneProvider>
</SlotFillProvider>
</>
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
>
<InterfaceSkeleton
header={ <Header /> }
sidebar={
! isMobile && (
<div className="edit-widgets-sidebar">
<Panel header={ __( 'Block Areas' ) }>
<BlockInspector
showNoBlockSelectedMessage={ false }
/>
</Panel>
</div>
)
}
content={ <WidgetAreasBlockEditorContent /> }
/>
<Popover.Slot />
</WidgetAreasBlockEditorProvider>
);
}

Expand Down
3 changes: 0 additions & 3 deletions packages/edit-widgets/src/components/layout/style.scss

This file was deleted.

Loading