Skip to content

Commit b08fd71

Browse files
authored
chore: add test block that duplicates on drag (#2377)
1 parent 6bf755b commit b08fd71

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

plugins/block-test/src/drag.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,47 @@
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

0 commit comments

Comments
 (0)