Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:WordPress/gutenberg into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsilverstein committed Jan 13, 2025
2 parents 714fa5a + aa38b22 commit a1d3fc1
Show file tree
Hide file tree
Showing 24 changed files with 388 additions and 310 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: 1 addition & 1 deletion docs/how-to-guides/feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if ( globalThis.IS_GUTENBERG_PLUGIN ) {

```js
if ( true ) {
// Wepack has replaced `globalThis.IS_GUTENBERG_PLUGIN` with `true`
// Webpack has replaced `globalThis.IS_GUTENBERG_PLUGIN` with `true`
pluginOnlyFeature();
}
```
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.7/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function gutenberg_bootstrap_server_block_bindings_sources() {
/**
* Initialize `canUpdateBlockBindings` editor setting if it doesn't exist. By default, it is `true` only for admin users.
*
* @param array $settings The block editor settings from the `block_editor_settings_all` filter.
* @param array $editor_settings The block editor settings from the `block_editor_settings_all` filter.
* @return array The editor settings including `canUpdateBlockBindings`.
*/
function gutenberg_add_can_update_block_bindings_editor_setting( $editor_settings ) {
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
4 changes: 3 additions & 1 deletion packages/block-directory/src/store/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ export const getDownloadableBlocks =
);

dispatch( receiveDownloadableBlocks( blocks, filterValue ) );
} catch {}
} catch {
dispatch( receiveDownloadableBlocks( [], filterValue ) );
}
};
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
32 changes: 10 additions & 22 deletions packages/block-library/src/details/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import {
RichText,
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
InspectorControls,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import {
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -30,30 +29,17 @@ const TEMPLATE = [
],
];

function DetailsEdit( { attributes, setAttributes, clientId } ) {
function DetailsEdit( { attributes, setAttributes } ) {
const { showContent, summary, allowedBlocks } = attributes;
const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps( blockProps, {
template: TEMPLATE,
__experimentalCaptureToolbars: true,
allowedBlocks,
} );
const [ isOpen, setIsOpen ] = useState( showContent );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

// Check if either the block or the inner blocks are selected.
const hasSelection = useSelect(
( select ) => {
const { isBlockSelected, hasSelectedInnerBlock } =
select( blockEditorStore );
/* Sets deep to true to also find blocks inside the details content block. */
return (
hasSelectedInnerBlock( clientId, true ) ||
isBlockSelected( clientId )
);
},
[ clientId ]
);

return (
<>
<InspectorControls>
Expand Down Expand Up @@ -89,11 +75,13 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) {
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
<details
{ ...innerBlocksProps }
open={ hasSelection || showContent }
>
<summary onClick={ ( event ) => event.preventDefault() }>
<details { ...innerBlocksProps } open={ isOpen }>
<summary
onClick={ ( event ) => {
event.preventDefault();
setIsOpen( ! isOpen );
} }
>
<RichText
identifier="summary"
aria-label={ __( 'Write summary' ) }
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
Loading

0 comments on commit a1d3fc1

Please sign in to comment.