mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
refactor(events): introduce EventType enum in separate module (#8530)
* refactor(events): Use "export ... from" where applicable
* refactor(events): Introduce EventType enum
Introduce an enum for the event .type values. We can't actually
use it as the type of the .type property on Abstract events,
because we want to allow developers to add their own custom
event types inheriting from this type, but at least this way we
can be reasonably sure that all of our own event subclasses have
distinct .type values—plus consistent use of enum syntax
(EventType.TYPE_NAME) is probably good for readability overall.
Put it in a separate module from the rest of events/utils.ts
because it would be helpful if event utils could use
event instanceof SomeEventType
for type narrowing but but at the moment most events are in
modules that depend on events/utils.ts for their .type
constant, and although circular ESM dependencies should work
in principle there are various restrictions and this
particular circularity causes issues at the moment.
A few of the event classes also depend on utils.ts for fire()
or other functions, which will be harder to deal with, but at
least this commit is win in terms of reducing the complexity
of our dependencies, making most of the Abstract event subclass
module dependent on type.ts, which has no imports, rather than
on utils.ts which has multiple imports.
This commit is contained in:
committed by
GitHub
parent
806f8f95d2
commit
7ccdcc5cef
@@ -6,156 +6,103 @@
|
||||
|
||||
// Former goog.module ID: Blockly.Events
|
||||
|
||||
import {Abstract, AbstractEventJson} from './events_abstract.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import {BlockChange, BlockChangeJson} from './events_block_change.js';
|
||||
import {BlockCreate, BlockCreateJson} from './events_block_create.js';
|
||||
import {BlockDelete, BlockDeleteJson} from './events_block_delete.js';
|
||||
import {BlockDrag, BlockDragJson} from './events_block_drag.js';
|
||||
import {
|
||||
import {EventType} from './type.js';
|
||||
|
||||
// Events.
|
||||
export {Abstract, AbstractEventJson} from './events_abstract.js';
|
||||
export {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
export {BlockChange, BlockChangeJson} from './events_block_change.js';
|
||||
export {BlockCreate, BlockCreateJson} from './events_block_create.js';
|
||||
export {BlockDelete, BlockDeleteJson} from './events_block_delete.js';
|
||||
export {BlockDrag, BlockDragJson} from './events_block_drag.js';
|
||||
export {
|
||||
BlockFieldIntermediateChange,
|
||||
BlockFieldIntermediateChangeJson,
|
||||
} from './events_block_field_intermediate_change.js';
|
||||
import {BlockMove, BlockMoveJson} from './events_block_move.js';
|
||||
import {BubbleOpen, BubbleOpenJson, BubbleType} from './events_bubble_open.js';
|
||||
import {Click, ClickJson, ClickTarget} from './events_click.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import {CommentChange, CommentChangeJson} from './events_comment_change.js';
|
||||
import {
|
||||
export {BlockMove, BlockMoveJson} from './events_block_move.js';
|
||||
export {BubbleOpen, BubbleOpenJson, BubbleType} from './events_bubble_open.js';
|
||||
export {Click, ClickJson, ClickTarget} from './events_click.js';
|
||||
export {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
export {CommentChange, CommentChangeJson} from './events_comment_change.js';
|
||||
export {
|
||||
CommentCollapse,
|
||||
CommentCollapseJson,
|
||||
} from './events_comment_collapse.js';
|
||||
import {CommentCreate, CommentCreateJson} from './events_comment_create.js';
|
||||
import {CommentDelete} from './events_comment_delete.js';
|
||||
import {CommentDrag, CommentDragJson} from './events_comment_drag.js';
|
||||
import {CommentMove, CommentMoveJson} from './events_comment_move.js';
|
||||
import {CommentResize, CommentResizeJson} from './events_comment_resize.js';
|
||||
import {MarkerMove, MarkerMoveJson} from './events_marker_move.js';
|
||||
import {Selected, SelectedJson} from './events_selected.js';
|
||||
import {ThemeChange, ThemeChangeJson} from './events_theme_change.js';
|
||||
import {
|
||||
export {CommentCreate, CommentCreateJson} from './events_comment_create.js';
|
||||
export {CommentDelete} from './events_comment_delete.js';
|
||||
export {CommentDrag, CommentDragJson} from './events_comment_drag.js';
|
||||
export {CommentMove, CommentMoveJson} from './events_comment_move.js';
|
||||
export {CommentResize, CommentResizeJson} from './events_comment_resize.js';
|
||||
export {MarkerMove, MarkerMoveJson} from './events_marker_move.js';
|
||||
export {Selected, SelectedJson} from './events_selected.js';
|
||||
export {ThemeChange, ThemeChangeJson} from './events_theme_change.js';
|
||||
export {
|
||||
ToolboxItemSelect,
|
||||
ToolboxItemSelectJson,
|
||||
} from './events_toolbox_item_select.js';
|
||||
import {TrashcanOpen, TrashcanOpenJson} from './events_trashcan_open.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
import {VarCreate, VarCreateJson} from './events_var_create.js';
|
||||
import {VarDelete, VarDeleteJson} from './events_var_delete.js';
|
||||
import {VarRename, VarRenameJson} from './events_var_rename.js';
|
||||
import {ViewportChange, ViewportChangeJson} from './events_viewport.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {FinishedLoading} from './workspace_events.js';
|
||||
export {TrashcanOpen, TrashcanOpenJson} from './events_trashcan_open.js';
|
||||
export {UiBase} from './events_ui_base.js';
|
||||
export {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
export {VarCreate, VarCreateJson} from './events_var_create.js';
|
||||
export {VarDelete, VarDeleteJson} from './events_var_delete.js';
|
||||
export {VarRename, VarRenameJson} from './events_var_rename.js';
|
||||
export {ViewportChange, ViewportChangeJson} from './events_viewport.js';
|
||||
export {FinishedLoading} from './workspace_events.js';
|
||||
|
||||
// Events.
|
||||
export {
|
||||
Abstract,
|
||||
AbstractEventJson,
|
||||
BlockBase,
|
||||
BlockBaseJson,
|
||||
BlockChange,
|
||||
BlockChangeJson,
|
||||
BlockCreate,
|
||||
BlockCreateJson,
|
||||
BlockDelete,
|
||||
BlockDeleteJson,
|
||||
BlockDrag,
|
||||
BlockDragJson,
|
||||
BlockFieldIntermediateChange,
|
||||
BlockFieldIntermediateChangeJson,
|
||||
BlockMove,
|
||||
BlockMoveJson,
|
||||
BubbleOpen,
|
||||
BubbleOpenJson,
|
||||
BubbleType,
|
||||
Click,
|
||||
ClickJson,
|
||||
ClickTarget,
|
||||
CommentBase,
|
||||
CommentBaseJson,
|
||||
CommentChange,
|
||||
CommentChangeJson,
|
||||
CommentCollapse,
|
||||
CommentCollapseJson,
|
||||
CommentCreate,
|
||||
CommentCreateJson,
|
||||
CommentDelete,
|
||||
CommentDrag,
|
||||
CommentDragJson,
|
||||
CommentMove,
|
||||
CommentMoveJson,
|
||||
CommentResize,
|
||||
CommentResizeJson,
|
||||
FinishedLoading,
|
||||
MarkerMove,
|
||||
MarkerMoveJson,
|
||||
Selected,
|
||||
SelectedJson,
|
||||
ThemeChange,
|
||||
ThemeChangeJson,
|
||||
ToolboxItemSelect,
|
||||
ToolboxItemSelectJson,
|
||||
TrashcanOpen,
|
||||
TrashcanOpenJson,
|
||||
UiBase,
|
||||
VarBase,
|
||||
VarBaseJson,
|
||||
VarCreate,
|
||||
VarCreateJson,
|
||||
VarDelete,
|
||||
VarDeleteJson,
|
||||
VarRename,
|
||||
VarRenameJson,
|
||||
ViewportChange,
|
||||
ViewportChangeJson,
|
||||
};
|
||||
export type {BumpEvent} from './utils.js';
|
||||
|
||||
// Event types.
|
||||
export const BLOCK_CHANGE = eventUtils.BLOCK_CHANGE;
|
||||
export const BLOCK_CREATE = eventUtils.BLOCK_CREATE;
|
||||
export const BLOCK_DELETE = eventUtils.BLOCK_DELETE;
|
||||
export const BLOCK_DRAG = eventUtils.BLOCK_DRAG;
|
||||
export const BLOCK_MOVE = eventUtils.BLOCK_MOVE;
|
||||
export const BLOCK_CHANGE = EventType.BLOCK_CHANGE;
|
||||
export const BLOCK_CREATE = EventType.BLOCK_CREATE;
|
||||
export const BLOCK_DELETE = EventType.BLOCK_DELETE;
|
||||
export const BLOCK_DRAG = EventType.BLOCK_DRAG;
|
||||
export const BLOCK_MOVE = EventType.BLOCK_MOVE;
|
||||
export const BLOCK_FIELD_INTERMEDIATE_CHANGE =
|
||||
eventUtils.BLOCK_FIELD_INTERMEDIATE_CHANGE;
|
||||
export const BUBBLE_OPEN = eventUtils.BUBBLE_OPEN;
|
||||
export type BumpEvent = eventUtils.BumpEvent;
|
||||
export const BUMP_EVENTS = eventUtils.BUMP_EVENTS;
|
||||
export const CHANGE = eventUtils.CHANGE;
|
||||
export const CLICK = eventUtils.CLICK;
|
||||
export const COMMENT_CHANGE = eventUtils.COMMENT_CHANGE;
|
||||
export const COMMENT_CREATE = eventUtils.COMMENT_CREATE;
|
||||
export const COMMENT_DELETE = eventUtils.COMMENT_DELETE;
|
||||
export const COMMENT_MOVE = eventUtils.COMMENT_MOVE;
|
||||
export const COMMENT_RESIZE = eventUtils.COMMENT_RESIZE;
|
||||
export const COMMENT_DRAG = eventUtils.COMMENT_DRAG;
|
||||
export const CREATE = eventUtils.CREATE;
|
||||
export const DELETE = eventUtils.DELETE;
|
||||
export const FINISHED_LOADING = eventUtils.FINISHED_LOADING;
|
||||
export const MARKER_MOVE = eventUtils.MARKER_MOVE;
|
||||
export const MOVE = eventUtils.MOVE;
|
||||
export const SELECTED = eventUtils.SELECTED;
|
||||
export const THEME_CHANGE = eventUtils.THEME_CHANGE;
|
||||
export const TOOLBOX_ITEM_SELECT = eventUtils.TOOLBOX_ITEM_SELECT;
|
||||
export const TRASHCAN_OPEN = eventUtils.TRASHCAN_OPEN;
|
||||
export const UI = eventUtils.UI;
|
||||
export const VAR_CREATE = eventUtils.VAR_CREATE;
|
||||
export const VAR_DELETE = eventUtils.VAR_DELETE;
|
||||
export const VAR_RENAME = eventUtils.VAR_RENAME;
|
||||
export const VIEWPORT_CHANGE = eventUtils.VIEWPORT_CHANGE;
|
||||
EventType.BLOCK_FIELD_INTERMEDIATE_CHANGE;
|
||||
export const BUBBLE_OPEN = EventType.BUBBLE_OPEN;
|
||||
/** @deprecated Use BLOCK_CHANGE instead */
|
||||
export const CHANGE = EventType.BLOCK_CHANGE;
|
||||
export const CLICK = EventType.CLICK;
|
||||
export const COMMENT_CHANGE = EventType.COMMENT_CHANGE;
|
||||
export const COMMENT_CREATE = EventType.COMMENT_CREATE;
|
||||
export const COMMENT_DELETE = EventType.COMMENT_DELETE;
|
||||
export const COMMENT_MOVE = EventType.COMMENT_MOVE;
|
||||
export const COMMENT_RESIZE = EventType.COMMENT_RESIZE;
|
||||
export const COMMENT_DRAG = EventType.COMMENT_DRAG;
|
||||
/** @deprecated Use BLOCK_CREATE instead */
|
||||
export const CREATE = EventType.BLOCK_CREATE;
|
||||
/** @deprecated Use BLOCK_DELETE instead */
|
||||
export const DELETE = EventType.BLOCK_DELETE;
|
||||
export const FINISHED_LOADING = EventType.FINISHED_LOADING;
|
||||
export const MARKER_MOVE = EventType.MARKER_MOVE;
|
||||
/** @deprecated Use BLOCK_MOVE instead */
|
||||
export const MOVE = EventType.BLOCK_MOVE;
|
||||
export const SELECTED = EventType.SELECTED;
|
||||
export const THEME_CHANGE = EventType.THEME_CHANGE;
|
||||
export const TOOLBOX_ITEM_SELECT = EventType.TOOLBOX_ITEM_SELECT;
|
||||
export const TRASHCAN_OPEN = EventType.TRASHCAN_OPEN;
|
||||
export const UI = EventType.UI;
|
||||
export const VAR_CREATE = EventType.VAR_CREATE;
|
||||
export const VAR_DELETE = EventType.VAR_DELETE;
|
||||
export const VAR_RENAME = EventType.VAR_RENAME;
|
||||
export const VIEWPORT_CHANGE = EventType.VIEWPORT_CHANGE;
|
||||
|
||||
export {BUMP_EVENTS} from './type.js';
|
||||
|
||||
// Event utils.
|
||||
export const clearPendingUndo = eventUtils.clearPendingUndo;
|
||||
export const disable = eventUtils.disable;
|
||||
export const enable = eventUtils.enable;
|
||||
export const filter = eventUtils.filter;
|
||||
export const fire = eventUtils.fire;
|
||||
export const fromJson = eventUtils.fromJson;
|
||||
export const getDescendantIds = eventUtils.getDescendantIds;
|
||||
export const get = eventUtils.get;
|
||||
export const getGroup = eventUtils.getGroup;
|
||||
export const getRecordUndo = eventUtils.getRecordUndo;
|
||||
export const isEnabled = eventUtils.isEnabled;
|
||||
export const setGroup = eventUtils.setGroup;
|
||||
export const setRecordUndo = eventUtils.setRecordUndo;
|
||||
export const disableOrphans = eventUtils.disableOrphans;
|
||||
export {
|
||||
clearPendingUndo,
|
||||
disable,
|
||||
disableOrphans,
|
||||
enable,
|
||||
filter,
|
||||
fire,
|
||||
fromJson,
|
||||
get,
|
||||
getDescendantIds,
|
||||
getGroup,
|
||||
getRecordUndo,
|
||||
isEnabled,
|
||||
setGroup,
|
||||
setRecordUndo,
|
||||
} from './utils.js';
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import * as common from '../common.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {getGroup, getRecordUndo} from './utils.js';
|
||||
|
||||
/**
|
||||
* Abstract class for an event.
|
||||
@@ -47,8 +47,8 @@ export abstract class Abstract {
|
||||
type = '';
|
||||
|
||||
constructor() {
|
||||
this.group = eventUtils.getGroup();
|
||||
this.recordUndo = eventUtils.getRecordUndo();
|
||||
this.group = getGroup();
|
||||
this.recordUndo = getRecordUndo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ import * as utilsXml from '../utils/xml.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import * as Xml from '../xml.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import {EventType} from './type.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ import * as eventUtils from './utils.js';
|
||||
* field values, comments, etc).
|
||||
*/
|
||||
export class BlockChange extends BlockBase {
|
||||
override type = eventUtils.BLOCK_CHANGE;
|
||||
override type = EventType.BLOCK_CHANGE;
|
||||
/**
|
||||
* The element that changed; one of 'field', 'comment', 'collapsed',
|
||||
* 'disabled', 'inline', or 'mutation'
|
||||
@@ -255,4 +256,4 @@ export interface BlockChangeJson extends BlockBaseJson {
|
||||
disabledReason?: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.CHANGE, BlockChange);
|
||||
registry.register(registry.Type.EVENT, EventType.BLOCK_CHANGE, BlockChange);
|
||||
|
||||
@@ -18,6 +18,7 @@ import * as utilsXml from '../utils/xml.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import * as Xml from '../xml.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import {EventType} from './type.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ import * as eventUtils from './utils.js';
|
||||
* created.
|
||||
*/
|
||||
export class BlockCreate extends BlockBase {
|
||||
override type = eventUtils.BLOCK_CREATE;
|
||||
override type = EventType.BLOCK_CREATE;
|
||||
|
||||
/** The XML representation of the created block(s). */
|
||||
xml?: Element | DocumentFragment;
|
||||
@@ -181,4 +182,4 @@ export interface BlockCreateJson extends BlockBaseJson {
|
||||
recordUndo?: boolean;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.CREATE, BlockCreate);
|
||||
registry.register(registry.Type.EVENT, EventType.BLOCK_CREATE, BlockCreate);
|
||||
|
||||
@@ -18,6 +18,7 @@ import * as utilsXml from '../utils/xml.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import * as Xml from '../xml.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import {EventType} from './type.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,7 @@ export class BlockDelete extends BlockBase {
|
||||
/** True if the deleted block was a shadow block, false otherwise. */
|
||||
wasShadow?: boolean;
|
||||
|
||||
override type = eventUtils.BLOCK_DELETE;
|
||||
override type = EventType.BLOCK_DELETE;
|
||||
|
||||
/** @param opt_block The deleted block. Undefined for a blank event. */
|
||||
constructor(opt_block?: Block) {
|
||||
@@ -178,4 +179,4 @@ export interface BlockDeleteJson extends BlockBaseJson {
|
||||
recordUndo?: boolean;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.DELETE, BlockDelete);
|
||||
registry.register(registry.Type.EVENT, EventType.BLOCK_DELETE, BlockDelete);
|
||||
|
||||
@@ -16,7 +16,7 @@ import * as registry from '../registry.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners when a block is being manually dragged/dropped.
|
||||
@@ -34,7 +34,7 @@ export class BlockDrag extends UiBase {
|
||||
*/
|
||||
blocks?: Block[];
|
||||
|
||||
override type = eventUtils.BLOCK_DRAG;
|
||||
override type = EventType.BLOCK_DRAG;
|
||||
|
||||
/**
|
||||
* @param opt_block The top block in the stack that is being dragged.
|
||||
@@ -113,4 +113,4 @@ export interface BlockDragJson extends AbstractEventJson {
|
||||
blocks?: Block[];
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.BLOCK_DRAG, BlockDrag);
|
||||
registry.register(registry.Type.EVENT, EventType.BLOCK_DRAG, BlockDrag);
|
||||
|
||||
@@ -16,7 +16,7 @@ import type {Block} from '../block.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners when the value of a block's field has changed but the
|
||||
@@ -24,7 +24,7 @@ import * as eventUtils from './utils.js';
|
||||
* event.
|
||||
*/
|
||||
export class BlockFieldIntermediateChange extends BlockBase {
|
||||
override type = eventUtils.BLOCK_FIELD_INTERMEDIATE_CHANGE;
|
||||
override type = EventType.BLOCK_FIELD_INTERMEDIATE_CHANGE;
|
||||
|
||||
// Intermediate events do not undo or redo. They may be fired frequently while
|
||||
// the field editor widget is open. A separate BLOCK_CHANGE event is fired
|
||||
@@ -161,6 +161,6 @@ export interface BlockFieldIntermediateChangeJson extends BlockBaseJson {
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.BLOCK_FIELD_INTERMEDIATE_CHANGE,
|
||||
EventType.BLOCK_FIELD_INTERMEDIATE_CHANGE,
|
||||
BlockFieldIntermediateChange,
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as registry from '../registry.js';
|
||||
import {Coordinate} from '../utils/coordinate.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {BlockBase, BlockBaseJson} from './events_block_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
interface BlockLocation {
|
||||
parentId?: string;
|
||||
@@ -30,7 +30,7 @@ interface BlockLocation {
|
||||
* connection to another, or from one location on the workspace to another.
|
||||
*/
|
||||
export class BlockMove extends BlockBase {
|
||||
override type = eventUtils.BLOCK_MOVE;
|
||||
override type = EventType.BLOCK_MOVE;
|
||||
|
||||
/** The ID of the old parent block. Undefined if it was a top-level block. */
|
||||
oldParentId?: string;
|
||||
@@ -303,4 +303,4 @@ export interface BlockMoveJson extends BlockBaseJson {
|
||||
recordUndo?: boolean;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.MOVE, BlockMove);
|
||||
registry.register(registry.Type.EVENT, EventType.BLOCK_MOVE, BlockMove);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
|
||||
// Former goog.module ID: Blockly.Events.BubbleOpen
|
||||
|
||||
import type {BlockSvg} from '../block_svg.js';
|
||||
@@ -16,7 +17,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import type {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Class for a bubble open event.
|
||||
@@ -31,7 +32,7 @@ export class BubbleOpen extends UiBase {
|
||||
/** The type of bubble; one of 'mutator', 'comment', or 'warning'. */
|
||||
bubbleType?: BubbleType;
|
||||
|
||||
override type = eventUtils.BUBBLE_OPEN;
|
||||
override type = EventType.BUBBLE_OPEN;
|
||||
|
||||
/**
|
||||
* @param opt_block The associated block. Undefined for a blank event.
|
||||
@@ -117,4 +118,4 @@ export interface BubbleOpenJson extends AbstractEventJson {
|
||||
blockId: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.BUBBLE_OPEN, BubbleOpen);
|
||||
registry.register(registry.Type.EVENT, EventType.BUBBLE_OPEN, BubbleOpen);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
|
||||
// Former goog.module ID: Blockly.Events.Click
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
@@ -16,7 +17,7 @@ import * as registry from '../registry.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that some blockly element was clicked.
|
||||
@@ -30,7 +31,7 @@ export class Click extends UiBase {
|
||||
* or 'zoom_controls'.
|
||||
*/
|
||||
targetType?: ClickTarget;
|
||||
override type = eventUtils.CLICK;
|
||||
override type = EventType.CLICK;
|
||||
|
||||
/**
|
||||
* @param opt_block The affected block. Null for click events that do not have
|
||||
@@ -106,4 +107,4 @@ export interface ClickJson extends AbstractEventJson {
|
||||
blockId?: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.CLICK, Click);
|
||||
registry.register(registry.Type.EVENT, EventType.CLICK, Click);
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from './events_abstract.js';
|
||||
import type {CommentCreate} from './events_comment_create.js';
|
||||
import type {CommentDelete} from './events_comment_delete.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {getGroup, getRecordUndo} from './utils.js';
|
||||
|
||||
/**
|
||||
* Abstract class for a comment event.
|
||||
@@ -44,8 +44,8 @@ export class CommentBase extends AbstractEvent {
|
||||
|
||||
this.commentId = opt_comment.id;
|
||||
this.workspaceId = opt_comment.workspace.id;
|
||||
this.group = eventUtils.getGroup();
|
||||
this.recordUndo = eventUtils.getRecordUndo();
|
||||
this.group = getGroup();
|
||||
this.recordUndo = getRecordUndo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,13 +15,13 @@ import type {WorkspaceComment} from '../comments/workspace_comment.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that the contents of a workspace comment has changed.
|
||||
*/
|
||||
export class CommentChange extends CommentBase {
|
||||
override type = eventUtils.COMMENT_CHANGE;
|
||||
override type = EventType.COMMENT_CHANGE;
|
||||
|
||||
// TODO(#6774): We should remove underscores.
|
||||
/** The previous contents of the comment. */
|
||||
@@ -153,8 +153,4 @@ export interface CommentChangeJson extends CommentBaseJson {
|
||||
newContents: string;
|
||||
}
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.COMMENT_CHANGE,
|
||||
CommentChange,
|
||||
);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_CHANGE, CommentChange);
|
||||
|
||||
@@ -8,10 +8,10 @@ import {WorkspaceComment} from '../comments/workspace_comment.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
export class CommentCollapse extends CommentBase {
|
||||
override type = eventUtils.COMMENT_COLLAPSE;
|
||||
override type = EventType.COMMENT_COLLAPSE;
|
||||
|
||||
constructor(
|
||||
comment?: WorkspaceComment,
|
||||
@@ -98,6 +98,6 @@ export interface CommentCollapseJson extends CommentBaseJson {
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.COMMENT_COLLAPSE,
|
||||
EventType.COMMENT_COLLAPSE,
|
||||
CommentCollapse,
|
||||
);
|
||||
|
||||
@@ -18,13 +18,13 @@ import * as utilsXml from '../utils/xml.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import * as Xml from '../xml.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a workspace comment was created.
|
||||
*/
|
||||
export class CommentCreate extends CommentBase {
|
||||
override type = eventUtils.COMMENT_CREATE;
|
||||
override type = EventType.COMMENT_CREATE;
|
||||
|
||||
/** The XML representation of the created workspace comment. */
|
||||
xml?: Element | DocumentFragment;
|
||||
@@ -111,8 +111,4 @@ export interface CommentCreateJson extends CommentBaseJson {
|
||||
json: object;
|
||||
}
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.COMMENT_CREATE,
|
||||
CommentCreate,
|
||||
);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_CREATE, CommentCreate);
|
||||
|
||||
@@ -18,13 +18,13 @@ import * as utilsXml from '../utils/xml.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import * as Xml from '../xml.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a workspace comment has been deleted.
|
||||
*/
|
||||
export class CommentDelete extends CommentBase {
|
||||
override type = eventUtils.COMMENT_DELETE;
|
||||
override type = EventType.COMMENT_DELETE;
|
||||
|
||||
/** The XML representation of the deleted workspace comment. */
|
||||
xml?: Element;
|
||||
@@ -110,8 +110,4 @@ export interface CommentDeleteJson extends CommentBaseJson {
|
||||
json: object;
|
||||
}
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.COMMENT_DELETE,
|
||||
CommentDelete,
|
||||
);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_DELETE, CommentDelete);
|
||||
|
||||
@@ -13,7 +13,7 @@ import * as registry from '../registry.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners when a comment is being manually dragged/dropped.
|
||||
@@ -25,7 +25,7 @@ export class CommentDrag extends UiBase {
|
||||
/** True if this is the start of a drag, false if this is the end of one. */
|
||||
isStart?: boolean;
|
||||
|
||||
override type = eventUtils.COMMENT_DRAG;
|
||||
override type = EventType.COMMENT_DRAG;
|
||||
|
||||
/**
|
||||
* @param opt_comment The comment that is being dragged.
|
||||
@@ -96,4 +96,4 @@ export interface CommentDragJson extends AbstractEventJson {
|
||||
commentId: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.COMMENT_DRAG, CommentDrag);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_DRAG, CommentDrag);
|
||||
|
||||
@@ -16,13 +16,13 @@ import * as registry from '../registry.js';
|
||||
import {Coordinate} from '../utils/coordinate.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a workspace comment has moved.
|
||||
*/
|
||||
export class CommentMove extends CommentBase {
|
||||
override type = eventUtils.COMMENT_MOVE;
|
||||
override type = EventType.COMMENT_MOVE;
|
||||
|
||||
/** The comment that is being moved. */
|
||||
comment_?: WorkspaceComment;
|
||||
@@ -203,4 +203,4 @@ export interface CommentMoveJson extends CommentBaseJson {
|
||||
newCoordinate: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.COMMENT_MOVE, CommentMove);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_MOVE, CommentMove);
|
||||
|
||||
@@ -13,13 +13,13 @@ import * as registry from '../registry.js';
|
||||
import {Size} from '../utils/size.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a workspace comment has resized.
|
||||
*/
|
||||
export class CommentResize extends CommentBase {
|
||||
override type = eventUtils.COMMENT_RESIZE;
|
||||
override type = EventType.COMMENT_RESIZE;
|
||||
|
||||
/** The size of the comment before the resize. */
|
||||
oldSize?: Size;
|
||||
@@ -166,8 +166,4 @@ export interface CommentResizeJson extends CommentBaseJson {
|
||||
newHeight: number;
|
||||
}
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.COMMENT_RESIZE,
|
||||
CommentResize,
|
||||
);
|
||||
registry.register(registry.Type.EVENT, EventType.COMMENT_RESIZE, CommentResize);
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a marker (used for keyboard navigation) has
|
||||
@@ -40,7 +40,7 @@ export class MarkerMove extends UiBase {
|
||||
*/
|
||||
isCursor?: boolean;
|
||||
|
||||
override type = eventUtils.MARKER_MOVE;
|
||||
override type = EventType.MARKER_MOVE;
|
||||
|
||||
/**
|
||||
* @param opt_block The affected block. Null if current node is of type
|
||||
@@ -130,4 +130,4 @@ export interface MarkerMoveJson extends AbstractEventJson {
|
||||
newNode: ASTNode;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.MARKER_MOVE, MarkerMove);
|
||||
registry.register(registry.Type.EVENT, EventType.MARKER_MOVE, MarkerMove);
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Class for a selected event.
|
||||
@@ -31,7 +31,7 @@ export class Selected extends UiBase {
|
||||
*/
|
||||
newElementId?: string;
|
||||
|
||||
override type = eventUtils.SELECTED;
|
||||
override type = EventType.SELECTED;
|
||||
|
||||
/**
|
||||
* @param opt_oldElementId The ID of the previously selected element. Null if
|
||||
@@ -94,4 +94,4 @@ export interface SelectedJson extends AbstractEventJson {
|
||||
newElementId?: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.SELECTED, Selected);
|
||||
registry.register(registry.Type.EVENT, EventType.SELECTED, Selected);
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that the workspace theme has changed.
|
||||
@@ -24,7 +24,7 @@ export class ThemeChange extends UiBase {
|
||||
/** The name of the new theme that has been set. */
|
||||
themeName?: string;
|
||||
|
||||
override type = eventUtils.THEME_CHANGE;
|
||||
override type = EventType.THEME_CHANGE;
|
||||
|
||||
/**
|
||||
* @param opt_themeName The theme name. Undefined for a blank event.
|
||||
@@ -81,4 +81,4 @@ export interface ThemeChangeJson extends AbstractEventJson {
|
||||
themeName: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.THEME_CHANGE, ThemeChange);
|
||||
registry.register(registry.Type.EVENT, EventType.THEME_CHANGE, ThemeChange);
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a toolbox item has been selected.
|
||||
@@ -27,7 +27,7 @@ export class ToolboxItemSelect extends UiBase {
|
||||
/** The newly selected toolbox item. */
|
||||
newItem?: string;
|
||||
|
||||
override type = eventUtils.TOOLBOX_ITEM_SELECT;
|
||||
override type = EventType.TOOLBOX_ITEM_SELECT;
|
||||
|
||||
/**
|
||||
* @param opt_oldItem The previously selected toolbox item.
|
||||
@@ -91,6 +91,6 @@ export interface ToolboxItemSelectJson extends AbstractEventJson {
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.TOOLBOX_ITEM_SELECT,
|
||||
EventType.TOOLBOX_ITEM_SELECT,
|
||||
ToolboxItemSelect,
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners when the trashcan is opening or closing.
|
||||
@@ -26,7 +26,7 @@ export class TrashcanOpen extends UiBase {
|
||||
* False if it is currently closing (previously open).
|
||||
*/
|
||||
isOpen?: boolean;
|
||||
override type = eventUtils.TRASHCAN_OPEN;
|
||||
override type = EventType.TRASHCAN_OPEN;
|
||||
|
||||
/**
|
||||
* @param opt_isOpen Whether the trashcan flyout is opening (false if
|
||||
@@ -84,4 +84,4 @@ export interface TrashcanOpenJson extends AbstractEventJson {
|
||||
isOpen: boolean;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.TRASHCAN_OPEN, TrashcanOpen);
|
||||
registry.register(registry.Type.EVENT, EventType.TRASHCAN_OPEN, TrashcanOpen);
|
||||
|
||||
@@ -15,13 +15,13 @@ import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a variable model has been created.
|
||||
*/
|
||||
export class VarCreate extends VarBase {
|
||||
override type = eventUtils.VAR_CREATE;
|
||||
override type = EventType.VAR_CREATE;
|
||||
|
||||
/** The type of the variable that was created. */
|
||||
varType?: string;
|
||||
@@ -122,4 +122,4 @@ export interface VarCreateJson extends VarBaseJson {
|
||||
varName: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.VAR_CREATE, VarCreate);
|
||||
registry.register(registry.Type.EVENT, EventType.VAR_CREATE, VarCreate);
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a variable model has been deleted.
|
||||
@@ -18,7 +18,7 @@ import * as eventUtils from './utils.js';
|
||||
* @class
|
||||
*/
|
||||
export class VarDelete extends VarBase {
|
||||
override type = eventUtils.VAR_DELETE;
|
||||
override type = EventType.VAR_DELETE;
|
||||
/** The type of the variable that was deleted. */
|
||||
varType?: string;
|
||||
/** The name of the variable that was deleted. */
|
||||
@@ -117,4 +117,4 @@ export interface VarDeleteJson extends VarBaseJson {
|
||||
varName: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.VAR_DELETE, VarDelete);
|
||||
registry.register(registry.Type.EVENT, EventType.VAR_DELETE, VarDelete);
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a variable model was renamed.
|
||||
@@ -18,7 +18,7 @@ import * as eventUtils from './utils.js';
|
||||
* @class
|
||||
*/
|
||||
export class VarRename extends VarBase {
|
||||
override type = eventUtils.VAR_RENAME;
|
||||
override type = EventType.VAR_RENAME;
|
||||
|
||||
/** The previous name of the variable. */
|
||||
oldName?: string;
|
||||
@@ -126,4 +126,4 @@ export interface VarRenameJson extends VarBaseJson {
|
||||
newName: string;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.VAR_RENAME, VarRename);
|
||||
registry.register(registry.Type.EVENT, EventType.VAR_RENAME, VarRename);
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that the workspace surface's position or scale has
|
||||
@@ -42,7 +42,7 @@ export class ViewportChange extends UiBase {
|
||||
/** The previous scale of the workspace. */
|
||||
oldScale?: number;
|
||||
|
||||
override type = eventUtils.VIEWPORT_CHANGE;
|
||||
override type = EventType.VIEWPORT_CHANGE;
|
||||
|
||||
/**
|
||||
* @param opt_top Top-edge of the visible portion of the workspace, relative
|
||||
@@ -144,6 +144,6 @@ export interface ViewportChangeJson extends AbstractEventJson {
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.VIEWPORT_CHANGE,
|
||||
EventType.VIEWPORT_CHANGE,
|
||||
ViewportChange,
|
||||
);
|
||||
|
||||
85
core/events/type.ts
Normal file
85
core/events/type.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enum of values for the .type property for event classes (concrete subclasses
|
||||
* of Abstract).
|
||||
*/
|
||||
export enum EventType {
|
||||
/** Type of event that creates a block. */
|
||||
BLOCK_CREATE = 'create',
|
||||
/** Type of event that deletes a block. */
|
||||
BLOCK_DELETE = 'delete',
|
||||
/** Type of event that changes a block. */
|
||||
BLOCK_CHANGE = 'change',
|
||||
/**
|
||||
* Type of event representing an in-progress change to a field of a
|
||||
* block, which is expected to be followed by a block change event.
|
||||
*/
|
||||
BLOCK_FIELD_INTERMEDIATE_CHANGE = 'block_field_intermediate_change',
|
||||
/** Type of event that moves a block. */
|
||||
BLOCK_MOVE = 'move',
|
||||
/** Type of event that creates a variable. */
|
||||
VAR_CREATE = 'var_create',
|
||||
/** Type of event that deletes a variable. */
|
||||
VAR_DELETE = 'var_delete',
|
||||
/** Type of event that renames a variable. */
|
||||
VAR_RENAME = 'var_rename',
|
||||
/**
|
||||
* Type of generic event that records a UI change.
|
||||
*
|
||||
* @deprecated Was only ever intended for internal use.
|
||||
*/
|
||||
UI = 'ui',
|
||||
/** Type of event that drags a block. */
|
||||
BLOCK_DRAG = 'drag',
|
||||
/** Type of event that records a change in selected element. */
|
||||
SELECTED = 'selected',
|
||||
/** Type of event that records a click. */
|
||||
CLICK = 'click',
|
||||
/** Type of event that records a marker move. */
|
||||
MARKER_MOVE = 'marker_move',
|
||||
/** Type of event that records a bubble open. */
|
||||
BUBBLE_OPEN = 'bubble_open',
|
||||
/** Type of event that records a trashcan open. */
|
||||
TRASHCAN_OPEN = 'trashcan_open',
|
||||
/** Type of event that records a toolbox item select. */
|
||||
TOOLBOX_ITEM_SELECT = 'toolbox_item_select',
|
||||
/** Type of event that records a theme change. */
|
||||
THEME_CHANGE = 'theme_change',
|
||||
/** Type of event that records a viewport change. */
|
||||
VIEWPORT_CHANGE = 'viewport_change',
|
||||
/** Type of event that creates a comment. */
|
||||
COMMENT_CREATE = 'comment_create',
|
||||
/** Type of event that deletes a comment. */
|
||||
COMMENT_DELETE = 'comment_delete',
|
||||
/** Type of event that changes a comment. */
|
||||
COMMENT_CHANGE = 'comment_change',
|
||||
/** Type of event that moves a comment. */
|
||||
COMMENT_MOVE = 'comment_move',
|
||||
/** Type of event that resizes a comment. */
|
||||
COMMENT_RESIZE = 'comment_resize',
|
||||
/** Type of event that drags a comment. */
|
||||
COMMENT_DRAG = 'comment_drag',
|
||||
/** Type of event that collapses a comment. */
|
||||
COMMENT_COLLAPSE = 'comment_collapse',
|
||||
/** Type of event that records a workspace load. */
|
||||
FINISHED_LOADING = 'finished_loading',
|
||||
}
|
||||
|
||||
/**
|
||||
* List of events that cause objects to be bumped back into the visible
|
||||
* portion of the workspace.
|
||||
*
|
||||
* Not to be confused with bumping so that disconnected connections do not
|
||||
* appear connected.
|
||||
*/
|
||||
export const BUMP_EVENTS: string[] = [
|
||||
EventType.BLOCK_CREATE,
|
||||
EventType.BLOCK_MOVE,
|
||||
EventType.COMMENT_CREATE,
|
||||
EventType.COMMENT_MOVE,
|
||||
];
|
||||
@@ -20,6 +20,7 @@ import type {CommentCreate} from './events_comment_create.js';
|
||||
import type {CommentMove} from './events_comment_move.js';
|
||||
import type {CommentResize} from './events_comment_resize.js';
|
||||
import type {ViewportChange} from './events_viewport.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/** Group ID for new events. Grouped events are indivisible. */
|
||||
let group = '';
|
||||
@@ -48,152 +49,6 @@ export function getRecordUndo(): boolean {
|
||||
/** Allow change events to be created and fired. */
|
||||
let disabled = 0;
|
||||
|
||||
/**
|
||||
* Name of event that creates a block. Will be deprecated for BLOCK_CREATE.
|
||||
*/
|
||||
export const CREATE = 'create';
|
||||
|
||||
/**
|
||||
* Name of event that creates a block.
|
||||
*/
|
||||
export const BLOCK_CREATE = CREATE;
|
||||
|
||||
/**
|
||||
* Name of event that deletes a block. Will be deprecated for BLOCK_DELETE.
|
||||
*/
|
||||
export const DELETE = 'delete';
|
||||
|
||||
/**
|
||||
* Name of event that deletes a block.
|
||||
*/
|
||||
export const BLOCK_DELETE = DELETE;
|
||||
|
||||
/**
|
||||
* Name of event that changes a block. Will be deprecated for BLOCK_CHANGE.
|
||||
*/
|
||||
export const CHANGE = 'change';
|
||||
|
||||
/**
|
||||
* Name of event that changes a block.
|
||||
*/
|
||||
export const BLOCK_CHANGE = CHANGE;
|
||||
|
||||
/**
|
||||
* Name of event representing an in-progress change to a field of a block, which
|
||||
* is expected to be followed by a block change event.
|
||||
*/
|
||||
export const BLOCK_FIELD_INTERMEDIATE_CHANGE =
|
||||
'block_field_intermediate_change';
|
||||
|
||||
/**
|
||||
* Name of event that moves a block. Will be deprecated for BLOCK_MOVE.
|
||||
*/
|
||||
export const MOVE = 'move';
|
||||
|
||||
/**
|
||||
* Name of event that moves a block.
|
||||
*/
|
||||
export const BLOCK_MOVE = MOVE;
|
||||
|
||||
/**
|
||||
* Name of event that creates a variable.
|
||||
*/
|
||||
export const VAR_CREATE = 'var_create';
|
||||
|
||||
/**
|
||||
* Name of event that deletes a variable.
|
||||
*/
|
||||
export const VAR_DELETE = 'var_delete';
|
||||
|
||||
/**
|
||||
* Name of event that renames a variable.
|
||||
*/
|
||||
export const VAR_RENAME = 'var_rename';
|
||||
|
||||
/**
|
||||
* Name of generic event that records a UI change.
|
||||
*/
|
||||
export const UI = 'ui';
|
||||
|
||||
/**
|
||||
* Name of event that drags a block.
|
||||
*/
|
||||
export const BLOCK_DRAG = 'drag';
|
||||
|
||||
/**
|
||||
* Name of event that records a change in selected element.
|
||||
*/
|
||||
export const SELECTED = 'selected';
|
||||
|
||||
/**
|
||||
* Name of event that records a click.
|
||||
*/
|
||||
export const CLICK = 'click';
|
||||
|
||||
/**
|
||||
* Name of event that records a marker move.
|
||||
*/
|
||||
export const MARKER_MOVE = 'marker_move';
|
||||
|
||||
/**
|
||||
* Name of event that records a bubble open.
|
||||
*/
|
||||
export const BUBBLE_OPEN = 'bubble_open';
|
||||
|
||||
/**
|
||||
* Name of event that records a trashcan open.
|
||||
*/
|
||||
export const TRASHCAN_OPEN = 'trashcan_open';
|
||||
|
||||
/**
|
||||
* Name of event that records a toolbox item select.
|
||||
*/
|
||||
export const TOOLBOX_ITEM_SELECT = 'toolbox_item_select';
|
||||
|
||||
/**
|
||||
* Name of event that records a theme change.
|
||||
*/
|
||||
export const THEME_CHANGE = 'theme_change';
|
||||
|
||||
/**
|
||||
* Name of event that records a viewport change.
|
||||
*/
|
||||
export const VIEWPORT_CHANGE = 'viewport_change';
|
||||
|
||||
/**
|
||||
* Name of event that creates a comment.
|
||||
*/
|
||||
export const COMMENT_CREATE = 'comment_create';
|
||||
|
||||
/**
|
||||
* Name of event that deletes a comment.
|
||||
*/
|
||||
export const COMMENT_DELETE = 'comment_delete';
|
||||
|
||||
/**
|
||||
* Name of event that changes a comment.
|
||||
*/
|
||||
export const COMMENT_CHANGE = 'comment_change';
|
||||
|
||||
/**
|
||||
* Name of event that moves a comment.
|
||||
*/
|
||||
export const COMMENT_MOVE = 'comment_move';
|
||||
|
||||
/** Name of event that resizes a comment. */
|
||||
export const COMMENT_RESIZE = 'comment_resize';
|
||||
|
||||
/** Name of event that drags a comment. */
|
||||
export const COMMENT_DRAG = 'comment_drag';
|
||||
|
||||
/** Type of event that collapses a comment. */
|
||||
export const COMMENT_COLLAPSE = 'comment_collapse';
|
||||
|
||||
/**
|
||||
* Name of event that records a workspace load.
|
||||
*/
|
||||
export const FINISHED_LOADING = 'finished_loading';
|
||||
|
||||
/**
|
||||
* The language-neutral ID for when the reason why a block is disabled is
|
||||
* because the block is not descended from a root block.
|
||||
@@ -214,20 +69,6 @@ export type BumpEvent =
|
||||
| CommentMove
|
||||
| CommentResize;
|
||||
|
||||
/**
|
||||
* List of events that cause objects to be bumped back into the visible
|
||||
* portion of the workspace.
|
||||
*
|
||||
* Not to be confused with bumping so that disconnected connections do not
|
||||
* appear connected.
|
||||
*/
|
||||
export const BUMP_EVENTS: string[] = [
|
||||
BLOCK_CREATE,
|
||||
BLOCK_MOVE,
|
||||
COMMENT_CREATE,
|
||||
COMMENT_MOVE,
|
||||
];
|
||||
|
||||
/** List of events queued for firing. */
|
||||
const FIRE_QUEUE: Abstract[] = [];
|
||||
|
||||
@@ -339,7 +180,7 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] {
|
||||
for (let i = 0, event; (event = queue[i]); i++) {
|
||||
if (!event.isNull()) {
|
||||
// Treat all UI events as the same type in hash table.
|
||||
const eventType = event.isUiEvent ? UI : event.type;
|
||||
const eventType = event.isUiEvent ? EventType.UI : event.type;
|
||||
// TODO(#5927): Check whether `blockId` exists before accessing it.
|
||||
const blockId = (event as AnyDuringMigration).blockId;
|
||||
const key = [eventType, blockId, event.workspaceId].join(' ');
|
||||
@@ -352,7 +193,10 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] {
|
||||
// move events.
|
||||
hash[key] = {event, index: i};
|
||||
mergedQueue.push(event);
|
||||
} else if (event.type === MOVE && lastEntry.index === i - 1) {
|
||||
} else if (
|
||||
event.type === EventType.BLOCK_MOVE &&
|
||||
lastEntry.index === i - 1
|
||||
) {
|
||||
const moveEvent = event as BlockMove;
|
||||
// Merge move events.
|
||||
lastEvent.newParentId = moveEvent.newParentId;
|
||||
@@ -371,21 +215,24 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] {
|
||||
}
|
||||
lastEntry.index = i;
|
||||
} else if (
|
||||
event.type === CHANGE &&
|
||||
event.type === EventType.BLOCK_CHANGE &&
|
||||
(event as BlockChange).element === lastEvent.element &&
|
||||
(event as BlockChange).name === lastEvent.name
|
||||
) {
|
||||
const changeEvent = event as BlockChange;
|
||||
// Merge change events.
|
||||
lastEvent.newValue = changeEvent.newValue;
|
||||
} else if (event.type === VIEWPORT_CHANGE) {
|
||||
} else if (event.type === EventType.VIEWPORT_CHANGE) {
|
||||
const viewportEvent = event as ViewportChange;
|
||||
// Merge viewport change events.
|
||||
lastEvent.viewTop = viewportEvent.viewTop;
|
||||
lastEvent.viewLeft = viewportEvent.viewLeft;
|
||||
lastEvent.scale = viewportEvent.scale;
|
||||
lastEvent.oldScale = viewportEvent.oldScale;
|
||||
} else if (event.type === CLICK && lastEvent.type === BUBBLE_OPEN) {
|
||||
} else if (
|
||||
event.type === EventType.CLICK &&
|
||||
lastEvent.type === EventType.BUBBLE_OPEN
|
||||
) {
|
||||
// Drop click events caused by opening/closing bubbles.
|
||||
} else {
|
||||
// Collision: newer events should merge into this event to maintain
|
||||
@@ -409,7 +256,7 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] {
|
||||
// AnyDuringMigration because: Property 'element' does not exist on type
|
||||
// 'Abstract'.
|
||||
if (
|
||||
event.type === CHANGE &&
|
||||
event.type === EventType.BLOCK_CHANGE &&
|
||||
(event as AnyDuringMigration).element === 'mutation'
|
||||
) {
|
||||
queue.unshift(queue.splice(i, 1)[0]);
|
||||
@@ -539,7 +386,10 @@ export function get(
|
||||
* @param event Custom data for event.
|
||||
*/
|
||||
export function disableOrphans(event: Abstract) {
|
||||
if (event.type === MOVE || event.type === CREATE) {
|
||||
if (
|
||||
event.type === EventType.BLOCK_MOVE ||
|
||||
event.type === EventType.BLOCK_CREATE
|
||||
) {
|
||||
const blockEvent = event as BlockMove | BlockCreate;
|
||||
if (!blockEvent.workspaceId) {
|
||||
return;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {Abstract as AbstractEvent} from './events_abstract.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners when the workspace has finished deserializing from
|
||||
@@ -23,7 +23,7 @@ import * as eventUtils from './utils.js';
|
||||
export class FinishedLoading extends AbstractEvent {
|
||||
override isBlank = true;
|
||||
override recordUndo = false;
|
||||
override type = eventUtils.FINISHED_LOADING;
|
||||
override type = EventType.FINISHED_LOADING;
|
||||
|
||||
/**
|
||||
* @param opt_workspace The workspace that has finished loading. Undefined
|
||||
@@ -41,6 +41,6 @@ export class FinishedLoading extends AbstractEvent {
|
||||
|
||||
registry.register(
|
||||
registry.Type.EVENT,
|
||||
eventUtils.FINISHED_LOADING,
|
||||
EventType.FINISHED_LOADING,
|
||||
FinishedLoading,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user