Skip to content

Commit

Permalink
Merge branch 'trunk' into add/media-text-add-spacing-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiego authored Aug 22, 2022
2 parents 5afa029 + 2bc40bb commit 787ec32
Show file tree
Hide file tree
Showing 133 changed files with 2,378 additions and 983 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module.exports = {
'reverse',
'size',
'snakeCase',
'sortBy',
'startCase',
'startsWith',
'stubFalse',
Expand Down
6 changes: 4 additions & 2 deletions bin/plugin/commands/changelog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
const { groupBy, escapeRegExp, flow, sortBy } = require( 'lodash' );
const { groupBy, escapeRegExp, flow } = require( 'lodash' );
const Octokit = require( '@octokit/rest' );
const { sprintf } = require( 'sprintf-js' );
const semver = require( 'semver' );
Expand Down Expand Up @@ -823,7 +823,9 @@ function getContributorPropsMarkdownList( ftcPRs ) {
* @return {IssuesListForRepoResponseItem[]} The sorted list of pull requests.
*/
function sortByUsername( items ) {
return sortBy( items, ( item ) => item.user.login.toLowerCase() );
return [ ...items ].sort( ( a, b ) =>
a.user.login.toLowerCase().localeCompare( b.user.login.toLowerCase() )
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/format-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You will need:
- A minimal plugin activated and setup ready to edit
- JavaScript setup for building and enqueuing

The [complete format-api example](https://github.com/WordPress/gutenberg-examples/tree/trunk/format-api) is available that you can use as a reference for your setup.
The [complete format-api example](https://github.com/WordPress/gutenberg-examples/tree/trunk/non-block-examples/format-api) is available that you can use as a reference for your setup.

## Step-by-step guide

Expand Down
14 changes: 7 additions & 7 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ Gather blocks in a layout container. ([Source](https://github.com/WordPress/gute
- **Name:** core/group
- **Category:** design
- **Supports:** align (full, wide), anchor, ariaLabel, color (background, gradients, link, text), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** tagName, templateLock
- **Attributes:** layout, tagName, templateLock

## Heading

Introduce new sections and organize content to help visitors (and search engines) understand the structure of your content. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/heading))

- **Name:** core/heading
- **Category:** text
- **Supports:** __unstablePasteTextInline, align (full, wide), anchor, color (background, gradients, link, text), spacing (margin), typography (fontSize, lineHeight), ~~className~~
- **Supports:** __unstablePasteTextInline, align (full, wide), anchor, color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~className~~
- **Attributes:** content, level, placeholder, textAlign

## Home Link
Expand Down Expand Up @@ -365,7 +365,7 @@ Set media and words side-by-side for a richer layout. ([Source](https://github.c

- **Name:** core/media-text
- **Category:** media
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), spacing (margin, padding), ~~html~~
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** align, focalPoint, href, imageFill, isStackedOnMobile, linkClass, linkDestination, linkTarget, mediaAlt, mediaId, mediaLink, mediaPosition, mediaSizeSlug, mediaType, mediaUrl, mediaWidth, rel, verticalAlignment

## Unsupported
Expand Down Expand Up @@ -437,7 +437,7 @@ Start with the basic building block of all narrative. ([Source](https://github.c

- **Name:** core/paragraph
- **Category:** text
- **Supports:** __unstablePasteTextInline, anchor, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~className~~
- **Supports:** __unstablePasteTextInline, anchor, color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~className~~
- **Attributes:** align, content, direction, dropCap, placeholder

## Pattern
Expand Down Expand Up @@ -527,7 +527,7 @@ Add the date of this post. ([Source](https://github.com/WordPress/gutenberg/tree

- **Name:** core/post-date
- **Category:** theme
- **Supports:** color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~
- **Supports:** color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** displayType, format, isLink, textAlign

## Post Excerpt
Expand Down Expand Up @@ -833,7 +833,7 @@ Insert poetry. Use special spacing formats. Or quote song lyrics. ([Source](http

- **Name:** core/verse
- **Category:** text
- **Supports:** anchor, color (background, gradients, link, text), spacing (padding), typography (fontSize, lineHeight)
- **Supports:** anchor, color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight)
- **Attributes:** content, textAlign

## Video
Expand All @@ -842,7 +842,7 @@ Embed a video from your media library or upload a new one. ([Source](https://git

- **Name:** core/video
- **Category:** media
- **Supports:** align, anchor
- **Supports:** align, anchor, spacing (margin, padding)
- **Attributes:** autoplay, caption, controls, id, loop, muted, playsInline, poster, preload, src, tracks

<!-- END TOKEN Autogenerated - DO NOT EDIT -->
11 changes: 11 additions & 0 deletions docs/reference-guides/theme-json-reference/theme-json-living.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Setting that enables the following UI tools:
- typography: lineHeight


---

### useRootPaddingAwareAlignments

_**Note:** Since WordPress 6.1._

Enables root padding (the values from `styles.spacing.padding`) to be applied to the contents of full-width blocks instead of the root block.

Please note that when using this setting, `styles.spacing.padding` should always be set as an object with `top`, `right`, `bottom`, `left` values declared separately.


---

### border
Expand Down
32 changes: 31 additions & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
$layout_styles = array();
if ( 'default' === $layout_type ) {
if ( $has_block_gap_support ) {
if ( is_array( $gap_value ) ) {
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
}
if ( $gap_value && ! $should_skip_gap_serialization ) {
array_push(
$layout_styles,
array(
'selector' => "$selector > *",
'declarations' => array(
'margin-block-start' => '0',
'margin-block-end' => '0',
),
),
array(
'selector' => "$selector$selector > * + *",
'declarations' => array(
'margin-block-start' => $gap_value,
'margin-block-end' => '0',
),
)
);
}
}
} elseif ( 'constrained' === $layout_type ) {
$content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
$wide_size = isset( $layout['wideSize'] ) ? $layout['wideSize'] : '';

Expand Down Expand Up @@ -254,11 +279,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false;
$default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout;

if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) {
if ( ! $global_layout_settings ) {
return $block_content;
}
$used_layout = $global_layout_settings;
}

$class_names = array();
Expand All @@ -268,6 +293,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$layout_classname = '';
$use_global_padding = gutenberg_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) && ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] );

// Set the correct layout type for blocks using legacy content width.
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
$used_layout['type'] = 'constrained';
}

if ( $use_global_padding ) {
$class_names[] = 'has-global-padding';
}
Expand Down
43 changes: 30 additions & 13 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,6 @@ function( $pseudo_selector ) use ( $selector ) {
}
}

/*
* Reset default browser margin on the root body element.
* This is set on the root selector **before** generating the ruleset
* from the `theme.json`. This is to ensure that if the `theme.json` declares
* `margin` in its `spacing` declaration for the `body` element then these
* user-generated values take precedence in the CSS cascade.
* @link https://github.com/WordPress/gutenberg/issues/36147.
*/
if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
$block_rules .= 'body { margin: 0; }';
}

// 2. Generate and append the rules that use the general selector.
$block_rules .= static::to_ruleset( $selector, $declarations );

Expand All @@ -793,6 +781,34 @@ function( $pseudo_selector ) use ( $selector ) {
}

if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
/*
* Reset default browser margin on the root body element.
* This is set on the root selector **before** generating the ruleset
* from the `theme.json`. This is to ensure that if the `theme.json` declares
* `margin` in its `spacing` declaration for the `body` element then these
* user-generated values take precedence in the CSS cascade.
* @link https://github.com/WordPress/gutenberg/issues/36147.
*/
$block_rules .= 'body { margin: 0;';

/*
* If there are content and wide widths in theme.json, output them
* as custom properties on the body element so all blocks can use them.
*/
if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) {
$content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize'];
$content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial';
$wide_size = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize'];
$wide_size = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial';
$block_rules .= '--wp--style--global--content-size: ' . $content_size . ';';
$block_rules .= '--wp--style--global--wide-size: ' . $wide_size . ';';
}

$block_rules .= '}';
}

if ( static::ROOT_BLOCK_SELECTOR === $selector ) {

if ( $use_root_padding ) {
$block_rules .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }';
$block_rules .= '.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }';
Expand All @@ -804,6 +820,7 @@ function( $pseudo_selector ) use ( $selector ) {
$block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
$block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';

$block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' );
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
if ( $has_block_gap_support ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
Expand Down Expand Up @@ -1295,7 +1312,7 @@ protected function get_layout_styles( $block_metadata ) {
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() );
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, and child combinator selectors.
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.

// Gap styles will only be output if the theme has block gap support, or supports a fallback gap.
// Default layout gap styles will be skipped for themes that do not explicitly opt-in to blockGap with a `true` or `false` value.
Expand Down
60 changes: 60 additions & 0 deletions lib/compat/wordpress-6.1/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,66 @@
}
]
},
"constrained": {
"name": "constrained",
"slug": "constrained",
"className": "is-layout-constrained",
"baseStyles": [
{
"selector": " > .alignleft",
"rules": {
"float": "left",
"margin-inline-start": "0",
"margin-inline-end": "2em"
}
},
{
"selector": " > .alignright",
"rules": {
"float": "right",
"margin-inline-start": "2em",
"margin-inline-end": "0"
}
},
{
"selector": " > .aligncenter",
"rules": {
"margin-left": "auto !important",
"margin-right": "auto !important"
}
},
{
"selector": " > :where(:not(.alignleft):not(.alignright):not(.alignfull))",
"rules": {
"max-width": "var(--wp--style--global--content-size)",
"margin-left": "auto !important",
"margin-right": "auto !important"
}
},
{
"selector": " > .alignwide",
"rules": {
"max-width": "var(--wp--style--global--wide-size)"
}
}
],
"spacingStyles": [
{
"selector": " > *",
"rules": {
"margin-block-start": "0",
"margin-block-end": "0"
}
},
{
"selector": " > * + *",
"rules": {
"margin-block-start": null,
"margin-block-end": "0"
}
}
]
},
"flex": {
"name": "flex",
"slug": "flex",
Expand Down
29 changes: 17 additions & 12 deletions packages/babel-plugin-makepot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@
*/

const { po } = require( 'gettext-parser' );
const {
pick,
reduce,
forEach,
sortBy,
isEqual,
merge,
isEmpty,
} = require( 'lodash' );
const { pick, reduce, forEach, isEqual, merge, isEmpty } = require( 'lodash' );
const { relative, sep } = require( 'path' );
const { writeFileSync } = require( 'fs' );

Expand Down Expand Up @@ -196,6 +188,20 @@ function isSameTranslation( a, b ) {
);
}

/**
* Sorts multiple translation objects by their reference.
* The reference is where they occur, in the format `file:line`.
*
* @param {Array} translations Array of translations to sort.
*
* @return {Array} Sorted translations.
*/
function sortByReference( translations = [] ) {
return [ ...translations ].sort( ( a, b ) =>
a.comments.reference.localeCompare( b.comments.reference )
);
}

module.exports = () => {
const strings = {};
let nplurals = 2,
Expand Down Expand Up @@ -323,9 +329,8 @@ module.exports = () => {
( memo, file ) => {
for ( const context in strings[ file ] ) {
// Within the same file, sort translations by line.
const sortedTranslations = sortBy(
strings[ file ][ context ],
'comments.reference'
const sortedTranslations = sortByReference(
strings[ file ][ context ]
);

forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) {
}

// Starting here, it's the fallback for themes not supporting the layout config.
if ( layoutType.name !== 'default' ) {
if ( layoutType.name !== 'default' && layoutType.name !== 'constrained' ) {
return [];
}
const { alignments: availableAlignments = DEFAULT_CONTROLS } = layout;
Expand Down
3 changes: 0 additions & 3 deletions packages/block-editor/src/components/rich-text/use-enter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* WordPress dependencies
*/
/**
* WordPress dependencies
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/url-input/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ $input-size: 300px;

.components-spinner {
position: absolute;
right: $input-padding;
bottom: $input-padding + $grid-unit-10 + 1;
margin: 0;
top: calc(50% - #{$spinner-size} / 2);
right: $grid-unit;
}
}

Expand Down
Loading

0 comments on commit 787ec32

Please sign in to comment.