From 29fb7b78930d82619f54dff120c18324750abfe2 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 12 Jan 2022 09:29:30 -0800 Subject: [PATCH] refactor: convert leaf event classes to es6 classes (#5870) * chore(tests): update event assert functions to pass in types directly * refactor: move event types from prototypes to constructors * refactor: convert events/events_block_change.js to ES6 class * refactor: convert events/events_block_create.js to ES6 class * refactor: convert events/events_block_delete.js to ES6 class * refactor: convert events/events_block_drag.js to ES6 class * refactor: convert events/events_block_move.js to ES6 class * refactor: convert events/events_click.js to ES6 class * refactor: convert events/events_comment_change.js to ES6 class * refactor: convert events/events_comment_create.js to ES6 class * refactor: convert events/events_comment_delete.js to ES6 class * refactor: convert events/events_comment_move.js to ES6 class * refactor: convert events/events_marker_move.js to ES6 class * refactor: convert events/events_selected.js to ES6 class * refactor: convert events/events_theme_change.js to ES6 class * refactor: convert events/events_toolbox_item_select.js to ES6 class * refactor: convert events/events_trashcan_open.js to ES6 class * refactor: convert events/events_ui.js to ES6 class * refactor: convert events/events_var_create.js to ES6 class * refactor: convert events/events_var_delete.js to ES6 class * refactor: convert events/events_var_rename.js to ES6 class * refactor: convert events/events_viewport.js to ES6 class * chore: rebuild * chore: run clang-format --- core/events/events_abstract.js | 12 +- core/events/events_block_change.js | 267 +++++++++---------- core/events/events_block_create.js | 146 ++++++----- core/events/events_block_delete.js | 180 ++++++------- core/events/events_block_drag.js | 101 ++++---- core/events/events_block_move.js | 303 +++++++++++----------- core/events/events_bubble_open.js | 12 +- core/events/events_click.js | 96 +++---- core/events/events_comment_change.js | 134 +++++----- core/events/events_comment_create.js | 90 +++---- core/events/events_comment_delete.js | 86 +++--- core/events/events_comment_move.js | 220 ++++++++-------- core/events/events_marker_move.js | 135 +++++----- core/events/events_selected.js | 93 +++---- core/events/events_theme_change.js | 75 +++--- core/events/events_toolbox_item_select.js | 93 +++---- core/events/events_trashcan_open.js | 77 +++--- core/events/events_ui.js | 97 +++---- core/events/events_ui_base.js | 12 +- core/events/events_var_create.js | 106 ++++---- core/events/events_var_delete.js | 106 ++++---- core/events/events_var_rename.js | 108 ++++---- core/events/events_viewport.js | 139 +++++----- tests/deps.js | 40 +-- tests/deps.mocha.js | 14 +- tests/mocha/block_create_event_test.js | 3 +- tests/mocha/comment_test.js | 15 +- tests/mocha/gesture_test.js | 5 +- tests/mocha/jso_deserialization_test.js | 46 ++-- tests/mocha/test_helpers.js | 2 - tests/mocha/theme_test.js | 3 +- tests/mocha/trashcan_test.js | 14 +- tests/mocha/workspace_svg_test.js | 13 +- tests/mocha/zoom_controls_test.js | 13 +- 34 files changed, 1452 insertions(+), 1404 deletions(-) diff --git a/core/events/events_abstract.js b/core/events/events_abstract.js index d88d8efab..c20d894db 100644 --- a/core/events/events_abstract.js +++ b/core/events/events_abstract.js @@ -53,13 +53,13 @@ const Abstract = function() { * @type {boolean} */ this.recordUndo = eventUtils.getRecordUndo(); -}; -/** - * Whether or not the event is a UI event. - * @type {boolean} - */ -Abstract.prototype.isUiEvent = false; + /** + * Whether or not the event is a UI event. + * @type {boolean} + */ + this.isUiEvent = false; +}; /** * Encode the event as JSON. diff --git a/core/events/events_block_change.js b/core/events/events_block_change.js index 4a9720ad8..cf8b6d0e9 100644 --- a/core/events/events_block_change.js +++ b/core/events/events_block_change.js @@ -17,7 +17,6 @@ goog.module('Blockly.Events.BlockChange'); const Xml = goog.require('Blockly.Xml'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {BlockBase} = goog.require('Blockly.Events.BlockBase'); /* eslint-disable-next-line no-unused-vars */ @@ -28,145 +27,149 @@ const {Block} = goog.requireType('Blockly.Block'); /** * Class for a block change event. - * @param {!Block=} opt_block The changed block. Undefined for a blank - * event. - * @param {string=} opt_element One of 'field', 'comment', 'disabled', etc. - * @param {?string=} opt_name Name of input or field affected, or null. - * @param {*=} opt_oldValue Previous value of element. - * @param {*=} opt_newValue New value of element. * @extends {BlockBase} - * @constructor - * @alias Blockly.Events.BlockChange */ -const BlockChange = function( - opt_block, opt_element, opt_name, opt_oldValue, opt_newValue) { - BlockChange.superClass_.constructor.call(this, opt_block); - if (!opt_block) { - return; // Blank event to be populated by fromJson. - } - this.element = typeof opt_element === 'undefined' ? '' : opt_element; - this.name = typeof opt_name === 'undefined' ? '' : opt_name; - this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue; - this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue; -}; -object.inherits(BlockChange, BlockBase); +class BlockChange extends BlockBase { + /** + * @param {!Block=} opt_block The changed block. Undefined for a blank + * event. + * @param {string=} opt_element One of 'field', 'comment', 'disabled', etc. + * @param {?string=} opt_name Name of input or field affected, or null. + * @param {*=} opt_oldValue Previous value of element. + * @param {*=} opt_newValue New value of element. + * @alias Blockly.Events.BlockChange + */ + constructor(opt_block, opt_element, opt_name, opt_oldValue, opt_newValue) { + super(opt_block); -/** - * Type of this event. - * @type {string} - */ -BlockChange.prototype.type = eventUtils.BLOCK_CHANGE; + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BLOCK_CHANGE; -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -BlockChange.prototype.toJson = function() { - const json = BlockChange.superClass_.toJson.call(this); - json['element'] = this.element; - if (this.name) { - json['name'] = this.name; - } - json['oldValue'] = this.oldValue; - json['newValue'] = this.newValue; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -BlockChange.prototype.fromJson = function(json) { - BlockChange.superClass_.fromJson.call(this, json); - this.element = json['element']; - this.name = json['name']; - this.oldValue = json['oldValue']; - this.newValue = json['newValue']; -}; - -/** - * Does this event record any change of state? - * @return {boolean} False if something changed. - */ -BlockChange.prototype.isNull = function() { - return this.oldValue === this.newValue; -}; - -/** - * Run a change event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -BlockChange.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - const block = workspace.getBlockById(this.blockId); - if (!block) { - console.warn('Can\'t change non-existent block: ' + this.blockId); - return; - } - if (block.mutator) { - // Close the mutator (if open) since we don't want to update it. - block.mutator.setVisible(false); - } - const value = forward ? this.newValue : this.oldValue; - switch (this.element) { - case 'field': { - const field = block.getField(this.name); - if (field) { - field.setValue(value); - } else { - console.warn('Can\'t set non-existent field: ' + this.name); - } - break; + if (!opt_block) { + return; // Blank event to be populated by fromJson. } - case 'comment': - block.setCommentText(/** @type {string} */ (value) || null); - break; - case 'collapsed': - block.setCollapsed(!!value); - break; - case 'disabled': - block.setEnabled(!value); - break; - case 'inline': - block.setInputsInline(!!value); - break; - case 'mutation': { - const oldState = BlockChange.getExtraBlockState_( - /** @type {!BlockSvg} */ (block)); - if (block.loadExtraState) { - block.loadExtraState(JSON.parse(/** @type {string} */ (value) || '{}')); - } else if (block.domToMutation) { - block.domToMutation( - Xml.textToDom(/** @type {string} */ (value) || '')); - } - eventUtils.fire( - new BlockChange(block, 'mutation', null, oldState, value)); - break; - } - default: - console.warn('Unknown change type: ' + this.element); + this.element = typeof opt_element === 'undefined' ? '' : opt_element; + this.name = typeof opt_name === 'undefined' ? '' : opt_name; + this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue; + this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue; } -}; -// TODO (#5397): Encapsulate this in the BlocklyMutationChange event when -// refactoring change events. -/** - * Returns the extra state of the given block (either as XML or a JSO, depending - * on the block's definition). - * @param {!BlockSvg} block The block to get the extra state of. - * @return {string} A stringified version of the extra state of the given block. - * @package - */ -BlockChange.getExtraBlockState_ = function(block) { - if (block.saveExtraState) { - const state = block.saveExtraState(); - return state ? JSON.stringify(state) : ''; - } else if (block.mutationToDom) { - const state = block.mutationToDom(); - return state ? Xml.domToText(state) : ''; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['element'] = this.element; + if (this.name) { + json['name'] = this.name; + } + json['oldValue'] = this.oldValue; + json['newValue'] = this.newValue; + return json; } - return ''; -}; + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.element = json['element']; + this.name = json['name']; + this.oldValue = json['oldValue']; + this.newValue = json['newValue']; + } + + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull() { + return this.oldValue === this.newValue; + } + + /** + * Run a change event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); + if (!block) { + console.warn('Can\'t change non-existent block: ' + this.blockId); + return; + } + if (block.mutator) { + // Close the mutator (if open) since we don't want to update it. + block.mutator.setVisible(false); + } + const value = forward ? this.newValue : this.oldValue; + switch (this.element) { + case 'field': { + const field = block.getField(this.name); + if (field) { + field.setValue(value); + } else { + console.warn('Can\'t set non-existent field: ' + this.name); + } + break; + } + case 'comment': + block.setCommentText(/** @type {string} */ (value) || null); + break; + case 'collapsed': + block.setCollapsed(!!value); + break; + case 'disabled': + block.setEnabled(!value); + break; + case 'inline': + block.setInputsInline(!!value); + break; + case 'mutation': { + const oldState = BlockChange.getExtraBlockState_( + /** @type {!BlockSvg} */ (block)); + if (block.loadExtraState) { + block.loadExtraState( + JSON.parse(/** @type {string} */ (value) || '{}')); + } else if (block.domToMutation) { + block.domToMutation( + Xml.textToDom(/** @type {string} */ (value) || '')); + } + eventUtils.fire( + new BlockChange(block, 'mutation', null, oldState, value)); + break; + } + default: + console.warn('Unknown change type: ' + this.element); + } + } + + // TODO (#5397): Encapsulate this in the BlocklyMutationChange event when + // refactoring change events. + /** + * Returns the extra state of the given block (either as XML or a JSO, + * depending on the block's definition). + * @param {!BlockSvg} block The block to get the extra state of. + * @return {string} A stringified version of the extra state of the given + * block. + * @package + */ + static getExtraBlockState_(block) { + if (block.saveExtraState) { + const state = block.saveExtraState(); + return state ? JSON.stringify(state) : ''; + } else if (block.mutationToDom) { + const state = block.mutationToDom(); + return state ? Xml.domToText(state) : ''; + } + return ''; + } +} registry.register(registry.Type.EVENT, eventUtils.CHANGE, BlockChange); diff --git a/core/events/events_block_create.js b/core/events/events_block_create.js index 9a3254358..19ae8128d 100644 --- a/core/events/events_block_create.js +++ b/core/events/events_block_create.js @@ -18,7 +18,6 @@ goog.module('Blockly.Events.BlockCreate'); const Xml = goog.require('Blockly.Xml'); const blocks = goog.require('Blockly.serialization.blocks'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {BlockBase} = goog.require('Blockly.Events.BlockBase'); /* eslint-disable-next-line no-unused-vars */ @@ -27,90 +26,93 @@ const {Block} = goog.requireType('Blockly.Block'); /** * Class for a block creation event. - * @param {!Block=} opt_block The created block. Undefined for a blank - * event. * @extends {BlockBase} - * @constructor - * @alias Blockly.Events.BlockCreate */ -const BlockCreate = function(opt_block) { - BlockCreate.superClass_.constructor.call(this, opt_block); - if (!opt_block) { - return; // Blank event to be populated by fromJson. - } - if (opt_block.isShadow()) { - // Moving shadow blocks is handled via disconnection. - this.recordUndo = false; - } +class BlockCreate extends BlockBase { + /** + * @param {!Block=} opt_block The created block. Undefined for a blank + * event. + * @alias Blockly.Events.BlockCreate + */ + constructor(opt_block) { + super(opt_block); - this.xml = Xml.blockToDomWithXY(opt_block); - this.ids = eventUtils.getDescendantIds(opt_block); + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BLOCK_CREATE; + + if (!opt_block) { + return; // Blank event to be populated by fromJson. + } + if (opt_block.isShadow()) { + // Moving shadow blocks is handled via disconnection. + this.recordUndo = false; + } + + this.xml = Xml.blockToDomWithXY(opt_block); + this.ids = eventUtils.getDescendantIds(opt_block); + + /** + * JSON representation of the block that was just created. + * @type {!blocks.State} + */ + this.json = /** @type {!blocks.State} */ ( + blocks.save(opt_block, {addCoordinates: true})); + } /** - * JSON representation of the block that was just created. - * @type {!blocks.State} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.json = /** @type {!blocks.State} */ ( - blocks.save(opt_block, {addCoordinates: true})); -}; -object.inherits(BlockCreate, BlockBase); - -/** - * Type of this event. - * @type {string} - */ -BlockCreate.prototype.type = eventUtils.BLOCK_CREATE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -BlockCreate.prototype.toJson = function() { - const json = BlockCreate.superClass_.toJson.call(this); - json['xml'] = Xml.domToText(this.xml); - json['ids'] = this.ids; - json['json'] = this.json; - if (!this.recordUndo) { - json['recordUndo'] = this.recordUndo; + toJson() { + const json = super.toJson(); + json['xml'] = Xml.domToText(this.xml); + json['ids'] = this.ids; + json['json'] = this.json; + if (!this.recordUndo) { + json['recordUndo'] = this.recordUndo; + } + return json; } - return json; -}; -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -BlockCreate.prototype.fromJson = function(json) { - BlockCreate.superClass_.fromJson.call(this, json); - this.xml = Xml.textToDom(json['xml']); - this.ids = json['ids']; - this.json = /** @type {!blocks.State} */ (json['json']); - if (json['recordUndo'] !== undefined) { - this.recordUndo = json['recordUndo']; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.xml = Xml.textToDom(json['xml']); + this.ids = json['ids']; + this.json = /** @type {!blocks.State} */ (json['json']); + if (json['recordUndo'] !== undefined) { + this.recordUndo = json['recordUndo']; + } } -}; -/** - * Run a creation event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -BlockCreate.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - if (forward) { - blocks.append(this.json, workspace); - } else { - for (let i = 0; i < this.ids.length; i++) { - const id = this.ids[i]; - const block = workspace.getBlockById(id); - if (block) { - block.dispose(false); - } else if (id === this.blockId) { - // Only complain about root-level block. - console.warn('Can\'t uncreate non-existent block: ' + id); + /** + * Run a creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + if (forward) { + blocks.append(this.json, workspace); + } else { + for (let i = 0; i < this.ids.length; i++) { + const id = this.ids[i]; + const block = workspace.getBlockById(id); + if (block) { + block.dispose(false); + } else if (id === this.blockId) { + // Only complain about root-level block. + console.warn('Can\'t uncreate non-existent block: ' + id); + } } } } -}; +} registry.register(registry.Type.EVENT, eventUtils.CREATE, BlockCreate); diff --git a/core/events/events_block_delete.js b/core/events/events_block_delete.js index 80ef65d5e..633433980 100644 --- a/core/events/events_block_delete.js +++ b/core/events/events_block_delete.js @@ -18,7 +18,6 @@ goog.module('Blockly.Events.BlockDelete'); const Xml = goog.require('Blockly.Xml'); const blocks = goog.require('Blockly.serialization.blocks'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {BlockBase} = goog.require('Blockly.Events.BlockBase'); /* eslint-disable-next-line no-unused-vars */ @@ -27,102 +26,105 @@ const {Block} = goog.requireType('Blockly.Block'); /** * Class for a block deletion event. - * @param {!Block=} opt_block The deleted block. Undefined for a blank - * event. * @extends {BlockBase} - * @constructor - * @alias Blockly.Events.BlockDelete */ -const BlockDelete = function(opt_block) { - BlockDelete.superClass_.constructor.call(this, opt_block); - if (!opt_block) { - return; // Blank event to be populated by fromJson. - } - if (opt_block.getParent()) { - throw Error('Connected blocks cannot be deleted.'); - } - if (opt_block.isShadow()) { - // Respawning shadow blocks is handled via disconnection. - this.recordUndo = false; - } - - this.oldXml = Xml.blockToDomWithXY(opt_block); - this.ids = eventUtils.getDescendantIds(opt_block); - +class BlockDelete extends BlockBase { /** - * Was the block that was just deleted a shadow? - * @type {boolean} + * @param {!Block=} opt_block The deleted block. Undefined for a blank + * event. + * @alias Blockly.Events.BlockDelete */ - this.wasShadow = opt_block.isShadow(); + constructor(opt_block) { + super(opt_block); - /** - * JSON representation of the block that was just deleted. - * @type {!blocks.State} - */ - this.oldJson = /** @type {!blocks.State} */ ( - blocks.save(opt_block, {addCoordinates: true})); -}; -object.inherits(BlockDelete, BlockBase); + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BLOCK_DELETE; -/** - * Type of this event. - * @type {string} - */ -BlockDelete.prototype.type = eventUtils.BLOCK_DELETE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -BlockDelete.prototype.toJson = function() { - const json = BlockDelete.superClass_.toJson.call(this); - json['oldXml'] = Xml.domToText(this.oldXml); - json['ids'] = this.ids; - json['wasShadow'] = this.wasShadow; - json['oldJson'] = this.oldJson; - if (!this.recordUndo) { - json['recordUndo'] = this.recordUndo; - } - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -BlockDelete.prototype.fromJson = function(json) { - BlockDelete.superClass_.fromJson.call(this, json); - this.oldXml = Xml.textToDom(json['oldXml']); - this.ids = json['ids']; - this.wasShadow = - json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow'; - this.oldJson = /** @type {!blocks.State} */ (json['oldJson']); - if (json['recordUndo'] !== undefined) { - this.recordUndo = json['recordUndo']; - } -}; - -/** - * Run a deletion event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -BlockDelete.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - if (forward) { - for (let i = 0; i < this.ids.length; i++) { - const id = this.ids[i]; - const block = workspace.getBlockById(id); - if (block) { - block.dispose(false); - } else if (id === this.blockId) { - // Only complain about root-level block. - console.warn('Can\'t delete non-existent block: ' + id); - } + if (!opt_block) { + return; // Blank event to be populated by fromJson. } - } else { - blocks.append(this.oldJson, workspace); + if (opt_block.getParent()) { + throw Error('Connected blocks cannot be deleted.'); + } + if (opt_block.isShadow()) { + // Respawning shadow blocks is handled via disconnection. + this.recordUndo = false; + } + + this.oldXml = Xml.blockToDomWithXY(opt_block); + this.ids = eventUtils.getDescendantIds(opt_block); + + /** + * Was the block that was just deleted a shadow? + * @type {boolean} + */ + this.wasShadow = opt_block.isShadow(); + + /** + * JSON representation of the block that was just deleted. + * @type {!blocks.State} + */ + this.oldJson = /** @type {!blocks.State} */ ( + blocks.save(opt_block, {addCoordinates: true})); } -}; + + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['oldXml'] = Xml.domToText(this.oldXml); + json['ids'] = this.ids; + json['wasShadow'] = this.wasShadow; + json['oldJson'] = this.oldJson; + if (!this.recordUndo) { + json['recordUndo'] = this.recordUndo; + } + return json; + } + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.oldXml = Xml.textToDom(json['oldXml']); + this.ids = json['ids']; + this.wasShadow = + json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow'; + this.oldJson = /** @type {!blocks.State} */ (json['oldJson']); + if (json['recordUndo'] !== undefined) { + this.recordUndo = json['recordUndo']; + } + } + + /** + * Run a deletion event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + if (forward) { + for (let i = 0; i < this.ids.length; i++) { + const id = this.ids[i]; + const block = workspace.getBlockById(id); + if (block) { + block.dispose(false); + } else if (id === this.blockId) { + // Only complain about root-level block. + console.warn('Can\'t delete non-existent block: ' + id); + } + } + } else { + blocks.append(this.oldJson, workspace); + } + } +} registry.register(registry.Type.EVENT, eventUtils.DELETE, BlockDelete); diff --git a/core/events/events_block_drag.js b/core/events/events_block_drag.js index 432246eb8..42fb45bee 100644 --- a/core/events/events_block_drag.js +++ b/core/events/events_block_drag.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.BlockDrag'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); /* eslint-disable-next-line no-unused-vars */ const {Block} = goog.requireType('Blockly.Block'); @@ -25,63 +24,65 @@ const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a block drag event. - * @param {!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 {UiBase} - * @constructor - * @alias Blockly.Events.BlockDrag */ -const BlockDrag = function(opt_block, opt_isStart, opt_blocks) { - const workspaceId = opt_block ? opt_block.workspace.id : undefined; - BlockDrag.superClass_.constructor.call(this, workspaceId); - this.blockId = opt_block ? opt_block.id : null; +class BlockDrag extends UiBase { + /** + * @param {!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. + * @alias Blockly.Events.BlockDrag + */ + constructor(opt_block, opt_isStart, opt_blocks) { + const workspaceId = opt_block ? opt_block.workspace.id : undefined; + super(workspaceId); + this.blockId = opt_block ? opt_block.id : null; + + /** + * Whether this is the start of a block drag. + * @type {boolean|undefined} + */ + this.isStart = opt_isStart; + + /** + * The blocks affected by this drag event. + * @type {!Array|undefined} + */ + this.blocks = opt_blocks; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BLOCK_DRAG; + } /** - * Whether this is the start of a block drag. - * @type {boolean|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.isStart = opt_isStart; + toJson() { + const json = super.toJson(); + json['isStart'] = this.isStart; + json['blockId'] = this.blockId; + json['blocks'] = this.blocks; + return json; + } /** - * The blocks affected by this drag event. - * @type {!Array|undefined} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.blocks = opt_blocks; -}; -object.inherits(BlockDrag, UiBase); - -/** - * Type of this event. - * @type {string} - */ -BlockDrag.prototype.type = eventUtils.BLOCK_DRAG; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -BlockDrag.prototype.toJson = function() { - const json = BlockDrag.superClass_.toJson.call(this); - json['isStart'] = this.isStart; - json['blockId'] = this.blockId; - json['blocks'] = this.blocks; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -BlockDrag.prototype.fromJson = function(json) { - BlockDrag.superClass_.fromJson.call(this, json); - this.isStart = json['isStart']; - this.blockId = json['blockId']; - this.blocks = json['blocks']; -}; + fromJson(json) { + super.fromJson(json); + this.isStart = json['isStart']; + this.blockId = json['blockId']; + this.blocks = json['blocks']; + } +} registry.register(registry.Type.EVENT, eventUtils.BLOCK_DRAG, BlockDrag); diff --git a/core/events/events_block_move.js b/core/events/events_block_move.js index a90d74bd2..c0a7adb95 100644 --- a/core/events/events_block_move.js +++ b/core/events/events_block_move.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.BlockMove'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {BlockBase} = goog.require('Blockly.Events.BlockBase'); /* eslint-disable-next-line no-unused-vars */ @@ -27,168 +26,176 @@ const {Coordinate} = goog.require('Blockly.utils.Coordinate'); /** * Class for a block move event. Created before the move. - * @param {!Block=} opt_block The moved block. Undefined for a blank - * event. * @extends {BlockBase} - * @constructor - * @alias Blockly.Events.BlockMove */ -const BlockMove = function(opt_block) { - BlockMove.superClass_.constructor.call(this, opt_block); - if (!opt_block) { - return; // Blank event to be populated by fromJson. - } - if (opt_block.isShadow()) { - // Moving shadow blocks is handled via disconnection. - this.recordUndo = false; - } +class BlockMove extends BlockBase { + /** + * @param {!Block=} opt_block The moved block. Undefined for a blank + * event. + * @alias Blockly.Events.BlockMove + */ + constructor(opt_block) { + super(opt_block); - const location = this.currentLocation_(); - this.oldParentId = location.parentId; - this.oldInputName = location.inputName; - this.oldCoordinate = location.coordinate; -}; -object.inherits(BlockMove, BlockBase); + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BLOCK_MOVE; -/** - * Type of this event. - * @type {string} - */ -BlockMove.prototype.type = eventUtils.BLOCK_MOVE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -BlockMove.prototype.toJson = function() { - const json = BlockMove.superClass_.toJson.call(this); - if (this.newParentId) { - json['newParentId'] = this.newParentId; - } - if (this.newInputName) { - json['newInputName'] = this.newInputName; - } - if (this.newCoordinate) { - json['newCoordinate'] = Math.round(this.newCoordinate.x) + ',' + - Math.round(this.newCoordinate.y); - } - if (!this.recordUndo) { - json['recordUndo'] = this.recordUndo; - } - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -BlockMove.prototype.fromJson = function(json) { - BlockMove.superClass_.fromJson.call(this, json); - this.newParentId = json['newParentId']; - this.newInputName = json['newInputName']; - if (json['newCoordinate']) { - const xy = json['newCoordinate'].split(','); - this.newCoordinate = new Coordinate(Number(xy[0]), Number(xy[1])); - } - if (json['recordUndo'] !== undefined) { - this.recordUndo = json['recordUndo']; - } -}; - -/** - * Record the block's new location. Called after the move. - */ -BlockMove.prototype.recordNew = function() { - const location = this.currentLocation_(); - this.newParentId = location.parentId; - this.newInputName = location.inputName; - this.newCoordinate = location.coordinate; -}; - -/** - * Returns the parentId and input if the block is connected, - * or the XY location if disconnected. - * @return {!Object} Collection of location info. - * @private - */ -BlockMove.prototype.currentLocation_ = function() { - const workspace = this.getEventWorkspace_(); - const block = workspace.getBlockById(this.blockId); - const location = {}; - const parent = block.getParent(); - if (parent) { - location.parentId = parent.id; - const input = parent.getInputWithBlock(block); - if (input) { - location.inputName = input.name; + if (!opt_block) { + return; // Blank event to be populated by fromJson. + } + if (opt_block.isShadow()) { + // Moving shadow blocks is handled via disconnection. + this.recordUndo = false; } - } else { - location.coordinate = block.getRelativeToSurfaceXY(); - } - return location; -}; -/** - * Does this event record any change of state? - * @return {boolean} False if something changed. - */ -BlockMove.prototype.isNull = function() { - return this.oldParentId === this.newParentId && - this.oldInputName === this.newInputName && - Coordinate.equals(this.oldCoordinate, this.newCoordinate); -}; + const location = this.currentLocation_(); + this.oldParentId = location.parentId; + this.oldInputName = location.inputName; + this.oldCoordinate = location.coordinate; -/** - * Run a move event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -BlockMove.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - const block = workspace.getBlockById(this.blockId); - if (!block) { - console.warn('Can\'t move non-existent block: ' + this.blockId); - return; + this.newParentId = null; + this.newInputName = null; + this.newCoordinate = null; } - const parentId = forward ? this.newParentId : this.oldParentId; - const inputName = forward ? this.newInputName : this.oldInputName; - const coordinate = forward ? this.newCoordinate : this.oldCoordinate; - let parentBlock; - if (parentId) { - parentBlock = workspace.getBlockById(parentId); - if (!parentBlock) { - console.warn('Can\'t connect to non-existent block: ' + parentId); + + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + if (this.newParentId) { + json['newParentId'] = this.newParentId; + } + if (this.newInputName) { + json['newInputName'] = this.newInputName; + } + if (this.newCoordinate) { + json['newCoordinate'] = Math.round(this.newCoordinate.x) + ',' + + Math.round(this.newCoordinate.y); + } + if (!this.recordUndo) { + json['recordUndo'] = this.recordUndo; + } + return json; + } + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.newParentId = json['newParentId']; + this.newInputName = json['newInputName']; + if (json['newCoordinate']) { + const xy = json['newCoordinate'].split(','); + this.newCoordinate = new Coordinate(Number(xy[0]), Number(xy[1])); + } + if (json['recordUndo'] !== undefined) { + this.recordUndo = json['recordUndo']; + } + } + + /** + * Record the block's new location. Called after the move. + */ + recordNew() { + const location = this.currentLocation_(); + this.newParentId = location.parentId; + this.newInputName = location.inputName; + this.newCoordinate = location.coordinate; + } + + /** + * Returns the parentId and input if the block is connected, + * or the XY location if disconnected. + * @return {!Object} Collection of location info. + * @private + */ + currentLocation_() { + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); + const location = {}; + const parent = block.getParent(); + if (parent) { + location.parentId = parent.id; + const input = parent.getInputWithBlock(block); + if (input) { + location.inputName = input.name; + } + } else { + location.coordinate = block.getRelativeToSurfaceXY(); + } + return location; + } + + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull() { + return this.oldParentId === this.newParentId && + this.oldInputName === this.newInputName && + Coordinate.equals(this.oldCoordinate, this.newCoordinate); + } + + /** + * Run a move event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + const block = workspace.getBlockById(this.blockId); + if (!block) { + console.warn('Can\'t move non-existent block: ' + this.blockId); return; } - } - if (block.getParent()) { - block.unplug(); - } - if (coordinate) { - const xy = block.getRelativeToSurfaceXY(); - block.moveBy(coordinate.x - xy.x, coordinate.y - xy.y); - } else { - let blockConnection = block.outputConnection; - if (!blockConnection || - (block.previousConnection && block.previousConnection.isConnected())) { - blockConnection = block.previousConnection; - } - let parentConnection; - const connectionType = blockConnection.type; - if (inputName) { - const input = parentBlock.getInput(inputName); - if (input) { - parentConnection = input.connection; + const parentId = forward ? this.newParentId : this.oldParentId; + const inputName = forward ? this.newInputName : this.oldInputName; + const coordinate = forward ? this.newCoordinate : this.oldCoordinate; + let parentBlock; + if (parentId) { + parentBlock = workspace.getBlockById(parentId); + if (!parentBlock) { + console.warn('Can\'t connect to non-existent block: ' + parentId); + return; } - } else if (connectionType === ConnectionType.PREVIOUS_STATEMENT) { - parentConnection = parentBlock.nextConnection; } - if (parentConnection) { - blockConnection.connect(parentConnection); + if (block.getParent()) { + block.unplug(); + } + if (coordinate) { + const xy = block.getRelativeToSurfaceXY(); + block.moveBy(coordinate.x - xy.x, coordinate.y - xy.y); } else { - console.warn('Can\'t connect to non-existent input: ' + inputName); + let blockConnection = block.outputConnection; + if (!blockConnection || + (block.previousConnection && + block.previousConnection.isConnected())) { + blockConnection = block.previousConnection; + } + let parentConnection; + const connectionType = blockConnection.type; + if (inputName) { + const input = parentBlock.getInput(inputName); + if (input) { + parentConnection = input.connection; + } + } else if (connectionType === ConnectionType.PREVIOUS_STATEMENT) { + parentConnection = parentBlock.nextConnection; + } + if (parentConnection) { + blockConnection.connect(parentConnection); + } else { + console.warn('Can\'t connect to non-existent input: ' + inputName); + } } } -}; +} registry.register(registry.Type.EVENT, eventUtils.MOVE, BlockMove); diff --git a/core/events/events_bubble_open.js b/core/events/events_bubble_open.js index 9c76fd751..95099951c 100644 --- a/core/events/events_bubble_open.js +++ b/core/events/events_bubble_open.js @@ -52,15 +52,15 @@ const BubbleOpen = function(opt_block, opt_isOpen, opt_bubbleType) { * @type {string|undefined} */ this.bubbleType = opt_bubbleType; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.BUBBLE_OPEN; }; object.inherits(BubbleOpen, UiBase); -/** - * Type of this event. - * @type {string} - */ -BubbleOpen.prototype.type = eventUtils.BUBBLE_OPEN; - /** * Encode the event as JSON. * @return {!Object} JSON representation. diff --git a/core/events/events_click.js b/core/events/events_click.js index 0bc9aa972..a855ea63c 100644 --- a/core/events/events_click.js +++ b/core/events/events_click.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.Click'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); /* eslint-disable-next-line no-unused-vars */ const {Block} = goog.requireType('Blockly.Block'); @@ -25,58 +24,63 @@ const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a click event. - * @param {?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. - * Not used if block is passed. Undefined for a blank event. - * @param {string=} opt_targetType The type of element targeted by this click - * event. Undefined for a blank event. * @extends {UiBase} - * @constructor - * @alias Blockly.Events.Click */ -const Click = function(opt_block, opt_workspaceId, opt_targetType) { - const workspaceId = opt_block ? opt_block.workspace.id : opt_workspaceId; - Click.superClass_.constructor.call(this, workspaceId); - this.blockId = opt_block ? opt_block.id : null; +class Click extends UiBase { + /** + * @param {?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. + * Not used if block is passed. Undefined for a blank event. + * @param {string=} opt_targetType The type of element targeted by this click + * event. Undefined for a blank event. + * @alias Blockly.Events.Click + */ + constructor(opt_block, opt_workspaceId, opt_targetType) { + let workspaceId = opt_block ? opt_block.workspace.id : opt_workspaceId; + if (workspaceId === null) { + workspaceId = undefined; + } + super(workspaceId); + this.blockId = opt_block ? opt_block.id : null; + + /** + * The type of element targeted by this click event. + * @type {string|undefined} + */ + this.targetType = opt_targetType; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.CLICK; + } /** - * The type of element targeted by this click event. - * @type {string|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.targetType = opt_targetType; -}; -object.inherits(Click, UiBase); - -/** - * Type of this event. - * @type {string} - */ -Click.prototype.type = eventUtils.CLICK; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -Click.prototype.toJson = function() { - const json = Click.superClass_.toJson.call(this); - json['targetType'] = this.targetType; - if (this.blockId) { - json['blockId'] = this.blockId; + toJson() { + const json = super.toJson(); + json['targetType'] = this.targetType; + if (this.blockId) { + json['blockId'] = this.blockId; + } + return json; } - return json; -}; -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -Click.prototype.fromJson = function(json) { - Click.superClass_.fromJson.call(this, json); - this.targetType = json['targetType']; - this.blockId = json['blockId']; -}; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.targetType = json['targetType']; + this.blockId = json['blockId']; + } +} registry.register(registry.Type.EVENT, eventUtils.CLICK, Click); diff --git a/core/events/events_comment_change.js b/core/events/events_comment_change.js index 1f6b44ba3..ec6b54e05 100644 --- a/core/events/events_comment_change.js +++ b/core/events/events_comment_change.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.CommentChange'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {CommentBase} = goog.require('Blockly.Events.CommentBase'); /* eslint-disable-next-line no-unused-vars */ @@ -25,77 +24,80 @@ const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment'); /** * Class for a comment change event. - * @param {!WorkspaceComment=} opt_comment The comment that is being - * changed. Undefined for a blank event. - * @param {string=} opt_oldContents Previous contents of the comment. - * @param {string=} opt_newContents New contents of the comment. * @extends {CommentBase} - * @constructor - * @alias Blockly.Events.CommentChange */ -const CommentChange = function(opt_comment, opt_oldContents, opt_newContents) { - CommentChange.superClass_.constructor.call(this, opt_comment); - if (!opt_comment) { - return; // Blank event to be populated by fromJson. +class CommentChange extends CommentBase { + /** + * @param {!WorkspaceComment=} opt_comment The comment that is being + * changed. Undefined for a blank event. + * @param {string=} opt_oldContents Previous contents of the comment. + * @param {string=} opt_newContents New contents of the comment. + * @alias Blockly.Events.CommentChange + */ + constructor(opt_comment, opt_oldContents, opt_newContents) { + super(opt_comment); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.COMMENT_CHANGE; + + if (!opt_comment) { + return; // Blank event to be populated by fromJson. + } + + this.oldContents_ = + typeof opt_oldContents === 'undefined' ? '' : opt_oldContents; + this.newContents_ = + typeof opt_newContents === 'undefined' ? '' : opt_newContents; } - this.oldContents_ = - typeof opt_oldContents === 'undefined' ? '' : opt_oldContents; - this.newContents_ = - typeof opt_newContents === 'undefined' ? '' : opt_newContents; -}; -object.inherits(CommentChange, CommentBase); - -/** - * Type of this event. - * @type {string} - */ -CommentChange.prototype.type = eventUtils.COMMENT_CHANGE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -CommentChange.prototype.toJson = function() { - const json = CommentChange.superClass_.toJson.call(this); - json['oldContents'] = this.oldContents_; - json['newContents'] = this.newContents_; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -CommentChange.prototype.fromJson = function(json) { - CommentChange.superClass_.fromJson.call(this, json); - this.oldContents_ = json['oldContents']; - this.newContents_ = json['newContents']; -}; - -/** - * Does this event record any change of state? - * @return {boolean} False if something changed. - */ -CommentChange.prototype.isNull = function() { - return this.oldContents_ === this.newContents_; -}; - -/** - * Run a change event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -CommentChange.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - const comment = workspace.getCommentById(this.commentId); - if (!comment) { - console.warn('Can\'t change non-existent comment: ' + this.commentId); - return; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['oldContents'] = this.oldContents_; + json['newContents'] = this.newContents_; + return json; } - const contents = forward ? this.newContents_ : this.oldContents_; - comment.setContent(contents); -}; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.oldContents_ = json['oldContents']; + this.newContents_ = json['newContents']; + } + + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull() { + return this.oldContents_ === this.newContents_; + } + + /** + * Run a change event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + const comment = workspace.getCommentById(this.commentId); + if (!comment) { + console.warn('Can\'t change non-existent comment: ' + this.commentId); + return; + } + const contents = forward ? this.newContents_ : this.oldContents_; + + comment.setContent(contents); + } +} registry.register( registry.Type.EVENT, eventUtils.COMMENT_CHANGE, CommentChange); diff --git a/core/events/events_comment_create.js b/core/events/events_comment_create.js index 5d9cb8d79..f3d15659b 100644 --- a/core/events/events_comment_create.js +++ b/core/events/events_comment_create.js @@ -17,7 +17,6 @@ goog.module('Blockly.Events.CommentCreate'); const Xml = goog.require('Blockly.Xml'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {CommentBase} = goog.require('Blockly.Events.CommentBase'); /* eslint-disable-next-line no-unused-vars */ @@ -26,55 +25,58 @@ const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment'); /** * Class for a comment creation event. - * @param {!WorkspaceComment=} opt_comment The created comment. - * Undefined for a blank event. * @extends {CommentBase} - * @constructor - * @alias Blockly.Events.CommentCreate */ -const CommentCreate = function(opt_comment) { - CommentCreate.superClass_.constructor.call(this, opt_comment); - if (!opt_comment) { - return; // Blank event to be populated by fromJson. +class CommentCreate extends CommentBase { + /** + * @param {!WorkspaceComment=} opt_comment The created comment. + * Undefined for a blank event. + * @alias Blockly.Events.CommentCreate + */ + constructor(opt_comment) { + super(opt_comment); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.COMMENT_CREATE; + + if (!opt_comment) { + return; // Blank event to be populated by fromJson. + } + + this.xml = opt_comment.toXmlWithXY(); } - this.xml = opt_comment.toXmlWithXY(); -}; -object.inherits(CommentCreate, CommentBase); + // TODO (#1266): "Full" and "minimal" serialization. + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['xml'] = Xml.domToText(this.xml); + return json; + } -/** - * Type of this event. - * @type {string} - */ -CommentCreate.prototype.type = eventUtils.COMMENT_CREATE; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.xml = Xml.textToDom(json['xml']); + } -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -// TODO (#1266): "Full" and "minimal" serialization. -CommentCreate.prototype.toJson = function() { - const json = CommentCreate.superClass_.toJson.call(this); - json['xml'] = Xml.domToText(this.xml); - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -CommentCreate.prototype.fromJson = function(json) { - CommentCreate.superClass_.fromJson.call(this, json); - this.xml = Xml.textToDom(json['xml']); -}; - -/** - * Run a creation event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -CommentCreate.prototype.run = function(forward) { - CommentBase.CommentCreateDeleteHelper(this, forward); -}; + /** + * Run a creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + CommentBase.CommentCreateDeleteHelper(this, forward); + } +} registry.register( registry.Type.EVENT, eventUtils.COMMENT_CREATE, CommentCreate); diff --git a/core/events/events_comment_delete.js b/core/events/events_comment_delete.js index 54e1df4ba..fc426ca5e 100644 --- a/core/events/events_comment_delete.js +++ b/core/events/events_comment_delete.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.CommentDelete'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {CommentBase} = goog.require('Blockly.Events.CommentBase'); /* eslint-disable-next-line no-unused-vars */ @@ -25,53 +24,56 @@ const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment'); /** * Class for a comment deletion event. - * @param {!WorkspaceComment=} opt_comment The deleted comment. - * Undefined for a blank event. * @extends {CommentBase} - * @constructor - * @alias Blockly.Events.CommentDelete */ -const CommentDelete = function(opt_comment) { - CommentDelete.superClass_.constructor.call(this, opt_comment); - if (!opt_comment) { - return; // Blank event to be populated by fromJson. +class CommentDelete extends CommentBase { + /** + * @param {!WorkspaceComment=} opt_comment The deleted comment. + * Undefined for a blank event. + * @alias Blockly.Events.CommentDelete + */ + constructor(opt_comment) { + super(opt_comment); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.COMMENT_DELETE; + + if (!opt_comment) { + return; // Blank event to be populated by fromJson. + } + + this.xml = opt_comment.toXmlWithXY(); } - this.xml = opt_comment.toXmlWithXY(); -}; -object.inherits(CommentDelete, CommentBase); + // TODO (#1266): "Full" and "minimal" serialization. + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + return json; + } -/** - * Type of this event. - * @type {string} - */ -CommentDelete.prototype.type = eventUtils.COMMENT_DELETE; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + } -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -// TODO (#1266): "Full" and "minimal" serialization. -CommentDelete.prototype.toJson = function() { - const json = CommentDelete.superClass_.toJson.call(this); - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -CommentDelete.prototype.fromJson = function(json) { - CommentDelete.superClass_.fromJson.call(this, json); -}; - -/** - * Run a creation event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -CommentDelete.prototype.run = function(forward) { - CommentBase.CommentCreateDeleteHelper(this, !forward); -}; + /** + * Run a creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + CommentBase.CommentCreateDeleteHelper(this, !forward); + } +} registry.register( registry.Type.EVENT, eventUtils.COMMENT_DELETE, CommentDelete); diff --git a/core/events/events_comment_move.js b/core/events/events_comment_move.js index 51ba01ab6..7545c619f 100644 --- a/core/events/events_comment_move.js +++ b/core/events/events_comment_move.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.CommentMove'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {CommentBase} = goog.require('Blockly.Events.CommentBase'); const {Coordinate} = goog.require('Blockly.utils.Coordinate'); @@ -26,129 +25,132 @@ const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment'); /** * Class for a comment move event. Created before the move. - * @param {!WorkspaceComment=} opt_comment The comment that is being - * moved. Undefined for a blank event. * @extends {CommentBase} - * @constructor - * @alias Blockly.Events.CommentMove */ -const CommentMove = function(opt_comment) { - CommentMove.superClass_.constructor.call(this, opt_comment); - if (!opt_comment) { - return; // Blank event to be populated by fromJson. +class CommentMove extends CommentBase { + /** + * @param {!WorkspaceComment=} opt_comment The comment that is being + * moved. Undefined for a blank event. + * @alias Blockly.Events.CommentMove + */ + constructor(opt_comment) { + super(opt_comment); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.COMMENT_MOVE; + + if (!opt_comment) { + return; // Blank event to be populated by fromJson. + } + + /** + * The comment that is being moved. Will be cleared after recording the new + * location. + * @type {WorkspaceComment} + */ + this.comment_ = opt_comment; + + /** + * The location before the move, in workspace coordinates. + * @type {!Coordinate} + */ + this.oldCoordinate_ = opt_comment.getXY(); + + /** + * The location after the move, in workspace coordinates. + * @type {Coordinate} + */ + this.newCoordinate_ = null; } /** - * The comment that is being moved. Will be cleared after recording the new - * location. - * @type {WorkspaceComment} + * Record the comment's new location. Called after the move. Can only be + * called once. */ - this.comment_ = opt_comment; + recordNew() { + if (!this.comment_) { + throw Error( + 'Tried to record the new position of a comment on the ' + + 'same event twice.'); + } + this.newCoordinate_ = this.comment_.getXY(); + this.comment_ = null; + } /** - * The location before the move, in workspace coordinates. - * @type {!Coordinate} + * Override the location before the move. Use this if you don't create the + * event until the end of the move, but you know the original location. + * @param {!Coordinate} xy The location before the move, + * in workspace coordinates. */ - this.oldCoordinate_ = opt_comment.getXY(); + setOldCoordinate(xy) { + this.oldCoordinate_ = xy; + } + + // TODO (#1266): "Full" and "minimal" serialization. + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + if (this.oldCoordinate_) { + json['oldCoordinate'] = Math.round(this.oldCoordinate_.x) + ',' + + Math.round(this.oldCoordinate_.y); + } + if (this.newCoordinate_) { + json['newCoordinate'] = Math.round(this.newCoordinate_.x) + ',' + + Math.round(this.newCoordinate_.y); + } + return json; + } /** - * The location after the move, in workspace coordinates. - * @type {Coordinate} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.newCoordinate_ = null; -}; -object.inherits(CommentMove, CommentBase); + fromJson(json) { + super.fromJson(json); -/** - * Record the comment's new location. Called after the move. Can only be - * called once. - */ -CommentMove.prototype.recordNew = function() { - if (!this.comment_) { - throw Error( - 'Tried to record the new position of a comment on the ' + - 'same event twice.'); - } - this.newCoordinate_ = this.comment_.getXY(); - this.comment_ = null; -}; - -/** - * Type of this event. - * @type {string} - */ -CommentMove.prototype.type = eventUtils.COMMENT_MOVE; - -/** - * Override the location before the move. Use this if you don't create the - * event until the end of the move, but you know the original location. - * @param {!Coordinate} xy The location before the move, - * in workspace coordinates. - */ -CommentMove.prototype.setOldCoordinate = function(xy) { - this.oldCoordinate_ = xy; -}; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -// TODO (#1266): "Full" and "minimal" serialization. -CommentMove.prototype.toJson = function() { - const json = CommentMove.superClass_.toJson.call(this); - if (this.oldCoordinate_) { - json['oldCoordinate'] = Math.round(this.oldCoordinate_.x) + ',' + - Math.round(this.oldCoordinate_.y); - } - if (this.newCoordinate_) { - json['newCoordinate'] = Math.round(this.newCoordinate_.x) + ',' + - Math.round(this.newCoordinate_.y); - } - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -CommentMove.prototype.fromJson = function(json) { - CommentMove.superClass_.fromJson.call(this, json); - - if (json['oldCoordinate']) { - const xy = json['oldCoordinate'].split(','); - this.oldCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1])); - } - if (json['newCoordinate']) { - const xy = json['newCoordinate'].split(','); - this.newCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1])); - } -}; - -/** - * Does this event record any change of state? - * @return {boolean} False if something changed. - */ -CommentMove.prototype.isNull = function() { - return Coordinate.equals(this.oldCoordinate_, this.newCoordinate_); -}; - -/** - * Run a move event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -CommentMove.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - const comment = workspace.getCommentById(this.commentId); - if (!comment) { - console.warn('Can\'t move non-existent comment: ' + this.commentId); - return; + if (json['oldCoordinate']) { + const xy = json['oldCoordinate'].split(','); + this.oldCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1])); + } + if (json['newCoordinate']) { + const xy = json['newCoordinate'].split(','); + this.newCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1])); + } } - const target = forward ? this.newCoordinate_ : this.oldCoordinate_; - // TODO: Check if the comment is being dragged, and give up if so. - const current = comment.getXY(); - comment.moveBy(target.x - current.x, target.y - current.y); -}; + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull() { + return Coordinate.equals(this.oldCoordinate_, this.newCoordinate_); + } + + /** + * Run a move event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + const comment = workspace.getCommentById(this.commentId); + if (!comment) { + console.warn('Can\'t move non-existent comment: ' + this.commentId); + return; + } + + const target = forward ? this.newCoordinate_ : this.oldCoordinate_; + // TODO: Check if the comment is being dragged, and give up if so. + const current = comment.getXY(); + comment.moveBy(target.x - current.x, target.y - current.y); + } +} registry.register(registry.Type.EVENT, eventUtils.COMMENT_MOVE, CommentMove); diff --git a/core/events/events_marker_move.js b/core/events/events_marker_move.js index 97f473d95..214d666ee 100644 --- a/core/events/events_marker_move.js +++ b/core/events/events_marker_move.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.MarkerMove'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {ASTNode} = goog.require('Blockly.ASTNode'); /* eslint-disable-next-line no-unused-vars */ @@ -28,81 +27,83 @@ const {Workspace} = goog.requireType('Blockly.Workspace'); /** * Class for a marker move event. - * @param {?Block=} opt_block The affected block. Null if current node - * is of type workspace. Undefined for a blank event. - * @param {boolean=} isCursor Whether this is a cursor event. Undefined for a - * blank event. - * @param {?ASTNode=} opt_oldNode The old node the marker used to be on. - * Undefined for a blank event. - * @param {!ASTNode=} opt_newNode The new node the marker is now on. - * Undefined for a blank event. * @extends {UiBase} - * @constructor - * @alias Blockly.Events.MarkerMove */ -const MarkerMove = function(opt_block, isCursor, opt_oldNode, opt_newNode) { - let workspaceId = opt_block ? opt_block.workspace.id : undefined; - if (opt_newNode && opt_newNode.getType() === ASTNode.types.WORKSPACE) { - workspaceId = (/** @type {!Workspace} */ (opt_newNode.getLocation())).id; +class MarkerMove extends UiBase { + /** + * @param {?Block=} opt_block The affected block. Null if current node + * is of type workspace. Undefined for a blank event. + * @param {boolean=} isCursor Whether this is a cursor event. Undefined for a + * blank event. + * @param {?ASTNode=} opt_oldNode The old node the marker used to be on. + * Undefined for a blank event. + * @param {!ASTNode=} opt_newNode The new node the marker is now on. + * Undefined for a blank event. + * @alias Blockly.Events.MarkerMove + */ + constructor(opt_block, isCursor, opt_oldNode, opt_newNode) { + let workspaceId = opt_block ? opt_block.workspace.id : undefined; + if (opt_newNode && opt_newNode.getType() === ASTNode.types.WORKSPACE) { + workspaceId = (/** @type {!Workspace} */ (opt_newNode.getLocation())).id; + } + super(workspaceId); + + /** + * The workspace identifier for this event. + * @type {?string} + */ + this.blockId = opt_block ? opt_block.id : null; + + /** + * The old node the marker used to be on. + * @type {?ASTNode|undefined} + */ + this.oldNode = opt_oldNode; + + /** + * The new node the marker is now on. + * @type {ASTNode|undefined} + */ + this.newNode = opt_newNode; + + /** + * Whether this is a cursor event. + * @type {boolean|undefined} + */ + this.isCursor = isCursor; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.MARKER_MOVE; } - MarkerMove.superClass_.constructor.call(this, workspaceId); /** - * The workspace identifier for this event. - * @type {?string} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.blockId = opt_block ? opt_block.id : null; + toJson() { + const json = super.toJson(); + json['isCursor'] = this.isCursor; + json['blockId'] = this.blockId; + json['oldNode'] = this.oldNode; + json['newNode'] = this.newNode; + return json; + } /** - * The old node the marker used to be on. - * @type {?ASTNode|undefined} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.oldNode = opt_oldNode; - - /** - * The new node the marker is now on. - * @type {ASTNode|undefined} - */ - this.newNode = opt_newNode; - - /** - * Whether this is a cursor event. - * @type {boolean|undefined} - */ - this.isCursor = isCursor; -}; -object.inherits(MarkerMove, UiBase); - -/** - * Type of this event. - * @type {string} - */ -MarkerMove.prototype.type = eventUtils.MARKER_MOVE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -MarkerMove.prototype.toJson = function() { - const json = MarkerMove.superClass_.toJson.call(this); - json['isCursor'] = this.isCursor; - json['blockId'] = this.blockId; - json['oldNode'] = this.oldNode; - json['newNode'] = this.newNode; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -MarkerMove.prototype.fromJson = function(json) { - MarkerMove.superClass_.fromJson.call(this, json); - this.isCursor = json['isCursor']; - this.blockId = json['blockId']; - this.oldNode = json['oldNode']; - this.newNode = json['newNode']; -}; + fromJson(json) { + super.fromJson(json); + this.isCursor = json['isCursor']; + this.blockId = json['blockId']; + this.oldNode = json['oldNode']; + this.newNode = json['newNode']; + } +} registry.register(registry.Type.EVENT, eventUtils.MARKER_MOVE, MarkerMove); diff --git a/core/events/events_selected.js b/core/events/events_selected.js index 7009a8549..fbf0d07a5 100644 --- a/core/events/events_selected.js +++ b/core/events/events_selected.js @@ -16,66 +16,67 @@ goog.module('Blockly.Events.Selected'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * 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_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 {UiBase} - * @constructor - * @alias Blockly.Events.Selected */ -const Selected = function(opt_oldElementId, opt_newElementId, opt_workspaceId) { - Selected.superClass_.constructor.call(this, opt_workspaceId); +class Selected extends UiBase { + /** + * @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_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. + * @alias Blockly.Events.Selected + */ + constructor(opt_oldElementId, opt_newElementId, opt_workspaceId) { + super(opt_workspaceId); + + /** + * The id of the last selected element. + * @type {?string|undefined} + */ + this.oldElementId = opt_oldElementId; + + /** + * The id of the selected element. + * @type {?string|undefined} + */ + this.newElementId = opt_newElementId; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.SELECTED; + } /** - * The id of the last selected element. - * @type {?string|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.oldElementId = opt_oldElementId; + toJson() { + const json = super.toJson(); + json['oldElementId'] = this.oldElementId; + json['newElementId'] = this.newElementId; + return json; + } /** - * The id of the selected element. - * @type {?string|undefined} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.newElementId = opt_newElementId; -}; -object.inherits(Selected, UiBase); - -/** - * Type of this event. - * @type {string} - */ -Selected.prototype.type = eventUtils.SELECTED; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -Selected.prototype.toJson = function() { - const json = Selected.superClass_.toJson.call(this); - json['oldElementId'] = this.oldElementId; - json['newElementId'] = this.newElementId; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -Selected.prototype.fromJson = function(json) { - Selected.superClass_.fromJson.call(this, json); - this.oldElementId = json['oldElementId']; - this.newElementId = json['newElementId']; -}; + fromJson(json) { + super.fromJson(json); + this.oldElementId = json['oldElementId']; + this.newElementId = json['newElementId']; + } +} registry.register(registry.Type.EVENT, eventUtils.SELECTED, Selected); diff --git a/core/events/events_theme_change.js b/core/events/events_theme_change.js index e1cba44c2..247bd0da8 100644 --- a/core/events/events_theme_change.js +++ b/core/events/events_theme_change.js @@ -16,55 +16,56 @@ goog.module('Blockly.Events.ThemeChange'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a theme change event. - * @param {string=} opt_themeName The theme name. Undefined for a blank event. - * @param {string=} opt_workspaceId The workspace identifier for this event. - * event. Undefined for a blank event. * @extends {UiBase} - * @constructor - * @alias Blockly.Events.ThemeChange */ -const ThemeChange = function(opt_themeName, opt_workspaceId) { - ThemeChange.superClass_.constructor.call(this, opt_workspaceId); +class ThemeChange extends UiBase { + /** + * @param {string=} opt_themeName The theme name. Undefined for a blank event. + * @param {string=} opt_workspaceId The workspace identifier for this event. + * event. Undefined for a blank event. + * @alias Blockly.Events.ThemeChange + */ + constructor(opt_themeName, opt_workspaceId) { + super(opt_workspaceId); + + /** + * The theme name. + * @type {string|undefined} + */ + this.themeName = opt_themeName; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.THEME_CHANGE; + } /** - * The theme name. - * @type {string|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.themeName = opt_themeName; -}; -object.inherits(ThemeChange, UiBase); + toJson() { + const json = super.toJson(); + json['themeName'] = this.themeName; + return json; + } -/** - * Type of this event. - * @type {string} - */ -ThemeChange.prototype.type = eventUtils.THEME_CHANGE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -ThemeChange.prototype.toJson = function() { - const json = ThemeChange.superClass_.toJson.call(this); - json['themeName'] = this.themeName; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -ThemeChange.prototype.fromJson = function(json) { - ThemeChange.superClass_.fromJson.call(this, json); - this.themeName = json['themeName']; -}; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.themeName = json['themeName']; + } +} registry.register(registry.Type.EVENT, eventUtils.THEME_CHANGE, ThemeChange); diff --git a/core/events/events_toolbox_item_select.js b/core/events/events_toolbox_item_select.js index f2ba9bf19..6a6509316 100644 --- a/core/events/events_toolbox_item_select.js +++ b/core/events/events_toolbox_item_select.js @@ -16,66 +16,67 @@ goog.module('Blockly.Events.ToolboxItemSelect'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a toolbox item select event. - * @param {?string=} opt_oldItem The previously selected toolbox item. Undefined - * for a blank event. - * @param {?string=} opt_newItem The newly selected toolbox item. Undefined for - * a blank event. - * @param {string=} opt_workspaceId The workspace identifier for this event. - * Undefined for a blank event. * @extends {UiBase} - * @constructor - * @alias Blockly.Events.ToolboxItemSelect */ -const ToolboxItemSelect = function(opt_oldItem, opt_newItem, opt_workspaceId) { - ToolboxItemSelect.superClass_.constructor.call(this, opt_workspaceId); +class ToolboxItemSelect extends UiBase { + /** + * @param {?string=} opt_oldItem The previously selected toolbox item. + * Undefined for a blank event. + * @param {?string=} opt_newItem The newly selected toolbox item. Undefined + * for a blank event. + * @param {string=} opt_workspaceId The workspace identifier for this event. + * Undefined for a blank event. + * @alias Blockly.Events.ToolboxItemSelect + */ + constructor(opt_oldItem, opt_newItem, opt_workspaceId) { + super(opt_workspaceId); + + /** + * The previously selected toolbox item. + * @type {?string|undefined} + */ + this.oldItem = opt_oldItem; + + /** + * The newly selected toolbox item. + * @type {?string|undefined} + */ + this.newItem = opt_newItem; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.TOOLBOX_ITEM_SELECT; + } /** - * The previously selected toolbox item. - * @type {?string|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.oldItem = opt_oldItem; + toJson() { + const json = super.toJson(); + json['oldItem'] = this.oldItem; + json['newItem'] = this.newItem; + return json; + } /** - * The newly selected toolbox item. - * @type {?string|undefined} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.newItem = opt_newItem; -}; -object.inherits(ToolboxItemSelect, UiBase); - -/** - * Type of this event. - * @type {string} - */ -ToolboxItemSelect.prototype.type = eventUtils.TOOLBOX_ITEM_SELECT; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -ToolboxItemSelect.prototype.toJson = function() { - const json = ToolboxItemSelect.superClass_.toJson.call(this); - json['oldItem'] = this.oldItem; - json['newItem'] = this.newItem; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -ToolboxItemSelect.prototype.fromJson = function(json) { - ToolboxItemSelect.superClass_.fromJson.call(this, json); - this.oldItem = json['oldItem']; - this.newItem = json['newItem']; -}; + fromJson(json) { + super.fromJson(json); + this.oldItem = json['oldItem']; + this.newItem = json['newItem']; + } +} registry.register( registry.Type.EVENT, eventUtils.TOOLBOX_ITEM_SELECT, ToolboxItemSelect); diff --git a/core/events/events_trashcan_open.js b/core/events/events_trashcan_open.js index 21fd0d3b3..565cee307 100644 --- a/core/events/events_trashcan_open.js +++ b/core/events/events_trashcan_open.js @@ -16,56 +16,57 @@ goog.module('Blockly.Events.TrashcanOpen'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a trashcan open 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 {UiBase} - * @constructor - * @alias Blockly.Events.TrashcanOpen */ -const TrashcanOpen = function(opt_isOpen, opt_workspaceId) { - TrashcanOpen.superClass_.constructor.call(this, opt_workspaceId); +class TrashcanOpen extends UiBase { + /** + * @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. + * @alias Blockly.Events.TrashcanOpen + */ + constructor(opt_isOpen, opt_workspaceId) { + super(opt_workspaceId); + + /** + * Whether the trashcan flyout is opening (false if closing). + * @type {boolean|undefined} + */ + this.isOpen = opt_isOpen; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.TRASHCAN_OPEN; + } /** - * Whether the trashcan flyout is opening (false if closing). - * @type {boolean|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.isOpen = opt_isOpen; -}; -object.inherits(TrashcanOpen, UiBase); + toJson() { + const json = super.toJson(); + json['isOpen'] = this.isOpen; + return json; + } -/** - * Type of this event. - * @type {string} - */ -TrashcanOpen.prototype.type = eventUtils.TRASHCAN_OPEN; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -TrashcanOpen.prototype.toJson = function() { - const json = TrashcanOpen.superClass_.toJson.call(this); - json['isOpen'] = this.isOpen; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -TrashcanOpen.prototype.fromJson = function(json) { - TrashcanOpen.superClass_.fromJson.call(this, json); - this.isOpen = json['isOpen']; -}; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.isOpen = json['isOpen']; + } +} registry.register(registry.Type.EVENT, eventUtils.TRASHCAN_OPEN, TrashcanOpen); diff --git a/core/events/events_ui.js b/core/events/events_ui.js index b505d3b20..2acb2fa4e 100644 --- a/core/events/events_ui.js +++ b/core/events/events_ui.js @@ -18,7 +18,6 @@ goog.module('Blockly.Events.Ui'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); /* eslint-disable-next-line no-unused-vars */ const {Block} = goog.requireType('Blockly.Block'); @@ -27,60 +26,62 @@ const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a UI event. - * @param {?Block=} opt_block The affected block. Null for UI events - * that do not have an associated block. Undefined for a blank event. - * @param {string=} opt_element One of 'selected', 'comment', 'mutatorOpen', - * etc. - * @param {*=} opt_oldValue Previous value of element. - * @param {*=} opt_newValue New value of element. * @extends {UiBase} * @deprecated December 2020. Instead use a more specific UI event. - * @constructor - * @alias Blockly.Events.Ui */ -const Ui = function(opt_block, opt_element, opt_oldValue, opt_newValue) { - const workspaceId = opt_block ? opt_block.workspace.id : undefined; - Ui.superClass_.constructor.call(this, workspaceId); +class Ui extends UiBase { + /** + * @param {?Block=} opt_block The affected block. Null for UI events + * that do not have an associated block. Undefined for a blank event. + * @param {string=} opt_element One of 'selected', 'comment', 'mutatorOpen', + * etc. + * @param {*=} opt_oldValue Previous value of element. + * @param {*=} opt_newValue New value of element. + * @alias Blockly.Events.Ui + */ + constructor(opt_block, opt_element, opt_oldValue, opt_newValue) { + const workspaceId = opt_block ? opt_block.workspace.id : undefined; + super(workspaceId); - this.blockId = opt_block ? opt_block.id : null; - this.element = typeof opt_element === 'undefined' ? '' : opt_element; - this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue; - this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue; -}; -object.inherits(Ui, UiBase); + this.blockId = opt_block ? opt_block.id : null; + this.element = typeof opt_element === 'undefined' ? '' : opt_element; + this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue; + this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue; -/** - * Type of this event. - * @type {string} - */ -Ui.prototype.type = eventUtils.UI; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -Ui.prototype.toJson = function() { - const json = Ui.superClass_.toJson.call(this); - json['element'] = this.element; - if (this.newValue !== undefined) { - json['newValue'] = this.newValue; + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.UI; } - if (this.blockId) { - json['blockId'] = this.blockId; - } - return json; -}; -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -Ui.prototype.fromJson = function(json) { - Ui.superClass_.fromJson.call(this, json); - this.element = json['element']; - this.newValue = json['newValue']; - this.blockId = json['blockId']; -}; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['element'] = this.element; + if (this.newValue !== undefined) { + json['newValue'] = this.newValue; + } + if (this.blockId) { + json['blockId'] = this.blockId; + } + return json; + } + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.element = json['element']; + this.newValue = json['newValue']; + this.blockId = json['blockId']; + } +} registry.register(registry.Type.EVENT, eventUtils.UI, Ui); diff --git a/core/events/events_ui_base.js b/core/events/events_ui_base.js index 1618f2876..cd7ad1d2e 100644 --- a/core/events/events_ui_base.js +++ b/core/events/events_ui_base.js @@ -50,13 +50,13 @@ const UiBase = function(opt_workspaceId) { // UI events do not undo or redo. this.recordUndo = false; + + /** + * Whether or not the event is a UI event. + * @type {boolean} + */ + this.isUiEvent = true; }; object.inherits(UiBase, Abstract); -/** - * Whether or not the event is a UI event. - * @type {boolean} - */ -UiBase.prototype.isUiEvent = true; - exports.UiBase = UiBase; diff --git a/core/events/events_var_create.js b/core/events/events_var_create.js index f924fd98d..0de02d99c 100644 --- a/core/events/events_var_create.js +++ b/core/events/events_var_create.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.VarCreate'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {VarBase} = goog.require('Blockly.Events.VarBase'); /* eslint-disable-next-line no-unused-vars */ @@ -25,62 +24,65 @@ const {VariableModel} = goog.requireType('Blockly.VariableModel'); /** * Class for a variable creation event. - * @param {!VariableModel=} opt_variable The created variable. Undefined - * for a blank event. * @extends {VarBase} - * @constructor - * @alias Blockly.Events.VarCreate */ -const VarCreate = function(opt_variable) { - VarCreate.superClass_.constructor.call(this, opt_variable); - if (!opt_variable) { - return; // Blank event to be populated by fromJson. +class VarCreate extends VarBase { + /** + * @param {!VariableModel=} opt_variable The created variable. Undefined + * for a blank event. + * @alias Blockly.Events.VarCreate + */ + constructor(opt_variable) { + super(opt_variable); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.VAR_CREATE; + + if (!opt_variable) { + return; // Blank event to be populated by fromJson. + } + + this.varType = opt_variable.type; + this.varName = opt_variable.name; } - this.varType = opt_variable.type; - this.varName = opt_variable.name; -}; -object.inherits(VarCreate, VarBase); - -/** - * Type of this event. - * @type {string} - */ -VarCreate.prototype.type = eventUtils.VAR_CREATE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -VarCreate.prototype.toJson = function() { - const json = VarCreate.superClass_.toJson.call(this); - json['varType'] = this.varType; - json['varName'] = this.varName; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -VarCreate.prototype.fromJson = function(json) { - VarCreate.superClass_.fromJson.call(this, json); - this.varType = json['varType']; - this.varName = json['varName']; -}; - -/** - * Run a variable creation event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -VarCreate.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - if (forward) { - workspace.createVariable(this.varName, this.varType, this.varId); - } else { - workspace.deleteVariableById(this.varId); + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['varType'] = this.varType; + json['varName'] = this.varName; + return json; } -}; + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.varType = json['varType']; + this.varName = json['varName']; + } + + /** + * Run a variable creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + if (forward) { + workspace.createVariable(this.varName, this.varType, this.varId); + } else { + workspace.deleteVariableById(this.varId); + } + } +} registry.register(registry.Type.EVENT, eventUtils.VAR_CREATE, VarCreate); diff --git a/core/events/events_var_delete.js b/core/events/events_var_delete.js index 2c8b34fb2..3c0eb2a58 100644 --- a/core/events/events_var_delete.js +++ b/core/events/events_var_delete.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.VarDelete'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {VarBase} = goog.require('Blockly.Events.VarBase'); /* eslint-disable-next-line no-unused-vars */ @@ -25,62 +24,65 @@ const {VariableModel} = goog.requireType('Blockly.VariableModel'); /** * Class for a variable deletion event. - * @param {!VariableModel=} opt_variable The deleted variable. Undefined - * for a blank event. * @extends {VarBase} - * @constructor - * @alias Blockly.Events.VarDelete */ -const VarDelete = function(opt_variable) { - VarDelete.superClass_.constructor.call(this, opt_variable); - if (!opt_variable) { - return; // Blank event to be populated by fromJson. +class VarDelete extends VarBase { + /** + * @param {!VariableModel=} opt_variable The deleted variable. Undefined + * for a blank event. + * @alias Blockly.Events.VarDelete + */ + constructor(opt_variable) { + super(opt_variable); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.VAR_DELETE; + + if (!opt_variable) { + return; // Blank event to be populated by fromJson. + } + + this.varType = opt_variable.type; + this.varName = opt_variable.name; } - this.varType = opt_variable.type; - this.varName = opt_variable.name; -}; -object.inherits(VarDelete, VarBase); - -/** - * Type of this event. - * @type {string} - */ -VarDelete.prototype.type = eventUtils.VAR_DELETE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -VarDelete.prototype.toJson = function() { - const json = VarDelete.superClass_.toJson.call(this); - json['varType'] = this.varType; - json['varName'] = this.varName; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -VarDelete.prototype.fromJson = function(json) { - VarDelete.superClass_.fromJson.call(this, json); - this.varType = json['varType']; - this.varName = json['varName']; -}; - -/** - * Run a variable deletion event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -VarDelete.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - if (forward) { - workspace.deleteVariableById(this.varId); - } else { - workspace.createVariable(this.varName, this.varType, this.varId); + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['varType'] = this.varType; + json['varName'] = this.varName; + return json; } -}; + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.varType = json['varType']; + this.varName = json['varName']; + } + + /** + * Run a variable deletion event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + if (forward) { + workspace.deleteVariableById(this.varId); + } else { + workspace.createVariable(this.varName, this.varType, this.varId); + } + } +} registry.register(registry.Type.EVENT, eventUtils.VAR_DELETE, VarDelete); diff --git a/core/events/events_var_rename.js b/core/events/events_var_rename.js index 97d8fd882..17d3774e5 100644 --- a/core/events/events_var_rename.js +++ b/core/events/events_var_rename.js @@ -16,7 +16,6 @@ goog.module('Blockly.Events.VarRename'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {VarBase} = goog.require('Blockly.Events.VarBase'); /* eslint-disable-next-line no-unused-vars */ @@ -25,63 +24,66 @@ const {VariableModel} = goog.requireType('Blockly.VariableModel'); /** * Class for a variable rename event. - * @param {!VariableModel=} opt_variable The renamed variable. Undefined - * for a blank event. - * @param {string=} newName The new name the variable will be changed to. * @extends {VarBase} - * @constructor - * @alias Blockly.Events.VarRename */ -const VarRename = function(opt_variable, newName) { - VarRename.superClass_.constructor.call(this, opt_variable); - if (!opt_variable) { - return; // Blank event to be populated by fromJson. +class VarRename extends VarBase { + /** + * @param {!VariableModel=} opt_variable The renamed variable. Undefined + * for a blank event. + * @param {string=} newName The new name the variable will be changed to. + * @alias Blockly.Events.VarRename + */ + constructor(opt_variable, newName) { + super(opt_variable); + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.VAR_RENAME; + + if (!opt_variable) { + return; // Blank event to be populated by fromJson. + } + + this.oldName = opt_variable.name; + this.newName = typeof newName === 'undefined' ? '' : newName; } - this.oldName = opt_variable.name; - this.newName = typeof newName === 'undefined' ? '' : newName; -}; -object.inherits(VarRename, VarBase); - -/** - * Type of this event. - * @type {string} - */ -VarRename.prototype.type = eventUtils.VAR_RENAME; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -VarRename.prototype.toJson = function() { - const json = VarRename.superClass_.toJson.call(this); - json['oldName'] = this.oldName; - json['newName'] = this.newName; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -VarRename.prototype.fromJson = function(json) { - VarRename.superClass_.fromJson.call(this, json); - this.oldName = json['oldName']; - this.newName = json['newName']; -}; - -/** - * Run a variable rename event. - * @param {boolean} forward True if run forward, false if run backward (undo). - */ -VarRename.prototype.run = function(forward) { - const workspace = this.getEventWorkspace_(); - if (forward) { - workspace.renameVariableById(this.varId, this.newName); - } else { - workspace.renameVariableById(this.varId, this.oldName); + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson() { + const json = super.toJson(); + json['oldName'] = this.oldName; + json['newName'] = this.newName; + return json; } -}; + + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json) { + super.fromJson(json); + this.oldName = json['oldName']; + this.newName = json['newName']; + } + + /** + * Run a variable rename event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward) { + const workspace = this.getEventWorkspace_(); + if (forward) { + workspace.renameVariableById(this.varId, this.newName); + } else { + workspace.renameVariableById(this.varId, this.oldName); + } + } +} registry.register(registry.Type.EVENT, eventUtils.VAR_RENAME, VarRename); diff --git a/core/events/events_viewport.js b/core/events/events_viewport.js index 71ac3d3c7..bde96edf8 100644 --- a/core/events/events_viewport.js +++ b/core/events/events_viewport.js @@ -16,89 +16,90 @@ goog.module('Blockly.Events.ViewportChange'); const eventUtils = goog.require('Blockly.Events.utils'); -const object = goog.require('Blockly.utils.object'); const registry = goog.require('Blockly.registry'); const {UiBase} = goog.require('Blockly.Events.UiBase'); /** * Class for a viewport change event. - * @param {number=} opt_top Top-edge of the visible portion of the workspace, - * 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. 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. - * @param {number=} opt_oldScale The old scale of the workspace. Undefined for a - * blank event. * @extends {UiBase} - * @constructor - * @alias Blockly.Events.ViewportChange */ -const ViewportChange = function( - opt_top, opt_left, opt_scale, opt_workspaceId, opt_oldScale) { - ViewportChange.superClass_.constructor.call(this, opt_workspaceId); +class ViewportChange extends UiBase { + /** + * @param {number=} opt_top Top-edge of the visible portion of the workspace, + * 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. 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. + * @param {number=} opt_oldScale The old scale of the workspace. Undefined for + * a blank event. + * @alias Blockly.Events.ViewportChange + */ + constructor(opt_top, opt_left, opt_scale, opt_workspaceId, opt_oldScale) { + super(opt_workspaceId); + + /** + * Top-edge of the visible portion of the workspace, relative to the + * workspace origin. + * @type {number|undefined} + */ + this.viewTop = opt_top; + + /** + * Left-edge of the visible portion of the workspace, relative to the + * workspace origin. + * @type {number|undefined} + */ + this.viewLeft = opt_left; + + /** + * The scale of the workspace. + * @type {number|undefined} + */ + this.scale = opt_scale; + + /** + * The old scale of the workspace. + * @type {number|undefined} + */ + this.oldScale = opt_oldScale; + + /** + * Type of this event. + * @type {string} + */ + this.type = eventUtils.VIEWPORT_CHANGE; + } /** - * Top-edge of the visible portion of the workspace, relative to the workspace - * origin. - * @type {number|undefined} + * Encode the event as JSON. + * @return {!Object} JSON representation. */ - this.viewTop = opt_top; + toJson() { + const json = super.toJson(); + json['viewTop'] = this.viewTop; + json['viewLeft'] = this.viewLeft; + json['scale'] = this.scale; + json['oldScale'] = this.oldScale; + return json; + } /** - * Left-edge of the visible portion of the workspace, relative to the - * workspace origin. - * @type {number|undefined} + * Decode the JSON event. + * @param {!Object} json JSON representation. */ - this.viewLeft = opt_left; - - /** - * The scale of the workspace. - * @type {number|undefined} - */ - this.scale = opt_scale; - - /** - * The old scale of the workspace. - * @type {number|undefined} - */ - this.oldScale = opt_oldScale; -}; -object.inherits(ViewportChange, UiBase); - -/** - * Type of this event. - * @type {string} - */ -ViewportChange.prototype.type = eventUtils.VIEWPORT_CHANGE; - -/** - * Encode the event as JSON. - * @return {!Object} JSON representation. - */ -ViewportChange.prototype.toJson = function() { - const json = ViewportChange.superClass_.toJson.call(this); - json['viewTop'] = this.viewTop; - json['viewLeft'] = this.viewLeft; - json['scale'] = this.scale; - json['oldScale'] = this.oldScale; - return json; -}; - -/** - * Decode the JSON event. - * @param {!Object} json JSON representation. - */ -ViewportChange.prototype.fromJson = function(json) { - ViewportChange.superClass_.fromJson.call(this, json); - this.viewTop = json['viewTop']; - this.viewLeft = json['viewLeft']; - this.scale = json['scale']; - this.oldScale = json['oldScale']; -}; + fromJson(json) { + super.fromJson(json); + this.viewTop = json['viewTop']; + this.viewLeft = json['viewLeft']; + this.scale = json['scale']; + this.oldScale = json['oldScale']; + } +} registry.register( registry.Type.EVENT, eventUtils.VIEWPORT_CHANGE, ViewportChange); diff --git a/tests/deps.js b/tests/deps.js index 55bfc76b6..ab5c32064 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -40,30 +40,30 @@ goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Block goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.Events.Abstract', 'Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.Events.BubbleOpen', 'Blockly.Events.Click', 'Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.FinishedLoading', 'Blockly.Events.MarkerMove', 'Blockly.Events.Selected', 'Blockly.Events.ThemeChange', 'Blockly.Events.ToolboxItemSelect', 'Blockly.Events.TrashcanOpen', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Events.ViewportChange', 'Blockly.Events.utils', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_block_base.js', ['Blockly.Events.BlockBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_block_change.js', ['Blockly.Events.BlockChange'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.ConnectionType', 'Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_block_change.js', ['Blockly.Events.BlockChange'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.ConnectionType', 'Blockly.Events.BlockBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_comment_base.js', ['Blockly.Events.CommentBase'], ['Blockly.Events.Abstract', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_comment_change.js', ['Blockly.Events.CommentChange'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_comment_create.js', ['Blockly.Events.CommentCreate'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_comment_delete.js', ['Blockly.Events.CommentDelete'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_comment_move.js', ['Blockly.Events.CommentMove'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.ASTNode', 'Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Selected'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_ui.js', ['Blockly.Events.Ui'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_comment_change.js', ['Blockly.Events.CommentChange'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_comment_create.js', ['Blockly.Events.CommentCreate'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.Xml', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_comment_delete.js', ['Blockly.Events.CommentDelete'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_comment_move.js', ['Blockly.Events.CommentMove'], ['Blockly.Events.CommentBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.ASTNode', 'Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Selected'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_ui.js', ['Blockly.Events.Ui'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_ui_base.js', ['Blockly.Events.UiBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/events_var_base.js', ['Blockly.Events.VarBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_var_create.js', ['Blockly.Events.VarCreate'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_var_delete.js', ['Blockly.Events.VarDelete'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_var_rename.js', ['Blockly.Events.VarRename'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_var_create.js', ['Blockly.Events.VarCreate'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_var_delete.js', ['Blockly.Events.VarDelete'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_var_rename.js', ['Blockly.Events.VarRename'], ['Blockly.Events.VarBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events.UiBase', 'Blockly.Events.utils', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/utils.js', ['Blockly.Events.utils'], ['Blockly.registry', 'Blockly.utils.idGenerator'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events.Abstract', 'Blockly.Events.utils', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils.parsing'], {'lang': 'es6', 'module': 'goog'}); diff --git a/tests/deps.mocha.js b/tests/deps.mocha.js index 4be80abef..a686fdda7 100644 --- a/tests/deps.mocha.js +++ b/tests/deps.mocha.js @@ -1,10 +1,10 @@ goog.addDependency('../../tests/mocha/.mocharc.js', [], []); goog.addDependency('../../tests/mocha/astnode_test.js', ['Blockly.test.astNode'], ['Blockly.ASTNode', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/block_change_event_test.js', ['Blockly.test.blockChangeEvent'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/block_create_event_test.js', ['Blockly.test.blockCreateEvent'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/block_create_event_test.js', ['Blockly.test.blockCreateEvent'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/block_json_test.js', ['Blockly.test.blockJson'], ['Blockly.Input'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/block_test.js', ['Blockly.test.blocks'], ['Blockly.ConnectionType', 'Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/comment_test.js', ['Blockly.test.comments'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/comment_test.js', ['Blockly.test.comments'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/connection_checker_test.js', ['Blockly.test.connectionChecker'], ['Blockly.ConnectionType', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/connection_db_test.js', ['Blockly.test.connectionDb'], ['Blockly.ConnectionType', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/connection_test.js', ['Blockly.test.connection'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); @@ -28,10 +28,10 @@ goog.addDependency('../../tests/mocha/field_textinput_test.js', ['Blockly.test.f goog.addDependency('../../tests/mocha/field_variable_test.js', ['Blockly.test.fieldVariable'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/flyout_test.js', ['Blockly.test.flyout'], ['Blockly.test.helpers', 'Blockly.test.toolboxHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/generator_test.js', ['Blockly.test.generator'], ['Blockly.Dart', 'Blockly.JavaScript', 'Blockly.Lua', 'Blockly.PHP', 'Blockly.Python', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/gesture_test.js', ['Blockly.test.gesture'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/gesture_test.js', ['Blockly.test.gesture'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/input_test.js', ['Blockly.test.input'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/insertion_marker_test.js', ['Blockly.test.insertionMarker'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/jso_deserialization_test.js', ['Blockly.test.jsoDeserialization'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/jso_deserialization_test.js', ['Blockly.test.jsoDeserialization'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/jso_serialization_test.js', ['Blockly.test.jsoSerialization'], ['Blockly.test.helpers'], {'lang': 'es8', 'module': 'goog'}); goog.addDependency('../../tests/mocha/json_test.js', ['Blockly.test.json'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/keydown_test.js', ['Blockly.test.keydown'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); @@ -46,7 +46,7 @@ goog.addDependency('../../tests/mocha/run_mocha_tests_in_browser.js', [], [], {' goog.addDependency('../../tests/mocha/serializer_test.js', ['Blockly.test.serialization'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/shortcut_registry_test.js', ['Blockly.test.shortcutRegistry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/toolbox_helper.js', ['Blockly.test.toolboxHelpers'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/toolbox_test.js', ['Blockly.test.toolbox'], ['Blockly.test.helpers', 'Blockly.test.toolboxHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/tooltip_test.js', ['Blockly.test.tooltip'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); @@ -58,7 +58,7 @@ goog.addDependency('../../tests/mocha/variables_test.js', ['Blockly.test.variabl goog.addDependency('../../tests/mocha/widget_div_test.js', ['Blockly.test.widgetDiv'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/workspace_comment_test.js', ['Blockly.test.workspaceComment'], ['Blockly.WorkspaceComment', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/workspace_helpers.js', ['Blockly.test.workspaceHelpers'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/workspace_svg_test.js', ['Blockly.test.workspaceSvg'], ['Blockly.test.helpers', 'Blockly.test.workspaceHelpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/workspace_svg_test.js', ['Blockly.test.workspaceSvg'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.workspaceHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/workspace_test.js', ['Blockly.test.workspace'], ['Blockly.test.helpers', 'Blockly.test.workspaceHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/xml_test.js', ['Blockly.test.xml'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/zoom_controls_test.js', ['Blockly.test.zoomControls'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/zoom_controls_test.js', ['Blockly.test.zoomControls'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); diff --git a/tests/mocha/block_create_event_test.js b/tests/mocha/block_create_event_test.js index 91a84af3e..69debed96 100644 --- a/tests/mocha/block_create_event_test.js +++ b/tests/mocha/block_create_event_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.blockCreateEvent'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -48,7 +49,7 @@ suite('Block Create Event', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'recordUndo': false}, + {'recordUndo': false, 'type': eventUtils.BLOCK_CREATE}, this.workspace.id, 'shadowId'); const calls = this.eventsFireStub.getCalls(); diff --git a/tests/mocha/comment_test.js b/tests/mocha/comment_test.js index fa3a86d6b..94a496637 100644 --- a/tests/mocha/comment_test.js +++ b/tests/mocha/comment_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.comments'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -54,7 +55,7 @@ suite('Comments', function() { assertEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {bubbleType: 'comment', isOpen: true}, this.workspace.id, + {bubbleType: 'comment', isOpen: true, type: eventUtils.BUBBLE_OPEN}, this.workspace.id, this.block.id); }); test('Not Editable', function() { @@ -66,8 +67,8 @@ suite('Comments', function() { assertNotEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {bubbleType: 'comment', isOpen: true}, this.workspace.id, - this.block.id); + {bubbleType: 'comment', isOpen: true, type: eventUtils.BUBBLE_OPEN}, + this.workspace.id, this.block.id); }); test('Editable -> Not Editable', function() { this.comment.setVisible(true); @@ -79,8 +80,8 @@ suite('Comments', function() { assertNotEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {bubbleType: 'comment', isOpen: true}, this.workspace.id, - this.block.id); + {bubbleType: 'comment', isOpen: true, type: eventUtils.BUBBLE_OPEN}, + this.workspace.id, this.block.id); }); test('Not Editable -> Editable', function() { const editableStub = sinon.stub(this.block, 'isEditable').returns(false); @@ -94,8 +95,8 @@ suite('Comments', function() { assertEditable(this.comment); assertEventFired( this.eventsFireStub, Blockly.Events.BubbleOpen, - {bubbleType: 'comment', isOpen: true}, this.workspace.id, - this.block.id); + {bubbleType: 'comment', isOpen: true, type: eventUtils.BUBBLE_OPEN}, + this.workspace.id, this.block.id); }); }); suite('Set/Get Bubble Size', function() { diff --git a/tests/mocha/gesture_test.js b/tests/mocha/gesture_test.js index 8ecaee0de..16a6cadda 100644 --- a/tests/mocha/gesture_test.js +++ b/tests/mocha/gesture_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.gesture'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, assertEventNotFired, defineBasicBlockWithField, dispatchPointerEvent, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -34,8 +35,8 @@ suite('Gesture', function() { assertEventFired(eventsFireStub, Blockly.Events.Selected, - {oldElementId: null, newElementId: block.id}, fieldWorkspace.id); - assertEventNotFired(eventsFireStub, Blockly.Events.Click, {}); + {oldElementId: null, newElementId: block.id, type: eventUtils.SELECTED}, fieldWorkspace.id); + assertEventNotFired(eventsFireStub, Blockly.Events.Click, {type: eventUtils.CLICK}); } function getTopFlyoutBlock(flyout) { diff --git a/tests/mocha/jso_deserialization_test.js b/tests/mocha/jso_deserialization_test.js index 3a0d51f8e..02eace4af 100644 --- a/tests/mocha/jso_deserialization_test.js +++ b/tests/mocha/jso_deserialization_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.jsoDeserialization'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -38,7 +39,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.FinishedLoading, - {}, + {type: eventUtils.FINISHED_LOADING}, this.workspace.id); }); @@ -58,9 +59,8 @@ suite('JSO Deserialization', function() { Blockly.Events.setGroup('my group'); Blockly.serialization.workspaces.load(state, this.workspace); assertEventFired( - this.eventsFireStub, - Blockly.Events.FinishedLoading, - {'group': 'my group'}, + this.eventsFireStub, Blockly.Events.FinishedLoading, + {'group': 'my group', "type": eventUtils.FINISHED_LOADING}, this.workspace.id); }); @@ -107,13 +107,12 @@ suite('JSO Deserialization', function() { }; Blockly.serialization.workspaces.load(state, this.workspace); assertEventFired( - this.eventsFireStub, - Blockly.Events.VarCreate, - { + this.eventsFireStub, Blockly.Events.VarCreate, { 'varName': 'test', 'varId': 'testId', 'varType': '', 'recordUndo': false, + "type": eventUtils.VAR_CREATE, }, this.workspace.id); }); @@ -129,13 +128,12 @@ suite('JSO Deserialization', function() { }; Blockly.serialization.workspaces.load(state, this.workspace, {recordUndo: true}); assertEventFired( - this.eventsFireStub, - Blockly.Events.VarCreate, - { + this.eventsFireStub, Blockly.Events.VarCreate, { 'varName': 'test', 'varId': 'testId', 'varType': '', 'recordUndo': true, + "type": eventUtils.VAR_CREATE, }, this.workspace.id); }); @@ -152,13 +150,12 @@ suite('JSO Deserialization', function() { Blockly.Events.setGroup('my group'); Blockly.serialization.workspaces.load(state, this.workspace); assertEventFired( - this.eventsFireStub, - Blockly.Events.VarCreate, - { + this.eventsFireStub, Blockly.Events.VarCreate, { 'varName': 'test', 'varId': 'testId', 'varType': '', 'group': 'my group', + "type": eventUtils.VAR_CREATE, }, this.workspace.id); }); @@ -216,9 +213,12 @@ suite('JSO Deserialization', function() { }, 0); chai.assert.equal(count, 1); assertEventFired( - this.eventsFireStub, - Blockly.Events.VarCreate, - {'varName': 'test', 'varId': 'testId', 'varType': ''}, + this.eventsFireStub, Blockly.Events.VarCreate, { + 'varName': 'test', + 'varId': 'testId', + 'varType': '', + "type": eventUtils.VAR_CREATE, + }, this.workspace.id); }); }); @@ -242,7 +242,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'recordUndo': false}, + {'recordUndo': false, "type": eventUtils.BLOCK_CREATE}, this.workspace.id, 'testId'); }); @@ -264,7 +264,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'recordUndo': true}, + {'recordUndo': true, "type": eventUtils.BLOCK_CREATE}, this.workspace.id, 'testId'); }); @@ -287,7 +287,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'group': 'my group'}, + {'group': 'my group', "type": eventUtils.BLOCK_CREATE}, this.workspace.id, 'testId'); }); @@ -348,7 +348,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {}, + {type: eventUtils.BLOCK_CREATE}, this.workspace.id, 'id1'); }); @@ -383,7 +383,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'recordUndo': true}, + {'recordUndo': true, "type": eventUtils.BLOCK_CREATE}, this.workspace.id, 'testId'); }); @@ -400,7 +400,7 @@ suite('JSO Deserialization', function() { assertEventFired( this.eventsFireStub, Blockly.Events.BlockCreate, - {'group': 'my group'}, + {'group': 'my group', "type": eventUtils.BLOCK_CREATE}, this.workspace.id, 'testId'); }); @@ -662,7 +662,7 @@ suite('JSO Deserialization', function() { Blockly.serialization.workspaces.load( {'first': {}, 'third': {}, 'second': {}}, this.workspace); - + Blockly.serialization.registry.unregister('first'); Blockly.serialization.registry.unregister('second'); Blockly.serialization.registry.unregister('third'); diff --git a/tests/mocha/test_helpers.js b/tests/mocha/test_helpers.js index 9a404e629..4f8ab2eaf 100644 --- a/tests/mocha/test_helpers.js +++ b/tests/mocha/test_helpers.js @@ -401,7 +401,6 @@ exports.assertEventEquals = assertEventEquals; function assertEventFired(spy, instanceType, expectedProperties, expectedWorkspaceId, expectedBlockId) { expectedProperties = Object.assign({ - type: instanceType.prototype.type, workspaceId: expectedWorkspaceId, blockId: expectedBlockId, }, expectedProperties); @@ -423,7 +422,6 @@ exports.assertEventFired = assertEventFired; */ function assertEventNotFired(spy, instanceType, expectedProperties, expectedWorkspaceId, expectedBlockId) { - expectedProperties.type = instanceType.prototype.type; if (expectedWorkspaceId !== undefined) { expectedProperties.workspaceId = expectedWorkspaceId; } diff --git a/tests/mocha/theme_test.js b/tests/mocha/theme_test.js index 5c8d5d24e..fa9480624 100644 --- a/tests/mocha/theme_test.js +++ b/tests/mocha/theme_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.theme'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -146,7 +147,7 @@ suite('Theme', function() { assertEventFired( this.eventsFireStub, Blockly.Events.ThemeChange, - {themeName: 'themeName'}, workspace.id); + {themeName: 'themeName', type: eventUtils.THEME_CHANGE}, workspace.id); } finally { workspaceTeardown.call(this, workspace); } diff --git a/tests/mocha/trashcan_test.js b/tests/mocha/trashcan_test.js index fc4550b77..d82f60699 100644 --- a/tests/mocha/trashcan_test.js +++ b/tests/mocha/trashcan_test.js @@ -6,8 +6,8 @@ goog.module('Blockly.test.trashcan'); -const {assertEventFired, assertEventNotFired, defineBasicBlockWithField, defineRowBlock, defineStatementBlock, defineStackBlock, defineMutatorBlocks, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers'); const eventUtils = goog.require('Blockly.Events.utils'); +const {assertEventFired, assertEventNotFired, defineBasicBlockWithField, defineRowBlock, defineStatementBlock, defineStackBlock, defineMutatorBlocks, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers'); suite("Trashcan", function() { @@ -77,9 +77,9 @@ suite("Trashcan", function() { simulateClick(this.trashcan.svgGroup_); assertEventNotFired( - this.eventsFireStub, Blockly.Events.TrashcanOpen, {}); + this.eventsFireStub, Blockly.Events.TrashcanOpen, {type: eventUtils.CLICK}); assertEventFired( - this.eventsFireStub, Blockly.Events.Click, {targetType: 'workspace'}, + this.eventsFireStub, Blockly.Events.Click, {targetType: 'workspace', type: eventUtils.CLICK}, this.workspace.id, null); }); test("Click with contents - fires trashcanOpen", function() { @@ -94,9 +94,9 @@ suite("Trashcan", function() { assertEventFired( this.eventsFireStub, Blockly.Events.TrashcanOpen, - {isOpen: true}, this.workspace.id); + {isOpen: true, type: eventUtils.TRASHCAN_OPEN}, this.workspace.id); assertEventNotFired( - this.eventsFireStub, Blockly.Events.Click, {}); + this.eventsFireStub, Blockly.Events.Click, {type: eventUtils.TRASHCAN_OPEN}); }); test("Click outside trashcan - fires trashcanClose", function() { sinon.stub(this.trashcan.flyout, 'isVisible').returns(true); @@ -109,9 +109,9 @@ suite("Trashcan", function() { assertEventFired( this.eventsFireStub, Blockly.Events.TrashcanOpen, - {isOpen: false}, this.workspace.id); + {isOpen: false, type: eventUtils.TRASHCAN_OPEN}, this.workspace.id); assertEventFired( - this.eventsFireStub, Blockly.Events.Click, {targetType: 'workspace'}, + this.eventsFireStub, Blockly.Events.Click, {targetType: 'workspace', type: eventUtils.CLICK}, this.workspace.id, null); }); }); diff --git a/tests/mocha/workspace_svg_test.js b/tests/mocha/workspace_svg_test.js index c6af088ec..6271b2795 100644 --- a/tests/mocha/workspace_svg_test.js +++ b/tests/mocha/workspace_svg_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.workspaceSvg'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, assertEventNotFired, assertVariableValues, createFireChangeListenerSpy, defineStackBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); const {testAWorkspace} = goog.require('Blockly.test.workspaceHelpers'); @@ -182,6 +183,7 @@ suite('WorkspaceSvg', function() { oldScale: 1, viewTop: metrics.viewTop, viewLeft: metrics.viewLeft, + type: eventUtils.VIEWPORT_CHANGE, }; assertSpyFiredViewportEvent( eventsFireStub, workspace, expectedProperties); @@ -294,9 +296,10 @@ suite('WorkspaceSvg', function() { ''), this.workspace); this.clock.runAll(); assertEventNotFired( - this.eventsFireStub, Blockly.Events.ViewportChange, {}); + this.eventsFireStub, Blockly.Events.ViewportChange, {type: eventUtils.VIEWPORT_CHANGE}); assertEventNotFired( - this.changeListenerSpy, Blockly.Events.ViewportChange, {}); + this.changeListenerSpy, Blockly.Events.ViewportChange, + {type: eventUtils.VIEWPORT_CHANGE}); }); test('domToWorkspace at 0,0 that doesn\'t trigger scroll', function() { // 4 blocks with space in center. @@ -317,9 +320,11 @@ suite('WorkspaceSvg', function() { Blockly.Xml.domToWorkspace(xmlDom, this.workspace); this.clock.runAll(); assertEventNotFired( - this.eventsFireStub, Blockly.Events.ViewportChange, {}); + this.eventsFireStub, Blockly.Events.ViewportChange, + {type: eventUtils.VIEWPORT_CHANGE}); assertEventNotFired( - this.changeListenerSpy, Blockly.Events.ViewportChange, {}); + this.changeListenerSpy, Blockly.Events.ViewportChange, + {type: eventUtils.VIEWPORT_CHANGE}); }); test.skip('domToWorkspace multiple blocks triggers one viewport event', function() { // TODO: Un-skip after adding filtering for consecutive viewport events. diff --git a/tests/mocha/zoom_controls_test.js b/tests/mocha/zoom_controls_test.js index e17bccddb..3d9d1f2d4 100644 --- a/tests/mocha/zoom_controls_test.js +++ b/tests/mocha/zoom_controls_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.zoomControls'); +const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers'); @@ -31,10 +32,10 @@ suite("Zoom Controls", function() { assertEventFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'zoom_controls'}, this.workspace.id, null); + {targetType: 'zoom_controls', type: eventUtils.CLICK}, this.workspace.id, null); assertEventNotFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'workspace'}); + {targetType: 'workspace', type: eventUtils.CLICK}); chai.assert.closeTo(this.workspace.getScale(), 1.2, 0.05); }); test("Zoom out", function() { @@ -42,10 +43,10 @@ suite("Zoom Controls", function() { assertEventFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'zoom_controls'}, this.workspace.id, null); + {targetType: 'zoom_controls', type: eventUtils.CLICK}, this.workspace.id, null); assertEventNotFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'workspace'}); + {targetType: 'workspace', type: eventUtils.CLICK}); chai.assert.closeTo(this.workspace.getScale(), 0.8, 0.05); }); test("Reset zoom", function() { @@ -53,10 +54,10 @@ suite("Zoom Controls", function() { assertEventFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'zoom_controls'}, this.workspace.id, null); + {targetType: 'zoom_controls', type: eventUtils.CLICK}, this.workspace.id, null); assertEventNotFired( this.eventsFireStub, Blockly.Events.Click, - {targetType: 'workspace'}); + {targetType: 'workspace', type: eventUtils.CLICK}); chai.assert.equal(this.workspace.getScale(), 1); }); });