refactor: Remove some uses of AnyDuringMigration (#6307)

* refactor: Remove uses of AnyDuringMigration from trashcan.ts.

* refactor: Remove uses of AnyDuringMigration in bubble.ts.

* refactor: Remove uses of AnyDuringMigration from connection_checker.ts.

* refactor: Remove uses of AnyDuringMigration from connection_db.ts.

* refactor: Remove uses of AnyDuringMigration in contextmenu_items.ts.

* refactor: Remove uses of AnyDuringMigration from grid.ts.

* refactor: Remove uses of AnyDuringMigration from i_drag_target.ts.

* refactor: Remove uses of AnyDuringMigration from i_ast_node_location_svg.ts.

* refactor: Remove uses of AnyDuringMigration from i_ast_node_location_with_block.ts.

* refactor: Remove uses of AnyDuringMigration from i_autohideable.ts.

* refactor: Remove uses of AnyDuringMigration from i_block_dragger.ts.

* refactor: Remove uses of AnyDuringMigration from i_bounded_element.ts.

* refactor: Remove uses of AnyDuringMigration from i_bubble.ts.

* refactor: Remove uses of AnyDuringMigration from i_collapsible_toolbox_item.ts.

* refactor: Remove uses of AnyDuringMigration from i_connection_checker.ts.

* refactor: Remove uses of AnyDuringMigration from i_contextmenu.ts.

* refactor: Remove uses of AnyDuringMigration in i_copyable.ts.

* refactor: Remove uses of AnyDuringMigration from i_deleteable.ts.

* refactor: Remove uses of AnyDuringMigration from i_delete_area.ts.

* refactor: Remove uses of AnyDuringMigration in i_flyout.ts.

* refactor: Remove uses of AnyDuringMigration in i_keyboard_accessible.ts.

* refactor: Remove uses of AnyDuringMigration in i_metrics_manager.ts.

* refactor: Remove uses of AnyDuringMigration from i_movable.ts.

* refactor: Remove uses of AnyDuringMigration in i_positionable.ts.

* refactor: Remove uses of AnyDuringMigration in i_selectable_toolbox_item.ts.

* refactor: Remove uses of AnyDuringMigration from i_selectable.ts.

* refactor: Remove uses of AnyDuringMigration in i_serializer.ts.

* refactor: Remove uses of AnyDuringMigration from i_styleable.ts.

* refactor: Remove uses of AnyDuringMigration in i_toolbox.ts.

* refactor: Make non-null checks explicit.
This commit is contained in:
Aaron Dodson
2022-08-04 10:09:24 -07:00
committed by GitHub
parent ee83f09753
commit f70f82327b
35 changed files with 296 additions and 329 deletions

View File

@@ -68,39 +68,29 @@ export class Bubble implements IBubble {
/** Mouse move event data. */
private static onMouseMoveWrapper_: browserEvents.Data|null = null;
workspace_: AnyDuringMigration;
content_: AnyDuringMigration;
shape_: AnyDuringMigration;
workspace_: WorkspaceSvg;
content_: SVGElement;
shape_: SVGElement;
/** Flag to stop incremental rendering during construction. */
private readonly rendered_: boolean;
/** The SVG group containing all parts of the bubble. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGGElement'.
private bubbleGroup_: SVGGElement = null as AnyDuringMigration;
private bubbleGroup_: SVGGElement|null = null;
/**
* The SVG path for the arrow from the bubble to the icon on the block.
*/
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGPathElement'.
private bubbleArrow_: SVGPathElement = null as AnyDuringMigration;
private bubbleArrow_: SVGPathElement|null = null;
/** The SVG rect for the main body of the bubble. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGRectElement'.
private bubbleBack_: SVGRectElement = null as AnyDuringMigration;
private bubbleBack_: SVGRectElement|null = null;
/** The SVG group for the resize hash marks on some bubbles. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGGElement'.
private resizeGroup_: SVGGElement = null as AnyDuringMigration;
private resizeGroup_: SVGGElement|null = null;
/** Absolute coordinate of anchor point, in workspace coordinates. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'Coordinate'.
private anchorXY_: Coordinate = null as AnyDuringMigration;
private anchorXY_!: Coordinate;
/**
* Relative X coordinate of bubble with respect to the anchor's centre,
@@ -125,10 +115,10 @@ export class Bubble implements IBubble {
private autoLayout_ = true;
/** Method to call on resize of bubble. */
private resizeCallback_: (() => AnyDuringMigration)|null = null;
private resizeCallback_: (() => void)|null = null;
/** Method to call on move of bubble. */
private moveCallback_: (() => AnyDuringMigration)|null = null;
private moveCallback_: (() => void)|null = null;
/** Mouse down on bubbleBack_ event data. */
private onMouseDownBubbleWrapper_: browserEvents.Data|null = null;
@@ -142,7 +132,7 @@ export class Bubble implements IBubble {
* @internal
*/
disposed = false;
private arrow_radians_: AnyDuringMigration;
private arrow_radians_: number;
/**
* @param workspace The workspace on which to draw the bubble.
@@ -260,9 +250,7 @@ export class Bubble implements IBubble {
},
this.resizeGroup_);
} else {
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGGElement'.
this.resizeGroup_ = null as AnyDuringMigration;
this.resizeGroup_ = null;
}
if (!this.workspace_.options.readOnly) {
@@ -290,7 +278,7 @@ export class Bubble implements IBubble {
* @param id ID of block.
*/
setSvgId(id: string) {
this.bubbleGroup_.setAttribute('data-block-id', id);
this.bubbleGroup_?.setAttribute('data-block-id', id);
}
/**
@@ -374,20 +362,16 @@ export class Bubble implements IBubble {
* Register a function as a callback event for when the bubble is resized.
* @param callback The function to call on resize.
*/
registerResizeEvent(callback: Function) {
// AnyDuringMigration because: Type 'Function' is not assignable to type
// '() => any'.
this.resizeCallback_ = callback as AnyDuringMigration;
registerResizeEvent(callback: () => void) {
this.resizeCallback_ = callback;
}
/**
* Register a function as a callback event for when the bubble is moved.
* @param callback The function to call on move.
*/
registerMoveEvent(callback: Function) {
// AnyDuringMigration because: Type 'Function' is not assignable to type
// '() => any'.
this.moveCallback_ = callback as AnyDuringMigration;
registerMoveEvent(callback: () => void) {
this.moveCallback_ = callback;
}
/**
@@ -396,9 +380,9 @@ export class Bubble implements IBubble {
* @internal
*/
promote(): boolean {
const svgGroup = this.bubbleGroup_.parentNode;
if (svgGroup!.lastChild !== this.bubbleGroup_) {
svgGroup!.appendChild(this.bubbleGroup_);
const svgGroup = this.bubbleGroup_?.parentNode;
if (svgGroup?.lastChild !== this.bubbleGroup_ && this.bubbleGroup_) {
svgGroup?.appendChild(this.bubbleGroup_);
return true;
}
return false;
@@ -630,7 +614,7 @@ export class Bubble implements IBubble {
* @internal
*/
moveTo(x: number, y: number) {
this.bubbleGroup_.setAttribute(
this.bubbleGroup_?.setAttribute(
'transform', 'translate(' + x + ',' + y + ')');
}
@@ -665,12 +649,8 @@ export class Bubble implements IBubble {
height = Math.max(height, doubleBorderWidth + 20);
this.width_ = width;
this.height_ = height;
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.bubbleBack_.setAttribute('width', width as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.bubbleBack_.setAttribute('height', height as AnyDuringMigration);
this.bubbleBack_?.setAttribute('width', width.toString());
this.bubbleBack_?.setAttribute('height', height.toString());
if (this.resizeGroup_) {
if (this.workspace_.RTL) {
// Mirror the resize group.
@@ -765,7 +745,7 @@ export class Bubble implements IBubble {
',' + (baseY2 + swirlRise) + ' ' + baseX2 + ',' + baseY2);
}
steps.push('z');
this.bubbleArrow_.setAttribute('d', steps.join(' '));
this.bubbleArrow_?.setAttribute('d', steps.join(' '));
}
/**
@@ -773,8 +753,8 @@ export class Bubble implements IBubble {
* @param hexColour Hex code of colour.
*/
setColour(hexColour: string) {
this.bubbleBack_.setAttribute('fill', hexColour);
this.bubbleArrow_.setAttribute('fill', hexColour);
this.bubbleBack_?.setAttribute('fill', hexColour);
this.bubbleArrow_?.setAttribute('fill', hexColour);
}
/** Dispose of this bubble. */

View File

@@ -79,7 +79,8 @@ export function duplicate(toDuplicate: ICopyable): ICopyable|null {
function duplicateInternal(toDuplicate: ICopyable): ICopyable|null {
const oldCopyData = copyData;
copy(toDuplicate);
const pastedThing = toDuplicate.toCopyData().source.paste(copyData!.saveInfo);
const pastedThing =
toDuplicate.toCopyData()?.source?.paste(copyData!.saveInfo) ?? null;
copyData = oldCopyData;
return pastedThing;
}

View File

@@ -207,9 +207,7 @@ export class ConnectionChecker implements IConnectionChecker {
*/
doDragChecks(a: RenderedConnection, b: RenderedConnection, distance: number):
boolean {
// AnyDuringMigration because: Argument of type 'RenderedConnection' is not
// assignable to parameter of type 'Connection'.
if (a.distanceFrom(b as AnyDuringMigration) > distance) {
if (a.distanceFrom(b) > distance) {
return false;
}
@@ -220,9 +218,7 @@ export class ConnectionChecker implements IConnectionChecker {
switch (b.type) {
case ConnectionType.PREVIOUS_STATEMENT:
// AnyDuringMigration because: Argument of type 'RenderedConnection' is
// not assignable to parameter of type 'Connection'.
return this.canConnectToPrevious_(a as AnyDuringMigration, b);
return this.canConnectToPrevious_(a, b);
case ConnectionType.OUTPUT_VALUE: {
// Don't offer to connect an already connected left (male) value plug to
// an available right (female) value plug.
@@ -259,9 +255,7 @@ export class ConnectionChecker implements IConnectionChecker {
}
// Don't let blocks try to connect to themselves or ones they nest.
// AnyDuringMigration because: Argument of type 'RenderedConnection' is not
// assignable to parameter of type 'Connection'.
if (common.draggingConnections.indexOf(b as AnyDuringMigration) !== -1) {
if (common.draggingConnections.indexOf(b) !== -1) {
return false;
}

View File

@@ -162,7 +162,7 @@ export class ConnectionDB {
pointerMid = Math.floor((pointerMin + pointerMax) / 2);
}
const neighbours: AnyDuringMigration[] = [];
const neighbours: RenderedConnection[] = [];
/**
* Computes if the current connection is within the allowed radius of
* another connection. This function is a closure and has access to outside
@@ -220,12 +220,10 @@ export class ConnectionDB {
*/
searchForClosest(
conn: RenderedConnection, maxRadius: number,
dxy: Coordinate): {connection: RenderedConnection, radius: number} {
dxy: Coordinate): {connection: RenderedConnection|null, radius: number} {
if (!this.connections_.length) {
// Don't bother.
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'RenderedConnection'.
return {connection: null as AnyDuringMigration, radius: maxRadius};
return {connection: null, radius: maxRadius};
}
// Stash the values of x and y from before the drag.
@@ -250,9 +248,7 @@ export class ConnectionDB {
temp = this.connections_[pointerMin];
if (this.connectionChecker.canConnect(conn, temp, true, bestRadius)) {
bestConnection = temp;
// AnyDuringMigration because: Argument of type 'RenderedConnection' is
// not assignable to parameter of type 'Connection'.
bestRadius = temp.distanceFrom(conn as AnyDuringMigration);
bestRadius = temp.distanceFrom(conn);
}
pointerMin--;
}
@@ -263,9 +259,7 @@ export class ConnectionDB {
temp = this.connections_[pointerMax];
if (this.connectionChecker.canConnect(conn, temp, true, bestRadius)) {
bestConnection = temp;
// AnyDuringMigration because: Argument of type 'RenderedConnection' is
// not assignable to parameter of type 'Connection'.
bestRadius = temp.distanceFrom(conn as AnyDuringMigration);
bestRadius = temp.distanceFrom(conn);
}
pointerMax++;
}
@@ -274,12 +268,7 @@ export class ConnectionDB {
conn.x = baseX;
conn.y = baseY;
// If there were no valid connections, bestConnection will be null.
// AnyDuringMigration because: Type 'RenderedConnection | null' is not
// assignable to type 'RenderedConnection'.
return {
connection: bestConnection as AnyDuringMigration,
radius: bestRadius
};
return {connection: bestConnection, radius: bestRadius};
}
/**

View File

@@ -114,7 +114,7 @@ function toggleOption_(shouldCollapse: boolean, topBlocks: BlockSvg[]) {
const DELAY = 10;
let ms = 0;
let timeoutCounter = 0;
function timeoutFn(block: AnyDuringMigration) {
function timeoutFn(block: BlockSvg) {
timeoutCounter--;
block.setCollapsed(shouldCollapse);
if (timeoutCounter === 0) {
@@ -123,13 +123,11 @@ function toggleOption_(shouldCollapse: boolean, topBlocks: BlockSvg[]) {
}
Events.setGroup(true);
for (let i = 0; i < topBlocks.length; i++) {
let block = topBlocks[i];
let block: BlockSvg|null = topBlocks[i];
while (block) {
timeoutCounter++;
setTimeout(timeoutFn.bind(null, block), ms);
// AnyDuringMigration because: Type 'BlockSvg | null' is not assignable
// to type 'BlockSvg'.
block = block.getNextBlock() as AnyDuringMigration;
block = block.getNextBlock();
ms += DELAY;
}
}
@@ -148,14 +146,12 @@ export function registerCollapse() {
if (scope.workspace!.options.collapse) {
const topBlocks = scope.workspace!.getTopBlocks(false);
for (let i = 0; i < topBlocks.length; i++) {
let block = topBlocks[i];
let block: BlockSvg|null = topBlocks[i];
while (block) {
if (!block.isCollapsed()) {
return 'enabled';
}
// AnyDuringMigration because: Type 'BlockSvg | null' is not
// assignable to type 'BlockSvg'.
block = block.getNextBlock() as AnyDuringMigration;
block = block.getNextBlock();
}
}
return 'disabled';
@@ -185,14 +181,12 @@ export function registerExpand() {
if (scope.workspace!.options.collapse) {
const topBlocks = scope.workspace!.getTopBlocks(false);
for (let i = 0; i < topBlocks.length; i++) {
let block = topBlocks[i];
let block: BlockSvg|null = topBlocks[i];
while (block) {
if (block.isCollapsed()) {
return 'enabled';
}
// AnyDuringMigration because: Type 'BlockSvg | null' is not
// assignable to type 'BlockSvg'.
block = block.getNextBlock() as AnyDuringMigration;
block = block.getNextBlock();
}
}
return 'disabled';
@@ -231,7 +225,7 @@ function addDeletableBlocks_(block: BlockSvg, deleteList: BlockSvg[]) {
* @return list of blocks to delete.
*/
function getDeletableBlocks_(workspace: WorkspaceSvg): BlockSvg[] {
const deleteList: AnyDuringMigration[] = [];
const deleteList: BlockSvg[] = [];
const topBlocks = workspace.getTopBlocks(true);
for (let i = 0; i < topBlocks.length; i++) {
addDeletableBlocks_(topBlocks[i], deleteList);
@@ -265,12 +259,10 @@ function deleteNext_(deleteList: BlockSvg[], eventGroup: string) {
* @alias Blockly.ContextMenuItems.registerDeleteAll
*/
export function registerDeleteAll() {
// AnyDuringMigration because: Type '(scope: Scope) => string | undefined' is
// not assignable to type 'string | ((p1: Scope) => string)'.
const deleteOption: RegistryItem = {
displayText(scope: Scope) {
if (!scope.workspace) {
return;
return '';
}
const deletableBlocksLength = getDeletableBlocks_(scope.workspace).length;
if (deletableBlocksLength === 1) {
@@ -282,7 +274,7 @@ export function registerDeleteAll() {
},
preconditionFn(scope: Scope) {
if (!scope.workspace) {
return;
return 'disabled';
}
const deletableBlocksLength = getDeletableBlocks_(scope.workspace).length;
return deletableBlocksLength > 0 ? 'enabled' : 'disabled';
@@ -310,7 +302,7 @@ export function registerDeleteAll() {
scopeType: ContextMenuRegistry.ScopeType.WORKSPACE,
id: 'workspaceDelete',
weight: 6,
} as AnyDuringMigration;
};
ContextMenuRegistry.registry.register(deleteOption);
}
/** Registers all workspace-scoped context menu items. */

View File

@@ -20,6 +20,7 @@ goog.declareModuleId('Blockly.Grid');
import * as dom from './utils/dom.js';
import {Svg} from './utils/svg.js';
import * as userAgent from './utils/useragent.js';
import {GridOptions} from './blockly_options.js';
/**
@@ -44,12 +45,12 @@ export class Grid {
* See grid documentation:
* https://developers.google.com/blockly/guides/configure/web/grid
*/
constructor(private pattern: SVGElement, options: AnyDuringMigration) {
constructor(private pattern: SVGElement, options: GridOptions) {
/** The spacing of the grid lines (in px). */
this.spacing_ = options['spacing'];
this.spacing_ = options['spacing'] ?? 0;
/** How long the grid lines should be (in px). */
this.length_ = options['length'];
this.length_ = options['length'] ?? 1;
/** The horizontal grid line, if it exists. */
this.line1_ = pattern.firstChild as SVGElement;
@@ -58,18 +59,7 @@ export class Grid {
this.line2_ = this.line1_ && this.line1_.nextSibling as SVGElement;
/** Whether blocks should snap to the grid. */
this.snapToGrid_ = options['snap'];
}
/**
* Dispose of this grid and unlink from the DOM.
* @suppress {checkTypes}
* @internal
*/
dispose() {
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGElement'.
this.pattern = null as AnyDuringMigration;
this.snapToGrid_ = options['snap'] ?? false;
}
/**
@@ -110,12 +100,8 @@ export class Grid {
// MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100.
const safeSpacing = this.spacing_ * scale || 100;
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.pattern.setAttribute('width', safeSpacing as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.pattern.setAttribute('height', safeSpacing as AnyDuringMigration);
this.pattern.setAttribute('width', safeSpacing.toString());
this.pattern.setAttribute('height', safeSpacing.toString());
let half = Math.floor(this.spacing_ / 2) + 0.5;
let start = half - this.length_ / 2;
@@ -143,21 +129,11 @@ export class Grid {
line: SVGElement, width: number, x1: number, x2: number, y1: number,
y2: number) {
if (line) {
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
line.setAttribute('stroke-width', width as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
line.setAttribute('x1', x1 as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
line.setAttribute('y1', y1 as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
line.setAttribute('x2', x2 as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
line.setAttribute('y2', y2 as AnyDuringMigration);
line.setAttribute('stroke-width', width.toString());
line.setAttribute('x1', x1.toString());
line.setAttribute('y1', y1.toString());
line.setAttribute('x2', x2.toString());
line.setAttribute('y2', y2.toString());
}
}
@@ -169,12 +145,8 @@ export class Grid {
* @internal
*/
moveTo(x: number, y: number) {
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.pattern.setAttribute('x', x as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.pattern.setAttribute('y', y as AnyDuringMigration);
this.pattern.setAttribute('x', x.toString());
this.pattern.setAttribute('y', y.toString());
if (userAgent.IE || userAgent.EDGE) {
// IE/Edge doesn't notice that the x/y offsets have changed.
@@ -191,9 +163,8 @@ export class Grid {
* @return The SVG element for the grid pattern.
* @internal
*/
static createDom(
rnd: string, gridOptions: AnyDuringMigration,
defs: SVGElement): SVGElement {
static createDom(rnd: string, gridOptions: GridOptions, defs: SVGElement):
SVGElement {
/*
<pattern id="blocklyGridPattern837493" patternUnits="userSpaceOnUse">
<rect stroke="#888" />
@@ -205,10 +176,10 @@ export class Grid {
{'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'},
defs);
// x1, y1, x1, x2 properties will be set later in update.
if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) {
if ((gridOptions['length'] ?? 1) > 0 && (gridOptions['spacing'] ?? 0) > 0) {
dom.createSvgElement(
Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern);
if (gridOptions['length'] > 1) {
if (gridOptions['length'] ?? 1 > 1) {
dom.createSvgElement(
Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern);
}

View File

@@ -27,11 +27,11 @@ export interface IASTNodeLocationSvg extends IASTNodeLocation {
* Add the marker SVG to this node's SVG group.
* @param markerSvg The SVG root of the marker to be added to the SVG group.
*/
setMarkerSvg: AnyDuringMigration;
setMarkerSvg(markerSvg: SVGElement|null): void;
/**
* Add the cursor SVG to this node's SVG group.
* @param cursorSvg The SVG root of the cursor to be added to the SVG group.
*/
setCursorSvg: AnyDuringMigration;
setCursorSvg(cursorSvg: SVGElement|null): void;
}

View File

@@ -22,6 +22,7 @@ goog.declareModuleId('Blockly.IASTNodeLocationWithBlock');
// import '../block.js';
import type {IASTNodeLocation} from './i_ast_node_location.js';
import type {Block} from '../block.js';
/**
@@ -33,5 +34,5 @@ export interface IASTNodeLocationWithBlock extends IASTNodeLocation {
* Get the source block associated with this node.
* @return The source block.
*/
getSourceBlock: AnyDuringMigration;
getSourceBlock(): Block;
}

View File

@@ -30,5 +30,5 @@ export interface IAutoHideable extends IComponent {
* @param onlyClosePopups Whether only popups should be closed.
* Flyouts should not be closed if this is true.
*/
autoHide: AnyDuringMigration;
autoHide(onlyClosePopups: boolean): void;
}

View File

@@ -13,6 +13,8 @@
* @namespace Blockly.IBlockDragger
*/
import * as goog from '../../closure/goog/goog.js';
import type {Coordinate} from '../utils/coordinate.js';
import type {BlockSvg} from '../block_svg.js';
goog.declareModuleId('Blockly.IBlockDragger');
/* eslint-disable-next-line no-unused-vars */
@@ -34,7 +36,7 @@ export interface IBlockDragger {
* at mouse down, in pixel units.
* @param healStack Whether or not to heal the stack after disconnecting.
*/
startDrag: AnyDuringMigration;
startDrag(currentDragDeltaXY: Coordinate, healStack: boolean): void;
/**
* Execute a step of block dragging, based on the given event. Update the
@@ -43,7 +45,7 @@ export interface IBlockDragger {
* @param currentDragDeltaXY How far the pointer has moved from the position
* at the start of the drag, in pixel units.
*/
drag: AnyDuringMigration;
drag(e: Event, currentDragDeltaXY: Coordinate): void;
/**
* Finish a block drag and put the block back on the workspace.
@@ -51,15 +53,15 @@ export interface IBlockDragger {
* @param currentDragDeltaXY How far the pointer has moved from the position
* at the start of the drag, in pixel units.
*/
endDrag: AnyDuringMigration;
endDrag(e: Event, currentDragDeltaXY: Coordinate): void;
/**
* Get a list of the insertion markers that currently exist. Drags have 0, 1,
* or 2 insertion markers.
* @return A possibly empty list of insertion marker blocks.
*/
getInsertionMarkers: AnyDuringMigration;
getInsertionMarkers(): BlockSvg[];
/** Sever all links from this object and do any necessary cleanup. */
dispose: () => void;
dispose(): void;
}

View File

@@ -13,6 +13,7 @@
* @namespace Blockly.IBoundedElement
*/
import * as goog from '../../closure/goog/goog.js';
import type {Rect} from '../utils/rect.js';
goog.declareModuleId('Blockly.IBoundedElement');
/* eslint-disable-next-line no-unused-vars */
@@ -30,12 +31,12 @@ export interface IBoundedElement {
* the element. Coordinate system: workspace coordinates.
* @return Object with coordinates of the bounded element.
*/
getBoundingRectangle: AnyDuringMigration;
getBoundingRectangle(): Rect;
/**
* Move the element by a relative offset.
* @param dx Horizontal offset in workspace units.
* @param dy Vertical offset in workspace units.
*/
moveBy: AnyDuringMigration;
moveBy(dx: number, dy: number): void;
}

View File

@@ -13,6 +13,8 @@
* @namespace Blockly.IBubble
*/
import * as goog from '../../closure/goog/goog.js';
import type {Coordinate} from '../utils/coordinate.js';
import type {BlockDragSurfaceSvg} from '../block_drag_surface.js';
goog.declareModuleId('Blockly.IBubble');
/* eslint-disable-next-line no-unused-vars */
@@ -36,13 +38,13 @@ export interface IBubble extends IDraggable, IContextMenu {
* relative to the drawing surface's origin (0,0), in workspace units.
* @return Object with .x and .y properties.
*/
getRelativeToSurfaceXY: AnyDuringMigration;
getRelativeToSurfaceXY(): Coordinate;
/**
* Return the root node of the bubble's SVG group.
* @return The root SVG node of the bubble's group.
*/
getSvgRoot: AnyDuringMigration;
getSvgRoot(): SVGElement;
/**
* Set whether auto-layout of this bubble is enabled. The first time a bubble
@@ -50,13 +52,13 @@ export interface IBubble extends IDraggable, IContextMenu {
* dragged it to reposition, it renders where the user put it.
* @param enable True if auto-layout should be enabled, false otherwise.
*/
setAutoLayout: AnyDuringMigration;
setAutoLayout(enable: boolean): void;
/**
* Triggers a move callback if one exists at the end of a drag.
* @param adding True if adding, false if removing.
* Sets whether or not this bubble is being dragged.
* @param adding True if dragging, false otherwise.
*/
setDragging: AnyDuringMigration;
setDragging(dragging: boolean): void;
/**
* Move this bubble during a drag, taking into account whether or not there is
@@ -65,21 +67,22 @@ export interface IBubble extends IDraggable, IContextMenu {
* or null if no drag surface is in use.
* @param newLoc The location to translate to, in workspace coordinates.
*/
moveDuringDrag: AnyDuringMigration;
moveDuringDrag(dragSurface: BlockDragSurfaceSvg|null, newLoc: Coordinate):
void;
/**
* Move the bubble to the specified location in workspace coordinates.
* @param x The x position to move to.
* @param y The y position to move to.
*/
moveTo: AnyDuringMigration;
moveTo(x: number, y: number): void;
/**
* Update the style of this bubble when it is dragged over a delete area.
* @param enable True if the bubble is about to be deleted, false otherwise.
*/
setDeleteStyle: AnyDuringMigration;
setDeleteStyle(enable: boolean): void;
/** Dispose of this bubble. */
dispose: () => void;
dispose(): void;
}

View File

@@ -21,6 +21,7 @@ goog.declareModuleId('Blockly.ICollapsibleToolboxItem');
// import './i_toolbox_item.js';
import type {ISelectableToolboxItem} from './i_selectable_toolbox_item.js';
import type {IToolboxItem} from './i_toolbox_item.js';
/**
@@ -32,15 +33,15 @@ export interface ICollapsibleToolboxItem extends ISelectableToolboxItem {
* Gets any children toolbox items. (ex. Gets the subcategories)
* @return The child toolbox items.
*/
getChildToolboxItems: AnyDuringMigration;
getChildToolboxItems(): IToolboxItem[];
/**
* Whether the toolbox item is expanded to show its child subcategories.
* @return True if the toolbox item shows its children, false if it is
* collapsed.
*/
isExpanded: AnyDuringMigration;
isExpanded(): boolean;
/** Toggles whether or not the toolbox item is expanded. */
toggleExpanded: () => void;
toggleExpanded(): void;
}

View File

@@ -15,6 +15,8 @@
* @namespace Blockly.IConnectionChecker
*/
import * as goog from '../../closure/goog/goog.js';
import type {Connection} from '../connection.js';
import type {RenderedConnection} from '../rendered_connection.js';
goog.declareModuleId('Blockly.IConnectionChecker');
/* eslint-disable-next-line no-unused-vars */
@@ -40,7 +42,9 @@ export interface IConnectionChecker {
* drag checks.
* @return Whether the connection is legal.
*/
canConnect: AnyDuringMigration;
canConnect(
a: Connection|null, b: Connection|null, isDragging: boolean,
opt_distance?: number): boolean;
/**
* Checks whether the current connection can connect with the target
@@ -53,7 +57,9 @@ export interface IConnectionChecker {
* @return Connection.CAN_CONNECT if the connection is legal, an error code
* otherwise.
*/
canConnectWithReason: AnyDuringMigration;
canConnectWithReason(
a: Connection|null, b: Connection|null, isDragging: boolean,
opt_distance?: number): number;
/**
* Helper method that translates a connection error code into a string.
@@ -62,7 +68,8 @@ export interface IConnectionChecker {
* @param b The second of the two connections being checked.
* @return A developer-readable error string.
*/
getErrorMessage: AnyDuringMigration;
getErrorMessage(errorCode: number, a: Connection|null, b: Connection|null):
string;
/**
* Check that connecting the given connections is safe, meaning that it would
@@ -71,7 +78,7 @@ export interface IConnectionChecker {
* @param b The second of the connections to check.
* @return An enum with the reason this connection is safe or unsafe.
*/
doSafetyChecks: AnyDuringMigration;
doSafetyChecks(a: Connection|null, b: Connection|null): number;
/**
* Check whether this connection is compatible with another connection with
@@ -81,7 +88,7 @@ export interface IConnectionChecker {
* @param b Connection to compare against.
* @return True if the connections share a type.
*/
doTypeChecks: AnyDuringMigration;
doTypeChecks(a: Connection, b: Connection): boolean;
/**
* Check whether this connection can be made by dragging.
@@ -90,5 +97,6 @@ export interface IConnectionChecker {
* @param distance The maximum allowable distance between connections.
* @return True if the connection is allowed during a drag.
*/
doDragChecks: AnyDuringMigration;
doDragChecks(a: RenderedConnection, b: RenderedConnection, distance: number):
boolean;
}

View File

@@ -22,5 +22,5 @@ export interface IContextMenu {
* Show the context menu for this object.
* @param e Mouse event.
*/
showContextMenu: AnyDuringMigration;
showContextMenu(e: Event): void;
}

View File

@@ -26,14 +26,14 @@ export interface ICopyable extends ISelectable {
* @return Copy metadata.
* @internal
*/
toCopyData: AnyDuringMigration;
toCopyData(): CopyData|null;
}
export namespace ICopyable {
export interface CopyData {
saveInfo: AnyDuringMigration|Element;
saveInfo: Object|Element;
source: WorkspaceSvg;
typeCounts: AnyDuringMigration|null;
typeCounts: Object|null;
}
}

View File

@@ -25,5 +25,5 @@ export interface IDeletable {
* Get whether this object is deletable or not.
* @return True if deletable.
*/
isDeletable: AnyDuringMigration;
isDeletable(): boolean;
}

View File

@@ -23,6 +23,7 @@ goog.declareModuleId('Blockly.IDeleteArea');
// import './i_draggable.js';
import type {IDragTarget} from './i_drag_target.js';
import type {IDraggable} from './i_draggable.js';
/**
@@ -41,5 +42,5 @@ export interface IDeleteArea extends IDragTarget {
* @return Whether the element provided would be deleted if dropped on this
* area.
*/
wouldDelete: AnyDuringMigration;
wouldDelete(element: IDraggable, couldConnect: boolean): boolean;
}

View File

@@ -15,6 +15,10 @@
* @namespace Blockly.IDragTarget
*/
import * as goog from '../../closure/goog/goog.js';
import {Rect} from '../utils/rect.js';
import {IDraggable} from './i_draggable.js';
goog.declareModuleId('Blockly.IDragTarget');
/* eslint-disable-next-line no-unused-vars */
@@ -40,33 +44,33 @@ export interface IDragTarget extends IComponent {
* @return The component's bounding box. Null if drag target area should be
* ignored.
*/
getClientRect: AnyDuringMigration;
getClientRect(): Rect|null;
/**
* Handles when a cursor with a block or bubble enters this drag target.
* @param dragElement The block or bubble currently being dragged.
*/
onDragEnter: AnyDuringMigration;
onDragEnter(dragElement: IDraggable): void;
/**
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
* @param dragElement The block or bubble currently being dragged.
*/
onDragOver: AnyDuringMigration;
onDragOver(dragElement: IDraggable): void;
/**
* Handles when a cursor with a block or bubble exits this drag target.
* @param dragElement The block or bubble currently being dragged.
*/
onDragExit: AnyDuringMigration;
onDragExit(dragElement: IDraggable): void;
/**
* Handles when a block or bubble is dropped on this component.
* Should not handle delete here.
* @param dragElement The block or bubble currently being dragged.
*/
onDrop: AnyDuringMigration;
onDrop(dragElement: IDraggable): void;
/**
* Returns whether the provided block or bubble should not be moved after
@@ -76,5 +80,5 @@ export interface IDragTarget extends IComponent {
* @return Whether the block or bubble provided should be returned to drag
* start.
*/
shouldPreventMove: AnyDuringMigration;
shouldPreventMove(dragElement: IDraggable): boolean;
}

View File

@@ -29,7 +29,10 @@ goog.declareModuleId('Blockly.IFlyout');
// import '../utils/svg.js';
import type {WorkspaceSvg} from '../workspace_svg.js';
import type {BlockSvg} from '../block_svg.js';
import type {Coordinate} from '../utils/coordinate.js';
import type {FlyoutDefinition} from '../utils/toolbox.js';
import type {Svg} from '../utils/svg.js';
import type {IRegistrable} from './i_registrable.js';
@@ -64,43 +67,43 @@ export interface IFlyout extends IRegistrable {
* or <g>.
* @return The flyout's SVG group.
*/
createDom: AnyDuringMigration;
createDom(tagName: string|Svg<SVGSVGElement>|Svg<SVGGElement>): SVGElement;
/**
* Initializes the flyout.
* @param targetWorkspace The workspace in which to create new blocks.
*/
init: AnyDuringMigration;
init(targetWorkspace: WorkspaceSvg): void;
/**
* Dispose of this flyout.
* Unlink from all DOM elements to prevent memory leaks.
*/
dispose: () => void;
dispose(): void;
/**
* Get the width of the flyout.
* @return The width of the flyout.
*/
getWidth: AnyDuringMigration;
getWidth(): number;
/**
* Get the height of the flyout.
* @return The width of the flyout.
* @return The height of the flyout.
*/
getHeight: AnyDuringMigration;
getHeight(): number;
/**
* Get the workspace inside the flyout.
* @return The workspace inside the flyout.
*/
getWorkspace: AnyDuringMigration;
getWorkspace(): WorkspaceSvg;
/**
* Is the flyout visible?
* @return True if visible.
*/
isVisible: AnyDuringMigration;
isVisible(): boolean;
/**
* Set whether the flyout is visible. A value of true does not necessarily
@@ -108,16 +111,16 @@ export interface IFlyout extends IRegistrable {
* hidden.
* @param visible True if visible.
*/
setVisible: AnyDuringMigration;
setVisible(visible: boolean): void;
/**
* Set whether this flyout's container is visible.
* @param visible Whether the container is visible.
*/
setContainerVisible: AnyDuringMigration;
setContainerVisible(visible: boolean): void;
/** Hide and empty the flyout. */
hide: () => void;
hide(): void;
/**
* Show and populate the flyout.
@@ -125,7 +128,7 @@ export interface IFlyout extends IRegistrable {
* of Nodes, a NodeList, a toolbox definition, or a string with the name
* of the dynamic category.
*/
show: AnyDuringMigration;
show(flyoutDef: FlyoutDefinition|string): void;
/**
* Create a copy of this block on the workspace.
@@ -133,31 +136,31 @@ export interface IFlyout extends IRegistrable {
* @return The newly created block.
* @throws {Error} if something went wrong with deserialization.
*/
createBlock: AnyDuringMigration;
createBlock(originalBlock: BlockSvg): BlockSvg;
/** Reflow blocks and their mats. */
reflow: () => void;
reflow(): void;
/**
* @return True if this flyout may be scrolled with a scrollbar or by
* dragging.
*/
isScrollable: AnyDuringMigration;
isScrollable(): boolean;
/**
* Calculates the x coordinate for the flyout position.
* @return X coordinate.
*/
getX: AnyDuringMigration;
getX(): number;
/**
* Calculates the y coordinate for the flyout position.
* @return Y coordinate.
*/
getY: AnyDuringMigration;
getY(): number;
/** Position the flyout. */
position: AnyDuringMigration;
position(): void;
/**
* Determine if a drag delta is toward the workspace, based on the position
@@ -167,7 +170,7 @@ export interface IFlyout extends IRegistrable {
* at mouse down, in pixel units.
* @return True if the drag is toward the workspace.
*/
isDragTowardWorkspace: AnyDuringMigration;
isDragTowardWorkspace(currentDragDeltaXY: Coordinate): boolean;
/**
* Does this flyout allow you to create a new instance of the given block?
@@ -176,8 +179,8 @@ export interface IFlyout extends IRegistrable {
* @return True if you can create a new instance of the block, false
* otherwise.
*/
isBlockCreatable: AnyDuringMigration;
isBlockCreatable(block: BlockSvg): boolean;
/** Scroll the flyout to the beginning of its contents. */
scrollToStart: () => void;
scrollToStart(): void;
}

View File

@@ -13,6 +13,7 @@
* @namespace Blockly.IKeyboardAccessible
*/
import * as goog from '../../closure/goog/goog.js';
import {KeyboardShortcut} from '../shortcut_registry.js';
goog.declareModuleId('Blockly.IKeyboardAccessible');
/* eslint-disable-next-line no-unused-vars */
@@ -30,5 +31,5 @@ export interface IKeyboardAccessible {
* @param shortcut The shortcut to be handled.
* @return True if the shortcut has been handled, false otherwise.
*/
onShortcut: AnyDuringMigration;
onShortcut(shortcut: KeyboardShortcut): boolean;
}

View File

@@ -13,6 +13,9 @@
* @namespace Blockly.IMetricsManager
*/
import * as goog from '../../closure/goog/goog.js';
import type {ContainerRegion, ToolboxMetrics, AbsoluteMetrics, UiMetrics} from '../metrics_manager.js';
import type {Size} from '../utils/size.js';
import type {Metrics} from '../utils/metrics.js';
goog.declareModuleId('Blockly.IMetricsManager');
/* eslint-disable-next-line no-unused-vars */
@@ -36,7 +39,7 @@ export interface IMetricsManager {
* @return Whether the scroll area has fixed edges.
* @internal
*/
hasFixedEdges: AnyDuringMigration;
hasFixedEdges(): boolean;
/**
* Returns the metrics for the scroll area of the workspace.
@@ -50,7 +53,9 @@ export interface IMetricsManager {
* again, if it is needed.
* @return The metrics for the scroll container
*/
getScrollMetrics: AnyDuringMigration;
getScrollMetrics(
opt_getWorkspaceCoordinates?: boolean, opt_viewMetrics?: ContainerRegion,
opt_contentMetrics?: ContainerRegion): ContainerRegion;
/**
* Gets the width and the height of the flyout on the workspace in pixel
@@ -59,7 +64,7 @@ export interface IMetricsManager {
* @param opt_own Whether to only return the workspace's own flyout.
* @return The width and height of the flyout.
*/
getFlyoutMetrics: AnyDuringMigration;
getFlyoutMetrics(opt_own?: boolean): ToolboxMetrics;
/**
* Gets the width, height and position of the toolbox on the workspace in
@@ -69,14 +74,14 @@ export interface IMetricsManager {
* simple toolbox @see {@link getFlyoutMetrics}.
* @return The object with the width, height and position of the toolbox.
*/
getToolboxMetrics: AnyDuringMigration;
getToolboxMetrics(): ToolboxMetrics;
/**
* Gets the width and height of the workspace's parent SVG element in pixel
* coordinates. This area includes the toolbox and the visible workspace area.
* @return The width and height of the workspace's parent SVG element.
*/
getSvgMetrics: AnyDuringMigration;
getSvgMetrics(): Size;
/**
* Gets the absolute left and absolute top in pixel coordinates.
@@ -84,7 +89,7 @@ export interface IMetricsManager {
* container.
* @return The absolute metrics for the workspace.
*/
getAbsoluteMetrics: AnyDuringMigration;
getAbsoluteMetrics(): AbsoluteMetrics;
/**
* Gets the metrics for the visible workspace in either pixel or workspace
@@ -94,7 +99,7 @@ export interface IMetricsManager {
* @return The width, height, top and left of the viewport in either workspace
* coordinates or pixel coordinates.
*/
getViewMetrics: AnyDuringMigration;
getViewMetrics(opt_getWorkspaceCoordinates?: boolean): ContainerRegion;
/**
* Gets content metrics in either pixel or workspace coordinates.
@@ -104,7 +109,7 @@ export interface IMetricsManager {
* workspace coordinates, false to get them in pixel coordinates.
* @return The metrics for the content container.
*/
getContentMetrics: AnyDuringMigration;
getContentMetrics(opt_getWorkspaceCoordinates?: boolean): ContainerRegion;
/**
* Returns an object with all the metrics required to size scrollbars for a
@@ -136,11 +141,11 @@ export interface IMetricsManager {
* compare.
* @return Contains size and position metrics of a top level workspace.
*/
getMetrics: AnyDuringMigration;
getMetrics(): Metrics;
/**
* Returns common metrics used by UI elements.
* @return The UI metrics.
*/
getUiMetrics: AnyDuringMigration;
getUiMetrics(): UiMetrics;
}

View File

@@ -25,5 +25,5 @@ export interface IMovable {
* Get whether this is movable or not.
* @return True if movable.
*/
isMovable: AnyDuringMigration;
isMovable(): boolean;
}

View File

@@ -13,6 +13,8 @@
* @namespace Blockly.IPositionable
*/
import * as goog from '../../closure/goog/goog.js';
import type {Rect} from '../utils/rect.js';
import type {UiMetrics} from '../metrics_manager.js';
goog.declareModuleId('Blockly.IPositionable');
/* eslint-disable-next-line no-unused-vars */
@@ -36,7 +38,7 @@ export interface IPositionable extends IComponent {
* @param metrics The workspace metrics.
* @param savedPositions List of rectangles that are already on the workspace.
*/
position: AnyDuringMigration;
position(metrics: UiMetrics, savedPositions: Rect[]): void;
/**
* Returns the bounding rectangle of the UI element in pixel units relative to
@@ -44,5 +46,5 @@ export interface IPositionable extends IComponent {
* @return The UI elements's bounding box. Null if bounding box should be
* ignored by other UI elements.
*/
getBoundingRectangle: AnyDuringMigration;
getBoundingRectangle(): Rect|null;
}

View File

@@ -27,8 +27,8 @@ export interface ISelectable extends IDeletable, IMovable {
id: string;
/** Select this. Highlight it visually. */
select: AnyDuringMigration;
select(): void;
/** Unselect this. Unhighlight it visually. */
unselect: AnyDuringMigration;
unselect(): void;
}

View File

@@ -13,6 +13,7 @@
* @namespace Blockly.ISelectableToolboxItem
*/
import * as goog from '../../closure/goog/goog.js';
import type {FlyoutItemInfoArray} from '../utils/toolbox';
goog.declareModuleId('Blockly.ISelectableToolboxItem');
/* eslint-disable-next-line no-unused-vars */
@@ -31,20 +32,20 @@ export interface ISelectableToolboxItem extends IToolboxItem {
* Gets the name of the toolbox item. Used for emitting events.
* @return The name of the toolbox item.
*/
getName: AnyDuringMigration;
getName(): string;
/**
* Gets the contents of the toolbox item. These are items that are meant to be
* displayed in the flyout.
* @return The definition of items to be displayed in the flyout.
*/
getContents: AnyDuringMigration;
getContents(): FlyoutItemInfoArray|string;
/**
* Sets the current toolbox item as selected.
* @param _isSelected True if this category is selected, false otherwise.
*/
setSelected: AnyDuringMigration;
setSelected(_isSelected: boolean): void;
/**
* Gets the HTML element that is clickable.
@@ -53,11 +54,11 @@ export interface ISelectableToolboxItem extends IToolboxItem {
* toolboxItem.
* @return The HTML element that receives clicks.
*/
getClickTarget: AnyDuringMigration;
getClickTarget(): Element;
/**
* Handles when the toolbox item is clicked.
* @param _e Click event to handle.
*/
onClick: AnyDuringMigration;
onClick(_e: Event): void;
}

View File

@@ -43,7 +43,7 @@ export interface ISerializer {
* @return A JS object containing the system's state, or null if there is no
* state to record.
*/
save(workspace: Workspace): AnyDuringMigration;
save(workspace: Workspace): Object|null;
/* eslint-enable valid-jsdoc */
/**
@@ -53,7 +53,7 @@ export interface ISerializer {
* @param workspace The workspace the system to deserialize is associated
* with.
*/
load(state: AnyDuringMigration, workspace: Workspace): void;
load(state: Object, workspace: Workspace): void;
/**
* Clears the state of the plugin or system.

View File

@@ -25,11 +25,11 @@ export interface IStyleable {
* Adds a style on the toolbox. Usually used to change the cursor.
* @param style The name of the class to add.
*/
addStyle: AnyDuringMigration;
addStyle(style: string): void;
/**
* Removes a style from the toolbox. Usually used to change the cursor.
* @param style The name of the class to remove.
*/
removeStyle: AnyDuringMigration;
removeStyle(style: string): void;
}

View File

@@ -29,6 +29,10 @@ goog.declareModuleId('Blockly.IToolbox');
// import '../workspace_svg.js';
import type {IRegistrable} from './i_registrable.js';
import type {IToolboxItem} from './i_toolbox_item.js';
import type {ToolboxInfo} from '../utils/toolbox.js';
import type {IFlyout} from './i_flyout.js';
import type {WorkspaceSvg} from '../workspace_svg.js';
/**
@@ -37,87 +41,87 @@ import type {IRegistrable} from './i_registrable.js';
*/
export interface IToolbox extends IRegistrable {
/** Initializes the toolbox. */
init: AnyDuringMigration;
init(): void;
/**
* Fills the toolbox with new toolbox items and removes any old contents.
* @param toolboxDef Object holding information for creating a toolbox.
*/
render: AnyDuringMigration;
render(toolboxDef: ToolboxInfo): void;
/**
* Gets the width of the toolbox.
* @return The width of the toolbox.
*/
getWidth: AnyDuringMigration;
getWidth(): number;
/**
* Gets the height of the toolbox.
* @return The width of the toolbox.
* @return The height of the toolbox.
*/
getHeight: AnyDuringMigration;
getHeight(): number;
/**
* Gets the toolbox flyout.
* @return The toolbox flyout.
*/
getFlyout: AnyDuringMigration;
getFlyout(): IFlyout|null;
/**
* Gets the workspace for the toolbox.
* @return The parent workspace for the toolbox.
*/
getWorkspace: AnyDuringMigration;
getWorkspace(): WorkspaceSvg;
/**
* Gets whether or not the toolbox is horizontal.
* @return True if the toolbox is horizontal, false if the toolbox is
* vertical.
*/
isHorizontal: AnyDuringMigration;
isHorizontal(): boolean;
/**
* Positions the toolbox based on whether it is a horizontal toolbox and
* whether the workspace is in rtl.
*/
position: AnyDuringMigration;
position(): void;
/** Handles resizing the toolbox when a toolbox item resizes. */
handleToolboxItemResize: AnyDuringMigration;
handleToolboxItemResize(): void;
/** Unhighlights any previously selected item. */
clearSelection: AnyDuringMigration;
clearSelection(): void;
/**
* Updates the category colours and background colour of selected categories.
*/
refreshTheme: AnyDuringMigration;
refreshTheme(): void;
/**
* Updates the flyout's content without closing it. Should be used in
* response to a change in one of the dynamic categories, such as variables or
* procedures.
*/
refreshSelection: AnyDuringMigration;
refreshSelection(): void;
/**
* Sets the visibility of the toolbox.
* @param isVisible True if toolbox should be visible.
*/
setVisible: AnyDuringMigration;
setVisible(isVisible: boolean): void;
/**
* Selects the toolbox item by it's position in the list of toolbox items.
* @param position The position of the item to select.
*/
selectItemByPosition: AnyDuringMigration;
selectItemByPosition(position: number): void;
/**
* Gets the selected item.
* @return The selected item, or null if no item is currently selected.
*/
getSelectedItem: AnyDuringMigration;
getSelectedItem(): IToolboxItem|null;
/** Disposes of this toolbox. */
dispose: AnyDuringMigration;
dispose(): void;
}

View File

@@ -319,7 +319,7 @@ export class Mutator extends Icon {
const tree = this.workspace_!.options.languageTree;
const flyout = this.workspace_!.getFlyout();
if (tree) {
flyout!.init(this.workspace_);
flyout!.init(this.workspace_!);
flyout!.show(tree);
}

View File

@@ -49,18 +49,18 @@ export interface ConnectionState {
*/
export interface State {
type: string;
id: string|undefined;
x: number|undefined;
y: number|undefined;
collapsed: boolean|undefined;
enabled: boolean|undefined;
inline: boolean|undefined;
data: string|undefined;
extraState: AnyDuringMigration|undefined;
icons: {[key: string]: AnyDuringMigration}|undefined;
fields: {[key: string]: AnyDuringMigration}|undefined;
inputs: {[key: string]: ConnectionState}|undefined;
next: ConnectionState|undefined;
id?: string;
x?: number;
y?: number;
collapsed?: boolean;
enabled?: boolean;
inline?: boolean;
data?: string;
extraState?: AnyDuringMigration;
icons?: {[key: string]: AnyDuringMigration};
fields?: {[key: string]: AnyDuringMigration};
inputs?: {[key: string]: ConnectionState};
next?: ConnectionState;
}
/**

View File

@@ -69,7 +69,8 @@ export function registerDelete() {
name: names.DELETE,
preconditionFn(workspace) {
const selected = common.getSelected();
return !workspace.options.readOnly && selected && selected.isDeletable();
return !workspace.options.readOnly && selected != null &&
selected.isDeletable();
},
callback(workspace, e) {
// Delete or backspace.
@@ -105,8 +106,8 @@ export function registerCopy() {
name: names.COPY,
preconditionFn(workspace) {
const selected = common.getSelected();
return !workspace.options.readOnly && !Gesture.inProgress() && selected &&
selected.isDeletable() && selected.isMovable();
return !workspace.options.readOnly && !Gesture.inProgress() &&
selected != null && selected.isDeletable() && selected.isMovable();
},
callback(workspace, e) {
// Prevent the default copy behavior, which may beep or otherwise indicate
@@ -139,10 +140,10 @@ export function registerCut() {
name: names.CUT,
preconditionFn(workspace) {
const selected = common.getSelected();
return !!(
!workspace.options.readOnly && !Gesture.inProgress() && selected &&
selected instanceof BlockSvg && selected.isDeletable() &&
selected.isMovable() && !selected.workspace.isFlyout);
return !workspace.options.readOnly && !Gesture.inProgress() &&
selected != null && selected instanceof BlockSvg &&
selected.isDeletable() && selected.isMovable() &&
!selected.workspace!.isFlyout;
},
callback() {
const selected = common.getSelected();

View File

@@ -42,6 +42,7 @@ import * as dom from './utils/dom.js';
import {Rect} from './utils/rect.js';
import {Size} from './utils/size.js';
import {Svg} from './utils/svg.js';
import {BlockInfo} from './utils/toolbox.js';
import * as toolbox from './utils/toolbox.js';
import type {WorkspaceSvg} from './workspace_svg.js';
@@ -67,9 +68,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
* The trashcan flyout.
* @internal
*/
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'IFlyout'.
flyout: IFlyout = null as AnyDuringMigration;
flyout: IFlyout|null = null;
/** Current open/close state of the lid. */
isLidOpen = false;
@@ -81,17 +80,13 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
private minOpenness_ = 0;
/** The SVG group containing the trash can. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGElement'.
private svgGroup_: SVGElement = null as AnyDuringMigration;
private svgGroup_: SVGElement|null = null;
/** The SVG image element of the trash can lid. */
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGElement'.
private svgLid_: SVGElement = null as AnyDuringMigration;
private svgLid_: SVGElement|null = null;
/** Task ID of opening/closing animation. */
private lidTask_: AnyDuringMigration = 0;
private lidTask_: ReturnType<typeof setTimeout>|null = null;
/** Current state of lid opening (0.0 = closed, 1.0 = open). */
private lidOpen_ = 0;
@@ -222,8 +217,8 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
init() {
if (this.workspace.options.maxTrashcanContents > 0) {
dom.insertAfter(
this.flyout.createDom(Svg.SVG), this.workspace.getParentSvg());
this.flyout.init(this.workspace);
this.flyout?.createDom(Svg.SVG)!, this.workspace.getParentSvg());
this.flyout?.init(this.workspace);
}
this.workspace.getComponentManager().addComponent({
component: this,
@@ -248,17 +243,12 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
this.workspace.getComponentManager().removeComponent('trashcan');
if (this.svgGroup_) {
dom.removeNode(this.svgGroup_);
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGElement'.
this.svgGroup_ = null as AnyDuringMigration;
this.svgGroup_ = null;
}
this.svgLid_ = null;
if (this.lidTask_) {
clearTimeout(this.lidTask_);
}
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'SVGElement'.
this.svgLid_ = null as AnyDuringMigration;
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'WorkspaceSvg'.
this.workspace = null as AnyDuringMigration;
clearTimeout(this.lidTask_);
}
/**
@@ -285,7 +275,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
const contents = this.contents_.map(function(string) {
return JSON.parse(string);
});
this.flyout.show(contents);
this.flyout?.show(contents);
this.fireUiEvent_(true);
}
@@ -294,7 +284,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
if (!this.contentsIsOpen()) {
return;
}
this.flyout.hide();
this.flyout?.hide();
this.fireUiEvent_(false);
this.workspace.recordDragTargets();
}
@@ -355,7 +345,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
this.top_ = positionRect.top;
this.left_ = positionRect.left;
this.svgGroup_.setAttribute(
this.svgGroup_?.setAttribute(
'transform', 'translate(' + this.left_ + ',' + this.top_ + ')');
}
@@ -425,7 +415,9 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
if (this.isLidOpen === state) {
return;
}
clearTimeout(this.lidTask_);
if (this.lidTask_) {
clearTimeout(this.lidTask_);
}
this.isLidOpen = state;
this.animateLid_();
}
@@ -442,9 +434,9 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
// Linear interpolation between min and max.
const opacity = OPACITY_MIN + this.lidOpen_ * (OPACITY_MAX - OPACITY_MIN);
// AnyDuringMigration because: Type 'number' is not assignable to type
// 'string'.
this.svgGroup_.style.opacity = opacity as AnyDuringMigration;
if (this.svgGroup_) {
this.svgGroup_.style.opacity = opacity.toString();
}
if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) {
this.lidTask_ =
@@ -460,7 +452,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
const openAtRight =
this.workspace.toolboxPosition === toolbox.Position.RIGHT ||
this.workspace.horizontalLayout && this.workspace.RTL;
this.svgLid_.setAttribute(
this.svgLid_?.setAttribute(
'transform',
'rotate(' + (openAtRight ? -lidAngle : lidAngle) + ',' +
(openAtRight ? 4 : WIDTH - 4) + ',' + (LID_HEIGHT - 2) + ')');
@@ -547,7 +539,8 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
}
const deleteEvent = event as BlockDelete;
if (event.type === eventUtils.BLOCK_DELETE && !deleteEvent.wasShadow) {
const cleanedJson = this.cleanBlockJson_(deleteEvent.oldJson);
const cleanedJson =
JSON.stringify(this.cleanBlockJson_(deleteEvent.oldJson));
if (this.contents_.indexOf(cleanedJson) !== -1) {
return;
}
@@ -565,9 +558,10 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
* Converts JSON representing a block into text that can be stored in the
* content array.
* @param json A JSON representation of a block's state.
* @return Text representing the JSON, cleaned of all unnecessary attributes.
* @return A BlockInfo object corresponding to the JSON, cleaned of all
* unnecessary attributes.
*/
private cleanBlockJson_(json: blocks.State): string {
private cleanBlockJson_(json: blocks.State): BlockInfo {
// Create a deep copy.
json = JSON.parse(JSON.stringify(json)) as blocks.State;
@@ -595,30 +589,39 @@ export class Trashcan extends DeleteArea implements IAutoHideable,
const inputs = json['inputs'];
for (const name in inputs) {
const input = inputs[name];
// AnyDuringMigration because: Argument of type 'State | undefined' is
// not assignable to parameter of type 'State'.
cleanRec((input as AnyDuringMigration)['block']);
// AnyDuringMigration because: Argument of type 'State | undefined' is
// not assignable to parameter of type 'State'.
cleanRec((input as AnyDuringMigration)['shadow']);
const block = input['block'];
const shadow = input['shadow'];
if (block) {
cleanRec(block);
}
if (shadow) {
cleanRec(shadow);
}
}
if (json['next']) {
const next = json['next'];
// AnyDuringMigration because: Argument of type 'State | undefined' is
// not assignable to parameter of type 'State'.
cleanRec((next as AnyDuringMigration)['block']);
// AnyDuringMigration because: Argument of type 'State | undefined' is
// not assignable to parameter of type 'State'.
cleanRec((next as AnyDuringMigration)['shadow']);
const block = next['block'];
const shadow = next['shadow'];
if (block) {
cleanRec(block);
}
if (shadow) {
cleanRec(shadow);
}
}
}
cleanRec(json);
(json as AnyDuringMigration)['kind'] = 'BLOCK';
return JSON.stringify(json);
const blockInfo: BlockInfo = {
'kind': 'BLOCK',
...json,
};
return blockInfo;
}
}
/** Width of both the trash can and lid images. */
const WIDTH = 47;

View File

@@ -36,22 +36,22 @@ import * as userAgent from './useragent.js';
*/
export interface BlockInfo {
kind: string;
blockxml: string|Node|undefined;
type: string|undefined;
gap: string|number|undefined;
disabled: string|boolean|undefined;
enabled: boolean|undefined;
id: string|undefined;
x: number|undefined;
y: number|undefined;
collapsed: boolean|undefined;
inline: boolean|undefined;
data: string|undefined;
extraState: AnyDuringMigration|undefined;
icons: {[key: string]: AnyDuringMigration}|undefined;
fields: {[key: string]: AnyDuringMigration}|undefined;
inputs: {[key: string]: ConnectionState}|undefined;
next: ConnectionState|undefined;
blockxml?: string|Node;
type?: string;
gap?: string|number;
disabled?: string|boolean;
enabled?: boolean;
id?: string;
x?: number;
y?: number;
collapsed?: boolean;
inline?: boolean;
data?: string;
extraState?: AnyDuringMigration;
icons?: {[key: string]: AnyDuringMigration};
fields?: {[key: string]: AnyDuringMigration};
inputs?: {[key: string]: ConnectionState};
next?: ConnectionState;
}
/**

View File

@@ -895,7 +895,6 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
}
if (this.grid_) {
this.grid_.dispose();
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'Grid'.
this.grid_ = null as AnyDuringMigration;