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

[pull] trunk from WordPress:trunk #133

Merged
merged 8 commits into from
Jan 2, 2025
Merged
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
4 changes: 2 additions & 2 deletions bin/test-create-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if [ "$expected" -ne "$actual" ]; then
exit 1
fi
expected=7
actual=$( find src -maxdepth 1 -type f | wc -l )
actual=$( find src -maxdepth 2 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`src\` directory, but found $actual."
exit 1
Expand All @@ -70,7 +70,7 @@ status "Building block..."

status "Verifying build..."
expected=9
actual=$( find build -maxdepth 1 -type f | wc -l )
actual=$( find build -maxdepth 2 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`build\` directory, but found $actual."
exit 1
Expand Down
453 changes: 453 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.6
* Requires PHP: 7.2
* Version: 19.9.0
* Version: 20.0.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function gutenberg_enqueue_block_style_variation_styles() {
}

// Add Gutenberg filters and action.
add_filter( 'render_block_data', 'gutenberg_render_block_style_variation_support_styles', 10, 2 );
add_filter( 'render_block_data', 'gutenberg_render_block_style_variation_support_styles' );
add_filter( 'render_block', 'gutenberg_render_block_style_variation_class_name', 10, 2 );
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_block_style_variation_styles', 1 );

Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/kses-allowed-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ function gutenberg_kses_allowed_html( $allowedtags ) {
);
return $allowedtags;
}
add_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowed_html', 10, 2 );
add_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowed_html' );
2 changes: 1 addition & 1 deletion lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function gutenberg_override_global_styles_endpoint( array $args ): array {

return $args;
}
add_filter( 'register_wp_global_styles_post_type_args', 'gutenberg_override_global_styles_endpoint', 10, 2 );
add_filter( 'register_wp_global_styles_post_type_args', 'gutenberg_override_global_styles_endpoint' );

/**
* Registers the Edit Site Export REST API routes.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "19.9.0",
"version": "20.0.0-rc.1",
"private": true,
"description": "A new WordPress editor experience.",
"author": "The WordPress Contributors",
Expand Down
55 changes: 31 additions & 24 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getGroupingBlockName,
} from './registration';
import {
isBlockRegistered,
normalizeBlockType,
__experimentalSanitizeBlockAttributes,
} from './utils';
Expand All @@ -31,6 +32,14 @@ import {
* @return {Object} Block object.
*/
export function createBlock( name, attributes = {}, innerBlocks = [] ) {
if ( ! isBlockRegistered( name ) ) {
return createBlock( 'core/missing', {
originalName: name,
originalContent: '',
originalUndelimitedContent: '',
} );
}

const sanitizedAttributes = __experimentalSanitizeBlockAttributes(
name,
attributes
Expand Down Expand Up @@ -94,15 +103,22 @@ export function __experimentalCloneSanitizedBlock(
mergeAttributes = {},
newInnerBlocks
) {
const { name } = block;

if ( ! isBlockRegistered( name ) ) {
return createBlock( 'core/missing', {
originalName: name,
originalContent: '',
originalUndelimitedContent: '',
} );
}

const clientId = uuid();

const sanitizedAttributes = __experimentalSanitizeBlockAttributes(
block.name,
{
...block.attributes,
...mergeAttributes,
}
);
const sanitizedAttributes = __experimentalSanitizeBlockAttributes( name, {
...block.attributes,
...mergeAttributes,
} );

return {
...block,
Expand Down Expand Up @@ -583,20 +599,11 @@ export function switchToBlockType( blocks, name ) {
*
* @return {Object} block.
*/
export const getBlockFromExample = ( name, example ) => {
try {
return createBlock(
name,
example.attributes,
( example.innerBlocks ?? [] ).map( ( innerBlock ) =>
getBlockFromExample( innerBlock.name, innerBlock )
)
);
} catch {
return createBlock( 'core/missing', {
originalName: name,
originalContent: '',
originalUndelimitedContent: '',
} );
}
};
export const getBlockFromExample = ( name, example ) =>
createBlock(
name,
example.attributes,
( example.innerBlocks ?? [] ).map( ( innerBlock ) =>
getBlockFromExample( innerBlock.name, innerBlock )
)
);
13 changes: 1 addition & 12 deletions packages/blocks/src/api/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,12 @@ export function synchronizeBlocksWithTemplate( blocks = [], template ) {
attributes
);

let [ blockName, blockAttributes ] =
const [ blockName, blockAttributes ] =
convertLegacyBlockNameAndAttributes(
name,
normalizedAttributes
);

// If a Block is undefined at this point, use the core/missing block as
// a placeholder for a better user experience.
if ( undefined === getBlockType( blockName ) ) {
blockAttributes = {
originalName: name,
originalContent: '',
originalUndelimitedContent: '',
};
blockName = 'core/missing';
}

return createBlock(
blockName,
blockAttributes,
Expand Down
15 changes: 15 additions & 0 deletions packages/blocks/src/api/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isUnmodifiedDefaultBlock,
getAccessibleBlockLabel,
getBlockLabel,
isBlockRegistered,
__experimentalSanitizeBlockAttributes,
getBlockAttributesNamesByRole,
isContentBlock,
Expand Down Expand Up @@ -213,6 +214,20 @@ describe( 'getAccessibleBlockLabel', () => {
} );
} );

describe( 'isBlockRegistered', () => {
it( 'returns true if the block is registered', () => {
registerBlockType( 'core/test-block', { title: 'Test block' } );
expect( isBlockRegistered( 'core/test-block' ) ).toBe( true );
unregisterBlockType( 'core/test-block' );
} );

it( 'returns false if the block is not registered', () => {
expect( isBlockRegistered( 'core/not-registered-test-block' ) ).toBe(
false
);
} );
} );

describe( 'sanitizeBlockAttributes', () => {
afterEach( () => {
getBlockTypes().forEach( ( block ) => {
Expand Down
11 changes: 11 additions & 0 deletions packages/blocks/src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ export function getDefault( attributeSchema ) {
}
}

/**
* Check if a block is registered.
*
* @param {string} name The block's name.
*
* @return {boolean} Whether the block is registered.
*/
export function isBlockRegistered( name ) {
return getBlockType( name ) !== undefined;
}

/**
* Ensure attributes contains only values defined by block type, and merge
* default values for missing attributes.
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

- Add new `Badge` component ([#66555](https://github.com/WordPress/gutenberg/pull/66555)).
- `Menu`: refactor to more granular sub-components ([#67422](https://github.com/WordPress/gutenberg/pull/67422)).
- `Badge`: Support text truncation ([#68107](https://github.com/WordPress/gutenberg/pull/68107)).

### Internal

Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ function Badge( {
icon={ contextBasedIcon() }
size={ 16 }
fill="currentColor"
className="components-badge__icon"
/>
) }
{ children }
<span className="components-badge__content">{ children }</span>
</span>
);
}
Expand Down
17 changes: 14 additions & 3 deletions packages/components/src/badge/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ $badge-colors: (
);

.components-badge {
@include reset;

background-color: color-mix(in srgb, $white 90%, var(--base-color));
color: color-mix(in srgb, $black 50%, var(--base-color));
padding: 0 $grid-unit-10;
min-height: $grid-unit-30;
max-width: 100%;
border-radius: $radius-small;
font-size: $font-size-small;
font-weight: 400;
flex-shrink: 0;
line-height: $font-line-height-small;
width: fit-content;
display: flex;
display: inline-flex;
align-items: center;
gap: 2px;

Expand All @@ -36,3 +37,13 @@ $badge-colors: (
}
}
}

.components-badge__icon {
flex-shrink: 0;
}

.components-badge__content {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
13 changes: 9 additions & 4 deletions packages/components/src/badge/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,32 @@ import { render, screen } from '@testing-library/react';
/**
* Internal dependencies
*/
import Badge from '..';
import _Badge from '..';

const testid = 'my-badge';
const Badge = ( props: React.ComponentProps< typeof _Badge > ) => (
<_Badge data-testid={ testid } { ...props } />
);

describe( 'Badge', () => {
it( 'should render correctly with default props', () => {
render( <Badge>Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toBeInTheDocument();
expect( badge.tagName ).toBe( 'SPAN' );
expect( badge ).toHaveClass( 'components-badge' );
} );

it( 'should render as per its intent and contain an icon', () => {
render( <Badge intent="error">Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toHaveClass( 'components-badge', 'is-error' );
expect( badge ).toHaveClass( 'has-icon' );
} );

it( 'should combine custom className with default class', () => {
render( <Badge className="custom-class">Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toHaveClass( 'components-badge' );
expect( badge ).toHaveClass( 'custom-class' );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
* Description: {{description}}
{{/description}}
* Version: {{version}}
* Requires at least: 6.6
* Requires PHP: 7.2
{{#requiresAtLeast}}
* Requires at least: {{requiresAtLeast}}
{{/requiresAtLeast}}
{{#requiresPHP}}
* Requires PHP: {{requiresPHP}}
{{/requiresPHP}}
{{#author}}
* Author: {{author}}
{{/author}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Contributors: {{author}}
{{/author}}
Tags: block
Tested up to: 6.6
{{#testedUpTo}}
Tested up to: {{testedUpTo}}
{{/testedUpTo}}
Stable tag: {{version}}
{{#license}}
License: {{license}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
* Description: {{description}}
{{/description}}
* Version: {{version}}
* Requires at least: 6.6
* Requires PHP: 7.2
{{#requiresAtLeast}}
* Requires at least: {{requiresAtLeast}}
{{/requiresAtLeast}}
{{#requiresPHP}}
* Requires PHP: {{requiresPHP}}
{{/requiresPHP}}
{{#author}}
* Author: {{author}}
{{/author}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Contributors: {{author}}
{{/author}}
Tags: block
Tested up to: 6.6
{{#testedUpTo}}
Tested up to: {{testedUpTo}}
{{/testedUpTo}}
Stable tag: {{version}}
{{#license}}
License: {{license}}
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Enhancement

- Add support for custom `textdomain` property for the scaffolded block ([#57197](https://github.com/WordPress/gutenberg/pull/57197)).
- Allow external templates to customize additional plugin header and readme fields: "Requires at least", "Requires PHP", and "Tested up to" ([#68193](https://github.com/WordPress/gutenberg/pull/68193))
- Update the default template to scaffold a block in its subfolder to make it easier to update to multiple blocks in a single plugin ([#68175](https://github.com/WordPress/gutenberg/pull/68175)).

### Internal

Expand Down
Loading
Loading