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 gutenberg_should_block_use_interactivity_api and the old implementation of interactive blocks #54297

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Expand Up @@ -266,7 +266,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/file
- **Category:** media
- **Supports:** align, anchor, color (background, gradients, link, ~~text~~), spacing (margin, padding)
- **Supports:** align, anchor, color (background, gradients, link, ~~text~~), interactivity, spacing (margin, padding)
- **Attributes:** displayPreview, downloadButtonText, fileId, fileName, href, id, previewHeight, showDownloadButton, textLinkHref, textLinkTarget

## Footnotes
Expand Down Expand Up @@ -421,7 +421,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht

- **Name:** core/navigation
- **Category:** theme
- **Supports:** align (full, wide), inserter, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), inserter, interactivity, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link
Expand Down
21 changes: 0 additions & 21 deletions lib/experimental/blocks.php
Expand Up @@ -5,27 +5,6 @@
* @package gutenberg
*/

/**
* Checks whether the experimental Interactivity API should be used for a block.
*
* Note: This function is located here instead of in interactivity-api/blocks.php because it has to be available earler.
*
* @param string $block_name Block name.
* @return bool Whether Interactivity API is used for block.
*/
function gutenberg_should_block_use_interactivity_api( $block_name ) {

/**
* Filters whether the experimental Interactivity API should be used for a block.
*
* @since 6.3.0
*
* @param bool $enabled Whether Interactivity API is used for block.
* @param string $block_name Block name.
*/
return (bool) apply_filters( 'gutenberg_should_block_use_interactivity_api', true, $block_name );
}

if ( ! function_exists( 'wp_enqueue_block_view_script' ) ) {
/**
* Enqueues a frontend script for a specific block.
Expand Down
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/block-library/package.json
Expand Up @@ -68,7 +68,6 @@
"fast-average-color": "^9.1.1",
"fast-deep-equal": "^3.1.3",
"memize": "^2.1.0",
"micromodal": "^0.4.10",
"remove-accents": "^0.5.0",
"uuid": "^8.3.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/file/block.json
Expand Up @@ -69,7 +69,8 @@
"background": true,
"link": true
}
}
},
"interactivity": true
},
"viewScript": "file:./view.min.js",
"editorStyle": "wp-block-file-editor",
Expand Down
20 changes: 1 addition & 19 deletions packages/block-library/src/file/index.php
Expand Up @@ -5,24 +5,6 @@
* @package WordPress
*/

if ( gutenberg_should_block_use_interactivity_api( 'core/file' ) ) {
/**
* Replaces view script for the File block with version using Interactivity API.
*
* @param array $metadata Block metadata as read in via block.json.
*
* @return array Filtered block type metadata.
*/
function gutenberg_block_core_file_update_interactive_view_script( $metadata ) {
if ( 'core/file' === $metadata['name'] ) {
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
$metadata['supports']['interactivity'] = true;
}
return $metadata;
}
add_filter( 'block_type_metadata', 'gutenberg_block_core_file_update_interactive_view_script', 10, 1 );
}

/**
* When the `core/file` block is rendering, check if we need to enqueue the `wp-block-file-view` script.
*
Expand Down Expand Up @@ -72,7 +54,7 @@ static function ( $matches ) {
);

// If it uses the Interactivity API, add the directives.
if ( gutenberg_should_block_use_interactivity_api( 'core/file' ) && $should_load_view_script ) {
if ( $should_load_view_script ) {
$processor = new WP_HTML_Tag_Processor( $content );
$processor->next_tag();
$processor->set_attribute( 'data-wp-interactive', '' );
Expand Down
15 changes: 0 additions & 15 deletions packages/block-library/src/file/utils/index.js
Expand Up @@ -54,18 +54,3 @@ const createActiveXObject = ( type ) => {
}
return ax;
};

/**
* Hides all .wp-block-file__embed elements on the document. This function is only intended
* to be run on the front-end, it may have weird side effects running in the block editor.
*/
export const hidePdfEmbedsOnUnsupportedBrowsers = () => {
if ( ! browserSupportsPdfs() ) {
const embeds = document.getElementsByClassName(
'wp-block-file__embed'
);
Array.from( embeds ).forEach( ( embed ) => {
embed.style.display = 'none';
} );
}
};
18 changes: 0 additions & 18 deletions packages/block-library/src/file/view-interactivity.js

This file was deleted.

19 changes: 14 additions & 5 deletions packages/block-library/src/file/view.js
@@ -1,9 +1,18 @@
/**
* WordPress dependencies
*/
import { store } from '@wordpress/interactivity';
/**
* Internal dependencies
*/
import { hidePdfEmbedsOnUnsupportedBrowsers } from './utils';
import { browserSupportsPdfs as hasPdfPreview } from './utils';

document.addEventListener(
'DOMContentLoaded',
hidePdfEmbedsOnUnsupportedBrowsers
);
store( {
selectors: {
core: {
file: {
hasPdfPreview,
},
},
},
} );
5 changes: 3 additions & 2 deletions packages/block-library/src/navigation/block.json
Expand Up @@ -131,9 +131,10 @@
}
}
}
}
},
"interactivity": true
},
"viewScript": [ "file:./view.min.js", "file:./view-modal.min.js" ],
"viewScript": "file:./view.min.js",
"editorStyle": "wp-block-navigation-editor",
"style": "wp-block-navigation"
}