Skip to content

Commit

Permalink
Merge branch 'master' into try/block-mover-appear-on-delay
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellr committed Aug 29, 2019
2 parents 7ee67d7 + 02c5f39 commit db9d48a
Show file tree
Hide file tree
Showing 80 changed files with 239 additions and 154 deletions.
1 change: 1 addition & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function gutenberg_reregister_core_block_types() {
'latest-comments.php' => 'core/latest-comments',
'latest-posts.php' => 'core/latest-posts',
'legacy-widget.php' => 'core/legacy-widget',
'navigation-menu.php' => 'core/navigation-menu',
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
Expand Down
46 changes: 46 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,49 @@ function gutenberg_filter_wp_insert_post_data( $data, $postarr ) {
return $data;
}
add_filter( 'wp_insert_post_data', 'gutenberg_filter_wp_insert_post_data', 10, 2 );


/**
* Shim that hooks into `pre_render_block` so as to override `render_block`
* with a function that passes `render_callback` the block object as the
* argument.
*
* @param string $pre_render The pre-rendered content. Default null.
* @param array $block The block being rendered.
*
* @return string String of rendered HTML.
*/
function gutenberg_provide_render_callback_with_block_object( $pre_render, $block ) {
global $post;

$source_block = $block;

/** This filter is documented in src/wp-includes/blocks.php */
$block = apply_filters( 'render_block_data', $block, $source_block );

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$is_dynamic = $block['blockName'] && null !== $block_type && $block_type->is_dynamic();
$block_content = '';
$index = 0;

foreach ( $block['innerContent'] as $chunk ) {
$block_content .= is_string( $chunk ) ? $chunk : render_block( $block['innerBlocks'][ $index++ ] );
}

if ( ! is_array( $block['attrs'] ) ) {
$block['attrs'] = array();
}

if ( $is_dynamic ) {
$global_post = $post;

$block_type->prepare_attributes_for_render( $block['attrs'] );
$block_content = (string) call_user_func( $block_type->render_callback, $block['attrs'], $block_content, $block );

$post = $global_post;
}

/** This filter is documented in src/wp-includes/blocks.php */
return apply_filters( 'render_block', $block_content, $block );
}
add_filter( 'pre_render_block', 'gutenberg_provide_render_callback_with_block_object', 10, 2 );
2 changes: 1 addition & 1 deletion packages/annotations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/annotations",
"version": "1.5.0",
"version": "1.6.0",
"description": "Annotate content in the Gutenberg editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/api-fetch",
"version": "3.4.0",
"version": "3.5.0",
"description": "Utility to make WordPress REST API requests.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/autop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/autop",
"version": "2.4.0",
"version": "2.5.0",
"description": "WordPress's automatic paragraph functions `autop` and `removep`.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Master
## 4.5.0 (2019-08-29)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-default/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/babel-preset-default",
"version": "4.4.0",
"version": "4.5.0",
"description": "Default Babel preset for WordPress development.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-editor",
"version": "3.0.0",
"version": "3.1.0",
"description": "Generic block editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
13 changes: 13 additions & 0 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@
width: auto;
border-bottom: $border-width solid $light-gray-800;
bottom: auto;

@include break-small() {
border-bottom: none;
}
}
}

Expand Down Expand Up @@ -1106,6 +1110,15 @@
// RTL note: this rule should not be auto-flipped based on direction.
/*rtl:ignore*/
float: right;

// IE11 moves the toolbar to the right because the parent container doesn't expand.
// A min-width mitigates this.
min-width: 200px;

// IE11 does not support `position: sticky`.
@supports (position: sticky) {
min-width: 0;
}
}

.block-editor-block-list__block[data-align="left"] &,
Expand Down
11 changes: 10 additions & 1 deletion packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

// Add a right border to show as separator in the block toolbar.
border-right: $border-width solid $light-gray-800;

// IE11 has thick paddings without this.
line-height: 0;
}

// Add a left border and adjust the color for Top Toolbar mode.
Expand All @@ -44,5 +47,11 @@
}

.block-editor-block-toolbar__slot {
display: inline-flex;
// Required for IE11.
display: inline-block;

// IE11 doesn't read rules inside this query. They are applied only to modern browsers.
@supports (position: sticky) {
display: inline-flex;
}
}
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { withViewportMatch } from '@wordpress/viewport'; // Temporary click-through disable on desktop.
import { Component } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { synchronizeBlocksWithTemplate, withBlockContentContext } from '@wordpress/blocks';
Expand Down Expand Up @@ -101,6 +102,7 @@ class InnerBlocks extends Component {

render() {
const {
isSmallScreen, // Temporary click-through disable on desktop.
clientId,
hasOverlay,
renderAppender,
Expand All @@ -114,7 +116,7 @@ class InnerBlocks extends Component {
const isPlaceholder = template === null && !! templateOptions;

const classes = classnames( 'editor-inner-blocks block-editor-inner-blocks', {
'has-overlay': hasOverlay && ! isPlaceholder,
'has-overlay': isSmallScreen && ( hasOverlay && ! isPlaceholder ), // Temporary click-through disable on desktop.
} );

return (
Expand All @@ -137,6 +139,7 @@ class InnerBlocks extends Component {
}

InnerBlocks = compose( [
withViewportMatch( { isSmallScreen: '< medium' } ), // Temporary click-through disable on desktop.
withBlockEditContext( ( context ) => pick( context, [ 'clientId' ] ) ),
withSelect( ( select, ownProps ) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-library",
"version": "2.7.0",
"version": "2.8.0",
"description": "Block library for the WordPress editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/navigation-menu-item/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
InnerBlocks,
InspectorControls,
PlainText,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -137,6 +138,10 @@ function NavigationMenuItemEdit( {
</InspectorControls>
<div className="wp-block-navigation-menu-item">
{ content }
<InnerBlocks
allowedBlocks={ [ 'core/navigation-menu-item' ] }
renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
</div>
</Fragment>
);
Expand Down
18 changes: 9 additions & 9 deletions packages/block-library/src/navigation-menu-item/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default function save( { attributes } ) {
/**
* WordPress dependencies
*/
import {
InnerBlocks,
} from '@wordpress/block-editor';

export default function save() {
return (
<a
href={ attributes.destination }
rel={ attributes.nofollow && 'nofollow' }
title={ attributes.title }
target={ attributes.opensInNewTab && '_blank' }
>
{ attributes.label }
</a>
<InnerBlocks.Content />
);
}
10 changes: 0 additions & 10 deletions packages/block-library/src/navigation-menu/block.json

This file was deleted.

9 changes: 1 addition & 8 deletions packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ import {
/**
* Internal dependencies
*/
import MenuItemInserter from './menu-item-inserter';
import { __ } from '@wordpress/i18n';

function NavigationMenu( {
attributes,
clientId,
isSelected,
setAttributes,
} ) {
return (
Expand All @@ -44,12 +41,8 @@ function NavigationMenu( {
<div className="wp-block-navigation-menu">
<InnerBlocks
allowedBlocks={ [ 'core/navigation-menu-item' ] }
renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
{ isSelected && (
<MenuItemInserter
rootClientId={ clientId }
/>
) }
</div>
</Fragment>
);
Expand Down
10 changes: 0 additions & 10 deletions packages/block-library/src/navigation-menu/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
white-space: nowrap;
}

// Todo: corerctly allow custom inserters and remove the need for this display none.
.wp-block-navigation-menu .block-editor-block-list__layout .block-list-appender {
display: none;
}

// Custom inserter
.wp-block-navigation-menu__inserter {
display: inline-block;
}

.wp-block-navigation-menu__inserter-content {
width: 350px;
padding: $grid-size-large;
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/navigation-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import metadata from './block.json';
import edit from './edit';
import save from './save';

const { name } = metadata;
export { metadata, name };
export const name = 'core/navigation-menu';

export const settings = {
title: __( 'Navigation Menu (Experimental)' ),
Expand Down
72 changes: 72 additions & 0 deletions packages/block-library/src/navigation-menu/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Server-side rendering of the `core/navigation-menu` block.
*
* @package gutenberg
*/

/**
* Renders the `core/navigation-menu` block on server.
*
* @param array $attributes The block attributes.
* @param array $content The saved content.
* @param array $block The parsed block.
*
* @return string Returns the post content with the legacy widget added.
*/
function render_block_navigation_menu( $attributes, $content, $block ) {
return '<nav className="wp-block-navigation-menu">' . build_navigation_menu_html( $block ) . '</nav>';
}

/**
* Walks the inner block structure and returns an HTML list for it.
*
* @param array $block The block.
*
* @return string Returns an HTML list from innerBlocks.
*/
function build_navigation_menu_html( $block ) {
$html = '';
foreach ( (array) $block['innerBlocks'] as $key => $menu_item ) {
$html .= '<li class="wp-block-navigation-menu-item"><a class="wp-block-navigation-menu-item"';
if ( isset( $menu_item['attrs']['destination'] ) ) {
$html .= ' href="' . $menu_item['attrs']['destination'] . '"';
}
if ( isset( $menu_item['attrs']['title'] ) ) {
$html .= ' title="' . $menu_item['attrs']['title'] . '"';
}
$html .= '>';
if ( isset( $menu_item['attrs']['label'] ) ) {
$html .= $menu_item['attrs']['label'];
}
$html .= '</a>';

if ( count( (array) $menu_item['innerBlocks'] ) > 0 ) {
$html .= build_navigation_menu_html( $menu_item );
}

$html .= '</li>';
}
return '<ul>' . $html . '</ul>';
}

/**
* Register the navigation menu block.
*/
function register_block_core_navigation_menu() {
register_block_type(
'core/navigation-menu',
array(
'category' => 'layout',
'attributes' => array(
'automaticallyAdd' => array(
'type' => 'boolean',
'default' => false,
),
),
'render_callback' => 'render_block_navigation_menu',
)
);
}

add_action( 'init', 'register_block_core_navigation_menu' );
4 changes: 1 addition & 3 deletions packages/block-library/src/navigation-menu/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { InnerBlocks } from '@wordpress/block-editor';

export default function save() {
return (
<nav>
<InnerBlocks.Content />
</nav>
<InnerBlocks.Content />
);
}
1 change: 1 addition & 0 deletions packages/block-library/src/video/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
}

.editor-video-poster-control .components-button {
display: block;
margin-right: 8px;
}

Expand Down
Loading

0 comments on commit db9d48a

Please sign in to comment.