Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add test block that duplicates on drag #2377

Merged
merged 1 commit into from
May 31, 2024
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 [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) {

Check warning on line 26 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
this.block = block;
}

isMovable() {

Check warning on line 30 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
return true;
}

startDrag(e) {

Check warning on line 34 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
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) {

Check warning on line 41 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
this.baseStrat.drag(e);
}

endDrag(e) {

Check warning on line 45 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
this.baseStrat.endDrag(e);
}

revertDrag(e) {

Check warning on line 49 in plugins/block-test/src/drag.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc comment
this.copy.dispose();
}
}

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

Expand Down
Loading