From 637497148d49fceabdd11a7c8c93f561bc28db4f Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Thu, 5 Nov 2020 11:40:17 -0800 Subject: [PATCH] Renaming ui event properties and updating documentation for consistency (#4432) * Renaming properties and updating documentation for consistency * Update more properties * fix tests --- blockly_uncompressed.js | 6 ++-- core/block_dragger.js | 6 ++-- core/events/events.js | 4 +-- .../{events_drag.js => events_block_drag.js} | 27 +++++++------- core/events/events_bubble_open.js | 15 ++++---- core/events/events_click.js | 13 +++---- core/events/events_marker_move.js | 14 ++++---- core/events/events_selected.js | 12 +++---- ...elect.js => events_toolbox_item_select.js} | 4 +-- core/events/events_trashcan_open.js | 6 ++-- core/events/events_viewport.js | 8 +++-- core/gesture.js | 6 ++-- tests/mocha/comment_test.js | 8 ++--- tests/mocha/event_test.js | 36 +++++++++---------- tests/mocha/gesture_test.js | 2 +- 15 files changed, 85 insertions(+), 82 deletions(-) rename core/events/{events_drag.js => events_block_drag.js} (64%) rename core/events/{events_toolbox_select.js => events_toolbox_item_select.js} (96%) diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 87104b08d..4eb0ec28c 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -24,7 +24,7 @@ this.BLOCKLY_BOOT = function(root) { goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.navigation', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.deprecation', 'Blockly.utils.object', 'Blockly.utils.string'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Drag', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {}); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.constants', 'Blockly.navigation', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {}); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.Events', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.constants', 'Blockly.inject', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour'], {}); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {}); @@ -43,13 +43,13 @@ goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Block goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml'], {}); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils'], {}); goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events'], {}); +goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); -goog.addDependency('../../core/events/events_drag.js', ['Blockly.Events.Drag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Selected'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); -goog.addDependency('../../core/events/events_toolbox_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); +goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {}); goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Blockly.Events.UiBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {}); diff --git a/core/block_dragger.js b/core/block_dragger.js index ef55a2be1..34a97b1ab 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -16,7 +16,7 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.Events.Drag'); +goog.require('Blockly.Events.BlockDrag'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -184,7 +184,7 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, * @private */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { - var event = new Blockly.Events.Drag(this.draggingBlock_, true, + var event = new Blockly.Events.BlockDrag(this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -261,7 +261,7 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { * @private */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { - var event = new Blockly.Events.Drag(this.draggingBlock_, false, + var event = new Blockly.Events.BlockDrag(this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; diff --git a/core/events/events.js b/core/events/events.js index 36469840a..9ba9f579d 100644 --- a/core/events/events.js +++ b/core/events/events.js @@ -149,10 +149,10 @@ Blockly.Events.BUBBLE_OPEN = 'bubble_open'; Blockly.Events.TRASHCAN_OPEN = 'trashcan_open'; /** - * Name of event that records a toolbox item change. + * Name of event that records a toolbox item select. * @const */ -Blockly.Events.TOOLBOX_ITEM_CHANGE = 'toolbox_item_change'; +Blockly.Events.TOOLBOX_ITEM_SELECT = 'toolbox_item_select'; /** * Name of event that records a theme change. diff --git a/core/events/events_drag.js b/core/events/events_block_drag.js similarity index 64% rename from core/events/events_drag.js rename to core/events/events_block_drag.js index 07d7f6198..2b36c308f 100644 --- a/core/events/events_drag.js +++ b/core/events/events_block_drag.js @@ -10,7 +10,7 @@ */ 'use strict'; -goog.provide('Blockly.Events.Drag'); +goog.provide('Blockly.Events.BlockDrag'); goog.require('Blockly.Events'); goog.require('Blockly.Events.UiBase'); @@ -18,46 +18,47 @@ goog.require('Blockly.registry'); goog.require('Blockly.utils.object'); /** - * Class for a click event. + * Class for a block drag event. * @param {!Blockly.Block=} opt_block The top block in the stack that is being * dragged. Undefined for a blank event. * @param {boolean=} opt_isStart Whether this is the start of a block drag. + * Undefined for a blank event. * @param {!Array.=} opt_blocks The blocks affected by this * drag. Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ -Blockly.Events.Drag = function(opt_block, opt_isStart, opt_blocks) { +Blockly.Events.BlockDrag = function(opt_block, opt_isStart, opt_blocks) { var workspaceId = opt_block ? opt_block.workspace.id : undefined; - Blockly.Events.Drag.superClass_.constructor.call(this, workspaceId); + Blockly.Events.BlockDrag.superClass_.constructor.call(this, workspaceId); this.blockId = opt_block ? opt_block.id : null; /** - * Whether this is the start of a block drag. Undefined for blank event + * Whether this is the start of a block drag. * @type {boolean|undefined} */ this.isStart = opt_isStart; /** - * The blocks affected by this drag event. Undefined for blank event + * The blocks affected by this drag event. * @type {!Array.|undefined} */ this.blocks = opt_blocks; }; -Blockly.utils.object.inherits(Blockly.Events.Drag, Blockly.Events.UiBase); +Blockly.utils.object.inherits(Blockly.Events.BlockDrag, Blockly.Events.UiBase); /** * Type of this event. * @type {string} */ -Blockly.Events.Drag.prototype.type = Blockly.Events.BLOCK_DRAG; +Blockly.Events.BlockDrag.prototype.type = Blockly.Events.BLOCK_DRAG; /** * Encode the event as JSON. * @return {!Object} JSON representation. */ -Blockly.Events.Drag.prototype.toJson = function() { - var json = Blockly.Events.Drag.superClass_.toJson.call(this); +Blockly.Events.BlockDrag.prototype.toJson = function() { + var json = Blockly.Events.BlockDrag.superClass_.toJson.call(this); json['isStart'] = this.isStart; json['blockId'] = this.blockId; json['blocks'] = this.blocks; @@ -68,12 +69,12 @@ Blockly.Events.Drag.prototype.toJson = function() { * Decode the JSON event. * @param {!Object} json JSON representation. */ -Blockly.Events.Drag.prototype.fromJson = function(json) { - Blockly.Events.Drag.superClass_.fromJson.call(this, json); +Blockly.Events.BlockDrag.prototype.fromJson = function(json) { + Blockly.Events.BlockDrag.superClass_.fromJson.call(this, json); this.isStart = json['isStart']; this.blockId = json['blockId']; this.blocks = json['blocks']; }; Blockly.registry.register(Blockly.registry.Type.EVENT, - Blockly.Events.BLOCK_DRAG, Blockly.Events.Drag); + Blockly.Events.BLOCK_DRAG, Blockly.Events.BlockDrag); diff --git a/core/events/events_bubble_open.js b/core/events/events_bubble_open.js index 4f276f2f2..fa6b99e13 100644 --- a/core/events/events_bubble_open.js +++ b/core/events/events_bubble_open.js @@ -21,13 +21,14 @@ goog.require('Blockly.utils.object'); * Class for a bubble open event. * @param {Blockly.BlockSvg} opt_block The associated block. Undefined for a * blank event. - * @param {boolean=} opt_isOpen Whether the bubble is opening (false if closing). - * @param {string=} opt_element The type of bubble. One of 'mutator', 'comment' - * or 'warning' + * @param {boolean=} opt_isOpen Whether the bubble is opening (false if + * closing). Undefined for a blank event. + * @param {string=} opt_bubbleType The type of bubble. One of 'mutator', 'comment' + * or 'warning'. Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ -Blockly.Events.BubbleOpen = function(opt_block, opt_isOpen, opt_element) { +Blockly.Events.BubbleOpen = function(opt_block, opt_isOpen, opt_bubbleType) { var workspaceId = opt_block ? opt_block.workspace.id : undefined; Blockly.Events.BubbleOpen.superClass_.constructor.call(this, workspaceId); this.blockId = opt_block ? opt_block.id : null; @@ -42,7 +43,7 @@ Blockly.Events.BubbleOpen = function(opt_block, opt_isOpen, opt_element) { * The type of bubble. One of 'mutator', 'comment', or 'warning'. * @type {string|undefined} */ - this.element = opt_element; + this.bubbleType = opt_bubbleType; }; Blockly.utils.object.inherits(Blockly.Events.BubbleOpen, Blockly.Events.UiBase); @@ -59,7 +60,7 @@ Blockly.Events.BubbleOpen.prototype.type = Blockly.Events.BUBBLE_OPEN; Blockly.Events.BubbleOpen.prototype.toJson = function() { var json = Blockly.Events.BubbleOpen.superClass_.toJson.call(this); json['isOpen'] = this.isOpen; - json['element'] = this.element; + json['bubbleType'] = this.bubbleType; json['blockId'] = this.blockId; return json; }; @@ -71,7 +72,7 @@ Blockly.Events.BubbleOpen.prototype.toJson = function() { Blockly.Events.BubbleOpen.prototype.fromJson = function(json) { Blockly.Events.BubbleOpen.superClass_.fromJson.call(this, json); this.isOpen = json['isOpen']; - this.element = json['element']; + this.bubbleType = json['bubbleType']; this.blockId = json['blockId']; }; diff --git a/core/events/events_click.js b/core/events/events_click.js index d5c355906..3b4766bf2 100644 --- a/core/events/events_click.js +++ b/core/events/events_click.js @@ -20,11 +20,12 @@ goog.require('Blockly.utils.object'); /** * Class for a click event. * @param {?Blockly.Block=} opt_block The affected block. Null for click events - * that do not have an associated block (i.e. workspace click). Undefined - * for a blank event. - * @param {string=} opt_workspaceId The workspace identifier for this event. + * that do not have an associated block (i.e. workspace click). Undefined + * for a blank event. + * @param {?string=} opt_workspaceId The workspace identifier for this event. + * Not used if block is passed. Undefined for a blank event. * @param {string=} opt_targetType The type of element targeted by this click - * event. + * event. Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ @@ -33,10 +34,6 @@ Blockly.Events.Click = function(opt_block, opt_workspaceId, opt_targetType) { Blockly.Events.Click.superClass_.constructor.call(this, workspaceId); this.blockId = opt_block ? opt_block.id : null; - if (!opt_targetType && !this.isBlank) { - opt_targetType = opt_block ? 'block' : 'workspace'; - } - /** * The type of element targeted by this click event. * @type {string|undefined} diff --git a/core/events/events_marker_move.js b/core/events/events_marker_move.js index 08bbe2c1d..d18872c39 100644 --- a/core/events/events_marker_move.js +++ b/core/events/events_marker_move.js @@ -25,17 +25,17 @@ goog.require('Blockly.utils.object'); * blank event. * @param {?Blockly.ASTNode=} opt_oldNode The old node the marker used to be on. * Undefined for a blank event. - * @param {!Blockly.ASTNode=} opt_curNode The new node the marker is now on. + * @param {!Blockly.ASTNode=} opt_newNode The new node the marker is now on. * Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ Blockly.Events.MarkerMove = function(opt_block, isCursor, opt_oldNode, - opt_curNode) { + opt_newNode) { var workspaceId = opt_block ? opt_block.workspace.id : undefined; - if (opt_curNode && opt_curNode.getType() == Blockly.ASTNode.types.WORKSPACE) { + if (opt_newNode && opt_newNode.getType() == Blockly.ASTNode.types.WORKSPACE) { workspaceId = - (/** @type {!Blockly.Workspace} */ (opt_curNode.getLocation())).id; + (/** @type {!Blockly.Workspace} */ (opt_newNode.getLocation())).id; } Blockly.Events.MarkerMove.superClass_.constructor.call(this, workspaceId); @@ -55,7 +55,7 @@ Blockly.Events.MarkerMove = function(opt_block, isCursor, opt_oldNode, * The new node the marker is now on. * @type {Blockly.ASTNode|undefined} */ - this.curNode = opt_curNode; + this.newNode = opt_newNode; /** * Whether this is a cursor event. @@ -80,7 +80,7 @@ Blockly.Events.MarkerMove.prototype.toJson = function() { json['isCursor'] = this.isCursor; json['blockId'] = this.blockId; json['oldNode'] = this.oldNode; - json['curNode'] = this.curNode; + json['newNode'] = this.newNode; return json; }; @@ -93,7 +93,7 @@ Blockly.Events.MarkerMove.prototype.fromJson = function(json) { this.isCursor = json['isCursor']; this.blockId = json['blockId']; this.oldNode = json['oldNode']; - this.curNode = json['curNode']; + this.newNode = json['newNode']; }; Blockly.registry.register(Blockly.registry.Type.EVENT, diff --git a/core/events/events_selected.js b/core/events/events_selected.js index bec0f55d2..089885425 100644 --- a/core/events/events_selected.js +++ b/core/events/events_selected.js @@ -18,17 +18,17 @@ goog.require('Blockly.registry'); goog.require('Blockly.utils.object'); /** - * Class for a Selected event. + * Class for a selected event. * @param {?string=} opt_oldElementId The id of the previously selected * element. Null if no element last selected. Undefined for a blank event. - * @param {?string=} opt_elementId The id of the selected element. Null if no + * @param {?string=} opt_newElementId The id of the selected element. Null if no * element currently selected (deselect). Undefined for a blank event. * @param {string=} opt_workspaceId The workspace identifier for this event. * Null if no element previously selected. Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ -Blockly.Events.Selected = function(opt_oldElementId, opt_elementId, +Blockly.Events.Selected = function(opt_oldElementId, opt_newElementId, opt_workspaceId) { Blockly.Events.Selected.superClass_.constructor.call(this, opt_workspaceId); @@ -42,7 +42,7 @@ Blockly.Events.Selected = function(opt_oldElementId, opt_elementId, * The id of the selected element. * @type {?string|undefined} */ - this.elementId = opt_elementId; + this.newElementId = opt_newElementId; }; Blockly.utils.object.inherits(Blockly.Events.Selected, Blockly.Events.UiBase); @@ -59,7 +59,7 @@ Blockly.Events.Selected.prototype.type = Blockly.Events.SELECTED; Blockly.Events.Selected.prototype.toJson = function() { var json = Blockly.Events.Selected.superClass_.toJson.call(this); json['oldElementId'] = this.oldElementId; - json['elementId'] = this.elementId; + json['newElementId'] = this.newElementId; return json; }; @@ -70,7 +70,7 @@ Blockly.Events.Selected.prototype.toJson = function() { Blockly.Events.Selected.prototype.fromJson = function(json) { Blockly.Events.Selected.superClass_.fromJson.call(this, json); this.oldElementId = json['oldElementId']; - this.elementId = json['elementId']; + this.newElementId = json['newElementId']; }; Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.SELECTED, diff --git a/core/events/events_toolbox_select.js b/core/events/events_toolbox_item_select.js similarity index 96% rename from core/events/events_toolbox_select.js rename to core/events/events_toolbox_item_select.js index d20d4288d..9f7226369 100644 --- a/core/events/events_toolbox_select.js +++ b/core/events/events_toolbox_item_select.js @@ -51,7 +51,7 @@ Blockly.utils.object.inherits(Blockly.Events.ToolboxItemSelect, Blockly.Events.U * Type of this event. * @type {string} */ -Blockly.Events.ToolboxItemSelect.prototype.type = Blockly.Events.TOOLBOX_ITEM_CHANGE; +Blockly.Events.ToolboxItemSelect.prototype.type = Blockly.Events.TOOLBOX_ITEM_SELECT; /** * Encode the event as JSON. @@ -75,4 +75,4 @@ Blockly.Events.ToolboxItemSelect.prototype.fromJson = function(json) { }; Blockly.registry.register(Blockly.registry.Type.EVENT, - Blockly.Events.TOOLBOX_ITEM_CHANGE, Blockly.Events.ToolboxItemSelect); + Blockly.Events.TOOLBOX_ITEM_SELECT, Blockly.Events.ToolboxItemSelect); diff --git a/core/events/events_trashcan_open.js b/core/events/events_trashcan_open.js index 0ec08c674..7567de0c4 100644 --- a/core/events/events_trashcan_open.js +++ b/core/events/events_trashcan_open.js @@ -19,8 +19,8 @@ goog.require('Blockly.utils.object'); /** * Class for a trashcan open event. - * @param {boolean=} opt_isOpen Whether the trashcan flyout is open. Undefined - * for a blank event. + * @param {boolean=} opt_isOpen Whether the trashcan flyout is opening (false if + * opening). Undefined for a blank event. * @param {string=} opt_workspaceId The workspace identifier for this event. * Undefined for a blank event. * @extends {Blockly.Events.UiBase} @@ -30,7 +30,7 @@ Blockly.Events.TrashcanOpen = function(opt_isOpen, opt_workspaceId) { Blockly.Events.TrashcanOpen.superClass_.constructor.call(this, opt_workspaceId); /** - * Whether the trashcan flyout is open. + * Whether the trashcan flyout is opening (false if closing). * @type {boolean|undefined} */ this.isOpen = opt_isOpen; diff --git a/core/events/events_viewport.js b/core/events/events_viewport.js index 0086074ac..744ec2d8d 100644 --- a/core/events/events_viewport.js +++ b/core/events/events_viewport.js @@ -20,11 +20,13 @@ goog.require('Blockly.utils.object'); /** * Class for a viewport change event. * @param {number=} opt_top Top-edge of the visible portion of the workspace, - * relative to the workspace origin. + * relative to the workspace origin. Undefined for a blank event. * @param {number=} opt_left Left-edge of the visible portion of the workspace, - * relative to the workspace origin. - * @param {number=} opt_scale The scale of the workspace. + * relative to the workspace origin. Undefined for a blank event. + * @param {number=} opt_scale The scale of the workspace. Undefined for a blank + * event. * @param {string=} opt_workspaceId The workspace identifier for this event. + * Undefined for a blank event. * @extends {Blockly.Events.UiBase} * @constructor */ diff --git a/core/gesture.js b/core/gesture.js index 9c0ee71e7..30a1faa5e 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -665,7 +665,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @private */ Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { - var clickEvent = new Blockly.Events.Click(null, ws.id); + var clickEvent = new Blockly.Events.Click(null, ws.id, 'workspace'); Blockly.Events.fire(clickEvent); }; @@ -756,7 +756,9 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { } } else { // Clicks events are on the start block, even if it was a shadow. - Blockly.Events.fire(new Blockly.Events.Click(this.startBlock_)); + var event = new Blockly.Events.Click( + this.startBlock_, this.startWorkspace_.id, 'block'); + Blockly.Events.fire(event); } this.bringBlockToFront_(); Blockly.Events.setGroup(false); diff --git a/tests/mocha/comment_test.js b/tests/mocha/comment_test.js index bbd3ad9c9..5cedf6709 100644 --- a/tests/mocha/comment_test.js +++ b/tests/mocha/comment_test.js @@ -49,7 +49,7 @@ suite('Comments', function() { assertEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {element: 'comment', isOpen: true}, this.workspace.id, + {bubbleType: 'comment', isOpen: true}, this.workspace.id, this.block.id); }); test('Not Editable', function() { @@ -64,7 +64,7 @@ suite('Comments', function() { assertNotEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {element: 'comment', isOpen: true}, this.workspace.id, + {bubbleType: 'comment', isOpen: true}, this.workspace.id, this.block.id); }); test('Editable -> Not Editable', function() { @@ -80,7 +80,7 @@ suite('Comments', function() { assertNotEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {element: 'comment', isOpen: true}, this.workspace.id, + {bubbleType: 'comment', isOpen: true}, this.workspace.id, this.block.id); }); test('Not Editable -> Editable', function() { @@ -98,7 +98,7 @@ suite('Comments', function() { assertEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {element: 'comment', isOpen: true}, this.workspace.id, + {bubbleType: 'comment', isOpen: true}, this.workspace.id, this.block.id); }); }); diff --git a/tests/mocha/event_test.js b/tests/mocha/event_test.js index c212a7366..41c6bc132 100644 --- a/tests/mocha/event_test.js +++ b/tests/mocha/event_test.js @@ -64,7 +64,7 @@ suite('Events', function() { }); test('Click without block', function() { - var event = new Blockly.Events.Click(null, this.workspace.id); + var event = new Blockly.Events.Click(null, this.workspace.id, 'workspace'); assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id, null, { 'targetType': 'workspace', 'recordUndo': false, @@ -170,7 +170,7 @@ suite('Events', function() { test('Click with block', function() { var TEST_GROUP_ID = 'testGroup'; Blockly.Events.setGroup(TEST_GROUP_ID); - var event = new Blockly.Events.Click(this.block); + var event = new Blockly.Events.Click(this.block, null, 'block'); assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id, this.TEST_BLOCK_ID, { 'targetType': 'block', @@ -473,20 +473,20 @@ suite('Events', function() { {title: 'Bubble open', class: Blockly.Events.BubbleOpen, getArgs: (thisObj) => [thisObj.block, true, 'mutator'], getExpectedJson: (thisObj) => ({type: 'bubble_open', isOpen: true, - element: 'mutator', blockId: thisObj.block.id})}, + bubbleType: 'mutator', blockId: thisObj.block.id})}, {title: 'Block click', class: Blockly.Events.Click, - getArgs: (thisObj) => [thisObj.block], + getArgs: (thisObj) => [thisObj.block, null, 'block'], getExpectedJson: (thisObj) => ({type: 'click', targetType: 'block', blockId: thisObj.block.id})}, {title: 'Workspace click', class: Blockly.Events.Click, - getArgs: (thisObj) => [null, thisObj.workspace.id], + getArgs: (thisObj) => [null, thisObj.workspace.id, 'workspace'], getExpectedJson: (thisObj) => ({type: 'click', targetType: 'workspace'})}, - {title: 'Drag start', class: Blockly.Events.Drag, + {title: 'Drag start', class: Blockly.Events.BlockDrag, getArgs: (thisObj) => [thisObj.block, true, [thisObj.block]], getExpectedJson: (thisObj) => ({type: 'drag', isStart: true, blockId: thisObj.block.id, blocks: [thisObj.block]})}, - {title: 'Drag end', class: Blockly.Events.Drag, + {title: 'Drag end', class: Blockly.Events.BlockDrag, getArgs: (thisObj) => [thisObj.block, false, [thisObj.block]], getExpectedJson: (thisObj) => ({type: 'drag', isStart: false, blockId: thisObj.block.id, blocks: [thisObj.block]})}, @@ -495,7 +495,7 @@ suite('Events', function() { new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, thisObj.block)], getExpectedJson: (thisObj) => ({type: 'marker_move', isCursor: true, blockId: thisObj.block.id, oldNode: null, - curNode: new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, + newNode: new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, thisObj.block)})}, {title: 'null to Workspace Marker move', class: Blockly.Events.MarkerMove, getArgs: (thisObj) => [null, true, null, @@ -503,7 +503,7 @@ suite('Events', function() { new Blockly.utils.Coordinate(0, 0))], getExpectedJson: (thisObj) => ({type: 'marker_move', isCursor: true, blockId: null, oldNode: null, - curNode: Blockly.ASTNode.createWorkspaceNode(thisObj.workspace, + newNode: Blockly.ASTNode.createWorkspaceNode(thisObj.workspace, new Blockly.utils.Coordinate(0, 0))})}, {title: 'Workspace to Block Marker move', class: Blockly.Events.MarkerMove, @@ -515,7 +515,7 @@ suite('Events', function() { isCursor: true, blockId: thisObj.block.id, oldNode: Blockly.ASTNode.createWorkspaceNode(thisObj.workspace, new Blockly.utils.Coordinate(0, 0)), - curNode: new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, + newNode: new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, thisObj.block)})}, {title: 'Block to Workspace Marker move', class: Blockly.Events.MarkerMove, @@ -526,28 +526,28 @@ suite('Events', function() { {title: 'Selected', class: Blockly.Events.Selected, getArgs: (thisObj) => [null, thisObj.block.id, thisObj.workspace.id], getExpectedJson: (thisObj) => ({type: 'selected', oldElementId: null, - elementId: thisObj.block.id})}, + newElementId: thisObj.block.id})}, {title: 'Selected (deselect)', class: Blockly.Events.Selected, getArgs: (thisObj) => [thisObj.block.id, null, thisObj.workspace.id], getExpectedJson: (thisObj) => ({type: 'selected', - oldElementId: thisObj.block.id, elementId: null})}, + oldElementId: thisObj.block.id, newElementId: null})}, {title: 'Theme Change', class: Blockly.Events.ThemeChange, getArgs: (thisObj) => ['classic', thisObj.workspace.id], getExpectedJson: () => ({type: 'theme_change', themeName: 'classic'})}, {title: 'Toolbox item select', class: Blockly.Events.ToolboxItemSelect, getArgs: (thisObj) => ['Math', 'Loops', thisObj.workspace.id], - getExpectedJson: () => ({type: 'toolbox_item_change', oldItem: 'Math', + getExpectedJson: () => ({type: 'toolbox_item_select', oldItem: 'Math', newItem: 'Loops'})}, {title: 'Toolbox item select (no previous)', class: Blockly.Events.ToolboxItemSelect, getArgs: (thisObj) => [null, 'Loops', thisObj.workspace.id], - getExpectedJson: () => ({type: 'toolbox_item_change', oldItem: null, + getExpectedJson: () => ({type: 'toolbox_item_select', oldItem: null, newItem: 'Loops'})}, {title: 'Toolbox item select (deselect)', class: Blockly.Events.ToolboxItemSelect, getArgs: (thisObj) => ['Math', null, thisObj.workspace.id], - getExpectedJson: () => ({type: 'toolbox_item_change', oldItem: 'Math', + getExpectedJson: () => ({type: 'toolbox_item_select', oldItem: 'Math', newItem: null})}, {title: 'Trashcan open', class: Blockly.Events.TrashcanOpen, getArgs: (thisObj) => [true, thisObj.workspace.id], @@ -893,9 +893,9 @@ suite('Events', function() { chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen); chai.assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BubbleOpen); chai.assert.isTrue(filteredEvents[2] instanceof Blockly.Events.BubbleOpen); - chai.assert.equal(filteredEvents[0].element, 'comment'); - chai.assert.equal(filteredEvents[1].element, 'mutator'); - chai.assert.equal(filteredEvents[2].element, 'warning'); + chai.assert.equal(filteredEvents[0].bubbleType, 'comment'); + chai.assert.equal(filteredEvents[1].bubbleType, 'mutator'); + chai.assert.equal(filteredEvents[2].bubbleType, 'warning'); }); test('Colliding events not dropped', function() { diff --git a/tests/mocha/gesture_test.js b/tests/mocha/gesture_test.js index 438c58f52..71c84cbe2 100644 --- a/tests/mocha/gesture_test.js +++ b/tests/mocha/gesture_test.js @@ -35,7 +35,7 @@ suite('Gesture', function() { assertEventFired(eventsFireStub, Blockly.Events.Selected, - {oldElementId: null, elementId: block.id}, fieldWorkspace.id); + {oldElementId: null, newElementId: block.id}, fieldWorkspace.id); assertEventNotFired(eventsFireStub, Blockly.Events.Click, {}); }