| @@ -86,17 +86,26 @@ | ||
| 86 | 86 | } |
| 87 | 87 | add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 ); |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | - * Adds the 'editor' dependency to wp-block-library, required by the Classic block. | |
| 90 | + * Handle special case dependencies for wp-block-library that depend on runtime conditions. | |
| 91 | 91 | * |
| 92 | + * This adds the 'editor' dependency conditionally based on experiments and classic block requirements. | |
| 93 | + * All other script registrations are handled by the auto-generated build/scripts.php file. | |
| 94 | + * | |
| 92 | 95 | * @param WP_Scripts $scripts WP_Scripts instance. |
| 93 | 96 | */ |
| 94 | 97 | function gutenberg_register_block_library_script_special_case( $scripts ) { |
| 95 | 98 | $handle = 'wp-block-library'; |
| 96 | 99 | $script = $scripts->query( $handle, 'registered' ); |
| 97 | - if ( ! in_array( 'editor', $script->deps, true ) ) { | |
| 98 | - $script->deps[] = 'editor'; | |
| 100 | + if ( | |
| 101 | + ! gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) || | |
| 102 | + ! empty( $_GET['requiresTinymce'] ) || | |
| 103 | + gutenberg_post_being_edited_requires_classic_block() | |
| 104 | + ) { | |
| 105 | + if ( ! in_array( 'editor', $script->deps, true ) ) { | |
| 106 | + $script->deps[] = 'editor'; | |
| 107 | + } | |
| 99 | 108 | } |
| 100 | 109 | } |
| 101 | 110 | add_action( 'wp_default_scripts', 'gutenberg_register_block_library_script_special_case', 11 ); |
| 102 | 111 | |
| @@ -124,12 +133,10 @@ | ||
| 124 | 133 | // else (for development or test) default to use the current time. |
| 125 | 134 | $version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); |
| 126 | 135 | $suffix = SCRIPT_DEBUG ? '' : '.min'; |
| 127 | 136 | |
| 128 | - // wp-components: add dashicons (icon font dependency) and design tokens. | |
| 129 | - $components_style = $styles->query( 'wp-components', 'registered' ); | |
| 130 | - $components_style->deps[] = 'dashicons'; | |
| 131 | - $components_style->deps[] = 'wp-theme'; | |
| 137 | + // wp-components: add dashicons (icon font dependency) | |
| 138 | + $styles->query( 'wp-components', 'registered' )->deps[] = 'dashicons'; | |
| 132 | 139 | |
| 133 | 140 | // wp-edit-post: add wp-edit-blocks (custom handle not auto-inferred) |
| 134 | 141 | $styles->query( 'wp-edit-post', 'registered' )->deps[] = 'wp-edit-blocks'; |
| 135 | 142 | |
| @@ -144,19 +151,8 @@ | ||
| 144 | 151 | |
| 145 | 152 | // wp-customize-widgets: add wp-edit-blocks (custom handle not auto-inferred) |
| 146 | 153 | $styles->query( 'wp-customize-widgets', 'registered' )->deps[] = 'wp-edit-blocks'; |
| 147 | 154 | |
| 148 | - gutenberg_override_style( | |
| 149 | - $styles, | |
| 150 | - 'wp-theme', | |
| 151 | - gutenberg_url( 'build/styles/theme/design-tokens' . $suffix . '.css' ), | |
| 152 | - array(), | |
| 153 | - $version | |
| 154 | - ); | |
| 155 | - $styles->add_data( 'wp-theme', 'rtl', 'replace' ); | |
| 156 | - $styles->add_data( 'wp-theme', 'suffix', $suffix ); | |
| 157 | - $styles->add_data( 'wp-theme', 'path', gutenberg_dir_path() . 'build/styles/theme/design-tokens' . $suffix . '.css' ); | |
| 158 | - | |
| 159 | 155 | // Register wp-base-styles and add it to the already registered wp-admin stylesheet |
| 160 | 156 | gutenberg_override_style( |
| 161 | 157 | $styles, |
| 162 | 158 | 'wp-base-styles', |
| @@ -192,12 +188,8 @@ | ||
| 192 | 188 | $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ); |
| 193 | 189 | |
| 194 | 190 | // Only add CONTENT styles here that should be enqueued in the iframe! |
| 195 | 191 | $wp_edit_blocks_dependencies = array( |
| 196 | - // Design System tokens load first so the `:root` CSS custom | |
| 197 | - // properties are defined before any consuming stylesheet reads | |
| 198 | - // them inside the editor iframe. | |
| 199 | - 'wp-theme', | |
| 200 | 192 | 'wp-components', |
| 201 | 193 | // This need to be added before the block library styles, |
| 202 | 194 | // The block library styles override the "reset" styles. |
| 203 | 195 | 'wp-reset-editor-styles', |
| @@ -374,41 +366,34 @@ | ||
| 374 | 366 | * |
| 375 | 367 | * @param WP_Scripts $scripts WP_Scripts instance. |
| 376 | 368 | */ |
| 377 | 369 | function gutenberg_register_vendor_scripts( $scripts ) { |
| 378 | - $extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | |
| 379 | - $vendors_dir = gutenberg_dir_path() . 'build/scripts/vendors/'; | |
| 370 | + $extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | |
| 380 | 371 | |
| 381 | - // When the React 19 experiment is enabled, register React 19 vendor | |
| 382 | - // scripts under the `react`, `react-dom`, and `react-jsx-runtime` handles. | |
| 383 | - $use_react_19 = gutenberg_is_experiment_enabled( 'gutenberg-react-19' ); | |
| 372 | + gutenberg_override_script( | |
| 373 | + $scripts, | |
| 374 | + 'react', | |
| 375 | + gutenberg_url( 'build/scripts/vendors/react' . $extension ), | |
| 376 | + // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry` as a dependency to `react` when `SCRIPT_DEBUG` is true. | |
| 377 | + // We need to preserve that here. | |
| 378 | + SCRIPT_DEBUG ? array( 'wp-react-refresh-entry', 'wp-polyfill' ) : array( 'wp-polyfill' ), | |
| 379 | + '18' | |
| 380 | + ); | |
| 381 | + gutenberg_override_script( | |
| 382 | + $scripts, | |
| 383 | + 'react-dom', | |
| 384 | + gutenberg_url( 'build/scripts/vendors/react-dom' . $extension ), | |
| 385 | + array( 'react' ), | |
| 386 | + '18' | |
| 387 | + ); | |
| 384 | 388 | |
| 385 | - $vendor_handles = array( 'react', 'react-dom', 'react-jsx-runtime' ); | |
| 386 | - | |
| 387 | - foreach ( $vendor_handles as $handle ) { | |
| 388 | - $source = $use_react_19 ? $handle . '-19' : $handle; | |
| 389 | - $asset_file = $vendors_dir . $source . '.min.asset.php'; | |
| 390 | - $asset = file_exists( $asset_file ) ? require $asset_file : array(); | |
| 391 | - $dependencies = $asset['dependencies'] ?? array(); | |
| 392 | - $version = $asset['version'] ?? '0'; | |
| 393 | - | |
| 394 | - gutenberg_override_script( | |
| 395 | - $scripts, | |
| 396 | - $handle, | |
| 397 | - gutenberg_url( 'build/scripts/vendors/' . $source . $extension ), | |
| 398 | - $dependencies, | |
| 399 | - $version | |
| 400 | - ); | |
| 401 | - } | |
| 402 | - | |
| 403 | - // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry` | |
| 404 | - // as a dependency to `react` when `SCRIPT_DEBUG` is true. Preserve that here. | |
| 405 | - if ( SCRIPT_DEBUG ) { | |
| 406 | - $react = $scripts->query( 'react', 'registered' ); | |
| 407 | - if ( $react && ! in_array( 'wp-react-refresh-entry', $react->deps, true ) ) { | |
| 408 | - $react->deps[] = 'wp-react-refresh-entry'; | |
| 409 | - } | |
| 410 | - } | |
| 389 | + gutenberg_override_script( | |
| 390 | + $scripts, | |
| 391 | + 'react-jsx-runtime', | |
| 392 | + gutenberg_url( 'build/scripts/vendors/react-jsx-runtime' . $extension ), | |
| 393 | + array( 'react' ), | |
| 394 | + '18' | |
| 395 | + ); | |
| 411 | 396 | } |
| 412 | 397 | add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' ); |
| 413 | 398 | |
| 414 | 399 | /** |
| @@ -448,11 +433,8 @@ | ||
| 448 | 433 | // Enqueue stored styles. |
| 449 | 434 | add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_stored_styles' ); |
| 450 | 435 | add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 ); |
| 451 | 436 | |
| 452 | -/** | |
| 453 | - * Enqueues the LaTeX to MathML loader script module in the block editor. | |
| 454 | - */ | |
| 455 | 437 | add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_latex_to_mathml_loader' ); |
| 456 | 438 | function gutenberg_enqueue_latex_to_mathml_loader() { |
| 457 | 439 | wp_enqueue_script_module( '@wordpress/latex-to-mathml/loader' ); |
| 458 | 440 | } |
| @@ -470,20 +452,8 @@ | ||
| 470 | 452 | function gutenberg_enqueue_vips_loader() { |
| 471 | 453 | wp_enqueue_script_module( '@wordpress/vips/loader' ); |
| 472 | 454 | } |
| 473 | 455 | |
| 474 | -/** | |
| 475 | - * Enqueue the video-conversion loader script module in the block editor. | |
| 476 | - * | |
| 477 | - * This registers @wordpress/video-conversion/worker as a dynamic dependency | |
| 478 | - * in the import map, enabling on-demand loading of the WebCodecs-based | |
| 479 | - * GIF-to-video processing module when animated GIF conversion is triggered | |
| 480 | - * via @wordpress/upload-media. | |
| 481 | - * | |
| 482 | - * @see packages/video-conversion/src/loader.ts | |
| 483 | - */ | |
| 484 | -if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { | |
| 485 | - add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_video_conversion_loader' ); | |
| 486 | -} | |
| 487 | -function gutenberg_enqueue_video_conversion_loader() { | |
| 488 | - wp_enqueue_script_module( '@wordpress/video-conversion/loader' ); | |
| 456 | +add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_core_abilities' ); | |
| 457 | +function gutenberg_enqueue_core_abilities() { | |
| 458 | + wp_enqueue_script_module( '@wordpress/core-abilities' ); | |
| 489 | 459 | } |