Migrate core/events/block_events.js to goog.module

This commit is contained in:
kozbial
2021-08-05 15:42:12 -07:00
committed by Monica Kozbial
parent 20dad54d38
commit fd0385dd63
6 changed files with 79 additions and 64 deletions

View File

@@ -10,11 +10,10 @@
*/
'use strict';
goog.provide('Blockly.Events.BlockBase');
goog.module('Blockly.Events.BlockBase');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('Blockly.Events.BlockBase');
goog.require('Blockly.utils.object');
goog.requireType('Blockly.Block');
@@ -27,8 +26,8 @@ goog.requireType('Blockly.Block');
* @extends {Blockly.Events.Abstract}
* @constructor
*/
Blockly.Events.BlockBase = function(opt_block) {
Blockly.Events.BlockBase.superClass_.constructor.call(this);
const BlockBase = function(opt_block) {
BlockBase.superClass_.constructor.call(this);
this.isBlank = typeof opt_block == 'undefined';
/**
@@ -43,15 +42,15 @@ Blockly.Events.BlockBase = function(opt_block) {
*/
this.workspaceId = this.isBlank ? '' : opt_block.workspace.id;
};
Blockly.utils.object.inherits(Blockly.Events.BlockBase,
Blockly.utils.object.inherits(BlockBase,
Blockly.Events.Abstract);
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.BlockBase.prototype.toJson = function() {
const json = Blockly.Events.BlockBase.superClass_.toJson.call(this);
BlockBase.prototype.toJson = function() {
const json = BlockBase.superClass_.toJson.call(this);
json['blockId'] = this.blockId;
return json;
};
@@ -60,7 +59,9 @@ Blockly.Events.BlockBase.prototype.toJson = function() {
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.BlockBase.prototype.fromJson = function(json) {
Blockly.Events.BlockBase.superClass_.fromJson.call(this, json);
BlockBase.prototype.fromJson = function(json) {
BlockBase.superClass_.fromJson.call(this, json);
this.blockId = json['blockId'];
};
exports = BlockBase;

View File

@@ -10,9 +10,11 @@
*/
'use strict';
goog.provide('Blockly.Events.BlockChange');
goog.module('Blockly.Events.BlockChange');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Events');
goog.require('Blockly.registry');
goog.require('Blockly.utils.object');
goog.require('Blockly.Xml');
@@ -30,9 +32,9 @@ goog.requireType('Blockly.Block');
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.BlockChange = function(opt_block, opt_element, opt_name, opt_oldValue,
const BlockChange = function(opt_block, opt_element, opt_name, opt_oldValue,
opt_newValue) {
Blockly.Events.BlockChange.superClass_.constructor.call(this, opt_block);
BlockChange.superClass_.constructor.call(this, opt_block);
if (!opt_block) {
return; // Blank event to be populated by fromJson.
}
@@ -41,20 +43,20 @@ Blockly.Events.BlockChange = function(opt_block, opt_element, opt_name, opt_oldV
this.oldValue = typeof opt_oldValue == 'undefined' ? '' : opt_oldValue;
this.newValue = typeof opt_newValue == 'undefined' ? '' : opt_newValue;
};
Blockly.utils.object.inherits(Blockly.Events.BlockChange, Blockly.Events.BlockBase);
Blockly.utils.object.inherits(BlockChange, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.BlockChange.prototype.type = Blockly.Events.BLOCK_CHANGE;
BlockChange.prototype.type = Blockly.Events.BLOCK_CHANGE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.BlockChange.prototype.toJson = function() {
const json = Blockly.Events.BlockChange.superClass_.toJson.call(this);
BlockChange.prototype.toJson = function() {
const json = BlockChange.superClass_.toJson.call(this);
json['element'] = this.element;
if (this.name) {
json['name'] = this.name;
@@ -68,8 +70,8 @@ Blockly.Events.BlockChange.prototype.toJson = function() {
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.BlockChange.prototype.fromJson = function(json) {
Blockly.Events.BlockChange.superClass_.fromJson.call(this, json);
BlockChange.prototype.fromJson = function(json) {
BlockChange.superClass_.fromJson.call(this, json);
this.element = json['element'];
this.name = json['name'];
this.oldValue = json['oldValue'];
@@ -80,7 +82,7 @@ Blockly.Events.BlockChange.prototype.fromJson = function(json) {
* Does this event record any change of state?
* @return {boolean} False if something changed.
*/
Blockly.Events.BlockChange.prototype.isNull = function() {
BlockChange.prototype.isNull = function() {
return this.oldValue == this.newValue;
};
@@ -88,7 +90,7 @@ Blockly.Events.BlockChange.prototype.isNull = function() {
* Run a change event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
Blockly.Events.BlockChange.prototype.run = function(forward) {
BlockChange.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
const block = workspace.getBlockById(this.blockId);
if (!block) {
@@ -133,7 +135,7 @@ Blockly.Events.BlockChange.prototype.run = function(forward) {
(value) || '<mutation/>');
block.domToMutation(dom);
}
Blockly.Events.fire(new Blockly.Events.BlockChange(
Blockly.Events.fire(new BlockChange(
block, 'mutation', null, oldMutation, value));
break;
}
@@ -143,4 +145,6 @@ Blockly.Events.BlockChange.prototype.run = function(forward) {
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.CHANGE,
Blockly.Events.BlockChange);
BlockChange);
exports = BlockChange;

View File

@@ -10,10 +10,12 @@
*/
'use strict';
goog.provide('Blockly.Events.BlockCreate');
goog.module('Blockly.Events.BlockCreate');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockBase');
goog.require('Blockly.registry');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.xml');
goog.require('Blockly.Xml');
@@ -28,8 +30,8 @@ goog.requireType('Blockly.Block');
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.BlockCreate = function(opt_block) {
Blockly.Events.BlockCreate.superClass_.constructor.call(this, opt_block);
const BlockCreate = function(opt_block) {
BlockCreate.superClass_.constructor.call(this, opt_block);
if (!opt_block) {
return; // Blank event to be populated by fromJson.
}
@@ -45,20 +47,20 @@ Blockly.Events.BlockCreate = function(opt_block) {
}
this.ids = Blockly.Events.getDescendantIds(opt_block);
};
Blockly.utils.object.inherits(Blockly.Events.BlockCreate, Blockly.Events.BlockBase);
Blockly.utils.object.inherits(BlockCreate, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.BlockCreate.prototype.type = Blockly.Events.BLOCK_CREATE;
BlockCreate.prototype.type = Blockly.Events.BLOCK_CREATE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.BlockCreate.prototype.toJson = function() {
const json = Blockly.Events.BlockCreate.superClass_.toJson.call(this);
BlockCreate.prototype.toJson = function() {
const json = BlockCreate.superClass_.toJson.call(this);
json['xml'] = Blockly.Xml.domToText(this.xml);
json['ids'] = this.ids;
if (!this.recordUndo) {
@@ -71,8 +73,8 @@ Blockly.Events.BlockCreate.prototype.toJson = function() {
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.BlockCreate.prototype.fromJson = function(json) {
Blockly.Events.BlockCreate.superClass_.fromJson.call(this, json);
BlockCreate.prototype.fromJson = function(json) {
BlockCreate.superClass_.fromJson.call(this, json);
this.xml = Blockly.Xml.textToDom(json['xml']);
this.ids = json['ids'];
if (json['recordUndo'] !== undefined) {
@@ -84,7 +86,7 @@ Blockly.Events.BlockCreate.prototype.fromJson = function(json) {
* Run a creation event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
Blockly.Events.BlockCreate.prototype.run = function(forward) {
BlockCreate.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
if (forward) {
const xml = Blockly.utils.xml.createElement('xml');
@@ -105,4 +107,6 @@ Blockly.Events.BlockCreate.prototype.run = function(forward) {
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.CREATE,
Blockly.Events.BlockCreate);
BlockCreate);
exports = BlockCreate;

View File

@@ -10,7 +10,8 @@
*/
'use strict';
goog.provide('Blockly.Events.BlockDelete');
goog.module('Blockly.Events.BlockDelete');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockBase');
@@ -29,8 +30,8 @@ goog.requireType('Blockly.Block');
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.BlockDelete = function(opt_block) {
Blockly.Events.BlockDelete.superClass_.constructor.call(this, opt_block);
const BlockDelete = function(opt_block) {
BlockDelete.superClass_.constructor.call(this, opt_block);
if (!opt_block) {
return; // Blank event to be populated by fromJson.
}
@@ -49,20 +50,20 @@ Blockly.Events.BlockDelete = function(opt_block) {
}
this.ids = Blockly.Events.getDescendantIds(opt_block);
};
Blockly.utils.object.inherits(Blockly.Events.BlockDelete, Blockly.Events.BlockBase);
Blockly.utils.object.inherits(BlockDelete, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.BlockDelete.prototype.type = Blockly.Events.BLOCK_DELETE;
BlockDelete.prototype.type = Blockly.Events.BLOCK_DELETE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.BlockDelete.prototype.toJson = function() {
const json = Blockly.Events.BlockDelete.superClass_.toJson.call(this);
BlockDelete.prototype.toJson = function() {
const json = BlockDelete.superClass_.toJson.call(this);
json['oldXml'] = Blockly.Xml.domToText(this.oldXml);
json['ids'] = this.ids;
if (!this.recordUndo) {
@@ -75,8 +76,8 @@ Blockly.Events.BlockDelete.prototype.toJson = function() {
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.BlockDelete.prototype.fromJson = function(json) {
Blockly.Events.BlockDelete.superClass_.fromJson.call(this, json);
BlockDelete.prototype.fromJson = function(json) {
BlockDelete.superClass_.fromJson.call(this, json);
this.oldXml = Blockly.Xml.textToDom(json['oldXml']);
this.ids = json['ids'];
if (json['recordUndo'] !== undefined) {
@@ -88,7 +89,7 @@ Blockly.Events.BlockDelete.prototype.fromJson = function(json) {
* Run a deletion event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
Blockly.Events.BlockDelete.prototype.run = function(forward) {
BlockDelete.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
if (forward) {
for (let i = 0; i < this.ids.length; i++) {
@@ -109,4 +110,6 @@ Blockly.Events.BlockDelete.prototype.run = function(forward) {
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.DELETE,
Blockly.Events.BlockDelete);
BlockDelete);
exports = BlockDelete;

View File

@@ -10,7 +10,8 @@
*/
'use strict';
goog.provide('Blockly.Events.BlockMove');
goog.module('Blockly.Events.BlockMove');
goog.module.declareLegacyNamespace();
goog.require('Blockly.connectionTypes');
goog.require('Blockly.Events');
@@ -29,8 +30,8 @@ goog.requireType('Blockly.Block');
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.BlockMove = function(opt_block) {
Blockly.Events.BlockMove.superClass_.constructor.call(this, opt_block);
const BlockMove = function(opt_block) {
BlockMove.superClass_.constructor.call(this, opt_block);
if (!opt_block) {
return; // Blank event to be populated by fromJson.
}
@@ -44,20 +45,20 @@ Blockly.Events.BlockMove = function(opt_block) {
this.oldInputName = location.inputName;
this.oldCoordinate = location.coordinate;
};
Blockly.utils.object.inherits(Blockly.Events.BlockMove, Blockly.Events.BlockBase);
Blockly.utils.object.inherits(BlockMove, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.BlockMove.prototype.type = Blockly.Events.BLOCK_MOVE;
BlockMove.prototype.type = Blockly.Events.BLOCK_MOVE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.BlockMove.prototype.toJson = function() {
const json = Blockly.Events.BlockMove.superClass_.toJson.call(this);
BlockMove.prototype.toJson = function() {
const json = BlockMove.superClass_.toJson.call(this);
if (this.newParentId) {
json['newParentId'] = this.newParentId;
}
@@ -78,8 +79,8 @@ Blockly.Events.BlockMove.prototype.toJson = function() {
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.BlockMove.prototype.fromJson = function(json) {
Blockly.Events.BlockMove.superClass_.fromJson.call(this, json);
BlockMove.prototype.fromJson = function(json) {
BlockMove.superClass_.fromJson.call(this, json);
this.newParentId = json['newParentId'];
this.newInputName = json['newInputName'];
if (json['newCoordinate']) {
@@ -95,7 +96,7 @@ Blockly.Events.BlockMove.prototype.fromJson = function(json) {
/**
* Record the block's new location. Called after the move.
*/
Blockly.Events.BlockMove.prototype.recordNew = function() {
BlockMove.prototype.recordNew = function() {
const location = this.currentLocation_();
this.newParentId = location.parentId;
this.newInputName = location.inputName;
@@ -108,7 +109,7 @@ Blockly.Events.BlockMove.prototype.recordNew = function() {
* @return {!Object} Collection of location info.
* @private
*/
Blockly.Events.BlockMove.prototype.currentLocation_ = function() {
BlockMove.prototype.currentLocation_ = function() {
const workspace = this.getEventWorkspace_();
const block = workspace.getBlockById(this.blockId);
const location = {};
@@ -129,7 +130,7 @@ Blockly.Events.BlockMove.prototype.currentLocation_ = function() {
* Does this event record any change of state?
* @return {boolean} False if something changed.
*/
Blockly.Events.BlockMove.prototype.isNull = function() {
BlockMove.prototype.isNull = function() {
return this.oldParentId == this.newParentId &&
this.oldInputName == this.newInputName &&
Blockly.utils.Coordinate.equals(this.oldCoordinate, this.newCoordinate);
@@ -139,7 +140,7 @@ Blockly.Events.BlockMove.prototype.isNull = function() {
* Run a move event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
Blockly.Events.BlockMove.prototype.run = function(forward) {
BlockMove.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
const block = workspace.getBlockById(this.blockId);
if (!block) {
@@ -184,4 +185,6 @@ Blockly.Events.BlockMove.prototype.run = function(forward) {
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.MOVE,
Blockly.Events.BlockMove);
BlockMove);
exports = BlockMove;

View File

@@ -36,12 +36,12 @@ goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockl
goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.common', 'Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']);
goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']);
goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_block_base.js', ['Blockly.Events.BlockBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Events.BlockBase', 'Blockly.utils.object']);
goog.addDependency('../../core/events/events_block_change.js', ['Blockly.Events.BlockChange'], ['Blockly.Events', 'Blockly.Xml', 'Blockly.utils.object']);
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.utils.object', 'Blockly.utils.xml']);
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml']);
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', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']);
goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object']);
goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});