Skip to content

Commit

Permalink
revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Nov 19, 2018
1 parent 3407de7 commit 1269a49
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ import { withSelect } from '@wordpress/data';
import { BlockControls, BlockAlignmentToolbar } from '../components';

/**
* Internal Constants
*/
* An array which includes all possible valid alignments,
* used to validate if an alignment is valid or not.
*
* @constant
* @type {string[]}
*/
const ALL_ALIGNMENTS = [ 'left', 'center', 'right', 'wide', 'full' ];

/**
* An array which includes all wide alignments.
* In order for this alignments to be valid they need to be supported by the block,
* and by the theme.
*
* @constant
* @type {string[]}
*/
const WIDE_ALIGNMENTS = [ 'wide', 'full' ];

/**
Expand All @@ -34,7 +47,7 @@ const WIDE_ALIGNMENTS = [ 'wide', 'full' ];
*
* @return {string[]} Valid alignments.
*/
export const getValidAlignments = ( blockAlign, hasWideBlockSupport = true, hasWideEnabled = true ) => {
export function getValidAlignments( blockAlign, hasWideBlockSupport = true, hasWideEnabled = true ) {
let validAlignments;
if ( Array.isArray( blockAlign ) ) {
validAlignments = blockAlign;
Expand All @@ -47,13 +60,13 @@ export const getValidAlignments = ( blockAlign, hasWideBlockSupport = true, hasW

if (
! hasWideEnabled ||
( blockAlign === true && ! hasWideBlockSupport )
( blockAlign === true && ! hasWideBlockSupport )
) {
return without( validAlignments, ...WIDE_ALIGNMENTS );
}

return validAlignments;
};
}

/**
* Filters registered block settings, extending attributes to include `align`.
Expand Down Expand Up @@ -158,7 +171,7 @@ export const withDataAlign = createHigherOrderComponent(
( select ) => {
const { getEditorSettings } = select( 'core/editor' );
return {
hasWideEnabled: getEditorSettings().alignWide,
hasWideEnabled: !! getEditorSettings().alignWide,
};
}
),
Expand Down

0 comments on commit 1269a49

Please sign in to comment.