<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56046] trunk: Editor: add box shadow support to blocks.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56046">56046</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56046","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>isabel_brison</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-26 23:42:16 +0000 (Mon, 26 Jun 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: add box shadow support to blocks.

Adds the ability for blocks to declare support for CSS box-shadow and processing of necessary styles.

Props madhudollu, sabernhardt, ramonopoly, spacedmonkey, mukesh27.
Fixes <a href="https://core.trac.wordpress.org/ticket/58590">#58590</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesksesphp">trunk/src/wp-includes/kses.php</a></li>
<li><a href="#trunksrcwpincludesstyleengineclasswpstyleenginephp">trunk/src/wp-includes/style-engine/class-wp-style-engine.php</a></li>
<li><a href="#trunksrcwpsettingsphp">trunk/src/wp-settings.php</a></li>
<li><a href="#trunktestsphpunittestsstyleenginestyleEnginephp">trunk/tests/phpunit/tests/style-engine/styleEngine.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportsshadowphp">trunk/src/wp-includes/block-supports/shadow.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportsshadowphp">trunk/tests/phpunit/tests/block-supports/shadow.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportsshadowphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/block-supports/shadow.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/shadow.php                           (rev 0)
+++ trunk/src/wp-includes/block-supports/shadow.php     2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,82 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Shadow block support flag.
+ *
+ * @package WordPress
+ * @since 6.3.0
+ */
+
+/**
+ * Registers the style and shadow block attributes for block types that support it.
+ *
+ * @since 6.3.0
+ * @access private
+ *
+ * @param WP_Block_Type $block_type Block Type.
+ */
+function wp_register_shadow_support( $block_type ) {
+       $has_shadow_support = block_has_support( $block_type, array( 'shadow' ), false );
+
+       if ( ! $has_shadow_support ) {
+               return;
+       }
+
+       if ( ! $block_type->attributes ) {
+               $block_type->attributes = array();
+       }
+
+       if ( array_key_exists( 'style', $block_type->attributes ) ) {
+               $block_type->attributes['style'] = array(
+                       'type' => 'object',
+               );
+       }
+
+       if ( array_key_exists( 'shadow', $block_type->attributes ) ) {
+               $block_type->attributes['shadow'] = array(
+                       'type' => 'string',
+               );
+       }
+}
+
+/**
+ * Add CSS classes and inline styles for shadow features to the incoming attributes array.
+ * This will be applied to the block markup in the front-end.
+ *
+ * @since 6.3.0
+ * @access private
+ *
+ * @param  WP_Block_Type $block_type       Block type.
+ * @param  array         $block_attributes Block attributes.
+ * @return array Shadow CSS classes and inline styles.
+ */
+function wp_apply_shadow_support( $block_type, $block_attributes ) {
+       $has_shadow_support = block_has_support( $block_type, array( 'shadow' ), false );
+
+       if ( ! $has_shadow_support ) {
+               return array();
+       }
+
+       $shadow_block_styles = array();
+
+       $preset_shadow                 = array_key_exists( 'shadow', $block_attributes ) ? "var:preset|shadow|{$block_attributes['shadow']}" : null;
+       $custom_shadow                 = isset( $block_attributes['style']['shadow'] ) ? $block_attributes['style']['shadow'] : null;
+       $shadow_block_styles['shadow'] = $preset_shadow ? $preset_shadow : $custom_shadow;
+
+       $attributes = array();
+       $styles     = wp_style_engine_get_styles( $shadow_block_styles );
+
+       if ( ! empty( $styles['css'] ) ) {
+               $attributes['style'] = $styles['css'];
+       }
+
+       return $attributes;
+}
+
+// Register the block support.
+WP_Block_Supports::get_instance()->register(
+       'shadow',
+       array(
+               'register_attribute' => 'wp_register_shadow_support',
+               'apply'              => 'wp_apply_shadow_support',
+       )
+);
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/block-supports/shadow.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcwpincludesksesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/kses.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/kses.php    2023-06-26 21:31:30 UTC (rev 56045)
+++ trunk/src/wp-includes/kses.php      2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2280,6 +2280,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.2.0 Added support for `aspect-ratio`, `position`, `top`, `right`, `bottom`, `left`,
</span><span class="cx" style="display: block; padding: 0 10px">  *              and `z-index` CSS properties.
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.3.0 Extended support for `filter` to accept a URL and added support for repeat().
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *              Added support for `box-shadow`.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $css        A string of CSS rules.
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $deprecated Not used.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2447,6 +2448,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'bottom',
</span><span class="cx" style="display: block; padding: 0 10px">                        'left',
</span><span class="cx" style="display: block; padding: 0 10px">                        'z-index',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'box-shadow',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'aspect-ratio',
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Custom CSS properties.
</span></span></pre></div>
<a id="trunksrcwpincludesstyleengineclasswpstyleenginephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/style-engine/class-wp-style-engine.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/style-engine/class-wp-style-engine.php      2023-06-26 21:31:30 UTC (rev 56045)
+++ trunk/src/wp-includes/style-engine/class-wp-style-engine.php        2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -148,6 +148,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'shadow'     => array(
+                       'shadow' => array(
+                               'property_keys' => array(
+                                       'default' => 'box-shadow',
+                               ),
+                               'path'          => array( 'shadow' ),
+                               'css_vars'      => array(
+                                       'shadow' => '--wp--preset--shadow--$slug',
+                               ),
+                       ),
+               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 'dimensions' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'minHeight' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'property_keys' => array(
</span></span></pre></div>
<a id="trunksrcwpsettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-settings.php 2023-06-26 21:31:30 UTC (rev 56045)
+++ trunk/src/wp-settings.php   2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -331,6 +331,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/custom-classname.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/dimensions.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/duotone.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require ABSPATH . WPINC . '/block-supports/shadow.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/elements.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/generated-classname.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/layout.php';
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportsshadowphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/block-supports/shadow.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/shadow.php                               (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/shadow.php 2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,89 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * @group block-supports
+ *
+ * @covers ::wp_apply_shadow_support
+ */
+class Test_Block_Supports_Shadow extends WP_UnitTestCase {
+       /**
+        * @var string|null
+        */
+       private $test_block_name;
+
+       public function set_up() {
+               parent::set_up();
+               $this->test_block_name = null;
+       }
+
+       public function tear_down() {
+               unregister_block_type( $this->test_block_name );
+               $this->test_block_name = null;
+               parent::set_up();
+       }
+
+       /**
+        * @ticket 58590
+        */
+       public function test_shadow_style_is_applied() {
+               $this->test_block_name = 'test/shadow-style-is-applied';
+               register_block_type(
+                       $this->test_block_name,
+                       array(
+                               'api_version' => 3,
+                               'attributes'  => array(
+                                       'style' => array(
+                                               'type' => 'object',
+                                       ),
+                               ),
+                               'supports'    => array(
+                                       'shadow' => true,
+                               ),
+                       )
+               );
+               $registry   = WP_Block_Type_Registry::get_instance();
+               $block_type = $registry->get_registered( $this->test_block_name );
+               $block_atts = array(
+                       'style' => array(
+                               'shadow' => '60px -16px teal',
+                       ),
+               );
+
+               $actual   = wp_apply_shadow_support( $block_type, $block_atts );
+               $expected = array(
+                       'style' => 'box-shadow:60px -16px teal;',
+               );
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       /**
+        * @ticket 58590
+        */
+       public function test_shadow_without_block_supports() {
+               $this->test_block_name = 'test/shadow-with-skipped-serialization-block-supports';
+               register_block_type(
+                       $this->test_block_name,
+                       array(
+                               'api_version' => 2,
+                               'attributes'  => array(
+                                       'style' => array(
+                                               'type' => 'object',
+                                       ),
+                               ),
+                               'supports'    => array(),
+                       )
+               );
+               $registry   = WP_Block_Type_Registry::get_instance();
+               $block_type = $registry->get_registered( $this->test_block_name );
+               $block_atts = array(
+                       'style' => array(
+                               'shadow' => '60px -16px teal',
+                       ),
+               );
+
+               $actual   = wp_apply_spacing_support( $block_type, $block_atts );
+               $expected = array();
+
+               $this->assertSame( $expected, $actual );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/shadow.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestsstyleenginestyleEnginephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/style-engine/styleEngine.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/style-engine/styleEngine.php    2023-06-26 21:31:30 UTC (rev 56045)
+++ trunk/tests/phpunit/tests/style-engine/styleEngine.php      2023-06-26 23:42:16 UTC (rev 56046)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,6 +26,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56467
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58549
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 58590
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers ::wp_style_engine_get_styles
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -182,6 +183,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'inline_valid_shadow_style'                    => array(
+                               'block_styles'    => array(
+                                       'shadow' => 'inset 5em 1em gold',
+                               ),
+                               'options'         => null,
+                               'expected_output' => array(
+                                       'css'          => 'box-shadow:inset 5em 1em gold;',
+                                       'declarations' => array(
+                                               'box-shadow' => 'inset 5em 1em gold',
+                                       ),
+                               ),
+                       ),
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         'inline_valid_typography_style'                => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'block_styles'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'typography' => array(
</span></span></pre>
</div>
</div>

</body>
</html>