Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
4 changes: 2 additions & 2 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextMenuOption|LegacyContextMenuOption>) =>
AnyDuringMigration)|null;
Expand Down
32 changes: 12 additions & 20 deletions core/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,30 @@ export const DEFAULT = 'default';
*/
export class Type<T> {
static CONNECTION_CHECKER = new Type<IConnectionChecker>('connectionChecker');

static CURSOR = new Type<Cursor>('cursor');

static EVENT = new Type<Abstract>('event');

static FIELD = new Type<Field>('field');

static RENDERER = new Type<Renderer>('renderer');

static TOOLBOX = new Type<IToolbox>('toolbox');

static THEME = new Type<Theme>('theme');

static TOOLBOX_ITEM = new Type<ToolboxItem>('toolboxItem');

static FLYOUTS_VERTICAL_TOOLBOX = new Type<IFlyout>('flyoutsVerticalToolbox');

static FLYOUTS_HORIZONTAL_TOOLBOX =
new Type<IFlyout>('flyoutsHorizontalToolbox');

static METRICS_MANAGER = new Type<IMetricsManager>('metricsManager');

static BLOCK_DRAGGER = new Type<IBlockDragger>('blockDragger');

/** @internal */
static SERIALIZER = new Type<ISerializer>('serializer');

Expand All @@ -89,31 +101,11 @@ export class Type<T> {
}
}

// 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.
Expand Down
29 changes: 17 additions & 12 deletions core/toolbox/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down Expand Up @@ -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);
Expand All @@ -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: [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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_;
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 :
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down