Skip to content

Commit 7c4b0bd

Browse files
BeksOmegacpcallen
andauthored
fix: delete area animation (#8149)
* fix: delete area animation * chore: format * Update core/dragging/dragger.ts Co-authored-by: Christopher Allen <cpcallen+github@gmail.com> --------- Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>
1 parent 139b4b9 commit 7c4b0bd

4 files changed

Lines changed: 50 additions & 14 deletions

File tree

core/block_animations.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ export function disposeUiEffect(block: BlockSvg) {
4242
// Deeply clone the current block.
4343
const clone: SVGGElement = svgGroup.cloneNode(true) as SVGGElement;
4444
clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')');
45-
if (workspace.isDragging()) {
46-
workspace.getLayerManager()?.moveToDragLayer({
47-
getSvgRoot: () => {
48-
return clone;
49-
},
50-
});
51-
} else {
52-
workspace.getLayerManager()?.getBlockLayer().appendChild(clone);
53-
}
45+
workspace.getLayerManager()?.appendToAnimationLayer({
46+
getSvgRoot: () => {
47+
return clone;
48+
},
49+
});
5450
const cloneRect = {
5551
'x': xy.x,
5652
'y': xy.y,

core/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ input[type=number] {
500500
margin-right: -24px;
501501
}
502502
503-
.blocklyBlockDragSurface {
503+
.blocklyBlockDragSurface, .blocklyAnimationLayer {
504504
position: absolute;
505505
top: 0;
506506
left: 0;

core/dragging/dragger.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {ComponentManager} from '../component_manager.js';
1414
import {IDeleteArea} from '../interfaces/i_delete_area.js';
1515
import * as registry from '../registry.js';
1616
import * as eventUtils from '../events/utils.js';
17+
import * as blockAnimations from '../block_animations.js';
18+
import {BlockSvg} from '../block_svg.js';
1719

1820
export class Dragger implements IDragger {
1921
protected startLoc: Coordinate;
@@ -105,12 +107,18 @@ export class Dragger implements IDragger {
105107
this.draggable.revertDrag();
106108
}
107109

110+
const wouldDelete =
111+
isDeletable(this.draggable) &&
112+
this.wouldDeleteDraggable(e, this.draggable);
113+
114+
// TODO(#8148): use a generalized API instead of an instanceof check.
115+
if (wouldDelete && this.draggable instanceof BlockSvg) {
116+
blockAnimations.disposeUiEffect(this.draggable);
117+
}
118+
108119
this.draggable.endDrag(e);
109120

110-
if (
111-
isDeletable(this.draggable) &&
112-
this.wouldDeleteDraggable(e, this.draggable)
113-
) {
121+
if (wouldDelete && isDeletable(this.draggable)) {
114122
// We want to make sure the delete gets grouped with any possible
115123
// move event.
116124
const newGroup = eventUtils.getGroup();

core/layer_manager.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {Coordinate} from './utils/coordinate.js';
1515
export class LayerManager {
1616
/** The layer elements being dragged are appended to. */
1717
private dragLayer: SVGGElement | undefined;
18+
/** The layer elements being animated are appended to. */
19+
private animationLayer: SVGGElement | undefined;
1820
/** The layers elements not being dragged are appended to. */
1921
private layers = new Map<number, SVGGElement>();
2022

@@ -26,6 +28,7 @@ export class LayerManager {
2628
// been appended yet.
2729
if (injectionDiv) {
2830
this.dragLayer = this.createDragLayer(injectionDiv);
31+
this.animationLayer = this.createAnimationLayer(injectionDiv);
2932
}
3033

3134
// We construct these manually so we can add the css class for backwards
@@ -48,6 +51,35 @@ export class LayerManager {
4851
return dom.createSvgElement(Svg.G, {}, svg);
4952
}
5053

54+
private createAnimationLayer(injectionDiv: Element) {
55+
const svg = dom.createSvgElement(Svg.SVG, {
56+
'class': 'blocklyAnimationLayer',
57+
'xmlns': dom.SVG_NS,
58+
'xmlns:html': dom.HTML_NS,
59+
'xmlns:xlink': dom.XLINK_NS,
60+
'version': '1.1',
61+
});
62+
injectionDiv.append(svg);
63+
return dom.createSvgElement(Svg.G, {}, svg);
64+
}
65+
66+
/**
67+
* Appends the element to the animation layer. The animation layer doesn't
68+
* move when the workspace moves, so e.g. delete animations don't move
69+
* when a block delete triggers a workspace resize.
70+
*
71+
* @internal
72+
*/
73+
appendToAnimationLayer(elem: IRenderedElement) {
74+
const currentTransform = this.dragLayer?.getAttribute('transform');
75+
// Only update the current transform when appending, so animations don't
76+
// move if the workspace moves.
77+
if (currentTransform) {
78+
this.animationLayer?.setAttribute('transform', currentTransform);
79+
}
80+
this.animationLayer?.appendChild(elem.getSvgRoot());
81+
}
82+
5183
/**
5284
* Translates layers when the workspace is dragged or zoomed.
5385
*

0 commit comments

Comments
 (0)