Make WordPress Core


Ignore:
Timestamp:
06/29/2021 03:08:16 PM (4 years ago)
Author:
youknowriad
Message:

Build: Split packages and blocks to their webpack configs.

This also adds support for the viewScript for blocks fixing
the PDF preview for file blocks.

Props desrosj, gziolo.
See #53397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r51255 r51259  
    4343            $asset_handle .= '-editor';
    4444        }
     45        if ( 0 === strpos( $field_name, 'view' ) ) {
     46            $asset_handle .= '-view';
     47        }
    4548        return $asset_handle;
    4649    }
     
    4952        'editorScript' => 'editor-script',
    5053        'script'       => 'script',
     54        'viewScript'   => 'view-script',
    5155        'editorStyle'  => 'editor-style',
    5256        'style'        => 'style',
     
    97101        return false;
    98102    }
    99     $script_asset = require $script_asset_path;
    100     $result       = wp_register_script(
     103    $is_core_block       = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
     104    $script_uri          = $is_core_block ?
     105        includes_url( str_replace( ABSPATH . WPINC, '', realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ) ) :
     106        plugins_url( $script_path, $metadata['file'] );
     107    $script_asset        = require $script_asset_path;
     108    $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
     109    $result              = wp_register_script(
    101110        $script_handle,
    102         plugins_url( $script_path, $metadata['file'] ),
    103         $script_asset['dependencies'],
    104         $script_asset['version']
     111        $script_uri,
     112        $script_dependencies,
     113        isset( $script_asset['version'] ) ? $script_asset['version'] : false
    105114    );
    106115    if ( ! $result ) {
     
    108117    }
    109118
    110     if ( ! empty( $metadata['textdomain'] ) ) {
     119    if ( ! empty( $metadata['textdomain'] ) && in_array( 'wp-i18n', $script_dependencies ) ) {
    111120        wp_set_script_translations( $script_handle, $metadata['textdomain'] );
    112121    }
     
    307316    }
    308317
     318    if ( ! empty( $metadata['viewScript'] ) ) {
     319        $settings['view_script'] = register_block_script_handle(
     320            $metadata,
     321            'viewScript'
     322        );
     323    }
     324
    309325    if ( ! empty( $metadata['editorStyle'] ) ) {
    310326        $settings['editor_style'] = register_block_style_handle(
Note: See TracChangeset for help on using the changeset viewer.