From 50131248d4092791092e33816eca468555a0d571 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 5 Oct 2022 11:38:14 +0100 Subject: [PATCH] Revert perf optimization --- .../data/data-core-block-editor.md | 8 ++-- .../block-list/use-in-between-inserter.js | 1 - .../components/block-tools/insertion-point.js | 6 +-- packages/block-editor/src/store/actions.js | 44 +++++++------------ 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/docs/reference-guides/data/data-core-block-editor.md b/docs/reference-guides/data/data-core-block-editor.md index ca0743b476520..31e4718500018 100644 --- a/docs/reference-guides/data/data-core-block-editor.md +++ b/docs/reference-guides/data/data-core-block-editor.md @@ -1191,10 +1191,6 @@ _Parameters_ Action that hides the insertion point. -_Returns_ - -- `Object`: Action object. - ### insertAfterBlock Action that inserts an empty block after a given block. @@ -1516,6 +1512,10 @@ _Parameters_ - _index_ `?number`: Index at which block should be inserted. - _\_\_unstableOptions_ `Object`: Whether or not to show an inserter button. +_Returns_ + +- `Object`: Action object. + ### startDraggingBlocks Returns an action object used in signalling that the user has begun to drag blocks. diff --git a/packages/block-editor/src/components/block-list/use-in-between-inserter.js b/packages/block-editor/src/components/block-list/use-in-between-inserter.js index 93bc68a56b646..bede4c796b165 100644 --- a/packages/block-editor/src/components/block-list/use-in-between-inserter.js +++ b/packages/block-editor/src/components/block-list/use-in-between-inserter.js @@ -146,7 +146,6 @@ export function useInBetweenInserter() { showInsertionPoint( rootClientId, index, { __unstableWithInserter: true, - delay: 500, } ); } diff --git a/packages/block-editor/src/components/block-tools/insertion-point.js b/packages/block-editor/src/components/block-tools/insertion-point.js index 004dbfe85222f..5bd69fcd2e532 100644 --- a/packages/block-editor/src/components/block-tools/insertion-point.js +++ b/packages/block-editor/src/components/block-tools/insertion-point.js @@ -149,13 +149,13 @@ function InsertionPointPopover( { ...( ! isVertical ? horizontalLine.rest : verticalLine.rest ), opacity: 1, borderRadius: '2px', - transition: { delay: isInserterShown ? 0.1 : 0, type: 'tween' }, + transition: { delay: isInserterShown ? 0.5 : 0, type: 'tween' }, }, hover: { ...( ! isVertical ? horizontalLine.hover : verticalLine.hover ), opacity: 1, borderRadius: '2px', - transition: { delay: 0.1, type: 'tween' }, + transition: { delay: 0.5, type: 'tween' }, }, }; @@ -165,7 +165,7 @@ function InsertionPointPopover( { }, rest: { scale: 1, - transition: { type: 'tween' }, + transition: { delay: 0.4, type: 'tween' }, }, }; diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 3466434fd602b..68b6f61ca89d6 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -621,8 +621,6 @@ export const insertBlocks = } }; -const delayedInsertionPointCalls = new WeakMap(); - /** * Action that shows the insertion point. * @@ -630,40 +628,28 @@ const delayedInsertionPointCalls = new WeakMap(); * which to insert. * @param {?number} index Index at which block should be inserted. * @param {Object} __unstableOptions Whether or not to show an inserter button. + * + * @return {Object} Action object. */ -export const showInsertionPoint = - ( rootClientId, index, __unstableOptions = {} ) => - ( { dispatch, registry } ) => { - const previousCall = delayedInsertionPointCalls.get( registry ); - if ( previousCall ) { - clearTimeout( previousCall ); - } - const { __unstableWithInserter, delay } = __unstableOptions; - delayedInsertionPointCalls.set( - registry, - setTimeout( () => { - dispatch( { - type: 'SHOW_INSERTION_POINT', - rootClientId, - index, - __unstableWithInserter, - } ); - }, delay ) - ); +export function showInsertionPoint( + rootClientId, + index, + __unstableOptions = {} +) { + const { __unstableWithInserter } = __unstableOptions; + return { + type: 'SHOW_INSERTION_POINT', + rootClientId, + index, + __unstableWithInserter, }; - +} /** * Action that hides the insertion point. - * - * @return {Object} Action object. */ export const hideInsertionPoint = () => - ( { select, dispatch, registry } ) => { - const previousCall = delayedInsertionPointCalls.get( registry ); - if ( previousCall ) { - clearTimeout( previousCall ); - } + ( { select, dispatch } ) => { if ( ! select.isBlockInsertionPointVisible() ) { return; }