Skip to content

Commit

Permalink
Block Switcher: Giving priority to the "to" transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and nylen committed Apr 19, 2017
1 parent 3e8b5b5 commit 9380c38
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions blocks/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ export function createBlock( blockType, attributes = {} ) {
* @return {Object?} Block object
*/
export function switchToBlockType( block, blockType ) {
// Find the right transformation by giving priority to the "to" transformation
const destinationSettings = getBlockSettings( blockType );
const sourceSettings = getBlockSettings( block.blockType );
const transformationsFrom = get( destinationSettings, 'transforms.from', [] );
const transformationsTo = get( sourceSettings, 'transforms.to', [] );

// Find the from transformation
const transformation =
transformationsFrom.find( t => t.blocks.indexOf( block.blockType ) !== -1 ) ||
transformationsTo.find( t => t.blocks.indexOf( blockType ) !== -1 );
transformationsTo.find( t => t.blocks.indexOf( blockType ) !== -1 ) ||
transformationsFrom.find( t => t.blocks.indexOf( block.blockType ) !== -1 );

if ( ! transformation ) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function VisualEditorBlock( props ) {
className={ className }
>
{ ( isSelected || isHovered ) && <BlockMover uid={ block.uid } /> }
<div className="editor-visual-editor__block_controls">
<div className="editor-visual-editor__block-controls">
{ isSelected && <BlockSwitcher uid={ block.uid } /> }
{ isSelected && settings.controls ? (
<Toolbar
Expand Down
6 changes: 3 additions & 3 deletions editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
}
}

.editor-visual-editor__block_controls {
.editor-visual-editor__block-controls {
position: absolute;
bottom: 100%;
margin-bottom: -4px;
left: 43px;
display: flex;
}

.editor-visual-editor__block_controls .editor-toolbar {
.editor-visual-editor__block-controls .editor-toolbar {
display: inline-flex;
}

.editor-visual-editor__block_controls .editor-block-switcher {
.editor-visual-editor__block-controls .editor-block-switcher {
display: inline-flex;
}

Expand Down

0 comments on commit 9380c38

Please sign in to comment.