diff --git a/core/block.ts b/core/block.ts index 2931dd6ac40..996c0736689 100644 --- a/core/block.ts +++ b/core/block.ts @@ -138,19 +138,19 @@ export class Block implements IASTNodeLocation, IDeletable { * shown to the user, but are declared as global variables in the generated * code. */ - getDeveloperVariables?: (() => string[])|null = undefined; + getDeveloperVariables?: (() => string[]) = undefined; /** * An optional function that reconfigures the block based on the contents of * the mutator dialog. */ - compose?: ((p1: Block) => void)|null = null; + compose?: ((p1: Block) => void) = undefined; /** * An optional function that populates the mutator's dialog with * this block's components. */ - decompose?: ((p1: Workspace) => Block)|null = null; + decompose?: ((p1: Workspace) => Block) = undefined; id: string; // AnyDuringMigration because: Type 'null' is not assignable to type // 'Connection'. diff --git a/core/block_svg.ts b/core/block_svg.ts index f4aff257df5..faaf0524ab5 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -86,9 +86,9 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * the block. */ static readonly COLLAPSED_WARNING_ID = 'TEMP_COLLAPSED_WARNING_'; - override decompose?: ((p1: Workspace) => BlockSvg)|null; + override decompose?: ((p1: Workspace) => BlockSvg); // override compose?: ((p1: BlockSvg) => void)|null; - saveConnections?: ((p1: BlockSvg) => AnyDuringMigration)|null; + saveConnections?: ((p1: BlockSvg) => AnyDuringMigration); customContextMenu?: ((p1: Array) => AnyDuringMigration)|null; diff --git a/core/registry.ts b/core/registry.ts index 0439d1482ba..b2f112def3f 100644 --- a/core/registry.ts +++ b/core/registry.ts @@ -62,18 +62,30 @@ export const DEFAULT = 'default'; */ export class Type { static CONNECTION_CHECKER = new Type('connectionChecker'); + static CURSOR = new Type('cursor'); + static EVENT = new Type('event'); + static FIELD = new Type('field'); + static RENDERER = new Type('renderer'); + static TOOLBOX = new Type('toolbox'); + static THEME = new Type('theme'); + static TOOLBOX_ITEM = new Type('toolboxItem'); + static FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); + static FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); + static METRICS_MANAGER = new Type('metricsManager'); + static BLOCK_DRAGGER = new Type('blockDragger'); + /** @internal */ static SERIALIZER = new Type('serializer'); @@ -89,31 +101,11 @@ export class Type { } } -// Type.CONNECTION_CHECKER = new Type('connectionChecker'); - -// Type.CURSOR = new Type('cursor'); - -// Type.EVENT = new Type('event'); - -// Type.FIELD = new Type('field'); - -// Type.RENDERER = new Type('renderer'); - -// Type.TOOLBOX = new Type('toolbox'); - -// Type.THEME = new Type('theme'); - -// Type.TOOLBOX_ITEM = new Type('toolboxItem'); -// Type.FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); -// Type.FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); -// Type.METRICS_MANAGER = new Type('metricsManager'); -// Type.BLOCK_DRAGGER = new Type('blockDragger'); -// Type.SERIALIZER = new Type('serializer'); /** * Registers a class based on a type and name. diff --git a/core/toolbox/toolbox.ts b/core/toolbox/toolbox.ts index be8d16f41eb..05c0be4b3e0 100644 --- a/core/toolbox/toolbox.ts +++ b/core/toolbox/toolbox.ts @@ -107,10 +107,15 @@ export class Toolbox extends DeleteArea implements IAutoHideable, protected boundEvents_: browserEvents.Data[] = []; override wouldDelete_: AnyDuringMigration; + /** The workspace this toolbox is on. */ + protected readonly workspace_: WorkspaceSvg; + /** @param workspace The workspace in which to create new blocks. */ - constructor(private readonly workspace: WorkspaceSvg) { + constructor(workspace: WorkspaceSvg) { super(); + this.workspace_ = workspace; + /** The JSON describing the contents of this toolbox. */ // AnyDuringMigration because: Type 'ToolboxInfo | { contents: never[]; }' // is not assignable to type 'ToolboxInfo'. @@ -141,12 +146,12 @@ export class Toolbox extends DeleteArea implements IAutoHideable, /** Initializes the toolbox */ init() { - const workspace = this.workspace; + const workspace = this.workspace_; const svg = workspace.getParentSvg(); this.flyout_ = this.createFlyout_(); - this.HtmlDiv = this.createDom_(this.workspace); + this.HtmlDiv = this.createDom_(this.workspace_); dom.insertAfter(this.flyout_.createDom('svg'), svg); this.setVisible(true); this.flyout_.init(workspace); @@ -156,7 +161,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, themeManager.subscribe( this.HtmlDiv, 'toolboxBackgroundColour', 'background-color'); themeManager.subscribe(this.HtmlDiv, 'toolboxForegroundColour', 'color'); - this.workspace.getComponentManager().addComponent({ + this.workspace_.getComponentManager().addComponent({ component: this, weight: 1, capabilities: [ @@ -310,7 +315,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * `Blockly.VerticalFlyout`, and no flyout plugin is specified. */ protected createFlyout_(): IFlyout { - const workspace = this.workspace; + const workspace = this.workspace_; // TODO (#4247): Look into adding a makeFlyout method to Blockly Options. const workspaceOptions = new Options(({ 'parentWorkspace': workspace, @@ -603,7 +608,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @return The parent workspace for the toolbox. */ getWorkspace(): WorkspaceSvg { - return this.workspace; + return this.workspace_; } /** @@ -637,7 +642,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * whether the workspace is in rtl. */ position() { - const workspaceMetrics = this.workspace.getMetrics(); + const workspaceMetrics = this.workspace_.getMetrics(); const toolboxDiv = this.HtmlDiv; if (!toolboxDiv) { // Not initialized yet. @@ -675,7 +680,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, handleToolboxItemResize() { // Reposition the workspace so that (0,0) is in the correct position // relative to the new absolute edge (ie toolbox edge). - const workspace = this.workspace; + const workspace = this.workspace_; const rect = this.HtmlDiv!.getBoundingClientRect(); const newX = this.toolboxPosition === toolbox.Position.LEFT ? workspace.scrollX + rect.width : @@ -735,7 +740,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, this.isVisible_ = isVisible; // Invisible toolbox is ignored as drag targets and must have the drag // target updated. - this.workspace.recordDragTargets(); + this.workspace_.recordDragTargets(); } /** @@ -887,7 +892,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, newElement = null; } const event = new (eventUtils.get(eventUtils.TOOLBOX_ITEM_SELECT))! - (oldElement, newElement, this.workspace.id); + (oldElement, newElement, this.workspace_.id); eventUtils.fire(event); } @@ -981,7 +986,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, /** Disposes of this toolbox. */ dispose() { - this.workspace.getComponentManager().removeComponent('toolbox'); + this.workspace_.getComponentManager().removeComponent('toolbox'); this.flyout_!.dispose(); for (let i = 0; i < this.contents_.length; i++) { const toolboxItem = this.contents_[i]; @@ -996,7 +1001,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, // AnyDuringMigration because: Argument of type 'HTMLDivElement | null' is // not assignable to parameter of type 'Element'. - this.workspace.getThemeManager().unsubscribe( + this.workspace_.getThemeManager().unsubscribe( this.HtmlDiv as AnyDuringMigration); dom.removeNode(this.HtmlDiv); }