Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions plugins/block-test/src/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@
* @author samelh@google.com (Sam El-Husseini)
*/

import * as Blockly from 'blockly/core';

/** Block that duplicates itself on drag. */
Blockly.Blocks['drag_to_dupe'] = {
init: function () {
this.setOutput(true, null);
this.appendDummyInput().appendField('drag to dupe');
this.setDragStrategy(new DragToDupe(this));
},
};

/** Drag strategy that duplicates the block on drag. */
class DragToDupe {
constructor(block) {
this.block = block;
}

isMovable() {
return true;
}

startDrag(e) {
const data = this.block.toCopyData();
this.copy = Blockly.clipboard.paste(data, this.block.workspace);
this.baseStrat = new Blockly.dragging.BlockDragStrategy(this.copy);
this.baseStrat.startDrag(e);
}

drag(e) {
this.baseStrat.drag(e);
}

endDrag(e) {
this.baseStrat.endDrag(e);
}

revertDrag(e) {
this.copy.dispose();
}
}

/**
* The Drag category.
*/
Expand Down Expand Up @@ -127,6 +168,21 @@ export const category = {
</statement>
</block>`,
},
{
kind: 'BLOCK',
type: 'drag_to_dupe',
},
{
kind: 'BLOCK',
type: 'text_print',
inputs: {
TEXT: {
shadow: {
type: 'drag_to_dupe',
},
},
},
},
],
};

Expand Down