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

Create @wordpress/interactivity with the Interactivity API #50906

Merged
merged 42 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2efa328
Start with package.json and README
DAreRodz May 26, 2023
455396b
Add new package to docs/manifest.json
DAreRodz May 26, 2023
b48ac7c
Copy-paste runtime files from block-library
DAreRodz May 26, 2023
596e4da
Add .npmrc file
DAreRodz May 26, 2023
bbcd7fa
Add interactivity package to dependencies
DAreRodz May 26, 2023
b24a7fb
Create a custom webpack config for interactivity
DAreRodz May 26, 2023
97e0278
Expose interactivity runtime in `wp.interactivity`
DAreRodz May 26, 2023
59ba71b
Update package-lock
DAreRodz May 26, 2023
d80af2d
Add `@wordpress/interactivity` to block-library deps
DAreRodz May 26, 2023
43af7ab
Rename entry point to index
DAreRodz May 26, 2023
b19d9f5
Remove vendors chunk
DAreRodz May 26, 2023
e971cd6
Add oddly required aliases
DAreRodz May 26, 2023
02701e9
Add view prefix to interactivity.js files
DAreRodz May 26, 2023
22d7543
Use view-interactivity files when enabled
DAreRodz May 26, 2023
04bf309
Stop adding defer to Interactivity scripts
DAreRodz May 26, 2023
91e3fde
Remove webpack config for interactivity.js files
DAreRodz May 26, 2023
75159c4
Remove interactivity runtime from block-library
DAreRodz May 26, 2023
df8563b
Remove interactivity runtime from sideEffects
DAreRodz May 26, 2023
7b1953f
Undo temporary fix for Interactivity API in dependency-extraction-web…
DAreRodz May 26, 2023
8a10636
Remove script loader for Interactivity API runtime
DAreRodz May 26, 2023
ffa40e7
Remove block-librar/interactivity from build_files
DAreRodz May 26, 2023
ea033b1
Add src/index.js to Interactivity API entry file
DAreRodz May 26, 2023
d9561b8
Remove unnecessary aliases
DAreRodz May 26, 2023
bec4852
Restore data-wp-body directive
DAreRodz May 26, 2023
8cb572c
Interactivity API: add `wp_store` (#51191)
luisherranz Jun 2, 2023
1b7ed17
Rename syntax to -- and data-wp-interactive (#51241)
luisherranz Jun 6, 2023
66c4c58
Merge branch 'trunk' into interactivity
luisherranz Jun 6, 2023
e740fff
Interactivity API: initial support for SSR (#51229)
luisherranz Jun 6, 2023
2f86561
Merge branch 'trunk' into interactivity
DAreRodz Jun 15, 2023
3ac4a7b
Remove require for missing script-loader.php
DAreRodz Jun 15, 2023
db7686e
Merge branch 'trunk' into interactivity
luisherranz Jun 20, 2023
4b0b87a
Remove missing PHP file
luisherranz Jun 21, 2023
02a46bb
Rename view file and fix block.json
luisherranz Jun 21, 2023
3d1a1c4
Merge branch 'trunk' into interactivity
luisherranz Jun 21, 2023
294bf69
Add "interactivity" to supports and fix renaming
luisherranz Jun 21, 2023
1ed1e34
Merge branch 'trunk' into interactivity
luisherranz Jun 23, 2023
8758865
Code improvements for the SSR part of the Interactivity API (#51640)
DAreRodz Jun 23, 2023
c745063
Add the full Interactivity API runtime (but removing the client-side …
DAreRodz Jun 27, 2023
242a3ba
Merge branch 'trunk' into interactivity
luisherranz Jun 27, 2023
e409e41
Remove custom watchOptions in interactivity webpack config
DAreRodz Jun 28, 2023
2ad3cae
Update version and description of interactivity package
DAreRodz Jun 28, 2023
abf22e5
Merge branch 'trunk' into interactivity
luisherranz Jun 28, 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
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,12 @@
"markdown_source": "../packages/icons/README.md",
"parent": "packages"
},
{
"title": "@wordpress/interactivity",
"slug": "packages-interactivity",
"markdown_source": "../packages/interactivity/README.md",
"parent": "packages"
},
{
"title": "@wordpress/interface",
"slug": "packages-interface",
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/interactivity-api/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function gutenberg_block_update_interactive_view_script( $metadata ) {
in_array( $metadata['name'], array( 'core/file', 'core/navigation', 'core/image' ), true ) &&
str_contains( $metadata['file'], 'build/block-library/blocks' )
) {
$metadata['viewScript'] = array( 'file:./interactivity.min.js' );
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
}
return $metadata;
}
Expand Down
19 changes: 0 additions & 19 deletions lib/experimental/interactivity-api/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,3 @@ function gutenberg_register_interactivity_scripts( $scripts ) {
}
}
add_action( 'wp_default_scripts', 'gutenberg_register_interactivity_scripts', 10, 1 );

/**
* Adds the "defer" attribute to all the interactivity script tags.
*
* @param string $tag The generated script tag.
* @param string $handle The script handle.
*
* @return string The modified script tag.
*/
function gutenberg_interactivity_scripts_add_defer_attribute( $tag, $handle ) {
if ( str_starts_with( $handle, 'wp-interactivity-' ) || str_contains( $tag, '/interactivity.min.js' ) ) {
$p = new WP_HTML_Tag_Processor( $tag );
$p->next_tag( array( 'tag' => 'script' ) );
$p->set_attribute( 'defer', true );
return $p->get_updated_html();
}
return $tag;
}
add_filter( 'script_loader_tag', 'gutenberg_interactivity_scripts_add_defer_attribute', 10, 2 );
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@wordpress/html-entities": "file:packages/html-entities",
"@wordpress/i18n": "file:packages/i18n",
"@wordpress/icons": "file:packages/icons",
"@wordpress/interactivity": "file:packages/interactivity",
"@wordpress/interface": "file:packages/interface",
"@wordpress/is-shallow-equal": "file:packages/is-shallow-equal",
"@wordpress/keyboard-shortcuts": "file:packages/keyboard-shortcuts",
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"sideEffects": [
"build-style/**",
"src/**/*.scss",
"{src,build,build-module}/*/init.js",
"{src,build,build-module}/utils/interactivity/index.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same side effects weren't added to the new @wordpress/interactivity package. I might cause issues in the long run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Greg. Added to the roadmap 🙂👍

"{src,build,build-module}/*/init.js"
],
"dependencies": {
"@babel/runtime": "^7.16.0",
Expand All @@ -52,6 +51,7 @@
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/interactivity": "file:../interactivity",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/notices": "file:../notices",
"@wordpress/primitives": "file:../primitives",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* WordPress dependencies
*/
import { store } from '@wordpress/interactivity';
/**
* Internal dependencies
*/
import { store } from '../utils/interactivity';
import { browserSupportsPdfs as hasPdfPreview } from './utils';

store( {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
* Internal dependencies
* WordPress dependencies
*/
import { store } from '../utils/interactivity';
import { store } from '@wordpress/interactivity';

const focusableSelectors = [
'a[href]',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
* WordPress dependencies
*/
import { store } from '../utils/interactivity';
import { store } from '@wordpress/interactivity';

const focusableSelectors = [
'a[href]',
Expand Down
98 changes: 0 additions & 98 deletions packages/block-library/src/utils/interactivity/portals.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/dependency-extraction-webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DependencyExtractionWebpackPlugin {
combinedOutputFile: null,
externalizedReport: false,
injectPolyfill: false,
__experimentalInjectInteractivityRuntime: false,
outputFormat: 'php',
outputFilename: null,
useDefaults: true,
Expand Down Expand Up @@ -143,7 +142,6 @@ class DependencyExtractionWebpackPlugin {
combinedOutputFile,
externalizedReport,
injectPolyfill,
__experimentalInjectInteractivityRuntime,
outputFormat,
outputFilename,
} = this.options;
Expand Down Expand Up @@ -186,14 +184,6 @@ class DependencyExtractionWebpackPlugin {
if ( injectPolyfill ) {
chunkDeps.add( 'wp-polyfill' );
}
// Temporary fix for Interactivity API until it gets moved to its package.
if ( __experimentalInjectInteractivityRuntime ) {
if ( ! chunkJSFile.startsWith( './interactivity/' ) ) {
chunkDeps.add( 'wp-interactivity-runtime' );
} else if ( './interactivity/runtime.min.js' === chunkJSFile ) {
chunkDeps.add( 'wp-interactivity-vendors' );
}
}

const processModule = ( { userRequest } ) => {
if ( this.externalizedDeps.has( userRequest ) ) {
Expand Down
1 change: 1 addition & 0 deletions packages/interactivity/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 1 addition & 0 deletions packages/interactivity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Interactivity
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions packages/interactivity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@wordpress/interactivity",
"version": "0.1.0",
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
"description": "API for developing interactive blocks.",
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"gutenberg",
"interactivity"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/interactivity/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/interactivity"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/labels/%5BFeature%5D%20Interactivity%20API"
},
"engines": {
"node": ">=12"
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@preact/signals": "^1.1.3",
"deepsignal": "^1.3.0",
"preact": "^10.13.2"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
*/
import { useContext, useMemo, useEffect } from 'preact/hooks';
import { deepSignal, peek } from 'deepsignal';
/**
* Internal dependencies
*/
import { createPortal } from './portals.js';

/**
* Internal dependencies
Expand Down Expand Up @@ -57,16 +53,6 @@ export default () => {
{ priority: 5 }
);

// data-wp-body
directive( 'body', ( { props: { children }, context: inherited } ) => {
const { Provider } = inherited;
const inheritedValue = useContext( inherited );
return createPortal(
<Provider value={ inheritedValue }>{ children }</Provider>,
document.body
);
} );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the body directive being removed. I guess we've lost those changes somehow while moving the files to their own package. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemiomorales, could you please take a look at commit bec4852 and check if everything related to the data-wp-body directive is there? 🙏

There was a problem after rebasing this branch onto trunk, and some changes were lost.

// data-wp-effect.[name]
directive( 'effect', ( { directives: { effect }, context, evaluate } ) => {
const contextValue = useContext( context );
Expand Down
Loading