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

Add Typography text-orientation (Upright and mixed letters) #52624

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
89ab1e5
Add text-orientation to the typography block support
carolinan Jul 14, 2023
7ecad4d
Update class-wp-style-engine.php
carolinan Jul 14, 2023
6288da8
Update legends, hide text-orientation control unless the text is vert…
carolinan Aug 10, 2023
7d64651
Update class-wp-style-engine.php
carolinan Aug 10, 2023
e4e680b
Update index.php
carolinan Aug 15, 2023
fd4c2d3
remove the class names
carolinan Aug 15, 2023
beca765
Replace the icons
carolinan Aug 17, 2023
819e33c
Update the onDeslect reset
carolinan Aug 17, 2023
0405684
Post navigation link: Add spacing to the inline style
carolinan Sep 1, 2023
8d82b61
Remove the broken reset
carolinan Sep 1, 2023
2b1bc2a
Post navigation link: Update the condition for the inline styles
carolinan Sep 1, 2023
09b5f91
Update index.php
carolinan Sep 1, 2023
6496ba4
Remove the unused useEffect from the typography panel
carolinan Sep 1, 2023
093e659
Update condition in typograhy.php and remove unnecessary constant fro…
carolinan Sep 4, 2023
18a0952
CS fix, remove unised variable.
carolinan Sep 4, 2023
4158f17
CS fix, adjust spacing.
carolinan Sep 4, 2023
1871d4d
Update lib/class-wp-theme-json-gutenberg.php
aristath Sep 6, 2023
c537dcb
add new UI to control writing mode
scruffian Sep 12, 2023
fcae9ae
remove sideways option
scruffian Sep 13, 2023
14d0f52
Map text orientation and writing mode to the values in the control
scruffian Sep 15, 2023
cde6b74
remove the text orientation control
scruffian Sep 15, 2023
032896f
update reset function
scruffian Sep 15, 2023
aa624ca
remove text orientation import
scruffian Sep 15, 2023
9d0832b
remove unused code
scruffian Sep 15, 2023
e6104cf
make alphabetical
scruffian Sep 15, 2023
916ab15
Add RTL icons
scruffian Sep 18, 2023
bdadc10
remove mixed icon
scruffian Sep 18, 2023
52e66f2
Add textHorizontal back
scruffian Sep 18, 2023
8906072
Merge branch 'trunk' into add/text-orientation
carolinan Sep 28, 2023
4845cba
CS fixes
aristath Sep 28, 2023
c0c5026
Update class-wp-theme-json-gutenberg.php
carolinan Sep 28, 2023
1e63355
Update class-wp-theme-json-gutenberg.php
carolinan Sep 28, 2023
21c9e70
Revert theme.json changes.
carolinan Sep 28, 2023
9adb5d2
Update theme.json
carolinan Sep 28, 2023
e29ce83
Merge branch 'trunk' into add/text-orientation
carolinan Oct 2, 2023
3328e3f
Re-add isShownByDefault
carolinan Oct 2, 2023
3116442
Add text-orientation to the safe_style_css filter
carolinan Oct 3, 2023
859ef09
Merge branch 'trunk' into add/text-orientation
carolinan Oct 3, 2023
45b8c19
Merge branch 'trunk' into add/text-orientation
carolinan Oct 10, 2023
542fdea
Try to safely remove unused code
carolinan Oct 10, 2023
cf7180b
fix CS spacing issues
carolinan Oct 10, 2023
f433ffb
Merge branch 'trunk' into add/text-orientation
carolinan Oct 18, 2023
e525528
Merge branch 'trunk' into add/text-orientation
carolinan Oct 25, 2023
8efe3a2
Fix CS issues after merge conflict
carolinan Oct 25, 2023
40d63e3
Merge branch 'trunk' into add/text-orientation
carolinan Jan 8, 2024
c42d2ea
Merge branch 'trunk' into add/text-orientation
carolinan Jan 25, 2024
859083e
Merge branch 'trunk' into add/text-orientation
carolinan Mar 7, 2024
5b6bd3e
Try to fix CS spacing issues after the merge conflict.
carolinan Mar 7, 2024
e060c4d
Try to re-add text-orientation block support
carolinan Mar 7, 2024
620e6be
CS: Increase spacing before double arrows in class-wp-theme-json-gute…
carolinan Mar 8, 2024
9ca0ded
Merge branch 'trunk' into add/text-orientation
carolinan Apr 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Settings related to typography.
| textColumns | boolean | false | |
| textDecoration | boolean | true | |
| writingMode | boolean | false | |
| textOrientation | boolean | false | |
| textTransform | boolean | true | |
| dropCap | boolean | true | |
| fontSizes | array | | fluid, name, size, slug |
Expand Down
6 changes: 6 additions & 0 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;
$has_text_orientation_support = $typography_supports['__experimentalTextOrientation'] ?? false;

Check warning on line 105 in lib/block-supports/typography.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 2 spaces.

Check failure on line 105 in lib/block-supports/typography.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Line indented incorrectly; expected at least 1 tabs, found 2 spaces

Check warning on line 105 in lib/block-supports/typography.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

// Whether to skip individual block support features.
$should_skip_font_size = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' );
Expand All @@ -115,6 +116,7 @@
$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' );
$should_skip_text_orentation = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textOrientation' );

$typography_block_styles = array();
if ( $has_font_size_support && ! $should_skip_font_size ) {
Expand Down Expand Up @@ -172,6 +174,10 @@

if ( $has_writing_mode_support && ! $should_skip_writing_mode && isset( $block_attributes['style']['typography']['writingMode'] ) ) {
$typography_block_styles['writingMode'] = $block_attributes['style']['typography']['writingMode'] ?? null;
// Text orientation requires writing mode to be set.
if ( $has_text_orientation_support && ! $should_skip_text_orentation && isset( $block_attributes['style']['typography']['textOrientation'] ) ) {
$typography_block_styles['textOrientation'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'textOrientation' ), null );
}
}

$attributes = array();
Expand Down
10 changes: 8 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@
* @since 6.1.0 Added `layout.definitions` and `useRootPaddingAwareAlignments`.
* @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', 'shadow.defaultPresets',
* `position.fixed` and `position.sticky`.
* @since 6.3.0 Removed `layout.definitions`. Added `typography.writingMode`.
* @since 6.3.0 Removed `layout.definitions`.
* @since 6.4.0 Added `layout.allowEditing`.
* @since 6.4.0 Added `lightbox`.
* Added `lightbox`.
* Added `typography.writingMode`.
* @since 6.6.0 Added `typography.textOrientation`.
* @var array
*/
const VALID_SETTINGS = array(
Expand Down Expand Up @@ -442,6 +444,7 @@
'textDecoration' => null,
'textTransform' => null,
'writingMode' => null,
'textOrientation' => null,

Check warning on line 447 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 2 spaces.

Check failure on line 447 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 447 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array item not aligned correctly; expected 12 spaces but found 6

Check warning on line 447 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 6 space(s) between "'textOrientation'" and double arrow, but found 1.
),
);

Expand Down Expand Up @@ -481,7 +484,9 @@
* added new property `shadow`,
* updated `blockGap` to be allowed at any level.
* @since 6.2.0 Added `outline`, and `minHeight` properties.
* @since 6.4.0 Added `writingMode` to `typography`.
* @since 6.6.0 Added `background` sub properties to top-level only.
* added `textOrientation` to `typography`.
*
* @var array
*/
Expand Down Expand Up @@ -538,6 +543,7 @@
'textDecoration' => null,
'textTransform' => null,
'writingMode' => null,
'textOrientation' => null,

Check warning on line 546 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found precision alignment of 2 spaces.

Check failure on line 546 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 546 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array item not aligned correctly; expected 12 spaces but found 6

Check warning on line 546 in lib/class-wp-theme-json-gutenberg.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 6 space(s) between "'textOrientation'" and double arrow, but found 1.
),
'css' => null,
);
Expand Down
18 changes: 18 additions & 0 deletions lib/compat/wordpress-6.6/kses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Temporary compatibility shims for block APIs present in Gutenberg.
*
* @package gutenberg
*/

/**
* Update allowed inline style attributes list.
*
* @param string[] $attrs Array of allowed CSS attributes.
* @return string[] CSS attributes.
*/
function gutenberg_safe_style_attrs_6_6( $attrs ) {
$attrs[] = 'text-orientation';
return $attrs;
}
add_filter( 'safe_style_css', 'gutenberg_safe_style_attrs_6_6' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.5/script-loader.php';

// WordPress 6.6 compat.
require __DIR__ . '/compat/wordpress-6.6/kses.php';
require __DIR__ . '/compat/wordpress-6.6/resolve-patterns.php';
require __DIR__ . '/compat/wordpress-6.6/block-bindings/pattern-overrides.php';
require __DIR__ . '/compat/wordpress-6.6/block-template-utils.php';
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const VALID_SETTINGS = [
'typography.textDecoration',
'typography.textTransform',
'typography.writingMode',
'typography.textOrientation',
];

export const useGlobalStylesReset = () => {
Expand Down Expand Up @@ -293,6 +294,7 @@ export function useSettingsForBlockElement(
'textTransform',
'textDecoration',
'writingMode',
'textOrientation',
].forEach( ( key ) => {
if ( ! supportedStyles.includes( key ) ) {
updatedSettings.typography = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __, isRTL } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element';

/**
Expand Down Expand Up @@ -315,20 +315,75 @@ export default function TypographyPanel( {
const hasTextDecoration = () => !! value?.typography?.textDecoration;
const resetTextDecoration = () => setTextDecoration( undefined );

// Text Orientation
// Writing Mode
const hasWritingModeControl = useHasWritingModeControl( settings );
const writingMode = decodeValue( inheritedValue?.typography?.writingMode );
const setWritingMode = ( newValue ) => {
onChange(
setImmutably(
value,
[ 'typography', 'writingMode' ],
newValue || undefined
)
);
};
const hasWritingMode = () => !! value?.typography?.writingMode;
const resetWritingMode = () => setWritingMode( undefined );
const resetWritingMode = () =>
setWritingModeAndTextOrientation( undefined );

// Text Orientation
const textOrientation = decodeValue(
inheritedValue?.typography?.textOrientation
);

// Returns the new text orientation and writing mode based on the value from the control.
const getTextOrientationAndWritingMode = ( valueFromControl ) => {
switch ( valueFromControl ) {
case 'top-to-bottom':
return {
newTextOrientation: 'mixed',
newWritingMode: isRTL() ? 'vertical-lr' : 'vertical-rl',
};

case 'upright':
return {
newTextOrientation: 'upright',
newWritingMode: isRTL() ? 'vertical-lr' : 'vertical-rl',
};

case 'horizontal':
return {
newTextOrientation: undefined,
newWritingMode: 'horizontal-tb',
};

default:
return {
newTextOrientation: undefined,
newWritingMode: undefined,
};
}
};

function getValuefromWritingModeAndTextOrientation() {
if ( writingMode === 'horizontal-tb' ) {
return 'horizontal';
}
if ( writingMode === 'vertical-lr' || writingMode === 'vertical-rl' ) {
if ( textOrientation === 'upright' ) {
return 'upright';
}
return 'top-to-bottom';
}
}

const setWritingModeAndTextOrientation = useCallback(
( newValue ) => {
const { newTextOrientation, newWritingMode } =
getTextOrientationAndWritingMode( newValue );

return onChange( {
...value,
typography: {
...value?.typography,
textOrientation: newTextOrientation,
writingMode: newWritingMode,
},
} );
},
[ onChange, value ]
);

const resetAllFilter = useCallback( ( previousValue ) => {
return {
Expand Down Expand Up @@ -475,23 +530,6 @@ export default function TypographyPanel( {
/>
</ToolsPanelItem>
) }
{ hasWritingModeControl && (
<ToolsPanelItem
className="single-column"
label={ __( 'Text orientation' ) }
hasValue={ hasWritingMode }
onDeselect={ resetWritingMode }
isShownByDefault={ defaultControls.writingMode }
panelId={ panelId }
>
<WritingModeControl
value={ writingMode }
onChange={ setWritingMode }
size="__unstable-large"
__nextHasNoMarginBottom
/>
</ToolsPanelItem>
) }
{ hasTextTransformControl && (
<ToolsPanelItem
label={ __( 'Letter case' ) }
Expand All @@ -510,6 +548,20 @@ export default function TypographyPanel( {
/>
</ToolsPanelItem>
) }
{ hasWritingModeControl && (
<ToolsPanelItem
label={ __( 'Text orientation' ) }
hasValue={ hasWritingMode }
onDeselect={ resetWritingMode }
isShownByDefault={ defaultControls.writingMode }
panelId={ panelId }
>
<WritingModeControl
value={ getValuefromWritingModeAndTextOrientation() }
onChange={ setWritingModeAndTextOrientation }
/>
</ToolsPanelItem>
) }
</Wrapper>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ import classnames from 'classnames';
*/
import { BaseControl, Button } from '@wordpress/components';
import { __, isRTL } from '@wordpress/i18n';
import { textHorizontal, textVertical } from '@wordpress/icons';
import {
textHorizontal,
textHorizontalRTL,
textUpright,
textVertical,
textVerticalRTL,
} from '@wordpress/icons';

const WRITING_MODES = [
{
name: __( 'Horizontal' ),
value: 'horizontal-tb',
icon: textHorizontal,
value: 'horizontal',
icon: isRTL() ? textHorizontalRTL : textHorizontal,
},
{
name: __( 'Vertical' ),
value: isRTL() ? 'vertical-lr' : 'vertical-rl',
icon: textVertical,
name: __( 'Top to bottom' ),
value: 'top-to-bottom',
icon: isRTL() ? textVerticalRTL : textVertical,
},
{
name: __( 'Upright' ),
value: 'upright',
icon: textUpright,
},
];

Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/hooks/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
* e.g. settings found in `block.json`.
*/
const WRITING_MODE_SUPPORT_KEY = 'typography.__experimentalWritingMode';
/**
* Key within block settings' supports array indicating support for text orientation
* e.g. settings found in `block.json`.
*/
const TEXT_ORIENTATION_SUPPORT_KEY = 'typography.__experimentalTextOrientation';
aristath marked this conversation as resolved.
Show resolved Hide resolved
/**
* Key within block settings' supports array indicating support for text
* transforms e.g. settings found in `block.json`.
Expand All @@ -63,6 +68,7 @@ const TYPOGRAPHY_SUPPORT_KEYS = [
TEXT_DECORATION_SUPPORT_KEY,
TEXT_TRANSFORM_SUPPORT_KEY,
WRITING_MODE_SUPPORT_KEY,
TEXT_ORIENTATION_SUPPORT_KEY,
LETTER_SPACING_SUPPORT_KEY,
];
const EFFECTS_SUPPORT_KEYS = [ 'shadow' ];
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export function useBlockSettings( name, parentLayout ) {
textColumns,
textDecoration,
writingMode,
textOrientation,
textTransform,
letterSpacing,
padding,
Expand Down Expand Up @@ -276,6 +277,7 @@ export function useBlockSettings( name, parentLayout ) {
'typography.textColumns',
'typography.textDecoration',
'typography.writingMode',
'typography.textOrientation',
'typography.textTransform',
'typography.letterSpacing',
'spacing.padding',
Expand Down Expand Up @@ -368,6 +370,7 @@ export function useBlockSettings( name, parentLayout ) {
textTransform,
letterSpacing,
writingMode,
textOrientation,
},
spacing: {
spacingSizes: {
Expand Down Expand Up @@ -411,6 +414,7 @@ export function useBlockSettings( name, parentLayout ) {
textTransform,
letterSpacing,
writingMode,
textOrientation,
padding,
margin,
blockGap,
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
@import "./components/skip-to-selected-block/style.scss";
@import "./components/text-decoration-control/style.scss";
@import "./components/text-transform-control/style.scss";
@import "./components/writing-mode-control/style.scss";
@import "./components/tool-selector/style.scss";
@import "./components/url-input/style.scss";
@import "./components/url-popover/style.scss";
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"__experimentalLetterSpacing": true,
"__experimentalTextTransform": true,
"__experimentalWritingMode": true,
"__experimentalTextOrientation": true,
"__experimentalDefaultControls": {
"fontSize": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalWritingMode": true,
"__experimentalTextOrientation": true,
"__experimentalDefaultControls": {
"fontSize": true
}
Expand Down
5 changes: 5 additions & 0 deletions packages/blocks/src/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
support: [ 'typography', '__experimentalWritingMode' ],
useEngine: true,
},
textOrientation: {
value: [ 'typography', 'textOrientation' ],
support: [ 'typography', '__experimentalTextOrientation' ],
useEngine: true,
},
'--wp--style--root--padding': {
value: [ 'spacing', 'padding' ],
support: [ 'spacing', 'padding' ],
Expand Down
3 changes: 3 additions & 0 deletions packages/icons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ export { default as sidesTop } from './library/sides-top';
export { default as sidesVertical } from './library/sides-vertical';
export { default as textColor } from './library/text-color';
export { default as textHorizontal } from './library/text-horizontal';
export { default as textHorizontalRTL } from './library/text-horizontal-rtl';
export { default as textUpright } from './library/text-upright';
export { default as textVertical } from './library/text-vertical';
export { default as textVerticalRTL } from './library/text-vertical-rtl';
export { default as tablet } from './library/tablet';
export { default as title } from './library/title';
export { default as tip } from './library/tip';
Expand Down
Loading
Loading