Skip to content

Commit

Permalink
prep build 11/26
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Nov 26, 2023
2 parents 81e7669 + 4a244f6 commit c31e55d
Show file tree
Hide file tree
Showing 67 changed files with 1,002 additions and 996 deletions.
6 changes: 2 additions & 4 deletions docs/reference-guides/data/data-core-edit-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ _Returns_

### hasPageContentFocus

Whether or not the editor allows only page content to be edited.

_Parameters_
> **Deprecated**
- _state_ `Object`: Global application state.
Whether or not the editor allows only page content to be edited.

_Returns_

Expand Down
25 changes: 25 additions & 0 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ _Related_

- getPreviousBlockClientId in core/block-editor store.

### getRenderingMode

Returns the post editor's rendering mode.

_Parameters_

- _state_ `Object`: Editor state.

_Returns_

- `string`: Rendering mode.

### getSelectedBlock

_Related_
Expand Down Expand Up @@ -1241,6 +1253,19 @@ _Related_

- selectBlock in core/block-editor store.

### setRenderingMode

Returns an action used to set the rendering mode of the post editor. We support multiple rendering modes:

- `all`: This is the default mode. It renders the post editor with all the features available. If a template is provided, it's preferred over the post.
- `template-only`: This mode renders the editor with only the template blocks visible.
- `post-only`: This mode extracts the post blocks from the template and renders only those. The idea is to allow the user to edit the post/page in isolation without the wrapping template.
- `template-locked`: This mode renders both the template and the post blocks but the template blocks are locked and can't be edited. The post blocks are editable.

_Parameters_

- _mode_ `string`: Mode (one of 'template-only', 'post-only', 'template-locked' or 'all').

### setTemplateValidity

_Related_
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/block-editor/src/components/block-rename/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as BlockRenameControl } from './rename-control';
export { default as BlockRenameModal } from './modal';
export { default as useBlockRename } from './use-block-rename';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isEmptyString( testString ) {
return testString?.trim()?.length === 0;
}
115 changes: 115 additions & 0 deletions packages/block-editor/src/components/block-rename/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* WordPress dependencies
*/
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Button,
TextControl,
Modal,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { speak } from '@wordpress/a11y';

/**
* Internal dependencies
*/
import isEmptyString from './is-empty-string';

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

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

const isNameValid = nameHasChanged || nameIsOriginal;

const autoSelectInputText = ( event ) => event.target.select();

const dialogDescription = useInstanceId(
BlockRenameModal,
`block-editor-rename-modal__description`
);

const handleSubmit = () => {
const message =
nameIsOriginal || nameIsEmpty
? sprintf(
/* translators: %s: new name/label for the block */
__( 'Block name reset to: "%s".' ),
editedBlockName
)
: sprintf(
/* translators: %s: new name/label for the block */
__( 'Block name changed to: "%s".' ),
editedBlockName
);

// Must be assertive to immediately announce change.
speak( message, 'assertive' );
onSave( editedBlockName );

// Immediate close avoids ability to hit save multiple times.
onClose();
};

return (
<Modal
title={ __( 'Rename' ) }
onRequestClose={ onClose }
overlayClassName="block-editor-block-rename-modal"
aria={ {
describedby: dialogDescription,
} }
focusOnMount="firstContentElement"
>
<p id={ dialogDescription }>
{ __( 'Enter a custom name for this block.' ) }
</p>
<form
onSubmit={ ( e ) => {
e.preventDefault();

if ( ! isNameValid ) {
return;
}

handleSubmit();
} }
>
<VStack spacing="3">
<TextControl
__nextHasNoMarginBottom
value={ editedBlockName }
label={ __( 'Block name' ) }
hideLabelFromVision={ true }
placeholder={ originalBlockName }
onChange={ setEditedBlockName }
onFocus={ autoSelectInputText }
/>
<HStack justify="right">
<Button variant="tertiary" onClick={ onClose }>
{ __( 'Cancel' ) }
</Button>

<Button
aria-disabled={ ! isNameValid }
variant="primary"
type="submit"
>
{ __( 'Save' ) }
</Button>
</HStack>
</VStack>
</form>
</Modal>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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;

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

const blockInformation = useBlockDisplayInformation( clientId );

return (
<>
<MenuItem
onClick={ () => {
setRenamingBlock( true );
} }
aria-expanded={ renamingBlock }
aria-haspopup="dialog"
>
{ __( 'Rename' ) }
</MenuItem>
{ renamingBlock && (
<BlockRenameModal
blockName={ customName || '' }
originalBlockName={ blockInformation?.title }
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 );
} }
/>
) }
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { getBlockSupport } from '@wordpress/blocks';

export default function useBlockRename( name ) {
return {
canRename: getBlockSupport( name, 'renaming', true ),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { BlockLockMenuItem, useBlockLock } from '../block-lock';
import { store as blockEditorStore } from '../../store';
import BlockModeToggle from '../block-settings-menu/block-mode-toggle';

import { BlockRenameControl, useBlockRename } from '../block-rename';

const { Fill, Slot } = createSlotFill( 'BlockSettingsMenuControls' );

const BlockSettingsMenuControlsSlot = ( {
Expand All @@ -44,7 +46,9 @@ const BlockSettingsMenuControlsSlot = ( {
);

const { canLock } = useBlockLock( selectedClientIds[ 0 ] );
const { canRename } = useBlockRename( selectedBlocks[ 0 ] );
const showLockButton = selectedClientIds.length === 1 && canLock;
const showRenameButton = selectedClientIds.length === 1 && canRename;

// Check if current selection of blocks is Groupable or Ungroupable
// and pass this props down to ConvertToGroupButton.
Expand Down Expand Up @@ -84,6 +88,11 @@ const BlockSettingsMenuControlsSlot = ( {
clientId={ selectedClientIds[ 0 ] }
/>
) }
{ showRenameButton && (
<BlockRenameControl
clientId={ selectedClientIds[ 0 ] }
/>
) }
{ fills }
{ fillProps?.canMove && ! fillProps?.onlyBlock && (
<MenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ function NonDefaultControls( { format, onChange } ) {
// formats.
const suggestedFormats = [
...new Set( [
/* translators: See https://www.php.net/manual/datetime.format.php */
'Y-m-d',
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'n/j/Y', 'short date format' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'n/j/Y g:i A', 'short date format with time' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'M j, Y', 'medium date format' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'M j, Y g:i A', 'medium date format with time' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'F j, Y', 'long date format' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'M j', 'short date format without the year' ),
] ),
];
Expand Down
Loading

0 comments on commit c31e55d

Please sign in to comment.