Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/moose 66 update post content selector #117

Merged
merged 14 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions wp-content/plugins/core/src/Blocks/Blocks_Definer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use DI;
use Tribe\Libs\Container\Definer_Interface;
use Tribe\Plugin\Blocks\Filters\Contracts\Filter_Factory;
use Tribe\Plugin\Blocks\Filters\List_Filter;
use Tribe\Plugin\Blocks\Filters\Paragraph_Filter;
use Tribe\Theme\blocks\core\button\Button;
use Tribe\Theme\blocks\core\column\Column;
use Tribe\Theme\blocks\core\columns\Columns;
Expand Down Expand Up @@ -70,6 +72,8 @@ public function define(): array {
] ),

self::FILTERS => DI\add( [
DI\get( Paragraph_Filter::class ),
DI\get( List_Filter::class ),
] ),

Filter_Factory::class => DI\autowire()->constructorParameter( 'filters', DI\get( self::FILTERS ) ),
Expand Down
8 changes: 4 additions & 4 deletions wp-content/plugins/core/src/Blocks/Blocks_Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function register(): void {
/**
* Filter block content using the render_block filter
*/
add_filter( 'render_block', function ( string $block_content, array $block ): string {
$filter = $this->container->get( Filter_Factory::class )->make( $block );
add_filter( 'render_block', function ( string $block_content, array $parsed_block, object $block ): string {
$filter = $this->container->get( Filter_Factory::class )->make( $parsed_block );

return $filter ? $filter->filter_block_content( $block_content, $block ) : $block_content;
}, 10, 2 );
return $filter ? $filter->filter_block_content( $block_content, $parsed_block, $block ) : $block_content;
}, 10, 3 );

/**
* Disable default WP block patterns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ abstract class Block_Content_Filter {

public const BLOCK = '';

abstract public function filter_block_content( string $block_content, array $block ): string;
abstract public function filter_block_content( string $block_content, array $parsed_block, object $block ): string;

}
18 changes: 18 additions & 0 deletions wp-content/plugins/core/src/Blocks/Filters/List_Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Blocks\Filters;

use Tribe\Plugin\Blocks\Filters\Contracts\Block_Content_Filter;
use Tribe\Plugin\Blocks\Filters\Traits\Add_Block_Default_Class_Name;

class List_Filter extends Block_Content_Filter {

use Add_Block_Default_Class_Name;

public const BLOCK = 'core/list';

public function filter_block_content( string $block_content, array $parsed_block, object $block ): string {
return $this->add_class_name( $block_content, $parsed_block, $block );
}

}
18 changes: 18 additions & 0 deletions wp-content/plugins/core/src/Blocks/Filters/Paragraph_Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Blocks\Filters;

use Tribe\Plugin\Blocks\Filters\Contracts\Block_Content_Filter;
use Tribe\Plugin\Blocks\Filters\Traits\Add_Block_Default_Class_Name;

class Paragraph_Filter extends Block_Content_Filter {

use Add_Block_Default_Class_Name;

public const BLOCK = 'core/paragraph';

public function filter_block_content( string $block_content, array $parsed_block, object $block ): string {
return $this->add_class_name( $block_content, $parsed_block, $block );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Blocks\Filters\Traits;

trait Add_Block_Default_Class_Name {

/**
* Ensures there's a `wp-block-<block name>` CSS class rendered for the specific blocks mentioned above.
*
* This filter is a polyfill for core blocks that don't render their own CSS class name.
* Without the class name on the block, CSS styling becomes much more problematic.
*
* Eventually WP Core should handle this for us and we can remove this filter.
*
* Related outstanding issues in Gutenberg:
* * https://github.com/WordPress/gutenberg/pull/42269
* * https://github.com/WordPress/gutenberg/issues/50486
* * https://github.com/WordPress/gutenberg/pull/47282
*
* @param string $block_content Rendered block content.
* @param array $parsed_block The block being rendered.
* @param object $block Block object.
*
* @return string Updated block content.
*/
public function add_class_name( string $block_content, array $parsed_block, object $block ): string {
if ( ! $block_content ) {
return $block_content;
}

if ( ! $block->block_type || $block->block_type->is_dynamic() ) {
return $block_content;
}

$tags = new \WP_HTML_Tag_Processor( $block_content );
if ( $tags->next_tag() ) {
$tags->add_class( wp_get_block_default_classname( $block->name ) );
}

return $tags->get_updated_html();
}

}
4 changes: 2 additions & 2 deletions wp-content/themes/core/assets/pcss/cards/_utilities.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
display: block;
padding: 0;

:where(.wp-site-blocks) & {
:where(.wp-block-post-content) & {
position: absolute;
background: transparent;
color: transparent;
Expand Down Expand Up @@ -74,7 +74,7 @@
}

/* this needs to be specific to override global focus visible styles */
:where(.wp-site-blocks) :not(.wp-element-button) & {
:where(.wp-block-post-content) :not(.wp-element-button) & {

&:focus-visible {

Expand Down
1 change: 0 additions & 1 deletion wp-content/themes/core/assets/pcss/editor.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@import "layout/default.pcss";
@import "global/reset.pcss";
@import "typography/anchors.pcss";
@import "typography/blockquote.pcss";

/* Patterns */
@import "cards/post.pcss";
Expand Down
9 changes: 9 additions & 0 deletions wp-content/themes/core/assets/pcss/global/reset.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ select {
margin: 0;
}

/**
* TODO: Make sure this is desired.
* This only appears to affect the block editor; and in unintended ways.
* I *think* we want to set a global default focus-visible style for the
* frontend, but it should _not_ bleed into the admin/editor.
*/

/*
:where(.wp-site-blocks) *:focus-visible {

@mixin focus-visible;
}
*/
1 change: 0 additions & 1 deletion wp-content/themes/core/assets/pcss/theme.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@import "global/reset.pcss";
@import "layout/default.pcss";
@import "typography/anchors.pcss";
@import "typography/blockquote.pcss";
@import "global/stacking-order.pcss";

/* Patterns */
Expand Down
5 changes: 2 additions & 3 deletions wp-content/themes/core/assets/pcss/typography/anchors.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

a {

:where(.wp-site-blocks) &:not(.wp-element-button):focus-visible {
.wp-block-post-content &:not(.wp-element-button):focus-visible {

@mixin focus-visible-inline-text;
}
Expand All @@ -17,8 +17,7 @@ a {
* Note: Not in theme.json as the selector needs to be more specific
* ------------------------------------------------------------------------- */

:where(.wp-site-blocks) :where(p, li) &,
.editor-styles-wrapper :where(p, li) & {
.wp-block-post-content :where(p, li) & {

@mixin inline-text-link;
}
Expand Down
14 changes: 0 additions & 14 deletions wp-content/themes/core/assets/pcss/typography/blockquote.pcss

This file was deleted.

2 changes: 1 addition & 1 deletion wp-content/themes/core/blocks/core/heading/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Styles specific to this block
*/

:--heading:where(.wp-block-heading) {
:--heading.wp-block-heading {

/* CASE: Style X-Large */
&.is-style-x-large {
Expand Down
77 changes: 31 additions & 46 deletions wp-content/themes/core/blocks/core/lists/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,43 @@
* Styles specific to this block
*/

/* ----------------------------------------------------------------------
* Ordered List
*
* The first selector applies to the FE, the second in the editor.
* The list block is the only block on the FE that doesn't get a class,
* so we're able to apply a :not() selector for the class attribute.
* While both will apply in the editor, only the second will affect
* the actual list block.
* ---------------------------------------------------------------------- */

.wp-site-blocks ol:not([class]),
ol.wp-block-list {
padding-inline-start: 1.2rem;

& li {
padding-inline-start: 10px;
.wp-block-list {

&::marker {
font-weight: var(--font-weight-bold);
}
li ~ li {
margin-top: var(--spacer-30);
}

/* ----------------------------------------------------------------------
* CASE: Ordered List
* ---------------------------------------------------------------------- */

ol& {
padding-inline-start: 1.2rem;

li {
padding-inline-start: 10px;

& ~ li {
margin-top: var(--spacer-30);
&::marker {
font-weight: var(--font-weight-bold);
}
}
}
}

/* ----------------------------------------------------------------------
* Unordered List
*
* The first selector applies to the FE, the second in the editor.
* The list block is the only block on the FE that doesn't get a class,
* so we're able to apply a :not() selector for the class attribute.
* While both will apply in the editor, only the second will affect
* the actual list block.
* ---------------------------------------------------------------------- */

.wp-site-blocks ul:not([class]),
ul.wp-block-list {
padding-inline-start: 10px;

& li {
padding-inline-start: 1.3rem;
position: relative;

&::marker {
content: var(--icon-list-bullet);
transform: translateX(10px);
}
/* ----------------------------------------------------------------------
* CASE: Unordered List
* ---------------------------------------------------------------------- */

ul& {
padding-inline-start: 10px;

li {
padding-inline-start: 1.3rem;
position: relative;

& ~ li {
margin-top: var(--spacer-30);
&::marker {
content: var(--icon-list-bullet);
transform: translateX(10px);
}
Comment on lines +5 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpellenwood I'm getting some warnings in postcss when trying to use these styles due to the ul& and ol& not having a symbol to start:
postcss-nesting: Nested selectors must start with a symbol and "ul&" begins with a letter.

Copy link
Collaborator Author

@dpellenwood dpellenwood Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I know that this was a later change to the spec, but it is valid now. (The second code example under this heading.) I think your project may not be using the latest version of postcss-preset-env or similar. That selector doesn't cause any errors here on Moose.

}
}
}
3 changes: 1 addition & 2 deletions wp-content/themes/core/blocks/core/paragraph/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Styles specific to this block
*/

:where(.wp-site-blocks) p,
p.wp-block-paragraph {
.wp-block-paragraph {

/* CASE: Style Large */
&.is-style-large {
Expand Down
4 changes: 2 additions & 2 deletions wp-content/themes/core/blocks/core/posttemplate/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Vertical (list layout) post template spacing
*/
.wp-site-blocks .wp-block-post-template:not(.is-layout-grid) .wp-block-post + .wp-block-post {
.wp-block-post-content .wp-block-post-template:not(.is-layout-grid) .wp-block-post + .wp-block-post {
margin-block-start: var(--spacer-40);
}

Expand All @@ -17,7 +17,7 @@
* width. The calculations subtract an extra pixel due to calc not enjoying our
* use of clamped spacer variables.
*/
.wp-site-blocks .wp-block-post-template.is-layout-grid {
.wp-block-post-content .wp-block-post-template.is-layout-grid {
--post-template-grid-template-columns: 1fr;
gap: var(--spacer-40);
grid-template-columns: var(--post-template-grid-template-columns);
Expand Down
Loading