-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add Interactivity API support #451
base: main
Are you sure you want to change the base?
Conversation
@parthnvaswani Can you look into why the PHP Unit test is failing? Also, add title of adding support for Interactivity API. |
@rtCamp/team-sys We are facing an issue with the PHP Unit test, it is failing because of this issue https://github.com/rtCamp/theme-elementary/actions/runs/9960495534/job/27712384396#step:6:58
I am adding an error log here as well. |
eb25c11
to
f2334bf
Compare
The |
const { getAsBooleanFromENV } = require( '@wordpress/scripts/utils' ); | ||
|
||
const hasExperimentalModulesFlag = getAsBooleanFromENV( 'WP_EXPERIMENTAL_MODULES' ); | ||
let scriptConfig, moduleConfig; | ||
|
||
if ( hasExperimentalModulesFlag ) { | ||
[ scriptConfig, moduleConfig ] = require( '@wordpress/scripts/config/webpack.config' ); | ||
} else { | ||
scriptConfig = require( '@wordpress/scripts/config/webpack.config' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { getAsBooleanFromENV } = require( '@wordpress/scripts/utils' ); | |
const hasExperimentalModulesFlag = getAsBooleanFromENV( 'WP_EXPERIMENTAL_MODULES' ); | |
let scriptConfig, moduleConfig; | |
if ( hasExperimentalModulesFlag ) { | |
[ scriptConfig, moduleConfig ] = require( '@wordpress/scripts/config/webpack.config' ); | |
} else { | |
scriptConfig = require( '@wordpress/scripts/config/webpack.config' ); | |
} | |
const [ scriptConfig, moduleConfig ] = require( '@wordpress/scripts/config/webpack.config' ); |
Since you have already enabled the experimental modules in the build script, there is no need to re-determine the logic in the webpack configuration. The getAsBooleanFromENV('WP_EXPERIMENTAL_MODULES')
function will always return true in this context.
let moduleScripts = {}; | ||
if ( hasExperimentalModulesFlag ) { | ||
moduleScripts = { | ||
...moduleConfig, | ||
entry: { | ||
'media-text-interactive': path.resolve( process.cwd(), 'assets', 'src', 'js', 'modules', 'media-text-interactive.js' ), | ||
}, | ||
output: { | ||
...moduleConfig.output, | ||
path: path.resolve( process.cwd(), 'assets', 'build', 'js', 'modules' ), | ||
filename: '[name].js', | ||
chunkFilename: '[name].js', | ||
}, | ||
}; | ||
} | ||
|
||
const customExports = [ scripts, styles ]; | ||
|
||
if ( hasExperimentalModulesFlag ) { | ||
customExports.push( moduleScripts ); | ||
} | ||
|
||
module.exports = customExports; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let moduleScripts = {}; | |
if ( hasExperimentalModulesFlag ) { | |
moduleScripts = { | |
...moduleConfig, | |
entry: { | |
'media-text-interactive': path.resolve( process.cwd(), 'assets', 'src', 'js', 'modules', 'media-text-interactive.js' ), | |
}, | |
output: { | |
...moduleConfig.output, | |
path: path.resolve( process.cwd(), 'assets', 'build', 'js', 'modules' ), | |
filename: '[name].js', | |
chunkFilename: '[name].js', | |
}, | |
}; | |
} | |
const customExports = [ scripts, styles ]; | |
if ( hasExperimentalModulesFlag ) { | |
customExports.push( moduleScripts ); | |
} | |
module.exports = customExports; | |
const mediaTextInteractiveModule = { | |
...moduleConfig, | |
entry: { | |
'media-text-interactive': path.resolve( process.cwd(), 'assets', 'src', 'js', 'modules', 'media-text-interactive.js' ), | |
}, | |
output: { | |
...moduleConfig.output, | |
path: path.resolve( process.cwd(), 'assets', 'build', 'js', 'modules' ), | |
filename: '[name].js', | |
chunkFilename: '[name].js', | |
}, | |
}; | |
module.exports = [ scripts, styles, mediaTextInteractiveModule ]; |
public function block_extensions() { | ||
|
||
Media_Text_Interactive::get_instance(); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function block_extensions() { | |
Media_Text_Interactive::get_instance(); | |
} | |
public function block_extensions() { | |
Media_Text_Interactive::get_instance(); | |
} |
Are these empty lines required here? I guess, it's due to the styling in this code?
protected function __construct() { | ||
|
||
$this->setup_hooks(); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function __construct() { | |
$this->setup_hooks(); | |
} | |
protected function __construct() { | |
$this->setup_hooks(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the file name can remain media-text
. Multiple core blocks use the interactivity API but do not suffix the block name to indicate the implementation details, such as using the interactivity API.
@parthnvaswani Please take a looks at the suggestions. |
To add support for interactive blocks I think only following things are needed,
Changes in webpack.config, other php classes etc are only to support custom modules, either for block independent functionality or for demonstration on core blocks. |
Description
This PR addresses the task of updating node packages and integrating support for JavaScript modules into the project. The focus is on enhancing theme scripts for the Interactivity API while ensuring compatibility with the latest dependencies, without breaking existing functionality.
Technical Details
package.json
to include the latest dependencies without affecting existing functionality.wp-script
dependency to version 27.6.0.@wordpress/interactivity
as a dependency.--experimental-modules
flag for compatibility with JavaScript modules.wp_enqueue_script_module
.modules
inassets/src/js
.modules
folder to demonstrate the implementation of JavaScript modules in the project.Checklist
package.json
to include the latest dependencies without breaking existing functionality.wp-script
dependency to version 27.6.0.@wordpress/interactivity
as a dependency.--experimental-modules
flag.wp_enqueue_script_module
.modules
inassets/src/js
.modules
folder.Screenshots/Recordings
Screen.Recording.2024-04-09.at.5.57.50.PM.mov
Fixes/Covers issue
Fixes #450