mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
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:
@@ -52,7 +52,7 @@ export function paste(): ICopyable|null {
|
|||||||
// started in a flyout workspace.
|
// started in a flyout workspace.
|
||||||
let workspace = copyData.source;
|
let workspace = copyData.source;
|
||||||
if (workspace.isFlyout) {
|
if (workspace.isFlyout) {
|
||||||
workspace = workspace.targetWorkspace;
|
workspace = workspace.targetWorkspace!;
|
||||||
}
|
}
|
||||||
if (copyData.typeCounts &&
|
if (copyData.typeCounts &&
|
||||||
workspace.isCapacityAvailable(copyData.typeCounts)) {
|
workspace.isCapacityAvailable(copyData.typeCounts)) {
|
||||||
|
|||||||
@@ -172,27 +172,28 @@ export class ComponentManager {
|
|||||||
* @param sorted Whether to return list ordered by weights.
|
* @param sorted Whether to return list ordered by weights.
|
||||||
* @return The components that match the specified capability.
|
* @return The components that match the specified capability.
|
||||||
*/
|
*/
|
||||||
getComponents<T>(capability: string|Capability<T>, sorted: boolean): T[] {
|
getComponents<T extends IComponent>(
|
||||||
|
capability: string|Capability<T>, sorted: boolean): T[] {
|
||||||
capability = String(capability).toLowerCase();
|
capability = String(capability).toLowerCase();
|
||||||
const componentIds = this.capabilityToComponentIds.get(capability);
|
const componentIds = this.capabilityToComponentIds.get(capability);
|
||||||
if (!componentIds) {
|
if (!componentIds) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const components: AnyDuringMigration[] = [];
|
const components: T[] = [];
|
||||||
if (sorted) {
|
if (sorted) {
|
||||||
const componentDataList: AnyDuringMigration[] = [];
|
const componentDataList: ComponentDatum[] = [];
|
||||||
componentIds.forEach((id) => {
|
componentIds.forEach((id) => {
|
||||||
componentDataList.push(this.componentData.get(id));
|
componentDataList.push(this.componentData.get(id)!);
|
||||||
});
|
});
|
||||||
componentDataList.sort(function(a, b) {
|
componentDataList.sort(function(a, b) {
|
||||||
return a.weight - b.weight;
|
return a.weight - b.weight;
|
||||||
});
|
});
|
||||||
componentDataList.forEach(function(ComponentDatum) {
|
componentDataList.forEach(function(componentDatum) {
|
||||||
components.push(ComponentDatum.component);
|
components.push(componentDatum.component as T);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
componentIds.forEach((id) => {
|
componentIds.forEach((id) => {
|
||||||
components.push(this.componentData.get(id)!.component);
|
components.push(this.componentData.get(id)!.component as T);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return components;
|
return components;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export class ContextMenuRegistry {
|
|||||||
*/
|
*/
|
||||||
getContextMenuOptions(scopeType: ScopeType, scope: Scope):
|
getContextMenuOptions(scopeType: ScopeType, scope: Scope):
|
||||||
ContextMenuOption[] {
|
ContextMenuOption[] {
|
||||||
const menuOptions: AnyDuringMigration[] = [];
|
const menuOptions: ContextMenuOption[] = [];
|
||||||
for (const item of this.registry_.values()) {
|
for (const item of this.registry_.values()) {
|
||||||
if (scopeType === item.scopeType) {
|
if (scopeType === item.scopeType) {
|
||||||
const precondition = item.preconditionFn(scope);
|
const precondition = item.preconditionFn(scope);
|
||||||
@@ -126,15 +126,15 @@ export namespace ContextMenuRegistry {
|
|||||||
* to callback and displayText functions that depend on this information.
|
* to callback and displayText functions that depend on this information.
|
||||||
*/
|
*/
|
||||||
export interface Scope {
|
export interface Scope {
|
||||||
block: BlockSvg|undefined;
|
block?: BlockSvg;
|
||||||
workspace: WorkspaceSvg|undefined;
|
workspace?: WorkspaceSvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A menu item as entered in the registry.
|
* A menu item as entered in the registry.
|
||||||
*/
|
*/
|
||||||
export interface RegistryItem {
|
export interface RegistryItem {
|
||||||
callback: (p1: Scope) => AnyDuringMigration;
|
callback: (p1: Scope) => void;
|
||||||
scopeType: ScopeType;
|
scopeType: ScopeType;
|
||||||
displayText: ((p1: Scope) => string)|string;
|
displayText: ((p1: Scope) => string)|string;
|
||||||
preconditionFn: (p1: Scope) => string;
|
preconditionFn: (p1: Scope) => string;
|
||||||
@@ -148,7 +148,7 @@ export namespace ContextMenuRegistry {
|
|||||||
export interface ContextMenuOption {
|
export interface ContextMenuOption {
|
||||||
text: string;
|
text: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
callback: (p1: Scope) => AnyDuringMigration;
|
callback: (p1: Scope) => void;
|
||||||
scope: Scope;
|
scope: Scope;
|
||||||
weight: number;
|
weight: number;
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ export namespace ContextMenuRegistry {
|
|||||||
export interface LegacyContextMenuOption {
|
export interface LegacyContextMenuOption {
|
||||||
text: string;
|
text: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
callback: (p1: Scope) => AnyDuringMigration;
|
callback: (p1: Scope) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
|
|||||||
* between 0 and 1 specifying the degree of scrolling and a
|
* between 0 and 1 specifying the degree of scrolling and a
|
||||||
* similar x property.
|
* similar x property.
|
||||||
*/
|
*/
|
||||||
protected abstract setMetrics_(xyRatio: {x: number, y: number}): void;
|
protected abstract setMetrics_(xyRatio: {x?: number, y?: number}): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lay out the blocks in the flyout.
|
* Lay out the blocks in the flyout.
|
||||||
@@ -493,7 +493,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
|
|||||||
}
|
}
|
||||||
// Update the scrollbar's visibility too since it should mimic the
|
// Update the scrollbar's visibility too since it should mimic the
|
||||||
// flyout's visibility.
|
// flyout's visibility.
|
||||||
this.workspace_.scrollbar.setContainerVisible(show);
|
this.workspace_.scrollbar?.setContainerVisible(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -682,14 +682,14 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
|
|||||||
// Look up the correct category generation function and call that to get a
|
// Look up the correct category generation function and call that to get a
|
||||||
// valid XML list.
|
// valid XML list.
|
||||||
const fnToApply =
|
const fnToApply =
|
||||||
this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
this.workspace_.targetWorkspace!.getToolboxCategoryCallback(
|
||||||
categoryName);
|
categoryName);
|
||||||
if (typeof fnToApply !== 'function') {
|
if (typeof fnToApply !== 'function') {
|
||||||
throw TypeError(
|
throw TypeError(
|
||||||
'Couldn\'t find a callback function when opening' +
|
'Couldn\'t find a callback function when opening' +
|
||||||
' a toolbox category.');
|
' a toolbox category.');
|
||||||
}
|
}
|
||||||
return fnToApply(this.workspace_.targetWorkspace);
|
return fnToApply(this.workspace_.targetWorkspace!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ export class HorizontalFlyout extends Flyout {
|
|||||||
|
|
||||||
/** Scroll the flyout to the top. */
|
/** Scroll the flyout to the top. */
|
||||||
override scrollToStart() {
|
override scrollToStart() {
|
||||||
this.workspace_.scrollbar.setX(this.RTL ? Infinity : 0);
|
this.workspace_.scrollbar?.setX(this.RTL ? Infinity : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +211,7 @@ export class HorizontalFlyout extends Flyout {
|
|||||||
const viewMetrics = metricsManager.getViewMetrics();
|
const viewMetrics = metricsManager.getViewMetrics();
|
||||||
|
|
||||||
const pos = viewMetrics.left - scrollMetrics.left + delta;
|
const pos = viewMetrics.left - scrollMetrics.left + delta;
|
||||||
this.workspace_.scrollbar.setX(pos);
|
this.workspace_.scrollbar?.setX(pos);
|
||||||
// When the flyout moves from a wheel event, hide WidgetDiv and
|
// When the flyout moves from a wheel event, hide WidgetDiv and
|
||||||
// dropDownDiv.
|
// dropDownDiv.
|
||||||
WidgetDiv.hide();
|
WidgetDiv.hide();
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ export class VerticalFlyout extends Flyout {
|
|||||||
|
|
||||||
/** Scroll the flyout to the top. */
|
/** Scroll the flyout to the top. */
|
||||||
override scrollToStart() {
|
override scrollToStart() {
|
||||||
this.workspace_.scrollbar.setY(0);
|
this.workspace_.scrollbar?.setY(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +201,7 @@ export class VerticalFlyout extends Flyout {
|
|||||||
const viewMetrics = metricsManager.getViewMetrics();
|
const viewMetrics = metricsManager.getViewMetrics();
|
||||||
const pos = viewMetrics.top - scrollMetrics.top + scrollDelta.y;
|
const pos = viewMetrics.top - scrollMetrics.top + scrollDelta.y;
|
||||||
|
|
||||||
this.workspace_.scrollbar.setY(pos);
|
this.workspace_.scrollbar?.setY(pos);
|
||||||
// When the flyout moves from a wheel event, hide WidgetDiv and
|
// When the flyout moves from a wheel event, hide WidgetDiv and
|
||||||
// dropDownDiv.
|
// dropDownDiv.
|
||||||
WidgetDiv.hide();
|
WidgetDiv.hide();
|
||||||
|
|||||||
@@ -247,10 +247,10 @@ function init(mainWorkspace: WorkspaceSvg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.hasTrashcan) {
|
if (options.hasTrashcan) {
|
||||||
mainWorkspace.trashcan.init();
|
mainWorkspace.trashcan!.init();
|
||||||
}
|
}
|
||||||
if (options.zoomOptions && options.zoomOptions.controls) {
|
if (options.zoomOptions && options.zoomOptions.controls) {
|
||||||
mainWorkspace.zoomControls_.init();
|
mainWorkspace.zoomControls_!.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.moveOptions && options.moveOptions.scrollbars) {
|
if (options.moveOptions && options.moveOptions.scrollbars) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class Options {
|
|||||||
* argument Contains an x and/or y property which is a float between 0
|
* argument Contains an x and/or y property which is a float between 0
|
||||||
* and 1 specifying the degree of scrolling.
|
* and 1 specifying the degree of scrolling.
|
||||||
*/
|
*/
|
||||||
setMetrics?: ((p1: {x: number, y: number}) => void) = undefined;
|
setMetrics?: ((p1: {x?: number, y?: number}) => void) = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that returns a metrics
|
* A function that returns a metrics
|
||||||
|
|||||||
@@ -105,8 +105,10 @@ export class Scrollbar {
|
|||||||
|
|
||||||
lengthAttribute_ = 'width';
|
lengthAttribute_ = 'width';
|
||||||
positionAttribute_ = 'x';
|
positionAttribute_ = 'x';
|
||||||
onMouseDownBarWrapper_: AnyDuringMigration;
|
onMouseDownBarWrapper_: browserEvents.Data|null;
|
||||||
onMouseDownHandleWrapper_: AnyDuringMigration;
|
onMouseDownHandleWrapper_: browserEvents.Data|null;
|
||||||
|
onMouseUpWrapper_: browserEvents.Data|null = null;
|
||||||
|
onMouseMoveWrapper_: browserEvents.Data|null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param workspace Workspace to bind the scrollbar to.
|
* @param workspace Workspace to bind the scrollbar to.
|
||||||
@@ -149,35 +151,25 @@ export class Scrollbar {
|
|||||||
// Store the thickness in a temp variable for readability.
|
// Store the thickness in a temp variable for readability.
|
||||||
const scrollbarThickness = Scrollbar.scrollbarThickness;
|
const scrollbarThickness = Scrollbar.scrollbarThickness;
|
||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
this.svgBackground_!.setAttribute(
|
this.svgBackground_!.setAttribute('height', String(scrollbarThickness));
|
||||||
'height', scrollbarThickness.toString());
|
this.outerSvg_!.setAttribute('height', String(scrollbarThickness));
|
||||||
this.outerSvg_!.setAttribute('height', scrollbarThickness.toString());
|
this.svgHandle_!.setAttribute('height', String(scrollbarThickness - 5));
|
||||||
this.svgHandle_!.setAttribute(
|
this.svgHandle_!.setAttribute('y', String(2.5));
|
||||||
'height', (scrollbarThickness - 5).toString());
|
|
||||||
this.svgHandle_!.setAttribute('y', (2.5).toString());
|
|
||||||
} else {
|
} else {
|
||||||
this.svgBackground_!.setAttribute('width', scrollbarThickness.toString());
|
this.svgBackground_!.setAttribute('width', String(scrollbarThickness));
|
||||||
this.outerSvg_!.setAttribute('width', scrollbarThickness.toString());
|
this.outerSvg_!.setAttribute('width', String(scrollbarThickness));
|
||||||
this.svgHandle_!.setAttribute(
|
this.svgHandle_!.setAttribute('width', String(scrollbarThickness - 5));
|
||||||
'width', (scrollbarThickness - 5).toString());
|
this.svgHandle_!.setAttribute('x', String(2.5));
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not
|
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
this.svgHandle_!.setAttribute('x', (2.5).toString());
|
|
||||||
|
|
||||||
this.lengthAttribute_ = 'height';
|
this.lengthAttribute_ = 'height';
|
||||||
this.positionAttribute_ = 'y';
|
this.positionAttribute_ = 'y';
|
||||||
}
|
}
|
||||||
const scrollbar = this;
|
const scrollbar = this;
|
||||||
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
|
|
||||||
// not assignable to parameter of type 'EventTarget'.
|
|
||||||
this.onMouseDownBarWrapper_ = browserEvents.conditionalBind(
|
this.onMouseDownBarWrapper_ = browserEvents.conditionalBind(
|
||||||
this.svgBackground_ as AnyDuringMigration, 'mousedown', scrollbar,
|
this.svgBackground_!, 'mousedown', scrollbar,
|
||||||
scrollbar.onMouseDownBar_);
|
scrollbar.onMouseDownBar_);
|
||||||
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
|
|
||||||
// not assignable to parameter of type 'EventTarget'.
|
|
||||||
this.onMouseDownHandleWrapper_ = browserEvents.conditionalBind(
|
this.onMouseDownHandleWrapper_ = browserEvents.conditionalBind(
|
||||||
this.svgHandle_ as AnyDuringMigration, 'mousedown', scrollbar,
|
this.svgHandle_!, 'mousedown', scrollbar, scrollbar.onMouseDownHandle_);
|
||||||
scrollbar.onMouseDownHandle_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,10 +179,14 @@ export class Scrollbar {
|
|||||||
*/
|
*/
|
||||||
dispose() {
|
dispose() {
|
||||||
this.cleanUp_();
|
this.cleanUp_();
|
||||||
browserEvents.unbind(this.onMouseDownBarWrapper_);
|
if (this.onMouseDownBarWrapper_) {
|
||||||
this.onMouseDownBarWrapper_ = null;
|
browserEvents.unbind(this.onMouseDownBarWrapper_);
|
||||||
browserEvents.unbind(this.onMouseDownHandleWrapper_);
|
this.onMouseDownBarWrapper_ = null;
|
||||||
this.onMouseDownHandleWrapper_ = null;
|
}
|
||||||
|
if (this.onMouseDownHandleWrapper_) {
|
||||||
|
browserEvents.unbind(this.onMouseDownHandleWrapper_);
|
||||||
|
this.onMouseDownHandleWrapper_ = null;
|
||||||
|
}
|
||||||
|
|
||||||
dom.removeNode(this.outerSvg_);
|
dom.removeNode(this.outerSvg_);
|
||||||
this.outerSvg_ = null;
|
this.outerSvg_ = null;
|
||||||
@@ -200,9 +196,6 @@ export class Scrollbar {
|
|||||||
this.workspace.getThemeManager().unsubscribe(this.svgHandle_);
|
this.workspace.getThemeManager().unsubscribe(this.svgHandle_);
|
||||||
this.svgHandle_ = null;
|
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) {
|
private setHandleLength_(newLength: number) {
|
||||||
this.handleLength_ = newLength;
|
this.handleLength_ = newLength;
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
|
||||||
// to parameter of type 'string'.
|
|
||||||
this.svgHandle_!.setAttribute(
|
this.svgHandle_!.setAttribute(
|
||||||
this.lengthAttribute_, this.handleLength_ as AnyDuringMigration);
|
this.lengthAttribute_, String(this.handleLength_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,10 +249,8 @@ export class Scrollbar {
|
|||||||
*/
|
*/
|
||||||
setHandlePosition(newPosition: number) {
|
setHandlePosition(newPosition: number) {
|
||||||
this.handlePosition_ = newPosition;
|
this.handlePosition_ = newPosition;
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
|
||||||
// to parameter of type 'string'.
|
|
||||||
this.svgHandle_!.setAttribute(
|
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) {
|
private setScrollbarLength_(newSize: number) {
|
||||||
this.scrollbarLength_ = newSize;
|
this.scrollbarLength_ = newSize;
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
|
||||||
// to parameter of type 'string'.
|
|
||||||
this.outerSvg_!.setAttribute(
|
this.outerSvg_!.setAttribute(
|
||||||
this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration);
|
this.lengthAttribute_, String(this.scrollbarLength_));
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
|
||||||
// to parameter of type 'string'.
|
|
||||||
this.svgBackground_!.setAttribute(
|
this.svgBackground_!.setAttribute(
|
||||||
this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration);
|
this.lengthAttribute_, String(this.scrollbarLength_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -561,35 +546,19 @@ export class Scrollbar {
|
|||||||
className += ' ' + opt_class;
|
className += ' ' + opt_class;
|
||||||
}
|
}
|
||||||
this.outerSvg_ = dom.createSvgElement(Svg.SVG, {'class': className});
|
this.outerSvg_ = dom.createSvgElement(Svg.SVG, {'class': className});
|
||||||
// AnyDuringMigration because: Argument of type 'SVGSVGElement | null' is
|
this.svgGroup_ = dom.createSvgElement(Svg.G, {}, this.outerSvg_);
|
||||||
// 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.svgBackground_ = dom.createSvgElement(
|
this.svgBackground_ = dom.createSvgElement(
|
||||||
Svg.RECT, {'class': 'blocklyScrollbarBackground'},
|
Svg.RECT, {'class': 'blocklyScrollbarBackground'}, this.svgGroup_);
|
||||||
this.svgGroup_ as AnyDuringMigration);
|
|
||||||
const radius = Math.floor((Scrollbar.scrollbarThickness - 5) / 2);
|
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(
|
this.svgHandle_ = dom.createSvgElement(
|
||||||
Svg.RECT,
|
Svg.RECT,
|
||||||
{'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius},
|
{'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius},
|
||||||
this.svgGroup_ as AnyDuringMigration);
|
this.svgGroup_);
|
||||||
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
|
|
||||||
// not assignable to parameter of type 'Element'.
|
|
||||||
this.workspace.getThemeManager().subscribe(
|
this.workspace.getThemeManager().subscribe(
|
||||||
this.svgHandle_ as AnyDuringMigration, 'scrollbarColour', 'fill');
|
this.svgHandle_!, 'scrollbarColour', 'fill');
|
||||||
// AnyDuringMigration because: Argument of type 'SVGRectElement | null' is
|
|
||||||
// not assignable to parameter of type 'Element'.
|
|
||||||
this.workspace.getThemeManager().subscribe(
|
this.workspace.getThemeManager().subscribe(
|
||||||
this.svgHandle_ as AnyDuringMigration, 'scrollbarOpacity',
|
this.svgHandle_!, 'scrollbarOpacity', 'fill-opacity');
|
||||||
'fill-opacity');
|
dom.insertAfter(this.outerSvg_!, this.workspace.getParentSvg());
|
||||||
// AnyDuringMigration because: Argument of type 'SVGSVGElement | null' is
|
|
||||||
// not assignable to parameter of type 'Element'.
|
|
||||||
dom.insertAfter(
|
|
||||||
this.outerSvg_ as AnyDuringMigration, this.workspace.getParentSvg());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -717,35 +686,21 @@ export class Scrollbar {
|
|||||||
this.workspace.setupDragSurface();
|
this.workspace.setupDragSurface();
|
||||||
|
|
||||||
// Record the current mouse position.
|
// Record the current mouse position.
|
||||||
// AnyDuringMigration because: Property 'clientY' does not exist on type
|
this.startDragMouse_ = this.horizontal ? e.clientX : e.clientY;
|
||||||
// 'Event'. AnyDuringMigration because: Property 'clientX' does not exist
|
this.onMouseUpWrapper_ = browserEvents.conditionalBind(
|
||||||
// on type 'Event'.
|
document, 'mouseup', this, this.onMouseUpHandle_);
|
||||||
this.startDragMouse_ = this.horizontal ? (e as AnyDuringMigration).clientX :
|
this.onMouseMoveWrapper_ = browserEvents.conditionalBind(
|
||||||
(e as AnyDuringMigration).clientY;
|
document, 'mousemove', this, this.onMouseMoveHandle_);
|
||||||
// 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_);
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drag the scrollbar's handle.
|
* Drag the scrollbar's handle.
|
||||||
* @param e Mouse up event.
|
* @param e Mouse move event.
|
||||||
*/
|
*/
|
||||||
private onMouseMoveHandle_(e: Event) {
|
private onMouseMoveHandle_(e: MouseEvent) {
|
||||||
// AnyDuringMigration because: Property 'clientY' does not exist on type
|
const currentMouse = this.horizontal ? e.clientX : e.clientY;
|
||||||
// 'Event'. AnyDuringMigration because: Property 'clientX' does not exist
|
|
||||||
// on type 'Event'.
|
|
||||||
const currentMouse = this.horizontal ? (e as AnyDuringMigration).clientX :
|
|
||||||
(e as AnyDuringMigration).clientY;
|
|
||||||
const mouseDelta = currentMouse - this.startDragMouse_;
|
const mouseDelta = currentMouse - this.startDragMouse_;
|
||||||
const handlePosition = this.startDragHandle + mouseDelta;
|
const handlePosition = this.startDragHandle + mouseDelta;
|
||||||
// Position the bar.
|
// Position the bar.
|
||||||
@@ -767,26 +722,13 @@ export class Scrollbar {
|
|||||||
*/
|
*/
|
||||||
private cleanUp_() {
|
private cleanUp_() {
|
||||||
this.workspace.hideChaff(true);
|
this.workspace.hideChaff(true);
|
||||||
// AnyDuringMigration because: Property 'onMouseUpWrapper_' does not exist
|
if (this.onMouseUpWrapper_) {
|
||||||
// on type 'typeof Scrollbar'.
|
browserEvents.unbind(this.onMouseUpWrapper_);
|
||||||
if ((Scrollbar as AnyDuringMigration).onMouseUpWrapper_) {
|
this.onMouseUpWrapper_ = null;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
// AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not
|
if (this.onMouseMoveWrapper_) {
|
||||||
// exist on type 'typeof Scrollbar'.
|
browserEvents.unbind(this.onMouseMoveWrapper_);
|
||||||
if ((Scrollbar as AnyDuringMigration).onMouseMoveWrapper_) {
|
this.onMouseMoveWrapper_ = null;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,17 +752,11 @@ export class Scrollbar {
|
|||||||
*/
|
*/
|
||||||
private updateMetrics_() {
|
private updateMetrics_() {
|
||||||
const ratio = this.getRatio_();
|
const ratio = this.getRatio_();
|
||||||
const xyRatio = {};
|
|
||||||
if (this.horizontal) {
|
if (this.horizontal) {
|
||||||
// AnyDuringMigration because: Property 'x' does not exist on type '{}'.
|
this.workspace.setMetrics({x: ratio});
|
||||||
(xyRatio as AnyDuringMigration).x = ratio;
|
|
||||||
} else {
|
} else {
|
||||||
// AnyDuringMigration because: Property 'y' does not exist on type '{}'.
|
this.workspace.setMetrics({y: ratio});
|
||||||
(xyRatio as AnyDuringMigration).y = ratio;
|
|
||||||
}
|
}
|
||||||
// AnyDuringMigration because: Argument of type '{}' is not assignable to
|
|
||||||
// parameter of type '{ x: number; y: number; }'.
|
|
||||||
this.workspace.setMetrics(xyRatio as AnyDuringMigration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ let canvasContext: CanvasRenderingContext2D = null as AnyDuringMigration;
|
|||||||
* @alias Blockly.utils.dom.createSvgElement
|
* @alias Blockly.utils.dom.createSvgElement
|
||||||
*/
|
*/
|
||||||
export function createSvgElement<T extends SVGElement>(
|
export function createSvgElement<T extends SVGElement>(
|
||||||
name: string|Svg<T>, attrs: AnyDuringMigration, opt_parent?: Element): T {
|
name: string|Svg<T>, attrs: AnyDuringMigration,
|
||||||
|
opt_parent?: Element|null): T {
|
||||||
const e = document.createElementNS(SVG_NS, String(name)) as T;
|
const e = document.createElementNS(SVG_NS, String(name)) as T;
|
||||||
for (const key in attrs) {
|
for (const key in attrs) {
|
||||||
e.setAttribute(key, attrs[key]);
|
e.setAttribute(key, attrs[key]);
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
|
|||||||
import type {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js';
|
import type {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js';
|
||||||
import * as Xml from './xml.js';
|
import * as Xml from './xml.js';
|
||||||
import {ZoomControls} from './zoom_controls.js';
|
import {ZoomControls} from './zoom_controls.js';
|
||||||
|
import {ContextMenuOption} from './contextmenu_registry.js';
|
||||||
|
|
||||||
|
|
||||||
/** Margin around the top/bottom/left/right after a zoomToFit call. */
|
/** Margin around the top/bottom/left/right after a zoomToFit call. */
|
||||||
@@ -209,9 +210,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
startScrollY = 0;
|
startScrollY = 0;
|
||||||
|
|
||||||
/** Distance from mouse to object being dragged. */
|
/** Distance from mouse to object being dragged. */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private dragDeltaXY_: Coordinate|null = null;
|
||||||
// 'Coordinate'.
|
|
||||||
private dragDeltaXY_: Coordinate = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** Current scale. */
|
/** Current scale. */
|
||||||
scale = 1;
|
scale = 1;
|
||||||
@@ -226,49 +225,33 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
private oldLeft_ = 0;
|
private oldLeft_ = 0;
|
||||||
|
|
||||||
/** The workspace's trashcan (if any). */
|
/** The workspace's trashcan (if any). */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
trashcan: Trashcan|null = null;
|
||||||
// 'Trashcan'.
|
|
||||||
trashcan: Trashcan = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** This workspace's scrollbars, if they exist. */
|
/** This workspace's scrollbars, if they exist. */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
scrollbar: ScrollbarPair|null = null;
|
||||||
// 'ScrollbarPair'.
|
|
||||||
scrollbar: ScrollbarPair = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixed flyout providing blocks which may be dragged into this workspace.
|
* Fixed flyout providing blocks which may be dragged into this workspace.
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private flyout_: IFlyout|null = null;
|
||||||
// 'IFlyout'.
|
|
||||||
private flyout_: IFlyout = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Category-based toolbox providing blocks which may be dragged into this
|
* Category-based toolbox providing blocks which may be dragged into this
|
||||||
* workspace.
|
* workspace.
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private toolbox_: IToolbox|null = null;
|
||||||
// 'IToolbox'.
|
|
||||||
private toolbox_: IToolbox = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current gesture in progress on this workspace, if any.
|
* The current gesture in progress on this workspace, if any.
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
currentGesture_: TouchGesture|null = null;
|
||||||
// 'TouchGesture'.
|
|
||||||
currentGesture_: TouchGesture = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** This workspace's surface for dragging blocks, if it exists. */
|
/** This workspace's surface for dragging blocks, if it exists. */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private readonly blockDragSurface_: BlockDragSurfaceSvg|null = null;
|
||||||
// 'BlockDragSurfaceSvg'.
|
|
||||||
private readonly blockDragSurface_: BlockDragSurfaceSvg =
|
|
||||||
null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** This workspace's drag surface, if it exists. */
|
/** This workspace's drag surface, if it exists. */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private readonly workspaceDragSurface_: WorkspaceDragSurfaceSvg|null = null;
|
||||||
// 'WorkspaceDragSurfaceSvg'.
|
|
||||||
private readonly workspaceDragSurface_: WorkspaceDragSurfaceSvg =
|
|
||||||
null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to move workspace to the drag surface when it is dragged.
|
* Whether to move workspace to the drag surface when it is dragged.
|
||||||
@@ -288,18 +271,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* The first parent div with 'injectionDiv' in the name, or null if not set.
|
* The first parent div with 'injectionDiv' in the name, or null if not set.
|
||||||
* Access this with getInjectionDiv.
|
* Access this with getInjectionDiv.
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private injectionDiv_: Element|null = null;
|
||||||
// 'Element'.
|
|
||||||
private injectionDiv_: Element = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last known position of the page scroll.
|
* Last known position of the page scroll.
|
||||||
* This is used to determine whether we have recalculated screen coordinate
|
* This is used to determine whether we have recalculated screen coordinate
|
||||||
* stuff since the page scrolled.
|
* stuff since the page scrolled.
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private lastRecordedPageScroll_: Coordinate|null = null;
|
||||||
// 'Coordinate'.
|
|
||||||
private lastRecordedPageScroll_: Coordinate = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Developers may define this function to add custom menu options to the
|
* Developers may define this function to add custom menu options to the
|
||||||
@@ -308,16 +287,15 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @param options List of menu options to add to.
|
* @param options List of menu options to add to.
|
||||||
* @param e The right-click event that triggered the context menu.
|
* @param e The right-click event that triggered the context menu.
|
||||||
*/
|
*/
|
||||||
configureContextMenu: AnyDuringMigration;
|
configureContextMenu:
|
||||||
|
((menuOptions: ContextMenuOption[], e: Event) => void)|null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In a flyout, the target workspace where blocks should be placed after a
|
* In a flyout, the target workspace where blocks should be placed after a
|
||||||
* drag. Otherwise null.
|
* drag. Otherwise null.
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
targetWorkspace: WorkspaceSvg|null = null;
|
||||||
// 'WorkspaceSvg'.
|
|
||||||
targetWorkspace: WorkspaceSvg = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** Inverted screen CTM, for use in mouseToSvg. */
|
/** Inverted screen CTM, for use in mouseToSvg. */
|
||||||
private inverseScreenCTM_: SVGMatrix|null = null;
|
private inverseScreenCTM_: SVGMatrix|null = null;
|
||||||
@@ -328,7 +306,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
getMetrics: () => Metrics;
|
getMetrics: () => Metrics;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
setMetrics: (p1: {x: number, y: number}) => void;
|
setMetrics: (p1: {x?: number, y?: number}) => void;
|
||||||
private readonly componentManager_: ComponentManager;
|
private readonly componentManager_: ComponentManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,19 +315,26 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
*/
|
*/
|
||||||
private readonly highlightedBlocks_: BlockSvg[] = [];
|
private readonly highlightedBlocks_: BlockSvg[] = [];
|
||||||
private audioManager_: WorkspaceAudio;
|
private audioManager_: WorkspaceAudio;
|
||||||
private grid_: Grid;
|
private grid_: Grid|null;
|
||||||
private markerManager_: MarkerManager;
|
private markerManager_: MarkerManager;
|
||||||
private toolboxCategoryCallbacks_:
|
|
||||||
{[key: string]: ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null};
|
/**
|
||||||
private flyoutButtonCallbacks_:
|
* Map from function names to callbacks, for deciding what to do when a
|
||||||
{[key: string]: ((p1: FlyoutButton) => AnyDuringMigration)|null};
|
* custom toolbox category is opened.
|
||||||
|
*/
|
||||||
|
private toolboxCategoryCallbacks =
|
||||||
|
new Map<string, (p1: WorkspaceSvg) => toolbox.FlyoutDefinition>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from function names to callbacks, for deciding what to do when a
|
||||||
|
* button is clicked.
|
||||||
|
*/
|
||||||
|
private flyoutButtonCallbacks = new Map<string, (p1: FlyoutButton) => void>();
|
||||||
protected themeManager_: ThemeManager;
|
protected themeManager_: ThemeManager;
|
||||||
private readonly renderer_: Renderer;
|
private readonly renderer_: Renderer;
|
||||||
|
|
||||||
/** Cached parent SVG. */
|
/** Cached parent SVG. */
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
private cachedParentSvg_: SVGElement|null = null;
|
||||||
// 'SVGElement'.
|
|
||||||
private cachedParentSvg_: SVGElement = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** True if keyboard accessibility mode is on, false otherwise. */
|
/** True if keyboard accessibility mode is on, false otherwise. */
|
||||||
keyboardAccessibilityMode = false;
|
keyboardAccessibilityMode = false;
|
||||||
@@ -369,7 +354,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
svgBlockCanvas_!: SVGElement;
|
svgBlockCanvas_!: SVGElement;
|
||||||
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
||||||
svgBubbleCanvas_!: SVGElement;
|
svgBubbleCanvas_!: SVGElement;
|
||||||
zoomControls_: AnyDuringMigration;
|
zoomControls_: ZoomControls|null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param options Dictionary of options.
|
* @param options Dictionary of options.
|
||||||
@@ -416,27 +401,13 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg));
|
new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg));
|
||||||
|
|
||||||
/** This workspace's grid object or null. */
|
/** This workspace's grid object or null. */
|
||||||
// AnyDuringMigration because: Type 'Grid | null' is not assignable to type
|
this.grid_ = this.options.gridPattern ?
|
||||||
// 'Grid'.
|
new Grid(this.options.gridPattern, options.gridOptions) :
|
||||||
this.grid_ = (this.options.gridPattern ?
|
null;
|
||||||
new Grid(this.options.gridPattern, options.gridOptions) :
|
|
||||||
null) as AnyDuringMigration;
|
|
||||||
|
|
||||||
/** Manager in charge of markers and cursors. */
|
/** Manager in charge of markers and cursors. */
|
||||||
this.markerManager_ = new MarkerManager(this);
|
this.markerManager_ = new MarkerManager(this);
|
||||||
|
|
||||||
/**
|
|
||||||
* Map from function names to callbacks, for deciding what to do when a
|
|
||||||
* custom toolbox category is opened.
|
|
||||||
*/
|
|
||||||
this.toolboxCategoryCallbacks_ = Object.create(null);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map from function names to callbacks, for deciding what to do when a
|
|
||||||
* button is clicked.
|
|
||||||
*/
|
|
||||||
this.flyoutButtonCallbacks_ = Object.create(null);
|
|
||||||
|
|
||||||
if (Variables && Variables.flyoutCategory) {
|
if (Variables && Variables.flyoutCategory) {
|
||||||
this.registerToolboxCategoryCallback(
|
this.registerToolboxCategoryCallback(
|
||||||
Variables.CATEGORY_NAME, Variables.flyoutCategory);
|
Variables.CATEGORY_NAME, Variables.flyoutCategory);
|
||||||
@@ -457,9 +428,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
this.themeManager_ = this.options.parentWorkspace ?
|
this.themeManager_ = this.options.parentWorkspace ?
|
||||||
this.options.parentWorkspace.getThemeManager() :
|
this.options.parentWorkspace.getThemeManager() :
|
||||||
new ThemeManager(this, this.options.theme || Classic);
|
new ThemeManager(this, this.options.theme || Classic);
|
||||||
// AnyDuringMigration because: Argument of type 'this' is not assignable to
|
this.themeManager_.subscribeWorkspace(this);
|
||||||
// parameter of type 'Workspace'.
|
|
||||||
this.themeManager_.subscribeWorkspace(this as AnyDuringMigration);
|
|
||||||
|
|
||||||
/** The block renderer used for rendering blocks on this workspace. */
|
/** The block renderer used for rendering blocks on this workspace. */
|
||||||
this.renderer_ = blockRendering.init(
|
this.renderer_ = blockRendering.init(
|
||||||
@@ -599,11 +568,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update all blocks in workspace that have a style name.
|
// Update all blocks in workspace that have a style name.
|
||||||
// AnyDuringMigration because: Argument of type 'BlockSvg[]' is not
|
|
||||||
// assignable to parameter of type 'Block[]'.
|
|
||||||
this.updateBlockStyles_(this.getAllBlocks(false).filter(function(block) {
|
this.updateBlockStyles_(this.getAllBlocks(false).filter(function(block) {
|
||||||
return !!block.getStyleName();
|
return !!block.getStyleName();
|
||||||
}) as AnyDuringMigration);
|
}));
|
||||||
|
|
||||||
// Update current toolbox selection.
|
// Update current toolbox selection.
|
||||||
this.refreshToolboxSelection();
|
this.refreshToolboxSelection();
|
||||||
@@ -745,7 +712,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
element = element.parentNode as Element;
|
element = element.parentNode as Element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.injectionDiv_;
|
return this.injectionDiv_!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -848,91 +815,56 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
}
|
}
|
||||||
if (this.svgGroup_) {
|
if (this.svgGroup_) {
|
||||||
dom.removeNode(this.svgGroup_);
|
dom.removeNode(this.svgGroup_);
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'SVGElement'.
|
|
||||||
this.svgGroup_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'SVGElement'.
|
|
||||||
this.svgBlockCanvas_ = null as AnyDuringMigration;
|
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'SVGElement'.
|
|
||||||
this.svgBubbleCanvas_ = null as AnyDuringMigration;
|
|
||||||
if (this.toolbox_) {
|
if (this.toolbox_) {
|
||||||
this.toolbox_.dispose();
|
this.toolbox_.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.toolbox_ = null;
|
||||||
// 'IToolbox'.
|
|
||||||
this.toolbox_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
if (this.flyout_) {
|
if (this.flyout_) {
|
||||||
this.flyout_.dispose();
|
this.flyout_.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.flyout_ = null;
|
||||||
// 'IFlyout'.
|
|
||||||
this.flyout_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
if (this.trashcan) {
|
if (this.trashcan) {
|
||||||
this.trashcan.dispose();
|
this.trashcan.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.trashcan = null;
|
||||||
// 'Trashcan'.
|
|
||||||
this.trashcan = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
if (this.scrollbar) {
|
if (this.scrollbar) {
|
||||||
this.scrollbar.dispose();
|
this.scrollbar.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.scrollbar = null;
|
||||||
// 'ScrollbarPair'.
|
|
||||||
this.scrollbar = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
if (this.zoomControls_) {
|
if (this.zoomControls_) {
|
||||||
this.zoomControls_.dispose();
|
this.zoomControls_.dispose();
|
||||||
this.zoomControls_ = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.audioManager_) {
|
if (this.audioManager_) {
|
||||||
this.audioManager_.dispose();
|
this.audioManager_.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'WorkspaceAudio'.
|
|
||||||
this.audioManager_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.grid_) {
|
if (this.grid_) {
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.grid_ = null;
|
||||||
// 'Grid'.
|
|
||||||
this.grid_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer_.dispose();
|
this.renderer_.dispose();
|
||||||
|
|
||||||
if (this.markerManager_) {
|
if (this.markerManager_) {
|
||||||
this.markerManager_.dispose();
|
this.markerManager_.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'MarkerManager'.
|
|
||||||
this.markerManager_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
// Dispose of theme manager after all blocks and mutators are disposed of.
|
// Dispose of theme manager after all blocks and mutators are disposed of.
|
||||||
if (this.themeManager_) {
|
if (this.themeManager_) {
|
||||||
// AnyDuringMigration because: Argument of type 'this' is not assignable
|
this.themeManager_.unsubscribeWorkspace(this);
|
||||||
// to parameter of type 'Workspace'.
|
|
||||||
this.themeManager_.unsubscribeWorkspace(this as AnyDuringMigration);
|
|
||||||
this.themeManager_.unsubscribe(this.svgBackground_);
|
this.themeManager_.unsubscribe(this.svgBackground_);
|
||||||
if (!this.options.parentWorkspace) {
|
if (!this.options.parentWorkspace) {
|
||||||
this.themeManager_.dispose();
|
this.themeManager_.dispose();
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
||||||
// 'ThemeManager'.
|
|
||||||
this.themeManager_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connectionDBList.length = 0;
|
this.connectionDBList.length = 0;
|
||||||
|
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type '{
|
this.toolboxCategoryCallbacks.clear();
|
||||||
// [key: string]: ((p1: WorkspaceSvg) => FlyoutDefinition) | null; }'.
|
this.flyoutButtonCallbacks.clear();
|
||||||
this.toolboxCategoryCallbacks_ = null as AnyDuringMigration;
|
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type '{
|
|
||||||
// [key: string]: ((p1: FlyoutButton) => any) | null; }'.
|
|
||||||
this.flyoutButtonCallbacks_ = null as AnyDuringMigration;
|
|
||||||
|
|
||||||
if (!this.options.parentWorkspace) {
|
if (!this.options.parentWorkspace) {
|
||||||
// Top-most workspace. Dispose of the div that the
|
// Top-most workspace. Dispose of the div that the
|
||||||
@@ -1135,17 +1067,13 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
this.cachedParentSvgSize_.width = width;
|
this.cachedParentSvgSize_.width = width;
|
||||||
// This is set to support the public (but deprecated) Blockly.svgSize
|
// This is set to support the public (but deprecated) Blockly.svgSize
|
||||||
// method.
|
// method.
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not
|
svg.setAttribute('data-cached-width', width.toString());
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
svg.setAttribute('data-cached-width', width as AnyDuringMigration);
|
|
||||||
}
|
}
|
||||||
if (height != null) {
|
if (height != null) {
|
||||||
this.cachedParentSvgSize_.height = height;
|
this.cachedParentSvgSize_.height = height;
|
||||||
// This is set to support the public (but deprecated) Blockly.svgSize
|
// This is set to support the public (but deprecated) Blockly.svgSize
|
||||||
// method.
|
// method.
|
||||||
// AnyDuringMigration because: Argument of type 'number' is not
|
svg.setAttribute('data-cached-height', height.toString());
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
svg.setAttribute('data-cached-height', height as AnyDuringMigration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1212,7 +1140,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
*/
|
*/
|
||||||
translate(x: number, y: number) {
|
translate(x: number, y: number) {
|
||||||
if (this.useWorkspaceDragSurface_ && this.isDragSurfaceActive_) {
|
if (this.useWorkspaceDragSurface_ && this.isDragSurfaceActive_) {
|
||||||
this.workspaceDragSurface_.translateSurface(x, y);
|
this.workspaceDragSurface_?.translateSurface(x, y);
|
||||||
} else {
|
} else {
|
||||||
const translation = 'translate(' + x + ',' + y + ') ' +
|
const translation = 'translate(' + x + ',' + y + ') ' +
|
||||||
'scale(' + this.scale + ')';
|
'scale(' + this.scale + ')';
|
||||||
@@ -1245,8 +1173,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
|
|
||||||
this.isDragSurfaceActive_ = false;
|
this.isDragSurfaceActive_ = false;
|
||||||
|
|
||||||
const trans = this.workspaceDragSurface_.getSurfaceTranslation();
|
const trans = this.workspaceDragSurface_!.getSurfaceTranslation();
|
||||||
this.workspaceDragSurface_.clearAndHide(this.svgGroup_);
|
this.workspaceDragSurface_!.clearAndHide(this.svgGroup_);
|
||||||
const translation = 'translate(' + trans.x + ',' + trans.y + ') ' +
|
const translation = 'translate(' + trans.x + ',' + trans.y + ') ' +
|
||||||
'scale(' + this.scale + ')';
|
'scale(' + this.scale + ')';
|
||||||
this.svgBlockCanvas_.setAttribute('transform', translation);
|
this.svgBlockCanvas_.setAttribute('transform', translation);
|
||||||
@@ -1279,19 +1207,15 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
// Figure out where we want to put the canvas back. The order
|
// Figure out where we want to put the canvas back. The order
|
||||||
// in the is important because things are layered.
|
// in the is important because things are layered.
|
||||||
const previousElement = this.svgBlockCanvas_.previousSibling as Element;
|
const previousElement = this.svgBlockCanvas_.previousSibling as Element;
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
const width =
|
||||||
// assignable to parameter of type 'string'.
|
parseInt(this.getParentSvg().getAttribute('width') ?? '0', 10);
|
||||||
const width = parseInt(
|
const height =
|
||||||
this.getParentSvg().getAttribute('width') as AnyDuringMigration, 10);
|
parseInt(this.getParentSvg().getAttribute('height') ?? '0', 10);
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
const height = parseInt(
|
|
||||||
this.getParentSvg().getAttribute('height') as AnyDuringMigration, 10);
|
|
||||||
const coord = svgMath.getRelativeXY(this.getCanvas());
|
const coord = svgMath.getRelativeXY(this.getCanvas());
|
||||||
this.workspaceDragSurface_.setContentsAndShow(
|
this.workspaceDragSurface_!.setContentsAndShow(
|
||||||
this.getCanvas(), this.getBubbleCanvas(), previousElement, width,
|
this.getCanvas(), this.getBubbleCanvas(), previousElement, width,
|
||||||
height, this.scale);
|
height, this.scale);
|
||||||
this.workspaceDragSurface_.translateSurface(coord.x, coord.y);
|
this.workspaceDragSurface_!.translateSurface(coord.x, coord.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1458,24 +1382,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
let blockX = 0;
|
let blockX = 0;
|
||||||
let blockY = 0;
|
let blockY = 0;
|
||||||
if (xmlBlock) {
|
if (xmlBlock) {
|
||||||
// AnyDuringMigration because: Argument of type 'this' is not
|
block = Xml.domToBlock(xmlBlock, this) as BlockSvg;
|
||||||
// assignable to parameter of type 'Workspace'.
|
blockX = parseInt(xmlBlock.getAttribute('x') ?? '0', 10);
|
||||||
block =
|
|
||||||
Xml.domToBlock(xmlBlock, this as AnyDuringMigration) as BlockSvg;
|
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
blockX = parseInt(xmlBlock.getAttribute('x') as AnyDuringMigration, 10);
|
|
||||||
if (this.RTL) {
|
if (this.RTL) {
|
||||||
blockX = -blockX;
|
blockX = -blockX;
|
||||||
}
|
}
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
blockY = parseInt(xmlBlock.getAttribute('y') ?? '0', 10);
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
blockY = parseInt(xmlBlock.getAttribute('y') as AnyDuringMigration, 10);
|
|
||||||
} else if (jsonBlock) {
|
} else if (jsonBlock) {
|
||||||
// AnyDuringMigration because: Argument of type 'this' is not
|
block = blocks.append(jsonBlock, this) as BlockSvg;
|
||||||
// assignable to parameter of type 'Workspace'.
|
|
||||||
block =
|
|
||||||
blocks.append(jsonBlock, this as AnyDuringMigration) as BlockSvg;
|
|
||||||
blockX = jsonBlock['x'] || 10;
|
blockX = jsonBlock['x'] || 10;
|
||||||
if (this.RTL) {
|
if (this.RTL) {
|
||||||
blockX = this.getWidth() - blockX;
|
blockX = this.getWidth() - blockX;
|
||||||
@@ -1545,19 +1459,10 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
eventUtils.disable();
|
eventUtils.disable();
|
||||||
let comment: WorkspaceCommentSvg;
|
let comment: WorkspaceCommentSvg;
|
||||||
try {
|
try {
|
||||||
// AnyDuringMigration because: Property 'get' does not exist on type
|
comment = WorkspaceCommentSvg.fromXmlRendered(xmlComment, this);
|
||||||
// '(name: string) => void'.
|
|
||||||
comment =
|
|
||||||
WorkspaceCommentSvg.fromXml(xmlComment, this) as AnyDuringMigration;
|
|
||||||
// Move the duplicate to original position.
|
// Move the duplicate to original position.
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
let commentX = parseInt(xmlComment.getAttribute('x') ?? '0', 10);
|
||||||
// assignable to parameter of type 'string'.
|
let commentY = parseInt(xmlComment.getAttribute('y') ?? '0', 10);
|
||||||
let commentX =
|
|
||||||
parseInt(xmlComment.getAttribute('x') as AnyDuringMigration, 10);
|
|
||||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
||||||
// assignable to parameter of type 'string'.
|
|
||||||
let commentY =
|
|
||||||
parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10);
|
|
||||||
if (!isNaN(commentX) && !isNaN(commentY)) {
|
if (!isNaN(commentX) && !isNaN(commentY)) {
|
||||||
if (this.RTL) {
|
if (this.RTL) {
|
||||||
commentX = -commentX;
|
commentX = -commentX;
|
||||||
@@ -1573,8 +1478,6 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
eventUtils.enable();
|
eventUtils.enable();
|
||||||
}
|
}
|
||||||
if (eventUtils.isEnabled()) {
|
if (eventUtils.isEnabled()) {
|
||||||
// AnyDuringMigration because: Property 'get' does not exist on type
|
|
||||||
// '(name: string) => void'.
|
|
||||||
WorkspaceComment.fireCreateEvent(comment);
|
WorkspaceComment.fireCreateEvent(comment);
|
||||||
}
|
}
|
||||||
comment.select();
|
comment.select();
|
||||||
@@ -1636,12 +1539,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @deprecated Use workspace.recordDragTargets. (2021 June)
|
* @deprecated Use workspace.recordDragTargets. (2021 June)
|
||||||
*/
|
*/
|
||||||
recordDeleteAreas() {
|
recordDeleteAreas() {
|
||||||
// AnyDuringMigration because: Property 'warn' does not exist on type
|
utils.deprecation.warn(
|
||||||
// 'void'.
|
'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021', 'June 2022',
|
||||||
(utils.deprecation as AnyDuringMigration)
|
'WorkspaceSvg.prototype.recordDragTargets');
|
||||||
.warn(
|
|
||||||
'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021',
|
|
||||||
'June 2022', 'WorkspaceSvg.prototype.recordDragTargets');
|
|
||||||
this.recordDragTargets();
|
this.recordDragTargets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1685,9 +1585,6 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
*/
|
*/
|
||||||
getDragTarget(e: Event): IDragTarget|null {
|
getDragTarget(e: Event): IDragTarget|null {
|
||||||
for (let i = 0, targetArea; targetArea = this.dragTargetAreas_[i]; i++) {
|
for (let i = 0, targetArea; targetArea = this.dragTargetAreas_[i]; i++) {
|
||||||
// AnyDuringMigration because: Property 'clientY' does not exist on
|
|
||||||
// type 'Event'. AnyDuringMigration because: Property 'clientX' does
|
|
||||||
// not exist on type 'Event'.
|
|
||||||
if (targetArea.clientRect.contains(
|
if (targetArea.clientRect.contains(
|
||||||
(e as AnyDuringMigration).clientX,
|
(e as AnyDuringMigration).clientX,
|
||||||
(e as AnyDuringMigration).clientY)) {
|
(e as AnyDuringMigration).clientY)) {
|
||||||
@@ -1734,7 +1631,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
// Fix scale of mouse event.
|
// Fix scale of mouse event.
|
||||||
point.x /= this.scale;
|
point.x /= this.scale;
|
||||||
point.y /= this.scale;
|
point.y /= this.scale;
|
||||||
return Coordinate.sum((this.dragDeltaXY_), point);
|
return Coordinate.sum((this.dragDeltaXY_!), point);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1779,7 +1676,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
const hasScrollbars = !!this.scrollbar;
|
const hasScrollbars = !!this.scrollbar;
|
||||||
return this.isMovable() &&
|
return this.isMovable() &&
|
||||||
(!hasScrollbars ||
|
(!hasScrollbars ||
|
||||||
hasScrollbars && this.scrollbar.canScrollHorizontally());
|
hasScrollbars && this.scrollbar!.canScrollHorizontally());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1790,7 +1687,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
const hasScrollbars = !!this.scrollbar;
|
const hasScrollbars = !!this.scrollbar;
|
||||||
return this.isMovable() &&
|
return this.isMovable() &&
|
||||||
(!hasScrollbars ||
|
(!hasScrollbars ||
|
||||||
hasScrollbars && this.scrollbar.canScrollVertically());
|
hasScrollbars && this.scrollbar!.canScrollVertically());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1867,8 +1764,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
// Start at 1 since the 0th block was used for initialization.
|
// Start at 1 since the 0th block was used for initialization.
|
||||||
for (let i = 1; i < topElements.length; i++) {
|
for (let i = 1; i < topElements.length; i++) {
|
||||||
const topElement = topElements[i];
|
const topElement = topElements[i];
|
||||||
if ((topElement as AnyDuringMigration).isInsertionmarker &&
|
if ((topElement as any).isInsertionMarker &&
|
||||||
(topElement as AnyDuringMigration).isInsertionMarker()) {
|
(topElement as any).isInsertionMarker()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const blockBoundary = topElement.getBoundingRectangle();
|
const blockBoundary = topElement.getBoundingRectangle();
|
||||||
@@ -1918,11 +1815,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
if (this.options.readOnly || this.isFlyout) {
|
if (this.options.readOnly || this.isFlyout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// AnyDuringMigration because: Argument of type '{ workspace: this; }' is
|
|
||||||
// not assignable to parameter of type 'Scope'.
|
|
||||||
const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
|
const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
|
||||||
ContextMenuRegistry.ScopeType.WORKSPACE,
|
ContextMenuRegistry.ScopeType.WORKSPACE, {workspace: this});
|
||||||
{workspace: this} as AnyDuringMigration);
|
|
||||||
|
|
||||||
// Allow the developer to add or modify menuOptions.
|
// Allow the developer to add or modify menuOptions.
|
||||||
if (this.configureContextMenu) {
|
if (this.configureContextMenu) {
|
||||||
@@ -1970,9 +1864,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
if (this.options.parentWorkspace) {
|
if (this.options.parentWorkspace) {
|
||||||
this.options.parentWorkspace.markFocused();
|
this.options.parentWorkspace.markFocused();
|
||||||
} else {
|
} else {
|
||||||
// AnyDuringMigration because: Argument of type 'this' is not assignable
|
common.setMainWorkspace(this);
|
||||||
// to parameter of type 'Workspace'.
|
|
||||||
common.setMainWorkspace(this as AnyDuringMigration);
|
|
||||||
// We call e.preventDefault in many event handlers which means we
|
// We call e.preventDefault in many event handlers which means we
|
||||||
// need to explicitly grab focus (e.g from a textarea) because
|
// need to explicitly grab focus (e.g from a textarea) because
|
||||||
// the browser will not do it for us. How to do this is browser
|
// the browser will not do it for us. How to do this is browser
|
||||||
@@ -1988,13 +1880,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
// In IE, SVGs can't be blurred or focused. Check to make sure the current
|
// In IE, SVGs can't be blurred or focused. Check to make sure the current
|
||||||
// focus can be blurred before doing so.
|
// focus can be blurred before doing so.
|
||||||
// See https://github.com/google/blockly/issues/4440
|
// See https://github.com/google/blockly/issues/4440
|
||||||
// AnyDuringMigration because: Property 'blur' does not exist on type
|
|
||||||
// 'Element'.
|
|
||||||
if (document.activeElement &&
|
if (document.activeElement &&
|
||||||
(document.activeElement as AnyDuringMigration).blur) {
|
document.activeElement instanceof HTMLElement) {
|
||||||
// AnyDuringMigration because: Property 'blur' does not exist on type
|
document.activeElement.blur();
|
||||||
// 'Element'.
|
|
||||||
(document.activeElement as AnyDuringMigration).blur();
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Focus the workspace SVG - this is for Chrome and Firefox.
|
// Focus the workspace SVG - this is for Chrome and Firefox.
|
||||||
@@ -2006,7 +1894,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
try {
|
try {
|
||||||
// In IE11, use setActive (which is IE only) so the page doesn't scroll
|
// In IE11, use setActive (which is IE only) so the page doesn't scroll
|
||||||
// to the workspace gaining focus.
|
// to the workspace gaining focus.
|
||||||
(this.getParentSvg().parentElement as AnyDuringMigration).setActive();
|
(this.getParentSvg().parentElement as any).setActive();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// setActive support was discontinued in Edge so when that fails, call
|
// setActive support was discontinued in Edge so when that fails, call
|
||||||
// focus instead.
|
// focus instead.
|
||||||
@@ -2465,12 +2353,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @param key The name to use to look up this function.
|
* @param key The name to use to look up this function.
|
||||||
* @param func The function to call when the given button is clicked.
|
* @param func The function to call when the given button is clicked.
|
||||||
*/
|
*/
|
||||||
registerButtonCallback(
|
registerButtonCallback(key: string, func: (p1: FlyoutButton) => void) {
|
||||||
key: string, func: (p1: FlyoutButton) => AnyDuringMigration) {
|
|
||||||
if (typeof func !== 'function') {
|
if (typeof func !== 'function') {
|
||||||
throw TypeError('Button callbacks must be functions.');
|
throw TypeError('Button callbacks must be functions.');
|
||||||
}
|
}
|
||||||
this.flyoutButtonCallbacks_[key] = func;
|
this.flyoutButtonCallbacks.set(key, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2480,10 +2367,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @return The function corresponding to the given key for this workspace;
|
* @return The function corresponding to the given key for this workspace;
|
||||||
* null if no callback is registered.
|
* null if no callback is registered.
|
||||||
*/
|
*/
|
||||||
getButtonCallback(key: string):
|
getButtonCallback(key: string): ((p1: FlyoutButton) => void)|null {
|
||||||
((p1: FlyoutButton) => AnyDuringMigration)|null {
|
return this.flyoutButtonCallbacks.get(key) ?? null;
|
||||||
const result = this.flyoutButtonCallbacks_[key];
|
|
||||||
return result ? result : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2491,7 +2376,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @param key The name associated with the callback function.
|
* @param key The name associated with the callback function.
|
||||||
*/
|
*/
|
||||||
removeButtonCallback(key: string) {
|
removeButtonCallback(key: string) {
|
||||||
this.flyoutButtonCallbacks_[key] = null;
|
this.flyoutButtonCallbacks.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2506,7 +2391,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
if (typeof func !== 'function') {
|
if (typeof func !== 'function') {
|
||||||
throw TypeError('Toolbox category callbacks must be functions.');
|
throw TypeError('Toolbox category callbacks must be functions.');
|
||||||
}
|
}
|
||||||
this.toolboxCategoryCallbacks_[key] = func;
|
this.toolboxCategoryCallbacks.set(key, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2518,7 +2403,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
*/
|
*/
|
||||||
getToolboxCategoryCallback(key: string):
|
getToolboxCategoryCallback(key: string):
|
||||||
((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null {
|
((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null {
|
||||||
return this.toolboxCategoryCallbacks_[key] || null;
|
return this.toolboxCategoryCallbacks.get(key) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2526,7 +2411,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @param key The name associated with the callback function.
|
* @param key The name associated with the callback function.
|
||||||
*/
|
*/
|
||||||
removeToolboxCategoryCallback(key: string) {
|
removeToolboxCategoryCallback(key: string) {
|
||||||
this.toolboxCategoryCallbacks_[key] = null;
|
this.toolboxCategoryCallbacks.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2568,9 +2453,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
clearGesture() {
|
clearGesture() {
|
||||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
this.currentGesture_ = null;
|
||||||
// 'TouchGesture'.
|
|
||||||
this.currentGesture_ = null as AnyDuringMigration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2622,7 +2505,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|||||||
* and 1 specifying the degree of scrolling.
|
* and 1 specifying the degree of scrolling.
|
||||||
*/
|
*/
|
||||||
private static setTopLevelWorkspaceMetrics_(
|
private static setTopLevelWorkspaceMetrics_(
|
||||||
this: WorkspaceSvg, xyRatio: AnyDuringMigration) {
|
this: WorkspaceSvg, xyRatio: {x?: number, y?: number}) {
|
||||||
const metrics = this.getMetrics();
|
const metrics = this.getMetrics();
|
||||||
|
|
||||||
if (typeof xyRatio.x === 'number') {
|
if (typeof xyRatio.x === 'number') {
|
||||||
|
|||||||
Reference in New Issue
Block a user