Skip to content

Commit dc4ff68

Browse files
ramonjdMamadukatorounitandrewserongpedro-mendonca
authored
Package update: bugfixes for 6.3 RC3 (#53089)
* Patterns: Enable focus mode editing (#52427) * PreventDefault when isComposing is true. apply patch from t-hamano. (#52844) see: #52821 (comment) * List View: Ensure onDrop does not fire if there is no target (#52959) * I18N: Add missing Gettext wrapper on strings in Edit Post overview sidebar (#52971) * I18N: Add missing gettext wrapper * Add context to disambiguate 'Outline' that is commonly used on borders. * Footnotes: disable based on post type (#52934) * Footnotes: disable based on post type * Address feedback * Fix typo * Format: disable if block is not registered * Lock usesContext api * Use Symbol instead of Math.random * Patterns Browse Screen: Fix back button when switching between categories (#52964) * Patterns: Allow orphaned template parts to appear in general category (#52961) * Spacing presets: fix bug with select control adding undefined preset values (#53005) * Site Editor: Fix canvas mode sync with URL (#52996) * Check if spacing tool is defined before displaying controls. (#53008) * Check if spacing tool is defined before displaying controls. * Don't show sides if spacing type false * Improve consistency of the Post editor and Site editor Document actions (#52246) * Remove redundant shortcut button. * Fix focus and hover style and improve consistency. * Rename post document-title and improve CSS consistency. * Site Editor: Fix the typo in the title label map (#53071) * Fix patterns search crash: check for existence of defaultView before attempting to get styles (#52956) * backport paging bug fixes (#53091) --------- Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> Co-authored-by: Hiroshi Urabe <mail@torounit.com> Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Co-authored-by: Pedro Mendonça <ped.gaspar@gmail.com> Co-authored-by: Ella <4710635+ellatrix@users.noreply.github.com> Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Co-authored-by: Glen Davies <glendaviesnz@users.noreply.github.com> Co-authored-by: tellthemachines <tellthemachines@users.noreply.github.com> Co-authored-by: Andrea Fercia <a.fercia@gmail.com>
1 parent 609a9df commit dc4ff68

File tree

28 files changed

+278
-161
lines changed

28 files changed

+278
-161
lines changed

packages/block-editor/src/components/editor-styles/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ function useDarkThemeBodyClassName( styles ) {
4343
body.appendChild( tempCanvas );
4444

4545
backgroundColor = defaultView
46-
.getComputedStyle( tempCanvas, null )
46+
?.getComputedStyle( tempCanvas, null )
4747
.getPropertyValue( 'background-color' );
4848

4949
body.removeChild( tempCanvas );
5050
} else {
5151
backgroundColor = defaultView
52-
.getComputedStyle( canvas, null )
52+
?.getComputedStyle( canvas, null )
5353
.getPropertyValue( 'background-color' );
5454
}
5555
const colordBackgroundColor = colord( backgroundColor );

packages/block-editor/src/components/global-styles/hooks.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ export function useSettingsForBlockElement(
331331
const sides = Array.isArray( supports?.spacing?.[ key ] )
332332
? supports?.spacing?.[ key ]
333333
: supports?.spacing?.[ key ]?.sides;
334-
if ( sides?.length ) {
334+
// Check if spacing type is supported before adding sides.
335+
if ( sides?.length && updatedSettings.spacing?.[ key ] ) {
335336
updatedSettings.spacing = {
336337
...updatedSettings.spacing,
337338
[ key ]: {

packages/block-editor/src/components/list-view/use-list-view-drop-zone.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ export default function useListViewDropZone( { dropZoneElement } ) {
489489

490490
const ref = useDropZone( {
491491
dropZoneElement,
492-
onDrop: onBlockDrop,
492+
onDrop( event ) {
493+
if ( target ) {
494+
onBlockDrop( event );
495+
}
496+
},
493497
onDragLeave() {
494498
throttled.cancel();
495499
setTarget( null );

packages/block-editor/src/components/rich-text/format-edit.js

+62-38
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,67 @@
22
* WordPress dependencies
33
*/
44
import { getActiveFormat, getActiveObject } from '@wordpress/rich-text';
5+
import { useContext, useMemo } from '@wordpress/element';
56

6-
export default function FormatEdit( {
7-
formatTypes,
8-
onChange,
9-
onFocus,
10-
value,
11-
forwardedRef,
12-
} ) {
13-
return formatTypes.map( ( settings ) => {
14-
const { name, edit: Edit } = settings;
15-
16-
if ( ! Edit ) {
17-
return null;
18-
}
19-
20-
const activeFormat = getActiveFormat( value, name );
21-
const isActive = activeFormat !== undefined;
22-
const activeObject = getActiveObject( value );
23-
const isObjectActive =
24-
activeObject !== undefined && activeObject.type === name;
25-
26-
return (
27-
<Edit
28-
key={ name }
29-
isActive={ isActive }
30-
activeAttributes={
31-
isActive ? activeFormat.attributes || {} : {}
32-
}
33-
isObjectActive={ isObjectActive }
34-
activeObjectAttributes={
35-
isObjectActive ? activeObject.attributes || {} : {}
36-
}
37-
value={ value }
38-
onChange={ onChange }
39-
onFocus={ onFocus }
40-
contentRef={ forwardedRef }
41-
/>
42-
);
43-
} );
7+
/**
8+
* Internal dependencies
9+
*/
10+
import BlockContext from '../block-context';
11+
12+
const DEFAULT_BLOCK_CONTEXT = {};
13+
14+
export const usesContextKey = Symbol( 'usesContext' );
15+
16+
function Edit( { onChange, onFocus, value, forwardedRef, settings } ) {
17+
const {
18+
name,
19+
edit: EditFunction,
20+
[ usesContextKey ]: usesContext,
21+
} = settings;
22+
23+
const blockContext = useContext( BlockContext );
24+
25+
// Assign context values using the block type's declared context needs.
26+
const context = useMemo( () => {
27+
return usesContext
28+
? Object.fromEntries(
29+
Object.entries( blockContext ).filter( ( [ key ] ) =>
30+
usesContext.includes( key )
31+
)
32+
)
33+
: DEFAULT_BLOCK_CONTEXT;
34+
}, [ usesContext, blockContext ] );
35+
36+
if ( ! EditFunction ) {
37+
return null;
38+
}
39+
40+
const activeFormat = getActiveFormat( value, name );
41+
const isActive = activeFormat !== undefined;
42+
const activeObject = getActiveObject( value );
43+
const isObjectActive =
44+
activeObject !== undefined && activeObject.type === name;
45+
46+
return (
47+
<EditFunction
48+
key={ name }
49+
isActive={ isActive }
50+
activeAttributes={ isActive ? activeFormat.attributes || {} : {} }
51+
isObjectActive={ isObjectActive }
52+
activeObjectAttributes={
53+
isObjectActive ? activeObject.attributes || {} : {}
54+
}
55+
value={ value }
56+
onChange={ onChange }
57+
onFocus={ onFocus }
58+
contentRef={ forwardedRef }
59+
context={ context }
60+
/>
61+
);
62+
}
63+
64+
export default function FormatEdit( { formatTypes, ...props } ) {
65+
return formatTypes.map( ( settings ) => (
66+
<Edit settings={ settings } { ...props } key={ settings.name } />
67+
) );
4468
}

packages/block-editor/src/components/spacing-sizes-control/test/utils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ describe( 'getCustomValueFromPreset', () => {
4949
} );
5050

5151
describe( 'getPresetValueFromCustomValue', () => {
52-
const spacingSizes = [ { name: 'Small', slug: 20, size: '8px' } ];
52+
const spacingSizes = [
53+
{ name: 'Default', slug: 'default', size: undefined },
54+
{ name: 'Small', slug: 20, size: '8px' },
55+
];
56+
it( 'should return undefined even if an undefined value exist in spacing sizes as occurs if spacingSizes has > 7 entries', () => {
57+
expect( getPresetValueFromCustomValue( undefined, spacingSizes ) ).toBe(
58+
undefined
59+
);
60+
} );
5361
it( 'should return original value if a string in spacing presets var format', () => {
5462
expect(
5563
getPresetValueFromCustomValue(

packages/block-editor/src/components/spacing-sizes-control/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export function getCustomValueFromPreset( value, spacingSizes ) {
101101
* @return {string} The preset value if it can be found.
102102
*/
103103
export function getPresetValueFromCustomValue( value, spacingSizes ) {
104-
// Return value as-is if it is already a preset;
105-
if ( isValueSpacingPreset( value ) || value === '0' ) {
104+
// Return value as-is if it is undefined or is already a preset, or '0';
105+
if ( ! value || isValueSpacingPreset( value ) || value === '0' ) {
106106
return value;
107107
}
108108

packages/block-editor/src/private-apis.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
default as ReusableBlocksRenameHint,
2323
useReusableBlocksRenameHint,
2424
} from './components/inserter/reusable-block-rename-hint';
25+
import { usesContextKey } from './components/rich-text/format-edit';
2526

2627
/**
2728
* Private @wordpress/block-editor APIs.
@@ -47,4 +48,5 @@ lock( privateApis, {
4748
ResolutionTool,
4849
ReusableBlocksRenameHint,
4950
useReusableBlocksRenameHint,
51+
usesContextKey,
5052
} );

packages/block-library/src/footnotes/edit.js

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
1717
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
1818
const blockProps = useBlockProps();
1919

20+
if ( postType !== 'post' && postType !== 'page' ) {
21+
return (
22+
<div { ...blockProps }>
23+
<Placeholder
24+
icon={ <BlockIcon icon={ icon } /> }
25+
label={ __( 'Footnotes' ) }
26+
// To do: add instructions. We can't add new string in RC.
27+
/>
28+
</div>
29+
);
30+
}
31+
2032
if ( ! footnotes.length ) {
2133
return (
2234
<div { ...blockProps }>

packages/block-library/src/footnotes/format.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import { insertObject } from '@wordpress/rich-text';
1212
import {
1313
RichTextToolbarButton,
1414
store as blockEditorStore,
15+
privateApis,
1516
} from '@wordpress/block-editor';
1617
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
17-
import { createBlock } from '@wordpress/blocks';
18+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
1819

1920
/**
2021
* Internal dependencies
2122
*/
2223
import { name } from './block.json';
24+
import { unlock } from '../lock-unlock';
25+
26+
const { usesContextKey } = unlock( privateApis );
2327

2428
export const formatName = 'core/footnote';
2529
export const format = {
@@ -30,17 +34,34 @@ export const format = {
3034
'data-fn': 'data-fn',
3135
},
3236
contentEditable: false,
33-
edit: function Edit( { value, onChange, isObjectActive } ) {
37+
[ usesContextKey ]: [ 'postType' ],
38+
edit: function Edit( {
39+
value,
40+
onChange,
41+
isObjectActive,
42+
context: { postType },
43+
} ) {
3444
const registry = useRegistry();
3545
const {
3646
getSelectedBlockClientId,
3747
getBlockRootClientId,
3848
getBlockName,
3949
getBlocks,
4050
} = useSelect( blockEditorStore );
51+
const footnotesBlockType = useSelect( ( select ) =>
52+
select( blocksStore ).getBlockType( name )
53+
);
4154
const { selectionChange, insertBlock } =
4255
useDispatch( blockEditorStore );
4356

57+
if ( ! footnotesBlockType ) {
58+
return null;
59+
}
60+
61+
if ( postType !== 'post' && postType !== 'page' ) {
62+
return null;
63+
}
64+
4465
function onClick() {
4566
registry.batch( () => {
4667
let id;

packages/block-library/src/footnotes/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const settings = {
2121
edit,
2222
};
2323

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

2726
export const init = () => {

packages/block-library/src/template-part/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function build_template_part_block_instance_variations() {
250250
'area' => $template_part->area,
251251
),
252252
'scope' => array( 'inserter' ),
253-
'icon' => $icon_by_area[ $template_part->area ],
253+
'icon' => isset( $icon_by_area[ $template_part->area ] ) ? $icon_by_area[ $template_part->area ] : null,
254254
'example' => array(
255255
'attributes' => array(
256256
'slug' => $template_part->slug,

packages/commands/src/components/command-menu.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ export function CommandMenu() {
201201
if ( ! isOpen ) {
202202
return false;
203203
}
204+
205+
const onKeyDown = ( event ) => {
206+
if (
207+
// Ignore keydowns from IMEs
208+
event.nativeEvent.isComposing ||
209+
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition
210+
// is `isComposing=false`, even though it's technically still part of the composition.
211+
// These can only be detected by keyCode.
212+
event.keyCode === 229
213+
) {
214+
event.preventDefault();
215+
}
216+
};
217+
204218
const isLoading = Object.values( loaders ).some( Boolean );
205219

206220
return (
@@ -211,7 +225,10 @@ export function CommandMenu() {
211225
__experimentalHideHeader
212226
>
213227
<div className="commands-command-menu__container">
214-
<Command label={ __( 'Command palette' ) }>
228+
<Command
229+
label={ __( 'Command palette' ) }
230+
onKeyDown={ onKeyDown }
231+
>
215232
<div className="commands-command-menu__header">
216233
<Command.Input
217234
ref={ commandMenuInput }

packages/edit-post/src/components/header/document-title/index.js packages/edit-post/src/components/header/document-actions/index.js

+22-23
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { displayShortcut } from '@wordpress/keycodes';
1919
*/
2020
import { store as editPostStore } from '../../../store';
2121

22-
function DocumentTitle() {
22+
function DocumentActions() {
2323
const { template, isEditing } = useSelect( ( select ) => {
2424
const { isEditingTemplate, getEditedPostTemplate } =
2525
select( editPostStore );
@@ -46,24 +46,26 @@ function DocumentTitle() {
4646
}
4747

4848
return (
49-
<div className="edit-post-document-title">
50-
<span className="edit-post-document-title__left">
51-
<Button
52-
onClick={ () => {
53-
clearSelectedBlock();
54-
setIsEditingTemplate( false );
55-
} }
56-
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
57-
>
58-
{ __( 'Back' ) }
59-
</Button>
60-
</span>
61-
49+
<div className="edit-post-document-actions">
50+
<Button
51+
className="edit-post-document-actions__back"
52+
onClick={ () => {
53+
clearSelectedBlock();
54+
setIsEditingTemplate( false );
55+
} }
56+
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
57+
>
58+
{ __( 'Back' ) }
59+
</Button>
6260
<Button
63-
className="edit-post-document-title__title"
61+
className="edit-post-document-actions__command"
6462
onClick={ () => openCommandCenter() }
6563
>
66-
<HStack spacing={ 1 } justify="center">
64+
<HStack
65+
className="edit-post-document-actions__title"
66+
spacing={ 1 }
67+
justify="center"
68+
>
6769
<BlockIcon icon={ layout } />
6870
<Text size="body" as="h1">
6971
<VisuallyHidden as="span">
@@ -72,15 +74,12 @@ function DocumentTitle() {
7274
{ templateTitle }
7375
</Text>
7476
</HStack>
75-
</Button>
76-
<Button
77-
className="edit-post-document-title__shortcut"
78-
onClick={ () => openCommandCenter() }
79-
>
80-
{ displayShortcut.primary( 'k' ) }
77+
<span className="edit-post-document-actions__shortcut">
78+
{ displayShortcut.primary( 'k' ) }
79+
</span>
8180
</Button>
8281
</div>
8382
);
8483
}
8584

86-
export default DocumentTitle;
85+
export default DocumentActions;

0 commit comments

Comments
 (0)