Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an empty list block v2 #39459

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/compat/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
11 changes: 11 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => __( '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',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
7 changes: 6 additions & 1 deletion packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -41,3 +42,7 @@ export const settings = {
save,
deprecated,
};

export const settings = window?.__experimentalEnableListBlockV2
? settingsV2
: settingsV1;
5 changes: 5 additions & 0 deletions packages/block-library/src/list/v2/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Edit() {
return <div>List block v2</div>;
}

export default Edit;
18 changes: 18 additions & 0 deletions packages/block-library/src/list/v2/index.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions packages/block-library/src/list/v2/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Save() {
return <div>List block v2</div>;
}

export default Save;