Skip to content

Commit

Permalink
Editor: add text orientation for blocks with typography support.
Browse files Browse the repository at this point in the history
Adds a new text orientation option to the typography block support, implemented with CSS writing-mode.

Props poena.
Fixes #59306.


git-svn-id: https://develop.svn.wordpress.org/trunk@56605 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Sep 18, 2023
1 parent ac8db41 commit da48a9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function wp_register_typography_support( $block_type ) {
$has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), 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_writing_mode_support = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );

$has_typography_support = $has_font_family_support
|| $has_font_size_support
Expand All @@ -43,7 +44,8 @@ function wp_register_typography_support( $block_type ) {
|| $has_line_height_support
|| $has_text_columns_support
|| $has_text_decoration_support
|| $has_text_transform_support;
|| $has_text_transform_support
|| $has_writing_mode_support;

if ( ! $block_type->attributes ) {
$block_type->attributes = array();
Expand Down Expand Up @@ -105,6 +107,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), 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_writing_mode_support = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );

// Whether to skip individual block support features.
$should_skip_font_size = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' );
Expand All @@ -116,6 +119,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
$should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
$should_skip_writing_mode = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );

$typography_block_styles = array();
if ( $has_font_size_support && ! $should_skip_font_size ) {
Expand Down Expand Up @@ -205,6 +209,17 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
);
}

if ( $has_writing_mode_support &&
! $should_skip_writing_mode &&
isset( $block_attributes['style']['typography']['writingMode'] )
) {
$typography_block_styles['writingMode'] = _wp_array_get(
$block_attributes,
array( 'style', 'typography', 'writingMode' ),
null
);
}

$attributes = array();
$styles = wp_style_engine_get_styles(
array( 'typography' => $typography_block_styles ),
Expand Down
6 changes: 5 additions & 1 deletion src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class WP_Theme_JSON {
* removed the `--wp--style--block-gap` property.
* @since 6.2.0 Added `outline-*`, and `min-height` properties.
* @since 6.3.0 Added `column-count` property.
* @since 6.4.0 Added `writing-mode` property.
*
* @var array
*/
Expand Down Expand Up @@ -261,6 +262,7 @@ class WP_Theme_JSON {
'text-transform' => array( 'typography', 'textTransform' ),
'filter' => array( 'filter', 'duotone' ),
'box-shadow' => array( 'shadow' ),
'writing-mode' => array( 'typography', 'writingMode' ),
);

/**
Expand Down Expand Up @@ -340,7 +342,7 @@ class WP_Theme_JSON {
* @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', 'shadow.defaultPresets',
* `position.fixed` and `position.sticky`.
* @since 6.3.0 Added support for `typography.textColumns`, removed `layout.definitions`.
* @since 6.4.0 Added `layout.allowEditing`.
* @since 6.4.0 Added `layout.allowEditing` and `typography.writingMode`.
*
* @var array
*/
Expand Down Expand Up @@ -409,6 +411,7 @@ class WP_Theme_JSON {
'textColumns' => null,
'textDecoration' => null,
'textTransform' => null,
'writingMode' => null,
),
);

Expand Down Expand Up @@ -471,6 +474,7 @@ class WP_Theme_JSON {
'textColumns' => null,
'textDecoration' => null,
'textTransform' => null,
'writingMode' => null,
),
'css' => null,
);
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
"letterSpacing": true,
"lineHeight": false,
"textDecoration": true,
"textTransform": true
"textTransform": true,
"writingMode": false
},
"blocks": {
"core/button": {
Expand Down

0 comments on commit da48a9e

Please sign in to comment.