Skip to content

Commit

Permalink
DROPME: Update block-library from Gutenberg PR
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Sep 19, 2024
1 parent da34a1f commit a825571
Show file tree
Hide file tree
Showing 61 changed files with 757 additions and 199 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/blocks/audio/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"keywords": [ "music", "sound", "podcast", "recording" ],
"textdomain": "default",
"attributes": {
"blob": {
"type": "string",
"__experimentalRole": "local"
},
"src": {
"type": "string",
"source": "attribute",
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/blocks/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalWritingMode": true,
"__experimentalDefaultControls": {
"fontSize": true
}
Expand Down
22 changes: 21 additions & 1 deletion src/wp-includes/blocks/buttons/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"align": [ "wide", "full" ],
"html": false,
"__experimentalExposeControlsToChildren": true,
"color": {
"gradients": true,
"text": false,
"__experimentalDefaultControls": {
"background": true
}
},
"spacing": {
"blockGap": true,
"blockGap": [ "horizontal", "vertical" ],
"padding": true,
"margin": [ "top", "bottom" ],
"__experimentalDefaultControls": {
"blockGap": true
Expand All @@ -33,6 +41,18 @@
"fontSize": true
}
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
},
"layout": {
"allowSwitching": false,
"allowInheriting": false,
Expand Down
42 changes: 34 additions & 8 deletions src/wp-includes/blocks/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
* Renders the `core/categories` block on server.
*
* @since 5.0.0
* @since 6.7.0 Enable client-side rendering if enhancedPagination context is true.
*
* @param array $attributes The block attributes.
* @param array $attributes The block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
*
* @return string Returns the categories list/dropdown markup.
*/
function render_block_core_categories( $attributes ) {
function render_block_core_categories( $attributes, $content, $block ) {
static $block_id = 0;
++$block_id;

$taxonomy = get_taxonomy( $attributes['taxonomy'] );

$args = array(
'echo' => false,
'hierarchical' => ! empty( $attributes['showHierarchy'] ),
'orderby' => 'name',
'show_count' => ! empty( $attributes['showPostCounts'] ),
'taxonomy' => $attributes['taxonomy'],
'title_li' => '',
'hide_empty' => empty( $attributes['showEmpty'] ),
);
Expand All @@ -33,10 +39,20 @@ function render_block_core_categories( $attributes ) {
if ( ! empty( $attributes['displayAsDropdown'] ) ) {
$id = 'wp-block-categories-' . $block_id;
$args['id'] = $id;
$args['show_option_none'] = __( 'Select Category' );
$wrapper_markup = '<div %1$s><label class="screen-reader-text" for="' . esc_attr( $id ) . '">' . __( 'Categories' ) . '</label>%2$s</div>';
$items_markup = wp_dropdown_categories( $args );
$type = 'dropdown';
$args['name'] = $taxonomy->query_var;
$args['value_field'] = 'slug';
$args['show_option_none'] = sprintf(
/* translators: %s: taxonomy's singular name */
__( 'Select %s' ),
$taxonomy->labels->singular_name
);

$show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : '';
$default_label = $taxonomy->label;
$label_text = ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
$wrapper_markup = '<div %1$s><label class="wp-block-categories__label' . $show_label . '" for="' . esc_attr( $id ) . '">' . $label_text . '</label>%2$s</div>';
$items_markup = wp_dropdown_categories( $args );
$type = 'dropdown';

if ( ! is_admin() ) {
// Inject the dropdown script immediately after the select dropdown.
Expand All @@ -48,9 +64,19 @@ function render_block_core_categories( $attributes ) {
);
}
} else {
$args['show_option_none'] = $taxonomy->labels->no_terms;

$wrapper_markup = '<ul %1$s>%2$s</ul>';
$items_markup = wp_list_categories( $args );
$type = 'list';

if ( ! empty( $block->context['enhancedPagination'] ) ) {
$p = new WP_HTML_Tag_Processor( $items_markup );
while ( $p->next_tag( 'a' ) ) {
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
}
$items_markup = $p->get_updated_html();
}
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => "wp-block-categories-{$type}" ) );
Expand Down Expand Up @@ -78,8 +104,8 @@ function build_dropdown_script_block_core_categories( $dropdown_id ) {
( function() {
var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
function onCatChange() {
if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
location.href = "<?php echo esc_url( home_url() ); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
if ( dropdown.options[ dropdown.selectedIndex ].value !== -1 ) {
location.href = "<?php echo esc_url( home_url() ); ?>/?" + dropdown.name + '=' + dropdown.options[ dropdown.selectedIndex ].value;
}
}
dropdown.onchange = onCatChange;
Expand Down
30 changes: 28 additions & 2 deletions src/wp-includes/blocks/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/categories",
"title": "Categories List",
"title": "Terms List",
"category": "widgets",
"description": "Display a list of all categories.",
"description": "Display a list of all terms of a given taxonomy.",
"keywords": [ "categories" ],
"textdomain": "default",
"attributes": {
"taxonomy": {
"type": "string",
"default": "category"
},
"displayAsDropdown": {
"type": "boolean",
"default": false
Expand All @@ -26,8 +31,17 @@
"showEmpty": {
"type": "boolean",
"default": false
},
"label": {
"type": "string",
"__experimentalRole": "content"
},
"showLabel": {
"type": "boolean",
"default": true
}
},
"usesContext": [ "enhancedPagination" ],
"supports": {
"align": true,
"html": false,
Expand All @@ -54,6 +68,18 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
}
},
"editorStyle": "wp-block-categories-editor",
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/blocks/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
Expand Down
15 changes: 14 additions & 1 deletion src/wp-includes/blocks/comment-author-name/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
}
}
},
"style": "wp-block-comment-author-name"
}
15 changes: 14 additions & 1 deletion src/wp-includes/blocks/comment-content/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,25 @@
"fontSize": true
}
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
},
"spacing": {
"padding": [ "horizontal", "vertical" ],
"__experimentalDefaultControls": {
"padding": true
}
},
"html": false
}
},
"style": "wp-block-comment-content"
}
12 changes: 7 additions & 5 deletions src/wp-includes/blocks/comment-date.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ function render_block_core_comment_date( $attributes, $content, $block ) {
$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$formatted_date = get_comment_date(
isset( $attributes['format'] ) ? $attributes['format'] : '',
$comment
);
$link = get_comment_link( $comment );
if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
// translators: %s: human-readable time difference.
$formatted_date = sprintf( __( '%s ago' ), human_time_diff( get_comment_date( 'U', $comment ) ) );
} else {
$formatted_date = get_comment_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $comment );
}
$link = get_comment_link( $comment );

if ( ! empty( $attributes['isLink'] ) ) {
$formatted_date = sprintf( '<a href="%1s">%2s</a>', esc_url( $link ), $formatted_date );
Expand Down
15 changes: 14 additions & 1 deletion src/wp-includes/blocks/comment-date/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
}
}
},
"style": "wp-block-comment-date"
}
15 changes: 13 additions & 2 deletions src/wp-includes/blocks/comment-edit-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
},
"spacing": {
"margin": true,
"padding": true
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
},
"typography": {
"fontSize": true,
Expand All @@ -47,6 +51,13 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true
}
}
},
"style": "wp-block-comment-edit-link"
}
15 changes: 13 additions & 2 deletions src/wp-includes/blocks/comment-reply-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
},
"spacing": {
"margin": true,
"padding": true
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
},
"typography": {
"fontSize": true,
Expand All @@ -40,6 +44,13 @@
"fontSize": true
}
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true
},
"html": false
}
},
"style": "wp-block-comment-reply-link"
}
12 changes: 12 additions & 0 deletions src/wp-includes/blocks/comment-template/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
},
"interactivity": {
"clientNavigation": true
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
}
},
"style": "wp-block-comment-template"
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/blocks/comments-pagination-next.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function render_block_core_comments_pagination_next( $attributes, $content, $blo
$label .= $pagination_arrow;
}

$next_comments_link = get_next_comments_link( $label, $max_page );
$next_comments_link = get_next_comments_link( $label, $max_page, $comment_vars['paged'] ?? null );

remove_filter( 'next_posts_link_attributes', $filter_link_attributes );

Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/blocks/comments-pagination-previous.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function render_block_core_comments_pagination_previous( $attributes, $content,
};
add_filter( 'previous_comments_link_attributes', $filter_link_attributes );

$previous_comments_link = get_previous_comments_link( $label );
$comment_vars = build_comment_query_vars_from_block( $block );
$previous_comments_link = get_previous_comments_link( $label, $comment_vars['paged'] ?? null );

remove_filter( 'previous_comments_link_attributes', $filter_link_attributes );

Expand Down
Loading

0 comments on commit a825571

Please sign in to comment.