Skip to content

Commit 94d2a2c

Browse files
authored
fix: reenable shadows for blocks being dragged (#79)
* fix: reenable shadows for blocks being dragged * fix: apply drop shadows to all dragging things via CSS * chore: add a license to shadows.js
1 parent fd1bc58 commit 94d2a2c

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

core/colours.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"textFieldText": "#575E75",
104104
"insertionMarker": "#000000",
105105
"insertionMarkerOpacity": 0.2,
106-
"dragShadowOpacity": 0.3,
106+
"dragShadowOpacity": 0.6,
107107
"stackGlow": "#FFF200",
108108
"stackGlowSize": 4,
109109
"stackGlowOpacity": 1,

core/css.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ const styles = `
284284
cursor: -webkit-grabbing;
285285
cursor: -moz-grabbing;
286286
}
287+
288+
/* All the blocks being dragged get the blocklyDragging class, so match only the root one */
289+
:not(.blocklyDragging) > .blocklyDragging {
290+
filter: url(#blocklyDragShadowFilter);
291+
}
292+
287293
/* Changes cursor on mouse down. Not effective in Firefox because of
288294
https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */
289295
.blocklyDraggable:active {

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import {
3131
ContinuousMetrics,
3232
} from '@blockly/continuous-toolbox';
3333
import {CheckableContinuousFlyout} from './checkable_continuous_flyout.js';
34-
import {ScratchContinuousToolbox} from './scratch_continuous_toolbox.js';
3534
import {buildGlowFilter, glowStack} from './glows.js';
35+
import {ScratchContinuousToolbox} from './scratch_continuous_toolbox.js';
3636
import './scratch_continuous_category.js';
37+
import {buildShadowFilter} from './shadows.js';
3738

3839
export * from 'blockly';
3940
export * from './block_reporting.js';
@@ -66,6 +67,7 @@ export function inject(container, options) {
6667
}
6768

6869
buildGlowFilter(workspace);
70+
buildShadowFilter(workspace);
6971

7072
Blockly.config.dragRadius = 3;
7173
Blockly.config.snapRadius = 48;

src/shadows.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as Blockly from 'blockly/core';
8+
import {Colours} from '../core/colours.js';
9+
10+
export function buildShadowFilter(workspace) {
11+
const svg = workspace.getParentSvg();
12+
const defs = Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.DEFS, {}, svg);
13+
// Adjust these width/height, x/y properties to stop the shadow from clipping
14+
var dragShadowFilter = Blockly.utils.dom.createSvgElement('filter',
15+
{
16+
'id': 'blocklyDragShadowFilter',
17+
'height': '140%',
18+
'width': '140%',
19+
'y': '-20%',
20+
'x': '-20%'
21+
},
22+
defs);
23+
Blockly.utils.dom.createSvgElement('feGaussianBlur',
24+
{
25+
'in': 'SourceAlpha',
26+
'stdDeviation': '6'
27+
},
28+
dragShadowFilter);
29+
var componentTransfer = Blockly.utils.dom.createSvgElement(
30+
'feComponentTransfer', {'result': 'offsetBlur'}, dragShadowFilter);
31+
// Shadow opacity is specified in the adjustable colour library,
32+
// since the darkness of the shadow largely depends on the workspace colour.
33+
Blockly.utils.dom.createSvgElement('feFuncA',
34+
{
35+
'type': 'linear',
36+
'slope': Colours.dragShadowOpacity
37+
},
38+
componentTransfer);
39+
Blockly.utils.dom.createSvgElement('feComposite',
40+
{
41+
'in': 'SourceGraphic',
42+
'in2': 'offsetBlur',
43+
'operator': 'over'
44+
},
45+
dragShadowFilter);
46+
}

0 commit comments

Comments
 (0)