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

Enable alignments/width for all blocks by default #28349

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { BlockListItems } from '../block-list';
import { BlockContextProvider } from '../block-context';
import { useBlockEditContext } from '../block-edit/context';
import useBlockSync from '../provider/use-block-sync';
import { defaultLayout, LayoutProvider } from './layout';
import { defaultLayout, flexHorizontalLayout, LayoutProvider } from './layout';

/**
* InnerBlocks is a component which allows a single block to have multiple blocks
Expand All @@ -50,9 +50,17 @@ function UncontrolledInnerBlocks( props ) {
renderAppender,
orientation,
placeholder,
__experimentalLayout: layout = defaultLayout,
__experimentalLayout,
} = props;

let layout = __experimentalLayout;
if ( ! layout && orientation === 'horizontal' ) {
layout = flexHorizontalLayout;
}
if ( ! layout && orientation !== 'horizontal' ) {
layout = defaultLayout;
}

useNestedSettingsUpdate(
clientId,
allowedBlocks,
Expand Down
12 changes: 10 additions & 2 deletions packages/block-editor/src/components/inner-blocks/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import BlockList from '../block-list';
import { useBlockEditContext } from '../block-edit/context';
import useBlockSync from '../provider/use-block-sync';
import { BlockContextProvider } from '../block-context';
import { defaultLayout, LayoutProvider } from './layout';
import { defaultLayout, flexHorizontalLayout, LayoutProvider } from './layout';

/**
* InnerBlocks is a component which allows a single block to have multiple blocks
Expand Down Expand Up @@ -51,9 +51,17 @@ function UncontrolledInnerBlocks( props ) {
horizontalAlignment,
filterInnerBlocks,
blockWidth,
__experimentalLayout: layout = defaultLayout,
__experimentalLayout,
} = props;

let layout = __experimentalLayout;
if ( ! layout && orientation === 'horizontal' ) {
layout = flexHorizontalLayout;
}
if ( ! layout && orientation !== 'horizontal' ) {
layout = defaultLayout;
}

const block = useSelect(
( select ) => select( 'core/block-editor' ).getBlock( clientId ),
[ clientId ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { createContext, useContext } from '@wordpress/element';

export const defaultLayout = { type: 'default' };
export const flexHorizontalLayout = { type: 'flex-horizontal' };

const Layout = createContext( defaultLayout );

Expand Down
8 changes: 4 additions & 4 deletions packages/block-editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function addAttribute( settings ) {
if ( has( settings.attributes, [ 'align', 'type' ] ) ) {
return settings;
}
if ( hasBlockSupport( settings, 'align' ) ) {
if ( hasBlockSupport( settings, 'align', true ) ) {
// Gracefully handle if settings.attributes is undefined.
settings.attributes = {
...settings.attributes,
Expand Down Expand Up @@ -120,7 +120,7 @@ export const withToolbarControls = createHigherOrderComponent(
// and without checking the layout for availble alignments.
// BlockAlignmentToolbar takes both of these into account.
const validAlignments = getValidAlignments(
getBlockSupport( blockName, 'align' ),
getBlockSupport( blockName, 'align', true ),
hasBlockSupport( blockName, 'alignWide', true )
);

Expand Down Expand Up @@ -174,7 +174,7 @@ export const withDataAlign = createHigherOrderComponent(
}

const validAlignments = getValidAlignments(
getBlockSupport( name, 'align' ),
getBlockSupport( name, 'align', true ),
hasBlockSupport( name, 'alignWide', true ),
hasWideEnabled
);
Expand All @@ -199,7 +199,7 @@ export const withDataAlign = createHigherOrderComponent(
*/
export function addAssignedAlign( props, blockType, attributes ) {
const { align } = attributes;
const blockAlign = getBlockSupport( blockType, 'align' );
const blockAlign = getBlockSupport( blockType, 'align', true );
const hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true );

// Compute valid alignments without taking into account if
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
}
},
"supports": {
"align": false,
"customClassName": false,
"html": false,
"inserter": false
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"apiVersion": 2,
"name": "core/column",
"category": "text",
"parent": [
"core/columns"
],
"parent": [ "core/columns" ],
"attributes": {
"verticalAlignment": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/freeform/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"supports": {
"className": false,
"customClassName": false,
"reusable": false
"reusable": false,
"align": false
},
"editorStyle": "wp-block-freeform-editor"
}
3 changes: 2 additions & 1 deletion packages/block-library/src/html/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"supports": {
"customClassName": false,
"className": false,
"html": false
"html": false,
"align": false
},
"editorStyle": "wp-block-html-editor"
}
1 change: 1 addition & 0 deletions packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
}
},
"supports": {
"align": false,
"anchor": true
},
"editorStyle": "wp-block-image-editor",
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/more/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"customClassName": false,
"className": false,
"html": false,
"multiple": false
"multiple": false,
"align": false
},
"editorStyle": "wp-block-more-editor"
}
3 changes: 2 additions & 1 deletion packages/block-library/src/nextpage/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"supports": {
"customClassName": false,
"className": false,
"html": false
"html": false,
"align": false
},
"editorStyle": "wp-block-nextpage-editor"
}
8 changes: 3 additions & 5 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
},
"direction": {
"type": "string",
"enum": [
"ltr",
"rtl"
]
"enum": [ "ltr", "rtl" ]
}
},
"supports": {
Expand All @@ -36,7 +33,8 @@
"fontSize": true,
"lineHeight": true,
"__experimentalSelector": "p",
"__unstablePasteTextInline": true
"__unstablePasteTextInline": true,
"align": false
},
"editorStyle": "wp-block-paragraph-editor",
"style": "wp-block-paragraph"
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/quote/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
}
},
"supports": {
"anchor": true
"anchor": true,
"align": false
},
"editorStyle": "wp-block-quote-editor",
"style": "wp-block-quote"
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/shortcode/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"supports": {
"className": false,
"customClassName": false,
"html": false
"html": false,
"align": false
},
"editorStyle": "wp-block-shortcode-editor"
}