Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1f3f99d
Bundle `@wordpress/interactivity` as an ES module
luisherranz Nov 9, 2023
8fe36f9
Add the class with a basic API
luisherranz Nov 13, 2023
68692d1
Make it work with the Navigation block
luisherranz Nov 13, 2023
0215330
Add versions
luisherranz Nov 13, 2023
9c5ea5d
Register `@wordpress/interactivity` module
luisherranz Nov 13, 2023
3ffc77c
Add query and image blocks
luisherranz Nov 13, 2023
7cc08c8
Add id with module identifier to the enqueued modules
luisherranz Nov 13, 2023
11b4e1b
Add requried $usage for admin/frontend
luisherranz Nov 14, 2023
c080fa7
Avoid the use of enqueue to register modules
luisherranz Nov 14, 2023
bd0a881
Refactor versions
luisherranz Nov 14, 2023
e0201ce
Switch from `both` to `['admin', 'frontend']`
luisherranz Nov 14, 2023
89f6be0
Improve comments
luisherranz Nov 14, 2023
64fd8ac
Add an optional static dependency graph
luisherranz Nov 14, 2023
6a21c10
Add static and dynamic dependencies in the server
luisherranz Nov 14, 2023
0e6a178
Add the file and search blocks
luisherranz Nov 14, 2023
211d1d5
Move $version out of $args to match wp_register_script
luisherranz Nov 15, 2023
400afda
Improve version logic
luisherranz Nov 15, 2023
87809c5
Add polyfill
luisherranz Nov 17, 2023
43ff14a
Fix $version using its own arg in register calls
luisherranz Nov 20, 2023
6d8d965
Add unit tests
cbravobernal Nov 27, 2023
823fcfa
Refactor tests, add test get import map
cbravobernal Nov 27, 2023
81c014e
Cleaning data
cbravobernal Nov 27, 2023
5488eab
Use gutenberg_url()
luisherranz Nov 28, 2023
4e6c5da
Use wp_print_script_tag
luisherranz Nov 28, 2023
829c6ec
Fix DocBlock on get_import_map()
luisherranz Nov 28, 2023
77cd95e
Merge branch 'trunk' into experiment/modules-and-import-maps-api-requ…
luisherranz Nov 28, 2023
366ad42
Load navigation module only on Gutenberg plugin
luisherranz Nov 28, 2023
4e7a3ef
Load query module only on Gutenberg plugin
luisherranz Nov 28, 2023
3e8d5fd
Load search module only on Gutenberg plugin
luisherranz Nov 28, 2023
46c9a65
Load file module only on Gutenberg plugin
luisherranz Nov 28, 2023
9f185d8
Load image module only on Gutenberg plugin
luisherranz Nov 28, 2023
df56463
Make registration optional
luisherranz Nov 28, 2023
0c6237a
Improve navigation logic
luisherranz Nov 28, 2023
2a2eeda
Remove unnecessary check
luisherranz Nov 28, 2023
5926282
Fix missing view file
luisherranz Nov 28, 2023
6b932fe
Don't print the import map if it's empty
luisherranz Nov 28, 2023
1b176d0
Load the importmap polyfill locally
luisherranz Nov 28, 2023
b627d73
Move the es-modules-shims package to the top
luisherranz Nov 28, 2023
0affd41
Use the public functions in the tests
luisherranz Nov 28, 2023
3cd253a
Update test to be more output oriented
cbravobernal Nov 29, 2023
148f1dd
Remove we from comments.
cbravobernal Nov 29, 2023
4135f22
Merge branch 'trunk' into experiment/modules-and-import-maps-api-requ…
luisherranz Nov 29, 2023
876fdb1
Start using modules in the interactivity e2e tests
luisherranz Nov 29, 2023
88fcee8
Update package-lock.json
luisherranz Nov 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
Prev Previous commit
Next Next commit
Load query module only on Gutenberg plugin
  • Loading branch information
luisherranz committed Nov 28, 2023
commit 4e7a3ef6fd4c83947cf481f18db0ee72eaf6a7bd
3 changes: 2 additions & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"layout": true
},
"editorStyle": "wp-block-query-editor",
"style": "wp-block-query"
"style": "wp-block-query",
"viewScript": "file:./view.min.js"
}
29 changes: 26 additions & 3 deletions packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
function render_block_core_query( $attributes, $content, $block ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
gutenberg_enqueue_module( '@wordpress/block-library/query' );

$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag() ) {
// Add the necessary directives.
Expand Down Expand Up @@ -69,6 +67,31 @@ class="wp-block-query__enhanced-pagination-animation"
}
}

$is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
$should_load_view_script = $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
$view_asset = 'wp-block-query-view';
$script_handles = $block->block_type->view_script_handles;

if ( $is_gutenberg_plugin ) {
if ( $should_load_view_script ) {
gutenberg_enqueue_module( '@wordpress/block-library/query' );
}
// Remove the view script because we are using the module.
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
} else {
if ( ! wp_script_is( $view_asset ) ) {
// 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_asset, $script_handles, true )
) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
}
// If the script is needed, but it was previously removed, add it again.
if ( $should_load_view_script && ! in_array( $view_asset, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
}
}
}

$style_asset = 'wp-block-query';
if ( ! wp_style_is( $style_asset ) ) {
$style_handles = $block->block_type->style_handles;
Expand Down Expand Up @@ -120,7 +143,7 @@ function register_block_core_query() {

gutenberg_register_module(
'@wordpress/block-library/query',
gutenberg_url( '/build/interactivity/query.min.js' ),
'/wp-content/plugins/gutenberg/build/interactivity/query.min.js',
array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
Expand Down