Skip to content

Commit

Permalink
chore: add test block that duplicates on drag (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega authored May 31, 2024
1 parent 6bf755b commit b08fd71
Showing 1 changed file with 56 additions and 0 deletions.
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 [email protected] (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

0 comments on commit b08fd71

Please sign in to comment.