File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 * @author samelh@google.com (Sam El-Husseini)
1111 */
1212
13+ import * as Blockly from 'blockly/core' ;
14+
15+ /** Block that duplicates itself on drag. */
16+ Blockly . Blocks [ 'drag_to_dupe' ] = {
17+ init : function ( ) {
18+ this . setOutput ( true , null ) ;
19+ this . appendDummyInput ( ) . appendField ( 'drag to dupe' ) ;
20+ this . setDragStrategy ( new DragToDupe ( this ) ) ;
21+ } ,
22+ } ;
23+
24+ /** Drag strategy that duplicates the block on drag. */
25+ class DragToDupe {
26+ constructor ( block ) {
27+ this . block = block ;
28+ }
29+
30+ isMovable ( ) {
31+ return true ;
32+ }
33+
34+ startDrag ( e ) {
35+ const data = this . block . toCopyData ( ) ;
36+ this . copy = Blockly . clipboard . paste ( data , this . block . workspace ) ;
37+ this . baseStrat = new Blockly . dragging . BlockDragStrategy ( this . copy ) ;
38+ this . baseStrat . startDrag ( e ) ;
39+ }
40+
41+ drag ( e ) {
42+ this . baseStrat . drag ( e ) ;
43+ }
44+
45+ endDrag ( e ) {
46+ this . baseStrat . endDrag ( e ) ;
47+ }
48+
49+ revertDrag ( e ) {
50+ this . copy . dispose ( ) ;
51+ }
52+ }
53+
1354/**
1455 * The Drag category.
1556 */
@@ -127,6 +168,21 @@ export const category = {
127168 </statement>
128169</block>` ,
129170 } ,
171+ {
172+ kind : 'BLOCK' ,
173+ type : 'drag_to_dupe' ,
174+ } ,
175+ {
176+ kind : 'BLOCK' ,
177+ type : 'text_print' ,
178+ inputs : {
179+ TEXT : {
180+ shadow : {
181+ type : 'drag_to_dupe' ,
182+ } ,
183+ } ,
184+ } ,
185+ } ,
130186 ] ,
131187} ;
132188
You can’t perform that action at this time.
0 commit comments