From fe4b3d3c01b03b1f5bd5843c451346a9232f1b4d Mon Sep 17 00:00:00 2001 From: DD Date: Mon, 12 Feb 2018 10:25:42 -0500 Subject: [PATCH] Pass through block drag event --- src/engine/blocks.js | 10 ++++++++++ src/engine/runtime.js | 17 +++++++++++++++++ src/virtual-machine.js | 3 +++ 3 files changed, 30 insertions(+) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 1b0070bf5..2e62e2f3e 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -288,6 +288,16 @@ class Blocks { newCoordinate: e.newCoordinate }); break; + case 'drag': + if (optRuntime) { + optRuntime.emitBlockDragUpdate(e.isOutside); + } + break; + case 'endDrag': + if (optRuntime) { + optRuntime.emitBlockDragUpdate(false /* areBlocksOverGui */); + } + break; case 'delete': // Don't accept delete events for missing blocks, // or shadow blocks being obscured. diff --git a/src/engine/runtime.js b/src/engine/runtime.js index aded2ccfb..621c7bd7a 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -379,6 +379,15 @@ class Runtime extends EventEmitter { return 'MONITORS_UPDATE'; } + /** + * Event name for block drag update. + * @const {string} + */ + static get BLOCK_DRAG_UPDATE () { + return 'BLOCK_DRAG_UPDATE'; + } + + /** * Event name for reporting that an extension was added. * @const {string} @@ -1387,6 +1396,14 @@ class Runtime extends EventEmitter { } } + /** + * Emit whether blocks are being dragged over gui + * @param {boolean} areBlocksOverGui True if blocks are dragged out of blocks workspace, false otherwise + */ + emitBlockDragUpdate (areBlocksOverGui) { + this.emit(Runtime.BLOCK_DRAG_UPDATE, areBlocksOverGui); + } + /** * Emit value for reporter to show in the blocks. * @param {string} blockId ID for the block. diff --git a/src/virtual-machine.js b/src/virtual-machine.js index d930ad534..f33f6fb92 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -74,6 +74,9 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.MONITORS_UPDATE, monitorList => { this.emit(Runtime.MONITORS_UPDATE, monitorList); }); + this.runtime.on(Runtime.BLOCK_DRAG_UPDATE, areBlocksOverGui => { + this.emit(Runtime.BLOCK_DRAG_UPDATE, areBlocksOverGui); + }); this.runtime.on(Runtime.EXTENSION_ADDED, blocksInfo => { this.emit(Runtime.EXTENSION_ADDED, blocksInfo); });