Skip to content

Commit

Permalink
Update: Typography supports shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 26, 2021
1 parent d4d76a1 commit 0aaef20
Show file tree
Hide file tree
Showing 32 changed files with 176 additions and 85 deletions.
36 changes: 23 additions & 13 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ function gutenberg_register_typography_support( $block_type ) {
return;
}

$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );
$typography_supports = _wp_array_get( $block_type->supports, array( 'typograpgy' ), false );
if ( ! $typography_supports ) {
return;
}

$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

$has_typography_support = $has_font_size_support
|| $has_font_weight_support
Expand Down Expand Up @@ -65,13 +70,18 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
$classes = array();
$styles = array();

$has_font_family_support = _wp_array_get( $block_type->supports, array( '__experimentalFontFamily' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );
$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
if ( ! $typography_supports ) {
return array();
}

$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

$skip_font_size_support_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipFontSizeSerialization' ), false );

Expand Down
33 changes: 33 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,36 @@ function gutenberg_block_has_support( $block_type, $feature, $default = false )

return true === $block_support || is_array( $block_support );
}

/**
* Updates the shape of supports for declaring fontSize and lineHeight.
*
* @param array $metadata Metadata for registering a block type.
* @return array Metadata for registering a block type with the supports shape updated.
*/
function gutenberg_migrate_old_typography_shape( $metadata ) {
if ( isset( $metadata['supports'] ) ) {
$font_size_support = _wp_array_get( $metadata['supports'], array( 'fontSize' ), null );
$line_height_support = _wp_array_get( $metadata['supports'], array( 'lineHeight' ), null );
if ( null !== $font_size_support ) {
trigger_error(
sprintf( __( 'Block %s is declaring fontSize support on block.json under supports.fontSize. Font size support is now declared under supports.typography.fontSize.', 'gutenberg' ), $metadata['name'] ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
gutenberg_experimental_set( $metadata['supports'], array( 'typography', 'fontSize' ), $font_size_support );
unset( $metadata['supports']['fontSize'] );
}
if ( null !== $line_height_support ) {
trigger_error(
sprintf( __( 'Block %s is declaring lineHeight support on block.json under supports.lineHeight. Line height support is now declared under supports.typography.lineHeight.', 'gutenberg' ), $metadata['name'] ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
gutenberg_experimental_set( $metadata['supports'], array( 'typography', 'lineHeight' ), $line_height_support );
unset( $metadata['supports']['lineHeight'] );
}
}
return $metadata;
}


add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );
4 changes: 2 additions & 2 deletions packages/block-editor/src/hooks/font-appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { cleanEmptyObject } from './utils';
/**
* Key within block settings' support array indicating support for font style.
*/
export const FONT_STYLE_SUPPORT_KEY = '__experimentalFontStyle';
export const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';

/**
* Key within block settings' support array indicating support for font weight.
*/
export const FONT_WEIGHT_SUPPORT_KEY = '__experimentalFontWeight';
export const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';

/**
* Inspector control panel containing the font appearance options.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/font-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { cleanEmptyObject } from './utils';
import useSetting from '../components/use-setting';
import FontFamilyControl from '../components/font-family';

export const FONT_FAMILY_SUPPORT_KEY = '__experimentalFontFamily';
export const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';

const getFontFamilyFromAttributeValue = ( fontFamilies, value ) => {
const attributeParsed = /var:preset\|font-family\|(.+)/.exec( value );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { cleanEmptyObject } from './utils';
import useSetting from '../components/use-setting';

export const FONT_SIZE_SUPPORT_KEY = 'fontSize';
export const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';

/**
* Filters registered block settings, extending attributes to include
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/line-height.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LineHeightControl from '../components/line-height-control';
import { cleanEmptyObject } from './utils';
import useSetting from '../components/use-setting';

export const LINE_HEIGHT_SUPPORT_KEY = 'lineHeight';
export const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';

/**
* Inspector control panel containing the line height related configuration
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/hooks/text-decoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { cleanEmptyObject } from './utils';
* Key within block settings' supports array indicating support for text
* decorations e.g. settings found in `block.json`.
*/
export const TEXT_DECORATION_SUPPORT_KEY = '__experimentalTextDecoration';
export const TEXT_DECORATION_SUPPORT_KEY =
'typography.__experimentalTextDecoration';

/**
* Inspector control panel containing the text decoration options.
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/hooks/text-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { cleanEmptyObject } from './utils';
* Key within block settings' supports array indicating support for text
* transforms e.g. settings found in `block.json`.
*/
export const TEXT_TRANSFORM_SUPPORT_KEY = '__experimentalTextTransform';
export const TEXT_TRANSFORM_SUPPORT_KEY =
'typography.__experimentalTextTransform';

/**
* Inspector control panel containing the text transform options.
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
"__experimentalSkipSerialization": true,
"gradients": true
},
"fontSize": true,
"typography": {
"fontSize": true,
"__experimentalFontFamily": true
},
"reusable": false,
"__experimentalBorder": {
"radius": true,
"__experimentalSkipSerialization": true
},
"__experimentalFontFamily": true,
"__experimentalSelector": ".wp-block-button__link"
},
"styles": [
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"supports": {
"anchor": true,
"fontSize": true
"typography": {
"fontSize": true
}
},
"style": "wp-block-code"
}
8 changes: 5 additions & 3 deletions packages/block-library/src/heading/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
"color": {
"link": true
},
"fontSize": true,
"lineHeight": true,
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontWeight": true
},
"__experimentalSelector": "h1,h2,h3,h4,h5,h6",
"__experimentalFontWeight": true,
"__unstablePasteTextInline": true
},
"editorStyle": "wp-block-heading-editor",
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/list/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"supports": {
"anchor": true,
"className": false,
"fontSize": true,
"typography": {
"fontSize": true
},
"color": {
"gradients": true
},
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/loginout/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
},
"supports": {
"className": true,
"fontSize": false
"typography": {
"fontSize": false
}
}
}
18 changes: 10 additions & 8 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@
"anchor": true,
"html": false,
"inserter": true,
"fontSize": true,
"lineHeight": true,
"__experimentalFontStyle": true,
"__experimentalFontWeight": true,
"__experimentalTextTransform": true,
"color": true,
"__experimentalFontFamily": true,
"__experimentalTextDecoration": true
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontStyle": true,
"__experimentalFontWeight": true,
"__experimentalTextTransform": true,
"__experimentalFontFamily": true,
"__experimentalTextDecoration": true
},
"color": true
},
"editorStyle": "wp-block-navigation-editor",
"style": "wp-block-navigation"
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"color": {
"link": true
},
"fontSize": true,
"lineHeight": true,
"typography": {
"fontSize": true,
"lineHeight": true
},
"__experimentalSelector": "p",
"__unstablePasteTextInline": true
},
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/post-author/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"usesContext": [ "postType", "postId" ],
"supports": {
"html": false,
"fontSize": true,
"typography": {
"fontSize": true,
"lineHeight": true
},
"color": {
"gradients": true,
"link": true
},
"lineHeight": true
}
},
"editorStyle": "wp-block-post-author-editor",
"style": "wp-block-post-author"
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/post-comments-count/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"color": {
"gradients": true
},
"fontSize": true,
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
}
}
6 changes: 4 additions & 2 deletions packages/block-library/src/post-comments-form/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"gradients": true,
"link": true
},
"fontSize": true,
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
},
"style": "wp-block-post-comments-form"
}
6 changes: 4 additions & 2 deletions packages/block-library/src/post-comments-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
},
"supports": {
"html": false,
"fontSize": true,
"color": {
"link": true,
"text": false
},
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
}
}
8 changes: 5 additions & 3 deletions packages/block-library/src/post-comments/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"supports": {
"html": false,
"align": [ "wide", "full" ],
"fontSize": true,
"typography": {
"fontSize": true,
"lineHeight": true
},
"color": {
"gradients": true,
"link": true
},
"lineHeight": true
}
},
"style": "wp-block-post-comments"
}
6 changes: 4 additions & 2 deletions packages/block-library/src/post-date/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"gradients": true,
"link": true
},
"fontSize": true,
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
}
}
6 changes: 4 additions & 2 deletions packages/block-library/src/post-excerpt/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
"usesContext": [ "postId", "postType" ],
"supports": {
"html": false,
"fontSize": true,
"color": {
"gradients": true,
"link": true
},
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-post-excerpt-editor",
"style": "wp-block-post-excerpt"
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/post-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"gradients": true,
"link": true
},
"fontSize": true,
"lineHeight": true,
"typography": {
"fontSize": true,
"lineHeight": true
},
"__experimentalFontFamily": true
},
"style": "wp-block-post-title"
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/preformatted/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"color": {
"gradients": true
},
"fontSize": true
"typography": {
"fontSize": true
}
},
"style": "wp-block-preformatted"
}
6 changes: 4 additions & 2 deletions packages/block-library/src/query-pagination-next/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"gradients": true,
"link": true
},
"fontSize": true,
"lineHeight": true
"typography": {
"fontSize": true,
"lineHeight": true
}
}
}
Loading

0 comments on commit 0aaef20

Please sign in to comment.