Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package update: bugfixes for 6.3 RC3 #53089

Merged
merged 14 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/editor-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ function useDarkThemeBodyClassName( styles ) {
body.appendChild( tempCanvas );

backgroundColor = defaultView
.getComputedStyle( tempCanvas, null )
?.getComputedStyle( tempCanvas, null )
.getPropertyValue( 'background-color' );

body.removeChild( tempCanvas );
} else {
backgroundColor = defaultView
.getComputedStyle( canvas, null )
?.getComputedStyle( canvas, null )
.getPropertyValue( 'background-color' );
}
const colordBackgroundColor = colord( backgroundColor );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ export function useSettingsForBlockElement(
const sides = Array.isArray( supports?.spacing?.[ key ] )
? supports?.spacing?.[ key ]
: supports?.spacing?.[ key ]?.sides;
if ( sides?.length ) {
// Check if spacing type is supported before adding sides.
if ( sides?.length && updatedSettings.spacing?.[ key ] ) {
updatedSettings.spacing = {
...updatedSettings.spacing,
[ key ]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ export default function useListViewDropZone( { dropZoneElement } ) {

const ref = useDropZone( {
dropZoneElement,
onDrop: onBlockDrop,
onDrop( event ) {
if ( target ) {
onBlockDrop( event );
}
},
onDragLeave() {
throttled.cancel();
setTarget( null );
Expand Down
100 changes: 62 additions & 38 deletions packages/block-editor/src/components/rich-text/format-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,67 @@
* WordPress dependencies
*/
import { getActiveFormat, getActiveObject } from '@wordpress/rich-text';
import { useContext, useMemo } from '@wordpress/element';

export default function FormatEdit( {
formatTypes,
onChange,
onFocus,
value,
forwardedRef,
} ) {
return formatTypes.map( ( settings ) => {
const { name, edit: Edit } = settings;

if ( ! Edit ) {
return null;
}

const activeFormat = getActiveFormat( value, name );
const isActive = activeFormat !== undefined;
const activeObject = getActiveObject( value );
const isObjectActive =
activeObject !== undefined && activeObject.type === name;

return (
<Edit
key={ name }
isActive={ isActive }
activeAttributes={
isActive ? activeFormat.attributes || {} : {}
}
isObjectActive={ isObjectActive }
activeObjectAttributes={
isObjectActive ? activeObject.attributes || {} : {}
}
value={ value }
onChange={ onChange }
onFocus={ onFocus }
contentRef={ forwardedRef }
/>
);
} );
/**
* Internal dependencies
*/
import BlockContext from '../block-context';

const DEFAULT_BLOCK_CONTEXT = {};

export const usesContextKey = Symbol( 'usesContext' );

function Edit( { onChange, onFocus, value, forwardedRef, settings } ) {
const {
name,
edit: EditFunction,
[ usesContextKey ]: usesContext,
} = settings;

const blockContext = useContext( BlockContext );

// Assign context values using the block type's declared context needs.
const context = useMemo( () => {
return usesContext
? Object.fromEntries(
Object.entries( blockContext ).filter( ( [ key ] ) =>
usesContext.includes( key )
)
)
: DEFAULT_BLOCK_CONTEXT;
}, [ usesContext, blockContext ] );

if ( ! EditFunction ) {
return null;
}

const activeFormat = getActiveFormat( value, name );
const isActive = activeFormat !== undefined;
const activeObject = getActiveObject( value );
const isObjectActive =
activeObject !== undefined && activeObject.type === name;

return (
<EditFunction
key={ name }
isActive={ isActive }
activeAttributes={ isActive ? activeFormat.attributes || {} : {} }
isObjectActive={ isObjectActive }
activeObjectAttributes={
isObjectActive ? activeObject.attributes || {} : {}
}
value={ value }
onChange={ onChange }
onFocus={ onFocus }
contentRef={ forwardedRef }
context={ context }
/>
);
}

export default function FormatEdit( { formatTypes, ...props } ) {
return formatTypes.map( ( settings ) => (
<Edit settings={ settings } { ...props } key={ settings.name } />
) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ describe( 'getCustomValueFromPreset', () => {
} );

describe( 'getPresetValueFromCustomValue', () => {
const spacingSizes = [ { name: 'Small', slug: 20, size: '8px' } ];
const spacingSizes = [
{ name: 'Default', slug: 'default', size: undefined },
{ name: 'Small', slug: 20, size: '8px' },
];
it( 'should return undefined even if an undefined value exist in spacing sizes as occurs if spacingSizes has > 7 entries', () => {
expect( getPresetValueFromCustomValue( undefined, spacingSizes ) ).toBe(
undefined
);
} );
it( 'should return original value if a string in spacing presets var format', () => {
expect(
getPresetValueFromCustomValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export function getCustomValueFromPreset( value, spacingSizes ) {
* @return {string} The preset value if it can be found.
*/
export function getPresetValueFromCustomValue( value, spacingSizes ) {
// Return value as-is if it is already a preset;
if ( isValueSpacingPreset( value ) || value === '0' ) {
// Return value as-is if it is undefined or is already a preset, or '0';
if ( ! value || isValueSpacingPreset( value ) || value === '0' ) {
return value;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
default as ReusableBlocksRenameHint,
useReusableBlocksRenameHint,
} from './components/inserter/reusable-block-rename-hint';
import { usesContextKey } from './components/rich-text/format-edit';

/**
* Private @wordpress/block-editor APIs.
Expand All @@ -47,4 +48,5 @@ lock( privateApis, {
ResolutionTool,
ReusableBlocksRenameHint,
useReusableBlocksRenameHint,
usesContextKey,
} );
12 changes: 12 additions & 0 deletions packages/block-library/src/footnotes/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
const blockProps = useBlockProps();

if ( postType !== 'post' && postType !== 'page' ) {
return (
<div { ...blockProps }>
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Footnotes' ) }
// To do: add instructions. We can't add new string in RC.
/>
</div>
);
}

if ( ! footnotes.length ) {
return (
<div { ...blockProps }>
Expand Down
25 changes: 23 additions & 2 deletions packages/block-library/src/footnotes/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import { insertObject } from '@wordpress/rich-text';
import {
RichTextToolbarButton,
store as blockEditorStore,
privateApis,
} from '@wordpress/block-editor';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';
import { createBlock, store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { name } from './block.json';
import { unlock } from '../lock-unlock';

const { usesContextKey } = unlock( privateApis );

export const formatName = 'core/footnote';
export const format = {
Expand All @@ -30,17 +34,34 @@ export const format = {
'data-fn': 'data-fn',
},
contentEditable: false,
edit: function Edit( { value, onChange, isObjectActive } ) {
[ usesContextKey ]: [ 'postType' ],
edit: function Edit( {
value,
onChange,
isObjectActive,
context: { postType },
} ) {
const registry = useRegistry();
const {
getSelectedBlockClientId,
getBlockRootClientId,
getBlockName,
getBlocks,
} = useSelect( blockEditorStore );
const footnotesBlockType = useSelect( ( select ) =>
select( blocksStore ).getBlockType( name )
);
const { selectionChange, insertBlock } =
useDispatch( blockEditorStore );

if ( ! footnotesBlockType ) {
return null;
}

if ( postType !== 'post' && postType !== 'page' ) {
return null;
}

function onClick() {
registry.batch( () => {
let id;
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/footnotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const settings = {
edit,
};

// Would be good to remove the format and HoR if the block is unregistered.
registerFormatType( formatName, format );

export const init = () => {
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 @@ -250,7 +250,7 @@ function build_template_part_block_instance_variations() {
'area' => $template_part->area,
),
'scope' => array( 'inserter' ),
'icon' => $icon_by_area[ $template_part->area ],
'icon' => isset( $icon_by_area[ $template_part->area ] ) ? $icon_by_area[ $template_part->area ] : null,
'example' => array(
'attributes' => array(
'slug' => $template_part->slug,
Expand Down
19 changes: 18 additions & 1 deletion packages/commands/src/components/command-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ export function CommandMenu() {
if ( ! isOpen ) {
return false;
}

const onKeyDown = ( event ) => {
if (
// Ignore keydowns from IMEs
event.nativeEvent.isComposing ||
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition
// is `isComposing=false`, even though it's technically still part of the composition.
// These can only be detected by keyCode.
event.keyCode === 229
) {
event.preventDefault();
}
};

const isLoading = Object.values( loaders ).some( Boolean );

return (
Expand All @@ -211,7 +225,10 @@ export function CommandMenu() {
__experimentalHideHeader
>
<div className="commands-command-menu__container">
<Command label={ __( 'Command palette' ) }>
<Command
label={ __( 'Command palette' ) }
onKeyDown={ onKeyDown }
>
<div className="commands-command-menu__header">
<Command.Input
ref={ commandMenuInput }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { displayShortcut } from '@wordpress/keycodes';
*/
import { store as editPostStore } from '../../../store';

function DocumentTitle() {
function DocumentActions() {
const { template, isEditing } = useSelect( ( select ) => {
const { isEditingTemplate, getEditedPostTemplate } =
select( editPostStore );
Expand All @@ -46,24 +46,26 @@ function DocumentTitle() {
}

return (
<div className="edit-post-document-title">
<span className="edit-post-document-title__left">
<Button
onClick={ () => {
clearSelectedBlock();
setIsEditingTemplate( false );
} }
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
>
{ __( 'Back' ) }
</Button>
</span>

<div className="edit-post-document-actions">
<Button
className="edit-post-document-actions__back"
onClick={ () => {
clearSelectedBlock();
setIsEditingTemplate( false );
} }
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
>
{ __( 'Back' ) }
</Button>
<Button
className="edit-post-document-title__title"
className="edit-post-document-actions__command"
onClick={ () => openCommandCenter() }
>
<HStack spacing={ 1 } justify="center">
<HStack
className="edit-post-document-actions__title"
spacing={ 1 }
justify="center"
>
<BlockIcon icon={ layout } />
<Text size="body" as="h1">
<VisuallyHidden as="span">
Expand All @@ -72,15 +74,12 @@ function DocumentTitle() {
{ templateTitle }
</Text>
</HStack>
</Button>
<Button
className="edit-post-document-title__shortcut"
onClick={ () => openCommandCenter() }
>
{ displayShortcut.primary( 'k' ) }
<span className="edit-post-document-actions__shortcut">
{ displayShortcut.primary( 'k' ) }
</span>
</Button>
</div>
);
}

export default DocumentTitle;
export default DocumentActions;
Loading
Loading