From ee95127fbb1cee1a1cd3620c8a6fc6e94dad3aba Mon Sep 17 00:00:00 2001 From: Margarita Cabrera Ramirez Date: Tue, 7 May 2024 16:27:56 +0900 Subject: [PATCH 01/17] add generic button instead of inserter between sections --- .../src/components/block-tools/style.scss | 8 ++ .../block-tools/zoom-out-mode-inserters.js | 108 ++++++++++++++++-- 2 files changed, 109 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/style.scss b/packages/block-editor/src/components/block-tools/style.scss index c5920bdf2f7d38..07654a784305db 100644 --- a/packages/block-editor/src/components/block-tools/style.scss +++ b/packages/block-editor/src/components/block-tools/style.scss @@ -47,6 +47,10 @@ top: calc(50% - #{$button-size-small * 0.5}); left: calc(50% - #{$button-size-small * 0.5}); + .is-pattern-inserter & { + top: 50%; + left: 50%; + } } .block-editor-block-list__block-side-inserter-popover .components-popover__content > div { @@ -262,3 +266,7 @@ .is-dragging-components-draggable .components-tooltip { display: none; } + +.block-editor-block-list__insertion-point.is-pattern-inserter .block-editor-button-pattern-inserter__button { + pointer-events: all; +} diff --git a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js index 5fad0e54e38a68..6cfb9cc6518af9 100644 --- a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js +++ b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js @@ -3,17 +3,35 @@ */ import { useSelect } from '@wordpress/data'; import { useEffect, useState } from '@wordpress/element'; +import { __unstableMotion as motion, Button } from '@wordpress/components'; +import { useReducedMotion } from '@wordpress/compose'; +import { plus } from '@wordpress/icons'; +import { _x } from '@wordpress/i18n'; /** * Internal dependencies */ import BlockPopoverInbetween from '../block-popover/inbetween'; import { store as blockEditorStore } from '../../store'; -import Inserter from '../inserter'; import { unlock } from '../../lock-unlock'; function ZoomOutModeInserters( { __unstableContentRef } ) { const [ isReady, setIsReady ] = useState( false ); + const { setInserterIsOpened, insertionIndex } = useSelect( + ( select ) => { + const { getSettings, getBlockIndex, getBlockCount } = + select( blockEditorStore ); + const settings = getSettings(); + const index = getBlockIndex( clientId ); + const blockCount = getBlockCount(); + + return { + setInserterIsOpened: settings.__experimentalSetIsInserterOpened, + insertionIndex: index === -1 ? blockCount : index, + }; + }, + [ clientId ] + ); const blockOrder = useSelect( ( select ) => { const { sectionRootClientId } = unlock( select( blockEditorStore ).getSettings() @@ -31,25 +49,101 @@ function ZoomOutModeInserters( { __unstableContentRef } ) { }; }, [] ); + useEffect( () => { + if ( setInserterIsOpened ) { + setInserterIsOpened( false ); + } + }, [ setInserterIsOpened ] ); + + const disableMotion = useReducedMotion(); + if ( ! isReady ) { return null; } + const lineVariants = { + // Initial position starts from the center and invisible. + start: { + opacity: 0, + scale: 0, + }, + // The line expands to fill the container. If the inserter is visible it + // is delayed so it appears orchestrated. + rest: { + opacity: 1, + scale: 1, + transition: { delay: 0.5, type: 'tween' }, + }, + hover: { + opacity: 1, + scale: 1, + transition: { delay: 0.5, type: 'tween' }, + }, + }; + const patternInserterVariants = { + start: { + scale: disableMotion ? 1 : 0, + translateX: '-50%', + translateY: '-50%', + }, + rest: { + scale: 1, + transition: { delay: 0.4, type: 'tween' }, + }, + }; + + const label = _x( + 'Add pattern', + 'Generic label for pattern inserter button' + ); + return [ undefined, ...blockOrder ].map( ( clientId, index ) => { + if ( index === blockOrder.length - 1 ) { + return null; + } return ( -
- + -
+ +