@@ -286,28 +286,33 @@ function get_legacy_widget_block_editor_settings() {
286286 * Collect the block editor assets that need to be loaded into the editor's iframe.
287287 *
288288 * @since 6.0.0
289+ * @since 7.0.0 Allow enqueuing script modules.
289290 * @access private
290291 *
291- * @global WP_Styles $wp_styles The WP_Styles current instance.
292- * @global WP_Scripts $wp_scripts The WP_Scripts current instance.
292+ * @global WP_Styles $wp_styles The WP_Styles current instance.
293+ * @global WP_Scripts $wp_scripts The WP_Scripts current instance.
294+ * @global WP_Script_Modules $wp_script_modules The WP_Script_Modules current instance.
293295 *
294296 * @return array {
295297 * The block editor assets.
296298 *
297- * @type string|false $styles String containing the HTML for styles.
298- * @type string|false $scripts String containing the HTML for scripts.
299+ * @type string|false $styles String containing the HTML for styles.
300+ * @type string|false $scripts String containing the HTML for scripts.
301+ * @type string|false $script_modules String containing the HTML for scripts.
299302 * }
300303 */
301304function _wp_get_iframed_editor_assets () {
302- global $ wp_styles , $ wp_scripts ;
305+ global $ wp_styles , $ wp_scripts, $ wp_script_modules ;
303306
304307 // Keep track of the styles and scripts instance to restore later.
305- $ current_wp_styles = $ wp_styles ;
306- $ current_wp_scripts = $ wp_scripts ;
308+ $ current_wp_styles = $ wp_styles ;
309+ $ current_wp_scripts = $ wp_scripts ;
310+ $ current_wp_script_modules = $ wp_script_modules ;
307311
308312 // Create new instances to collect the assets.
309313 $ wp_styles = new WP_Styles ();
310314 $ wp_scripts = new WP_Scripts ();
315+ $ wp_script_modules = $ wp_script_modules ->clone_without_enqueued_modules ();
311316
312317 /*
313318 * Register all currently registered styles and scripts. The actions that
@@ -379,13 +384,22 @@ function _wp_get_iframed_editor_assets() {
379384 wp_print_footer_scripts ();
380385 $ scripts = ob_get_clean ();
381386
387+ ob_start ();
388+ $ wp_script_modules ->print_import_map ();
389+ $ wp_script_modules ->print_head_enqueued_script_modules ();
390+ $ wp_script_modules ->print_enqueued_script_modules ();
391+ $ wp_script_modules ->print_script_module_preloads ();
392+ $ script_modules = ob_get_clean ();
393+
382394 // Restore the original instances.
383- $ wp_styles = $ current_wp_styles ;
384- $ wp_scripts = $ current_wp_scripts ;
395+ $ wp_styles = $ current_wp_styles ;
396+ $ wp_scripts = $ current_wp_scripts ;
397+ $ wp_script_modules = $ current_wp_script_modules ;
385398
386399 return array (
387- 'styles ' => $ styles ,
388- 'scripts ' => $ scripts ,
400+ 'styles ' => $ styles ,
401+ 'scripts ' => $ scripts ,
402+ 'script_modules ' => $ script_modules ,
389403 );
390404}
391405
0 commit comments