Skip to content

Commit

Permalink
Editor: Extract BlockList as reusable component
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Nov 20, 2017
1 parent 2d50d76 commit 87e417f
Show file tree
Hide file tree
Showing 32 changed files with 558 additions and 524 deletions.
2 changes: 1 addition & 1 deletion blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export default class Editable extends Component {
// Find the parent "relative" positioned container
const container = this.props.inlineToolbar ?
this.editor.getBody().closest( '.blocks-editable' ) :
this.editor.getBody().closest( '.editor-visual-editor__block' );
this.editor.getBody().closest( '.editor-block-list__block' );
const containerPosition = container.getBoundingClientRect();
const blockPadding = 14;
const blockMoverMargin = 18;
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/button/editor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$blocks-button__height: 46px;

.editor-visual-editor__block[data-type="core/button"] {
.editor-block-list__block[data-type="core/button"] {
&[data-align="center"] {
text-align: center;
}
Expand Down
4 changes: 1 addition & 3 deletions blocks/library/categories/editor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

.editor-visual-editor__block[data-type="core/categories"] {

.editor-block-list__block[data-type="core/categories"] {
.wp-block-categories ul {
padding-left: 2.5em;

Expand Down
2 changes: 1 addition & 1 deletion blocks/library/cover-image/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.editor-visual-editor__block[data-type="core/cover-image"] {
.editor-block-list__block[data-type="core/cover-image"] {
.blocks-editable__tinymce[data-is-empty="true"]:before {
position: inherit;
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/freeform/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.editor-visual-editor__block[data-type="core/freeform"] .blocks-editable__tinymce {
.editor-block-list__block[data-type="core/freeform"] .blocks-editable__tinymce {
margin-top: $item-spacing;

p {
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
margin-bottom: -16px;
}

.editor-visual-editor__block[data-type="core/gallery"] .editor-visual-editor__block-edit {
.editor-block-list__block[data-type="core/gallery"] .editor-block-list__block-edit {
overflow: hidden;
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/library/heading/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.editor-visual-editor__block[data-type="core/heading"] {
.editor-block-list__block[data-type="core/heading"] {
h1,
h2,
h3,
Expand Down
6 changes: 3 additions & 3 deletions blocks/library/image/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
left: -6px !important;
}

.editor-visual-editor__block[data-type="core/image"] {
.editor-block-list__block[data-type="core/image"] {
.blocks-format-toolbar__link-modal {
top: 0;
left: 0;
Expand All @@ -73,8 +73,8 @@
}
}

.editor-visual-editor__block[data-type="core/image"][data-align="right"],
.editor-visual-editor__block[data-type="core/image"][data-align="left"] {
.editor-block-list__block[data-type="core/image"][data-align="right"],
.editor-block-list__block[data-type="core/image"][data-align="left"] {
max-width: none !important;
&[data-resized="false"] {
max-width: 370px !important;
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/latest-posts/editor.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.editor-visual-editor__block[data-type="core/latest-posts"] {
.editor-block-list__block[data-type="core/latest-posts"] {

.wp-block-latest-posts {
padding-left: 2.5em;
Expand Down
6 changes: 3 additions & 3 deletions blocks/library/more/editor.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.editor-visual-editor__block[data-type="core/more"] {
.editor-block-list__block[data-type="core/more"] {
max-width: 100%;
text-align: center;
}

.editor-visual-editor__block .wp-block-more {
.editor-block-list__block .wp-block-more {
input {
font-size: 12px;
text-transform: uppercase;
Expand All @@ -29,6 +29,6 @@
left: $block-mover-padding-visible + $block-padding;
right: $block-mover-padding-visible + $block-padding;
border-top: 3px dashed $light-gray-700;
z-index: z-index( '.editor-visual-editor__block .wp-block-more:before' );
z-index: z-index( '.editor-block-list__block .wp-block-more:before' );
}
}
2 changes: 1 addition & 1 deletion blocks/library/pullquote/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.editor-visual-editor__block[data-type="core/pullquote"] {
.editor-block-list__block[data-type="core/pullquote"] {
&[data-align="left"],
&[data-align="right"] {
max-width: 400px;
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/table/editor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.editor-visual-editor__block[data-type="core/table"] {
.editor-block-list__block[data-type="core/table"] {

.editor-block-toolbar__group > div:not(.editor-block-toolbar__mobile-tools) {
display: flex;
Expand Down
8 changes: 4 additions & 4 deletions editor/assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

$z-layers: (
'.editor-block-switcher__arrow': 1,
'.editor-visual-editor__block:before': -1,
'.editor-visual-editor__block .wp-block-more:before': -1,
'.editor-visual-editor__block {core/image aligned left or right}': 20,
'.editor-block-list__block:before': -1,
'.editor-block-list__block .wp-block-more:before': -1,
'.editor-block-list__block {core/image aligned left or right}': 20,
'.freeform-toolbar': 10,
'.editor-warning': 1,
'.editor-visual-editor__sibling-inserter': 1,
'.editor-block-list__sibling-inserter': 1,
'.components-form-toggle__input': 1,
'.editor-format-list__menu': 1,
'.editor-inserter__tabs': 1,
Expand Down
2 changes: 1 addition & 1 deletion editor/assets/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ body.gutenberg-editor-page {
}

.editor-post-title,
.editor-visual-editor__block {
.editor-block-list__block {
input,
textarea {
border-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import NavigableToolbar from '../../navigable-toolbar';
import { BlockToolbar } from '../../components';
import { BlockToolbar } from '../';
import { isFeatureActive } from '../../selectors';

function BlockContextualToolbar( { hasFixedToolbar } ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { Warning } from '../../components';
import Warning from '../warning';

const warning = (
<Warning>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BlockHTML extends Component {
const { html } = this.state;
return (
<TextareaAutosize
className="blocks-visual-editor__block-html-textarea"
className="editor-block-list__block-html-textarea"
value={ html }
onBlur={ this.onBlur }
onChange={ this.onChange }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import BlockMover from '../../components/block-mover';
import BlockSettingsMenu from '../../components/block-settings-menu';
import BlockMover from '../block-mover';
import BlockSettingsMenu from '../block-settings-menu';
import InvalidBlockWarning from './invalid-block-warning';
import BlockCrashWarning from './block-crash-warning';
import BlockCrashBoundary from './block-crash-boundary';
Expand Down Expand Up @@ -56,7 +56,7 @@ import {

const { BACKSPACE, ESCAPE, DELETE, ENTER, UP, RIGHT, DOWN, LEFT } = keycodes;

class VisualEditorBlock extends Component {
class BlockListBlock extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -324,7 +324,7 @@ class VisualEditorBlock extends Component {
const { isHovered, isSelected, isMultiSelected, isFirstMultiSelected, focus } = this.props;
const showUI = isSelected && ( ! this.props.isTyping || ( focus && focus.collapsed === false ) );
const { error } = this.state;
const wrapperClassName = classnames( 'editor-visual-editor__block', {
const wrapperClassName = classnames( 'editor-block-list__block', {
'has-warning': ! isValid || !! error,
'is-selected': showUI,
'is-multi-selected': isMultiSelected,
Expand Down Expand Up @@ -369,7 +369,7 @@ class VisualEditorBlock extends Component {
onMouseDown={ this.onPointerDown }
onKeyDown={ this.onKeyDown }
onFocus={ this.onFocus }
className="editor-visual-editor__block-edit"
className="editor-block-list__block-edit"
tabIndex="0"
aria-label={ blockLabel }
>
Expand Down Expand Up @@ -487,4 +487,4 @@ export default connect(
dispatch( editPost( { meta } ) );
},
} )
)( VisualEditorBlock );
)( BlockListBlock );
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import { serialize, getDefaultBlockName, createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import VisualEditorBlock from './block';
import VisualEditorSiblingInserter from './sibling-inserter';
import './style.scss';
import BlockListBlock from './block';
import BlockListSiblingInserter from './sibling-inserter';
import BlockDropZone from './block-drop-zone';
import {
getBlockUids,
Expand All @@ -38,7 +39,7 @@ import {
} from '../../selectors';
import { insertBlock, startMultiSelect, stopMultiSelect, multiSelect, selectBlock } from '../../actions';

class VisualEditorBlockList extends Component {
class BlockList extends Component {
constructor( props ) {
super( props );

Expand Down Expand Up @@ -209,22 +210,22 @@ class VisualEditorBlockList extends Component {

return (
<div>
{ !! blocks.length && <VisualEditorSiblingInserter /> }
{ !! blocks.length && <BlockListSiblingInserter /> }
{ flatMap( blocks, ( uid ) => [
<VisualEditorBlock
<BlockListBlock
key={ 'block-' + uid }
uid={ uid }
blockRef={ this.setBlockRef }
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>,
<VisualEditorSiblingInserter
<BlockListSiblingInserter
key={ 'sibling-inserter-' + uid }
uid={ uid }
/>,
] ) }
{ ! blocks.length &&
<div className="editor-visual-editor__placeholder">
<div className="editor-block-list__placeholder">
<BlockDropZone />
<input
type="text"
Expand Down Expand Up @@ -270,4 +271,4 @@ export default connect(
dispatch( { type: 'REMOVE_BLOCKS', uids } );
},
} )
)( VisualEditorBlockList );
)( BlockList );
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { connect } from 'react-redux';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
*/
import { Warning } from '../../components';
import {
getBlockType,
getUnknownTypeHandlerName,
Expand All @@ -23,6 +18,7 @@ import {
* Internal dependencies
*/
import { replaceBlock } from '../../actions';
import Warning from '../warning';

function InvalidBlockWarning( { ignoreInvalid, switchToBlockType } ) {
const htmlBlockName = 'core/html';
Expand All @@ -37,7 +33,7 @@ function InvalidBlockWarning( { ignoreInvalid, switchToBlockType } ) {
'Overwrite the external changes or Convert to %s or %s to keep ' +
'your changes.'
), defaultBlockType.title, htmlBlockType.title ) }</p>
<p className="visual-editor__invalid-block-warning-buttons">
<p>
<Button
onClick={ ignoreInvalid }
isLarge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { connect } from 'react-redux';
/**
* Internal dependencies
*/
import BlockMover from '../../components/block-mover';
import BlockSettingsMenu from '../../components/block-settings-menu';
import BlockMover from '../block-mover';
import BlockSettingsMenu from '../block-settings-menu';
import {
getMultiSelectedBlockUids,
isMultiSelecting,
} from '../../selectors';

function VisualEditorBlockMultiControls( { multiSelectedBlockUids, isSelecting } ) {
function BlockListMultiControls( { multiSelectedBlockUids, isSelecting } ) {
if ( isSelecting ) {
return null;
}
Expand All @@ -36,4 +36,4 @@ export default connect( ( state ) => {
multiSelectedBlockUids: getMultiSelectedBlockUids( state ),
isSelecting: isMultiSelecting( state ),
};
} )( VisualEditorBlockMultiControls );
} )( BlockListMultiControls );
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { focus } from '@wordpress/utils';
/**
* Internal dependencies
*/
import { Inserter } from '../../components';
import Inserter from '../inserter';
import {
getBlockUids,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
isBlockWithinSelection,
} from '../../selectors';

class VisualEditorSiblingInserter extends Component {
class BlockListSiblingInserter extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -96,7 +96,7 @@ class VisualEditorSiblingInserter extends Component {
const { insertIndex, showInsertionPoint } = this.props;
const { isVisible } = this.state;

const classes = classnames( 'editor-visual-editor__sibling-inserter', {
const classes = classnames( 'editor-block-list__sibling-inserter', {
'is-visible': isVisible || showInsertionPoint,
} );

Expand All @@ -111,7 +111,7 @@ class VisualEditorSiblingInserter extends Component {
onMouseLeave={ this.hide }
tabIndex={ isVisible ? -1 : 0 }>
{ showInsertionPoint && (
<div className="editor-visual-editor__insertion-point" />
<div className="editor-block-list__insertion-point" />
) }
{ isVisible &&
<Inserter
Expand Down Expand Up @@ -140,4 +140,4 @@ export default connect(
),
};
}
)( VisualEditorSiblingInserter );
)( BlockListSiblingInserter );
Loading

0 comments on commit 87e417f

Please sign in to comment.