mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-03 20:24:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51259 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -42,12 +42,16 @@ function generate_block_asset_handle( $block_name, $field_name ) {
|
||||
if ( 0 === strpos( $field_name, 'editor' ) ) {
|
||||
$asset_handle .= '-editor';
|
||||
}
|
||||
if ( 0 === strpos( $field_name, 'view' ) ) {
|
||||
$asset_handle .= '-view';
|
||||
}
|
||||
return $asset_handle;
|
||||
}
|
||||
|
||||
$field_mappings = array(
|
||||
'editorScript' => 'editor-script',
|
||||
'script' => 'script',
|
||||
'viewScript' => 'view-script',
|
||||
'editorStyle' => 'editor-style',
|
||||
'style' => 'style',
|
||||
);
|
||||
@@ -96,18 +100,23 @@ function register_block_script_handle( $metadata, $field_name ) {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
$script_asset = require $script_asset_path;
|
||||
$result = wp_register_script(
|
||||
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC );
|
||||
$script_uri = $is_core_block ?
|
||||
includes_url( str_replace( ABSPATH . WPINC, '', realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ) ) :
|
||||
plugins_url( $script_path, $metadata['file'] );
|
||||
$script_asset = require $script_asset_path;
|
||||
$script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
|
||||
$result = wp_register_script(
|
||||
$script_handle,
|
||||
plugins_url( $script_path, $metadata['file'] ),
|
||||
$script_asset['dependencies'],
|
||||
$script_asset['version']
|
||||
$script_uri,
|
||||
$script_dependencies,
|
||||
isset( $script_asset['version'] ) ? $script_asset['version'] : false
|
||||
);
|
||||
if ( ! $result ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $metadata['textdomain'] ) ) {
|
||||
if ( ! empty( $metadata['textdomain'] ) && in_array( 'wp-i18n', $script_dependencies ) ) {
|
||||
wp_set_script_translations( $script_handle, $metadata['textdomain'] );
|
||||
}
|
||||
|
||||
@@ -306,6 +315,13 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $metadata['viewScript'] ) ) {
|
||||
$settings['view_script'] = register_block_script_handle(
|
||||
$metadata,
|
||||
'viewScript'
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $metadata['editorStyle'] ) ) {
|
||||
$settings['editor_style'] = register_block_style_handle(
|
||||
$metadata,
|
||||
|
||||
Reference in New Issue
Block a user