From 7c8779521f6ed7e40b102200b26ad334b34dc6c8 Mon Sep 17 00:00:00 2001 From: Stian Date: Wed, 16 Oct 2024 15:19:39 +0200 Subject: [PATCH 1/4] Use v3 --- packages/themes/block-theme/t2.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/themes/block-theme/t2.json b/packages/themes/block-theme/t2.json index 05c8404..bf20d3c 100644 --- a/packages/themes/block-theme/t2.json +++ b/packages/themes/block-theme/t2.json @@ -39,6 +39,6 @@ "t2/wrap-custom-html-block" ], "t2/custom-block-margin": { - "version": 2 + "version": "experimental_v3" } } From 96c2ee4ae69066a28bd9ffba12b59daccd7956d2 Mon Sep 17 00:00:00 2001 From: Stian Date: Wed, 16 Oct 2024 15:19:56 +0200 Subject: [PATCH 2/4] Remove v2 setup --- .../block-theme/includes/block-margin.php | 133 ------------------ packages/themes/block-theme/theme.json | 14 -- 2 files changed, 147 deletions(-) delete mode 100644 packages/themes/block-theme/includes/block-margin.php 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/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)", From 1a5e862431b2a8a61babcf1ab41c10a2796e1e7f Mon Sep 17 00:00:00 2001 From: Stian Date: Wed, 16 Oct 2024 15:24:28 +0200 Subject: [PATCH 3/4] Debug color for block containers --- packages/themes/block-theme/src/view.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/themes/block-theme/src/view.css b/packages/themes/block-theme/src/view.css index 5cdc88f..396d7dc 100644 --- a/packages/themes/block-theme/src/view.css +++ b/packages/themes/block-theme/src/view.css @@ -9,3 +9,5 @@ :where([hidden]) { display: none !important; } + +:root :where(.wp-site-blocks, .is-layout-constrained, .is-layout-flow, .is-layout-flex.is-vertical, .wp-block-media-text__content, .t2-accordion-item__inner-container, .t2-factbox__inner-container, .t2-faq-item__inner-container, .t2-infobox__content, .t2-simple-media-text__content-inner, .t2-tab-inner-content) { border: dashed thin #f00; } From 6d5ffdb38eb5fd777297663e483fc77403a4f90f Mon Sep 17 00:00:00 2001 From: Stian Date: Mon, 25 Nov 2024 12:35:18 +0100 Subject: [PATCH 4/4] Remove debug code --- packages/themes/block-theme/src/view.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/themes/block-theme/src/view.css b/packages/themes/block-theme/src/view.css index 396d7dc..5cdc88f 100644 --- a/packages/themes/block-theme/src/view.css +++ b/packages/themes/block-theme/src/view.css @@ -9,5 +9,3 @@ :where([hidden]) { display: none !important; } - -:root :where(.wp-site-blocks, .is-layout-constrained, .is-layout-flow, .is-layout-flex.is-vertical, .wp-block-media-text__content, .t2-accordion-item__inner-container, .t2-factbox__inner-container, .t2-faq-item__inner-container, .t2-infobox__content, .t2-simple-media-text__content-inner, .t2-tab-inner-content) { border: dashed thin #f00; }