From d9a5a7c0892c239fe3088120d691ddd3573b6a31 Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 15 Mar 2024 18:04:09 +0300 Subject: [PATCH] added support for new Ghost Kit extensions --- .../boxes/supports-ghost-kit/index.js | 98 +++++++++++++++---- assets/editor/blocks/main/index.js | 2 - classes/class-blocks.php | 47 ++++----- 3 files changed, 102 insertions(+), 45 deletions(-) diff --git a/assets/editor-constructor/boxes/supports-ghost-kit/index.js b/assets/editor-constructor/boxes/supports-ghost-kit/index.js index d343073a9..22e69998b 100644 --- a/assets/editor-constructor/boxes/supports-ghost-kit/index.js +++ b/assets/editor-constructor/boxes/supports-ghost-kit/index.js @@ -3,6 +3,7 @@ * WordPress dependencies. */ import { __ } from '@wordpress/i18n'; +import { useEffect } from '@wordpress/element'; import { Notice, BaseControl, @@ -16,13 +17,29 @@ export default function SupportsGhostKitSettings(props) { const { supports_classname: supportsClassname, + supports_ghostkit_effects: supportsGktEffects, + supports_ghostkit_position: supportsGktPosition, supports_ghostkit_spacings: supportsGktSpacings, - supports_ghostkit_display: supportsGktDisplay, - supports_ghostkit_scroll_reveal: supportsGktScrollReveal, supports_ghostkit_frame: supportsGktFrame, + supports_ghostkit_transform: supportsGktTransform, supports_ghostkit_custom_css: supportsGktCustomCSS, + supports_ghostkit_display: supportsGktDisplay, + supports_ghostkit_attributes: supportsGktAttributes, + + // Deprecated. + supports_ghostkit_scroll_reveal: supportsGktScrollReveal, } = data; + // Migrate old attribute. + useEffect(() => { + if (typeof supportsGktScrollReveal !== 'undefined') { + updateData({ + supports_ghostkit_scroll_reveal: undefined, + supports_ghostkit_effects: supportsGktScrollReveal, + }); + } + }, [supportsGktScrollReveal, updateData]); + return ( <> {!window.GHOSTKIT ? ( @@ -50,10 +67,13 @@ export default function SupportsGhostKitSettings(props) { ) : null} - {(supportsGktSpacings || + {(supportsGktPosition || + supportsGktSpacings || supportsGktDisplay || supportsGktFrame || - supportsGktCustomCSS) && + supportsGktTransform || + supportsGktCustomCSS || + supportsGktAttributes) && !supportsClassname ? ( updateData({ - supports_ghostkit_spacings: value, - supports_classname: value || supportsClassname, + supports_ghostkit_effects: value, }) } /> updateData({ - supports_ghostkit_display: value, + supports_ghostkit_position: value, supports_classname: value || supportsClassname, }) } /> - updateData({ supports_ghostkit_scroll_reveal: value }) + updateData({ + supports_ghostkit_spacings: value, + supports_classname: value || supportsClassname, + }) } /> + + updateData({ + supports_ghostkit_transform: value, + supports_classname: value || supportsClassname, + }) + } + /> + + updateData({ + supports_ghostkit_display: value, + supports_classname: value || supportsClassname, + }) + } + /> + + updateData({ supports_ghostkit_attributes: value }) + } + /> ); } diff --git a/assets/editor/blocks/main/index.js b/assets/editor/blocks/main/index.js index dda785169..e96163bff 100644 --- a/assets/editor/blocks/main/index.js +++ b/assets/editor/blocks/main/index.js @@ -51,8 +51,6 @@ options.blocks.forEach((item) => { keywords: item.keywords, supports: item.supports, - ghostkit: item.ghostkit, - lazyblock: true, edit(props) { diff --git a/classes/class-blocks.php b/classes/class-blocks.php index 95d29ad7a..e4fd33fd8 100644 --- a/classes/class-blocks.php +++ b/classes/class-blocks.php @@ -954,6 +954,28 @@ public function marshal_block_data_with_controls( $id = null, $post_title = null $styles = (array) $get_meta_value( 'lazyblocks_styles' ); + // Prepare supports. + $supports = array( + 'customClassName' => $get_meta_value( 'lazyblocks_supports_classname' ), + 'anchor' => $get_meta_value( 'lazyblocks_supports_anchor' ), + 'html' => $get_meta_value( 'lazyblocks_supports_html' ), + 'multiple' => $get_meta_value( 'lazyblocks_supports_multiple' ), + 'inserter' => $get_meta_value( 'lazyblocks_supports_inserter' ), + 'reusable' => $get_meta_value( 'lazyblocks_supports_reusable' ), + 'lock' => $get_meta_value( 'lazyblocks_supports_lock' ), + 'align' => $align, + 'ghostkit' => array( + 'effects' => $get_meta_value( 'lazyblocks_supports_ghostkit_effects' ) || $get_meta_value( 'lazyblocks_supports_ghostkit_scroll_reveal' ) || false, + 'position' => $get_meta_value( 'lazyblocks_supports_ghostkit_position' ) || false, + 'spacings' => $get_meta_value( 'lazyblocks_supports_ghostkit_spacings' ) || false, + 'frame' => $get_meta_value( 'lazyblocks_supports_ghostkit_frame' ) || false, + 'transform' => $get_meta_value( 'lazyblocks_supports_ghostkit_transform' ) || false, + 'customCSS' => $get_meta_value( 'lazyblocks_supports_ghostkit_custom_css' ) || false, + 'display' => $get_meta_value( 'lazyblocks_supports_ghostkit_display' ) || false, + 'attributes' => $get_meta_value( 'lazyblocks_supports_ghostkit_attributes' ) || false, + ), + ); + return apply_filters( 'lzb/block_data', array( @@ -965,25 +987,7 @@ public function marshal_block_data_with_controls( $id = null, $post_title = null 'description' => $get_meta_value( 'lazyblocks_description' ), 'category' => $this->sanitize_slug( esc_html( $get_meta_value( 'lazyblocks_category' ) ) ), 'category_label' => esc_html( $get_meta_value( 'lazyblocks_category' ) ), - 'supports' => array( - 'customClassName' => $get_meta_value( 'lazyblocks_supports_classname' ), - 'anchor' => $get_meta_value( 'lazyblocks_supports_anchor' ), - 'html' => $get_meta_value( 'lazyblocks_supports_html' ), - 'multiple' => $get_meta_value( 'lazyblocks_supports_multiple' ), - 'inserter' => $get_meta_value( 'lazyblocks_supports_inserter' ), - 'reusable' => $get_meta_value( 'lazyblocks_supports_reusable' ), - 'lock' => $get_meta_value( 'lazyblocks_supports_lock' ), - 'align' => $align, - ), - 'ghostkit' => array( - 'supports' => array( - 'spacings' => $get_meta_value( 'lazyblocks_supports_ghostkit_spacings' ), - 'display' => $get_meta_value( 'lazyblocks_supports_ghostkit_display' ), - 'scrollReveal' => $get_meta_value( 'lazyblocks_supports_ghostkit_scroll_reveal' ), - 'frame' => $get_meta_value( 'lazyblocks_supports_ghostkit_frame' ), - 'customCSS' => $get_meta_value( 'lazyblocks_supports_ghostkit_custom_css' ), - ), - ), + 'supports' => $supports, 'controls' => $controls, 'code' => array( 'output_method' => $get_meta_value( 'lazyblocks_code_output_method' ), @@ -1406,6 +1410,7 @@ public function register_block_render() { $data = array( 'api_version' => 3, 'attributes' => $attributes, + 'supports' => $block['supports'], 'render_callback' => function( $render_attributes, $render_content = null ) { // Usually this context is used to properly preload content in the Pro plugin. $render_context = is_admin() ? 'editor' : 'frontend'; @@ -1603,10 +1608,6 @@ public function render_callback( $attributes, $content = null, $context = 'front $array_atts['id'] = esc_attr( $attributes['anchor'] ); } - if ( isset( $attributes['ghostkitSR'] ) && $attributes['ghostkitSR'] ) { - $array_atts['data-ghostkit-sr'] = esc_attr( $attributes['ghostkitSR'] ); - } - $html_atts = get_block_wrapper_attributes( $array_atts ); $result = '
' . $result . '
';