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

Try/html api with packages update and layout.php back ports #3955

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
15863a8
Introduce HTML Tag Processor
dmsnell Jan 26, 2023
40e1cb3
Move class_exists calls to wp-html
dmsnell Jan 30, 2023
8b507e5
Mark helper classes `final`
dmsnell Jan 30, 2023
561acff
Updates from review feedback, mostly docs
dmsnell Jan 30, 2023
57550e7
WP_HTML_Tag_Processor_Test: test improvements
hellofromtonya Jan 30, 2023
b708c6b
Load API files directly from wp-settings.php
hellofromtonya Jan 30, 2023
521a500
Tests: remove loading API files
hellofromtonya Jan 30, 2023
8bdfae4
Renames test classes to coding standard
hellofromtonya Jan 30, 2023
bc17086
Renames test filenames to coding standard
hellofromtonya Jan 30, 2023
334e415
Cleans HEADS from merge conflict from test file
hellofromtonya Jan 30, 2023
def4ed4
Reword explanation of lexical updates
dmsnell Jan 31, 2023
b924e03
docblock and consistency updates, addressing some PR feedback
dmsnell Jan 31, 2023
91dc772
Move HTML processing modules into new html directory
dmsnell Jan 31, 2023
1fd0d7d
Documentation wording updates.
dmsnell Jan 31, 2023
361710d
Rename library to "HTML-API" instead of "HTML"
dmsnell Jan 31, 2023
2d1411a
Un-finalize helper classes
dmsnell Jan 31, 2023
d8fdf41
Replace throwing with trigger_error( E_USER_WARNING )
dmsnell Jan 31, 2023
1465218
Add test to check for bug when encounting unexpected </SCRIPT> closer
dmsnell Feb 1, 2023
5c1a5d5
Update tests: fix data provider and remove Exception expectation
dmsnell Feb 1, 2023
c50ffee
Lint issue
dmsnell Feb 1, 2023
9a5ccf0
Fix broken tests
dmsnell Feb 1, 2023
0053f9f
Update the WordPress packages with Gutenberg 15.0.1 changes
ntsekouras Feb 1, 2023
384c6b9
backport layout support changes
ntsekouras Feb 1, 2023
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
5,442 changes: 2,587 additions & 2,855 deletions package-lock.json

Large diffs are not rendered by default.

125 changes: 63 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
],
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
"@wordpress/babel-preset-default": "7.1.1",
"@wordpress/dependency-extraction-webpack-plugin": "4.0.2",
"@wordpress/e2e-test-utils": "8.1.1",
"@wordpress/scripts": "24.1.2",
"@wordpress/babel-preset-default": "7.10.0",
"@wordpress/dependency-extraction-webpack-plugin": "4.9.0",
"@wordpress/e2e-test-utils": "9.3.0",
"@wordpress/scripts": "25.3.0",
"autoprefixer": "^9.8.8",
"chalk": "5.1.0",
"check-node-version": "4.2.1",
Expand Down Expand Up @@ -76,62 +76,63 @@
"webpack-livereload-plugin": "3.0.2"
},
"dependencies": {
"@wordpress/a11y": "3.17.1",
"@wordpress/annotations": "2.17.3",
"@wordpress/api-fetch": "6.14.1",
"@wordpress/autop": "3.17.1",
"@wordpress/blob": "3.17.1",
"@wordpress/block-directory": "3.15.12",
"@wordpress/block-editor": "10.0.10",
"@wordpress/block-library": "7.14.12",
"@wordpress/block-serialization-default-parser": "4.17.1",
"@wordpress/blocks": "11.16.4",
"@wordpress/components": "21.0.7",
"@wordpress/compose": "5.15.2",
"@wordpress/core-data": "5.0.4",
"@wordpress/customize-widgets": "3.14.12",
"@wordpress/data": "7.1.3",
"@wordpress/data-controls": "2.17.3",
"@wordpress/date": "4.17.1",
"@wordpress/deprecated": "3.17.1",
"@wordpress/dom": "3.17.2",
"@wordpress/dom-ready": "3.17.1",
"@wordpress/edit-post": "6.14.12",
"@wordpress/edit-site": "4.14.14",
"@wordpress/edit-widgets": "4.14.12",
"@wordpress/editor": "12.16.10",
"@wordpress/element": "4.15.1",
"@wordpress/escape-html": "2.17.1",
"@wordpress/format-library": "3.15.10",
"@wordpress/hooks": "3.17.1",
"@wordpress/html-entities": "3.17.1",
"@wordpress/i18n": "4.17.1",
"@wordpress/icons": "9.8.1",
"@wordpress/interface": "4.16.7",
"@wordpress/is-shallow-equal": "4.17.1",
"@wordpress/keyboard-shortcuts": "3.15.3",
"@wordpress/keycodes": "3.17.1",
"@wordpress/list-reusable-blocks": "3.15.7",
"@wordpress/media-utils": "4.8.1",
"@wordpress/notices": "3.17.3",
"@wordpress/nux": "5.15.7",
"@wordpress/plugins": "4.15.2",
"@wordpress/preferences": "2.9.7",
"@wordpress/preferences-persistence": "1.9.1",
"@wordpress/primitives": "3.15.1",
"@wordpress/priority-queue": "2.17.2",
"@wordpress/redux-routine": "4.17.1",
"@wordpress/reusable-blocks": "3.15.10",
"@wordpress/rich-text": "5.15.3",
"@wordpress/server-side-render": "3.15.7",
"@wordpress/shortcode": "3.17.1",
"@wordpress/style-engine": "1.0.3",
"@wordpress/token-list": "2.17.1",
"@wordpress/url": "3.18.1",
"@wordpress/viewport": "4.15.3",
"@wordpress/warning": "2.17.1",
"@wordpress/widgets": "2.15.10",
"@wordpress/wordcount": "3.17.1",
"@wordpress/a11y": "3.26.0",
"@wordpress/annotations": "2.26.0",
"@wordpress/api-fetch": "6.23.0",
"@wordpress/autop": "3.26.0",
"@wordpress/blob": "3.26.0",
"@wordpress/block-directory": "4.3.0",
"@wordpress/block-editor": "11.3.0",
"@wordpress/block-library": "8.3.0",
"@wordpress/block-serialization-default-parser": "4.26.0",
"@wordpress/blocks": "12.3.0",
"@wordpress/components": "23.3.0",
"@wordpress/compose": "6.3.0",
"@wordpress/core-data": "6.3.0",
"@wordpress/customize-widgets": "4.3.0",
"@wordpress/data": "8.3.0",
"@wordpress/data-controls": "2.26.0",
"@wordpress/date": "4.26.0",
"@wordpress/deprecated": "3.26.0",
"@wordpress/dom": "3.26.0",
"@wordpress/dom-ready": "3.26.0",
"@wordpress/edit-post": "7.3.0",
"@wordpress/edit-site": "5.3.0",
"@wordpress/edit-widgets": "5.3.0",
"@wordpress/editor": "13.3.0",
"@wordpress/element": "5.3.0",
"@wordpress/escape-html": "2.26.0",
"@wordpress/experiments": "0.8.0",
"@wordpress/format-library": "4.3.0",
"@wordpress/hooks": "3.26.0",
"@wordpress/html-entities": "3.26.0",
"@wordpress/i18n": "4.26.0",
"@wordpress/icons": "9.17.0",
"@wordpress/interface": "5.3.0",
"@wordpress/is-shallow-equal": "4.26.0",
"@wordpress/keyboard-shortcuts": "4.3.0",
"@wordpress/keycodes": "3.26.0",
"@wordpress/list-reusable-blocks": "4.3.0",
"@wordpress/media-utils": "4.17.0",
"@wordpress/notices": "3.26.0",
"@wordpress/nux": "6.0.0",
"@wordpress/plugins": "5.3.0",
"@wordpress/preferences": "3.3.0",
"@wordpress/preferences-persistence": "1.18.0",
"@wordpress/primitives": "3.24.0",
"@wordpress/priority-queue": "2.26.0",
"@wordpress/redux-routine": "4.26.0",
"@wordpress/reusable-blocks": "4.3.0",
"@wordpress/rich-text": "6.3.0",
"@wordpress/server-side-render": "4.3.0",
"@wordpress/shortcode": "3.26.0",
"@wordpress/style-engine": "1.9.0",
"@wordpress/token-list": "2.26.0",
"@wordpress/url": "3.27.0",
"@wordpress/viewport": "5.3.0",
"@wordpress/warning": "2.26.0",
"@wordpress/widgets": "3.3.0",
"@wordpress/wordcount": "3.26.0",
"backbone": "1.4.1",
"clipboard": "2.0.11",
"core-js-url-browser": "3.6.4",
Expand All @@ -149,8 +150,8 @@
"moment": "2.29.4",
"objectFitPolyfill": "2.3.5",
"polyfill-library": "4.4.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"regenerator-runtime": "0.13.9",
"twemoji": "14.0.2",
"underscore": "1.13.6",
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/assets/script-loader-packages.min.php

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ function _wp_get_iframed_editor_assets() {

$script_handles = array();
$style_handles = array(
'wp-block-editor',
'wp-block-library',
'wp-edit-blocks',
);

Expand Down
111 changes: 105 additions & 6 deletions src/wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,25 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
return '';
}

/**
* Gets classname from last tag in a string of HTML.
*
* @since 6.2.0
*
* @param string $html markup to be processed.
* @return string String of inner wrapper classnames.
*/
function wp_get_classnames_from_last_tag( $html ) {
$tags = new WP_HTML_Tag_Processor( $html );
$last_classnames = '';

while ( $tags->next_tag() ) {
$last_classnames = $tags->get_attribute( 'class' );
}

return (string) $last_classnames;
}

/**
* Renders the layout config to the block wrapper.
*
Expand All @@ -309,13 +328,60 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
* @return string Filtered block content.
*/
function wp_render_layout_support_flag( $block_content, $block ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
$has_child_layout = isset( $block['attrs']['style']['layout']['selfStretch'] );

if ( ! $support_layout ) {
if ( ! $support_layout
&& ! $has_child_layout ) {
return $block_content;
}

$outer_class_names = array();

if ( $has_child_layout && ( 'fixed' === $block['attrs']['style']['layout']['selfStretch'] || 'fill' === $block['attrs']['style']['layout']['selfStretch'] ) ) {

$container_content_class = wp_unique_id( 'wp-container-content-' );

$child_layout_styles = array();

if ( 'fixed' === $block['attrs']['style']['layout']['selfStretch'] && isset( $block['attrs']['style']['layout']['flexSize'] ) ) {
$child_layout_styles[] = array(
'selector' => ".$container_content_class",
'declarations' => array(
'flex-basis' => $block['attrs']['style']['layout']['flexSize'],
'box-sizing' => 'border-box',
),
);
} elseif ( 'fill' === $block['attrs']['style']['layout']['selfStretch'] ) {
$child_layout_styles[] = array(
'selector' => ".$container_content_class",
'declarations' => array(
'flex-grow' => '1',
),
);
}

wp_style_engine_get_stylesheet_from_css_rules(
$child_layout_styles,
array(
'context' => 'block-supports',
'prettify' => false,
)
);

$outer_class_names[] = $container_content_class;

}

// Return early if only child layout exists.
if ( ! $support_layout && ! empty( $outer_class_names ) ) {
$content = new WP_HTML_Tag_Processor( $block_content );
$content->next_tag();
$content->add_class( implode( ' ', $outer_class_names ) );
return (string) $content;
}

$block_gap = wp_get_global_settings( array( 'spacing', 'blockGap' ) );
$global_layout_settings = wp_get_global_settings( array( 'layout' ) );
$has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false;
Expand All @@ -330,7 +396,6 @@ function wp_render_layout_support_flag( $block_content, $block ) {

$class_names = array();
$layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() );
$block_classname = wp_get_block_default_classname( $block['blockName'] );
$container_class = wp_unique_id( 'wp-container-' );
$layout_classname = '';

Expand Down Expand Up @@ -406,7 +471,7 @@ function wp_render_layout_support_flag( $block_content, $block ) {
$should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );

$style = wp_get_layout_style(
".$block_classname.$container_class",
".$container_class.$container_class",
$used_layout,
$has_block_gap_support,
$gap_value,
Expand All @@ -421,6 +486,40 @@ function wp_render_layout_support_flag( $block_content, $block ) {
}
}

$content_with_outer_classnames = '';

if ( ! empty( $outer_class_names ) ) {
$content_with_outer_classnames = new WP_HTML_Tag_Processor( $block_content );
$content_with_outer_classnames->next_tag();
foreach ( $outer_class_names as $outer_class_name ) {
$content_with_outer_classnames->add_class( $outer_class_name );
}

$content_with_outer_classnames = (string) $content_with_outer_classnames;
}

/**
* The first chunk of innerContent contains the block markup up until the inner blocks start.
* We want to target the opening tag of the inner blocks wrapper, which is the last tag in that chunk.
*/
$inner_content_classnames = isset( $block['innerContent'][0] ) && 'string' === gettype( $block['innerContent'][0] ) ? wp_get_classnames_from_last_tag( $block['innerContent'][0] ) : '';

$content = $content_with_outer_classnames ? new WP_HTML_Tag_Processor( $content_with_outer_classnames ) : new WP_HTML_Tag_Processor( $block_content );

if ( $inner_content_classnames ) {
$content->next_tag( array( 'class_name' => $inner_content_classnames ) );
foreach ( $class_names as $class_name ) {
$content->add_class( $class_name );
}
} else {
$content->next_tag();
foreach ( $class_names as $class_name ) {
$content->add_class( $class_name );
}
}

return (string) $content;

/*
* This assumes the hook only applies to blocks with a single wrapper.
* A limitation of this hook is that nested inner blocks wrappers are not yet supported.
Expand All @@ -432,7 +531,7 @@ function wp_render_layout_support_flag( $block_content, $block ) {
1
);

return $content;
return (string) $content;
}

// Register the block support.
Expand Down
11 changes: 4 additions & 7 deletions src/wp-includes/blocks/archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
function render_block_core_archives( $attributes ) {
$show_post_count = ! empty( $attributes['showPostCounts'] );
$type = isset( $attributes['type'] ) ? $attributes['type'] : 'monthly';
$class = '';

$class = 'wp-block-archives-list';

if ( ! empty( $attributes['displayAsDropdown'] ) ) {

$class .= ' wp-block-archives-dropdown';
$class = 'wp-block-archives-dropdown';

$dropdown_id = wp_unique_id( 'wp-block-archives-' );
$title = __( 'Archives' );
Expand All @@ -40,9 +41,7 @@ function render_block_core_archives( $attributes ) {

$archives = wp_get_archives( $dropdown_args );

$classnames = esc_attr( $class );

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );

switch ( $dropdown_args['type'] ) {
case 'yearly':
Expand Down Expand Up @@ -75,8 +74,6 @@ function render_block_core_archives( $attributes ) {
);
}

$class .= ' wp-block-archives-list';

/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
$archives_args = apply_filters(
'widget_archives_args',
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/blocks/archives/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"supports": {
"align": true,
"anchor": true,
"html": false,
"spacing": {
"margin": true,
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/blocks/avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function render_block_core_avatar( $attributes, $content, $block ) {
$label = 'aria-label="' . sprintf( esc_attr__( '(%s author archive, opens in a new tab)' ), $author_name ) . '"';
}
// translators: %1$s: Author archive link. %2$s: Link target. %3$s Aria label. %4$s Avatar image.
$avatar_block = sprintf( '<a href="%1$s" target="%2$s" %3$s class="wp-block-avatar__link">%4$s</a>', get_author_posts_url( $author_id ), esc_attr( $attributes['linkTarget'] ), $label, $avatar_block );
$avatar_block = sprintf( '<a href="%1$s" target="%2$s" %3$s class="wp-block-avatar__link">%4$s</a>', esc_url( get_author_posts_url( $author_id ) ), esc_attr( $attributes['linkTarget'] ), $label, $avatar_block );
}
return sprintf( '<div %1s>%2s</div>', $wrapper_attributes, $avatar_block );
}
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/blocks/avatar/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "core/avatar",
"title": "Avatar",
"category": "theme",
"description": "Add a user's avatar.",
"description": "Add a users avatar.",
"textdomain": "default",
"attributes": {
"userId": {
Expand All @@ -25,6 +25,7 @@
},
"usesContext": [ "postType", "postId", "commentId" ],
"supports": {
"anchor": true,
"html": false,
"align": true,
"alignWide": false,
Expand Down
3 changes: 1 addition & 2 deletions src/wp-includes/blocks/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ function render_block_core_block( $attributes ) {
if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
// is set in `wp_debug_mode()`.
$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;

return $is_debug ?
// translators: Visible only in the front end, this warning takes the place of a faulty block.
Expand Down
3 changes: 1 addition & 2 deletions src/wp-includes/blocks/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
"customClassName": false,
"html": false,
"inserter": false
},
"editorStyle": "wp-block-editor"
}
}
2 changes: 1 addition & 1 deletion src/wp-includes/blocks/blocks-json.php

Large diffs are not rendered by default.

Loading