Skip to content

Commit

Permalink
prep build 1/13
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Jan 13, 2025
2 parents e2a4f11 + 0c42f22 commit df10db4
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 233 deletions.
2 changes: 2 additions & 0 deletions bin/generate-gutenberg-php.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
/**
* Prints `define` statements for the production version of `gutenberg.php`
* (the plugin entry point).
*
* @global string $plugin_version The version number of the plugin.
*/
function print_production_defines() {
global $plugin_version;
Expand Down
2 changes: 2 additions & 0 deletions lib/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

/**
* Redirects the demo page to edit a new post.
*
* @global string $pagenow The name of the current admin page being viewed.
*/
function gutenberg_redirect_demo() {
global $pagenow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
background: none;
border: 0;
text-align: left;
transition: box-shadow 0.1s linear;

@media not (prefers-reduced-motion) {
transition: box-shadow 0.1s linear;
}

// The item contains absolutely positioned items.
// Set `position: relative` on the parent to prevent overflow issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ function BackgroundImageControls( {
label={ imgLabel }
/>
}
variant="secondary"
renderToggle={ ( props ) => (
<Button { ...props } __next40pxDefaultSize />
) }
Expand Down
52 changes: 40 additions & 12 deletions packages/block-editor/src/components/block-rename/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,44 @@ import {
import { __, sprintf } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { speak } from '@wordpress/a11y';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { useBlockDisplayInformation } from '..';
import isEmptyString from './is-empty-string';

export default function BlockRenameModal( {
blockName,
originalBlockName,
onClose,
onSave,
export default function BlockRenameModal( { clientId, onClose } ) {
const [ editedBlockName, setEditedBlockName ] = useState();

const blockInformation = useBlockDisplayInformation( clientId );
const { metadata } = useSelect(
( select ) => {
const { getBlockAttributes } = select( blockEditorStore );

return {
metadata: getBlockAttributes( clientId )?.metadata,
};
},
[ clientId ]
);
const { updateBlockAttributes } = useDispatch( blockEditorStore );

const blockName = metadata?.name || '';
const originalBlockName = blockInformation?.title;
// Pattern Overrides is a WordPress-only feature but it also uses the Block Binding API.
// Ideally this should not be inside the block editor package, but we keep it here for simplicity.
hasOverridesWarning,
} ) {
const [ editedBlockName, setEditedBlockName ] = useState( blockName );
const hasOverridesWarning =
!! blockName &&
!! metadata?.bindings &&
Object.values( metadata.bindings ).some(
( binding ) => binding.source === 'core/pattern-overrides'
);

const nameHasChanged = editedBlockName !== blockName;
const nameHasChanged =
editedBlockName !== undefined && editedBlockName !== blockName;
const nameIsOriginal = editedBlockName === originalBlockName;
const nameIsEmpty = isEmptyString( editedBlockName );

Expand All @@ -37,6 +57,8 @@ export default function BlockRenameModal( {
const autoSelectInputText = ( event ) => event.target.select();

const handleSubmit = () => {
const newName =
nameIsOriginal || nameIsEmpty ? undefined : editedBlockName;
const message =
nameIsOriginal || nameIsEmpty
? sprintf(
Expand All @@ -52,7 +74,12 @@ export default function BlockRenameModal( {

// Must be assertive to immediately announce change.
speak( message, 'assertive' );
onSave( editedBlockName );
updateBlockAttributes( [ clientId ], {
metadata: {
...metadata,
name: newName,
},
} );

// Immediate close avoids ability to hit save multiple times.
onClose();
Expand Down Expand Up @@ -81,7 +108,7 @@ export default function BlockRenameModal( {
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
value={ editedBlockName }
value={ editedBlockName ?? blockName }
label={ __( 'Name' ) }
help={
hasOverridesWarning
Expand All @@ -105,7 +132,8 @@ export default function BlockRenameModal( {

<Button
__next40pxDefaultSize
aria-disabled={ ! isNameValid }
accessibleWhenDisabled
disabled={ ! isNameValid }
variant="primary"
type="submit"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,17 @@
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { useBlockDisplayInformation } from '..';
import isEmptyString from './is-empty-string';
import BlockRenameModal from './modal';

export default function BlockRenameControl( { clientId } ) {
const [ renamingBlock, setRenamingBlock ] = useState( false );

const { metadata } = useSelect(
( select ) => {
const { getBlockAttributes } = select( blockEditorStore );

const _metadata = getBlockAttributes( clientId )?.metadata;
return {
metadata: _metadata,
};
},
[ clientId ]
);

const { updateBlockAttributes } = useDispatch( blockEditorStore );

const customName = metadata?.name;
const hasPatternOverrides =
!! customName &&
!! metadata?.bindings &&
Object.values( metadata.bindings ).some(
( binding ) => binding.source === 'core/pattern-overrides'
);

function onChange( newName ) {
updateBlockAttributes( [ clientId ], {
metadata: {
...metadata,
name: newName,
},
} );
}

const blockInformation = useBlockDisplayInformation( clientId );

return (
<>
<MenuItem
Expand All @@ -63,23 +26,8 @@ export default function BlockRenameControl( { clientId } ) {
</MenuItem>
{ renamingBlock && (
<BlockRenameModal
blockName={ customName || '' }
originalBlockName={ blockInformation?.title }
hasOverridesWarning={ hasPatternOverrides }
clientId={ clientId }
onClose={ () => setRenamingBlock( false ) }
onSave={ ( newName ) => {
// If the new value is the block's original name (e.g. `Group`)
// or it is an empty string then assume the intent is to reset
// the value. Therefore reset the metadata.
if (
newName === blockInformation?.title ||
isEmptyString( newName )
) {
newName = undefined;
}

onChange( newName );
} }
/>
) }
</>
Expand Down
20 changes: 20 additions & 0 deletions packages/block-library/src/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
import { __ } from '@wordpress/i18n';
import { navigation as icon } from '@wordpress/icons';
import { select } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,6 +55,23 @@ export const settings = {
},
edit,
save,
__experimentalLabel: ( { ref } ) => {
if ( ! ref ) {
return;
}

const navigation = select( coreStore ).getEditedEntityRecord(
'postType',
'wp_navigation',
ref
);

if ( ! navigation?.title ) {
return;
}

return decodeEntities( navigation.title );
},
deprecated,
};

Expand Down
68 changes: 53 additions & 15 deletions packages/block-library/src/post-author-name/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ import {
import { useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
import { PanelBody, ToggleControl } from '@wordpress/components';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

function PostAuthorNameEdit( {
context: { postType, postId },
Expand Down Expand Up @@ -61,6 +70,8 @@ function PostAuthorNameEdit( {
displayName
);

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
<>
<BlockControls group="block">
Expand All @@ -72,26 +83,53 @@ function PostAuthorNameEdit( {
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
isLink: false,
linkTarget: '_self',
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
label={ __( 'Link to author archive' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
isShownByDefault
hasValue={ () => isLink }
onDeselect={ () => setAttributes( { isLink: false } ) }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
label={ __( 'Link to author archive' ) }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ linkTarget === '_blank' }
checked={ isLink }
/>
</ToolsPanelItem>
{ isLink && (
<ToolsPanelItem
label={ __( 'Open in new tab' ) }
isShownByDefault
hasValue={ () => linkTarget !== '_self' }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
<div { ...blockProps }>
{ supportsAuthor
Expand Down
Loading

0 comments on commit df10db4

Please sign in to comment.