Skip to content

Commit

Permalink
Merge branch 'trunk' into components/move-kebabcase
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Dec 13, 2023
2 parents 5c77153 + 2936660 commit 569e9a9
Show file tree
Hide file tree
Showing 50 changed files with 1,143 additions and 463 deletions.
15 changes: 15 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
== Changelog ==

= 17.2.1 =

## Changelog

### Bug Fixes

- Fix: Fatal php error if a template was created by an author that was deleted ([56990](https://github.com/WordPress/gutenberg/pull/56990))

## Contributors

The following contributors merged PRs in this release:

@jorgefilipecosta


= 17.2.0 =


Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.3
* Requires PHP: 7.0
* Version: 17.2.0
* Version: 17.2.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
6 changes: 5 additions & 1 deletion lib/compat/wordpress-6.5/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function _gutenberg_get_wp_templates_author_text_field( $template_object ) {
case 'site':
return get_bloginfo( 'name' );
case 'user':
return get_user_by( 'id', $template_object['author'] )->get( 'display_name' );
$author = get_user_by( 'id', $template_object['author'] );
if ( ! $author ) {
return __( 'Unknown author', 'gutenberg' );
}
return $author->get( 'display_name' );
}
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "17.2.0",
"version": "17.2.1",
"private": true,
"description": "A new WordPress editor experience.",
"author": "The WordPress Contributors",
Expand Down
128 changes: 114 additions & 14 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
} from '../../utils/math';
import { store as blockEditorStore } from '../../store';

const THRESHOLD_DISTANCE = 30;
const MINIMUM_HEIGHT_FOR_THRESHOLD = 120;
const MINIMUM_WIDTH_FOR_THRESHOLD = 120;

/** @typedef {import('../../utils/math').WPPoint} WPPoint */
/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */

Expand Down Expand Up @@ -48,24 +52,86 @@ import { store as blockEditorStore } from '../../store';
* @param {WPBlockData[]} blocksData The block data list.
* @param {WPPoint} position The position of the item being dragged.
* @param {WPBlockListOrientation} orientation The orientation of the block list.
* @param {Object} options Additional options.
* @return {[number, WPDropOperation]} The drop target position.
*/
export function getDropTargetPosition(
blocksData,
position,
orientation = 'vertical'
orientation = 'vertical',
options = {}
) {
const allowedEdges =
orientation === 'horizontal'
? [ 'left', 'right' ]
: [ 'top', 'bottom' ];

const isRightToLeft = isRTL();

let nearestIndex = 0;
let insertPosition = 'before';
let minDistance = Infinity;

const {
dropZoneElement,
parentBlockOrientation,
rootBlockIndex = 0,
} = options;

// Allow before/after when dragging over the top/bottom edges of the drop zone.
if ( dropZoneElement && parentBlockOrientation !== 'horizontal' ) {
const rect = dropZoneElement.getBoundingClientRect();
const [ distance, edge ] = getDistanceToNearestEdge( position, rect, [
'top',
'bottom',
] );

// If dragging over the top or bottom of the drop zone, insert the block
// before or after the parent block. This only applies to blocks that use
// a drop zone element, typically container blocks such as Group or Cover.
if (
rect.height > MINIMUM_HEIGHT_FOR_THRESHOLD &&
distance < THRESHOLD_DISTANCE
) {
if ( edge === 'top' ) {
return [ rootBlockIndex, 'before' ];
}
if ( edge === 'bottom' ) {
return [ rootBlockIndex + 1, 'after' ];
}
}
}

const isRightToLeft = isRTL();

// Allow before/after when dragging over the left/right edges of the drop zone.
if ( dropZoneElement && parentBlockOrientation === 'horizontal' ) {
const rect = dropZoneElement.getBoundingClientRect();
const [ distance, edge ] = getDistanceToNearestEdge( position, rect, [
'left',
'right',
] );

// If dragging over the left or right of the drop zone, insert the block
// before or after the parent block. This only applies to blocks that use
// a drop zone element, typically container blocks such as Group.
if (
rect.width > MINIMUM_WIDTH_FOR_THRESHOLD &&
distance < THRESHOLD_DISTANCE
) {
if (
( isRightToLeft && edge === 'right' ) ||
( ! isRightToLeft && edge === 'left' )
) {
return [ rootBlockIndex, 'before' ];
}
if (
( isRightToLeft && edge === 'left' ) ||
( ! isRightToLeft && edge === 'right' )
) {
return [ rootBlockIndex + 1, 'after' ];
}
}
}

blocksData.forEach(
( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {
const rect = getBoundingClientRect();
Expand Down Expand Up @@ -150,19 +216,27 @@ export default function useBlockDropZone( {
operation: 'insert',
} );

const isDisabled = useSelect(
const { isDisabled, parentBlockClientId, rootBlockIndex } = useSelect(
( select ) => {
const {
__unstableIsWithinBlockOverlay,
__unstableHasActiveBlockOverlayActive,
getBlockIndex,
getBlockParents,
getBlockEditingMode,
} = select( blockEditorStore );
const blockEditingMode = getBlockEditingMode( targetRootClientId );
return (
blockEditingMode !== 'default' ||
__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||
__unstableIsWithinBlockOverlay( targetRootClientId )
);
return {
parentBlockClientId:
getBlockParents( targetRootClientId, true )[ 0 ] || '',
rootBlockIndex: getBlockIndex( targetRootClientId ),
isDisabled:
blockEditingMode !== 'default' ||
__unstableHasActiveBlockOverlayActive(
targetRootClientId
) ||
__unstableIsWithinBlockOverlay( targetRootClientId ),
};
},
[ targetRootClientId ]
);
Expand All @@ -172,9 +246,15 @@ export default function useBlockDropZone( {
const { showInsertionPoint, hideInsertionPoint } =
useDispatch( blockEditorStore );

const onBlockDrop = useOnBlockDrop( targetRootClientId, dropTarget.index, {
operation: dropTarget.operation,
} );
const onBlockDrop = useOnBlockDrop(
dropTarget.operation === 'before' || dropTarget.operation === 'after'
? parentBlockClientId
: targetRootClientId,
dropTarget.index,
{
operation: dropTarget.operation,
}
);
const throttled = useThrottle(
useCallback(
( event, ownerDocument ) => {
Expand Down Expand Up @@ -211,26 +291,46 @@ export default function useBlockDropZone( {
const [ targetIndex, operation ] = getDropTargetPosition(
blocksData,
{ x: event.clientX, y: event.clientY },
getBlockListSettings( targetRootClientId )?.orientation
getBlockListSettings( targetRootClientId )?.orientation,
{
dropZoneElement,
parentBlockClientId,
parentBlockOrientation: parentBlockClientId
? getBlockListSettings( parentBlockClientId )
?.orientation
: undefined,
rootBlockIndex,
}
);

registry.batch( () => {
setDropTarget( {
index: targetIndex,
operation,
} );
showInsertionPoint( targetRootClientId, targetIndex, {

const insertionPointClientId = [
'before',
'after',
].includes( operation )
? parentBlockClientId
: targetRootClientId;

showInsertionPoint( insertionPointClientId, targetIndex, {
operation,
} );
} );
},
[
dropZoneElement,
getBlocks,
targetRootClientId,
getBlockListSettings,
registry,
showInsertionPoint,
getBlockIndex,
parentBlockClientId,
rootBlockIndex,
]
),
200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ export default function useOnBlockDrop(
operation,
getBlockOrder,
getBlocksByClientId,
insertBlocks,
moveBlocksToPosition,
registry,
removeBlocks,
replaceBlocks,
targetBlockIndex,
targetRootClientId,
]
Expand Down
Loading

0 comments on commit 569e9a9

Please sign in to comment.