diff --git a/packages/themes/block-theme/includes/block-margin.php b/packages/themes/block-theme/includes/block-margin.php deleted file mode 100644 index 6b85c6b..0000000 --- a/packages/themes/block-theme/includes/block-margin.php +++ /dev/null @@ -1,133 +0,0 @@ - '80' ); -\add_filter( 't2/custom_block_margin/last/size_key', fn() => '80' ); -\add_filter( 'render_block', __NAMESPACE__ . '\\do_add_block_spacing_support_to_additional_containers' ); - -/** - * Change the root selector to all contrained containers. - * - * @param string $root_selector Root selector. - * @param boolean $is_editor Is editor. - * @return string - */ -function do_override_root_selector( string $root_selector, bool $is_editor ): string { - return $is_editor ? ':is(.block-editor-writing-flow, body)' : 'body'; -} - -/** - * Overide the last selector to include .entry-content blocks only. - * - * @return array - */ -function do_override_last_selectors(): array { - return [ - // Only non-alignfull last child in entry content container. - 'body .entry-content.is-layout-constrained > :last-child:not(.alignfull)', - ]; -} - -/** - * Override T2 Custom Block Margin Config. - * - * @param array $config Config. - * @param string $root_selector Root selector. - * @return array - */ -function do_override_custom_block_margin_config( array $config, $root_selector ): array { - // Simplify root selector to include only containers supported by Block Spacing API. - $config['selector'] = "{$root_selector} :is( - .wp-site-blocks, - .is-layout-flow, - .is-layout-flex.is-vertical, - .is-layout-constrained, - )"; - - $config['gaps'] = [ - '00' => [ - 'selectors' => [ - // First child in any container. - ':first-child', - - // Trailing full size Groups and Covers. - '.wp-block-group.alignfull + .wp-block-group.alignfull', - '.wp-block-cover.alignfull + .wp-block-cover.alignfull', - - // Spacer blocks. - '.wp-block-spacer', - '.wp-block-spacer + *', - '.wp-block-t2-spacer', - '.wp-block-t2-spacer + *', - ], - ], - '20' => [ - 'selectors' => [], - ], - '30' => [ - 'selectors' => [], - ], - '40' => [ - 'selectors' => [], - ], - '50' => [ // Medium. - 'selectors' => [ - // Small block spacing for related blocks, e.g. paragraph + paragraph or heading + paragraph. - ':is(p, .wp-block-list, .wp-block-heading, .wp-block-post-title, summary) + :is(p, .wp-block-list)', - ], - ], - '60' => [ - 'selectors' => [], - ], - '70' => [ - 'selectors' => [], - ], - '80' => [ // Default. - 'selectors' => [], - ], - ]; - - return $config; -} - -/** - * Override block rendering and add .is-layout-flow to selected containers to support Block Spacing API. - * - * @param string $block_content Block content. - * @return string - */ -function do_add_block_spacing_support_to_additional_containers( string $block_content ): string { - $containers = [ - 'wp-block-media-text__content', - 't2-simple-media-text__content-inner', - 't2-accordion-item__inner-container', - 't2-factbox__inner-container', - 't2-infobox__content', - 't2-faq-item__inner-container', - ]; - - foreach ( $containers as $container ) { - if ( \str_contains( $block_content, $container ) ) { - $processor = new \WP_HTML_Tag_Processor( $block_content ); - $processor->next_tag( [ 'class_name' => $container ] ); - $processor->add_class( 'is-layout-flow' ); - - $block_content = $processor->get_updated_html(); - } - } - - return $block_content; -} diff --git a/packages/themes/block-theme/t2.json b/packages/themes/block-theme/t2.json index f9a6542..da1b646 100644 --- a/packages/themes/block-theme/t2.json +++ b/packages/themes/block-theme/t2.json @@ -36,6 +36,6 @@ "t2/wrap-custom-html-block" ], "t2/custom-block-margin": { - "version": 2 + "version": "experimental_v3" } } diff --git a/packages/themes/block-theme/theme.json b/packages/themes/block-theme/theme.json index aa8685c..204fdb3 100644 --- a/packages/themes/block-theme/theme.json +++ b/packages/themes/block-theme/theme.json @@ -40,20 +40,6 @@ "12": 1.2, "15": 1.5 }, - "t2/custom-block-margin": { - "spacing": { - "00": "0", - "20": "var(--wp--preset--spacing--20)", - "30": "var(--wp--preset--spacing--30)", - "40": "var(--wp--preset--spacing--40)", - "50": "var(--wp--preset--spacing--50)", - "60": "var(--wp--preset--spacing--60)", - "70": "var(--wp--preset--spacing--70)", - "80": "var(--wp--preset--spacing--80)", - "default": "var(--wp--preset--spacing--80)", - "last": "var(--wp--preset--spacing--80)" - } - }, "t2/featured-content-layout": { "spacing": { "rowGap": "var(--wp--preset--spacing--50)",