Skip to content

Commit

Permalink
Cherry-picked commits for WordPress 6.4 RC3 (#55583)
Browse files Browse the repository at this point in the history
* Patterns: set context of pattern category api call to view so authors and contributors can access (#55553)

* Query Loop: Disallow "enhanced pagination" with core blocks that may contain third-party blocks (#55539)

* Update useContainsThirdPartyBlocks and texts

* Improve texts a bit

* Show the list of unsupported blocks

* Use the BlockTitle component instead

* Simplify modal text

* Revert "Query Loop: Disallow "enhanced pagination" with core blocks that may contain third-party blocks (#55539)"

This reverts commit f2dd6de.

* Query Loop: Disallow "enhanced pagination" with core blocks that may contain third-party blocks (#55539)

* Update useContainsThirdPartyBlocks and texts

* Improve texts a bit

* Show the list of unsupported blocks

* Use the BlockTitle component instead

* Simplify modal text

* Revert CSS changes to show/hide embedded pdf (#55667)

* Ensure Term Description block is available in core (#55669)

Reverts changes in #51053, to address a regression in which the Term Description block was only available in core when the Gutenberg plugin was active.

---------

Co-authored-by: Glen Davies <[email protected]>
Co-authored-by: David Arenas <[email protected]>
  • Loading branch information
3 people committed Oct 28, 2023
1 parent 2b32d59 commit f28647d
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 32 deletions.
1 change: 0 additions & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ Edit the different global regions of your site, like the header, footer, sidebar
Display the description of categories, tags and custom taxonomies when viewing an archive. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/term-description))

- **Name:** core/term-description
- **Experimental:** fse
- **Category:** theme
- **Supports:** align (full, wide), color (background, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** textAlign
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static function ( $matches ) {
$processor->next_tag();
$processor->set_attribute( 'data-wp-interactive', '' );
$processor->next_tag( 'object' );
$processor->set_attribute( 'data-wp-style--display', 'selectors.core.file.hasPdfPreview' );
$processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' );
$processor->set_attribute( 'hidden', true );
return $processor->get_updated_html();
}

Expand Down
6 changes: 0 additions & 6 deletions packages/block-library/src/file/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
margin-bottom: 1em;
}

@media (max-width: 768px) {
.wp-block-file__embed {
display: none;
}
}

//This needs a low specificity so it won't override the rules from the button element if defined in theme.json.
:where(.wp-block-file__button) {
border-radius: 2em;
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/file/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { store } from '@wordpress/interactivity';
/**
* Internal dependencies
*/
import { browserSupportsPdfs } from './utils';
import { browserSupportsPdfs as hasPdfPreview } from './utils';

store( {
selectors: {
core: {
file: {
hasPdfPreview: browserSupportsPdfs() ? 'inherit' : 'none',
hasPdfPreview,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { useState, useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useContainsThirdPartyBlocks } from '../utils';
import { useUnsupportedBlockList } from '../utils';

const disableEnhancedPaginationDescription = __(
'Plugin blocks are not supported yet. For the enhanced pagination to work, remove the plugin block, then re-enable "Enhanced pagination" in the Query Block settings.'
'You have added unsupported blocks. For the enhanced pagination to work, remove them, then re-enable "Enhanced pagination" in the Query Block settings.'
);

const modalDescriptionId =
Expand All @@ -28,11 +28,11 @@ export default function EnhancedPaginationModal( {
} ) {
const [ isOpen, setOpen ] = useState( false );

const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
const unsupported = useUnsupportedBlockList( clientId );

useEffect( () => {
setOpen( containsThirdPartyBlocks && enhancedPagination );
}, [ containsThirdPartyBlocks, enhancedPagination, setOpen ] );
setOpen( !! unsupported.length && enhancedPagination );
}, [ unsupported.length, enhancedPagination, setOpen ] );

return (
isOpen && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
*/
import { ToggleControl, Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { BlockTitle } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { useContainsThirdPartyBlocks } from '../../utils';
import { useUnsupportedBlockList } from '../../utils';

export default function EnhancedPaginationControl( {
enhancedPagination,
setAttributes,
clientId,
} ) {
const enhancedPaginationNotice = __(
"Enhanced pagination doesn't support plugin blocks yet. If you want to enable it, you have to remove all plugin blocks from the Query Loop."
);

const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
const unsupported = useUnsupportedBlockList( clientId );

return (
<>
Expand All @@ -28,20 +25,32 @@ export default function EnhancedPaginationControl( {
'Browsing between pages won’t require a full page reload.'
) }
checked={ !! enhancedPagination }
disabled={ containsThirdPartyBlocks }
disabled={ unsupported.length }
onChange={ ( value ) => {
setAttributes( {
enhancedPagination: !! value,
} );
} }
/>
{ containsThirdPartyBlocks && (
{ !! unsupported.length && (
<Notice
status="warning"
isDismissible={ false }
className="wp-block-query__enhanced-pagination-notice"
>
{ enhancedPaginationNotice }
{ __(
"Enhanced pagination doesn't support the following blocks:"
) }
<ul>
{ unsupported.map( ( id ) => (
<li key={ id }>
<BlockTitle clientId={ id } />
</li>
) ) }
</ul>
{ __(
'If you want to enable it, you have to remove all unsupported blocks first.'
) }
</Notice>
) }
</>
Expand Down
21 changes: 14 additions & 7 deletions packages/block-library/src/query/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,28 @@ export const usePatterns = ( clientId, name ) => {
};

/**
* Hook that returns whether the Query Loop with the given `clientId` contains
* any third-party block.
* Hook that returns a list of unsupported blocks inside the Query Loop with the
* given `clientId`.
*
* @param {string} clientId The block's client ID.
* @return {boolean} True if it contains third-party blocks.
* @return {string[]} List of block titles.
*/
export const useContainsThirdPartyBlocks = ( clientId ) => {
export const useUnsupportedBlockList = ( clientId ) => {
return useSelect(
( select ) => {
const { getClientIdsOfDescendants, getBlockName } =
select( blockEditorStore );

return getClientIdsOfDescendants( clientId ).some(
( descendantClientId ) =>
! getBlockName( descendantClientId ).startsWith( 'core/' )
return getClientIdsOfDescendants( clientId ).filter(
( descendantClientId ) => {
const blockName = getBlockName( descendantClientId );
return (
! blockName.startsWith( 'core/' ) ||
blockName === 'core/post-content' ||
blockName === 'core/template-part' ||
blockName === 'core/block'
);
}
);
},
[ clientId ]
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/term-description/block.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"__experimental": "fse",
"name": "core/term-description",
"title": "Term Description",
"category": "theme",
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ export const getUserPatternCategories =
{
per_page: -1,
_fields: 'id,name,description,slug',
context: 'view',
}
);

Expand Down

0 comments on commit f28647d

Please sign in to comment.