mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
fix: make eventUtils throw if event type not registered (#6381)
* chore: update lint rules * fix: have eventUtils.get throw if event isn't found * chore: remove nonnull assertion from eventUtils.get and format
This commit is contained in:
committed by
GitHub
parent
980fe138e7
commit
60bc01acc8
@@ -291,7 +291,7 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
|
||||
// Fire a create event.
|
||||
if (eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(this));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(this));
|
||||
}
|
||||
} finally {
|
||||
if (!existingGroup) {
|
||||
@@ -323,7 +323,7 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
|
||||
this.unplug(healStack);
|
||||
if (eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))!(this));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this));
|
||||
}
|
||||
|
||||
if (this.onchangeWrapper_) {
|
||||
@@ -1248,8 +1248,8 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
*/
|
||||
setInputsInline(newBoolean: boolean) {
|
||||
if (this.inputsInline !== newBoolean) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this, 'inline', null, this.inputsInline, newBoolean));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this, 'inline', null, this.inputsInline, newBoolean));
|
||||
this.inputsInline = newBoolean;
|
||||
}
|
||||
}
|
||||
@@ -1318,8 +1318,8 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
if (this.isEnabled() !== enabled) {
|
||||
const oldValue = this.disabled;
|
||||
this.disabled = !enabled;
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this, 'disabled', null, oldValue, !enabled));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this, 'disabled', null, oldValue, !enabled));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1357,8 +1357,8 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
*/
|
||||
setCollapsed(collapsed: boolean) {
|
||||
if (this.collapsed_ !== collapsed) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this, 'collapsed', null, this.collapsed_, collapsed));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this, 'collapsed', null, this.collapsed_, collapsed));
|
||||
this.collapsed_ = collapsed;
|
||||
}
|
||||
}
|
||||
@@ -2064,8 +2064,8 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
if (this.commentModel.text === text) {
|
||||
return;
|
||||
}
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this, 'comment', null, this.commentModel.text, text));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this, 'comment', null, this.commentModel.text, text));
|
||||
this.commentModel.text = text;
|
||||
// AnyDuringMigration because: Type 'string | null' is not assignable to
|
||||
// type 'string | Comment'.
|
||||
@@ -2111,7 +2111,7 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
throw Error('Block has parent.');
|
||||
}
|
||||
const event =
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove;
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))(this) as BlockMove;
|
||||
this.xy_.translate(dx, dy);
|
||||
event.recordNew();
|
||||
eventUtils.fire(event);
|
||||
|
||||
@@ -163,8 +163,8 @@ export class BlockDragger implements IBlockDragger {
|
||||
|
||||
/** Fire a UI event at the start of a block drag. */
|
||||
protected fireDragStartEvent_() {
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))!
|
||||
(this.draggingBlock_, true, this.draggingBlock_.getDescendants(false));
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))(
|
||||
this.draggingBlock_, true, this.draggingBlock_.getDescendants(false));
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
@@ -312,8 +312,8 @@ export class BlockDragger implements IBlockDragger {
|
||||
|
||||
/** Fire a UI event at the end of a block drag. */
|
||||
protected fireDragEndEvent_() {
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))!
|
||||
(this.draggingBlock_, false, this.draggingBlock_.getDescendants(false));
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))(
|
||||
this.draggingBlock_, false, this.draggingBlock_.getDescendants(false));
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
@@ -352,8 +352,8 @@ export class BlockDragger implements IBlockDragger {
|
||||
|
||||
/** Fire a move event at the end of a block drag. */
|
||||
protected fireMoveEvent_() {
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_MOVE))!
|
||||
(this.draggingBlock_) as BlockMove;
|
||||
const event = new (eventUtils.get(eventUtils.BLOCK_MOVE))(
|
||||
this.draggingBlock_) as BlockMove;
|
||||
event.oldCoordinate = this.startXY_;
|
||||
event.recordNew();
|
||||
eventUtils.fire(event);
|
||||
|
||||
@@ -279,8 +279,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
|
||||
eventUtils.enable();
|
||||
}
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))!
|
||||
(oldId, this.id, this.workspace.id);
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))(
|
||||
oldId, this.id, this.workspace.id);
|
||||
eventUtils.fire(event);
|
||||
common.setSelected(this);
|
||||
this.addSelect();
|
||||
@@ -294,8 +294,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
|
||||
if (common.getSelected() !== this) {
|
||||
return;
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))!
|
||||
(this.id, null, this.workspace.id);
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))(
|
||||
this.id, null, this.workspace.id);
|
||||
event.workspaceId = this.workspace.id;
|
||||
eventUtils.fire(event);
|
||||
common.setSelected(null);
|
||||
|
||||
@@ -192,8 +192,8 @@ export class BubbleDragger {
|
||||
/** Fire a move event at the end of a bubble drag. */
|
||||
private fireMoveEvent_() {
|
||||
if (this.bubble instanceof WorkspaceCommentSvg) {
|
||||
const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))!
|
||||
(this.bubble) as CommentMove;
|
||||
const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))(
|
||||
this.bubble) as CommentMove;
|
||||
event.setOldCoordinate(this.startXY_);
|
||||
event.recordNew();
|
||||
eventUtils.fire(event);
|
||||
|
||||
@@ -166,9 +166,9 @@ export class Comment extends Icon {
|
||||
*/
|
||||
function(this: Comment, _e: Event) {
|
||||
if (this.cachedText_ !== this.model_.text) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this.block_, 'comment', null, this.cachedText_,
|
||||
this.model_.text));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this.block_, 'comment', null, this.cachedText_,
|
||||
this.model_.text));
|
||||
}
|
||||
});
|
||||
this.onInputWrapper_ = browserEvents.conditionalBind(
|
||||
@@ -232,8 +232,8 @@ export class Comment extends Icon {
|
||||
if (visible === this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))!
|
||||
(this.block_, visible, 'comment'));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))(
|
||||
this.block_, visible, 'comment'));
|
||||
this.model_.pinned = visible;
|
||||
if (visible) {
|
||||
this.createBubble_();
|
||||
|
||||
@@ -116,7 +116,7 @@ export class Connection implements IASTNodeLocationWithBlock {
|
||||
let event;
|
||||
if (eventUtils.isEnabled()) {
|
||||
event =
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove;
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))(childBlock) as BlockMove;
|
||||
}
|
||||
connectReciprocally(this, childConnection);
|
||||
childBlock.setParent(parentBlock);
|
||||
@@ -293,7 +293,7 @@ export class Connection implements IASTNodeLocationWithBlock {
|
||||
let event;
|
||||
if (eventUtils.isEnabled()) {
|
||||
event =
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove;
|
||||
new (eventUtils.get(eventUtils.BLOCK_MOVE))(childBlock) as BlockMove;
|
||||
}
|
||||
const otherConnection = this.targetConnection;
|
||||
if (otherConnection) {
|
||||
|
||||
@@ -249,7 +249,7 @@ export function callbackFactory(block: Block, xml: Element): Function {
|
||||
eventUtils.enable();
|
||||
}
|
||||
if (eventUtils.isEnabled() && !newBlock.isShadow()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(newBlock));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(newBlock));
|
||||
}
|
||||
newBlock.select();
|
||||
};
|
||||
|
||||
@@ -328,6 +328,7 @@ export function show(
|
||||
const internal = {
|
||||
/**
|
||||
* Get sizing info about the bounding element.
|
||||
*
|
||||
* @return An object containing size information about the bounding element
|
||||
* (bounding box and width/height).
|
||||
*/
|
||||
@@ -348,6 +349,7 @@ const internal = {
|
||||
/**
|
||||
* Helper to position the drop-down and the arrow, maintaining bounds.
|
||||
* See explanation of origin points in show.
|
||||
*
|
||||
* @param primaryX Desired origin point x, in absolute px.
|
||||
* @param primaryY Desired origin point y, in absolute px.
|
||||
* @param secondaryX Secondary/alternative origin point x, in absolute px.
|
||||
|
||||
@@ -507,12 +507,16 @@ export function fromJson(
|
||||
* Gets the class for a specific event type from the registry.
|
||||
*
|
||||
* @param eventType The type of the event to get.
|
||||
* @returns The event class with the given type or null if none exists.
|
||||
* @returns The event class with the given type.
|
||||
* @alias Blockly.Events.utils.get
|
||||
*/
|
||||
export function get(eventType: string):
|
||||
(new (...p1: AnyDuringMigration[]) => Abstract)|null {
|
||||
return registry.getClass(registry.Type.EVENT, eventType);
|
||||
(new (...p1: AnyDuringMigration[]) => Abstract) {
|
||||
const event = registry.getClass(registry.Type.EVENT, eventType);
|
||||
if (!event) {
|
||||
throw new Error(`Event type ${eventType} not found in registry.`);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -967,8 +967,8 @@ export abstract class Field implements IASTNodeLocationSvg,
|
||||
|
||||
this.doValueUpdate_(newValue);
|
||||
if (source && eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(source, 'field', this.name || null, oldValue, newValue));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
source, 'field', this.name || null, oldValue, newValue));
|
||||
}
|
||||
if (this.isDirty_) {
|
||||
this.forceRerender();
|
||||
|
||||
@@ -187,9 +187,9 @@ export class FieldTextInput extends Field {
|
||||
// Revert value when the text becomes invalid.
|
||||
this.value_ = this.htmlInput_!.getAttribute('data-untyped-default-value');
|
||||
if (this.sourceBlock_ && eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(this.sourceBlock_, 'field', this.name || null,
|
||||
oldValue, this.value_));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
this.sourceBlock_, 'field', this.name || null, oldValue,
|
||||
this.value_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -991,13 +991,13 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
|
||||
// Fire a VarCreate event for each (if any) new variable created.
|
||||
for (let i = 0; i < newVariables.length; i++) {
|
||||
const thisVariable = newVariables[i];
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))!
|
||||
(thisVariable));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.VAR_CREATE))(thisVariable));
|
||||
}
|
||||
|
||||
// Block events come after var events, in case they refer to newly created
|
||||
// variables.
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(newBlock));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(newBlock));
|
||||
}
|
||||
if (this.autoClose) {
|
||||
this.hide();
|
||||
|
||||
@@ -625,8 +625,8 @@ export class Gesture {
|
||||
* @param ws The workspace that a user clicks on.
|
||||
*/
|
||||
private fireWorkspaceClick_(ws: WorkspaceSvg) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.CLICK))!
|
||||
(null, ws.id, 'workspace'));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.CLICK))(null, ws.id, 'workspace'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,8 +712,8 @@ export class Gesture {
|
||||
}
|
||||
} else {
|
||||
// Clicks events are on the start block, even if it was a shadow.
|
||||
const event = new (eventUtils.get(eventUtils.CLICK))!
|
||||
(this.startBlock_, this.startWorkspace_.id, 'block');
|
||||
const event = new (eventUtils.get(eventUtils.CLICK))(
|
||||
this.startBlock_, this.startWorkspace_.id, 'block');
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
this.bringBlockToFront_();
|
||||
|
||||
@@ -301,8 +301,8 @@ export class Mutator extends Icon {
|
||||
// No change.
|
||||
return;
|
||||
}
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))!
|
||||
(this.block_, visible, 'mutator'));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))(
|
||||
this.block_, visible, 'mutator'));
|
||||
if (visible) {
|
||||
// Create the bubble.
|
||||
this.bubble_ = new Bubble(
|
||||
@@ -460,7 +460,7 @@ export class Mutator extends Icon {
|
||||
|
||||
const newExtraState = BlockChange.getExtraBlockState_(block);
|
||||
if (oldExtraState !== newExtraState) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!(
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
block, 'mutation', null, oldExtraState, newExtraState));
|
||||
// Ensure that any bump is part of this mutation's event group.
|
||||
const mutationGroup = eventUtils.getGroup();
|
||||
|
||||
@@ -423,8 +423,8 @@ export function mutateCallers(defBlock: Block) {
|
||||
// undo action since it is deterministically tied to the procedure's
|
||||
// definition mutation.
|
||||
eventUtils.setRecordUndo(false);
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
|
||||
(caller, 'mutation', null, oldMutation, newMutation));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
|
||||
caller, 'mutation', null, oldMutation, newMutation));
|
||||
eventUtils.setRecordUndo(oldRecordUndo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,8 +562,8 @@ export class MarkerSvg {
|
||||
*/
|
||||
private fireMarkerEvent_(oldNode: ASTNode, curNode: ASTNode) {
|
||||
const curBlock = curNode.getSourceBlock();
|
||||
const event = new (eventUtils.get(eventUtils.MARKER_MOVE))!
|
||||
(curBlock, this.isCursor(), oldNode, curNode);
|
||||
const event = new (eventUtils.get(eventUtils.MARKER_MOVE))(
|
||||
curBlock, this.isCursor(), oldNode, curNode);
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ export function appendInternal(
|
||||
const block = appendPrivate(state, workspace, {parentConnection, isShadow});
|
||||
|
||||
eventUtils.enable();
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(block));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block));
|
||||
eventUtils.setGroup(existingGroup);
|
||||
eventUtils.setRecordUndo(prevRecordUndo);
|
||||
|
||||
|
||||
@@ -96,8 +96,7 @@ export function load(
|
||||
}
|
||||
dom.stopTextWidthCache();
|
||||
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))!
|
||||
(workspace));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))(workspace));
|
||||
|
||||
eventUtils.setGroup(existingGroup);
|
||||
eventUtils.setRecordUndo(prevRecordUndo);
|
||||
|
||||
@@ -928,8 +928,8 @@ export class Toolbox extends DeleteArea implements IAutoHideable,
|
||||
if (oldItem === newItem) {
|
||||
newElement = null;
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.TOOLBOX_ITEM_SELECT))!
|
||||
(oldElement, newElement, this.workspace_.id);
|
||||
const event = new (eventUtils.get(eventUtils.TOOLBOX_ITEM_SELECT))(
|
||||
oldElement, newElement, this.workspace_.id);
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -503,8 +503,8 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
|
||||
* @param trashcanOpen Whether the flyout is opening.
|
||||
*/
|
||||
private fireUiEvent_(trashcanOpen: boolean) {
|
||||
const uiEvent = new (eventUtils.get(eventUtils.TRASHCAN_OPEN))!
|
||||
(trashcanOpen, this.workspace.id);
|
||||
const uiEvent = new (eventUtils.get(eventUtils.TRASHCAN_OPEN))(
|
||||
trashcanOpen, this.workspace.id);
|
||||
eventUtils.fire(uiEvent);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ export class VariableMap {
|
||||
*/
|
||||
private renameVariableAndUses_(
|
||||
variable: VariableModel, newName: string, blocks: Block[]) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_RENAME))!
|
||||
(variable, newName));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.VAR_RENAME))(variable, newName));
|
||||
variable.name = newName;
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
blocks[i].updateVarName(variable);
|
||||
@@ -139,7 +139,7 @@ export class VariableMap {
|
||||
blocks[i].renameVarById(variable.getId(), conflictVar.getId());
|
||||
}
|
||||
// Finally delete the original variable, which is now unreferenced.
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_DELETE))!(variable));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_DELETE))(variable));
|
||||
// And remove it from the list.
|
||||
arrayUtils.removeElem(this.variableMap.get(type)!, variable);
|
||||
}
|
||||
@@ -200,8 +200,8 @@ export class VariableMap {
|
||||
const tempVar = variableList[i];
|
||||
if (tempVar.getId() === variableId) {
|
||||
variableList.splice(i, 1);
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_DELETE))!
|
||||
(variable));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.VAR_DELETE))(variable));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export class VariableModel {
|
||||
*/
|
||||
this.id_ = opt_id || idGenerator.genUid();
|
||||
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))!(this));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))(this));
|
||||
}
|
||||
|
||||
/** @returns The ID for the variable. */
|
||||
|
||||
@@ -88,8 +88,8 @@ export class Warning extends Icon {
|
||||
if (visible === this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))!
|
||||
(this.block_, visible, 'warning'));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))(
|
||||
this.block_, visible, 'warning'));
|
||||
if (visible) {
|
||||
this.createBubble_();
|
||||
} else {
|
||||
|
||||
@@ -97,7 +97,7 @@ export class WorkspaceComment {
|
||||
}
|
||||
|
||||
if (eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))!(this));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))(this));
|
||||
}
|
||||
// Remove from the list of top comments and the comment database.
|
||||
this.workspace.removeTopComment(this);
|
||||
@@ -167,7 +167,7 @@ export class WorkspaceComment {
|
||||
*/
|
||||
moveBy(dx: number, dy: number) {
|
||||
const event =
|
||||
new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove;
|
||||
new (eventUtils.get(eventUtils.COMMENT_MOVE))(this) as CommentMove;
|
||||
this.xy_.translate(dx, dy);
|
||||
event.recordNew();
|
||||
eventUtils.fire(event);
|
||||
@@ -252,8 +252,8 @@ export class WorkspaceComment {
|
||||
*/
|
||||
setContent(content: string) {
|
||||
if (this.content_ !== content) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CHANGE))!
|
||||
(this, this.content_, content));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CHANGE))(
|
||||
this, this.content_, content));
|
||||
this.content_ = content;
|
||||
}
|
||||
}
|
||||
@@ -314,8 +314,8 @@ export class WorkspaceComment {
|
||||
eventUtils.setGroup(true);
|
||||
}
|
||||
try {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CREATE))!
|
||||
(comment));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.COMMENT_CREATE))(comment));
|
||||
} finally {
|
||||
if (!existingGroup) {
|
||||
eventUtils.setGroup(false);
|
||||
|
||||
@@ -146,7 +146,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
|
||||
}
|
||||
|
||||
if (eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))!(this));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))(this));
|
||||
}
|
||||
|
||||
dom.removeNode(this.svgGroup_);
|
||||
@@ -234,8 +234,8 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
|
||||
eventUtils.enable();
|
||||
}
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))!
|
||||
(oldId, this.id, this.workspace.id);
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))(
|
||||
oldId, this.id, this.workspace.id);
|
||||
eventUtils.fire(event);
|
||||
common.setSelected(this);
|
||||
this.addSelect();
|
||||
@@ -250,8 +250,8 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
|
||||
if (common.getSelected() !== this) {
|
||||
return;
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))!
|
||||
(this.id, null, this.workspace.id);
|
||||
const event = new (eventUtils.get(eventUtils.SELECTED))(
|
||||
this.id, null, this.workspace.id);
|
||||
eventUtils.fire(event);
|
||||
common.setSelected(null);
|
||||
this.removeSelect();
|
||||
@@ -350,7 +350,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
|
||||
*/
|
||||
override moveBy(dx: number, dy: number) {
|
||||
const event =
|
||||
new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove;
|
||||
new (eventUtils.get(eventUtils.COMMENT_MOVE))(this) as CommentMove;
|
||||
// TODO: Do I need to look up the relative to surface XY position here?
|
||||
const xy = this.getRelativeToSurfaceXY();
|
||||
this.translate(xy.x + dx, xy.y + dy);
|
||||
|
||||
@@ -577,8 +577,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
const event = new (eventUtils.get(eventUtils.THEME_CHANGE))!
|
||||
(this.getTheme().name, this.id);
|
||||
const event = new (eventUtils.get(eventUtils.THEME_CHANGE))(
|
||||
this.getTheme().name, this.id);
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
@@ -1141,8 +1141,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
// of negligible changes in viewport top/left.
|
||||
return;
|
||||
}
|
||||
const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))!
|
||||
(top, left, scale, this.id, this.oldScale_);
|
||||
const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))(
|
||||
top, left, scale, this.id, this.oldScale_);
|
||||
this.oldScale_ = scale;
|
||||
this.oldTop_ = top;
|
||||
this.oldLeft_ = left;
|
||||
@@ -1469,7 +1469,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
eventUtils.enable();
|
||||
}
|
||||
if (eventUtils.isEnabled() && !block!.isShadow()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(block!));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block!));
|
||||
}
|
||||
block!.select();
|
||||
return block!;
|
||||
|
||||
@@ -503,8 +503,7 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] {
|
||||
if ((workspace as WorkspaceSvg).setResizesEnabled) {
|
||||
(workspace as WorkspaceSvg).setResizesEnabled(true);
|
||||
}
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))!
|
||||
(workspace));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))(workspace));
|
||||
return newBlockIds;
|
||||
}
|
||||
|
||||
@@ -618,12 +617,12 @@ export function domToBlock(xmlBlock: Element, workspace: Workspace): Block {
|
||||
// Fire a VarCreate event for each (if any) new variable created.
|
||||
for (let i = 0; i < newVariables.length; i++) {
|
||||
const thisVariable = newVariables[i];
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))!
|
||||
(thisVariable));
|
||||
eventUtils.fire(
|
||||
new (eventUtils.get(eventUtils.VAR_CREATE))(thisVariable));
|
||||
}
|
||||
// Block events come after var events, in case they refer to newly created
|
||||
// variables.
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.CREATE))!(topBlock));
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.CREATE))(topBlock));
|
||||
}
|
||||
return topBlock;
|
||||
}
|
||||
|
||||
@@ -414,8 +414,8 @@ export class ZoomControls implements IPositionable {
|
||||
|
||||
/** Fires a zoom control UI event. */
|
||||
private fireZoomEvent_() {
|
||||
const uiEvent = new (eventUtils.get(eventUtils.CLICK))!
|
||||
(null, this.workspace.id, 'zoom_controls');
|
||||
const uiEvent = new (eventUtils.get(eventUtils.CLICK))(
|
||||
null, this.workspace.id, 'zoom_controls');
|
||||
eventUtils.fire(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user