Skip to content

Commit

Permalink
Merge branch 'trunk' into docs/fundamentals-block-development---diagr…
Browse files Browse the repository at this point in the history
…am-links
  • Loading branch information
juanmaguitar committed Dec 13, 2023
2 parents 0d7a248 + 77a8b55 commit 8ab4c45
Show file tree
Hide file tree
Showing 48 changed files with 885 additions and 429 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
3 changes: 3 additions & 0 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ function gutenberg_render_background_support( $block_content, $block ) {
)
);

if ( function_exists( 'wp_render_background_support' ) ) {
remove_filter( 'render_block', 'wp_render_background_support' );
}
add_filter( 'render_block', 'gutenberg_render_background_support', 10, 2 );
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
5 changes: 1 addition & 4 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useState } from 'react';
import {
BlockEditorProvider,
BlockList,
BlockTools,
WritingFlow,
} from '@wordpress/block-editor';

Expand All @@ -32,9 +31,7 @@ function MyEditorComponent() {
onInput={ ( blocks ) => updateBlocks( blocks ) }
onChange={ ( blocks ) => updateBlocks( blocks ) }
>
<BlockTools>
<BlockCanvas height="400px" />
</BlockTools>
<BlockCanvas height="400px" />
</BlockEditorProvider>
);
}
Expand Down
48 changes: 31 additions & 17 deletions packages/block-editor/src/components/block-canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';
import { useRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockList from '../block-list';
import BlockTools from '../block-tools';
import EditorStyles from '../editor-styles';
import Iframe from '../iframe';
import WritingFlow from '../writing-flow';
Expand All @@ -23,11 +25,15 @@ export function ExperimentalBlockCanvas( {
} ) {
const resetTypingRef = useMouseMoveTypingReset();
const clearerRef = useBlockSelectionClearer();
const contentRef = useMergeRefs( [ contentRefProp, clearerRef ] );
const localRef = useRef();
const contentRef = useMergeRefs( [ contentRefProp, clearerRef, localRef ] );

if ( ! shouldIframe ) {
return (
<>
<BlockTools
__unstableContentRef={ localRef }
style={ { height, display: 'flex' } }
>
<EditorStyles
styles={ styles }
scope=".editor-styles-wrapper"
Expand All @@ -36,29 +42,37 @@ export function ExperimentalBlockCanvas( {
ref={ contentRef }
className="editor-styles-wrapper"
tabIndex={ -1 }
style={ { height } }
style={ {
height: '100%',
width: '100%',
} }
>
{ children }
</WritingFlow>
</>
</BlockTools>
);
}

return (
<Iframe
{ ...iframeProps }
ref={ resetTypingRef }
contentRef={ contentRef }
style={ {
width: '100%',
height,
...iframeProps?.style,
} }
name="editor-canvas"
<BlockTools
__unstableContentRef={ localRef }
style={ { height, display: 'flex' } }
>
<EditorStyles styles={ styles } />
{ children }
</Iframe>
<Iframe
{ ...iframeProps }
ref={ resetTypingRef }
contentRef={ contentRef }
style={ {
width: '100%',
height: '100%',
...iframeProps?.style,
} }
name="editor-canvas"
>
<EditorStyles styles={ styles } />
{ children }
</Iframe>
</BlockTools>
);
}

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 8ab4c45

Please sign in to comment.