refactor: Remove uses of AnyDuringMigration from scrollbar.ts, workspace_svg.ts, contextmenu_registry.ts, and component_manager.ts (#6318)

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

* refactor: Remove almost all uses of AnyDuringMigration from workspace_svg.ts.

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

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

* refactor: Use String() rather than toString().

* fix: Fix lint and build errors.
This commit is contained in:
Aaron Dodson
2022-08-22 11:04:11 -07:00
committed by GitHub
parent eca2b1bc4a
commit 9454b7070c
11 changed files with 162 additions and 341 deletions

View File

@@ -105,8 +105,10 @@ export class Scrollbar {
lengthAttribute_ = 'width';
positionAttribute_ = 'x';
onMouseDownBarWrapper_: AnyDuringMigration;
onMouseDownHandleWrapper_: AnyDuringMigration;
onMouseDownBarWrapper_: browserEvents.Data|null;
onMouseDownHandleWrapper_: browserEvents.Data|null;
onMouseUpWrapper_: browserEvents.Data|null = null;
onMouseMoveWrapper_: browserEvents.Data|null = null;
/**
* @param workspace Workspace to bind the scrollbar to.
@@ -149,35 +151,25 @@ export class Scrollbar {
// Store the thickness in a temp variable for readability.
const scrollbarThickness = Scrollbar.scrollbarThickness;
if (horizontal) {
this.svgBackground_!.setAttribute(
'height', scrollbarThickness.toString());
this.outerSvg_!.setAttribute('height', scrollbarThickness.toString());
this.svgHandle_!.setAttribute(
'height', (scrollbarThickness - 5).toString());
this.svgHandle_!.setAttribute('y', (2.5).toString());
this.svgBackground_!.setAttribute('height', String(scrollbarThickness));
this.outerSvg_!.setAttribute('height', String(scrollbarThickness));
this.svgHandle_!.setAttribute('height', String(scrollbarThickness - 5));
this.svgHandle_!.setAttribute('y', String(2.5));
} else {
this.svgBackground_!.setAttribute('width', scrollbarThickness.toString());
this.outerSvg_!.setAttribute('width', scrollbarThickness.toString());
this.svgHandle_!.setAttribute(
'width', (scrollbarThickness - 5).toString());
// AnyDuringMigration because: Argument of type 'number' is not
// assignable to parameter of type 'string'.
this.svgHandle_!.setAttribute('x', (2.5).toString());
this.svgBackground_!.setAttribute('width', String(scrollbarThickness));
this.outerSvg_!.setAttribute('width', String(scrollbarThickness));
this.svgHandle_!.setAttribute('width', String(scrollbarThickness - 5));
this.svgHandle_!.setAttribute('x', String(2.5));
this.lengthAttribute_ = 'height';
this.positionAttribute_ = 'y';
}
const scrollbar = this;
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
// not assignable to parameter of type 'EventTarget'.
this.onMouseDownBarWrapper_ = browserEvents.conditionalBind(
this.svgBackground_ as AnyDuringMigration, 'mousedown', scrollbar,
this.svgBackground_!, 'mousedown', scrollbar,
scrollbar.onMouseDownBar_);
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
// not assignable to parameter of type 'EventTarget'.
this.onMouseDownHandleWrapper_ = browserEvents.conditionalBind(
this.svgHandle_ as AnyDuringMigration, 'mousedown', scrollbar,
scrollbar.onMouseDownHandle_);
this.svgHandle_!, 'mousedown', scrollbar, scrollbar.onMouseDownHandle_);
}
/**
@@ -187,10 +179,14 @@ export class Scrollbar {
*/
dispose() {
this.cleanUp_();
browserEvents.unbind(this.onMouseDownBarWrapper_);
this.onMouseDownBarWrapper_ = null;
browserEvents.unbind(this.onMouseDownHandleWrapper_);
this.onMouseDownHandleWrapper_ = null;
if (this.onMouseDownBarWrapper_) {
browserEvents.unbind(this.onMouseDownBarWrapper_);
this.onMouseDownBarWrapper_ = null;
}
if (this.onMouseDownHandleWrapper_) {
browserEvents.unbind(this.onMouseDownHandleWrapper_);
this.onMouseDownHandleWrapper_ = null;
}
dom.removeNode(this.outerSvg_);
this.outerSvg_ = null;
@@ -200,9 +196,6 @@ export class Scrollbar {
this.workspace.getThemeManager().unsubscribe(this.svgHandle_);
this.svgHandle_ = null;
}
// AnyDuringMigration because: Type 'null' is not assignable to type
// 'WorkspaceSvg'.
this.workspace = null as AnyDuringMigration;
}
/**
@@ -227,10 +220,8 @@ export class Scrollbar {
*/
private setHandleLength_(newLength: number) {
this.handleLength_ = newLength;
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.svgHandle_!.setAttribute(
this.lengthAttribute_, this.handleLength_ as AnyDuringMigration);
this.lengthAttribute_, String(this.handleLength_));
}
/**
@@ -258,10 +249,8 @@ export class Scrollbar {
*/
setHandlePosition(newPosition: number) {
this.handlePosition_ = newPosition;
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.svgHandle_!.setAttribute(
this.positionAttribute_, this.handlePosition_ as AnyDuringMigration);
this.positionAttribute_, String(this.handlePosition_));
}
/**
@@ -271,14 +260,10 @@ export class Scrollbar {
*/
private setScrollbarLength_(newSize: number) {
this.scrollbarLength_ = newSize;
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.outerSvg_!.setAttribute(
this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'number' is not assignable
// to parameter of type 'string'.
this.lengthAttribute_, String(this.scrollbarLength_));
this.svgBackground_!.setAttribute(
this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration);
this.lengthAttribute_, String(this.scrollbarLength_));
}
/**
@@ -561,35 +546,19 @@ export class Scrollbar {
className += ' ' + opt_class;
}
this.outerSvg_ = dom.createSvgElement(Svg.SVG, {'class': className});
// AnyDuringMigration because: Argument of type 'SVGSVGElement | null' is
// not assignable to parameter of type 'Element | undefined'.
this.svgGroup_ =
dom.createSvgElement(Svg.G, {}, this.outerSvg_ as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'SVGGElement | null' is not
// assignable to parameter of type 'Element | undefined'.
this.svgGroup_ = dom.createSvgElement(Svg.G, {}, this.outerSvg_);
this.svgBackground_ = dom.createSvgElement(
Svg.RECT, {'class': 'blocklyScrollbarBackground'},
this.svgGroup_ as AnyDuringMigration);
Svg.RECT, {'class': 'blocklyScrollbarBackground'}, this.svgGroup_);
const radius = Math.floor((Scrollbar.scrollbarThickness - 5) / 2);
// AnyDuringMigration because: Argument of type 'SVGGElement | null' is not
// assignable to parameter of type 'Element | undefined'.
this.svgHandle_ = dom.createSvgElement(
Svg.RECT,
{'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius},
this.svgGroup_ as AnyDuringMigration);
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
// not assignable to parameter of type 'Element'.
this.svgGroup_);
this.workspace.getThemeManager().subscribe(
this.svgHandle_ as AnyDuringMigration, 'scrollbarColour', 'fill');
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
// not assignable to parameter of type 'Element'.
this.svgHandle_!, 'scrollbarColour', 'fill');
this.workspace.getThemeManager().subscribe(
this.svgHandle_ as AnyDuringMigration, 'scrollbarOpacity',
'fill-opacity');
// AnyDuringMigration because: Argument of type 'SVGSVGElement | null' is
// not assignable to parameter of type 'Element'.
dom.insertAfter(
this.outerSvg_ as AnyDuringMigration, this.workspace.getParentSvg());
this.svgHandle_!, 'scrollbarOpacity', 'fill-opacity');
dom.insertAfter(this.outerSvg_!, this.workspace.getParentSvg());
}
/**
@@ -717,35 +686,21 @@ export class Scrollbar {
this.workspace.setupDragSurface();
// Record the current mouse position.
// AnyDuringMigration because: Property 'clientY' does not exist on type
// 'Event'. AnyDuringMigration because: Property 'clientX' does not exist
// on type 'Event'.
this.startDragMouse_ = this.horizontal ? (e as AnyDuringMigration).clientX :
(e as AnyDuringMigration).clientY;
// AnyDuringMigration because: Property 'onMouseUpWrapper_' does not exist
// on type 'typeof Scrollbar'.
(Scrollbar as AnyDuringMigration).onMouseUpWrapper_ =
browserEvents.conditionalBind(
document, 'mouseup', this, this.onMouseUpHandle_);
// AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not
// exist on type 'typeof Scrollbar'.
(Scrollbar as AnyDuringMigration).onMouseMoveWrapper_ =
browserEvents.conditionalBind(
document, 'mousemove', this, this.onMouseMoveHandle_);
this.startDragMouse_ = this.horizontal ? e.clientX : e.clientY;
this.onMouseUpWrapper_ = browserEvents.conditionalBind(
document, 'mouseup', this, this.onMouseUpHandle_);
this.onMouseMoveWrapper_ = browserEvents.conditionalBind(
document, 'mousemove', this, this.onMouseMoveHandle_);
e.stopPropagation();
e.preventDefault();
}
/**
* Drag the scrollbar's handle.
* @param e Mouse up event.
* @param e Mouse move event.
*/
private onMouseMoveHandle_(e: Event) {
// AnyDuringMigration because: Property 'clientY' does not exist on type
// 'Event'. AnyDuringMigration because: Property 'clientX' does not exist
// on type 'Event'.
const currentMouse = this.horizontal ? (e as AnyDuringMigration).clientX :
(e as AnyDuringMigration).clientY;
private onMouseMoveHandle_(e: MouseEvent) {
const currentMouse = this.horizontal ? e.clientX : e.clientY;
const mouseDelta = currentMouse - this.startDragMouse_;
const handlePosition = this.startDragHandle + mouseDelta;
// Position the bar.
@@ -767,26 +722,13 @@ export class Scrollbar {
*/
private cleanUp_() {
this.workspace.hideChaff(true);
// AnyDuringMigration because: Property 'onMouseUpWrapper_' does not exist
// on type 'typeof Scrollbar'.
if ((Scrollbar as AnyDuringMigration).onMouseUpWrapper_) {
// AnyDuringMigration because: Property 'onMouseUpWrapper_' does not
// exist on type 'typeof Scrollbar'.
browserEvents.unbind((Scrollbar as AnyDuringMigration).onMouseUpWrapper_);
// AnyDuringMigration because: Property 'onMouseUpWrapper_' does not
// exist on type 'typeof Scrollbar'.
(Scrollbar as AnyDuringMigration).onMouseUpWrapper_ = null;
if (this.onMouseUpWrapper_) {
browserEvents.unbind(this.onMouseUpWrapper_);
this.onMouseUpWrapper_ = null;
}
// AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not
// exist on type 'typeof Scrollbar'.
if ((Scrollbar as AnyDuringMigration).onMouseMoveWrapper_) {
// AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not
// exist on type 'typeof Scrollbar'.
browserEvents.unbind(
(Scrollbar as AnyDuringMigration).onMouseMoveWrapper_);
// AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not
// exist on type 'typeof Scrollbar'.
(Scrollbar as AnyDuringMigration).onMouseMoveWrapper_ = null;
if (this.onMouseMoveWrapper_) {
browserEvents.unbind(this.onMouseMoveWrapper_);
this.onMouseMoveWrapper_ = null;
}
}
@@ -810,17 +752,11 @@ export class Scrollbar {
*/
private updateMetrics_() {
const ratio = this.getRatio_();
const xyRatio = {};
if (this.horizontal) {
// AnyDuringMigration because: Property 'x' does not exist on type '{}'.
(xyRatio as AnyDuringMigration).x = ratio;
this.workspace.setMetrics({x: ratio});
} else {
// AnyDuringMigration because: Property 'y' does not exist on type '{}'.
(xyRatio as AnyDuringMigration).y = ratio;
this.workspace.setMetrics({y: ratio});
}
// AnyDuringMigration because: Argument of type '{}' is not assignable to
// parameter of type '{ x: number; y: number; }'.
this.workspace.setMetrics(xyRatio as AnyDuringMigration);
}
/**