Skip to content

Commit

Permalink
do displacement on drag
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jul 25, 2024
1 parent 82e61c4 commit 4e1b5c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
20 changes: 6 additions & 14 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ function Items( {
selectedBlocks,
visibleBlocks,
shouldRenderAppender,
insertionPoint,
isZoomOut,
sectionRootClientId,
sectionClientIds,
blockInsertionPoint,
} = useSelect(
( select ) => {
const {
Expand All @@ -199,6 +199,7 @@ function Items( {
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
getBlockInsertionPoint,
} = unlock( select( blockEditorStore ) );
const _order = getBlockOrder( rootClientId );

Expand All @@ -213,13 +214,6 @@ function Items( {
const { sectionRootClientId: root } = unlock( getSettings() );
const selectedBlockClientId = getSelectedBlockClientId();
const sectionRootClientIds = getBlockOrder( root );
// To do: move ZoomOutModeInserters to core/editor.
// Or we perhaps we should move the insertion point state to the
// block-editor store. I'm not sure what it was ever moved to the editor
// store, because all the inserter components all live in the
// block-editor package.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const editor = select( 'core/editor' );
return {
order: _order,
selectedBlocks: getSelectedBlockClientIds(),
Expand All @@ -238,7 +232,7 @@ function Items( {
sectionRootClientId: root,
sectionClientIds: sectionRootClientIds,
blockOrder: getBlockOrder( root ),
insertionPoint: unlock( editor ).getInsertionPoint(),
blockInsertionPoint: getBlockInsertionPoint(),
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
Expand Down Expand Up @@ -291,11 +285,9 @@ function Items( {
>
{ renderZoomOutSeparator(
isSectionBlock( clientId, sectionClientIds ) &&
insertionPoint.insertionIndex === 0 &&
blockInsertionPoint.index === 0 &&
clientId ===
sectionClientIds[
insertionPoint.insertionIndex
]
sectionClientIds[ blockInsertionPoint.index ]
) }
<BlockListBlock
rootClientId={ rootClientId }
Expand All @@ -305,7 +297,7 @@ function Items( {
isSectionBlock( clientId, sectionClientIds ) &&
clientId ===
sectionClientIds[
insertionPoint.insertionIndex - 1
blockInsertionPoint.index - 1
]
) }
</AsyncModeProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { useEffect, useRef, useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -16,9 +16,9 @@ function ZoomOutModeInserters() {
const [ isReady, setIsReady ] = useState( false );
const {
hasSelection,
blockInsertionPointVisible,
blockInsertionPoint,
blockOrder,
blockInsertionPointVisible,
setInserterIsOpened,
sectionRootClientId,
selectedBlockClientId,
Expand All @@ -39,16 +39,18 @@ function ZoomOutModeInserters() {
blockInsertionPoint: getBlockInsertionPoint(),
blockOrder: getBlockOrder( root ),
blockInsertionPointVisible: isBlockInsertionPointVisible(),
blockInsertionPoint: getBlockInsertionPoint(),
sectionRootClientId: root,
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
selectedBlockClientId: getSelectedBlockClientId(),
hoveredBlockClientId: getHoveredBlockClientId(),
};
}, [] );

const blockEditorDispatch = useDispatch( blockEditorStore );

const isMounted = useRef( false );

// Defer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
const timeout = setTimeout( () => {
Expand Down Expand Up @@ -80,7 +82,6 @@ function ZoomOutModeInserters() {
hoveredBlockClientId === nextClientId;

const { showInsertionPoint } = blockEditorDispatch;

return (
<BlockPopoverInbetween
key={ index }
Expand Down

0 comments on commit 4e1b5c5

Please sign in to comment.