Skip to content

Commit

Permalink
Add block editor to widgets.php
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 25, 2021
1 parent bbe9df9 commit 5a6c23f
Show file tree
Hide file tree
Showing 34 changed files with 1,844 additions and 734 deletions.
823 changes: 649 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,24 @@
"@wordpress/api-fetch": "5.1.0",
"@wordpress/autop": "3.1.0",
"@wordpress/blob": "3.1.0",
"@wordpress/block-directory": "2.1.0",
"@wordpress/block-directory": "2.1.2",
"@wordpress/block-editor": "6.1.0",
"@wordpress/block-library": "3.1.0",
"@wordpress/block-library": "3.2.1",
"@wordpress/block-serialization-default-parser": "4.1.0",
"@wordpress/blocks": "9.1.0",
"@wordpress/components": "14.1.0",
"@wordpress/compose": "4.1.0",
"@wordpress/core-data": "3.1.0",
"@wordpress/core-data": "3.1.1",
"@wordpress/customize-widgets": "1.0.1",
"@wordpress/data": "5.1.0",
"@wordpress/data-controls": "2.1.0",
"@wordpress/date": "4.1.0",
"@wordpress/deprecated": "3.1.0",
"@wordpress/dom": "3.1.0",
"@wordpress/dom-ready": "3.1.0",
"@wordpress/edit-post": "4.1.0",
"@wordpress/editor": "10.1.0",
"@wordpress/edit-post": "4.1.2",
"@wordpress/edit-widgets": "2.1.2",
"@wordpress/editor": "10.1.1",
"@wordpress/element": "3.1.0",
"@wordpress/escape-html": "2.1.0",
"@wordpress/format-library": "2.1.0",
Expand All @@ -117,14 +119,15 @@
"@wordpress/primitives": "2.1.0",
"@wordpress/priority-queue": "2.1.0",
"@wordpress/redux-routine": "4.1.0",
"@wordpress/reusable-blocks": "2.1.0",
"@wordpress/reusable-blocks": "2.1.1",
"@wordpress/rich-text": "4.1.0",
"@wordpress/server-side-render": "2.1.0",
"@wordpress/shortcode": "3.1.0",
"@wordpress/token-list": "2.1.0",
"@wordpress/url": "3.1.0",
"@wordpress/viewport": "3.1.0",
"@wordpress/warning": "2.1.0",
"@wordpress/widgets": "1.1.1",
"@wordpress/wordcount": "3.1.0",
"backbone": "1.4.0",
"clipboard": "2.0.8",
Expand Down
3 changes: 1 addition & 2 deletions src/wp-admin/admin-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@
$admin_body_class .= ' no-customize-support no-svg';

if ( $current_screen->is_block_editor() ) {
// Default to is-fullscreen-mode to avoid jumps in the UI.
$admin_body_class .= ' block-editor-page is-fullscreen-mode wp-embed-responsive';
$admin_body_class .= ' block-editor-page wp-embed-responsive';
}

$error_get_last = error_get_last();
Expand Down
8 changes: 8 additions & 0 deletions src/wp-admin/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
$current_screen = get_current_screen();
$current_screen->is_block_editor( true );

// Default to is-fullscreen-mode to avoid jumps in the UI.
add_filter(
'admin_body_class',
function( $classes ) {
return "$classes is-fullscreen-mode";
}
);

/*
* Emoji replacement is disabled for now, until it plays nicely with React.
*/
Expand Down
103 changes: 103 additions & 0 deletions src/wp-admin/widgets-form-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* The block-based widgets editor, for use in widgets.php.
*
* @package WordPress
* @subpackage Administration
*/

// Don't load directly.
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}

// Flag that we're loading the block editor.
$current_screen = get_current_screen();
$current_screen->is_block_editor( true );

$block_editor_context = new WP_Block_Editor_Context();

$preload_paths = array(
array( '/wp/v2/media', 'OPTIONS' ),
'/wp/v2/sidebars?context=edit&per_page=-1',
'/wp/v2/widgets?context=edit&per_page=-1&_embed=about',
);
block_editor_rest_api_preload( $preload_paths, $block_editor_context );

$editor_settings = get_block_editor_settings(
array(
/**
* Filters the list of widget-type IDs that should **not** be offered by the
* Legacy Widget block.
*
* Returning an empty array will make all widgets available.
*
* @since 5.8.0
*
* @param array $widgets An array of excluded widget-type IDs.
*/
'widgetTypesToHideFromLegacyWidgetBlock' => apply_filters(
'widget_types_to_hide_from_legacy_widget_block',
array(
'pages',
'calendar',
'archives',
'media_audio',
'media_image',
'media_gallery',
'media_video',
'meta',
'search',
'text',
'categories',
'recent-posts',
'recent-comments',
'rss',
'tag_cloud',
'nav_menu',
'custom_html',
'block',
)
),
),
$block_editor_context
);

wp_add_inline_script(
'wp-edit-widgets',
sprintf(
'wp.domReady( function() {
wp.editWidgets.initialize( "widgets-editor", %s );
} );',
wp_json_encode( $editor_settings )
)
);

// Preload server-registered block schemas.
wp_add_inline_script(
'wp-blocks',
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
);

wp_add_inline_script(
'wp-blocks',
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( 'widgets-editor' ) ) ),
'after'
);

wp_enqueue_script( 'wp-edit-widgets' );
wp_enqueue_script( 'admin-widgets' );
wp_enqueue_script( 'wp-format-library' );
wp_enqueue_style( 'wp-edit-widgets' );
wp_enqueue_style( 'wp-format-library' );

/** This action is documented in edit-form-blocks.php */
do_action( 'enqueue_block_editor_assets' );

require_once ABSPATH . 'wp-admin/admin-header.php';
?>

<div id="widgets-editor" class="blocks-widgets-container"></div>

<?php
require_once ABSPATH . 'wp-admin/admin-footer.php';
Loading

0 comments on commit 5a6c23f

Please sign in to comment.