Migrate core/events/block_events.js named requires

This commit is contained in:
kozbial
2021-08-05 15:42:29 -07:00
committed by Monica Kozbial
parent fd0385dd63
commit 7889b02d9b
5 changed files with 80 additions and 80 deletions

View File

@@ -13,17 +13,17 @@
goog.module('Blockly.Events.BlockBase');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Events.Abstract');
goog.require('Blockly.utils.object');
goog.requireType('Blockly.Block');
const Abstract = goog.require('Blockly.Events.Abstract');
/* eslint-disable-next-line no-unused-vars */
const Block = goog.requireType('Blockly.Block');
const object = goog.require('Blockly.utils.object');
/**
* Abstract class for a block event.
* @param {!Blockly.Block=} opt_block The block this event corresponds to.
* @param {!Block=} opt_block The block this event corresponds to.
* Undefined for a blank event.
* @extends {Blockly.Events.Abstract}
* @extends {Abstract}
* @constructor
*/
const BlockBase = function(opt_block) {
@@ -42,8 +42,8 @@ const BlockBase = function(opt_block) {
*/
this.workspaceId = this.isBlank ? '' : opt_block.workspace.id;
};
Blockly.utils.object.inherits(BlockBase,
Blockly.Events.Abstract);
object.inherits(BlockBase,
Abstract);
/**
* Encode the event as JSON.

View File

@@ -13,23 +13,23 @@
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');
goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const Block = goog.requireType('Blockly.Block');
const Events = goog.require('Blockly.Events');
const Xml = goog.require('Blockly.Xml');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/**
* Class for a block change event.
* @param {!Blockly.Block=} opt_block The changed block. Undefined for a blank
* @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 {Blockly.Events.BlockBase}
* @extends {Events.BlockBase}
* @constructor
*/
const BlockChange = function(opt_block, opt_element, opt_name, opt_oldValue,
@@ -43,13 +43,13 @@ const BlockChange = function(opt_block, opt_element, opt_name, opt_oldValue,
this.oldValue = typeof opt_oldValue == 'undefined' ? '' : opt_oldValue;
this.newValue = typeof opt_newValue == 'undefined' ? '' : opt_newValue;
};
Blockly.utils.object.inherits(BlockChange, Blockly.Events.BlockBase);
object.inherits(BlockChange, Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
BlockChange.prototype.type = Blockly.Events.BLOCK_CHANGE;
BlockChange.prototype.type = Events.BLOCK_CHANGE;
/**
* Encode the event as JSON.
@@ -128,14 +128,14 @@ BlockChange.prototype.run = function(forward) {
let oldMutation = '';
if (block.mutationToDom) {
const oldMutationDom = block.mutationToDom();
oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom);
oldMutation = oldMutationDom && Xml.domToText(oldMutationDom);
}
if (block.domToMutation) {
const dom = Blockly.Xml.textToDom(/** @type {string} */
const dom = Xml.textToDom(/** @type {string} */
(value) || '<mutation/>');
block.domToMutation(dom);
}
Blockly.Events.fire(new BlockChange(
Events.fire(new BlockChange(
block, 'mutation', null, oldMutation, value));
break;
}
@@ -144,7 +144,7 @@ BlockChange.prototype.run = function(forward) {
}
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.CHANGE,
registry.register(registry.Type.EVENT, Events.CHANGE,
BlockChange);
exports = BlockChange;

View File

@@ -13,21 +13,21 @@
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');
goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const Block = goog.requireType('Blockly.Block');
const BlockBase = goog.require('Blockly.Events.BlockBase');
const Events = goog.require('Blockly.Events');
const Xml = goog.require('Blockly.Xml');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
const xml = goog.require('Blockly.utils.xml');
/**
* Class for a block creation event.
* @param {!Blockly.Block=} opt_block The created block. Undefined for a blank
* @param {!Block=} opt_block The created block. Undefined for a blank
* event.
* @extends {Blockly.Events.BlockBase}
* @extends {BlockBase}
* @constructor
*/
const BlockCreate = function(opt_block) {
@@ -41,19 +41,19 @@ const BlockCreate = function(opt_block) {
}
if (opt_block.workspace.rendered) {
this.xml = Blockly.Xml.blockToDomWithXY(opt_block);
this.xml = Xml.blockToDomWithXY(opt_block);
} else {
this.xml = Blockly.Xml.blockToDom(opt_block);
this.xml = Xml.blockToDom(opt_block);
}
this.ids = Blockly.Events.getDescendantIds(opt_block);
this.ids = Events.getDescendantIds(opt_block);
};
Blockly.utils.object.inherits(BlockCreate, Blockly.Events.BlockBase);
object.inherits(BlockCreate, BlockBase);
/**
* Type of this event.
* @type {string}
*/
BlockCreate.prototype.type = Blockly.Events.BLOCK_CREATE;
BlockCreate.prototype.type = Events.BLOCK_CREATE;
/**
* Encode the event as JSON.
@@ -61,7 +61,7 @@ BlockCreate.prototype.type = Blockly.Events.BLOCK_CREATE;
*/
BlockCreate.prototype.toJson = function() {
const json = BlockCreate.superClass_.toJson.call(this);
json['xml'] = Blockly.Xml.domToText(this.xml);
json['xml'] = Xml.domToText(this.xml);
json['ids'] = this.ids;
if (!this.recordUndo) {
json['recordUndo'] = this.recordUndo;
@@ -75,7 +75,7 @@ BlockCreate.prototype.toJson = function() {
*/
BlockCreate.prototype.fromJson = function(json) {
BlockCreate.superClass_.fromJson.call(this, json);
this.xml = Blockly.Xml.textToDom(json['xml']);
this.xml = Xml.textToDom(json['xml']);
this.ids = json['ids'];
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
@@ -89,9 +89,9 @@ BlockCreate.prototype.fromJson = function(json) {
BlockCreate.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
if (forward) {
const xml = Blockly.utils.xml.createElement('xml');
xml.appendChild(this.xml);
Blockly.Xml.domToWorkspace(xml, workspace);
const xmlEl = xml.createElement('xml');
xmlEl.appendChild(this.xml);
Xml.domToWorkspace(xmlEl, workspace);
} else {
for (let i = 0; i < this.ids.length; i++) {
const id = this.ids[i];
@@ -106,7 +106,7 @@ BlockCreate.prototype.run = function(forward) {
}
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.CREATE,
registry.register(registry.Type.EVENT, Events.CREATE,
BlockCreate);
exports = BlockCreate;

View File

@@ -13,21 +13,21 @@
goog.module('Blockly.Events.BlockDelete');
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');
goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const Block = goog.requireType('Blockly.Block');
const BlockBase = goog.require('Blockly.Events.BlockBase');
const Events = goog.require('Blockly.Events');
const Xml = goog.require('Blockly.Xml');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
const xml = goog.require('Blockly.utils.xml');
/**
* Class for a block deletion event.
* @param {!Blockly.Block=} opt_block The deleted block. Undefined for a blank
* @param {!Block=} opt_block The deleted block. Undefined for a blank
* event.
* @extends {Blockly.Events.BlockBase}
* @extends {BlockBase}
* @constructor
*/
const BlockDelete = function(opt_block) {
@@ -44,19 +44,19 @@ const BlockDelete = function(opt_block) {
}
if (opt_block.workspace.rendered) {
this.oldXml = Blockly.Xml.blockToDomWithXY(opt_block);
this.oldXml = Xml.blockToDomWithXY(opt_block);
} else {
this.oldXml = Blockly.Xml.blockToDom(opt_block);
this.oldXml = Xml.blockToDom(opt_block);
}
this.ids = Blockly.Events.getDescendantIds(opt_block);
this.ids = Events.getDescendantIds(opt_block);
};
Blockly.utils.object.inherits(BlockDelete, Blockly.Events.BlockBase);
object.inherits(BlockDelete, BlockBase);
/**
* Type of this event.
* @type {string}
*/
BlockDelete.prototype.type = Blockly.Events.BLOCK_DELETE;
BlockDelete.prototype.type = Events.BLOCK_DELETE;
/**
* Encode the event as JSON.
@@ -64,7 +64,7 @@ BlockDelete.prototype.type = Blockly.Events.BLOCK_DELETE;
*/
BlockDelete.prototype.toJson = function() {
const json = BlockDelete.superClass_.toJson.call(this);
json['oldXml'] = Blockly.Xml.domToText(this.oldXml);
json['oldXml'] = Xml.domToText(this.oldXml);
json['ids'] = this.ids;
if (!this.recordUndo) {
json['recordUndo'] = this.recordUndo;
@@ -78,7 +78,7 @@ BlockDelete.prototype.toJson = function() {
*/
BlockDelete.prototype.fromJson = function(json) {
BlockDelete.superClass_.fromJson.call(this, json);
this.oldXml = Blockly.Xml.textToDom(json['oldXml']);
this.oldXml = Xml.textToDom(json['oldXml']);
this.ids = json['ids'];
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
@@ -103,13 +103,13 @@ BlockDelete.prototype.run = function(forward) {
}
}
} else {
const xml = Blockly.utils.xml.createElement('xml');
xml.appendChild(this.oldXml);
Blockly.Xml.domToWorkspace(xml, workspace);
const xmlEl = xml.createElement('xml');
xmlEl.appendChild(this.oldXml);
Xml.domToWorkspace(xmlEl, workspace);
}
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.DELETE,
registry.register(registry.Type.EVENT, Events.DELETE,
BlockDelete);
exports = BlockDelete;

View File

@@ -13,21 +13,21 @@
goog.module('Blockly.Events.BlockMove');
goog.module.declareLegacyNamespace();
goog.require('Blockly.connectionTypes');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockBase');
goog.require('Blockly.registry');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.object');
goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const Block = goog.requireType('Blockly.Block');
const BlockBase = goog.require('Blockly.Events.BlockBase');
const Coordinate = goog.require('Blockly.utils.Coordinate');
const Events = goog.require('Blockly.Events');
const connectionTypes = goog.require('Blockly.connectionTypes');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/**
* Class for a block move event. Created before the move.
* @param {!Blockly.Block=} opt_block The moved block. Undefined for a blank
* @param {!Block=} opt_block The moved block. Undefined for a blank
* event.
* @extends {Blockly.Events.BlockBase}
* @extends {BlockBase}
* @constructor
*/
const BlockMove = function(opt_block) {
@@ -45,13 +45,13 @@ const BlockMove = function(opt_block) {
this.oldInputName = location.inputName;
this.oldCoordinate = location.coordinate;
};
Blockly.utils.object.inherits(BlockMove, Blockly.Events.BlockBase);
object.inherits(BlockMove, BlockBase);
/**
* Type of this event.
* @type {string}
*/
BlockMove.prototype.type = Blockly.Events.BLOCK_MOVE;
BlockMove.prototype.type = Events.BLOCK_MOVE;
/**
* Encode the event as JSON.
@@ -86,7 +86,7 @@ BlockMove.prototype.fromJson = function(json) {
if (json['newCoordinate']) {
const xy = json['newCoordinate'].split(',');
this.newCoordinate =
new Blockly.utils.Coordinate(Number(xy[0]), Number(xy[1]));
new Coordinate(Number(xy[0]), Number(xy[1]));
}
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
@@ -133,7 +133,7 @@ BlockMove.prototype.currentLocation_ = function() {
BlockMove.prototype.isNull = function() {
return this.oldParentId == this.newParentId &&
this.oldInputName == this.newInputName &&
Blockly.utils.Coordinate.equals(this.oldCoordinate, this.newCoordinate);
Coordinate.equals(this.oldCoordinate, this.newCoordinate);
};
/**
@@ -173,7 +173,7 @@ BlockMove.prototype.run = function(forward) {
if (input) {
parentConnection = input.connection;
}
} else if (connectionType == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
} else if (connectionType == connectionTypes.PREVIOUS_STATEMENT) {
parentConnection = parentBlock.nextConnection;
}
if (parentConnection) {
@@ -184,7 +184,7 @@ BlockMove.prototype.run = function(forward) {
}
};
Blockly.registry.register(Blockly.registry.Type.EVENT, Blockly.Events.MOVE,
registry.register(registry.Type.EVENT, Events.MOVE,
BlockMove);
exports = BlockMove;