Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/font-weight-list
Browse files Browse the repository at this point in the history
  • Loading branch information
mikachan committed Jun 24, 2024
2 parents f0b23cf + db68ea4 commit a55bf4f
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 37 deletions.
11 changes: 9 additions & 2 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ export default function Image( {
</InspectorControls>
);

const arePatternOverridesEnabled =
metadata?.bindings?.__default?.source === 'core/pattern-overrides';

const {
lockUrlControls = false,
lockHrefControls = false,
Expand Down Expand Up @@ -470,7 +473,7 @@ export default function Image( {
lockHrefControls:
// Disable editing the link of the URL if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the link on the frontend.
hasParentPattern,
hasParentPattern || arePatternOverridesEnabled,
lockCaption:
// Disable editing the caption if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the caption on the frontend.
Expand Down Expand Up @@ -971,7 +974,11 @@ export default function Image( {
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={ isSingleSelected && hasNonContentControls }
showToolbarButton={
isSingleSelected &&
hasNonContentControls &&
! arePatternOverridesEnabled
}
readOnly={ lockCaption }
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function render_block_core_template_part( $attributes ) {
global $wp_embed;
$content = $wp_embed->autoembed( $content );

if ( empty( $attributes['tagName'] ) ) {
if ( empty( $attributes['tagName'] ) || tag_escape( $attributes['tagName'] ) !== $attributes['tagName'] ) {
$area_tag = 'div';
if ( $area_definition && isset( $area_definition['area_tag'] ) ) {
$area_tag = $area_definition['area_tag'];
Expand Down
8 changes: 8 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

## 4.44.0 (2024-06-15)

### Bug fix

- Pin the `@wordpress/scripts` version to a version supported by WordPress 6.5 ([#62234](https://github.com/WordPress/gutenberg/pull/62234)).

## 4.43.0 (2024-05-31)

## 4.42.0 (2024-05-16)

### Breaking Change

- Increase the minimum required Node.js version to v20.10.0 matching the support defined for Gutenberg and WordPress core ([#61430](https://github.com/WordPress/gutenberg/pull/61430)).

## 4.41.0 (2024-05-02)

## 4.40.0 (2024-04-19)
Expand Down
94 changes: 68 additions & 26 deletions packages/editor/src/components/post-actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,34 +307,29 @@ const trashPostAction = {
},
};

function useTrashPostAction( postType ) {
function useCanUserEligibilityCheckPostType( capability, resource, action ) {
const registry = useRegistry();
const { resource, cachedCanUserResolvers } = useSelect(
( select ) => {
const { getPostType, getCachedResolvers } = select( coreStore );
return {
resource: getPostType( postType )?.rest_base || '',
cachedCanUserResolvers: getCachedResolvers().canUser,
};
},
[ postType ]
);
return useMemo(
() => ( {
...trashPostAction,
...action,
isEligible( item ) {
return (
trashPostAction.isEligible( item ) &&
action.isEligible( item ) &&
registry
.select( coreStore )
.canUser( 'delete', resource, item.id )
.canUser( capability, resource, item.id )
);
},
} ),
// We are making this use memo depend on cachedCanUserResolvers as a way to make the component using this hook re-render
// when user capabilities are resolved. This makes sure the isEligible function is re-evaluated.
// eslint-disable-next-line react-hooks/exhaustive-deps
[ registry, resource, cachedCanUserResolvers ]
[ action, registry, capability, resource ]
);
}

function useTrashPostAction( resource ) {
return useCanUserEligibilityCheckPostType(
'delete',
resource,
trashPostAction
);
}

Expand Down Expand Up @@ -428,6 +423,14 @@ const permanentlyDeletePostAction = {
},
};

function usePermanentlyDeletePostAction( resource ) {
return useCanUserEligibilityCheckPostType(
'delete',
resource,
permanentlyDeletePostAction
);
}

const restorePostAction = {
id: 'restore',
label: __( 'Restore' ),
Expand Down Expand Up @@ -535,6 +538,14 @@ const restorePostAction = {
},
};

function useRestorePostAction( resource ) {
return useCanUserEligibilityCheckPostType(
'update',
resource,
restorePostAction
);
}

const viewPostAction = {
id: 'view-post',
label: __( 'View' ),
Expand Down Expand Up @@ -694,6 +705,14 @@ const renamePostAction = {
},
};

function useRenamePostAction( resource ) {
return useCanUserEligibilityCheckPostType(
'update',
resource,
renamePostAction
);
}

const useDuplicatePostAction = ( postType ) => {
const { userCanCreatePost } = useSelect(
( select ) => {
Expand Down Expand Up @@ -1038,23 +1057,36 @@ export const duplicateTemplatePartAction = {
};

export function usePostActions( { postType, onActionPerformed, context } ) {
const { defaultActions, postTypeObject, userCanCreatePostType } = useSelect(
const {
defaultActions,
postTypeObject,
userCanCreatePostType,
resource,
cachedCanUserResolvers,
} = useSelect(
( select ) => {
const { getPostType, canUser } = select( coreStore );
const { getPostType, canUser, getCachedResolvers } =
select( coreStore );
const { getEntityActions } = unlock( select( editorStore ) );
const _postTypeObject = getPostType( postType );
const resource = _postTypeObject?.rest_base || '';
const _resource = _postTypeObject?.rest_base || '';
return {
postTypeObject: _postTypeObject,
defaultActions: getEntityActions( 'postType', postType ),
userCanCreatePostType: canUser( 'create', resource ),
userCanCreatePostType: canUser( 'create', _resource ),
resource: _resource,
cachedCanUserResolvers: getCachedResolvers()?.canUser,
};
},
[ postType ]
);

const duplicatePostAction = useDuplicatePostAction( postType );
const trashPostActionForPostType = useTrashPostAction( postType );
const trashPostActionForPostType = useTrashPostAction( resource );
const permanentlyDeletePostActionForPostType =
usePermanentlyDeletePostAction( resource );
const renamePostActionForPostType = useRenamePostAction( resource );
const restorePostActionForPostType = useRestorePostAction( resource );
const isTemplateOrTemplatePart = [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
Expand All @@ -1080,13 +1112,16 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
userCanCreatePostType &&
duplicateTemplatePartAction,
isPattern && userCanCreatePostType && duplicatePatternAction,
supportsTitle && renamePostAction,
supportsTitle && renamePostActionForPostType,
isPattern && exportPatternAsJSONAction,
isTemplateOrTemplatePart ? resetTemplateAction : restorePostAction,
isTemplateOrTemplatePart
? resetTemplateAction
: restorePostActionForPostType,
isTemplateOrTemplatePart || isPattern
? deletePostAction
: trashPostActionForPostType,
! isTemplateOrTemplatePart && permanentlyDeletePostAction,
! isTemplateOrTemplatePart &&
permanentlyDeletePostActionForPostType,
...defaultActions,
].filter( Boolean );
// Filter actions based on provided context. If not provided
Expand Down Expand Up @@ -1144,6 +1179,9 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
}

return actions;
// We are making this use memo depend on cachedCanUserResolvers as a way to make the component using this hook re-render
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
defaultActions,
userCanCreatePostType,
Expand All @@ -1152,10 +1190,14 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
postTypeObject?.viewable,
duplicatePostAction,
trashPostActionForPostType,
restorePostActionForPostType,
renamePostActionForPostType,
permanentlyDeletePostActionForPostType,
onActionPerformed,
isLoaded,
supportsRevisions,
supportsTitle,
context,
cachedCanUserResolvers,
] );
}
5 changes: 2 additions & 3 deletions packages/editor/src/hooks/pattern-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const {
*/
const withPatternOverrideControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const isSupportedBlock = Object.keys(
PARTIAL_SYNCING_SUPPORTED_BLOCKS
).includes( props.name );
const isSupportedBlock =
!! PARTIAL_SYNCING_SUPPORTED_BLOCKS[ props.name ];

return (
<>
Expand Down
24 changes: 20 additions & 4 deletions packages/patterns/src/components/pattern-overrides-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ function addBindings( bindings ) {
};
}

function PatternOverridesControls( { attributes, setAttributes } ) {
function PatternOverridesControls( {
attributes,
setAttributes,
name: blockName,
} ) {
const controlId = useId();
const [ showAllowOverridesModal, setShowAllowOverridesModal ] =
useState( false );
Expand Down Expand Up @@ -71,15 +75,25 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
return null;
}

const hasUnsupportedImageAttributes =
blockName === 'core/image' &&
( !! attributes.caption?.length || !! attributes.href?.length );

const helpText = hasUnsupportedImageAttributes
? __(
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
)
: __(
'Allow changes to this block throughout instances of this pattern.'
);

return (
<>
<InspectorControls group="advanced">
<BaseControl
id={ controlId }
label={ __( 'Overrides' ) }
help={ __(
'Allow changes to this block throughout instances of this pattern.'
) }
help={ helpText }
>
<Button
__next40pxDefaultSize
Expand All @@ -93,6 +107,8 @@ function PatternOverridesControls( { attributes, setAttributes } ) {
setShowAllowOverridesModal( true );
}
} }
disabled={ hasUnsupportedImageAttributes }
__experimentalIsFocusable
>
{ allowOverrides
? __( 'Disable overrides' )
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test.describe( 'Pages', () => {
await admin.visitSiteEditor();
} );

test( 'create a new page, edit template and toggle page template preview', async ( {
test.skip( 'create a new page, edit template and toggle page template preview', async ( {
page,
editor,
} ) => {
Expand Down

0 comments on commit a55bf4f

Please sign in to comment.