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

Backport fixes to WordPress 5.5 beta2 #23903

Merged
merged 15 commits into from Jul 13, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -47,6 +47,12 @@ public function register_routes() {
'type' => 'integer',
),

// Src is required to check for correct $image_meta.
'src' => array(
'type' => 'string',
'required' => true,
),

// Crop values are in percents.
'x' => array(
'type' => 'number',
@@ -114,9 +120,66 @@ public function apply_edits( $request ) {
$image_file = wp_get_original_image_path( $attachment_id );
$image_meta = wp_get_attachment_metadata( $attachment_id );

if ( ! $image_meta || ! $image_file ) {
$error = __( 'Unable to get meta information for file.', 'gutenberg' );
return new WP_Error( 'rest_unknown_attachment', $error, array( 'status' => 404 ) );
if ( function_exists( 'wp_image_file_matches_image_meta' ) ) {
if (
! $image_meta ||
! $image_file ||
! wp_image_file_matches_image_meta( $request['src'], $image_meta )
) {
return new WP_Error(
'rest_unknown_attachment',
__( 'Unable to get meta information for file.', 'gutenberg' ),
array( 'status' => 404 )
);
}
} else {
// Back-compat for WP versions < 5.5.
if ( ! $image_meta || ! $image_file ) {
return new WP_Error(
'rest_unknown_attachment',
__( 'Unable to get meta information for file.', 'gutenberg' ),
array( 'status' => 404 )
);
} else {
$match = false;
$image_src = $request['src'];

if ( isset( $image_meta['file'] ) && strlen( $image_meta['file'] ) > 4 ) {
// Remove quiery args.
list( $image_src ) = explode( '?', $image_src );

// Check if the relative image path from the image meta is at the end of $image_src.
if ( strrpos( $image_src, $image_meta['file'] ) === strlen( $image_src ) - strlen( $image_meta['file'] ) ) {
$match = true;
}

if ( ! empty( $image_meta['sizes'] ) ) {
// Retrieve the uploads sub-directory from the full size image.
$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );

if ( $dirname ) {
$dirname = trailingslashit( $dirname );
}

foreach ( $image_meta['sizes'] as $image_size_data ) {
$relative_path = $dirname . $image_size_data['file'];

if ( strrpos( $image_src, $relative_path ) === strlen( $image_src ) - strlen( $relative_path ) ) {
$match = true;
break;
}
}
}
}

if ( ! $match ) {
return new WP_Error(
'rest_unknown_attachment',
__( 'Unable to get meta information for file.', 'gutenberg' ),
array( 'status' => 404 )
);
}
}
}

$supported_types = array( 'image/jpeg', 'image/png', 'image/gif' );

Some generated files are not rendered by default. Learn more.

@@ -18,20 +18,17 @@ const BlockDraggable = ( {
onDragStart,
onDragEnd,
} ) => {
const { srcRootClientId, index, isDraggable } = useSelect(
const { srcRootClientId, isDraggable } = useSelect(
( select ) => {
const {
getBlockIndex,
getBlockRootClientId,
getTemplateLock,
} = select( 'core/block-editor' );
const { getBlockRootClientId, getTemplateLock } = select(
'core/block-editor'
);
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
const templateLock = rootClientId
? getTemplateLock( rootClientId )
: null;

return {
index: getBlockIndex( clientIds[ 0 ], rootClientId ),
srcRootClientId: rootClientId,
isDraggable: 'all' !== templateLock,
};
@@ -64,7 +61,6 @@ const BlockDraggable = ( {

const transferData = {
type: 'block',
srcIndex: index,
srcClientIds: clientIds,
srcRootClientId,
};
@@ -55,6 +55,9 @@ export default function useScrollWhenDragging() {
}, [] );

const scrollOnDragOver = useCallback( ( event ) => {
if ( ! scrollParentY.current ) {
return;
}
const scrollParentHeight = scrollParentY.current.offsetHeight;
const offsetDragStartPosition =
dragStartY.current - scrollParentY.current.offsetTop;
@@ -15,7 +15,7 @@ import {
forwardRef,
} from '@wordpress/element';
import { focus, isTextField, placeCaretAtHorizontalEdge } from '@wordpress/dom';
import { ENTER } from '@wordpress/keycodes';
import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';

@@ -75,7 +75,9 @@ const BlockComponent = forwardRef(
},
[ isSelected ]
);
const { insertDefaultBlock } = useDispatch( 'core/block-editor' );
const { insertDefaultBlock, removeBlock } = useDispatch(
'core/block-editor'
);
const fallbackRef = useRef();
const isAligned = wrapperProps && !! wrapperProps[ 'data-align' ];
wrapper = wrapper || fallbackRef;
@@ -169,7 +171,11 @@ const BlockComponent = forwardRef(
props.onKeyDown( event );
}

if ( keyCode !== ENTER ) {
if (
keyCode !== ENTER &&
keyCode !== BACKSPACE &&
keyCode !== DELETE
) {
return;
}

@@ -181,6 +187,8 @@ const BlockComponent = forwardRef(

if ( keyCode === ENTER ) {
insertDefaultBlock( {}, rootClientId, index + 1 );
} else {
removeBlock( clientId );
}
};

@@ -13,6 +13,7 @@
// Overrides the default padding applied in editor styles otherwise preview centering break.
&.editor-styles-wrapper {
padding: 0;
margin: 0;
}
}

@@ -183,14 +183,11 @@ export default compose( [
getBlockRootClientId,
hasInserterItems,
__experimentalGetAllowedBlocks,
getBlockSelectionEnd,
} = select( 'core/block-editor' );
const { getBlockVariations } = select( 'core/blocks' );

rootClientId =
rootClientId ||
getBlockRootClientId( clientId || getBlockSelectionEnd() ) ||
undefined;
rootClientId || getBlockRootClientId( clientId ) || undefined;

const allowedBlocks = __experimentalGetAllowedBlocks( rootClientId );

@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { orderBy } from 'lodash';

/**
* WordPress dependencies
*/
@@ -46,7 +51,11 @@ function QuickInserterList( {
onHover,
} ) {
const shownBlockTypes = useMemo(
() => blockTypes.slice( 0, SHOWN_BLOCK_TYPES ),
() =>
orderBy( blockTypes, [ 'frecency' ], [ 'desc' ] ).slice(
0,
SHOWN_BLOCK_TYPES
),
[ blockTypes ]
);
const shownBlockPatterns = useMemo(
@@ -267,7 +267,11 @@ $block-inserter-tabs-height: 44px;
}

.block-editor-inserter__quick-inserter {
width: $block-inserter-width;
width: 100%;

@include break-medium {
width: $block-inserter-width;
}
}

.block-editor-inserter__quick-inserter-results {
@@ -291,9 +295,7 @@ $block-inserter-tabs-height: 44px;
}

.block-editor-inserter__popover.is-quick > .components-popover__content > div {
@include break-medium {
padding: 0;
}
padding: 0;
}

.block-editor-inserter__quick-inserter-expand.components-button {
@@ -131,7 +131,7 @@ function KeyboardShortcuts() {
},
[ clientIds, removeBlocks ]
),
{ isDisabled: clientIds.length < 1 }
{ isDisabled: clientIds.length < 2 }
);

useShortcut(
@@ -19,7 +19,7 @@ export default function SpacingPanelControl( { children, ...props } ) {
const isSpacingEnabled = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
return get( getSettings(), '__experimentalEnableCustomSpacing' );
} );
}, [] );

if ( ! isSpacingEnabled ) return null;

@@ -12,7 +12,7 @@ import {
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';
import { edit as editIcon } from '@wordpress/icons';
import { Icon, edit as editIcon } from '@wordpress/icons';

const selectIcon = (
<SVG
@@ -60,7 +60,7 @@ function ToolSelector( props, ref ) {
value: 'edit',
label: (
<>
{ editIcon }
<Icon icon={ editIcon } />
{ __( 'Edit' ) }
</>
),
@@ -137,7 +137,6 @@ function parseDropEvent( event ) {
let result = {
srcRootClientId: null,
srcClientIds: null,
srcIndex: null,
type: null,
};

@@ -176,28 +175,32 @@ export default function useBlockDropZone( {
} ) {
const [ targetBlockIndex, setTargetBlockIndex ] = useState( null );

function selector( select ) {
const {
getBlockListSettings,
getClientIdsOfDescendants,
getSettings,
getTemplateLock,
} = select( 'core/block-editor' );
return {
orientation: getBlockListSettings( targetRootClientId )
?.orientation,
getClientIdsOfDescendants,
hasUploadPermissions: !! getSettings().mediaUpload,
isLockedAll: getTemplateLock( targetRootClientId ) === 'all',
};
}

const {
getClientIdsOfDescendants,
getBlockIndex,
hasUploadPermissions,
isLockedAll,
orientation,
} = useSelect( selector, [ targetRootClientId ] );
} = useSelect(
( select ) => {
const {
getBlockListSettings,
getClientIdsOfDescendants: _getClientIdsOfDescendants,
getBlockIndex: _getBlockIndex,
getSettings,
getTemplateLock,
} = select( 'core/block-editor' );
return {
orientation: getBlockListSettings( targetRootClientId )
?.orientation,
getClientIdsOfDescendants: _getClientIdsOfDescendants,
getBlockIndex: _getBlockIndex,
hasUploadPermissions: !! getSettings().mediaUpload,
isLockedAll: getTemplateLock( targetRootClientId ) === 'all',
};
},
[ targetRootClientId ]
);
const {
insertBlocks,
updateBlockAttributes,
@@ -249,7 +252,6 @@ export default function useBlockDropZone( {
const {
srcRootClientId: sourceRootClientId,
srcClientIds: sourceClientIds,
srcIndex: sourceBlockIndex,
type: dropType,
} = parseDropEvent( event );

@@ -258,6 +260,8 @@ export default function useBlockDropZone( {
return;
}

const sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );

// If the user is dropping to the same position, return early.
if (
sourceRootClientId === targetRootClientId &&
@@ -299,6 +303,7 @@ export default function useBlockDropZone( {
},
[
getClientIdsOfDescendants,
getBlockIndex,
targetBlockIndex,
moveBlocksToPosition,
targetRootClientId,
@@ -192,6 +192,8 @@ export default function ImageEditor( {
attrs.rotation = rotation;
}

attrs.src = url;

apiFetch( {
path: `wp/v2/media/${ id }/edit`,
method: 'POST',
@@ -15,6 +15,18 @@
function render_block_core_search( $attributes ) {
static $instance_id = 0;

// Older versions of the Search block defaulted the label and buttonText
// attributes to `__( 'Search' )` meaning that many posts contain `<!--
// wp:search /-->`. Support these by defaulting an undefined label and
// buttonText to `__( 'Search' )`.
$attributes = wp_parse_args(
$attributes,
array(
'label' => __( 'Search' ),
'buttonText' => __( 'Search' ),
)
);

$input_id = 'wp-block-search__input-' . ++$instance_id;
$label_markup = '';
$button_markup = '';
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.