mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
refactor: Remove more uses of AnyDuringMigration (#6439)
* refactor: Remove uses of AnyDuringMigration from workspace_comment.ts * refactor: Remove uses of AnyDuringMigration from separator.ts. * refactor: Remove uses of AnyDuringMigration from category.ts. * refactor: Remove uses of AnyDuringMigration from rendered_connection.ts. * refactor: Removed uses of AnyDuringMigration from flyout_metrics_manager.ts. * refactor: Remove uses of AnyDuringMigration from dom.ts.
This commit is contained in:
@@ -72,7 +72,6 @@ export class FlyoutMetricsManager extends MetricsManager {
|
||||
override getScrollMetrics(
|
||||
opt_getWorkspaceCoordinates?: boolean, opt_viewMetrics?: ContainerRegion,
|
||||
opt_contentMetrics?: ContainerRegion) {
|
||||
// AnyDuringMigration because: Expected 1 arguments, but got 0.
|
||||
const contentMetrics = opt_contentMetrics || this.getContentMetrics();
|
||||
const margin = this.flyout_.MARGIN * this.workspace_.scale;
|
||||
const scale = opt_getWorkspaceCoordinates ? this.workspace_.scale : 1;
|
||||
|
||||
@@ -15,7 +15,7 @@ goog.declareModuleId('Blockly.Grid');
|
||||
|
||||
import * as dom from './utils/dom.js';
|
||||
import {Svg} from './utils/svg.js';
|
||||
import {GridOptions} from './blockly_options.js';
|
||||
import {GridOptions} from './options.js';
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -391,7 +391,7 @@ export class RenderedConnection extends Connection {
|
||||
// rendering takes place, since rendering requires knowing the dimensions
|
||||
// of lower blocks. Also, since rendering a block renders all its parents,
|
||||
// we only need to render the leaf nodes.
|
||||
let renderList: AnyDuringMigration[] = [];
|
||||
let renderList: Block[] = [];
|
||||
if (this.type !== ConnectionType.INPUT_VALUE &&
|
||||
this.type !== ConnectionType.NEXT_STATEMENT) {
|
||||
// Only spider down.
|
||||
|
||||
@@ -217,9 +217,9 @@ export class Debug {
|
||||
return;
|
||||
}
|
||||
|
||||
let colour;
|
||||
let size;
|
||||
let fill;
|
||||
let colour = '';
|
||||
let size = 0;
|
||||
let fill = '';
|
||||
if (conn.type === ConnectionType.INPUT_VALUE) {
|
||||
size = 4;
|
||||
colour = 'magenta';
|
||||
|
||||
@@ -567,7 +567,7 @@ export class MarkerSvg {
|
||||
*
|
||||
* @returns The object holding attributes to make the marker blink.
|
||||
*/
|
||||
protected getBlinkProperties_(): object {
|
||||
protected getBlinkProperties_(): {[key: string]: string} {
|
||||
return {
|
||||
'attributeType': 'XML',
|
||||
'attributeName': 'fill',
|
||||
|
||||
@@ -287,7 +287,9 @@ export class Scrollbar {
|
||||
const tempX = this.position.x + this.origin_.x;
|
||||
const tempY = this.position.y + this.origin_.y;
|
||||
const transform = 'translate(' + tempX + 'px,' + tempY + 'px)';
|
||||
dom.setCssTransform(this.outerSvg_ as Element, transform);
|
||||
if (this.outerSvg_) {
|
||||
dom.setCssTransform(this.outerSvg_, transform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ import type {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_
|
||||
import type {ISelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.js';
|
||||
import type {IToolbox} from '../interfaces/i_toolbox.js';
|
||||
import type {IToolboxItem} from '../interfaces/i_toolbox_item.js';
|
||||
import type {CategoryInfo, DynamicCategoryInfo, FlyoutDefinition, FlyoutItemInfo, FlyoutItemInfoArray, StaticCategoryInfo} from '../utils/toolbox.js';
|
||||
import * as registry from '../registry.js';
|
||||
import * as aria from '../utils/aria.js';
|
||||
import * as colourUtils from '../utils/colour.js';
|
||||
@@ -50,7 +51,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
static defaultBackgroundColour = '#57e';
|
||||
|
||||
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
||||
override toolboxItemDef_!: toolbox.CategoryInfo;
|
||||
override toolboxItemDef_!: CategoryInfo;
|
||||
|
||||
/** The name that will be displayed on the category. */
|
||||
protected name_ = '';
|
||||
@@ -81,7 +82,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
protected isDisabled_ = false;
|
||||
|
||||
/** The flyout items for this category. */
|
||||
protected flyoutItems_: string|toolbox.FlyoutItemInfoArray = [];
|
||||
protected flyoutItems_: string|FlyoutItemInfoArray = [];
|
||||
|
||||
/**
|
||||
* @param categoryDef The information needed to create a category in the
|
||||
@@ -91,7 +92,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
* a parent.
|
||||
*/
|
||||
constructor(
|
||||
categoryDef: toolbox.CategoryInfo, parentToolbox: IToolbox,
|
||||
categoryDef: CategoryInfo, parentToolbox: IToolbox,
|
||||
opt_parent?: ICollapsibleToolboxItem) {
|
||||
super(categoryDef, parentToolbox, opt_parent);
|
||||
|
||||
@@ -122,10 +123,6 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
* category.
|
||||
*/
|
||||
protected makeDefaultCssConfig_(): CssConfig {
|
||||
// AnyDuringMigration because: Type '{ container: string; row: string;
|
||||
// rowcontentcontainer: string; icon: string; label: string; contents:
|
||||
// string; selected: string; openicon: string; closedicon: string; }' is not
|
||||
// assignable to type 'CssConfig'.
|
||||
return {
|
||||
'container': 'blocklyToolboxCategory',
|
||||
'row': 'blocklyTreeRow',
|
||||
@@ -136,7 +133,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
'selected': 'blocklyTreeSelected',
|
||||
'openicon': 'blocklyTreeIconOpen',
|
||||
'closedicon': 'blocklyTreeIconClosed',
|
||||
} as AnyDuringMigration;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,18 +142,19 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*
|
||||
* @param categoryDef The information needed to create a category.
|
||||
*/
|
||||
protected parseContents_(categoryDef: toolbox.CategoryInfo) {
|
||||
const contents = (categoryDef as AnyDuringMigration)['contents'];
|
||||
protected parseContents_(categoryDef: CategoryInfo) {
|
||||
if ('custom' in categoryDef) {
|
||||
this.flyoutItems_ = categoryDef['custom'];
|
||||
} else {
|
||||
const contents = categoryDef['contents'];
|
||||
if (!contents) return;
|
||||
|
||||
if ((categoryDef as AnyDuringMigration)['custom']) {
|
||||
this.flyoutItems_ = (categoryDef as AnyDuringMigration)['custom'];
|
||||
} else if (contents) {
|
||||
for (let i = 0; i < contents.length; i++) {
|
||||
const itemDef = contents[i];
|
||||
const flyoutItem = itemDef as toolbox.FlyoutItemInfo;
|
||||
// AnyDuringMigration because: Property 'push' does not exist on type
|
||||
// 'string | FlyoutItemInfoArray'.
|
||||
(this.flyoutItems_ as AnyDuringMigration).push(flyoutItem);
|
||||
const flyoutItem = itemDef as FlyoutItemInfo;
|
||||
if (Array.isArray(this.flyoutItems_)) {
|
||||
this.flyoutItems_.push(flyoutItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,14 +164,14 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*
|
||||
* @param categoryDef The information needed to create a category.
|
||||
*/
|
||||
protected parseCategoryDef_(categoryDef: toolbox.CategoryInfo) {
|
||||
this.name_ = parsing.replaceMessageReferences(
|
||||
(categoryDef as AnyDuringMigration)['name']);
|
||||
protected parseCategoryDef_(categoryDef: CategoryInfo) {
|
||||
this.name_ = 'name' in categoryDef ?
|
||||
parsing.replaceMessageReferences(categoryDef['name']) :
|
||||
'';
|
||||
this.colour_ = this.getColour_(categoryDef);
|
||||
Object.assign(
|
||||
this.cssConfig_,
|
||||
categoryDef['cssconfig'] ||
|
||||
(categoryDef as AnyDuringMigration)['cssConfig']);
|
||||
categoryDef['cssconfig'] || (categoryDef as any)['cssConfig']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,8 +182,8 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
protected createDom_(): HTMLDivElement {
|
||||
this.htmlDiv_ = this.createContainer_();
|
||||
aria.setRole(this.htmlDiv_, aria.Role.TREEITEM);
|
||||
aria.setState((this.htmlDiv_), aria.State.SELECTED, false);
|
||||
aria.setState((this.htmlDiv_), aria.State.LEVEL, this.level_);
|
||||
aria.setState(this.htmlDiv_, aria.State.SELECTED, false);
|
||||
aria.setState(this.htmlDiv_, aria.State.LEVEL, this.level_);
|
||||
|
||||
this.rowDiv_ = this.createRowContainer_();
|
||||
this.rowDiv_.style.pointerEvents = 'auto';
|
||||
@@ -201,11 +199,11 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
|
||||
this.labelDom_ = this.createLabelDom_(this.name_);
|
||||
this.rowContents_.appendChild(this.labelDom_);
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string | number | boolean | string[]'.
|
||||
aria.setState(
|
||||
this.htmlDiv_ as Element, aria.State.LABELLEDBY,
|
||||
this.labelDom_.getAttribute('id') as AnyDuringMigration);
|
||||
|
||||
const id = this.labelDom_.getAttribute('id');
|
||||
if (id) {
|
||||
aria.setState(this.htmlDiv_, aria.State.LABELLEDBY, id);
|
||||
}
|
||||
|
||||
this.addColourBorder_(this.colour_);
|
||||
|
||||
@@ -219,7 +217,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*/
|
||||
protected createContainer_(): HTMLDivElement {
|
||||
const container = document.createElement('div');
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['container'];
|
||||
const className = this.cssConfig_['container'];
|
||||
if (className) {
|
||||
container.classList.add(className);
|
||||
}
|
||||
@@ -233,21 +231,15 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
* @returns The div that holds the contents container.
|
||||
*/
|
||||
protected createRowContainer_(): HTMLDivElement {
|
||||
const rowDiv = (document.createElement('div'));
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['row'];
|
||||
const rowDiv = document.createElement('div');
|
||||
const className = this.cssConfig_['row'];
|
||||
if (className) {
|
||||
rowDiv.classList.add(className);
|
||||
}
|
||||
let nestedPadding = ToolboxCategory.nestedPadding * this.getLevel();
|
||||
// AnyDuringMigration because: Type 'string' is not assignable to type
|
||||
// 'number'.
|
||||
nestedPadding = (nestedPadding.toString() + 'px') as AnyDuringMigration;
|
||||
// AnyDuringMigration because: Type 'number' is not assignable to type
|
||||
// 'string'. AnyDuringMigration because: Type 'number' is not assignable to
|
||||
// type 'string'.
|
||||
this.workspace_.RTL ?
|
||||
rowDiv.style.paddingRight = nestedPadding as AnyDuringMigration :
|
||||
rowDiv.style.paddingLeft = nestedPadding as AnyDuringMigration;
|
||||
const nestedPadding =
|
||||
`${ToolboxCategory.nestedPadding * this.getLevel()}px`;
|
||||
this.workspace_.RTL ? rowDiv.style.paddingRight = nestedPadding :
|
||||
rowDiv.style.paddingLeft = nestedPadding;
|
||||
return rowDiv;
|
||||
}
|
||||
|
||||
@@ -259,8 +251,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*/
|
||||
protected createRowContentsContainer_(): HTMLDivElement {
|
||||
const contentsContainer = document.createElement('div');
|
||||
const className =
|
||||
(this.cssConfig_ as AnyDuringMigration)['rowcontentcontainer'];
|
||||
const className = this.cssConfig_['rowcontentcontainer'];
|
||||
if (className) {
|
||||
contentsContainer.classList.add(className);
|
||||
}
|
||||
@@ -275,7 +266,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
protected createIconDom_(): Element {
|
||||
const toolboxIcon = document.createElement('span');
|
||||
if (!this.parentToolbox_.isHorizontal()) {
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['icon'];
|
||||
const className = this.cssConfig_['icon'];
|
||||
if (className) {
|
||||
toolboxIcon.classList.add(className);
|
||||
}
|
||||
@@ -296,7 +287,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
const toolboxLabel = document.createElement('span');
|
||||
toolboxLabel.setAttribute('id', this.getId() + '.label');
|
||||
toolboxLabel.textContent = name;
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['label'];
|
||||
const className = this.cssConfig_['label'];
|
||||
if (className) {
|
||||
toolboxLabel.classList.add(className);
|
||||
}
|
||||
@@ -305,7 +296,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
|
||||
/** Updates the colour for this category. */
|
||||
refreshTheme() {
|
||||
this.colour_ = this.getColour_((this.toolboxItemDef_));
|
||||
this.colour_ = this.getColour_(this.toolboxItemDef_);
|
||||
this.addColourBorder_(this.colour_);
|
||||
}
|
||||
|
||||
@@ -332,7 +323,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
* @param categoryDef The object holding information on the category.
|
||||
* @returns The hex colour for the category.
|
||||
*/
|
||||
protected getColour_(categoryDef: toolbox.CategoryInfo): string {
|
||||
protected getColour_(categoryDef: CategoryInfo): string {
|
||||
const styleName =
|
||||
categoryDef['categorystyle'] || (categoryDef as any)['categoryStyle'];
|
||||
const colour = categoryDef['colour'];
|
||||
@@ -343,10 +334,8 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
'" must not have both a style and a colour');
|
||||
} else if (styleName) {
|
||||
return this.getColourfromStyle_(styleName);
|
||||
} else {
|
||||
// AnyDuringMigration because: Argument of type 'string | undefined' is
|
||||
// not assignable to parameter of type 'string | number'.
|
||||
return this.parseColour_(colour as AnyDuringMigration);
|
||||
} else if (colour) {
|
||||
return this.parseColour_(colour);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -425,11 +414,11 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
if (!iconDiv) {
|
||||
return;
|
||||
}
|
||||
// AnyDuringMigration because: Argument of type 'string | undefined' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
dom.removeClasses(
|
||||
iconDiv, (this.cssConfig_ as AnyDuringMigration)['closedicon']);
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['openicon'];
|
||||
const closedIconClass = this.cssConfig_['closedicon'];
|
||||
if (closedIconClass) {
|
||||
dom.removeClasses(iconDiv, closedIconClass);
|
||||
}
|
||||
const className = this.cssConfig_['openicon'];
|
||||
if (className) {
|
||||
iconDiv.classList.add(className);
|
||||
}
|
||||
@@ -444,11 +433,11 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
if (!iconDiv) {
|
||||
return;
|
||||
}
|
||||
// AnyDuringMigration because: Argument of type 'string | undefined' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
dom.removeClasses(
|
||||
iconDiv, (this.cssConfig_ as AnyDuringMigration)['openicon']);
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['closedicon'];
|
||||
const openIconClass = this.cssConfig_['openicon'];
|
||||
if (openIconClass) {
|
||||
dom.removeClasses(iconDiv, openIconClass);
|
||||
}
|
||||
const className = this.cssConfig_['closedicon'];
|
||||
if (className) {
|
||||
iconDiv.classList.add(className);
|
||||
}
|
||||
@@ -532,7 +521,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
if (!this.rowDiv_) {
|
||||
return;
|
||||
}
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['selected'];
|
||||
const className = this.cssConfig_['selected'];
|
||||
if (isSelected) {
|
||||
const defaultColour =
|
||||
this.parseColour_(ToolboxCategory.defaultBackgroundColour);
|
||||
@@ -556,9 +545,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*/
|
||||
setDisabled(isDisabled: boolean) {
|
||||
this.isDisabled_ = isDisabled;
|
||||
// AnyDuringMigration because: Argument of type 'boolean' is not assignable
|
||||
// to parameter of type 'string'.
|
||||
this.getDiv()!.setAttribute('disabled', isDisabled as AnyDuringMigration);
|
||||
this.getDiv()!.setAttribute('disabled', `${isDisabled}`);
|
||||
isDisabled ? this.getDiv()!.setAttribute('disabled', 'true') :
|
||||
this.getDiv()!.removeAttribute('disabled');
|
||||
}
|
||||
@@ -586,7 +573,7 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
*
|
||||
* @returns The definition of items to be displayed in the flyout.
|
||||
*/
|
||||
getContents(): toolbox.FlyoutItemInfoArray|string {
|
||||
getContents(): FlyoutItemInfoArray|string {
|
||||
return this.flyoutItems_;
|
||||
}
|
||||
|
||||
@@ -598,18 +585,35 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
* @param contents The contents to be displayed in the flyout. A string can be
|
||||
* supplied to create a dynamic category.
|
||||
*/
|
||||
updateFlyoutContents(contents: toolbox.FlyoutDefinition|string) {
|
||||
updateFlyoutContents(contents: FlyoutDefinition|string) {
|
||||
this.flyoutItems_ = [];
|
||||
|
||||
if (typeof contents === 'string') {
|
||||
(this.toolboxItemDef_ as AnyDuringMigration)['custom'] = contents;
|
||||
const newDefinition: DynamicCategoryInfo = {
|
||||
kind: this.toolboxItemDef_.kind,
|
||||
custom: contents,
|
||||
id: this.toolboxItemDef_.id,
|
||||
categorystyle: this.toolboxItemDef_.categorystyle,
|
||||
colour: this.toolboxItemDef_.colour,
|
||||
cssconfig: this.toolboxItemDef_.cssconfig,
|
||||
hidden: this.toolboxItemDef_.hidden,
|
||||
};
|
||||
this.toolboxItemDef_ = newDefinition;
|
||||
} else {
|
||||
// Removes old custom field when contents is updated.
|
||||
delete (this.toolboxItemDef_ as AnyDuringMigration)['custom'];
|
||||
(this.toolboxItemDef_ as AnyDuringMigration)['contents'] =
|
||||
toolbox.convertFlyoutDefToJsonArray(contents);
|
||||
const newDefinition: StaticCategoryInfo = {
|
||||
kind: this.toolboxItemDef_.kind,
|
||||
name: 'name' in this.toolboxItemDef_ ? this.toolboxItemDef_['name'] :
|
||||
'',
|
||||
contents: toolbox.convertFlyoutDefToJsonArray(contents),
|
||||
id: this.toolboxItemDef_.id,
|
||||
categorystyle: this.toolboxItemDef_.categorystyle,
|
||||
colour: this.toolboxItemDef_.colour,
|
||||
cssconfig: this.toolboxItemDef_.cssconfig,
|
||||
hidden: this.toolboxItemDef_.hidden,
|
||||
};
|
||||
this.toolboxItemDef_ = newDefinition;
|
||||
}
|
||||
this.parseContents_((this.toolboxItemDef_));
|
||||
this.parseContents_(this.toolboxItemDef_);
|
||||
}
|
||||
|
||||
override dispose() {
|
||||
@@ -620,14 +624,15 @@ export class ToolboxCategory extends ToolboxItem implements
|
||||
export namespace ToolboxCategory {
|
||||
/** All the CSS class names that are used to create a category. */
|
||||
export interface CssConfig {
|
||||
container: string|undefined;
|
||||
row: string|undefined;
|
||||
rowcontentcontainer: string|undefined;
|
||||
icon: string|undefined;
|
||||
label: string|undefined;
|
||||
selected: string|undefined;
|
||||
openicon: string|undefined;
|
||||
closedicon: string|undefined;
|
||||
container?: string;
|
||||
row?: string;
|
||||
rowcontentcontainer?: string;
|
||||
icon?: string;
|
||||
label?: string;
|
||||
contents?: string;
|
||||
selected?: string;
|
||||
openicon?: string;
|
||||
closedicon?: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ export class ToolboxSeparator extends ToolboxItem {
|
||||
*/
|
||||
protected createDom_(): HTMLDivElement {
|
||||
const container = document.createElement('div');
|
||||
const className = (this.cssConfig_ as AnyDuringMigration)['container'];
|
||||
const className = this.cssConfig_['container'];
|
||||
if (className) {
|
||||
container.classList.add(className);
|
||||
}
|
||||
|
||||
@@ -52,15 +52,13 @@ export enum NodeType {
|
||||
}
|
||||
|
||||
/** Temporary cache of text widths. */
|
||||
let cacheWidths: AnyDuringMigration = null;
|
||||
let cacheWidths: {[key: string]: number}|null = null;
|
||||
|
||||
/** Number of current references to cache. */
|
||||
let cacheReference = 0;
|
||||
|
||||
/** A HTML canvas context used for computing text width. */
|
||||
// AnyDuringMigration because: Type 'null' is not assignable to type
|
||||
// 'CanvasRenderingContext2D'.
|
||||
let canvasContext: CanvasRenderingContext2D = null as AnyDuringMigration;
|
||||
let canvasContext: CanvasRenderingContext2D|null = null;
|
||||
|
||||
/**
|
||||
* Helper method for creating SVG elements.
|
||||
@@ -72,11 +70,11 @@ let canvasContext: CanvasRenderingContext2D = null as AnyDuringMigration;
|
||||
* @alias Blockly.utils.dom.createSvgElement
|
||||
*/
|
||||
export function createSvgElement<T extends SVGElement>(
|
||||
name: string|Svg<T>, attrs: AnyDuringMigration,
|
||||
name: string|Svg<T>, attrs: {[key: string]: string|number},
|
||||
opt_parent?: Element|null): T {
|
||||
const e = document.createElementNS(SVG_NS, String(name)) as T;
|
||||
for (const key in attrs) {
|
||||
e.setAttribute(key, attrs[key]);
|
||||
e.setAttribute(key, `${attrs[key]}`);
|
||||
}
|
||||
if (opt_parent) {
|
||||
opt_parent.appendChild(e);
|
||||
@@ -218,13 +216,10 @@ export function containsNode(parent: Node, descendant: Node): boolean {
|
||||
* @param transform The value of the CSS `transform` property.
|
||||
* @alias Blockly.utils.dom.setCssTransform
|
||||
*/
|
||||
export function setCssTransform(element: Element, transform: string) {
|
||||
// AnyDuringMigration because: Property 'style' does not exist on type
|
||||
// 'Element'.
|
||||
(element as AnyDuringMigration).style['transform'] = transform;
|
||||
// AnyDuringMigration because: Property 'style' does not exist on type
|
||||
// 'Element'.
|
||||
(element as AnyDuringMigration).style['-webkit-transform'] = transform;
|
||||
export function setCssTransform(
|
||||
element: HTMLElement|SVGElement, transform: string) {
|
||||
element.style['transform'] = transform;
|
||||
element.style['-webkit-transform' as any] = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +297,7 @@ export function getTextWidth(textElement: SVGTextElement): number {
|
||||
* @alias Blockly.utils.dom.getFastTextWidth
|
||||
*/
|
||||
export function getFastTextWidth(
|
||||
textElement: Element, fontSize: number, fontWeight: string,
|
||||
textElement: SVGTextElement, fontSize: number, fontWeight: string,
|
||||
fontFamily: string): number {
|
||||
return getFastTextWidthWithSizeString(
|
||||
textElement, fontSize + 'pt', fontWeight, fontFamily);
|
||||
@@ -323,13 +318,10 @@ export function getFastTextWidth(
|
||||
* @alias Blockly.utils.dom.getFastTextWidthWithSizeString
|
||||
*/
|
||||
export function getFastTextWidthWithSizeString(
|
||||
textElement: Element, fontSize: string, fontWeight: string,
|
||||
textElement: SVGTextElement, fontSize: string, fontWeight: string,
|
||||
fontFamily: string): number {
|
||||
const text = textElement.textContent;
|
||||
// AnyDuringMigration because: Property 'baseVal' does not exist on type
|
||||
// 'string'.
|
||||
const key =
|
||||
text + '\n' + (textElement.className as AnyDuringMigration).baseVal;
|
||||
const key = text + '\n' + textElement.className.baseVal;
|
||||
let width;
|
||||
|
||||
// Return the cached width if it exists.
|
||||
@@ -355,9 +347,11 @@ export function getFastTextWidthWithSizeString(
|
||||
canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily;
|
||||
|
||||
// Measure the text width using the helper canvas context.
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
width = canvasContext.measureText(text as AnyDuringMigration).width;
|
||||
if (text) {
|
||||
width = canvasContext.measureText(text).width;
|
||||
} else {
|
||||
width = 0;
|
||||
}
|
||||
|
||||
// Cache the computed width and return.
|
||||
if (cacheWidths) {
|
||||
@@ -385,9 +379,7 @@ export function measureFontMetrics(
|
||||
|
||||
const block = (document.createElement('div'));
|
||||
block.style.width = '1px';
|
||||
// AnyDuringMigration because: Type 'number' is not assignable to type
|
||||
// 'string'.
|
||||
block.style.height = 0 as AnyDuringMigration;
|
||||
block.style.height = '0';
|
||||
|
||||
const div = (document.createElement('div'));
|
||||
div.setAttribute('style', 'position: fixed; top: 0; left: 0; display: flex;');
|
||||
|
||||
@@ -267,18 +267,10 @@ export class WorkspaceComment {
|
||||
*/
|
||||
toXmlWithXY(opt_noId?: boolean): Element {
|
||||
const element = this.toXml(opt_noId);
|
||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
||||
// to parameter of type 'string'.
|
||||
element.setAttribute('x', Math.round(this.xy_.x) as AnyDuringMigration);
|
||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
||||
// to parameter of type 'string'.
|
||||
element.setAttribute('y', Math.round(this.xy_.y) as AnyDuringMigration);
|
||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
||||
// to parameter of type 'string'.
|
||||
element.setAttribute('h', this.height_ as AnyDuringMigration);
|
||||
// AnyDuringMigration because: Argument of type 'number' is not assignable
|
||||
// to parameter of type 'string'.
|
||||
element.setAttribute('w', this.width_ as AnyDuringMigration);
|
||||
element.setAttribute('x', `${Math.round(this.xy_.x)}`);
|
||||
element.setAttribute('y', `${Math.round(this.xy_.y)}`);
|
||||
element.setAttribute('h', `${this.height_}`);
|
||||
element.setAttribute('w', `${this.width_}`);
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -338,14 +330,10 @@ export class WorkspaceComment {
|
||||
const comment =
|
||||
new WorkspaceComment(workspace, info.content, info.h, info.w, info.id);
|
||||
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
const commentX =
|
||||
parseInt(xmlComment.getAttribute('x') as AnyDuringMigration, 10);
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
const commentY =
|
||||
parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10);
|
||||
const xmlX = xmlComment.getAttribute('x');
|
||||
const xmlY = xmlComment.getAttribute('y');
|
||||
const commentX = xmlX ? parseInt(xmlX, 10) : NaN;
|
||||
const commentY = xmlY ? parseInt(xmlY, 10) : NaN;
|
||||
if (!isNaN(commentX) && !isNaN(commentY)) {
|
||||
comment.moveBy(commentX, commentY);
|
||||
}
|
||||
@@ -371,39 +359,27 @@ export class WorkspaceComment {
|
||||
} {
|
||||
const xmlH = xml.getAttribute('h');
|
||||
const xmlW = xml.getAttribute('w');
|
||||
const xmlX = xml.getAttribute('x');
|
||||
const xmlY = xml.getAttribute('y');
|
||||
const xmlId = xml.getAttribute('id');
|
||||
|
||||
if (!xmlId) {
|
||||
throw new Error('No ID present in XML comment definition.');
|
||||
}
|
||||
|
||||
return {
|
||||
// @type {string}
|
||||
// AnyDuringMigration because: Type 'string | null' is not assignable to
|
||||
// type 'string'.
|
||||
id: xml.getAttribute('id') as
|
||||
AnyDuringMigration, // The height of the comment in workspace units,
|
||||
// or 100 if not specified.
|
||||
// @type {number}
|
||||
h: xmlH ? parseInt(xmlH, 10) :
|
||||
100, // The width of the comment in workspace units, or 100 if
|
||||
// not specified.
|
||||
// @type {number}
|
||||
w: xmlW ? parseInt(xmlW, 10) :
|
||||
100, // The x position of the comment in workspace coordinates,
|
||||
// or NaN if not
|
||||
id: xmlId,
|
||||
// The height of the comment in workspace units, or 100 if not specified.
|
||||
h: xmlH ? parseInt(xmlH, 10) : 100,
|
||||
// The width of the comment in workspace units, or 100 if not specified.
|
||||
w: xmlW ? parseInt(xmlW, 10) : 100,
|
||||
// The x position of the comment in workspace coordinates, or NaN if not
|
||||
// specified in the XML.
|
||||
// @type {number}
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
x: parseInt(
|
||||
xml.getAttribute('x') as AnyDuringMigration,
|
||||
10), // The y position of the comment in workspace coordinates, or
|
||||
// NaN if not
|
||||
x: xmlX ? parseInt(xmlX, 10) : NaN,
|
||||
// The y position of the comment in workspace coordinates, or NaN if not
|
||||
// specified in the XML.
|
||||
// @type {number}
|
||||
// AnyDuringMigration because: Argument of type 'string | null' is not
|
||||
// assignable to parameter of type 'string'.
|
||||
y: parseInt(
|
||||
xml.getAttribute('y') as AnyDuringMigration, 10), // @type {string}
|
||||
// AnyDuringMigration because: Type 'string | null' is not assignable to
|
||||
// type 'string'.
|
||||
content: xml.textContent as AnyDuringMigration,
|
||||
y: xmlY ? parseInt(xmlY, 10) : NaN,
|
||||
content: xml.textContent ?? '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user