diff --git a/docs/how-to-guides/widgets/legacy-widget-block.md b/docs/how-to-guides/widgets/legacy-widget-block.md index c32136a10e4fef..21d22561d1509c 100644 --- a/docs/how-to-guides/widgets/legacy-widget-block.md +++ b/docs/how-to-guides/widgets/legacy-widget-block.md @@ -123,3 +123,49 @@ function hide_example_widget( $widget_types ) { } add_filter( 'widget_types_to_hide_from_legacy_widget_block', 'hide_example_widget' ); ``` + +## Using the Legacy Widget block in other block editors (Advanced) + +You may optionally allow the Legacy Widget block in other block editors such as +the WordPress post editor. This is not enabled by default. + +First, ensure that any styles and scripts required by the legacy widgets are +loaded onto the page. A convenient way of doing this is to manually perform all +of the hooks that ordinarily run when a user browses to the widgets WP Admin +screen. + +```php +add_action( 'admin_print_styles', function() { + if ( get_current_screen()->is_block_editor() ) { + do_action( 'admin_print_styles-widgets.php' ); + } +} ); +add_action( 'admin_print_scripts', function() { + if ( get_current_screen()->is_block_editor() ) { + do_action( 'load-widgets.php' ); + do_action( 'widgets.php' ); + do_action( 'sidebar_admin_setup' ); + do_action( 'admin_print_scripts-widgets.php' ); + } +} ); +add_action( 'admin_print_footer_scripts', function() { + if ( get_current_screen()->is_block_editor() ) { + do_action( 'admin_print_footer_scripts-widgets.php' ); + } +} ); +add_action( 'admin_footer', function() { + if ( get_current_screen()->is_block_editor() ) { + do_action( 'admin_footer-widgets.php' ); + } +} ); +``` + +Then, register the Legacy Widget block using `registerLegacyWidgetBlock` which +is defined in the `@wordpress/widgets` package. + +```php +add_action( 'enqueue_block_editor_assets', function() { + wp_enqueue_script( 'wp-widgets' ); + wp_add_inline_script( 'wp-widgets', 'wp.widgets.registerLegacyWidgetBlock()' ); +} ); +``` diff --git a/lib/blocks.php b/lib/blocks.php index e04842e8a9445f..5140c33732bacf 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -5,24 +5,6 @@ * @package gutenberg */ -/* - * Fixes the priority of register_block_core_legacy_widget(). - * - * This hook was incorrectly added to Core with priority 20. #32300 fixes this - * but causes block registration warnings in the Gutenberg plugin until the - * changes are made in Core. - * - * This temporary fix can be removed after the changes to - * @wordpress/block-library in #32300 have been published to npm and updated in - * Core. - * - * See https://github.com/WordPress/gutenberg/pull/32300. - */ -if ( 20 === has_action( 'init', 'register_block_core_legacy_widget' ) ) { - remove_action( 'init', 'register_block_core_legacy_widget', 20 ); - add_action( 'init', 'register_block_core_legacy_widget', 10 ); -} - /** * Substitutes the implementation of a core-registered block type, if exists, * with the built result from the plugin. @@ -74,7 +56,6 @@ function gutenberg_reregister_core_block_types() { 'file.php' => 'core/file', 'latest-comments.php' => 'core/latest-comments', 'latest-posts.php' => 'core/latest-posts', - 'legacy-widget.php' => 'core/legacy-widget', 'loginout.php' => 'core/loginout', 'navigation.php' => 'core/navigation', 'navigation-link.php' => 'core/navigation-link', @@ -120,8 +101,14 @@ function gutenberg_reregister_core_block_types() { 'block_folders' => array( 'widget-area', ), + 'block_names' => array(), + ), + __DIR__ . '/../build/widgets/blocks/' => array( + 'block_folders' => array( + 'legacy-widget', + ), 'block_names' => array( - 'widget-area.php' => 'core/widget-area', + 'legacy-widget.php' => 'core/legacy-widget', ), ), ); diff --git a/lib/client-assets.php b/lib/client-assets.php index c52c5ae04f2b04..3a366796d6218c 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -447,7 +447,7 @@ function gutenberg_register_packages_styles( $styles ) { $styles, 'wp-edit-widgets', gutenberg_url( 'build/edit-widgets/style.css' ), - array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-reusable-blocks' ), + array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ), $version ); $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' ); @@ -465,7 +465,7 @@ function gutenberg_register_packages_styles( $styles ) { $styles, 'wp-customize-widgets', gutenberg_url( 'build/customize-widgets/style.css' ), - array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ), + array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-widgets' ), $version ); $styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' ); @@ -478,6 +478,14 @@ function gutenberg_register_packages_styles( $styles ) { $version ); $styles->add_data( 'wp-reusable-block', 'rtl', 'replace' ); + + gutenberg_override_style( + $styles, + 'wp-widgets', + gutenberg_url( 'build/widgets/style.css' ), + array( 'wp-components' ) + ); + $styles->add_data( 'wp-widgets', 'rtl', 'replace' ); } add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' ); diff --git a/lib/widgets-page.php b/lib/widgets-page.php index 06376c2c71e396..1a4089eea66fd7 100644 --- a/lib/widgets-page.php +++ b/lib/widgets-page.php @@ -103,3 +103,59 @@ function gutenberg_widgets_editor_load_block_editor_scripts_and_styles( $is_bloc function gutenberg_widgets_editor_add_admin_body_classes( $classes ) { return "$classes block-editor-page wp-embed-responsive"; } + +/** + * Emulates the Widgets screen `admin_print_styles` when at the block editor + * screen. + */ +function gutenberg_block_editor_admin_print_styles() { + if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) { + /** This action is documented in wp-admin/admin-footer.php */ + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + do_action( 'admin_print_styles-widgets.php' ); + } +} +add_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' ); + +/** + * Emulates the Widgets screen `admin_print_scripts` when at the block editor + * screen. + */ +function gutenberg_block_editor_admin_print_scripts() { + if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) { + /** This action is documented in wp-admin/includes/ajax-actions.php */ + do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + /** This action is documented in wp-admin/includes/ajax-actions.php */ + do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + /** This action is documented in wp-admin/widgets.php */ + do_action( 'sidebar_admin_setup' ); + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + do_action( 'admin_print_scripts-widgets.php' ); + } +} +add_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' ); + +/** + * Emulates the Widgets screen `admin_print_footer_scripts` when at the block + * editor screen. + */ +function gutenberg_block_editor_admin_print_footer_scripts() { + if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) { + /** This action is documented in wp-admin/admin-footer.php */ + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + do_action( 'admin_print_footer_scripts-widgets.php' ); + } +} +add_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' ); + +/** + * Emulates the Widgets screen `admin_footer` when at the block editor screen. + */ +function gutenberg_block_editor_admin_footer() { + if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) { + /** This action is documented in wp-admin/admin-footer.php */ + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + do_action( 'admin_footer-widgets.php' ); + } +} +add_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' ); diff --git a/lib/widgets.php b/lib/widgets.php index 3d6143337003be..53621323f9c182 100644 --- a/lib/widgets.php +++ b/lib/widgets.php @@ -11,6 +11,12 @@ * @return boolean True if a screen containing the block editor is being loaded. */ function gutenberg_is_block_editor() { + _deprecated_function( + 'gutenberg_is_block_editor', + '10.8', + 'WP_Screen::is_block_editor' + ); + // If get_current_screen does not exist, we are neither in the standard block editor for posts, or the widget block editor. // We can safely return false. if ( ! function_exists( 'get_current_screen' ) ) { @@ -44,79 +50,6 @@ function gutenberg_use_widgets_block_editor() { ); } -/** - * Emulates the Widgets screen `admin_print_styles` when at the block editor - * screen. - */ -function gutenberg_block_editor_admin_print_styles() { - if ( gutenberg_is_block_editor() ) { - /** This action is documented in wp-admin/admin-footer.php */ - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - do_action( 'admin_print_styles-widgets.php' ); - } -} -add_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' ); - -/** - * Emulates the Widgets screen `admin_print_scripts` when at the block editor - * screen. - */ -function gutenberg_block_editor_admin_print_scripts() { - if ( gutenberg_is_block_editor() ) { - /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - /** This action is documented in wp-admin/widgets.php */ - do_action( 'sidebar_admin_setup' ); - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - do_action( 'admin_print_scripts-widgets.php' ); - } -} -add_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' ); - -/** - * Emulates the Widgets screen `admin_print_footer_scripts` when at the block - * editor screen. - */ -function gutenberg_block_editor_admin_print_footer_scripts() { - if ( gutenberg_is_block_editor() ) { - /** This action is documented in wp-admin/admin-footer.php */ - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - do_action( 'admin_print_footer_scripts-widgets.php' ); - } -} -add_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' ); - -/** - * Emulates the Widgets screen `admin_footer` when at the block editor screen. - */ -function gutenberg_block_editor_admin_footer() { - if ( gutenberg_is_block_editor() ) { - /** This action is documented in wp-admin/admin-footer.php */ - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - do_action( 'admin_footer-widgets.php' ); - } -} -add_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' ); - -/** - * Adds a save widgets nonce required by the legacy widgets block. - */ -function gutenberg_print_save_widgets_nonce() { - // The function wpWidgets.save needs this nonce to work as expected. - echo implode( - "\n", - array( - '
', - wp_nonce_field( 'save-sidebar-widgets', '_wpnonce_widgets', false ), - '
', - ) - ); -} -add_action( 'admin_footer-widgets.php', 'gutenberg_print_save_widgets_nonce' ); - - /** * Returns the settings required by legacy widgets blocks. * @@ -137,7 +70,6 @@ function gutenberg_get_legacy_widget_settings() { 'media_image', 'media_gallery', 'media_video', - 'meta', 'search', 'text', 'categories', @@ -150,89 +82,11 @@ function gutenberg_get_legacy_widget_settings() { ) ); - // Backwards compatibility. Remove this in or after Gutenberg 10.5. - if ( has_filter( 'widgets_to_exclude_from_legacy_widget_block' ) ) { - /** - * Filters the list of widget classes that should **not** be offered by the legacy widget block. - * - * Returning an empty array will make all the widgets available. - * - * @param array $widgets An array of excluded widgets classnames. - * - * @since 5.6.0 - */ - $widgets_to_exclude_from_legacy_widget_block = apply_filters( - 'widgets_to_exclude_from_legacy_widget_block', - array( - 'WP_Widget_Block', - 'WP_Widget_Pages', - 'WP_Widget_Calendar', - 'WP_Widget_Archives', - 'WP_Widget_Media_Audio', - 'WP_Widget_Media_Image', - 'WP_Widget_Media_Gallery', - 'WP_Widget_Media_Video', - 'WP_Widget_Meta', - 'WP_Widget_Search', - 'WP_Widget_Text', - 'WP_Widget_Categories', - 'WP_Widget_Recent_Posts', - 'WP_Widget_Recent_Comments', - 'WP_Widget_RSS', - 'WP_Widget_Tag_Cloud', - 'WP_Widget_Custom_HTML', - ) - ); - - _deprecated_hook( - 'widgets_to_exclude_from_legacy_widget_block', - '10.3', - "wp.hooks.addFilter( 'legacyWidget.isWidgetTypeHidden', ... )" - ); - - foreach ( $wp_widget_factory->widgets as $widget ) { - if ( - in_array( get_class( $widget ), $widgets_to_exclude_from_legacy_widget_block, true ) && - ! in_array( $widget->id_base, $widget_types_to_hide_from_legacy_widget_block, true ) - ) { - $widget_types_to_hide_from_legacy_widget_block[] = $widget->id_base; - } - } - } - $settings['widgetTypesToHideFromLegacyWidgetBlock'] = $widget_types_to_hide_from_legacy_widget_block; return $settings; } -/** - * Extends default editor settings with values supporting legacy widgets. - * - * This can be removed when plugin support requires WordPress 5.8.0+. - * - * @param array $settings Default editor settings. - * - * @return array Filtered editor settings. - */ -function gutenberg_legacy_widget_settings( $settings ) { - return array_merge( $settings, gutenberg_get_legacy_widget_settings() ); -} -// This can be removed when plugin support requires WordPress 5.8.0+. -if ( function_exists( 'get_block_editor_settings' ) ) { - add_filter( 'block_editor_settings_all', 'gutenberg_legacy_widget_settings' ); -} else { - add_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' ); -} - -/** - * Function to enqueue admin-widgets as part of the block editor assets. - */ -function gutenberg_enqueue_widget_scripts() { - wp_enqueue_script( 'admin-widgets' ); -} - -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_widget_scripts' ); - /** * Overrides dynamic_sidebar_params to make sure Blocks are not wrapped in
tag. * @@ -306,4 +160,7 @@ function gutenberg_set_show_instance_in_rest_on_core_widgets() { } } } -add_action( 'widgets_init', 'gutenberg_set_show_instance_in_rest_on_core_widgets' ); + +if ( ! function_exists( 'wp_use_widgets_block_editor' ) ) { + add_action( 'widgets_init', 'gutenberg_set_show_instance_in_rest_on_core_widgets' ); +} diff --git a/package-lock.json b/package-lock.json index ec71f1a540e48b..eea92994025264 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14320,12 +14320,20 @@ "version": "file:packages/widgets", "requires": { "@babel/runtime": "^7.13.10", + "@wordpress/api-fetch": "file:packages/api-fetch", + "@wordpress/block-editor": "file:packages/block-editor", "@wordpress/blocks": "file:packages/blocks", "@wordpress/components": "file:packages/components", + "@wordpress/compose": "file:packages/compose", "@wordpress/core-data": "file:packages/core-data", "@wordpress/data": "file:packages/data", + "@wordpress/element": "file:packages/element", "@wordpress/i18n": "file:packages/i18n", - "@wordpress/icons": "file:packages/icons" + "@wordpress/icons": "file:packages/icons", + "@wordpress/notices": "file:packages/notices", + "@wordpress/url": "file:packages/url", + "classnames": "^2.2.5", + "lodash": "^4.17.21" } }, "@wordpress/wordcount": { diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 46b6aa9443a5ee..62ed002f5d028e 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## Breaking Changes + +- Removes the `core/legacy-widget` block. This is now in `@wordpress/widgets` + via `registerLegacyWidgetBlock()`. + ## 3.2.0 (2021-05-24) ### New Features diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 4118213572e232..49d89ff9e7c3f9 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -20,7 +20,6 @@ @import "./html/editor.scss"; @import "./image/editor.scss"; @import "./latest-posts/editor.scss"; -@import "./legacy-widget/editor.scss"; @import "./media-text/editor.scss"; @import "./more/editor.scss"; @import "./navigation/editor.scss"; diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 73713305c10308..0716373e244b8b 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -38,7 +38,6 @@ import * as navigationLink from './navigation-link'; import * as homeLink from './home-link'; import * as latestComments from './latest-comments'; import * as latestPosts from './latest-posts'; -import * as legacyWidget from './legacy-widget'; import * as logInOut from './loginout'; import * as list from './list'; import * as missing from './missing'; @@ -148,7 +147,6 @@ export const __experimentalGetCoreBlocks = () => [ mediaText, latestComments, latestPosts, - legacyWidget, missing, more, nextpage, diff --git a/packages/customize-widgets/src/index.js b/packages/customize-widgets/src/index.js index 1b2d02b3c81fd9..3a725ccdda2ba6 100644 --- a/packages/customize-widgets/src/index.js +++ b/packages/customize-widgets/src/index.js @@ -7,7 +7,10 @@ import { __experimentalGetCoreBlocks, __experimentalRegisterExperimentalCoreBlocks, } from '@wordpress/block-library'; -import { registerLegacyWidgetVariations } from '@wordpress/widgets'; +import { + registerLegacyWidgetBlock, + registerLegacyWidgetVariations, +} from '@wordpress/widgets'; /** * Internal dependencies @@ -30,11 +33,10 @@ export function initialize( editorName, blockEditorSettings ) { ( block ) => ! [ 'core/more' ].includes( block.name ) ); registerCoreBlocks( coreBlocks ); - + registerLegacyWidgetBlock(); if ( process.env.GUTENBERG_PHASE === 2 ) { __experimentalRegisterExperimentalCoreBlocks(); } - registerLegacyWidgetVariations( blockEditorSettings ); const SidebarControl = getSidebarControl( blockEditorSettings ); diff --git a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.html b/packages/e2e-tests/fixtures/blocks/core__legacy-widget.html deleted file mode 100644 index 293a884c37414f..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.json b/packages/e2e-tests/fixtures/blocks/core__legacy-widget.json deleted file mode 100644 index fc919a1597d6ca..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.json +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "clientId": "_clientId_0", - "name": "core/legacy-widget", - "isValid": true, - "attributes": { - "id": null, - "idBase": "search", - "instance": { - "encoded": "YTowOnt9", - "hash": "b9b82f721929717273108125217fbcd9", - "raw": {} - } - }, - "innerBlocks": [], - "originalContent": "" - } -] diff --git a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.parsed.json b/packages/e2e-tests/fixtures/blocks/core__legacy-widget.parsed.json deleted file mode 100644 index e97d26c0f43b22..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.parsed.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "blockName": "core/legacy-widget", - "attrs": { - "idBase": "search", - "instance": { - "encoded": "YTowOnt9", - "hash": "b9b82f721929717273108125217fbcd9", - "raw": {} - } - }, - "innerBlocks": [], - "innerHTML": "", - "innerContent": [] - } -] diff --git a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.serialized.html b/packages/e2e-tests/fixtures/blocks/core__legacy-widget.serialized.html deleted file mode 100644 index 293a884c37414f..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__legacy-widget.serialized.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/e2e-tests/specs/editor/plugins/__snapshots__/wp-editor-meta-box.test.js.snap b/packages/e2e-tests/specs/editor/plugins/__snapshots__/wp-editor-meta-box.test.js.snap index 485862873b648d..29a3d82f5f0685 100644 --- a/packages/e2e-tests/specs/editor/plugins/__snapshots__/wp-editor-meta-box.test.js.snap +++ b/packages/e2e-tests/specs/editor/plugins/__snapshots__/wp-editor-meta-box.test.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`WP Editor Meta Boxes Should save the changes 1`] = `"

Typing in a metabox

"`; +exports[`WP Editor Meta Boxes Should save the changes 1`] = `"Typing in a metabox"`; diff --git a/packages/edit-widgets/src/index.js b/packages/edit-widgets/src/index.js index c1582396ddef25..b69edb7b2fc132 100644 --- a/packages/edit-widgets/src/index.js +++ b/packages/edit-widgets/src/index.js @@ -12,7 +12,10 @@ import { __experimentalRegisterExperimentalCoreBlocks, } from '@wordpress/block-library'; import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data'; -import { registerLegacyWidgetVariations } from '@wordpress/widgets'; +import { + registerLegacyWidgetBlock, + registerLegacyWidgetVariations, +} from '@wordpress/widgets'; /** * Internal dependencies @@ -33,6 +36,7 @@ export function initialize( id, settings ) { ( block ) => ! [ 'core/more' ].includes( block.name ) ); registerCoreBlocks( coreBlocks ); + registerLegacyWidgetBlock(); if ( process.env.GUTENBERG_PHASE === 2 ) { __experimentalRegisterExperimentalCoreBlocks(); } diff --git a/packages/widgets/package.json b/packages/widgets/package.json index 728213cd52ff16..fe46cb0f44d96c 100644 --- a/packages/widgets/package.json +++ b/packages/widgets/package.json @@ -21,12 +21,20 @@ "react-native": "src/index", "dependencies": { "@babel/runtime": "^7.13.10", + "@wordpress/api-fetch": "file:../api-fetch", + "@wordpress/block-editor": "file:../block-editor", "@wordpress/blocks": "file:../blocks", "@wordpress/components": "file:../components", + "@wordpress/compose": "file:../compose", "@wordpress/core-data": "file:../core-data", "@wordpress/data": "file:../data", + "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", - "@wordpress/icons": "file:../icons" + "@wordpress/icons": "file:../icons", + "@wordpress/notices": "file:../notices", + "@wordpress/url": "file:../url", + "classnames": "^2.2.5", + "lodash": "^4.17.21" }, "publishConfig": { "access": "public" diff --git a/packages/block-library/src/legacy-widget/README.md b/packages/widgets/src/blocks/legacy-widget/README.md similarity index 100% rename from packages/block-library/src/legacy-widget/README.md rename to packages/widgets/src/blocks/legacy-widget/README.md diff --git a/packages/block-library/src/legacy-widget/block.json b/packages/widgets/src/blocks/legacy-widget/block.json similarity index 100% rename from packages/block-library/src/legacy-widget/block.json rename to packages/widgets/src/blocks/legacy-widget/block.json diff --git a/packages/block-library/src/legacy-widget/edit/control.js b/packages/widgets/src/blocks/legacy-widget/edit/control.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/control.js rename to packages/widgets/src/blocks/legacy-widget/edit/control.js diff --git a/packages/block-library/src/legacy-widget/edit/convert-to-blocks-button.js b/packages/widgets/src/blocks/legacy-widget/edit/convert-to-blocks-button.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/convert-to-blocks-button.js rename to packages/widgets/src/blocks/legacy-widget/edit/convert-to-blocks-button.js diff --git a/packages/block-library/src/legacy-widget/edit/form.js b/packages/widgets/src/blocks/legacy-widget/edit/form.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/form.js rename to packages/widgets/src/blocks/legacy-widget/edit/form.js diff --git a/packages/block-library/src/legacy-widget/edit/index.js b/packages/widgets/src/blocks/legacy-widget/edit/index.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/index.js rename to packages/widgets/src/blocks/legacy-widget/edit/index.js diff --git a/packages/block-library/src/legacy-widget/edit/inspector-card.js b/packages/widgets/src/blocks/legacy-widget/edit/inspector-card.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/inspector-card.js rename to packages/widgets/src/blocks/legacy-widget/edit/inspector-card.js diff --git a/packages/block-library/src/legacy-widget/edit/no-preview.js b/packages/widgets/src/blocks/legacy-widget/edit/no-preview.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/no-preview.js rename to packages/widgets/src/blocks/legacy-widget/edit/no-preview.js diff --git a/packages/block-library/src/legacy-widget/edit/preview.js b/packages/widgets/src/blocks/legacy-widget/edit/preview.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/preview.js rename to packages/widgets/src/blocks/legacy-widget/edit/preview.js diff --git a/packages/block-library/src/legacy-widget/edit/widget-type-selector.js b/packages/widgets/src/blocks/legacy-widget/edit/widget-type-selector.js similarity index 100% rename from packages/block-library/src/legacy-widget/edit/widget-type-selector.js rename to packages/widgets/src/blocks/legacy-widget/edit/widget-type-selector.js diff --git a/packages/block-library/src/legacy-widget/editor.scss b/packages/widgets/src/blocks/legacy-widget/editor.scss similarity index 98% rename from packages/block-library/src/legacy-widget/editor.scss rename to packages/widgets/src/blocks/legacy-widget/editor.scss index 710e4d905879cf..0d9a2164754207 100644 --- a/packages/block-library/src/legacy-widget/editor.scss +++ b/packages/widgets/src/blocks/legacy-widget/editor.scss @@ -63,8 +63,9 @@ .wp-block-legacy-widget__edit-no-preview { background: $gray-100; - padding: $grid-unit-10 $grid-unit-15; + font-family: $default-font; font-size: $default-font-size; + padding: $grid-unit-10 $grid-unit-15; h3 { font-size: 14px; diff --git a/packages/block-library/src/legacy-widget/index.js b/packages/widgets/src/blocks/legacy-widget/index.js similarity index 100% rename from packages/block-library/src/legacy-widget/index.js rename to packages/widgets/src/blocks/legacy-widget/index.js diff --git a/packages/block-library/src/legacy-widget/index.php b/packages/widgets/src/blocks/legacy-widget/index.php similarity index 100% rename from packages/block-library/src/legacy-widget/index.php rename to packages/widgets/src/blocks/legacy-widget/index.php diff --git a/packages/block-library/src/legacy-widget/transforms.js b/packages/widgets/src/blocks/legacy-widget/transforms.js similarity index 100% rename from packages/block-library/src/legacy-widget/transforms.js rename to packages/widgets/src/blocks/legacy-widget/transforms.js diff --git a/packages/widgets/src/index.js b/packages/widgets/src/index.js index 03f11440474a82..c02afc7a3f57cf 100644 --- a/packages/widgets/src/index.js +++ b/packages/widgets/src/index.js @@ -1,3 +1,27 @@ +/** + * WordPress dependencies + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import * as legacyWidget from './blocks/legacy-widget'; + export * from './components'; -export { default as registerLegacyWidgetVariations } from './register-legacy-widget-variations'; export * from './utils'; + +/** + * Registers the Legacy Widget block. + * + * Note that for the block to be useful, any scripts required by a widget must + * be loaded into the page. + * + * @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/ + */ +export function registerLegacyWidgetBlock() { + const { metadata, settings, name } = legacyWidget; + registerBlockType( { name, ...metadata }, settings ); +} + +export { default as registerLegacyWidgetVariations } from './register-legacy-widget-variations'; diff --git a/packages/widgets/src/style.scss b/packages/widgets/src/style.scss new file mode 100644 index 00000000000000..4ba09348938568 --- /dev/null +++ b/packages/widgets/src/style.scss @@ -0,0 +1 @@ +@import "./blocks/legacy-widget/editor.scss"; diff --git a/webpack.config.js b/webpack.config.js index af7269181c007e..ca72469c286b35 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -244,6 +244,7 @@ module.exports = { './packages/block-library/src/': 'build/block-library/blocks/', './packages/edit-widgets/src/blocks/': 'build/edit-widgets/blocks/', + './packages/widgets/src/blocks/': 'build/widgets/blocks/', } ).flatMap( ( [ from, to ] ) => [ { from: `${ from }/**/index.php`,