Skip to content

Commit

Permalink
Showing 14 changed files with 321 additions and 335 deletions.
358 changes: 179 additions & 179 deletions blockly_uncompressed.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Extensions');
goog.require('Blockly.fieldRegistry');
goog.require('Blockly.IASTNodeLocation');
goog.require('Blockly.IDeletable');
goog.require('Blockly.Input');
goog.require('Blockly.inputTypes');
goog.require('Blockly.Tooltip');
@@ -57,6 +58,7 @@ goog.requireType('Blockly.VariableModel');
* create a new ID.
* @constructor
* @implements {Blockly.IASTNodeLocation}
* @implements {Blockly.IDeletable}
* @throws When the prototypeName is not valid or not allowed.
*/
Blockly.Block = function(workspace, prototypeName, opt_id) {
10 changes: 5 additions & 5 deletions core/block_dragger.js
Original file line number Diff line number Diff line change
@@ -245,10 +245,10 @@ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) {
// Call drag enter/exit/over after wouldDeleteBlock is called in
// InsertionMarkerManager.update.
if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
oldDragTarget && oldDragTarget.onDragExit(this.draggingBlock_);
this.dragTarget_ && this.dragTarget_.onDragEnter(this.draggingBlock_);
}
this.dragTarget_ && this.dragTarget_.onDragOver();
this.dragTarget_ && this.dragTarget_.onDragOver(this.draggingBlock_);
};

/**
@@ -269,7 +269,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) {
Blockly.blockAnimations.disconnectUiStop();

var preventMove = !!this.dragTarget_ &&
this.dragTarget_.shouldPreventBlockMove(this.draggingBlock_);
this.dragTarget_.shouldPreventMove(this.draggingBlock_);
if (preventMove) {
var newLoc = this.startXY_;
} else {
@@ -279,7 +279,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) {
this.draggingBlock_.moveOffDragSurface(newLoc);

if (this.dragTarget_) {
this.dragTarget_.onBlockDrop(this.draggingBlock_);
this.dragTarget_.onDrop(this.draggingBlock_);
}

if (this.wouldDeleteBlock_) {
2 changes: 2 additions & 0 deletions core/block_svg.js
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ goog.require('Blockly.Events.Selected');
goog.require('Blockly.IASTNodeLocationSvg');
goog.require('Blockly.IBoundedElement');
goog.require('Blockly.ICopyable');
goog.require('Blockly.IDraggable');
goog.require('Blockly.Msg');
goog.require('Blockly.RenderedConnection');
goog.require('Blockly.TabNavigateCursor');
@@ -69,6 +70,7 @@ goog.requireType('Blockly.WorkspaceSvg');
* @implements {Blockly.IASTNodeLocationSvg}
* @implements {Blockly.IBoundedElement}
* @implements {Blockly.ICopyable}
* @implements {Blockly.IDraggable}
* @constructor
*/
Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
13 changes: 7 additions & 6 deletions core/bubble_dragger.js
Original file line number Diff line number Diff line change
@@ -144,11 +144,12 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
this.updateCursorDuringBubbleDrag_();
}

// Call drag enter/exit/over after wouldDeleteBlock is called in shouldDelete_
if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
oldDragTarget && oldDragTarget.onDragExit(this.draggingBubble_);
this.dragTarget_ && this.dragTarget_.onDragEnter(this.draggingBubble_);
}
this.dragTarget_ && this.dragTarget_.onDragOver();
this.dragTarget_ && this.dragTarget_.onDragOver(this.draggingBubble_);
};

/**
@@ -166,7 +167,7 @@ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
Blockly.ComponentManager.Capability.DELETE_AREA);
if (isDeleteArea) {
return (/** @type {!Blockly.IDeleteArea} */ (dragTarget))
.wouldDeleteBubble(this.draggingBubble_);
.wouldDelete(this.draggingBubble_, false);
}
}
return false;
@@ -194,7 +195,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function(
this.dragBubble(e, currentDragDeltaXY);

var preventMove = this.dragTarget_ &&
this.dragTarget_.shouldPreventBubbleMove(this.draggingBubble_);
this.dragTarget_.shouldPreventMove(this.draggingBubble_);
if (preventMove) {
var newLoc = this.startXY_;
} else {
@@ -205,7 +206,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function(
this.draggingBubble_.moveTo(newLoc.x, newLoc.y);

if (this.dragTarget_) {
this.dragTarget_.onBubbleDrop(this.draggingBubble_);
this.dragTarget_.onDrop(this.draggingBubble_);
}

if (this.wouldDeleteBubble_) {
38 changes: 17 additions & 21 deletions core/delete_area.js
Original file line number Diff line number Diff line change
@@ -14,9 +14,11 @@

goog.provide('Blockly.DeleteArea');

goog.require('Blockly.BlockSvg');
goog.require('Blockly.DragTarget');
goog.require('Blockly.IDeleteArea');

goog.requireType('Blockly.IDraggable');

/**
* Abstract class for a component that can delete a block or bubble that is
@@ -39,30 +41,24 @@ Blockly.DeleteArea = function() {
Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget);

/**
* Returns whether the provided block would be deleted if dropped on this area.
* This method should check if the block is deletable and is always called
* Returns whether the provided block or bubble would be deleted if dropped on
* this area.
* This method should check if the element is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.BlockSvg} block The block.
* @param {boolean} couldConnect Whether the block could could connect to
* @param {!Blockly.IDraggable} element The block or bubble currently being
* dragged.
* @param {boolean} couldConnect Whether the element could could connect to
* another.
* @return {boolean} Whether the block provided would be deleted if dropped on
* @return {boolean} Whether the element provided would be deleted if dropped on
* this area.
*/
Blockly.DeleteArea.prototype.wouldDeleteBlock = function(block, couldConnect) {
var couldDeleteBlock = !block.getParent() && block.isDeletable();
this.wouldDelete_ = couldDeleteBlock && !couldConnect;
return this.wouldDelete_;
};

/**
* Returns whether the provided bubble would be deleted if dropped on this area.
* This method should check if the bubble is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.IBubble} bubble The bubble.
* @return {boolean} Whether the bubble provided would be deleted if dropped on
* this area.
*/
Blockly.DeleteArea.prototype.wouldDeleteBubble = function(bubble) {
this.wouldDelete_ = bubble.isDeletable();
Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) {
if (element instanceof Blockly.BlockSvg) {
var block = /** @type {Blockly.BlockSvg} */ (element);
var couldDeleteBlock = !block.getParent() && block.isDeletable();
this.wouldDelete_ = couldDeleteBlock && !couldConnect;
} else {
this.wouldDelete_ = element.isDeletable();
}
return this.wouldDelete_;
};
60 changes: 23 additions & 37 deletions core/drag_target.js
Original file line number Diff line number Diff line change
@@ -16,8 +16,7 @@ goog.provide('Blockly.DragTarget');

goog.require('Blockly.IDragTarget');

goog.requireType('Blockly.BlockSvg');
goog.requireType('Blockly.IBubble');
goog.requireType('Blockly.IDraggable');
goog.requireType('Blockly.utils.Rect');


@@ -39,64 +38,51 @@ Blockly.DragTarget.prototype.getClientRect;

/**
* Handles when a cursor with a block or bubble enters this drag target.
* @param {!Blockly.IDraggable} _dragElement The block or bubble currently being
* dragged.
*/
Blockly.DragTarget.prototype.onDragEnter = function() {
Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) {
// no-op
};

/**
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
* @param {!Blockly.IDraggable} _dragElement The block or bubble currently being
* dragged.
*/
Blockly.DragTarget.prototype.onDragOver = function() {
Blockly.DragTarget.prototype.onDragOver = function(_dragElement) {
// no-op
};

/**
* Handles when a cursor with a block or bubble exits this drag target.
* @param {!Blockly.IDraggable} _dragElement The block or bubble currently being
* dragged.
*/
Blockly.DragTarget.prototype.onDragExit = function() {
Blockly.DragTarget.prototype.onDragExit = function(_dragElement) {
// no-op
};

/**
* Handles when a block is dropped on this component. Should not handle delete
* here.
* @param {!Blockly.BlockSvg} _block The block.
* Handles when a block or bubble is dropped on this component.
* Should not handle delete here.
* @param {!Blockly.IDraggable} _dragElement The block or bubble currently being
* dragged.
*/
Blockly.DragTarget.prototype.onBlockDrop = function(_block) {
Blockly.DragTarget.prototype.onDrop = function(_dragElement) {
// no-op
};

/**
* Handles when a bubble is dropped on this component. Should not handle delete
* here.
* @param {!Blockly.IBubble} _bubble The bubble.
* Returns whether the provided block or bubble should not be moved after being
* dropped on this component. If true, the element will return to where it was
* when the drag started.
* @param {!Blockly.IDraggable} _dragElement The block or bubble currently being
* dragged.
* @return {boolean} Whether the block or bubble provided should be returned to
* drag start.
*/
Blockly.DragTarget.prototype.onBubbleDrop = function(_bubble) {
// no-op
};

/**
* Returns whether the provided block should not be moved after being dropped
* on this component. If true, block will return to where it was when the drag
* started.
* @param {!Blockly.BlockSvg} _block The block.
* @return {boolean} Whether the block provided should be returned to drag
* start.
*/
Blockly.DragTarget.prototype.shouldPreventBlockMove = function(_block) {
return false;
};

/**
* Returns whether the provided bubble should not be moved after being dropped
* on this component. If true, bubble will return to where it was when the drag
* started.
* @param {!Blockly.IBubble} _bubble The bubble.
* @return {boolean} Whether the bubble provided should be returned to drag
* start.
*/
Blockly.DragTarget.prototype.shouldPreventBubbleMove = function(_bubble) {
Blockly.DragTarget.prototype.shouldPreventMove = function(_dragElement) {
return false;
};
2 changes: 1 addition & 1 deletion core/insertion_marker_manager.js
Original file line number Diff line number Diff line change
@@ -463,7 +463,7 @@ Blockly.InsertionMarkerManager.prototype.shouldDelete_ = function(
if (isDeleteArea) {
return (
/** @type {!Blockly.IDeleteArea} */ (dragTarget))
.wouldDeleteBlock(this.topBlock_, candidate && !!candidate.closest);
.wouldDelete(this.topBlock_, candidate && !!candidate.closest);
}
}
return false;
4 changes: 2 additions & 2 deletions core/interfaces/i_bubble.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
goog.provide('Blockly.IBubble');

goog.require('Blockly.IContextMenu');
goog.require('Blockly.IDeletable');
goog.require('Blockly.IDraggable');

goog.requireType('Blockly.BlockDragSurfaceSvg');
goog.requireType('Blockly.utils.Coordinate');
@@ -23,7 +23,7 @@ goog.requireType('Blockly.utils.Coordinate');
/**
* A bubble interface.
* @interface
* @extends {Blockly.IDeletable}
* @extends {Blockly.IDraggable}
* @extends {Blockly.IContextMenu}
*/
Blockly.IBubble = function() {};
27 changes: 9 additions & 18 deletions core/interfaces/i_delete_area.js
Original file line number Diff line number Diff line change
@@ -16,8 +16,7 @@ goog.provide('Blockly.IDeleteArea');

goog.require('Blockly.IDragTarget');

goog.requireType('Blockly.BlockSvg');
goog.requireType('Blockly.IBubble');
goog.requireType('Blockly.IDraggable');


/**
@@ -29,23 +28,15 @@ goog.requireType('Blockly.IBubble');
Blockly.IDeleteArea = function() {};

/**
* Returns whether the provided block would be deleted if dropped on this area.
* This method should check if the block is deletable and is always called
* Returns whether the provided block or bubble would be deleted if dropped on
* this area.
* This method should check if the element is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.BlockSvg} block The block.
* @param {boolean} couldConnect Whether the block could could connect to
* @param {!Blockly.IDraggable} element The block or bubble currently being
* dragged.
* @param {boolean} couldConnect Whether the element could could connect to
* another.
* @return {boolean} Whether the block provided would be deleted if dropped on
* @return {boolean} Whether the element provided would be deleted if dropped on
* this area.
*/
Blockly.IDeleteArea.prototype.wouldDeleteBlock;

/**
* Returns whether the provided bubble would be deleted if dropped on this area.
* This method should check if the bubble is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.IBubble} bubble The bubble.
* @return {boolean} Whether the bubble provided would be deleted if dropped on
* this area.
*/
Blockly.IDeleteArea.prototype.wouldDeleteBubble;
Blockly.IDeleteArea.prototype.wouldDelete;
Loading

0 comments on commit a17cb7f

Please sign in to comment.