-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File: Add experimental integration with Interactivity API
- Loading branch information
Showing
7 changed files
with
105 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Temporary compatibility shims for block APIs present in Gutenberg. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Adds Interactivity API directives to the File block markup using the Tag Processor. | ||
* | ||
* @param string $block_content Markup of the File block. | ||
* @param array $block The full block, including name and attributes. | ||
* @param WP_Block $instance The block instance. | ||
* | ||
* @return string File block markup with the directives injected when applicable. | ||
*/ | ||
function gutenberg_block_core_file_add_directives_to_content( $block_content, $block, $instance ) { | ||
if ( empty( $instance->attributes['displayPreview'] ) ) { | ||
return $block_content; | ||
} | ||
$processor = new WP_HTML_Tag_Processor( $block_content ); | ||
$processor->next_tag(); | ||
$processor->set_attribute( 'data-wp-init', 'effects.core.file.init' ); | ||
return $processor->get_updated_html(); | ||
} | ||
add_filter( 'render_block_core/file', 'gutenberg_block_core_file_add_directives_to_content', 10, 3 ); | ||
|
||
/** | ||
* 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_view_script( $metadata ) { | ||
if ( 'core/file' === $metadata['name'] && str_contains( $metadata['file'], 'build/block-library/blocks' ) ) { | ||
$metadata['viewScript'] = array( 'file:./view/interactivity.min.js' ); | ||
} | ||
return $metadata; | ||
} | ||
add_filter( 'block_type_metadata', 'gutenberg_block_core_file_update_view_script', 10, 1 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store } from '../../utils/interactivity'; | ||
import { hidePdfEmbedsOnUnsupportedBrowsers } from '../utils'; | ||
|
||
store( { | ||
effects: { | ||
core: { | ||
file: { | ||
init() { | ||
hidePdfEmbedsOnUnsupportedBrowsers(); | ||
}, | ||
}, | ||
}, | ||
}, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters