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