From 1c59c033cd65634a065c305376deb48077ec1a11 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 18 Mar 2024 13:40:00 -0700 Subject: [PATCH 1/4] fix: Fix block disposal animations --- core/block_animations.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/block_animations.ts b/core/block_animations.ts index 615aa81d114..0dd88c7d0c6 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -9,6 +9,7 @@ import type {BlockSvg} from './block_svg.js'; import * as dom from './utils/dom.js'; import {Svg} from './utils/svg.js'; +import * as svgMath from './utils/svg_math.js'; /** A bounding box for a cloned block. */ interface CloneRect { @@ -38,11 +39,17 @@ export function disposeUiEffect(block: BlockSvg) { const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); - const xy = workspace.getSvgXY(svgGroup); + const xy = block.getRelativeToSurfaceXY(); // Deeply clone the current block. const clone: SVGGElement = svgGroup.cloneNode(true) as SVGGElement; clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); - workspace.getParentSvg().appendChild(clone); + if (workspace.isDragging()) { + workspace.getLayerManager()?.moveToDragLayer({ + getSvgRoot: () => { return clone; } + }); + } else { + workspace.getLayerManager()?.getBlockLayer().appendChild(clone); + } const cloneRect = { 'x': xy.x, 'y': xy.y, @@ -60,14 +67,12 @@ export function disposeUiEffect(block: BlockSvg) { * @param rect Starting rect of the clone. * @param rtl True if RTL, false if LTR. * @param start Date of animation's start. - * @param workspaceScale Scale of workspace. */ function disposeUiStep( clone: Element, rect: CloneRect, rtl: boolean, start: Date, - workspaceScale: number, ) { const ms = new Date().getTime() - start.getTime(); const percent = ms / 150; @@ -75,14 +80,14 @@ function disposeUiStep( dom.removeNode(clone); } else { const x = - rect.x + (((rtl ? -1 : 1) * rect.width * workspaceScale) / 2) * percent; - const y = rect.y + rect.height * workspaceScale * percent; - const scale = (1 - percent) * workspaceScale; + rect.x + (((rtl ? -1 : 1) * rect.width) / 2) * percent; + const y = rect.y + rect.height / 2 * percent; + const scale = (1 - percent); clone.setAttribute( 'transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')', ); - setTimeout(disposeUiStep, 10, clone, rect, rtl, start, workspaceScale); + setTimeout(disposeUiStep, 10, clone, rect, rtl, start); } } From 12371ef8ca27bd3b1af6775e918684d41be9a20c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 18 Mar 2024 15:35:11 -0700 Subject: [PATCH 2/4] chore: Run lint --- core/block_animations.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/block_animations.ts b/core/block_animations.ts index 0dd88c7d0c6..ee123d15a9c 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -45,7 +45,9 @@ export function disposeUiEffect(block: BlockSvg) { clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); if (workspace.isDragging()) { workspace.getLayerManager()?.moveToDragLayer({ - getSvgRoot: () => { return clone; } + getSvgRoot: () => { + return clone; + }, }); } else { workspace.getLayerManager()?.getBlockLayer().appendChild(clone); @@ -79,10 +81,9 @@ function disposeUiStep( if (percent > 1) { dom.removeNode(clone); } else { - const x = - rect.x + (((rtl ? -1 : 1) * rect.width) / 2) * percent; - const y = rect.y + rect.height / 2 * percent; - const scale = (1 - percent); + const x = rect.x + (((rtl ? -1 : 1) * rect.width) / 2) * percent; + const y = rect.y + (rect.height / 2) * percent; + const scale = 1 - percent; clone.setAttribute( 'transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')', From d5254a77a265cb2165432f23a59f377836d19686 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 18 Mar 2024 15:37:07 -0700 Subject: [PATCH 3/4] chore: Remove unused import --- core/block_animations.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/block_animations.ts b/core/block_animations.ts index ee123d15a9c..aded284c09b 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -9,7 +9,6 @@ import type {BlockSvg} from './block_svg.js'; import * as dom from './utils/dom.js'; import {Svg} from './utils/svg.js'; -import * as svgMath from './utils/svg_math.js'; /** A bounding box for a cloned block. */ interface CloneRect { From 7f7d42ccfde2e6332b6eebfd104787b51eb8713d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 18 Mar 2024 15:43:45 -0700 Subject: [PATCH 4/4] fix: Remove unused function arg --- core/block_animations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_animations.ts b/core/block_animations.ts index aded284c09b..d3bd13118a1 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -57,7 +57,7 @@ export function disposeUiEffect(block: BlockSvg) { 'width': block.width, 'height': block.height, }; - disposeUiStep(clone, cloneRect, workspace.RTL, new Date(), workspace.scale); + disposeUiStep(clone, cloneRect, workspace.RTL, new Date()); } /** * Animate a cloned block and eventually dispose of it.