From 5a412611ccd59ef2d775543c868eddfcc1d93f45 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 15 Mar 2022 13:38:24 +0100 Subject: [PATCH 1/2] Add an empty list block v2 --- lib/compat/experimental/blocks.php | 11 +++++++++++ lib/experiments-page.php | 11 +++++++++++ packages/block-library/src/list/index.js | 7 ++++++- packages/block-library/src/list/v2/edit.js | 5 +++++ packages/block-library/src/list/v2/index.js | 18 ++++++++++++++++++ packages/block-library/src/list/v2/save.js | 5 +++++ 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 packages/block-library/src/list/v2/edit.js create mode 100644 packages/block-library/src/list/v2/index.js create mode 100644 packages/block-library/src/list/v2/save.js diff --git a/lib/compat/experimental/blocks.php b/lib/compat/experimental/blocks.php index e0b57c663300f..657affc4aab94 100644 --- a/lib/compat/experimental/blocks.php +++ b/lib/compat/experimental/blocks.php @@ -159,3 +159,14 @@ function ( $response ) { } } add_action( 'rest_api_init', 'gutenberg_rest_comment_set_children_as_embeddable' ); + +/** + * Sets a global JS variable used to trigger the availability of the experimental list block. + */ +function gutenberg_enable_experimental_list_block() { + if ( get_option( 'gutenberg-experiments' ) && array_key_exists( 'gutenberg-list-v2', get_option( 'gutenberg-experiments' ) ) ) { + wp_add_inline_script( 'wp-block-library', 'window.__experimentalEnableListBlockV2 = true', 'before' ); + } +} + +add_action( 'admin_init', 'gutenberg_enable_experimental_list_block' ); diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 9421d84b88db9..f62a775d2360d 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -51,6 +51,17 @@ function gutenberg_initialize_experiments_settings() { 'id' => 'gutenberg-navigation', ) ); + add_settings_field( + 'gutenberg-list-v2', + __( 'List block v2', 'gutenberg' ), + 'gutenberg_display_experiment_field', + 'gutenberg-experiments', + 'gutenberg_experiments_section', + array( + 'label' => __( 'Enable List block v2 (with inner blocks)', 'gutenberg' ), + 'id' => 'gutenberg-list-v2', + ) + ); register_setting( 'gutenberg-experiments', 'gutenberg-experiments' diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 8b3e31e7cf54c..38878a4194dfa 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -11,12 +11,13 @@ import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; +import settingsV2 from './v2'; const { name } = metadata; export { metadata, name }; -export const settings = { +const settingsV1 = { icon, example: { attributes: { @@ -41,3 +42,7 @@ export const settings = { save, deprecated, }; + +export const settings = window.__experimentalEnableListBlockV2 + ? settingsV2 + : settingsV1; diff --git a/packages/block-library/src/list/v2/edit.js b/packages/block-library/src/list/v2/edit.js new file mode 100644 index 0000000000000..db14ebaa0427f --- /dev/null +++ b/packages/block-library/src/list/v2/edit.js @@ -0,0 +1,5 @@ +function Edit() { + return
List block v2
; +} + +export default Edit; diff --git a/packages/block-library/src/list/v2/index.js b/packages/block-library/src/list/v2/index.js new file mode 100644 index 0000000000000..9e96f2d40116b --- /dev/null +++ b/packages/block-library/src/list/v2/index.js @@ -0,0 +1,18 @@ +/** + * WordPress dependencies + */ +import { list as icon } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import edit from './edit'; +import save from './save'; + +const settings = { + icon, + edit, + save, +}; + +export default settings; diff --git a/packages/block-library/src/list/v2/save.js b/packages/block-library/src/list/v2/save.js new file mode 100644 index 0000000000000..8970ff165f725 --- /dev/null +++ b/packages/block-library/src/list/v2/save.js @@ -0,0 +1,5 @@ +function Save() { + return
List block v2
; +} + +export default Save; From dafb9a29d89499b76577dbe0fadc8c53f560b7a3 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 16 Mar 2022 08:36:11 +0100 Subject: [PATCH 2/2] More scary message --- lib/experiments-page.php | 2 +- packages/block-library/src/list/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experiments-page.php b/lib/experiments-page.php index f62a775d2360d..a0aabb3f3ec6b 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -58,7 +58,7 @@ function gutenberg_initialize_experiments_settings() { 'gutenberg-experiments', 'gutenberg_experiments_section', array( - 'label' => __( 'Enable List block v2 (with inner blocks)', 'gutenberg' ), + 'label' => __( 'Test a new list block that uses nested list item blocks (Warning: The new block is not ready. You may experience content loss, avoid using it on production sites)', 'gutenberg' ), 'id' => 'gutenberg-list-v2', ) ); diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 38878a4194dfa..f107ccd332a5c 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -43,6 +43,6 @@ const settingsV1 = { deprecated, }; -export const settings = window.__experimentalEnableListBlockV2 +export const settings = window?.__experimentalEnableListBlockV2 ? settingsV2 : settingsV1;