mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-08 06:34:34 +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,
|
||||
|
||||
@@ -156,7 +156,7 @@ class WP_Block_Type {
|
||||
public $provides_context = null;
|
||||
|
||||
/**
|
||||
* Block type editor script handle.
|
||||
* Block type editor only script handle.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var string|null
|
||||
@@ -164,7 +164,7 @@ class WP_Block_Type {
|
||||
public $editor_script = null;
|
||||
|
||||
/**
|
||||
* Block type front end script handle.
|
||||
* Block type front end and editor script handle.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var string|null
|
||||
@@ -172,7 +172,15 @@ class WP_Block_Type {
|
||||
public $script = null;
|
||||
|
||||
/**
|
||||
* Block type editor style handle.
|
||||
* Block type front end only script handle.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var string|null
|
||||
*/
|
||||
public $view_script = null;
|
||||
|
||||
/**
|
||||
* Block type editor only style handle.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var string|null
|
||||
@@ -180,7 +188,7 @@ class WP_Block_Type {
|
||||
public $editor_style = null;
|
||||
|
||||
/**
|
||||
* Block type front end style handle.
|
||||
* Block type front end and editor style handle.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var string|null
|
||||
@@ -225,10 +233,11 @@ class WP_Block_Type {
|
||||
* @type array|null $attributes Block type attributes property schemas.
|
||||
* @type array $uses_context Context values inherited by blocks of this type.
|
||||
* @type array|null $provides_context Context provided by blocks of this type.
|
||||
* @type string|null $editor_script Block type editor script handle.
|
||||
* @type string|null $script Block type front end script handle.
|
||||
* @type string|null $editor_style Block type editor style handle.
|
||||
* @type string|null $style Block type front end style handle.
|
||||
* @type string|null $editor_script Block type editor only script handle.
|
||||
* @type string|null $script Block type front end and editor script handle.
|
||||
* @type string|null $view_script Block type front end only script handle.
|
||||
* @type string|null $editor_style Block type editor only style handle.
|
||||
* @type string|null $style Block type front end and editor style handle.
|
||||
* }
|
||||
*/
|
||||
public function __construct( $block_type, $args = array() ) {
|
||||
|
||||
Reference in New Issue
Block a user