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

Remove Interactivity API experimental flag #50941

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0aa898a
Remove experimental flag
SantosGuillamot May 25, 2023
1e5faae
Move interactive scripts to `block.json`
SantosGuillamot May 25, 2023
4993973
Add scripts conditionally
SantosGuillamot May 25, 2023
203428c
Move directives to `index.php` files
SantosGuillamot May 25, 2023
07c7688
Remove experimental flag from lightbox tests
SantosGuillamot May 25, 2023
dc024f1
Fix PHP coding standards
SantosGuillamot May 25, 2023
b396c0f
Fix file PHP unit tests
SantosGuillamot May 25, 2023
8311145
Fix PHP comment spaces
SantosGuillamot May 25, 2023
3391914
Fix linting in image block
SantosGuillamot May 25, 2023
49e46b9
Comment navigation frontend interactivity tests
SantosGuillamot May 25, 2023
63da9c3
Comment script loader
SantosGuillamot May 25, 2023
f8904e1
Comment hook to add directives
SantosGuillamot May 25, 2023
1b3b9be
Comment conditional loading
SantosGuillamot May 25, 2023
a38a289
Remove `viewScript` from `block.json`
SantosGuillamot May 25, 2023
bb52141
Revert "Remove `viewScript` from `block.json`"
SantosGuillamot May 25, 2023
93849d7
Roll back everything but the conditional load
SantosGuillamot May 25, 2023
f183139
Remove `viewScript` from `block.json`
SantosGuillamot May 25, 2023
f7b72c5
Move navigation directives to the markup
SantosGuillamot May 25, 2023
eef7d94
Merge branch 'trunk' into experiment/remove-interactivity-api-experim…
SantosGuillamot May 25, 2023
1ad4320
Add JavaScript file back to navigation block
SantosGuillamot May 25, 2023
ec12f7d
Remove Interactivity API
SantosGuillamot May 26, 2023
3c50f64
Add directives to markup (without JS)
SantosGuillamot May 26, 2023
640d021
Add JavaScript (without directives)
SantosGuillamot May 26, 2023
ebea6ce
Run only navigation spec
SantosGuillamot May 26, 2023
df05c46
Add directives (with JS)
SantosGuillamot May 26, 2023
8053c88
Remove puppeteer from workflow
SantosGuillamot May 26, 2023
16155f8
Remove directives from the submenu (Tag Processor)
SantosGuillamot May 26, 2023
54d509f
Remove directives and add custom attribute
SantosGuillamot May 26, 2023
a1c0539
Include only nav element directives
SantosGuillamot May 26, 2023
f05d3c2
Add open button directives
SantosGuillamot May 26, 2023
6a62fe3
Add responsive container directives
SantosGuillamot May 26, 2023
4b30255
Responsive container without negation operator
SantosGuillamot May 26, 2023
72e343f
Add everything but the negation operator
SantosGuillamot May 26, 2023
9cedc48
Revert "Add everything but the negation operator"
SantosGuillamot May 26, 2023
0f29bb9
Add the rest of navigation block directives
SantosGuillamot May 26, 2023
d2267f9
Add submenu directives
SantosGuillamot May 26, 2023
c76b8d0
Remove submenu button directives
SantosGuillamot May 26, 2023
12087a1
Remove submenu directives and add custom attr
SantosGuillamot May 26, 2023
dea6a43
Move submenu Tag Processor return
SantosGuillamot May 29, 2023
000c2f4
Apply changes to aria-hidden attribute
SantosGuillamot May 29, 2023
b91cfd3
Uncomment commented code
SantosGuillamot May 29, 2023
2a55115
Remove `aria-hidden` attribute
SantosGuillamot May 29, 2023
3dcb009
Merge branch 'trunk' into experiment/remove-interactivity-api-experim…
SantosGuillamot May 29, 2023
a97c9c7
Solve linting issues
SantosGuillamot May 29, 2023
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
234 changes: 0 additions & 234 deletions lib/experimental/interactivity-api/blocks.php

This file was deleted.

12 changes: 0 additions & 12 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-interactivity-api-core-blocks',
__( 'Core blocks', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test the core blocks using the Interactivity API', 'gutenberg' ),
'id' => 'gutenberg-interactivity-api-core-blocks',
)
);

add_settings_field(
'gutenberg-pattern-enhancements',
__( 'Pattern enhancements', 'gutenberg' ),
Expand Down
5 changes: 1 addition & 4 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/kses.php';
require __DIR__ . '/experimental/l10n.php';
require __DIR__ . '/experimental/navigation-fallback.php';
if ( gutenberg_is_experiment_enabled( 'gutenberg-interactivity-api-core-blocks' ) ) {
require __DIR__ . '/experimental/interactivity-api/script-loader.php';
require __DIR__ . '/experimental/interactivity-api/blocks.php';
}
require __DIR__ . '/experimental/interactivity-api/script-loader.php';

// Fonts API.
if ( ! class_exists( 'WP_Fonts' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/file/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}
}
},
"viewScript": "file:./view.min.js",
"viewScript": "file:./interactivity.min.js",
"editorStyle": "wp-block-file-editor",
"style": "wp-block-file"
}
35 changes: 29 additions & 6 deletions packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@
/**
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-file-view` script.
*
* @param array $attributes The block attributes.
* @param string $content The block content.
* @param array $attributes The block attributes.
* @param string $content The block content.
* @param WP_Block $block The parsed block.
*
* @return string Returns the block content.
*/
function render_block_core_file( $attributes, $content ) {
$should_load_view_script = ! empty( $attributes['displayPreview'] ) && ! wp_script_is( 'wp-block-file-view' );
if ( $should_load_view_script ) {
wp_enqueue_script( 'wp-block-file-view' );
function render_block_core_file( $attributes, $content, $block ) {
$should_load_view_script = ! empty( $attributes['displayPreview'] );
$view_js_file = 'wp-block-file-view';
// If the script already exists, there is no point in removing it from viewScript.
if ( ! wp_script_is( $view_js_file ) ) {
$script_handles = $block->block_type->view_script_handles;

// If the script is not needed, and it is still in the `view_script_handles`, remove it.
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
}
// If the script is needed, but it was previously removed, add it again.
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
}
}

// Update object's aria-label attribute if present in block HTML.
Expand All @@ -41,6 +53,17 @@ function ( $matches ) {
$content
);

// If it uses the Interactivity API, add the directives.
if ( $should_load_view_script ) {
$processor = new WP_HTML_Tag_Processor( $content );
$processor->next_tag();
$processor->set_attribute( 'data-wp-island', '' );
$processor->next_tag( 'object' );
$processor->set_attribute( 'data-wp-bind.hidden', '!selectors.core.file.hasPdfPreview' );
$processor->set_attribute( 'hidden', true );
return $processor->get_updated_html();
}

return $content;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/block-library/src/file/view.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/block-library/src/image/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
},
{ "name": "rounded", "label": "Rounded" }
],
"viewScript": "file:./interactivity.min.js",
"editorStyle": "wp-block-image-editor",
"style": "wp-block-image"
}
26 changes: 21 additions & 5 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* Renders the `core/image` block on the server,
* adding a data-id attribute to the element if core/gallery has added on pre-render.
*
* @param array $attributes The block attributes.
* @param string $content The block content.
* @param array $attributes The block attributes.
* @param string $content The block content.
* @param WP_Block $block The parsed block.
*
* @return string Returns the block content with the data-id attribute added.
*/
function render_block_core_image( $attributes, $content ) {
function render_block_core_image( $attributes, $content, $block ) {

$processor = new WP_HTML_Tag_Processor( $content );
$processor->next_tag( 'img' );
Expand Down Expand Up @@ -45,9 +47,23 @@ function render_block_core_image( $attributes, $content ) {
}
}

$experiments = get_option( 'gutenberg-experiments' );
$should_load_view_script = 'none' === $link_destination && $lightbox;
$view_js_file = 'wp-block-image-view';
// If the script already exists, there is no point in removing it from viewScript.
if ( ! wp_script_is( $view_js_file ) ) {
$script_handles = $block->block_type->view_script_handles;

// If the script is not needed, and it is still in the `view_script_handles`, remove it.
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
}
// If the script is needed, but it was previously removed, add it again.
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
}
}

if ( ! empty( $experiments['gutenberg-interactivity-api-core-blocks'] ) && 'none' === $link_destination && $lightbox ) {
if ( $should_load_view_script ) {

$aria_label = __( 'Enlarge image' );

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
}
}
},
"viewScript": [ "file:./view.min.js", "file:./view-modal.min.js" ],
"viewScript": "file:./interactivity.min.js",
"editorStyle": "wp-block-navigation-editor",
"style": "wp-block-navigation"
}
Loading