From a49344372a24af21b9a111a8346f37ae620a3533 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 25 Jan 2022 16:35:25 -0600 Subject: [PATCH] Try rendering SVGs from server --- lib/full-site-editing/edit-site-page.php | 10 + packages/block-editor/src/hooks/duotone.js | 174 +++++++----------- .../block-editor/resizable-editor.js | 6 +- .../editor/global-styles-renderer.js | 3 +- .../global-styles/use-global-styles-output.js | 34 +--- .../src/components/global-styles/utils.js | 1 - 6 files changed, 79 insertions(+), 149 deletions(-) diff --git a/lib/full-site-editing/edit-site-page.php b/lib/full-site-editing/edit-site-page.php index 076beff97f12d6..3418054f12b9aa 100644 --- a/lib/full-site-editing/edit-site-page.php +++ b/lib/full-site-editing/edit-site-page.php @@ -165,6 +165,16 @@ static function( $classes ) { ) ); + add_action( + 'admin_head', + function() { + $filters = wp_get_global_styles_svg_filters(); + if ( ! empty( $filters ) ) { + printf( '', wp_json_encode( $filters ) ); + } + } + ); + wp_add_inline_script( 'wp-blocks', sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ), diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index dafd92020da377..13de8f2a4d79ac 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -60,109 +60,82 @@ export function getValuesFromColors( colors = [] ) { */ /** - * Stylesheet for rendering the duotone filter. + * SVG and stylesheet needed for rendering the duotone filter. * * @param {Object} props Duotone props. * @param {string} props.selector Selector to apply the filter to. * @param {string} props.id Unique id for this duotone filter. + * @param {Values} props.values R, G, B, and A values to filter with. * * @return {WPElement} Duotone element. */ -function DuotoneStylesheet( { selector, id } ) { - const css = ` +function DuotoneFilter( { selector, id, values } ) { + const stylesheet = ` ${ selector } { filter: url( #${ id } ); } `; - return ; -} -/** - * SVG for rendering the duotone filter. - * - * @param {Object} props Duotone props. - * @param {string} props.id Unique id for this duotone filter. - * @param {Values} props.values R, G, B, and A values to filter with. - * - * @return {WPElement} Duotone element. - */ -function DuotoneFilter( { id, values } ) { return ( - - - - - - - - + + + + - + + + + + + - - - - - - ); -} - -/** - * SVG and stylesheet needed for rendering the duotone filter. - * - * @param {Object} props Duotone props. - * @param {string} props.selector Selector to apply the filter to. - * @param {string} props.id Unique id for this duotone filter. - * @param {Values} props.values R, G, B, and A values to filter with. - * - * @return {WPElement} Duotone element. - */ -function InlineDuotone( { selector, id, values } ) { - return ( - <> - - + + + +