From 3ea312a4b6db1890329e533472592119a97db01f Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 17 Jun 2022 19:53:57 +0000 Subject: [PATCH] chore: format --- core/block.ts | 280 ++++----- core/block_animations.ts | 48 +- core/block_drag_surface.ts | 38 +- core/block_dragger.ts | 63 +- core/block_svg.ts | 206 +++---- core/blockly.ts | 562 +++++++++--------- core/blocks.ts | 2 +- core/browser_events.ts | 24 +- core/bubble.ts | 218 +++---- core/bubble_dragger.ts | 38 +- core/bump_objects.ts | 52 +- core/clipboard.ts | 10 +- core/comment.ts | 122 ++-- core/common.ts | 38 +- core/component_manager.ts | 60 +- core/connection.ts | 91 +-- core/connection_checker.ts | 58 +- core/connection_db.ts | 24 +- core/contextmenu.ts | 74 +-- core/contextmenu_items.ts | 48 +- core/contextmenu_registry.ts | 24 +- core/css.ts | 6 +- core/delete_area.ts | 8 +- core/dialog.ts | 36 +- core/drag_target.ts | 8 +- core/dropdowndiv.ts | 116 ++-- core/events/events.ts | 106 ++-- core/events/events_abstract.ts | 10 +- core/events/events_block_base.ts | 4 +- core/events/events_block_change.ts | 14 +- core/events/events_block_create.ts | 6 +- core/events/events_block_delete.ts | 8 +- core/events/events_block_drag.ts | 4 +- core/events/events_block_move.ts | 28 +- core/events/events_bubble_open.ts | 8 +- core/events/events_click.ts | 8 +- core/events/events_comment_base.ts | 12 +- core/events/events_comment_change.ts | 18 +- core/events/events_comment_create.ts | 6 +- core/events/events_comment_delete.ts | 6 +- core/events/events_comment_move.ts | 14 +- core/events/events_marker_move.ts | 16 +- core/events/events_selected.ts | 10 +- core/events/events_theme_change.ts | 2 +- core/events/events_toolbox_item_select.ts | 12 +- core/events/events_trashcan_open.ts | 2 +- core/events/events_ui.ts | 8 +- core/events/events_ui_base.ts | 2 +- core/events/events_var_base.ts | 4 +- core/events/events_var_create.ts | 4 +- core/events/events_var_delete.ts | 4 +- core/events/events_var_rename.ts | 4 +- core/events/events_viewport.ts | 8 +- core/events/utils.ts | 50 +- core/events/workspace_events.ts | 6 +- core/extensions.ts | 88 +-- core/field.ts | 164 ++--- core/field_angle.ts | 101 ++-- core/field_checkbox.ts | 12 +- core/field_colour.ts | 66 +- core/field_dropdown.ts | 163 ++--- core/field_image.ts | 52 +- core/field_label.ts | 14 +- core/field_label_serializable.ts | 6 +- core/field_multilineinput.ts | 64 +- core/field_number.ts | 36 +- core/field_registry.ts | 20 +- core/field_textinput.ts | 78 +-- core/field_variable.ts | 96 +-- core/flyout_base.ts | 163 ++--- core/flyout_button.ts | 102 ++-- core/flyout_horizontal.ts | 60 +- core/flyout_metrics_manager.ts | 18 +- core/flyout_vertical.ts | 60 +- core/generator.ts | 70 +-- core/gesture.ts | 98 +-- core/grid.ts | 20 +- core/icon.ts | 28 +- core/inject.ts | 150 ++--- core/input.ts | 30 +- core/input_types.ts | 2 +- core/insertion_marker_manager.ts | 106 ++-- core/interfaces/i_ast_node_location_svg.ts | 2 +- .../i_ast_node_location_with_block.ts | 2 +- core/interfaces/i_autohideable.ts | 2 +- core/interfaces/i_bubble.ts | 4 +- core/interfaces/i_collapsible_toolbox_item.ts | 2 +- core/interfaces/i_copyable.ts | 8 +- core/interfaces/i_delete_area.ts | 2 +- core/interfaces/i_drag_target.ts | 2 +- core/interfaces/i_draggable.ts | 2 +- core/interfaces/i_flyout.ts | 6 +- core/interfaces/i_positionable.ts | 2 +- core/interfaces/i_registrable_field.ts | 2 +- core/interfaces/i_selectable.ts | 4 +- core/interfaces/i_selectable_toolbox_item.ts | 2 +- core/interfaces/i_serializer.ts | 2 +- core/interfaces/i_toolbox.ts | 2 +- core/interfaces/i_toolbox_item.ts | 6 +- core/internal_constants.ts | 6 +- core/keyboard_nav/ast_node.ts | 80 +-- core/keyboard_nav/basic_cursor.ts | 34 +- core/keyboard_nav/cursor.ts | 24 +- core/keyboard_nav/marker.ts | 6 +- core/keyboard_nav/tab_navigate_cursor.ts | 10 +- core/marker_manager.ts | 32 +- core/menu.ts | 54 +- core/menuitem.ts | 28 +- core/metrics_manager.ts | 67 ++- core/msg.ts | 2 +- core/mutator.ts | 114 ++-- core/names.ts | 36 +- core/options.ts | 70 +-- core/positionable_helpers.ts | 36 +- core/procedures.ts | 60 +- core/registry.ts | 111 ++-- core/rendered_connection.ts | 85 +-- core/renderers/common/block_rendering.ts | 143 +++-- core/renderers/common/constants.ts | 260 ++++---- core/renderers/common/debug.ts | 12 +- core/renderers/common/debugger.ts | 251 ++++---- core/renderers/common/drawer.ts | 81 ++- core/renderers/common/i_path_object.ts | 4 +- core/renderers/common/info.ts | 127 ++-- core/renderers/common/marker_svg.ts | 164 ++--- core/renderers/common/path_object.ts | 22 +- core/renderers/common/renderer.ts | 59 +- core/renderers/geras/constants.ts | 22 +- core/renderers/geras/drawer.ts | 31 +- core/renderers/geras/geras.ts | 18 +- core/renderers/geras/highlight_constants.ts | 89 ++- core/renderers/geras/highlighter.ts | 109 ++-- core/renderers/geras/info.ts | 81 ++- .../geras/measurables/inline_input.ts | 9 +- .../geras/measurables/statement_input.ts | 9 +- core/renderers/geras/path_object.ts | 23 +- core/renderers/geras/renderer.ts | 25 +- core/renderers/measurables/base.ts | 4 +- core/renderers/measurables/bottom_row.ts | 15 +- core/renderers/measurables/connection.ts | 11 +- .../measurables/external_value_input.ts | 13 +- core/renderers/measurables/field.ts | 15 +- core/renderers/measurables/hat.ts | 6 +- core/renderers/measurables/icon.ts | 9 +- core/renderers/measurables/in_row_spacer.ts | 6 +- core/renderers/measurables/inline_input.ts | 25 +- .../renderers/measurables/input_connection.ts | 23 +- core/renderers/measurables/input_row.ts | 18 +- core/renderers/measurables/jagged_edge.ts | 6 +- core/renderers/measurables/next_connection.ts | 11 +- .../measurables/output_connection.ts | 11 +- .../measurables/previous_connection.ts | 11 +- core/renderers/measurables/round_corner.ts | 12 +- core/renderers/measurables/row.ts | 12 +- core/renderers/measurables/spacer_row.ts | 12 +- core/renderers/measurables/square_corner.ts | 12 +- core/renderers/measurables/statement_input.ts | 13 +- core/renderers/measurables/top_row.ts | 22 +- core/renderers/measurables/types.ts | 11 +- core/renderers/minimalist/constants.ts | 2 +- core/renderers/minimalist/drawer.ts | 7 +- core/renderers/minimalist/info.ts | 7 +- core/renderers/minimalist/minimalist.ts | 10 +- core/renderers/minimalist/renderer.ts | 15 +- core/renderers/thrasos/info.ts | 43 +- core/renderers/thrasos/renderer.ts | 7 +- core/renderers/thrasos/thrasos.ts | 6 +- core/renderers/zelos/constants.ts | 265 ++++----- core/renderers/zelos/drawer.ts | 89 ++- core/renderers/zelos/info.ts | 169 +++--- core/renderers/zelos/marker_svg.ts | 39 +- .../renderers/zelos/measurables/bottom_row.ts | 8 +- core/renderers/zelos/measurables/inputs.ts | 6 +- .../zelos/measurables/row_elements.ts | 6 +- core/renderers/zelos/measurables/top_row.ts | 13 +- core/renderers/zelos/path_object.ts | 45 +- core/renderers/zelos/renderer.ts | 51 +- core/renderers/zelos/zelos.ts | 20 +- core/scrollbar.ts | 128 ++-- core/scrollbar_pair.ts | 46 +- core/serialization/blocks.ts | 124 ++-- core/serialization/exceptions.ts | 8 +- core/serialization/registry.ts | 2 +- core/serialization/variables.ts | 12 +- core/serialization/workspaces.ts | 21 +- core/shortcut_items.ts | 20 +- core/shortcut_registry.ts | 45 +- core/theme.ts | 54 +- core/theme/classic.ts | 40 +- core/theme/themes.ts | 6 +- core/theme/zelos.ts | 20 +- core/theme_manager.ts | 14 +- core/toolbox/category.ts | 104 ++-- core/toolbox/collapsible_category.ts | 64 +- core/toolbox/separator.ts | 16 +- core/toolbox/toolbox.ts | 144 ++--- core/toolbox/toolbox_item.ts | 26 +- core/tooltip.ts | 32 +- core/touch.ts | 97 ++- core/touch_gesture.ts | 34 +- core/trashcan.ts | 138 ++--- core/utils.ts | 199 ++++--- core/utils/aria.ts | 2 +- core/utils/array.ts | 2 +- core/utils/colour.ts | 8 +- core/utils/coordinate.ts | 8 +- core/utils/deprecation.ts | 2 +- core/utils/dom.ts | 26 +- core/utils/idgenerator.ts | 4 +- core/utils/math.ts | 2 +- core/utils/object.ts | 6 +- core/utils/parsing.ts | 36 +- core/utils/rect.ts | 10 +- core/utils/size.ts | 2 +- core/utils/string.ts | 22 +- core/utils/style.ts | 24 +- core/utils/svg.ts | 46 +- core/utils/svg_math.ts | 33 +- core/utils/svg_paths.ts | 2 +- core/utils/toolbox.ts | 118 ++-- core/utils/useragent.ts | 76 +-- core/variable_map.ts | 52 +- core/variable_model.ts | 8 +- core/variables.ts | 104 ++-- core/variables_dynamic.ts | 30 +- core/warning.ts | 54 +- core/widgetdiv.ts | 22 +- core/workspace.ts | 82 +-- core/workspace_audio.ts | 10 +- core/workspace_comment.ts | 44 +- core/workspace_comment_svg.ts | 288 ++++----- core/workspace_drag_surface_svg.ts | 22 +- core/workspace_dragger.ts | 4 +- core/workspace_svg.ts | 352 +++++------ core/xml.ts | 145 ++--- core/zoom_controls.ts | 156 ++--- 236 files changed, 5599 insertions(+), 5634 deletions(-) diff --git a/core/block.ts b/core/block.ts index 9b0987773..2823f752b 100644 --- a/core/block.ts +++ b/core/block.ts @@ -19,41 +19,41 @@ import './events/events_block_create'; // Unused import preserved for side-effects. Remove if unneeded. import './events/events_block_delete'; -import { Blocks } from './blocks.js'; +import {Blocks} from './blocks.js'; /* eslint-disable-next-line no-unused-vars */ -import { Comment } from './comment.js'; +import {Comment} from './comment.js'; import * as common from './common.js'; -import { Connection } from './connection.js'; -import { ConnectionType } from './connection_type.js'; +import {Connection} from './connection.js'; +import {ConnectionType} from './connection_type.js'; import * as constants from './constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; +import {Abstract} from './events/events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockMove } from './events/events_block_move.js'; +import {BlockMove} from './events/events_block_move.js'; import * as eventUtils from './events/utils.js'; import * as Extensions from './extensions.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { Align, Input } from './input.js'; -import { inputTypes } from './input_types.js'; +import {Align, Input} from './input.js'; +import {inputTypes} from './input_types.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocation } from './interfaces/i_ast_node_location.js'; +import {IASTNodeLocation} from './interfaces/i_ast_node_location.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDeletable } from './interfaces/i_deletable.js'; -import { ASTNode } from './keyboard_nav/ast_node.js'; +import {IDeletable} from './interfaces/i_deletable.js'; +import {ASTNode} from './keyboard_nav/ast_node.js'; /* eslint-disable-next-line no-unused-vars */ -import { Mutator } from './mutator.js'; +import {Mutator} from './mutator.js'; import * as Tooltip from './tooltip.js'; import * as arrayUtils from './utils/array.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as idGenerator from './utils/idgenerator.js'; import * as parsing from './utils/parsing.js'; -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -68,7 +68,7 @@ export class Block implements IASTNodeLocation, IDeletable { * changes. This is usually only called from the constructor, the block type * initializer function, or an extension initializer function. */ - onchange?: ((p1: Abstract) => AnyDuringMigration) | null; + onchange?: ((p1: Abstract) => AnyDuringMigration)|null; /** The language-neutral ID given to the collapsed input. */ static readonly COLLAPSED_INPUT_NAME: string = constants.COLLAPSED_INPUT_NAME; @@ -80,7 +80,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Optional text data that round-trips between blocks and XML. * Has no effect. May be used by 3rd parties for meta information. */ - data: string | null = null; + data: string|null = null; /** Has this block been disposed of? */ disposed = false; @@ -89,7 +89,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Colour of the block as HSV hue value (0-360) * This may be null if the block colour was not set via a hue number. */ - private hue_: number | null = null; + private hue_: number|null = null; /** Colour of the block in '#RRGGBB' format. */ protected colour_ = '#000000'; @@ -98,28 +98,28 @@ export class Block implements IASTNodeLocation, IDeletable { protected styleName_ = ''; /** An optional method called during initialization. */ - init?: (() => AnyDuringMigration) | null = undefined; + init?: (() => AnyDuringMigration)|null = undefined; /** * An optional serialization method for defining how to serialize the * mutation state to XML. This must be coupled with defining * `domToMutation`. */ - mutationToDom?: ((...p1: AnyDuringMigration[]) => Element) | null = undefined; + mutationToDom?: ((...p1: AnyDuringMigration[]) => Element)|null = undefined; /** * An optional deserialization method for defining how to deserialize the * mutation state from XML. This must be coupled with defining * `mutationToDom`. */ - domToMutation?: ((p1: Element) => AnyDuringMigration) | null = undefined; + domToMutation?: ((p1: Element) => AnyDuringMigration)|null = undefined; /** * An optional serialization method for defining how to serialize the * block's extra state (eg mutation state) to something JSON compatible. * This must be coupled with defining `loadExtraState`. */ - saveExtraState?: (() => AnyDuringMigration) | null = undefined; + saveExtraState?: (() => AnyDuringMigration)|null = undefined; /** * An optional serialization method for defining how to deserialize the @@ -127,13 +127,13 @@ export class Block implements IASTNodeLocation, IDeletable { * This must be coupled with defining `saveExtraState`. */ loadExtraState?: - ((p1: AnyDuringMigration) => AnyDuringMigration) | null = undefined; + ((p1: AnyDuringMigration) => AnyDuringMigration)|null = undefined; /** * An optional property for suppressing adding STATEMENT_PREFIX and * STATEMENT_SUFFIX to generated code. */ - suppressPrefixSuffix: boolean | null = false; + suppressPrefixSuffix: boolean|null = false; /** * An optional property for declaring developer variables. Return a list of @@ -141,19 +141,19 @@ export class Block implements IASTNodeLocation, IDeletable { * shown to the user, but are declared as global variables in the generated * code. */ - getDeveloperVariables?: (() => string[]) | null = undefined; + getDeveloperVariables?: (() => string[])|null = undefined; /** * An optional function that reconfigures the block based on the contents of * the mutator dialog. */ - compose?: ((p1: Block) => void) | null = null; + compose?: ((p1: Block) => void)|null = null; /** * An optional function that populates the mutator's dialog with * this block's components. */ - decompose?: ((p1: Workspace) => Block) | null = null; + decompose?: ((p1: Workspace) => Block)|null = null; id: string; // AnyDuringMigration because: Type 'null' is not assignable to type // 'Connection'. @@ -170,7 +170,7 @@ export class Block implements IASTNodeLocation, IDeletable { tooltip: Tooltip.TipInfo = ''; contextMenu = true; - protected parentBlock_: this | null = null; + protected parentBlock_: this|null = null; protected childBlocks_: this[] = []; @@ -183,13 +183,13 @@ export class Block implements IASTNodeLocation, IDeletable { private isShadow_ = false; protected collapsed_ = false; - protected outputShape_: number | null = null; + protected outputShape_: number|null = null; /** * A string representing the comment attached to this block. * @deprecated August 2019. Use getCommentText instead. */ - comment: string | Comment | null = null; + comment: string|Comment|null = null; commentModel: CommentModel; private readonly xy_: Coordinate; isInFlyout: boolean; @@ -202,17 +202,17 @@ export class Block implements IASTNodeLocation, IDeletable { /** Name of the type of hat. */ hat?: string = undefined; - rendered: boolean | null = null; + rendered: boolean|null = null; /** * String for block help, or function that returns a URL. Null for no help. */ // AnyDuringMigration because: Type 'null' is not assignable to type 'string // | Function'. - helpUrl: string | Function = null as AnyDuringMigration; + helpUrl: string|Function = null as AnyDuringMigration; /** A bound callback function to use when the parent workspace changes. */ - private onchangeWrapper_: ((p1: Abstract) => AnyDuringMigration) | null = null; + private onchangeWrapper_: ((p1: Abstract) => AnyDuringMigration)|null = null; /** A count of statement inputs on the block. */ statementInputCount = 0; @@ -234,11 +234,11 @@ export class Block implements IASTNodeLocation, IDeletable { this.workspace = workspace; this.id = opt_id && !workspace.getBlockById(opt_id) ? opt_id : - idGenerator.genUid(); + idGenerator.genUid(); workspace.setBlockById(this.id, this); /** A model of the comment attached to this block. */ - this.commentModel = { text: null, pinned: false, size: new Size(160, 80) }; + this.commentModel = {text: null, pinned: false, size: new Size(160, 80)}; /** * The block's position in workspace units. (0, 0) is at the workspace's @@ -414,7 +414,7 @@ export class Block implements IASTNodeLocation, IDeletable { const thisConnection = this.getOnlyValueConnection_(); if (!thisConnection || !thisConnection.isConnected() || - thisConnection.targetBlock()!.isShadow()) { + thisConnection.targetBlock()!.isShadow()) { // Too many or too few possible connections on this block, or there's // nothing on the other side of this connection. return; @@ -425,7 +425,7 @@ export class Block implements IASTNodeLocation, IDeletable { childConnection?.disconnect(); // Connect child to the parent if possible, otherwise bump away. if (this.workspace.connectionChecker.canConnect( - childConnection, parentConnection, false)) { + childConnection, parentConnection, false)) { parentConnection.connect(childConnection!); } else { childConnection?.onFailedConnect(parentConnection); @@ -441,13 +441,13 @@ export class Block implements IASTNodeLocation, IDeletable { * * @return The connection on the value input, or null. */ - private getOnlyValueConnection_(): Connection | null { + private getOnlyValueConnection_(): Connection|null { let connection = null; for (let i = 0; i < this.inputList.length; i++) { const thisConnection = this.inputList[i].connection; if (thisConnection && - thisConnection.type === ConnectionType.INPUT_VALUE && - thisConnection.targetConnection) { + thisConnection.type === ConnectionType.INPUT_VALUE && + thisConnection.targetConnection) { if (connection) { return null; } @@ -478,8 +478,8 @@ export class Block implements IASTNodeLocation, IDeletable { const nextTarget = this.nextConnection.targetConnection; nextTarget?.disconnect(); if (previousTarget && - this.workspace.connectionChecker.canConnect( - previousTarget, nextTarget, false)) { + this.workspace.connectionChecker.canConnect( + previousTarget, nextTarget, false)) { // Attach the next statement to the previous statement. previousTarget.connect(nextTarget!); } @@ -518,7 +518,7 @@ export class Block implements IASTNodeLocation, IDeletable { * connection. * @return The last next connection on the stack, or null. */ - lastConnectionInStack(ignoreShadows: boolean): Connection | null { + lastConnectionInStack(ignoreShadows: boolean): Connection|null { let nextConnection = this.nextConnection; while (nextConnection) { const nextBlock = nextConnection.targetBlock(); @@ -544,7 +544,7 @@ export class Block implements IASTNodeLocation, IDeletable { * value block). * @return The block (if any) that holds the current block. */ - getParent(): this | null { + getParent(): this|null { return this.parentBlock_; } @@ -553,7 +553,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param block A block connected to an input on this block. * @return The input (if any) that connects to the specified block. */ - getInputWithBlock(block: Block): Input | null { + getInputWithBlock(block: Block): Input|null { for (let i = 0, input; input = this.inputList[i]; i++) { if (input.connection && input.connection.targetBlock() === block) { return input; @@ -569,7 +569,7 @@ export class Block implements IASTNodeLocation, IDeletable { * etc. * @return The block (if any) that surrounds the current block. */ - getSurroundParent(): this | null { + getSurroundParent(): this|null { let block = this; let prevBlock; do { @@ -590,7 +590,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Return the next statement block directly connected to this block. * @return The next statement block or null. */ - getNextBlock(): Block | null { + getNextBlock(): Block|null { return this.nextConnection && this.nextConnection.targetBlock(); } @@ -598,7 +598,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Returns the block connected to the previous connection. * @return The previous statement block or null. */ - getPreviousBlock(): Block | null { + getPreviousBlock(): Block|null { return this.previousConnection && this.previousConnection.targetBlock(); } @@ -607,10 +607,10 @@ export class Block implements IASTNodeLocation, IDeletable { * if there are none. * @return The first statement connection or null. */ - getFirstStatementConnection(): Connection | null { + getFirstStatementConnection(): Connection|null { for (let i = 0, input; input = this.inputList[i]; i++) { if (input.connection && - input.connection.type === ConnectionType.NEXT_STATEMENT) { + input.connection.type === ConnectionType.NEXT_STATEMENT) { return input.connection; } } @@ -624,7 +624,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ getRootBlock(): this { let rootBlock: this; - let block: this | null = this; + let block: this|null = this; do { rootBlock = block; block = rootBlock.parentBlock_; @@ -646,7 +646,7 @@ export class Block implements IASTNodeLocation, IDeletable { // AnyDuringMigration because: Type 'Block' is not assignable to type // 'this'. } while (previous && previous.getNextBlock() === block && - (block = previous as AnyDuringMigration)); + (block = previous as AnyDuringMigration)); return block; } @@ -682,7 +682,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Set parent of this block to be a new block or null. * @param newParent New parent block. */ - setParent(newParent: this | null) { + setParent(newParent: this|null) { if (newParent === this.parentBlock_) { return; } @@ -690,8 +690,8 @@ export class Block implements IASTNodeLocation, IDeletable { // Check that block is connected to new parent if new parent is not null and // that block is not connected to superior one if new parent is null. const targetBlock = - this.previousConnection && this.previousConnection.targetBlock() || - this.outputConnection && this.outputConnection.targetBlock(); + this.previousConnection && this.previousConnection.targetBlock() || + this.outputConnection && this.outputConnection.targetBlock(); const isConnected = !!targetBlock; if (isConnected && newParent && targetBlock !== newParent) { @@ -700,8 +700,8 @@ export class Block implements IASTNodeLocation, IDeletable { throw Error('Block not connected to new parent.'); } else if (isConnected && !newParent) { throw Error( - 'Cannot set parent to null while block is still connected to' + - ' superior block.'); + 'Cannot set parent to null while block is still connected to' + + ' superior block.'); } @@ -742,7 +742,7 @@ export class Block implements IASTNodeLocation, IDeletable { // AnyDuringMigration because: Argument of type 'Block[]' is not // assignable to parameter of type 'this[]'. blocks.push.apply( - blocks, child.getDescendants(ordered) as AnyDuringMigration); + blocks, child.getDescendants(ordered) as AnyDuringMigration); } return blocks; } @@ -753,7 +753,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ isDeletable(): boolean { return this.deletable_ && !this.isShadow_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -770,7 +770,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ isMovable(): boolean { return this.movable_ && !this.isShadow_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -793,7 +793,7 @@ export class Block implements IASTNodeLocation, IDeletable { return true; } return this.workspace.isCapacityAvailable( - common.getBlockTypeCounts(this, true)); + common.getBlockTypeCounts(this, true)); } /** @@ -835,7 +835,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ isEditable(): boolean { return this.editable_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -867,7 +867,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param conn The other connection to match. * @return The matching connection on this block, or null. */ - getMatchingConnection(otherBlock: Block, conn: Connection): Connection | null { + getMatchingConnection(otherBlock: Block, conn: Connection): Connection|null { const connections = this.getConnections_(true); const otherConnections = otherBlock.getConnections_(true); if (connections.length !== otherConnections.length) { @@ -886,7 +886,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param url URL string for block help, or function that returns a URL. Null * for no help. */ - setHelpUrl(url: string | Function) { + setHelpUrl(url: string|Function) { this.helpUrl = url; } @@ -928,7 +928,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Get the HSV hue value of a block. Null if hue not set. * @return Hue value (0-360). */ - getHue(): number | null { + getHue(): number|null { return this.hue_; } @@ -937,7 +937,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param colour HSV hue value (0 to 360), #RRGGBB string, or a message * reference string pointing to one of those two values. */ - setColour(colour: number | string) { + setColour(colour: number|string) { const parsed = parsing.parseBlockColour(colour); this.hue_ = parsed.hue; this.colour_ = parsed.hex; @@ -976,13 +976,13 @@ export class Block implements IASTNodeLocation, IDeletable { * @param name The name of the field. * @return Named field, or null if field does not exist. */ - getField(name: string): Field | null { + getField(name: string): Field|null { if (typeof name !== 'string') { throw TypeError( - 'Block.prototype.getField expects a string ' + - 'with the field name but received ' + - (name === undefined ? 'nothing' : name + ' of type ' + typeof name) + - ' instead'); + 'Block.prototype.getField expects a string ' + + 'with the field name but received ' + + (name === undefined ? 'nothing' : name + ' of type ' + typeof name) + + ' instead'); } for (let i = 0, input; input = this.inputList[i]; i++) { for (let j = 0, field; field = input.fieldRow[j]; j++) { @@ -1020,7 +1020,7 @@ export class Block implements IASTNodeLocation, IDeletable { for (let j = 0, field; field = input.fieldRow[j]; j++) { if (field.referencesVariables()) { const model = - this.workspace.getVariableById(field.getValue() as string); + this.workspace.getVariableById(field.getValue() as string); // Check if the variable actually exists (and isn't just a potential // variable). if (model) { @@ -1041,7 +1041,7 @@ export class Block implements IASTNodeLocation, IDeletable { for (let i = 0, input; input = this.inputList[i]; i++) { for (let j = 0, field; field = input.fieldRow[j]; j++) { if (field.referencesVariables() && - variable.getId() === field.getValue()) { + variable.getId() === field.getValue()) { field.refreshVariableName(); } } @@ -1097,22 +1097,22 @@ export class Block implements IASTNodeLocation, IDeletable { * @param opt_check Statement type or list of statement types. Null/undefined * if any type could be connected. */ - setPreviousStatement(newBoolean: boolean, opt_check?: string | string[] | null) { + setPreviousStatement(newBoolean: boolean, opt_check?: string|string[]|null) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.previousConnection) { this.previousConnection = - this.makeConnection_(ConnectionType.PREVIOUS_STATEMENT); + this.makeConnection_(ConnectionType.PREVIOUS_STATEMENT); } this.previousConnection.setCheck(opt_check); } else { if (this.previousConnection) { if (this.previousConnection.isConnected()) { throw Error( - 'Must disconnect previous statement before removing ' + - 'connection.'); + 'Must disconnect previous statement before removing ' + + 'connection.'); } this.previousConnection.dispose(); // AnyDuringMigration because: Type 'null' is not assignable to type @@ -1128,22 +1128,22 @@ export class Block implements IASTNodeLocation, IDeletable { * @param opt_check Statement type or list of statement types. Null/undefined * if any type could be connected. */ - setNextStatement(newBoolean: boolean, opt_check?: string | string[] | null) { + setNextStatement(newBoolean: boolean, opt_check?: string|string[]|null) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.nextConnection) { this.nextConnection = - this.makeConnection_(ConnectionType.NEXT_STATEMENT); + this.makeConnection_(ConnectionType.NEXT_STATEMENT); } this.nextConnection.setCheck(opt_check); } else { if (this.nextConnection) { if (this.nextConnection.isConnected()) { throw Error( - 'Must disconnect next statement before removing ' + - 'connection.'); + 'Must disconnect next statement before removing ' + + 'connection.'); } this.nextConnection.dispose(); // AnyDuringMigration because: Type 'null' is not assignable to type @@ -1159,21 +1159,21 @@ export class Block implements IASTNodeLocation, IDeletable { * @param opt_check Returned type or list of returned types. Null or * undefined if any type could be returned (e.g. variable get). */ - setOutput(newBoolean: boolean, opt_check?: string | string[] | null) { + setOutput(newBoolean: boolean, opt_check?: string|string[]|null) { if (newBoolean) { if (opt_check === undefined) { opt_check = null; } if (!this.outputConnection) { this.outputConnection = - this.makeConnection_(ConnectionType.OUTPUT_VALUE); + this.makeConnection_(ConnectionType.OUTPUT_VALUE); } this.outputConnection.setCheck(opt_check); } else { if (this.outputConnection) { if (this.outputConnection.isConnected()) { throw Error( - 'Must disconnect output value before removing connection.'); + 'Must disconnect output value before removing connection.'); } this.outputConnection.dispose(); // AnyDuringMigration because: Type 'null' is not assignable to type @@ -1190,7 +1190,7 @@ export class Block implements IASTNodeLocation, IDeletable { setInputsInline(newBoolean: boolean) { if (this.inputsInline !== newBoolean) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this, 'inline', null, this.inputsInline, newBoolean)); + (this, 'inline', null, this.inputsInline, newBoolean)); this.inputsInline = newBoolean; } } @@ -1207,14 +1207,14 @@ export class Block implements IASTNodeLocation, IDeletable { // Not defined explicitly. Figure out what would look best. for (let i = 1; i < this.inputList.length; i++) { if (this.inputList[i - 1].type === inputTypes.DUMMY && - this.inputList[i].type === inputTypes.DUMMY) { + this.inputList[i].type === inputTypes.DUMMY) { // Two dummy inputs in a row. Don't inline them. return false; } } for (let i = 1; i < this.inputList.length; i++) { if (this.inputList[i - 1].type === inputTypes.VALUE && - this.inputList[i].type === inputTypes.DUMMY) { + this.inputList[i].type === inputTypes.DUMMY) { // Dummy input after a value input. Inline them. return true; } @@ -1226,7 +1226,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Set the block's output shape. * @param outputShape Value representing an output shape. */ - setOutputShape(outputShape: number | null) { + setOutputShape(outputShape: number|null) { this.outputShape_ = outputShape; } @@ -1234,7 +1234,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Get the block's output shape. * @return Value representing output shape if one exists. */ - getOutputShape(): number | null { + getOutputShape(): number|null { return this.outputShape_; } @@ -1255,7 +1255,7 @@ export class Block implements IASTNodeLocation, IDeletable { const oldValue = this.disabled; this.disabled = !enabled; eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this, 'disabled', null, oldValue, !enabled)); + (this, 'disabled', null, oldValue, !enabled)); } } @@ -1291,7 +1291,7 @@ export class Block implements IASTNodeLocation, IDeletable { setCollapsed(collapsed: boolean) { if (this.collapsed_ !== collapsed) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this, 'collapsed', null, this.collapsed_, collapsed)); + (this, 'collapsed', null, this.collapsed_, collapsed)); this.collapsed_ = collapsed; } } @@ -1325,13 +1325,13 @@ export class Block implements IASTNodeLocation, IDeletable { checks = connection.targetConnection.getCheck(); } return !!checks && - (checks.indexOf('Boolean') !== -1 || checks.indexOf('Number') !== -1); + (checks.indexOf('Boolean') !== -1 || checks.indexOf('Number') !== -1); } /** Check that we haven't circled back to the original root node. */ function checkRoot() { if (node && node.getType() === rootNode?.getType() && - node.getLocation() === rootNode?.getLocation()) { + node.getLocation() === rootNode?.getLocation()) { node = null; } } @@ -1368,7 +1368,7 @@ export class Block implements IASTNodeLocation, IDeletable { checkRoot(); // If we hit an input on the way up, possibly close out parentheses. if (node && node.getType() === ASTNode.types.INPUT && - shouldAddParentheses(node.getLocation() as Connection)) { + shouldAddParentheses(node.getLocation() as Connection)) { text.push(')'); } } @@ -1394,7 +1394,7 @@ export class Block implements IASTNodeLocation, IDeletable { // Join the text array, removing spaces around added parentheses. // AnyDuringMigration because: Type 'string' is not assignable to type // 'any[]'. - text = text.reduce(function (acc, value) { + text = text.reduce(function(acc, value) { return acc + (acc.substr(-1) === '(' || value === ')' ? '' : ' ') + value; }, '') as AnyDuringMigration; // AnyDuringMigration because: Property 'trim' does not exist on type @@ -1408,7 +1408,7 @@ export class Block implements IASTNodeLocation, IDeletable { // AnyDuringMigration because: Type 'string' is not assignable to type // 'any[]'. text = (text.substring(0, opt_maxLength - 3) + '...') as - AnyDuringMigration; + AnyDuringMigration; } } return text; @@ -1455,8 +1455,8 @@ export class Block implements IASTNodeLocation, IDeletable { // Validate inputs. if (json['output'] && json['previousStatement']) { throw Error( - warningPrefix + - 'Must not have both an output and a previousStatement.'); + warningPrefix + + 'Must not have both an output and a previousStatement.'); } // Set basic properties of block. @@ -1480,8 +1480,8 @@ export class Block implements IASTNodeLocation, IDeletable { let i = 0; while (json['message' + i] !== undefined) { this.interpolate_( - json['message' + i], json['args' + i] || [], - json['lastDummyAlign' + i], warningPrefix); + json['message' + i], json['args' + i] || [], + json['lastDummyAlign' + i], warningPrefix); i++; } @@ -1519,10 +1519,10 @@ export class Block implements IASTNodeLocation, IDeletable { } if (typeof json['extensions'] === 'string') { console.warn( - warningPrefix + - 'JSON attribute \'extensions\' should be an array of' + - ' strings. Found raw string in JSON for \'' + json['type'] + - '\' block.'); + warningPrefix + + 'JSON attribute \'extensions\' should be an array of' + + ' strings. Found raw string in JSON for \'' + json['type'] + + '\' block.'); json['extensions'] = [json['extensions']]; } // Correct and continue. @@ -1585,7 +1585,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ mixin(mixinObj: AnyDuringMigration, opt_disableCheck?: boolean) { if (opt_disableCheck !== undefined && - typeof opt_disableCheck !== 'boolean') { + typeof opt_disableCheck !== 'boolean') { throw Error('opt_disableCheck must be a boolean if provided'); } if (!opt_disableCheck) { @@ -1597,8 +1597,8 @@ export class Block implements IASTNodeLocation, IDeletable { } if (overwrites.length) { throw Error( - 'Mixin will overwrite block members: ' + - JSON.stringify(overwrites)); + 'Mixin will overwrite block members: ' + + JSON.stringify(overwrites)); } } Object.assign(this, mixinObj); @@ -1614,8 +1614,8 @@ export class Block implements IASTNodeLocation, IDeletable { * @param warningPrefix Warning prefix string identifying block. */ private interpolate_( - message: string, args: AnyDuringMigration[], - lastDummyAlign: string | undefined, warningPrefix: string) { + message: string, args: AnyDuringMigration[], + lastDummyAlign: string|undefined, warningPrefix: string) { const tokens = parsing.tokenizeInterpolation(message); this.validateTokens_(tokens, args.length); const elements = this.interpolateArguments_(tokens, args, lastDummyAlign); @@ -1650,7 +1650,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param tokens An array of tokens to validate * @param argsCount The number of args that need to be referred to. */ - private validateTokens_(tokens: Array, argsCount: number) { + private validateTokens_(tokens: Array, argsCount: number) { const visitedArgsHash = []; let visitedArgsCount = 0; for (let i = 0; i < tokens.length; i++) { @@ -1660,21 +1660,21 @@ export class Block implements IASTNodeLocation, IDeletable { } if (token < 1 || token > argsCount) { throw Error( - 'Block "' + this.type + '": ' + - 'Message index %' + token + ' out of range.'); + 'Block "' + this.type + '": ' + + 'Message index %' + token + ' out of range.'); } if (visitedArgsHash[token]) { throw Error( - 'Block "' + this.type + '": ' + - 'Message index %' + token + ' duplicated.'); + 'Block "' + this.type + '": ' + + 'Message index %' + token + ' duplicated.'); } visitedArgsHash[token] = true; visitedArgsCount++; } if (visitedArgsCount !== argsCount) { throw Error( - 'Block "' + this.type + '": ' + - 'Message does not reference all ' + argsCount + ' arg(s).'); + 'Block "' + this.type + '": ' + + 'Message does not reference all ' + argsCount + ' arg(s).'); } } @@ -1689,8 +1689,8 @@ export class Block implements IASTNodeLocation, IDeletable { * @return The JSON definitions of field and inputs to add to the block. */ private interpolateArguments_( - tokens: Array, args: Array, - lastDummyAlign: string | undefined): AnyDuringMigration[] { + tokens: Array, args: Array, + lastDummyAlign: string|undefined): AnyDuringMigration[] { const elements = []; for (let i = 0; i < tokens.length; i++) { let element = tokens[i]; @@ -1711,9 +1711,9 @@ export class Block implements IASTNodeLocation, IDeletable { const length = elements.length; if (length && - !this.isInputKeyword_( - (elements as AnyDuringMigration)[length - 1]['type'])) { - const dummyInput = { 'type': 'input_dummy' }; + !this.isInputKeyword_( + (elements as AnyDuringMigration)[length - 1]['type'])) { + const dummyInput = {'type': 'input_dummy'}; if (lastDummyAlign) { (dummyInput as AnyDuringMigration)['align'] = lastDummyAlign; } @@ -1730,8 +1730,8 @@ export class Block implements IASTNodeLocation, IDeletable { * @param element The element to try to turn into a field. * @return The field defined by the JSON, or null if one couldn't be created. */ - private fieldFromJson_(element: { alt?: string, type?: string, text?: string }): - Field | null { + private fieldFromJson_(element: {alt?: string, type?: string, text?: string}): + Field|null { const field = fieldRegistry.fromJson(element); if (!field && element['alt']) { if (typeof element['alt'] === 'string') { @@ -1753,7 +1753,7 @@ export class Block implements IASTNodeLocation, IDeletable { * created for some reason (should never happen). */ private inputFromJson_(element: AnyDuringMigration, warningPrefix: string): - Input | null { + Input|null { const alignmentLookup = { 'LEFT': Align.LEFT, 'RIGHT': Align.RIGHT, @@ -1783,8 +1783,8 @@ export class Block implements IASTNodeLocation, IDeletable { } if (element['align']) { const alignment = - (alignmentLookup as - AnyDuringMigration)[element['align'].toUpperCase()]; + (alignmentLookup as + AnyDuringMigration)[element['align'].toUpperCase()]; if (alignment === undefined) { console.warn(warningPrefix + 'Illegal align value: ', element['align']); } else { @@ -1802,7 +1802,7 @@ export class Block implements IASTNodeLocation, IDeletable { */ private isInputKeyword_(str: string): boolean { return str === 'input_value' || str === 'input_statement' || - str === 'input_dummy'; + str === 'input_dummy'; } /** @@ -1811,7 +1811,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param str String to turn into the JSON definition of a label field. * @return The JSON definition or null. */ - private stringToFieldJson_(str: string): { text: string, type: string } | null { + private stringToFieldJson_(str: string): {text: string, type: string}|null { str = str.trim(); if (str) { return { @@ -1840,7 +1840,7 @@ export class Block implements IASTNodeLocation, IDeletable { // AnyDuringMigration because: Argument of type 'Connection | null' is not // assignable to parameter of type 'Connection'. const input = - new Input(type, name, this, (connection as AnyDuringMigration)); + new Input(type, name, this, (connection as AnyDuringMigration)); // Append input to list. this.inputList.push(input); return input; @@ -1852,7 +1852,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param refName Name of input that should be after the moved input, or null * to be the input at the end. */ - moveInputBefore(name: string, refName: string | null) { + moveInputBefore(name: string, refName: string|null) { if (name === refName) { return; } @@ -1937,7 +1937,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param name The name of the input. * @return The input object, or null if input does not exist. */ - getInput(name: string): Input | null { + getInput(name: string): Input|null { for (let i = 0, input; input = this.inputList[i]; i++) { if (input.name === name) { return input; @@ -1953,7 +1953,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @return The attached value block, or null if the input is either * disconnected or if the input does not exist. */ - getInputTargetBlock(name: string): Block | null { + getInputTargetBlock(name: string): Block|null { const input = this.getInput(name); return input && input.connection && input.connection.targetBlock(); } @@ -1962,7 +1962,7 @@ export class Block implements IASTNodeLocation, IDeletable { * Returns the comment on this block (or null if there is no comment). * @return Block's comment. */ - getCommentText(): string | null { + getCommentText(): string|null { return this.commentModel.text; } @@ -1970,12 +1970,12 @@ export class Block implements IASTNodeLocation, IDeletable { * Set this block's comment text. * @param text The text, or null to delete. */ - setCommentText(text: string | null) { + setCommentText(text: string|null) { if (this.commentModel.text === text) { return; } eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this, 'comment', null, this.commentModel.text, text)); + (this, 'comment', null, this.commentModel.text, text)); this.commentModel.text = text; // AnyDuringMigration because: Type 'string | null' is not assignable to // type 'string | Comment'. @@ -1989,7 +1989,7 @@ export class Block implements IASTNodeLocation, IDeletable { * @param _opt_id An optional ID for the warning text to be able to maintain * multiple warnings. */ - setWarningText(_text: string | null, _opt_id?: string) {} + setWarningText(_text: string|null, _opt_id?: string) {} // NOP. /** @@ -2018,7 +2018,7 @@ export class Block implements IASTNodeLocation, IDeletable { throw Error('Block has parent.'); } const event = - new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove; + new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove; this.xy_.translate(dx, dy); event.recordNew(); eventUtils.fire(event); @@ -2087,7 +2087,7 @@ export class Block implements IASTNodeLocation, IDeletable { } } export interface CommentModel { - text: string | null; + text: string|null; pinned: boolean; size: Size; } diff --git a/core/block_animations.ts b/core/block_animations.ts index 5abd4f6e3..4033bb3d6 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; /** A bounding box for a cloned block. */ interface CloneRect { @@ -48,7 +48,7 @@ export function disposeUiEffect(block: BlockSvg) { // AnyDuringMigration because: Property 'setAttribute' does not exist on type // 'Node'. (clone as AnyDuringMigration) - .setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); + .setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); workspace.getParentSvg().appendChild(clone); const cloneRect = {'x': xy.x, 'y': xy.y, 'width': block.width, 'height': block.height}; @@ -56,8 +56,8 @@ export function disposeUiEffect(block: BlockSvg) { // AnyDuringMigration because: Argument of type 'Node' is not assignable to // parameter of type 'Element'. disposeUiStep( - clone as AnyDuringMigration, cloneRect, workspace.RTL, new Date(), - workspace.scale); + clone as AnyDuringMigration, cloneRect, workspace.RTL, new Date(), + workspace.scale); } /** * Animate a cloned block and eventually dispose of it. @@ -70,21 +70,21 @@ export function disposeUiEffect(block: BlockSvg) { * @param workspaceScale Scale of workspace. */ function disposeUiStep( - clone: Element, rect: CloneRect, rtl: boolean, start: Date, - workspaceScale: number) { + clone: Element, rect: CloneRect, rtl: boolean, start: Date, + workspaceScale: number) { const ms = new Date().getTime() - start.getTime(); const percent = ms / 150; if (percent > 1) { dom.removeNode(clone); } else { const x = - rect.x + (rtl ? -1 : 1) * rect.width * workspaceScale / 2 * percent; + rect.x + (rtl ? -1 : 1) * rect.width * workspaceScale / 2 * percent; const y = rect.y + rect.height * workspaceScale * percent; const scale = (1 - percent) * workspaceScale; clone.setAttribute( - 'transform', - 'translate(' + x + ',' + y + ')' + - ' scale(' + scale + ')'); + 'transform', + 'translate(' + x + ',' + y + ')' + + ' scale(' + scale + ')'); setTimeout(disposeUiStep, 10, clone, rect, rtl, start, workspaceScale); } } @@ -113,15 +113,15 @@ export function connectionUiEffect(block: BlockSvg) { xy.y += 3 * scale; } const ripple = dom.createSvgElement( - Svg.CIRCLE, { - 'cx': xy.x, - 'cy': xy.y, - 'r': 0, - 'fill': 'none', - 'stroke': '#888', - 'stroke-width': 10, - }, - workspace.getParentSvg()); + Svg.CIRCLE, { + 'cx': xy.x, + 'cy': xy.y, + 'r': 0, + 'fill': 'none', + 'stroke': '#888', + 'stroke-width': 10, + }, + workspace.getParentSvg()); // Start the animation. connectionUiStep(ripple, new Date(), scale); } @@ -188,15 +188,15 @@ function disconnectUiStep(group: SVGElement, magnitude: number, start: Date) { (group as AnyDuringMigration).skew_ = ''; } else { const skew = Math.round( - Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); + Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); (group as AnyDuringMigration).skew_ = 'skewX(' + skew + ')'; disconnectGroup = group; disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute( - 'transform', - (group as AnyDuringMigration).translate_ + - (group as AnyDuringMigration).skew_); + 'transform', + (group as AnyDuringMigration).translate_ + + (group as AnyDuringMigration).skew_); } /** diff --git a/core/block_drag_surface.ts b/core/block_drag_surface.ts index 229e92414..43080da5b 100644 --- a/core/block_drag_surface.ts +++ b/core/block_drag_surface.ts @@ -25,9 +25,9 @@ * @class */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; @@ -38,13 +38,13 @@ import * as svgMath from './utils/svg_math.js'; */ export class BlockDragSurfaceSvg { /** The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom. */ - private SVG_: SVGElement | null = null; + private SVG_: SVGElement|null = null; /** * This is where blocks live while they are being dragged if the drag * surface is enabled. */ - private dragGroup_: SVGElement | null = null; + private dragGroup_: SVGElement|null = null; /** * Cached value for the scale of the drag surface. @@ -57,7 +57,7 @@ export class BlockDragSurfaceSvg { * This translation is in pixel units, because the scale is applied to the * drag group rather than the top-level SVG. */ - private surfaceXY_: Coordinate | null = null; + private surfaceXY_: Coordinate|null = null; private readonly childSurfaceXY_: Coordinate; /** @param container Containing element. */ @@ -79,18 +79,18 @@ export class BlockDragSurfaceSvg { } // Already created. this.SVG_ = dom.createSvgElement( - Svg.SVG, { - 'xmlns': dom.SVG_NS, - 'xmlns:html': dom.HTML_NS, - 'xmlns:xlink': dom.XLINK_NS, - 'version': '1.1', - 'class': 'blocklyBlockDragSurface', - }, - this.container); + Svg.SVG, { + 'xmlns': dom.SVG_NS, + 'xmlns:html': dom.HTML_NS, + 'xmlns:xlink': dom.XLINK_NS, + 'version': '1.1', + 'class': 'blocklyBlockDragSurface', + }, + this.container); // AnyDuringMigration because: Argument of type 'SVGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.dragGroup_ = - dom.createSvgElement(Svg.G, {}, this.SVG_ as AnyDuringMigration); + dom.createSvgElement(Svg.G, {}, this.SVG_ as AnyDuringMigration); } /** @@ -142,8 +142,8 @@ export class BlockDragSurfaceSvg { // AnyDuringMigration because: Argument of type 'SVGElement | null' is not // assignable to parameter of type 'Element'. dom.setCssTransform( - this.SVG_ as AnyDuringMigration, - 'translate3d(' + x + 'px, ' + y + 'px, 0)'); + this.SVG_ as AnyDuringMigration, + 'translate3d(' + x + 'px, ' + y + 'px, 0)'); } /** @@ -186,7 +186,7 @@ export class BlockDragSurfaceSvg { * BlockSvg.getRelativeToSurfaceXY). * @return Drag surface group element. */ - getGroup(): SVGElement | null { + getGroup(): SVGElement|null { return this.dragGroup_; } @@ -194,7 +194,7 @@ export class BlockDragSurfaceSvg { * Returns the SVG drag surface. * @returns The SVG drag surface. */ - getSvgRoot(): SVGElement | null { + getSvgRoot(): SVGElement|null { return this.SVG_; } @@ -203,7 +203,7 @@ export class BlockDragSurfaceSvg { * for BlockSvg.getRelativeToSurfaceXY). * @return Drag surface block DOM element, or null if no blocks exist. */ - getCurrentBlock(): Element | null { + getCurrentBlock(): Element|null { return this.dragGroup_!.firstChild as Element; } diff --git a/core/block_dragger.ts b/core/block_dragger.ts index 1f52170ad..189ea7150 100644 --- a/core/block_dragger.ts +++ b/core/block_dragger.ts @@ -17,24 +17,24 @@ import './events/events_block_drag'; import * as blockAnimation from './block_animations.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as bumpObjects from './bump_objects.js'; import * as common from './common.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockMove } from './events/events_block_move.js'; +import {BlockMove} from './events/events_block_move.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Icon } from './icon.js'; -import { InsertionMarkerManager } from './insertion_marker_manager.js'; +import {Icon} from './icon.js'; +import {InsertionMarkerManager} from './insertion_marker_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBlockDragger } from './interfaces/i_block_dragger.js'; +import {IBlockDragger} from './interfaces/i_block_dragger.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; import * as registry from './registry.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -46,7 +46,7 @@ export class BlockDragger implements IBlockDragger { protected draggedConnectionManager_: InsertionMarkerManager; /** Which drag area the mouse pointer is over, if any. */ - private dragTarget_: IDragTarget | null = null; + private dragTarget_: IDragTarget|null = null; /** Whether the block would be deleted if dropped immediately. */ protected wouldDeleteBlock_ = false; @@ -58,8 +58,8 @@ export class BlockDragger implements IBlockDragger { * @param workspace The workspace to drag on. */ constructor( - private readonly block: BlockSvg, - private readonly workspace: WorkspaceSvg) { + private readonly block: BlockSvg, + private readonly workspace: WorkspaceSvg) { /** Object that keeps track of connections on dragged blocks. */ this.draggedConnectionManager_ = new InsertionMarkerManager(this.block); @@ -129,9 +129,9 @@ export class BlockDragger implements IBlockDragger { */ protected shouldDisconnect_(healStack: boolean): boolean { return !!( - this.block.getParent() || - healStack && this.block.nextConnection && - this.block.nextConnection.targetBlock()); + this.block.getParent() || + healStack && this.block.nextConnection && + this.block.nextConnection.targetBlock()); } /** @@ -141,7 +141,7 @@ export class BlockDragger implements IBlockDragger { * at mouse down, in pixel units. */ protected disconnectBlock_( - healStack: boolean, currentDragDeltaXY: Coordinate) { + healStack: boolean, currentDragDeltaXY: Coordinate) { this.block.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Coordinate.sum(this.startXY_, delta); @@ -154,7 +154,7 @@ export class BlockDragger implements IBlockDragger { /** Fire a UI event at the start of a block drag. */ protected fireDragStartEvent_() { const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))! - (this.block, true, this.block.getDescendants(false)); + (this.block, true, this.block.getDescendants(false)); eventUtils.fire(event); } @@ -208,9 +208,9 @@ export class BlockDragger implements IBlockDragger { blockAnimation.disconnectUiStop(); const preventMove = - !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.block); + !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.block); let newLoc: Coordinate; - let delta: Coordinate | null = null; + let delta: Coordinate|null = null; if (preventMove) { newLoc = this.startXY_; } else { @@ -234,9 +234,9 @@ export class BlockDragger implements IBlockDragger { // Blocks dragged directly from a flyout may need to be bumped into // bounds. bumpObjects.bumpIntoBounds( - this.block.workspace, - this.workspace.getMetricsManager().getScrollMetrics(true), - this.block); + this.block.workspace, + this.workspace.getMetricsManager().getScrollMetrics(true), + this.block); } } this.workspace.setResizesEnabled(true); @@ -251,7 +251,8 @@ export class BlockDragger implements IBlockDragger { * @return New location after drag. delta is in workspace units. newLocation * is the new coordinate where the block should end up. */ - protected getNewLocationAfterDrag_(currentDragDeltaXY: Coordinate): { delta: Coordinate, newLocation: Coordinate } { + protected getNewLocationAfterDrag_(currentDragDeltaXY: Coordinate): + {delta: Coordinate, newLocation: Coordinate} { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLocation = Coordinate.sum(this.startXY_, delta); return { @@ -297,7 +298,7 @@ export class BlockDragger implements IBlockDragger { /** Fire a UI event at the end of a block drag. */ protected fireDragEndEvent_() { const event = new (eventUtils.get(eventUtils.BLOCK_DRAG))! - (this.block, false, this.block.getDescendants(false)); + (this.block, false, this.block.getDescendants(false)); eventUtils.fire(event); } @@ -312,20 +313,20 @@ export class BlockDragger implements IBlockDragger { if (toolbox) { const style = this.block.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + 'blocklyToolboxGrab'; // AnyDuringMigration because: Property 'removeStyle' does not exist on // type 'IToolbox'. if (isEnd && - typeof (toolbox as AnyDuringMigration).removeStyle === 'function') { + typeof (toolbox as AnyDuringMigration).removeStyle === 'function') { // AnyDuringMigration because: Property 'removeStyle' does not exist on // type 'IToolbox'. (toolbox as AnyDuringMigration).removeStyle(style); // AnyDuringMigration because: Property 'addStyle' does not exist on // type 'IToolbox'. } else if ( - !isEnd && - typeof (toolbox as AnyDuringMigration).addStyle === 'function') { + !isEnd && + typeof (toolbox as AnyDuringMigration).addStyle === 'function') { // AnyDuringMigration because: Property 'addStyle' does not exist on // type 'IToolbox'. (toolbox as AnyDuringMigration).addStyle(style); @@ -336,7 +337,7 @@ export class BlockDragger implements IBlockDragger { /** Fire a move event at the end of a block drag. */ protected fireMoveEvent_() { const event = - new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this.block) as BlockMove; + new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this.block) as BlockMove; event.oldCoordinate = this.startXY_; event.recordNew(); eventUtils.fire(event); @@ -360,8 +361,8 @@ export class BlockDragger implements IBlockDragger { */ protected pixelsToWorkspaceUnits_(pixelCoord: Coordinate): Coordinate { const result = new Coordinate( - pixelCoord.x / this.workspace.scale, - pixelCoord.y / this.workspace.scale); + pixelCoord.x / this.workspace.scale, + pixelCoord.y / this.workspace.scale); if (this.workspace.isMutator) { // If we're in a mutator, its scale is always 1, purely because of some // oddities in our rendering optimizations. The actual scale is the same @@ -393,7 +394,7 @@ export class BlockDragger implements IBlockDragger { getInsertionMarkers(): BlockSvg[] { // No insertion markers with the old style of dragged connection managers. if (this.draggedConnectionManager_ && - this.draggedConnectionManager_.getInsertionMarkers) { + this.draggedConnectionManager_.getInsertionMarkers) { return this.draggedConnectionManager_.getInsertionMarkers(); } return []; diff --git a/core/block_svg.ts b/core/block_svg.ts index 60f1d5c70..c9cc9468b 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -19,61 +19,61 @@ import './events/events_selected'; // Unused import preserved for side-effects. Remove if unneeded. import './touch'; -import { Block } from './block.js'; +import {Block} from './block.js'; import * as blockAnimations from './block_animations.js'; import * as browserEvents from './browser_events.js'; /* eslint-disable-next-line no-unused-vars */ -import { Comment } from './comment.js'; +import {Comment} from './comment.js'; import * as common from './common.js'; -import { config } from './config.js'; +import {config} from './config.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from './connection.js'; -import { ConnectionType } from './connection_type.js'; +import {Connection} from './connection.js'; +import {ConnectionType} from './connection_type.js'; import * as constants from './constants.js'; import * as ContextMenu from './contextmenu.js'; -import { ContextMenuOption, ContextMenuRegistry, LegacyContextMenuOption } from './contextmenu_registry.js'; +import {ContextMenuOption, ContextMenuRegistry, LegacyContextMenuOption} from './contextmenu_registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockMove } from './events/events_block_move.js'; +import {BlockMove} from './events/events_block_move.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; -import { FieldLabel } from './field_label.js'; +import {Field} from './field.js'; +import {FieldLabel} from './field_label.js'; /* eslint-disable-next-line no-unused-vars */ -import { Icon } from './icon.js'; +import {Icon} from './icon.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from './input.js'; +import {Input} from './input.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js'; +import {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBoundedElement } from './interfaces/i_bounded_element.js'; -import { CopyData, ICopyable } from './interfaces/i_copyable.js'; +import {IBoundedElement} from './interfaces/i_bounded_element.js'; +import {CopyData, ICopyable} from './interfaces/i_copyable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from './interfaces/i_draggable.js'; +import {IDraggable} from './interfaces/i_draggable.js'; import * as internalConstants from './internal_constants.js'; -import { ASTNode } from './keyboard_nav/ast_node.js'; -import { TabNavigateCursor } from './keyboard_nav/tab_navigate_cursor.js'; -import { MarkerManager } from './marker_manager.js'; -import { Msg } from './msg.js'; +import {ASTNode} from './keyboard_nav/ast_node.js'; +import {TabNavigateCursor} from './keyboard_nav/tab_navigate_cursor.js'; +import {MarkerManager} from './marker_manager.js'; +import {Msg} from './msg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Mutator } from './mutator.js'; -import { RenderedConnection } from './rendered_connection.js'; +import {Mutator} from './mutator.js'; +import {RenderedConnection} from './rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Debug as BlockRenderingDebug } from './renderers/common/debugger.js'; +import {Debug as BlockRenderingDebug} from './renderers/common/debugger.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPathObject } from './renderers/common/i_path_object.js'; +import {IPathObject} from './renderers/common/i_path_object.js'; import * as blocks from './serialization/blocks.js'; -import { BlockStyle } from './theme.js'; +import {BlockStyle} from './theme.js'; import * as Tooltip from './tooltip.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Rect } from './utils/rect.js'; -import { Svg } from './utils/svg.js'; +import {Rect} from './utils/rect.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; /* eslint-disable-next-line no-unused-vars */ -import { Warning } from './warning.js'; -import { Workspace } from './workspace.js'; +import {Warning} from './warning.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -82,8 +82,8 @@ import { WorkspaceSvg } from './workspace_svg.js'; * @alias Blockly.BlockSvg */ export class BlockSvg extends Block implements IASTNodeLocationSvg, - IBoundedElement, ICopyable, - IDraggable { + IBoundedElement, ICopyable, + IDraggable { /** * Constant for identifying rows that are to be rendered inline. * Don't collide with Blockly.inputTypes. @@ -96,17 +96,17 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * the block. */ static readonly COLLAPSED_WARNING_ID = 'TEMP_COLLAPSED_WARNING_'; - override decompose?: ((p1: Workspace) => BlockSvg) | null; + override decompose?: ((p1: Workspace) => BlockSvg)|null; // override compose?: ((p1: BlockSvg) => void)|null; - saveConnections?: ((p1: BlockSvg) => AnyDuringMigration) | null; + saveConnections?: ((p1: BlockSvg) => AnyDuringMigration)|null; customContextMenu?: - ((p1: Array) => - AnyDuringMigration) | null; + ((p1: Array) => + AnyDuringMigration)|null; /** * An property used internally to reference the block's rendering debugger. */ - renderingDebugger: BlockRenderingDebug | null = null; + renderingDebugger: BlockRenderingDebug|null = null; /** * Height of this block, not including any statement blocks above or below. @@ -126,16 +126,16 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, */ // AnyDuringMigration because: Type 'null' is not assignable to type '{ [key: // string]: number; }'. - private warningTextDb_: { [key: string]: number } = null as AnyDuringMigration; + private warningTextDb_: {[key: string]: number} = null as AnyDuringMigration; /** Block's mutator icon (if any). */ - mutator: Mutator | null = null; + mutator: Mutator|null = null; /** Block's comment icon (if any). */ - private commentIcon_: Comment | null = null; + private commentIcon_: Comment|null = null; /** Block's warning icon (if any). */ - warning: Warning | null = null; + warning: Warning|null = null; // Create core elements for the block. private svgGroup_: SVGGElement; @@ -207,14 +207,14 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, /** The renderer's path object. */ this.pathObject = - workspace.getRenderer().makePathObject(this.svgGroup_, this.style); + workspace.getRenderer().makePathObject(this.svgGroup_, this.style); /** * Whether to move the block to the drag surface when it is dragged. * True if it should move, false if it should be translated directly. */ this.useDragSurface_ = - svgMath.is3dSupported() && !!workspace.getBlockDragSurface(); + svgMath.is3dSupported() && !!workspace.getBlockDragSurface(); const svgPath = this.pathObject.svgPath; (svgPath as AnyDuringMigration).tooltip = this; @@ -258,7 +258,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Get the secondary colour of a block. * @return #RRGGBB string. */ - getColourSecondary(): string | null { + getColourSecondary(): string|null { return this.style.colourSecondary; } @@ -266,7 +266,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Get the tertiary colour of a block. * @return #RRGGBB string. */ - getColourTertiary(): string | null { + getColourTertiary(): string|null { return this.style.colourTertiary; } @@ -295,7 +295,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, } } const event = new (eventUtils.get(eventUtils.SELECTED))! - (oldId, this.id, this.workspace.id); + (oldId, this.id, this.workspace.id); eventUtils.fire(event); common.setSelected(this); this.addSelect(); @@ -310,7 +310,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, return; } const event = new (eventUtils.get(eventUtils.SELECTED))! - (this.id, null, this.workspace.id); + (this.id, null, this.workspace.id); event.workspaceId = this.workspace.id; eventUtils.fire(event); common.setSelected(null); @@ -339,7 +339,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Sets the parent of this block to be a new block or null. * @param newParent New parent block. */ - override setParent(newParent: this | null) { + override setParent(newParent: this|null) { const oldParent = this.parentBlock_; if (newParent === oldParent) { return; @@ -388,8 +388,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, let y = 0; const dragSurfaceGroup = this.useDragSurface_ ? - this.workspace.getBlockDragSurface()!.getGroup() : - null; + this.workspace.getBlockDragSurface()!.getGroup() : + null; let element: SVGElement = this.getSvgRoot(); if (element) { @@ -401,16 +401,16 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // If this element is the current element on the drag surface, include // the translation of the drag surface itself. if (this.useDragSurface_ && - this.workspace.getBlockDragSurface()!.getCurrentBlock() === - element) { + this.workspace.getBlockDragSurface()!.getCurrentBlock() === + element) { const surfaceTranslation = - this.workspace.getBlockDragSurface()!.getSurfaceTranslation(); + this.workspace.getBlockDragSurface()!.getSurfaceTranslation(); x += surfaceTranslation.x; y += surfaceTranslation.y; } element = element.parentNode as SVGElement; } while (element && element !== this.workspace.getCanvas() && - element !== dragSurfaceGroup); + element !== dragSurfaceGroup); } return new Coordinate(x, y); } @@ -425,7 +425,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, throw Error('Block has parent.'); } const eventsEnabled = eventUtils.isEnabled(); - let event: BlockMove | null = null; + let event: BlockMove|null = null; if (eventsEnabled) { event = new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove; } @@ -447,7 +447,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, */ translate(x: number, y: number) { this.getSvgRoot().setAttribute( - 'transform', 'translate(' + x + ',' + y + ')'); + 'transform', 'translate(' + x + ',' + y + ')'); } /** @@ -496,7 +496,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // Translate to current position, turning off 3d. this.translate(newXY.x, newXY.y); this.workspace.getBlockDragSurface()!.clearAndHide( - this.workspace.getCanvas()); + this.workspace.getCanvas()); } /** @@ -508,15 +508,15 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, moveDuringDrag(newLoc: Coordinate) { if (this.useDragSurface_) { this.workspace.getBlockDragSurface()!.translateSurface( - newLoc.x, newLoc.y); + newLoc.x, newLoc.y); } else { (this.svgGroup_ as AnyDuringMigration).translate_ = - 'translate(' + newLoc.x + ',' + newLoc.y + ')'; + 'translate(' + newLoc.x + ',' + newLoc.y + ')'; (this.svgGroup_ as AnyDuringMigration) - .setAttribute( - 'transform', - (this.svgGroup_ as AnyDuringMigration).translate_ + - (this.svgGroup_ as AnyDuringMigration).skew_); + .setAttribute( + 'transform', + (this.svgGroup_ as AnyDuringMigration).translate_ + + (this.svgGroup_ as AnyDuringMigration).skew_); } } @@ -555,9 +555,9 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, const half = spacing / 2; const xy = this.getRelativeToSurfaceXY(); const dx = - Math.round(Math.round((xy.x - half) / spacing) * spacing + half - xy.x); + Math.round(Math.round((xy.x - half) / spacing) * spacing + half - xy.x); const dy = - Math.round(Math.round((xy.y - half) / spacing) * spacing + half - xy.y); + Math.round(Math.round((xy.y - half) / spacing) * spacing + half - xy.y); if (dx || dy) { this.moveBy(dx, dy); } @@ -646,11 +646,11 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, return; } const input = this.getInput(collapsedInputName) || - this.appendDummyInput(collapsedInputName); + this.appendDummyInput(collapsedInputName); // AnyDuringMigration because: Argument of type 'FieldLabel' is not // assignable to parameter of type 'string | Field'. input.appendField( - new FieldLabel(text) as AnyDuringMigration, collapsedFieldName); + new FieldLabel(text) as AnyDuringMigration, collapsedFieldName); } /** @@ -695,7 +695,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, /** Load the block's help page in a new window. */ showHelp() { const url = - typeof this.helpUrl === 'function' ? this.helpUrl() : this.helpUrl; + typeof this.helpUrl === 'function' ? this.helpUrl() : this.helpUrl; if (url) { window.open(url); } @@ -706,15 +706,15 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * @return Context menu options or null if no menu. */ protected generateContextMenu(): - Array | null { + Array|null { if (this.workspace.options.readOnly || !this.contextMenu) { return null; } // AnyDuringMigration because: Argument of type '{ block: this; }' is not // assignable to parameter of type 'Scope'. const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions( - ContextMenuRegistry.ScopeType.BLOCK, - { block: this } as AnyDuringMigration); + ContextMenuRegistry.ScopeType.BLOCK, + {block: this} as AnyDuringMigration); // Allow the block to add or modify menuOptions. if (this.customContextMenu) { @@ -831,7 +831,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, this.isInsertionMarker_ = insertionMarker; if (this.isInsertionMarker_) { this.setColour( - this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR); + this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR); this.pathObject.updateInsertionMarker(true); } } @@ -932,7 +932,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, this.dispose(false, true); } else { this.dispose(/* heal */ - true, true); + true, true); } eventUtils.setGroup(false); } @@ -941,7 +941,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Encode a block for copying. * @return Copy metadata, or null if the block is an insertion marker. */ - toCopyData(): CopyData | null { + toCopyData(): CopyData|null { if (this.isInsertionMarker_) { return null; } @@ -950,9 +950,9 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // 'this' is not assignable to parameter of type 'Block'. return { saveInfo: blocks.save( - this as AnyDuringMigration, - { addCoordinates: true, addNextBlocks: false }) as - blocks.State, + this as AnyDuringMigration, + {addCoordinates: true, addNextBlocks: false}) as + blocks.State, source: this.workspace, typeCounts: common.getBlockTypeCounts(this as AnyDuringMigration, true), }; @@ -996,7 +996,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * comment. * @return The comment icon attached to this block, or null. */ - getCommentIcon(): Comment | null { + getCommentIcon(): Comment|null { return this.commentIcon_; } @@ -1004,7 +1004,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Set this block's comment text. * @param text The text, or null to delete. */ - override setCommentText(text: string | null) { + override setCommentText(text: string|null) { // AnyDuringMigration because: Property 'get' does not exist on type // '(name: string) => void'. if (this.commentModel.text === text) { @@ -1043,7 +1043,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * @param opt_id An optional ID for the warning text to be able to maintain * multiple warnings. */ - override setWarningText(text: string | null, opt_id?: string) { + override setWarningText(text: string|null, opt_id?: string) { if (!this.warningTextDb_) { // Create a database of warning PIDs. // Only runs once per block (and only those with warnings). @@ -1065,7 +1065,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // Don't change the warning text during a drag. // Wait until the drag finishes. const thisBlock = this; - this.warningTextDb_[id] = setTimeout(function () { + this.warningTextDb_[id] = setTimeout(function() { if (thisBlock.workspace) { // Check block wasn't deleted. delete thisBlock.warningTextDb_[id]; @@ -1091,7 +1091,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, } if (collapsedParent) { collapsedParent.setWarningText( - Msg['COLLAPSED_WARNINGS_WARNING'], BlockSvg.COLLAPSED_WARNING_ID); + Msg['COLLAPSED_WARNINGS_WARNING'], BlockSvg.COLLAPSED_WARNING_ID); } if (!this.warning) { @@ -1125,7 +1125,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Give this block a mutator dialog. * @param mutator A mutator dialog instance or null to remove. */ - override setMutator(mutator: Mutator | null) { + override setMutator(mutator: Mutator|null) { if (this.mutator && this.mutator !== mutator) { this.mutator.dispose(); } @@ -1208,11 +1208,11 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Change the colour of a block. * @param colour HSV hue value, or #RRGGBB string. */ - override setColour(colour: number | string) { + override setColour(colour: number|string) { super.setColour(colour); const styleObj = - this.workspace.getRenderer().getConstants().getBlockStyleForColour( - this.colour_); + this.workspace.getRenderer().getConstants().getBlockStyleForColour( + this.colour_); this.pathObject.setStyle(styleObj.style); this.style = styleObj.style; @@ -1228,8 +1228,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, */ override setStyle(blockStyleName: string) { const blockStyle = - this.workspace.getRenderer().getConstants().getBlockStyle( - blockStyleName); + this.workspace.getRenderer().getConstants().getBlockStyle( + blockStyleName); this.styleName_ = blockStyleName; if (blockStyle) { @@ -1274,7 +1274,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * if any type could be connected. */ override setPreviousStatement( - newBoolean: boolean, opt_check?: string | string[] | null) { + newBoolean: boolean, opt_check?: string|string[]|null) { super.setPreviousStatement(newBoolean, opt_check); if (this.rendered) { @@ -1290,7 +1290,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * if any type could be connected. */ override setNextStatement( - newBoolean: boolean, opt_check?: string | string[] | null) { + newBoolean: boolean, opt_check?: string|string[]|null) { super.setNextStatement(newBoolean, opt_check); if (this.rendered) { @@ -1305,7 +1305,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * @param opt_check Returned type or list of returned types. Null or * undefined if any type could be returned (e.g. variable get). */ - override setOutput(newBoolean: boolean, opt_check?: string | string[] | null) { + override setOutput(newBoolean: boolean, opt_check?: string|string[]|null) { super.setOutput(newBoolean, opt_check); if (this.rendered) { @@ -1463,7 +1463,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * @return The last next connection on the stack, or null. */ override lastConnectionInStack(ignoreShadows: boolean): RenderedConnection - | null { + |null { return super.lastConnectionInStack(ignoreShadows) as RenderedConnection; } @@ -1476,7 +1476,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * @return The matching connection on this block, or null. */ override getMatchingConnection(otherBlock: Block, conn: Connection): - RenderedConnection | null { + RenderedConnection|null { return super.getMatchingConnection(otherBlock, conn) as RenderedConnection; } @@ -1493,7 +1493,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Return the next statement block directly connected to this block. * @return The next statement block or null. */ - override getNextBlock(): BlockSvg | null { + override getNextBlock(): BlockSvg|null { return super.getNextBlock() as BlockSvg; } @@ -1501,7 +1501,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * Returns the block connected to the previous connection. * @return The previous statement block or null. */ - override getPreviousBlock(): BlockSvg | null { + override getPreviousBlock(): BlockSvg|null { return super.getPreviousBlock() as BlockSvg; } @@ -1561,13 +1561,13 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, // Ensure that any snap and bump are part of this move's event group. const group = eventUtils.getGroup(); - setTimeout(function () { + setTimeout(function() { eventUtils.setGroup(group); block.snapToGrid(); eventUtils.setGroup(false); }, config.bumpDelay / 2); - setTimeout(function () { + setTimeout(function() { eventUtils.setGroup(group); block.bumpNeighbours(); eventUtils.setGroup(false); @@ -1583,12 +1583,12 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * block is positioned. */ positionNearConnection( - sourceConnection: RenderedConnection, - targetConnection: RenderedConnection) { + sourceConnection: RenderedConnection, + targetConnection: RenderedConnection) { // We only need to position the new block if it's before the existing one, // otherwise its position is set by the previous block. if (sourceConnection.type === ConnectionType.NEXT_STATEMENT || - sourceConnection.type === ConnectionType.INPUT_VALUE) { + sourceConnection.type === ConnectionType.INPUT_VALUE) { const dx = targetConnection.x - sourceConnection.x; const dy = targetConnection.y - sourceConnection.y; @@ -1597,7 +1597,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, } /** @return The first statement connection or null. */ - override getFirstStatementConnection(): RenderedConnection | null { + override getFirstStatementConnection(): RenderedConnection|null { return super.getFirstStatementConnection() as RenderedConnection | null; } @@ -1719,7 +1719,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, * and any blocks stacked below it. * @return Object with height and width properties in workspace units. */ - getHeightWidth(): { height: number, width: number } { + getHeightWidth(): {height: number, width: number} { let height = this.height; let width = this.width; // Recursively add size of subsequent blocks. @@ -1731,7 +1731,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg, height += nextHeightWidth.height - tabHeight; width = Math.max(width, nextHeightWidth.width); } - return { height, width }; + return {height, width}; } /** diff --git a/core/blockly.ts b/core/blockly.ts index 7f4bb2fa1..c7df50282 100644 --- a/core/blockly.ts +++ b/core/blockly.ts @@ -22,117 +22,117 @@ import './events/events_ui_base'; // Unused import preserved for side-effects. Remove if unneeded. import './events/events_var_create'; -import { Block } from './block.js'; +import {Block} from './block.js'; import * as blockAnimations from './block_animations.js'; -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; -import { BlockDragger } from './block_dragger.js'; -import { BlockSvg } from './block_svg.js'; -import { BlocklyOptions } from './blockly_options.js'; -import { Blocks } from './blocks.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; +import {BlockDragger} from './block_dragger.js'; +import {BlockSvg} from './block_svg.js'; +import {BlocklyOptions} from './blockly_options.js'; +import {Blocks} from './blocks.js'; import * as browserEvents from './browser_events.js'; -import { Bubble } from './bubble.js'; -import { BubbleDragger } from './bubble_dragger.js'; +import {Bubble} from './bubble.js'; +import {BubbleDragger} from './bubble_dragger.js'; import * as bumpObjects from './bump_objects.js'; import * as clipboard from './clipboard.js'; -import { Comment } from './comment.js'; +import {Comment} from './comment.js'; import * as common from './common.js'; -import { ComponentManager } from './component_manager.js'; -import { config } from './config.js'; -import { Connection } from './connection.js'; -import { ConnectionChecker } from './connection_checker.js'; -import { ConnectionDB } from './connection_db.js'; -import { ConnectionType } from './connection_type.js'; +import {ComponentManager} from './component_manager.js'; +import {config} from './config.js'; +import {Connection} from './connection.js'; +import {ConnectionChecker} from './connection_checker.js'; +import {ConnectionDB} from './connection_db.js'; +import {ConnectionType} from './connection_type.js'; import * as ContextMenu from './contextmenu.js'; import * as ContextMenuItems from './contextmenu_items.js'; -import { ContextMenuRegistry } from './contextmenu_registry.js'; +import {ContextMenuRegistry} from './contextmenu_registry.js'; import * as Css from './css.js'; -import { DeleteArea } from './delete_area.js'; +import {DeleteArea} from './delete_area.js'; import * as dialog from './dialog.js'; -import { DragTarget } from './drag_target.js'; +import {DragTarget} from './drag_target.js'; import * as dropDownDiv from './dropdowndiv.js'; import * as Events from './events/events.js'; import * as Extensions from './extensions.js'; -import { Field } from './field.js'; -import { FieldAngle } from './field_angle.js'; -import { FieldCheckbox } from './field_checkbox.js'; -import { FieldColour } from './field_colour.js'; -import { FieldDropdown } from './field_dropdown.js'; -import { FieldImage } from './field_image.js'; -import { FieldLabel } from './field_label.js'; -import { FieldLabelSerializable } from './field_label_serializable.js'; -import { FieldMultilineInput } from './field_multilineinput.js'; -import { FieldNumber } from './field_number.js'; +import {Field} from './field.js'; +import {FieldAngle} from './field_angle.js'; +import {FieldCheckbox} from './field_checkbox.js'; +import {FieldColour} from './field_colour.js'; +import {FieldDropdown} from './field_dropdown.js'; +import {FieldImage} from './field_image.js'; +import {FieldLabel} from './field_label.js'; +import {FieldLabelSerializable} from './field_label_serializable.js'; +import {FieldMultilineInput} from './field_multilineinput.js'; +import {FieldNumber} from './field_number.js'; import * as fieldRegistry from './field_registry.js'; -import { FieldTextInput } from './field_textinput.js'; -import { FieldVariable } from './field_variable.js'; -import { Flyout } from './flyout_base.js'; -import { FlyoutButton } from './flyout_button.js'; -import { HorizontalFlyout } from './flyout_horizontal.js'; -import { FlyoutMetricsManager } from './flyout_metrics_manager.js'; -import { VerticalFlyout } from './flyout_vertical.js'; -import { Generator } from './generator.js'; -import { Gesture } from './gesture.js'; -import { Grid } from './grid.js'; -import { Icon } from './icon.js'; -import { inject } from './inject.js'; -import { Align, Input } from './input.js'; -import { inputTypes } from './input_types.js'; -import { InsertionMarkerManager } from './insertion_marker_manager.js'; -import { IASTNodeLocation } from './interfaces/i_ast_node_location.js'; -import { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js'; -import { IASTNodeLocationWithBlock } from './interfaces/i_ast_node_location_with_block.js'; -import { IAutoHideable } from './interfaces/i_autohideable.js'; -import { IBlockDragger } from './interfaces/i_block_dragger.js'; -import { IBoundedElement } from './interfaces/i_bounded_element.js'; -import { IBubble } from './interfaces/i_bubble.js'; -import { ICollapsibleToolboxItem } from './interfaces/i_collapsible_toolbox_item.js'; -import { IComponent } from './interfaces/i_component.js'; -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; -import { IContextMenu } from './interfaces/i_contextmenu.js'; -import { ICopyable } from './interfaces/i_copyable.js'; -import { IDeletable } from './interfaces/i_deletable.js'; -import { IDeleteArea } from './interfaces/i_delete_area.js'; -import { IDragTarget } from './interfaces/i_drag_target.js'; -import { IDraggable } from './interfaces/i_draggable.js'; -import { IFlyout } from './interfaces/i_flyout.js'; -import { IKeyboardAccessible } from './interfaces/i_keyboard_accessible.js'; -import { IMetricsManager } from './interfaces/i_metrics_manager.js'; -import { IMovable } from './interfaces/i_movable.js'; -import { IPositionable } from './interfaces/i_positionable.js'; -import { IRegistrable } from './interfaces/i_registrable.js'; -import { IRegistrableField } from './interfaces/i_registrable_field.js'; -import { ISelectable } from './interfaces/i_selectable.js'; -import { ISelectableToolboxItem } from './interfaces/i_selectable_toolbox_item.js'; -import { ISerializer as SerializerInterface } from './interfaces/i_serializer.js'; -import { IStyleable } from './interfaces/i_styleable.js'; -import { IToolbox } from './interfaces/i_toolbox.js'; -import { IToolboxItem } from './interfaces/i_toolbox_item.js'; +import {FieldTextInput} from './field_textinput.js'; +import {FieldVariable} from './field_variable.js'; +import {Flyout} from './flyout_base.js'; +import {FlyoutButton} from './flyout_button.js'; +import {HorizontalFlyout} from './flyout_horizontal.js'; +import {FlyoutMetricsManager} from './flyout_metrics_manager.js'; +import {VerticalFlyout} from './flyout_vertical.js'; +import {Generator} from './generator.js'; +import {Gesture} from './gesture.js'; +import {Grid} from './grid.js'; +import {Icon} from './icon.js'; +import {inject} from './inject.js'; +import {Align, Input} from './input.js'; +import {inputTypes} from './input_types.js'; +import {InsertionMarkerManager} from './insertion_marker_manager.js'; +import {IASTNodeLocation} from './interfaces/i_ast_node_location.js'; +import {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js'; +import {IASTNodeLocationWithBlock} from './interfaces/i_ast_node_location_with_block.js'; +import {IAutoHideable} from './interfaces/i_autohideable.js'; +import {IBlockDragger} from './interfaces/i_block_dragger.js'; +import {IBoundedElement} from './interfaces/i_bounded_element.js'; +import {IBubble} from './interfaces/i_bubble.js'; +import {ICollapsibleToolboxItem} from './interfaces/i_collapsible_toolbox_item.js'; +import {IComponent} from './interfaces/i_component.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; +import {IContextMenu} from './interfaces/i_contextmenu.js'; +import {ICopyable} from './interfaces/i_copyable.js'; +import {IDeletable} from './interfaces/i_deletable.js'; +import {IDeleteArea} from './interfaces/i_delete_area.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; +import {IDraggable} from './interfaces/i_draggable.js'; +import {IFlyout} from './interfaces/i_flyout.js'; +import {IKeyboardAccessible} from './interfaces/i_keyboard_accessible.js'; +import {IMetricsManager} from './interfaces/i_metrics_manager.js'; +import {IMovable} from './interfaces/i_movable.js'; +import {IPositionable} from './interfaces/i_positionable.js'; +import {IRegistrable} from './interfaces/i_registrable.js'; +import {IRegistrableField} from './interfaces/i_registrable_field.js'; +import {ISelectable} from './interfaces/i_selectable.js'; +import {ISelectableToolboxItem} from './interfaces/i_selectable_toolbox_item.js'; +import {ISerializer as SerializerInterface} from './interfaces/i_serializer.js'; +import {IStyleable} from './interfaces/i_styleable.js'; +import {IToolbox} from './interfaces/i_toolbox.js'; +import {IToolboxItem} from './interfaces/i_toolbox_item.js'; import * as internalConstants from './internal_constants.js'; -import { ASTNode } from './keyboard_nav/ast_node.js'; -import { BasicCursor } from './keyboard_nav/basic_cursor.js'; -import { Cursor } from './keyboard_nav/cursor.js'; -import { Marker } from './keyboard_nav/marker.js'; -import { TabNavigateCursor } from './keyboard_nav/tab_navigate_cursor.js'; -import { MarkerManager } from './marker_manager.js'; -import { Menu } from './menu.js'; -import { MenuItem } from './menuitem.js'; -import { MetricsManager } from './metrics_manager.js'; -import { Msg } from './msg.js'; -import { Mutator } from './mutator.js'; -import { Names } from './names.js'; -import { Options } from './options.js'; +import {ASTNode} from './keyboard_nav/ast_node.js'; +import {BasicCursor} from './keyboard_nav/basic_cursor.js'; +import {Cursor} from './keyboard_nav/cursor.js'; +import {Marker} from './keyboard_nav/marker.js'; +import {TabNavigateCursor} from './keyboard_nav/tab_navigate_cursor.js'; +import {MarkerManager} from './marker_manager.js'; +import {Menu} from './menu.js'; +import {MenuItem} from './menuitem.js'; +import {MetricsManager} from './metrics_manager.js'; +import {Msg} from './msg.js'; +import {Mutator} from './mutator.js'; +import {Names} from './names.js'; +import {Options} from './options.js'; import * as uiPosition from './positionable_helpers.js'; import * as Procedures from './procedures.js'; import * as registry from './registry.js'; -import { RenderedConnection } from './rendered_connection.js'; +import {RenderedConnection} from './rendered_connection.js'; import * as blockRendering from './renderers/common/block_rendering.js'; import * as constants from './renderers/common/constants.js'; import * as geras from './renderers/geras/geras.js'; import * as minimalist from './renderers/minimalist/minimalist.js'; import * as thrasos from './renderers/thrasos/thrasos.js'; import * as zelos from './renderers/zelos/zelos.js'; -import { Scrollbar } from './scrollbar.js'; -import { ScrollbarPair } from './scrollbar_pair.js'; +import {Scrollbar} from './scrollbar.js'; +import {ScrollbarPair} from './scrollbar_pair.js'; import * as serializationBlocks from './serialization/blocks.js'; import * as serializationExceptions from './serialization/exceptions.js'; import * as serializationPriorities from './serialization/priorities.js'; @@ -140,39 +140,39 @@ import * as serializationRegistry from './serialization/registry.js'; import * as serializationVariables from './serialization/variables.js'; import * as serializationWorkspaces from './serialization/workspaces.js'; import * as ShortcutItems from './shortcut_items.js'; -import { ShortcutRegistry } from './shortcut_registry.js'; -import { Theme } from './theme.js'; +import {ShortcutRegistry} from './shortcut_registry.js'; +import {Theme} from './theme.js'; import * as Themes from './theme/themes.js'; -import { ThemeManager } from './theme_manager.js'; -import { ToolboxCategory } from './toolbox/category.js'; -import { CollapsibleToolboxCategory } from './toolbox/collapsible_category.js'; -import { ToolboxSeparator } from './toolbox/separator.js'; -import { Toolbox } from './toolbox/toolbox.js'; -import { ToolboxItem } from './toolbox/toolbox_item.js'; +import {ThemeManager} from './theme_manager.js'; +import {ToolboxCategory} from './toolbox/category.js'; +import {CollapsibleToolboxCategory} from './toolbox/collapsible_category.js'; +import {ToolboxSeparator} from './toolbox/separator.js'; +import {Toolbox} from './toolbox/toolbox.js'; +import {ToolboxItem} from './toolbox/toolbox_item.js'; import * as Tooltip from './tooltip.js'; import * as Touch from './touch.js'; -import { TouchGesture } from './touch_gesture.js'; -import { Trashcan } from './trashcan.js'; +import {TouchGesture} from './touch_gesture.js'; +import {Trashcan} from './trashcan.js'; import * as utils from './utils.js'; import * as colour from './utils/colour.js'; import * as deprecation from './utils/deprecation.js'; import * as svgMath from './utils/svg_math.js'; import * as toolbox from './utils/toolbox.js'; -import { VariableMap } from './variable_map.js'; -import { VariableModel } from './variable_model.js'; +import {VariableMap} from './variable_map.js'; +import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; import * as VariablesDynamic from './variables_dynamic.js'; -import { Warning } from './warning.js'; +import {Warning} from './warning.js'; import * as WidgetDiv from './widgetdiv.js'; -import { Workspace } from './workspace.js'; -import { WorkspaceAudio } from './workspace_audio.js'; -import { WorkspaceComment } from './workspace_comment.js'; -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; -import { WorkspaceDragSurfaceSvg } from './workspace_drag_surface_svg.js'; -import { WorkspaceDragger } from './workspace_dragger.js'; -import { resizeSvgContents as realResizeSvgContents, WorkspaceSvg } from './workspace_svg.js'; +import {Workspace} from './workspace.js'; +import {WorkspaceAudio} from './workspace_audio.js'; +import {WorkspaceComment} from './workspace_comment.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; +import {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js'; +import {WorkspaceDragger} from './workspace_dragger.js'; +import {resizeSvgContents as realResizeSvgContents, WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; -import { ZoomControls } from './zoom_controls.js'; +import {ZoomControls} from './zoom_controls.js'; /** @@ -304,7 +304,7 @@ export function hideChaff(opt_onlyClosePopups?: boolean) { // AnyDuringMigration because: Property 'getMainWorkspace' does not exist on // type 'void'. ((common as AnyDuringMigration).getMainWorkspace() as WorkspaceSvg) - .hideChaff(opt_onlyClosePopups); + .hideChaff(opt_onlyClosePopups); } /** @@ -329,7 +329,7 @@ export const getMainWorkspace = (common as AnyDuringMigration).getMainWorkspace; // AnyDuringMigration because: Property 'defineBlocksWithJsonArray' does not // exist on type 'void'. export const defineBlocksWithJsonArray = - (common as AnyDuringMigration).defineBlocksWithJsonArray; + (common as AnyDuringMigration).defineBlocksWithJsonArray; /** * Set the parent container. This is the container element that the WidgetDiv, * dropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` @@ -342,7 +342,7 @@ export const defineBlocksWithJsonArray = // AnyDuringMigration because: Property 'setParentContainer' does not exist on // type 'void'. export const setParentContainer = - (common as AnyDuringMigration).setParentContainer; + (common as AnyDuringMigration).setParentContainer; /** @@ -365,8 +365,8 @@ export const svgSize = svgMath.svgSize; */ function resizeSvgContentsLocal(workspace: WorkspaceSvg) { deprecation.warn( - 'Blockly.resizeSvgContents', 'December 2021', 'December 2022', - 'Blockly.WorkspaceSvg.resizeSvgContents'); + 'Blockly.resizeSvgContents', 'December 2021', 'December 2022', + 'Blockly.WorkspaceSvg.resizeSvgContents'); realResizeSvgContents(workspace); } export const resizeSvgContents = resizeSvgContentsLocal; @@ -380,8 +380,8 @@ export const resizeSvgContents = resizeSvgContentsLocal; */ export function copy(toCopy: ICopyable) { deprecation.warn( - 'Blockly.copy', 'December 2021', 'December 2022', - 'Blockly.clipboard.copy'); + 'Blockly.copy', 'December 2021', 'December 2022', + 'Blockly.clipboard.copy'); // AnyDuringMigration because: Property 'copy' does not exist on type 'void'. (clipboard as AnyDuringMigration).copy(toCopy); } @@ -395,8 +395,8 @@ export function copy(toCopy: ICopyable) { */ export function paste(): boolean { deprecation.warn( - 'Blockly.paste', 'December 2021', 'December 2022', - 'Blockly.clipboard.paste'); + 'Blockly.paste', 'December 2021', 'December 2022', + 'Blockly.clipboard.paste'); // AnyDuringMigration because: Property 'paste' does not exist on type // 'void'. return !!(clipboard as AnyDuringMigration).paste(); @@ -411,8 +411,8 @@ export function paste(): boolean { */ export function duplicate(toDuplicate: ICopyable) { deprecation.warn( - 'Blockly.duplicate', 'December 2021', 'December 2022', - 'Blockly.clipboard.duplicate'); + 'Blockly.duplicate', 'December 2021', 'December 2022', + 'Blockly.clipboard.duplicate'); // AnyDuringMigration because: Property 'duplicate' does not exist on type // 'void'. (clipboard as AnyDuringMigration).duplicate(toDuplicate); @@ -428,8 +428,8 @@ export function duplicate(toDuplicate: ICopyable) { */ export function isNumber(str: string): boolean { deprecation.warn( - 'Blockly.isNumber', 'December 2021', 'December 2022', - 'Blockly.utils.string.isNumber'); + 'Blockly.isNumber', 'December 2021', 'December 2022', + 'Blockly.utils.string.isNumber'); // AnyDuringMigration because: Property 'string' does not exist on type // 'void'. return (utils as AnyDuringMigration).string.isNumber(str); @@ -445,8 +445,8 @@ export function isNumber(str: string): boolean { */ export function hueToHex(hue: number): string { deprecation.warn( - 'Blockly.hueToHex', 'December 2021', 'December 2022', - 'Blockly.utils.colour.hueToHex'); + 'Blockly.hueToHex', 'December 2021', 'December 2022', + 'Blockly.utils.colour.hueToHex'); return colour.hueToHex(hue); } @@ -465,11 +465,11 @@ export function hueToHex(hue: number): string { * @alias Blockly.bindEvent_ */ export function bindEvent_( - node: EventTarget, name: string, thisObject: AnyDuringMigration | null, - func: Function): browserEvents.Data { + node: EventTarget, name: string, thisObject: AnyDuringMigration|null, + func: Function): browserEvents.Data { deprecation.warn( - 'Blockly.bindEvent_', 'December 2021', 'December 2022', - 'Blockly.browserEvents.bind'); + 'Blockly.bindEvent_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.bind'); return browserEvents.bind(node, name, thisObject, func); } @@ -484,8 +484,8 @@ export function bindEvent_( */ export function unbindEvent_(bindData: browserEvents.Data): Function { deprecation.warn( - 'Blockly.unbindEvent_', 'December 2021', 'December 2022', - 'Blockly.browserEvents.unbind'); + 'Blockly.unbindEvent_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.unbind'); return browserEvents.unbind(bindData); } @@ -510,15 +510,15 @@ export function unbindEvent_(bindData: browserEvents.Data): Function { * @alias Blockly.bindEventWithChecks_ */ export function bindEventWithChecks_( - node: EventTarget, name: string, thisObject: AnyDuringMigration | null, - func: Function, opt_noCaptureIdentifier?: boolean, - opt_noPreventDefault?: boolean): browserEvents.Data { + node: EventTarget, name: string, thisObject: AnyDuringMigration|null, + func: Function, opt_noCaptureIdentifier?: boolean, + opt_noPreventDefault?: boolean): browserEvents.Data { deprecation.warn( - 'Blockly.bindEventWithChecks_', 'December 2021', 'December 2022', - 'Blockly.browserEvents.conditionalBind'); + 'Blockly.bindEventWithChecks_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.conditionalBind'); return browserEvents.conditionalBind( - node, name, thisObject, func, opt_noCaptureIdentifier, - opt_noPreventDefault); + node, name, thisObject, func, opt_noCaptureIdentifier, + opt_noPreventDefault); } // Aliases to allow external code to access these values for legacy reasons. @@ -530,11 +530,11 @@ export const DELETE_VARIABLE_ID = internalConstants.DELETE_VARIABLE_ID; // AnyDuringMigration because: Property 'COLLAPSED_INPUT_NAME' does not exist // on type 'void'. export const COLLAPSED_INPUT_NAME = - (constants as AnyDuringMigration).COLLAPSED_INPUT_NAME; + (constants as AnyDuringMigration).COLLAPSED_INPUT_NAME; // AnyDuringMigration because: Property 'COLLAPSED_FIELD_NAME' does not exist // on type 'void'. export const COLLAPSED_FIELD_NAME = - (constants as AnyDuringMigration).COLLAPSED_FIELD_NAME; + (constants as AnyDuringMigration).COLLAPSED_FIELD_NAME; /** * String for use in the "custom" attribute of a category in toolbox XML. @@ -545,7 +545,7 @@ export const COLLAPSED_FIELD_NAME = // AnyDuringMigration because: Property 'CATEGORY_NAME' does not exist on type // 'void'. export const VARIABLE_CATEGORY_NAME: string = - (Variables as AnyDuringMigration).CATEGORY_NAME; + (Variables as AnyDuringMigration).CATEGORY_NAME; /** * String for use in the "custom" attribute of a category in toolbox XML. @@ -556,7 +556,7 @@ export const VARIABLE_CATEGORY_NAME: string = // AnyDuringMigration because: Property 'CATEGORY_NAME' does not exist on type // 'void'. export const VARIABLE_DYNAMIC_CATEGORY_NAME: string = - (VariablesDynamic as AnyDuringMigration).CATEGORY_NAME; + (VariablesDynamic as AnyDuringMigration).CATEGORY_NAME; /** * String for use in the "custom" attribute of a category in toolbox XML. * This string indicates that the category should be dynamically populated with @@ -566,150 +566,150 @@ export const VARIABLE_DYNAMIC_CATEGORY_NAME: string = // AnyDuringMigration because: Property 'CATEGORY_NAME' does not exist on type // 'void'. export const PROCEDURE_CATEGORY_NAME: string = - (Procedures as AnyDuringMigration).CATEGORY_NAME; + (Procedures as AnyDuringMigration).CATEGORY_NAME; // Re-export submodules that no longer declareLegacyNamespace. -export { browserEvents }; -export { ContextMenu }; -export { ContextMenuItems }; -export { Css }; -export { Events }; -export { Extensions }; -export { Procedures }; -export { ShortcutItems }; -export { Themes }; -export { Tooltip }; -export { Touch }; -export { Variables }; -export { VariablesDynamic }; -export { WidgetDiv }; -export { Xml }; -export { blockAnimations }; -export { blockRendering }; -export { bumpObjects }; -export { clipboard }; -export { common }; -export { constants }; -export { dialog }; -export { fieldRegistry }; -export { geras }; -export { minimalist }; -export { registry }; -export { thrasos }; -export { uiPosition }; -export { utils }; -export { zelos }; -export { ASTNode }; -export { BasicCursor }; -export { Block }; -export { BlocklyOptions }; -export { BlockDragger }; -export { BlockDragSurfaceSvg }; -export { BlockSvg }; -export { Blocks }; -export { Bubble }; -export { BubbleDragger }; -export { CollapsibleToolboxCategory }; -export { Comment }; -export { ComponentManager }; -export { Connection }; -export { ConnectionType }; -export { ConnectionChecker }; -export { ConnectionDB }; -export { ContextMenuRegistry }; -export { Cursor }; -export { DeleteArea }; -export { DragTarget }; +export {browserEvents}; +export {ContextMenu}; +export {ContextMenuItems}; +export {Css}; +export {Events}; +export {Extensions}; +export {Procedures}; +export {ShortcutItems}; +export {Themes}; +export {Tooltip}; +export {Touch}; +export {Variables}; +export {VariablesDynamic}; +export {WidgetDiv}; +export {Xml}; +export {blockAnimations}; +export {blockRendering}; +export {bumpObjects}; +export {clipboard}; +export {common}; +export {constants}; +export {dialog}; +export {fieldRegistry}; +export {geras}; +export {minimalist}; +export {registry}; +export {thrasos}; +export {uiPosition}; +export {utils}; +export {zelos}; +export {ASTNode}; +export {BasicCursor}; +export {Block}; +export {BlocklyOptions}; +export {BlockDragger}; +export {BlockDragSurfaceSvg}; +export {BlockSvg}; +export {Blocks}; +export {Bubble}; +export {BubbleDragger}; +export {CollapsibleToolboxCategory}; +export {Comment}; +export {ComponentManager}; +export {Connection}; +export {ConnectionType}; +export {ConnectionChecker}; +export {ConnectionDB}; +export {ContextMenuRegistry}; +export {Cursor}; +export {DeleteArea}; +export {DragTarget}; export const DropDownDiv = dropDownDiv; -export { Field }; -export { FieldAngle }; -export { FieldCheckbox }; -export { FieldColour }; -export { FieldDropdown }; -export { FieldImage }; -export { FieldLabel }; -export { FieldLabelSerializable }; -export { FieldMultilineInput }; -export { FieldNumber }; -export { FieldTextInput }; -export { FieldVariable }; -export { Flyout }; -export { FlyoutButton }; -export { FlyoutMetricsManager }; -export { Generator }; -export { Gesture }; -export { Grid }; -export { HorizontalFlyout }; -export { IASTNodeLocation }; -export { IASTNodeLocationSvg }; -export { IASTNodeLocationWithBlock }; -export { IAutoHideable }; -export { IBlockDragger }; -export { IBoundedElement }; -export { IBubble }; -export { ICollapsibleToolboxItem }; -export { IComponent }; -export { IConnectionChecker }; -export { IContextMenu }; -export { Icon }; -export { ICopyable }; -export { IDeletable }; -export { IDeleteArea }; -export { IDragTarget }; -export { IDraggable }; -export { IFlyout }; -export { IKeyboardAccessible }; -export { IMetricsManager }; -export { IMovable }; -export { Input }; -export { InsertionMarkerManager }; -export { IPositionable }; -export { IRegistrable }; -export { IRegistrableField }; -export { ISelectable }; -export { ISelectableToolboxItem }; -export { IStyleable }; -export { IToolbox }; -export { IToolboxItem }; -export { Marker }; -export { MarkerManager }; -export { Menu }; -export { MenuItem }; -export { MetricsManager }; -export { Mutator }; -export { Msg }; -export { Names }; -export { Options }; -export { RenderedConnection }; -export { Scrollbar }; -export { ScrollbarPair }; -export { ShortcutRegistry }; -export { TabNavigateCursor }; -export { Theme }; -export { ThemeManager }; -export { Toolbox }; -export { ToolboxCategory }; -export { ToolboxItem }; -export { ToolboxSeparator }; -export { TouchGesture }; -export { Trashcan }; -export { VariableMap }; -export { VariableModel }; -export { VerticalFlyout }; -export { Warning }; -export { Workspace }; -export { WorkspaceAudio }; -export { WorkspaceComment }; -export { WorkspaceCommentSvg }; -export { WorkspaceDragSurfaceSvg }; -export { WorkspaceDragger }; -export { WorkspaceSvg }; -export { ZoomControls }; -export { config }; +export {Field}; +export {FieldAngle}; +export {FieldCheckbox}; +export {FieldColour}; +export {FieldDropdown}; +export {FieldImage}; +export {FieldLabel}; +export {FieldLabelSerializable}; +export {FieldMultilineInput}; +export {FieldNumber}; +export {FieldTextInput}; +export {FieldVariable}; +export {Flyout}; +export {FlyoutButton}; +export {FlyoutMetricsManager}; +export {Generator}; +export {Gesture}; +export {Grid}; +export {HorizontalFlyout}; +export {IASTNodeLocation}; +export {IASTNodeLocationSvg}; +export {IASTNodeLocationWithBlock}; +export {IAutoHideable}; +export {IBlockDragger}; +export {IBoundedElement}; +export {IBubble}; +export {ICollapsibleToolboxItem}; +export {IComponent}; +export {IConnectionChecker}; +export {IContextMenu}; +export {Icon}; +export {ICopyable}; +export {IDeletable}; +export {IDeleteArea}; +export {IDragTarget}; +export {IDraggable}; +export {IFlyout}; +export {IKeyboardAccessible}; +export {IMetricsManager}; +export {IMovable}; +export {Input}; +export {InsertionMarkerManager}; +export {IPositionable}; +export {IRegistrable}; +export {IRegistrableField}; +export {ISelectable}; +export {ISelectableToolboxItem}; +export {IStyleable}; +export {IToolbox}; +export {IToolboxItem}; +export {Marker}; +export {MarkerManager}; +export {Menu}; +export {MenuItem}; +export {MetricsManager}; +export {Mutator}; +export {Msg}; +export {Names}; +export {Options}; +export {RenderedConnection}; +export {Scrollbar}; +export {ScrollbarPair}; +export {ShortcutRegistry}; +export {TabNavigateCursor}; +export {Theme}; +export {ThemeManager}; +export {Toolbox}; +export {ToolboxCategory}; +export {ToolboxItem}; +export {ToolboxSeparator}; +export {TouchGesture}; +export {Trashcan}; +export {VariableMap}; +export {VariableModel}; +export {VerticalFlyout}; +export {Warning}; +export {Workspace}; +export {WorkspaceAudio}; +export {WorkspaceComment}; +export {WorkspaceCommentSvg}; +export {WorkspaceDragSurfaceSvg}; +export {WorkspaceDragger}; +export {WorkspaceSvg}; +export {ZoomControls}; +export {config}; /** @deprecated Use Blockly.ConnectionType instead. */ export const connectionTypes = ConnectionType; -export { inject }; -export { inputTypes }; +export {inject}; +export {inputTypes}; export namespace serialization { export const blocks = serializationBlocks; export const exceptions = serializationExceptions; @@ -731,5 +731,5 @@ export namespace serialization { // Blockly.Msg module - so make sure it is, but only if there is not // yet a Blockly global variable. if (!('Blockly' in globalThis)) { - (globalThis as AnyDuringMigration)['Blockly'] = { 'Msg': Msg }; + (globalThis as AnyDuringMigration)['Blockly'] = {'Msg': Msg}; } diff --git a/core/blocks.ts b/core/blocks.ts index e3bade9c5..28fa28c76 100644 --- a/core/blocks.ts +++ b/core/blocks.ts @@ -23,4 +23,4 @@ export type BlockDefinition = AnyDuringMigration; * A mapping of block type names to block prototype objects. * @alias Blockly.blocks.Blocks */ -export const Blocks: { [key: string]: BlockDefinition } = Object.create(null); +export const Blocks: {[key: string]: BlockDefinition} = Object.create(null); diff --git a/core/browser_events.ts b/core/browser_events.ts index 53db9cd2b..34d5d13df 100644 --- a/core/browser_events.ts +++ b/core/browser_events.ts @@ -56,9 +56,9 @@ const PAGE_MODE_MULTIPLIER = 125; * @alias Blockly.browserEvents.conditionalBind */ export function conditionalBind( - node: EventTarget, name: string, thisObject: AnyDuringMigration | null, - func: Function, opt_noCaptureIdentifier?: boolean, - opt_noPreventDefault?: boolean): Data { + node: EventTarget, name: string, thisObject: AnyDuringMigration|null, + func: Function, opt_noCaptureIdentifier?: boolean, + opt_noPreventDefault?: boolean): Data { let handled = false; function wrapFunc(e: AnyDuringMigration) { const captureIdentifier = !opt_noCaptureIdentifier; @@ -126,8 +126,8 @@ export function conditionalBind( * @alias Blockly.browserEvents.bind */ export function bind( - node: EventTarget, name: string, thisObject: AnyDuringMigration | null, - func: Function): Data { + node: EventTarget, name: string, thisObject: AnyDuringMigration|null, + func: Function): Data { function wrapFunc(e: AnyDuringMigration) { if (thisObject) { func.call(thisObject, e); @@ -200,16 +200,16 @@ export function unbind(bindData: Data): Function { export function isTargetInput(e: Event): boolean { if (e.target instanceof HTMLElement) { if (e.target.isContentEditable || - e.target.getAttribute('data-is-text-input') === 'true') { + e.target.getAttribute('data-is-text-input') === 'true') { return true; } if (e.target instanceof HTMLInputElement) { const target = e.target; return target.type === 'text' || target.type === 'number' || - target.type === 'email' || target.type === 'password' || - target.type === 'search' || target.type === 'tel' || - target.type === 'url'; + target.type === 'email' || target.type === 'password' || + target.type === 'search' || target.type === 'tel' || + target.type === 'url'; } if (e.target instanceof HTMLTextAreaElement) { @@ -249,7 +249,7 @@ export function isRightButton(e: Event): boolean { * @alias Blockly.browserEvents.mouseToSvg */ export function mouseToSvg( - e: Event, svg: SVGSVGElement, matrix: SVGMatrix | null): SVGPoint { + e: Event, svg: SVGSVGElement, matrix: SVGMatrix|null): SVGPoint { const svgPoint = svg.createSVGPoint(); // AnyDuringMigration because: Property 'clientX' does not exist on type // 'Event'. @@ -270,12 +270,12 @@ export function mouseToSvg( * @return Scroll delta object with .x and .y properties. * @alias Blockly.browserEvents.getScrollDeltaPixels */ -export function getScrollDeltaPixels(e: WheelEvent): { x: number, y: number } { +export function getScrollDeltaPixels(e: WheelEvent): {x: number, y: number} { switch (e.deltaMode) { case 0x00: // Pixel mode. default: - return { x: e.deltaX, y: e.deltaY }; + return {x: e.deltaX, y: e.deltaY}; case 0x01: // Line mode. return { diff --git a/core/bubble.ts b/core/bubble.ts index 652478075..c631399c3 100644 --- a/core/bubble.ts +++ b/core/bubble.ts @@ -18,23 +18,23 @@ import './metrics_manager'; import './workspace'; /* eslint-disable-next-line no-unused-vars */ -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBubble } from './interfaces/i_bubble.js'; -import { ContainerRegion } from './metrics_manager.js'; -import { Scrollbar } from './scrollbar.js'; +import {IBubble} from './interfaces/i_bubble.js'; +import {ContainerRegion} from './metrics_manager.js'; +import {Scrollbar} from './scrollbar.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; import * as math from './utils/math.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -64,10 +64,10 @@ export class Bubble implements IBubble { static ANCHOR_RADIUS = 8; /** Mouse up event data. */ - private static onMouseUpWrapper_: browserEvents.Data | null = null; + private static onMouseUpWrapper_: browserEvents.Data|null = null; /** Mouse move event data. */ - private static onMouseMoveWrapper_: browserEvents.Data | null = null; + private static onMouseMoveWrapper_: browserEvents.Data|null = null; workspace_: AnyDuringMigration; content_: AnyDuringMigration; shape_: AnyDuringMigration; @@ -125,16 +125,16 @@ export class Bubble implements IBubble { private autoLayout_ = true; /** Method to call on resize of bubble. */ - private resizeCallback_: (() => AnyDuringMigration) | null = null; + private resizeCallback_: (() => AnyDuringMigration)|null = null; /** Method to call on move of bubble. */ - private moveCallback_: (() => AnyDuringMigration) | null = null; + private moveCallback_: (() => AnyDuringMigration)|null = null; /** Mouse down on bubbleBack_ event data. */ - private onMouseDownBubbleWrapper_: browserEvents.Data | null = null; + private onMouseDownBubbleWrapper_: browserEvents.Data|null = null; /** Mouse down on resizeGroup_ event data. */ - private onMouseDownResizeWrapper_: browserEvents.Data | null = null; + private onMouseDownResizeWrapper_: browserEvents.Data|null = null; /** * Describes whether this bubble has been disposed of (nodes and event @@ -153,9 +153,9 @@ export class Bubble implements IBubble { * @struct */ constructor( - workspace: WorkspaceSvg, content: SVGElement, shape: SVGElement, - anchorXY: Coordinate, bubbleWidth: number | null, - bubbleHeight: number | null) { + workspace: WorkspaceSvg, content: SVGElement, shape: SVGElement, + anchorXY: Coordinate, bubbleWidth: number|null, + bubbleHeight: number|null) { this.rendered_ = false; this.workspace_ = workspace; this.content_ = content; @@ -169,7 +169,7 @@ export class Bubble implements IBubble { const canvas = workspace.getBubbleCanvas(); canvas.appendChild( - this.createDom_(content, !!(bubbleWidth && bubbleHeight))); + this.createDom_(content, !!(bubbleWidth && bubbleHeight))); this.setAnchorLocation(anchorXY); if (!bubbleWidth || !bubbleHeight) { @@ -208,9 +208,9 @@ export class Bubble implements IBubble { */ this.bubbleGroup_ = dom.createSvgElement(Svg.G, {}); - let filter: { filter?: string } = { + let filter: {filter?: string} = { 'filter': 'url(#' + - this.workspace_.getRenderer().getConstants().embossFilterId + ')', + this.workspace_.getRenderer().getConstants().embossFilterId + ')', }; if (userAgent.JavaFx) { // Multiple reports that JavaFX can't handle filters. @@ -220,44 +220,44 @@ export class Bubble implements IBubble { const bubbleEmboss = dom.createSvgElement(Svg.G, filter, this.bubbleGroup_); this.bubbleArrow_ = dom.createSvgElement(Svg.PATH, {}, bubbleEmboss); this.bubbleBack_ = dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyDraggable', - 'x': 0, - 'y': 0, - 'rx': Bubble.BORDER_WIDTH, - 'ry': Bubble.BORDER_WIDTH, - }, - bubbleEmboss); + Svg.RECT, { + 'class': 'blocklyDraggable', + 'x': 0, + 'y': 0, + 'rx': Bubble.BORDER_WIDTH, + 'ry': Bubble.BORDER_WIDTH, + }, + bubbleEmboss); if (hasResize) { this.resizeGroup_ = dom.createSvgElement( - Svg.G, { - 'class': this.workspace_.RTL ? 'blocklyResizeSW' : - 'blocklyResizeSE', - }, - this.bubbleGroup_); + Svg.G, { + 'class': this.workspace_.RTL ? 'blocklyResizeSW' : + 'blocklyResizeSE', + }, + this.bubbleGroup_); const resizeSize = 2 * Bubble.BORDER_WIDTH; dom.createSvgElement( - Svg.POLYGON, - { 'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString()) }, - this.resizeGroup_); + Svg.POLYGON, + {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, + this.resizeGroup_); dom.createSvgElement( - Svg.LINE, { - 'class': 'blocklyResizeLine', - 'x1': resizeSize / 3, - 'y1': resizeSize - 1, - 'x2': resizeSize - 1, - 'y2': resizeSize / 3, - }, - this.resizeGroup_); + Svg.LINE, { + 'class': 'blocklyResizeLine', + 'x1': resizeSize / 3, + 'y1': resizeSize - 1, + 'x2': resizeSize - 1, + 'y2': resizeSize / 3, + }, + this.resizeGroup_); dom.createSvgElement( - Svg.LINE, { - 'class': 'blocklyResizeLine', - 'x1': resizeSize * 2 / 3, - 'y1': resizeSize - 1, - 'x2': resizeSize - 1, - 'y2': resizeSize * 2 / 3, - }, - this.resizeGroup_); + Svg.LINE, { + 'class': 'blocklyResizeLine', + 'x1': resizeSize * 2 / 3, + 'y1': resizeSize - 1, + 'x2': resizeSize - 1, + 'y2': resizeSize * 2 / 3, + }, + this.resizeGroup_); } else { // AnyDuringMigration because: Type 'null' is not assignable to type // 'SVGGElement'. @@ -266,10 +266,10 @@ export class Bubble implements IBubble { if (!this.workspace_.options.readOnly) { this.onMouseDownBubbleWrapper_ = browserEvents.conditionalBind( - this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_); + this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_); if (this.resizeGroup_) { this.onMouseDownResizeWrapper_ = browserEvents.conditionalBind( - this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); + this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); } } this.bubbleGroup_.appendChild(content); @@ -340,14 +340,14 @@ export class Bubble implements IBubble { } // Left-click (or middle click) this.workspace_.startDrag( - e, - new Coordinate( - this.workspace_.RTL ? -this.width_ : this.width_, this.height_)); + e, + new Coordinate( + this.workspace_.RTL ? -this.width_ : this.width_, this.height_)); Bubble.onMouseUpWrapper_ = browserEvents.conditionalBind( - document, 'mouseup', this, Bubble.bubbleMouseUp_); + document, 'mouseup', this, Bubble.bubbleMouseUp_); Bubble.onMouseMoveWrapper_ = browserEvents.conditionalBind( - document, 'mousemove', this, this.resizeMouseMove_); + document, 'mousemove', this, this.resizeMouseMove_); this.workspace_.hideChaff(); // This event has been handled. No need to bubble up to the document. e.stopPropagation(); @@ -416,7 +416,7 @@ export class Bubble implements IBubble { private layoutBubble_() { // Get the metrics in workspace units. const viewMetrics = - this.workspace_.getMetricsManager().getViewMetrics(true); + this.workspace_.getMetricsManager().getViewMetrics(true); const optimalLeft = this.getOptimalRelativeLeft_(viewMetrics); const optimalTop = this.getOptimalRelativeTop_(viewMetrics); @@ -425,29 +425,29 @@ export class Bubble implements IBubble { const topPosition = { x: optimalLeft, y: -this.height_ - - this.workspace_.getRenderer().getConstants().MIN_BLOCK_HEIGHT as - number, + this.workspace_.getRenderer().getConstants().MIN_BLOCK_HEIGHT as + number, }; - const startPosition = { x: -this.width_ - 30, y: optimalTop }; - const endPosition = { x: bbox.width, y: optimalTop }; - const bottomPosition = { x: optimalLeft, y: bbox.height }; + const startPosition = {x: -this.width_ - 30, y: optimalTop}; + const endPosition = {x: bbox.width, y: optimalTop}; + const bottomPosition = {x: optimalLeft, y: bbox.height}; const closerPosition = - bbox.width < bbox.height ? endPosition : bottomPosition; + bbox.width < bbox.height ? endPosition : bottomPosition; const fartherPosition = - bbox.width < bbox.height ? bottomPosition : endPosition; + bbox.width < bbox.height ? bottomPosition : endPosition; const topPositionOverlap = this.getOverlap_(topPosition, viewMetrics); const startPositionOverlap = this.getOverlap_(startPosition, viewMetrics); const closerPositionOverlap = this.getOverlap_(closerPosition, viewMetrics); const fartherPositionOverlap = - this.getOverlap_(fartherPosition, viewMetrics); + this.getOverlap_(fartherPosition, viewMetrics); // Set the position to whichever position shows the most of the bubble, // with tiebreaks going in the order: top > start > close > far. const mostOverlap = Math.max( - topPositionOverlap, startPositionOverlap, closerPositionOverlap, - fartherPositionOverlap); + topPositionOverlap, startPositionOverlap, closerPositionOverlap, + fartherPositionOverlap); if (topPositionOverlap === mostOverlap) { this.relativeLeft_ = topPosition.x; this.relativeTop_ = topPosition.y; @@ -480,12 +480,12 @@ export class Bubble implements IBubble { * @return The percentage of the bubble that is visible. */ private getOverlap_( - relativeMin: { x: number, y: number }, - viewMetrics: ContainerRegion): number { + relativeMin: {x: number, y: number}, + viewMetrics: ContainerRegion): number { // The position of the top-left corner of the bubble in workspace units. const bubbleMin = { x: this.workspace_.RTL ? this.anchorXY_.x - relativeMin.x - this.width_ : - relativeMin.x + this.anchorXY_.x, + relativeMin.x + this.anchorXY_.x, y: relativeMin.y + this.anchorXY_.y, }; // The position of the bottom-right corner of the bubble in workspace units. @@ -500,7 +500,7 @@ export class Bubble implements IBubble { // the calculation. // The position of the top-left corner of the workspace. - const workspaceMin = { x: viewMetrics.left, y: viewMetrics.top }; + const workspaceMin = {x: viewMetrics.left, y: viewMetrics.top}; // The position of the bottom-right corner of the workspace. const workspaceMax = { x: viewMetrics.left + viewMetrics.width, @@ -508,13 +508,13 @@ export class Bubble implements IBubble { }; const overlapWidth = Math.min(bubbleMax.x, workspaceMax.x) - - Math.max(bubbleMin.x, workspaceMin.x); + Math.max(bubbleMin.x, workspaceMin.x); const overlapHeight = Math.min(bubbleMax.y, workspaceMax.y) - - Math.max(bubbleMin.y, workspaceMin.y); + Math.max(bubbleMin.y, workspaceMin.y); return Math.max( - 0, - Math.min( - 1, overlapWidth * overlapHeight / (this.width_ * this.height_))); + 0, + Math.min( + 1, overlapWidth * overlapHeight / (this.width_ * this.height_))); } /** @@ -541,7 +541,7 @@ export class Bubble implements IBubble { const workspaceRight = viewMetrics.left + viewMetrics.width; const workspaceLeft = viewMetrics.left + // Thickness in workspace units. - Scrollbar.scrollbarThickness / this.workspace_.scale; + Scrollbar.scrollbarThickness / this.workspace_.scale; if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. @@ -556,8 +556,8 @@ export class Bubble implements IBubble { const workspaceLeft = viewMetrics.left; const workspaceRight = viewMetrics.left + - viewMetrics.width - // Thickness in workspace units. - Scrollbar.scrollbarThickness / this.workspace_.scale; + viewMetrics.width - // Thickness in workspace units. + Scrollbar.scrollbarThickness / this.workspace_.scale; if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. @@ -591,8 +591,8 @@ export class Bubble implements IBubble { const bubbleBottom = bubbleTop + this.height_; const workspaceTop = viewMetrics.top; const workspaceBottom = viewMetrics.top + - viewMetrics.height - // Thickness in workspace units. - Scrollbar.scrollbarThickness / this.workspace_.scale; + viewMetrics.height - // Thickness in workspace units. + Scrollbar.scrollbarThickness / this.workspace_.scale; const anchorY = this.anchorXY_.y; if (bubbleTop < workspaceTop) { @@ -625,7 +625,7 @@ export class Bubble implements IBubble { */ moveTo(x: number, y: number) { this.bubbleGroup_.setAttribute( - 'transform', 'translate(' + x + ',' + y + ')'); + 'transform', 'translate(' + x + ',' + y + ')'); } /** @@ -669,14 +669,14 @@ export class Bubble implements IBubble { // Mirror the resize group. const resizeSize = 2 * Bubble.BORDER_WIDTH; this.resizeGroup_.setAttribute( - 'transform', - 'translate(' + resizeSize + ',' + (height - doubleBorderWidth) + - ') scale(-1 1)'); + 'transform', + 'translate(' + resizeSize + ',' + (height - doubleBorderWidth) + + ') scale(-1 1)'); } else { this.resizeGroup_.setAttribute( - 'transform', - 'translate(' + (width - doubleBorderWidth) + ',' + - (height - doubleBorderWidth) + ')'); + 'transform', + 'translate(' + (width - doubleBorderWidth) + ',' + + (height - doubleBorderWidth) + ')'); } } if (this.autoLayout_) { @@ -727,7 +727,7 @@ export class Bubble implements IBubble { // Calculate the thickness of the base of the arrow. const bubbleSize = this.getBubbleSize(); let thickness = - (bubbleSize.width + bubbleSize.height) / Bubble.ARROW_THICKNESS; + (bubbleSize.width + bubbleSize.height) / Bubble.ARROW_THICKNESS; thickness = Math.min(thickness, bubbleSize.width, bubbleSize.height) / 4; // Back the tip of the arrow off of the anchor. @@ -751,11 +751,11 @@ export class Bubble implements IBubble { steps.push('M' + baseX1 + ',' + baseY1); steps.push( - 'C' + (baseX1 + swirlRun) + ',' + (baseY1 + swirlRise) + ' ' + - relAnchorX + ',' + relAnchorY + ' ' + relAnchorX + ',' + relAnchorY); + 'C' + (baseX1 + swirlRun) + ',' + (baseY1 + swirlRise) + ' ' + + relAnchorX + ',' + relAnchorY + ' ' + relAnchorX + ',' + relAnchorY); steps.push( - 'C' + relAnchorX + ',' + relAnchorY + ' ' + (baseX2 + swirlRun) + - ',' + (baseY2 + swirlRise) + ' ' + baseX2 + ',' + baseY2); + 'C' + relAnchorX + ',' + relAnchorY + ' ' + (baseX2 + swirlRun) + + ',' + (baseY2 + swirlRise) + ' ' + baseX2 + ',' + baseY2); } steps.push('z'); this.bubbleArrow_.setAttribute('d', steps.join(' ')); @@ -812,10 +812,10 @@ export class Bubble implements IBubble { */ getRelativeToSurfaceXY(): Coordinate { return new Coordinate( - this.workspace_.RTL ? - -this.relativeLeft_ + this.anchorXY_.x - this.width_ : - this.anchorXY_.x + this.relativeLeft_, - this.anchorXY_.y + this.relativeTop_); + this.workspace_.RTL ? + -this.relativeLeft_ + this.anchorXY_.x - this.width_ : + this.anchorXY_.x + this.relativeLeft_, + this.anchorXY_.y + this.relativeTop_); } /** @@ -862,7 +862,7 @@ export class Bubble implements IBubble { const lines = text.split('\n'); for (let i = 0; i < lines.length; i++) { const tspanElement = dom.createSvgElement( - Svg.TSPAN, { 'dy': '1em', 'x': Bubble.BORDER_WIDTH }, paragraph); + Svg.TSPAN, {'dy': '1em', 'x': Bubble.BORDER_WIDTH}, paragraph); const textNode = document.createTextNode(lines[i]); tspanElement.appendChild(textNode); } @@ -877,11 +877,11 @@ export class Bubble implements IBubble { * @return The non editable bubble. */ static createNonEditableBubble( - paragraphElement: SVGTextElement, block: BlockSvg, - iconXY: Coordinate): Bubble { + paragraphElement: SVGTextElement, block: BlockSvg, + iconXY: Coordinate): Bubble { const bubble = new Bubble( - (block.workspace), paragraphElement, block.pathObject.svgPath, (iconXY), - null, null); + (block.workspace), paragraphElement, block.pathObject.svgPath, (iconXY), + null, null); // Expose this bubble's block's ID on its top-level SVG group. bubble.setSvgId(block.id); if (block.RTL) { @@ -889,11 +889,11 @@ export class Bubble implements IBubble { // This cannot be done until the bubble is rendered on screen. const maxWidth = paragraphElement.getBBox().width; for (let i = 0, textElement; - textElement = paragraphElement.childNodes[i] as SVGTSpanElement; - i++) { + textElement = paragraphElement.childNodes[i] as SVGTSpanElement; + i++) { textElement.setAttribute('text-anchor', 'end'); textElement.setAttribute( - 'x', (maxWidth + Bubble.BORDER_WIDTH).toString()); + 'x', (maxWidth + Bubble.BORDER_WIDTH).toString()); } } return bubble; diff --git a/core/bubble_dragger.ts b/core/bubble_dragger.ts index 255097582..8fe8fe143 100644 --- a/core/bubble_dragger.ts +++ b/core/bubble_dragger.ts @@ -18,22 +18,22 @@ import './bubble'; import './constants'; /* eslint-disable-next-line no-unused-vars */ -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; -import { ComponentManager } from './component_manager.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; +import {ComponentManager} from './component_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentMove } from './events/events_comment_move.js'; +import {CommentMove} from './events/events_comment_move.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBubble } from './interfaces/i_bubble.js'; +import {IBubble} from './interfaces/i_bubble.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDeleteArea } from './interfaces/i_delete_area.js'; +import {IDeleteArea} from './interfaces/i_delete_area.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; -import { Coordinate } from './utils/coordinate.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; +import {Coordinate} from './utils/coordinate.js'; import * as svgMath from './utils/svg_math.js'; -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -44,7 +44,7 @@ import { WorkspaceSvg } from './workspace_svg.js'; */ export class BubbleDragger { /** Which drag target the mouse pointer is over, if any. */ - private dragTarget_: IDragTarget | null = null; + private dragTarget_: IDragTarget|null = null; /** Whether the bubble would be deleted if dropped immediately. */ private wouldDeleteBubble_ = false; @@ -69,9 +69,9 @@ export class BubbleDragger { // AnyDuringMigration because: Type 'BlockDragSurfaceSvg | null' is not // assignable to type 'BlockDragSurfaceSvg'. this.dragSurface_ = - (svgMath.is3dSupported() && !!workspace.getBlockDragSurface() ? - workspace.getBlockDragSurface() : - null) as AnyDuringMigration; + (svgMath.is3dSupported() && !!workspace.getBlockDragSurface() ? + workspace.getBlockDragSurface() : + null) as AnyDuringMigration; } /** @@ -142,11 +142,11 @@ export class BubbleDragger { * @param dragTarget The drag target that the bubblee is currently over. * @return Whether dropping the bubble immediately would delete the block. */ - private shouldDelete_(dragTarget: IDragTarget | null): boolean { + private shouldDelete_(dragTarget: IDragTarget|null): boolean { if (dragTarget) { const componentManager = this.workspace.getComponentManager(); const isDeleteArea = componentManager.hasCapability( - dragTarget.id, ComponentManager.Capability.DELETE_AREA); + dragTarget.id, ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (dragTarget as IDeleteArea).wouldDelete(this.bubble, false); } @@ -173,7 +173,7 @@ export class BubbleDragger { this.dragBubble(e, currentDragDeltaXY); const preventMove = - this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.bubble); + this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.bubble); let newLoc; if (preventMove) { newLoc = this.startXY_; @@ -211,7 +211,7 @@ export class BubbleDragger { private fireMoveEvent_() { if (this.bubble instanceof WorkspaceCommentSvg) { const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))! - (this.bubble) as CommentMove; + (this.bubble) as CommentMove; event.setOldCoordinate(this.startXY_); event.recordNew(); eventUtils.fire(event); @@ -230,8 +230,8 @@ export class BubbleDragger { */ private pixelsToWorkspaceUnits_(pixelCoord: Coordinate): Coordinate { const result = new Coordinate( - pixelCoord.x / this.workspace.scale, - pixelCoord.y / this.workspace.scale); + pixelCoord.x / this.workspace.scale, + pixelCoord.y / this.workspace.scale); if (this.workspace.isMutator) { // If we're in a mutator, its scale is always 1, purely because of some // oddities in our rendering optimizations. The actual scale is the same diff --git a/core/bump_objects.ts b/core/bump_objects.ts index f5bfecbd9..46c3ae2cd 100644 --- a/core/bump_objects.ts +++ b/core/bump_objects.ts @@ -33,24 +33,24 @@ * @namespace Blockly.bumpObjects */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; -import { BlockCreate } from './events/events_block_create.js'; -import { BlockMove } from './events/events_block_move.js'; -import { CommentCreate } from './events/events_comment_create.js'; -import { CommentMove } from './events/events_comment_move.js'; +import {Abstract} from './events/events_abstract.js'; +import {BlockCreate} from './events/events_block_create.js'; +import {BlockMove} from './events/events_block_move.js'; +import {CommentCreate} from './events/events_comment_create.js'; +import {CommentMove} from './events/events_comment_move.js'; /* eslint-disable-next-line no-unused-vars */ -import { ViewportChange } from './events/events_viewport.js'; +import {ViewportChange} from './events/events_viewport.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBoundedElement } from './interfaces/i_bounded_element.js'; -import { ContainerRegion, MetricsManager } from './metrics_manager.js'; +import {IBoundedElement} from './interfaces/i_bounded_element.js'; +import {ContainerRegion, MetricsManager} from './metrics_manager.js'; import * as mathUtils from './utils/math.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -63,8 +63,8 @@ import { WorkspaceSvg } from './workspace_svg.js'; * @alias Blockly.bumpObjects.bumpIntoBounds */ function bumpObjectIntoBounds( - workspace: WorkspaceSvg, scrollMetrics: ContainerRegion, - object: IBoundedElement): boolean { + workspace: WorkspaceSvg, scrollMetrics: ContainerRegion, + object: IBoundedElement): boolean { // Compute new top/left position for object. const objectMetrics = object.getBoundingRectangle(); const height = objectMetrics.bottom - objectMetrics.top; @@ -76,7 +76,7 @@ function bumpObjectIntoBounds( // If the object is taller than the workspace we want to // top-align the block const newYPosition = - mathUtils.clamp(topClamp, objectMetrics.top, bottomClamp); + mathUtils.clamp(topClamp, objectMetrics.top, bottomClamp); const deltaY = newYPosition - objectMetrics.top; // Note: Even in RTL mode the "anchor" of the object is the @@ -96,7 +96,7 @@ function bumpObjectIntoBounds( rightClamp = Math.max(leftClamp, rightClamp); } const newXPosition = - mathUtils.clamp(leftClamp, objectMetrics.left, rightClamp); + mathUtils.clamp(leftClamp, objectMetrics.left, rightClamp); const deltaX = newXPosition - objectMetrics.left; if (deltaX || deltaY) { @@ -114,7 +114,7 @@ export const bumpIntoBounds = bumpObjectIntoBounds; * @alias Blockly.bumpObjects.bumpIntoBoundsHandler */ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): - (p1: Abstract) => AnyDuringMigration { + (p1: Abstract) => AnyDuringMigration { return (e) => { const metricsManager = workspace.getMetricsManager(); if (!metricsManager.hasFixedEdges() || workspace.isDragging()) { @@ -126,7 +126,7 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): // Triggered by move/create event const object = - extractObjectFromEvent(workspace, e as eventUtils.BumpEvent); + extractObjectFromEvent(workspace, e as eventUtils.BumpEvent); if (!object) { return; } @@ -135,12 +135,12 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): eventUtils.setGroup(e.group); const wasBumped = bumpObjectIntoBounds( - workspace, scrollMetricsInWsCoords, (object as IBoundedElement)); + workspace, scrollMetricsInWsCoords, (object as IBoundedElement)); if (wasBumped && !e.group) { console.warn( - 'Moved object in bounds but there was no' + - ' event group. This may break undo.'); + 'Moved object in bounds but there was no' + + ' event group. This may break undo.'); } if (oldGroup !== null) { eventUtils.setGroup(oldGroup); @@ -148,7 +148,7 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): } else if (e.type === eventUtils.VIEWPORT_CHANGE) { const viewportEvent = (e as ViewportChange); if (viewportEvent.scale && viewportEvent.oldScale && - viewportEvent.scale > viewportEvent.oldScale) { + viewportEvent.scale > viewportEvent.oldScale) { bumpTopObjectsIntoBounds(workspace); } } @@ -164,8 +164,8 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg): * object. */ function extractObjectFromEvent( - workspace: WorkspaceSvg, e: eventUtils.BumpEvent): BlockSvg | null | - WorkspaceCommentSvg { + workspace: WorkspaceSvg, e: eventUtils.BumpEvent): BlockSvg|null| + WorkspaceCommentSvg { let object = null; switch (e.type) { case eventUtils.BLOCK_CREATE: @@ -178,9 +178,9 @@ function extractObjectFromEvent( case eventUtils.COMMENT_CREATE: case eventUtils.COMMENT_MOVE: object = workspace.getCommentById( - (e as CommentCreate | CommentMove).commentId) as - WorkspaceCommentSvg | - null; + (e as CommentCreate | CommentMove).commentId) as + WorkspaceCommentSvg | + null; break; } return object; diff --git a/core/clipboard.ts b/core/clipboard.ts index f305aff95..1030c2318 100644 --- a/core/clipboard.ts +++ b/core/clipboard.ts @@ -11,11 +11,11 @@ * Blockly's internal clipboard for managing copy-paste. * @namespace Blockly.clipboard */ -import { CopyData, ICopyable } from './interfaces/i_copyable.js'; +import {CopyData, ICopyable} from './interfaces/i_copyable.js'; /** Metadata about the object that is currently on the clipboard. */ -let copyData: CopyData | null = null; +let copyData: CopyData|null = null; /** * Copy a block or workspace comment onto the local clipboard. @@ -31,7 +31,7 @@ export function copy(toCopy: ICopyable) { * @return The pasted thing if the paste was successful, null otherwise. * @alias Blockly.clipboard.paste */ -export function paste(): ICopyable | null { +export function paste(): ICopyable|null { if (!copyData) { return null; } @@ -42,7 +42,7 @@ export function paste(): ICopyable | null { workspace = workspace.targetWorkspace; } if (copyData.typeCounts && - workspace.isCapacityAvailable(copyData.typeCounts)) { + workspace.isCapacityAvailable(copyData.typeCounts)) { return workspace.paste(copyData.saveInfo); } return null; @@ -55,7 +55,7 @@ export function paste(): ICopyable | null { * duplication failed. * @alias Blockly.clipboard.duplicate */ -export function duplicate(toDuplicate: ICopyable): ICopyable | null { +export function duplicate(toDuplicate: ICopyable): ICopyable|null { const oldCopyData = copyData; copy(toDuplicate); const pastedThing = toDuplicate.toCopyData().source.paste(copyData!.saveInfo); diff --git a/core/comment.ts b/core/comment.ts index b95f41dc8..17e920fe0 100644 --- a/core/comment.ts +++ b/core/comment.ts @@ -24,20 +24,20 @@ import './events/events_bubble_open'; // Unused import preserved for side-effects. Remove if unneeded. import './warning'; -import { CommentModel } from './block.js'; +import {CommentModel} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; -import { Bubble } from './bubble.js'; +import {Bubble} from './bubble.js'; import * as Css from './css.js'; import * as eventUtils from './events/utils.js'; -import { Icon } from './icon.js'; +import {Icon} from './icon.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; @@ -52,30 +52,30 @@ export class Comment extends Icon { * The model's text value at the start of an edit. * Used to tell if an event should be fired at the end of an edit. */ - private cachedText_: string | null = ''; + private cachedText_: string|null = ''; /** Mouse up event data. */ - private onMouseUpWrapper_: browserEvents.Data | null = null; + private onMouseUpWrapper_: browserEvents.Data|null = null; /** Wheel event data. */ - private onWheelWrapper_: browserEvents.Data | null = null; + private onWheelWrapper_: browserEvents.Data|null = null; /** Change event data. */ - private onChangeWrapper_: browserEvents.Data | null = null; + private onChangeWrapper_: browserEvents.Data|null = null; /** Input event data. */ - private onInputWrapper_: browserEvents.Data | null = null; + private onInputWrapper_: browserEvents.Data|null = null; /** * The SVG element that contains the text edit area, or null if not created. */ - private foreignObject_: SVGForeignObjectElement | null = null; + private foreignObject_: SVGForeignObjectElement|null = null; /** The editable text area, or null if not created. */ - private textarea_: HTMLTextAreaElement | null = null; + private textarea_: HTMLTextAreaElement|null = null; /** The top-level node of the comment text, or null if not created. */ - private paragraphElement_: SVGTextElement | null = null; + private paragraphElement_: SVGTextElement|null = null; override bubble_: AnyDuringMigration; /** @param block The block associated with this comment. */ @@ -98,28 +98,28 @@ export class Comment extends Icon { protected override drawIcon_(group: Element) { // Circle. dom.createSvgElement( - Svg.CIRCLE, - { 'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8' }, group); + Svg.CIRCLE, + {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and // operating systems render it differently. Body of question mark. dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyIconSymbol', - 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + - '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + - '-1.201,0.998 -1.201,1.528 -1.204,2.19z', - }, - group); + Svg.PATH, { + 'class': 'blocklyIconSymbol', + 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + + '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + + '-1.201,0.998 -1.201,1.528 -1.204,2.19z', + }, + group); // Dot of question mark. dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyIconSymbol', - 'x': '6.8', - 'y': '10.78', - 'height': '2', - 'width': '2', - }, - group); + Svg.RECT, { + 'class': 'blocklyIconSymbol', + 'x': '6.8', + 'y': '10.78', + 'height': '2', + 'width': '2', + }, + group); } /** @@ -140,15 +140,15 @@ export class Comment extends Icon { */ this.foreignObject_ = dom.createSvgElement( - Svg.FOREIGNOBJECT, - { 'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH }); + Svg.FOREIGNOBJECT, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}); const body = document.createElementNS(dom.HTML_NS, 'body'); body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea') as - HTMLTextAreaElement; + HTMLTextAreaElement; const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -164,28 +164,28 @@ export class Comment extends Icon { // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. this.onMouseUpWrapper_ = browserEvents.conditionalBind( - textarea, 'mouseup', this, this.startEdit_, true, true); + textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. this.onWheelWrapper_ = browserEvents.conditionalBind( - textarea, 'wheel', this, function (e: AnyDuringMigration) { - e.stopPropagation(); - }); + textarea, 'wheel', this, function(e: AnyDuringMigration) { + e.stopPropagation(); + }); this.onChangeWrapper_ = browserEvents.conditionalBind( - textarea, 'change', this, - /** @param _e Unused event parameter. */ - function (this: Comment, _e: Event) { - if (this.cachedText_ !== this.model_.text) { - eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this.block_, 'comment', null, this.cachedText_, - this.model_.text)); - } - }); + textarea, 'change', this, + /** @param _e Unused event parameter. */ + function(this: Comment, _e: Event) { + if (this.cachedText_ !== this.model_.text) { + eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! + (this.block_, 'comment', null, this.cachedText_, + this.model_.text)); + } + }); this.onInputWrapper_ = browserEvents.conditionalBind( - textarea, 'input', this, - /** @param _e Unused event parameter. */ - function (this: Comment, _e: Event) { - this.model_.text = textarea.value; - }); + textarea, 'input', this, + /** @param _e Unused event parameter. */ + function(this: Comment, _e: Event) { + this.model_.text = textarea.value; + }); setTimeout(textarea.focus.bind(textarea), 0); @@ -228,11 +228,11 @@ export class Comment extends Icon { // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.foreignObject_!.setAttribute( - 'width', widthMinusBorder as AnyDuringMigration); + 'width', widthMinusBorder as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.foreignObject_!.setAttribute( - 'height', heightMinusBorder as AnyDuringMigration); + 'height', heightMinusBorder as AnyDuringMigration); this.textarea_!.style.width = widthMinusBorder - 4 + 'px'; this.textarea_!.style.height = heightMinusBorder - 4 + 'px'; } @@ -246,7 +246,7 @@ export class Comment extends Icon { return; } eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))! - (this.block_, visible, 'comment')); + (this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { this.createBubble_(); @@ -270,9 +270,9 @@ export class Comment extends Icon { /** Show an editable bubble. */ private createEditableBubble_() { this.bubble_ = new Bubble( - (this.block_.workspace), this.createEditor_(), - this.block_.pathObject.svgPath, (this.iconXY_ as Coordinate), - this.model_.size.width, this.model_.size.height); + (this.block_.workspace), this.createEditor_(), + this.block_.pathObject.svgPath, (this.iconXY_ as Coordinate), + this.model_.size.width, this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerResizeEvent(this.onBubbleResize_.bind(this)); @@ -288,9 +288,9 @@ export class Comment extends Icon { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. this.paragraphElement_ = - Bubble.textToDom(this.block_.getCommentText() as AnyDuringMigration); + Bubble.textToDom(this.block_.getCommentText() as AnyDuringMigration); this.bubble_ = Bubble.createNonEditableBubble( - this.paragraphElement_, (this.block_), this.iconXY_ as Coordinate); + this.paragraphElement_, (this.block_), this.iconXY_ as Coordinate); this.applyColour(); } diff --git a/core/common.ts b/core/common.ts index d258926eb..f77a64b5d 100644 --- a/core/common.ts +++ b/core/common.ts @@ -37,16 +37,16 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; -import { BlockDefinition, Blocks } from './blocks.js'; +import {Block} from './block.js'; +import {BlockDefinition, Blocks} from './blocks.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from './connection.js'; +import {Connection} from './connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ICopyable } from './interfaces/i_copyable.js'; +import {ICopyable} from './interfaces/i_copyable.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -78,14 +78,14 @@ export function setMainWorkspace(workspace: Workspace) { /** * Currently selected block. */ -let selected: ICopyable | null = null; +let selected: ICopyable|null = null; /** * Returns the currently selected block. * @return The currently selected block. * @alias Blockly.common.getSelected */ -export function getSelected(): ICopyable | null { +export function getSelected(): ICopyable|null { return selected; } @@ -96,14 +96,14 @@ export function getSelected(): ICopyable | null { * @param newSelection The newly selected block. * @alias Blockly.common.setSelected */ -export function setSelected(newSelection: ICopyable | null) { +export function setSelected(newSelection: ICopyable|null) { selected = newSelection; } /** * Container element in which to render the WidgetDiv, DropDownDiv and Tooltip. */ -let parentContainer: Element | null; +let parentContainer: Element|null; /** * Get the container element in which to render the WidgetDiv, DropDownDiv and\ @@ -111,7 +111,7 @@ let parentContainer: Element | null; * @return The parent container. * @alias Blockly.common.getParentContainer */ -export function getParentContainer(): Element | null { +export function getParentContainer(): Element|null { return parentContainer; } @@ -178,7 +178,7 @@ export const draggingConnections: Connection[] = []; * @alias Blockly.common.getBlockTypeCounts */ export function getBlockTypeCounts( - block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { + block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { const typeCountsMap = Object.create(null); const descendants = block.getDescendants(true); if (opt_stripFollowing) { @@ -206,7 +206,7 @@ export function getBlockTypeCounts( * of jsonDef. */ function jsonInitFactory(jsonDef: AnyDuringMigration): () => void { - return function (this: Block) { + return function(this: Block) { this.jsonInit(jsonDef); }; } @@ -230,8 +230,8 @@ export function defineBlocksWithJsonArray(jsonArray: AnyDuringMigration[]) { * @alias Blockly.common.defineBlocksWithJsonArray */ export function createBlockDefinitionsFromJsonArray( - jsonArray: AnyDuringMigration[]): { [key: string]: BlockDefinition } { - const blocks: { [key: string]: BlockDefinition } = {}; + jsonArray: AnyDuringMigration[]): {[key: string]: BlockDefinition} { + const blocks: {[key: string]: BlockDefinition} = {}; for (let i = 0; i < jsonArray.length; i++) { const elem = jsonArray[i]; if (!elem) { @@ -241,11 +241,11 @@ export function createBlockDefinitionsFromJsonArray( const type = elem['type']; if (!type) { console.warn( - `Block definition #${i} in JSON array is missing a type attribute. ` + - 'Skipping.'); + `Block definition #${i} in JSON array is missing a type attribute. ` + + 'Skipping.'); continue; } - blocks[type] = { init: jsonInitFactory(elem) }; + blocks[type] = {init: jsonInitFactory(elem)}; } return blocks; } @@ -257,7 +257,7 @@ export function createBlockDefinitionsFromJsonArray( * type names to block definitions. * @alias Blockly.common.defineBlocks */ -export function defineBlocks(blocks: { [key: string]: BlockDefinition }) { +export function defineBlocks(blocks: {[key: string]: BlockDefinition}) { // Iterate over own enumerable properties. for (const type of Object.keys(blocks)) { const definition = blocks[type]; diff --git a/core/component_manager.ts b/core/component_manager.ts index 741194640..c58934c27 100644 --- a/core/component_manager.ts +++ b/core/component_manager.ts @@ -14,23 +14,23 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IAutoHideable } from './interfaces/i_autohideable.js'; +import {IAutoHideable} from './interfaces/i_autohideable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IComponent } from './interfaces/i_component.js'; +import {IComponent} from './interfaces/i_component.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDeleteArea } from './interfaces/i_delete_area.js'; +import {IDeleteArea} from './interfaces/i_delete_area.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPositionable } from './interfaces/i_positionable.js'; +import {IPositionable} from './interfaces/i_positionable.js'; import * as arrayUtils from './utils/array.js'; class Capability { - static POSITIONABLE = new Capability < IPositionable > ('positionable'); - static DRAG_TARGET = new Capability < IDragTarget > ('drag_target'); - static DELETE_AREA = new Capability < IDeleteArea > ('delete_area'); - static AUTOHIDEABLE = new Capability < IAutoHideable > ('autohideable'); + static POSITIONABLE = new Capability('positionable'); + static DRAG_TARGET = new Capability('drag_target'); + static DELETE_AREA = new Capability('delete_area'); + static AUTOHIDEABLE = new Capability('autohideable'); private readonly name_: string; /** @param name The name of the component capability. */ constructor(name: string) { @@ -54,8 +54,8 @@ export class ComponentManager { static Capability = Capability; // static Capability: AnyDuringMigration; - private readonly componentData_: { [key: string]: ComponentDatum }; - private readonly capabilityToComponentIds_: { [key: string]: string[] }; + private readonly componentData_: {[key: string]: ComponentDatum}; + private readonly capabilityToComponentIds_: {[key: string]: string[]}; /** Creates a new ComponentManager instance. */ constructor() { @@ -79,8 +79,8 @@ export class ComponentManager { const id = componentInfo.component.id; if (!opt_allowOverrides && this.componentData_[id]) { throw Error( - 'Plugin "' + id + '" with capabilities "' + - this.componentData_[id].capabilities + '" already added.'); + 'Plugin "' + id + '" with capabilities "' + + this.componentData_[id].capabilities + '" already added.'); } this.componentData_[id] = componentInfo; const stringCapabilities = []; @@ -117,15 +117,15 @@ export class ComponentManager { * @param id The ID of the component to add the capability to. * @param capability The capability to add. */ - addCapability(id: string, capability: string | Capability) { + addCapability(id: string, capability: string|Capability) { if (!this.getComponent(id)) { throw Error( - 'Cannot add capability, "' + capability + '". Plugin "' + id + - '" has not been added to the ComponentManager'); + 'Cannot add capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (this.hasCapability(id, capability)) { console.warn( - 'Plugin "' + id + 'already has capability "' + capability + '"'); + 'Plugin "' + id + 'already has capability "' + capability + '"'); return; } capability = String(capability).toLowerCase(); @@ -138,16 +138,16 @@ export class ComponentManager { * @param id The ID of the component to remove the capability from. * @param capability The capability to remove. */ - removeCapability(id: string, capability: string | Capability) { + removeCapability(id: string, capability: string|Capability) { if (!this.getComponent(id)) { throw Error( - 'Cannot remove capability, "' + capability + '". Plugin "' + id + - '" has not been added to the ComponentManager'); + 'Cannot remove capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (!this.hasCapability(id, capability)) { console.warn( - 'Plugin "' + id + 'doesn\'t have capability "' + capability + - '" to remove'); + 'Plugin "' + id + 'doesn\'t have capability "' + capability + + '" to remove'); return; } capability = String(capability).toLowerCase(); @@ -161,7 +161,7 @@ export class ComponentManager { * @param capability The capability to check for. * @return Whether the component has the capability. */ - hasCapability(id: string, capability: string | Capability): boolean { + hasCapability(id: string, capability: string|Capability): boolean { capability = String(capability).toLowerCase(); return this.componentData_[id].capabilities.indexOf(capability) !== -1; } @@ -171,7 +171,7 @@ export class ComponentManager { * @param id The ID of the component to get. * @return The component with the given name or undefined if not found. */ - getComponent(id: string): IComponent | undefined { + getComponent(id: string): IComponent|undefined { return this.componentData_[id] && this.componentData_[id].component; } @@ -181,7 +181,7 @@ export class ComponentManager { * @param sorted Whether to return list ordered by weights. * @return The components that match the specified capability. */ - getComponents(capability: string | Capability, sorted: boolean): T[] { + getComponents(capability: string|Capability, sorted: boolean): T[] { capability = String(capability).toLowerCase(); const componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { @@ -191,18 +191,18 @@ export class ComponentManager { if (sorted) { const componentDataList: AnyDuringMigration[] = []; const componentData = this.componentData_; - componentIds.forEach(function (id) { + componentIds.forEach(function(id) { componentDataList.push(componentData[id]); }); - componentDataList.sort(function (a, b) { + componentDataList.sort(function(a, b) { return a.weight - b.weight; }); - componentDataList.forEach(function (ComponentDatum) { + componentDataList.forEach(function(ComponentDatum) { components.push(ComponentDatum.component); }); } else { const componentData = this.componentData_; - componentIds.forEach(function (id) { + componentIds.forEach(function(id) { components.push(componentData[id].component); }); } @@ -211,6 +211,6 @@ export class ComponentManager { } export interface ComponentDatum { component: IComponent; - capabilities: Array>; + capabilities: Array>; weight: number; } \ No newline at end of file diff --git a/core/connection.ts b/core/connection.ts index d6473af39..0102e6c17 100644 --- a/core/connection.ts +++ b/core/connection.ts @@ -16,17 +16,17 @@ import './constants'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; -import { ConnectionType } from './connection_type.js'; +import {Block} from './block.js'; +import {ConnectionType} from './connection_type.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockMove } from './events/events_block_move.js'; +import {BlockMove} from './events/events_block_move.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from './input.js'; +import {Input} from './input.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationWithBlock } from './interfaces/i_ast_node_location_with_block.js'; +import {IASTNodeLocationWithBlock} from './interfaces/i_ast_node_location_with_block.js'; /* eslint-disable-next-line no-unused-vars */ -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; import * as blocks from './serialization/blocks.js'; import * as Xml from './xml.js'; @@ -48,7 +48,7 @@ export class Connection implements IASTNodeLocationWithBlock { static REASON_PREVIOUS_AND_OUTPUT = 8; /** Connection this connection connects to. Null if not connected. */ - targetConnection: Connection | null = null; + targetConnection: Connection|null = null; /** Has this connection been disposed of? */ disposed = false; @@ -68,7 +68,7 @@ export class Connection implements IASTNodeLocationWithBlock { /** Vertical location of this connection. */ y = 0; - private shadowState_: blocks.State | null = null; + private shadowState_: blocks.State|null = null; /** * @param source The block establishing this connection. @@ -110,7 +110,7 @@ export class Connection implements IASTNodeLocationWithBlock { let event; if (eventUtils.isEnabled()) { event = - new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove; + new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove; } connectReciprocally(parentConnection, childConnection); childBlock.setParent(parentBlock); @@ -122,10 +122,10 @@ export class Connection implements IASTNodeLocationWithBlock { // Deal with the orphan if it exists. if (orphan) { const orphanConnection = parentConnection.type === INPUT ? - orphan.outputConnection : - orphan.previousConnection; + orphan.outputConnection : + orphan.previousConnection; const connection = Connection.getConnectionForOrphanedConnection( - childBlock, (orphanConnection)); + childBlock, (orphanConnection)); if (connection) { orphanConnection.connect(connection); } else { @@ -166,7 +166,7 @@ export class Connection implements IASTNodeLocationWithBlock { */ isSuperior(): boolean { return this.type === ConnectionType.INPUT_VALUE || - this.type === ConnectionType.NEXT_STATEMENT; + this.type === ConnectionType.NEXT_STATEMENT; } /** @@ -274,7 +274,7 @@ export class Connection implements IASTNodeLocationWithBlock { let event; if (eventUtils.isEnabled()) { event = - new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove; + new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove; } const otherConnection = this.targetConnection; if (otherConnection) { @@ -300,7 +300,7 @@ export class Connection implements IASTNodeLocationWithBlock { * Returns the block that this connection connects to. * @return The connected block or null if none is connected. */ - targetBlock(): Block | null { + targetBlock(): Block|null { if (this.isConnected()) { return this.targetConnection?.getSourceBlock() ?? null; } @@ -313,9 +313,9 @@ export class Connection implements IASTNodeLocationWithBlock { protected onCheckChanged_() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && - (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.source; child!.unplug(); } @@ -327,7 +327,7 @@ export class Connection implements IASTNodeLocationWithBlock { * types are compatible. * @return The connection being modified (to allow chaining). */ - setCheck(check: string | string[] | null): Connection { + setCheck(check: string|string[]|null): Connection { if (check) { // Ensure that check is in an array. if (!Array.isArray(check)) { @@ -348,7 +348,7 @@ export class Connection implements IASTNodeLocationWithBlock { * @return List of compatible value types. * Null if all types are compatible. */ - getCheck(): AnyDuringMigration[] | null { + getCheck(): AnyDuringMigration[]|null { return this.check_; } @@ -356,8 +356,8 @@ export class Connection implements IASTNodeLocationWithBlock { * Changes the connection's shadow block. * @param shadowDom DOM representation of a block or null. */ - setShadowDom(shadowDom: Element | null) { - this.setShadowStateInternal_({ shadowDom }); + setShadowDom(shadowDom: Element|null) { + this.setShadowStateInternal_({shadowDom}); } /** @@ -368,18 +368,18 @@ export class Connection implements IASTNodeLocationWithBlock { * just returned. * @return Shadow DOM representation of a block or null. */ - getShadowDom(returnCurrent?: boolean): Element | null { + getShadowDom(returnCurrent?: boolean): Element|null { return returnCurrent && this.targetBlock()!.isShadow() ? - Xml.blockToDom((this.targetBlock() as Block)) as Element : - this.shadowDom_; + Xml.blockToDom((this.targetBlock() as Block)) as Element : + this.shadowDom_; } /** * Changes the connection's shadow block. * @param shadowState An state represetation of the block or null. */ - setShadowState(shadowState: blocks.State | null) { - this.setShadowStateInternal_({ shadowState }); + setShadowState(shadowState: blocks.State|null) { + this.setShadowStateInternal_({shadowState}); } /** @@ -391,7 +391,7 @@ export class Connection implements IASTNodeLocationWithBlock { * returned. * @return Serialized object representation of the block, or null. */ - getShadowState(returnCurrent?: boolean): blocks.State | null { + getShadowState(returnCurrent?: boolean): blocks.State|null { if (returnCurrent && this.targetBlock() && this.targetBlock()!.isShadow()) { return blocks.save(this.targetBlock() as Block); } @@ -418,7 +418,7 @@ export class Connection implements IASTNodeLocationWithBlock { * @return The input that the connection belongs to or null if no parent * exists. */ - getParentInput(): Input | null { + getParentInput(): Input|null { let parentInput = null; const inputs = this.source.inputList; for (let i = 0; i < inputs.length; i++) { @@ -470,7 +470,8 @@ export class Connection implements IASTNodeLocationWithBlock { * temporarily sets those properties to null so no shadow respawns. * @return The state of both the shadowDom_ and shadowState_ properties. */ - private stashShadowState_(): { shadowDom: Element | null, shadowState: blocks.State | null } { + private stashShadowState_(): + {shadowDom: Element|null, shadowState: blocks.State|null} { const shadowDom = this.getShadowDom(true); const shadowState = this.getShadowState(true); // Set to null so it doesn't respawn. @@ -478,7 +479,7 @@ export class Connection implements IASTNodeLocationWithBlock { // 'Element'. this.shadowDom_ = null as AnyDuringMigration; this.shadowState_ = null; - return { shadowDom, shadowState }; + return {shadowDom, shadowState}; } /** @@ -486,9 +487,9 @@ export class Connection implements IASTNodeLocationWithBlock { * @param param0 The state to reapply to the shadowDom_ and shadowState_ * properties. */ - private applyShadowState_({ shadowDom, shadowState }: { - shadowDom: Element | null, - shadowState: blocks.State | null + private applyShadowState_({shadowDom, shadowState}: { + shadowDom: Element|null, + shadowState: blocks.State|null }) { // AnyDuringMigration because: Type 'Element | null' is not assignable to // type 'Element'. @@ -500,9 +501,9 @@ export class Connection implements IASTNodeLocationWithBlock { * Sets the state of the shadow of this connection. * @param param0 The state to set the shadow of this connection to. */ - private setShadowStateInternal_({ shadowDom = null, shadowState = null }: { - shadowDom?: Element | null, - shadowState?: blocks.State | null + private setShadowStateInternal_({shadowDom = null, shadowState = null}: { + shadowDom?: Element|null, + shadowState?: blocks.State|null } = {}) { // One or both of these should always be null. // If neither is null, the shadowState will get priority. @@ -540,7 +541,7 @@ export class Connection implements IASTNodeLocationWithBlock { * @return The shadow block that was created, or null if both the shadowState_ * and shadowDom_ are null. */ - private createShadowBlock_(attemptToConnect: boolean): Block | null { + private createShadowBlock_(attemptToConnect: boolean): Block|null { const parentBlock = this.getSourceBlock(); const shadowState = this.getShadowState(); const shadowDom = this.getShadowDom(); @@ -577,7 +578,7 @@ export class Connection implements IASTNodeLocationWithBlock { } } else { throw new Error( - 'Cannot connect a shadow block to a previous/output connection'); + 'Cannot connect a shadow block to a previous/output connection'); } } return blockShadow; @@ -590,7 +591,7 @@ export class Connection implements IASTNodeLocationWithBlock { * properties, in their respective serialized forms. * @param shadow The shadow to serialize, or null. */ - private serializeShadow_(shadow: Block | null) { + private serializeShadow_(shadow: Block|null) { if (!shadow) { return; } @@ -607,10 +608,10 @@ export class Connection implements IASTNodeLocationWithBlock { * @return The suitable connection point on the chain of blocks, or null. */ static getConnectionForOrphanedConnection( - startBlock: Block, orphanConnection: Connection): Connection | null { + startBlock: Block, orphanConnection: Connection): Connection|null { if (orphanConnection.type === ConnectionType.OUTPUT_VALUE) { return getConnectionForOrphanedOutput( - startBlock, orphanConnection.getSourceBlock()); + startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. const connection = startBlock.lastConnectionInStack(true); @@ -643,8 +644,8 @@ function connectReciprocally(first: Connection, second: Connection) { * @param orphanBlock The inferior block. * @return The suitable connection point on 'block', or null. */ -function getSingleConnection(block: Block, orphanBlock: Block): Connection | - null { +function getSingleConnection(block: Block, orphanBlock: Block): Connection| + null { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -673,7 +674,7 @@ function getSingleConnection(block: Block, orphanBlock: Block): Connection | * @return The suitable connection point on the chain of blocks, or null. */ function getConnectionForOrphanedOutput( - startBlock: Block, orphanBlock: Block): Connection | null { + startBlock: Block, orphanBlock: Block): Connection|null { let newBlock = startBlock; let connection; while (connection = getSingleConnection((newBlock), orphanBlock)) { diff --git a/core/connection_checker.ts b/core/connection_checker.ts index 5bbcfd572..18508fccd 100644 --- a/core/connection_checker.ts +++ b/core/connection_checker.ts @@ -17,14 +17,14 @@ */ import * as common from './common.js'; -import { Connection } from './connection.js'; -import { ConnectionType } from './connection_type.js'; +import {Connection} from './connection.js'; +import {ConnectionType} from './connection_type.js'; /* eslint-disable-next-line no-unused-vars */ -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; import * as internalConstants from './internal_constants.js'; import * as registry from './registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from './rendered_connection.js'; +import {RenderedConnection} from './rendered_connection.js'; /** @@ -43,10 +43,10 @@ export class ConnectionChecker implements IConnectionChecker { * @return Whether the connection is legal. */ canConnect( - a: Connection | null, b: Connection | null, isDragging: boolean, - opt_distance?: number): boolean { + a: Connection|null, b: Connection|null, isDragging: boolean, + opt_distance?: number): boolean { return this.canConnectWithReason(a, b, isDragging, opt_distance) === - Connection.CAN_CONNECT; + Connection.CAN_CONNECT; } /** @@ -61,8 +61,8 @@ export class ConnectionChecker implements IConnectionChecker { * otherwise. */ canConnectWithReason( - a: Connection | null, b: Connection | null, isDragging: boolean, - opt_distance?: number): number { + a: Connection|null, b: Connection|null, isDragging: boolean, + opt_distance?: number): number { const safety = this.doSafetyChecks(a, b); if (safety !== Connection.CAN_CONNECT) { return safety; @@ -76,9 +76,9 @@ export class ConnectionChecker implements IConnectionChecker { } if (isDragging && - !this.doDragChecks( - a as RenderedConnection, b as RenderedConnection, - opt_distance || 0)) { + !this.doDragChecks( + a as RenderedConnection, b as RenderedConnection, + opt_distance || 0)) { return Connection.REASON_DRAG_CHECKS_FAILED; } @@ -92,8 +92,8 @@ export class ConnectionChecker implements IConnectionChecker { * @param b The second of the two connections being checked. * @return A developer-readable error string. */ - getErrorMessage(errorCode: number, a: Connection | null, b: Connection | null): - string { + getErrorMessage(errorCode: number, a: Connection|null, b: Connection|null): + string { switch (errorCode) { case Connection.REASON_SELF_CONNECTION: return 'Attempted to connect a block to itself.'; @@ -109,7 +109,7 @@ export class ConnectionChecker implements IConnectionChecker { const connTwo = b!; let msg = 'Connection checks failed. '; msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + - connTwo.getCheck(); + connTwo.getCheck(); return msg; } case Connection.REASON_SHADOW_PARENT: @@ -130,7 +130,7 @@ export class ConnectionChecker implements IConnectionChecker { * @param b The second of the connections to check. * @return An enum with the reason this connection is safe or unsafe. */ - doSafetyChecks(a: Connection | null, b: Connection | null): number { + doSafetyChecks(a: Connection|null, b: Connection|null): number { if (!a || !b) { return Connection.REASON_TARGET_NULL; } @@ -152,22 +152,22 @@ export class ConnectionChecker implements IConnectionChecker { if (superiorBlock === inferiorBlock) { return Connection.REASON_SELF_CONNECTION; } else if ( - inferiorConnection.type !== - internalConstants.OPPOSITE_TYPE[superiorConnection.type]) { + inferiorConnection.type !== + internalConstants.OPPOSITE_TYPE[superiorConnection.type]) { return Connection.REASON_WRONG_TYPE; } else if (superiorBlock.workspace !== inferiorBlock.workspace) { return Connection.REASON_DIFFERENT_WORKSPACES; } else if (superiorBlock.isShadow() && !inferiorBlock.isShadow()) { return Connection.REASON_SHADOW_PARENT; } else if ( - inferiorConnection.type === ConnectionType.OUTPUT_VALUE && - inferiorBlock.previousConnection && - inferiorBlock.previousConnection.isConnected()) { + inferiorConnection.type === ConnectionType.OUTPUT_VALUE && + inferiorBlock.previousConnection && + inferiorBlock.previousConnection.isConnected()) { return Connection.REASON_PREVIOUS_AND_OUTPUT; } else if ( - inferiorConnection.type === ConnectionType.PREVIOUS_STATEMENT && - inferiorBlock.outputConnection && - inferiorBlock.outputConnection.isConnected()) { + inferiorConnection.type === ConnectionType.PREVIOUS_STATEMENT && + inferiorBlock.outputConnection && + inferiorBlock.outputConnection.isConnected()) { return Connection.REASON_PREVIOUS_AND_OUTPUT; } return Connection.CAN_CONNECT; @@ -207,7 +207,7 @@ export class ConnectionChecker implements IConnectionChecker { * @return True if the connection is allowed during a drag. */ doDragChecks(a: RenderedConnection, b: RenderedConnection, distance: number): - boolean { + boolean { // AnyDuringMigration because: Argument of type 'RenderedConnection' is not // assignable to parameter of type 'Connection'. if (a.distanceFrom(b as AnyDuringMigration) > distance) { @@ -228,7 +228,7 @@ export class ConnectionChecker implements IConnectionChecker { // Don't offer to connect an already connected left (male) value plug to // an available right (female) value plug. if (b.isConnected() && !b.targetBlock()!.isInsertionMarker() || - a.isConnected()) { + a.isConnected()) { return false; } break; @@ -238,7 +238,7 @@ export class ConnectionChecker implements IConnectionChecker { // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. if (b.isConnected() && !b.targetBlock()!.isMovable() && - !b.targetBlock()!.isShadow()) { + !b.targetBlock()!.isShadow()) { return false; } break; @@ -249,7 +249,7 @@ export class ConnectionChecker implements IConnectionChecker { // is fine. Similarly, replacing a terminal statement with another // terminal statement is allowed. if (b.isConnected() && !a.getSourceBlock().nextConnection && - !b.targetBlock()!.isShadow() && b.targetBlock()!.nextConnection) { + !b.targetBlock()!.isShadow() && b.targetBlock()!.nextConnection) { return false; } break; @@ -305,4 +305,4 @@ export class ConnectionChecker implements IConnectionChecker { } registry.register( - registry.Type.CONNECTION_CHECKER, registry.DEFAULT, ConnectionChecker); + registry.Type.CONNECTION_CHECKER, registry.DEFAULT, ConnectionChecker); diff --git a/core/connection_db.ts b/core/connection_db.ts index ad1cbd198..e88a7281b 100644 --- a/core/connection_db.ts +++ b/core/connection_db.ts @@ -21,13 +21,13 @@ // Unused import preserved for side-effects. Remove if unneeded. import './constants'; -import { ConnectionType } from './connection_type.js'; +import {ConnectionType} from './connection_type.js'; /* eslint-disable-next-line no-unused-vars */ -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from './rendered_connection.js'; +import {RenderedConnection} from './rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; /** @@ -66,7 +66,7 @@ export class ConnectionDB { * @return The index of the connection, or -1 if the connection was not found. */ private findIndexOfConnection_(conn: RenderedConnection, yPos: number): - number { + number { if (!this.connections_.length) { return -1; } @@ -89,7 +89,7 @@ export class ConnectionDB { pointer = bestGuess; while (pointer < this.connections_.length && - this.connections_[pointer].y === yPos) { + this.connections_[pointer].y === yPos) { if (this.connections_[pointer] === conn) { return pointer; } @@ -145,7 +145,7 @@ export class ConnectionDB { * @return List of connections. */ getNeighbours(connection: RenderedConnection, maxRadius: number): - RenderedConnection[] { + RenderedConnection[] { const db = this.connections_; const currentX = connection.x; const currentY = connection.y; @@ -206,7 +206,7 @@ export class ConnectionDB { * @return True if connection is in range. */ private isInYRange_(index: number, baseY: number, maxRadius: number): - boolean { + boolean { return Math.abs(this.connections_[index].y - baseY) <= maxRadius; } @@ -220,13 +220,13 @@ export class ConnectionDB { * connection or null, and 'radius' which is the distance. */ searchForClosest( - conn: RenderedConnection, maxRadius: number, - dxy: Coordinate): { connection: RenderedConnection, radius: number } { + conn: RenderedConnection, maxRadius: number, + dxy: Coordinate): {connection: RenderedConnection, radius: number} { if (!this.connections_.length) { // Don't bother. // AnyDuringMigration because: Type 'null' is not assignable to type // 'RenderedConnection'. - return { connection: null as AnyDuringMigration, radius: maxRadius }; + return {connection: null as AnyDuringMigration, radius: maxRadius}; } // Stash the values of x and y from before the drag. @@ -260,7 +260,7 @@ export class ConnectionDB { let pointerMax = closestIndex; while (pointerMax < this.connections_.length && - this.isInYRange_(pointerMax, conn.y, maxRadius)) { + this.isInYRange_(pointerMax, conn.y, maxRadius)) { temp = this.connections_[pointerMax]; if (this.checker.canConnect(conn, temp, true, bestRadius)) { bestConnection = temp; diff --git a/core/contextmenu.ts b/core/contextmenu.ts index f0cbe51a0..9ebb217fa 100644 --- a/core/contextmenu.ts +++ b/core/contextmenu.ts @@ -33,36 +33,36 @@ * @namespace Blockly.ContextMenu */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as clipboard from './clipboard.js'; -import { config } from './config.js'; -import { ContextMenuOption, ContextMenuRegistry, LegacyContextMenuOption } from './contextmenu_registry.js'; +import {config} from './config.js'; +import {ContextMenuOption, ContextMenuRegistry, LegacyContextMenuOption} from './contextmenu_registry.js'; import * as BlockCreate from './events/events_block_create.js'; import * as eventUtils from './events/utils.js'; -import { Menu } from './menu.js'; -import { MenuItem } from './menuitem.js'; -import { Msg } from './msg.js'; +import {Menu} from './menu.js'; +import {MenuItem} from './menuitem.js'; +import {Msg} from './msg.js'; import * as aria from './utils/aria.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as deprecation from './utils/deprecation.js'; import * as dom from './utils/dom.js'; -import { Rect } from './utils/rect.js'; +import {Rect} from './utils/rect.js'; import * as svgMath from './utils/svg_math.js'; import * as userAgent from './utils/useragent.js'; import * as WidgetDiv from './widgetdiv.js'; -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; /** * Which block is the context menu attached to? */ -let currentBlock: Block | null = null; +let currentBlock: Block|null = null; let dummyOwner = {}; @@ -71,7 +71,7 @@ let dummyOwner = {}; * @return The block the context menu is attached to. * @alias Blockly.ContextMenu.getCurrentBlock */ -export function getCurrentBlock(): Block | null { +export function getCurrentBlock(): Block|null { return currentBlock; } @@ -80,14 +80,14 @@ export function getCurrentBlock(): Block | null { * @param block The block the context menu is attached to. * @alias Blockly.ContextMenu.setCurrentBlock */ -export function setCurrentBlock(block: Block | null) { +export function setCurrentBlock(block: Block|null) { currentBlock = block; } /** * Menu object. */ -let menu_: Menu | null = null; +let menu_: Menu|null = null; /** * Construct the menu based on the list of options and show the menu. @@ -97,8 +97,8 @@ let menu_: Menu | null = null; * @alias Blockly.ContextMenu.show */ export function show( - e: Event, options: (ContextMenuOption | LegacyContextMenuOption)[], - rtl: boolean) { + e: Event, options: (ContextMenuOption|LegacyContextMenuOption)[], + rtl: boolean) { WidgetDiv.show(dummyOwner, rtl, dispose); if (!options.length) { hide(); @@ -110,7 +110,7 @@ export function show( position_(menu, e, rtl); // 1ms delay is required for focusing on context menus because some other // mouse event is still waiting in the queue and clears focus. - setTimeout(function () { + setTimeout(function() { menu.focus(); }, 1); currentBlock = null; @@ -124,8 +124,8 @@ export function show( * @return The menu that will be shown on right click. */ function populate_( - options: (ContextMenuOption | LegacyContextMenuOption)[], - rtl: boolean): Menu { + options: (ContextMenuOption|LegacyContextMenuOption)[], + rtl: boolean): Menu { /* Here's what one option object looks like: {text: 'Make It So', enabled: true, @@ -141,7 +141,7 @@ function populate_( menu.addChild(menuItem); menuItem.setEnabled(option.enabled); if (option.enabled) { - const actionHandler = function (this: ContextMenuOption) { + const actionHandler = function(this: ContextMenuOption) { hide(); this.callback(this.scope); }; @@ -165,10 +165,10 @@ function position_(menu: Menu, e: Event, rtl: boolean) { // This one is just a point, but we'll pretend that it's a rect so we can use // some helper functions. const anchorBBox = new Rect( - mouseEvent.clientY + viewportBBox.top, - mouseEvent.clientY + viewportBBox.top, - mouseEvent.clientX + viewportBBox.left, - mouseEvent.clientX + viewportBBox.left); + mouseEvent.clientY + viewportBBox.top, + mouseEvent.clientY + viewportBBox.top, + mouseEvent.clientX + viewportBBox.left, + mouseEvent.clientX + viewportBBox.left); createWidget_(menu); const menuSize = menu.getSize(); @@ -201,7 +201,7 @@ function createWidget_(menu: Menu) { dom.addClass((menuDom as Element), 'blocklyContextMenu'); // Prevent system context menu when right-clicking a Blockly context menu. browserEvents.conditionalBind( - (menuDom as EventTarget), 'contextmenu', null, haltPropagation); + (menuDom as EventTarget), 'contextmenu', null, haltPropagation); // Focus only after the initial render to avoid issue #1329. menu.focus(); } @@ -279,11 +279,11 @@ export function callbackFactory(block: Block, xml: Element): Function { * @alias Blockly.ContextMenu.commentDeleteOption */ export function commentDeleteOption(comment: WorkspaceCommentSvg): - LegacyContextMenuOption { + LegacyContextMenuOption { const deleteOption = { text: Msg['REMOVE_COMMENT'], enabled: true, - callback: function () { + callback: function() { eventUtils.setGroup(true); comment.dispose(); eventUtils.setGroup(false); @@ -301,11 +301,11 @@ export function commentDeleteOption(comment: WorkspaceCommentSvg): * @alias Blockly.ContextMenu.commentDuplicateOption */ export function commentDuplicateOption(comment: WorkspaceCommentSvg): - LegacyContextMenuOption { + LegacyContextMenuOption { const duplicateOption = { text: Msg['DUPLICATE_COMMENT'], enabled: true, - callback: function () { + callback: function() { clipboard.duplicate(comment); }, }; @@ -323,13 +323,13 @@ export function commentDuplicateOption(comment: WorkspaceCommentSvg): * @alias Blockly.ContextMenu.workspaceCommentOption */ export function workspaceCommentOption( - ws: WorkspaceSvg, e: Event): ContextMenuOption { + ws: WorkspaceSvg, e: Event): ContextMenuOption { // Helper function to create and position a comment correctly based on the // location of the mouse event. function addWsComment() { const comment = new WorkspaceCommentSvg( - ws, Msg['WORKSPACE_COMMENT_DEFAULT_TEXT'], - WorkspaceCommentSvg.DEFAULT_SIZE, WorkspaceCommentSvg.DEFAULT_SIZE); + ws, Msg['WORKSPACE_COMMENT_DEFAULT_TEXT'], + WorkspaceCommentSvg.DEFAULT_SIZE, WorkspaceCommentSvg.DEFAULT_SIZE); const injectionDiv = ws.getInjectionDiv(); // Bounding rect coordinates are in client coordinates, meaning that they @@ -340,8 +340,8 @@ export function workspaceCommentOption( // The client coordinates offset by the injection div's upper left corner. const mouseEvent = e as MouseEvent; const clientOffsetPixels = new Coordinate( - mouseEvent.clientX - boundingRect.left, - mouseEvent.clientY - boundingRect.top); + mouseEvent.clientX - boundingRect.left, + mouseEvent.clientY - boundingRect.top); // The offset in pixels between the main workspace's origin and the upper // left corner of the injection div. @@ -350,7 +350,7 @@ export function workspaceCommentOption( // The position of the new comment in pixels relative to the origin of the // main workspace. const finalOffset = - Coordinate.difference(clientOffsetPixels, mainOffsetPixels); + Coordinate.difference(clientOffsetPixels, mainOffsetPixels); // The position of the new comment in main workspace coordinates. finalOffset.scale(1 / ws.scale); @@ -370,7 +370,7 @@ export function workspaceCommentOption( enabled: !userAgent.IE, } as ContextMenuOption; wsCommentOption.text = Msg['ADD_COMMENT']; - wsCommentOption.callback = function () { + wsCommentOption.callback = function() { addWsComment(); }; return wsCommentOption; diff --git a/core/contextmenu_items.ts b/core/contextmenu_items.ts index bc7a9bdc9..ee1fdcce4 100644 --- a/core/contextmenu_items.ts +++ b/core/contextmenu_items.ts @@ -12,18 +12,18 @@ * @namespace Blockly.ContextMenuItems */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as clipboard from './clipboard.js'; -import { ContextMenuRegistry, RegistryItem, Scope } from './contextmenu_registry.js'; +import {ContextMenuRegistry, RegistryItem, Scope} from './contextmenu_registry.js'; import * as dialog from './dialog.js'; import * as Events from './events/events.js'; import * as eventUtils from './events/utils.js'; -import { inputTypes } from './input_types.js'; -import { Msg } from './msg.js'; +import {inputTypes} from './input_types.js'; +import {Msg} from './msg.js'; import * as idGenerator from './utils/idgenerator.js'; import * as userAgent from './utils/useragent.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -275,7 +275,7 @@ export function registerDeleteAll() { return Msg['DELETE_BLOCK']; } else { return Msg['DELETE_X_BLOCKS'].replace( - '%1', String(deletableBlocksLength)); + '%1', String(deletableBlocksLength)); } }, preconditionFn(scope: Scope) { @@ -296,13 +296,13 @@ export function registerDeleteAll() { deleteNext_(deletableBlocks, eventGroup); } else { dialog.confirm( - Msg['DELETE_ALL_BLOCKS'].replace( - '%1', String(deletableBlocks.length)), - function (ok) { - if (ok) { - deleteNext_(deletableBlocks, eventGroup); - } - }); + Msg['DELETE_ALL_BLOCKS'].replace( + '%1', String(deletableBlocks.length)), + function(ok) { + if (ok) { + deleteNext_(deletableBlocks, eventGroup); + } + }); } }, scopeType: ContextMenuRegistry.ScopeType.WORKSPACE, @@ -370,8 +370,8 @@ export function registerComment() { const block = scope.block; // IE doesn't support necessary features for comment editing. if (!userAgent.IE && !block!.isInFlyout && - block!.workspace.options.comments && !block!.isCollapsed() && - block!.isEditable()) { + block!.workspace.options.comments && !block!.isCollapsed() && + block!.isEditable()) { return 'enabled'; } return 'hidden'; @@ -399,7 +399,7 @@ export function registerInline() { const inlineOption: RegistryItem = { displayText(scope: Scope) { return scope.block!.getInputsInline() ? Msg['EXTERNAL_INPUTS'] : - Msg['INLINE_INPUTS']; + Msg['INLINE_INPUTS']; }, preconditionFn(scope: Scope) { const block = scope.block; @@ -408,7 +408,7 @@ export function registerInline() { // Only display this option if there are two value or dummy inputs // next to each other. if (block!.inputList[i - 1].type !== inputTypes.STATEMENT && - block!.inputList[i].type !== inputTypes.STATEMENT) { + block!.inputList[i].type !== inputTypes.STATEMENT) { return 'enabled'; } } @@ -433,12 +433,12 @@ export function registerCollapseExpandBlock() { const collapseExpandOption: RegistryItem = { displayText(scope: Scope) { return scope.block!.isCollapsed() ? Msg['EXPAND_BLOCK'] : - Msg['COLLAPSE_BLOCK']; + Msg['COLLAPSE_BLOCK']; }, preconditionFn(scope: Scope) { const block = scope.block; if (!block!.isInFlyout && block!.isMovable() && - block!.workspace.options.collapse) { + block!.workspace.options.collapse) { return 'enabled'; } return 'hidden'; @@ -461,12 +461,12 @@ export function registerDisable() { const disableOption: RegistryItem = { displayText(scope: Scope) { return scope.block!.isEnabled() ? Msg['DISABLE_BLOCK'] : - Msg['ENABLE_BLOCK']; + Msg['ENABLE_BLOCK']; }, preconditionFn(scope: Scope) { const block = scope.block; if (!block!.isInFlyout && block!.workspace.options.disable && - block!.isEditable()) { + block!.isEditable()) { if (block!.getInheritedDisabled()) { return 'disabled'; } @@ -508,8 +508,8 @@ export function registerDelete() { descendantCount -= nextBlock.getDescendants(false).length; } return descendantCount === 1 ? - Msg['DELETE_BLOCK'] : - Msg['DELETE_X_BLOCKS'].replace('%1', String(descendantCount)); + Msg['DELETE_BLOCK'] : + Msg['DELETE_X_BLOCKS'].replace('%1', String(descendantCount)); }, preconditionFn(scope: Scope) { if (!scope.block!.isInFlyout && scope.block!.isDeletable()) { @@ -541,7 +541,7 @@ export function registerHelp() { preconditionFn(scope: Scope) { const block = scope.block; const url = typeof block!.helpUrl === 'function' ? block!.helpUrl() : - block!.helpUrl; + block!.helpUrl; if (url) { return 'enabled'; } diff --git a/core/contextmenu_registry.ts b/core/contextmenu_registry.ts index 9ae1b1fb3..3cd545660 100644 --- a/core/contextmenu_registry.ts +++ b/core/contextmenu_registry.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; enum ScopeType { @@ -38,7 +38,7 @@ export class ContextMenuRegistry { static ScopeType = ScopeType; static registry: ContextMenuRegistry; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - private registry_!: { [key: string]: RegistryItem }; + private registry_!: {[key: string]: RegistryItem}; /** Resets the existing singleton instance of ContextMenuRegistry. */ constructor() { @@ -79,7 +79,7 @@ export class ContextMenuRegistry { * @param id The ID of the RegistryItem to get. * @return RegistryItem or null if not found */ - getItem(id: string): RegistryItem | null { + getItem(id: string): RegistryItem|null { return this.registry_[id] || null; } @@ -94,17 +94,17 @@ export class ContextMenuRegistry { * @return the list of ContextMenuOptions */ getContextMenuOptions(scopeType: ScopeType, scope: Scope): - ContextMenuOption[] { + ContextMenuOption[] { const menuOptions: AnyDuringMigration[] = []; const registry = this.registry_; - Object.keys(registry).forEach(function (id) { + Object.keys(registry).forEach(function(id) { const item = registry[id]; if (scopeType === item.scopeType) { const precondition = item.preconditionFn(scope); if (precondition !== 'hidden') { const displayText = typeof item.displayText === 'function' ? - item.displayText(scope) : - item.displayText; + item.displayText(scope) : + item.displayText; const menuOption: ContextMenuOption = { text: displayText, enabled: precondition === 'enabled', @@ -116,20 +116,20 @@ export class ContextMenuRegistry { } } }); - menuOptions.sort(function (a, b) { + menuOptions.sort(function(a, b) { return a.weight - b.weight; }); return menuOptions; } } export interface Scope { - block: BlockSvg | undefined; - workspace: WorkspaceSvg | undefined; + block: BlockSvg|undefined; + workspace: WorkspaceSvg|undefined; } export interface RegistryItem { callback: (p1: Scope) => AnyDuringMigration; scopeType: ScopeType; - displayText: ((p1: Scope) => string) | string; + displayText: ((p1: Scope) => string)|string; preconditionFn: (p1: Scope) => string; weight: number; id: string; diff --git a/core/css.ts b/core/css.ts index ad1fc9030..efac5ac92 100644 --- a/core/css.ts +++ b/core/css.ts @@ -24,15 +24,15 @@ let injected = false; * @param cssContent Multiline CSS string or an array of single lines of CSS. * @alias Blockly.Css.register */ -export function register(cssContent: string | string[]) { +export function register(cssContent: string|string[]) { if (injected) { throw Error('CSS already injected'); } if (Array.isArray(cssContent)) { deprecation.warn( - 'Registering CSS by passing an array of strings', 'September 2021', - 'September 2022', 'css.register passing a multiline string'); + 'Registering CSS by passing an array of strings', 'September 2021', + 'September 2022', 'css.register passing a multiline string'); content += '\n' + cssContent.join('\n'); } else { // Add new cssContent in the global content. diff --git a/core/delete_area.ts b/core/delete_area.ts index 76c756ab1..4da8dc7fb 100644 --- a/core/delete_area.ts +++ b/core/delete_area.ts @@ -17,12 +17,12 @@ * @class */ -import { BlockSvg } from './block_svg.js'; -import { DragTarget } from './drag_target.js'; +import {BlockSvg} from './block_svg.js'; +import {DragTarget} from './drag_target.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDeleteArea } from './interfaces/i_delete_area.js'; +import {IDeleteArea} from './interfaces/i_delete_area.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from './interfaces/i_draggable.js'; +import {IDraggable} from './interfaces/i_draggable.js'; /** diff --git a/core/dialog.ts b/core/dialog.ts index bc399f567..d0387be5e 100644 --- a/core/dialog.ts +++ b/core/dialog.ts @@ -16,22 +16,22 @@ * @namespace Blockly.dialog */ -let alertImplementation = function ( - message: AnyDuringMigration, opt_callback: AnyDuringMigration) { +let alertImplementation = function( + message: AnyDuringMigration, opt_callback: AnyDuringMigration) { window.alert(message); if (opt_callback) { opt_callback(); } }; -let confirmImplementation = function ( - message: AnyDuringMigration, callback: AnyDuringMigration) { +let confirmImplementation = function( + message: AnyDuringMigration, callback: AnyDuringMigration) { callback(window.confirm(message)); }; -let promptImplementation = function ( - message: AnyDuringMigration, defaultValue: AnyDuringMigration, - callback: AnyDuringMigration) { +let promptImplementation = function( + message: AnyDuringMigration, defaultValue: AnyDuringMigration, + callback: AnyDuringMigration) { callback(window.prompt(message, defaultValue)); }; @@ -43,7 +43,7 @@ let promptImplementation = function ( * @alias Blockly.dialog.alert */ export function alert( - message: string, opt_callback?: () => AnyDuringMigration) { + message: string, opt_callback?: () => AnyDuringMigration) { alertImplementation(message, opt_callback); } @@ -54,8 +54,8 @@ export function alert( * @alias Blockly.dialog.setAlert */ export function setAlert( - alertFunction: (p1: string, p2?: () => AnyDuringMigration) => - AnyDuringMigration) { + alertFunction: (p1: string, p2?: () => AnyDuringMigration) => + AnyDuringMigration) { alertImplementation = alertFunction; } @@ -67,7 +67,7 @@ export function setAlert( * @alias Blockly.dialog.confirm */ export function confirm( - message: string, callback: (p1: boolean) => AnyDuringMigration) { + message: string, callback: (p1: boolean) => AnyDuringMigration) { confirmImplementation(message, callback); } @@ -78,8 +78,8 @@ export function confirm( * @alias Blockly.dialog.setConfirm */ export function setConfirm( - confirmFunction: (p1: string, p2: (p1: boolean) => AnyDuringMigration) => - AnyDuringMigration) { + confirmFunction: (p1: string, p2: (p1: boolean) => AnyDuringMigration) => + AnyDuringMigration) { confirmImplementation = confirmFunction; } @@ -94,8 +94,8 @@ export function setConfirm( * @alias Blockly.dialog.prompt */ export function prompt( - message: string, defaultValue: string, - callback: (p1: string | null) => AnyDuringMigration) { + message: string, defaultValue: string, + callback: (p1: string|null) => AnyDuringMigration) { promptImplementation(message, defaultValue, callback); } @@ -106,8 +106,8 @@ export function prompt( * @alias Blockly.dialog.setPrompt */ export function setPrompt( - promptFunction: - (p1: string, p2: string, p3: (p1: string | null) => AnyDuringMigration) => - AnyDuringMigration) { + promptFunction: + (p1: string, p2: string, p3: (p1: string|null) => AnyDuringMigration) => + AnyDuringMigration) { promptImplementation = promptFunction; } diff --git a/core/drag_target.ts b/core/drag_target.ts index b968f538d..a836003c4 100644 --- a/core/drag_target.ts +++ b/core/drag_target.ts @@ -18,11 +18,11 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from './interfaces/i_draggable.js'; +import {IDraggable} from './interfaces/i_draggable.js'; /* eslint-disable-next-line no-unused-vars */ -import { Rect } from './utils/rect.js'; +import {Rect} from './utils/rect.js'; /** @@ -79,7 +79,7 @@ export class DragTarget implements IDragTarget { * @return The component's bounding box. Null if drag target area should be * ignored. */ - getClientRect(): Rect | null { + getClientRect(): Rect|null { return null; } diff --git a/core/dropdowndiv.ts b/core/dropdowndiv.ts index 2b43bc128..0d89fffb4 100644 --- a/core/dropdowndiv.ts +++ b/core/dropdowndiv.ts @@ -17,18 +17,18 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as common from './common.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as dom from './utils/dom.js'; import * as math from './utils/math.js'; -import { Rect } from './utils/rect.js'; +import {Rect} from './utils/rect.js'; /* eslint-disable-next-line no-unused-vars */ -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; import * as style from './utils/style.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -59,10 +59,10 @@ export const ANIMATION_TIME = 0.25; * Timer for animation out, to be cleared if we need to immediately hide * without disrupting new shows. */ -let animateOutTimer: number | null = null; +let animateOutTimer: number|null = null; /** Callback for when the drop-down is hidden. */ -let onHide: Function | null = null; +let onHide: Function|null = null; /** A class name representing the current owner's workspace renderer. */ let renderedClassName = ''; @@ -83,13 +83,13 @@ let arrow: HTMLDivElement; * Drop-downs will appear within the bounds of this element if possible. * Set in setBoundsElement. */ -let boundsElement: Element | null = null; +let boundsElement: Element|null = null; /** The object currently using the drop-down. */ -let owner: AnyDuringMigration | null = null; +let owner: AnyDuringMigration|null = null; /** Whether the dropdown was positioned to a field or the source block. */ -let positionToField: boolean | null = null; +let positionToField: boolean|null = null; /** * Dropdown bounds info object used to encapsulate sizing information about a @@ -110,9 +110,9 @@ export interface PositionMetrics { initialY: number; finalX: number; finalY: number; - arrowX: number | null; - arrowY: number | null; - arrowAtTop: boolean | null; + arrowX: number|null; + arrowY: number|null; + arrowAtTop: boolean|null; arrowVisible: boolean; } @@ -140,14 +140,14 @@ export function createDom() { div.style.opacity = 0 as AnyDuringMigration; // Transition animation for transform: translate() and opacity. div.style.transition = 'transform ' + ANIMATION_TIME + 's, ' + - 'opacity ' + ANIMATION_TIME + 's'; + 'opacity ' + ANIMATION_TIME + 's'; // Handle focusin/out events to add a visual indicator when // a child is focused or blurred. - div.addEventListener('focusin', function () { + div.addEventListener('focusin', function() { dom.addClass(div, 'blocklyFocused'); }); - div.addEventListener('focusout', function () { + div.addEventListener('focusout', function() { dom.removeClass(div, 'blocklyFocused'); }); } @@ -157,7 +157,7 @@ export function createDom() { * within the box of this element if possible. * @param boundsElem Element to bind drop-down to. */ -export function setBoundsElement(boundsElem: Element | null) { +export function setBoundsElement(boundsElem: Element|null) { boundsElement = boundsElem; } @@ -197,10 +197,10 @@ export function setColour(backgroundColour: string, borderColour: string) { * @return True if the menu rendered below block; false if above. */ export function showPositionedByBlock( - field: Field, block: BlockSvg, opt_onHide?: Function, - opt_secondaryYOffset?: number): boolean { + field: Field, block: BlockSvg, opt_onHide?: Function, + opt_secondaryYOffset?: number): boolean { return showPositionedByRect( - getScaledBboxOfBlock(block), field, opt_onHide, opt_secondaryYOffset); + getScaledBboxOfBlock(block), field, opt_onHide, opt_secondaryYOffset); } /** @@ -214,11 +214,11 @@ export function showPositionedByBlock( * @return True if the menu rendered below block; false if above. */ export function showPositionedByField( - field: Field, opt_onHide?: Function, - opt_secondaryYOffset?: number): boolean { + field: Field, opt_onHide?: Function, + opt_secondaryYOffset?: number): boolean { positionToField = true; return showPositionedByRect( - getScaledBboxOfField(field), field, opt_onHide, opt_secondaryYOffset); + getScaledBboxOfField(field), field, opt_onHide, opt_secondaryYOffset); } /** * Get the scaled bounding box of a block. @@ -256,8 +256,8 @@ function getScaledBboxOfField(field: Field): Rect { * @return True if the menu rendered below block; false if above. */ function showPositionedByRect( - bBox: Rect, field: Field, opt_onHide?: Function, - opt_secondaryYOffset?: number): boolean { + bBox: Rect, field: Field, opt_onHide?: Function, + opt_secondaryYOffset?: number): boolean { // If we can fit it, render below the block. const primaryX = bBox.left + (bBox.right - bBox.left) / 2; const primaryY = bBox.bottom; @@ -275,8 +275,8 @@ function showPositionedByRect( } setBoundsElement(workspace.getParentSvg().parentNode as Element | null); return show( - field, sourceBlock.RTL, primaryX, primaryY, secondaryX, secondaryY, - opt_onHide); + field, sourceBlock.RTL, primaryX, primaryY, secondaryX, secondaryY, + opt_onHide); } /** @@ -297,9 +297,9 @@ function showPositionedByRect( * @return True if the menu rendered at the primary origin point. */ export function show( - newOwner: AnyDuringMigration | null, rtl: boolean, primaryX: number, - primaryY: number, secondaryX: number, secondaryY: number, - opt_onHide?: Function): boolean { + newOwner: AnyDuringMigration|null, rtl: boolean, primaryX: number, + primaryY: number, secondaryX: number, secondaryY: number, + opt_onHide?: Function): boolean { owner = newOwner; onHide = opt_onHide || null; // Set direction. @@ -331,7 +331,7 @@ const internal = {}; */ // AnyDuringMigration because: Property 'getBoundsInfo' does not exist on type // '{}'. -(internal as AnyDuringMigration).getBoundsInfo = function (): BoundsInfo { +(internal as AnyDuringMigration).getBoundsInfo = function(): BoundsInfo { const boundPosition = style.getPageOffset(boundsElement as Element); const boundSize = style.getSize(boundsElement as Element); @@ -357,9 +357,9 @@ const internal = {}; */ // AnyDuringMigration because: Property 'getPositionMetrics' does not exist on // type '{}'. -(internal as AnyDuringMigration).getPositionMetrics = function ( - primaryX: number, primaryY: number, secondaryX: number, - secondaryY: number): PositionMetrics { +(internal as AnyDuringMigration).getPositionMetrics = function( + primaryX: number, primaryY: number, secondaryX: number, + secondaryY: number): PositionMetrics { // AnyDuringMigration because: Property 'getBoundsInfo' does not exist on // type '{}'. const boundsInfo = (internal as AnyDuringMigration).getBoundsInfo(); @@ -398,10 +398,10 @@ const internal = {}; * arrow. */ function getPositionBelowMetrics( - primaryX: number, primaryY: number, boundsInfo: BoundsInfo, - divSize: Size): PositionMetrics { + primaryX: number, primaryY: number, boundsInfo: BoundsInfo, + divSize: Size): PositionMetrics { const xCoords = - getPositionX(primaryX, boundsInfo.left, boundsInfo.right, divSize.width); + getPositionX(primaryX, boundsInfo.left, boundsInfo.right, divSize.width); const arrowY = -(ARROW_SIZE / 2 + BORDER_SIZE); const finalY = primaryY + PADDING_Y; @@ -430,10 +430,10 @@ function getPositionBelowMetrics( * arrow. */ function getPositionAboveMetrics( - secondaryX: number, secondaryY: number, boundsInfo: BoundsInfo, - divSize: Size): PositionMetrics { + secondaryX: number, secondaryY: number, boundsInfo: BoundsInfo, + divSize: Size): PositionMetrics { const xCoords = getPositionX( - secondaryX, boundsInfo.left, boundsInfo.right, divSize.width); + secondaryX, boundsInfo.left, boundsInfo.right, divSize.width); const arrowY = divSize.height - BORDER_SIZE * 2 - ARROW_SIZE / 2; const finalY = secondaryY - divSize.height - PADDING_Y; @@ -463,9 +463,9 @@ function getPositionAboveMetrics( * arrow. */ function getPositionTopOfPageMetrics( - sourceX: number, boundsInfo: BoundsInfo, divSize: Size): PositionMetrics { + sourceX: number, boundsInfo: BoundsInfo, divSize: Size): PositionMetrics { const xCoords = - getPositionX(sourceX, boundsInfo.left, boundsInfo.right, divSize.width); + getPositionX(sourceX, boundsInfo.left, boundsInfo.right, divSize.width); // No need to provide arrow-specific information because it won't be visible. return { @@ -491,8 +491,8 @@ function getPositionTopOfPageMetrics( * the DropDownDiv and the arrow. */ export function getPositionX( - sourceX: number, boundsLeft: number, boundsRight: number, - divWidth: number): { divX: number, arrowX: number } { + sourceX: number, boundsLeft: number, boundsRight: number, + divWidth: number): {divX: number, arrowX: number} { let divX = sourceX; // Offset the topLeft coord so that the dropdowndiv is centered. divX -= divWidth / 2; @@ -507,9 +507,9 @@ export function getPositionX( const horizPadding = ARROW_HORIZONTAL_PADDING; // Clamp the arrow position so that it stays attached to the dropdowndiv. relativeArrowX = math.clamp( - horizPadding, relativeArrowX, divWidth - horizPadding - ARROW_SIZE); + horizPadding, relativeArrowX, divWidth - horizPadding - ARROW_SIZE); - return { arrowX: relativeArrowX, divX }; + return {arrowX: relativeArrowX, divX}; } /** @@ -528,8 +528,8 @@ export function isVisible(): boolean { * @return True if hidden. */ export function hideIfOwner( - divOwner: AnyDuringMigration | null, - opt_withoutAnimation?: boolean): boolean { + divOwner: AnyDuringMigration|null, + opt_withoutAnimation?: boolean): boolean { if (owner === divOwner) { if (opt_withoutAnimation) { hideWithoutAnimation(); @@ -550,7 +550,7 @@ export function hide() { // 'string'. div.style.opacity = 0 as AnyDuringMigration; // Finish animation - reset all values to default. - animateOutTimer = setTimeout(function () { + animateOutTimer = setTimeout(function() { hideWithoutAnimation(); }, ANIMATION_TIME * 1000); if (onHide) { @@ -607,23 +607,23 @@ export function hideWithoutAnimation() { * @return True if the menu rendered at the primary origin point. */ function positionInternal( - primaryX: number, primaryY: number, secondaryX: number, - secondaryY: number): boolean { + primaryX: number, primaryY: number, secondaryX: number, + secondaryY: number): boolean { // AnyDuringMigration because: Property 'getPositionMetrics' does not exist // on type '{}'. const metrics = - (internal as AnyDuringMigration) - .getPositionMetrics(primaryX, primaryY, secondaryX, secondaryY); + (internal as AnyDuringMigration) + .getPositionMetrics(primaryX, primaryY, secondaryX, secondaryY); // Update arrow CSS. if (metrics.arrowVisible) { arrow.style.display = ''; arrow.style.transform = 'translate(' + metrics.arrowX + 'px,' + - metrics.arrowY + 'px) rotate(45deg)'; + metrics.arrowY + 'px) rotate(45deg)'; arrow.setAttribute( - 'class', - metrics.arrowAtTop ? 'blocklyDropDownArrow blocklyArrowTop' : - 'blocklyDropDownArrow blocklyArrowBottom'); + 'class', + metrics.arrowAtTop ? 'blocklyDropDownArrow blocklyArrowTop' : + 'blocklyDropDownArrow blocklyArrowBottom'); } else { arrow.style.display = 'none'; } @@ -666,7 +666,7 @@ export function repositionForWindowResize() { const field = owner as Field; const block = field.getSourceBlock() as BlockSvg; const bBox = positionToField ? getScaledBboxOfField(field) : - getScaledBboxOfBlock(block); + getScaledBboxOfBlock(block); // If we can fit it, render below the block. const primaryX = bBox.left + (bBox.right - bBox.left) / 2; const primaryY = bBox.bottom; diff --git a/core/events/events.ts b/core/events/events.ts index 9b8d61b7a..a89bb8ff5 100644 --- a/core/events/events.ts +++ b/core/events/events.ts @@ -14,64 +14,64 @@ import * as deprecation from '../utils/deprecation.js'; -import { Abstract as AbstractEvent } from './events_abstract.js'; -import { BlockBase } from './events_block_base.js'; -import { BlockChange } from './events_block_change.js'; -import { BlockCreate } from './events_block_create.js'; -import { BlockDelete } from './events_block_delete.js'; -import { BlockDrag } from './events_block_drag.js'; -import { BlockMove } from './events_block_move.js'; -import { BubbleOpen } from './events_bubble_open.js'; -import { Click } from './events_click.js'; -import { CommentBase } from './events_comment_base.js'; -import { CommentChange } from './events_comment_change.js'; -import { CommentCreate } from './events_comment_create.js'; -import { CommentDelete } from './events_comment_delete.js'; -import { CommentMove } from './events_comment_move.js'; -import { MarkerMove } from './events_marker_move.js'; -import { Selected } from './events_selected.js'; -import { ThemeChange } from './events_theme_change.js'; -import { ToolboxItemSelect } from './events_toolbox_item_select.js'; -import { TrashcanOpen } from './events_trashcan_open.js'; -import { Ui } from './events_ui.js'; -import { UiBase } from './events_ui_base.js'; -import { VarBase } from './events_var_base.js'; -import { VarCreate } from './events_var_create.js'; -import { VarDelete } from './events_var_delete.js'; -import { VarRename } from './events_var_rename.js'; -import { ViewportChange } from './events_viewport.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; +import {BlockBase} from './events_block_base.js'; +import {BlockChange} from './events_block_change.js'; +import {BlockCreate} from './events_block_create.js'; +import {BlockDelete} from './events_block_delete.js'; +import {BlockDrag} from './events_block_drag.js'; +import {BlockMove} from './events_block_move.js'; +import {BubbleOpen} from './events_bubble_open.js'; +import {Click} from './events_click.js'; +import {CommentBase} from './events_comment_base.js'; +import {CommentChange} from './events_comment_change.js'; +import {CommentCreate} from './events_comment_create.js'; +import {CommentDelete} from './events_comment_delete.js'; +import {CommentMove} from './events_comment_move.js'; +import {MarkerMove} from './events_marker_move.js'; +import {Selected} from './events_selected.js'; +import {ThemeChange} from './events_theme_change.js'; +import {ToolboxItemSelect} from './events_toolbox_item_select.js'; +import {TrashcanOpen} from './events_trashcan_open.js'; +import {Ui} from './events_ui.js'; +import {UiBase} from './events_ui_base.js'; +import {VarBase} from './events_var_base.js'; +import {VarCreate} from './events_var_create.js'; +import {VarDelete} from './events_var_delete.js'; +import {VarRename} from './events_var_rename.js'; +import {ViewportChange} from './events_viewport.js'; import * as eventUtils from './utils.js'; -import { FinishedLoading } from './workspace_events.js'; +import {FinishedLoading} from './workspace_events.js'; // Events. export const Abstract = AbstractEvent; -export { BubbleOpen }; -export { BlockBase }; -export { BlockChange }; -export { BlockCreate }; -export { BlockDelete }; -export { BlockDrag }; -export { BlockMove }; -export { Click }; -export { CommentBase }; -export { CommentChange }; -export { CommentCreate }; -export { CommentDelete }; -export { CommentMove }; -export { FinishedLoading }; -export { MarkerMove }; -export { Selected }; -export { ThemeChange }; -export { ToolboxItemSelect }; -export { TrashcanOpen }; -export { Ui }; -export { UiBase }; -export { VarBase }; -export { VarCreate }; -export { VarDelete }; -export { VarRename }; -export { ViewportChange }; +export {BubbleOpen}; +export {BlockBase}; +export {BlockChange}; +export {BlockCreate}; +export {BlockDelete}; +export {BlockDrag}; +export {BlockMove}; +export {Click}; +export {CommentBase}; +export {CommentChange}; +export {CommentCreate}; +export {CommentDelete}; +export {CommentMove}; +export {FinishedLoading}; +export {MarkerMove}; +export {Selected}; +export {ThemeChange}; +export {ToolboxItemSelect}; +export {TrashcanOpen}; +export {Ui}; +export {UiBase}; +export {VarBase}; +export {VarCreate}; +export {VarDelete}; +export {VarRename}; +export {ViewportChange}; // Event types. export const BLOCK_CHANGE = eventUtils.BLOCK_CHANGE; diff --git a/core/events/events_abstract.ts b/core/events/events_abstract.ts index 9d5ca2752..8c645a1d5 100644 --- a/core/events/events_abstract.ts +++ b/core/events/events_abstract.ts @@ -17,7 +17,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; import * as eventUtils from './utils.js'; @@ -28,7 +28,7 @@ import * as eventUtils from './utils.js'; */ export abstract class Abstract { /** Whether or not the event is blank (to be populated by fromJson). */ - isBlank: boolean | null = null; + isBlank: boolean|null = null; /** The workspace identifier for this event. */ workspaceId?: string = undefined; @@ -59,7 +59,7 @@ export abstract class Abstract { * @return JSON representation. */ toJson(): AnyDuringMigration { - const json = { 'type': this.type }; + const json = {'type': this.type}; if (this.group) { (json as AnyDuringMigration)['group'] = this.group; } @@ -102,8 +102,8 @@ export abstract class Abstract { } if (!workspace) { throw Error( - 'Workspace is null. Event must have been generated from real' + - ' Blockly events.'); + 'Workspace is null. Event must have been generated from real' + + ' Blockly events.'); } return workspace; } diff --git a/core/events/events_block_base.ts b/core/events/events_block_base.ts index 117edfaf2..c85885bf9 100644 --- a/core/events/events_block_base.ts +++ b/core/events/events_block_base.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; -import { Abstract as AbstractEvent } from './events_abstract.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; /** diff --git a/core/events/events_block_change.ts b/core/events/events_block_change.ts index 386cd6cf8..b0463e590 100644 --- a/core/events/events_block_change.ts +++ b/core/events/events_block_change.ts @@ -13,13 +13,13 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../block_svg.js'; +import {BlockSvg} from '../block_svg.js'; import * as registry from '../registry.js'; import * as Xml from '../xml.js'; -import { BlockBase } from './events_block_base.js'; +import {BlockBase} from './events_block_base.js'; import * as eventUtils from './utils.js'; @@ -32,7 +32,7 @@ export class BlockChange extends BlockBase { // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. element!: string; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - name!: string | null; + name!: string|null; oldValue: AnyDuringMigration; newValue: AnyDuringMigration; @@ -44,8 +44,8 @@ export class BlockChange extends BlockBase { * @param opt_newValue New value of element. */ constructor( - opt_block?: Block, opt_element?: string, opt_name?: string | null, - opt_oldValue?: AnyDuringMigration, opt_newValue?: AnyDuringMigration) { + opt_block?: Block, opt_element?: string, opt_name?: string|null, + opt_oldValue?: AnyDuringMigration, opt_newValue?: AnyDuringMigration) { super(opt_block); /** Type of this event. */ @@ -143,7 +143,7 @@ export class BlockChange extends BlockBase { block.domToMutation(Xml.textToDom(value as string || '')); } eventUtils.fire( - new BlockChange(block, 'mutation', null, oldState, value)); + new BlockChange(block, 'mutation', null, oldState, value)); break; } default: diff --git a/core/events/events_block_create.ts b/core/events/events_block_create.ts index 3fa9def07..1cf90773d 100644 --- a/core/events/events_block_create.ts +++ b/core/events/events_block_create.ts @@ -13,12 +13,12 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; import * as blocks from '../serialization/blocks.js'; import * as Xml from '../xml.js'; -import { BlockBase } from './events_block_base.js'; +import {BlockBase} from './events_block_base.js'; import * as eventUtils from './utils.js'; @@ -54,7 +54,7 @@ export class BlockCreate extends BlockBase { this.ids = eventUtils.getDescendantIds(opt_block); /** JSON representation of the block that was just created. */ - this.json = blocks.save(opt_block, { addCoordinates: true }) as blocks.State; + this.json = blocks.save(opt_block, {addCoordinates: true}) as blocks.State; } /** diff --git a/core/events/events_block_delete.ts b/core/events/events_block_delete.ts index e606c827a..e2ab44698 100644 --- a/core/events/events_block_delete.ts +++ b/core/events/events_block_delete.ts @@ -13,12 +13,12 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; import * as blocks from '../serialization/blocks.js'; import * as Xml from '../xml.js'; -import { BlockBase } from './events_block_base.js'; +import {BlockBase} from './events_block_base.js'; import * as eventUtils from './utils.js'; @@ -63,7 +63,7 @@ export class BlockDelete extends BlockBase { /** JSON representation of the block that was just deleted. */ this.oldJson = - blocks.save(opt_block, { addCoordinates: true }) as blocks.State; + blocks.save(opt_block, {addCoordinates: true}) as blocks.State; } /** @@ -91,7 +91,7 @@ export class BlockDelete extends BlockBase { this.oldXml = Xml.textToDom(json['oldXml']); this.ids = json['ids']; this.wasShadow = - json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow'; + json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow'; this.oldJson = json['oldJson'] as blocks.State; if (json['recordUndo'] !== undefined) { this.recordUndo = json['recordUndo']; diff --git a/core/events/events_block_drag.ts b/core/events/events_block_drag.ts index d4d39a50c..8d240d57f 100644 --- a/core/events/events_block_drag.ts +++ b/core/events/events_block_drag.ts @@ -13,10 +13,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_block_move.ts b/core/events/events_block_move.ts index d964e814c..6abdbcc56 100644 --- a/core/events/events_block_move.ts +++ b/core/events/events_block_move.ts @@ -13,18 +13,18 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; -import { ConnectionType } from '../connection_type.js'; +import {Block} from '../block.js'; +import {ConnectionType} from '../connection_type.js'; import * as registry from '../registry.js'; -import { Coordinate } from '../utils/coordinate.js'; +import {Coordinate} from '../utils/coordinate.js'; -import { BlockBase } from './events_block_base.js'; +import {BlockBase} from './events_block_base.js'; import * as eventUtils from './utils.js'; interface BlockLocation { parentId: string; inputName: string; - coordinate: Coordinate | null; + coordinate: Coordinate|null; } // eslint-disable-line no-unused-vars /** @@ -40,11 +40,11 @@ export class BlockMove extends BlockBase { // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. oldInputName!: string; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - oldCoordinate!: Coordinate | null; + oldCoordinate!: Coordinate|null; - newParentId: string | null = null; - newInputName: string | null = null; - newCoordinate: Coordinate | null = null; + newParentId: string|null = null; + newInputName: string|null = null; + newCoordinate: Coordinate|null = null; /** @param opt_block The moved block. Undefined for a blank event. */ constructor(opt_block?: Block) { @@ -80,7 +80,7 @@ export class BlockMove extends BlockBase { } if (this.newCoordinate) { json['newCoordinate'] = Math.round(this.newCoordinate.x) + ',' + - Math.round(this.newCoordinate.y); + Math.round(this.newCoordinate.y); } if (!this.recordUndo) { json['recordUndo'] = this.recordUndo; @@ -143,8 +143,8 @@ export class BlockMove extends BlockBase { */ override isNull(): boolean { return this.oldParentId === this.newParentId && - this.oldInputName === this.newInputName && - Coordinate.equals(this.oldCoordinate, this.newCoordinate); + this.oldInputName === this.newInputName && + Coordinate.equals(this.oldCoordinate, this.newCoordinate); } /** @@ -161,7 +161,7 @@ export class BlockMove extends BlockBase { const parentId = forward ? this.newParentId : this.oldParentId; const inputName = forward ? this.newInputName : this.oldInputName; const coordinate = forward ? this.newCoordinate : this.oldCoordinate; - let parentBlock: Block | null; + let parentBlock: Block|null; if (parentId) { parentBlock = workspace.getBlockById(parentId); if (!parentBlock) { @@ -178,7 +178,7 @@ export class BlockMove extends BlockBase { } else { let blockConnection = block.outputConnection; if (!blockConnection || - block.previousConnection && block.previousConnection.isConnected()) { + block.previousConnection && block.previousConnection.isConnected()) { blockConnection = block.previousConnection; } let parentConnection; diff --git a/core/events/events_bubble_open.ts b/core/events/events_bubble_open.ts index 95e2c5581..a57bc9a22 100644 --- a/core/events/events_bubble_open.ts +++ b/core/events/events_bubble_open.ts @@ -13,10 +13,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../block_svg.js'; +import {BlockSvg} from '../block_svg.js'; import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -25,7 +25,7 @@ import * as eventUtils from './utils.js'; * @alias Blockly.Events.BubbleOpen */ export class BubbleOpen extends UiBase { - blockId: string | null; + blockId: string|null; isOpen?: boolean; bubbleType?: string; override type: string; @@ -38,7 +38,7 @@ export class BubbleOpen extends UiBase { * 'warning'. Undefined for a blank event. */ constructor( - opt_block: BlockSvg, opt_isOpen?: boolean, opt_bubbleType?: string) { + opt_block: BlockSvg, opt_isOpen?: boolean, opt_bubbleType?: string) { const workspaceId = opt_block ? opt_block.workspace.id : undefined; super(workspaceId); this.blockId = opt_block ? opt_block.id : null; diff --git a/core/events/events_click.ts b/core/events/events_click.ts index e407d09f9..50a5597f4 100644 --- a/core/events/events_click.ts +++ b/core/events/events_click.ts @@ -13,10 +13,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -39,8 +39,8 @@ export class Click extends UiBase { * Undefined for a blank event. */ constructor( - opt_block?: Block | null, opt_workspaceId?: string | null, - opt_targetType?: string) { + opt_block?: Block|null, opt_workspaceId?: string|null, + opt_targetType?: string) { let workspaceId = opt_block ? opt_block.workspace.id : opt_workspaceId; if (workspaceId === null) { workspaceId = undefined; diff --git a/core/events/events_comment_base.ts b/core/events/events_comment_base.ts index 337a56f1f..053aafea5 100644 --- a/core/events/events_comment_base.ts +++ b/core/events/events_comment_base.ts @@ -14,14 +14,14 @@ import * as utilsXml from '../utils/xml.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from '../workspace_comment.js'; +import {WorkspaceComment} from '../workspace_comment.js'; import * as Xml from '../xml.js'; -import { Abstract as AbstractEvent } from './events_abstract.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentCreate } from './events_comment_create.js'; +import {CommentCreate} from './events_comment_create.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentDelete } from './events_comment_delete.js'; +import {CommentDelete} from './events_comment_delete.js'; import * as eventUtils from './utils.js'; @@ -87,7 +87,7 @@ export class CommentBase extends AbstractEvent { * @param create if True then Create, if False then Delete */ static CommentCreateDeleteHelper( - event: CommentCreate | CommentDelete, create: boolean) { + event: CommentCreate|CommentDelete, create: boolean) { const workspace = event.getEventWorkspace_(); if (create) { const xmlElement = utilsXml.createElement('xml'); @@ -100,7 +100,7 @@ export class CommentBase extends AbstractEvent { } else { // Only complain about root-level block. console.warn( - 'Can\'t uncreate non-existent comment: ' + event.commentId); + 'Can\'t uncreate non-existent comment: ' + event.commentId); } } } diff --git a/core/events/events_comment_change.ts b/core/events/events_comment_change.ts index af500e626..ef8b5156f 100644 --- a/core/events/events_comment_change.ts +++ b/core/events/events_comment_change.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from '../workspace_comment.js'; +import {WorkspaceComment} from '../workspace_comment.js'; -import { CommentBase } from './events_comment_base.js'; +import {CommentBase} from './events_comment_base.js'; import * as eventUtils from './utils.js'; @@ -39,21 +39,21 @@ export class CommentChange extends CommentBase { * @param opt_newContents New contents of the comment. */ constructor( - opt_comment?: WorkspaceComment, opt_oldContents?: string, - opt_newContents?: string) { + opt_comment?: WorkspaceComment, opt_oldContents?: string, + opt_newContents?: string) { super(opt_comment); /** Type of this event. */ this.type = eventUtils.COMMENT_CHANGE; if (!opt_comment) { - return; // Blank event to be populated by fromJson. + return; // Blank event to be populated by fromJson. } - + this.oldContents_ = - typeof opt_oldContents === 'undefined' ? '' : opt_oldContents; + typeof opt_oldContents === 'undefined' ? '' : opt_oldContents; this.newContents_ = - typeof opt_newContents === 'undefined' ? '' : opt_newContents; + typeof opt_newContents === 'undefined' ? '' : opt_newContents; } /** @@ -103,4 +103,4 @@ export class CommentChange extends CommentBase { } registry.register( - registry.Type.EVENT, eventUtils.COMMENT_CHANGE, CommentChange); + registry.Type.EVENT, eventUtils.COMMENT_CHANGE, CommentChange); diff --git a/core/events/events_comment_create.ts b/core/events/events_comment_create.ts index 715fa3ef7..f6698e802 100644 --- a/core/events/events_comment_create.ts +++ b/core/events/events_comment_create.ts @@ -14,10 +14,10 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from '../workspace_comment.js'; +import {WorkspaceComment} from '../workspace_comment.js'; import * as Xml from '../xml.js'; -import { CommentBase } from './events_comment_base.js'; +import {CommentBase} from './events_comment_base.js'; import * as eventUtils from './utils.js'; @@ -77,4 +77,4 @@ export class CommentCreate extends CommentBase { } registry.register( - registry.Type.EVENT, eventUtils.COMMENT_CREATE, CommentCreate); + registry.Type.EVENT, eventUtils.COMMENT_CREATE, CommentCreate); diff --git a/core/events/events_comment_delete.ts b/core/events/events_comment_delete.ts index dd9f82004..967b84b85 100644 --- a/core/events/events_comment_delete.ts +++ b/core/events/events_comment_delete.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from '../workspace_comment.js'; +import {WorkspaceComment} from '../workspace_comment.js'; -import { CommentBase } from './events_comment_base.js'; +import {CommentBase} from './events_comment_base.js'; import * as eventUtils from './utils.js'; @@ -72,4 +72,4 @@ export class CommentDelete extends CommentBase { } registry.register( - registry.Type.EVENT, eventUtils.COMMENT_DELETE, CommentDelete); + registry.Type.EVENT, eventUtils.COMMENT_DELETE, CommentDelete); diff --git a/core/events/events_comment_move.ts b/core/events/events_comment_move.ts index 4516f7b01..8212e27a0 100644 --- a/core/events/events_comment_move.ts +++ b/core/events/events_comment_move.ts @@ -13,11 +13,11 @@ */ import * as registry from '../registry.js'; -import { Coordinate } from '../utils/coordinate.js'; +import {Coordinate} from '../utils/coordinate.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from '../workspace_comment.js'; +import {WorkspaceComment} from '../workspace_comment.js'; -import { CommentBase } from './events_comment_base.js'; +import {CommentBase} from './events_comment_base.js'; import * as eventUtils from './utils.js'; @@ -69,8 +69,8 @@ export class CommentMove extends CommentBase { recordNew() { if (!this.comment_) { throw Error( - 'Tried to record the new position of a comment on the ' + - 'same event twice.'); + 'Tried to record the new position of a comment on the ' + + 'same event twice.'); } this.newCoordinate_ = this.comment_.getXY(); // AnyDuringMigration because: Type 'null' is not assignable to type @@ -96,11 +96,11 @@ export class CommentMove extends CommentBase { const json = super.toJson(); if (this.oldCoordinate_) { json['oldCoordinate'] = Math.round(this.oldCoordinate_.x) + ',' + - Math.round(this.oldCoordinate_.y); + Math.round(this.oldCoordinate_.y); } if (this.newCoordinate_) { json['newCoordinate'] = Math.round(this.newCoordinate_.x) + ',' + - Math.round(this.newCoordinate_.y); + Math.round(this.newCoordinate_.y); } return json; } diff --git a/core/events/events_marker_move.ts b/core/events/events_marker_move.ts index fc6bc5ecd..e56b7b443 100644 --- a/core/events/events_marker_move.ts +++ b/core/events/events_marker_move.ts @@ -13,13 +13,13 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; -import { ASTNode } from '../keyboard_nav/ast_node.js'; +import {Block} from '../block.js'; +import {ASTNode} from '../keyboard_nav/ast_node.js'; import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -28,8 +28,8 @@ import * as eventUtils from './utils.js'; * @alias Blockly.Events.MarkerMove */ export class MarkerMove extends UiBase { - blockId: string | null; - oldNode?: ASTNode | null; + blockId: string|null; + oldNode?: ASTNode|null; newNode?: ASTNode; isCursor?: boolean; override type: string; @@ -45,8 +45,8 @@ export class MarkerMove extends UiBase { * Undefined for a blank event. */ constructor( - opt_block?: Block | null, isCursor?: boolean, opt_oldNode?: ASTNode | null, - opt_newNode?: ASTNode) { + opt_block?: Block|null, isCursor?: boolean, opt_oldNode?: ASTNode|null, + opt_newNode?: ASTNode) { let workspaceId = opt_block ? opt_block.workspace.id : undefined; if (opt_newNode && opt_newNode.getType() === ASTNode.types.WORKSPACE) { workspaceId = (opt_newNode.getLocation() as Workspace).id; diff --git a/core/events/events_selected.ts b/core/events/events_selected.ts index 54d9bf88a..703e9d05d 100644 --- a/core/events/events_selected.ts +++ b/core/events/events_selected.ts @@ -14,7 +14,7 @@ import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -23,8 +23,8 @@ import * as eventUtils from './utils.js'; * @alias Blockly.Events.Selected */ export class Selected extends UiBase { - oldElementId?: string | null; - newElementId?: string | null; + oldElementId?: string|null; + newElementId?: string|null; override type: string; /** @@ -36,8 +36,8 @@ export class Selected extends UiBase { * Null if no element previously selected. Undefined for a blank event. */ constructor( - opt_oldElementId?: string | null, opt_newElementId?: string | null, - opt_workspaceId?: string) { + opt_oldElementId?: string|null, opt_newElementId?: string|null, + opt_workspaceId?: string) { super(opt_workspaceId); /** The id of the last selected element. */ diff --git a/core/events/events_theme_change.ts b/core/events/events_theme_change.ts index f89dbf1b6..88b6a10ee 100644 --- a/core/events/events_theme_change.ts +++ b/core/events/events_theme_change.ts @@ -14,7 +14,7 @@ import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_toolbox_item_select.ts b/core/events/events_toolbox_item_select.ts index 97c1a8a7b..712d32711 100644 --- a/core/events/events_toolbox_item_select.ts +++ b/core/events/events_toolbox_item_select.ts @@ -16,7 +16,7 @@ import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -25,8 +25,8 @@ import * as eventUtils from './utils.js'; * @alias Blockly.Events.ToolboxItemSelect */ export class ToolboxItemSelect extends UiBase { - oldItem?: string | null; - newItem?: string | null; + oldItem?: string|null; + newItem?: string|null; override type: string; /** @@ -38,8 +38,8 @@ export class ToolboxItemSelect extends UiBase { * Undefined for a blank event. */ constructor( - opt_oldItem?: string | null, opt_newItem?: string | null, - opt_workspaceId?: string) { + opt_oldItem?: string|null, opt_newItem?: string|null, + opt_workspaceId?: string) { super(opt_workspaceId); /** The previously selected toolbox item. */ @@ -75,4 +75,4 @@ export class ToolboxItemSelect extends UiBase { } registry.register( - registry.Type.EVENT, eventUtils.TOOLBOX_ITEM_SELECT, ToolboxItemSelect); + registry.Type.EVENT, eventUtils.TOOLBOX_ITEM_SELECT, ToolboxItemSelect); diff --git a/core/events/events_trashcan_open.ts b/core/events/events_trashcan_open.ts index 9d2a25733..66d547e5b 100644 --- a/core/events/events_trashcan_open.ts +++ b/core/events/events_trashcan_open.ts @@ -14,7 +14,7 @@ import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_ui.ts b/core/events/events_ui.ts index ad2760167..ef0005082 100644 --- a/core/events/events_ui.ts +++ b/core/events/events_ui.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -44,8 +44,8 @@ export class Ui extends UiBase { * @param opt_newValue New value of element. */ constructor( - opt_block?: Block | null, opt_element?: string, - opt_oldValue?: AnyDuringMigration, opt_newValue?: AnyDuringMigration) { + opt_block?: Block|null, opt_element?: string, + opt_oldValue?: AnyDuringMigration, opt_newValue?: AnyDuringMigration) { const workspaceId = opt_block ? opt_block.workspace.id : undefined; super(workspaceId); diff --git a/core/events/events_ui_base.ts b/core/events/events_ui_base.ts index 650da7f71..b75c59fa4 100644 --- a/core/events/events_ui_base.ts +++ b/core/events/events_ui_base.ts @@ -15,7 +15,7 @@ * Blockly's editor. * @class */ -import { Abstract as AbstractEvent } from './events_abstract.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; /** diff --git a/core/events/events_var_base.ts b/core/events/events_var_base.ts index 82bc3bedd..16de758f3 100644 --- a/core/events/events_var_base.ts +++ b/core/events/events_var_base.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from '../variable_model.js'; +import {VariableModel} from '../variable_model.js'; -import { Abstract as AbstractEvent } from './events_abstract.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; /** diff --git a/core/events/events_var_create.ts b/core/events/events_var_create.ts index 1b8ae9be6..14aad3fbe 100644 --- a/core/events/events_var_create.ts +++ b/core/events/events_var_create.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from '../variable_model.js'; +import {VariableModel} from '../variable_model.js'; -import { VarBase } from './events_var_base.js'; +import {VarBase} from './events_var_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_var_delete.ts b/core/events/events_var_delete.ts index e8cdcf660..877622fa0 100644 --- a/core/events/events_var_delete.ts +++ b/core/events/events_var_delete.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from '../variable_model.js'; +import {VariableModel} from '../variable_model.js'; -import { VarBase } from './events_var_base.js'; +import {VarBase} from './events_var_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_var_rename.ts b/core/events/events_var_rename.ts index 3bc4e8f8b..24b7b5d66 100644 --- a/core/events/events_var_rename.ts +++ b/core/events/events_var_rename.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from '../variable_model.js'; +import {VariableModel} from '../variable_model.js'; -import { VarBase } from './events_var_base.js'; +import {VarBase} from './events_var_base.js'; import * as eventUtils from './utils.js'; diff --git a/core/events/events_viewport.ts b/core/events/events_viewport.ts index 304e2fb34..2c1e6e537 100644 --- a/core/events/events_viewport.ts +++ b/core/events/events_viewport.ts @@ -14,7 +14,7 @@ import * as registry from '../registry.js'; -import { UiBase } from './events_ui_base.js'; +import {UiBase} from './events_ui_base.js'; import * as eventUtils from './utils.js'; @@ -41,8 +41,8 @@ export class ViewportChange extends UiBase { * event. */ constructor( - opt_top?: number, opt_left?: number, opt_scale?: number, - opt_workspaceId?: string, opt_oldScale?: number) { + opt_top?: number, opt_left?: number, opt_scale?: number, + opt_workspaceId?: string, opt_oldScale?: number) { super(opt_workspaceId); /** @@ -94,4 +94,4 @@ export class ViewportChange extends UiBase { } registry.register( - registry.Type.EVENT, eventUtils.VIEWPORT_CHANGE, ViewportChange); + registry.Type.EVENT, eventUtils.VIEWPORT_CHANGE, ViewportChange); diff --git a/core/events/utils.ts b/core/events/utils.ts index 4507cf08c..a6f4202e6 100644 --- a/core/events/utils.ts +++ b/core/events/utils.ts @@ -17,28 +17,28 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; import * as registry from '../registry.js'; import * as idGenerator from '../utils/idgenerator.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events_abstract.js'; +import {Abstract} from './events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockChange } from './events_block_change.js'; +import {BlockChange} from './events_block_change.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockCreate } from './events_block_create.js'; +import {BlockCreate} from './events_block_create.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockMove } from './events_block_move.js'; +import {BlockMove} from './events_block_move.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentCreate } from './events_comment_create.js'; +import {CommentCreate} from './events_comment_create.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentMove } from './events_comment_move.js'; +import {CommentMove} from './events_comment_move.js'; /* eslint-disable-next-line no-unused-vars */ -import { ViewportChange } from './events_viewport.js'; +import {ViewportChange} from './events_viewport.js'; /** Group ID for new events. Grouped events are indivisible. */ @@ -232,7 +232,7 @@ export const FINISHED_LOADING = 'finished_loading'; * appear connected. * @alias Blockly.Events.utils.BumpEvent */ -export type BumpEvent = BlockCreate | BlockMove | CommentCreate | CommentMove; +export type BumpEvent = BlockCreate|BlockMove|CommentCreate|CommentMove; /** * List of events that cause objects to be bumped back into the visible @@ -243,7 +243,7 @@ export type BumpEvent = BlockCreate | BlockMove | CommentCreate | CommentMove; * @alias Blockly.Events.utils.BUMP_EVENTS */ export const BUMP_EVENTS: string[] = - [BLOCK_CREATE, BLOCK_MOVE, COMMENT_CREATE, COMMENT_MOVE]; + [BLOCK_CREATE, BLOCK_MOVE, COMMENT_CREATE, COMMENT_MOVE]; /** List of events queued for firing. */ const FIRE_QUEUE: Abstract[] = []; @@ -310,7 +310,7 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] { // Each item in the hash table has the event and the index of that event // in the input array. This lets us make sure we only merge adjacent // move events. - hash[key] = { event, index: i }; + hash[key] = {event, index: i}; mergedQueue.push(event); } else if (event.type === MOVE && lastEntry.index === i - 1) { const moveEvent = event as BlockMove; @@ -320,9 +320,9 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] { lastEvent.newCoordinate = moveEvent.newCoordinate; lastEntry.index = i; } else if ( - event.type === CHANGE && - (event as BlockChange).element === lastEvent.element && - (event as BlockChange).name === lastEvent.name) { + event.type === CHANGE && + (event as BlockChange).element === lastEvent.element && + (event as BlockChange).name === lastEvent.name) { const changeEvent = event as BlockChange; // Merge change events. lastEvent.newValue = changeEvent.newValue; @@ -339,13 +339,13 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] { { // Collision: newer events should merge into this event to maintain // order. - hash[key] = { event, index: i }; + hash[key] = {event, index: i}; mergedQueue.push(event); } } } // Filter out any events that have become null due to merging. - queue = mergedQueue.filter(function (e) { + queue = mergedQueue.filter(function(e) { return !e.isNull(); }); if (!forward) { @@ -358,7 +358,7 @@ export function filter(queueIn: Abstract[], forward: boolean): Abstract[] { // AnyDuringMigration because: Property 'element' does not exist on type // 'Abstract'. if (event.type === CHANGE && - (event as AnyDuringMigration).element === 'mutation') { + (event as AnyDuringMigration).element === 'mutation') { queue.unshift(queue.splice(i, 1)[0]); } } @@ -417,7 +417,7 @@ export function getGroup(): string { * String to set group explicitly. * @alias Blockly.Events.utils.setGroup */ -export function setGroup(state: boolean | string) { +export function setGroup(state: boolean|string) { if (typeof state === 'boolean') { group = state ? idGenerator.genUid() : ''; } else { @@ -449,7 +449,7 @@ export function getDescendantIds(block: Block): string[] { * @alias Blockly.Events.utils.fromJson */ export function fromJson( - json: AnyDuringMigration, workspace: Workspace): Abstract { + json: AnyDuringMigration, workspace: Workspace): Abstract { const eventClass = get(json['type']); if (!eventClass) { throw Error('Unknown event type.'); @@ -467,7 +467,7 @@ export function fromJson( * @alias Blockly.Events.utils.get */ export function get(eventType: string): - (new (...p1: AnyDuringMigration[]) => Abstract) | null { + (new (...p1: AnyDuringMigration[]) => Abstract)|null { return registry.getClass(registry.Type.EVENT, eventType); } @@ -486,7 +486,7 @@ export function disableOrphans(event: Abstract) { return; } const eventWorkspace = - Workspace.getById(blockEvent.workspaceId) as WorkspaceSvg; + Workspace.getById(blockEvent.workspaceId) as WorkspaceSvg; let block = eventWorkspace.getBlockById(blockEvent.blockId); if (block) { // Changing blocks as part of this event shouldn't be undoable. @@ -500,8 +500,8 @@ export function disableOrphans(event: Abstract) { child.setEnabled(true); } } else if ( - (block.outputConnection || block.previousConnection) && - !eventWorkspace.isDragging()) { + (block.outputConnection || block.previousConnection) && + !eventWorkspace.isDragging()) { do { block.setEnabled(false); block = block.getNextBlock(); diff --git a/core/events/workspace_events.ts b/core/events/workspace_events.ts index cbd6866fe..a44d851df 100644 --- a/core/events/workspace_events.ts +++ b/core/events/workspace_events.ts @@ -14,9 +14,9 @@ import * as registry from '../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; -import { Abstract as AbstractEvent } from './events_abstract.js'; +import {Abstract as AbstractEvent} from './events_abstract.js'; import * as eventUtils from './utils.js'; @@ -81,4 +81,4 @@ export class FinishedLoading extends AbstractEvent { } registry.register( - registry.Type.EVENT, eventUtils.FINISHED_LOADING, FinishedLoading); + registry.Type.EVENT, eventUtils.FINISHED_LOADING, FinishedLoading); diff --git a/core/extensions.ts b/core/extensions.ts index 4c8442da5..02548e4f4 100644 --- a/core/extensions.ts +++ b/core/extensions.ts @@ -23,16 +23,16 @@ import './mutator'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; -import { BlockSvg } from './block_svg.js'; -import { FieldDropdown } from './field_dropdown.js'; -import { Mutator } from './mutator.js'; +import {Block} from './block.js'; +import {BlockSvg} from './block_svg.js'; +import {FieldDropdown} from './field_dropdown.js'; +import {Mutator} from './mutator.js'; import * as parsing from './utils/parsing.js'; /** The set of all registered extensions, keyed by extension name/id. */ const allExtensions = Object.create(null); -export const TEST_ONLY = { allExtensions }; +export const TEST_ONLY = {allExtensions}; /** * Registers a new extension function. Extensions are functions that help @@ -70,7 +70,7 @@ export function registerMixin(name: string, mixinObj: AnyDuringMigration) { if (!mixinObj || typeof mixinObj !== 'object') { throw Error('Error: Mixin "' + name + '" must be a object'); } - register(name, function (this: Block) { + register(name, function(this: Block) { this.mixin(mixinObj); }); } @@ -89,8 +89,8 @@ export function registerMixin(name: string, mixinObj: AnyDuringMigration) { * @alias Blockly.Extensions.registerMutator */ export function registerMutator( - name: string, mixinObj: AnyDuringMigration, - opt_helperFn?: () => AnyDuringMigration, opt_blockList?: string[]) { + name: string, mixinObj: AnyDuringMigration, + opt_helperFn?: () => AnyDuringMigration, opt_blockList?: string[]) { const errorPrefix = 'Error when registering mutator "' + name + '": '; checkHasMutatorProperties(errorPrefix, mixinObj); @@ -101,7 +101,7 @@ export function registerMutator( } // Sanity checks passed. - register(name, function (this: Block) { + register(name, function(this: Block) { if (hasMutatorDialog) { this.setMutator(new Mutator(this as BlockSvg, opt_blockList || [])); } @@ -124,7 +124,7 @@ export function unregister(name: string) { delete allExtensions[name]; } else { console.warn( - 'No extension mapping for name "' + name + '" found to unregister'); + 'No extension mapping for name "' + name + '" found to unregister'); } } @@ -168,10 +168,10 @@ export function apply(name: string, block: Block, isMutator: boolean) { checkHasMutatorProperties(errorPrefix, block); } else { if (!mutatorPropertiesMatch( - mutatorProperties as AnyDuringMigration[], block)) { + mutatorProperties as AnyDuringMigration[], block)) { throw Error( - 'Error when applying extension "' + name + '": ' + - 'mutation properties changed when applying a non-mutator extension.'); + 'Error when applying extension "' + name + '": ' + + 'mutation properties changed when applying a non-mutator extension.'); } } } @@ -188,9 +188,9 @@ function checkNoMutatorProperties(mutationName: string, block: Block) { const properties = getMutatorProperties(block); if (properties.length) { throw Error( - 'Error: tried to apply mutation "' + mutationName + - '" to a block that already has mutator functions.' + - ' Block id: ' + block.id); + 'Error: tried to apply mutation "' + mutationName + + '" to a block that already has mutator functions.' + + ' Block id: ' + block.id); } } @@ -205,10 +205,10 @@ function checkNoMutatorProperties(mutationName: string, block: Block) { * actually a function. */ function checkXmlHooks( - object: AnyDuringMigration, errorPrefix: string): boolean { + object: AnyDuringMigration, errorPrefix: string): boolean { return checkHasFunctionPair( - object.mutationToDom, object.domToMutation, - errorPrefix + ' mutationToDom/domToMutation'); + object.mutationToDom, object.domToMutation, + errorPrefix + ' mutationToDom/domToMutation'); } /** * Checks if the given object has both the 'saveExtraState' and 'loadExtraState' @@ -221,10 +221,10 @@ function checkXmlHooks( * actually a function. */ function checkJsonHooks( - object: AnyDuringMigration, errorPrefix: string): boolean { + object: AnyDuringMigration, errorPrefix: string): boolean { return checkHasFunctionPair( - object.saveExtraState, object.loadExtraState, - errorPrefix + ' saveExtraState/loadExtraState'); + object.saveExtraState, object.loadExtraState, + errorPrefix + ' saveExtraState/loadExtraState'); } /** @@ -237,9 +237,9 @@ function checkJsonHooks( * actually a function. */ function checkMutatorDialog( - object: AnyDuringMigration, errorPrefix: string): boolean { + object: AnyDuringMigration, errorPrefix: string): boolean { return checkHasFunctionPair( - object.compose, object.decompose, errorPrefix + ' compose/decompose'); + object.compose, object.decompose, errorPrefix + ' compose/decompose'); } /** @@ -254,8 +254,8 @@ function checkMutatorDialog( * actually a function. */ function checkHasFunctionPair( - func1: AnyDuringMigration, func2: AnyDuringMigration, - errorPrefix: string): boolean { + func1: AnyDuringMigration, func2: AnyDuringMigration, + errorPrefix: string): boolean { if (func1 && func2) { if (typeof func1 !== 'function' || typeof func2 !== 'function') { throw Error(errorPrefix + ' must be a function'); @@ -273,13 +273,13 @@ function checkHasFunctionPair( * @param object The object to inspect. */ function checkHasMutatorProperties( - errorPrefix: string, object: AnyDuringMigration) { + errorPrefix: string, object: AnyDuringMigration) { const hasXmlHooks = checkXmlHooks(object, errorPrefix); const hasJsonHooks = checkJsonHooks(object, errorPrefix); if (!hasXmlHooks && !hasJsonHooks) { throw Error( - errorPrefix + - 'Mutations must contain either XML hooks, or JSON hooks, or both'); + errorPrefix + + 'Mutations must contain either XML hooks, or JSON hooks, or both'); } // A block with a mutator isn't required to have a mutation dialog, but // it should still have both or neither of compose and decompose. @@ -326,7 +326,7 @@ function getMutatorProperties(block: Block): AnyDuringMigration[] { * @return True if the property lists match. */ function mutatorPropertiesMatch( - oldProperties: AnyDuringMigration[], block: Block): boolean { + oldProperties: AnyDuringMigration[], block: Block): boolean { const newProperties = getMutatorProperties(block); if (newProperties.length !== oldProperties.length) { return false; @@ -353,7 +353,7 @@ export function runAfterPageLoad(fn: () => AnyDuringMigration) { fn(); } else { // Poll readyState. - const readyStateCheckInterval = setInterval(function () { + const readyStateCheckInterval = setInterval(function() { if (document.readyState === 'complete') { clearInterval(readyStateCheckInterval); fn(); @@ -382,7 +382,7 @@ export function runAfterPageLoad(fn: () => AnyDuringMigration) { * @alias Blockly.Extensions.buildTooltipForDropdown */ export function buildTooltipForDropdown( - dropdownName: string, lookupTable: { [key: string]: string }): Function { + dropdownName: string, lookupTable: {[key: string]: string}): Function { // List of block types already validated, to minimize duplicate warnings. const blockTypesChecked: AnyDuringMigration[] = []; @@ -392,7 +392,7 @@ export function buildTooltipForDropdown( // of document object, in which case skip the validation. if (typeof document === 'object') { // Relies on document.readyState - runAfterPageLoad(function () { + runAfterPageLoad(function() { for (const key in lookupTable) { // Will print warnings if reference is missing. parsing.checkMessageReferences(lookupTable[key]); @@ -407,14 +407,14 @@ export function buildTooltipForDropdown( blockTypesChecked.push(this.type); } - this.setTooltip(function (this: Block) { + this.setTooltip(function(this: Block) { const value = String(this.getFieldValue(dropdownName)); let tooltip = lookupTable[value]; if (tooltip === null) { if (blockTypesChecked.indexOf(this.type) === -1) { // Warn for missing values on generated tooltips. let warning = 'No tooltip mapping for value ' + value + ' of field ' + - dropdownName; + dropdownName; if (this.type !== null) { warning += ' of block type ' + this.type; } @@ -437,7 +437,7 @@ export function buildTooltipForDropdown( * @param lookupTable The string lookup table */ function checkDropdownOptionsInTable( - block: Block, dropdownName: string, lookupTable: { [key: string]: string }) { + block: Block, dropdownName: string, lookupTable: {[key: string]: string}) { // Validate all dropdown options have values. const dropdown = block.getField(dropdownName); if (dropdown instanceof FieldDropdown && !dropdown.isOptionListDynamic()) { @@ -447,8 +447,8 @@ function checkDropdownOptionsInTable( // label, then value if (lookupTable[optionKey] === null) { console.warn( - 'No tooltip mapping for value ' + optionKey + ' of field ' + - dropdownName + ' of block type ' + block.type); + 'No tooltip mapping for value ' + optionKey + ' of field ' + + dropdownName + ' of block type ' + block.type); } } } @@ -465,14 +465,14 @@ function checkDropdownOptionsInTable( * @alias Blockly.Extensions.buildTooltipWithFieldText */ export function buildTooltipWithFieldText( - msgTemplate: string, fieldName: string): Function { + msgTemplate: string, fieldName: string): Function { // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. // runAfterPageLoad() does not run in a Node.js environment due to lack // of document object, in which case skip the validation. if (typeof document === 'object') { // Relies on document.readyState - runAfterPageLoad(function () { + runAfterPageLoad(function() { // Will print warnings if reference is missing. parsing.checkMessageReferences(msgTemplate); }); @@ -480,10 +480,10 @@ export function buildTooltipWithFieldText( /** The actual extension. */ function extensionFn(this: Block) { - this.setTooltip(function (this: Block) { + this.setTooltip(function(this: Block) { const field = this.getField(fieldName); return parsing.replaceMessageReferences(msgTemplate) - .replace('%1', field ? field.getText() : ''); + .replace('%1', field ? field.getText() : ''); }.bind(this)); } return extensionFn; @@ -497,10 +497,10 @@ export function buildTooltipWithFieldText( */ function extensionParentTooltip(this: Block) { const tooltipWhenNotConnected = this.tooltip; - this.setTooltip(function (this: Block) { + this.setTooltip(function(this: Block) { const parent = this.getParent(); return parent && parent.getInputsInline() && parent.tooltip || - tooltipWhenNotConnected; + tooltipWhenNotConnected; }.bind(this)); } register('parent_tooltip_when_inline', extensionParentTooltip); diff --git a/core/field.ts b/core/field.ts index bf7f74818..1fa9a5761 100644 --- a/core/field.ts +++ b/core/field.ts @@ -26,41 +26,41 @@ import './events/events_block_change'; import './gesture'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as dropDownDiv from './dropdowndiv.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from './input.js'; +import {Input} from './input.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js'; +import {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationWithBlock } from './interfaces/i_ast_node_location_with_block.js'; +import {IASTNodeLocationWithBlock} from './interfaces/i_ast_node_location_with_block.js'; /* eslint-disable-next-line no-unused-vars */ -import { IKeyboardAccessible } from './interfaces/i_keyboard_accessible.js'; +import {IKeyboardAccessible} from './interfaces/i_keyboard_accessible.js'; /* eslint-disable-next-line no-unused-vars */ -import { IRegistrable } from './interfaces/i_registrable.js'; -import { MarkerManager } from './marker_manager.js'; +import {IRegistrable} from './interfaces/i_registrable.js'; +import {MarkerManager} from './marker_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './renderers/common/constants.js'; -import { KeyboardShortcut } from './shortcut_registry.js'; +import {ConstantProvider} from './renderers/common/constants.js'; +import {KeyboardShortcut} from './shortcut_registry.js'; import * as Tooltip from './tooltip.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; import * as parsing from './utils/parsing.js'; -import { Rect } from './utils/rect.js'; -import { Sentinel } from './utils/sentinel.js'; -import { Size } from './utils/size.js'; +import {Rect} from './utils/rect.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Size} from './utils/size.js'; import * as style from './utils/style.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; import * as utilsXml from './utils/xml.js'; import * as WidgetDiv from './widgetdiv.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; @@ -69,8 +69,8 @@ import * as Xml from './xml.js'; * @alias Blockly.Field */ export abstract class Field implements IASTNodeLocationSvg, - IASTNodeLocationWithBlock, - IKeyboardAccessible, IRegistrable { + IASTNodeLocationWithBlock, + IKeyboardAccessible, IRegistrable { /** The default value for this field. */ protected DEFAULT_VALUE: any = null; @@ -100,7 +100,7 @@ export abstract class Field implements IASTNodeLocationSvg, * Used to cache the field's tooltip value if setTooltip is called when the * field is not yet initialized. Is *not* guaranteed to be accurate. */ - private tooltip_: Tooltip.TipInfo | null = null; + private tooltip_: Tooltip.TipInfo|null = null; protected size_: Size; /** @@ -139,7 +139,7 @@ export abstract class Field implements IASTNodeLocationSvg, protected textContent_: Text = null as AnyDuringMigration; /** Mouse down event listener data. */ - private mouseDownWrapper_: browserEvents.Data | null = null; + private mouseDownWrapper_: browserEvents.Data|null = null; /** Constants associated with the source block's renderer. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -173,10 +173,10 @@ export abstract class Field implements IASTNodeLocationSvg, protected clickTarget_: Element = null as AnyDuringMigration; /** The prefix field. */ - prefixField: string | null = null; + prefixField: string|null = null; /** The suffix field. */ - suffixField: string | null = null; + suffixField: string|null = null; /** * Editable fields usually show some sort of UI indicating they are @@ -207,8 +207,8 @@ export abstract class Field implements IASTNodeLocationSvg, * this parameter supports. */ constructor( - value: AnyDuringMigration, opt_validator?: Function | null, - opt_config?: AnyDuringMigration) { + value: AnyDuringMigration, opt_validator?: Function|null, + opt_config?: AnyDuringMigration) { /** * A generic value possessed by the field. * Should generally be non-null, only null when the field is created. @@ -262,12 +262,12 @@ export abstract class Field implements IASTNodeLocationSvg, * Get the renderer constant provider. * @return The renderer constant provider. */ - getConstants(): ConstantProvider | null { + getConstants(): ConstantProvider|null { if (!this.constants_ && this.sourceBlock_ && this.sourceBlock_.workspace && - this.sourceBlock_.workspace.rendered) { + this.sourceBlock_.workspace.rendered) { this.constants_ = (this.sourceBlock_.workspace as WorkspaceSvg) - .getRenderer() - .getConstants(); + .getRenderer() + .getConstants(); } return this.constants_; } @@ -322,16 +322,16 @@ export abstract class Field implements IASTNodeLocationSvg, */ protected createBorderRect_() { this.borderRect_ = dom.createSvgElement( - Svg.RECT, { - 'rx': this.getConstants()!.FIELD_BORDER_RECT_RADIUS, - 'ry': this.getConstants()!.FIELD_BORDER_RECT_RADIUS, - 'x': 0, - 'y': 0, - 'height': this.size_.height, - 'width': this.size_.width, - 'class': 'blocklyFieldRect', - }, - this.fieldGroup_); + Svg.RECT, { + 'rx': this.getConstants()!.FIELD_BORDER_RECT_RADIUS, + 'ry': this.getConstants()!.FIELD_BORDER_RECT_RADIUS, + 'x': 0, + 'y': 0, + 'height': this.size_.height, + 'width': this.size_.width, + 'class': 'blocklyFieldRect', + }, + this.fieldGroup_); } /** @@ -341,10 +341,10 @@ export abstract class Field implements IASTNodeLocationSvg, */ protected createTextElement_() { this.textElement_ = dom.createSvgElement( - Svg.TEXT, { - 'class': 'blocklyText', - }, - this.fieldGroup_); + Svg.TEXT, { + 'class': 'blocklyText', + }, + this.fieldGroup_); if (this.getConstants()!.FIELD_TEXT_BASELINE_CENTER) { this.textElement_.setAttribute('dominant-baseline', 'central'); } @@ -359,7 +359,7 @@ export abstract class Field implements IASTNodeLocationSvg, protected bindEvents_() { Tooltip.bindMouseEvents(this.getClickTarget_()); this.mouseDownWrapper_ = browserEvents.conditionalBind( - this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); + this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); } /** @@ -418,14 +418,14 @@ export abstract class Field implements IASTNodeLocationSvg, * Used to see if `this` has overridden any relevant hooks. * @return The stringified version of the XML state, or null. */ - protected saveLegacyState(callingClass: AnyDuringMigration): string | null { + protected saveLegacyState(callingClass: AnyDuringMigration): string|null { if (callingClass.prototype.saveState === this.saveState && - callingClass.prototype.toXml !== this.toXml) { + callingClass.prototype.toXml !== this.toXml) { const elem = utilsXml.createElement('field'); elem.setAttribute('name', this.name || ''); const text = Xml.domToText(this.toXml(elem)); return text.replace( - ' xmlns="https://developers.google.com/blockly/xml"', ''); + ' xmlns="https://developers.google.com/blockly/xml"', ''); } // Either they called this on purpose from their saveState, or they have // no implementations of either hook. Just do our thing. @@ -441,9 +441,9 @@ export abstract class Field implements IASTNodeLocationSvg, * @return Whether the state was applied or not. */ loadLegacyState(callingClass: AnyDuringMigration, state: AnyDuringMigration): - boolean { + boolean { if (callingClass.prototype.loadState === this.loadState && - callingClass.prototype.fromXml !== this.fromXml) { + callingClass.prototype.fromXml !== this.fromXml) { this.fromXml(Xml.textToDom(state as string)); return true; } @@ -511,8 +511,8 @@ export abstract class Field implements IASTNodeLocationSvg, */ isClickable(): boolean { return this.enabled_ && !!this.sourceBlock_ && - this.sourceBlock_.isEditable() && - this.showEditor_ !== Field.prototype.showEditor_; + this.sourceBlock_.isEditable() && + this.showEditor_ !== Field.prototype.showEditor_; } /** @@ -524,7 +524,7 @@ export abstract class Field implements IASTNodeLocationSvg, */ isCurrentlyEditable(): boolean { return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && - this.sourceBlock_.isEditable(); + this.sourceBlock_.isEditable(); } /** @@ -539,9 +539,9 @@ export abstract class Field implements IASTNodeLocationSvg, isSerializable = true; } else if (this.EDITABLE) { console.warn( - 'Detected an editable field that was not serializable.' + - ' Please define SERIALIZABLE property as true on all editable custom' + - ' fields. Proceeding with serialization.'); + 'Detected an editable field that was not serializable.' + + ' Please define SERIALIZABLE property as true on all editable custom' + + ' fields. Proceeding with serialization.'); isSerializable = true; } } @@ -595,7 +595,7 @@ export abstract class Field implements IASTNodeLocationSvg, * Gets the validation function for editable fields, or null if not set. * @return Validation function, or null. */ - getValidator(): Function | null { + getValidator(): Function|null { return this.validator_; } @@ -657,16 +657,16 @@ export abstract class Field implements IASTNodeLocationSvg, protected updateSize_(opt_margin?: number) { const constants = this.getConstants(); const xOffset = opt_margin !== undefined ? opt_margin : - this.borderRect_ ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : - 0; + this.borderRect_ ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : + 0; let totalWidth = xOffset * 2; let totalHeight = constants!.FIELD_TEXT_HEIGHT; let contentWidth = 0; if (this.textElement_) { contentWidth = dom.getFastTextWidth( - this.textElement_, constants!.FIELD_TEXT_FONTSIZE, - constants!.FIELD_TEXT_FONTWEIGHT, constants!.FIELD_TEXT_FONTFAMILY); + this.textElement_, constants!.FIELD_TEXT_FONTSIZE, + constants!.FIELD_TEXT_FONTWEIGHT, constants!.FIELD_TEXT_FONTFAMILY); totalWidth += contentWidth; } if (this.borderRect_) { @@ -696,17 +696,17 @@ export abstract class Field implements IASTNodeLocationSvg, // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.textElement_.setAttribute( - 'x', - (this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : - xOffset) as AnyDuringMigration); + 'x', + (this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : + xOffset) as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.textElement_.setAttribute( - 'y', - (constants!.FIELD_TEXT_BASELINE_CENTER ? - halfHeight : - halfHeight - constants!.FIELD_TEXT_HEIGHT / 2 + - constants!.FIELD_TEXT_BASELINE) as AnyDuringMigration); + 'y', + (constants!.FIELD_TEXT_BASELINE_CENTER ? + halfHeight : + halfHeight - constants!.FIELD_TEXT_HEIGHT / 2 + + constants!.FIELD_TEXT_BASELINE) as AnyDuringMigration); } /** Position a field's border rect after a size change. */ @@ -717,21 +717,21 @@ export abstract class Field implements IASTNodeLocationSvg, // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.borderRect_.setAttribute( - 'width', this.size_.width as AnyDuringMigration); + 'width', this.size_.width as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.borderRect_.setAttribute( - 'height', this.size_.height as AnyDuringMigration); + 'height', this.size_.height as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.borderRect_.setAttribute( - 'rx', - this.getConstants()!.FIELD_BORDER_RECT_RADIUS as AnyDuringMigration); + 'rx', + this.getConstants()!.FIELD_BORDER_RECT_RADIUS as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.borderRect_.setAttribute( - 'ry', - this.getConstants()!.FIELD_BORDER_RECT_RADIUS as AnyDuringMigration); + 'ry', + this.getConstants()!.FIELD_BORDER_RECT_RADIUS as AnyDuringMigration); } /** @@ -752,8 +752,8 @@ export abstract class Field implements IASTNodeLocationSvg, // If the field is not visible the width will be 0 as well, one of the // problems with the old system. console.warn( - 'Deprecated use of setting size_.width to 0 to rerender a' + - ' field. Set field.isDirty_ to true instead.'); + 'Deprecated use of setting size_.width to 0 to rerender a' + + ' field. Set field.isDirty_ to true instead.'); this.render_(); } return this.size_; @@ -849,7 +849,7 @@ export abstract class Field implements IASTNodeLocationSvg, * Return null to resort to a string cast. * @return Current text or null. */ - protected getText_(): string | null { + protected getText_(): string|null { return null; } @@ -930,7 +930,7 @@ export abstract class Field implements IASTNodeLocationSvg, this.doValueUpdate_(newValue); if (source && eventUtils.isEnabled()) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (source, 'field', this.name || null, oldValue, newValue)); + (source, 'field', this.name || null, oldValue, newValue)); } if (this.isDirty_) { this.forceRerender(); @@ -945,8 +945,8 @@ export abstract class Field implements IASTNodeLocationSvg, * @return New value, or an Error object. */ private processValidation_( - newValue: AnyDuringMigration, - validatedValue: AnyDuringMigration): AnyDuringMigration { + newValue: AnyDuringMigration, + validatedValue: AnyDuringMigration): AnyDuringMigration { if (validatedValue === null) { this.doValueInvalid_(newValue); if (this.isDirty_) { @@ -975,7 +975,7 @@ export abstract class Field implements IASTNodeLocationSvg, * @return The validated value, same as input by default. */ protected doClassValidation_(opt_newValue?: AnyDuringMigration): - AnyDuringMigration { + AnyDuringMigration { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -1022,7 +1022,7 @@ export abstract class Field implements IASTNodeLocationSvg, * display the tooltip of the parent block. To not display a tooltip pass * the empty string. */ - setTooltip(newTip: Tooltip.TipInfo | null) { + setTooltip(newTip: Tooltip.TipInfo|null) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; @@ -1046,7 +1046,7 @@ export abstract class Field implements IASTNodeLocationSvg, return Tooltip.getTooltipOfObject(clickTarget); } // Field has not been initialized yet. Return stashed this.tooltip_ value. - return Tooltip.getTooltipOfObject({ tooltip: this.tooltip_ }); + return Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); } /** diff --git a/core/field_angle.ts b/core/field_angle.ts index 64776045a..1e13b0193 100644 --- a/core/field_angle.ts +++ b/core/field_angle.ts @@ -12,19 +12,19 @@ * @class */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as Css from './css.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { FieldTextInput } from './field_textinput.js'; +import {FieldTextInput} from './field_textinput.js'; import * as dom from './utils/dom.js'; -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; import * as math from './utils/math.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; -import { Svg } from './utils/svg.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; import * as WidgetDiv from './widgetdiv.js'; @@ -76,13 +76,13 @@ export class FieldAngle extends FieldTextInput { private round_: number; /** The angle picker's SVG element. */ - private editor_: SVGElement | null = null; + private editor_: SVGElement|null = null; /** The angle picker's gauge path depending on the value. */ - gauge_: SVGElement | null = null; + gauge_: SVGElement|null = null; /** The angle picker's line drawn representing the value's angle. */ - line_: SVGElement | null = null; + line_: SVGElement|null = null; /** The degree symbol for this field. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -90,13 +90,13 @@ export class FieldAngle extends FieldTextInput { protected symbol_: SVGTSpanElement = null as AnyDuringMigration; /** Wrapper click event data. */ - private clickWrapper_: browserEvents.Data | null = null; + private clickWrapper_: browserEvents.Data|null = null; /** Surface click event data. */ - private clickSurfaceWrapper_: browserEvents.Data | null = null; + private clickSurfaceWrapper_: browserEvents.Data|null = null; /** Surface mouse move event data. */ - private moveSurfaceWrapper_: browserEvents.Data | null = null; + private moveSurfaceWrapper_: browserEvents.Data|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -118,8 +118,8 @@ export class FieldAngle extends FieldTextInput { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | number | Sentinel, opt_validator?: Function, - opt_config?: AnyDuringMigration) { + opt_value?: string|number|Sentinel, opt_validator?: Function, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); /** @@ -242,22 +242,21 @@ export class FieldAngle extends FieldTextInput { if (this.sourceBlock_ instanceof BlockSvg) { dropDownDiv.setColour( - this.sourceBlock_.style.colourPrimary, - this.sourceBlock_.style.colourTertiary); + this.sourceBlock_.style.colourPrimary, + this.sourceBlock_.style.colourTertiary); } // AnyDuringMigration because: Argument of type 'this' is not assignable to // parameter of type 'Field'. dropDownDiv.showPositionedByField( - this as AnyDuringMigration, this.dropdownDispose_.bind(this)); + this as AnyDuringMigration, this.dropdownDispose_.bind(this)); this.updateGraph_(); } /** Create the angle dropdown editor. */ private dropdownCreate_() { - const svg = dom.createSvgElement( - Svg.SVG, { + const svg = dom.createSvgElement(Svg.SVG, { 'xmlns': dom.SVG_NS, 'xmlns:html': dom.HTML_NS, 'xmlns:xlink': dom.XLINK_NS, @@ -267,50 +266,50 @@ export class FieldAngle extends FieldTextInput { 'style': 'touch-action: none', }); const circle = dom.createSvgElement( - Svg.CIRCLE, { - 'cx': FieldAngle.HALF, - 'cy': FieldAngle.HALF, - 'r': FieldAngle.RADIUS, - 'class': 'blocklyAngleCircle', - }, - svg); + Svg.CIRCLE, { + 'cx': FieldAngle.HALF, + 'cy': FieldAngle.HALF, + 'r': FieldAngle.RADIUS, + 'class': 'blocklyAngleCircle', + }, + svg); this.gauge_ = - dom.createSvgElement(Svg.PATH, { 'class': 'blocklyAngleGauge' }, svg); + dom.createSvgElement(Svg.PATH, {'class': 'blocklyAngleGauge'}, svg); this.line_ = dom.createSvgElement( - Svg.LINE, { - 'x1': FieldAngle.HALF, - 'y1': FieldAngle.HALF, - 'class': 'blocklyAngleLine', - }, - svg); + Svg.LINE, { + 'x1': FieldAngle.HALF, + 'y1': FieldAngle.HALF, + 'class': 'blocklyAngleLine', + }, + svg); // Draw markers around the edge. for (let angle = 0; angle < 360; angle += 15) { dom.createSvgElement( - Svg.LINE, { - 'x1': FieldAngle.HALF + FieldAngle.RADIUS, - 'y1': FieldAngle.HALF, - 'x2': FieldAngle.HALF + FieldAngle.RADIUS - - (angle % 45 === 0 ? 10 : 5), - 'y2': FieldAngle.HALF, - 'class': 'blocklyAngleMarks', - 'transform': 'rotate(' + angle + ',' + FieldAngle.HALF + ',' + - FieldAngle.HALF + ')', - }, - svg); + Svg.LINE, { + 'x1': FieldAngle.HALF + FieldAngle.RADIUS, + 'y1': FieldAngle.HALF, + 'x2': FieldAngle.HALF + FieldAngle.RADIUS - + (angle % 45 === 0 ? 10 : 5), + 'y2': FieldAngle.HALF, + 'class': 'blocklyAngleMarks', + 'transform': 'rotate(' + angle + ',' + FieldAngle.HALF + ',' + + FieldAngle.HALF + ')', + }, + svg); } // The angle picker is different from other fields in that it updates on // mousemove even if it's not in the middle of a drag. In future we may // change this behaviour. this.clickWrapper_ = - browserEvents.conditionalBind(svg, 'click', this, this.hide_); + browserEvents.conditionalBind(svg, 'click', this, this.hide_); // On touch devices, the picker's value is only updated with a drag. Add // a click handler on the drag surface to update the value if the surface // is clicked. this.clickSurfaceWrapper_ = browserEvents.conditionalBind( - circle, 'click', this, this.onMouseMove_, true, true); + circle, 'click', this, this.onMouseMove_, true, true); this.moveSurfaceWrapper_ = browserEvents.conditionalBind( - circle, 'mousemove', this, this.onMouseMove_, true, true); + circle, 'mousemove', this, this.onMouseMove_, true, true); this.editor_ = svg; } @@ -414,13 +413,13 @@ export class FieldAngle extends FieldTextInput { y2 -= Math.sin(angleRadians) * FieldAngle.RADIUS; // Don't ask how the flag calculations work. They just do. let largeFlag = - Math.abs(Math.floor((angleRadians - angle1) / Math.PI) % 2); + Math.abs(Math.floor((angleRadians - angle1) / Math.PI) % 2); if (clockwiseFlag) { largeFlag = 1 - largeFlag; } path.push( - ' l ', x1, ',', y1, ' A ', FieldAngle.RADIUS, ',', FieldAngle.RADIUS, - ' 0 ', largeFlag, ' ', clockwiseFlag, ' ', x2, ',', y2, ' z'); + ' l ', x1, ',', y1, ' A ', FieldAngle.RADIUS, ',', FieldAngle.RADIUS, + ' 0 ', largeFlag, ' ', clockwiseFlag, ' ', x2, ',', y2, ' z'); } this.gauge_.setAttribute('d', path.join('')); // AnyDuringMigration because: Argument of type 'number' is not assignable @@ -474,7 +473,7 @@ export class FieldAngle extends FieldTextInput { * @return A valid angle, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - number | null { + number|null { const value = Number(opt_newValue); if (isNaN(value) || !isFinite(value)) { return null; diff --git a/core/field_checkbox.ts b/core/field_checkbox.ts index e356715cc..707efbd25 100644 --- a/core/field_checkbox.ts +++ b/core/field_checkbox.ts @@ -15,11 +15,11 @@ // Unused import preserved for side-effects. Remove if unneeded. import './events/events_block_change'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; +import {Sentinel} from './utils/sentinel.js'; /** @@ -61,8 +61,8 @@ export class FieldCheckbox extends Field { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | boolean | Sentinel, opt_validator?: Function, - opt_config?: AnyDuringMigration) { + opt_value?: string|boolean|Sentinel, opt_validator?: Function, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); /** @@ -130,7 +130,7 @@ export class FieldCheckbox extends Field { * @param character The character to use for the check mark, or null to use * the default. */ - setCheckCharacter(character: string | null) { + setCheckCharacter(character: string|null) { this.checkChar_ = character || FieldCheckbox.CHECK_CHAR; this.forceRerender(); } @@ -146,7 +146,7 @@ export class FieldCheckbox extends Field { * @return A valid value ('TRUE' or 'FALSE), or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { if (opt_newValue === true || opt_newValue === 'TRUE') { return 'TRUE'; } diff --git a/core/field_colour.ts b/core/field_colour.ts index 19425a9ec..21807ee4e 100644 --- a/core/field_colour.ts +++ b/core/field_colour.ts @@ -15,20 +15,20 @@ // Unused import preserved for side-effects. Remove if unneeded. import './events/events_block_change'; -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as Css from './css.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; import * as aria from './utils/aria.js'; import * as colour from './utils/colour.js'; import * as dom from './utils/dom.js'; import * as idGenerator from './utils/idgenerator.js'; -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; -import { Size } from './utils/size.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Size} from './utils/size.js'; /** @@ -80,25 +80,25 @@ export class FieldColour extends Field { static COLUMNS = 7; /** The field's colour picker element. */ - private picker_: Element | null = null; + private picker_: Element|null = null; /** Index of the currently highlighted element. */ - private highlightedIndex_: number | null = null; + private highlightedIndex_: number|null = null; /** Mouse click event data. */ - private onClickWrapper_: browserEvents.Data | null = null; + private onClickWrapper_: browserEvents.Data|null = null; /** Mouse move event data. */ - private onMouseMoveWrapper_: browserEvents.Data | null = null; + private onMouseMoveWrapper_: browserEvents.Data|null = null; /** Mouse enter event data. */ - private onMouseEnterWrapper_: browserEvents.Data | null = null; + private onMouseEnterWrapper_: browserEvents.Data|null = null; /** Mouse leave event data. */ - private onMouseLeaveWrapper_: browserEvents.Data | null = null; + private onMouseLeaveWrapper_: browserEvents.Data|null = null; /** Key down event data. */ - private onKeyDownWrapper_: browserEvents.Data | null = null; + private onKeyDownWrapper_: browserEvents.Data|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -153,8 +153,8 @@ export class FieldColour extends Field { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | Sentinel, opt_validator?: Function, - opt_config?: AnyDuringMigration) { + opt_value?: string|Sentinel, opt_validator?: Function, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); if (opt_value === Field.SKIP_SETUP) { @@ -187,8 +187,8 @@ export class FieldColour extends Field { /** Create the block UI for this colour field. */ override initView() { this.size_ = new Size( - this.getConstants()!.FIELD_COLOUR_DEFAULT_WIDTH, - this.getConstants()!.FIELD_COLOUR_DEFAULT_HEIGHT); + this.getConstants()!.FIELD_COLOUR_DEFAULT_WIDTH, + this.getConstants()!.FIELD_COLOUR_DEFAULT_HEIGHT); if (!this.getConstants()!.FIELD_COLOUR_FULL_BLOCK) { this.createBorderRect_(); this.borderRect_.style['fillOpacity'] = '1'; @@ -204,7 +204,7 @@ export class FieldColour extends Field { } } else if (this.sourceBlock_ instanceof BlockSvg) { this.sourceBlock_.pathObject.svgPath.setAttribute( - 'fill', this.getValue() as string); + 'fill', this.getValue() as string); this.sourceBlock_.pathObject.svgPath.setAttribute('stroke', '#fff'); } } @@ -215,7 +215,7 @@ export class FieldColour extends Field { * @return A valid colour, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { if (typeof opt_newValue !== 'string') { return null; } @@ -232,10 +232,10 @@ export class FieldColour extends Field { if (this.borderRect_) { this.borderRect_.style.fill = newValue as string; } else if ( - this.sourceBlock_ && this.sourceBlock_.rendered && - this.sourceBlock_ instanceof BlockSvg) { + this.sourceBlock_ && this.sourceBlock_.rendered && + this.sourceBlock_ instanceof BlockSvg) { this.sourceBlock_.pathObject.svgPath.setAttribute( - 'fill', newValue as string); + 'fill', newValue as string); this.sourceBlock_.pathObject.svgPath.setAttribute('stroke', '#fff'); } } @@ -292,7 +292,7 @@ export class FieldColour extends Field { // Focus so we can start receiving keyboard events. // AnyDuringMigration because: Property 'focus' does not exist on type // 'Element'. - (this.picker_ as AnyDuringMigration)!.focus({ preventScroll: true }); + (this.picker_ as AnyDuringMigration)!.focus({preventScroll: true}); } /** @@ -417,7 +417,7 @@ export class FieldColour extends Field { private onMouseEnter_() { // AnyDuringMigration because: Property 'focus' does not exist on type // 'Element'. - (this.picker_ as AnyDuringMigration)!.focus({ preventScroll: true }); + (this.picker_ as AnyDuringMigration)!.focus({preventScroll: true}); } /** @@ -438,7 +438,7 @@ export class FieldColour extends Field { * Returns the currently highlighted item (if any). * @return Highlighted item (null if none). */ - private getHighlighted_(): HTMLElement | null { + private getHighlighted_(): HTMLElement|null { if (!this.highlightedIndex_) { return null; } @@ -474,8 +474,8 @@ export class FieldColour extends Field { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string | number | boolean | string[]'. aria.setState( - this.picker_ as Element, aria.State.ACTIVEDESCENDANT, - cell.getAttribute('id') as AnyDuringMigration); + this.picker_ as Element, aria.State.ACTIVEDESCENDANT, + cell.getAttribute('id') as AnyDuringMigration); } /** Create a colour picker dropdown editor. */ @@ -492,7 +492,7 @@ export class FieldColour extends Field { aria.setRole(table, aria.Role.GRID); aria.setState(table, aria.State.EXPANDED, true); aria.setState( - table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); + table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); aria.setState(table, aria.State.COLCOUNT, columns); let row: Element; for (let i = 0; i < colours.length; i++) { @@ -522,15 +522,15 @@ export class FieldColour extends Field { // Configure event handler on the table to listen for any event in a cell. this.onClickWrapper_ = browserEvents.conditionalBind( - table, 'click', this, this.onClick_, true); + table, 'click', this, this.onClick_, true); this.onMouseMoveWrapper_ = browserEvents.conditionalBind( - table, 'mousemove', this, this.onMouseMove_, true); + table, 'mousemove', this, this.onMouseMove_, true); this.onMouseEnterWrapper_ = browserEvents.conditionalBind( - table, 'mouseenter', this, this.onMouseEnter_, true); + table, 'mouseenter', this, this.onMouseEnter_, true); this.onMouseLeaveWrapper_ = browserEvents.conditionalBind( - table, 'mouseleave', this, this.onMouseLeave_, true); + table, 'mouseleave', this, this.onMouseLeave_, true); this.onKeyDownWrapper_ = - browserEvents.conditionalBind(table, 'keydown', this, this.onKeyDown_); + browserEvents.conditionalBind(table, 'keydown', this, this.onKeyDown_); this.picker_ = table; } @@ -578,7 +578,7 @@ export class FieldColour extends Field { // AnyDuringMigration because: Property 'DEFAULT_VALUE' is protected and only // accessible within class 'FieldColour' and its subclasses. (FieldColour.prototype as AnyDuringMigration).DEFAULT_VALUE = - FieldColour.COLOURS[0]; + FieldColour.COLOURS[0]; /** CSS for colour picker. See css.js for use. */ Css.register(` diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index cec4fd7ec..963ef5b94 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -19,20 +19,20 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { Menu } from './menu.js'; -import { MenuItem } from './menuitem.js'; +import {Menu} from './menu.js'; +import {MenuItem} from './menuitem.js'; import * as aria from './utils/aria.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; +import {Sentinel} from './utils/sentinel.js'; import * as utilsString from './utils/string.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; @@ -52,21 +52,21 @@ export class FieldDropdown extends Field { static ARROW_CHAR: AnyDuringMigration; /** A reference to the currently selected menu item. */ - private selectedMenuItem_: MenuItem | null = null; + private selectedMenuItem_: MenuItem|null = null; /** The dropdown menu. */ - protected menu_: Menu | null = null; + protected menu_: Menu|null = null; /** * SVG image element if currently selected option is an image, or null. */ - private imageElement_: SVGImageElement | null = null; + private imageElement_: SVGImageElement|null = null; /** Tspan based arrow element. */ - private arrow_: SVGTSpanElement | null = null; + private arrow_: SVGTSpanElement|null = null; /** SVG based arrow element. */ - private svgArrow_: SVGElement | null = null; + private svgArrow_: SVGElement|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -77,8 +77,8 @@ export class FieldDropdown extends Field { /** Mouse cursor style when over the hotspot that initiates the editor. */ override CURSOR = 'default'; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - protected menuGenerator_!: AnyDuringMigration[][] | - ((this: FieldDropdown) => AnyDuringMigration[][]); + protected menuGenerator_!: AnyDuringMigration[][]| + ((this: FieldDropdown) => AnyDuringMigration[][]); /** A cache of the most recently generated options. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -88,14 +88,14 @@ export class FieldDropdown extends Field { /** * The prefix field label, of common words set after options are trimmed. */ - override prefixField: string | null = null; + override prefixField: string|null = null; /** * The suffix field label, of common words set after options are trimmed. */ - override suffixField: string | null = null; + override suffixField: string|null = null; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - private selectedOption_!: Array; + private selectedOption_!: Array; override clickTarget_: AnyDuringMigration; /** @@ -115,8 +115,8 @@ export class FieldDropdown extends Field { * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ constructor( - menuGenerator: AnyDuringMigration[][] | Function | Sentinel, - opt_validator?: Function, opt_config?: AnyDuringMigration) { + menuGenerator: AnyDuringMigration[][]|Function|Sentinel, + opt_validator?: Function, opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); @@ -134,7 +134,7 @@ export class FieldDropdown extends Field { * or a function which generates these options. */ this.menuGenerator_ = menuGenerator as AnyDuringMigration[][] | - ((this: FieldDropdown) => AnyDuringMigration[][]); + ((this: FieldDropdown) => AnyDuringMigration[][]); this.trimOptions_(); @@ -207,21 +207,21 @@ export class FieldDropdown extends Field { */ protected shouldAddBorderRect_(): boolean { return !this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || - this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && - !this.sourceBlock_.isShadow(); + this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && + !this.sourceBlock_.isShadow(); } /** Create a tspan based arrow. */ protected createTextArrow_() { this.arrow_ = dom.createSvgElement(Svg.TSPAN, {}, this.textElement_); this.arrow_!.appendChild(document.createTextNode( - this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : - ' ' + FieldDropdown.ARROW_CHAR)); + this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { // AnyDuringMigration because: Argument of type 'SVGTSpanElement | null' // is not assignable to parameter of type 'Node'. this.textElement_.insertBefore( - this.arrow_ as AnyDuringMigration, this.textContent_); + this.arrow_ as AnyDuringMigration, this.textContent_); } else { // AnyDuringMigration because: Argument of type 'SVGTSpanElement | null' // is not assignable to parameter of type 'Node'. @@ -232,14 +232,14 @@ export class FieldDropdown extends Field { /** Create an SVG based arrow. */ protected createSVGArrow_() { this.svgArrow_ = dom.createSvgElement( - Svg.IMAGE, { - 'height': this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', - 'width': this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', - }, - this.fieldGroup_); + Svg.IMAGE, { + 'height': this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', + 'width': this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', + }, + this.fieldGroup_); this.svgArrow_!.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_DATAURI); + dom.XLINK_NS, 'xlink:href', + this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_DATAURI); } /** @@ -256,8 +256,8 @@ export class FieldDropdown extends Field { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. this.menu_!.openingCoords = new Coordinate( - (opt_e as AnyDuringMigration).clientX, - (opt_e as AnyDuringMigration).clientY); + (opt_e as AnyDuringMigration).clientX, + (opt_e as AnyDuringMigration).clientY); } else { this.menu_!.openingCoords = null; } @@ -271,11 +271,11 @@ export class FieldDropdown extends Field { if (this.getConstants()!.FIELD_DROPDOWN_COLOURED_DIV) { const primaryColour = this.sourceBlock_.isShadow() ? - this.sourceBlock_.getParent()!.getColour() : - this.sourceBlock_.getColour(); + this.sourceBlock_.getParent()!.getColour() : + this.sourceBlock_.getColour(); const borderColour = this.sourceBlock_.isShadow() ? - (this.sourceBlock_.getParent() as BlockSvg).style.colourTertiary : - (this.sourceBlock_ as BlockSvg).style.colourTertiary; + (this.sourceBlock_.getParent() as BlockSvg).style.colourTertiary : + (this.sourceBlock_ as BlockSvg).style.colourTertiary; dropDownDiv.setColour(primaryColour, borderColour); } @@ -405,7 +405,7 @@ export class FieldDropdown extends Field { } this.menuGenerator_ = - FieldDropdown.applyTrim_(options, prefixLength, suffixLength); + FieldDropdown.applyTrim_(options, prefixLength, suffixLength); } /** @@ -430,7 +430,7 @@ export class FieldDropdown extends Field { // AnyDuringMigration because: Property 'call' does not exist on type // 'any[][] | ((this: FieldDropdown) => any[][])'. this.generatedOptions_ = - (this.menuGenerator_ as AnyDuringMigration).call(this); + (this.menuGenerator_ as AnyDuringMigration).call(this); validateOptions(this.generatedOptions_); } return this.generatedOptions_; @@ -444,7 +444,7 @@ export class FieldDropdown extends Field { * @return A valid language-neutral option, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { let isValueValid = false; const options = this.getOptions(true); for (let i = 0, option; option = options[i]; i++) { @@ -457,9 +457,9 @@ export class FieldDropdown extends Field { if (!isValueValid) { if (this.sourceBlock_) { console.warn( - 'Cannot set the dropdown\'s value to an unavailable option.' + - ' Block type: ' + this.sourceBlock_.type + - ', Field name: ' + this.name + ', Value: ' + opt_newValue); + 'Cannot set the dropdown\'s value to an unavailable option.' + + ' Block type: ' + this.sourceBlock_.type + + ', Field name: ' + this.name + ', Value: ' + opt_newValue); } return null; } @@ -526,15 +526,15 @@ export class FieldDropdown extends Field { private renderSelectedImage_(imageJson: ImageProperties) { this.imageElement_!.style.display = ''; this.imageElement_!.setAttributeNS( - dom.XLINK_NS, 'xlink:href', imageJson.src); + dom.XLINK_NS, 'xlink:href', imageJson.src); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.imageElement_!.setAttribute( - 'height', imageJson.height as AnyDuringMigration); + 'height', imageJson.height as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.imageElement_!.setAttribute( - 'width', imageJson.width as AnyDuringMigration); + 'width', imageJson.width as AnyDuringMigration); const imageHeight = Number(imageJson.height); const imageWidth = Number(imageJson.width); @@ -542,21 +542,21 @@ export class FieldDropdown extends Field { // Height and width include the border rect. const hasBorder = !!this.borderRect_; const height = Math.max( - hasBorder ? this.getConstants()!.FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + IMAGE_Y_PADDING); + hasBorder ? this.getConstants()!.FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, + imageHeight + IMAGE_Y_PADDING); const xPadding = - hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; + hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_( - imageWidth + xPadding, - height / 2 - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + imageWidth + xPadding, + height / 2 - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { arrowWidth = dom.getFastTextWidth( - this.arrow_ as SVGTSpanElement, - this.getConstants()!.FIELD_TEXT_FONTSIZE, - this.getConstants()!.FIELD_TEXT_FONTWEIGHT, - this.getConstants()!.FIELD_TEXT_FONTFAMILY); + this.arrow_ as SVGTSpanElement, + this.getConstants()!.FIELD_TEXT_FONTSIZE, + this.getConstants()!.FIELD_TEXT_FONTWEIGHT, + this.getConstants()!.FIELD_TEXT_FONTFAMILY); } this.size_.width = imageWidth + arrowWidth + xPadding * 2; this.size_.height = height; @@ -570,7 +570,8 @@ export class FieldDropdown extends Field { this.textElement_.setAttribute('text-anchor', 'end'); this.imageElement_!.setAttribute('x', xPadding.toString()); } - this.imageElement_!.setAttribute('y', (height / 2 - imageHeight / 2).toString()); + this.imageElement_!.setAttribute( + 'y', (height / 2 - imageHeight / 2).toString()); this.positionTextElement_(arrowX + xPadding, imageWidth + arrowWidth); } @@ -585,19 +586,19 @@ export class FieldDropdown extends Field { // Height and width include the border rect. const hasBorder = !!this.borderRect_; const height = Math.max( - hasBorder ? this.getConstants()!.FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - this.getConstants()!.FIELD_TEXT_HEIGHT); + hasBorder ? this.getConstants()!.FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, + this.getConstants()!.FIELD_TEXT_HEIGHT); const textWidth = dom.getFastTextWidth( - this.textElement_, this.getConstants()!.FIELD_TEXT_FONTSIZE, - this.getConstants()!.FIELD_TEXT_FONTWEIGHT, - this.getConstants()!.FIELD_TEXT_FONTFAMILY); + this.textElement_, this.getConstants()!.FIELD_TEXT_FONTSIZE, + this.getConstants()!.FIELD_TEXT_FONTWEIGHT, + this.getConstants()!.FIELD_TEXT_FONTFAMILY); const xPadding = - hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; + hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_( - textWidth + xPadding, - height / 2 - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + textWidth + xPadding, + height / 2 - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } this.size_.width = textWidth + arrowWidth + xPadding * 2; this.size_.height = height; @@ -617,12 +618,12 @@ export class FieldDropdown extends Field { } const hasBorder = !!this.borderRect_; const xPadding = - hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; + hasBorder ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; const textPadding = this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_PADDING; const svgArrowSize = this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE; const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; this.svgArrow_.setAttribute( - 'transform', 'translate(' + arrowX + ',' + y + ')'); + 'transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; } @@ -632,7 +633,7 @@ export class FieldDropdown extends Field { * image we return the image alt text. * @return Selected option text. */ - protected override getText_(): string | null { + protected override getText_(): string|null { if (!this.selectedOption_) { return null; } @@ -665,8 +666,8 @@ export class FieldDropdown extends Field { * @return A new array with all of the option text trimmed. */ static applyTrim_( - options: AnyDuringMigration[][], prefixLength: number, - suffixLength: number): AnyDuringMigration[][] { + options: AnyDuringMigration[][], prefixLength: number, + suffixLength: number): AnyDuringMigration[][] { const newOptions = []; // Remove the prefix and suffix from the options. for (let i = 0; i < options.length; i++) { @@ -717,23 +718,23 @@ function validateOptions(options: AnyDuringMigration) { if (!Array.isArray(tuple)) { foundError = true; console.error( - 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + - 'array. Found: ', - tuple); + 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + + 'array. Found: ', + tuple); } else if (typeof tuple[1] !== 'string') { foundError = true; console.error( - 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + - 'a string. Found ' + tuple[1] + ' in: ', - tuple); + 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + + 'a string. Found ' + tuple[1] + ' in: ', + tuple); } else if ( - tuple[0] && typeof tuple[0] !== 'string' && - typeof tuple[0].src !== 'string') { + tuple[0] && typeof tuple[0] !== 'string' && + typeof tuple[0].src !== 'string') { foundError = true; console.error( - 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + - 'string label or image description. Found' + tuple[0] + ' in: ', - tuple); + 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + + 'string label or image description. Found' + tuple[0] + ' in: ', + tuple); } } if (foundError) { diff --git a/core/field_image.ts b/core/field_image.ts index 177b7f7c7..0afc1cdc8 100644 --- a/core/field_image.ts +++ b/core/field_image.ts @@ -12,14 +12,14 @@ * @class */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; import * as dom from './utils/dom.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; /** @@ -39,7 +39,7 @@ export class FieldImage extends Field { private readonly imageHeight_: number; /** The function to be called when this field is clicked. */ - private clickHandler_: ((p1: FieldImage) => AnyDuringMigration) | null = null; + private clickHandler_: ((p1: FieldImage) => AnyDuringMigration)|null = null; /** The rendered field's image element. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -83,9 +83,9 @@ export class FieldImage extends Field { * for a list of properties this parameter supports. */ constructor( - src: string | Sentinel, width: string | number, height: string | number, - opt_alt?: string, opt_onClick?: (p1: FieldImage) => AnyDuringMigration, - opt_flipRtl?: boolean, opt_config?: AnyDuringMigration) { + src: string|Sentinel, width: string|number, height: string|number, + opt_alt?: string, opt_onClick?: (p1: FieldImage) => AnyDuringMigration, + opt_flipRtl?: boolean, opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); // Return early. @@ -96,13 +96,13 @@ export class FieldImage extends Field { const imageWidth = Number(parsing.replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error( - 'Height and width values of an image field must cast to' + - ' numbers.'); + 'Height and width values of an image field must cast to' + + ' numbers.'); } if (imageHeight <= 0 || imageWidth <= 0) { throw Error( - 'Height and width values of an image field must be greater' + - ' than 0.'); + 'Height and width values of an image field must be greater' + + ' than 0.'); } /** The size of the area rendered by the field. */ @@ -143,14 +143,14 @@ export class FieldImage extends Field { /** Create the block UI for this image. */ override initView() { this.imageElement_ = dom.createSvgElement( - Svg.IMAGE, { - 'height': this.imageHeight_ + 'px', - 'width': this.size_.width + 'px', - 'alt': this.altText_, - }, - this.fieldGroup_); + Svg.IMAGE, { + 'height': this.imageHeight_ + 'px', + 'width': this.size_.width + 'px', + 'alt': this.altText_, + }, + this.fieldGroup_); this.imageElement_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', this.value_ as string); + dom.XLINK_NS, 'xlink:href', this.value_ as string); if (this.clickHandler_) { this.imageElement_.style.cursor = 'pointer'; @@ -166,7 +166,7 @@ export class FieldImage extends Field { * @return A string, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { if (typeof opt_newValue !== 'string') { return null; } @@ -182,7 +182,7 @@ export class FieldImage extends Field { this.value_ = newValue; if (this.imageElement_) { this.imageElement_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', String(this.value_)); + dom.XLINK_NS, 'xlink:href', String(this.value_)); } } @@ -198,7 +198,7 @@ export class FieldImage extends Field { * Set the alt text of this image. * @param alt New alt text. */ - setAlt(alt: string | null) { + setAlt(alt: string|null) { if (alt === this.altText_) { return; } @@ -223,7 +223,7 @@ export class FieldImage extends Field { * @param func The function that is called when the image is clicked, or null * to remove. */ - setOnClickHandler(func: ((p1: FieldImage) => AnyDuringMigration) | null) { + setOnClickHandler(func: ((p1: FieldImage) => AnyDuringMigration)|null) { this.clickHandler_ = func; } @@ -233,7 +233,7 @@ export class FieldImage extends Field { * Return the image alt text instead. * @return The image alt text. */ - protected override getText_(): string | null { + protected override getText_(): string|null { return this.altText_; } @@ -249,8 +249,8 @@ export class FieldImage extends Field { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. return new this( - options['src'], options['width'], options['height'], undefined, - undefined, undefined, options); + options['src'], options['width'], options['height'], undefined, + undefined, undefined, options); } } diff --git a/core/field_label.ts b/core/field_label.ts index 23d7cb569..bc5b42328 100644 --- a/core/field_label.ts +++ b/core/field_label.ts @@ -16,12 +16,12 @@ * @class */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; import * as dom from './utils/dom.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; +import {Sentinel} from './utils/sentinel.js'; /** @@ -33,7 +33,7 @@ export class FieldLabel extends Field { protected override DEFAULT_VALUE = ''; /** The html class name to use for this field. */ - private class_: string | null = null; + private class_: string|null = null; /** * Editable fields usually show some sort of UI indicating they are @@ -54,8 +54,8 @@ export class FieldLabel extends Field { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | Sentinel, opt_class?: string, - opt_config?: AnyDuringMigration) { + opt_value?: string|Sentinel, opt_class?: string, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); if (opt_value === Field.SKIP_SETUP) { @@ -88,7 +88,7 @@ export class FieldLabel extends Field { * @return A valid string, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -99,7 +99,7 @@ export class FieldLabel extends Field { * Set the CSS class applied to the field's textElement_. * @param cssClass The new CSS class name, or null to remove. */ - setClass(cssClass: string | null) { + setClass(cssClass: string|null) { if (this.textElement_) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. diff --git a/core/field_label_serializable.ts b/core/field_label_serializable.ts index 2474e95f7..bd3b35076 100644 --- a/core/field_label_serializable.ts +++ b/core/field_label_serializable.ts @@ -18,7 +18,7 @@ * @class */ -import { FieldLabel } from './field_label.js'; +import {FieldLabel} from './field_label.js'; import * as fieldRegistry from './field_registry.js'; import * as parsing from './utils/parsing.js'; @@ -51,7 +51,7 @@ export class FieldLabelSerializable extends FieldLabel { * for a list of properties this parameter supports. */ constructor( - opt_value?: string, opt_class?: string, opt_config?: AnyDuringMigration) { + opt_value?: string, opt_class?: string, opt_config?: AnyDuringMigration) { super(String(opt_value ?? ''), opt_class, opt_config); } @@ -63,7 +63,7 @@ export class FieldLabelSerializable extends FieldLabel { * @nocollapse */ static override fromJson(options: AnyDuringMigration): - FieldLabelSerializable { + FieldLabelSerializable { const text = parsing.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class // doesn't override the static fromJson method. diff --git a/core/field_multilineinput.ts b/core/field_multilineinput.ts index aa5a52484..b6a61a324 100644 --- a/core/field_multilineinput.ts +++ b/core/field_multilineinput.ts @@ -13,16 +13,16 @@ */ import * as Css from './css.js'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { FieldTextInput } from './field_textinput.js'; +import {FieldTextInput} from './field_textinput.js'; import * as aria from './utils/aria.js'; import * as dom from './utils/dom.js'; -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; -import { Svg } from './utils/svg.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; import * as WidgetDiv from './widgetdiv.js'; @@ -65,8 +65,8 @@ export class FieldMultilineInput extends FieldTextInput { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | Sentinel, opt_validator?: Function, - opt_config?: AnyDuringMigration) { + opt_value?: string|Sentinel, opt_validator?: Function, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); if (opt_value === Field.SKIP_SETUP) { @@ -98,7 +98,7 @@ export class FieldMultilineInput extends FieldTextInput { // `Blockly.Xml.domToText` will appear on a single line (this is a // limitation of the plain-text format). fieldElement.textContent = - (this.getValue() as string).replace(/\n/g, ' '); + (this.getValue() as string).replace(/\n/g, ' '); return fieldElement; } @@ -138,10 +138,10 @@ export class FieldMultilineInput extends FieldTextInput { override initView() { this.createBorderRect_(); this.textGroup_ = dom.createSvgElement( - Svg.G, { - 'class': 'blocklyEditableText', - }, - this.fieldGroup_); + Svg.G, { + 'class': 'blocklyEditableText', + }, + this.fieldGroup_); } /** @@ -158,7 +158,7 @@ export class FieldMultilineInput extends FieldTextInput { const lines = textLines.split('\n'); textLines = ''; const displayLinesNumber = - this.isOverflowedY_ ? this.maxLines_ : lines.length; + this.isOverflowedY_ ? this.maxLines_ : lines.length; for (let i = 0; i < displayLinesNumber; i++) { let text = lines[i]; if (text.length > this.maxDisplayLength) { @@ -209,15 +209,15 @@ export class FieldMultilineInput extends FieldTextInput { let y = 0; for (let i = 0; i < lines.length; i++) { const lineHeight = this.getConstants()!.FIELD_TEXT_HEIGHT + - this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING; + this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING; const span = dom.createSvgElement( - Svg.TEXT, { - 'class': 'blocklyText blocklyMultilineText', - 'x': this.getConstants()!.FIELD_BORDER_RECT_X_PADDING, - 'y': y + this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING, - 'dy': this.getConstants()!.FIELD_TEXT_BASELINE, - }, - this.textGroup_); + Svg.TEXT, { + 'class': 'blocklyText blocklyMultilineText', + 'x': this.getConstants()!.FIELD_BORDER_RECT_X_PADDING, + 'y': y + this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING, + 'dy': this.getConstants()!.FIELD_TEXT_BASELINE, + }, + this.textGroup_); span.appendChild(document.createTextNode(lines[i])); y += lineHeight; } @@ -265,7 +265,7 @@ export class FieldMultilineInput extends FieldTextInput { totalWidth = textWidth; } totalHeight += this.getConstants()!.FIELD_TEXT_HEIGHT + - (i > 0 ? this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING : 0); + (i > 0 ? this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING : 0); } if (this.isBeingEdited_) { // The default width is based on the longest line in the display text, @@ -275,7 +275,7 @@ export class FieldMultilineInput extends FieldTextInput { // lines than this.maxLines_. const actualEditorLines = this.value_.split('\n'); const dummyTextElement = dom.createSvgElement( - Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText' }); + Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); const fontSize = this.getConstants()!.FIELD_TEXT_FONTSIZE; const fontWeight = this.getConstants()!.FIELD_TEXT_FONTWEIGHT; const fontFamily = this.getConstants()!.FIELD_TEXT_FONTFAMILY; @@ -283,18 +283,18 @@ export class FieldMultilineInput extends FieldTextInput { for (let i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { actualEditorLines[i] = - actualEditorLines[i].substring(0, this.maxDisplayLength); + actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; const lineWidth = dom.getFastTextWidth( - dummyTextElement, fontSize, fontWeight, fontFamily); + dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; } } const scrollbarWidth = - this.htmlInput_!.offsetWidth - this.htmlInput_!.clientWidth; + this.htmlInput_!.offsetWidth - this.htmlInput_!.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -306,7 +306,7 @@ export class FieldMultilineInput extends FieldTextInput { // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. this.borderRect_.setAttribute( - 'height', totalHeight as AnyDuringMigration); + 'height', totalHeight as AnyDuringMigration); } this.size_.width = totalWidth; this.size_.height = totalHeight; @@ -341,7 +341,7 @@ export class FieldMultilineInput extends FieldTextInput { // AnyDuringMigration because: Argument of type 'boolean' is not assignable // to parameter of type 'string'. htmlInput.setAttribute( - 'spellcheck', this.spellcheck_ as AnyDuringMigration); + 'spellcheck', this.spellcheck_ as AnyDuringMigration); const fontSize = this.getConstants()!.FIELD_TEXT_FONTSIZE * scale + 'pt'; div!.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; @@ -349,11 +349,11 @@ export class FieldMultilineInput extends FieldTextInput { htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants()!.FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = - this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING * scale / 2; + this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING * scale / 2; htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + - 'px ' + paddingX + 'px'; + 'px ' + paddingX + 'px'; const lineHeight = this.getConstants()!.FIELD_TEXT_HEIGHT + - this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING; + this.getConstants()!.FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = lineHeight * scale + 'px'; div!.appendChild(htmlInput); @@ -380,7 +380,7 @@ export class FieldMultilineInput extends FieldTextInput { */ setMaxLines(maxLines: number) { if (typeof maxLines === 'number' && maxLines > 0 && - maxLines !== this.maxLines_) { + maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); } diff --git a/core/field_number.ts b/core/field_number.ts index bad1a2ca0..d3e582413 100644 --- a/core/field_number.ts +++ b/core/field_number.ts @@ -12,12 +12,12 @@ * @class */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { FieldTextInput } from './field_textinput.js'; +import {FieldTextInput} from './field_textinput.js'; import * as aria from './utils/aria.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; +import {Sentinel} from './utils/sentinel.js'; /** @@ -41,7 +41,7 @@ export class FieldNumber extends FieldTextInput { * The number of decimal places to allow, or null to allow any number of * decimal digits. */ - private decimalPlaces_: number | null = null; + private decimalPlaces_: number|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -69,9 +69,9 @@ export class FieldNumber extends FieldTextInput { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | number | Sentinel, opt_min?: string | number | null, - opt_max?: string | number | null, opt_precision?: string | number | null, - opt_validator?: Function | null, opt_config?: AnyDuringMigration) { + opt_value?: string|number|Sentinel, opt_min?: string|number|null, + opt_max?: string|number|null, opt_precision?: string|number|null, + opt_validator?: Function|null, opt_config?: AnyDuringMigration) { // Pass SENTINEL so that we can define properties before value validation. super(Field.SKIP_SETUP); @@ -113,8 +113,8 @@ export class FieldNumber extends FieldTextInput { * @param precision Precision for value. */ setConstraints( - min: number | string | undefined | null, max: number | string | undefined | null, - precision: number | string | undefined | null) { + min: number|string|undefined|null, max: number|string|undefined|null, + precision: number|string|undefined|null) { this.setMinInternal_(min); this.setMaxInternal_(max); this.setPrecisionInternal_(precision); @@ -126,7 +126,7 @@ export class FieldNumber extends FieldTextInput { * reflect. * @param min Minimum value. */ - setMin(min: number | string | undefined | null) { + setMin(min: number|string|undefined|null) { this.setMinInternal_(min); this.setValue(this.getValue()); } @@ -136,7 +136,7 @@ export class FieldNumber extends FieldTextInput { * value updates. * @param min Minimum value. */ - private setMinInternal_(min: number | string | undefined | null) { + private setMinInternal_(min: number|string|undefined|null) { if (min == null) { this.min_ = -Infinity; } else { @@ -161,7 +161,7 @@ export class FieldNumber extends FieldTextInput { * reflect. * @param max Maximum value. */ - setMax(max: number | string | undefined | null) { + setMax(max: number|string|undefined|null) { this.setMaxInternal_(max); this.setValue(this.getValue()); } @@ -171,7 +171,7 @@ export class FieldNumber extends FieldTextInput { * value updates. * @param max Maximum value. */ - private setMaxInternal_(max: number | string | undefined | null) { + private setMaxInternal_(max: number|string|undefined|null) { if (max == null) { this.max_ = Infinity; } else { @@ -196,7 +196,7 @@ export class FieldNumber extends FieldTextInput { * value is rounded. Updates the field to reflect. * @param precision The number to which the field's value is rounded. */ - setPrecision(precision: number | string | undefined | null) { + setPrecision(precision: number|string|undefined|null) { this.setPrecisionInternal_(precision); this.setValue(this.getValue()); } @@ -206,14 +206,14 @@ export class FieldNumber extends FieldTextInput { * value updates. * @param precision The number to which the field's value is rounded. */ - private setPrecisionInternal_(precision: number | string | undefined | null) { + private setPrecisionInternal_(precision: number|string|undefined|null) { this.precision_ = Number(precision) || 0; let precisionString = String(this.precision_); if (precisionString.indexOf('e') !== -1) { // String() is fast. But it turns .0000001 into '1e-7'. // Use the much slower toLocaleString to access all the digits. precisionString = - this.precision_.toLocaleString('en-US', { maximumFractionDigits: 20 }); + this.precision_.toLocaleString('en-US', {maximumFractionDigits: 20}); } const decimalIndex = precisionString.indexOf('.'); if (decimalIndex === -1) { @@ -242,7 +242,7 @@ export class FieldNumber extends FieldTextInput { * @return A valid number, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - number | null { + number|null { if (opt_newValue === null) { return null; } @@ -302,7 +302,7 @@ export class FieldNumber extends FieldTextInput { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. return new this( - options['value'], undefined, undefined, undefined, undefined, options); + options['value'], undefined, undefined, undefined, undefined, options); } } diff --git a/core/field_registry.ts b/core/field_registry.ts index 84753bd68..012e4d1ac 100644 --- a/core/field_registry.ts +++ b/core/field_registry.ts @@ -19,9 +19,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; /* eslint-disable-next-line no-unused-vars */ -import { IRegistrableField } from './interfaces/i_registrable_field.js'; +import {IRegistrableField} from './interfaces/i_registrable_field.js'; import * as registry from './registry.js'; @@ -59,17 +59,17 @@ export function unregister(type: string) { * type name * @alias Blockly.fieldRegistry.fromJson */ -export function fromJson(options: AnyDuringMigration): Field | null { +export function fromJson(options: AnyDuringMigration): Field|null { const fieldObject = - registry.getObject(registry.Type.FIELD, options['type']) as - IRegistrableField | - null; + registry.getObject(registry.Type.FIELD, options['type']) as + IRegistrableField | + null; if (!fieldObject) { console.warn( - 'Blockly could not create a field of type ' + options['type'] + - '. The field is probably not being registered. This could be because' + - ' the file is not loaded, the field does not register itself (Issue' + - ' #1584), or the registration is not being reached.'); + 'Blockly could not create a field of type ' + options['type'] + + '. The field is probably not being registered. This could be because' + + ' the file is not loaded, the field does not register itself (Issue' + + ' #1584), or the registration is not being reached.'); return null; } return fieldObject.fromJson(options); diff --git a/core/field_textinput.ts b/core/field_textinput.ts index 323868330..10945c8b0 100644 --- a/core/field_textinput.ts +++ b/core/field_textinput.ts @@ -16,25 +16,25 @@ import './events/events_block_change'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as dialog from './dialog.js'; import * as dropDownDiv from './dropdowndiv.js'; import * as eventUtils from './events/utils.js'; -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { Msg } from './msg.js'; +import {Msg} from './msg.js'; import * as aria from './utils/aria.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; +import {Sentinel} from './utils/sentinel.js'; import * as userAgent from './utils/useragent.js'; import * as WidgetDiv from './widgetdiv.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -43,7 +43,7 @@ import { WorkspaceSvg } from './workspace_svg.js'; */ export class FieldTextInput extends Field { /** The default value for this field. */ - protected override DEFAULT_VALUE: string | number = ''; + protected override DEFAULT_VALUE: string|number = ''; /** * Pixel size of input border radius. @@ -55,7 +55,7 @@ export class FieldTextInput extends Field { protected spellcheck_ = true; /** The HTML input element. */ - protected htmlInput_: HTMLInputElement | null = null; + protected htmlInput_: HTMLInputElement|null = null; /** True if the field's value is currently being edited via the UI. */ protected isBeingEdited_ = false; @@ -66,19 +66,19 @@ export class FieldTextInput extends Field { protected isTextValid_ = false; /** Key down event data. */ - private onKeyDownWrapper_: browserEvents.Data | null = null; + private onKeyDownWrapper_: browserEvents.Data|null = null; /** Key input event data. */ - private onKeyInputWrapper_: browserEvents.Data | null = null; + private onKeyInputWrapper_: browserEvents.Data|null = null; /** * Whether the field should consider the whole parent block to be its click * target. */ - fullBlockClickTarget_: boolean | null = false; + fullBlockClickTarget_: boolean|null = false; /** The workspace that this field belongs to. */ - protected workspace_: WorkspaceSvg | null = null; + protected workspace_: WorkspaceSvg|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -107,8 +107,8 @@ export class FieldTextInput extends Field { * for a list of properties this parameter supports. */ constructor( - opt_value?: string | Sentinel, opt_validator?: Function | null, - opt_config?: AnyDuringMigration) { + opt_value?: string|Sentinel, opt_validator?: Function|null, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); if (opt_value === Field.SKIP_SETUP) { @@ -148,7 +148,7 @@ export class FieldTextInput extends Field { // The special case is when this is the only non-label field on the block // and it has an output but no inputs. this.fullBlockClickTarget_ = - nFields <= 1 && this.sourceBlock_.outputConnection && !nConnections; + nFields <= 1 && this.sourceBlock_.outputConnection && !nConnections; } else { this.fullBlockClickTarget_ = false; } @@ -167,7 +167,7 @@ export class FieldTextInput extends Field { * @return A valid string, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - AnyDuringMigration { + AnyDuringMigration { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -190,8 +190,8 @@ export class FieldTextInput extends Field { this.value_ = this.htmlInput_!.getAttribute('data-untyped-default-value'); if (this.sourceBlock_ && eventUtils.isEnabled()) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (this.sourceBlock_, 'field', this.name || null, - oldValue, this.value_)); + (this.sourceBlock_, 'field', this.name || null, + oldValue, this.value_)); } } } @@ -217,11 +217,11 @@ export class FieldTextInput extends Field { if (this.sourceBlock_ && this.getConstants()!.FULL_BLOCK_FIELDS) { if (this.borderRect_) { this.borderRect_.setAttribute( - 'stroke', (this.sourceBlock_ as BlockSvg).style.colourTertiary); + 'stroke', (this.sourceBlock_ as BlockSvg).style.colourTertiary); } else { (this.sourceBlock_ as BlockSvg) - .pathObject.svgPath.setAttribute( - 'fill', this.getConstants()!.FIELD_BORDER_RECT_COLOUR); + .pathObject.svgPath.setAttribute( + 'fill', this.getConstants()!.FIELD_BORDER_RECT_COLOUR); } } } @@ -260,7 +260,7 @@ export class FieldTextInput extends Field { // AnyDuringMigration because: Argument of type 'boolean' is not // assignable to parameter of type 'string'. this.htmlInput_.setAttribute( - 'spellcheck', this.spellcheck_ as AnyDuringMigration); + 'spellcheck', this.spellcheck_ as AnyDuringMigration); } } @@ -275,7 +275,7 @@ export class FieldTextInput extends Field { this.workspace_ = (this.sourceBlock_ as BlockSvg).workspace; const quietInput = opt_quietInput || false; if (!quietInput && - (userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) { + (userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -288,12 +288,12 @@ export class FieldTextInput extends Field { */ private showPromptEditor_() { dialog.prompt( - Msg['CHANGE_VALUE_TITLE'], this.getText(), (text: string | null) => { - // Text is null if user pressed cancel button. - if (text !== null) { - this.setValue(this.getValueFromEditorText_(text)); - } - }); + Msg['CHANGE_VALUE_TITLE'], this.getText(), (text: string|null) => { + // Text is null if user pressed cancel button. + if (text !== null) { + this.setValue(this.getValueFromEditorText_(text)); + } + }); } /** @@ -328,7 +328,7 @@ export class FieldTextInput extends Field { // AnyDuringMigration because: Argument of type 'boolean' is not assignable // to parameter of type 'string'. htmlInput.setAttribute( - 'spellcheck', this.spellcheck_ as AnyDuringMigration); + 'spellcheck', this.spellcheck_ as AnyDuringMigration); const scale = this.workspace_!.getScale(); const fontSize = this.getConstants()!.FIELD_TEXT_FONTSIZE * scale + 'pt'; div!.style.fontSize = fontSize; @@ -342,14 +342,14 @@ export class FieldTextInput extends Field { borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block const strokeColour = this.sourceBlock_.getParent() ? - (this.sourceBlock_.getParent() as BlockSvg).style.colourTertiary : - (this.sourceBlock_ as BlockSvg).style.colourTertiary; + (this.sourceBlock_.getParent() as BlockSvg).style.colourTertiary : + (this.sourceBlock_ as BlockSvg).style.colourTertiary; htmlInput.style.border = 1 * scale + 'px solid ' + strokeColour; div!.style.borderRadius = borderRadius; div!.style.transition = 'box-shadow 0.25s ease 0s'; if (this.getConstants()!.FIELD_TEXTINPUT_BOX_SHADOW) { div!.style.boxShadow = - 'rgba(255, 255, 255, 0.3) 0 0 0 ' + 4 * scale + 'px'; + 'rgba(255, 255, 255, 0.3) 0 0 0 ' + 4 * scale + 'px'; } } htmlInput.style.borderRadius = borderRadius; @@ -408,10 +408,10 @@ export class FieldTextInput extends Field { protected bindInputEvents_(htmlInput: HTMLElement) { // Trap Enter without IME and Esc to hide. this.onKeyDownWrapper_ = browserEvents.conditionalBind( - htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); + htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); // Resize after every input change. this.onKeyInputWrapper_ = browserEvents.conditionalBind( - htmlInput, 'input', this, this.onHtmlInputChange_); + htmlInput, 'input', this, this.onHtmlInputChange_); } /** Unbind handlers for user input and workspace size changes. */ @@ -440,7 +440,7 @@ export class FieldTextInput extends Field { // 'Event'. } else if ((e as AnyDuringMigration).keyCode === KeyCodes.ESC) { this.setValue( - this.htmlInput_!.getAttribute('data-untyped-default-value')); + this.htmlInput_!.getAttribute('data-untyped-default-value')); WidgetDiv.hide(); dropDownDiv.hideWithoutAnimation(); // AnyDuringMigration because: Property 'keyCode' does not exist on type @@ -452,7 +452,7 @@ export class FieldTextInput extends Field { // 'Event'. AnyDuringMigration because: Argument of type 'this' is not // assignable to parameter of type 'Field'. (this.sourceBlock_ as BlockSvg) - .tab(this as AnyDuringMigration, !(e as AnyDuringMigration).shiftKey); + .tab(this as AnyDuringMigration, !(e as AnyDuringMigration).shiftKey); e.preventDefault(); } } @@ -522,7 +522,7 @@ export class FieldTextInput extends Field { * behaviour (which is a string cast of the field's value). * @return The HTML value if we're editing, otherwise null. */ - protected override getText_(): string | null { + protected override getText_(): string|null { if (this.isBeingEdited_ && this.htmlInput_) { // We are currently editing, return the HTML input value instead. return this.htmlInput_.value; diff --git a/core/field_variable.ts b/core/field_variable.ts index 1b8a23397..bff75a755 100644 --- a/core/field_variable.ts +++ b/core/field_variable.ts @@ -15,21 +15,21 @@ import './events/events_block_change'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; -import { Field } from './field.js'; -import { FieldDropdown } from './field_dropdown.js'; +import {Block} from './block.js'; +import {Field} from './field.js'; +import {FieldDropdown} from './field_dropdown.js'; import * as fieldRegistry from './field_registry.js'; import * as internalConstants from './internal_constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { Menu } from './menu.js'; +import {Menu} from './menu.js'; /* eslint-disable-next-line no-unused-vars */ -import { MenuItem } from './menuitem.js'; -import { Msg } from './msg.js'; +import {MenuItem} from './menuitem.js'; +import {Msg} from './msg.js'; import * as parsing from './utils/parsing.js'; /* eslint-disable-next-line no-unused-vars */ -import { Sentinel } from './utils/sentinel.js'; -import { Size } from './utils/size.js'; -import { VariableModel } from './variable_model.js'; +import {Sentinel} from './utils/sentinel.js'; +import {Size} from './utils/size.js'; +import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; import * as Xml from './xml.js'; @@ -39,8 +39,8 @@ import * as Xml from './xml.js'; * @alias Blockly.FieldVariable */ export class FieldVariable extends FieldDropdown { - protected override menuGenerator_: AnyDuringMigration[][] | - ((this: FieldDropdown) => AnyDuringMigration[][]); + protected override menuGenerator_: AnyDuringMigration[][]| + ((this: FieldDropdown) => AnyDuringMigration[][]); defaultVariableName: string; /** The type of the default variable for this field. */ @@ -50,11 +50,11 @@ export class FieldVariable extends FieldDropdown { * All of the types of variables that will be available in this field's * dropdown. */ - variableTypes: string[] | null = []; + variableTypes: string[]|null = []; protected override size_: Size; /** The variable model associated with this field. */ - private variable_: VariableModel | null = null; + private variable_: VariableModel|null = null; /** * Serializable fields are saved by the serializer, non-serializable fields @@ -82,9 +82,9 @@ export class FieldVariable extends FieldDropdown { * for a list of properties this parameter supports. */ constructor( - varName: string | null | Sentinel, opt_validator?: Function, - opt_variableTypes?: string[], opt_defaultType?: string, - opt_config?: AnyDuringMigration) { + varName: string|null|Sentinel, opt_validator?: Function, + opt_variableTypes?: string[], opt_defaultType?: string, + opt_config?: AnyDuringMigration) { super(Field.SKIP_SETUP); /** @@ -139,16 +139,16 @@ export class FieldVariable extends FieldDropdown { } // Initialization already happened. const variable = Variables.getOrCreateVariablePackage( - this.sourceBlock_.workspace, null, this.defaultVariableName, - this.defaultType_); + this.sourceBlock_.workspace, null, this.defaultVariableName, + this.defaultType_); // Don't call setValue because we don't want to cause a rerender. this.doValueUpdate_(variable.getId()); } override shouldAddBorderRect_() { return super.shouldAddBorderRect_() && - (!this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || - this.sourceBlock_.type !== 'variables_get'); + (!this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || + this.sourceBlock_.type !== 'variables_get'); } /** @@ -162,21 +162,21 @@ export class FieldVariable extends FieldDropdown { // 'variabletype' should be lowercase, but until July 2019 it was sometimes // recorded as 'variableType'. Thus we need to check for both. const variableType = fieldElement.getAttribute('variabletype') || - fieldElement.getAttribute('variableType') || ''; + fieldElement.getAttribute('variableType') || ''; // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string | undefined'. const variable = Variables.getOrCreateVariablePackage( - this.sourceBlock_.workspace, id, variableName as AnyDuringMigration, - variableType); + this.sourceBlock_.workspace, id, variableName as AnyDuringMigration, + variableType); // This should never happen :) if (variableType !== null && variableType !== variable.type) { throw Error( - 'Serialized variable type with id \'' + variable.getId() + - '\' had type ' + variable.type + ', and ' + - 'does not match variable field that references it: ' + - Xml.domToText(fieldElement) + '.'); + 'Serialized variable type with id \'' + variable.getId() + + '\' had type ' + variable.type + ', and ' + + 'does not match variable field that references it: ' + + Xml.domToText(fieldElement) + '.'); } this.setValue(variable.getId()); @@ -214,7 +214,7 @@ export class FieldVariable extends FieldDropdown { } // Make sure the variable is initialized. this.initModel(); - const state = { 'id': this.variable_!.getId() }; + const state = {'id': this.variable_!.getId()}; if (doFullSerialization) { (state as AnyDuringMigration)['name'] = this.variable_!.name; (state as AnyDuringMigration)['type'] = this.variable_!.type; @@ -232,8 +232,8 @@ export class FieldVariable extends FieldDropdown { } // This is necessary so that blocks in the flyout can have custom var names. const variable = Variables.getOrCreateVariablePackage( - this.sourceBlock_.workspace, state['id'] || null, state['name'], - state['type'] || ''); + this.sourceBlock_.workspace, state['id'] || null, state['name'], + state['type'] || ''); this.setValue(variable.getId()); } @@ -252,7 +252,7 @@ export class FieldVariable extends FieldDropdown { * Get the variable's ID. * @return Current variable's ID. */ - override getValue(): string | null { + override getValue(): string|null { return this.variable_ ? this.variable_.getId() : null; } @@ -271,7 +271,7 @@ export class FieldVariable extends FieldDropdown { * after the variable has been deleted). * @return The selected variable, or null if none was selected. */ - getVariable(): VariableModel | null { + getVariable(): VariableModel|null { return this.variable_; } @@ -282,7 +282,7 @@ export class FieldVariable extends FieldDropdown { * a block and workspace at that point. * @return Validation function, or null. */ - override getValidator(): Function | null { + override getValidator(): Function|null { // Validators shouldn't operate on the initial setValue call. // Normally this is achieved by calling setValidator after setValue, but // this is not a possibility with variable fields. @@ -298,7 +298,7 @@ export class FieldVariable extends FieldDropdown { * @return The validated ID, or null if invalid. */ protected override doClassValidation_(opt_newValue?: AnyDuringMigration): - string | null { + string|null { if (opt_newValue === null) { return null; } @@ -306,15 +306,15 @@ export class FieldVariable extends FieldDropdown { const variable = Variables.getVariable(this.sourceBlock_.workspace, newId); if (!variable) { console.warn( - 'Variable id doesn\'t point to a real variable! ' + - 'ID was ' + newId); + 'Variable id doesn\'t point to a real variable! ' + + 'ID was ' + newId); return null; } // Type Checks. const type = variable.type; if (!this.typeIsAllowed_(type)) { console.warn( - 'Variable type doesn\'t match this field! Type was ' + type); + 'Variable type doesn\'t match this field! Type was ' + type); return null; } return newId; @@ -329,7 +329,7 @@ export class FieldVariable extends FieldDropdown { */ protected override doValueUpdate_(newId: AnyDuringMigration) { this.variable_ = - Variables.getVariable(this.sourceBlock_.workspace, newId as string); + Variables.getVariable(this.sourceBlock_.workspace, newId as string); super.doValueUpdate_(newId); } @@ -371,7 +371,7 @@ export class FieldVariable extends FieldDropdown { // Throw an error if variableTypes is an empty list. const name = this.getText(); throw Error( - '\'variableTypes\' of field variable ' + name + ' was an empty list'); + '\'variableTypes\' of field variable ' + name + ' was an empty list'); } return variableTypes; } @@ -405,13 +405,13 @@ export class FieldVariable extends FieldDropdown { } if (!isInArray) { throw Error( - 'Invalid default type \'' + defaultType + '\' in ' + - 'the definition of a FieldVariable'); + 'Invalid default type \'' + defaultType + '\' in ' + + 'the definition of a FieldVariable'); } } else { throw Error( - '\'variableTypes\' was not an array in the definition of ' + - 'a FieldVariable'); + '\'variableTypes\' was not an array in the definition of ' + + 'a FieldVariable'); } // Only update the field once all checks pass. this.defaultType_ = defaultType; @@ -441,7 +441,7 @@ export class FieldVariable extends FieldDropdown { if (id === internalConstants.RENAME_VARIABLE_ID) { // Rename variable. Variables.renameVariable( - this.sourceBlock_.workspace, this.variable_ as VariableModel); + this.sourceBlock_.workspace, this.variable_ as VariableModel); return; } else if (id === internalConstants.DELETE_VARIABLE_ID) { // Delete variable. @@ -485,8 +485,8 @@ export class FieldVariable extends FieldDropdown { static dropdownCreate(this: FieldVariable): AnyDuringMigration[][] { if (!this.variable_) { throw Error( - 'Tried to call dropdownCreate on a variable field with no' + - ' variable selected.'); + 'Tried to call dropdownCreate on a variable field with no' + + ' variable selected.'); } const name = this.getText(); let variableModelList: AnyDuringMigration[] = []; @@ -497,7 +497,7 @@ export class FieldVariable extends FieldDropdown { for (let i = 0; i < variableTypes.length; i++) { const variableType = variableTypes[i]; const variables = - this.sourceBlock_.workspace.getVariablesOfType(variableType); + this.sourceBlock_.workspace.getVariablesOfType(variableType); variableModelList = variableModelList.concat(variables); } } @@ -509,7 +509,7 @@ export class FieldVariable extends FieldDropdown { options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } options.push( - [Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID]); + [Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID]); if (Msg['DELETE_VARIABLE']) { options.push([ Msg['DELETE_VARIABLE'].replace('%1', name), diff --git a/core/flyout_base.ts b/core/flyout_base.ts index 8746fca85..0efc7fd5b 100644 --- a/core/flyout_base.ts +++ b/core/flyout_base.ts @@ -34,38 +34,38 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; import * as common from './common.js'; -import { ComponentManager } from './component_manager.js'; -import { DeleteArea } from './delete_area.js'; +import {ComponentManager} from './component_manager.js'; +import {DeleteArea} from './delete_area.js'; import * as BlockCreate from './events/events_block_create.js'; import * as VarCreate from './events/events_var_create.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { FlyoutButton } from './flyout_button.js'; -import { FlyoutMetricsManager } from './flyout_metrics_manager.js'; +import {FlyoutButton} from './flyout_button.js'; +import {FlyoutMetricsManager} from './flyout_metrics_manager.js'; import * as Gesture from './gesture.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { Options } from './options.js'; +import {Options} from './options.js'; import * as blockRendering from './renderers/common/block_rendering.js'; -import { ScrollbarPair } from './scrollbar_pair.js'; +import {ScrollbarPair} from './scrollbar_pair.js'; import * as blocks from './serialization/blocks.js'; import * as Tooltip from './tooltip.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; import * as idGenerator from './utils/idgenerator.js'; /* eslint-disable-next-line no-unused-vars */ -import { Rect } from './utils/rect.js'; -import { Svg } from './utils/svg.js'; +import {Rect} from './utils/rect.js'; +import {Svg} from './utils/svg.js'; import * as toolbox from './utils/toolbox.js'; import * as Variables from './variables.js'; -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; @@ -100,7 +100,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * between 0 and 1 specifying the degree of scrolling and a * 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. @@ -161,14 +161,14 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * Function that will be registered as a change listener on the workspace * to reflow when blocks in the flyout workspace change. */ - private reflowWrapper_: Function | null = null; + private reflowWrapper_: Function|null = null; /** * Function that disables blocks in the flyout based on max block counts * allowed in the target workspace. Registered as a change listener on the * target workspace. */ - private filterWrapper_: Function | null = null; + private filterWrapper_: Function|null = null; /** * List of background mats that lurk behind each block to catch clicks @@ -259,12 +259,12 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * The path around the background of the flyout, which will be filled with a * background colour. */ - protected svgBackground_: SVGPathElement | null = null; + protected svgBackground_: SVGPathElement|null = null; /** * The root SVG group for the button or label. */ - protected svgGroup_: SVGGElement | null = null; + protected svgGroup_: SVGGElement|null = null; /** * @param workspaceOptions Dictionary of options for the * workspace. @@ -275,7 +275,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.setMetricsManager( - new FlyoutMetricsManager(this.workspace_, this)); + new FlyoutMetricsManager(this.workspace_, this)); this.workspace_.isFlyout = true; // Keep the workspace visibility consistent with the flyout's visibility. @@ -335,7 +335,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * put the flyout in. This should be or . * @return The flyout's SVG group. */ - createDom(tagName: string | Svg | Svg): SVGElement { + createDom(tagName: string|Svg|Svg): SVGElement { /* @@ -345,14 +345,14 @@ export abstract class Flyout extends DeleteArea implements IFlyout { // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. this.svgGroup_ = dom.createSvgElement( - tagName, { 'class': 'blocklyFlyout', 'style': 'display: none' }); + tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}); this.svgBackground_ = dom.createSvgElement( - Svg.PATH, { 'class': 'blocklyFlyoutBackground' }, this.svgGroup_); + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( - this.svgBackground_, 'flyoutBackgroundColour', 'fill'); + this.svgBackground_, 'flyoutBackgroundColour', 'fill'); this.workspace_.getThemeManager().subscribe( - this.svgBackground_, 'flyoutOpacity', 'fill-opacity'); + this.svgBackground_, 'flyoutOpacity', 'fill-opacity'); return this.svgGroup_; } @@ -366,15 +366,15 @@ export abstract class Flyout extends DeleteArea implements IFlyout { this.workspace_.targetWorkspace = targetWorkspace; this.workspace_.scrollbar = new ScrollbarPair( - this.workspace_, this.horizontalLayout, !this.horizontalLayout, - 'blocklyFlyoutScrollbar', this.SCROLLBAR_MARGIN); + this.workspace_, this.horizontalLayout, !this.horizontalLayout, + 'blocklyFlyoutScrollbar', this.SCROLLBAR_MARGIN); this.hide(); Array.prototype.push.apply( - this.eventWrappers_, - browserEvents.conditionalBind( - (this.svgGroup_ as SVGGElement), 'wheel', this, this.wheel_)); + this.eventWrappers_, + browserEvents.conditionalBind( + (this.svgGroup_ as SVGGElement), 'wheel', this, this.wheel_)); if (!this.autoClose) { this.filterWrapper_ = this.filterForCapacity_.bind(this); this.targetWorkspace.addChangeListener(this.filterWrapper_); @@ -382,14 +382,14 @@ export abstract class Flyout extends DeleteArea implements IFlyout { // Dragging the flyout up and down. Array.prototype.push.apply( - this.eventWrappers_, - browserEvents.conditionalBind( - (this.svgBackground_ as SVGPathElement), 'mousedown', this, - this.onMouseDown_)); + this.eventWrappers_, + browserEvents.conditionalBind( + (this.svgBackground_ as SVGPathElement), 'mousedown', this, + this.onMouseDown_)); // A flyout connected to a workspace doesn't have its own current gesture. this.workspace_.getGesture = - this.targetWorkspace.getGesture.bind(this.targetWorkspace); + this.targetWorkspace.getGesture.bind(this.targetWorkspace); // Get variables from the main workspace rather than the target workspace. this.workspace_.setVariableMap(this.targetWorkspace.getVariableMap()); @@ -554,11 +554,11 @@ export abstract class Flyout extends DeleteArea implements IFlyout { // reposition in resize, we need to call setPosition. See issue #4692. if (scrollbar.hScroll) { scrollbar.hScroll.setPosition( - scrollbar.hScroll.position.x, scrollbar.hScroll.position.y); + scrollbar.hScroll.position.x, scrollbar.hScroll.position.y); } if (scrollbar.vScroll) { scrollbar.vScroll.setPosition( - scrollbar.vScroll.position.x, scrollbar.vScroll.position.y); + scrollbar.vScroll.position.x, scrollbar.vScroll.position.y); } } } @@ -590,7 +590,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ - show(flyoutDef: toolbox.FlyoutDefinition | string) { + show(flyoutDef: toolbox.FlyoutDefinition|string) { this.workspace_.setResizesEnabled(false); this.hide(); this.clearOldBlocks_(); @@ -617,8 +617,8 @@ export abstract class Flyout extends DeleteArea implements IFlyout { } this.listeners_.push(browserEvents.conditionalBind( - (this.svgBackground_ as SVGPathElement), 'mouseover', this, - deselectAll)); + (this.svgBackground_ as SVGPathElement), 'mouseover', this, + deselectAll)); if (this.horizontalLayout) { this.height_ = 0; @@ -645,7 +645,8 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * of objects to show in the flyout. * @return The list of contents and gaps needed to lay out the flyout. */ - private createFlyoutInfo_(parsedContent: toolbox.FlyoutItemInfoArray): { contents: FlyoutItem[], gaps: number[] } { + private createFlyoutInfo_(parsedContent: toolbox.FlyoutItemInfoArray): + {contents: FlyoutItem[], gaps: number[]} { const contents: FlyoutItem[] = []; const gaps: number[] = []; this.permanentlyDisabled_.length = 0; @@ -656,10 +657,10 @@ export abstract class Flyout extends DeleteArea implements IFlyout { const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); const parsedDynamicContent = - toolbox.convertFlyoutDefToJsonArray(flyoutDef); + toolbox.convertFlyoutDefToJsonArray(flyoutDef); // Replace the element at i with the dynamic content it represents. parsedContent.splice.apply( - parsedContent, [i, 1, ...parsedDynamicContent]); + parsedContent, [i, 1, ...parsedDynamicContent]); contentInfo = parsedContent[i]; } @@ -667,7 +668,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { case 'BLOCK': { const blockInfo = (contentInfo as toolbox.BlockInfo); const block = this.createFlyoutBlock_(blockInfo); - contents.push({ type: FlyoutItemType.BLOCK, block: block }); + contents.push({type: FlyoutItemType.BLOCK, block: block}); this.addBlockGap_(blockInfo, gaps, defaultGap); break; } @@ -680,20 +681,20 @@ export abstract class Flyout extends DeleteArea implements IFlyout { const labelInfo = (contentInfo as toolbox.LabelInfo); // A label is a button with different styling. const label = this.createButton_(labelInfo, /** isLabel */ true); - contents.push({ type: FlyoutItemType.BUTTON, button: label }); + contents.push({type: FlyoutItemType.BUTTON, button: label}); gaps.push(defaultGap); break; } case 'BUTTON': { const buttonInfo = (contentInfo as toolbox.ButtonInfo); const button = this.createButton_(buttonInfo, /** isLabel */ false); - contents.push({ type: FlyoutItemType.BUTTON, button: button }); + contents.push({type: FlyoutItemType.BUTTON, button: button}); gaps.push(defaultGap); break; } } } - return { contents: contents, gaps: gaps }; + return {contents: contents, gaps: gaps}; } /** @@ -703,16 +704,16 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * flyout in one of its many forms. */ private getDynamicCategoryContents_(categoryName: string): - toolbox.FlyoutDefinition { + toolbox.FlyoutDefinition { // Look up the correct category generation function and call that to get a // valid XML list. const fnToApply = - this.workspace_.targetWorkspace.getToolboxCategoryCallback( - categoryName); + this.workspace_.targetWorkspace.getToolboxCategoryCallback( + categoryName); if (typeof fnToApply !== 'function') { throw TypeError( - 'Couldn\'t find a callback function when opening' + - ' a toolbox category.'); + 'Couldn\'t find a callback function when opening' + + ' a toolbox category.'); } return fnToApply(this.workspace_.targetWorkspace); } @@ -725,10 +726,10 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * flyout. */ private createButton_(btnInfo: toolbox.ButtonOrLabelInfo, isLabel: boolean): - FlyoutButton { + FlyoutButton { const curButton = new FlyoutButton( - this.workspace_, (this.targetWorkspace as WorkspaceSvg), btnInfo, - isLabel); + this.workspace_, (this.targetWorkspace as WorkspaceSvg), btnInfo, + isLabel); return curButton; } @@ -742,8 +743,8 @@ export abstract class Flyout extends DeleteArea implements IFlyout { let block; if (blockInfo['blockxml']) { const xml = (typeof blockInfo['blockxml'] === 'string' ? - Xml.textToDom(blockInfo['blockxml']) : - blockInfo['blockxml']) as Element; + Xml.textToDom(blockInfo['blockxml']) : + blockInfo['blockxml']) as Element; block = this.getRecycledBlock_(xml.getAttribute('type')!); if (!block) { block = Xml.domToBlock(xml, this.workspace_); @@ -753,7 +754,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { if (!block) { if (blockInfo['enabled'] === undefined) { blockInfo['enabled'] = blockInfo['disabled'] !== 'true' && - blockInfo['disabled'] !== true; + blockInfo['disabled'] !== true; } block = blocks.append((blockInfo as blocks.State), this.workspace_); } @@ -774,7 +775,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * @return The recycled block, or undefined if * one could not be recycled. */ - private getRecycledBlock_(blockType: string): BlockSvg | undefined { + private getRecycledBlock_(blockType: string): BlockSvg|undefined { let index = -1; for (let i = 0; i < this.recycledBlocks_.length; i++) { if (this.recycledBlocks_[i].type === blockType) { @@ -793,14 +794,14 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * next. */ private addBlockGap_( - blockInfo: toolbox.BlockInfo, gaps: number[], defaultGap: number) { + blockInfo: toolbox.BlockInfo, gaps: number[], defaultGap: number) { let gap; if (blockInfo['gap']) { gap = parseInt(blockInfo['gap'].toString(), 10); } else if (blockInfo['blockxml']) { const xml = (typeof blockInfo['blockxml'] === 'string' ? - Xml.textToDom(blockInfo['blockxml']) : - blockInfo['blockxml']) as Element; + Xml.textToDom(blockInfo['blockxml']) : + blockInfo['blockxml']) as Element; gap = parseInt(xml.getAttribute('gap')!, 10); } gaps.push(!gap || isNaN(gap) ? defaultGap : gap); @@ -815,7 +816,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * element. */ private addSeparatorGap_( - sepInfo: toolbox.SeparatorInfo, gaps: number[], defaultGap: number) { + sepInfo: toolbox.SeparatorInfo, gaps: number[], defaultGap: number) { // Change the gap between two toolbox elements. // // The default gap is 24, can be set larger or smaller. @@ -901,19 +902,19 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * as a mat for that block. */ protected addBlockListeners_( - root: SVGElement, block: BlockSvg, rect: SVGElement) { + root: SVGElement, block: BlockSvg, rect: SVGElement) { this.listeners_.push(browserEvents.conditionalBind( - root, 'mousedown', null, this.blockMouseDown_(block))); + root, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push(browserEvents.conditionalBind( - rect, 'mousedown', null, this.blockMouseDown_(block))); + rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( - browserEvents.bind(root, 'mouseenter', block, block.addSelect)); + browserEvents.bind(root, 'mouseenter', block, block.addSelect)); this.listeners_.push( - browserEvents.bind(root, 'mouseleave', block, block.removeSelect)); + browserEvents.bind(root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( - browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); + browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); this.listeners_.push( - browserEvents.bind(rect, 'mouseleave', block, block.removeSelect)); + browserEvents.bind(rect, 'mouseleave', block, block.removeSelect)); } /** @@ -975,7 +976,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { this.targetWorkspace.hideChaff(); const newVariables = Variables.getAddedVariables( - this.targetWorkspace, variablesBeforeCreation); + this.targetWorkspace, variablesBeforeCreation); if (eventUtils.isEnabled()) { eventUtils.setGroup(true); @@ -983,7 +984,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))! - (thisVariable)); + (thisVariable)); } // Block events come after var events, in case they refer to newly created @@ -1012,7 +1013,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { // Clicking on a flyout button or label is a lot like clicking on the // flyout background. this.listeners_.push(browserEvents.conditionalBind( - buttonSvg, 'mousedown', this, this.onMouseDown_)); + buttonSvg, 'mousedown', this, this.onMouseDown_)); this.buttons_.push(button); } @@ -1030,8 +1031,8 @@ export abstract class Flyout extends DeleteArea implements IFlyout { * the block. */ protected createRect_( - block: BlockSvg, x: number, y: number, - blockHW: { height: number, width: number }, index: number): SVGElement { + block: BlockSvg, x: number, y: number, + blockHW: {height: number, width: number}, index: number): SVGElement { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = dom.createSvgElement(Svg.RECT, { @@ -1065,7 +1066,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { const blockXY = block.getRelativeToSurfaceXY(); rect.setAttribute('y', blockXY.y.toString()); rect.setAttribute( - 'x', (this.RTL ? blockXY.x - blockHW.width : blockXY.x).toString()); + 'x', (this.RTL ? blockXY.x - blockHW.width : blockXY.x).toString()); } /** @@ -1079,7 +1080,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { for (let i = 0, block; block = blocks[i]; i++) { if (this.permanentlyDisabled_.indexOf(block) === -1) { const enable = this.targetWorkspace.isCapacityAvailable( - common.getBlockTypeCounts(block)); + common.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -1107,7 +1108,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { */ isScrollable(): boolean { return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : - false; + false; } /** @@ -1158,12 +1159,12 @@ export abstract class Flyout extends DeleteArea implements IFlyout { // The position of the old block in pixels relative to the upper left corner // of the injection div. const oldBlockOffsetPixels = - Coordinate.sum(flyoutOffsetPixels, oldBlockPos); + Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. const finalOffset = - Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); + Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); @@ -1176,6 +1177,6 @@ export abstract class Flyout extends DeleteArea implements IFlyout { */ export interface FlyoutItem { type: FlyoutItemType; - button?: FlyoutButton | undefined; - block?: BlockSvg | undefined; + button?: FlyoutButton|undefined; + block?: BlockSvg|undefined; } diff --git a/core/flyout_button.ts b/core/flyout_button.ts index de64e416e..9d0a41a3f 100644 --- a/core/flyout_button.ts +++ b/core/flyout_button.ts @@ -14,15 +14,15 @@ import * as browserEvents from './browser_events.js'; import * as Css from './css.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; import * as parsing from './utils/parsing.js'; import * as style from './utils/style.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; /* eslint-disable-next-line no-unused-vars */ import * as toolbox from './utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -38,10 +38,10 @@ export class FlyoutButton { private readonly text_: string; private readonly position_: Coordinate; private readonly callbackKey_: string; - private readonly cssClass_: string | null; + private readonly cssClass_: string|null; /** Mouse up event data. */ - private onMouseUpWrapper_: browserEvents.Data | null = null; + private onMouseUpWrapper_: browserEvents.Data|null = null; info: toolbox.ButtonOrLabelInfo; /** The width of the button's rect. */ @@ -51,10 +51,10 @@ export class FlyoutButton { height = 0; /** The root SVG group for the button or label. */ - private svgGroup_: SVGGElement | null = null; + private svgGroup_: SVGGElement|null = null; /** The SVG element with the text of the label or button. */ - private svgText_: SVGTextElement | null = null; + private svgText_: SVGTextElement|null = null; /** * @param workspace The workspace in which to place this button. @@ -63,19 +63,19 @@ export class FlyoutButton { * @param isLabel Whether this button should be styled as a label. */ constructor( - private readonly workspace: WorkspaceSvg, - private readonly targetWorkspace: WorkspaceSvg, - json: toolbox.ButtonOrLabelInfo, private readonly isLabel_: boolean) { + private readonly workspace: WorkspaceSvg, + private readonly targetWorkspace: WorkspaceSvg, + json: toolbox.ButtonOrLabelInfo, private readonly isLabel_: boolean) { this.text_ = json['text']; this.position_ = new Coordinate(0, 0); /** The key to the function called when this button is clicked. */ this.callbackKey_ = - (json as - AnyDuringMigration)['callbackKey'] || /* Check the lower case version - too to satisfy IE */ - (json as AnyDuringMigration)['callbackkey']; + (json as + AnyDuringMigration)['callbackKey'] || /* Check the lower case version + too to satisfy IE */ + (json as AnyDuringMigration)['callbackkey']; /** If specified, a CSS class to add to this button. */ this.cssClass_ = (json as AnyDuringMigration)['web-class'] || null; @@ -95,39 +95,39 @@ export class FlyoutButton { } this.svgGroup_ = dom.createSvgElement( - Svg.G, { 'class': cssClass }, this.workspace.getCanvas()); + Svg.G, {'class': cssClass}, this.workspace.getCanvas()); let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). shadow = dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyFlyoutButtonShadow', - 'rx': 4, - 'ry': 4, - 'x': 1, - 'y': 1, - }, - this.svgGroup_!); + Svg.RECT, { + 'class': 'blocklyFlyoutButtonShadow', + 'rx': 4, + 'ry': 4, + 'x': 1, + 'y': 1, + }, + this.svgGroup_!); } // Background rectangle. const rect = dom.createSvgElement( - Svg.RECT, { - 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : - 'blocklyFlyoutButtonBackground', - 'rx': 4, - 'ry': 4, - }, - this.svgGroup_!); + Svg.RECT, { + 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : + 'blocklyFlyoutButtonBackground', + 'rx': 4, + 'ry': 4, + }, + this.svgGroup_!); const svgText = dom.createSvgElement( - Svg.TEXT, { - 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', - 'x': 0, - 'y': 0, - 'text-anchor': 'middle', - }, - this.svgGroup_!); + Svg.TEXT, { + 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', + 'x': 0, + 'y': 0, + 'text-anchor': 'middle', + }, + this.svgGroup_!); let text = parsing.replaceMessageReferences(this.text_); if (this.workspace.RTL) { // Force text to be RTL by adding an RLM. @@ -137,16 +137,16 @@ export class FlyoutButton { if (this.isLabel_) { this.svgText_ = svgText; this.workspace.getThemeManager().subscribe( - this.svgText_, 'flyoutForegroundColour', 'fill'); + this.svgText_, 'flyoutForegroundColour', 'fill'); } const fontSize = style.getComputedStyle(svgText, 'fontSize'); const fontWeight = style.getComputedStyle(svgText, 'fontWeight'); const fontFamily = style.getComputedStyle(svgText, 'fontFamily'); this.width = dom.getFastTextWidthWithSizeString( - svgText, fontSize, fontWeight, fontFamily); + svgText, fontSize, fontWeight, fontFamily); const fontMetrics = - dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); + dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; if (!this.isLabel_) { @@ -160,16 +160,16 @@ export class FlyoutButton { svgText.setAttribute('x', (this.width / 2).toString()); svgText.setAttribute( - 'y', - (this.height / 2 - fontMetrics.height / 2 + fontMetrics.baseline) - .toString()); + 'y', + (this.height / 2 - fontMetrics.height / 2 + fontMetrics.baseline) + .toString()); this.updateTransform_(); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'EventTarget'. this.onMouseUpWrapper_ = browserEvents.conditionalBind( - this.svgGroup_ as AnyDuringMigration, 'mouseup', this, this.onMouseUp_); + this.svgGroup_ as AnyDuringMigration, 'mouseup', this, this.onMouseUp_); return this.svgGroup_!; } @@ -182,8 +182,8 @@ export class FlyoutButton { /** Update SVG attributes to match internal state. */ private updateTransform_() { this.svgGroup_!.setAttribute( - 'transform', - 'translate(' + this.position_.x + ',' + this.position_.y + ')'); + 'transform', + 'translate(' + this.position_.x + ',' + this.position_.y + ')'); } /** @@ -248,15 +248,15 @@ export class FlyoutButton { if (this.isLabel_ && this.callbackKey_) { console.warn( - 'Labels should not have callbacks. Label text: ' + this.text_); + 'Labels should not have callbacks. Label text: ' + this.text_); } else if ( - !this.isLabel_ && - !(this.callbackKey_ && - this.targetWorkspace.getButtonCallback(this.callbackKey_))) { + !this.isLabel_ && + !(this.callbackKey_ && + this.targetWorkspace.getButtonCallback(this.callbackKey_))) { console.warn('Buttons should have callbacks. Button text: ' + this.text_); } else if (!this.isLabel_) { const callback = - this.targetWorkspace.getButtonCallback(this.callbackKey_); + this.targetWorkspace.getButtonCallback(this.callbackKey_); if (callback) { callback(this); } diff --git a/core/flyout_horizontal.ts b/core/flyout_horizontal.ts index 56f572715..2fae3fd65 100644 --- a/core/flyout_horizontal.ts +++ b/core/flyout_horizontal.ts @@ -16,16 +16,16 @@ import * as browserEvents from './browser_events.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Flyout, FlyoutItem } from './flyout_base.js'; +import {Flyout, FlyoutItem} from './flyout_base.js'; /* eslint-disable-next-line no-unused-vars */ -import { FlyoutButton } from './flyout_button.js'; +import {FlyoutButton} from './flyout_button.js'; /* eslint-disable-next-line no-unused-vars */ -import { Options } from './options.js'; +import {Options} from './options.js'; import * as registry from './registry.js'; -import { Scrollbar } from './scrollbar.js'; +import {Scrollbar} from './scrollbar.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; -import { Rect } from './utils/rect.js'; +import {Coordinate} from './utils/coordinate.js'; +import {Rect} from './utils/rect.js'; import * as toolbox from './utils/toolbox.js'; import * as WidgetDiv from './widgetdiv.js'; @@ -52,7 +52,7 @@ export class HorizontalFlyout extends Flyout { * @param xyRatio Contains a y property which is a float between 0 and 1 * specifying the degree of scrolling and a similar x property. */ - protected override setMetrics_(xyRatio: { x: number, y: number }) { + protected override setMetrics_(xyRatio: {x: number, y: number}) { if (!this.isVisible()) { return; } @@ -64,13 +64,13 @@ export class HorizontalFlyout extends Flyout { if (typeof xyRatio.x === 'number') { this.workspace_.scrollX = - -(scrollMetrics.left + - (scrollMetrics.width - viewMetrics.width) * xyRatio.x); + -(scrollMetrics.left + + (scrollMetrics.width - viewMetrics.width) * xyRatio.x); } this.workspace_.translate( - this.workspace_.scrollX + absoluteMetrics.left, - this.workspace_.scrollY + absoluteMetrics.top); + this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.scrollY + absoluteMetrics.top); } /** @@ -158,7 +158,7 @@ export class HorizontalFlyout extends Flyout { private setBackgroundPath_(width: number, height: number) { const atTop = this.toolboxPosition_ === toolbox.Position.TOP; // Start at top left. - const path: (string | number)[] = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; + const path: (string|number)[] = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; if (atTop) { // Top. @@ -167,24 +167,24 @@ export class HorizontalFlyout extends Flyout { path.push('v', height); // Bottom. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, - -this.CORNER_RADIUS, this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + -this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('h', -width); // Left. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, - -this.CORNER_RADIUS, -this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + -this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('z'); } else { // Top. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, - this.CORNER_RADIUS, -this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('h', width); // Right. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, - this.CORNER_RADIUS, this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('v', height); // Bottom. path.push('h', -width - 2 * this.CORNER_RADIUS); @@ -265,7 +265,7 @@ export class HorizontalFlyout extends Flyout { // AnyDuringMigration because: Argument of type 'BlockSvg | undefined' // is not assignable to parameter of type 'BlockSvg'. const rect = this.createRect_( - block as AnyDuringMigration, moveX, cursorY, blockHW, i); + block as AnyDuringMigration, moveX, cursorY, blockHW, i); cursorX += blockHW.width + gaps[i]; // AnyDuringMigration because: Argument of type 'BlockSvg | undefined' @@ -296,7 +296,7 @@ export class HorizontalFlyout extends Flyout { const range = this.dragAngleRange_; // Check for up or down dragging. if (dragDirection < 90 + range && dragDirection > 90 - range || - dragDirection > -90 - range && dragDirection < -90 + range) { + dragDirection > -90 - range && dragDirection < -90 + range) { return true; } return false; @@ -308,7 +308,7 @@ export class HorizontalFlyout extends Flyout { * @return The component's bounding box. Null if drag target area should be * ignored. */ - override getClientRect(): Rect | null { + override getClientRect(): Rect|null { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -357,19 +357,19 @@ export class HorizontalFlyout extends Flyout { // AnyDuringMigration because: Argument of type 'SVGElement | // undefined' is not assignable to parameter of type 'SVGElement'. this.moveRectToBlock_( - this.rectMap_.get(block) as AnyDuringMigration, block); + this.rectMap_.get(block) as AnyDuringMigration, block); } } if (this.targetWorkspace!.toolboxPosition === this.toolboxPosition_ && - this.toolboxPosition_ === toolbox.Position.TOP && - !this.targetWorkspace!.getToolbox()) { + this.toolboxPosition_ === toolbox.Position.TOP && + !this.targetWorkspace!.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that // (0,0) is in the correct position relative to the new absolute edge // (ie toolbox edge). this.targetWorkspace!.translate( - this.targetWorkspace!.scrollX, - this.targetWorkspace!.scrollY + flyoutHeight); + this.targetWorkspace!.scrollX, + this.targetWorkspace!.scrollY + flyoutHeight); } this.height_ = flyoutHeight; this.position(); @@ -379,5 +379,5 @@ export class HorizontalFlyout extends Flyout { } registry.register( - registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, registry.DEFAULT, - HorizontalFlyout); + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, registry.DEFAULT, + HorizontalFlyout); diff --git a/core/flyout_metrics_manager.ts b/core/flyout_metrics_manager.ts index 55df26ac9..009bb004d 100644 --- a/core/flyout_metrics_manager.ts +++ b/core/flyout_metrics_manager.ts @@ -13,10 +13,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; -import { ContainerRegion, MetricsManager } from './metrics_manager.js'; +import {IFlyout} from './interfaces/i_flyout.js'; +import {ContainerRegion, MetricsManager} from './metrics_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -38,8 +38,8 @@ export class FlyoutMetricsManager extends MetricsManager { * This is in workspace coordinates. * @return The bounding box of the blocks on the workspace. */ - private getBoundingBox_(): SVGRect | - { height: number, y: number, width: number, x: number } { + private getBoundingBox_(): SVGRect| + {height: number, y: number, width: number, x: number} { let blockBoundingBox; try { blockBoundingBox = this.workspace.getCanvas().getBBox(); @@ -47,7 +47,7 @@ export class FlyoutMetricsManager extends MetricsManager { // Firefox has trouble with hidden elements (Bug 528969). // 2021 Update: It looks like this was fixed around Firefox 77 released in // 2020. - blockBoundingBox = { height: 0, y: 0, width: 0, x: 0 }; + blockBoundingBox = {height: 0, y: 0, width: 0, x: 0}; } return blockBoundingBox; } @@ -66,11 +66,11 @@ export class FlyoutMetricsManager extends MetricsManager { } override getScrollMetrics( - opt_getWorkspaceCoordinates: boolean, opt_viewMetrics: ContainerRegion, - opt_contentMetrics: ContainerRegion) { + opt_getWorkspaceCoordinates: boolean, opt_viewMetrics: ContainerRegion, + opt_contentMetrics: ContainerRegion) { // AnyDuringMigration because: Expected 1 arguments, but got 0. const contentMetrics = - opt_contentMetrics || (this.getContentMetrics as AnyDuringMigration)(); + opt_contentMetrics || (this.getContentMetrics as AnyDuringMigration)(); const margin = this.flyout.MARGIN * this.workspace.scale; const scale = opt_getWorkspaceCoordinates ? this.workspace.scale : 1; diff --git a/core/flyout_vertical.ts b/core/flyout_vertical.ts index 83a28856f..2faa2f11d 100644 --- a/core/flyout_vertical.ts +++ b/core/flyout_vertical.ts @@ -19,16 +19,16 @@ import './constants'; import * as browserEvents from './browser_events.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Flyout, FlyoutItem } from './flyout_base.js'; +import {Flyout, FlyoutItem} from './flyout_base.js'; /* eslint-disable-next-line no-unused-vars */ -import { FlyoutButton } from './flyout_button.js'; +import {FlyoutButton} from './flyout_button.js'; /* eslint-disable-next-line no-unused-vars */ -import { Options } from './options.js'; +import {Options} from './options.js'; import * as registry from './registry.js'; -import { Scrollbar } from './scrollbar.js'; +import {Scrollbar} from './scrollbar.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; -import { Rect } from './utils/rect.js'; +import {Coordinate} from './utils/coordinate.js'; +import {Rect} from './utils/rect.js'; import * as toolbox from './utils/toolbox.js'; import * as WidgetDiv from './widgetdiv.js'; @@ -57,7 +57,7 @@ export class VerticalFlyout extends Flyout { * @param xyRatio Contains a y property which is a float between 0 and 1 * specifying the degree of scrolling and a similar x property. */ - protected override setMetrics_(xyRatio: { x: number, y: number }) { + protected override setMetrics_(xyRatio: {x: number, y: number}) { if (!this.isVisible()) { return; } @@ -68,12 +68,12 @@ export class VerticalFlyout extends Flyout { if (typeof xyRatio.y === 'number') { this.workspace_.scrollY = - -(scrollMetrics.top + - (scrollMetrics.height - viewMetrics.height) * xyRatio.y); + -(scrollMetrics.top + + (scrollMetrics.height - viewMetrics.height) * xyRatio.y); } this.workspace_.translate( - this.workspace_.scrollX + absoluteMetrics.left, - this.workspace_.scrollY + absoluteMetrics.top); + this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.scrollY + absoluteMetrics.top); } /** @@ -144,7 +144,7 @@ export class VerticalFlyout extends Flyout { const edgeWidth = this.width_ - this.CORNER_RADIUS; const edgeHeight = - targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; + targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); const x = this.getX(); @@ -163,20 +163,20 @@ export class VerticalFlyout extends Flyout { const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. - const path: Array = - ['M ' + (atRight ? totalWidth : 0) + ',0']; + const path: Array = + ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. path.push('h', (atRight ? -width : width)); // Rounded corner. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, - atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); // Side closest to workspace. path.push('v', Math.max(0, height)); // Rounded corner. path.push( - 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, - atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); // Bottom. path.push('h', (atRight ? width : -width)); path.push('z'); @@ -238,14 +238,14 @@ export class VerticalFlyout extends Flyout { const root = block!.getSvgRoot(); const blockHW = block!.getHeightWidth(); const moveX = - block!.outputConnection ? cursorX - this.tabWidth_ : cursorX; + block!.outputConnection ? cursorX - this.tabWidth_ : cursorX; block!.moveBy(moveX, cursorY); // AnyDuringMigration because: Argument of type 'BlockSvg | undefined' // is not assignable to parameter of type 'BlockSvg'. const rect = this.createRect_( - block as AnyDuringMigration, - this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); + block as AnyDuringMigration, + this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); // AnyDuringMigration because: Argument of type 'BlockSvg | undefined' // is not assignable to parameter of type 'BlockSvg'. @@ -277,7 +277,7 @@ export class VerticalFlyout extends Flyout { const range = this.dragAngleRange_; // Check for left or right dragging. if (dragDirection < range && dragDirection > -range || - (dragDirection < -180 + range || dragDirection > 180 - range)) { + (dragDirection < -180 + range || dragDirection > 180 - range)) { return true; } return false; @@ -289,7 +289,7 @@ export class VerticalFlyout extends Flyout { * @return The component's bounding box. Null if drag target area should be * ignored. */ - override getClientRect(): Rect | null { + override getClientRect(): Rect|null { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -350,7 +350,7 @@ export class VerticalFlyout extends Flyout { // AnyDuringMigration because: Argument of type 'SVGElement | // undefined' is not assignable to parameter of type 'SVGElement'. this.moveRectToBlock_( - this.rectMap_.get(block) as AnyDuringMigration, block); + this.rectMap_.get(block) as AnyDuringMigration, block); } } if (this.RTL) { @@ -358,20 +358,20 @@ export class VerticalFlyout extends Flyout { for (let i = 0, button; button = this.buttons_[i]; i++) { const y = button.getPosition().y; const x = flyoutWidth / this.workspace_.scale - button.width - - this.MARGIN - this.tabWidth_; + this.MARGIN - this.tabWidth_; button.moveTo(x, y); } } if (this.targetWorkspace!.toolboxPosition === this.toolboxPosition_ && - this.toolboxPosition_ === toolbox.Position.LEFT && - !this.targetWorkspace!.getToolbox()) { + this.toolboxPosition_ === toolbox.Position.LEFT && + !this.targetWorkspace!.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that // (0,0) is in the correct position relative to the new absolute edge // (ie toolbox edge). this.targetWorkspace!.translate( - this.targetWorkspace!.scrollX + flyoutWidth, - this.targetWorkspace!.scrollY); + this.targetWorkspace!.scrollX + flyoutWidth, + this.targetWorkspace!.scrollY); } this.width_ = flyoutWidth; this.position(); @@ -381,4 +381,4 @@ export class VerticalFlyout extends Flyout { } registry.register( - registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout); + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout); diff --git a/core/generator.ts b/core/generator.ts index 65a41f032..b2fa90573 100644 --- a/core/generator.ts +++ b/core/generator.ts @@ -17,13 +17,13 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; import * as common from './common.js'; /* eslint-disable-next-line no-unused-vars */ -import { Names, NameType } from './names.js'; +import {Names, NameType} from './names.js'; import * as deprecation from './utils/deprecation.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -48,21 +48,21 @@ export class Generator { * Any instances of '%1' will be replaced by the block ID that failed. * E.g. ' checkTimeout(%1);\n' */ - INFINITE_LOOP_TRAP: string | null = null; + INFINITE_LOOP_TRAP: string|null = null; /** * Arbitrary code to inject before every statement. * Any instances of '%1' will be replaced by the block ID of the statement. * E.g. 'highlight(%1);\n' */ - STATEMENT_PREFIX: string | null = null; + STATEMENT_PREFIX: string|null = null; /** * Arbitrary code to inject after every statement. * Any instances of '%1' will be replaced by the block ID of the statement. * E.g. 'highlight(%1);\n' */ - STATEMENT_SUFFIX: string | null = null; + STATEMENT_SUFFIX: string|null = null; /** * The method of indenting. Defaults to two spaces, but language generators @@ -85,7 +85,7 @@ export class Generator { * will cause blockToCode to emit a warning if the generator has not been * initialized. If this flag is untouched, it will have no effect. */ - isInitialized: boolean | null = null; + isInitialized: boolean|null = null; /** Comma-separated list of reserved words. */ protected RESERVED_WORDS_ = ''; @@ -107,7 +107,7 @@ export class Generator { this.name_ = name; this.FUNCTION_NAME_PLACEHOLDER_REGEXP_ = - new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g'); + new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g'); } /** @@ -119,7 +119,7 @@ export class Generator { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn( - 'No workspace specified in workspaceToCode call. Guessing.'); + 'No workspace specified in workspaceToCode call. Guessing.'); workspace = common.getMainWorkspace(); } let code = []; @@ -211,11 +211,11 @@ export class Generator { * For value blocks, an array containing the generated code and an * operator order value. Returns '' if block is null. */ - blockToCode(block: Block | null, opt_thisOnly?: boolean): string - | AnyDuringMigration[] { + blockToCode(block: Block|null, opt_thisOnly?: boolean): string + |AnyDuringMigration[] { if (this.isInitialized === false) { console.warn( - 'Generator init was not called before blockToCode was called.'); + 'Generator init was not called before blockToCode was called.'); } if (!block) { return ''; @@ -232,8 +232,8 @@ export class Generator { const func = (this as AnyDuringMigration)[block.type]; if (typeof func !== 'function') { throw Error( - 'Language "' + this.name_ + '" does not know how to generate ' + - 'code for block type "' + block.type + '".'); + 'Language "' + this.name_ + '" does not know how to generate ' + + 'code for block type "' + block.type + '".'); } // First argument to func.call is the value of 'this' in the generator. // Prior to 24 September 2013 'this' was the only way to access the block. @@ -293,7 +293,7 @@ export class Generator { const innerOrder = tuple[1]; if (isNaN(innerOrder)) { throw TypeError( - 'Expecting valid order from value block: ' + targetBlock.type); + 'Expecting valid order from value block: ' + targetBlock.type); } if (!code) { return ''; @@ -309,7 +309,7 @@ export class Generator { // In all known languages multiple such code blocks are not order // sensitive. In fact in Python ('a' 'b') 'c' would fail. if (outerOrderClass === innerOrderClass && - (outerOrderClass === 0 || outerOrderClass === 99)) { + (outerOrderClass === 0 || outerOrderClass === 99)) { } else { // The operators outside this code are stronger than the operators // inside this code. To prevent the code from being pulled apart, @@ -318,7 +318,7 @@ export class Generator { // Check for special exceptions. for (let i = 0; i < this.ORDER_OVERRIDES.length; i++) { if (this.ORDER_OVERRIDES[i][0] === outerOrder && - this.ORDER_OVERRIDES[i][1] === innerOrder) { + this.ORDER_OVERRIDES[i][1] === innerOrder) { parensNeeded = false; break; } @@ -349,8 +349,8 @@ export class Generator { // Statement blocks must only return code. if (typeof code !== 'string') { throw TypeError( - 'Expecting code from statement block: ' + - (targetBlock && targetBlock.type)); + 'Expecting code from statement block: ' + + (targetBlock && targetBlock.type)); } if (code) { code = this.prefixLines((code), this.INDENT); @@ -370,18 +370,18 @@ export class Generator { addLoopTrap(branch: string, block: Block): string { if (this.INFINITE_LOOP_TRAP) { branch = this.prefixLines( - this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + - branch; + this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + + branch; } if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) { branch = this.prefixLines( - this.injectId(this.STATEMENT_SUFFIX, block), this.INDENT) + - branch; + this.injectId(this.STATEMENT_SUFFIX, block), this.INDENT) + + branch; } if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { branch = branch + - this.prefixLines( - this.injectId(this.STATEMENT_PREFIX, block), this.INDENT); + this.prefixLines( + this.injectId(this.STATEMENT_PREFIX, block), this.INDENT); } return branch; } @@ -428,17 +428,17 @@ export class Generator { * @return The actual name of the new function. This may differ from * desiredName if the former has already been taken by the user. */ - protected provideFunction_(desiredName: string, code: string[] | string): - string { + protected provideFunction_(desiredName: string, code: string[]|string): + string { if (!this.definitions_[desiredName]) { const functionName = - this.nameDB_!.getDistinctName(desiredName, NameType.PROCEDURE); + this.nameDB_!.getDistinctName(desiredName, NameType.PROCEDURE); this.functionNames_[desiredName] = functionName; if (Array.isArray(code)) { code = code.join('\n'); } let codeText = code.trim().replace( - this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); + this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); // Change all ' ' indents into the desired indent. // To avoid an infinite loop of replacements, change all indents to '\0' // character first, then replace them all with the indent. @@ -482,7 +482,7 @@ export class Generator { * @return Code with comments and subsequent blocks added. */ protected scrub_(_block: Block, code: string, _opt_thisOnly?: boolean): - string { + string { // Optionally override return code; } @@ -528,12 +528,12 @@ Object.defineProperties(Generator.prototype, { variableDB_: ({ /** @return Name database. */ get(this: Generator): Names | - undefined { - deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); - return this.nameDB_; - }, + undefined { + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + return this.nameDB_; + }, /** @param nameDb New name database. */ - set(this: Generator, nameDb: Names | undefined) { + set(this: Generator, nameDb: Names|undefined) { deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; }, diff --git a/core/gesture.ts b/core/gesture.ts index 23bcfdbbb..d147d9e1e 100644 --- a/core/gesture.ts +++ b/core/gesture.ts @@ -23,31 +23,31 @@ import './events/events_click'; import * as blockAnimations from './block_animations.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; -import { BubbleDragger } from './bubble_dragger.js'; +import {BubbleDragger} from './bubble_dragger.js'; import * as common from './common.js'; -import { config } from './config.js'; +import {config} from './config.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBlockDragger } from './interfaces/i_block_dragger.js'; +import {IBlockDragger} from './interfaces/i_block_dragger.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBubble } from './interfaces/i_bubble.js'; +import {IBubble} from './interfaces/i_bubble.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; import * as internalConstants from './internal_constants.js'; import * as registry from './registry.js'; import * as Tooltip from './tooltip.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; -import { Workspace } from './workspace.js'; +import {Coordinate} from './utils/coordinate.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; -import { WorkspaceDragger } from './workspace_dragger.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; +import {WorkspaceDragger} from './workspace_dragger.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; @@ -133,13 +133,13 @@ export class Gesture { * A handle to use to unbind a mouse move listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. */ - protected onMoveWrapper_: browserEvents.Data | null = null; + protected onMoveWrapper_: browserEvents.Data|null = null; /** * A handle to use to unbind a mouse up listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. */ - protected onUpWrapper_: browserEvents.Data | null = null; + protected onUpWrapper_: browserEvents.Data|null = null; /** The object tracking a bubble drag, or null if none is in progress. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -147,7 +147,7 @@ export class Gesture { private bubbleDragger_: BubbleDragger = null as AnyDuringMigration; /** The object tracking a block drag, or null if none is in progress. */ - private blockDragger_: IBlockDragger | null = null; + private blockDragger_: IBlockDragger|null = null; /** * The object tracking a workspace or flyout workspace drag, or null if none @@ -178,7 +178,7 @@ export class Gesture { * reference to it. */ constructor( - private e: Event, private readonly creatorWorkspace: WorkspaceSvg) { + private e: Event, private readonly creatorWorkspace: WorkspaceSvg) { /** * How far the mouse has moved during this drag, in pixel units. * (0, 0) is at this.mouseDownXY_. @@ -226,7 +226,7 @@ export class Gesture { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. const currentXY = new Coordinate( - (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); + (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { @@ -244,14 +244,14 @@ export class Gesture { */ private updateDragDelta_(currentXY: Coordinate): boolean { this.currentDragDeltaXY_ = - Coordinate.difference(currentXY, (this.mouseDownXY_)); + Coordinate.difference(currentXY, (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { const currentDragDelta = Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. const limitRadius = - this.flyout_ ? config.flyoutDragRadius : config.dragRadius; + this.flyout_ ? config.flyoutDragRadius : config.dragRadius; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -277,7 +277,7 @@ export class Gesture { return false; } if (!this.flyout_.isScrollable() || - this.flyout_.isDragTowardWorkspace(this.currentDragDeltaXY_)) { + this.flyout_.isDragTowardWorkspace(this.currentDragDeltaXY_)) { // AnyDuringMigration because: Type 'WorkspaceSvg | null' is not // assignable to type 'WorkspaceSvg'. this.startWorkspace_ = this.flyout_.targetWorkspace as AnyDuringMigration; @@ -352,8 +352,8 @@ export class Gesture { */ private updateIsDraggingWorkspace_() { const wsMovable = this.flyout_ ? - this.flyout_.isScrollable() : - this.startWorkspace_ && this.startWorkspace_.isDraggable(); + this.flyout_.isScrollable() : + this.startWorkspace_ && this.startWorkspace_.isDraggable(); if (!wsMovable) { return; @@ -394,10 +394,10 @@ export class Gesture { /** Create a block dragger and start dragging the selected block. */ private startDraggingBlock_() { const BlockDraggerClass = registry.getClassFromOptions( - registry.Type.BLOCK_DRAGGER, this.creatorWorkspace.options, true); + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace.options, true); this.blockDragger_ = - new BlockDraggerClass!((this.targetBlock_), (this.startWorkspace_)); + new BlockDraggerClass!((this.targetBlock_), (this.startWorkspace_)); this.blockDragger_!.startDrag(this.currentDragDeltaXY_, this.healStack_); this.blockDragger_!.drag(this.e, this.currentDragDeltaXY_); } @@ -406,7 +406,7 @@ export class Gesture { /** Create a bubble dragger and start dragging the selected bubble. */ private startDraggingBubble_() { this.bubbleDragger_ = - new BubbleDragger((this.startBubble_), (this.startWorkspace_)); + new BubbleDragger((this.startBubble_), (this.startWorkspace_)); this.bubbleDragger_.startBubbleDrag(); this.bubbleDragger_.dragBubble(this.e, this.currentDragDeltaXY_); } @@ -451,8 +451,8 @@ export class Gesture { // TODO(#6097): Make types accurate, possibly by refactoring touch handling. const typelessEvent = e as AnyDuringMigration; if ((e.type.toLowerCase() === 'touchstart' || - e.type.toLowerCase() === 'pointerdown') && - typelessEvent.pointerType !== 'mouse') { + e.type.toLowerCase() === 'pointerdown') && + typelessEvent.pointerType !== 'mouse') { Touch.longStart(typelessEvent, this); } @@ -460,13 +460,13 @@ export class Gesture { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. this.mouseDownXY_ = new Coordinate( - (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); + (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); // AnyDuringMigration because: Property 'metaKey' does not exist on type // 'Event'. AnyDuringMigration because: Property 'ctrlKey' does not exist // on type 'Event'. AnyDuringMigration because: Property 'altKey' does not // exist on type 'Event'. this.healStack_ = (e as AnyDuringMigration).altKey || - (e as AnyDuringMigration).ctrlKey || (e as AnyDuringMigration).metaKey; + (e as AnyDuringMigration).ctrlKey || (e as AnyDuringMigration).metaKey; this.bindMouseEvents(e); } @@ -477,9 +477,9 @@ export class Gesture { */ bindMouseEvents(e: Event) { this.onMoveWrapper_ = browserEvents.conditionalBind( - document, 'mousemove', null, this.handleMove.bind(this)); + document, 'mousemove', null, this.handleMove.bind(this)); this.onUpWrapper_ = browserEvents.conditionalBind( - document, 'mouseup', null, this.handleUp.bind(this)); + document, 'mouseup', null, this.handleUp.bind(this)); e.preventDefault(); e.stopPropagation(); @@ -596,8 +596,8 @@ export class Gesture { handleWsStart(e: Event, ws: WorkspaceSvg) { if (this.hasStarted_) { throw Error( - 'Tried to call gesture.handleWsStart, ' + - 'but the gesture had already been started.'); + 'Tried to call gesture.handleWsStart, ' + + 'but the gesture had already been started.'); } this.setStartWorkspace_(ws); this.e = e; @@ -610,7 +610,7 @@ export class Gesture { */ private fireWorkspaceClick_(ws: WorkspaceSvg) { eventUtils.fire(new (eventUtils.get(eventUtils.CLICK))! - (null, ws.id, 'workspace')); + (null, ws.id, 'workspace')); } /** @@ -621,8 +621,8 @@ export class Gesture { handleFlyoutStart(e: Event, flyout: IFlyout) { if (this.hasStarted_) { throw Error( - 'Tried to call gesture.handleFlyoutStart, ' + - 'but the gesture had already been started.'); + 'Tried to call gesture.handleFlyoutStart, ' + + 'but the gesture had already been started.'); } this.setStartFlyout_(flyout); this.handleWsStart(e, flyout.getWorkspace()); @@ -636,8 +636,8 @@ export class Gesture { handleBlockStart(e: Event, block: BlockSvg) { if (this.hasStarted_) { throw Error( - 'Tried to call gesture.handleBlockStart, ' + - 'but the gesture had already been started.'); + 'Tried to call gesture.handleBlockStart, ' + + 'but the gesture had already been started.'); } this.setStartBlock(block); this.e = e; @@ -651,8 +651,8 @@ export class Gesture { handleBubbleStart(e: Event, bubble: IBubble) { if (this.hasStarted_) { throw Error( - 'Tried to call gesture.handleBubbleStart, ' + - 'but the gesture had already been started.'); + 'Tried to call gesture.handleBubbleStart, ' + + 'but the gesture had already been started.'); } this.setStartBubble(bubble); this.e = e; @@ -691,7 +691,7 @@ export class Gesture { } else { // Clicks events are on the start block, even if it was a shadow. const event = new (eventUtils.get(eventUtils.CLICK))! - (this.startBlock_, this.startWorkspace_.id, 'block'); + (this.startBlock_, this.startWorkspace_.id, 'block'); eventUtils.fire(event); } this.bringBlockToFront_(); @@ -736,8 +736,8 @@ export class Gesture { setStartField(field: Field) { if (this.hasStarted_) { throw Error( - 'Tried to call gesture.setStartField, ' + - 'but the gesture had already been started.'); + 'Tried to call gesture.setStartField, ' + + 'but the gesture had already been started.'); } if (!this.startField_) { this.startField_ = field; @@ -833,7 +833,7 @@ export class Gesture { // not a field click. const hasStartBlock = !!this.startBlock_; return hasStartBlock && !this.hasExceededDragRadius_ && - !this.isFieldClick_(); + !this.isFieldClick_(); } /** @@ -843,9 +843,9 @@ export class Gesture { */ private isFieldClick_(): boolean { const fieldClickable = - this.startField_ ? this.startField_.isClickable() : false; + this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && - (!this.flyout_ || !this.flyout_.autoClose); + (!this.flyout_ || !this.flyout_.autoClose); } /** @@ -855,7 +855,7 @@ export class Gesture { */ private isWorkspaceClick_(): boolean { const onlyTouchedWorkspace = - !this.startBlock_ && !this.startBubble_ && !this.startField_; + !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; } @@ -869,7 +869,7 @@ export class Gesture { */ isDragging(): boolean { return this.isDraggingWorkspace_ || this.isDraggingBlock_ || - this.isDraggingBubble_; + this.isDraggingBubble_; } /** @@ -900,7 +900,7 @@ export class Gesture { * @return The dragger that is currently in use or null if no drag is in * progress. */ - getCurrentDragger(): WorkspaceDragger | BubbleDragger | IBlockDragger | null { + getCurrentDragger(): WorkspaceDragger|BubbleDragger|IBlockDragger|null { if (this.isDraggingBlock_) { return this.blockDragger_; } else if (this.isDraggingWorkspace_) { diff --git a/core/grid.ts b/core/grid.ts index 2787e92b8..c9f8a713f 100644 --- a/core/grid.ts +++ b/core/grid.ts @@ -17,7 +17,7 @@ */ import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; @@ -134,8 +134,8 @@ export class Grid { * @param y2 The new y end position of the line (in px). */ private setLineAttributes_( - line: SVGElement, width: number, x1: number, x2: number, y1: number, - y2: number) { + line: SVGElement, width: number, x1: number, x2: number, y1: number, + y2: number) { if (line) { // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. @@ -184,8 +184,8 @@ export class Grid { * @return The SVG element for the grid pattern. */ static createDom( - rnd: string, gridOptions: AnyDuringMigration, - defs: SVGElement): SVGElement { + rnd: string, gridOptions: AnyDuringMigration, + defs: SVGElement): SVGElement { /* @@ -193,16 +193,16 @@ export class Grid { */ const gridPattern = dom.createSvgElement( - Svg.PATTERN, - { 'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse' }, - defs); + Svg.PATTERN, + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, + defs); // x1, y1, x1, x2 properties will be set later in update. if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { dom.createSvgElement( - Svg.LINE, { 'stroke': gridOptions['colour'] }, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { dom.createSvgElement( - Svg.LINE, { 'stroke': gridOptions['colour'] }, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } } else { // Edge 16 doesn't handle empty patterns diff --git a/core/icon.ts b/core/icon.ts index e7b0fd439..dc4dc40ae 100644 --- a/core/icon.ts +++ b/core/icon.ts @@ -13,14 +13,14 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as browserEvents from './browser_events.js'; /* eslint-disable-next-line no-unused-vars */ -import { Bubble } from './bubble.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Bubble} from './bubble.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; @@ -31,7 +31,7 @@ import * as svgMath from './utils/svg_math.js'; export abstract class Icon { protected block_: BlockSvg; /** The icon SVG group. */ - iconGroup_: SVGGElement | null = null; + iconGroup_: SVGGElement|null = null; /** Whether this icon gets hidden when the block is collapsed. */ collapseHidden = true; @@ -40,10 +40,10 @@ export abstract class Icon { readonly SIZE = 17; /** Bubble UI (if visible). */ - protected bubble_: Bubble | null = null; + protected bubble_: Bubble|null = null; /** Absolute coordinate of icon's center. */ - protected iconXY_: Coordinate | null = null; + protected iconXY_: Coordinate|null = null; /** @param block The block associated with this icon. */ constructor(block: BlockSvg) { @@ -62,7 +62,7 @@ export abstract class Icon { */ this.iconGroup_ = - dom.createSvgElement(Svg.G, { 'class': 'blocklyIconGroup' }); + dom.createSvgElement(Svg.G, {'class': 'blocklyIconGroup'}); if (this.block_.isInFlyout) { dom.addClass(this.iconGroup_ as Element, 'blocklyIconGroupReadonly'); } @@ -76,8 +76,8 @@ export abstract class Icon { // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'EventTarget'. browserEvents.conditionalBind( - this.iconGroup_ as AnyDuringMigration, 'mouseup', this, - this.iconClick_); + this.iconGroup_ as AnyDuringMigration, 'mouseup', this, + this.iconClick_); this.updateEditable(); } @@ -146,8 +146,8 @@ export abstract class Icon { const blockXY = this.block_.getRelativeToSurfaceXY(); const iconXY = svgMath.getRelativeXY(this.iconGroup_ as SVGElement); const newXY = new Coordinate( - blockXY.x + iconXY.x + this.SIZE / 2, - blockXY.y + iconXY.y + this.SIZE / 2); + blockXY.x + iconXY.x + this.SIZE / 2, + blockXY.y + iconXY.y + this.SIZE / 2); if (!Coordinate.equals(this.getIconLocation(), newXY)) { this.setIconLocation(newXY); } @@ -157,7 +157,7 @@ export abstract class Icon { * Returns the center of the block's icon relative to the surface. * @return Object with x and y properties in workspace coordinates. */ - getIconLocation(): Coordinate | null { + getIconLocation(): Coordinate|null { return this.iconXY_; } diff --git a/core/inject.ts b/core/inject.ts index 6993e3cdd..9df59d4e0 100644 --- a/core/inject.ts +++ b/core/inject.ts @@ -14,29 +14,29 @@ import 'angular-mocks'; -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; +import {BlocklyOptions} from './blockly_options.js'; import * as browserEvents from './browser_events.js'; import * as bumpObjects from './bump_objects.js'; import * as common from './common.js'; import * as Css from './css.js'; import * as dropDownDiv from './dropdowndiv.js'; -import { Grid } from './grid.js'; -import { Msg } from './msg.js'; -import { Options } from './options.js'; -import { ScrollbarPair } from './scrollbar_pair.js'; -import { ShortcutRegistry } from './shortcut_registry.js'; +import {Grid} from './grid.js'; +import {Msg} from './msg.js'; +import {Options} from './options.js'; +import {ScrollbarPair} from './scrollbar_pair.js'; +import {ShortcutRegistry} from './shortcut_registry.js'; import * as Tooltip from './tooltip.js'; import * as Touch from './touch.js'; import * as aria from './utils/aria.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as userAgent from './utils/useragent.js'; import * as WidgetDiv from './widgetdiv.js'; -import { Workspace } from './workspace.js'; -import { WorkspaceDragSurfaceSvg } from './workspace_drag_surface_svg.js'; -import { WorkspaceSvg } from './workspace_svg.js'; +import {Workspace} from './workspace.js'; +import {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -47,18 +47,18 @@ import { WorkspaceSvg } from './workspace_svg.js'; * @alias Blockly.inject */ export function inject( - container: Element | string, opt_options?: BlocklyOptions): WorkspaceSvg { + container: Element|string, opt_options?: BlocklyOptions): WorkspaceSvg { if (typeof container === 'string') { // AnyDuringMigration because: Type 'Element | null' is not assignable to // type 'string | Element'. container = (document.getElementById(container) || - document.querySelector(container)) as AnyDuringMigration; + document.querySelector(container)) as AnyDuringMigration; } // Verify that the container is in document. // AnyDuringMigration because: Argument of type 'string | Element' is not // assignable to parameter of type 'Node'. if (!container || - !dom.containsNode(document, container as AnyDuringMigration)) { + !dom.containsNode(document, container as AnyDuringMigration)) { throw Error('Error: container is not in current document.'); } const options = new Options(opt_options || {} as BlocklyOptions); @@ -79,7 +79,7 @@ export function inject( const workspaceDragSurface = new WorkspaceDragSurfaceSvg(subContainer); const workspace = - createMainWorkspace(svg, options, blockDragSurface, workspaceDragSurface); + createMainWorkspace(svg, options, blockDragSurface, workspaceDragSurface); init(workspace); @@ -91,7 +91,7 @@ export function inject( common.svgResize(workspace); - subContainer.addEventListener('focusin', function () { + subContainer.addEventListener('focusin', function() { // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not // assignable to parameter of type 'Workspace'. common.setMainWorkspace(workspace as AnyDuringMigration); @@ -127,15 +127,15 @@ function createDom(container: Element, options: Options): Element { */ const svg = dom.createSvgElement( - Svg.SVG, { - 'xmlns': dom.SVG_NS, - 'xmlns:html': dom.HTML_NS, - 'xmlns:xlink': dom.XLINK_NS, - 'version': '1.1', - 'class': 'blocklySvg', - 'tabindex': '0', - }, - container); + Svg.SVG, { + 'xmlns': dom.SVG_NS, + 'xmlns:html': dom.HTML_NS, + 'xmlns:xlink': dom.XLINK_NS, + 'version': '1.1', + 'class': 'blocklySvg', + 'tabindex': '0', + }, + container); /* ... filters go here ... @@ -160,21 +160,21 @@ function createDom(container: Element, options: Options): Element { * @return Newly created main workspace. */ function createMainWorkspace( - svg: Element, options: Options, blockDragSurface: BlockDragSurfaceSvg, - workspaceDragSurface: WorkspaceDragSurfaceSvg): WorkspaceSvg { + svg: Element, options: Options, blockDragSurface: BlockDragSurfaceSvg, + workspaceDragSurface: WorkspaceDragSurfaceSvg): WorkspaceSvg { options.parentWorkspace = null; const mainWorkspace = - new WorkspaceSvg(options, blockDragSurface, workspaceDragSurface); + new WorkspaceSvg(options, blockDragSurface, workspaceDragSurface); const wsOptions = mainWorkspace.options; mainWorkspace.scale = wsOptions.zoomOptions.startScale; svg.appendChild(mainWorkspace.createDom('blocklyMainBackground')); // Set the theme name and renderer name onto the injection div. dom.addClass( - mainWorkspace.getInjectionDiv(), - mainWorkspace.getRenderer().getClassName()); + mainWorkspace.getInjectionDiv(), + mainWorkspace.getRenderer().getClassName()); dom.addClass( - mainWorkspace.getInjectionDiv(), mainWorkspace.getTheme().getClassName()); + mainWorkspace.getInjectionDiv(), mainWorkspace.getTheme().getClassName()); if (!wsOptions.hasCategories && wsOptions.languageTree) { // Add flyout as an that is a sibling of the workspace SVG. @@ -189,13 +189,13 @@ function createMainWorkspace( } // Register the workspace svg as a UI component. mainWorkspace.getThemeManager().subscribe( - svg, 'workspaceBackgroundColour', 'background-color'); + svg, 'workspaceBackgroundColour', 'background-color'); // A null translation will also apply the correct initial scale. mainWorkspace.translate(0, 0); mainWorkspace.addChangeListener( - bumpObjects.bumpIntoBoundsHandler(mainWorkspace)); + bumpObjects.bumpIntoBoundsHandler(mainWorkspace)); // The SVG is now fully assembled. common.svgResize(mainWorkspace); @@ -215,19 +215,19 @@ function init(mainWorkspace: WorkspaceSvg) { // Suppress the browser's context menu. browserEvents.conditionalBind( - svg.parentNode as Element, 'contextmenu', null, - function (e: AnyDuringMigration) { - if (!browserEvents.isTargetInput(e)) { - e.preventDefault(); - } - }); + svg.parentNode as Element, 'contextmenu', null, + function(e: AnyDuringMigration) { + if (!browserEvents.isTargetInput(e)) { + e.preventDefault(); + } + }); const workspaceResizeHandler = - browserEvents.conditionalBind(window, 'resize', null, function () { - mainWorkspace.hideChaff(true); - common.svgResize(mainWorkspace); - bumpObjects.bumpTopObjectsIntoBounds(mainWorkspace); - }); + browserEvents.conditionalBind(window, 'resize', null, function() { + mainWorkspace.hideChaff(true); + common.svgResize(mainWorkspace); + bumpObjects.bumpTopObjectsIntoBounds(mainWorkspace); + }); mainWorkspace.setResizeHandlerWrapper(workspaceResizeHandler); bindDocumentEvents(); @@ -256,15 +256,15 @@ function init(mainWorkspace: WorkspaceSvg) { if (options.moveOptions && options.moveOptions.scrollbars) { const horizontalScroll = options.moveOptions.scrollbars === true || - !!options.moveOptions.scrollbars.horizontal; + !!options.moveOptions.scrollbars.horizontal; const verticalScroll = options.moveOptions.scrollbars === true || - !!options.moveOptions.scrollbars.vertical; + !!options.moveOptions.scrollbars.vertical; mainWorkspace.scrollbar = new ScrollbarPair( - mainWorkspace, horizontalScroll, verticalScroll, - 'blocklyMainWorkspaceScrollbar'); + mainWorkspace, horizontalScroll, verticalScroll, + 'blocklyMainWorkspaceScrollbar'); mainWorkspace.scrollbar.resize(); } else { - mainWorkspace.setMetrics({ x: 0.5, y: 0.5 }); + mainWorkspace.setMetrics({x: 0.5, y: 0.5}); } // Load the sounds. @@ -287,7 +287,7 @@ function onKeyDown(e: KeyboardEvent) { } if (browserEvents.isTargetInput(e) || - mainWorkspace.rendered && !mainWorkspace.isVisible()) { + mainWorkspace.rendered && !mainWorkspace.isVisible()) { // When focused on an HTML text input widget, don't trap any keys. // Ignore keypresses on rendered workspaces that have been explicitly // hidden. @@ -314,7 +314,7 @@ let documentEventsBound = false; */ function bindDocumentEvents() { if (!documentEventsBound) { - browserEvents.conditionalBind(document, 'scroll', null, function () { + browserEvents.conditionalBind(document, 'scroll', null, function() { const workspaces = Workspace.getAll(); for (let i = 0, workspace; workspace = workspaces[i]; i++) { if (workspace instanceof WorkspaceSvg) { @@ -330,10 +330,10 @@ function bindDocumentEvents() { // Some iPad versions don't fire resize after portrait to landscape change. if (userAgent.IPAD) { browserEvents.conditionalBind( - window, 'orientationchange', document, function () { - // TODO (#397): Fix for multiple Blockly workspaces. - common.svgResize(common.getMainWorkspace() as WorkspaceSvg); - }); + window, 'orientationchange', document, function() { + // TODO (#397): Fix for multiple Blockly workspaces. + common.svgResize(common.getMainWorkspace() as WorkspaceSvg); + }); } } documentEventsBound = true; @@ -347,26 +347,26 @@ function bindDocumentEvents() { function loadSounds(pathToMedia: string, workspace: WorkspaceSvg) { const audioMgr = workspace.getAudioManager(); audioMgr.load( - [ - pathToMedia + 'click.mp3', - pathToMedia + 'click.wav', - pathToMedia + 'click.ogg', - ], - 'click'); + [ + pathToMedia + 'click.mp3', + pathToMedia + 'click.wav', + pathToMedia + 'click.ogg', + ], + 'click'); audioMgr.load( - [ - pathToMedia + 'disconnect.wav', - pathToMedia + 'disconnect.mp3', - pathToMedia + 'disconnect.ogg', - ], - 'disconnect'); + [ + pathToMedia + 'disconnect.wav', + pathToMedia + 'disconnect.mp3', + pathToMedia + 'disconnect.ogg', + ], + 'disconnect'); audioMgr.load( - [ - pathToMedia + 'delete.mp3', - pathToMedia + 'delete.ogg', - pathToMedia + 'delete.wav', - ], - 'delete'); + [ + pathToMedia + 'delete.mp3', + pathToMedia + 'delete.ogg', + pathToMedia + 'delete.wav', + ], + 'delete'); // Bind temporary hooks that preload the sounds. const soundBinds: AnyDuringMigration[] = []; @@ -384,7 +384,7 @@ function loadSounds(pathToMedia: string, workspace: WorkspaceSvg) { // Android ignores any sound not loaded as a result of a user action. soundBinds.push(browserEvents.conditionalBind( - document, 'mousemove', null, unbindSounds, true)); + document, 'mousemove', null, unbindSounds, true)); soundBinds.push(browserEvents.conditionalBind( - document, 'touchstart', null, unbindSounds, true)); + document, 'touchstart', null, unbindSounds, true)); } diff --git a/core/input.ts b/core/input.ts index 65ab0d314..ff5fe94f6 100644 --- a/core/input.ts +++ b/core/input.ts @@ -16,17 +16,17 @@ import './field_label'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from './connection.js'; +import {Connection} from './connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; import * as fieldRegistry from './field_registry.js'; -import { inputTypes } from './input_types.js'; +import {inputTypes} from './input_types.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from './rendered_connection.js'; +import {RenderedConnection} from './rendered_connection.js'; /** @@ -50,11 +50,11 @@ export class Input { * @param connection Optional connection for this input. */ constructor( - public type: number, public name: string, block: Block, - public connection: Connection | null) { + public type: number, public name: string, block: Block, + public connection: Connection|null) { if (type !== inputTypes.DUMMY && !name) { throw Error( - 'Value inputs and statement inputs must have non-empty name.'); + 'Value inputs and statement inputs must have non-empty name.'); } this.sourceBlock_ = block; @@ -66,7 +66,7 @@ export class Input { * Get the source block for this input. * @return The source block, or null if there is none. */ - getSourceBlock(): Block | null { + getSourceBlock(): Block|null { return this.sourceBlock_; } @@ -78,7 +78,7 @@ export class Input { * field again. Should be unique to the host block. * @return The input being append to (to allow chaining). */ - appendField(field: string | Field, opt_name?: string): Input { + appendField(field: string|Field, opt_name?: string): Input { this.insertFieldAt(this.fieldRow.length, field, opt_name); return this; } @@ -92,7 +92,7 @@ export class Input { * field again. Should be unique to the host block. * @return The index following the last inserted field. */ - insertFieldAt(index: number, field: string | Field, opt_name?: string): number { + insertFieldAt(index: number, field: string|Field, opt_name?: string): number { if (index < 0 || index > this.fieldRow.length) { throw Error('index ' + index + ' out of bounds.'); } @@ -221,7 +221,7 @@ export class Input { * types are compatible. * @return The input being modified (to allow chaining). */ - setCheck(check: string | string[] | null): Input { + setCheck(check: string|string[]|null): Input { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -249,7 +249,7 @@ export class Input { * @param shadow DOM representation of a block or null. * @return The input being modified (to allow chaining). */ - setShadowDom(shadow: Element | null): Input { + setShadowDom(shadow: Element|null): Input { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -261,7 +261,7 @@ export class Input { * Returns the XML representation of the connection's shadow block. * @return Shadow DOM representation of a block or null. */ - getShadowDom(): Element | null { + getShadowDom(): Element|null { if (!this.connection) { throw Error('This input does not have a connection.'); } diff --git a/core/input_types.ts b/core/input_types.ts index 7cec1e012..cbc890732 100644 --- a/core/input_types.ts +++ b/core/input_types.ts @@ -13,7 +13,7 @@ * @namespace Blockly.inputTypes */ -import { ConnectionType } from './connection_type.js'; +import {ConnectionType} from './connection_type.js'; /** diff --git a/core/insertion_marker_manager.ts b/core/insertion_marker_manager.ts index 7da875ee5..d99776557 100644 --- a/core/insertion_marker_manager.ts +++ b/core/insertion_marker_manager.ts @@ -14,29 +14,29 @@ import * as blockAnimations from './block_animations.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as common from './common.js'; -import { ComponentManager } from './component_manager.js'; -import { config } from './config.js'; -import { ConnectionType } from './connection_type.js'; +import {ComponentManager} from './component_manager.js'; +import {config} from './config.js'; +import {ConnectionType} from './connection_type.js'; import * as constants from './constants.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDeleteArea } from './interfaces/i_delete_area.js'; +import {IDeleteArea} from './interfaces/i_delete_area.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from './rendered_connection.js'; +import {RenderedConnection} from './rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** Represents a nearby valid connection. */ interface CandidateConnection { - closest: RenderedConnection | null; - local: RenderedConnection | null; + closest: RenderedConnection|null; + local: RenderedConnection|null; radius: number; } // eslint-disable-line no-unused-vars @@ -45,9 +45,9 @@ interface CandidateConnection { * missing any components. */ const DUPLICATE_BLOCK_ERROR = 'The insertion marker ' + - 'manager tried to create a marker but the result is missing %1. If ' + - 'you are using a mutator, make sure your domToMutation method is ' + - 'properly defined.'; + 'manager tried to create a marker but the result is missing %1. If ' + + 'you are using a mutator, make sure your domToMutation method is ' + + 'properly defined.'; export enum PreviewType { @@ -222,13 +222,13 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'RenderedConnection' is // not assignable to parameter of type 'Connection'. this.localConnection_.connect( - this.closestConnection_ as AnyDuringMigration); + this.closestConnection_ as AnyDuringMigration); if (this.topBlock_.rendered) { // Trigger a connection animation. // Determine which connection is inferior (lower in the source stack). const inferiorConnection = this.localConnection_.isSuperior() ? - this.closestConnection_ : - this.localConnection_; + this.closestConnection_ : + this.localConnection_; blockAnimations.connectionUiEffect(inferiorConnection.getSourceBlock()); // Bring the just-edited stack to the front. const rootBlock = this.topBlock_.getRootBlock(); @@ -242,13 +242,13 @@ export class InsertionMarkerManager { * @param dxy Position relative to drag start, in workspace units. * @param dragTarget The drag target that the block is currently over. */ - update(dxy: Coordinate, dragTarget: IDragTarget | null) { + update(dxy: Coordinate, dragTarget: IDragTarget|null) { const candidate = this.getCandidate_(dxy); this.wouldDeleteBlock_ = this.shouldDelete_(candidate, dragTarget); const shouldUpdate = - this.wouldDeleteBlock_ || this.shouldUpdatePreviews_(candidate, dxy); + this.wouldDeleteBlock_ || this.shouldUpdatePreviews_(candidate, dxy); if (shouldUpdate) { // Don't fire events for insertion marker creation or movement. @@ -354,7 +354,7 @@ export class InsertionMarkerManager { * @return Whether the preview should be updated. */ private shouldUpdatePreviews_( - candidate: CandidateConnection, dxy: Coordinate): boolean { + candidate: CandidateConnection, dxy: Coordinate): boolean { const candidateLocal = candidate.local; const candidateClosest = candidate.closest; const radius = candidate.radius; @@ -366,24 +366,24 @@ export class InsertionMarkerManager { if (this.localConnection_ && this.closestConnection_) { // The connection was the same as the current connection. if (this.closestConnection_ === candidateClosest && - this.localConnection_ === candidateLocal) { + this.localConnection_ === candidateLocal) { return false; } const xDiff = - this.localConnection_.x + dxy.x - this.closestConnection_.x; + this.localConnection_.x + dxy.x - this.closestConnection_.x; const yDiff = - this.localConnection_.y + dxy.y - this.closestConnection_.y; + this.localConnection_.y + dxy.y - this.closestConnection_.y; const curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); // Slightly prefer the existing preview over a new preview. return !( - candidateClosest && - radius > curDistance - config.currentConnectionPreference); + candidateClosest && + radius > curDistance - config.currentConnectionPreference); } else if (!this.localConnection_ && !this.closestConnection_) { // We weren't showing a preview before, but we should now. return true; } else { console.error( - 'Only one of localConnection_ and closestConnection_ was set.'); + 'Only one of localConnection_ and closestConnection_ was set.'); } } else { // No connection found. @@ -392,7 +392,7 @@ export class InsertionMarkerManager { } console.error( - 'Returning true from shouldUpdatePreviews, but it\'s not clear why.'); + 'Returning true from shouldUpdatePreviews, but it\'s not clear why.'); return true; } @@ -428,7 +428,7 @@ export class InsertionMarkerManager { radius = neighbour.radius; } } - return { closest: candidateClosest, local: candidateLocal, radius }; + return {closest: candidateClosest, local: candidateLocal, radius}; } /** @@ -456,14 +456,14 @@ export class InsertionMarkerManager { * @return Whether dropping the block immediately would delete the block. */ private shouldDelete_( - candidate: CandidateConnection, dragTarget: IDragTarget | null): boolean { + candidate: CandidateConnection, dragTarget: IDragTarget|null): boolean { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); const isDeleteArea = componentManager.hasCapability( - dragTarget.id, ComponentManager.Capability.DELETE_AREA); + dragTarget.id, ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (dragTarget as IDeleteArea) - .wouldDelete(this.topBlock_, candidate && !!candidate.closest); + .wouldDelete(this.topBlock_, candidate && !!candidate.closest); } } return false; @@ -493,7 +493,7 @@ export class InsertionMarkerManager { // Something went wrong and we're trying to connect to an invalid // connection. if (closest === this.closestConnection_ || - closest.getSourceBlock().isInsertionMarker()) { + closest.getSourceBlock().isInsertionMarker()) { console.log('Trying to connect to an insertion marker'); return; } @@ -513,7 +513,7 @@ export class InsertionMarkerManager { const closest = this.closestConnection_; const renderer = this.workspace_.getRenderer(); const method = renderer.getConnectionPreviewMethod( - (closest), (this.localConnection_), this.topBlock_); + (closest), (this.localConnection_), this.topBlock_); switch (method) { case InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE: @@ -532,7 +532,7 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'RenderedConnection' is not // assignable to parameter of type 'Connection'. if (closest && - renderer.shouldHighlightConnection(closest as AnyDuringMigration)) { + renderer.shouldHighlightConnection(closest as AnyDuringMigration)) { closest.highlight(); } } @@ -561,7 +561,7 @@ export class InsertionMarkerManager { // Also hide if we had a preview before but now we're going to delete // instead. if (hadPreview && - (closestChanged || localChanged || this.wouldDeleteBlock_)) { + (closestChanged || localChanged || this.wouldDeleteBlock_)) { this.hidePreview_(); } } @@ -586,8 +586,8 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'RenderedConnection' is not // assignable to parameter of type 'Connection'. if (this.closestConnection_ && this.closestConnection_.targetBlock() && - this.workspace_.getRenderer().shouldHighlightConnection( - this.closestConnection_ as AnyDuringMigration)) { + this.workspace_.getRenderer().shouldHighlightConnection( + this.closestConnection_ as AnyDuringMigration)) { this.closestConnection_.unhighlight(); } if (this.fadedBlock_) { @@ -614,7 +614,7 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'BlockSvg' is not // assignable to parameter of type 'Block'. imConn = imBlock.getMatchingConnection( - local.getSourceBlock() as AnyDuringMigration, local); + local.getSourceBlock() as AnyDuringMigration, local); } catch (e) { // It's possible that the number of connections on the local block has // changed since the insertion marker was originally created. Let's @@ -627,13 +627,13 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'BlockSvg' is not // assignable to parameter of type 'Block'. imConn = imBlock.getMatchingConnection( - local.getSourceBlock() as AnyDuringMigration, local); + local.getSourceBlock() as AnyDuringMigration, local); } if (imConn === this.markerConnection_) { throw Error( - 'Made it to showInsertionMarker_ even though the marker isn\'t ' + - 'changing'); + 'Made it to showInsertionMarker_ even though the marker isn\'t ' + + 'changing'); } // Render disconnected from everything else so that we have a valid @@ -675,17 +675,17 @@ export class InsertionMarkerManager { const markerOutput = imBlock.outputConnection; const isFirstInStatementStack = - imConn === markerNext && !(markerPrev && markerPrev.targetConnection); + imConn === markerNext && !(markerPrev && markerPrev.targetConnection); const isFirstInOutputStack = imConn.type === ConnectionType.INPUT_VALUE && - !(markerOutput && markerOutput.targetConnection); + !(markerOutput && markerOutput.targetConnection); // The insertion marker is the first block in a stack. Unplug won't do // anything in that case. Instead, unplug the following block. if (isFirstInStatementStack || isFirstInOutputStack) { imConn.targetBlock()!.unplug(false); } else if ( - imConn.type === ConnectionType.NEXT_STATEMENT && - imConn !== markerNext) { + imConn.type === ConnectionType.NEXT_STATEMENT && + imConn !== markerNext) { // Inside of a C-block, first statement connection. const innerConnection = imConn.targetConnection; if (innerConnection) { @@ -693,24 +693,24 @@ export class InsertionMarkerManager { } const previousBlockNextConnection = - markerPrev ? markerPrev.targetConnection : null; + markerPrev ? markerPrev.targetConnection : null; imBlock.unplug(true); if (previousBlockNextConnection) { // AnyDuringMigration because: Argument of type 'RenderedConnection' is // not assignable to parameter of type 'Connection'. previousBlockNextConnection.connect( - innerConnection as AnyDuringMigration); + innerConnection as AnyDuringMigration); } } else { imBlock.unplug(/* healStack */ - true); + true); } if (imConn.targetConnection) { throw Error( - 'markerConnection_ still connected at the end of ' + - 'disconnectInsertionMarker'); + 'markerConnection_ still connected at the end of ' + + 'disconnectInsertionMarker'); } // AnyDuringMigration because: Type 'null' is not assignable to type @@ -729,7 +729,7 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'RenderedConnection' is not // assignable to parameter of type 'Connection'. this.highlightedBlock_.highlightShapeForInput( - closest as AnyDuringMigration, true); + closest as AnyDuringMigration, true); } /** Hides any visible input outlines. */ @@ -737,7 +737,7 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Argument of type 'RenderedConnection' is not // assignable to parameter of type 'Connection'. this.highlightedBlock_.highlightShapeForInput( - this.closestConnection_ as AnyDuringMigration, false); + this.closestConnection_ as AnyDuringMigration, false); // AnyDuringMigration because: Type 'null' is not assignable to type // 'BlockSvg'. this.highlightedBlock_ = null as AnyDuringMigration; @@ -751,7 +751,7 @@ export class InsertionMarkerManager { // AnyDuringMigration because: Type 'BlockSvg | null' is not assignable to // type 'BlockSvg'. this.fadedBlock_ = - this.closestConnection_.targetBlock() as AnyDuringMigration; + this.closestConnection_.targetBlock() as AnyDuringMigration; this.fadedBlock_.fadeForReplacement(true); } diff --git a/core/interfaces/i_ast_node_location_svg.ts b/core/interfaces/i_ast_node_location_svg.ts index f7d21420f..767337e8f 100644 --- a/core/interfaces/i_ast_node_location_svg.ts +++ b/core/interfaces/i_ast_node_location_svg.ts @@ -13,7 +13,7 @@ * @namespace Blockly.IASTNodeLocationSvg */ /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocation } from './i_ast_node_location.js'; +import {IASTNodeLocation} from './i_ast_node_location.js'; /** diff --git a/core/interfaces/i_ast_node_location_with_block.ts b/core/interfaces/i_ast_node_location_with_block.ts index 8898189f9..ba1ac6685 100644 --- a/core/interfaces/i_ast_node_location_with_block.ts +++ b/core/interfaces/i_ast_node_location_with_block.ts @@ -22,7 +22,7 @@ import '../block'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocation } from './i_ast_node_location.js'; +import {IASTNodeLocation} from './i_ast_node_location.js'; /** diff --git a/core/interfaces/i_autohideable.ts b/core/interfaces/i_autohideable.ts index 413ff2b2f..4421789cc 100644 --- a/core/interfaces/i_autohideable.ts +++ b/core/interfaces/i_autohideable.ts @@ -18,7 +18,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IComponent } from './i_component.js'; +import {IComponent} from './i_component.js'; /** diff --git a/core/interfaces/i_bubble.ts b/core/interfaces/i_bubble.ts index 0b6e48a79..e9e4f0b34 100644 --- a/core/interfaces/i_bubble.ts +++ b/core/interfaces/i_bubble.ts @@ -21,9 +21,9 @@ import '../block_drag_surface'; import '../utils/coordinate'; /* eslint-disable-next-line no-unused-vars */ -import { IContextMenu } from './i_contextmenu.js'; +import {IContextMenu} from './i_contextmenu.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from './i_draggable.js'; +import {IDraggable} from './i_draggable.js'; /** diff --git a/core/interfaces/i_collapsible_toolbox_item.ts b/core/interfaces/i_collapsible_toolbox_item.ts index a396bb10e..d73aa1724 100644 --- a/core/interfaces/i_collapsible_toolbox_item.ts +++ b/core/interfaces/i_collapsible_toolbox_item.ts @@ -18,7 +18,7 @@ // Unused import preserved for side-effects. Remove if unneeded. import './i_toolbox_item'; -import { ISelectableToolboxItem } from './i_selectable_toolbox_item.js'; +import {ISelectableToolboxItem} from './i_selectable_toolbox_item.js'; /** diff --git a/core/interfaces/i_copyable.ts b/core/interfaces/i_copyable.ts index 87180e365..a047808bf 100644 --- a/core/interfaces/i_copyable.ts +++ b/core/interfaces/i_copyable.ts @@ -15,9 +15,9 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; -import { ISelectable } from './i_selectable.js'; +import {ISelectable} from './i_selectable.js'; /** @alias Blockly.ICopyable */ @@ -29,7 +29,7 @@ export interface ICopyable extends ISelectable { toCopyData: AnyDuringMigration; } export interface CopyData { - saveInfo: AnyDuringMigration | Element; + saveInfo: AnyDuringMigration|Element; source: WorkspaceSvg; - typeCounts: AnyDuringMigration | null; + typeCounts: AnyDuringMigration|null; } diff --git a/core/interfaces/i_delete_area.ts b/core/interfaces/i_delete_area.ts index 47e515071..a1e0ff06e 100644 --- a/core/interfaces/i_delete_area.ts +++ b/core/interfaces/i_delete_area.ts @@ -22,7 +22,7 @@ // Unused import preserved for side-effects. Remove if unneeded. import './i_draggable'; -import { IDragTarget } from './i_drag_target.js'; +import {IDragTarget} from './i_drag_target.js'; /** diff --git a/core/interfaces/i_drag_target.ts b/core/interfaces/i_drag_target.ts index 543489471..a2e62e0bc 100644 --- a/core/interfaces/i_drag_target.ts +++ b/core/interfaces/i_drag_target.ts @@ -25,7 +25,7 @@ import './i_draggable'; // Unused import preserved for side-effects. Remove if unneeded. import '../utils/rect'; -import { IComponent } from './i_component.js'; +import {IComponent} from './i_component.js'; /** diff --git a/core/interfaces/i_draggable.ts b/core/interfaces/i_draggable.ts index 4a5ada253..f1ee5f2f9 100644 --- a/core/interfaces/i_draggable.ts +++ b/core/interfaces/i_draggable.ts @@ -14,7 +14,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IDeletable } from './i_deletable.js'; +import {IDeletable} from './i_deletable.js'; /** diff --git a/core/interfaces/i_flyout.ts b/core/interfaces/i_flyout.ts index 207b64892..91a15e759 100644 --- a/core/interfaces/i_flyout.ts +++ b/core/interfaces/i_flyout.ts @@ -27,10 +27,10 @@ import '../utils/coordinate'; import '../utils/svg'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { IRegistrable } from './i_registrable.js'; +import {IRegistrable} from './i_registrable.js'; /** @@ -45,7 +45,7 @@ export interface IFlyout extends IRegistrable { RTL: boolean; /** The target workspace */ - targetWorkspace: WorkspaceSvg | null; + targetWorkspace: WorkspaceSvg|null; /** Margin around the edges of the blocks in the flyout. */ readonly MARGIN: number; diff --git a/core/interfaces/i_positionable.ts b/core/interfaces/i_positionable.ts index ee14ed7f1..df0aa3f98 100644 --- a/core/interfaces/i_positionable.ts +++ b/core/interfaces/i_positionable.ts @@ -21,7 +21,7 @@ import '../metrics_manager'; // Unused import preserved for side-effects. Remove if unneeded. import '../utils/rect'; -import { IComponent } from './i_component.js'; +import {IComponent} from './i_component.js'; /** diff --git a/core/interfaces/i_registrable_field.ts b/core/interfaces/i_registrable_field.ts index 243a2b1e8..439fa4e30 100644 --- a/core/interfaces/i_registrable_field.ts +++ b/core/interfaces/i_registrable_field.ts @@ -14,7 +14,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../field.js'; +import {Field} from '../field.js'; type fromJson = (p1: object) => Field; diff --git a/core/interfaces/i_selectable.ts b/core/interfaces/i_selectable.ts index 6defb4342..d29085625 100644 --- a/core/interfaces/i_selectable.ts +++ b/core/interfaces/i_selectable.ts @@ -14,9 +14,9 @@ */ // eslint-disable-next-line no-unused-vars -import { IDeletable } from './i_deletable.js'; +import {IDeletable} from './i_deletable.js'; // eslint-disable-next-line no-unused-vars -import { IMovable } from './i_movable.js'; +import {IMovable} from './i_movable.js'; /** diff --git a/core/interfaces/i_selectable_toolbox_item.ts b/core/interfaces/i_selectable_toolbox_item.ts index c6206c31f..2ecf1d1ee 100644 --- a/core/interfaces/i_selectable_toolbox_item.ts +++ b/core/interfaces/i_selectable_toolbox_item.ts @@ -18,7 +18,7 @@ import '../utils/toolbox'; /* eslint-disable-next-line no-unused-vars */ -import { IToolboxItem } from './i_toolbox_item.js'; +import {IToolboxItem} from './i_toolbox_item.js'; /** diff --git a/core/interfaces/i_serializer.ts b/core/interfaces/i_serializer.ts index 21830c713..43333b401 100644 --- a/core/interfaces/i_serializer.ts +++ b/core/interfaces/i_serializer.ts @@ -18,7 +18,7 @@ */ // eslint-disable-next-line no-unused-vars -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; /** diff --git a/core/interfaces/i_toolbox.ts b/core/interfaces/i_toolbox.ts index 696f0ab68..3e588cfb5 100644 --- a/core/interfaces/i_toolbox.ts +++ b/core/interfaces/i_toolbox.ts @@ -27,7 +27,7 @@ import './i_toolbox_item'; import '../workspace_svg'; /* eslint-disable-next-line no-unused-vars */ -import { IRegistrable } from './i_registrable.js'; +import {IRegistrable} from './i_registrable.js'; /** diff --git a/core/interfaces/i_toolbox_item.ts b/core/interfaces/i_toolbox_item.ts index 8f2c0a41c..06744f2f1 100644 --- a/core/interfaces/i_toolbox_item.ts +++ b/core/interfaces/i_toolbox_item.ts @@ -30,7 +30,7 @@ export interface IToolboxItem { * Gets the div for the toolbox item. * @return The div for the toolbox item. */ - getDiv(): Element | null; + getDiv(): Element|null; /** * Gets a unique identifier for this toolbox item. @@ -43,7 +43,7 @@ export interface IToolboxItem { * @return The parent toolbox item, or null if this toolbox item is not * nested. */ - getParent(): IToolboxItem | null; + getParent(): IToolboxItem|null; /** * Gets the nested level of the category. @@ -70,7 +70,7 @@ export interface IToolboxItem { * Gets the HTML element that is clickable. * @return The HTML element that receives clicks. */ - getClickTarget(): Element | null; + getClickTarget(): Element|null; /** * Sets whether the category is visible or not. diff --git a/core/internal_constants.ts b/core/internal_constants.ts index d79093677..946e4d7c8 100644 --- a/core/internal_constants.ts +++ b/core/internal_constants.ts @@ -16,7 +16,7 @@ * @namespace Blockly.internalConstants */ -import { ConnectionType } from './connection_type.js'; +import {ConnectionType} from './connection_type.js'; /** @@ -40,9 +40,9 @@ export const OPPOSITE_TYPE: number[] = []; OPPOSITE_TYPE[ConnectionType.INPUT_VALUE] = ConnectionType.OUTPUT_VALUE; OPPOSITE_TYPE[ConnectionType.OUTPUT_VALUE] = ConnectionType.INPUT_VALUE; OPPOSITE_TYPE[ConnectionType.NEXT_STATEMENT] = - ConnectionType.PREVIOUS_STATEMENT; + ConnectionType.PREVIOUS_STATEMENT; OPPOSITE_TYPE[ConnectionType.PREVIOUS_STATEMENT] = - ConnectionType.NEXT_STATEMENT; + ConnectionType.NEXT_STATEMENT; /** * String for use in the dropdown created in field_variable. diff --git a/core/keyboard_nav/ast_node.ts b/core/keyboard_nav/ast_node.ts index a4374cedf..95fe4305b 100644 --- a/core/keyboard_nav/ast_node.ts +++ b/core/keyboard_nav/ast_node.ts @@ -17,21 +17,21 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from '../connection.js'; -import { ConnectionType } from '../connection_type.js'; +import {Connection} from '../connection.js'; +import {ConnectionType} from '../connection_type.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../field.js'; +import {Field} from '../field.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../input.js'; +import {Input} from '../input.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocation } from '../interfaces/i_ast_node_location.js'; +import {IASTNodeLocation} from '../interfaces/i_ast_node_location.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationWithBlock } from '../interfaces/i_ast_node_location_with_block.js'; -import { Coordinate } from '../utils/coordinate.js'; +import {IASTNodeLocationWithBlock} from '../interfaces/i_ast_node_location_with_block.js'; +import {Coordinate} from '../utils/coordinate.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; /** @@ -103,7 +103,7 @@ export class ASTNode { * Parse the optional parameters. * @param params The user specified parameters. */ - private processParams_(params: Params | null) { + private processParams_(params: Params|null) { if (!params) { return; } @@ -156,7 +156,7 @@ export class ASTNode { * @return The AST node holding the next field or connection or null if there * is no editable field or input connection after the given input. */ - private findNextForInput_(): ASTNode | null { + private findNextForInput_(): ASTNode|null { const location = this.location_ as Connection; const parentInput = location.getParentInput(); const block = parentInput!.getSourceBlock(); @@ -185,7 +185,7 @@ export class ASTNode { * @return The AST node pointing to the next field or connection or null if * there is no editable field or input connection after the given input. */ - private findNextForField_(): ASTNode | null { + private findNextForField_(): ASTNode|null { const location = this.location_ as Field; const input = location.getParentInput(); const block = location.getSourceBlock(); @@ -214,7 +214,7 @@ export class ASTNode { * connection. * @return The AST node holding the previous field or connection. */ - private findPrevForInput_(): ASTNode | null { + private findPrevForInput_(): ASTNode|null { const location = this.location_ as Connection; const parentInput = location.getParentInput(); const block = parentInput!.getSourceBlock(); @@ -242,7 +242,7 @@ export class ASTNode { * connection in the same block. The current location must be a field. * @return The AST node holding the previous input or field. */ - private findPrevForField_(): ASTNode | null { + private findPrevForField_(): ASTNode|null { const location = this.location_ as Field; const parentInput = location.getParentInput(); const block = location.getSourceBlock(); @@ -275,7 +275,7 @@ export class ASTNode { * @return The first block of the next stack or null if there are no blocks on * the workspace. */ - private navigateBetweenStacks_(forward: boolean): ASTNode | null { + private navigateBetweenStacks_(forward: boolean): ASTNode|null { let curLocation = this.getLocation(); // TODO(#6097): Use instanceof checks to exit early for values of // curLocation that don't make sense. @@ -302,7 +302,7 @@ export class ASTNode { } } throw Error( - 'Couldn\'t find ' + (forward ? 'next' : 'previous') + ' stack?!'); + 'Couldn\'t find ' + (forward ? 'next' : 'previous') + ' stack?!'); } /** @@ -312,7 +312,7 @@ export class ASTNode { * @param block The block that we want to find the top connection on. * @return The AST node containing the top connection. */ - private findTopASTNodeForBlock_(block: Block): ASTNode | null { + private findTopASTNodeForBlock_(block: Block): ASTNode|null { const topConnection = getParentConnection(block); if (topConnection) { return ASTNode.createConnectionNode(topConnection); @@ -328,7 +328,7 @@ export class ASTNode { * @return The AST node pointing to the input connection or the top block of * the stack this block is in. */ - private getOutAstNodeForBlock_(block: Block): ASTNode | null { + private getOutAstNodeForBlock_(block: Block): ASTNode|null { if (!block) { return null; } @@ -339,12 +339,12 @@ export class ASTNode { // If the top connection has a parentInput, create an AST node pointing to // that input. if (topConnection && topConnection.targetConnection && - topConnection.targetConnection.getParentInput()) { + topConnection.targetConnection.getParentInput()) { // AnyDuringMigration because: Argument of type 'Input | null' is not // assignable to parameter of type 'Input'. return ASTNode.createInputNode( - topConnection.targetConnection.getParentInput() as - AnyDuringMigration); + topConnection.targetConnection.getParentInput() as + AnyDuringMigration); } else { // Go to stack level if you are not underneath an input. return ASTNode.createStackNode(topBlock); @@ -358,7 +358,7 @@ export class ASTNode { * Null if there are no editable fields or inputs with connections on the * block. */ - private findFirstFieldOrInput_(block: Block): ASTNode | null { + private findFirstFieldOrInput_(block: Block): ASTNode|null { const inputs = block.inputList; for (let i = 0; i < inputs.length; i++) { const input = inputs[i]; @@ -381,7 +381,7 @@ export class ASTNode { * @return The source block of the location, or null if the node is of type * workspace. */ - getSourceBlock(): Block | null { + getSourceBlock(): Block|null { if (this.getType() === ASTNode.types.BLOCK) { return this.getLocation() as Block; } else if (this.getType() === ASTNode.types.STACK) { @@ -398,7 +398,7 @@ export class ASTNode { * @return An AST node that wraps the next field, connection, block, or * workspace. Or null if there is no node to the right. */ - next(): ASTNode | null { + next(): ASTNode|null { switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(true); @@ -438,7 +438,7 @@ export class ASTNode { * @return An AST node that wraps the next field, connection, workspace, or * block. Or null if there is nothing below this node. */ - in(): ASTNode | null { + in(): ASTNode|null { switch (this.type_) { case ASTNode.types.WORKSPACE: { const workspace = this.location_ as Workspace; @@ -472,7 +472,7 @@ export class ASTNode { * block. Or null if no node exists to the left. * null. */ - prev(): ASTNode | null { + prev(): ASTNode|null { switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(false); @@ -514,14 +514,14 @@ export class ASTNode { * @return An AST node that wraps the next field, connection, workspace or * block. Or null if we are at the workspace level. */ - out(): ASTNode | null { + out(): ASTNode|null { switch (this.type_) { case ASTNode.types.STACK: { const block = this.location_ as Block; const blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. const wsCoordinate = - new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); + new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); } case ASTNode.types.OUTPUT: { @@ -578,7 +578,7 @@ export class ASTNode { * @param field The location of the AST node. * @return An AST node pointing to a field. */ - static createFieldNode(field: Field): ASTNode | null { + static createFieldNode(field: Field): ASTNode|null { if (!field) { return null; } @@ -592,7 +592,7 @@ export class ASTNode { * @param connection This is the connection the node will point to. * @return An AST node pointing to a connection. */ - static createConnectionNode(connection: Connection): ASTNode | null { + static createConnectionNode(connection: Connection): ASTNode|null { if (!connection) { return null; } @@ -601,13 +601,13 @@ export class ASTNode { // AnyDuringMigration because: Argument of type 'Input | null' is not // assignable to parameter of type 'Input'. return ASTNode.createInputNode( - connection.getParentInput() as AnyDuringMigration); + connection.getParentInput() as AnyDuringMigration); } else if ( - type === ConnectionType.NEXT_STATEMENT && connection.getParentInput()) { + type === ConnectionType.NEXT_STATEMENT && connection.getParentInput()) { // AnyDuringMigration because: Argument of type 'Input | null' is not // assignable to parameter of type 'Input'. return ASTNode.createInputNode( - connection.getParentInput() as AnyDuringMigration); + connection.getParentInput() as AnyDuringMigration); } else if (type === ConnectionType.NEXT_STATEMENT) { return new ASTNode(ASTNode.types.NEXT, connection); } else if (type === ConnectionType.OUTPUT_VALUE) { @@ -624,7 +624,7 @@ export class ASTNode { * @param input The input used to create an AST node. * @return An AST node pointing to a input. */ - static createInputNode(input: Input): ASTNode | null { + static createInputNode(input: Input): ASTNode|null { if (!input || !input.connection) { return null; } @@ -636,7 +636,7 @@ export class ASTNode { * @param block The block used to create an AST node. * @return An AST node pointing to a block. */ - static createBlockNode(block: Block): ASTNode | null { + static createBlockNode(block: Block): ASTNode|null { if (!block) { return null; } @@ -652,7 +652,7 @@ export class ASTNode { * @return An AST node of type stack that points to the top block on the * stack. */ - static createStackNode(topBlock: Block): ASTNode | null { + static createStackNode(topBlock: Block): ASTNode|null { if (!topBlock) { return null; } @@ -667,11 +667,11 @@ export class ASTNode { * workspace. */ static createWorkspaceNode( - workspace: Workspace | null, wsCoordinate: Coordinate | null): ASTNode | null { + workspace: Workspace|null, wsCoordinate: Coordinate|null): ASTNode|null { if (!wsCoordinate || !workspace) { return null; } - const params = { wsCoordinate }; + const params = {wsCoordinate}; return new ASTNode(ASTNode.types.WORKSPACE, workspace, params); } @@ -681,7 +681,7 @@ export class ASTNode { * @param block The block to find the top most AST node on. * @return The AST node holding the top most position on the block. */ - static createTopNode(block: Block): ASTNode | null { + static createTopNode(block: Block): ASTNode|null { let astNode; const topConnection = getParentConnection(block); if (topConnection) { @@ -707,7 +707,7 @@ export interface Params { function getParentConnection(block: Block): Connection { let topConnection = block.outputConnection; if (!topConnection || - block.previousConnection && block.previousConnection.isConnected()) { + block.previousConnection && block.previousConnection.isConnected()) { topConnection = block.previousConnection; } return topConnection; diff --git a/core/keyboard_nav/basic_cursor.ts b/core/keyboard_nav/basic_cursor.ts index 946818eb2..d94a6c969 100644 --- a/core/keyboard_nav/basic_cursor.ts +++ b/core/keyboard_nav/basic_cursor.ts @@ -18,8 +18,8 @@ import * as registry from '../registry.js'; -import { ASTNode } from './ast_node.js'; -import { Cursor } from './cursor.js'; +import {ASTNode} from './ast_node.js'; +import {Cursor} from './cursor.js'; /** @@ -42,7 +42,7 @@ export class BasicCursor extends Cursor { * @return The next node, or null if the current node is not set or there is * no next value. */ - override next(): ASTNode | null { + override next(): ASTNode|null { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -62,7 +62,7 @@ export class BasicCursor extends Cursor { * @return The next node, or null if the current node is not set or there is * no next value. */ - override in(): ASTNode | null { + override in(): ASTNode|null { return this.next(); } @@ -71,7 +71,7 @@ export class BasicCursor extends Cursor { * @return The previous node, or null if the current node is not set or there * is no previous value. */ - override prev(): ASTNode | null { + override prev(): ASTNode|null { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -91,7 +91,7 @@ export class BasicCursor extends Cursor { * @return The previous node, or null if the current node is not set or there * is no previous value. */ - override out(): ASTNode | null { + override out(): ASTNode|null { return this.prev(); } @@ -105,8 +105,8 @@ export class BasicCursor extends Cursor { * @return The next node in the traversal. */ protected getNextNode_( - node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean): ASTNode - | null { + node: ASTNode|null, isValid: (p1: ASTNode|null) => boolean): ASTNode + |null { if (!node) { return null; } @@ -138,12 +138,12 @@ export class BasicCursor extends Cursor { * exists. */ protected getPreviousNode_( - node: ASTNode | null, isValid: (p1: ASTNode | null) => boolean): ASTNode - | null { + node: ASTNode|null, isValid: (p1: ASTNode|null) => boolean): ASTNode + |null { if (!node) { return null; } - let newNode: ASTNode | null = node.prev(); + let newNode: ASTNode|null = node.prev(); if (newNode) { newNode = this.getRightMostChild_(newNode); @@ -164,12 +164,12 @@ export class BasicCursor extends Cursor { * @param node The AST node to check whether it is valid. * @return True if the node should be visited, false otherwise. */ - protected validNode_(node: ASTNode | null): boolean { + protected validNode_(node: ASTNode|null): boolean { let isValid = false; const type = node && node.getType(); if (type === ASTNode.types.OUTPUT || type === ASTNode.types.INPUT || - type === ASTNode.types.FIELD || type === ASTNode.types.NEXT || - type === ASTNode.types.PREVIOUS || type === ASTNode.types.WORKSPACE) { + type === ASTNode.types.FIELD || type === ASTNode.types.NEXT || + type === ASTNode.types.PREVIOUS || type === ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -180,7 +180,7 @@ export class BasicCursor extends Cursor { * @param node The current position in the AST. * @return The parent AST node or null if there are no valid parents. */ - private findSiblingOrParent_(node: ASTNode | null): ASTNode | null { + private findSiblingOrParent_(node: ASTNode|null): ASTNode|null { if (!node) { return null; } @@ -197,7 +197,7 @@ export class BasicCursor extends Cursor { * @return The right most child of the given node, or the node if no child * exists. */ - private getRightMostChild_(node: ASTNode | null): ASTNode | null { + private getRightMostChild_(node: ASTNode|null): ASTNode|null { if (!node!.in()) { return node; } @@ -210,4 +210,4 @@ export class BasicCursor extends Cursor { } registry.register( - registry.Type.CURSOR, BasicCursor.registrationName, BasicCursor); + registry.Type.CURSOR, BasicCursor.registrationName, BasicCursor); diff --git a/core/keyboard_nav/cursor.ts b/core/keyboard_nav/cursor.ts index ed46ea683..027531916 100644 --- a/core/keyboard_nav/cursor.ts +++ b/core/keyboard_nav/cursor.ts @@ -18,8 +18,8 @@ import * as registry from '../registry.js'; -import { ASTNode } from './ast_node.js'; -import { Marker } from './marker.js'; +import {ASTNode} from './ast_node.js'; +import {Marker} from './marker.js'; /** * Class for a cursor. @@ -39,7 +39,7 @@ export class Cursor extends Marker { * @return The next element, or null if the current node is not set or there * is no next value. */ - next(): ASTNode | null { + next(): ASTNode|null { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -47,8 +47,8 @@ export class Cursor extends Marker { let newNode = curNode.next(); while (newNode && newNode.next() && - (newNode.getType() === ASTNode.types.NEXT || - newNode.getType() === ASTNode.types.BLOCK)) { + (newNode.getType() === ASTNode.types.NEXT || + newNode.getType() === ASTNode.types.BLOCK)) { newNode = newNode.next(); } @@ -63,15 +63,15 @@ export class Cursor extends Marker { * @return The in element, or null if the current node is not set or there is * no in value. */ - in(): ASTNode | null { - let curNode: ASTNode | null = this.getCurNode(); + in(): ASTNode|null { + let curNode: ASTNode|null = this.getCurNode(); if (!curNode) { return null; } // If we are on a previous or output connection, go to the block level // before performing next operation. if (curNode.getType() === ASTNode.types.PREVIOUS || - curNode.getType() === ASTNode.types.OUTPUT) { + curNode.getType() === ASTNode.types.OUTPUT) { curNode = curNode.next(); } const newNode = curNode?.in() ?? null; @@ -87,7 +87,7 @@ export class Cursor extends Marker { * @return The previous element, or null if the current node is not set or * there is no previous value. */ - prev(): ASTNode | null { + prev(): ASTNode|null { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -95,8 +95,8 @@ export class Cursor extends Marker { let newNode = curNode.prev(); while (newNode && newNode.prev() && - (newNode.getType() === ASTNode.types.NEXT || - newNode.getType() === ASTNode.types.BLOCK)) { + (newNode.getType() === ASTNode.types.NEXT || + newNode.getType() === ASTNode.types.BLOCK)) { newNode = newNode.prev(); } @@ -111,7 +111,7 @@ export class Cursor extends Marker { * @return The out element, or null if the current node is not set or there is * no out value. */ - out(): ASTNode | null { + out(): ASTNode|null { const curNode = this.getCurNode(); if (!curNode) { return null; diff --git a/core/keyboard_nav/marker.ts b/core/keyboard_nav/marker.ts index a246cb839..fb58117d9 100644 --- a/core/keyboard_nav/marker.ts +++ b/core/keyboard_nav/marker.ts @@ -18,9 +18,9 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { MarkerSvg } from '../renderers/common/marker_svg.js'; +import {MarkerSvg} from '../renderers/common/marker_svg.js'; -import { ASTNode } from './ast_node.js'; +import {ASTNode} from './ast_node.js'; /** @@ -30,7 +30,7 @@ import { ASTNode } from './ast_node.js'; */ export class Marker { /** The colour of the marker. */ - colour: string | null = null; + colour: string|null = null; /** The current location of the marker. */ // AnyDuringMigration because: Type 'null' is not assignable to type diff --git a/core/keyboard_nav/tab_navigate_cursor.ts b/core/keyboard_nav/tab_navigate_cursor.ts index dc4c616ec..e1fbfa288 100644 --- a/core/keyboard_nav/tab_navigate_cursor.ts +++ b/core/keyboard_nav/tab_navigate_cursor.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../field.js'; +import {Field} from '../field.js'; -import { ASTNode } from './ast_node.js'; -import { BasicCursor } from './basic_cursor.js'; +import {ASTNode} from './ast_node.js'; +import {BasicCursor} from './basic_cursor.js'; /** @@ -33,13 +33,13 @@ export class TabNavigateCursor extends BasicCursor { * @param node The AST node to check whether it is valid. * @return True if the node should be visited, false otherwise. */ - override validNode_(node: ASTNode | null): boolean { + override validNode_(node: ASTNode|null): boolean { let isValid = false; const type = node && node.getType(); if (node) { const location = node.getLocation() as Field; if (type === ASTNode.types.FIELD && location && - location.isTabNavigable() && location.isClickable()) { + location.isTabNavigable() && location.isClickable()) { isValid = true; } } diff --git a/core/marker_manager.ts b/core/marker_manager.ts index d84a8c89f..2f74ae6d7 100644 --- a/core/marker_manager.ts +++ b/core/marker_manager.ts @@ -12,11 +12,11 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { Cursor } from './keyboard_nav/cursor.js'; +import {Cursor} from './keyboard_nav/cursor.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from './keyboard_nav/marker.js'; +import {Marker} from './keyboard_nav/marker.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -28,14 +28,14 @@ export class MarkerManager { static readonly LOCAL_MARKER = 'local_marker_1'; /** The cursor. */ - private cursor_: Cursor | null = null; + private cursor_: Cursor|null = null; /** The cursor's SVG element. */ - private cursorSvg_: SVGElement | null = null; - private markers_: { [key: string]: Marker }; + private cursorSvg_: SVGElement|null = null; + private markers_: {[key: string]: Marker}; /** The marker's SVG element. */ - private markerSvg_: SVGElement | null = null; + private markerSvg_: SVGElement|null = null; /** @param workspace The workspace for the marker manager. */ constructor(private readonly workspace: WorkspaceSvg) { @@ -53,7 +53,7 @@ export class MarkerManager { this.unregisterMarker(id); } marker.setDrawer( - this.workspace.getRenderer().makeMarkerDrawer(this.workspace, marker)); + this.workspace.getRenderer().makeMarkerDrawer(this.workspace, marker)); this.setMarkerSvg(marker.getDrawer().createDom()); this.markers_[id] = marker; } @@ -69,8 +69,8 @@ export class MarkerManager { delete this.markers_[id]; } else { throw Error( - 'Marker with ID ' + id + ' does not exist. ' + - 'Can only unregister markers that exist.'); + 'Marker with ID ' + id + ' does not exist. ' + + 'Can only unregister markers that exist.'); } } @@ -78,7 +78,7 @@ export class MarkerManager { * Get the cursor for the workspace. * @return The cursor for this workspace. */ - getCursor(): Cursor | null { + getCursor(): Cursor|null { return this.cursor_; } @@ -88,7 +88,7 @@ export class MarkerManager { * @return The marker that corresponds to the given ID, or null if none * exists. */ - getMarker(id: string): Marker | null { + getMarker(id: string): Marker|null { return this.markers_[id] || null; } @@ -104,7 +104,7 @@ export class MarkerManager { this.cursor_ = cursor; if (this.cursor_) { const drawer = this.workspace.getRenderer().makeMarkerDrawer( - this.workspace, this.cursor_); + this.workspace, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); } @@ -115,7 +115,7 @@ export class MarkerManager { * @param cursorSvg The SVG root of the cursor to be added to the workspace * SVG group. */ - setCursorSvg(cursorSvg: SVGElement | null) { + setCursorSvg(cursorSvg: SVGElement|null) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -130,7 +130,7 @@ export class MarkerManager { * @param markerSvg The SVG root of the marker to be added to the workspace * SVG group. */ - setMarkerSvg(markerSvg: SVGElement | null) { + setMarkerSvg(markerSvg: SVGElement|null) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -139,7 +139,7 @@ export class MarkerManager { if (this.workspace.getBlockCanvas()) { if (this.cursorSvg_) { this.workspace.getBlockCanvas()!.insertBefore( - markerSvg, this.cursorSvg_); + markerSvg, this.cursorSvg_); } else { this.workspace.getBlockCanvas()!.appendChild(markerSvg); } diff --git a/core/menu.ts b/core/menu.ts index 0f0d21371..38cd61711 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -14,13 +14,13 @@ import * as browserEvents from './browser_events.js'; /* eslint-disable-next-line no-unused-vars */ -import { MenuItem } from './menuitem.js'; +import {MenuItem} from './menuitem.js'; import * as aria from './utils/aria.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; /* eslint-disable-next-line no-unused-vars */ -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; import * as style from './utils/style.js'; @@ -41,34 +41,34 @@ export class Menu { * prevent the consequent mouseup event due to a simple click from * activating a menu item immediately. */ - openingCoords: Coordinate | null = null; + openingCoords: Coordinate|null = null; /** * This is the element that we will listen to the real focus events on. * A value of null means no menu item is highlighted. */ - private highlightedItem_: MenuItem | null = null; + private highlightedItem_: MenuItem|null = null; /** Mouse over event data. */ - private mouseOverHandler_: browserEvents.Data | null = null; + private mouseOverHandler_: browserEvents.Data|null = null; /** Click event data. */ - private clickHandler_: browserEvents.Data | null = null; + private clickHandler_: browserEvents.Data|null = null; /** Mouse enter event data. */ - private mouseEnterHandler_: browserEvents.Data | null = null; + private mouseEnterHandler_: browserEvents.Data|null = null; /** Mouse leave event data. */ - private mouseLeaveHandler_: browserEvents.Data | null = null; + private mouseLeaveHandler_: browserEvents.Data|null = null; /** Key down event data. */ - private onKeyDownHandler_: browserEvents.Data | null = null; + private onKeyDownHandler_: browserEvents.Data|null = null; /** The menu's root DOM element. */ - private element_: HTMLDivElement | null = null; + private element_: HTMLDivElement|null = null; /** ARIA name for this menu. */ - private roleName_: aria.Role | null = null; + private roleName_: aria.Role|null = null; /** Constructs a new Menu instance. */ constructor() {} @@ -102,15 +102,15 @@ export class Menu { // Add event handlers. this.mouseOverHandler_ = browserEvents.conditionalBind( - element, 'mouseover', this, this.handleMouseOver_, true); + element, 'mouseover', this, this.handleMouseOver_, true); this.clickHandler_ = browserEvents.conditionalBind( - element, 'click', this, this.handleClick_, true); + element, 'click', this, this.handleClick_, true); this.mouseEnterHandler_ = browserEvents.conditionalBind( - element, 'mouseenter', this, this.handleMouseEnter_, true); + element, 'mouseenter', this, this.handleMouseEnter_, true); this.mouseLeaveHandler_ = browserEvents.conditionalBind( - element, 'mouseleave', this, this.handleMouseLeave_, true); + element, 'mouseleave', this, this.handleMouseLeave_, true); this.onKeyDownHandler_ = browserEvents.conditionalBind( - element, 'keydown', this, this.handleKeyEvent_); + element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); } @@ -119,7 +119,7 @@ export class Menu { * Gets the menu's element. * @return The DOM element. */ - getElement(): Element | null { + getElement(): Element|null { return this.element_; } @@ -129,7 +129,7 @@ export class Menu { if (el) { // AnyDuringMigration because: Property 'focus' does not exist on type // 'Element'. - (el as AnyDuringMigration).focus({ preventScroll: true }); + (el as AnyDuringMigration).focus({preventScroll: true}); dom.addClass(el, 'blocklyFocused'); } } @@ -192,7 +192,7 @@ export class Menu { * @param elem DOM element whose owner is to be returned. * @return Menu item for which the DOM element belongs to. */ - private getMenuItem_(elem: Element): MenuItem | null { + private getMenuItem_(elem: Element): MenuItem|null { const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. @@ -220,7 +220,7 @@ export class Menu { * Highlights the given menu item, or clears highlighting if null. * @param item Item to highlight, or null. */ - setHighlighted(item: MenuItem | null) { + setHighlighted(item: MenuItem|null) { const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); @@ -246,7 +246,7 @@ export class Menu { // AnyDuringMigration because: Argument of type 'MenuItem | null' is not // assignable to parameter of type 'MenuItem'. const index = - this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); + this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); this.highlightHelper_(index, 1); } @@ -258,7 +258,7 @@ export class Menu { // AnyDuringMigration because: Argument of type 'MenuItem | null' is not // assignable to parameter of type 'MenuItem'. const index = - this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); + this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); } @@ -325,7 +325,7 @@ export class Menu { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. const newCoords = new Coordinate( - (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); + (e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY); if (Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same @@ -380,8 +380,8 @@ export class Menu { // exist on type 'Event'. AnyDuringMigration because: Property 'shiftKey' // does not exist on type 'Event'. if ((e as AnyDuringMigration).shiftKey || - (e as AnyDuringMigration).ctrlKey || - (e as AnyDuringMigration).metaKey || (e as AnyDuringMigration).altKey) { + (e as AnyDuringMigration).ctrlKey || + (e as AnyDuringMigration).metaKey || (e as AnyDuringMigration).altKey) { // Do not handle the key event if any modifier key is pressed. return; } diff --git a/core/menuitem.ts b/core/menuitem.ts index 091663624..5406d2c34 100644 --- a/core/menuitem.ts +++ b/core/menuitem.ts @@ -26,13 +26,13 @@ export class MenuItem { private enabled_ = true; /** The DOM element for the menu item. */ - private element_: HTMLDivElement | null = null; + private element_: HTMLDivElement|null = null; /** Whether the menu item is rendered right-to-left. */ private rightToLeft_ = false; /** ARIA name for this menu. */ - private roleName_: aria.Role | null = null; + private roleName_: aria.Role|null = null; /** Is this menu item checkable. */ private checkable_ = false; @@ -44,7 +44,7 @@ export class MenuItem { private highlight_ = false; /** Bound function to call when this menu item is clicked. */ - private actionHandler_: Function | null = null; + private actionHandler_: Function|null = null; /** * @param content Text caption to display as the content of the item, or a @@ -52,8 +52,8 @@ export class MenuItem { * @param opt_value Data/model associated with the menu item. */ constructor( - private readonly content: string | HTMLElement, - private readonly opt_value?: string) {} + private readonly content: string|HTMLElement, + private readonly opt_value?: string) {} /** * Creates the menuitem's DOM. @@ -67,12 +67,12 @@ export class MenuItem { // Set class and style // goog-menuitem* is deprecated, use blocklyMenuItem*. May 2020. element.className = 'blocklyMenuItem goog-menuitem ' + - (this.enabled_ ? '' : - 'blocklyMenuItemDisabled goog-menuitem-disabled ') + - (this.checked_ ? 'blocklyMenuItemSelected goog-option-selected ' : '') + - (this.highlight_ ? 'blocklyMenuItemHighlight goog-menuitem-highlight ' : - '') + - (this.rightToLeft_ ? 'blocklyMenuItemRtl goog-menuitem-rtl ' : ''); + (this.enabled_ ? '' : + 'blocklyMenuItemDisabled goog-menuitem-disabled ') + + (this.checked_ ? 'blocklyMenuItemSelected goog-option-selected ' : '') + + (this.highlight_ ? 'blocklyMenuItemHighlight goog-menuitem-highlight ' : + '') + + (this.rightToLeft_ ? 'blocklyMenuItemRtl goog-menuitem-rtl ' : ''); const content = (document.createElement('div')); content.className = 'blocklyMenuItemContent goog-menuitem-content'; @@ -95,8 +95,8 @@ export class MenuItem { aria.setRole(element, this.roleName_); } aria.setState( - element, aria.State.SELECTED, - this.checkable_ && this.checked_ || false); + element, aria.State.SELECTED, + this.checkable_ && this.checked_ || false); aria.setState(element, aria.State.DISABLED, !this.enabled_); return element; @@ -111,7 +111,7 @@ export class MenuItem { * Gets the menu item's element. * @return The DOM element. */ - getElement(): Element | null { + getElement(): Element|null { return this.element_; } diff --git a/core/metrics_manager.ts b/core/metrics_manager.ts index 3a3318ff5..724834386 100644 --- a/core/metrics_manager.ts +++ b/core/metrics_manager.ts @@ -13,18 +13,18 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { IMetricsManager } from './interfaces/i_metrics_manager.js'; +import {IMetricsManager} from './interfaces/i_metrics_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from './interfaces/i_toolbox.js'; +import {IToolbox} from './interfaces/i_toolbox.js'; import * as registry from './registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { Metrics } from './utils/metrics.js'; -import { Size } from './utils/size.js'; +import {Metrics} from './utils/metrics.js'; +import {Size} from './utils/size.js'; import * as toolboxUtils from './utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -42,7 +42,7 @@ export class MetricsManager implements IMetricsManager { * @return An object containing width and height attributes, which will both * be zero if elem did not exist. */ - protected getDimensionsPx_(elem: IToolbox | null | IFlyout): Size { + protected getDimensionsPx_(elem: IToolbox|null|IFlyout): Size { let width = 0; let height = 0; if (elem) { @@ -61,7 +61,7 @@ export class MetricsManager implements IMetricsManager { */ getFlyoutMetrics(opt_own?: boolean): ToolboxMetrics { const flyoutDimensions = - this.getDimensionsPx_(this.workspace.getFlyout(opt_own)); + this.getDimensionsPx_(this.workspace.getFlyout(opt_own)); return { width: flyoutDimensions.width, height: flyoutDimensions.height, @@ -79,7 +79,7 @@ export class MetricsManager implements IMetricsManager { */ getToolboxMetrics(): ToolboxMetrics { const toolboxDimensions = - this.getDimensionsPx_(this.workspace.getToolbox()); + this.getDimensionsPx_(this.workspace.getToolbox()); return { width: toolboxDimensions.width, @@ -110,7 +110,7 @@ export class MetricsManager implements IMetricsManager { const doesToolboxExist = !!this.workspace.getToolbox(); const doesFlyoutExist = !!this.workspace.getFlyout(true); const toolboxPosition = - doesToolboxExist ? toolboxMetrics.position : flyoutMetrics.position; + doesToolboxExist ? toolboxMetrics.position : flyoutMetrics.position; const atLeft = toolboxPosition === toolboxUtils.Position.LEFT; const atTop = toolboxPosition === toolboxUtils.Position.TOP; @@ -147,24 +147,24 @@ export class MetricsManager implements IMetricsManager { const flyoutMetrics = this.getFlyoutMetrics(true); const doesToolboxExist = !!this.workspace.getToolbox(); const toolboxPosition = - doesToolboxExist ? toolboxMetrics.position : flyoutMetrics.position; + doesToolboxExist ? toolboxMetrics.position : flyoutMetrics.position; if (this.workspace.getToolbox()) { if (toolboxPosition === toolboxUtils.Position.TOP || - toolboxPosition === toolboxUtils.Position.BOTTOM) { + toolboxPosition === toolboxUtils.Position.BOTTOM) { svgMetrics.height -= toolboxMetrics.height; } else if ( - toolboxPosition === toolboxUtils.Position.LEFT || - toolboxPosition === toolboxUtils.Position.RIGHT) { + toolboxPosition === toolboxUtils.Position.LEFT || + toolboxPosition === toolboxUtils.Position.RIGHT) { svgMetrics.width -= toolboxMetrics.width; } } else if (this.workspace.getFlyout(true)) { if (toolboxPosition === toolboxUtils.Position.TOP || - toolboxPosition === toolboxUtils.Position.BOTTOM) { + toolboxPosition === toolboxUtils.Position.BOTTOM) { svgMetrics.height -= flyoutMetrics.height; } else if ( - toolboxPosition === toolboxUtils.Position.LEFT || - toolboxPosition === toolboxUtils.Position.RIGHT) { + toolboxPosition === toolboxUtils.Position.LEFT || + toolboxPosition === toolboxUtils.Position.RIGHT) { svgMetrics.width -= flyoutMetrics.width; } } @@ -204,7 +204,7 @@ export class MetricsManager implements IMetricsManager { hasFixedEdges(): boolean { // This exists for optimization of bump logic. return !this.workspace.isMovableHorizontally() || - !this.workspace.isMovableVertically(); + !this.workspace.isMovableVertically(); } /** @@ -215,7 +215,7 @@ export class MetricsManager implements IMetricsManager { * @return The fixed edges of the scroll area. */ protected getComputedFixedEdges_(opt_viewMetrics?: ContainerRegion): - FixedEdges { + FixedEdges { if (!this.hasFixedEdges()) { // Return early if there are no edges. return {}; @@ -245,7 +245,8 @@ export class MetricsManager implements IMetricsManager { * @return The padded content area. */ protected getPaddedContent_( - viewMetrics: ContainerRegion, contentMetrics: ContainerRegion): { top: number, bottom: number, left: number, right: number } { + viewMetrics: ContainerRegion, contentMetrics: ContainerRegion): + {top: number, bottom: number, left: number, right: number} { const contentBottom = contentMetrics.top + contentMetrics.height; const contentRight = contentMetrics.left + contentMetrics.width; @@ -257,15 +258,15 @@ export class MetricsManager implements IMetricsManager { // Add a padding around the content that is at least half a screen wide. // Ensure padding is wide enough that blocks can scroll over entire screen. const top = - Math.min(contentMetrics.top - halfHeight, contentBottom - viewHeight); + Math.min(contentMetrics.top - halfHeight, contentBottom - viewHeight); const left = - Math.min(contentMetrics.left - halfWidth, contentRight - viewWidth); + Math.min(contentMetrics.left - halfWidth, contentRight - viewWidth); const bottom = - Math.max(contentBottom + halfHeight, contentMetrics.top + viewHeight); + Math.max(contentBottom + halfHeight, contentMetrics.top + viewHeight); const right = - Math.max(contentRight + halfWidth, contentMetrics.left + viewWidth); + Math.max(contentRight + halfWidth, contentMetrics.left + viewWidth); - return { top, bottom, left, right }; + return {top, bottom, left, right}; } /** @@ -281,8 +282,8 @@ export class MetricsManager implements IMetricsManager { * @return The metrics for the scroll container. */ getScrollMetrics( - opt_getWorkspaceCoordinates?: boolean, opt_viewMetrics?: ContainerRegion, - opt_contentMetrics?: ContainerRegion): ContainerRegion { + opt_getWorkspaceCoordinates?: boolean, opt_viewMetrics?: ContainerRegion, + opt_contentMetrics?: ContainerRegion): ContainerRegion { const scale = opt_getWorkspaceCoordinates ? this.workspace.scale : 1; const viewMetrics = opt_viewMetrics || this.getViewMetrics(false); const contentMetrics = opt_contentMetrics || this.getContentMetrics(); @@ -293,13 +294,13 @@ export class MetricsManager implements IMetricsManager { // Use combination of fixed bounds and padded content to make scroll area. const top = - fixedEdges.top !== undefined ? fixedEdges.top : paddedContent.top; + fixedEdges.top !== undefined ? fixedEdges.top : paddedContent.top; const left = - fixedEdges.left !== undefined ? fixedEdges.left : paddedContent.left; + fixedEdges.left !== undefined ? fixedEdges.left : paddedContent.left; const bottom = fixedEdges.bottom !== undefined ? fixedEdges.bottom : - paddedContent.bottom; + paddedContent.bottom; const right = - fixedEdges.right !== undefined ? fixedEdges.right : paddedContent.right; + fixedEdges.right !== undefined ? fixedEdges.right : paddedContent.right; return { top: top / scale, @@ -363,7 +364,7 @@ export class MetricsManager implements IMetricsManager { const viewMetrics = this.getViewMetrics(); const contentMetrics = this.getContentMetrics(); const scrollMetrics = - this.getScrollMetrics(false, viewMetrics, contentMetrics); + this.getScrollMetrics(false, viewMetrics, contentMetrics); return { contentHeight: contentMetrics.height, @@ -424,4 +425,4 @@ export interface UiMetrics { } registry.register( - registry.Type.METRICS_MANAGER, registry.DEFAULT, MetricsManager); + registry.Type.METRICS_MANAGER, registry.DEFAULT, MetricsManager); diff --git a/core/msg.ts b/core/msg.ts index adf230317..9eb98c15b 100644 --- a/core/msg.ts +++ b/core/msg.ts @@ -14,4 +14,4 @@ /** A dictionary of localised messages. */ -export const Msg: { [key: string]: string } = Object.create(null); +export const Msg: {[key: string]: string} = Object.create(null); diff --git a/core/mutator.ts b/core/mutator.ts index aaee8b33d..2c3b5fb31 100644 --- a/core/mutator.ts +++ b/core/mutator.ts @@ -20,28 +20,28 @@ import './events/events_bubble_open'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; -import { Bubble } from './bubble.js'; -import { config } from './config.js'; +import {BlocklyOptions} from './blockly_options.js'; +import {Bubble} from './bubble.js'; +import {config} from './config.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from './connection.js'; +import {Connection} from './connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; -import { BlockChange } from './events/events_block_change.js'; +import {Abstract} from './events/events_abstract.js'; +import {BlockChange} from './events/events_block_change.js'; import * as eventUtils from './events/utils.js'; -import { Icon } from './icon.js'; -import { Options } from './options.js'; +import {Icon} from './icon.js'; +import {Options} from './options.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as toolbox from './utils/toolbox.js'; import * as xml from './utils/xml.js'; -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -52,7 +52,7 @@ export class Mutator extends Icon { quarkNames_: AnyDuringMigration; /** Workspace in the mutator's bubble. */ - private workspace_: WorkspaceSvg | null = null; + private workspace_: WorkspaceSvg|null = null; /** Width of workspace. */ private workspaceWidth_ = 0; @@ -64,19 +64,19 @@ export class Mutator extends Icon { * The SVG element that is the parent of the mutator workspace, or null if * not created. */ - private svgDialog_: SVGSVGElement | null = null; + private svgDialog_: SVGSVGElement|null = null; /** * The root block of the mutator workspace, created by decomposing the * source block. */ - private rootBlock_: BlockSvg | null = null; + private rootBlock_: BlockSvg|null = null; /** * Function registered on the main workspace to update the mutator contents * when the main workspace changes. */ - private sourceListener_: Function | null = null; + private sourceListener_: Function|null = null; /** * The PID associated with the updateWorkpace_ timeout, or 0 if no timeout @@ -103,7 +103,7 @@ export class Mutator extends Icon { * @return The workspace inside this mutator icon's bubble or null if the * mutator isn't open. */ - getWorkspace(): WorkspaceSvg | null { + getWorkspace(): WorkspaceSvg|null { return this.workspace_; } @@ -114,31 +114,31 @@ export class Mutator extends Icon { protected override drawIcon_(group: Element) { // Square with rounded corners. dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyIconShape', - 'rx': '4', - 'ry': '4', - 'height': '16', - 'width': '16', - }, - group); + Svg.RECT, { + 'class': 'blocklyIconShape', + 'rx': '4', + 'ry': '4', + 'height': '16', + 'width': '16', + }, + group); // Gear teeth. dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyIconSymbol', - 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + - '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + - '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + - '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + - '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + - '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + - '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z', - }, - group); + Svg.PATH, { + 'class': 'blocklyIconSymbol', + 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + + '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + + '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + + '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + + '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + + '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + + '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z', + }, + group); // Axle hole. dom.createSvgElement( - Svg.CIRCLE, - { 'class': 'blocklyIconShape', 'r': '2.7', 'cx': '8', 'cy': '8' }, group); + Svg.CIRCLE, + {'class': 'blocklyIconShape', 'r': '2.7', 'cx': '8', 'cy': '8'}, group); } /** @@ -163,7 +163,7 @@ export class Mutator extends Icon { */ this.svgDialog_ = dom.createSvgElement( - Svg.SVG, { 'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH }); + Svg.SVG, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}); // Convert the list of names into a list of XML objects for the flyout. let quarkXml; if (this.quarkNames_.length) { @@ -188,7 +188,7 @@ export class Mutator extends Icon { 'rendererOverrides': this.block_.workspace.options.rendererOverrides, } as BlocklyOptions)); workspaceOptions.toolboxPosition = - this.block_.RTL ? toolbox.Position.RIGHT : toolbox.Position.LEFT; + this.block_.RTL ? toolbox.Position.RIGHT : toolbox.Position.LEFT; const hasFlyout = !!quarkXml; if (hasFlyout) { workspaceOptions.languageTree = toolbox.convertToolboxDefToJson(quarkXml); @@ -224,7 +224,7 @@ export class Mutator extends Icon { if (this.block_.isEditable()) { if (this.iconGroup_) { dom.removeClass( - this.iconGroup_ as Element, 'blocklyIconGroupReadonly'); + this.iconGroup_ as Element, 'blocklyIconGroupReadonly'); } } else { // Close any mutator bubble. Icon is not clickable. @@ -245,7 +245,7 @@ export class Mutator extends Icon { const flyout = this.workspace_!.getFlyout(); if (flyout) { const flyoutScrollMetrics = - flyout.getWorkspace().getMetricsManager().getScrollMetrics(); + flyout.getWorkspace().getMetricsManager().getScrollMetrics(); height = Math.max(height, flyoutScrollMetrics.height + 20); width += flyout.getWidth(); } @@ -256,23 +256,23 @@ export class Mutator extends Icon { // Only resize if the size difference is significant. Eliminates // shuddering. if (Math.abs(this.workspaceWidth_ - width) > doubleBorderWidth || - Math.abs(this.workspaceHeight_ - height) > doubleBorderWidth) { + Math.abs(this.workspaceHeight_ - height) > doubleBorderWidth) { // Record some layout information for workspace metrics. this.workspaceWidth_ = width; this.workspaceHeight_ = height; // Resize the bubble. this.bubble_!.setBubbleSize( - width + doubleBorderWidth, height + doubleBorderWidth); + width + doubleBorderWidth, height + doubleBorderWidth); // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. this.svgDialog_!.setAttribute( - 'width', this.workspaceWidth_ as AnyDuringMigration); + 'width', this.workspaceWidth_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. this.svgDialog_!.setAttribute( - 'height', this.workspaceHeight_ as AnyDuringMigration); + 'height', this.workspaceHeight_ as AnyDuringMigration); this.workspace_!.setCachedParentSvgSize( - this.workspaceWidth_, this.workspaceHeight_); + this.workspaceWidth_, this.workspaceHeight_); } if (this.block_.RTL) { @@ -300,13 +300,13 @@ export class Mutator extends Icon { return; } eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))! - (this.block_, visible, 'mutator')); + (this.block_, visible, 'mutator')); if (visible) { // Create the bubble. this.bubble_ = new Bubble( - (this.block_.workspace as WorkspaceSvg), this.createEditor_(), - this.block_.pathObject.svgPath, (this.iconXY_ as Coordinate), null, - null); + (this.block_.workspace as WorkspaceSvg), this.createEditor_(), + this.block_.pathObject.svgPath, (this.iconXY_ as Coordinate), null, + null); // Expose this mutator's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this)); @@ -457,10 +457,10 @@ export class Mutator extends Icon { const newExtraState = BlockChange.getExtraBlockState_(block); if (oldExtraState !== newExtraState) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!( - block, 'mutation', null, oldExtraState, newExtraState)); + block, 'mutation', null, oldExtraState, newExtraState)); // Ensure that any bump is part of this mutation's event group. const mutationGroup = eventUtils.getGroup(); - setTimeout(function () { + setTimeout(function() { const oldGroup = eventUtils.getGroup(); eventUtils.setGroup(mutationGroup); block.bumpNeighbours(); @@ -511,7 +511,7 @@ export class Mutator extends Icon { * @return True iff a reconnection was made, false otherwise. */ static reconnect( - connectionChild: Connection, block: Block, inputName: string): boolean { + connectionChild: Connection, block: Block, inputName: string): boolean { if (!connectionChild || !connectionChild.getSourceBlock().workspace) { return false; } @@ -519,7 +519,7 @@ export class Mutator extends Icon { const connectionParent = block.getInput(inputName)!.connection; const currentParent = connectionChild.targetBlock(); if ((!currentParent || currentParent === block) && connectionParent && - connectionParent.targetConnection !== connectionChild) { + connectionParent.targetConnection !== connectionChild) { if (connectionParent.isConnected()) { // There's already something connected here. Get rid of it. connectionParent.disconnect(); @@ -536,7 +536,7 @@ export class Mutator extends Icon { * @param workspace The workspace that is inside a mutator. * @return The mutator's parent workspace or null. */ - static findParentWs(workspace: WorkspaceSvg): WorkspaceSvg | null { + static findParentWs(workspace: WorkspaceSvg): WorkspaceSvg|null { let outerWs = null; if (workspace && workspace.options) { const parent = workspace.options.parentWorkspace; diff --git a/core/names.ts b/core/names.ts index 4f1330f03..4d9591f27 100644 --- a/core/names.ts +++ b/core/names.ts @@ -17,13 +17,13 @@ // Unused import preserved for side-effects. Remove if unneeded. import './procedures'; -import { Msg } from './msg.js'; +import {Msg} from './msg.js'; import * as Procedures from './procedures.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableMap } from './variable_map.js'; +import {VariableMap} from './variable_map.js'; import * as Variables from './variables.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -35,13 +35,13 @@ export class Names { static DEVELOPER_VARIABLE_TYPE: AnyDuringMigration; private readonly variablePrefix_: string; private readonly reservedDict_: AnyDuringMigration; - private db_: { [key: string]: { [key: string]: string } }; - private dbReverse_: { [key: string]: boolean }; + private db_: {[key: string]: {[key: string]: string}}; + private dbReverse_: {[key: string]: boolean}; /** * The variable map from the workspace, containing Blockly variable models. */ - private variableMap_: VariableMap | null = null; + private variableMap_: VariableMap|null = null; /** * @param reservedWords A comma-separated string of words that are illegal for @@ -98,14 +98,14 @@ export class Names { * @return The name of the referenced variable, or null if there was no * variable map or the variable was not found in the map. */ - private getNameForUserVariable_(id: string): string | null { + private getNameForUserVariable_(id: string): string|null { if (!this.variableMap_) { console.warn( - 'Deprecated call to Names.prototype.getName without ' + - 'defining a variable map. To fix, add the following code in your ' + - 'generator\'s init() function:\n' + - 'Blockly.YourGeneratorName.nameDB_.setVariableMap(' + - 'workspace.getVariableMap());'); + 'Deprecated call to Names.prototype.getName without ' + + 'defining a variable map. To fix, add the following code in your ' + + 'generator\'s init() function:\n' + + 'Blockly.YourGeneratorName.nameDB_.setVariableMap(' + + 'workspace.getVariableMap());'); return null; } const variable = this.variableMap_.getVariableById(id); @@ -146,7 +146,7 @@ export class Names { * 'DEVELOPER_VARIABLE', etc...). * @return An entity name that is legal in the exported language. */ - getName(nameOrId: string, type: NameType | string): string { + getName(nameOrId: string, type: NameType|string): string { let name = nameOrId; if (type === NameType.VARIABLE) { const varName = this.getNameForUserVariable_(nameOrId); @@ -158,7 +158,7 @@ export class Names { const normalizedName = name.toLowerCase(); const isVar = - type === NameType.VARIABLE || type === NameType.DEVELOPER_VARIABLE; + type === NameType.VARIABLE || type === NameType.DEVELOPER_VARIABLE; const prefix = isVar ? this.variablePrefix_ : ''; if (!(type in this.db_)) { @@ -179,7 +179,7 @@ export class Names { * 'DEVELOPER_VARIABLE', etc...). * @return A list of Blockly entity names (no constraints). */ - getUserNames(type: NameType | string): string[] { + getUserNames(type: NameType|string): string[] { const typeDb = this.db_[type] || {}; return Object.keys(typeDb); } @@ -194,11 +194,11 @@ export class Names { * 'DEVELOPER_VARIABLE', etc...). * @return An entity name that is legal in the exported language. */ - getDistinctName(name: string, type: NameType | string): string { + getDistinctName(name: string, type: NameType|string): string { let safeName = this.safeName_(name); let i = ''; while (this.dbReverse_[safeName + i] || - safeName + i in this.reservedDict_) { + safeName + i in this.reservedDict_) { // Collision with existing name. Create a unique name. // AnyDuringMigration because: Type 'string | 2' is not assignable to // type 'string'. @@ -207,7 +207,7 @@ export class Names { safeName += i; this.dbReverse_[safeName] = true; const isVar = - type === NameType.VARIABLE || type === NameType.DEVELOPER_VARIABLE; + type === NameType.VARIABLE || type === NameType.DEVELOPER_VARIABLE; const prefix = isVar ? this.variablePrefix_ : ''; return prefix + safeName; } diff --git a/core/options.ts b/core/options.ts index 33ef189d3..fe3d48de2 100644 --- a/core/options.ts +++ b/core/options.ts @@ -13,16 +13,16 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; +import {BlocklyOptions} from './blockly_options.js'; import * as registry from './registry.js'; -import { Theme } from './theme.js'; -import { Classic } from './theme/classic.js'; +import {Theme} from './theme.js'; +import {Classic} from './theme/classic.js'; import * as idGenerator from './utils/idgenerator.js'; /* eslint-disable-next-line no-unused-vars */ -import { Metrics } from './utils/metrics.js'; +import {Metrics} from './utils/metrics.js'; import * as toolbox from './utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -38,7 +38,7 @@ export class Options { disable: boolean; readOnly: boolean; maxBlocks: number; - maxInstances: { [key: string]: number } | null; + maxInstances: {[key: string]: number}|null; pathToMedia: string; hasCategories: boolean; moveOptions: MoveOptions; @@ -48,22 +48,22 @@ export class Options { hasSounds: boolean; hasCss: boolean; horizontalLayout: boolean; - languageTree: toolbox.ToolboxInfo | null; + languageTree: toolbox.ToolboxInfo|null; gridOptions: GridOptions; zoomOptions: ZoomOptions; toolboxPosition: toolbox.Position; theme: Theme; renderer: string; - rendererOverrides: AnyDuringMigration | null; + rendererOverrides: AnyDuringMigration|null; /** * The SVG element for the grid pattern. * Created during injection. */ - gridPattern: SVGElement | null = null; - parentWorkspace: WorkspaceSvg | null; + gridPattern: SVGElement|null = null; + parentWorkspace: WorkspaceSvg|null; plugins: { - [key: string]: (new (...p1: AnyDuringMigration[]) => AnyDuringMigration) | + [key: string]: (new(...p1: AnyDuringMigration[]) => AnyDuringMigration)| string }; @@ -74,7 +74,7 @@ export class Options { * argument Contains an x and/or y property which is a float between 0 * 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 @@ -98,7 +98,7 @@ export class Options { const readOnly = !!(options as AnyDuringMigration)['readOnly']; if (!readOnly) { toolboxJsonDef = toolbox.convertToolboxDefToJson( - (options as AnyDuringMigration)['toolbox']); + (options as AnyDuringMigration)['toolbox']); hasCategories = toolbox.hasCategories(toolboxJsonDef); hasTrashcan = (options as AnyDuringMigration)['trashcan']; if (hasTrashcan === undefined) { @@ -123,7 +123,7 @@ export class Options { } let maxTrashcanContents = - (options as AnyDuringMigration)['maxTrashcanContents']; + (options as AnyDuringMigration)['maxTrashcanContents']; if (hasTrashcan) { if (maxTrashcanContents === undefined) { maxTrashcanContents = 32; @@ -142,10 +142,10 @@ export class Options { let toolboxPosition: toolbox.Position; if (horizontalLayout) { toolboxPosition = - toolboxAtStart ? toolbox.Position.TOP : toolbox.Position.BOTTOM; + toolboxAtStart ? toolbox.Position.TOP : toolbox.Position.BOTTOM; } else { toolboxPosition = toolboxAtStart === rtl ? toolbox.Position.RIGHT : - toolbox.Position.LEFT; + toolbox.Position.LEFT; } let hasCss = (options as AnyDuringMigration)['css']; @@ -194,7 +194,7 @@ export class Options { this.theme = Options.parseThemeOptions_(options); this.renderer = renderer; this.rendererOverrides = - (options as AnyDuringMigration)['rendererOverrides']; + (options as AnyDuringMigration)['rendererOverrides']; /** * The parent of the current workspace, or null if there is no parent @@ -215,11 +215,11 @@ export class Options { * @return Normalized move options. */ private static parseMoveOptions_( - options: AnyDuringMigration, hasCategories: boolean): MoveOptions { + options: AnyDuringMigration, hasCategories: boolean): MoveOptions { const move = options['move'] || {}; const moveOptions = {} as MoveOptions; if (move['scrollbars'] === undefined && - options['scrollbars'] === undefined) { + options['scrollbars'] === undefined) { // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars = hasCategories; @@ -230,11 +230,11 @@ export class Options { // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars.horizontal = - !!move['scrollbars']['horizontal']; + !!move['scrollbars']['horizontal']; // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars.vertical = - !!move['scrollbars']['vertical']; + !!move['scrollbars']['vertical']; // Convert scrollbars object to boolean if they have the same value. // This allows us to easily check for whether any scrollbars exist using // !!moveOptions.scrollbars. @@ -242,7 +242,7 @@ export class Options { // type '{}'. AnyDuringMigration because: Property 'scrollbars' does not // exist on type '{}'. if ((moveOptions as AnyDuringMigration).scrollbars.horizontal && - (moveOptions as AnyDuringMigration).scrollbars.vertical) { + (moveOptions as AnyDuringMigration).scrollbars.vertical) { // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars = true; @@ -250,8 +250,8 @@ export class Options { // type '{}'. AnyDuringMigration because: Property 'scrollbars' does // not exist on type '{}'. } else if ( - !(moveOptions as AnyDuringMigration).scrollbars.horizontal && - !(moveOptions as AnyDuringMigration).scrollbars.vertical) { + !(moveOptions as AnyDuringMigration).scrollbars.horizontal && + !(moveOptions as AnyDuringMigration).scrollbars.vertical) { // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars = false; @@ -260,19 +260,19 @@ export class Options { // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. (moveOptions as AnyDuringMigration).scrollbars = - !!move['scrollbars'] || !!options['scrollbars']; + !!move['scrollbars'] || !!options['scrollbars']; } // AnyDuringMigration because: Property 'scrollbars' does not exist on type // '{}'. if (!(moveOptions as AnyDuringMigration).scrollbars || - move['wheel'] === undefined) { + move['wheel'] === undefined) { // Defaults to true if single-direction scroll is enabled. // AnyDuringMigration because: Property 'scrollbars' does not exist on // type '{}'. AnyDuringMigration because: Property 'wheel' does not exist // on type '{}'. (moveOptions as AnyDuringMigration).wheel = - typeof (moveOptions as AnyDuringMigration).scrollbars === 'object'; + typeof (moveOptions as AnyDuringMigration).scrollbars === 'object'; } else { // AnyDuringMigration because: Property 'wheel' does not exist on type // '{}'. @@ -333,7 +333,7 @@ export class Options { // AnyDuringMigration because: Property 'startScale' does not exist on // type '{}'. (zoomOptions as AnyDuringMigration).startScale = - Number(zoom['startScale']); + Number(zoom['startScale']); } if (zoom['maxScale'] === undefined) { // AnyDuringMigration because: Property 'maxScale' does not exist on type @@ -361,7 +361,7 @@ export class Options { // AnyDuringMigration because: Property 'scaleSpeed' does not exist on // type '{}'. (zoomOptions as AnyDuringMigration).scaleSpeed = - Number(zoom['scaleSpeed']); + Number(zoom['scaleSpeed']); } if (zoom['pinch'] === undefined) { // AnyDuringMigration because: Property 'controls' does not exist on type @@ -369,8 +369,8 @@ export class Options { // type '{}'. AnyDuringMigration because: Property 'pinch' does not exist // on type '{}'. (zoomOptions as AnyDuringMigration).pinch = - (zoomOptions as AnyDuringMigration).wheel || - (zoomOptions as AnyDuringMigration).controls; + (zoomOptions as AnyDuringMigration).wheel || + (zoomOptions as AnyDuringMigration).controls; } else { // AnyDuringMigration because: Property 'pinch' does not exist on type // '{}'. @@ -398,12 +398,12 @@ export class Options { // AnyDuringMigration because: Property 'length' does not exist on type // '{}'. (gridOptions as AnyDuringMigration).length = - grid['length'] === undefined ? 1 : Number(grid['length']); + grid['length'] === undefined ? 1 : Number(grid['length']); // AnyDuringMigration because: Property 'spacing' does not exist on type // '{}'. AnyDuringMigration because: Property 'snap' does not exist on type // '{}'. (gridOptions as AnyDuringMigration).snap = - (gridOptions as AnyDuringMigration).spacing > 0 && !!grid['snap']; + (gridOptions as AnyDuringMigration).spacing > 0 && !!grid['snap']; return gridOptions; } @@ -421,7 +421,7 @@ export class Options { return theme; } return Theme.defineTheme( - theme.name || 'builtin' + idGenerator.getNextUniqueId(), theme); + theme.name || 'builtin' + idGenerator.getNextUniqueId(), theme); } } export interface GridOptions { @@ -432,7 +432,7 @@ export interface GridOptions { } export interface MoveOptions { drag: boolean; - scrollbars: boolean | ScrollbarOptions; + scrollbars: boolean|ScrollbarOptions; wheel: boolean; } export interface ScrollbarOptions { diff --git a/core/positionable_helpers.ts b/core/positionable_helpers.ts index c75fd53b6..dfc7ce648 100644 --- a/core/positionable_helpers.ts +++ b/core/positionable_helpers.ts @@ -15,14 +15,14 @@ // Unused import preserved for side-effects. Remove if unneeded. import './metrics_manager'; -import { UiMetrics } from './metrics_manager.js'; -import { Scrollbar } from './scrollbar.js'; -import { Rect } from './utils/rect.js'; +import {UiMetrics} from './metrics_manager.js'; +import {Scrollbar} from './scrollbar.js'; +import {Rect} from './utils/rect.js'; /* eslint-disable-next-line no-unused-vars */ -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; import * as toolbox from './utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -76,13 +76,13 @@ export enum bumpDirection { * @alias Blockly.uiPosition.getStartPositionRect */ export function getStartPositionRect( - position: Position, size: Size, horizontalPadding: number, - verticalPadding: number, metrics: UiMetrics, - workspace: WorkspaceSvg): Rect { + position: Position, size: Size, horizontalPadding: number, + verticalPadding: number, metrics: UiMetrics, + workspace: WorkspaceSvg): Rect { // Horizontal positioning. let left = 0; const hasVerticalScrollbar = - workspace.scrollbar && workspace.scrollbar.canScrollVertically(); + workspace.scrollbar && workspace.scrollbar.canScrollVertically(); if (position.horizontal === horizontalPosition.LEFT) { left = metrics.absoluteMetrics.left + horizontalPadding; if (hasVerticalScrollbar && workspace.RTL) { @@ -91,7 +91,7 @@ export function getStartPositionRect( } else { // position.horizontal === horizontalPosition.RIGHT left = metrics.absoluteMetrics.left + metrics.viewMetrics.width - - size.width - horizontalPadding; + size.width - horizontalPadding; if (hasVerticalScrollbar && !workspace.RTL) { left -= Scrollbar.scrollbarThickness; } @@ -103,7 +103,7 @@ export function getStartPositionRect( } else { // position.vertical === verticalPosition.BOTTOM top = metrics.absoluteMetrics.top + metrics.viewMetrics.height - - size.height - verticalPadding; + size.height - verticalPadding; if (workspace.scrollbar && workspace.scrollbar.canScrollHorizontally()) { // The scrollbars are always positioned on the bottom if they exist. top -= Scrollbar.scrollbarThickness; @@ -123,15 +123,15 @@ export function getStartPositionRect( * @alias Blockly.uiPosition.getCornerOppositeToolbox */ export function getCornerOppositeToolbox( - workspace: WorkspaceSvg, metrics: UiMetrics): Position { + workspace: WorkspaceSvg, metrics: UiMetrics): Position { const leftCorner = - metrics.toolboxMetrics.position !== toolbox.Position.LEFT && - (!workspace.horizontalLayout || workspace.RTL); + metrics.toolboxMetrics.position !== toolbox.Position.LEFT && + (!workspace.horizontalLayout || workspace.RTL); const topCorner = metrics.toolboxMetrics.position === toolbox.Position.BOTTOM; const hPosition = - leftCorner ? horizontalPosition.LEFT : horizontalPosition.RIGHT; + leftCorner ? horizontalPosition.LEFT : horizontalPosition.RIGHT; const vPosition = topCorner ? verticalPosition.TOP : verticalPosition.BOTTOM; - return { horizontal: hPosition, vertical: vPosition }; + return {horizontal: hPosition, vertical: vPosition}; } /** @@ -148,8 +148,8 @@ export function getCornerOppositeToolbox( * @alias Blockly.uiPosition.bumpPositionRect */ export function bumpPositionRect( - startRect: Rect, margin: number, bumpDir: bumpDirection, - savedPositions: Rect[]): Rect { + startRect: Rect, margin: number, bumpDir: bumpDirection, + savedPositions: Rect[]): Rect { let top = startRect.top; const left = startRect.left; const width = startRect.right - startRect.left; diff --git a/core/procedures.ts b/core/procedures.ts index 365881b70..0d12b8902 100644 --- a/core/procedures.ts +++ b/core/procedures.ts @@ -15,24 +15,24 @@ import './events/events_block_change'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; -import { Blocks } from './blocks.js'; +import {BlockSvg} from './block_svg.js'; +import {Blocks} from './blocks.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; +import {Abstract} from './events/events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { BubbleOpen } from './events/events_bubble_open.js'; +import {BubbleOpen} from './events/events_bubble_open.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; -import { Msg } from './msg.js'; -import { Names } from './names.js'; +import {Field} from './field.js'; +import {Msg} from './msg.js'; +import {Names} from './names.js'; import * as utilsXml from './utils/xml.js'; import * as Variables from './variables.js'; -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; @@ -72,14 +72,14 @@ export interface ProcedureBlock { */ export function allProcedures(root: Workspace): AnyDuringMigration[][][] { const proceduresNoReturn = - root.getBlocksByType('procedures_defnoreturn', false) - .map(function (block) { + root.getBlocksByType('procedures_defnoreturn', false) + .map(function(block) { + return (block as unknown as ProcedureBlock).getProcedureDef(); + }); + const proceduresReturn = + root.getBlocksByType('procedures_defreturn', false).map(function(block) { return (block as unknown as ProcedureBlock).getProcedureDef(); }); - const proceduresReturn = - root.getBlocksByType('procedures_defreturn', false).map(function (block) { - return (block as unknown as ProcedureBlock).getProcedureDef(); - }); proceduresNoReturn.sort(procTupleComparator); proceduresReturn.sort(procTupleComparator); return [proceduresNoReturn, proceduresReturn]; @@ -93,8 +93,8 @@ export function allProcedures(root: Workspace): AnyDuringMigration[][][] { * @return -1, 0, or 1 to signify greater than, equality, or less than. */ function procTupleComparator( - ta: AnyDuringMigration[], tb: AnyDuringMigration[]): number { - return ta[0].localeCompare(tb[0], undefined, { sensitivity: 'base' }); + ta: AnyDuringMigration[], tb: AnyDuringMigration[]): number { + return ta[0].localeCompare(tb[0], undefined, {sensitivity: 'base'}); } /** @@ -133,7 +133,7 @@ export function findLegalName(name: string, block: Block): string { * @return True if the name is legal. */ function isLegalName( - name: string, workspace: Workspace, opt_exclude?: Block): boolean { + name: string, workspace: Workspace, opt_exclude?: Block): boolean { return !isNameUsed(name, workspace, opt_exclude); } @@ -147,7 +147,7 @@ function isLegalName( * @alias Blockly.Procedures.isNameUsed */ export function isNameUsed( - name: string, workspace: Workspace, opt_exclude?: Block): boolean { + name: string, workspace: Workspace, opt_exclude?: Block): boolean { const blocks = workspace.getAllBlocks(false); // Iterate through every block and check the name. for (let i = 0; i < blocks.length; i++) { @@ -212,7 +212,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { const nameField = utilsXml.createElement('field'); nameField.setAttribute('name', 'NAME'); nameField.appendChild( - utilsXml.createTextNode(Msg['PROCEDURES_DEFNORETURN_PROCEDURE'])); + utilsXml.createTextNode(Msg['PROCEDURES_DEFNORETURN_PROCEDURE'])); block.appendChild(nameField); xmlList.push(block); } @@ -228,7 +228,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { const nameField = utilsXml.createElement('field'); nameField.setAttribute('name', 'NAME'); nameField.appendChild( - utilsXml.createTextNode(Msg['PROCEDURES_DEFRETURN_PROCEDURE'])); + utilsXml.createTextNode(Msg['PROCEDURES_DEFRETURN_PROCEDURE'])); block.appendChild(nameField); xmlList.push(block); } @@ -255,7 +255,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { * @param templateName The type of the block to generate. */ function populateProcedures( - procedureList: AnyDuringMigration[][], templateName: string) { + procedureList: AnyDuringMigration[][], templateName: string) { for (let i = 0; i < procedureList.length; i++) { const name = procedureList[i][0]; const args = procedureList[i][1]; @@ -308,7 +308,7 @@ function updateMutatorFlyout(workspace: WorkspaceSvg) { const nameField = utilsXml.createElement('field'); nameField.setAttribute('name', 'NAME'); const argValue = - Variables.generateUniqueNameFromOptions(DEFAULT_ARG, usedNames); + Variables.generateUniqueNameFromOptions(DEFAULT_ARG, usedNames); const fieldContent = utilsXml.createTextNode(argValue); nameField.appendChild(fieldContent); @@ -330,12 +330,12 @@ export function mutatorOpenListener(e: Abstract) { } const bubbleEvent = e as BubbleOpen; if (!(bubbleEvent.bubbleType === 'mutator' && bubbleEvent.isOpen) || - !bubbleEvent.blockId) { + !bubbleEvent.blockId) { return; } const workspaceId = (bubbleEvent.workspaceId); const block = Workspace.getById(workspaceId)!.getBlockById( - bubbleEvent.blockId) as BlockSvg; + bubbleEvent.blockId) as BlockSvg; const type = block.type; if (type !== 'procedures_defnoreturn' && type !== 'procedures_defreturn') { return; @@ -351,8 +351,8 @@ export function mutatorOpenListener(e: Abstract) { */ function mutatorChangeListener(e: Abstract) { if (e.type !== eventUtils.BLOCK_CREATE && - e.type !== eventUtils.BLOCK_DELETE && - e.type !== eventUtils.BLOCK_CHANGE) { + e.type !== eventUtils.BLOCK_DELETE && + e.type !== eventUtils.BLOCK_CHANGE) { return; } const workspaceId = e.workspaceId as string; @@ -411,7 +411,7 @@ export function mutateCallers(defBlock: Block) { // definition mutation. eventUtils.setRecordUndo(false); eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))! - (caller, 'mutation', null, oldMutation, newMutation)); + (caller, 'mutation', null, oldMutation, newMutation)); eventUtils.setRecordUndo(oldRecordUndo); } } @@ -424,7 +424,7 @@ export function mutateCallers(defBlock: Block) { * @return The procedure definition block, or null not found. * @alias Blockly.Procedures.getDefinition */ -export function getDefinition(name: string, workspace: Workspace): Block | null { +export function getDefinition(name: string, workspace: Workspace): Block|null { // Do not assume procedure is a top block. Some languages allow nested // procedures. Also do not assume it is one of the built-in blocks. Only // rely on getProcedureDef. diff --git a/core/registry.ts b/core/registry.ts index 9aabc4208..8b9df288c 100644 --- a/core/registry.ts +++ b/core/registry.ts @@ -17,31 +17,31 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; +import {Abstract} from './events/events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; +import {Field} from './field.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBlockDragger } from './interfaces/i_block_dragger.js'; +import {IBlockDragger} from './interfaces/i_block_dragger.js'; /* eslint-disable-next-line no-unused-vars */ -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { IMetricsManager } from './interfaces/i_metrics_manager.js'; +import {IMetricsManager} from './interfaces/i_metrics_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { ISerializer } from './interfaces/i_serializer.js'; +import {ISerializer} from './interfaces/i_serializer.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from './interfaces/i_toolbox.js'; +import {IToolbox} from './interfaces/i_toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { Cursor } from './keyboard_nav/cursor.js'; +import {Cursor} from './keyboard_nav/cursor.js'; /* eslint-disable-next-line no-unused-vars */ -import { Options } from './options.js'; +import {Options} from './options.js'; /* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderers/common/renderer.js'; +import {Renderer} from './renderers/common/renderer.js'; /* eslint-disable-next-line no-unused-vars */ -import { Theme } from './theme.js'; +import {Theme} from './theme.js'; /* eslint-disable-next-line no-unused-vars */ -import { ToolboxItem } from './toolbox/toolbox_item.js'; +import {ToolboxItem} from './toolbox/toolbox_item.js'; /** @@ -51,16 +51,16 @@ import { ToolboxItem } from './toolbox/toolbox_item.js'; */ const typeMap: { [key: string]: - { [key: string]: (new () => AnyDuringMigration) | AnyDuringMigration } + {[key: string]: (new () => AnyDuringMigration)|AnyDuringMigration} } = Object.create(null); -export const TEST_ONLY = { typeMap }; +export const TEST_ONLY = {typeMap}; /** * A map of maps. With the keys being the type and caseless name of the class we * are registring, and the value being the most recent cased name for that * registration. */ -const nameMap: { [key: string]: { [key: string]: string } } = Object.create(null); +const nameMap: {[key: string]: {[key: string]: string}} = Object.create(null); /** * The string used to register the default class for a type of plugin. @@ -73,20 +73,20 @@ export const DEFAULT = 'default'; * @alias Blockly.registry.Type */ export class Type { - static CONNECTION_CHECKER = new Type < IConnectionChecker > ('connectionChecker'); - static CURSOR = new Type < Cursor > ('cursor'); - static EVENT = new Type < Abstract > ('event'); - static FIELD = new Type < Field > ('field'); - static RENDERER = new Type < Renderer > ('renderer'); - static TOOLBOX = new Type < IToolbox > ('toolbox'); - static THEME = new Type < Theme > ('theme'); - static TOOLBOX_ITEM = new Type < ToolboxItem > ('toolboxItem'); - static FLYOUTS_VERTICAL_TOOLBOX = new Type < IFlyout > ('flyoutsVerticalToolbox'); + static CONNECTION_CHECKER = new Type('connectionChecker'); + static CURSOR = new Type('cursor'); + static EVENT = new Type('event'); + static FIELD = new Type('field'); + static RENDERER = new Type('renderer'); + static TOOLBOX = new Type('toolbox'); + static THEME = new Type('theme'); + static TOOLBOX_ITEM = new Type('toolboxItem'); + static FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); static FLYOUTS_HORIZONTAL_TOOLBOX = - new Type < IFlyout > ('flyoutsHorizontalToolbox'); - static METRICS_MANAGER = new Type < IMetricsManager > ('metricsManager'); - static BLOCK_DRAGGER = new Type < IBlockDragger > ('blockDragger'); - static SERIALIZER = new Type < ISerializer > ('serializer'); + new Type('flyoutsHorizontalToolbox'); + static METRICS_MANAGER = new Type('metricsManager'); + static BLOCK_DRAGGER = new Type('blockDragger'); + static SERIALIZER = new Type('serializer'); /** @param name The name of the registry type. */ constructor(private readonly name: string) {} @@ -141,22 +141,22 @@ export class Type { * @alias Blockly.registry.register */ export function register( - type: string | Type, name: string, - registryItem: (new (...p1: AnyDuringMigration[]) => T) | null | + type: string|Type, name: string, + registryItem: (new (...p1: AnyDuringMigration[]) => T)|null| AnyDuringMigration, - opt_allowOverrides?: boolean): void { + opt_allowOverrides?: boolean): void { if (!(type instanceof Type) && typeof type !== 'string' || - String(type).trim() === '') { + String(type).trim() === '') { throw Error( - 'Invalid type "' + type + '". The type must be a' + - ' non-empty string or a Blockly.registry.Type.'); + 'Invalid type "' + type + '". The type must be a' + + ' non-empty string or a Blockly.registry.Type.'); } type = String(type).toLowerCase(); if (typeof name !== 'string' || name.trim() === '') { throw Error( - 'Invalid name "' + name + '". The name must be a' + - ' non-empty string.'); + 'Invalid name "' + name + '". The name must be a' + + ' non-empty string.'); } const caselessName = name.toLowerCase(); if (!registryItem) { @@ -176,8 +176,8 @@ export function register( // Don't throw an error if opt_allowOverrides is true. if (!opt_allowOverrides && typeRegistry[caselessName]) { throw Error( - 'Name "' + caselessName + '" with type "' + type + - '" already registered.'); + 'Name "' + caselessName + '" with type "' + type + + '" already registered.'); } typeRegistry[caselessName] = registryItem; nameRegistry[caselessName] = name; @@ -190,7 +190,7 @@ export function register( * @param registryItem A class or object that we are checking for the required * properties. */ -function validate(type: string, registryItem: Function | AnyDuringMigration) { +function validate(type: string, registryItem: Function|AnyDuringMigration) { switch (type) { case String(Type.FIELD): if (typeof registryItem.fromJson !== 'function') { @@ -207,14 +207,14 @@ function validate(type: string, registryItem: Function | AnyDuringMigration) { * @param name The plugin's name. (Ex. field_angle, geras) * @alias Blockly.registry.unregister */ -export function unregister(type: string | Type, name: string) { +export function unregister(type: string|Type, name: string) { type = String(type).toLowerCase(); name = name.toLowerCase(); const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { console.warn( - 'Unable to unregister [' + name + '][' + type + '] from the ' + - 'registry.'); + 'Unable to unregister [' + name + '][' + type + '] from the ' + + 'registry.'); return; } delete typeMap[type][name]; @@ -233,8 +233,8 @@ export function unregister(type: string | Type, name: string) { * exists. */ function getItem( - type: string | Type, name: string, opt_throwIfMissing?: boolean): - (new (...p1: AnyDuringMigration[]) => T) | null | AnyDuringMigration { + type: string|Type, name: string, opt_throwIfMissing?: boolean): + (new (...p1: AnyDuringMigration[]) => T)|null|AnyDuringMigration { type = String(type).toLowerCase(); name = name.toLowerCase(); const typeRegistry = typeMap[type]; @@ -242,7 +242,7 @@ function getItem( const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { throw new Error( - msg + ' You must require or register a ' + type + ' plugin.'); + msg + ' You must require or register a ' + type + ' plugin.'); } else { console.warn(msg); } @@ -261,7 +261,7 @@ function getItem( * otherwise. * @alias Blockly.registry.hasItem */ -export function hasItem(type: string | Type, name: string): boolean { +export function hasItem(type: string|Type, name: string): boolean { type = String(type).toLowerCase(); name = name.toLowerCase(); const typeRegistry = typeMap[type]; @@ -282,11 +282,11 @@ export function hasItem(type: string | Type, name: string): boolean { * @alias Blockly.registry.getClass */ export function getClass( - type: string | Type, name: string, opt_throwIfMissing?: boolean): - (new (...p1: AnyDuringMigration[]) => T) | null { + type: string|Type, name: string, opt_throwIfMissing?: boolean): + (new (...p1: AnyDuringMigration[]) => T)|null { return getItem(type, name, opt_throwIfMissing) as ( - new (...p1: AnyDuringMigration[]) => T) | - null; + new (...p1: AnyDuringMigration[]) => T) | + null; } /** @@ -300,7 +300,7 @@ export function getClass( * @alias Blockly.registry.getObject */ export function getObject( - type: string | Type, name: string, opt_throwIfMissing?: boolean): T | null { + type: string|Type, name: string, opt_throwIfMissing?: boolean): T|null { return getItem(type, name, opt_throwIfMissing) as T; } @@ -315,7 +315,8 @@ export function getObject( * @alias Blockly.registry.getAllItems */ export function getAllItems( - type: string | Type, opt_cased: boolean, opt_throwIfMissing?: boolean): { [key: string]: T | null | (new (...p1: AnyDuringMigration[]) => T) } | null { + type: string|Type, opt_cased: boolean, opt_throwIfMissing?: boolean): + {[key: string]: T|null|(new (...p1: AnyDuringMigration[]) => T)}|null { type = String(type).toLowerCase(); const typeRegistry = typeMap[type]; if (!typeRegistry) { @@ -351,8 +352,8 @@ export function getAllItems( * @alias Blockly.registry.getClassFromOptions */ export function getClassFromOptions( - type: Type, options: Options, opt_throwIfMissing?: boolean): - (new (...p1: AnyDuringMigration[]) => T) | null { + type: Type, options: Options, opt_throwIfMissing?: boolean): + (new (...p1: AnyDuringMigration[]) => T)|null { const typeName = type.toString(); const plugin = options.plugins[typeName] || DEFAULT; diff --git a/core/rendered_connection.ts b/core/rendered_connection.ts index 8c8f80839..00e1f1fe3 100644 --- a/core/rendered_connection.ts +++ b/core/rendered_connection.ts @@ -13,20 +13,20 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as common from './common.js'; -import { config } from './config.js'; -import { Connection } from './connection.js'; +import {config} from './config.js'; +import {Connection} from './connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConnectionDB } from './connection_db.js'; -import { ConnectionType } from './connection_type.js'; +import {ConnectionDB} from './connection_db.js'; +import {ConnectionType} from './connection_type.js'; import * as eventUtils from './events/utils.js'; import * as internalConstants from './internal_constants.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; import * as svgPaths from './utils/svg_paths.js'; @@ -75,7 +75,7 @@ export class RenderedConnection extends Connection { private trackedState_: TrackedState; /** Connection this connection connects to. Null if not connected. */ - override targetConnection: RenderedConnection | null = null; + override targetConnection: RenderedConnection|null = null; /** * @param source The block establishing this connection. @@ -95,8 +95,8 @@ export class RenderedConnection extends Connection { * current workspace. */ this.dbOpposite_ = - source.workspace - .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; + source.workspace + .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; /** Workspace units, (0, 0) is top left of block. */ this.offsetInBlock_ = new Coordinate(0, 0); @@ -128,7 +128,7 @@ export class RenderedConnection extends Connection { * Returns the block that this connection connects to. * @return The connected block or null if none is connected. */ - override targetBlock(): BlockSvg | null { + override targetBlock(): BlockSvg|null { return super.targetBlock() as BlockSvg; } @@ -176,16 +176,16 @@ export class RenderedConnection extends Connection { const selected = common.getSelected() == rootBlock; selected || rootBlock.addSelect(); let dx = staticConnection.x + config.snapRadius + - Math.floor(Math.random() * BUMP_RANDOMNESS) - this.x; + Math.floor(Math.random() * BUMP_RANDOMNESS) - this.x; let dy = staticConnection.y + config.snapRadius + - Math.floor(Math.random() * BUMP_RANDOMNESS) - this.y; + Math.floor(Math.random() * BUMP_RANDOMNESS) - this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. dy = -dy; } if (rootBlock.RTL) { dx = staticConnection.x - config.snapRadius - - Math.floor(Math.random() * BUMP_RANDOMNESS) - this.x; + Math.floor(Math.random() * BUMP_RANDOMNESS) - this.x; } rootBlock.moveBy(dx, dy); selected || rootBlock.removeSelect(); @@ -225,7 +225,7 @@ export class RenderedConnection extends Connection { */ moveToOffset(blockTL: Coordinate) { this.moveTo( - blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); + blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); } /** @@ -261,7 +261,7 @@ export class RenderedConnection extends Connection { // Workspace coordinates. const xy = svgMath.getRelativeXY(svgRoot); block!.getSvgRoot().setAttribute( - 'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); + 'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block!.moveConnections(-dx, -dy); } } @@ -275,7 +275,8 @@ export class RenderedConnection extends Connection { * @return Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ - closest(maxLimit: number, dxy: Coordinate): { connection: RenderedConnection | null, radius: number } { + closest(maxLimit: number, dxy: Coordinate): + {connection: RenderedConnection|null, radius: number} { return this.dbOpposite_.searchForClosest(this, maxLimit, dxy); } @@ -284,22 +285,22 @@ export class RenderedConnection extends Connection { let steps; const sourceBlockSvg = (this.sourceBlock_); const renderConstants = - sourceBlockSvg.workspace.getRenderer().getConstants(); + sourceBlockSvg.workspace.getRenderer().getConstants(); const shape = renderConstants.shapeFor(this); if (this.type === ConnectionType.INPUT_VALUE || - this.type === ConnectionType.OUTPUT_VALUE) { + this.type === ConnectionType.OUTPUT_VALUE) { // Vertical line, puzzle tab, vertical line. const yLen = renderConstants.TAB_OFFSET_FROM_TOP; steps = svgPaths.moveBy(0, -yLen) + svgPaths.lineOnAxis('v', yLen) + - (shape as unknown as PathDownShape).pathDown + - svgPaths.lineOnAxis('v', yLen); + (shape as unknown as PathDownShape).pathDown + + svgPaths.lineOnAxis('v', yLen); } else { const xLen = - renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; + renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. steps = svgPaths.moveBy(-xLen, 0) + svgPaths.lineOnAxis('h', xLen) + - (shape as unknown as PathLeftShape).pathLeft + - svgPaths.lineOnAxis('h', xLen); + (shape as unknown as PathLeftShape).pathLeft + + svgPaths.lineOnAxis('h', xLen); } const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const x = this.x - xy.x; @@ -307,13 +308,13 @@ export class RenderedConnection extends Connection { // AnyDuringMigration because: Property 'highlightedPath_' does not exist // on type 'typeof Connection'. (Connection as AnyDuringMigration).highlightedPath_ = dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyHighlightedConnectionPath', - 'd': steps, - 'transform': 'translate(' + x + ',' + y + ')' + - (this.sourceBlock_.RTL ? ' scale(-1 1)' : ''), - }, - this.sourceBlock_.getSvgRoot()); + Svg.PATH, { + 'class': 'blocklyHighlightedConnectionPath', + 'd': steps, + 'transform': 'translate(' + x + ',' + y + ')' + + (this.sourceBlock_.RTL ? ' scale(-1 1)' : ''), + }, + this.sourceBlock_.getSvgRoot()); } /** Remove the highlighting around this connection. */ @@ -332,9 +333,9 @@ export class RenderedConnection extends Connection { */ setTracking(doTracking: boolean) { if (doTracking && - this.trackedState_ === RenderedConnection.TrackedState.TRACKED || - !doTracking && - this.trackedState_ === RenderedConnection.TrackedState.UNTRACKED) { + this.trackedState_ === RenderedConnection.TrackedState.TRACKED || + !doTracking && + this.trackedState_ === RenderedConnection.TrackedState.UNTRACKED) { return; } if (this.sourceBlock_.isInFlyout) { @@ -393,7 +394,7 @@ export class RenderedConnection extends Connection { // we only need to render the leaf nodes. let renderList: AnyDuringMigration[] = []; if (this.type !== ConnectionType.INPUT_VALUE && - this.type !== ConnectionType.NEXT_STATEMENT) { + this.type !== ConnectionType.NEXT_STATEMENT) { // Only spider down. return renderList; } @@ -432,7 +433,7 @@ export class RenderedConnection extends Connection { const block = this.getSourceBlock(); if (eventUtils.getRecordUndo()) { const group = eventUtils.getGroup(); - setTimeout(function (this: RenderedConnection) { + setTimeout(function(this: RenderedConnection) { if (!block.isDisposed() && !block.getParent()) { eventUtils.setGroup(group); this.bumpAwayFrom(otherConnection as RenderedConnection); @@ -448,7 +449,7 @@ export class RenderedConnection extends Connection { * @param childBlock The inferior block. */ protected override disconnectInternal_( - parentBlock: Block, childBlock: Block) { + parentBlock: Block, childBlock: Block) { super.disconnectInternal_(parentBlock, childBlock); const renderedParent = parentBlock as BlockSvg; const renderedChild = childBlock as BlockSvg; @@ -518,7 +519,7 @@ export class RenderedConnection extends Connection { } if (parentRendered && childRendered) { if (parentConnection.type === ConnectionType.NEXT_STATEMENT || - parentConnection.type === ConnectionType.PREVIOUS_STATEMENT) { + parentConnection.type === ConnectionType.PREVIOUS_STATEMENT) { // Child block may need to square off its corners if it is in a stack. // Rendering a child will render its parent. childBlock.render(); @@ -543,9 +544,9 @@ export class RenderedConnection extends Connection { protected override onCheckChanged_() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && - (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child!.unplug(); // Bump away. diff --git a/core/renderers/common/block_rendering.ts b/core/renderers/common/block_rendering.ts index 14bdf81de..f89100690 100644 --- a/core/renderers/common/block_rendering.ts +++ b/core/renderers/common/block_rendering.ts @@ -14,41 +14,40 @@ import * as registry from '../../registry.js'; /* eslint-disable-next-line no-unused-vars */ -import { Theme } from '../../theme.js'; +import {Theme} from '../../theme.js'; import * as deprecation from '../../utils/deprecation.js'; +import {Measurable} from '../measurables/base.js'; +import {BottomRow} from '../measurables/bottom_row.js'; +import {Connection} from '../measurables/connection.js'; +import {ExternalValueInput} from '../measurables/external_value_input.js'; +import {Field} from '../measurables/field.js'; +import {Hat} from '../measurables/hat.js'; +import {Icon} from '../measurables/icon.js'; +import {InRowSpacer} from '../measurables/in_row_spacer.js'; +import {InlineInput} from '../measurables/inline_input.js'; +import {InputConnection} from '../measurables/input_connection.js'; +import {InputRow} from '../measurables/input_row.js'; +import {JaggedEdge} from '../measurables/jagged_edge.js'; +import {NextConnection} from '../measurables/next_connection.js'; +import {OutputConnection} from '../measurables/output_connection.js'; +import {PreviousConnection} from '../measurables/previous_connection.js'; +import {RoundCorner} from '../measurables/round_corner.js'; +import {Row} from '../measurables/row.js'; +import {SpacerRow} from '../measurables/spacer_row.js'; +import {SquareCorner} from '../measurables/square_corner.js'; +import {StatementInput} from '../measurables/statement_input.js'; +import {TopRow} from '../measurables/top_row.js'; +import {Types} from '../measurables/types.js'; -import { Measurable } from '../measurables/base.js'; -import { BottomRow } from '../measurables/bottom_row.js'; -import { Connection } from '../measurables/connection.js'; -import { ExternalValueInput } from '../measurables/external_value_input.js'; -import { Field } from '../measurables/field.js'; -import { Hat } from '../measurables/hat.js'; -import { Icon } from '../measurables/icon.js'; -import { InRowSpacer } from '../measurables/in_row_spacer.js'; -import { InlineInput } from '../measurables/inline_input.js'; -import { InputConnection } from '../measurables/input_connection.js'; -import { InputRow } from '../measurables/input_row.js'; -import { JaggedEdge } from '../measurables/jagged_edge.js'; -import { NextConnection } from '../measurables/next_connection.js'; -import { OutputConnection } from '../measurables/output_connection.js'; -import { PreviousConnection } from '../measurables/previous_connection.js'; -import { RoundCorner } from '../measurables/round_corner.js'; -import { Row } from '../measurables/row.js'; -import { SpacerRow } from '../measurables/spacer_row.js'; -import { SquareCorner } from '../measurables/square_corner.js'; -import { StatementInput } from '../measurables/statement_input.js'; -import { TopRow } from '../measurables/top_row.js'; -import { Types } from '../measurables/types.js'; - -import { ConstantProvider } from './constants.js'; +import {ConstantProvider} from './constants.js'; import * as debug from './debug.js'; -import { Debug } from './debugger.js'; -import { Drawer } from './drawer.js'; -import { IPathObject } from './i_path_object.js'; -import { RenderInfo } from './info.js'; -import { MarkerSvg } from './marker_svg.js'; -import { PathObject } from './path_object.js'; -import { Renderer } from './renderer.js'; +import {Debug} from './debugger.js'; +import {Drawer} from './drawer.js'; +import {IPathObject} from './i_path_object.js'; +import {RenderInfo} from './info.js'; +import {MarkerSvg} from './marker_svg.js'; +import {PathObject} from './path_object.js'; +import {Renderer} from './renderer.js'; /** * Returns whether the debugger is turned on. @@ -58,9 +57,9 @@ import { Renderer } from './renderer.js'; */ export function isDebuggerEnabled(): boolean { deprecation.warn( - 'Blockly.blockRendering.isDebuggerEnabled()', 'September 2021', - 'September 2022', - 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); + 'Blockly.blockRendering.isDebuggerEnabled()', 'September 2021', + 'September 2022', + 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); return debug.isDebuggerEnabled(); } @@ -90,9 +89,9 @@ export function unregister(name: string) { */ export function startDebugger() { deprecation.warn( - 'Blockly.blockRendering.startDebugger()', 'September 2021', - 'September 2022', - 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); + 'Blockly.blockRendering.startDebugger()', 'September 2021', + 'September 2022', + 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); debug.startDebugger(); } @@ -103,9 +102,9 @@ export function startDebugger() { */ export function stopDebugger() { deprecation.warn( - 'Blockly.blockRendering.stopDebugger()', 'September 2021', - 'September 2022', - 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); + 'Blockly.blockRendering.stopDebugger()', 'September 2021', + 'September 2022', + 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); debug.stopDebugger(); } @@ -119,39 +118,39 @@ export function stopDebugger() { * @alias Blockly.blockRendering.init */ export function init( - name: string, theme: Theme, opt_rendererOverrides?: object): Renderer { + name: string, theme: Theme, opt_rendererOverrides?: object): Renderer { const rendererClass = registry.getClass(registry.Type.RENDERER, name); const renderer = new rendererClass!(name); renderer.init(theme, opt_rendererOverrides); return renderer; } -export { BottomRow }; -export { Connection }; -export { ConstantProvider }; -export { Debug }; -export { Drawer }; -export { ExternalValueInput }; -export { Field }; -export { Hat }; -export { Icon }; -export { InRowSpacer }; -export { InlineInput }; -export { InputConnection }; -export { InputRow }; -export { IPathObject }; -export { JaggedEdge }; -export { MarkerSvg }; -export { Measurable }; -export { NextConnection }; -export { OutputConnection }; -export { PathObject }; -export { PreviousConnection }; -export { Renderer }; -export { RenderInfo }; -export { RoundCorner }; -export { Row }; -export { SpacerRow }; -export { SquareCorner }; -export { StatementInput }; -export { TopRow }; -export { Types }; +export {BottomRow}; +export {Connection}; +export {ConstantProvider}; +export {Debug}; +export {Drawer}; +export {ExternalValueInput}; +export {Field}; +export {Hat}; +export {Icon}; +export {InRowSpacer}; +export {InlineInput}; +export {InputConnection}; +export {InputRow}; +export {IPathObject}; +export {JaggedEdge}; +export {MarkerSvg}; +export {Measurable}; +export {NextConnection}; +export {OutputConnection}; +export {PathObject}; +export {PreviousConnection}; +export {Renderer}; +export {RenderInfo}; +export {RoundCorner}; +export {Row}; +export {SpacerRow}; +export {SquareCorner}; +export {StatementInput}; +export {TopRow}; +export {Types}; diff --git a/core/renderers/common/constants.ts b/core/renderers/common/constants.ts index a59f25eab..9297c04e3 100644 --- a/core/renderers/common/constants.ts +++ b/core/renderers/common/constants.ts @@ -11,14 +11,14 @@ * An object that provides constants for rendering blocks. * @class */ -import { ConnectionType } from '../../connection_type.js'; +import {ConnectionType} from '../../connection_type.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; -import { BlockStyle, Theme } from '../../theme.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +import {BlockStyle, Theme} from '../../theme.js'; import * as colour from '../../utils/colour.js'; import * as dom from '../../utils/dom.js'; import * as parsing from '../../utils/parsing.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; import * as userAgent from '../../utils/useragent.js'; @@ -60,8 +60,8 @@ export interface PuzzleTab { type: number; width: number; height: number; - pathDown: string | ((p1: number) => string); - pathUp: string | ((p1: number) => string); + pathDown: string|((p1: number) => string); + pathUp: string|((p1: number) => string); } /** @@ -75,15 +75,11 @@ export interface JaggedTeeth { } export type BaseShape = { - type: number; - width: number; - height: number; + type: number; width: number; height: number; }; export type DynamicShape = { - type: number; - width: (p1: number) => number; - height: (p1: number) => number; + type: number; width: (p1: number) => number; height: (p1: number) => number; isDynamic: true; connectionOffsetY: (p1: number) => number; connectionOffsetX: (p1: number) => number; @@ -94,7 +90,7 @@ export type DynamicShape = { }; /** An object containing sizing and type information about a shape. */ -export type Shape = BaseShape | DynamicShape; +export type Shape = BaseShape|DynamicShape; /** An object containing sizing and type information about a dynamic shape. */ // export interface DynamicShape { @@ -290,7 +286,7 @@ export class ConstantProvider { * The defs tag that contains all filters and patterns for this Blockly * instance. */ - private defs_: SVGElement | null = null; + private defs_: SVGElement|null = null; /** * The ID of the emboss filter, or the empty string if no filter is set. @@ -367,7 +363,7 @@ export class ConstantProvider { INSERTION_MARKER_OPACITY = 0.2; /** Enum for connection shapes. */ - SHAPES = { PUZZLE: 1, NOTCH: 2 }; + SHAPES = {PUZZLE: 1, NOTCH: 2}; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. JAGGED_TEETH!: JaggedTeeth; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. @@ -381,7 +377,7 @@ export class ConstantProvider { // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. OUTSIDE_CORNERS!: OutsideCorners; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - blockStyles!: { [key: string]: BlockStyle }; + blockStyles!: {[key: string]: BlockStyle}; constructor() { /** @@ -441,17 +437,17 @@ export class ConstantProvider { /** A dropdown field's SVG arrow datauri. */ this.FIELD_DROPDOWN_SVG_ARROW_DATAURI = - 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + - 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + - 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + - 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + - 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + - 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + - 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + - 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + - 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + - 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + - 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; + 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + + 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + + 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + + 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + + 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + + 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + + 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + + 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + + 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + + 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + + 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; /** A colour field's default height. */ this.FIELD_COLOUR_DEFAULT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT; @@ -523,7 +519,7 @@ export class ConstantProvider { this.setComponentConstants_(theme); this.ADD_START_HATS = - theme.startHats !== null ? theme.startHats : this.ADD_START_HATS; + theme.startHats !== null ? theme.startHats : this.ADD_START_HATS; } /** @@ -544,8 +540,8 @@ export class ConstantProvider { } const fontMetrics = dom.measureFontMetrics( - 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, - this.FIELD_TEXT_FONTFAMILY); + 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, + this.FIELD_TEXT_FONTFAMILY); this.FIELD_TEXT_HEIGHT = fontMetrics.height; this.FIELD_TEXT_BASELINE = fontMetrics.baseline; @@ -557,15 +553,15 @@ export class ConstantProvider { */ protected setComponentConstants_(theme: Theme) { this.CURSOR_COLOUR = - theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR; + theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR; this.MARKER_COLOUR = - theme.getComponentStyle('markerColour') || this.MARKER_COLOUR; + theme.getComponentStyle('markerColour') || this.MARKER_COLOUR; this.INSERTION_MARKER_COLOUR = - theme.getComponentStyle('insertionMarkerColour') || - this.INSERTION_MARKER_COLOUR; + theme.getComponentStyle('insertionMarkerColour') || + this.INSERTION_MARKER_COLOUR; this.INSERTION_MARKER_OPACITY = - Number(theme.getComponentStyle('insertionMarkerOpacity')) || - this.INSERTION_MARKER_OPACITY; + Number(theme.getComponentStyle('insertionMarkerOpacity')) || + this.INSERTION_MARKER_OPACITY; } /** @@ -575,12 +571,12 @@ export class ConstantProvider { * @return An object containing the style and an autogenerated name for that * style. */ - getBlockStyleForColour(colour: string): { style: BlockStyle, name: string } { + getBlockStyleForColour(colour: string): {style: BlockStyle, name: string} { const name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } - return { style: this.blockStyles[name], name }; + return {style: this.blockStyles[name], name}; } /** @@ -589,11 +585,11 @@ export class ConstantProvider { * @return The named block style, or a default style if no style with the * given name was found. */ - getBlockStyle(blockStyleName: string | null): BlockStyle { + getBlockStyle(blockStyleName: string|null): BlockStyle { return this.blockStyles[blockStyleName || ''] || - (blockStyleName && blockStyleName.indexOf('auto_') === 0 ? - this.getBlockStyleForColour(blockStyleName.substring(5)).style : - this.createBlockStyle_('#000000')); + (blockStyleName && blockStyleName.indexOf('auto_') === 0 ? + this.getBlockStyleForColour(blockStyleName.substring(5)).style : + this.createBlockStyle_('#000000')); } /** @@ -602,7 +598,7 @@ export class ConstantProvider { * @return A populated block style based on the given colour. */ protected createBlockStyle_(colour: string): BlockStyle { - return this.validatedBlockStyle_({ 'colourPrimary': colour }); + return this.validatedBlockStyle_({'colourPrimary': colour}); } /** @@ -624,14 +620,14 @@ export class ConstantProvider { } // Validate required properties. const parsedColour = - parsing.parseBlockColour(valid['colourPrimary'] || '#000'); + parsing.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? - parsing.parseBlockColour(valid['colourSecondary']).hex : - this.generateSecondaryColour_(valid.colourPrimary); + parsing.parseBlockColour(valid['colourSecondary']).hex : + this.generateSecondaryColour_(valid.colourPrimary); valid.colourTertiary = valid['colourTertiary'] ? - parsing.parseBlockColour(valid['colourTertiary']).hex : - this.generateTertiaryColour_(valid.colourPrimary); + parsing.parseBlockColour(valid['colourTertiary']).hex : + this.generateTertiaryColour_(valid.colourPrimary); valid.hat = valid['hat'] || ''; return valid; @@ -687,7 +683,7 @@ export class ConstantProvider { svgPaths.point(-width * 2, height / 2), svgPaths.point(width, height / 4), ]); - return { height, width, path: mainPath }; + return {height, width, path: mainPath}; } /** @@ -702,7 +698,7 @@ export class ConstantProvider { svgPaths.point(70, -height), svgPaths.point(width, 0), ]); - return { height, width, path: mainPath }; + return {height, width, path: mainPath}; } /** @@ -737,14 +733,14 @@ export class ConstantProvider { const endPoint2 = svgPaths.point(width, forward * halfHeight); return svgPaths.curve( - 'c', - [ - svgPaths.point(0, forward * control1Y), - svgPaths.point(-width, back * control2Y), - endPoint1, - ]) + - svgPaths.curve( - 's', [svgPaths.point(width, back * control3Y), endPoint2]); + 'c', + [ + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), + endPoint1, + ]) + + svgPaths.curve( + 's', [svgPaths.point(width, back * control3Y), endPoint2]); } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 @@ -803,10 +799,10 @@ export class ConstantProvider { const radius = this.CORNER_RADIUS; const innerTopLeftCorner = - svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); const innerBottomLeftCorner = - svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { width: radius, @@ -824,19 +820,19 @@ export class ConstantProvider { const radius = this.CORNER_RADIUS; /** SVG path for drawing the rounded top-left corner. */ const topLeft = svgPaths.moveBy(0, radius) + - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** SVG path for drawing the rounded top-right corner. */ const topRight = - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** SVG path for drawing the rounded bottom-left corner. */ const bottomLeft = - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** SVG path for drawing the rounded bottom-right corner. */ const bottomRight = - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { topLeft, @@ -900,44 +896,44 @@ export class ConstantProvider { // AnyDuringMigration because: Argument of type 'SVGElement | null' is not // assignable to parameter of type 'Element | undefined'. const embossFilter = dom.createSvgElement( - Svg.FILTER, { 'id': 'blocklyEmbossFilter' + this.randomIdentifier }, - this.defs_ as AnyDuringMigration); + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, + this.defs_ as AnyDuringMigration); dom.createSvgElement( - Svg.FEGAUSSIANBLUR, - { 'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur' }, - embossFilter); + Svg.FEGAUSSIANBLUR, + {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, + embossFilter); const feSpecularLighting = dom.createSvgElement( - Svg.FESPECULARLIGHTING, { - 'in': 'blur', - 'surfaceScale': 1, - 'specularConstant': 0.5, - 'specularExponent': 10, - 'lighting-color': 'white', - 'result': 'specOut', - }, - embossFilter); + Svg.FESPECULARLIGHTING, { + 'in': 'blur', + 'surfaceScale': 1, + 'specularConstant': 0.5, + 'specularExponent': 10, + 'lighting-color': 'white', + 'result': 'specOut', + }, + embossFilter); dom.createSvgElement( - Svg.FEPOINTLIGHT, { 'x': -5000, 'y': -10000, 'z': 20000 }, - feSpecularLighting); + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, + feSpecularLighting); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'specOut', - 'in2': 'SourceAlpha', - 'operator': 'in', - 'result': 'specOut', - }, - embossFilter); + Svg.FECOMPOSITE, { + 'in': 'specOut', + 'in2': 'SourceAlpha', + 'operator': 'in', + 'result': 'specOut', + }, + embossFilter); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'SourceGraphic', - 'in2': 'specOut', - 'operator': 'arithmetic', - 'k1': 0, - 'k2': 1, - 'k3': 1, - 'k4': 0, - }, - embossFilter); + Svg.FECOMPOSITE, { + 'in': 'SourceGraphic', + 'in2': 'specOut', + 'operator': 'arithmetic', + 'k1': 0, + 'k2': 1, + 'k3': 1, + 'k4': 0, + }, + embossFilter); this.embossFilterId = embossFilter.id; this.embossFilter_ = embossFilter; @@ -951,18 +947,18 @@ export class ConstantProvider { // AnyDuringMigration because: Argument of type 'SVGElement | null' is not // assignable to parameter of type 'Element | undefined'. const disabledPattern = dom.createSvgElement( - Svg.PATTERN, { - 'id': 'blocklyDisabledPattern' + this.randomIdentifier, - 'patternUnits': 'userSpaceOnUse', - 'width': 10, - 'height': 10, - }, - this.defs_ as AnyDuringMigration); + Svg.PATTERN, { + 'id': 'blocklyDisabledPattern' + this.randomIdentifier, + 'patternUnits': 'userSpaceOnUse', + 'width': 10, + 'height': 10, + }, + this.defs_ as AnyDuringMigration); dom.createSvgElement( - Svg.RECT, { 'width': 10, 'height': 10, 'fill': '#aaa' }, disabledPattern); + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( - Svg.PATH, { 'd': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0' }, - disabledPattern); + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, + disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -979,37 +975,37 @@ export class ConstantProvider { // AnyDuringMigration because: Argument of type 'SVGElement | null' is // not assignable to parameter of type 'Element | undefined'. const debugFilter = dom.createSvgElement( - Svg.FILTER, { - 'id': 'blocklyDebugFilter' + this.randomIdentifier, - 'height': '160%', - 'width': '180%', - 'y': '-30%', - 'x': '-40%', - }, - this.defs_ as AnyDuringMigration); + Svg.FILTER, { + 'id': 'blocklyDebugFilter' + this.randomIdentifier, + 'height': '160%', + 'width': '180%', + 'y': '-30%', + 'x': '-40%', + }, + this.defs_ as AnyDuringMigration); // Set all gaussian blur pixels to 1 opacity before applying flood const debugComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, { 'result': 'outBlur' }, debugFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( - Svg.FEFUNCA, - { 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' }, - debugComponentTransfer); + Svg.FEFUNCA, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, + debugComponentTransfer); // Color the highlight dom.createSvgElement( - Svg.FEFLOOD, { - 'flood-color': '#ff0000', - 'flood-opacity': 0.5, - 'result': 'outColor', - }, - debugFilter); + Svg.FEFLOOD, { + 'flood-color': '#ff0000', + 'flood-opacity': 0.5, + 'result': 'outColor', + }, + debugFilter); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'outColor', - 'in2': 'outBlur', - 'operator': 'in', - 'result': 'outGlow', - }, - debugFilter); + Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow', + }, + debugFilter); this.debugFilterId = debugFilter.id; this.debugFilter_ = debugFilter; } diff --git a/core/renderers/common/debug.ts b/core/renderers/common/debug.ts index 5fa8cf556..c4b4fa385 100644 --- a/core/renderers/common/debug.ts +++ b/core/renderers/common/debug.ts @@ -34,9 +34,9 @@ export function isDebuggerEnabled(): boolean { */ export function startDebugger() { deprecation.warn( - 'Blockly.blockRendering.debug.startDebugger()', 'February 2022', - 'September 2022', - 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); + 'Blockly.blockRendering.debug.startDebugger()', 'February 2022', + 'September 2022', + 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); useDebugger = true; } @@ -48,8 +48,8 @@ export function startDebugger() { */ export function stopDebugger() { deprecation.warn( - 'Blockly.blockRendering.debug.stopDebugger()', 'February 2022', - 'September 2022', - 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); + 'Blockly.blockRendering.debug.stopDebugger()', 'February 2022', + 'September 2022', + 'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'); useDebugger = false; } diff --git a/core/renderers/common/debugger.ts b/core/renderers/common/debugger.ts index 842ed55ee..d240f8012 100644 --- a/core/renderers/common/debugger.ts +++ b/core/renderers/common/debugger.ts @@ -14,30 +14,29 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { ConnectionType } from '../../connection_type.js'; -import { FieldLabel } from '../../field_label.js'; +import {BlockSvg} from '../../block_svg.js'; +import {ConnectionType} from '../../connection_type.js'; +import {FieldLabel} from '../../field_label.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Measurable} from '../measurables/base.js'; +import {Field} from '../measurables/field.js'; +/* eslint-disable-next-line no-unused-vars */ +import {InRowSpacer} from '../measurables/in_row_spacer.js'; +import {InputConnection} from '../measurables/input_connection.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Row} from '../measurables/row.js'; +import {Types} from '../measurables/types.js'; +/* eslint-disable-next-line no-unused-vars */ +import {RenderInfo as ZelosInfo} from '../zelos/info.js'; /* eslint-disable-next-line no-unused-vars */ -import { Measurable } from '../measurables/base.js'; -import { Field } from '../measurables/field.js'; +import {ConstantProvider} from './constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { InRowSpacer } from '../measurables/in_row_spacer.js'; -import { InputConnection } from '../measurables/input_connection.js'; -/* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; -import { Types } from '../measurables/types.js'; -/* eslint-disable-next-line no-unused-vars */ -import { RenderInfo as ZelosInfo } from '../zelos/info.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; -/* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /** @@ -105,18 +104,18 @@ export class Debug { } this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'rowSpacerRect blockRenderDebug', - 'x': isRtl ? -(row.xPos + row.width) : row.xPos, - 'y': cursorY, - 'width': row.width, - 'height': height, - 'stroke': isNegativeSpacing ? 'black' : 'blue', - 'fill': 'blue', - 'fill-opacity': '0.5', - 'stroke-width': '1px', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'rowSpacerRect blockRenderDebug', + 'x': isRtl ? -(row.xPos + row.width) : row.xPos, + 'y': cursorY, + 'width': row.width, + 'height': height, + 'stroke': isNegativeSpacing ? 'black' : 'blue', + 'fill': 'blue', + 'fill-opacity': '0.5', + 'stroke-width': '1px', + }, + this.svgRoot_)); } /** @@ -138,18 +137,18 @@ export class Debug { } const yPos = elem.centerline - elem.height / 2; this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'elemSpacerRect blockRenderDebug', - 'x': xPos, - 'y': yPos, - 'width': width, - 'height': elem.height, - 'stroke': 'pink', - 'fill': isNegativeSpacing ? 'black' : 'pink', - 'fill-opacity': '0.5', - 'stroke-width': '1px', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'elemSpacerRect blockRenderDebug', + 'x': xPos, + 'y': yPos, + 'width': width, + 'height': elem.height, + 'stroke': 'pink', + 'fill': isNegativeSpacing ? 'black' : 'pink', + 'fill-opacity': '0.5', + 'stroke-width': '1px', + }, + this.svgRoot_)); } /** @@ -165,39 +164,39 @@ export class Debug { } const yPos = elem.centerline - elem.height / 2; this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'rowRenderingRect blockRenderDebug', - 'x': xPos, - 'y': yPos, - 'width': elem.width, - 'height': elem.height, - 'stroke': 'black', - 'fill': 'none', - 'stroke-width': '1px', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'rowRenderingRect blockRenderDebug', + 'x': xPos, + 'y': yPos, + 'width': elem.width, + 'height': elem.height, + 'stroke': 'black', + 'fill': 'none', + 'stroke-width': '1px', + }, + this.svgRoot_)); if (Types.isField(elem) && elem instanceof Field && - elem.field instanceof FieldLabel) { + elem.field instanceof FieldLabel) { const baseline = this.constants.FIELD_TEXT_BASELINE; this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'rowRenderingRect blockRenderDebug', - 'x': xPos, - 'y': yPos + baseline, - 'width': elem.width, - 'height': '0.1px', - 'stroke': 'red', - 'fill': 'none', - 'stroke-width': '0.5px', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'rowRenderingRect blockRenderDebug', + 'x': xPos, + 'y': yPos + baseline, + 'width': elem.width, + 'height': '0.1px', + 'stroke': 'red', + 'fill': 'none', + 'stroke-width': '0.5px', + }, + this.svgRoot_)); } } if (Types.isInput(elem) && elem instanceof InputConnection && - Debug.config.connections) { + Debug.config.connections) { this.drawConnection(elem.connectionModel); } } @@ -240,15 +239,15 @@ export class Debug { // because: Property 'offsetInBlock_' is private and only accessible within // class 'RenderedConnection'. this.debugElements_.push(dom.createSvgElement( - Svg.CIRCLE, { - 'class': 'blockRenderDebug', - 'cx': (conn as AnyDuringMigration).offsetInBlock_.x, - 'cy': (conn as AnyDuringMigration).offsetInBlock_.y, - 'r': size, - 'fill': fill, - 'stroke': colour, - }, - this.svgRoot_)); + Svg.CIRCLE, { + 'class': 'blockRenderDebug', + 'cx': (conn as AnyDuringMigration).offsetInBlock_.x, + 'cy': (conn as AnyDuringMigration).offsetInBlock_.y, + 'r': size, + 'fill': fill, + 'stroke': colour, + }, + this.svgRoot_)); } /** @@ -262,17 +261,17 @@ export class Debug { return; } this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'elemRenderingRect blockRenderDebug', - 'x': isRtl ? -(row.xPos + row.width) : row.xPos, - 'y': row.yPos, - 'width': row.width, - 'height': row.height, - 'stroke': 'red', - 'fill': 'none', - 'stroke-width': '1px', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'elemRenderingRect blockRenderDebug', + 'x': isRtl ? -(row.xPos + row.width) : row.xPos, + 'y': row.yPos, + 'width': row.width, + 'height': row.height, + 'stroke': 'red', + 'fill': 'none', + 'stroke-width': '1px', + }, + this.svgRoot_)); // AnyDuringMigration because: Property 'isTopOrBottomRow' does not exist // on type 'typeof Types'. @@ -282,18 +281,18 @@ export class Debug { if (Debug.config.connectedBlockBounds) { this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'connectedBlockWidth blockRenderDebug', - 'x': isRtl ? -(row.xPos + row.widthWithConnectedBlocks) : row.xPos, - 'y': row.yPos, - 'width': row.widthWithConnectedBlocks, - 'height': row.height, - 'stroke': this.randomColour_, - 'fill': 'none', - 'stroke-width': '1px', - 'stroke-dasharray': '3,3', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'connectedBlockWidth blockRenderDebug', + 'x': isRtl ? -(row.xPos + row.widthWithConnectedBlocks) : row.xPos, + 'y': row.yPos, + 'width': row.widthWithConnectedBlocks, + 'height': row.height, + 'stroke': this.randomColour_, + 'fill': 'none', + 'stroke-width': '1px', + 'stroke-dasharray': '3,3', + }, + this.svgRoot_)); } } @@ -331,35 +330,35 @@ export class Debug { let xPos = info.RTL ? -info.width : 0; const yPos = 0; this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'blockBoundingBox blockRenderDebug', - 'x': xPos, - 'y': yPos, - 'width': info.width, - 'height': info.height, - 'stroke': 'black', - 'fill': 'none', - 'stroke-width': '1px', - 'stroke-dasharray': '5,5', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'blockBoundingBox blockRenderDebug', + 'x': xPos, + 'y': yPos, + 'width': info.width, + 'height': info.height, + 'stroke': 'black', + 'fill': 'none', + 'stroke-width': '1px', + 'stroke-dasharray': '5,5', + }, + this.svgRoot_)); if (Debug.config.connectedBlockBounds) { // Bounding box with children. xPos = info.RTL ? -info.widthWithChildren : 0; this.debugElements_.push(dom.createSvgElement( - Svg.RECT, { - 'class': 'blockRenderDebug', - 'x': xPos, - 'y': yPos, - 'width': info.widthWithChildren, - 'height': info.height, - 'stroke': '#DF57BC', - 'fill': 'none', - 'stroke-width': '1px', - 'stroke-dasharray': '3,3', - }, - this.svgRoot_)); + Svg.RECT, { + 'class': 'blockRenderDebug', + 'x': xPos, + 'y': yPos, + 'width': info.widthWithChildren, + 'height': info.height, + 'stroke': '#DF57BC', + 'fill': 'none', + 'stroke-width': '1px', + 'stroke-dasharray': '3,3', + }, + this.svgRoot_)); } } @@ -373,7 +372,7 @@ export class Debug { this.svgRoot_ = block.getSvgRoot(); this.randomColour_ = - '#' + Math.floor(Math.random() * 16777215).toString(16); + '#' + Math.floor(Math.random() * 16777215).toString(16); let cursorY = 0; for (let i = 0; i < info.rows.length; i++) { @@ -418,8 +417,8 @@ export class Debug { return; } svgPath.setAttribute( - 'filter', 'url(#' + this.constants.debugFilterId + ')'); - setTimeout(function () { + 'filter', 'url(#' + this.constants.debugFilterId + ')'); + setTimeout(function() { svgPath.setAttribute('filter', ''); }, 100); } diff --git a/core/renderers/common/drawer.ts b/core/renderers/common/drawer.ts index 29b176fe7..8c174688a 100644 --- a/core/renderers/common/drawer.ts +++ b/core/renderers/common/drawer.ts @@ -13,29 +13,28 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; - -import { Connection } from '../measurables/connection.js'; +import {Connection} from '../measurables/connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ExternalValueInput } from '../measurables/external_value_input.js'; +import {ExternalValueInput} from '../measurables/external_value_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../measurables/field.js'; +import {Field} from '../measurables/field.js'; /* eslint-disable-next-line no-unused-vars */ -import { Icon } from '../measurables/icon.js'; +import {Icon} from '../measurables/icon.js'; /* eslint-disable-next-line no-unused-vars */ -import { InlineInput } from '../measurables/inline_input.js'; +import {InlineInput} from '../measurables/inline_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { PreviousConnection } from '../measurables/previous_connection.js'; +import {PreviousConnection} from '../measurables/previous_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; -import { Types } from '../measurables/types.js'; +import {Row} from '../measurables/row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider, Notch, PuzzleTab } from './constants.js'; +import {ConstantProvider, Notch, PuzzleTab} from './constants.js'; import * as debug from './debug.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /** @@ -143,9 +142,9 @@ export class Drawer { } else if (Types.isRightRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight; } else if ( - Types.isPreviousConnection(elem) && elem instanceof Connection) { + Types.isPreviousConnection(elem) && elem instanceof Connection) { this.outlinePath_ += - ((elem as PreviousConnection).shape as Notch).pathLeft; + ((elem as PreviousConnection).shape as Notch).pathLeft; // AnyDuringMigration because: Property 'isHat' does not exist on type // 'typeof Types'. } else if ((Types as AnyDuringMigration).isHat(elem)) { @@ -165,7 +164,7 @@ export class Drawer { protected drawJaggedEdge_(row: Row) { const remainder = row.height - this.constants_.JAGGED_TEETH.height; this.outlinePath_ += - this.constants_.JAGGED_TEETH.path + svgPaths.lineOnAxis('v', remainder); + this.constants_.JAGGED_TEETH.path + svgPaths.lineOnAxis('v', remainder); } /** @@ -182,14 +181,14 @@ export class Drawer { // on type 'Shape'. AnyDuringMigration because: Property 'pathDown' does // not exist on type 'Shape'. const pathDown = - typeof (input.shape as AnyDuringMigration).pathDown === 'function' ? + typeof (input.shape as AnyDuringMigration).pathDown === 'function' ? ((input.shape as AnyDuringMigration).pathDown as (p1: number) => - AnyDuringMigration)(input.height) : + AnyDuringMigration)(input.height) : (input.shape as AnyDuringMigration).pathDown; this.outlinePath_ += svgPaths.lineOnAxis('H', input.xPos + input.width) + - pathDown + - svgPaths.lineOnAxis('v', row.height - input.connectionHeight); + pathDown + + svgPaths.lineOnAxis('v', row.height - input.connectionHeight); } /** @@ -202,16 +201,16 @@ export class Drawer { const x = input.xPos + input.notchOffset + (input.shape as Notch).width; const innerTopLeftCorner = (input.shape as Notch).pathRight + - svgPaths.lineOnAxis( - 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + - this.constants_.INSIDE_CORNERS.pathTop; + svgPaths.lineOnAxis( + 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + + this.constants_.INSIDE_CORNERS.pathTop; const innerHeight = row.height - 2 * this.constants_.INSIDE_CORNERS.height; this.outlinePath_ += svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + - svgPaths.lineOnAxis('v', innerHeight) + - this.constants_.INSIDE_CORNERS.pathBottom + - svgPaths.lineOnAxis('H', row.xPos + row.width); + svgPaths.lineOnAxis('v', innerHeight) + + this.constants_.INSIDE_CORNERS.pathBottom + + svgPaths.lineOnAxis('H', row.xPos + row.width); this.positionStatementInputConnection_(row); } @@ -252,7 +251,7 @@ export class Drawer { } this.outlinePath_ += - svgPaths.lineOnAxis('V', bottomRow.baseline - rightCornerYOffset); + svgPaths.lineOnAxis('V', bottomRow.baseline - rightCornerYOffset); this.outlinePath_ += outlinePath; } @@ -266,11 +265,11 @@ export class Drawer { if (outputConnection) { const tabBottom = - outputConnection.connectionOffsetY + outputConnection.height; + outputConnection.connectionOffsetY + outputConnection.height; const pathUp = typeof outputConnection.shape.pathUp === 'function' ? - (outputConnection.shape.pathUp as (p1: number) => - AnyDuringMigration)(outputConnection.height) : - outputConnection.shape.pathUp; + (outputConnection.shape.pathUp as (p1: number) => + AnyDuringMigration)(outputConnection.height) : + outputConnection.shape.pathUp; // Draw a line up to the bottom of the tab. this.outlinePath_ += svgPaths.lineOnAxis('V', tabBottom) + pathUp; @@ -300,7 +299,7 @@ export class Drawer { * Push a field or icon's new position to its SVG root. * @param fieldInfo The rendering information for the field or icon. */ - protected layoutField_(fieldInfo: Icon | Field) { + protected layoutField_(fieldInfo: Icon|Field) { let svgGroup; if (Types.isField(fieldInfo)) { // AnyDuringMigration because: Property 'field' does not exist on type @@ -327,13 +326,13 @@ export class Drawer { if (Types.isIcon(fieldInfo)) { svgGroup.setAttribute('display', 'block'); svgGroup.setAttribute( - 'transform', 'translate(' + xPos + ',' + yPos + ')'); + 'transform', 'translate(' + xPos + ',' + yPos + ')'); // AnyDuringMigration because: Property 'icon' does not exist on type // 'Icon | Field'. (fieldInfo as AnyDuringMigration).icon.computeIconLocation(); } else { svgGroup.setAttribute( - 'transform', 'translate(' + xPos + ',' + yPos + ')' + scale); + 'transform', 'translate(' + xPos + ',' + yPos + ')' + scale); } if (this.info_.isInsertionMarker) { @@ -357,11 +356,11 @@ export class Drawer { const connectionRight = input.xPos + input.connectionWidth; this.inlinePath_ += svgPaths.moveTo(connectionRight, yPos) + - svgPaths.lineOnAxis('v', connectionTop) + - (input.shape as PuzzleTab).pathDown + - svgPaths.lineOnAxis('v', height - connectionBottom) + - svgPaths.lineOnAxis('h', width - input.connectionWidth) + - svgPaths.lineOnAxis('v', -height) + 'z'; + svgPaths.lineOnAxis('v', connectionTop) + + (input.shape as PuzzleTab).pathDown + + svgPaths.lineOnAxis('v', height - connectionBottom) + + svgPaths.lineOnAxis('h', width - input.connectionWidth) + + svgPaths.lineOnAxis('v', -height) + 'z'; this.positionInlineInputConnection_(input); } @@ -382,7 +381,7 @@ export class Drawer { connX *= -1; } input.connectionModel.setOffsetInBlock( - connX, yPos + input.connectionOffsetY); + connX, yPos + input.connectionOffsetY); } } @@ -447,10 +446,10 @@ export class Drawer { protected positionOutputConnection_() { if (this.info_.outputConnection) { const x = - this.info_.startX + this.info_.outputConnection.connectionOffsetX; + this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; this.block_.outputConnection.setOffsetInBlock( - connX, this.info_.outputConnection.connectionOffsetY); + connX, this.info_.outputConnection.connectionOffsetY); } } } diff --git a/core/renderers/common/i_path_object.ts b/core/renderers/common/i_path_object.ts index 7a3841916..76081b10b 100644 --- a/core/renderers/common/i_path_object.ts +++ b/core/renderers/common/i_path_object.ts @@ -26,10 +26,10 @@ import '../../connection'; // Unused import preserved for side-effects. Remove if unneeded. import '../../theme'; -import { BlockStyle } from '../../theme.js'; +import {BlockStyle} from '../../theme.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; +import {ConstantProvider} from './constants.js'; /** diff --git a/core/renderers/common/info.ts b/core/renderers/common/info.ts index 9f7713eb6..381f37464 100644 --- a/core/renderers/common/info.ts +++ b/core/renderers/common/info.ts @@ -13,39 +13,38 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { Align, Input } from '../../input.js'; -import { inputTypes } from '../../input_types.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Align, Input} from '../../input.js'; +import {inputTypes} from '../../input_types.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Measurable} from '../measurables/base.js'; +import {BottomRow} from '../measurables/bottom_row.js'; +import {ExternalValueInput} from '../measurables/external_value_input.js'; +import {Field} from '../measurables/field.js'; +import {Hat} from '../measurables/hat.js'; +import {Icon} from '../measurables/icon.js'; +import {InRowSpacer} from '../measurables/in_row_spacer.js'; +import {InlineInput} from '../measurables/inline_input.js'; +import {InputRow} from '../measurables/input_row.js'; +import {JaggedEdge} from '../measurables/jagged_edge.js'; +import {NextConnection} from '../measurables/next_connection.js'; +import {OutputConnection} from '../measurables/output_connection.js'; +import {PreviousConnection} from '../measurables/previous_connection.js'; +import {RoundCorner} from '../measurables/round_corner.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Row} from '../measurables/row.js'; +import {SpacerRow} from '../measurables/spacer_row.js'; +import {SquareCorner} from '../measurables/square_corner.js'; +import {StatementInput} from '../measurables/statement_input.js'; +import {TopRow} from '../measurables/top_row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { Measurable } from '../measurables/base.js'; -import { BottomRow } from '../measurables/bottom_row.js'; -import { ExternalValueInput } from '../measurables/external_value_input.js'; -import { Field } from '../measurables/field.js'; -import { Hat } from '../measurables/hat.js'; -import { Icon } from '../measurables/icon.js'; -import { InRowSpacer } from '../measurables/in_row_spacer.js'; -import { InlineInput } from '../measurables/inline_input.js'; -import { InputRow } from '../measurables/input_row.js'; -import { JaggedEdge } from '../measurables/jagged_edge.js'; -import { NextConnection } from '../measurables/next_connection.js'; -import { OutputConnection } from '../measurables/output_connection.js'; -import { PreviousConnection } from '../measurables/previous_connection.js'; -import { RoundCorner } from '../measurables/round_corner.js'; +import {ConstantProvider} from './constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; -import { SpacerRow } from '../measurables/spacer_row.js'; -import { SquareCorner } from '../measurables/square_corner.js'; -import { StatementInput } from '../measurables/statement_input.js'; -import { TopRow } from '../measurables/top_row.js'; -import { Types } from '../measurables/types.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; -/* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderer.js'; +import {Renderer} from './renderer.js'; /** @@ -111,10 +110,10 @@ export class RenderInfo { // AnyDuringMigration because: Type 'OutputConnection | null' is not // assignable to type 'OutputConnection'. this.outputConnection = - (!block.outputConnection ? - null : - new OutputConnection(this.constants_, (block.outputConnection))) as - AnyDuringMigration; + (!block.outputConnection ? + null : + new OutputConnection(this.constants_, (block.outputConnection))) as + AnyDuringMigration; /** * Whether the block should be rendered as a single line, either because @@ -229,12 +228,12 @@ export class RenderInfo { populateTopRow_() { const hasPrevious = !!this.block_.previousConnection; const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : - this.constants_.ADD_START_HATS) && - !this.outputConnection && !hasPrevious; + this.constants_.ADD_START_HATS) && + !this.outputConnection && !hasPrevious; let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - SquareCorner : - RoundCorner; + SquareCorner : + RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { @@ -244,25 +243,25 @@ export class RenderInfo { } else if (hasPrevious) { this.topRow.hasPreviousConnection = true; this.topRow.connection = new PreviousConnection( - this.constants_, - (this.block_.previousConnection as RenderedConnection)); + this.constants_, + (this.block_.previousConnection as RenderedConnection)); this.topRow.elements.push(this.topRow.connection); } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type === inputTypes.STATEMENT; + this.block_.inputList[0].type === inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. if (precedesStatement && !this.block_.isCollapsed()) { this.topRow.minHeight = - this.constants_.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT; + this.constants_.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT; } else { this.topRow.minHeight = this.constants_.TOP_ROW_MIN_HEIGHT; } cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? SquareCorner : - RoundCorner; + RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_, 'right')); } @@ -271,14 +270,14 @@ export class RenderInfo { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1].type === - inputTypes.STATEMENT; + this.block_.inputList[this.block_.inputList.length - 1].type === + inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. if (followsStatement) { this.bottomRow.minHeight = - this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; + this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; } else { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } @@ -293,7 +292,7 @@ export class RenderInfo { if (this.bottomRow.hasNextConnection) { this.bottomRow.connection = new NextConnection( - this.constants_, (this.block_.nextConnection as RenderedConnection)); + this.constants_, (this.block_.nextConnection as RenderedConnection)); this.bottomRow.elements.push(this.bottomRow.connection); } @@ -327,10 +326,10 @@ export class RenderInfo { // Dummy inputs have no visual representation, but the information is // still important. activeRow.minHeight = Math.max( - activeRow.minHeight, - input.getSourceBlock() && input.getSourceBlock()!.isShadow() ? - this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : - this.constants_.DUMMY_INPUT_MIN_HEIGHT); + activeRow.minHeight, + input.getSourceBlock() && input.getSourceBlock()!.isShadow() ? + this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : + this.constants_.DUMMY_INPUT_MIN_HEIGHT); activeRow.hasDummyInput = true; } if (activeRow.align === null) { @@ -352,7 +351,7 @@ export class RenderInfo { } // A statement input or an input following one always gets a new row. if (input.type === inputTypes.STATEMENT || - lastInput.type === inputTypes.STATEMENT) { + lastInput.type === inputTypes.STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. @@ -371,7 +370,7 @@ export class RenderInfo { if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. row.elements.push(new InRowSpacer( - this.constants_, this.getInRowSpacing_(null, oldElems[0]))); + this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { continue; @@ -385,8 +384,8 @@ export class RenderInfo { if (row.endsWithElemSpacer()) { // There's a spacer after the last element in the row. row.elements.push(new InRowSpacer( - this.constants_, - this.getInRowSpacing_(oldElems[oldElems.length - 1], null))); + this.constants_, + this.getInRowSpacing_(oldElems[oldElems.length - 1], null))); } } } @@ -399,8 +398,8 @@ export class RenderInfo { * @param next The element after the spacer. * @return The size of the spacing between the two elements. */ - protected getInRowSpacing_(prev: Measurable | null, next: Measurable | null): - number { + protected getInRowSpacing_(prev: Measurable|null, next: Measurable|null): + number { if (!prev) { // Statement input padding. if (next && Types.isStatementInput(next)) { @@ -452,10 +451,10 @@ export class RenderInfo { const statementInput = row.getLastInput(); const innerWidth = row.width - statementInput.width; widestStatementRowFields = - Math.max(widestStatementRowFields, innerWidth); + Math.max(widestStatementRowFields, innerWidth); } widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); + Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); } this.statementEdge = widestStatementRowFields; @@ -564,7 +563,7 @@ export class RenderInfo { statementInput.height = Math.max(statementInput.height, row.height); row.width += desiredWidth - currentWidth; row.widthWithConnectedBlocks = - Math.max(row.width, this.statementEdge + row.connectedBlockWidths); + Math.max(row.width, this.statementEdge + row.connectedBlockWidths); } /** Add spacers between rows and set their sizes. */ @@ -636,7 +635,7 @@ export class RenderInfo { if (Types.isBottomRow(row)) { const bottomRow = row as BottomRow; const baseline = - bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; + bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -688,15 +687,15 @@ export class RenderInfo { yCursor += row.height; widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); + Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); this.recordElemPositions_(row); } if (this.outputConnection && this.block_.nextConnection && - this.block_.nextConnection.isConnected()) { + this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. widestRowWithConnectedBlocks = Math.max( - widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width); + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width); } this.widthWithChildren = widestRowWithConnectedBlocks + this.startX; diff --git a/core/renderers/common/marker_svg.ts b/core/renderers/common/marker_svg.ts index c459713a7..d41721041 100644 --- a/core/renderers/common/marker_svg.ts +++ b/core/renderers/common/marker_svg.ts @@ -17,28 +17,28 @@ import '../../events/events_marker_move'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from '../../connection.js'; -import { ConnectionType } from '../../connection_type.js'; +import {Connection} from '../../connection.js'; +import {ConnectionType} from '../../connection_type.js'; import * as eventUtils from '../../events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../../field.js'; +import {Field} from '../../field.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationSvg } from '../../interfaces/i_ast_node_location_svg.js'; -import { ASTNode } from '../../keyboard_nav/ast_node.js'; +import {IASTNodeLocationSvg} from '../../interfaces/i_ast_node_location_svg.js'; +import {ASTNode} from '../../keyboard_nav/ast_node.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from '../../keyboard_nav/marker.js'; +import {Marker} from '../../keyboard_nav/marker.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../../workspace_svg.js'; +import {WorkspaceSvg} from '../../workspace_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider, Notch, PuzzleTab } from './constants.js'; +import {ConstantProvider, Notch, PuzzleTab} from './constants.js'; /** The name of the CSS class for a cursor. */ @@ -62,22 +62,22 @@ export class MarkerSvg { * The workspace, field, or block that the marker SVG element should be * attached to. */ - private parent_: IASTNodeLocationSvg | null = null; + private parent_: IASTNodeLocationSvg|null = null; /** The current SVG element for the marker. */ - currentMarkerSvg: Element | null = null; + currentMarkerSvg: Element|null = null; colour_: string; /** The root SVG group containing the marker. */ - protected markerSvg_: SVGGElement | null = null; - protected svgGroup_: SVGGElement | null = null; + protected markerSvg_: SVGGElement|null = null; + protected svgGroup_: SVGGElement|null = null; - protected markerBlock_: SVGPathElement | null = null; + protected markerBlock_: SVGPathElement|null = null; - protected markerInput_: SVGPathElement | null = null; - protected markerSvgLine_: SVGRectElement | null = null; + protected markerInput_: SVGPathElement|null = null; + protected markerSvgLine_: SVGRectElement|null = null; - protected markerSvgRect_: SVGRectElement | null = null; + protected markerSvgRect_: SVGRectElement|null = null; /** * @param workspace The workspace the marker belongs to. @@ -85,10 +85,10 @@ export class MarkerSvg { * @param marker The marker to draw. */ constructor( - private readonly workspace: WorkspaceSvg, - private constants: ConstantProvider, private readonly marker: Marker) { + private readonly workspace: WorkspaceSvg, + private constants: ConstantProvider, private readonly marker: Marker) { const defaultColour = this.isCursor() ? this.constants.CURSOR_COLOUR : - this.constants.MARKER_COLOUR; + this.constants.MARKER_COLOUR; /** The colour of the marker. */ this.colour_ = marker.colour || defaultColour; @@ -128,7 +128,7 @@ export class MarkerSvg { createDom(): SVGElement { const className = this.isCursor() ? CURSOR_CLASS : MARKER_CLASS; - this.svgGroup_ = dom.createSvgElement(Svg.G, { 'class': className }); + this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': className}); this.createDomInternal_(); return this.svgGroup_; @@ -168,7 +168,7 @@ export class MarkerSvg { this.constants = this.workspace.getRenderer().getConstants(); const defaultColour = this.isCursor() ? this.constants.CURSOR_COLOUR : - this.constants.MARKER_COLOUR; + this.constants.MARKER_COLOUR; this.colour_ = this.marker.colour || defaultColour; this.applyColour_(curNode); @@ -227,13 +227,13 @@ export class MarkerSvg { if (block.previousConnection) { const connectionShape = - this.constants.shapeFor(block.previousConnection) as Notch | - PuzzleTab; + this.constants.shapeFor(block.previousConnection) as Notch | + PuzzleTab; this.positionPrevious_( - width, markerOffset, markerHeight, connectionShape); + width, markerOffset, markerHeight, connectionShape); } else if (block.outputConnection) { const connectionShape = - this.constants.shapeFor(block.outputConnection) as Notch | PuzzleTab; + this.constants.shapeFor(block.outputConnection) as Notch | PuzzleTab; this.positionOutput_(width, height, connectionShape); } else { this.positionBlock_(width, markerOffset, markerHeight); @@ -385,11 +385,11 @@ export class MarkerSvg { * @param markerHeight The height of the marker. */ protected positionBlock_( - width: number, markerOffset: number, markerHeight: number) { + width: number, markerOffset: number, markerHeight: number) { const markerPath = svgPaths.moveBy(-markerOffset, markerHeight) + - svgPaths.lineOnAxis('V', -markerOffset) + - svgPaths.lineOnAxis('H', width + markerOffset * 2) + - svgPaths.lineOnAxis('V', markerHeight); + svgPaths.lineOnAxis('V', -markerOffset) + + svgPaths.lineOnAxis('H', width + markerOffset * 2) + + svgPaths.lineOnAxis('V', markerHeight); this.markerBlock_!.setAttribute('d', markerPath); if (this.workspace.RTL) { // AnyDuringMigration because: Argument of type 'SVGPathElement | null' @@ -409,13 +409,13 @@ export class MarkerSvg { const y = connection.getOffsetInBlock().y; const path = svgPaths.moveTo(0, 0) + - (this.constants.shapeFor(connection) as PuzzleTab).pathDown; + (this.constants.shapeFor(connection) as PuzzleTab).pathDown; this.markerInput_!.setAttribute('d', path); this.markerInput_!.setAttribute( - 'transform', - 'translate(' + x + ',' + y + ')' + - (this.workspace.RTL ? ' scale(-1 1)' : '')); + 'transform', + 'translate(' + x + ',' + y + ')' + + (this.workspace.RTL ? ' scale(-1 1)' : '')); this.currentMarkerSvg = this.markerInput_; } @@ -447,14 +447,14 @@ export class MarkerSvg { * @param connectionShape The shape object for the connection. */ protected positionOutput_( - width: number, height: number, connectionShape: Notch | PuzzleTab) { + width: number, height: number, connectionShape: Notch|PuzzleTab) { // AnyDuringMigration because: Property 'pathDown' does not exist on type // 'Notch | PuzzleTab'. const markerPath = svgPaths.moveBy(width, 0) + - svgPaths.lineOnAxis('h', -(width - connectionShape.width)) + - svgPaths.lineOnAxis('v', this.constants.TAB_OFFSET_FROM_TOP) + - (connectionShape as AnyDuringMigration).pathDown + - svgPaths.lineOnAxis('V', height) + svgPaths.lineOnAxis('H', width); + svgPaths.lineOnAxis('h', -(width - connectionShape.width)) + + svgPaths.lineOnAxis('v', this.constants.TAB_OFFSET_FROM_TOP) + + (connectionShape as AnyDuringMigration).pathDown + + svgPaths.lineOnAxis('V', height) + svgPaths.lineOnAxis('H', width); this.markerBlock_!.setAttribute('d', markerPath); if (this.workspace.RTL) { // AnyDuringMigration because: Argument of type 'SVGPathElement | null' @@ -474,16 +474,16 @@ export class MarkerSvg { * @param connectionShape The shape object for the connection. */ protected positionPrevious_( - width: number, markerOffset: number, markerHeight: number, - connectionShape: Notch | PuzzleTab) { + width: number, markerOffset: number, markerHeight: number, + connectionShape: Notch|PuzzleTab) { // AnyDuringMigration because: Property 'pathLeft' does not exist on type // 'Notch | PuzzleTab'. const markerPath = svgPaths.moveBy(-markerOffset, markerHeight) + - svgPaths.lineOnAxis('V', -markerOffset) + - svgPaths.lineOnAxis('H', this.constants.NOTCH_OFFSET_LEFT) + - (connectionShape as AnyDuringMigration).pathLeft + - svgPaths.lineOnAxis('H', width + markerOffset * 2) + - svgPaths.lineOnAxis('V', markerHeight); + svgPaths.lineOnAxis('V', -markerOffset) + + svgPaths.lineOnAxis('H', this.constants.NOTCH_OFFSET_LEFT) + + (connectionShape as AnyDuringMigration).pathLeft + + svgPaths.lineOnAxis('H', width + markerOffset * 2) + + svgPaths.lineOnAxis('V', markerHeight); this.markerBlock_!.setAttribute('d', markerPath); if (this.workspace.RTL) { // AnyDuringMigration because: Argument of type 'SVGPathElement | null' @@ -541,7 +541,7 @@ export class MarkerSvg { private fireMarkerEvent_(oldNode: ASTNode, curNode: ASTNode) { const curBlock = curNode.getSourceBlock(); const event = new (eventUtils.get(eventUtils.MARKER_MOVE))! - (curBlock, this.isCursor(), oldNode, curNode); + (curBlock, this.isCursor(), oldNode, curNode); eventUtils.fire(event); } @@ -577,55 +577,55 @@ export class MarkerSvg { // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerSvg_ = dom.createSvgElement( - Svg.G, { - 'width': this.constants.CURSOR_WS_WIDTH, - 'height': this.constants.WS_CURSOR_HEIGHT, - }, - this.svgGroup_ as AnyDuringMigration); + Svg.G, { + 'width': this.constants.CURSOR_WS_WIDTH, + 'height': this.constants.WS_CURSOR_HEIGHT, + }, + this.svgGroup_ as AnyDuringMigration); // A horizontal line used to represent a workspace coordinate or next // connection. // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerSvgLine_ = dom.createSvgElement( - Svg.RECT, { - 'width': this.constants.CURSOR_WS_WIDTH, - 'height': this.constants.WS_CURSOR_HEIGHT, - 'style': 'display: none', - }, - this.markerSvg_ as AnyDuringMigration); + Svg.RECT, { + 'width': this.constants.CURSOR_WS_WIDTH, + 'height': this.constants.WS_CURSOR_HEIGHT, + 'style': 'display: none', + }, + this.markerSvg_ as AnyDuringMigration); // A filled in rectangle used to represent a stack. // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerSvgRect_ = dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyVerticalMarker', - 'rx': 10, - 'ry': 10, - 'style': 'display: none', - }, - this.markerSvg_ as AnyDuringMigration); + Svg.RECT, { + 'class': 'blocklyVerticalMarker', + 'rx': 10, + 'ry': 10, + 'style': 'display: none', + }, + this.markerSvg_ as AnyDuringMigration); // A filled in puzzle piece used to represent an input value. // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerInput_ = dom.createSvgElement( - Svg.PATH, { 'transform': '', 'style': 'display: none' }, - this.markerSvg_ as AnyDuringMigration); + Svg.PATH, {'transform': '', 'style': 'display: none'}, + this.markerSvg_ as AnyDuringMigration); // A path used to represent a previous connection and a block, an output // connection and a block, or a block. // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerBlock_ = dom.createSvgElement( - Svg.PATH, { - 'transform': '', - 'style': 'display: none', - 'fill': 'none', - 'stroke-width': this.constants.CURSOR_STROKE_WIDTH, - }, - this.markerSvg_ as AnyDuringMigration); + Svg.PATH, { + 'transform': '', + 'style': 'display: none', + 'fill': 'none', + 'stroke-width': this.constants.CURSOR_STROKE_WIDTH, + }, + this.markerSvg_ as AnyDuringMigration); // Markers and stack markers don't blink. if (this.isCursor()) { @@ -633,19 +633,19 @@ export class MarkerSvg { // AnyDuringMigration because: Argument of type 'SVGRectElement | null' // is not assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.ANIMATE, blinkProperties, - this.markerSvgLine_ as AnyDuringMigration); + Svg.ANIMATE, blinkProperties, + this.markerSvgLine_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'SVGPathElement | null' // is not assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.ANIMATE, blinkProperties, - this.markerInput_ as AnyDuringMigration); + Svg.ANIMATE, blinkProperties, + this.markerInput_ as AnyDuringMigration); blinkProperties['attributeName'] = 'stroke'; // AnyDuringMigration because: Argument of type 'SVGPathElement | null' // is not assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.ANIMATE, blinkProperties, - this.markerBlock_ as AnyDuringMigration); + Svg.ANIMATE, blinkProperties, + this.markerBlock_ as AnyDuringMigration); } // AnyDuringMigration because: Type 'SVGGElement | null' is not assignable diff --git a/core/renderers/common/path_object.ts b/core/renderers/common/path_object.ts index cadc7206c..bab4523bd 100644 --- a/core/renderers/common/path_object.ts +++ b/core/renderers/common/path_object.ts @@ -17,17 +17,17 @@ import '../../theme'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from '../../connection.js'; -import { BlockStyle } from '../../theme.js'; +import {Connection} from '../../connection.js'; +import {BlockStyle} from '../../theme.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; +import {ConstantProvider} from './constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPathObject } from './i_path_object.js'; +import {IPathObject} from './i_path_object.js'; /** @@ -61,13 +61,13 @@ export class PathObject implements IPathObject { * @param constants The renderer's constants. */ constructor( - root: SVGElement, public style: BlockStyle, - public constants: ConstantProvider) { + root: SVGElement, public style: BlockStyle, + public constants: ConstantProvider) { this.svgRoot = root; /** The primary path of the block. */ this.svgPath = - dom.createSvgElement(Svg.PATH, { 'class': 'blocklyPath' }, this.svgRoot); + dom.createSvgElement(Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); } /** @@ -165,7 +165,7 @@ export class PathObject implements IPathObject { updateHighlighted(enable: boolean) { if (enable) { this.svgPath.setAttribute( - 'filter', 'url(#' + this.constants.embossFilterId + ')'); + 'filter', 'url(#' + this.constants.embossFilterId + ')'); } else { this.svgPath.setAttribute('filter', 'none'); } @@ -190,7 +190,7 @@ export class PathObject implements IPathObject { this.setClass_('blocklyDisabled', disabled); if (disabled) { this.svgPath.setAttribute( - 'fill', 'url(#' + this.constants.disabledPatternId + ')'); + 'fill', 'url(#' + this.constants.disabledPatternId + ')'); } } diff --git a/core/renderers/common/renderer.ts b/core/renderers/common/renderer.ts index 872cbbbaf..3121cca74 100644 --- a/core/renderers/common/renderer.ts +++ b/core/renderers/common/renderer.ts @@ -12,31 +12,32 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../../block.js'; +import {Block} from '../../block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { Connection } from '../../connection.js'; -import { ConnectionType } from '../../connection_type.js'; -import { InsertionMarkerManager, PreviewType } from '../../insertion_marker_manager.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Connection} from '../../connection.js'; +import {ConnectionType} from '../../connection_type.js'; +import {InsertionMarkerManager, PreviewType} from '../../insertion_marker_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { IRegistrable } from '../../interfaces/i_registrable.js'; +import {IRegistrable} from '../../interfaces/i_registrable.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from '../../keyboard_nav/marker.js'; +import {Marker} from '../../keyboard_nav/marker.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; -import { BlockStyle, Theme } from '../../theme.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +import {BlockStyle, Theme} from '../../theme.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../../workspace_svg.js'; -import { ConstantProvider } from './constants.js'; +import {WorkspaceSvg} from '../../workspace_svg.js'; + +import {ConstantProvider} from './constants.js'; import * as debug from './debug.js'; /* eslint-disable-next-line no-unused-vars */ -import { Debug } from './debugger.js'; -import { Drawer } from './drawer.js'; +import {Debug} from './debugger.js'; +import {Drawer} from './drawer.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPathObject } from './i_path_object.js'; -import { RenderInfo } from './info.js'; -import { MarkerSvg } from './marker_svg.js'; -import { PathObject } from './path_object.js'; +import {IPathObject} from './i_path_object.js'; +import {RenderInfo} from './info.js'; +import {MarkerSvg} from './marker_svg.js'; +import {PathObject} from './path_object.js'; /** @@ -48,7 +49,7 @@ export class Renderer implements IRegistrable { protected constants_!: ConstantProvider; /** Rendering constant overrides, passed in through options. */ - overrides: object | null = null; + overrides: object|null = null; /** @param name The renderer name. */ constructor(public name: string) {} @@ -83,8 +84,8 @@ export class Renderer implements IRegistrable { */ createDom(svg: SVGElement, theme: Theme) { this.constants_.createDom( - svg, this.name + '-' + theme.name, - '.' + this.getClassName() + '.' + theme.getClassName()); + svg, this.name + '-' + theme.name, + '.' + this.getClassName() + '.' + theme.getClassName()); } /** @@ -204,12 +205,12 @@ export class Renderer implements IRegistrable { * @return Whether there is a home for the orphan or not. */ orphanCanConnectAtEnd( - topBlock: BlockSvg, orphanBlock: BlockSvg, localType: number): boolean { + topBlock: BlockSvg, orphanBlock: BlockSvg, localType: number): boolean { const orphanConnection = localType === ConnectionType.OUTPUT_VALUE ? - orphanBlock.outputConnection : - orphanBlock.previousConnection; + orphanBlock.outputConnection : + orphanBlock.previousConnection; return !!Connection.getConnectionForOrphanedConnection( - topBlock as Block, orphanConnection as Connection); + topBlock as Block, orphanConnection as Connection); } /** @@ -221,13 +222,13 @@ export class Renderer implements IRegistrable { * @return The preview type to display. */ getConnectionPreviewMethod( - closest: RenderedConnection, local: RenderedConnection, - topBlock: BlockSvg): PreviewType { + closest: RenderedConnection, local: RenderedConnection, + topBlock: BlockSvg): PreviewType { if (local.type === ConnectionType.OUTPUT_VALUE || - local.type === ConnectionType.PREVIOUS_STATEMENT) { + local.type === ConnectionType.PREVIOUS_STATEMENT) { if (!closest.isConnected() || - this.orphanCanConnectAtEnd( - topBlock, closest.targetBlock() as BlockSvg, local.type)) { + this.orphanCanConnectAtEnd( + topBlock, closest.targetBlock() as BlockSvg, local.type)) { return InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER; } return InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; diff --git a/core/renderers/geras/constants.ts b/core/renderers/geras/constants.ts index 404ac0ebb..51c568365 100644 --- a/core/renderers/geras/constants.ts +++ b/core/renderers/geras/constants.ts @@ -16,7 +16,7 @@ * @class */ -import { ConstantProvider as BaseConstantProvider } from '../common/constants.js'; +import {ConstantProvider as BaseConstantProvider} from '../common/constants.js'; /** @@ -45,15 +45,15 @@ export class ConstantProvider extends BaseConstantProvider { override getCSS_(selector: string) { return super.getCSS_(selector) - .concat(/* eslint-enable indent */ - [ - /* eslint-disable indent */ - // Insertion marker. - selector + ' .blocklyInsertionMarker>.blocklyPathLight,', - selector + ' .blocklyInsertionMarker>.blocklyPathDark {', - 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';', - 'stroke: none;', - '}', - ]); + .concat(/* eslint-enable indent */ + [ + /* eslint-disable indent */ + // Insertion marker. + selector + ' .blocklyInsertionMarker>.blocklyPathLight,', + selector + ' .blocklyInsertionMarker>.blocklyPathDark {', + 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';', + 'stroke: none;', + '}', + ]); } } diff --git a/core/renderers/geras/drawer.ts b/core/renderers/geras/drawer.ts index 5e91f3059..11ee9d680 100644 --- a/core/renderers/geras/drawer.ts +++ b/core/renderers/geras/drawer.ts @@ -15,22 +15,21 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; - import * as debug from '../common/debug.js'; -import { Drawer as BaseDrawer } from '../common/drawer.js'; -import { Row } from '../measurables/row.js'; +import {Drawer as BaseDrawer} from '../common/drawer.js'; +import {Row} from '../measurables/row.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; -import { Highlighter } from './highlighter.js'; +import {ConstantProvider} from './constants.js'; +import {Highlighter} from './highlighter.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /* eslint-disable-next-line no-unused-vars */ -import { InlineInput } from './measurables/inline_input.js'; +import {InlineInput} from './measurables/inline_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { PathObject } from './path_object.js'; +import {PathObject} from './path_object.js'; /** @@ -99,7 +98,7 @@ export class Drawer extends BaseDrawer { this.highlighter_.drawRightSideRow(row); this.outlinePath_ += svgPaths.lineOnAxis('H', row.xPos + row.width) + - svgPaths.lineOnAxis('V', row.yPos + row.height); + svgPaths.lineOnAxis('V', row.yPos + row.height); } override drawBottom_() { @@ -130,13 +129,13 @@ export class Drawer extends BaseDrawer { if (input.connectionModel) { // xPos already contains info about startX let connX = - input.xPos + input.connectionWidth + this.constants_.DARK_PATH_OFFSET; + input.xPos + input.connectionWidth + this.constants_.DARK_PATH_OFFSET; if (this.info_.RTL) { connX *= -1; } input.connectionModel.setOffsetInBlock( - connX, - yPos + input.connectionOffsetY + this.constants_.DARK_PATH_OFFSET); + connX, + yPos + input.connectionOffsetY + this.constants_.DARK_PATH_OFFSET); } } @@ -150,7 +149,7 @@ export class Drawer extends BaseDrawer { connX += this.constants_.DARK_PATH_OFFSET; } input.connectionModel.setOffsetInBlock( - connX, row.yPos + this.constants_.DARK_PATH_OFFSET); + connX, row.yPos + this.constants_.DARK_PATH_OFFSET); } } @@ -173,9 +172,9 @@ export class Drawer extends BaseDrawer { const x = connInfo.xPos; // Already contains info about startX. const connX = - (this.info_.RTL ? -x : x) + this.constants_.DARK_PATH_OFFSET / 2; + (this.info_.RTL ? -x : x) + this.constants_.DARK_PATH_OFFSET / 2; connInfo.connectionModel.setOffsetInBlock( - connX, bottomRow.baseline + this.constants_.DARK_PATH_OFFSET); + connX, bottomRow.baseline + this.constants_.DARK_PATH_OFFSET); } } } diff --git a/core/renderers/geras/geras.ts b/core/renderers/geras/geras.ts index b56ceecb8..ec065f9ff 100644 --- a/core/renderers/geras/geras.ts +++ b/core/renderers/geras/geras.ts @@ -12,15 +12,15 @@ * @namespace Blockly.geras */ -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { HighlightConstantProvider } from './highlight_constants.js'; -import { Highlighter } from './highlighter.js'; -import { RenderInfo } from './info.js'; -import { InlineInput } from './measurables/inline_input.js'; -import { StatementInput } from './measurables/statement_input.js'; -import { PathObject } from './path_object.js'; -import { Renderer } from './renderer.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {HighlightConstantProvider} from './highlight_constants.js'; +import {Highlighter} from './highlighter.js'; +import {RenderInfo} from './info.js'; +import {InlineInput} from './measurables/inline_input.js'; +import {StatementInput} from './measurables/statement_input.js'; +import {PathObject} from './path_object.js'; +import {Renderer} from './renderer.js'; export { ConstantProvider, diff --git a/core/renderers/geras/highlight_constants.ts b/core/renderers/geras/highlight_constants.ts index 817d94476..05cd7c41d 100644 --- a/core/renderers/geras/highlight_constants.ts +++ b/core/renderers/geras/highlight_constants.ts @@ -12,9 +12,8 @@ * @class */ import * as svgPaths from '../../utils/svg_paths.js'; - /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; /** An object containing sizing and path information about an outside corner. */ export interface OutsideCorner { @@ -151,21 +150,21 @@ export class HighlightConstantProvider { const distance45outside = (1 - Math.SQRT1_2) * (radius + offset) - offset; const pathTopRtl = svgPaths.moveBy(distance45outside, distance45outside) + - svgPaths.arc( - 'a', '0 0,0', radius, - svgPaths.point( - -distance45outside - offset, radius - distance45outside)); + svgPaths.arc( + 'a', '0 0,0', radius, + svgPaths.point( + -distance45outside - offset, radius - distance45outside)); const pathBottomRtl = svgPaths.arc( - 'a', '0 0,0', radius + offset, - svgPaths.point(radius + offset, radius + offset)); + 'a', '0 0,0', radius + offset, + svgPaths.point(radius + offset, radius + offset)); const pathBottomLtr = - svgPaths.moveBy(distance45outside, -distance45outside) + - svgPaths.arc( - 'a', '0 0,0', radius + offset, - svgPaths.point( - radius - distance45outside, distance45outside + offset)); + svgPaths.moveBy(distance45outside, -distance45outside) + + svgPaths.arc( + 'a', '0 0,0', radius + offset, + svgPaths.point( + radius - distance45outside, distance45outside + offset)); return { width: radius + offset, @@ -196,25 +195,25 @@ export class HighlightConstantProvider { const topLeftStartX = distance45inside; const topLeftStartY = distance45inside; const topLeftCornerHighlightRtl = - svgPaths.moveBy(topLeftStartX, topLeftStartY) + - svgPaths.arc( - 'a', '0 0,1', radius - offset, - svgPaths.point(radius - topLeftStartX, -topLeftStartY + offset)); + svgPaths.moveBy(topLeftStartX, topLeftStartY) + + svgPaths.arc( + 'a', '0 0,1', radius - offset, + svgPaths.point(radius - topLeftStartX, -topLeftStartY + offset)); /** * SVG path for drawing the highlight on the rounded top-left corner. */ const topLeftCornerHighlightLtr = svgPaths.moveBy(offset, radius) + - svgPaths.arc( - 'a', '0 0,1', radius - offset, - svgPaths.point(radius, -radius + offset)); + svgPaths.arc( + 'a', '0 0,1', radius - offset, + svgPaths.point(radius, -radius + offset)); const bottomLeftStartX = distance45inside; const bottomLeftStartY = -distance45inside; const bottomLeftPath = svgPaths.moveBy(bottomLeftStartX, bottomLeftStartY) + - svgPaths.arc( - 'a', '0 0,1', radius - offset, - svgPaths.point( - -bottomLeftStartX + offset, -bottomLeftStartY - radius)); + svgPaths.arc( + 'a', '0 0,1', radius - offset, + svgPaths.point( + -bottomLeftStartX + offset, -bottomLeftStartY - radius)); return { height: radius, @@ -240,29 +239,29 @@ export class HighlightConstantProvider { const verticalOverlap = 2.5; const highlightRtlUp = - svgPaths.moveBy(-2, -height + verticalOverlap + 0.9) + - svgPaths.lineTo(width * -0.45, -2.1); + svgPaths.moveBy(-2, -height + verticalOverlap + 0.9) + + svgPaths.lineTo(width * -0.45, -2.1); const highlightRtlDown = svgPaths.lineOnAxis('v', verticalOverlap) + - svgPaths.moveBy(-width * 0.97, 2.5) + - svgPaths.curve( - 'q', - [ - svgPaths.point(-width * 0.05, 10), - svgPaths.point(width * 0.3, 9.5), - ]) + - svgPaths.moveBy(width * 0.67, -1.9) + - svgPaths.lineOnAxis('v', verticalOverlap); + svgPaths.moveBy(-width * 0.97, 2.5) + + svgPaths.curve( + 'q', + [ + svgPaths.point(-width * 0.05, 10), + svgPaths.point(width * 0.3, 9.5), + ]) + + svgPaths.moveBy(width * 0.67, -1.9) + + svgPaths.lineOnAxis('v', verticalOverlap); const highlightLtrUp = svgPaths.lineOnAxis('v', -1.5) + - svgPaths.moveBy(width * -0.92, -0.5) + - svgPaths.curve( - 'q', - [svgPaths.point(width * -0.19, -5.5), svgPaths.point(0, -11)]) + - svgPaths.moveBy(width * 0.92, 1); + svgPaths.moveBy(width * -0.92, -0.5) + + svgPaths.curve( + 'q', + [svgPaths.point(width * -0.19, -5.5), svgPaths.point(0, -11)]) + + svgPaths.moveBy(width * 0.92, 1); const highlightLtrDown = - svgPaths.moveBy(-5, height - 0.7) + svgPaths.lineTo(width * 0.46, -2.1); + svgPaths.moveBy(-5, height - 0.7) + svgPaths.lineTo(width * 0.46, -2.1); return { width, @@ -283,8 +282,8 @@ export class HighlightConstantProvider { makeNotch(): Notch { // This is only for the previous connection. const pathLeft = svgPaths.lineOnAxis('h', this.OFFSET) + - this.constantProvider.NOTCH.pathLeft; - return { pathLeft }; + this.constantProvider.NOTCH.pathLeft; + return {pathLeft}; } /** @@ -293,8 +292,8 @@ export class HighlightConstantProvider { */ makeJaggedTeeth(): JaggedTeeth { const pathLeft = svgPaths.lineTo(5.1, 2.6) + svgPaths.moveBy(-10.2, 6.8) + - svgPaths.lineTo(5.1, 2.6); - return { pathLeft, height: 12, width: 10.2 }; + svgPaths.lineTo(5.1, 2.6); + return {pathLeft, height: 12, width: 10.2}; } /** diff --git a/core/renderers/geras/highlighter.ts b/core/renderers/geras/highlighter.ts index c7b06dfa5..9a07c58af 100644 --- a/core/renderers/geras/highlighter.ts +++ b/core/renderers/geras/highlighter.ts @@ -21,25 +21,22 @@ import './renderer'; import * as svgPaths from '../../utils/svg_paths.js'; +/* eslint-disable-next-line no-unused-vars */ +import {ConstantProvider} from '../common/constants.js'; +/* eslint-disable-next-line no-unused-vars */ +import {BottomRow} from '../measurables/bottom_row.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Row} from '../measurables/row.js'; +import {SpacerRow} from '../measurables/spacer_row.js'; +/* eslint-disable-next-line no-unused-vars */ +import {TopRow} from '../measurables/top_row.js'; +import {Types} from '../measurables/types.js'; +import {HighlightConstantProvider, InsideCorner, JaggedTeeth, Notch, OutsideCorner, PuzzleTab, StartHat} from './highlight_constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {RenderInfo} from './info.js'; /* eslint-disable-next-line no-unused-vars */ -import { BottomRow } from '../measurables/bottom_row.js'; -/* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; -import { SpacerRow } from '../measurables/spacer_row.js'; -/* eslint-disable-next-line no-unused-vars */ -import { TopRow } from '../measurables/top_row.js'; -import { Types } from '../measurables/types.js'; -import { OutsideCorner, InsideCorner, StartHat, Notch, PuzzleTab, JaggedTeeth } from './highlight_constants.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { HighlightConstantProvider } from './highlight_constants.js'; -/* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; -/* eslint-disable-next-line no-unused-vars */ -import { InlineInput } from './measurables/inline_input.js'; +import {InlineInput} from './measurables/inline_input.js'; /** @@ -124,7 +121,7 @@ export class Highlighter { // horizontal, use its width and position for an absolute horizontal // move. this.steps_ += svgPaths.lineOnAxis( - 'H', elem.xPos + elem.width - this.highlightOffset_); + 'H', elem.xPos + elem.width - this.highlightOffset_); } } @@ -139,9 +136,9 @@ export class Highlighter { drawJaggedEdge_(row: Row) { if (this.info_.RTL) { const remainder = - row.height - this.jaggedTeethPaths_.height - this.highlightOffset_; + row.height - this.jaggedTeethPaths_.height - this.highlightOffset_; this.steps_ += - this.jaggedTeethPaths_.pathLeft + svgPaths.lineOnAxis('v', remainder); + this.jaggedTeethPaths_.pathLeft + svgPaths.lineOnAxis('v', remainder); } } @@ -155,13 +152,13 @@ export class Highlighter { const belowTabHeight = row.height - input.connectionHeight; this.steps_ += - svgPaths.moveTo( - input.xPos + input.width - this.highlightOffset_, row.yPos) + - this.puzzleTabPaths_.pathDown(this.RTL_) + - svgPaths.lineOnAxis('v', belowTabHeight); + svgPaths.moveTo( + input.xPos + input.width - this.highlightOffset_, row.yPos) + + this.puzzleTabPaths_.pathDown(this.RTL_) + + svgPaths.lineOnAxis('v', belowTabHeight); } else { this.steps_ += svgPaths.moveTo(input.xPos + input.width, row.yPos) + - this.puzzleTabPaths_.pathDown(this.RTL_); + this.puzzleTabPaths_.pathDown(this.RTL_); } } @@ -174,16 +171,16 @@ export class Highlighter { if (this.RTL_) { const innerHeight = row.height - 2 * this.insideCornerPaths_.height; this.steps_ += svgPaths.moveTo(input.xPos, row.yPos) + - this.insideCornerPaths_.pathTop(this.RTL_) + - svgPaths.lineOnAxis('v', innerHeight) + - this.insideCornerPaths_.pathBottom(this.RTL_) + - svgPaths.lineTo( - row.width - input.xPos - this.insideCornerPaths_.width, 0); + this.insideCornerPaths_.pathTop(this.RTL_) + + svgPaths.lineOnAxis('v', innerHeight) + + this.insideCornerPaths_.pathBottom(this.RTL_) + + svgPaths.lineTo( + row.width - input.xPos - this.insideCornerPaths_.width, 0); } else { this.steps_ += svgPaths.moveTo(input.xPos, row.yPos + row.height) + - this.insideCornerPaths_.pathBottom(this.RTL_) + - svgPaths.lineTo( - row.width - input.xPos - this.insideCornerPaths_.width, 0); + this.insideCornerPaths_.pathBottom(this.RTL_) + + svgPaths.lineTo( + row.width - input.xPos - this.insideCornerPaths_.width, 0); } } @@ -200,7 +197,7 @@ export class Highlighter { this.steps_ += svgPaths.lineOnAxis('H', rightEdge); if (row.height > this.highlightOffset_) { this.steps_ += svgPaths.lineOnAxis( - 'V', row.yPos + row.height - this.highlightOffset_); + 'V', row.yPos + row.height - this.highlightOffset_); } } } @@ -214,13 +211,13 @@ export class Highlighter { // Highlighting is always from the top left, both in LTR and RTL. if (this.RTL_) { this.steps_ += - svgPaths.lineOnAxis('V', row.baseline - this.highlightOffset_); + svgPaths.lineOnAxis('V', row.baseline - this.highlightOffset_); } else { const cornerElem = this.info_.bottomRow.elements[0]; if (Types.isLeftSquareCorner(cornerElem)) { this.steps_ += svgPaths.moveTo( - row.xPos + this.highlightOffset_, - row.baseline - this.highlightOffset_); + row.xPos + this.highlightOffset_, + row.baseline - this.highlightOffset_); } else if (Types.isLeftRoundedCorner(cornerElem)) { this.steps_ += svgPaths.moveTo(row.xPos, row.baseline); this.steps_ += this.outsideCornerPaths_.bottomLeft(); @@ -233,7 +230,7 @@ export class Highlighter { const outputConnection = this.info_.outputConnection; if (outputConnection) { const tabBottom = - outputConnection.connectionOffsetY + outputConnection.height; + outputConnection.connectionOffsetY + outputConnection.height; // Draw a line up to the bottom of the tab. if (this.RTL_) { this.steps_ += svgPaths.moveTo(this.info_.startX, tabBottom); @@ -250,10 +247,10 @@ export class Highlighter { const topRow = this.info_.topRow; if (Types.isLeftRoundedCorner(topRow.elements[0])) { this.steps_ += - svgPaths.lineOnAxis('V', this.outsideCornerPaths_.height); + svgPaths.lineOnAxis('V', this.outsideCornerPaths_.height); } else { this.steps_ += - svgPaths.lineOnAxis('V', topRow.capline + this.highlightOffset_); + svgPaths.lineOnAxis('V', topRow.capline + this.highlightOffset_); } } } @@ -274,29 +271,29 @@ export class Highlighter { if (this.RTL_) { const aboveTabHeight = input.connectionOffsetY - offset; const belowTabHeight = input.height - - (input.connectionOffsetY + input.connectionHeight) + offset; + (input.connectionOffsetY + input.connectionHeight) + offset; const startX = connectionRight - offset; this.inlineSteps_ += - svgPaths.moveTo(startX, startY) + // Right edge above tab. - svgPaths.lineOnAxis('v', aboveTabHeight) + // Back of tab. - this.puzzleTabPaths_.pathDown(this.RTL_) + // Right edge below tab. - svgPaths.lineOnAxis('v', belowTabHeight) + // Bottom. - svgPaths.lineOnAxis('h', bottomHighlightWidth); + svgPaths.moveTo(startX, startY) + // Right edge above tab. + svgPaths.lineOnAxis('v', aboveTabHeight) + // Back of tab. + this.puzzleTabPaths_.pathDown(this.RTL_) + // Right edge below tab. + svgPaths.lineOnAxis('v', belowTabHeight) + // Bottom. + svgPaths.lineOnAxis('h', bottomHighlightWidth); } else { this.inlineSteps_ += // Go to top right corner. - svgPaths.moveTo( - input.xPos + input.width + offset, - startY) + // Highlight right edge, bottom. - svgPaths.lineOnAxis('v', input.height) + - svgPaths.lineOnAxis( - 'h', -bottomHighlightWidth) + // Go to top of tab. - svgPaths.moveTo( - connectionRight, - yPos + input.connectionOffsetY) + // Short highlight glint at - // bottom of tab. - this.puzzleTabPaths_.pathDown(this.RTL_); + svgPaths.moveTo( + input.xPos + input.width + offset, + startY) + // Highlight right edge, bottom. + svgPaths.lineOnAxis('v', input.height) + + svgPaths.lineOnAxis( + 'h', -bottomHighlightWidth) + // Go to top of tab. + svgPaths.moveTo( + connectionRight, + yPos + input.connectionOffsetY) + // Short highlight glint at + // bottom of tab. + this.puzzleTabPaths_.pathDown(this.RTL_); } } } diff --git a/core/renderers/geras/info.ts b/core/renderers/geras/info.ts index d6c32d806..171575434 100644 --- a/core/renderers/geras/info.ts +++ b/core/renderers/geras/info.ts @@ -17,31 +17,30 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { Input } from '../../input.js'; -import { inputTypes } from '../../input_types.js'; - -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; -import { Measurable } from '../measurables/base.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Input} from '../../input.js'; +import {inputTypes} from '../../input_types.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +import {Measurable} from '../measurables/base.js'; /* eslint-disable-next-line no-unused-vars */ -import { BottomRow } from '../measurables/bottom_row.js'; -import { ExternalValueInput } from '../measurables/external_value_input.js'; +import {BottomRow} from '../measurables/bottom_row.js'; +import {ExternalValueInput} from '../measurables/external_value_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../measurables/field.js'; -import { InRowSpacer } from '../measurables/in_row_spacer.js'; +import {Field} from '../measurables/field.js'; +import {InRowSpacer} from '../measurables/in_row_spacer.js'; /* eslint-disable-next-line no-unused-vars */ -import { InputRow } from '../measurables/input_row.js'; -import { Row } from '../measurables/row.js'; +import {InputRow} from '../measurables/input_row.js'; +import {Row} from '../measurables/row.js'; /* eslint-disable-next-line no-unused-vars */ -import { TopRow } from '../measurables/top_row.js'; -import { Types } from '../measurables/types.js'; +import {TopRow} from '../measurables/top_row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; -import { InlineInput } from './measurables/inline_input.js'; -import { StatementInput } from './measurables/statement_input.js'; +import {ConstantProvider} from './constants.js'; +import {InlineInput} from './measurables/inline_input.js'; +import {StatementInput} from './measurables/statement_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderer.js'; +import {Renderer} from './renderer.js'; /** @@ -79,15 +78,15 @@ export class RenderInfo extends BaseRenderInfo { super.populateBottomRow_(); const followsStatement = this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1].type === - inputTypes.STATEMENT; + this.block_.inputList[this.block_.inputList.length - 1].type === + inputTypes.STATEMENT; // The minimum height of the bottom row is smaller in Geras than in other // renderers, because the dark path adds a pixel. // If one of the row's elements has a greater height this will be // overwritten in the compute pass. if (!followsStatement) { this.bottomRow.minHeight = - this.constants_.MEDIUM_PADDING - this.constants_.DARK_PATH_OFFSET; + this.constants_.MEDIUM_PADDING - this.constants_.DARK_PATH_OFFSET; } } @@ -106,7 +105,7 @@ export class RenderInfo extends BaseRenderInfo { // Dummy inputs have no visual representation, but the information is // still important. activeRow.minHeight = - Math.max(activeRow.minHeight, this.constants_.DUMMY_INPUT_MIN_HEIGHT); + Math.max(activeRow.minHeight, this.constants_.DUMMY_INPUT_MIN_HEIGHT); activeRow.hasDummyInput = true; } // Ignore row alignment if inline. @@ -129,7 +128,7 @@ export class RenderInfo extends BaseRenderInfo { if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. row.elements.push(new InRowSpacer( - this.constants_, this.getInRowSpacing_(null, oldElems[0]))); + this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { continue; @@ -142,7 +141,7 @@ export class RenderInfo extends BaseRenderInfo { row.elements.push(oldElems[oldElems.length - 1]); if (row.endsWithElemSpacer()) { let spacing = - this.getInRowSpacing_(oldElems[oldElems.length - 1], null); + this.getInRowSpacing_(oldElems[oldElems.length - 1], null); if (hasExternalInputs && row.hasDummyInput) { spacing += this.constants_.TAB_WIDTH; } @@ -152,7 +151,7 @@ export class RenderInfo extends BaseRenderInfo { } } - override getInRowSpacing_(prev: Measurable | null, next: Measurable | null) { + override getInRowSpacing_(prev: Measurable|null, next: Measurable|null) { if (!prev) { // Between an editable field and the beginning of the row. if (next && Types.isField(next) && (next as Field).isEditable) { @@ -259,7 +258,7 @@ export class RenderInfo extends BaseRenderInfo { // RTL) to make the dark path under the previous connection show // through. const offset = - (this.RTL ? 1 : -1) * this.constants_.DARK_PATH_OFFSET / 2; + (this.RTL ? 1 : -1) * this.constants_.DARK_PATH_OFFSET / 2; return next.notchOffset + offset; } } @@ -273,14 +272,14 @@ export class RenderInfo extends BaseRenderInfo { // RTL) to make the dark path under the previous connection show // through. const offset = - (this.RTL ? 1 : -1) * this.constants_.DARK_PATH_OFFSET / 2; + (this.RTL ? 1 : -1) * this.constants_.DARK_PATH_OFFSET / 2; return next.notchOffset - this.constants_.CORNER_RADIUS + offset; } } // Spacing between two fields of the same editability. if (Types.isField(prev) && next && Types.isField(next) && - (prev as Field).isEditable === (next as Field).isEditable) { + (prev as Field).isEditable === (next as Field).isEditable) { return this.constants_.LARGE_PADDING; } @@ -326,7 +325,7 @@ export class RenderInfo extends BaseRenderInfo { if (Types.isBottomRow(row)) { const bottomRow = row as BottomRow; const baseline = - bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; + bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -344,8 +343,8 @@ export class RenderInfo extends BaseRenderInfo { if (Types.isField(elem) || Types.isIcon(elem)) { result += elem.height / 2; if ((row.hasInlineInput || row.hasStatement) && - elem.height + this.constants_.TALL_INPUT_FIELD_OFFSET_Y <= - row.height) { + elem.height + this.constants_.TALL_INPUT_FIELD_OFFSET_Y <= + row.height) { result += this.constants_.TALL_INPUT_FIELD_OFFSET_Y; } } else if (Types.isInlineInput(elem)) { @@ -373,7 +372,7 @@ export class RenderInfo extends BaseRenderInfo { this.alignStatementRow_(row as InputRow); } if (prevInput && prevInput.hasStatement && - row.width < prevInput.width) { + row.width < prevInput.width) { rowNextRightEdges.set(row, prevInput.width); } else { nextRightEdge = row.width; @@ -393,7 +392,7 @@ export class RenderInfo extends BaseRenderInfo { } else { const currentWidth = row.width; const desiredWidth = - Math.max(prevRightEdge, rowNextRightEdges.get(row)); + Math.max(prevRightEdge, rowNextRightEdges.get(row)); const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); @@ -407,7 +406,7 @@ export class RenderInfo extends BaseRenderInfo { // Limit the width of a statement row when a block is inline. if (this.isInline && row.hasStatement) { return this.statementEdge + this.constants_.MAX_BOTTOM_WIDTH + - this.startX; + this.startX; } return super.getDesiredRowWidth_(row); } @@ -424,11 +423,11 @@ export class RenderInfo extends BaseRenderInfo { yCursor += row.height; widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); + Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); // Add padding to the bottom row if block height is less than minimum const heightWithoutHat = yCursor - this.topRow.ascenderHeight; if (row === this.bottomRow && - heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) { + heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) { // But the hat height shouldn't be part of this. const diff = this.constants_.MIN_BLOCK_HEIGHT - heightWithoutHat; this.bottomRow.height += diff; @@ -437,17 +436,17 @@ export class RenderInfo extends BaseRenderInfo { this.recordElemPositions_(row); } if (this.outputConnection && this.block_.nextConnection && - this.block_.nextConnection.isConnected()) { + this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. widestRowWithConnectedBlocks = Math.max( - widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width - - this.constants_.DARK_PATH_OFFSET); + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width - + this.constants_.DARK_PATH_OFFSET); } this.bottomRow.baseline = yCursor - this.bottomRow.descenderHeight; this.widthWithChildren = widestRowWithConnectedBlocks + this.startX + - this.constants_.DARK_PATH_OFFSET; + this.constants_.DARK_PATH_OFFSET; this.width += this.constants_.DARK_PATH_OFFSET; this.height = yCursor + this.constants_.DARK_PATH_OFFSET; this.startY = this.topRow.capline; diff --git a/core/renderers/geras/measurables/inline_input.ts b/core/renderers/geras/measurables/inline_input.ts index 0b4f8409d..931a9f66f 100644 --- a/core/renderers/geras/measurables/inline_input.ts +++ b/core/renderers/geras/measurables/inline_input.ts @@ -17,12 +17,11 @@ */ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../../input.js'; -import { ConstantProvider as BaseConstantProvider } from '../../../renderers/common/constants.js'; -import { InlineInput as BaseInlineInput } from '../../../renderers/measurables/inline_input.js'; - +import {Input} from '../../../input.js'; +import {ConstantProvider as BaseConstantProvider} from '../../../renderers/common/constants.js'; +import {InlineInput as BaseInlineInput} from '../../../renderers/measurables/inline_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider as GerasConstantProvider } from '../constants.js'; +import {ConstantProvider as GerasConstantProvider} from '../constants.js'; /** diff --git a/core/renderers/geras/measurables/statement_input.ts b/core/renderers/geras/measurables/statement_input.ts index cd8b722b0..ae9b1c866 100644 --- a/core/renderers/geras/measurables/statement_input.ts +++ b/core/renderers/geras/measurables/statement_input.ts @@ -18,12 +18,11 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../../input.js'; -import { ConstantProvider as BaseConstantProvider } from '../../../renderers/common/constants.js'; -import { StatementInput as BaseStatementInput } from '../../../renderers/measurables/statement_input.js'; - +import {Input} from '../../../input.js'; +import {ConstantProvider as BaseConstantProvider} from '../../../renderers/common/constants.js'; +import {StatementInput as BaseStatementInput} from '../../../renderers/measurables/statement_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider as GerasConstantProvider } from '../constants.js'; +import {ConstantProvider as GerasConstantProvider} from '../constants.js'; /** diff --git a/core/renderers/geras/path_object.ts b/core/renderers/geras/path_object.ts index 8baa548a1..144f4db0a 100644 --- a/core/renderers/geras/path_object.ts +++ b/core/renderers/geras/path_object.ts @@ -16,16 +16,15 @@ // Unused import preserved for side-effects. Remove if unneeded. import '../../theme'; -import { BlockStyle } from '../../theme.js'; +import {BlockSvg} from '../../block_svg.js'; +import {BlockStyle} from '../../theme.js'; import * as colour from '../../utils/colour.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; -import { BlockSvg } from '../../block_svg.js'; - -import { PathObject as BasePathObject } from '../common/path_object.js'; +import {Svg} from '../../utils/svg.js'; +import {PathObject as BasePathObject} from '../common/path_object.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; +import {ConstantProvider} from './constants.js'; /** @@ -47,13 +46,13 @@ export class PathObject extends BasePathObject { * @param constants The renderer's constants. */ constructor( - root: SVGElement, style: BlockStyle, - public override constants: ConstantProvider) { + root: SVGElement, style: BlockStyle, + public override constants: ConstantProvider) { super(root, style, constants); /** The dark path of the block. */ this.svgPathDark = dom.createSvgElement( - Svg.PATH, { 'class': 'blocklyPathDark', 'transform': 'translate(1,1)' }); + Svg.PATH, {'class': 'blocklyPathDark', 'transform': 'translate(1,1)'}); // SVG draw order is based on the order of elements (top most = back most) // So we need to insert the dark path before the base path to make sure it // gets drawn first. @@ -61,7 +60,7 @@ export class PathObject extends BasePathObject { /** The light path of the block. */ this.svgPathLight = dom.createSvgElement( - Svg.PATH, { 'class': 'blocklyPathLight' }, this.svgRoot); + Svg.PATH, {'class': 'blocklyPathLight'}, this.svgRoot); } override setPath(mainPath: string) { @@ -98,13 +97,13 @@ export class PathObject extends BasePathObject { override setStyle(blockStyle: BlockStyle) { this.style = blockStyle; this.colourDark = - colour.blend('#000', this.style.colourPrimary, 0.2) || this.colourDark; + colour.blend('#000', this.style.colourPrimary, 0.2) || this.colourDark; } override updateHighlighted(highlighted: boolean) { if (highlighted) { this.svgPath.setAttribute( - 'filter', 'url(#' + this.constants.embossFilterId + ')'); + 'filter', 'url(#' + this.constants.embossFilterId + ')'); this.svgPathLight.style.display = 'none'; } else { this.svgPath.setAttribute('filter', 'none'); diff --git a/core/renderers/geras/renderer.ts b/core/renderers/geras/renderer.ts index 4e1d12140..dd88754d8 100644 --- a/core/renderers/geras/renderer.ts +++ b/core/renderers/geras/renderer.ts @@ -16,19 +16,18 @@ import '../common/constants'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { BlockStyle, Theme } from '../../theme.js'; - +import {BlockSvg} from '../../block_svg.js'; +import {BlockStyle, Theme} from '../../theme.js'; import * as blockRendering from '../common/block_rendering.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; -import { Renderer as BaseRenderer } from '../common/renderer.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +import {Renderer as BaseRenderer} from '../common/renderer.js'; -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { HighlightConstantProvider } from './highlight_constants.js'; -import { RenderInfo } from './info.js'; -import { PathObject } from './path_object.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {HighlightConstantProvider} from './highlight_constants.js'; +import {RenderInfo} from './info.js'; +import {PathObject} from './path_object.js'; /** @@ -40,7 +39,7 @@ export class Renderer extends BaseRenderer { // AnyDuringMigration because: Type 'null' is not assignable to type // 'HighlightConstantProvider'. private highlightConstants_: HighlightConstantProvider = - null as AnyDuringMigration; + null as AnyDuringMigration; /** @param name The renderer name. */ constructor(name: string) { @@ -83,7 +82,7 @@ export class Renderer extends BaseRenderer { * @return The drawer. */ protected override makeDrawer_(block: BlockSvg, info: BaseRenderInfo): - Drawer { + Drawer { return new Drawer(block, (info as RenderInfo)); } @@ -95,7 +94,7 @@ export class Renderer extends BaseRenderer { */ override makePathObject(root: SVGElement, style: BlockStyle): PathObject { return new PathObject( - root, style, (this.getConstants() as ConstantProvider)); + root, style, (this.getConstants() as ConstantProvider)); } /** diff --git a/core/renderers/measurables/base.ts b/core/renderers/measurables/base.ts index 781b09ba6..a2ec1d4f7 100644 --- a/core/renderers/measurables/base.ts +++ b/core/renderers/measurables/base.ts @@ -13,9 +13,9 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Types } from './types.js'; +import {Types} from './types.js'; /** diff --git a/core/renderers/measurables/bottom_row.ts b/core/renderers/measurables/bottom_row.ts index 46b2bef33..140c3cbeb 100644 --- a/core/renderers/measurables/bottom_row.ts +++ b/core/renderers/measurables/bottom_row.ts @@ -17,15 +17,14 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; +/* eslint-disable-next-line no-unused-vars */ +import {ConstantProvider} from '../common/constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { NextConnection } from './next_connection.js'; -import { Row } from './row.js'; -import { Types } from './types.js'; +import {NextConnection} from './next_connection.js'; +import {Row} from './row.js'; +import {Types} from './types.js'; /** @@ -41,7 +40,7 @@ export class BottomRow extends Row { hasNextConnection = false; /** The next connection on the row, if any. */ - connection: NextConnection | null = null; + connection: NextConnection|null = null; /** * The amount that the bottom of the block extends below the horizontal diff --git a/core/renderers/measurables/connection.ts b/core/renderers/measurables/connection.ts index 131c91bdc..33e3fa0b7 100644 --- a/core/renderers/measurables/connection.ts +++ b/core/renderers/measurables/connection.ts @@ -18,12 +18,11 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +import {ConstantProvider, Shape} from '../common/constants.js'; -import { ConstantProvider, Shape } from '../common/constants.js'; - -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** * The base class to represent a connection and the space that it takes up on @@ -40,7 +39,7 @@ export class Connection extends Measurable { * represents. */ constructor( - constants: ConstantProvider, public connectionModel: RenderedConnection) { + constants: ConstantProvider, public connectionModel: RenderedConnection) { super(constants); this.shape = this.constants.shapeFor(connectionModel); diff --git a/core/renderers/measurables/external_value_input.ts b/core/renderers/measurables/external_value_input.ts index d19cc7ddd..bae5d71e7 100644 --- a/core/renderers/measurables/external_value_input.ts +++ b/core/renderers/measurables/external_value_input.ts @@ -18,12 +18,11 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../input.js'; +import {Input} from '../../input.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ConstantProvider } from '../common/constants.js'; - -import { InputConnection } from './input_connection.js'; -import { Types } from './types.js'; +import {InputConnection} from './input_connection.js'; +import {Types} from './types.js'; /** @@ -50,11 +49,11 @@ export class ExternalValueInput extends InputConnection { this.height = this.shape.height as number; } else { this.height = this.connectedBlockHeight - - this.constants.TAB_OFFSET_FROM_TOP - this.constants.MEDIUM_PADDING; + this.constants.TAB_OFFSET_FROM_TOP - this.constants.MEDIUM_PADDING; } this.width = this.shape.width as - number + this.constants.EXTERNAL_VALUE_INPUT_PADDING; + number + this.constants.EXTERNAL_VALUE_INPUT_PADDING; this.connectionOffsetY = this.constants.TAB_OFFSET_FROM_TOP; diff --git a/core/renderers/measurables/field.ts b/core/renderers/measurables/field.ts index 485339e5f..ea515b56b 100644 --- a/core/renderers/measurables/field.ts +++ b/core/renderers/measurables/field.ts @@ -18,14 +18,13 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Field as BlocklyField } from '../../field.js'; +import {Field as BlocklyField} from '../../field.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../input.js'; +import {Input} from '../../input.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ConstantProvider } from '../common/constants.js'; - -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** @@ -46,8 +45,8 @@ export class Field extends Measurable { * @param parentInput The parent input for the field. */ constructor( - constants: ConstantProvider, public field: BlocklyField, - public parentInput: Input) { + constants: ConstantProvider, public field: BlocklyField, + public parentInput: Input) { super(constants); this.isEditable = field.EDITABLE; diff --git a/core/renderers/measurables/hat.ts b/core/renderers/measurables/hat.ts index eca95bfb8..f97b4621b 100644 --- a/core/renderers/measurables/hat.ts +++ b/core/renderers/measurables/hat.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** diff --git a/core/renderers/measurables/icon.ts b/core/renderers/measurables/icon.ts index 380ff8389..4582fd0de 100644 --- a/core/renderers/measurables/icon.ts +++ b/core/renderers/measurables/icon.ts @@ -18,12 +18,11 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Icon as BlocklyIcon } from '../../icon.js'; +import {Icon as BlocklyIcon} from '../../icon.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ConstantProvider } from '../common/constants.js'; - -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** diff --git a/core/renderers/measurables/in_row_spacer.ts b/core/renderers/measurables/in_row_spacer.ts index 6928f1173..2e0566295 100644 --- a/core/renderers/measurables/in_row_spacer.ts +++ b/core/renderers/measurables/in_row_spacer.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** diff --git a/core/renderers/measurables/inline_input.ts b/core/renderers/measurables/inline_input.ts index 934cc6a9a..7298dca51 100644 --- a/core/renderers/measurables/inline_input.ts +++ b/core/renderers/measurables/inline_input.ts @@ -18,12 +18,11 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../input.js'; +import {Input} from '../../input.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ConstantProvider } from '../common/constants.js'; - -import { InputConnection } from './input_connection.js'; -import { Types } from './types.js'; +import {InputConnection} from './input_connection.js'; +import {Types} from './types.js'; /** @@ -55,22 +54,22 @@ export class InlineInput extends InputConnection { } this.connectionHeight = !this.isDynamicShape ? - this.shape.height as number : - (this.shape.height as (p1: number) => number)(this.height); + this.shape.height as number : + (this.shape.height as (p1: number) => number)(this.height); this.connectionWidth = !this.isDynamicShape ? - this.shape.width as number : - (this.shape.width as (p1: number) => number)(this.height); + this.shape.width as number : + (this.shape.width as (p1: number) => number)(this.height); if (!this.connectedBlock) { this.width += this.connectionWidth * (this.isDynamicShape ? 2 : 1); } this.connectionOffsetY = 'connectionOffsetY' in this.shape ? - this.shape.connectionOffsetY(this.connectionHeight) : - this.constants.TAB_OFFSET_FROM_TOP; + this.shape.connectionOffsetY(this.connectionHeight) : + this.constants.TAB_OFFSET_FROM_TOP; this.connectionOffsetX = 'connectionOffsetX' in this.shape ? - this.shape.connectionOffsetX(this.connectionWidth) : - 0; + this.shape.connectionOffsetX(this.connectionWidth) : + 0; } } diff --git a/core/renderers/measurables/input_connection.ts b/core/renderers/measurables/input_connection.ts index a2a48e1da..912086a76 100644 --- a/core/renderers/measurables/input_connection.ts +++ b/core/renderers/measurables/input_connection.ts @@ -15,17 +15,16 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../input.js'; +import {Input} from '../../input.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +/* eslint-disable-next-line no-unused-vars */ +import {ConstantProvider} from '../common/constants.js'; -/* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; - -import { Connection } from './connection.js'; -import { Types } from './types.js'; +import {Connection} from './connection.js'; +import {Types} from './types.js'; /** @@ -35,7 +34,7 @@ import { Types } from './types.js'; */ export class InputConnection extends Connection { align: number; - connectedBlock: BlockSvg | null; + connectedBlock: BlockSvg|null; connectedBlockWidth: number; connectedBlockHeight: number; connectionOffsetX: number = 0; @@ -53,9 +52,9 @@ export class InputConnection extends Connection { this.align = input.align; this.connectedBlock = - (input.connection && input.connection.targetBlock() ? - input.connection.targetBlock() as BlockSvg : - null); + (input.connection && input.connection.targetBlock() ? + input.connection.targetBlock() as BlockSvg : + null); if (this.connectedBlock) { const bBox = this.connectedBlock.getHeightWidth(); diff --git a/core/renderers/measurables/input_row.ts b/core/renderers/measurables/input_row.ts index 12bd47043..7b14546a9 100644 --- a/core/renderers/measurables/input_row.ts +++ b/core/renderers/measurables/input_row.ts @@ -16,13 +16,13 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ExternalValueInput } from './external_value_input.js'; -import { InputConnection } from './input_connection.js'; -import { Row } from './row.js'; -import { StatementInput } from './statement_input.js'; -import { Types } from './types.js'; +import {ExternalValueInput} from './external_value_input.js'; +import {InputConnection} from './input_connection.js'; +import {Row} from './row.js'; +import {StatementInput} from './statement_input.js'; +import {Types} from './types.js'; /** @@ -54,10 +54,10 @@ export class InputRow extends Row { if (Types.isStatementInput(elem) && elem instanceof StatementInput) { connectedBlockWidths += elem.connectedBlockWidth; } else if ( - Types.isExternalInput(elem) && elem instanceof ExternalValueInput && - elem.connectedBlockWidth !== 0) { + Types.isExternalInput(elem) && elem instanceof ExternalValueInput && + elem.connectedBlockWidth !== 0) { connectedBlockWidths += - elem.connectedBlockWidth - elem.connectionWidth; + elem.connectedBlockWidth - elem.connectionWidth; } } if (!Types.isSpacer(elem)) { diff --git a/core/renderers/measurables/jagged_edge.ts b/core/renderers/measurables/jagged_edge.ts index 027d22564..871308757 100644 --- a/core/renderers/measurables/jagged_edge.ts +++ b/core/renderers/measurables/jagged_edge.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** diff --git a/core/renderers/measurables/next_connection.ts b/core/renderers/measurables/next_connection.ts index 96c992a56..a73b78060 100644 --- a/core/renderers/measurables/next_connection.ts +++ b/core/renderers/measurables/next_connection.ts @@ -16,13 +16,12 @@ * @class */ /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; - +import {RenderedConnection} from '../../rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Connection } from './connection.js'; -import { Types } from './types.js'; +import {Connection} from './connection.js'; +import {Types} from './types.js'; /** @@ -38,7 +37,7 @@ export class NextConnection extends Connection { * represents. */ constructor( - constants: ConstantProvider, connectionModel: RenderedConnection) { + constants: ConstantProvider, connectionModel: RenderedConnection) { super(constants, connectionModel); this.type |= Types.NEXT_CONNECTION; this.height = this.shape.height as number; diff --git a/core/renderers/measurables/output_connection.ts b/core/renderers/measurables/output_connection.ts index 93ab5ede2..2b7d12800 100644 --- a/core/renderers/measurables/output_connection.ts +++ b/core/renderers/measurables/output_connection.ts @@ -39,13 +39,12 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; - +import {RenderedConnection} from '../../rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Connection } from './connection.js'; -import { Types } from './types.js'; +import {Connection} from './connection.js'; +import {Types} from './types.js'; /** @@ -65,7 +64,7 @@ export class OutputConnection extends Connection { * represents. */ constructor( - constants: ConstantProvider, connectionModel: RenderedConnection) { + constants: ConstantProvider, connectionModel: RenderedConnection) { super(constants, connectionModel); this.type |= Types.OUTPUT_CONNECTION; diff --git a/core/renderers/measurables/previous_connection.ts b/core/renderers/measurables/previous_connection.ts index c92c12351..802ea15bd 100644 --- a/core/renderers/measurables/previous_connection.ts +++ b/core/renderers/measurables/previous_connection.ts @@ -17,13 +17,12 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; - +import {RenderedConnection} from '../../rendered_connection.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Connection } from './connection.js'; -import { Types } from './types.js'; +import {Connection} from './connection.js'; +import {Types} from './types.js'; /** @@ -39,7 +38,7 @@ export class PreviousConnection extends Connection { * represents. */ constructor( - constants: ConstantProvider, connectionModel: RenderedConnection) { + constants: ConstantProvider, connectionModel: RenderedConnection) { super(constants, connectionModel); this.type |= Types.PREVIOUS_CONNECTION; this.height = this.shape.height as number; diff --git a/core/renderers/measurables/round_corner.ts b/core/renderers/measurables/round_corner.ts index 584b040af..610b252ab 100644 --- a/core/renderers/measurables/round_corner.ts +++ b/core/renderers/measurables/round_corner.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** @@ -37,9 +37,9 @@ export class RoundCorner extends Measurable { constructor(constants: ConstantProvider, opt_position?: string) { super(constants); this.type = - (!opt_position || opt_position === 'left' ? Types.LEFT_ROUND_CORNER : - Types.RIGHT_ROUND_CORNER) | - Types.CORNER; + (!opt_position || opt_position === 'left' ? Types.LEFT_ROUND_CORNER : + Types.RIGHT_ROUND_CORNER) | + Types.CORNER; this.width = this.constants.CORNER_RADIUS; // The rounded corner extends into the next row by 4 so we only take the // height that is aligned with this row. diff --git a/core/renderers/measurables/row.ts b/core/renderers/measurables/row.ts index 47a45dba6..3232135f8 100644 --- a/core/renderers/measurables/row.ts +++ b/core/renderers/measurables/row.ts @@ -13,15 +13,15 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { Measurable } from './base.js'; +import {Measurable} from './base.js'; /* eslint-disable-next-line no-unused-vars */ -import { InRowSpacer } from './in_row_spacer.js'; +import {InRowSpacer} from './in_row_spacer.js'; /* eslint-disable-next-line no-unused-vars */ -import { InputConnection } from './input_connection.js'; -import { Types } from './types.js'; +import {InputConnection} from './input_connection.js'; +import {Types} from './types.js'; /** @@ -95,7 +95,7 @@ export class Row { notchOffset: number; /** Alignment of the row. */ - align: number | null = null; + align: number|null = null; /** @param constants_ The rendering constants provider. */ constructor(protected readonly constants_: ConstantProvider) { diff --git a/core/renderers/measurables/spacer_row.ts b/core/renderers/measurables/spacer_row.ts index 0b4899385..c2de76a6d 100644 --- a/core/renderers/measurables/spacer_row.ts +++ b/core/renderers/measurables/spacer_row.ts @@ -13,11 +13,11 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { InRowSpacer } from './in_row_spacer.js'; -import { Row } from './row.js'; -import { Types } from './types.js'; +import {InRowSpacer} from './in_row_spacer.js'; +import {Row} from './row.js'; +import {Types} from './types.js'; /** @@ -39,8 +39,8 @@ export class SpacerRow extends Row { * @param width The width of the spacer. */ constructor( - constants: ConstantProvider, public override height: number, - public override width: number) { + constants: ConstantProvider, public override height: number, + public override width: number) { super(constants); this.type |= Types.SPACER | Types.BETWEEN_ROW_SPACER; diff --git a/core/renderers/measurables/square_corner.ts b/core/renderers/measurables/square_corner.ts index c91cde904..a42c8d9be 100644 --- a/core/renderers/measurables/square_corner.ts +++ b/core/renderers/measurables/square_corner.ts @@ -17,10 +17,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Measurable } from './base.js'; -import { Types } from './types.js'; +import {Measurable} from './base.js'; +import {Types} from './types.js'; /** @@ -37,9 +37,9 @@ export class SquareCorner extends Measurable { constructor(constants: ConstantProvider, opt_position?: string) { super(constants); this.type = - (!opt_position || opt_position === 'left' ? Types.LEFT_SQUARE_CORNER : - Types.RIGHT_SQUARE_CORNER) | - Types.CORNER; + (!opt_position || opt_position === 'left' ? Types.LEFT_SQUARE_CORNER : + Types.RIGHT_SQUARE_CORNER) | + Types.CORNER; this.height = this.constants.NO_PADDING; this.width = this.constants.NO_PADDING; } diff --git a/core/renderers/measurables/statement_input.ts b/core/renderers/measurables/statement_input.ts index 3e856ef75..3b655758d 100644 --- a/core/renderers/measurables/statement_input.ts +++ b/core/renderers/measurables/statement_input.ts @@ -17,12 +17,11 @@ */ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../input.js'; +import {Input} from '../../input.js'; +import {ConstantProvider} from '../common/constants.js'; -import { ConstantProvider } from '../common/constants.js'; - -import { InputConnection } from './input_connection.js'; -import { Types } from './types.js'; +import {InputConnection} from './input_connection.js'; +import {Types} from './types.js'; /** @@ -46,9 +45,9 @@ export class StatementInput extends InputConnection { // We allow the dark path to show on the parent block so that the child // block looks embossed. This takes up an extra pixel in both x and y. this.height = - this.connectedBlockHeight + this.constants.STATEMENT_BOTTOM_SPACER; + this.connectedBlockHeight + this.constants.STATEMENT_BOTTOM_SPACER; } this.width = this.constants.STATEMENT_INPUT_NOTCH_OFFSET + - (this.shape.width as number); + (this.shape.width as number); } } diff --git a/core/renderers/measurables/top_row.ts b/core/renderers/measurables/top_row.ts index 78ed1b71a..2fed200c1 100644 --- a/core/renderers/measurables/top_row.ts +++ b/core/renderers/measurables/top_row.ts @@ -13,16 +13,15 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - +import {BlockSvg} from '../../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../common/constants.js'; +import {ConstantProvider} from '../common/constants.js'; -import { Hat } from './hat.js'; +import {Hat} from './hat.js'; /* eslint-disable-next-line no-unused-vars */ -import { PreviousConnection } from './previous_connection.js'; -import { Row } from './row.js'; -import { Types } from './types.js'; +import {PreviousConnection} from './previous_connection.js'; +import {Row} from './row.js'; +import {Types} from './types.js'; /** @@ -50,7 +49,7 @@ export class TopRow extends Row { hasPreviousConnection = false; /** The previous connection on the block, if any. */ - connection: PreviousConnection | null = null; + connection: PreviousConnection|null = null; override widthWithConnectedBlocks: AnyDuringMigration; /** @param constants The rendering constants provider. */ @@ -67,13 +66,12 @@ export class TopRow extends Row { */ hasLeftSquareCorner(block: BlockSvg): boolean { const hasHat = - (block.hat ? block.hat === 'cap' : - this.constants_.ADD_START_HATS) && - !block.outputConnection && !block.previousConnection; + (block.hat ? block.hat === 'cap' : this.constants_.ADD_START_HATS) && + !block.outputConnection && !block.previousConnection; const prevBlock = block.getPreviousBlock(); return !!block.outputConnection || hasHat || - (prevBlock ? prevBlock.getNextBlock() === block : false); + (prevBlock ? prevBlock.getNextBlock() === block : false); } /** diff --git a/core/renderers/measurables/types.ts b/core/renderers/measurables/types.ts index 1868577eb..f2c66c097 100644 --- a/core/renderers/measurables/types.ts +++ b/core/renderers/measurables/types.ts @@ -13,9 +13,9 @@ * @namespace Blockly.blockRendering.Types */ /* eslint-disable-next-line no-unused-vars */ -import { Measurable } from './base.js'; +import {Measurable} from './base.js'; /* eslint-disable-next-line no-unused-vars */ -import { Row } from './row.js'; +import {Row} from './row.js'; /** @@ -23,7 +23,7 @@ import { Row } from './row.js'; * @alias Blockly.blockRendering.Types */ class TypesContainer { - [index: string]: number | Function; + [index: string]: number|Function; NONE = 0; // None @@ -135,7 +135,7 @@ class TypesContainer { * @param elem The element to check. * @return 1 if the object stores information about a spacer. */ - isSpacer(elem: Measurable | Row): number { + isSpacer(elem: Measurable|Row): number { return elem.type & this.SPACER; } @@ -203,7 +203,8 @@ class TypesContainer { } /** - * Whether a measurable stores information about a previous or next connection. + * Whether a measurable stores information about a previous or next + * connection. * @param elem The element to check. * @return 1 if the object stores information about a previous or next * connection. diff --git a/core/renderers/minimalist/constants.ts b/core/renderers/minimalist/constants.ts index 7ba0ca0c9..878e81b88 100644 --- a/core/renderers/minimalist/constants.ts +++ b/core/renderers/minimalist/constants.ts @@ -16,7 +16,7 @@ * @class */ -import { ConstantProvider as BaseConstantProvider } from '../common/constants.js'; +import {ConstantProvider as BaseConstantProvider} from '../common/constants.js'; /** diff --git a/core/renderers/minimalist/drawer.ts b/core/renderers/minimalist/drawer.ts index 289df31ef..a971fdd5c 100644 --- a/core/renderers/minimalist/drawer.ts +++ b/core/renderers/minimalist/drawer.ts @@ -13,12 +13,11 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - -import { Drawer as BaseDrawer } from '../common/drawer.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Drawer as BaseDrawer} from '../common/drawer.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /** diff --git a/core/renderers/minimalist/info.ts b/core/renderers/minimalist/info.ts index c6e8cc762..6215e1e2b 100644 --- a/core/renderers/minimalist/info.ts +++ b/core/renderers/minimalist/info.ts @@ -13,12 +13,11 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; +import {BlockSvg} from '../../block_svg.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; /* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderer.js'; +import {Renderer} from './renderer.js'; /** diff --git a/core/renderers/minimalist/minimalist.ts b/core/renderers/minimalist/minimalist.ts index fd1dbc082..fe563b138 100644 --- a/core/renderers/minimalist/minimalist.ts +++ b/core/renderers/minimalist/minimalist.ts @@ -12,9 +12,9 @@ * @namespace Blockly.minimalist */ -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { RenderInfo } from './info.js'; -import { Renderer } from './renderer.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {RenderInfo} from './info.js'; +import {Renderer} from './renderer.js'; -export { ConstantProvider, Drawer, Renderer, RenderInfo }; +export {ConstantProvider, Drawer, Renderer, RenderInfo}; diff --git a/core/renderers/minimalist/renderer.ts b/core/renderers/minimalist/renderer.ts index 582caed1e..15998fe9d 100644 --- a/core/renderers/minimalist/renderer.ts +++ b/core/renderers/minimalist/renderer.ts @@ -13,16 +13,15 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - +import {BlockSvg} from '../../block_svg.js'; import * as blockRendering from '../common/block_rendering.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; -import { Renderer as BaseRenderer } from '../common/renderer.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +import {Renderer as BaseRenderer} from '../common/renderer.js'; -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { RenderInfo } from './info.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {RenderInfo} from './info.js'; /** @@ -60,7 +59,7 @@ export class Renderer extends BaseRenderer { * @return The drawer. */ protected override makeDrawer_(block: BlockSvg, info: BaseRenderInfo): - Drawer { + Drawer { return new Drawer(block, (info as RenderInfo)); } } diff --git a/core/renderers/thrasos/info.ts b/core/renderers/thrasos/info.ts index ae17e3b10..3cc724bdf 100644 --- a/core/renderers/thrasos/info.ts +++ b/core/renderers/thrasos/info.ts @@ -17,22 +17,21 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; -import { Measurable } from '../measurables/base.js'; +import {BlockSvg} from '../../block_svg.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +import {Measurable} from '../measurables/base.js'; /* eslint-disable-next-line no-unused-vars */ -import { BottomRow } from '../measurables/bottom_row.js'; +import {BottomRow} from '../measurables/bottom_row.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from '../measurables/field.js'; -import { InRowSpacer } from '../measurables/in_row_spacer.js'; -import { Row } from '../measurables/row.js'; +import {Field} from '../measurables/field.js'; +import {InRowSpacer} from '../measurables/in_row_spacer.js'; +import {Row} from '../measurables/row.js'; /* eslint-disable-next-line no-unused-vars */ -import { TopRow } from '../measurables/top_row.js'; -import { Types } from '../measurables/types.js'; +import {TopRow} from '../measurables/top_row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderer.js'; +import {Renderer} from './renderer.js'; /** @@ -83,7 +82,7 @@ export class RenderInfo extends BaseRenderInfo { if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. row.elements.push(new InRowSpacer( - this.constants_, this.getInRowSpacing_(null, oldElems[0]))); + this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { continue; @@ -96,7 +95,7 @@ export class RenderInfo extends BaseRenderInfo { row.elements.push(oldElems[oldElems.length - 1]); if (row.endsWithElemSpacer()) { let spacing = - this.getInRowSpacing_(oldElems[oldElems.length - 1], null); + this.getInRowSpacing_(oldElems[oldElems.length - 1], null); if (hasExternalInputs && row.hasDummyInput) { spacing += this.constants_.TAB_WIDTH; } @@ -106,7 +105,7 @@ export class RenderInfo extends BaseRenderInfo { } } - override getInRowSpacing_(prev: Measurable | null, next: Measurable | null) { + override getInRowSpacing_(prev: Measurable|null, next: Measurable|null) { if (!prev) { // Between an editable field and the beginning of the row. if (next && Types.isField(next) && (next as Field).isEditable) { @@ -229,7 +228,7 @@ export class RenderInfo extends BaseRenderInfo { // Spacing between two fields of the same editability. if (Types.isField(prev) && next && Types.isField(next) && - (prev as Field).isEditable === (next as Field).isEditable) { + (prev as Field).isEditable === (next as Field).isEditable) { return this.constants_.LARGE_PADDING; } @@ -272,7 +271,7 @@ export class RenderInfo extends BaseRenderInfo { if (Types.isBottomRow(row)) { const bottomRow = row as BottomRow; const baseline = - bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; + bottomRow.yPos + bottomRow.height - bottomRow.descenderHeight; if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -291,7 +290,7 @@ export class RenderInfo extends BaseRenderInfo { let result = row.yPos; if (Types.isField(elem) && row.hasStatement) { const offset = - this.constants_.TALL_INPUT_FIELD_OFFSET_Y + elem.height / 2; + this.constants_.TALL_INPUT_FIELD_OFFSET_Y + elem.height / 2; result += offset; } else { result += row.height / 2; @@ -312,11 +311,11 @@ export class RenderInfo extends BaseRenderInfo { yCursor += row.height; widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); + Math.max(widestRowWithConnectedBlocks, row.widthWithConnectedBlocks); // Add padding to the bottom row if block height is less than minimum const heightWithoutHat = yCursor - this.topRow.ascenderHeight; if (row === this.bottomRow && - heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) { + heightWithoutHat < this.constants_.MIN_BLOCK_HEIGHT) { // But the hat height shouldn't be part of this. const diff = this.constants_.MIN_BLOCK_HEIGHT - heightWithoutHat; this.bottomRow.height += diff; @@ -325,11 +324,11 @@ export class RenderInfo extends BaseRenderInfo { this.recordElemPositions_(row); } if (this.outputConnection && this.block_.nextConnection && - this.block_.nextConnection.isConnected()) { + this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. widestRowWithConnectedBlocks = Math.max( - widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width); + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width); } this.bottomRow.baseline = yCursor - this.bottomRow.descenderHeight; diff --git a/core/renderers/thrasos/renderer.ts b/core/renderers/thrasos/renderer.ts index 616946dd6..d44142390 100644 --- a/core/renderers/thrasos/renderer.ts +++ b/core/renderers/thrasos/renderer.ts @@ -13,12 +13,11 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; - +import {BlockSvg} from '../../block_svg.js'; import * as blockRendering from '../common/block_rendering.js'; -import { Renderer as BaseRenderer } from '../common/renderer.js'; +import {Renderer as BaseRenderer} from '../common/renderer.js'; -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /** diff --git a/core/renderers/thrasos/thrasos.ts b/core/renderers/thrasos/thrasos.ts index 0600b7e76..1c849bc46 100644 --- a/core/renderers/thrasos/thrasos.ts +++ b/core/renderers/thrasos/thrasos.ts @@ -12,7 +12,7 @@ * @namespace Blockly.thrasos */ -import { RenderInfo } from './info.js'; -import { Renderer } from './renderer.js'; +import {RenderInfo} from './info.js'; +import {Renderer} from './renderer.js'; -export { Renderer, RenderInfo }; +export {Renderer, RenderInfo}; diff --git a/core/renderers/zelos/constants.ts b/core/renderers/zelos/constants.ts index cab10614c..c5a441412 100644 --- a/core/renderers/zelos/constants.ts +++ b/core/renderers/zelos/constants.ts @@ -15,16 +15,15 @@ * mode. * @class */ -import { ConnectionType } from '../../connection_type.js'; -import { RenderedConnection } from '../../rendered_connection.js'; -import { Theme } from '../../theme.js'; +import {ConnectionType} from '../../connection_type.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +import {Theme} from '../../theme.js'; import * as utilsColour from '../../utils/colour.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; - /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider as BaseConstantProvider, Shape } from '../common/constants.js'; +import {ConstantProvider as BaseConstantProvider, Shape} from '../common/constants.js'; /** An object containing sizing and path information about inside corners. */ export interface InsideCorners { @@ -84,7 +83,7 @@ export class ConstantProvider extends BaseConstantProvider { override START_HAT_WIDTH = 96; - override SHAPES = { HEXAGONAL: 1, ROUND: 2, SQUARE: 3, PUZZLE: 4, NOTCH: 5 }; + override SHAPES = {HEXAGONAL: 1, ROUND: 2, SQUARE: 3, PUZZLE: 4, NOTCH: 5}; SHAPE_IN_SHAPE_PADDING: AnyDuringMigration; override FULL_BLOCK_FIELDS = true; @@ -93,7 +92,7 @@ export class ConstantProvider extends BaseConstantProvider { override FIELD_TEXT_FONTWEIGHT = 'bold'; override FIELD_TEXT_FONTFAMILY = - '"Helvetica Neue", "Segoe UI", Helvetica, sans-serif'; + '"Helvetica Neue", "Segoe UI", Helvetica, sans-serif'; override FIELD_BORDER_RECT_RADIUS: AnyDuringMigration; override FIELD_BORDER_RECT_X_PADDING: AnyDuringMigration; override FIELD_BORDER_RECT_Y_PADDING: AnyDuringMigration; @@ -156,19 +155,19 @@ export class ConstantProvider extends BaseConstantProvider { * The object containing information about the hexagon used for a boolean * reporter block. Null before init is called. */ - HEXAGONAL: Shape | null = null; + HEXAGONAL: Shape|null = null; /** * The object containing information about the hexagon used for a number or * string reporter block. Null before init is called. */ - ROUNDED: Shape | null = null; + ROUNDED: Shape|null = null; /** * The object containing information about the hexagon used for a * rectangular reporter block. Null before init is called. */ - SQUARED: Shape | null = null; + SQUARED: Shape|null = null; constructor() { super(); @@ -282,7 +281,7 @@ export class ConstantProvider extends BaseConstantProvider { super.setFontConstants_(theme); this.FIELD_BORDER_RECT_HEIGHT = - this.FIELD_TEXT_HEIGHT + this.FIELD_BORDER_RECT_Y_PADDING * 2; + this.FIELD_TEXT_HEIGHT + this.FIELD_BORDER_RECT_Y_PADDING * 2; this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT = this.FIELD_BORDER_RECT_HEIGHT; } @@ -293,26 +292,26 @@ export class ConstantProvider extends BaseConstantProvider { this.SQUARED = this.makeSquared(); this.STATEMENT_INPUT_NOTCH_OFFSET = this.NOTCH_OFFSET_LEFT + - (this.INSIDE_CORNERS as InsideCorners).rightWidth; + (this.INSIDE_CORNERS as InsideCorners).rightWidth; } override setDynamicProperties_(theme: Theme) { super.setDynamicProperties_(theme); this.SELECTED_GLOW_COLOUR = theme.getComponentStyle('selectedGlowColour') || - this.SELECTED_GLOW_COLOUR; + this.SELECTED_GLOW_COLOUR; const selectedGlowSize = - Number(theme.getComponentStyle('selectedGlowSize')); + Number(theme.getComponentStyle('selectedGlowSize')); this.SELECTED_GLOW_SIZE = selectedGlowSize && !isNaN(selectedGlowSize) ? - selectedGlowSize : - this.SELECTED_GLOW_SIZE; + selectedGlowSize : + this.SELECTED_GLOW_SIZE; this.REPLACEMENT_GLOW_COLOUR = - theme.getComponentStyle('replacementGlowColour') || - this.REPLACEMENT_GLOW_COLOUR; + theme.getComponentStyle('replacementGlowColour') || + this.REPLACEMENT_GLOW_COLOUR; const replacementGlowSize = - Number(theme.getComponentStyle('replacementGlowSize')); + Number(theme.getComponentStyle('replacementGlowSize')); this.REPLACEMENT_GLOW_SIZE = - replacementGlowSize && !isNaN(replacementGlowSize) ? + replacementGlowSize && !isNaN(replacementGlowSize) ? replacementGlowSize : this.REPLACEMENT_GLOW_SIZE; } @@ -336,7 +335,7 @@ export class ConstantProvider extends BaseConstantProvider { svgPaths.point(71, -height), svgPaths.point(width, 0), ]); - return { height, width, path: mainPath }; + return {height, width, path: mainPath}; } /** @@ -366,7 +365,7 @@ export class ConstantProvider extends BaseConstantProvider { const direction = right ? -1 : 1; const dy = forward * height / 2; return svgPaths.lineTo(-direction * width, dy) + - svgPaths.lineTo(direction * width, dy); + svgPaths.lineTo(direction * width, dy); } return { @@ -424,19 +423,19 @@ export class ConstantProvider extends BaseConstantProvider { * @return A path fragment describing a rounded connection. */ function makeMainPath( - blockHeight: number, up: boolean, right: boolean): string { + blockHeight: number, up: boolean, right: boolean): string { const remainingHeight = - blockHeight > maxHeight ? blockHeight - maxHeight : 0; + blockHeight > maxHeight ? blockHeight - maxHeight : 0; const height = blockHeight > maxHeight ? maxHeight : blockHeight; const radius = height / 2; return svgPaths.arc( - 'a', '0 0,1', radius, - svgPaths.point( - (up ? -1 : 1) * radius, (up ? -1 : 1) * radius)) + - svgPaths.lineOnAxis('v', (right ? 1 : -1) * remainingHeight) + - svgPaths.arc( - 'a', '0 0,1', radius, - svgPaths.point((up ? 1 : -1) * radius, (up ? -1 : 1) * radius)); + 'a', '0 0,1', radius, + svgPaths.point( + (up ? -1 : 1) * radius, (up ? -1 : 1) * radius)) + + svgPaths.lineOnAxis('v', (right ? 1 : -1) * remainingHeight) + + svgPaths.arc( + 'a', '0 0,1', radius, + svgPaths.point((up ? 1 : -1) * radius, (up ? -1 : 1) * radius)); } return { @@ -494,13 +493,13 @@ export class ConstantProvider extends BaseConstantProvider { function makeMainPath(height: number, up: boolean, right: boolean): string { const innerHeight = height - radius * 2; return svgPaths.arc( - 'a', '0 0,1', radius, - svgPaths.point( - (up ? -1 : 1) * radius, (up ? -1 : 1) * radius)) + - svgPaths.lineOnAxis('v', (right ? 1 : -1) * innerHeight) + - svgPaths.arc( - 'a', '0 0,1', radius, - svgPaths.point((up ? 1 : -1) * radius, (up ? -1 : 1) * radius)); + 'a', '0 0,1', radius, + svgPaths.point( + (up ? -1 : 1) * radius, (up ? -1 : 1) * radius)) + + svgPaths.lineOnAxis('v', (right ? 1 : -1) * innerHeight) + + svgPaths.arc( + 'a', '0 0,1', radius, + svgPaths.point((up ? 1 : -1) * radius, (up ? -1 : 1) * radius)); } return { @@ -591,34 +590,34 @@ export class ConstantProvider extends BaseConstantProvider { */ function makeMainPath(dir: number): string { return svgPaths.curve( - 'c', - [ - svgPaths.point(dir * curveWidth / 2, 0), - svgPaths.point(dir * curveWidth * 3 / 4, quarterHeight / 2), - svgPaths.point(dir * curveWidth, quarterHeight), - ]) + - svgPaths.line([svgPaths.point(dir * curveWidth, halfHeight)]) + - svgPaths.curve( - 'c', - [ - svgPaths.point(dir * curveWidth / 4, quarterHeight / 2), - svgPaths.point(dir * curveWidth / 2, quarterHeight), - svgPaths.point(dir * curveWidth, quarterHeight), - ]) + - svgPaths.lineOnAxis('h', dir * innerWidth) + - svgPaths.curve( - 'c', - [ - svgPaths.point(dir * curveWidth / 2, 0), - svgPaths.point(dir * curveWidth * 3 / 4, -(quarterHeight / 2)), + 'c', + [ + svgPaths.point(dir * curveWidth / 2, 0), + svgPaths.point(dir * curveWidth * 3 / 4, quarterHeight / 2), + svgPaths.point(dir * curveWidth, quarterHeight), + ]) + + svgPaths.line([svgPaths.point(dir * curveWidth, halfHeight)]) + + svgPaths.curve( + 'c', + [ + svgPaths.point(dir * curveWidth / 4, quarterHeight / 2), + svgPaths.point(dir * curveWidth / 2, quarterHeight), + svgPaths.point(dir * curveWidth, quarterHeight), + ]) + + svgPaths.lineOnAxis('h', dir * innerWidth) + + svgPaths.curve( + 'c', + [ + svgPaths.point(dir * curveWidth / 2, 0), + svgPaths.point(dir * curveWidth * 3 / 4, -(quarterHeight / 2)), + svgPaths.point(dir * curveWidth, -quarterHeight), + ]) + + svgPaths.line([svgPaths.point(dir * curveWidth, -halfHeight)]) + + svgPaths.curve('c', [ + svgPaths.point(dir * curveWidth / 4, -(quarterHeight / 2)), + svgPaths.point(dir * curveWidth / 2, -quarterHeight), svgPaths.point(dir * curveWidth, -quarterHeight), - ]) + - svgPaths.line([svgPaths.point(dir * curveWidth, -halfHeight)]) + - svgPaths.curve('c', [ - svgPaths.point(dir * curveWidth / 4, -(quarterHeight / 2)), - svgPaths.point(dir * curveWidth / 2, -quarterHeight), - svgPaths.point(dir * curveWidth, -quarterHeight), - ]); + ]); } const pathLeft = makeMainPath(1); @@ -637,16 +636,16 @@ export class ConstantProvider extends BaseConstantProvider { const radius = this.CORNER_RADIUS; const innerTopLeftCorner = - svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); const innerTopRightCorner = - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); const innerBottomLeftCorner = - svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); const innerBottomRightCorner = - svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); return { width: radius, @@ -679,89 +678,89 @@ export class ConstantProvider extends BaseConstantProvider { // Using a dilate distorts the block shape. // Instead use a gaussian blur, and then set all alpha to 1 with a transfer. const selectedGlowFilter = dom.createSvgElement( - Svg.FILTER, { - 'id': 'blocklySelectedGlowFilter' + this.randomIdentifier, - 'height': '160%', - 'width': '180%', - 'y': '-30%', - 'x': '-40%', - }, - defs); + Svg.FILTER, { + 'id': 'blocklySelectedGlowFilter' + this.randomIdentifier, + 'height': '160%', + 'width': '180%', + 'y': '-30%', + 'x': '-40%', + }, + defs); dom.createSvgElement( - Svg.FEGAUSSIANBLUR, - { 'in': 'SourceGraphic', 'stdDeviation': this.SELECTED_GLOW_SIZE }, - selectedGlowFilter); + Svg.FEGAUSSIANBLUR, + {'in': 'SourceGraphic', 'stdDeviation': this.SELECTED_GLOW_SIZE}, + selectedGlowFilter); // Set all gaussian blur pixels to 1 opacity before applying flood const selectedComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, { 'result': 'outBlur' }, selectedGlowFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, selectedGlowFilter); dom.createSvgElement( - Svg.FEFUNCA, - { 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' }, - selectedComponentTransfer); + Svg.FEFUNCA, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, + selectedComponentTransfer); // Color the highlight dom.createSvgElement( - Svg.FEFLOOD, { - 'flood-color': this.SELECTED_GLOW_COLOUR, - 'flood-opacity': 1, - 'result': 'outColor', - }, - selectedGlowFilter); + Svg.FEFLOOD, { + 'flood-color': this.SELECTED_GLOW_COLOUR, + 'flood-opacity': 1, + 'result': 'outColor', + }, + selectedGlowFilter); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'outColor', - 'in2': 'outBlur', - 'operator': 'in', - 'result': 'outGlow', - }, - selectedGlowFilter); + Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow', + }, + selectedGlowFilter); this.selectedGlowFilterId = selectedGlowFilter.id; this.selectedGlowFilter_ = selectedGlowFilter; // Using a dilate distorts the block shape. // Instead use a gaussian blur, and then set all alpha to 1 with a transfer. const replacementGlowFilter = dom.createSvgElement( - Svg.FILTER, { - 'id': 'blocklyReplacementGlowFilter' + this.randomIdentifier, - 'height': '160%', - 'width': '180%', - 'y': '-30%', - 'x': '-40%', - }, - defs); + Svg.FILTER, { + 'id': 'blocklyReplacementGlowFilter' + this.randomIdentifier, + 'height': '160%', + 'width': '180%', + 'y': '-30%', + 'x': '-40%', + }, + defs); dom.createSvgElement( - Svg.FEGAUSSIANBLUR, - { 'in': 'SourceGraphic', 'stdDeviation': this.REPLACEMENT_GLOW_SIZE }, - replacementGlowFilter); + Svg.FEGAUSSIANBLUR, + {'in': 'SourceGraphic', 'stdDeviation': this.REPLACEMENT_GLOW_SIZE}, + replacementGlowFilter); // Set all gaussian blur pixels to 1 opacity before applying flood const replacementComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, { 'result': 'outBlur' }, replacementGlowFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, replacementGlowFilter); dom.createSvgElement( - Svg.FEFUNCA, - { 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' }, - replacementComponentTransfer); + Svg.FEFUNCA, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, + replacementComponentTransfer); // Color the highlight dom.createSvgElement( - Svg.FEFLOOD, { - 'flood-color': this.REPLACEMENT_GLOW_COLOUR, - 'flood-opacity': 1, - 'result': 'outColor', - }, - replacementGlowFilter); + Svg.FEFLOOD, { + 'flood-color': this.REPLACEMENT_GLOW_COLOUR, + 'flood-opacity': 1, + 'result': 'outColor', + }, + replacementGlowFilter); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'outColor', - 'in2': 'outBlur', - 'operator': 'in', - 'result': 'outGlow', - }, - replacementGlowFilter); + Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow', + }, + replacementGlowFilter); dom.createSvgElement( - Svg.FECOMPOSITE, { - 'in': 'SourceGraphic', - 'in2': 'outGlow', - 'operator': 'over', - }, - replacementGlowFilter); + Svg.FECOMPOSITE, { + 'in': 'SourceGraphic', + 'in2': 'outGlow', + 'operator': 'over', + }, + replacementGlowFilter); this.replacementGlowFilterId = replacementGlowFilter.id; this.replacementGlowFilter_ = replacementGlowFilter; } @@ -773,7 +772,7 @@ export class ConstantProvider extends BaseConstantProvider { selector + ' .blocklyText,', selector + ' .blocklyFlyoutLabelText {', 'font: ' + this.FIELD_TEXT_FONTWEIGHT + ' ' + this.FIELD_TEXT_FONTSIZE + - 'pt ' + this.FIELD_TEXT_FONTFAMILY + ';', + 'pt ' + this.FIELD_TEXT_FONTFAMILY + ';', '}', // Fields. diff --git a/core/renderers/zelos/drawer.ts b/core/renderers/zelos/drawer.ts index e8c10a1f9..c6b51987c 100644 --- a/core/renderers/zelos/drawer.ts +++ b/core/renderers/zelos/drawer.ts @@ -13,28 +13,27 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; import * as svgPaths from '../../utils/svg_paths.js'; - /* eslint-disable-next-line no-unused-vars */ -import { BaseShape, DynamicShape, Notch } from '../common/constants.js'; +import {BaseShape, DynamicShape, Notch} from '../common/constants.js'; import * as debug from '../common/debug.js'; -import { Drawer as BaseDrawer } from '../common/drawer.js'; -import { InlineInput } from '../measurables/inline_input.js'; +import {Drawer as BaseDrawer} from '../common/drawer.js'; +import {InlineInput} from '../measurables/inline_input.js'; /* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; +import {Row} from '../measurables/row.js'; /* eslint-disable-next-line no-unused-vars */ -import { SpacerRow } from '../measurables/spacer_row.js'; -import { Types } from '../measurables/types.js'; +import {SpacerRow} from '../measurables/spacer_row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { InsideCorners } from './constants.js'; +import {InsideCorners} from './constants.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo } from './info.js'; +import {RenderInfo} from './info.js'; /* eslint-disable-next-line no-unused-vars */ -import { StatementInput } from './measurables/inputs.js'; +import {StatementInput} from './measurables/inputs.js'; /* eslint-disable-next-line no-unused-vars */ -import { PathObject } from './path_object.js'; +import {PathObject} from './path_object.js'; /** @@ -79,16 +78,16 @@ export class Drawer extends BaseDrawer { // AnyDuringMigration because: Type 'number' is not assignable to type // 'null'. pathObject.outputShapeType = - this.info_.outputConnection.shape.type as AnyDuringMigration; + this.info_.outputConnection.shape.type as AnyDuringMigration; } pathObject.endDrawing(); } override drawOutline_() { if (this.info_.outputConnection && - this.info_.outputConnection.isDynamicShape && - !this.info_.hasStatementInput && - !this.info_.bottomRow.hasNextConnection) { + this.info_.outputConnection.isDynamicShape && + !this.info_.hasStatementInput && + !this.info_.bottomRow.hasNextConnection) { this.drawFlatTop_(); this.drawRightDynamicConnection_(); this.drawFlatBottom_(); @@ -100,7 +99,7 @@ export class Drawer extends BaseDrawer { override drawLeft_() { if (this.info_.outputConnection && - this.info_.outputConnection.isDynamicShape) { + this.info_.outputConnection.isDynamicShape) { this.drawLeftDynamicConnection_(); } else { super.drawLeft_(); @@ -120,21 +119,21 @@ export class Drawer extends BaseDrawer { const spacerRow = row as SpacerRow; if (spacerRow.precedesStatement || spacerRow.followsStatement) { const cornerHeight = - (this.constants_.INSIDE_CORNERS as InsideCorners).rightHeight; + (this.constants_.INSIDE_CORNERS as InsideCorners).rightHeight; const remainingHeight = - spacerRow.height - (spacerRow.precedesStatement ? cornerHeight : 0); + spacerRow.height - (spacerRow.precedesStatement ? cornerHeight : 0); this.outlinePath_ += - (spacerRow.followsStatement ? - (this.constants_.INSIDE_CORNERS as InsideCorners) - .pathBottomRight : - '') + - (remainingHeight > 0 ? - svgPaths.lineOnAxis('V', spacerRow.yPos + remainingHeight) : - '') + - (spacerRow.precedesStatement ? - (this.constants_.INSIDE_CORNERS as InsideCorners) - .pathTopRight : - ''); + (spacerRow.followsStatement ? + (this.constants_.INSIDE_CORNERS as InsideCorners) + .pathBottomRight : + '') + + (remainingHeight > 0 ? + svgPaths.lineOnAxis('V', spacerRow.yPos + remainingHeight) : + '') + + (spacerRow.precedesStatement ? + (this.constants_.INSIDE_CORNERS as InsideCorners) + .pathTopRight : + ''); return; } } @@ -146,7 +145,7 @@ export class Drawer extends BaseDrawer { */ protected drawRightDynamicConnection_() { this.outlinePath_ += (this.info_.outputConnection.shape as DynamicShape) - .pathRightDown(this.info_.outputConnection.height); + .pathRightDown(this.info_.outputConnection.height); } /** @@ -156,7 +155,7 @@ export class Drawer extends BaseDrawer { this.positionOutputConnection_(); this.outlinePath_ += (this.info_.outputConnection.shape as DynamicShape) - .pathUp(this.info_.outputConnection.height); + .pathUp(this.info_.outputConnection.height); // Close off the path. This draws a vertical line up to the start of the // block's path, which may be either a rounded or a sharp corner. @@ -198,10 +197,10 @@ export class Drawer extends BaseDrawer { const connectionRight = input.xPos + input.connectionWidth; const outlinePath = svgPaths.moveTo(connectionRight, yPos) + - svgPaths.lineOnAxis('h', width) + - (input.shape as DynamicShape).pathRightDown(input.height) + - svgPaths.lineOnAxis('h', -width) + - (input.shape as DynamicShape).pathUp(input.height) + 'z'; + svgPaths.lineOnAxis('h', width) + + (input.shape as DynamicShape).pathRightDown(input.height) + + svgPaths.lineOnAxis('h', -width) + + (input.shape as DynamicShape).pathUp(input.height) + 'z'; const pathObject = this.block_.pathObject as PathObject; pathObject.setOutlinePath(inputName, outlinePath); } @@ -212,21 +211,21 @@ export class Drawer extends BaseDrawer { const x = input.xPos + input.notchOffset + (input.shape as BaseShape).width; const innerTopLeftCorner = (input.shape as Notch).pathRight + - svgPaths.lineOnAxis( - 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + - this.constants_.INSIDE_CORNERS.pathTop; + svgPaths.lineOnAxis( + 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + + this.constants_.INSIDE_CORNERS.pathTop; const innerHeight = row.height - 2 * this.constants_.INSIDE_CORNERS.height; const innerBottomLeftCorner = this.constants_.INSIDE_CORNERS.pathBottom + - svgPaths.lineOnAxis( - 'h', input.notchOffset - this.constants_.INSIDE_CORNERS.width) + - (input.connectedBottomNextConnection ? '' : - (input.shape as Notch).pathLeft); + svgPaths.lineOnAxis( + 'h', input.notchOffset - this.constants_.INSIDE_CORNERS.width) + + (input.connectedBottomNextConnection ? '' : + (input.shape as Notch).pathLeft); this.outlinePath_ += svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + - svgPaths.lineOnAxis('v', innerHeight) + innerBottomLeftCorner + - svgPaths.lineOnAxis('H', row.xPos + row.width); + svgPaths.lineOnAxis('v', innerHeight) + innerBottomLeftCorner + + svgPaths.lineOnAxis('H', row.xPos + row.width); this.positionStatementInputConnection_(row); } diff --git a/core/renderers/zelos/info.ts b/core/renderers/zelos/info.ts index 6d984cdcc..b8af223f2 100644 --- a/core/renderers/zelos/info.ts +++ b/core/renderers/zelos/info.ts @@ -16,36 +16,35 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { FieldImage } from '../../field_image.js'; -import { FieldLabel } from '../../field_label.js'; -import { FieldTextInput } from '../../field_textinput.js'; -import { Align, Input } from '../../input.js'; -import { inputTypes } from '../../input_types.js'; +import {BlockSvg} from '../../block_svg.js'; +import {FieldImage} from '../../field_image.js'; +import {FieldLabel} from '../../field_label.js'; +import {FieldTextInput} from '../../field_textinput.js'; +import {Align, Input} from '../../input.js'; +import {inputTypes} from '../../input_types.js'; +/* eslint-disable-next-line no-unused-vars */ +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Measurable} from '../measurables/base.js'; +import {Field} from '../measurables/field.js'; +import {InRowSpacer} from '../measurables/in_row_spacer.js'; +import {InputConnection} from '../measurables/input_connection.js'; +/* eslint-disable-next-line no-unused-vars */ +import {Row} from '../measurables/row.js'; +/* eslint-disable-next-line no-unused-vars */ +import {SpacerRow} from '../measurables/spacer_row.js'; +import {Types} from '../measurables/types.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; +import {ConstantProvider, InsideCorners} from './constants.js'; +import {BottomRow} from './measurables/bottom_row.js'; +import {StatementInput} from './measurables/inputs.js'; +import {RightConnectionShape} from './measurables/row_elements.js'; +import {TopRow} from './measurables/top_row.js'; /* eslint-disable-next-line no-unused-vars */ -import { Measurable } from '../measurables/base.js'; -import { Field } from '../measurables/field.js'; -import { InRowSpacer } from '../measurables/in_row_spacer.js'; -import { InputConnection } from '../measurables/input_connection.js'; +import {PathObject} from './path_object.js'; /* eslint-disable-next-line no-unused-vars */ -import { Row } from '../measurables/row.js'; -/* eslint-disable-next-line no-unused-vars */ -import { SpacerRow } from '../measurables/spacer_row.js'; -import { Types } from '../measurables/types.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider, InsideCorners } from './constants.js'; -import { BottomRow } from './measurables/bottom_row.js'; -import { StatementInput } from './measurables/inputs.js'; -import { RightConnectionShape } from './measurables/row_elements.js'; -import { TopRow } from './measurables/top_row.js'; -/* eslint-disable-next-line no-unused-vars */ -import { PathObject } from './path_object.js'; -/* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderer.js'; +import {Renderer} from './renderer.js'; /** @@ -65,7 +64,7 @@ export class RenderInfo extends BaseRenderInfo { override isInline = true; isMultiRow: boolean; hasStatementInput: boolean; - rightSide: RightConnectionShape | null; + rightSide: RightConnectionShape|null; private readonly rightAlignedDummyInputs_: WeakMap; /** @@ -104,8 +103,8 @@ export class RenderInfo extends BaseRenderInfo { * An object with rendering information about the right connection shape. */ this.rightSide = this.outputConnection ? - new RightConnectionShape(this.constants_) : - null; + new RightConnectionShape(this.constants_) : + null; /** * A map of rows to right aligned dummy inputs within those rows. Used to @@ -141,7 +140,7 @@ export class RenderInfo extends BaseRenderInfo { } // A statement input or an input following one always gets a new row. if (input.type === inputTypes.STATEMENT || - lastInput.type === inputTypes.STATEMENT) { + lastInput.type === inputTypes.STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. @@ -154,19 +153,19 @@ export class RenderInfo extends BaseRenderInfo { override getDesiredRowWidth_(row: Row): number { if (row.hasStatement) { const rightCornerWidth = - (this.constants_.INSIDE_CORNERS as InsideCorners).rightWidth || 0; + (this.constants_.INSIDE_CORNERS as InsideCorners).rightWidth || 0; return this.width - this.startX - rightCornerWidth; } return super.getDesiredRowWidth_(row); } - override getInRowSpacing_(prev: Measurable | null, next: Measurable | null): - number { + override getInRowSpacing_(prev: Measurable|null, next: Measurable|null): + number { if (!prev || !next) { // No need for padding at the beginning or end of the row if the // output shape is dynamic. if (this.outputConnection && this.outputConnection.isDynamicShape && - !this.hasStatementInput && !this.bottomRow.hasNextConnection) { + !this.hasStatementInput && !this.bottomRow.hasNextConnection) { return this.constants_.NO_PADDING; } } @@ -186,7 +185,7 @@ export class RenderInfo extends BaseRenderInfo { // AnyDuringMigration because: Property 'isHat' does not exist on type // 'typeof Types'. if (prev && Types.isLeftSquareCorner(prev) && next && - (Types as AnyDuringMigration).isHat(next)) { + (Types as AnyDuringMigration).isHat(next)) { return this.constants_.NO_PADDING; } return this.constants_.MEDIUM_PADDING; @@ -201,19 +200,19 @@ export class RenderInfo extends BaseRenderInfo { const precedesStatement = Types.isInputRow(next) && next.hasStatement; if (precedesStatement || followsStatement) { const cornerHeight = - (this.constants_.INSIDE_CORNERS as InsideCorners).rightHeight || 0; + (this.constants_.INSIDE_CORNERS as InsideCorners).rightHeight || 0; const height = Math.max(this.constants_.NOTCH_HEIGHT, cornerHeight); return precedesStatement && followsStatement ? - Math.max(height, this.constants_.DUMMY_INPUT_MIN_HEIGHT) : - height; + Math.max(height, this.constants_.DUMMY_INPUT_MIN_HEIGHT) : + height; } // Top and bottom rows act as a spacer so we don't need any extra padding. if (Types.isTopRow(prev)) { const topRow = prev as TopRow; if (!topRow.hasPreviousConnection && - (!this.outputConnection || this.hasStatementInput)) { + (!this.outputConnection || this.hasStatementInput)) { return Math.abs( - this.constants_.NOTCH_HEIGHT - this.constants_.CORNER_RADIUS); + this.constants_.NOTCH_HEIGHT - this.constants_.CORNER_RADIUS); } return this.constants_.NO_PADDING; } @@ -221,15 +220,15 @@ export class RenderInfo extends BaseRenderInfo { const bottomRow = next as BottomRow; if (!this.outputConnection) { const topHeight = Math.max( - this.topRow.minHeight, - Math.max( - this.constants_.NOTCH_HEIGHT, - this.constants_.CORNER_RADIUS)) - - this.constants_.CORNER_RADIUS; + this.topRow.minHeight, + Math.max( + this.constants_.NOTCH_HEIGHT, + this.constants_.CORNER_RADIUS)) - + this.constants_.CORNER_RADIUS; return topHeight; } else if (!bottomRow.hasNextConnection && this.hasStatementInput) { return Math.abs( - this.constants_.NOTCH_HEIGHT - this.constants_.CORNER_RADIUS); + this.constants_.NOTCH_HEIGHT - this.constants_.CORNER_RADIUS); } return this.constants_.NO_PADDING; } @@ -239,7 +238,7 @@ export class RenderInfo extends BaseRenderInfo { override getSpacerRowWidth_(prev: Row, next: Row): number { const width = this.width - this.startX; if (Types.isInputRow(prev) && prev.hasStatement || - Types.isInputRow(next) && next.hasStatement) { + Types.isInputRow(next) && next.hasStatement) { return Math.max(width, this.constants_.STATEMENT_INPUT_SPACER_MIN_WIDTH); } return width; @@ -247,13 +246,13 @@ export class RenderInfo extends BaseRenderInfo { override getElemCenterline_(row: Row, elem: Measurable): number { if (row.hasStatement && !Types.isSpacer(elem) && - !Types.isStatementInput(elem)) { + !Types.isStatementInput(elem)) { return row.yPos + this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT / 2; } if (Types.isInlineInput(elem) && elem instanceof InputConnection) { const connectedBlock = elem.connectedBlock; if (connectedBlock && connectedBlock.outputConnection && - connectedBlock.nextConnection) { + connectedBlock.nextConnection) { return row.yPos + connectedBlock.height / 2; } } @@ -265,7 +264,7 @@ export class RenderInfo extends BaseRenderInfo { // other right, keep track of the right aligned dummy input so we can add // padding later. if (input.type === inputTypes.DUMMY && activeRow.hasDummyInput && - activeRow.align === Align.LEFT && input.align === Align.RIGHT) { + activeRow.align === Align.LEFT && input.align === Align.RIGHT) { this.rightAlignedDummyInputs_.set(activeRow, input); } else if (input.type === inputTypes.STATEMENT) { // Handle statements without next connections correctly. @@ -289,7 +288,7 @@ export class RenderInfo extends BaseRenderInfo { alignmentDivider = elem; } if (Types.isField(elem) && elem instanceof Field && - elem.parentInput === this.rightAlignedDummyInputs_.get(row)) { + elem.parentInput === this.rightAlignedDummyInputs_.get(row)) { break; } } @@ -309,7 +308,7 @@ export class RenderInfo extends BaseRenderInfo { */ protected adjustXPosition_() { const notchTotalWidth = - this.constants_.NOTCH_OFFSET_LEFT + this.constants_.NOTCH_WIDTH; + this.constants_.NOTCH_OFFSET_LEFT + this.constants_.NOTCH_WIDTH; let minXPos = notchTotalWidth; // Run through every input row on the block and only apply bump logic to the // first input row (if the block has prev connection) and every input row @@ -320,17 +319,17 @@ export class RenderInfo extends BaseRenderInfo { const nextSpacer = this.rows[i + 1] as SpacerRow; const hasPrevNotch = i === 2 ? !!this.topRow.hasPreviousConnection : - !!prevSpacer.followsStatement; + !!prevSpacer.followsStatement; const hasNextNotch = i + 2 >= this.rows.length - 1 ? - !!this.bottomRow.hasNextConnection : - !!nextSpacer.precedesStatement; + !!this.bottomRow.hasNextConnection : + !!nextSpacer.precedesStatement; if (Types.isInputRow(row) && row.hasStatement) { row.measure(); minXPos = row.width - row.getLastInput().width + notchTotalWidth; } else if ( - hasPrevNotch && (i === 2 || hasNextNotch) && Types.isInputRow(row) && - !row.hasStatement) { + hasPrevNotch && (i === 2 || hasNextNotch) && Types.isInputRow(row) && + !row.hasStatement) { let xCursor = row.xPos; let prevInRowSpacer = null; for (let j = 0; j < row.elements.length; j++) { @@ -340,9 +339,9 @@ export class RenderInfo extends BaseRenderInfo { } if (prevInRowSpacer && (Types.isField(elem) || Types.isInput(elem))) { if (xCursor < minXPos && - !(Types.isField(elem) && elem instanceof Field && - (elem.field instanceof FieldLabel || - elem.field instanceof FieldImage))) { + !(Types.isField(elem) && elem instanceof Field && + (elem.field instanceof FieldLabel || + elem.field instanceof FieldImage))) { const difference = minXPos - xCursor; prevInRowSpacer.width += difference; } @@ -366,7 +365,7 @@ export class RenderInfo extends BaseRenderInfo { } const outputConnectionShape = this.outputConnection.shape; if (!('isDynamic' in outputConnectionShape && - outputConnectionShape.isDynamic)) { + outputConnectionShape.isDynamic)) { return; } @@ -381,8 +380,8 @@ export class RenderInfo extends BaseRenderInfo { // Adjust the height of the output connection. const blockHeight = this.bottomRow.hasNextConnection ? - this.height - this.bottomRow.descenderHeight : - this.height; + this.height - this.bottomRow.descenderHeight : + this.height; const connectionHeight = outputConnectionShape.height(blockHeight); const connectionWidth = outputConnectionShape.width(blockHeight); @@ -390,9 +389,9 @@ export class RenderInfo extends BaseRenderInfo { this.outputConnection.width = connectionWidth; this.outputConnection.startX = connectionWidth; this.outputConnection.connectionOffsetY = - outputConnectionShape.connectionOffsetY(connectionHeight); + outputConnectionShape.connectionOffsetY(connectionHeight); this.outputConnection.connectionOffsetX = - outputConnectionShape.connectionOffsetX(connectionWidth); + outputConnectionShape.connectionOffsetX(connectionWidth); // Add the right connection measurable. // Don't add it if we have a value-to-statement or a value-to-stack block. @@ -417,7 +416,7 @@ export class RenderInfo extends BaseRenderInfo { */ protected finalizeHorizontalAlignment_() { if (!this.outputConnection || this.hasStatementInput || - this.bottomRow.hasNextConnection) { + this.bottomRow.hasNextConnection) { return; } let totalNegativeSpacing = 0; @@ -432,7 +431,7 @@ export class RenderInfo extends BaseRenderInfo { let rightNegPadding = this.getNegativeSpacing_(lastElem); totalNegativeSpacing = leftNegPadding + rightNegPadding; const minBlockWidth = - this.constants_.MIN_BLOCK_WIDTH + this.outputConnection.width * 2; + this.constants_.MIN_BLOCK_WIDTH + this.outputConnection.width * 2; if (this.width - totalNegativeSpacing < minBlockWidth) { // Maintain a minimum block width, split negative spacing between left // and right edge. @@ -482,7 +481,7 @@ export class RenderInfo extends BaseRenderInfo { const width = this.height / 2 > maxWidth ? maxWidth : this.height / 2; const topPadding = this.constants_.SMALL_PADDING; const roundPadding = - width * (1 - Math.sin(Math.acos((width - topPadding) / width))); + width * (1 - Math.sin(Math.acos((width - topPadding) / width))); return connectionWidth - roundPadding; } default: @@ -492,32 +491,32 @@ export class RenderInfo extends BaseRenderInfo { if (Types.isInlineInput(elem) && elem instanceof InputConnection) { const connectedBlock = elem.connectedBlock; const innerShape = connectedBlock ? - (connectedBlock.pathObject as PathObject).outputShapeType : - elem.shape.type; + (connectedBlock.pathObject as PathObject).outputShapeType : + elem.shape.type; if (innerShape == null) { return 0; } // Special case for value to stack / value to statement blocks. if (connectedBlock && connectedBlock.outputConnection && - (connectedBlock.statementInputCount || - connectedBlock.nextConnection)) { + (connectedBlock.statementInputCount || + connectedBlock.nextConnection)) { return 0; } // Special case for hexagonal output. if (outerShape === constants.SHAPES.HEXAGONAL && - outerShape !== innerShape) { + outerShape !== innerShape) { return 0; } return connectionWidth - - this.constants_.SHAPE_IN_SHAPE_PADDING[outerShape][innerShape]; + this.constants_.SHAPE_IN_SHAPE_PADDING[outerShape][innerShape]; } else if (Types.isField(elem) && elem instanceof Field) { // Special case for text inputs. if (outerShape === constants.SHAPES.ROUND && - elem.field instanceof FieldTextInput) { + elem.field instanceof FieldTextInput) { return connectionWidth - 2.75 * constants.GRID_UNIT; } return connectionWidth - - this.constants_.SHAPE_IN_SHAPE_PADDING[outerShape][0]; + this.constants_.SHAPE_IN_SHAPE_PADDING[outerShape][0]; } else if (Types.isIcon(elem)) { return this.constants_.SMALL_PADDING; } @@ -542,17 +541,17 @@ export class RenderInfo extends BaseRenderInfo { const firstRow = i === 2; const hasPrevNotch = firstRow ? !!this.topRow.hasPreviousConnection : - !!prevSpacer.followsStatement; + !!prevSpacer.followsStatement; const hasNextNotch = i + 2 >= this.rows.length - 1 ? - !!this.bottomRow.hasNextConnection : - !!nextSpacer.precedesStatement; + !!this.bottomRow.hasNextConnection : + !!nextSpacer.precedesStatement; if (hasPrevNotch) { const elem = row.elements[1]; const hasSingleTextOrImageField = row.elements.length === 3 && - elem instanceof Field && - (elem.field instanceof FieldLabel || - elem.field instanceof FieldImage); + elem instanceof Field && + (elem.field instanceof FieldLabel || + elem.field instanceof FieldImage); if (!firstRow && hasSingleTextOrImageField) { // Remove some padding if we have a single image or text field. prevSpacer.height -= this.constants_.SMALL_PADDING; @@ -568,9 +567,9 @@ export class RenderInfo extends BaseRenderInfo { for (let j = 0; j < row.elements.length; j++) { const elem = row.elements[j]; if (elem instanceof InputConnection && Types.isInlineInput(elem) && - elem.connectedBlock && !elem.connectedBlock.isShadow() && - elem.connectedBlock.getHeightWidth().height >= - minVerticalTightNestingHeight) { + elem.connectedBlock && !elem.connectedBlock.isShadow() && + elem.connectedBlock.getHeightWidth().height >= + minVerticalTightNestingHeight) { hasNonShadowConnectedBlocks = true; break; } diff --git a/core/renderers/zelos/marker_svg.ts b/core/renderers/zelos/marker_svg.ts index db9e5942c..5fcd0f533 100644 --- a/core/renderers/zelos/marker_svg.ts +++ b/core/renderers/zelos/marker_svg.ts @@ -13,24 +13,23 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; +import {BlockSvg} from '../../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ASTNode } from '../../keyboard_nav/ast_node.js'; +import {ASTNode} from '../../keyboard_nav/ast_node.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from '../../keyboard_nav/marker.js'; +import {Marker} from '../../keyboard_nav/marker.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderedConnection } from '../../rendered_connection.js'; +import {RenderedConnection} from '../../rendered_connection.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; +import {Svg} from '../../utils/svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../../workspace_svg.js'; +import {WorkspaceSvg} from '../../workspace_svg.js'; +/* eslint-disable-next-line no-unused-vars */ +import {ConstantProvider as BaseConstantProvider} from '../common/constants.js'; +import {MarkerSvg as BaseMarkerSvg} from '../common/marker_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider as BaseConstantProvider } from '../common/constants.js'; -import { MarkerSvg as BaseMarkerSvg } from '../common/marker_svg.js'; - -/* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider as ZelosConstantProvider } from './constants.js'; +import {ConstantProvider as ZelosConstantProvider} from './constants.js'; /** @@ -41,7 +40,7 @@ export class MarkerSvg extends BaseMarkerSvg { // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. constants_!: ZelosConstantProvider; - private markerCircle_: SVGCircleElement | null = null; + private markerCircle_: SVGCircleElement|null = null; /** * @param workspace The workspace the marker belongs to. @@ -49,8 +48,8 @@ export class MarkerSvg extends BaseMarkerSvg { * @param marker The marker to draw. */ constructor( - workspace: WorkspaceSvg, constants: BaseConstantProvider, - marker: Marker) { + workspace: WorkspaceSvg, constants: BaseConstantProvider, + marker: Marker) { super(workspace, constants, marker); } @@ -126,12 +125,12 @@ export class MarkerSvg extends BaseMarkerSvg { // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.markerCircle_ = dom.createSvgElement( - Svg.CIRCLE, { - 'r': this.constants_.CURSOR_RADIUS, - 'style': 'display: none', - 'stroke-width': this.constants_.CURSOR_STROKE_WIDTH, - }, - this.markerSvg_!); + Svg.CIRCLE, { + 'r': this.constants_.CURSOR_RADIUS, + 'style': 'display: none', + 'stroke-width': this.constants_.CURSOR_STROKE_WIDTH, + }, + this.markerSvg_!); // Markers and stack cursors don't blink. if (this.isCursor()) { diff --git a/core/renderers/zelos/measurables/bottom_row.ts b/core/renderers/zelos/measurables/bottom_row.ts index 6e8d39fda..60cbae65e 100644 --- a/core/renderers/zelos/measurables/bottom_row.ts +++ b/core/renderers/zelos/measurables/bottom_row.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../../block_svg.js'; -import { ConstantProvider } from '../../../renderers/common/constants.js'; -import { BottomRow as BaseBottomRow } from '../../../renderers/measurables/bottom_row.js'; +import {BlockSvg} from '../../../block_svg.js'; +import {ConstantProvider} from '../../../renderers/common/constants.js'; +import {BottomRow as BaseBottomRow} from '../../../renderers/measurables/bottom_row.js'; /** @@ -43,6 +43,6 @@ export class BottomRow extends BaseBottomRow { /** Render a round corner unless the block has an output connection. */ override hasRightSquareCorner(block: BlockSvg) { return !!block.outputConnection && !block.statementInputCount && - !block.nextConnection; + !block.nextConnection; } } diff --git a/core/renderers/zelos/measurables/inputs.ts b/core/renderers/zelos/measurables/inputs.ts index 2a37a89e7..2046a124a 100644 --- a/core/renderers/zelos/measurables/inputs.ts +++ b/core/renderers/zelos/measurables/inputs.ts @@ -18,9 +18,9 @@ /* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */ -import { Input } from '../../../input.js'; -import { ConstantProvider } from '../../../renderers/common/constants.js'; -import { StatementInput as BaseStatementInput } from '../../../renderers/measurables/statement_input.js'; +import {Input} from '../../../input.js'; +import {ConstantProvider} from '../../../renderers/common/constants.js'; +import {StatementInput as BaseStatementInput} from '../../../renderers/measurables/statement_input.js'; /** diff --git a/core/renderers/zelos/measurables/row_elements.ts b/core/renderers/zelos/measurables/row_elements.ts index c0d8d55be..085914952 100644 --- a/core/renderers/zelos/measurables/row_elements.ts +++ b/core/renderers/zelos/measurables/row_elements.ts @@ -17,9 +17,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from '../../../renderers/common/constants.js'; -import { Measurable } from '../../../renderers/measurables/base.js'; -import { Types } from '../../../renderers/measurables/types.js'; +import {ConstantProvider} from '../../../renderers/common/constants.js'; +import {Measurable} from '../../../renderers/measurables/base.js'; +import {Types} from '../../../renderers/measurables/types.js'; /** diff --git a/core/renderers/zelos/measurables/top_row.ts b/core/renderers/zelos/measurables/top_row.ts index d4a0a9ec2..de9d9e5f5 100644 --- a/core/renderers/zelos/measurables/top_row.ts +++ b/core/renderers/zelos/measurables/top_row.ts @@ -13,9 +13,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../../block_svg.js'; -import { ConstantProvider } from '../../../renderers/common/constants.js'; -import { TopRow as BaseTopRow } from '../../../renderers/measurables/top_row.js'; +import {BlockSvg} from '../../../block_svg.js'; +import {ConstantProvider} from '../../../renderers/common/constants.js'; +import {TopRow as BaseTopRow} from '../../../renderers/measurables/top_row.js'; /** @@ -40,15 +40,14 @@ export class TopRow extends BaseTopRow { /** Render a round corner unless the block has an output connection. */ override hasLeftSquareCorner(block: BlockSvg) { const hasHat = - (block.hat ? block.hat === 'cap' : - this.constants_.ADD_START_HATS) && - !block.outputConnection && !block.previousConnection; + (block.hat ? block.hat === 'cap' : this.constants_.ADD_START_HATS) && + !block.outputConnection && !block.previousConnection; return !!block.outputConnection || hasHat; } /** Render a round corner unless the block has an output connection. */ override hasRightSquareCorner(block: BlockSvg) { return !!block.outputConnection && !block.statementInputCount && - !block.nextConnection; + !block.nextConnection; } } diff --git a/core/renderers/zelos/path_object.ts b/core/renderers/zelos/path_object.ts index 487a0d12e..25dc0653b 100644 --- a/core/renderers/zelos/path_object.ts +++ b/core/renderers/zelos/path_object.ts @@ -16,16 +16,15 @@ // Unused import preserved for side-effects. Remove if unneeded. import '../../theme'; -import { BlockSvg } from '../../block_svg.js'; -import { Connection } from '../../connection.js'; -import { BlockStyle } from '../../theme.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Connection} from '../../connection.js'; +import {BlockStyle} from '../../theme.js'; import * as dom from '../../utils/dom.js'; -import { Svg } from '../../utils/svg.js'; - -import { PathObject as BasePathObject } from '../common/path_object.js'; +import {Svg} from '../../utils/svg.js'; +import {PathObject as BasePathObject} from '../common/path_object.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConstantProvider } from './constants.js'; +import {ConstantProvider} from './constants.js'; /** @@ -35,8 +34,8 @@ import { ConstantProvider } from './constants.js'; */ export class PathObject extends BasePathObject { /** The selected path of the block. */ - private svgPathSelected_: SVGElement | null = null; - private readonly outlines_: { [key: string]: SVGElement }; + private svgPathSelected_: SVGElement|null = null; + private readonly outlines_: {[key: string]: SVGElement}; /** * A set used to determine which outlines were used during a draw pass. The @@ -46,8 +45,8 @@ export class PathObject extends BasePathObject { */ // AnyDuringMigration because: Type 'null' is not assignable to type '{ [key: // string]: number; }'. - private remainingOutlines_: { [key: string]: number } = - null as AnyDuringMigration; + private remainingOutlines_: {[key: string]: number} = + null as AnyDuringMigration; /** * The type of block's output connection shape. This is set when a block @@ -61,8 +60,8 @@ export class PathObject extends BasePathObject { * @param constants The renderer's constants. */ constructor( - root: SVGElement, style: BlockStyle, - public override constants: ConstantProvider) { + root: SVGElement, style: BlockStyle, + public override constants: ConstantProvider) { super(root, style, constants); /** The outline paths on the block. */ @@ -105,7 +104,7 @@ export class PathObject extends BasePathObject { this.svgPathSelected_ = this.svgPath.cloneNode(true) as SVGElement; this.svgPathSelected_.setAttribute('fill', 'none'); this.svgPathSelected_.setAttribute( - 'filter', 'url(#' + this.constants.selectedGlowFilterId + ')'); + 'filter', 'url(#' + this.constants.selectedGlowFilterId + ')'); this.svgRoot.appendChild(this.svgPathSelected_); } } else { @@ -120,7 +119,7 @@ export class PathObject extends BasePathObject { this.setClass_('blocklyReplaceable', enable); if (enable) { this.svgPath.setAttribute( - 'filter', 'url(#' + this.constants.replacementGlowFilterId + ')'); + 'filter', 'url(#' + this.constants.replacementGlowFilterId + ')'); } else { this.svgPath.removeAttribute('filter'); } @@ -134,7 +133,7 @@ export class PathObject extends BasePathObject { } if (enable) { outlinePath.setAttribute( - 'filter', 'url(#' + this.constants.replacementGlowFilterId + ')'); + 'filter', 'url(#' + this.constants.replacementGlowFilterId + ')'); } else { outlinePath.removeAttribute('filter'); } @@ -184,13 +183,13 @@ export class PathObject extends BasePathObject { private getOutlinePath_(name: string): SVGElement { if (!this.outlines_[name]) { this.outlines_[name] = dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyOutlinePath', // IE doesn't like paths without the - // data definition, set empty - // default - 'd': '', - }, - this.svgRoot); + Svg.PATH, { + 'class': 'blocklyOutlinePath', // IE doesn't like paths without the + // data definition, set empty + // default + 'd': '', + }, + this.svgRoot); } if (this.remainingOutlines_) { delete this.remainingOutlines_[name]; diff --git a/core/renderers/zelos/renderer.ts b/core/renderers/zelos/renderer.ts index ef7339c69..99e738070 100644 --- a/core/renderers/zelos/renderer.ts +++ b/core/renderers/zelos/renderer.ts @@ -16,27 +16,26 @@ import '../../theme'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../../block_svg.js'; -import { Connection } from '../../connection.js'; -import { ConnectionType } from '../../connection_type.js'; -import { InsertionMarkerManager } from '../../insertion_marker_manager.js'; +import {BlockSvg} from '../../block_svg.js'; +import {Connection} from '../../connection.js'; +import {ConnectionType} from '../../connection_type.js'; +import {InsertionMarkerManager} from '../../insertion_marker_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from '../../keyboard_nav/marker.js'; -import { RenderedConnection } from '../../rendered_connection.js'; -import { BlockStyle } from '../../theme.js'; +import {Marker} from '../../keyboard_nav/marker.js'; +import {RenderedConnection} from '../../rendered_connection.js'; +import {BlockStyle} from '../../theme.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../../workspace_svg.js'; - +import {WorkspaceSvg} from '../../workspace_svg.js'; import * as blockRendering from '../common/block_rendering.js'; /* eslint-disable-next-line no-unused-vars */ -import { RenderInfo as BaseRenderInfo } from '../common/info.js'; -import { Renderer as BaseRenderer } from '../common/renderer.js'; +import {RenderInfo as BaseRenderInfo} from '../common/info.js'; +import {Renderer as BaseRenderer} from '../common/renderer.js'; -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { RenderInfo } from './info.js'; -import { MarkerSvg } from './marker_svg.js'; -import { PathObject } from './path_object.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {RenderInfo} from './info.js'; +import {MarkerSvg} from './marker_svg.js'; +import {PathObject} from './path_object.js'; /** @@ -76,7 +75,7 @@ export class Renderer extends BaseRenderer { * @return The drawer. */ protected override makeDrawer_(block: BlockSvg, info: BaseRenderInfo): - Drawer { + Drawer { return new Drawer(block, (info as RenderInfo)); } @@ -87,7 +86,7 @@ export class Renderer extends BaseRenderer { * @return The object in charge of drawing the marker. */ override makeMarkerDrawer(workspace: WorkspaceSvg, marker: Marker): - MarkerSvg { + MarkerSvg { return new MarkerSvg(workspace, this.getConstants(), marker); } @@ -99,26 +98,26 @@ export class Renderer extends BaseRenderer { */ override makePathObject(root: SVGElement, style: BlockStyle): PathObject { return new PathObject( - root, style, (this.getConstants() as ConstantProvider)); + root, style, (this.getConstants() as ConstantProvider)); } /** - * Get the current renderer's constant provider. We assume that when this is - * called, the renderer has already been initialized. - * @return The constant provider. - */ + * Get the current renderer's constant provider. We assume that when this is + * called, the renderer has already been initialized. + * @return The constant provider. + */ override getConstants(): ConstantProvider { return this.constants_; } override shouldHighlightConnection(conn: Connection) { return conn.type !== ConnectionType.INPUT_VALUE && - conn.type !== ConnectionType.OUTPUT_VALUE; + conn.type !== ConnectionType.OUTPUT_VALUE; } override getConnectionPreviewMethod( - closest: RenderedConnection, local: RenderedConnection, - topBlock: BlockSvg) { + closest: RenderedConnection, local: RenderedConnection, + topBlock: BlockSvg) { if (local.type === ConnectionType.OUTPUT_VALUE) { if (!closest.isConnected()) { return InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE; diff --git a/core/renderers/zelos/zelos.ts b/core/renderers/zelos/zelos.ts index b444966a6..5e64cb052 100644 --- a/core/renderers/zelos/zelos.ts +++ b/core/renderers/zelos/zelos.ts @@ -12,16 +12,16 @@ * @namespace Blockly.zelos */ -import { ConstantProvider } from './constants.js'; -import { Drawer } from './drawer.js'; -import { RenderInfo } from './info.js'; -import { MarkerSvg } from './marker_svg.js'; -import { BottomRow } from './measurables/bottom_row.js'; -import { StatementInput } from './measurables/inputs.js'; -import { RightConnectionShape } from './measurables/row_elements.js'; -import { TopRow } from './measurables/top_row.js'; -import { PathObject } from './path_object.js'; -import { Renderer } from './renderer.js'; +import {ConstantProvider} from './constants.js'; +import {Drawer} from './drawer.js'; +import {RenderInfo} from './info.js'; +import {MarkerSvg} from './marker_svg.js'; +import {BottomRow} from './measurables/bottom_row.js'; +import {StatementInput} from './measurables/inputs.js'; +import {RightConnectionShape} from './measurables/row_elements.js'; +import {TopRow} from './measurables/top_row.js'; +import {PathObject} from './path_object.js'; +import {Renderer} from './renderer.js'; export { BottomRow, diff --git a/core/scrollbar.ts b/core/scrollbar.ts index 62755e266..07e8ec3a5 100644 --- a/core/scrollbar.ts +++ b/core/scrollbar.ts @@ -14,14 +14,14 @@ import * as browserEvents from './browser_events.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Metrics } from './utils/metrics.js'; -import { Svg } from './utils/svg.js'; +import {Metrics} from './utils/metrics.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** * A note on units: most of the numbers that are in CSS pixels are scaled if the * scrollbar is in a mutator. @@ -49,7 +49,7 @@ export class Scrollbar { private readonly margin_: number; /** Previously recorded metrics from the workspace. */ - private oldHostMetrics_: Metrics | null = null; + private oldHostMetrics_: Metrics|null = null; /** * The ratio of handle position offset to workspace content displacement. @@ -89,13 +89,13 @@ export class Scrollbar { /** Whether the workspace containing this scrollbar is visible. */ private containerVisible_ = true; - private svgBackground_: SVGRectElement | null = null; + private svgBackground_: SVGRectElement|null = null; - private svgHandle_: SVGRectElement | null = null; + private svgHandle_: SVGRectElement|null = null; - private outerSvg_: SVGSVGElement | null = null; + private outerSvg_: SVGSVGElement|null = null; - private svgGroup_: SVGGElement | null = null; + private svgGroup_: SVGGElement|null = null; position: Coordinate; lengthAttribute_ = 'width'; @@ -111,8 +111,8 @@ export class Scrollbar { * @param opt_margin The margin to apply to this scrollbar. */ constructor( - private workspace: WorkspaceSvg, private readonly horizontal: boolean, - opt_pair?: boolean, opt_class?: string, opt_margin?: number) { + private workspace: WorkspaceSvg, private readonly horizontal: boolean, + opt_pair?: boolean, opt_class?: string, opt_margin?: number) { /** Whether this scrollbar is part of a pair. */ this.pair_ = opt_pair || false; /** @@ -120,8 +120,8 @@ export class Scrollbar { * viewport in pixels). */ this.margin_ = opt_margin !== undefined ? - opt_margin : - Scrollbar.DEFAULT_SCROLLBAR_MARGIN; + opt_margin : + Scrollbar.DEFAULT_SCROLLBAR_MARGIN; /** * The location of the origin of the workspace that the scrollbar is in, @@ -144,16 +144,16 @@ export class Scrollbar { const scrollbarThickness = Scrollbar.scrollbarThickness; if (horizontal) { this.svgBackground_!.setAttribute( - 'height', scrollbarThickness.toString()); + 'height', scrollbarThickness.toString()); this.outerSvg_!.setAttribute('height', scrollbarThickness.toString()); this.svgHandle_!.setAttribute( - 'height', (scrollbarThickness - 5).toString()); + 'height', (scrollbarThickness - 5).toString()); this.svgHandle_!.setAttribute('y', (2.5).toString()); } else { this.svgBackground_!.setAttribute('width', scrollbarThickness.toString()); this.outerSvg_!.setAttribute('width', scrollbarThickness.toString()); this.svgHandle_!.setAttribute( - 'width', (scrollbarThickness - 5).toString()); + 'width', (scrollbarThickness - 5).toString()); // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. this.svgHandle_!.setAttribute('x', (2.5).toString()); @@ -165,13 +165,13 @@ export class Scrollbar { // AnyDuringMigration because: Argument of type 'SVGRectElement | null' is // not assignable to parameter of type 'EventTarget'. this.onMouseDownBarWrapper_ = browserEvents.conditionalBind( - this.svgBackground_ as AnyDuringMigration, 'mousedown', scrollbar, - scrollbar.onMouseDownBar_); + this.svgBackground_ as AnyDuringMigration, 'mousedown', scrollbar, + scrollbar.onMouseDownBar_); // AnyDuringMigration because: Argument of type 'SVGRectElement | null' is // not assignable to parameter of type 'EventTarget'. this.onMouseDownHandleWrapper_ = browserEvents.conditionalBind( - this.svgHandle_ as AnyDuringMigration, 'mousedown', scrollbar, - scrollbar.onMouseDownHandle_); + this.svgHandle_ as AnyDuringMigration, 'mousedown', scrollbar, + scrollbar.onMouseDownHandle_); } /** @@ -224,7 +224,7 @@ export class Scrollbar { // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.svgHandle_!.setAttribute( - this.lengthAttribute_, this.handleLength_ as AnyDuringMigration); + this.lengthAttribute_, this.handleLength_ as AnyDuringMigration); } /** @@ -255,7 +255,7 @@ export class Scrollbar { // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.svgHandle_!.setAttribute( - this.positionAttribute_, this.handlePosition_ as AnyDuringMigration); + this.positionAttribute_, this.handlePosition_ as AnyDuringMigration); } /** @@ -268,11 +268,11 @@ export class Scrollbar { // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.outerSvg_!.setAttribute( - this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration); + this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.svgBackground_!.setAttribute( - this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration); + this.lengthAttribute_, this.scrollbarLength_ as AnyDuringMigration); } /** @@ -309,7 +309,7 @@ export class Scrollbar { } if (this.oldHostMetrics_ && - Scrollbar.metricsAreEquivalent_(hostMetrics, this.oldHostMetrics_)) { + Scrollbar.metricsAreEquivalent_(hostMetrics, this.oldHostMetrics_)) { return; } @@ -337,9 +337,9 @@ export class Scrollbar { return true; } return this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth || - this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || - this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft || - this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop; + this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || + this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft || + this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop; } /** @@ -378,7 +378,7 @@ export class Scrollbar { // Horizontal toolbar should always be just above the bottom of the // workspace. const yCoordinate = hostMetrics.absoluteTop + hostMetrics.viewHeight - - Scrollbar.scrollbarThickness - this.margin_; + Scrollbar.scrollbarThickness - this.margin_; this.setPosition(xCoordinate, yCoordinate); // If the view has been resized, a content resize will also be necessary. @@ -412,7 +412,7 @@ export class Scrollbar { // Resize the handle. let handleLength = - this.scrollbarLength_ * hostMetrics.viewWidth / hostMetrics.scrollWidth; + this.scrollbarLength_ * hostMetrics.viewWidth / hostMetrics.scrollWidth; handleLength = this.constrainHandleLength_(handleLength); this.setHandleLength_(handleLength); @@ -468,9 +468,9 @@ export class Scrollbar { this.setScrollbarLength_(Math.max(0, viewSize)); const xCoordinate = this.workspace.RTL ? - hostMetrics.absoluteLeft + this.margin_ : - hostMetrics.absoluteLeft + hostMetrics.viewWidth - - Scrollbar.scrollbarThickness - this.margin_; + hostMetrics.absoluteLeft + this.margin_ : + hostMetrics.absoluteLeft + hostMetrics.viewWidth - + Scrollbar.scrollbarThickness - this.margin_; const yCoordinate = hostMetrics.absoluteTop + this.margin_; this.setPosition(xCoordinate, yCoordinate); @@ -506,7 +506,7 @@ export class Scrollbar { // Resize the handle. let handleLength = this.scrollbarLength_ * hostMetrics.viewHeight / - hostMetrics.scrollHeight; + hostMetrics.scrollHeight; handleLength = this.constrainHandleLength_(handleLength); this.setHandleLength_(handleLength); @@ -549,40 +549,40 @@ export class Scrollbar { */ let className = - 'blocklyScrollbar' + (this.horizontal ? 'Horizontal' : 'Vertical'); + 'blocklyScrollbar' + (this.horizontal ? 'Horizontal' : 'Vertical'); if (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 // not assignable to parameter of type 'Element | undefined'. this.svgGroup_ = - dom.createSvgElement(Svg.G, {}, this.outerSvg_ as AnyDuringMigration); + 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( - Svg.RECT, { 'class': 'blocklyScrollbarBackground' }, - this.svgGroup_ as AnyDuringMigration); + Svg.RECT, {'class': 'blocklyScrollbarBackground'}, + this.svgGroup_ as AnyDuringMigration); const radius = Math.floor((Scrollbar.scrollbarThickness - 5) / 2); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.svgHandle_ = dom.createSvgElement( - Svg.RECT, - { 'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius }, - this.svgGroup_ as AnyDuringMigration); + Svg.RECT, + {'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius}, + this.svgGroup_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'SVGRectElement | null' is // not assignable to parameter of type 'Element'. this.workspace.getThemeManager().subscribe( - this.svgHandle_ as AnyDuringMigration, 'scrollbarColour', 'fill'); + this.svgHandle_ as AnyDuringMigration, 'scrollbarColour', 'fill'); // AnyDuringMigration because: Argument of type 'SVGRectElement | null' is // not assignable to parameter of type 'Element'. this.workspace.getThemeManager().subscribe( - this.svgHandle_ as AnyDuringMigration, 'scrollbarOpacity', - 'fill-opacity'); + this.svgHandle_ as AnyDuringMigration, 'scrollbarOpacity', + 'fill-opacity'); // AnyDuringMigration because: Argument of type 'SVGSVGElement | null' is // not assignable to parameter of type 'Element'. dom.insertAfter( - this.outerSvg_ as AnyDuringMigration, this.workspace.getParentSvg()); + this.outerSvg_ as AnyDuringMigration, this.workspace.getParentSvg()); } /** @@ -665,7 +665,7 @@ export class Scrollbar { return; } const mouseXY = browserEvents.mouseToSvg( - e, this.workspace.getParentSvg(), this.workspace.getInverseScreenCTM()); + e, this.workspace.getParentSvg(), this.workspace.getInverseScreenCTM()); const mouseLocation = this.horizontal ? mouseXY.x : mouseXY.y; const handleXY = svgMath.getInjectionDivXY(this.svgHandle_ as Element); @@ -715,17 +715,17 @@ export class Scrollbar { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. this.startDragMouse_ = this.horizontal ? (e as AnyDuringMigration).clientX : - (e as AnyDuringMigration).clientY; + (e as AnyDuringMigration).clientY; // AnyDuringMigration because: Property 'onMouseUpWrapper_' does not exist // on type 'typeof Scrollbar'. (Scrollbar as AnyDuringMigration).onMouseUpWrapper_ = - browserEvents.conditionalBind( - document, 'mouseup', this, this.onMouseUpHandle_); + 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_); + browserEvents.conditionalBind( + document, 'mousemove', this, this.onMouseMoveHandle_); e.stopPropagation(); e.preventDefault(); } @@ -739,7 +739,7 @@ export class Scrollbar { // 'Event'. AnyDuringMigration because: Property 'clientX' does not exist // on type 'Event'. const currentMouse = this.horizontal ? (e as AnyDuringMigration).clientX : - (e as AnyDuringMigration).clientY; + (e as AnyDuringMigration).clientY; const mouseDelta = currentMouse - this.startDragMouse_; const handlePosition = this.startDragHandle + mouseDelta; // Position the bar. @@ -777,7 +777,7 @@ export class Scrollbar { // AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not // exist on type 'typeof Scrollbar'. browserEvents.unbind( - (Scrollbar as AnyDuringMigration).onMouseMoveWrapper_); + (Scrollbar as AnyDuringMigration).onMouseMoveWrapper_); // AnyDuringMigration because: Property 'onMouseMoveWrapper_' does not // exist on type 'typeof Scrollbar'. (Scrollbar as AnyDuringMigration).onMouseMoveWrapper_ = null; @@ -848,17 +848,17 @@ export class Scrollbar { * @return Whether the two sets of metrics are equivalent. */ private static metricsAreEquivalent_(first: Metrics, second: Metrics): - boolean { + boolean { return first.viewWidth === second.viewWidth && - first.viewHeight === second.viewHeight && - first.viewLeft === second.viewLeft && - first.viewTop === second.viewTop && - first.absoluteTop === second.absoluteTop && - first.absoluteLeft === second.absoluteLeft && - first.scrollWidth === second.scrollWidth && - first.scrollHeight === second.scrollHeight && - first.scrollLeft === second.scrollLeft && - first.scrollTop === second.scrollTop; + first.viewHeight === second.viewHeight && + first.viewLeft === second.viewLeft && + first.viewTop === second.viewTop && + first.absoluteTop === second.absoluteTop && + first.absoluteLeft === second.absoluteLeft && + first.scrollWidth === second.scrollWidth && + first.scrollHeight === second.scrollHeight && + first.scrollLeft === second.scrollLeft && + first.scrollTop === second.scrollTop; } } diff --git a/core/scrollbar_pair.ts b/core/scrollbar_pair.ts index a286a67ff..1ca09a0c8 100644 --- a/core/scrollbar_pair.ts +++ b/core/scrollbar_pair.ts @@ -13,13 +13,13 @@ */ import * as eventUtils from './events/utils.js'; -import { Scrollbar } from './scrollbar.js'; +import {Scrollbar} from './scrollbar.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Metrics } from './utils/metrics.js'; -import { Svg } from './utils/svg.js'; +import {Metrics} from './utils/metrics.js'; +import {Svg} from './utils/svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -32,7 +32,7 @@ export class ScrollbarPair { corner_: AnyDuringMigration; /** Previously recorded metrics from the workspace. */ - private oldHostMetrics_: Metrics | null = null; + private oldHostMetrics_: Metrics|null = null; /** * @param workspace Workspace to bind the scrollbars to. @@ -43,19 +43,19 @@ export class ScrollbarPair { * @param opt_margin The margin to apply to these scrollbars. */ constructor( - private workspace: WorkspaceSvg, addHorizontal?: boolean, - addVertical?: boolean, opt_class?: string, opt_margin?: number) { + private workspace: WorkspaceSvg, addHorizontal?: boolean, + addVertical?: boolean, opt_class?: string, opt_margin?: number) { addHorizontal = addHorizontal === undefined ? true : addHorizontal; addVertical = addVertical === undefined ? true : addVertical; const isPair = addHorizontal && addVertical; if (addHorizontal) { this.hScroll = - new Scrollbar(workspace, true, isPair, opt_class, opt_margin); + new Scrollbar(workspace, true, isPair, opt_class, opt_margin); } if (addVertical) { this.vScroll = - new Scrollbar(workspace, false, isPair, opt_class, opt_margin); + new Scrollbar(workspace, false, isPair, opt_class, opt_margin); } if (isPair) { @@ -106,25 +106,25 @@ export class ScrollbarPair { let resizeH = false; let resizeV = false; if (!this.oldHostMetrics_ || - this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth || - this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || - this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop || - this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft) { + this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth || + this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || + this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop || + this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft) { // The window has been resized or repositioned. resizeH = true; resizeV = true; } else { // Has the content been resized or moved? if (!this.oldHostMetrics_ || - this.oldHostMetrics_.scrollWidth !== hostMetrics.scrollWidth || - this.oldHostMetrics_.viewLeft !== hostMetrics.viewLeft || - this.oldHostMetrics_.scrollLeft !== hostMetrics.scrollLeft) { + this.oldHostMetrics_.scrollWidth !== hostMetrics.scrollWidth || + this.oldHostMetrics_.viewLeft !== hostMetrics.viewLeft || + this.oldHostMetrics_.scrollLeft !== hostMetrics.scrollLeft) { resizeH = true; } if (!this.oldHostMetrics_ || - this.oldHostMetrics_.scrollHeight !== hostMetrics.scrollHeight || - this.oldHostMetrics_.viewTop !== hostMetrics.viewTop || - this.oldHostMetrics_.scrollTop !== hostMetrics.scrollTop) { + this.oldHostMetrics_.scrollHeight !== hostMetrics.scrollHeight || + this.oldHostMetrics_.viewTop !== hostMetrics.viewTop || + this.oldHostMetrics_.scrollTop !== hostMetrics.scrollTop) { resizeV = true; } } @@ -147,13 +147,13 @@ export class ScrollbarPair { if (this.hScroll && this.vScroll) { // Reposition the corner square. if (!this.oldHostMetrics_ || - this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth || - this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft) { + this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth || + this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft) { this.corner_.setAttribute('x', this.vScroll.position.x); } if (!this.oldHostMetrics_ || - this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || - this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop) { + this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight || + this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop) { this.corner_.setAttribute('y', this.hScroll.position.y); } } diff --git a/core/serialization/blocks.ts b/core/serialization/blocks.ts index f354df0ac..2a00a1f79 100644 --- a/core/serialization/blocks.ts +++ b/core/serialization/blocks.ts @@ -16,21 +16,21 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from '../block_svg.js'; +import {BlockSvg} from '../block_svg.js'; // eslint-disable-next-line no-unused-vars -import { Connection } from '../connection.js'; +import {Connection} from '../connection.js'; import * as eventUtils from '../events/utils.js'; -import { inputTypes } from '../input_types.js'; +import {inputTypes} from '../input_types.js'; // eslint-disable-next-line no-unused-vars -import { ISerializer } from '../interfaces/i_serializer.js'; -import { Size } from '../utils/size.js'; +import {ISerializer} from '../interfaces/i_serializer.js'; +import {Size} from '../utils/size.js'; // eslint-disable-next-line no-unused-vars -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; import * as Xml from '../xml.js'; -import { BadConnectionCheck, MissingBlockType, MissingConnection, RealChildOfShadow } from './exceptions.js'; +import {BadConnectionCheck, MissingBlockType, MissingConnection, RealChildOfShadow} from './exceptions.js'; import * as priorities from './priorities.js'; import * as serializationRegistry from './registry.js'; @@ -43,8 +43,8 @@ import * as serializationRegistry from './registry.js'; * @alias Blockly.serialization.blocks.ConnectionState */ export interface ConnectionState { - shadow: State | undefined; - block: State | undefined; + shadow: State|undefined; + block: State|undefined; } /** @@ -53,18 +53,18 @@ export interface ConnectionState { */ export interface State { type: string; - id: string | undefined; - x: number | undefined; - y: number | undefined; - collapsed: boolean | undefined; - enabled: boolean | undefined; - inline: boolean | undefined; - data: string | undefined; - extraState: AnyDuringMigration | undefined; - icons: { [key: string]: AnyDuringMigration } | undefined; - fields: { [key: string]: AnyDuringMigration } | undefined; - inputs: { [key: string]: ConnectionState } | undefined; - next: ConnectionState | undefined; + id: string|undefined; + x: number|undefined; + y: number|undefined; + collapsed: boolean|undefined; + enabled: boolean|undefined; + inline: boolean|undefined; + data: string|undefined; + extraState: AnyDuringMigration|undefined; + icons: {[key: string]: AnyDuringMigration}|undefined; + fields: {[key: string]: AnyDuringMigration}|undefined; + inputs: {[key: string]: ConnectionState}|undefined; + next: ConnectionState|undefined; } /** @@ -94,7 +94,7 @@ export function save(block: Block, { addInputBlocks?: boolean, addNextBlocks?: boolean, doFullSerialization?: boolean -} = {}): State | null { +} = {}): State|null { if (block.isInsertionMarker()) { return null; } @@ -151,7 +151,7 @@ function saveAttributes(block: Block, state: State) { state['enabled'] = false; } if (block.inputsInline !== undefined && - block.inputsInline !== block.inputsInlineDefault) { + block.inputsInline !== block.inputsInlineDefault) { state['inline'] = block.inputsInline; } // Data is a nullable string, so we don't need to worry about falsy values. @@ -186,9 +186,9 @@ function saveExtraState(block: Block, state: State) { const extraState = block.mutationToDom(); if (extraState !== null) { state['extraState'] = - Xml.domToText(extraState) - .replace( - ' xmlns="https://developers.google.com/blockly/xml"', ''); + Xml.domToText(extraState) + .replace( + ' xmlns="https://developers.google.com/blockly/xml"', ''); } } } @@ -243,7 +243,7 @@ function saveFields(block: Block, state: State, doFullSerialization: boolean) { * @param doFullSerialization Whether or not to do full serialization. */ function saveInputBlocks( - block: Block, state: State, doFullSerialization: boolean) { + block: Block, state: State, doFullSerialization: boolean) { const inputs = Object.create(null); for (let i = 0; i < block.inputList.length; i++) { const input = block.inputList[i]; @@ -251,7 +251,7 @@ function saveInputBlocks( continue; } const connectionState = - saveConnection(input.connection as Connection, doFullSerialization); + saveConnection(input.connection as Connection, doFullSerialization); if (connectionState) { inputs[input.name] = connectionState; } @@ -270,12 +270,12 @@ function saveInputBlocks( * @param doFullSerialization Whether or not to do full serialization. */ function saveNextBlocks( - block: Block, state: State, doFullSerialization: boolean) { + block: Block, state: State, doFullSerialization: boolean) { if (!block.nextConnection) { return; } const connectionState = - saveConnection(block.nextConnection, doFullSerialization); + saveConnection(block.nextConnection, doFullSerialization); if (connectionState) { state['next'] = connectionState; } @@ -290,7 +290,7 @@ function saveNextBlocks( * @param doFullSerialization Whether or not to do full serialization. */ function saveConnection(connection: Connection, doFullSerialization: boolean): - ConnectionState | null { + ConnectionState|null { const shadow = connection.getShadowState(true); const child = connection.targetBlock(); if (!shadow && !child) { @@ -301,7 +301,7 @@ function saveConnection(connection: Connection, doFullSerialization: boolean): state['shadow'] = shadow; } if (child && !child.isShadow()) { - state['block'] = save(child, { doFullSerialization }); + state['block'] = save(child, {doFullSerialization}); } return state; } @@ -316,9 +316,9 @@ function saveConnection(connection: Connection, doFullSerialization: boolean): * @alias Blockly.serialization.blocks.append */ export function append( - state: State, workspace: Workspace, - { recordUndo = false }: { recordUndo?: boolean } = {}): Block { - return appendInternal(state, workspace, { recordUndo }); + state: State, workspace: Workspace, + {recordUndo = false}: {recordUndo?: boolean} = {}): Block { + return appendInternal(state, workspace, {recordUndo}); } /** @@ -338,12 +338,12 @@ export function append( * @alias Blockly.serialization.blocks.appendInternal */ export function appendInternal( - state: State, workspace: Workspace, - { parentConnection = undefined, isShadow = false, recordUndo = false }: { - parentConnection?: Connection, - isShadow?: boolean, - recordUndo?: boolean - } = {}): Block { + state: State, workspace: Workspace, + {parentConnection = undefined, isShadow = false, recordUndo = false}: { + parentConnection?: Connection, + isShadow?: boolean, + recordUndo?: boolean + } = {}): Block { const prevRecordUndo = eventUtils.getRecordUndo(); eventUtils.setRecordUndo(recordUndo); const existingGroup = eventUtils.getGroup(); @@ -352,7 +352,7 @@ export function appendInternal( } eventUtils.disable(); - const block = appendPrivate(state, workspace, { parentConnection, isShadow }); + const block = appendPrivate(state, workspace, {parentConnection, isShadow}); eventUtils.enable(); eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(block)); @@ -387,9 +387,9 @@ export function appendInternal( * @return The block that was just appended. */ function appendPrivate( - state: State, workspace: Workspace, - { parentConnection = undefined, isShadow = false }: - { parentConnection?: Connection, isShadow?: boolean } = {}): Block { + state: State, workspace: Workspace, + {parentConnection = undefined, isShadow = false}: + {parentConnection?: Connection, isShadow?: boolean} = {}): Block { if (!state['type']) { throw new MissingBlockType(state); } @@ -469,7 +469,7 @@ function loadExtraState(block: Block, state: State) { * @param state The state which defines the given block */ function tryToConnectParent( - parentConnection: Connection | undefined, child: Block, state: State) { + parentConnection: Connection|undefined, child: Block, state: State) { if (!parentConnection) { return; } @@ -498,13 +498,13 @@ function tryToConnectParent( if (!connected) { const checker = child.workspace.connectionChecker; throw new BadConnectionCheck( - checker.getErrorMessage( - checker.canConnectWithReason( - childConnection, parentConnection, false), - childConnection, parentConnection), - parentConnection.type === inputTypes.VALUE ? 'output connection' : - 'previous connection', - child, state); + checker.getErrorMessage( + checker.canConnectWithReason( + childConnection, parentConnection, false), + childConnection, parentConnection), + parentConnection.type === inputTypes.VALUE ? 'output connection' : + 'previous connection', + child, state); } } @@ -553,7 +553,7 @@ function loadFields(block: Block, state: State) { const field = block.getField(fieldName); if (!field) { console.warn( - `Ignoring non-existant field ${fieldName} in block ${block.type}`); + `Ignoring non-existant field ${fieldName} in block ${block.type}`); continue; } field.loadState(fieldState); @@ -604,14 +604,14 @@ function loadNextBlocks(block: Block, state: State) { * shadow block, or any connected real block. */ function loadConnection( - connection: Connection, connectionState: ConnectionState) { + connection: Connection, connectionState: ConnectionState) { if (connectionState['shadow']) { connection.setShadowState(connectionState['shadow']); } if (connectionState['block']) { appendPrivate( - connectionState['block'], connection.getSourceBlock().workspace, - { parentConnection: connection }); + connectionState['block'], connection.getSourceBlock().workspace, + {parentConnection: connection}); } } @@ -663,11 +663,11 @@ class BlockSerializer implements ISerializer { * @return The state of the workspace's blocks, or null if there are no * blocks. */ - save(workspace: Workspace): { languageVersion: number, blocks: State[] } | null { + save(workspace: Workspace): {languageVersion: number, blocks: State[]}|null { const blockStates = []; for (const block of workspace.getTopBlocks(false)) { const state = - saveBlock(block, { addCoordinates: true, doFullSerialization: false }); + saveBlock(block, {addCoordinates: true, doFullSerialization: false}); if (state) { blockStates.push(state); } @@ -688,10 +688,10 @@ class BlockSerializer implements ISerializer { * @param workspace The workspace to deserialize into. */ load( - state: { languageVersion: number, blocks: State[] }, workspace: Workspace) { + state: {languageVersion: number, blocks: State[]}, workspace: Workspace) { const blockStates = state['blocks']; for (const state of blockStates) { - append(state, workspace, { recordUndo: eventUtils.getRecordUndo() }); + append(state, workspace, {recordUndo: eventUtils.getRecordUndo()}); } } diff --git a/core/serialization/exceptions.ts b/core/serialization/exceptions.ts index fa1044682..d8bf8af9a 100644 --- a/core/serialization/exceptions.ts +++ b/core/serialization/exceptions.ts @@ -35,10 +35,10 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Block } from '../block.js'; +import {Block} from '../block.js'; // eslint-disable-next-line no-unused-vars -import { State } from './blocks.js'; +import {State} from './blocks.js'; /** @alias Blockly.serialization.exceptions.DeserializationError */ @@ -88,8 +88,8 @@ export class BadConnectionCheck extends DeserializationError { * @param childState The state object representing the child block. */ constructor( - reason: string, childConnection: string, public childBlock: Block, - public childState: State) { + reason: string, childConnection: string, public childBlock: Block, + public childState: State) { super(`The block ${childBlock.toDevString()} could not connect its ${childConnection} to its parent, because: ${reason}`); } diff --git a/core/serialization/registry.ts b/core/serialization/registry.ts index 210ce85df..bf3553915 100644 --- a/core/serialization/registry.ts +++ b/core/serialization/registry.ts @@ -17,7 +17,7 @@ */ // eslint-disable-next-line no-unused-vars -import { ISerializer } from '../interfaces/i_serializer.js'; +import {ISerializer} from '../interfaces/i_serializer.js'; import * as registry from '../registry.js'; diff --git a/core/serialization/variables.ts b/core/serialization/variables.ts index 4f93f25f8..dc85d55d3 100644 --- a/core/serialization/variables.ts +++ b/core/serialization/variables.ts @@ -17,9 +17,9 @@ */ // eslint-disable-next-line no-unused-vars -import { ISerializer } from '../interfaces/i_serializer.js'; +import {ISerializer} from '../interfaces/i_serializer.js'; // eslint-disable-next-line no-unused-vars -import { Workspace } from '../workspace.js'; +import {Workspace} from '../workspace.js'; import * as priorities from './priorities.js'; import * as serializationRegistry from './registry.js'; @@ -32,7 +32,7 @@ import * as serializationRegistry from './registry.js'; export interface State { name: string; id: string; - type: string | undefined; + type: string|undefined; } /** @@ -54,7 +54,7 @@ class VariableSerializer implements ISerializer { * @return The state of the workspace's variables, or null if there are no * variables. */ - save(workspace: Workspace): State[] | null { + save(workspace: Workspace): State[]|null { const variableStates = []; for (const variable of workspace.getAllVariables()) { const state = { @@ -69,7 +69,7 @@ class VariableSerializer implements ISerializer { // AnyDuringMigration because: Type '{ name: string; id: string; }[] | // null' is not assignable to type 'State[] | null'. return (variableStates.length ? variableStates : null) as - AnyDuringMigration; + AnyDuringMigration; } /** @@ -81,7 +81,7 @@ class VariableSerializer implements ISerializer { load(state: State[], workspace: Workspace) { for (const varState of state) { workspace.createVariable( - varState['name'], varState['type'], varState['id']); + varState['name'], varState['type'], varState['id']); } } diff --git a/core/serialization/workspaces.ts b/core/serialization/workspaces.ts index 606032fe7..1911987c5 100644 --- a/core/serialization/workspaces.ts +++ b/core/serialization/workspaces.ts @@ -17,12 +17,12 @@ */ import * as eventUtils from '../events/utils.js'; -import { ISerializer } from '../interfaces/i_serializer.js'; +import {ISerializer} from '../interfaces/i_serializer.js'; import * as registry from '../registry.js'; import * as dom from '../utils/dom.js'; // eslint-disable-next-line no-unused-vars -import { Workspace } from '../workspace.js'; -import { WorkspaceSvg } from '../workspace_svg.js'; +import {Workspace} from '../workspace.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; /** @@ -31,7 +31,8 @@ import { WorkspaceSvg } from '../workspace_svg.js'; * @return The serialized state of the workspace. * @alias Blockly.serialization.workspaces.save */ -export function save(workspace: Workspace): { [key: string]: AnyDuringMigration } { +export function save(workspace: Workspace): + {[key: string]: AnyDuringMigration} { const state = Object.create(null); const serializerMap = registry.getAllItems(registry.Type.SERIALIZER, true); for (const key in serializerMap) { @@ -52,17 +53,17 @@ export function save(workspace: Workspace): { [key: string]: AnyDuringMigration * @alias Blockly.serialization.workspaces.load */ export function load( - state: { [key: string]: AnyDuringMigration }, workspace: Workspace, - { recordUndo = false }: { recordUndo?: boolean } = {}) { + state: {[key: string]: AnyDuringMigration}, workspace: Workspace, + {recordUndo = false}: {recordUndo?: boolean} = {}) { const serializerMap = registry.getAllItems(registry.Type.SERIALIZER, true); if (!serializerMap) { return; } const deserializers = Object.entries(serializerMap) - .sort( - (a, b) => (b[1] as ISerializer)!.priority - - (a[1] as ISerializer)!.priority); + .sort( + (a, b) => (b[1] as ISerializer)!.priority - + (a[1] as ISerializer)!.priority); const prevRecordUndo = eventUtils.getRecordUndo(); eventUtils.setRecordUndo(recordUndo); @@ -97,7 +98,7 @@ export function load( dom.stopTextWidthCache(); eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))! - (workspace)); + (workspace)); eventUtils.setGroup(existingGroup); eventUtils.setRecordUndo(prevRecordUndo); diff --git a/core/shortcut_items.ts b/core/shortcut_items.ts index e672291f1..75fdffbea 100644 --- a/core/shortcut_items.ts +++ b/core/shortcut_items.ts @@ -11,15 +11,15 @@ * Registers default keyboard shortcuts. * @namespace Blockly.ShortcutItems */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; import * as clipboard from './clipboard.js'; import * as common from './common.js'; -import { Gesture } from './gesture.js'; +import {Gesture} from './gesture.js'; /* eslint-disable-next-line no-unused-vars */ -import { ICopyable } from './interfaces/i_copyable.js'; -import { KeyboardShortcut, ShortcutRegistry } from './shortcut_registry.js'; -import { KeyCodes } from './utils/keycodes.js'; -import { WorkspaceSvg } from './workspace_svg.js'; +import {ICopyable} from './interfaces/i_copyable.js'; +import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js'; +import {KeyCodes} from './utils/keycodes.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -103,7 +103,7 @@ export function registerCopy() { preconditionFn(workspace) { const selected = common.getSelected(); return !workspace.options.readOnly && !Gesture.inProgress() && selected && - selected.isDeletable() && selected.isMovable(); + selected.isDeletable() && selected.isMovable(); }, callback(workspace, e) { // Prevent the default copy behavior, which may beep or otherwise indicate @@ -137,9 +137,9 @@ export function registerCut() { preconditionFn(workspace) { const selected = common.getSelected(); return !!( - !workspace.options.readOnly && !Gesture.inProgress() && selected && - selected instanceof BlockSvg && selected.isDeletable() && - selected.isMovable() && !selected.workspace.isFlyout); + !workspace.options.readOnly && !Gesture.inProgress() && selected && + selected instanceof BlockSvg && selected.isDeletable() && + selected.isMovable() && !selected.workspace.isFlyout); }, callback() { const selected = common.getSelected(); diff --git a/core/shortcut_registry.ts b/core/shortcut_registry.ts index 82ed09e08..ab5516352 100644 --- a/core/shortcut_registry.ts +++ b/core/shortcut_registry.ts @@ -16,10 +16,10 @@ * @class */ -import { KeyCodes } from './utils/keycodes.js'; +import {KeyCodes} from './utils/keycodes.js'; import * as object from './utils/object.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -38,9 +38,9 @@ export class ShortcutRegistry { }; static registry: AnyDuringMigration; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - private registry_!: { [key: string]: KeyboardShortcut }; + private registry_!: {[key: string]: KeyboardShortcut}; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. - private keyMap_!: { [key: string]: string[] }; + private keyMap_!: {[key: string]: string[]}; /** Resets the existing ShortcutRegistry singleton. */ constructor() { @@ -67,7 +67,7 @@ export class ShortcutRegistry { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( - 'Shortcut with name "' + shortcut.name + '" already exists.'); + 'Shortcut with name "' + shortcut.name + '" already exists.'); } this.registry_[shortcut.name] = shortcut; @@ -91,7 +91,7 @@ export class ShortcutRegistry { if (!shortcut) { console.warn( - 'Keyboard shortcut with name "' + shortcutName + '" not found.'); + 'Keyboard shortcut with name "' + shortcutName + '" not found.'); return false; } @@ -113,14 +113,14 @@ export class ShortcutRegistry { * @throws {Error} if the given key code is already mapped to a shortcut. */ addKeyMapping( - keyCode: string | number | KeyCodes, shortcutName: string, - opt_allowCollision?: boolean) { + keyCode: string|number|KeyCodes, shortcutName: string, + opt_allowCollision?: boolean) { keyCode = String(keyCode); const shortcutNames = this.keyMap_[keyCode]; if (shortcutNames && !opt_allowCollision) { throw new Error( - 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + - shortcutNames.toString()); + 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + + shortcutNames.toString()); } else if (shortcutNames && opt_allowCollision) { shortcutNames.unshift(shortcutName); } else { @@ -140,13 +140,13 @@ export class ShortcutRegistry { * @return True if a key mapping was removed, false otherwise. */ removeKeyMapping(keyCode: string, shortcutName: string, opt_quiet?: boolean): - boolean { + boolean { const shortcutNames = this.keyMap_[keyCode]; if (!shortcutNames && !opt_quiet) { console.warn( - 'No keyboard shortcut with name "' + shortcutName + - '" registered with key code "' + keyCode + '"'); + 'No keyboard shortcut with name "' + shortcutName + + '" registered with key code "' + keyCode + '"'); return false; } @@ -160,8 +160,8 @@ export class ShortcutRegistry { } if (!opt_quiet) { console.warn( - 'No keyboard shortcut with name "' + shortcutName + - '" registered with key code "' + keyCode + '"'); + 'No keyboard shortcut with name "' + shortcutName + + '" registered with key code "' + keyCode + '"'); } return false; } @@ -183,7 +183,7 @@ export class ShortcutRegistry { * mappings. * @param keyMap The object with key code to shortcut names. */ - setKeyMap(keyMap: { [key: string]: string[] }) { + setKeyMap(keyMap: {[key: string]: string[]}) { this.keyMap_ = keyMap; } @@ -191,7 +191,7 @@ export class ShortcutRegistry { * Gets the current key map. * @return The object holding key codes to ShortcutRegistry.KeyboardShortcut. */ - getKeyMap(): { [key: string]: KeyboardShortcut[] } { + getKeyMap(): {[key: string]: KeyboardShortcut[]} { return object.deepMerge(Object.create(null), this.keyMap_); } @@ -199,7 +199,7 @@ export class ShortcutRegistry { * Gets the registry of keyboard shortcuts. * @return The registry of keyboard shortcuts. */ - getRegistry(): { [key: string]: KeyboardShortcut } { + getRegistry(): {[key: string]: KeyboardShortcut} { return object.deepMerge(Object.create(null), this.registry_); } @@ -233,7 +233,7 @@ export class ShortcutRegistry { * @return The list of shortcuts to call when the given keyCode is used. * Undefined if no shortcuts exist. */ - getShortcutNamesByKeyCode(keyCode: string): string[] | undefined { + getShortcutNamesByKeyCode(keyCode: string): string[]|undefined { return this.keyMap_[keyCode] || []; } @@ -299,14 +299,14 @@ export class ShortcutRegistry { * valid modifiers can be found in the ShortcutRegistry.modifierKeys. * @return The serialized key code for the given modifiers and key. */ - createSerializedKey(keyCode: number, modifiers: string[] | null): string { + createSerializedKey(keyCode: number, modifiers: string[]|null): string { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); for (const modifier in ShortcutRegistry.modifierKeys) { const modifierKeyCode = - (ShortcutRegistry.modifierKeys as AnyDuringMigration)[modifier]; + (ShortcutRegistry.modifierKeys as AnyDuringMigration)[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey !== '') { serializedKey += '+'; @@ -326,8 +326,7 @@ export class ShortcutRegistry { } export interface KeyboardShortcut { - callback?: - ((p1: Workspace, p2: Event, p3: KeyboardShortcut) => boolean); + callback?: ((p1: Workspace, p2: Event, p3: KeyboardShortcut) => boolean); name: string; preconditionFn?: ((p1: Workspace) => boolean); metadata?: object; diff --git a/core/theme.ts b/core/theme.ts index 67cc3064b..d1b8b0721 100644 --- a/core/theme.ts +++ b/core/theme.ts @@ -21,8 +21,8 @@ import * as object from './utils/object.js'; * @alias Blockly.Theme */ export class Theme { - blockStyles: { [key: string]: BlockStyle }; - categoryStyles: { [key: string]: CategoryStyle }; + blockStyles: {[key: string]: BlockStyle}; + categoryStyles: {[key: string]: CategoryStyle}; componentStyles: ComponentStyle; fontStyle: FontStyle; @@ -30,7 +30,7 @@ export class Theme { * Whether or not to add a 'hat' on top of all blocks with no previous or * output connections. */ - startHats: boolean | null = null; + startHats: boolean|null = null; /** * @param name Theme name. @@ -41,9 +41,9 @@ export class Theme { * @param opt_componentStyles A map of Blockly component names to style value. */ constructor( - public name: string, opt_blockStyles?: { [key: string]: BlockStyle }, - opt_categoryStyles?: { [key: string]: CategoryStyle }, - opt_componentStyles?: ComponentStyle) { + public name: string, opt_blockStyles?: {[key: string]: BlockStyle}, + opt_categoryStyles?: {[key: string]: CategoryStyle}, + opt_componentStyles?: ComponentStyle) { /** The block styles map. */ this.blockStyles = opt_blockStyles || Object.create(null); @@ -52,7 +52,7 @@ export class Theme { /** The UI components styles map. */ this.componentStyles = - opt_componentStyles || Object.create(null) as ComponentStyle; + opt_componentStyles || Object.create(null) as ComponentStyle; /** The font style. */ this.fontStyle = Object.create(null) as FontStyle; @@ -93,7 +93,7 @@ export class Theme { * @param componentName The name of the component. * @return The style value. */ - getComponentStyle(componentName: string): string | null { + getComponentStyle(componentName: string): string|null { const style = (this.componentStyles as AnyDuringMigration)[componentName]; if (style && typeof style === 'string' && this.getComponentStyle((style))) { return this.getComponentStyle((style)); @@ -166,25 +166,25 @@ export interface CategoryStyle { colour: string; } export interface ComponentStyle { - workspaceBackgroundColour: string | null; - toolboxBackgroundColour: string | null; - toolboxForegroundColour: string | null; - flyoutBackgroundColour: string | null; - flyoutForegroundColour: string | null; - flyoutOpacity: number | null; - scrollbarColour: string | null; - scrollbarOpacity: number | null; - insertionMarkerColour: string | null; - insertionMarkerOpacity: number | null; - markerColour: string | null; - cursorColour: string | null; - selectedGlowColour: string | null; - selectedGlowOpacity: number | null; - replacementGlowColour: string | null; - replacementGlowOpacity: number | null; + workspaceBackgroundColour: string|null; + toolboxBackgroundColour: string|null; + toolboxForegroundColour: string|null; + flyoutBackgroundColour: string|null; + flyoutForegroundColour: string|null; + flyoutOpacity: number|null; + scrollbarColour: string|null; + scrollbarOpacity: number|null; + insertionMarkerColour: string|null; + insertionMarkerOpacity: number|null; + markerColour: string|null; + cursorColour: string|null; + selectedGlowColour: string|null; + selectedGlowOpacity: number|null; + replacementGlowColour: string|null; + replacementGlowOpacity: number|null; } export interface FontStyle { - family: string | null; - weight: string | null; - size: number | null; + family: string|null; + weight: string|null; + size: number|null; } diff --git a/core/theme/classic.ts b/core/theme/classic.ts index 727cffe8e..50b10f1ef 100644 --- a/core/theme/classic.ts +++ b/core/theme/classic.ts @@ -16,32 +16,32 @@ * @namespace Blockly.Themes.Classic */ -import { Theme } from '../theme.js'; +import {Theme} from '../theme.js'; const defaultBlockStyles = { - 'colour_blocks': { 'colourPrimary': '20' }, - 'list_blocks': { 'colourPrimary': '260' }, - 'logic_blocks': { 'colourPrimary': '210' }, - 'loop_blocks': { 'colourPrimary': '120' }, - 'math_blocks': { 'colourPrimary': '230' }, - 'procedure_blocks': { 'colourPrimary': '290' }, - 'text_blocks': { 'colourPrimary': '160' }, - 'variable_blocks': { 'colourPrimary': '330' }, - 'variable_dynamic_blocks': { 'colourPrimary': '310' }, - 'hat_blocks': { 'colourPrimary': '330', 'hat': 'cap' }, + 'colour_blocks': {'colourPrimary': '20'}, + 'list_blocks': {'colourPrimary': '260'}, + 'logic_blocks': {'colourPrimary': '210'}, + 'loop_blocks': {'colourPrimary': '120'}, + 'math_blocks': {'colourPrimary': '230'}, + 'procedure_blocks': {'colourPrimary': '290'}, + 'text_blocks': {'colourPrimary': '160'}, + 'variable_blocks': {'colourPrimary': '330'}, + 'variable_dynamic_blocks': {'colourPrimary': '310'}, + 'hat_blocks': {'colourPrimary': '330', 'hat': 'cap'}, }; const categoryStyles = { - 'colour_category': { 'colour': '20' }, - 'list_category': { 'colour': '260' }, - 'logic_category': { 'colour': '210' }, - 'loop_category': { 'colour': '120' }, - 'math_category': { 'colour': '230' }, - 'procedure_category': { 'colour': '290' }, - 'text_category': { 'colour': '160' }, - 'variable_category': { 'colour': '330' }, - 'variable_dynamic_category': { 'colour': '310' }, + 'colour_category': {'colour': '20'}, + 'list_category': {'colour': '260'}, + 'logic_category': {'colour': '210'}, + 'loop_category': {'colour': '120'}, + 'math_category': {'colour': '230'}, + 'procedure_category': {'colour': '290'}, + 'text_category': {'colour': '160'}, + 'variable_category': {'colour': '330'}, + 'variable_dynamic_category': {'colour': '310'}, }; /** diff --git a/core/theme/themes.ts b/core/theme/themes.ts index 5d6e64e5f..cd051d72f 100644 --- a/core/theme/themes.ts +++ b/core/theme/themes.ts @@ -12,7 +12,7 @@ * @namespace Blockly.Themes */ -import { Classic } from './classic.js'; -import { Zelos } from './zelos.js'; +import {Classic} from './classic.js'; +import {Zelos} from './zelos.js'; -export { Classic, Zelos }; +export {Classic, Zelos}; diff --git a/core/theme/zelos.ts b/core/theme/zelos.ts index b7cc7d8a7..ede6bd9c4 100644 --- a/core/theme/zelos.ts +++ b/core/theme/zelos.ts @@ -12,7 +12,7 @@ * @namespace Blockly.Themes.Zelos */ -import { Theme } from '../theme.js'; +import {Theme} from '../theme.js'; const defaultBlockStyles = { @@ -70,15 +70,15 @@ const defaultBlockStyles = { }; const categoryStyles = { - 'colour_category': { 'colour': '#CF63CF' }, - 'list_category': { 'colour': '#9966FF' }, - 'logic_category': { 'colour': '#4C97FF' }, - 'loop_category': { 'colour': '#0fBD8C' }, - 'math_category': { 'colour': '#59C059' }, - 'procedure_category': { 'colour': '#FF6680' }, - 'text_category': { 'colour': '#FFBF00' }, - 'variable_category': { 'colour': '#FF8C1A' }, - 'variable_dynamic_category': { 'colour': '#FF8C1A' }, + 'colour_category': {'colour': '#CF63CF'}, + 'list_category': {'colour': '#9966FF'}, + 'logic_category': {'colour': '#4C97FF'}, + 'loop_category': {'colour': '#0fBD8C'}, + 'math_category': {'colour': '#59C059'}, + 'procedure_category': {'colour': '#FF6680'}, + 'text_category': {'colour': '#FFBF00'}, + 'variable_category': {'colour': '#FF8C1A'}, + 'variable_dynamic_category': {'colour': '#FF8C1A'}, }; /** diff --git a/core/theme_manager.ts b/core/theme_manager.ts index 27664b885..dbe47ae33 100644 --- a/core/theme_manager.ts +++ b/core/theme_manager.ts @@ -17,13 +17,13 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Theme } from './theme.js'; +import {Theme} from './theme.js'; import * as arrayUtils from './utils/array.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -33,7 +33,7 @@ import { WorkspaceSvg } from './workspace_svg.js'; export class ThemeManager { /** A list of workspaces that are subscribed to this theme. */ private subscribedWorkspaces_: Workspace[] = []; - private componentDB_: { [key: string]: Component[] }; + private componentDB_: {[key: string]: Component[]}; owner_: AnyDuringMigration; /** @@ -76,7 +76,7 @@ export class ThemeManager { // Refresh all registered Blockly UI components. for (let i = 0, keys = Object.keys(this.componentDB_), key; key = keys[i]; - i++) { + i++) { for (let j = 0, component; component = this.componentDB_[key][j]; j++) { const element = component.element; const propertyName = component.propertyName; @@ -108,7 +108,7 @@ export class ThemeManager { unsubscribeWorkspace(workspace: Workspace) { if (!arrayUtils.removeElem(this.subscribedWorkspaces_, workspace)) { throw Error( - 'Cannot unsubscribe a workspace that hasn\'t been subscribed.'); + 'Cannot unsubscribe a workspace that hasn\'t been subscribed.'); } } @@ -126,7 +126,7 @@ export class ThemeManager { } // Add the element to our component map. - this.componentDB_[componentName].push({ element, propertyName }); + this.componentDB_[componentName].push({element, propertyName}); // Initialize the element with its corresponding theme style. const style = this.theme && this.theme.getComponentStyle(componentName); diff --git a/core/toolbox/category.ts b/core/toolbox/category.ts index 905ee2996..84b11646e 100644 --- a/core/toolbox/category.ts +++ b/core/toolbox/category.ts @@ -14,12 +14,12 @@ import * as Css from '../css.js'; /* eslint-disable-next-line no-unused-vars */ -import { ICollapsibleToolboxItem } from '../interfaces/i_collapsible_toolbox_item.js'; +import {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { ISelectableToolboxItem } from '../interfaces/i_selectable_toolbox_item.js'; +import {ISelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from '../interfaces/i_toolbox.js'; -import { IToolboxItem } from '../interfaces/i_toolbox_item.js'; +import {IToolbox} from '../interfaces/i_toolbox.js'; +import {IToolboxItem} from '../interfaces/i_toolbox_item.js'; import * as registry from '../registry.js'; import * as aria from '../utils/aria.js'; import * as colourUtils from '../utils/colour.js'; @@ -27,7 +27,7 @@ import * as dom from '../utils/dom.js'; import * as parsing from '../utils/parsing.js'; import * as toolbox from '../utils/toolbox.js'; -import { ToolboxItem } from './toolbox_item.js'; +import {ToolboxItem} from './toolbox_item.js'; /** @@ -35,7 +35,7 @@ import { ToolboxItem } from './toolbox_item.js'; * @alias Blockly.ToolboxCategory */ export class ToolboxCategory extends ToolboxItem implements - ISelectableToolboxItem { + ISelectableToolboxItem { /** Name used for registering a toolbox category. */ static registrationName = 'category'; @@ -61,19 +61,19 @@ export class ToolboxCategory extends ToolboxItem implements protected colour_ = ''; /** The html container for the category. */ - protected htmlDiv_: HTMLDivElement | null = null; + protected htmlDiv_: HTMLDivElement|null = null; /** The html element for the category row. */ - protected rowDiv_: HTMLDivElement | null = null; + protected rowDiv_: HTMLDivElement|null = null; /** The html element that holds children elements of the category row. */ - protected rowContents_: HTMLDivElement | null = null; + protected rowContents_: HTMLDivElement|null = null; /** The html element for the toolbox icon. */ - protected iconDom_: Element | null = null; + protected iconDom_: Element|null = null; /** The html element for the toolbox label. */ - protected labelDom_: Element | null = null; + protected labelDom_: Element|null = null; protected cssConfig_: CssConfig; /** True if the category is meant to be hidden, false otherwise. */ @@ -83,7 +83,7 @@ export class ToolboxCategory extends ToolboxItem implements protected isDisabled_ = false; /** The flyout items for this category. */ - protected flyoutItems_: string | toolbox.FlyoutItemInfoArray = []; + protected flyoutItems_: string|toolbox.FlyoutItemInfoArray = []; /** * @param categoryDef The information needed to create a category in the @@ -93,8 +93,8 @@ export class ToolboxCategory extends ToolboxItem implements * a parent. */ constructor( - categoryDef: toolbox.CategoryInfo, parentToolbox: IToolbox, - opt_parent?: ICollapsibleToolboxItem) { + categoryDef: toolbox.CategoryInfo, parentToolbox: IToolbox, + opt_parent?: ICollapsibleToolboxItem) { super(categoryDef, parentToolbox, opt_parent); /** All the css class names that are used to create a category. */ @@ -167,7 +167,7 @@ export class ToolboxCategory extends ToolboxItem implements */ protected parseCategoryDef_(categoryDef: toolbox.CategoryInfo) { this.name_ = parsing.replaceMessageReferences( - (categoryDef as AnyDuringMigration)['name']); + (categoryDef as AnyDuringMigration)['name']); this.colour_ = this.getColour_(categoryDef); Object.assign( this.cssConfig_, @@ -201,8 +201,8 @@ export class ToolboxCategory extends ToolboxItem implements // 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); + this.htmlDiv_ as Element, aria.State.LABELLEDBY, + this.labelDom_.getAttribute('id') as AnyDuringMigration); this.addColourBorder_(this.colour_); @@ -218,7 +218,7 @@ export class ToolboxCategory extends ToolboxItem implements // AnyDuringMigration because: Argument of type 'string | undefined' is not // assignable to parameter of type 'string'. dom.addClass( - container, (this.cssConfig_ as AnyDuringMigration)['container']); + container, (this.cssConfig_ as AnyDuringMigration)['container']); return container; } @@ -240,8 +240,8 @@ export class ToolboxCategory extends ToolboxItem implements // '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; + rowDiv.style.paddingRight = nestedPadding as AnyDuringMigration : + rowDiv.style.paddingLeft = nestedPadding as AnyDuringMigration; return rowDiv; } @@ -255,8 +255,8 @@ export class ToolboxCategory extends ToolboxItem implements // AnyDuringMigration because: Argument of type 'string | undefined' is not // assignable to parameter of type 'string'. dom.addClass( - contentsContainer, - (this.cssConfig_ as AnyDuringMigration)['rowcontentcontainer']); + contentsContainer, + (this.cssConfig_ as AnyDuringMigration)['rowcontentcontainer']); return contentsContainer; } @@ -270,7 +270,7 @@ export class ToolboxCategory extends ToolboxItem implements // AnyDuringMigration because: Argument of type 'string | undefined' is // not assignable to parameter of type 'string'. dom.addClass( - toolboxIcon, (this.cssConfig_ as AnyDuringMigration)['icon']); + toolboxIcon, (this.cssConfig_ as AnyDuringMigration)['icon']); } toolboxIcon.style.display = 'inline-block'; @@ -290,7 +290,7 @@ export class ToolboxCategory extends ToolboxItem implements // AnyDuringMigration because: Argument of type 'string | undefined' is not // assignable to parameter of type 'string'. dom.addClass( - toolboxLabel, (this.cssConfig_ as AnyDuringMigration)['label']); + toolboxLabel, (this.cssConfig_ as AnyDuringMigration)['label']); return toolboxLabel; } @@ -307,7 +307,7 @@ export class ToolboxCategory extends ToolboxItem implements protected addColourBorder_(colour: string) { if (colour) { const border = - ToolboxCategory.borderWidth + 'px solid ' + (colour || '#ddd'); + ToolboxCategory.borderWidth + 'px solid ' + (colour || '#ddd'); if (this.workspace_.RTL) { this.rowDiv_!.style.borderRight = border; } else { @@ -323,13 +323,13 @@ export class ToolboxCategory extends ToolboxItem implements */ protected getColour_(categoryDef: toolbox.CategoryInfo): string { const styleName = - categoryDef['categorystyle'] || (categoryDef as any)['categoryStyle']; + categoryDef['categorystyle'] || (categoryDef as any)['categoryStyle']; const colour = categoryDef['colour']; if (colour && styleName) { console.warn( - 'Toolbox category "' + this.name_ + - '" must not have both a style and a colour'); + 'Toolbox category "' + this.name_ + + '" must not have both a style and a colour'); } else if (styleName) { return this.getColourfromStyle_(styleName); } else { @@ -354,7 +354,7 @@ export class ToolboxCategory extends ToolboxItem implements return this.parseColour_(style.colour); } else { console.warn( - 'Style "' + styleName + '" must exist and contain a colour value'); + 'Style "' + styleName + '" must exist and contain a colour value'); } } return ''; @@ -377,7 +377,7 @@ export class ToolboxCategory extends ToolboxItem implements * reference string pointing to one of those two values. * @return The hex colour for the category. */ - private parseColour_(colourValue: number | string): string { + private parseColour_(colourValue: number|string): string { // Decode the colour for any potential message references // (eg. `%{BKY_MATH_HUE}`). const colour = parsing.replaceMessageReferences(colourValue); @@ -394,8 +394,8 @@ export class ToolboxCategory extends ToolboxItem implements return hex; } else { console.warn( - 'Toolbox category "' + this.name_ + - '" has unrecognized colour attribute: ' + colour); + 'Toolbox category "' + this.name_ + + '" has unrecognized colour attribute: ' + colour); return ''; } } @@ -406,14 +406,14 @@ export class ToolboxCategory extends ToolboxItem implements * Adds appropriate classes to display an open icon. * @param iconDiv The div that holds the icon. */ - protected openIcon_(iconDiv: Element | null) { + protected openIcon_(iconDiv: Element|null) { 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']); + iconDiv, (this.cssConfig_ as AnyDuringMigration)['closedicon']); // AnyDuringMigration because: Argument of type 'string | undefined' is not // assignable to parameter of type 'string'. dom.addClass(iconDiv, (this.cssConfig_ as AnyDuringMigration)['openicon']); @@ -423,18 +423,18 @@ export class ToolboxCategory extends ToolboxItem implements * Adds appropriate classes to display a closed icon. * @param iconDiv The div that holds the icon. */ - protected closeIcon_(iconDiv: Element | null) { + protected closeIcon_(iconDiv: Element|null) { 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']); + iconDiv, (this.cssConfig_ as AnyDuringMigration)['openicon']); // AnyDuringMigration because: Argument of type 'string | undefined' is not // assignable to parameter of type 'string'. dom.addClass( - iconDiv, (this.cssConfig_ as AnyDuringMigration)['closedicon']); + iconDiv, (this.cssConfig_ as AnyDuringMigration)['closedicon']); } /** @@ -508,7 +508,7 @@ export class ToolboxCategory extends ToolboxItem implements setSelected(isSelected: boolean) { if (isSelected) { const defaultColour = - this.parseColour_(ToolboxCategory.defaultBackgroundColour); + this.parseColour_(ToolboxCategory.defaultBackgroundColour); this.rowDiv_!.style.backgroundColor = this.colour_ || defaultColour; dom.addClass(this.rowDiv_!, this.cssConfig_['selected']!); } else { @@ -528,7 +528,7 @@ export class ToolboxCategory extends ToolboxItem implements // to parameter of type 'string'. this.getDiv()!.setAttribute('disabled', isDisabled as AnyDuringMigration); isDisabled ? this.getDiv()!.setAttribute('disabled', 'true') : - this.getDiv()!.removeAttribute('disabled'); + this.getDiv()!.removeAttribute('disabled'); } /** @@ -552,7 +552,7 @@ export class ToolboxCategory extends ToolboxItem implements * displayed in the flyout. * @return The definition of items to be displayed in the flyout. */ - getContents(): toolbox.FlyoutItemInfoArray | string { + getContents(): toolbox.FlyoutItemInfoArray|string { return this.flyoutItems_; } @@ -563,7 +563,7 @@ 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: toolbox.FlyoutDefinition|string) { this.flyoutItems_ = []; if (typeof contents === 'string') { @@ -572,7 +572,7 @@ export class ToolboxCategory extends ToolboxItem implements // Removes old custom field when contents is updated. delete (this.toolboxItemDef_ as AnyDuringMigration)['custom']; (this.toolboxItemDef_ as AnyDuringMigration)['contents'] = - toolbox.convertFlyoutDefToJsonArray(contents); + toolbox.convertFlyoutDefToJsonArray(contents); } this.parseContents_((this.toolboxItemDef_)); } @@ -582,14 +582,14 @@ export class ToolboxCategory extends ToolboxItem implements } } 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|undefined; + row: string|undefined; + rowcontentcontainer: string|undefined; + icon: string|undefined; + label: string|undefined; + selected: string|undefined; + openicon: string|undefined; + closedicon: string|undefined; } /** CSS for Toolbox. See css.js for use. */ @@ -668,5 +668,5 @@ Css.register(` `); registry.register( - registry.Type.TOOLBOX_ITEM, ToolboxCategory.registrationName, - ToolboxCategory); + registry.Type.TOOLBOX_ITEM, ToolboxCategory.registrationName, + ToolboxCategory); diff --git a/core/toolbox/collapsible_category.ts b/core/toolbox/collapsible_category.ts index 07ae7fc94..3866a0f14 100644 --- a/core/toolbox/collapsible_category.ts +++ b/core/toolbox/collapsible_category.ts @@ -13,18 +13,18 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ICollapsibleToolboxItem } from '../interfaces/i_collapsible_toolbox_item.js'; +import {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from '../interfaces/i_toolbox.js'; +import {IToolbox} from '../interfaces/i_toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolboxItem } from '../interfaces/i_toolbox_item.js'; +import {IToolboxItem} from '../interfaces/i_toolbox_item.js'; import * as registry from '../registry.js'; import * as aria from '../utils/aria.js'; import * as dom from '../utils/dom.js'; import * as toolbox from '../utils/toolbox.js'; -import { ToolboxCategory } from './category.js'; -import { ToolboxSeparator } from './separator.js'; +import {ToolboxCategory} from './category.js'; +import {ToolboxSeparator} from './separator.js'; /** @@ -32,12 +32,12 @@ import { ToolboxSeparator } from './separator.js'; * @alias Blockly.CollapsibleToolboxCategory */ export class CollapsibleToolboxCategory extends ToolboxCategory implements - ICollapsibleToolboxItem { + ICollapsibleToolboxItem { /** Name used for registering a collapsible toolbox category. */ static override registrationName = 'collapsibleCategory'; /** Container for any child categories. */ - protected subcategoriesDiv_: HTMLDivElement | null = null; + protected subcategoriesDiv_: HTMLDivElement|null = null; /** Whether or not the category should display its subcategories. */ protected expanded_ = false; @@ -55,8 +55,8 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements * a parent. */ constructor( - categoryDef: toolbox.CategoryInfo, toolbox: IToolbox, - opt_parent?: ICollapsibleToolboxItem) { + categoryDef: toolbox.CategoryInfo, toolbox: IToolbox, + opt_parent?: ICollapsibleToolboxItem) { super(categoryDef, toolbox, opt_parent); } @@ -86,9 +86,9 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements // Separators can exist as either a flyout item or a toolbox item so // decide where it goes based on the type of the previous item. if (!registry.hasItem(registry.Type.TOOLBOX_ITEM, itemDef['kind']) || - itemDef['kind'].toLowerCase() === - ToolboxSeparator.registrationName && - prevIsFlyoutItem) { + itemDef['kind'].toLowerCase() === + ToolboxSeparator.registrationName && + prevIsFlyoutItem) { const flyoutItem = itemDef as toolbox.FlyoutItemInfo; this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; @@ -110,13 +110,13 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements // Categories that are collapsible are created using a class registered // under a different name. if (registryName.toUpperCase() == 'CATEGORY' && - toolbox.isCategoryCollapsible(categoryDef)) { + toolbox.isCategoryCollapsible(categoryDef)) { registryName = CollapsibleToolboxCategory.registrationName; } const ToolboxItemClass = - registry.getClass(registry.Type.TOOLBOX_ITEM, registryName); + registry.getClass(registry.Type.TOOLBOX_ITEM, registryName); const toolboxItem = - new ToolboxItemClass!(itemDef, this.parentToolbox, this); + new ToolboxItemClass!(itemDef, this.parentToolbox, this); this.toolboxItems_.push(toolboxItem); } @@ -124,8 +124,8 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements super.init(); this.setExpanded( - (this.toolboxItemDef_ as AnyDuringMigration)['expanded'] === 'true' || - (this.toolboxItemDef_ as AnyDuringMigration)['expanded']); + (this.toolboxItemDef_ as AnyDuringMigration)['expanded'] === 'true' || + (this.toolboxItemDef_ as AnyDuringMigration)['expanded']); } override createDom_() { @@ -145,7 +145,7 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements // AnyDuringMigration because: Argument of type 'string | undefined' is // not assignable to parameter of type 'string'. dom.addClass( - toolboxIcon, (this.cssConfig_ as AnyDuringMigration)['icon']); + toolboxIcon, (this.cssConfig_ as AnyDuringMigration)['icon']); toolboxIcon.style.visibility = 'visible'; } @@ -159,10 +159,10 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements * @return The div holding all the subcategories. */ protected createSubCategoriesDom_(subcategories: IToolboxItem[]): - HTMLDivElement { + HTMLDivElement { const contentsContainer = (document.createElement('div')); dom.addClass( - contentsContainer, (this.cssConfig_ as AnyDuringMigration)['contents']); + contentsContainer, (this.cssConfig_ as AnyDuringMigration)['contents']); for (let i = 0; i < subcategories.length; i++) { const newCategory = subcategories[i]; @@ -193,7 +193,7 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements this.closeIcon_(this.iconDom_); } aria.setState( - this.htmlDiv_ as HTMLDivElement, aria.State.EXPANDED, isExpanded); + this.htmlDiv_ as HTMLDivElement, aria.State.EXPANDED, isExpanded); this.parentToolbox.handleToolboxItemResize(); } @@ -247,18 +247,18 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements } } export interface CssConfig { - container: string | null; - row: string | null; - rowcontentcontainer: string | null; - icon: string | null; - label: string | null; - selected: string | null; - openicon: string | null; - closedicon: string | null; - contents: string | null; + container: string|null; + row: string|null; + rowcontentcontainer: string|null; + icon: string|null; + label: string|null; + selected: string|null; + openicon: string|null; + closedicon: string|null; + contents: string|null; } registry.register( - registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, - CollapsibleToolboxCategory); + registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, + CollapsibleToolboxCategory); diff --git a/core/toolbox/separator.ts b/core/toolbox/separator.ts index b31c046b9..79795d91f 100644 --- a/core/toolbox/separator.ts +++ b/core/toolbox/separator.ts @@ -14,13 +14,13 @@ import * as Css from '../css.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from '../interfaces/i_toolbox.js'; +import {IToolbox} from '../interfaces/i_toolbox.js'; import * as registry from '../registry.js'; import * as dom from '../utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ import * as toolbox from '../utils/toolbox.js'; -import { ToolboxItem } from './toolbox_item.js'; +import {ToolboxItem} from './toolbox_item.js'; /** @@ -33,9 +33,9 @@ export class ToolboxSeparator extends ToolboxItem { static registrationName = 'sep'; /** All the CSS class names that are used to create a separator. */ - protected cssConfig_: CssConfig = { 'container': 'blocklyTreeSeparator' }; + protected cssConfig_: CssConfig = {'container': 'blocklyTreeSeparator'}; - private htmlDiv_: HTMLDivElement | null = null; + private htmlDiv_: HTMLDivElement|null = null; /** * @param separatorDef The information needed to create a separator. @@ -45,7 +45,7 @@ export class ToolboxSeparator extends ToolboxItem { super(separatorDef, toolbox); const cssConfig = - separatorDef['cssconfig'] || (separatorDef as any)['cssConfig']; + separatorDef['cssconfig'] || (separatorDef as any)['cssConfig']; Object.assign(this.cssConfig_, cssConfig); } @@ -73,7 +73,7 @@ export class ToolboxSeparator extends ToolboxItem { } } export interface CssConfig { - container: string | undefined; + container: string|undefined; } /** CSS for Toolbox. See css.js for use. */ @@ -95,5 +95,5 @@ Css.register(` `); registry.register( - registry.Type.TOOLBOX_ITEM, ToolboxSeparator.registrationName, - ToolboxSeparator); + registry.Type.TOOLBOX_ITEM, ToolboxSeparator.registrationName, + ToolboxSeparator); diff --git a/core/toolbox/toolbox.ts b/core/toolbox/toolbox.ts index 2899a4940..45df25546 100644 --- a/core/toolbox/toolbox.ts +++ b/core/toolbox/toolbox.ts @@ -17,48 +17,48 @@ import '../shortcut_registry'; // Unused import preserved for side-effects. Remove if unneeded. import '../events/events_toolbox_item_select'; -import { BlockSvg } from '../block_svg.js'; +import {BlockSvg} from '../block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from '../blockly_options.js'; +import {BlocklyOptions} from '../blockly_options.js'; import * as browserEvents from '../browser_events.js'; import * as common from '../common.js'; -import { ComponentManager } from '../component_manager.js'; +import {ComponentManager} from '../component_manager.js'; import * as Css from '../css.js'; -import { DeleteArea } from '../delete_area.js'; +import {DeleteArea} from '../delete_area.js'; import * as eventUtils from '../events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IAutoHideable } from '../interfaces/i_autohideable.js'; +import {IAutoHideable} from '../interfaces/i_autohideable.js'; /* eslint-disable-next-line no-unused-vars */ -import { ICollapsibleToolboxItem } from '../interfaces/i_collapsible_toolbox_item.js'; +import {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from '../interfaces/i_draggable.js'; +import {IDraggable} from '../interfaces/i_draggable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from '../interfaces/i_flyout.js'; +import {IFlyout} from '../interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { IKeyboardAccessible } from '../interfaces/i_keyboard_accessible.js'; +import {IKeyboardAccessible} from '../interfaces/i_keyboard_accessible.js'; /* eslint-disable-next-line no-unused-vars */ -import { ISelectableToolboxItem } from '../interfaces/i_selectable_toolbox_item.js'; +import {ISelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { IStyleable } from '../interfaces/i_styleable.js'; +import {IStyleable} from '../interfaces/i_styleable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from '../interfaces/i_toolbox.js'; +import {IToolbox} from '../interfaces/i_toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolboxItem } from '../interfaces/i_toolbox_item.js'; -import { Options } from '../options.js'; +import {IToolboxItem} from '../interfaces/i_toolbox_item.js'; +import {Options} from '../options.js'; import * as registry from '../registry.js'; -import { KeyboardShortcut } from '../shortcut_registry.js'; +import {KeyboardShortcut} from '../shortcut_registry.js'; import * as Touch from '../touch.js'; import * as aria from '../utils/aria.js'; import * as dom from '../utils/dom.js'; -import { KeyCodes } from '../utils/keycodes.js'; -import { Rect } from '../utils/rect.js'; +import {KeyCodes} from '../utils/keycodes.js'; +import {Rect} from '../utils/rect.js'; import * as toolbox from '../utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { ToolboxCategory } from './category.js'; -import { CollapsibleToolboxCategory } from './collapsible_category.js'; +import {ToolboxCategory} from './category.js'; +import {CollapsibleToolboxCategory} from './collapsible_category.js'; /** @@ -67,8 +67,8 @@ import { CollapsibleToolboxCategory } from './collapsible_category.js'; * @alias Blockly.Toolbox */ export class Toolbox extends DeleteArea implements IAutoHideable, - IKeyboardAccessible, - IStyleable, IToolbox { + IKeyboardAccessible, + IStyleable, IToolbox { /** * The unique id for this component that is used to register with the * ComponentManager. @@ -78,10 +78,10 @@ export class Toolbox extends DeleteArea implements IAutoHideable, private readonly horizontalLayout_: boolean; /** The html container for the toolbox. */ - HtmlDiv: HTMLDivElement | null = null; + HtmlDiv: HTMLDivElement|null = null; /** The html container for the contents of a toolbox. */ - protected contentsDiv_: HTMLDivElement | null = null; + protected contentsDiv_: HTMLDivElement|null = null; /** Whether the Toolbox is visible. */ protected isVisible_ = false; @@ -97,15 +97,15 @@ export class Toolbox extends DeleteArea implements IAutoHideable, RTL: boolean; /** The flyout for the toolbox. */ - private flyout_: IFlyout | null = null; - protected contentMap_: { [key: string]: IToolboxItem }; + private flyout_: IFlyout|null = null; + protected contentMap_: {[key: string]: IToolboxItem}; toolboxPosition: toolbox.Position; /** The currently selected item. */ - protected selectedItem_: ISelectableToolboxItem | null = null; + protected selectedItem_: ISelectableToolboxItem|null = null; /** The previously selected item. */ - protected previouslySelectedItem_: ISelectableToolboxItem | null = null; + protected previouslySelectedItem_: ISelectableToolboxItem|null = null; /** * Array holding info needed to unbind event handlers. @@ -122,8 +122,8 @@ export class Toolbox extends DeleteArea implements IAutoHideable, /** The JSON describing the contents of this toolbox. */ // AnyDuringMigration because: Type 'ToolboxInfo | { contents: never[]; }' // is not assignable to type 'ToolboxInfo'. - this.toolboxDef_ = (workspace.options.languageTree || { 'contents': [] }) as - AnyDuringMigration; + this.toolboxDef_ = (workspace.options.languageTree || {'contents': []}) as + AnyDuringMigration; /** Whether the toolbox should be laid out horizontally. */ this.horizontalLayout_ = workspace.options.horizontalLayout; @@ -162,7 +162,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, this.render(this.toolboxDef_); const themeManager = workspace.getThemeManager(); themeManager.subscribe( - this.HtmlDiv, 'toolboxBackgroundColour', 'background-color'); + this.HtmlDiv, 'toolboxBackgroundColour', 'background-color'); themeManager.subscribe(this.HtmlDiv, 'toolboxForegroundColour', 'color'); this.workspace.getComponentManager().addComponent({ component: this, @@ -229,15 +229,15 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * toolbox. */ protected attachEvents_( - container: HTMLDivElement, contentsContainer: HTMLDivElement) { + container: HTMLDivElement, contentsContainer: HTMLDivElement) { // Clicking on toolbox closes popups. const clickEvent = browserEvents.conditionalBind( - container, 'click', this, this.onClick_, + container, 'click', this, this.onClick_, /* opt_noCaptureIdentifier */ false, /* opt_noPreventDefault */ true); this.boundEvents_.push(clickEvent); const keyDownEvent = browserEvents.conditionalBind( - contentsContainer, 'keydown', this, this.onKeyDown_, + contentsContainer, 'keydown', this, this.onKeyDown_, /* opt_noCaptureIdentifier */ false, /* opt_noPreventDefault */ true); this.boundEvents_.push(keyDownEvent); } @@ -337,10 +337,10 @@ export class Toolbox extends DeleteArea implements IAutoHideable, let FlyoutClass = null; if (workspace.horizontalLayout) { FlyoutClass = registry.getClassFromOptions( - registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, workspace.options, true); + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, workspace.options, true); } else { FlyoutClass = registry.getClassFromOptions( - registry.Type.FLYOUTS_VERTICAL_TOOLBOX, workspace.options, true); + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, workspace.options, true); } return new FlyoutClass!(workspaceOptions); } @@ -387,18 +387,18 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @param fragment The document fragment to add the child toolbox elements to. */ private createToolboxItem_( - toolboxItemDef: toolbox.ToolboxItemInfo, fragment: DocumentFragment) { + toolboxItemDef: toolbox.ToolboxItemInfo, fragment: DocumentFragment) { let registryName = toolboxItemDef['kind']; // Categories that are collapsible are created using a class registered // under a different name. if (registryName.toUpperCase() === 'CATEGORY' && - toolbox.isCategoryCollapsible(toolboxItemDef as toolbox.CategoryInfo)) { + toolbox.isCategoryCollapsible(toolboxItemDef as toolbox.CategoryInfo)) { registryName = CollapsibleToolboxCategory.registrationName; } const ToolboxItemClass = registry.getClass( - registry.Type.TOOLBOX_ITEM, registryName.toLowerCase()); + registry.Type.TOOLBOX_ITEM, registryName.toLowerCase()); if (ToolboxItemClass) { const toolboxItem = new ToolboxItemClass(toolboxItemDef, this); toolboxItem.init(); @@ -462,7 +462,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @return The component's bounding box. Null if drag target area should be * ignored. */ - override getClientRect(): Rect | null { + override getClientRect(): Rect|null { if (!this.HtmlDiv || !this.isVisible_) { return null; } @@ -563,7 +563,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, */ protected updateCursorDeleteStyle_(addStyle: boolean) { const style = - this.wouldDelete_ ? 'blocklyToolboxDelete' : 'blocklyToolboxGrab'; + this.wouldDelete_ ? 'blocklyToolboxDelete' : 'blocklyToolboxGrab'; if (addStyle) { this.addStyle(style); } else { @@ -576,7 +576,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @param id The ID of the toolbox item. * @return The toolbox item with the given ID, or null if no item exists. */ - getToolboxItemById(id: string): IToolboxItem | null { + getToolboxItemById(id: string): IToolboxItem|null { return this.contentMap_[id] || null; } @@ -600,7 +600,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * Gets the toolbox flyout. * @return The toolbox flyout. */ - getFlyout(): IFlyout | null { + getFlyout(): IFlyout|null { return this.flyout_; } @@ -616,7 +616,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * Gets the selected item. * @return The selected item, or null if no item is currently selected. */ - getSelectedItem(): ISelectableToolboxItem | null { + getSelectedItem(): ISelectableToolboxItem|null { return this.selectedItem_; } @@ -625,7 +625,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @return The previously selected item, or null if no item was previously * selected. */ - getPreviouslySelectedItem(): ISelectableToolboxItem | null { + getPreviouslySelectedItem(): ISelectableToolboxItem|null { return this.previouslySelectedItem_; } @@ -683,11 +683,11 @@ export class Toolbox extends DeleteArea implements IAutoHideable, const workspace = this.workspace; const rect = this.HtmlDiv!.getBoundingClientRect(); const newX = this.toolboxPosition === toolbox.Position.LEFT ? - workspace.scrollX + rect.width : - workspace.scrollX; + workspace.scrollX + rect.width : + workspace.scrollX; const newY = this.toolboxPosition === toolbox.Position.TOP ? - workspace.scrollY + rect.height : - workspace.scrollY; + workspace.scrollY + rect.height : + workspace.scrollY; workspace.translate(newX, newY); // Even though the div hasn't changed size, the visible workspace @@ -721,7 +721,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, */ refreshSelection() { if (this.selectedItem_ && this.selectedItem_.isSelectable() && - this.selectedItem_.getContents().length) { + this.selectedItem_.getContents().length) { this.flyout_!.show(this.selectedItem_.getContents()); } } @@ -758,7 +758,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * No-op if the item is not selectable. * @param newItem The toolbox item to select. */ - setSelectedItem(newItem: IToolboxItem | null) { + setSelectedItem(newItem: IToolboxItem|null) { const oldItem = this.selectedItem_; if (!newItem && !oldItem || newItem && !newItem.isSelectable()) { @@ -769,14 +769,14 @@ export class Toolbox extends DeleteArea implements IAutoHideable, // AnyDuringMigration because: Argument of type 'IToolboxItem' is not // assignable to parameter of type 'ISelectableToolboxItem'. if (this.shouldDeselectItem_(oldItem, newItem as AnyDuringMigration) && - oldItem !== null) { + oldItem !== null) { this.deselectItem_(oldItem); } // AnyDuringMigration because: Argument of type 'IToolboxItem' is not // assignable to parameter of type 'ISelectableToolboxItem'. if (this.shouldSelectItem_(oldItem, newItem as AnyDuringMigration) && - newItem !== null) { + newItem !== null) { // AnyDuringMigration because: Argument of type 'IToolboxItem' is not // assignable to parameter of type 'ISelectableToolboxItem'. this.selectItem_(oldItem, newItem as AnyDuringMigration); @@ -797,12 +797,12 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @return True if the old item should be deselected, false otherwise. */ protected shouldDeselectItem_( - oldItem: ISelectableToolboxItem | null, - newItem: ISelectableToolboxItem | null): boolean { + oldItem: ISelectableToolboxItem|null, + newItem: ISelectableToolboxItem|null): boolean { // Deselect the old item unless the old item is collapsible and has been // previously clicked on. return oldItem !== null && - (!oldItem.isCollapsible() || oldItem !== newItem); + (!oldItem.isCollapsible() || oldItem !== newItem); } /** @@ -812,8 +812,8 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @return True if the new item should be selected, false otherwise. */ protected shouldSelectItem_( - oldItem: ISelectableToolboxItem | null, - newItem: ISelectableToolboxItem | null): boolean { + oldItem: ISelectableToolboxItem|null, + newItem: ISelectableToolboxItem|null): boolean { // Select the new item unless the old item equals the new item. return newItem !== null && newItem !== oldItem; } @@ -828,7 +828,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, this.previouslySelectedItem_ = item; item.setSelected(false); aria.setState( - this.contentsDiv_ as Element, aria.State.ACTIVEDESCENDANT, ''); + this.contentsDiv_ as Element, aria.State.ACTIVEDESCENDANT, ''); } /** @@ -837,13 +837,13 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @param newItem The newly selected toolbox item. */ protected selectItem_( - oldItem: ISelectableToolboxItem | null, newItem: ISelectableToolboxItem) { + oldItem: ISelectableToolboxItem|null, newItem: ISelectableToolboxItem) { this.selectedItem_ = newItem; this.previouslySelectedItem_ = oldItem; newItem.setSelected(true); aria.setState( - this.contentsDiv_ as Element, aria.State.ACTIVEDESCENDANT, - newItem.getId()); + this.contentsDiv_ as Element, aria.State.ACTIVEDESCENDANT, + newItem.getId()); } /** @@ -865,10 +865,10 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @param newItem The newly selected toolbox item. */ protected updateFlyout_( - oldItem: ISelectableToolboxItem | null, - newItem: ISelectableToolboxItem | null) { + oldItem: ISelectableToolboxItem|null, + newItem: ISelectableToolboxItem|null) { if (!newItem || oldItem === newItem && !newItem.isCollapsible() || - !newItem.getContents().length) { + !newItem.getContents().length) { this.flyout_!.hide(); } else { this.flyout_!.show(newItem.getContents()); @@ -882,8 +882,8 @@ export class Toolbox extends DeleteArea implements IAutoHideable, * @param newItem The newly selected toolbox item. */ private fireSelectEvent_( - oldItem: ISelectableToolboxItem | null, - newItem: ISelectableToolboxItem | null) { + oldItem: ISelectableToolboxItem|null, + newItem: ISelectableToolboxItem|null) { const oldElement = oldItem && oldItem.getName(); let newElement = newItem && newItem.getName(); // In this case the toolbox closes, so the newElement should be null. @@ -891,7 +891,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, newElement = null; } const event = new (eventUtils.get(eventUtils.TOOLBOX_ITEM_SELECT))! - (oldElement, newElement, this.workspace.id); + (oldElement, newElement, this.workspace.id); eventUtils.fire(event); } @@ -905,13 +905,13 @@ export class Toolbox extends DeleteArea implements IAutoHideable, } if (this.selectedItem_.isCollapsible() && - (this.selectedItem_ as ICollapsibleToolboxItem).isExpanded()) { + (this.selectedItem_ as ICollapsibleToolboxItem).isExpanded()) { const collapsibleItem = this.selectedItem_ as ICollapsibleToolboxItem; collapsibleItem.toggleExpanded(); return true; } else if ( - this.selectedItem_.getParent() && - this.selectedItem_.getParent()!.isSelectable()) { + this.selectedItem_.getParent() && + this.selectedItem_.getParent()!.isSelectable()) { this.setSelectedItem(this.selectedItem_.getParent()); return true; } @@ -1001,7 +1001,7 @@ export class Toolbox extends DeleteArea implements IAutoHideable, // AnyDuringMigration because: Argument of type 'HTMLDivElement | null' is // not assignable to parameter of type 'Element'. this.workspace.getThemeManager().unsubscribe( - this.HtmlDiv as AnyDuringMigration); + this.HtmlDiv as AnyDuringMigration); dom.removeNode(this.HtmlDiv); } } diff --git a/core/toolbox/toolbox_item.ts b/core/toolbox/toolbox_item.ts index 1ca6fff33..efc84b067 100644 --- a/core/toolbox/toolbox_item.ts +++ b/core/toolbox/toolbox_item.ts @@ -13,16 +13,16 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { ICollapsibleToolboxItem } from '../interfaces/i_collapsible_toolbox_item.js'; +import {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from '../interfaces/i_toolbox.js'; +import {IToolbox} from '../interfaces/i_toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolboxItem } from '../interfaces/i_toolbox_item.js'; +import {IToolboxItem} from '../interfaces/i_toolbox_item.js'; import * as idGenerator from '../utils/idgenerator.js'; /* eslint-disable-next-line no-unused-vars */ import * as toolbox from '../utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; /** @@ -31,9 +31,9 @@ import { WorkspaceSvg } from '../workspace_svg.js'; */ export class ToolboxItem implements IToolboxItem { protected id_: string; - protected parent_: ICollapsibleToolboxItem | null; + protected parent_: ICollapsibleToolboxItem|null; protected level_: number; - protected toolboxItemDef_: toolbox.ToolboxItemInfo | null; + protected toolboxItemDef_: toolbox.ToolboxItemInfo|null; protected workspace_: WorkspaceSvg; /** @@ -43,12 +43,12 @@ export class ToolboxItem implements IToolboxItem { * have a parent. */ constructor( - toolboxItemDef: toolbox.ToolboxItemInfo, - protected readonly parentToolbox: IToolbox, - opt_parent?: ICollapsibleToolboxItem) { + toolboxItemDef: toolbox.ToolboxItemInfo, + protected readonly parentToolbox: IToolbox, + opt_parent?: ICollapsibleToolboxItem) { /** The id for the category. */ this.id_ = (toolboxItemDef as AnyDuringMigration)['toolboxitemid'] || - idGenerator.getNextUniqueId(); + idGenerator.getNextUniqueId(); /** The parent of the category. */ this.parent_ = opt_parent || null; @@ -75,7 +75,7 @@ export class ToolboxItem implements IToolboxItem { * Gets the div for the toolbox item. * @return The div for the toolbox item. */ - getDiv(): Element | null { + getDiv(): Element|null { return null; } @@ -87,7 +87,7 @@ export class ToolboxItem implements IToolboxItem { * @return The HTML element that receives clicks, or null if this item should * not receive clicks. */ - getClickTarget(): Element | null { + getClickTarget(): Element|null { return null; } @@ -104,7 +104,7 @@ export class ToolboxItem implements IToolboxItem { * @return The parent toolbox item, or null if this toolbox item is not * nested. */ - getParent(): ICollapsibleToolboxItem | null { + getParent(): ICollapsibleToolboxItem|null { return null; } diff --git a/core/tooltip.ts b/core/tooltip.ts index addaf0baf..203e8addc 100644 --- a/core/tooltip.ts +++ b/core/tooltip.ts @@ -50,7 +50,7 @@ import * as blocklyString from './utils/string.js'; * @alias Blockly.Tooltip.TipInfo */ export type TipInfo = - string | { tooltip: AnyDuringMigration } | (() => TipInfo | string | Function); + string|{tooltip: AnyDuringMigration}|(() => TipInfo|string|Function); /** * A function that renders custom tooltip UI. @@ -66,7 +66,7 @@ export type CustomTooltip = (p1: Element, p2: Element) => AnyDuringMigration; * this is defined, the function will be called instead of rendering the default * tooltip UI. */ -let customTooltip: CustomTooltip | undefined = undefined; +let customTooltip: CustomTooltip|undefined = undefined; /** * Sets a custom function that will be called if present instead of the default @@ -82,7 +82,7 @@ export function setCustomTooltip(customFn: CustomTooltip) { * Gets the custom tooltip function. * @returns The custom tooltip function, if defined. */ -export function getCustomTooltip(): CustomTooltip | undefined { +export function getCustomTooltip(): CustomTooltip|undefined { return customTooltip; } @@ -163,14 +163,14 @@ export const HOVER_MS = 750; export const MARGINS = 5; /** The HTML container. Set once by createDom. */ -let containerDiv: HTMLDivElement | null = null; +let containerDiv: HTMLDivElement|null = null; /** * Returns the HTML tooltip container. * @returns The HTML tooltip container. * @alias Blockly.Tooltip.getDiv */ -export function getDiv(): HTMLDivElement | null { +export function getDiv(): HTMLDivElement|null { return containerDiv; } @@ -180,7 +180,7 @@ export function getDiv(): HTMLDivElement | null { * @return The tooltip text of the element. * @alias Blockly.Tooltip.getTooltipOfObject */ -export function getTooltipOfObject(object: AnyDuringMigration | null): string { +export function getTooltipOfObject(object: AnyDuringMigration|null): string { const obj = getTargetObject(object); if (obj) { let tooltip = obj.tooltip; @@ -201,11 +201,11 @@ export function getTooltipOfObject(object: AnyDuringMigration | null): string { * @param obj The object are trying to find the target tooltip object of. * @return The target tooltip object. */ -function getTargetObject(obj: object | null): { tooltip: AnyDuringMigration } | null { +function getTargetObject(obj: object|null): {tooltip: AnyDuringMigration}|null { while (obj && (obj as any).tooltip) { if (typeof (obj as any).tooltip === 'string' || - typeof (obj as any).tooltip === 'function') { - return obj as { tooltip: string | (() => string) }; + typeof (obj as any).tooltip === 'function') { + return obj as {tooltip: string | (() => string)}; } obj = (obj as any).tooltip; } @@ -236,9 +236,9 @@ export function createDom() { export function bindMouseEvents(element: Element) { // TODO (#6097): Don't stash wrapper info on the DOM. (element as AnyDuringMigration).mouseOverWrapper_ = - browserEvents.bind(element, 'mouseover', null, onMouseOver); + browserEvents.bind(element, 'mouseover', null, onMouseOver); (element as AnyDuringMigration).mouseOutWrapper_ = - browserEvents.bind(element, 'mouseout', null, onMouseOut); + browserEvents.bind(element, 'mouseout', null, onMouseOut); // Don't use bindEvent_ for mousemove since that would create a // corresponding touch handler, even though this only makes sense in the @@ -296,7 +296,7 @@ function onMouseOut(_e: Event) { // a mouseOut followed instantly by a mouseOver. Fork off the mouseOut // event and kill it if a mouseOver is received immediately. // This way the task only fully executes if mousing into the void. - mouseOutPid = setTimeout(function () { + mouseOutPid = setTimeout(function() { element = null; poisonedElement = null; hide(); @@ -421,7 +421,7 @@ function renderDefaultContent() { * @param rtl True if the tooltip should be in right-to-left layout. * @returns Coordinates at which the tooltip div should be placed. */ -function getPosition(rtl: boolean): { x: number, y: number } { +function getPosition(rtl: boolean): {x: number, y: number} { // Position the tooltip just below the cursor. const windowWidth = document.documentElement.clientWidth; const windowHeight = document.documentElement.clientHeight; @@ -444,14 +444,14 @@ function getPosition(rtl: boolean): { x: number, y: number } { anchorX = Math.max(MARGINS - window.scrollX, anchorX); } else { if (anchorX + containerDiv!.offsetWidth > - windowWidth + window.scrollX - 2 * MARGINS) { + windowWidth + window.scrollX - 2 * MARGINS) { // Falling off the right edge of the screen; // clamp the tooltip on the edge. anchorX = windowWidth - containerDiv!.offsetWidth - 2 * MARGINS; } } - return { x: anchorX, y: anchorY }; + return {x: anchorX, y: anchorY}; } /** Create the tooltip and show it. */ @@ -476,7 +476,7 @@ function show() { containerDiv.style.display = 'block'; visible = true; - const { x, y } = getPosition(rtl); + const {x, y} = getPosition(rtl); containerDiv.style.left = x + 'px'; containerDiv.style.top = y + 'px'; } diff --git a/core/touch.ts b/core/touch.ts index 69e002464..5e04ae323 100644 --- a/core/touch.ts +++ b/core/touch.ts @@ -13,7 +13,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Gesture } from './gesture.js'; +import {Gesture} from './gesture.js'; /** @@ -36,39 +36,39 @@ const LONGPRESS = 750; * Copied from Closure's goog.events.BrowserFeature.TOUCH_ENABLED */ export const TOUCH_ENABLED = 'ontouchstart' in globalThis || - !!(globalThis['document'] && document.documentElement && - 'ontouchstart' in - document.documentElement) || // IE10 uses non-standard touch events, - // so it has a different check. - !!(globalThis['navigator'] && - (globalThis['navigator']['maxTouchPoints'] || - (globalThis['navigator'] as any)['msMaxTouchPoints'])); + !!(globalThis['document'] && document.documentElement && + 'ontouchstart' in + document.documentElement) || // IE10 uses non-standard touch events, + // so it has a different check. + !!(globalThis['navigator'] && + (globalThis['navigator']['maxTouchPoints'] || + (globalThis['navigator'] as any)['msMaxTouchPoints'])); /** Which touch events are we currently paying attention to? */ -let touchIdentifier_: string | null = null; +let touchIdentifier_: string|null = null; /** * The TOUCH_MAP lookup dictionary specifies additional touch events to fire, * in conjunction with mouse events. * @alias Blockly.Touch.TOUCH_MAP */ -export const TOUCH_MAP: { [key: string]: string[] } = globalThis['PointerEvent'] ? - { - 'mousedown': ['pointerdown'], - 'mouseenter': ['pointerenter'], - 'mouseleave': ['pointerleave'], - 'mousemove': ['pointermove'], - 'mouseout': ['pointerout'], - 'mouseover': ['pointerover'], - 'mouseup': ['pointerup', 'pointercancel'], - 'touchend': ['pointerup'], - 'touchcancel': ['pointercancel'], - } : - { - 'mousedown': ['touchstart'], - 'mousemove': ['touchmove'], - 'mouseup': ['touchend', 'touchcancel'], - }; +export const TOUCH_MAP: {[key: string]: string[]} = globalThis['PointerEvent'] ? + { + 'mousedown': ['pointerdown'], + 'mouseenter': ['pointerenter'], + 'mouseleave': ['pointerleave'], + 'mousemove': ['pointermove'], + 'mouseout': ['pointerout'], + 'mouseover': ['pointerover'], + 'mouseup': ['pointerup', 'pointercancel'], + 'touchend': ['pointerup'], + 'touchcancel': ['pointercancel'], + } : + { + 'mousedown': ['touchstart'], + 'mousemove': ['touchmove'], + 'mouseup': ['touchend', 'touchcancel'], + }; /** PID of queued long-press task. */ let longPid_ = 0; @@ -87,10 +87,10 @@ export function longStart(e: Event, gesture: Gesture) { longStop(); // Punt on multitouch events. if (e instanceof TouchEvent && e.changedTouches && - e.changedTouches.length !== 1) { + e.changedTouches.length !== 1) { return; } - longPid_ = setTimeout(function () { + longPid_ = setTimeout(function() { // TODO(#6097): Make types accurate, possibly by refactoring touch handling. const typelessEvent = e as AnyDuringMigration; // Additional check to distinguish between touch events and pointer events @@ -141,7 +141,7 @@ export function clearTouchIdentifier() { * handler; false if it should be blocked. * @alias Blockly.Touch.shouldHandleEvent */ -export function shouldHandleEvent(e: Event | PseudoEvent): boolean { +export function shouldHandleEvent(e: Event|PseudoEvent): boolean { return !isMouseOrTouchEvent(e) || checkTouchIdentifier(e); } @@ -153,7 +153,7 @@ export function shouldHandleEvent(e: Event | PseudoEvent): boolean { * Otherwise 'mouse'. * @alias Blockly.Touch.getTouchIdentifierFromEvent */ -export function getTouchIdentifierFromEvent(e: Event | PseudoEvent): string { +export function getTouchIdentifierFromEvent(e: Event|PseudoEvent): string { if (e instanceof MouseEvent) { return 'mouse'; } @@ -177,13 +177,13 @@ export function getTouchIdentifierFromEvent(e: Event | PseudoEvent): string { // AnyDuringMigration because: Property 'changedTouches' does not exist on // type 'PseudoEvent | Event'. return (pseudoEvent as AnyDuringMigration).changedTouches && - (pseudoEvent as AnyDuringMigration).changedTouches[0] && - (pseudoEvent as AnyDuringMigration).changedTouches[0].identifier !== - undefined && - (pseudoEvent as AnyDuringMigration).changedTouches[0].identifier !== - null ? - String((pseudoEvent as AnyDuringMigration).changedTouches[0].identifier) : - 'mouse'; + (pseudoEvent as AnyDuringMigration).changedTouches[0] && + (pseudoEvent as AnyDuringMigration).changedTouches[0].identifier !== + undefined && + (pseudoEvent as AnyDuringMigration).changedTouches[0].identifier !== + null ? + String((pseudoEvent as AnyDuringMigration).changedTouches[0].identifier) : + 'mouse'; } /** @@ -199,7 +199,7 @@ export function getTouchIdentifierFromEvent(e: Event | PseudoEvent): string { * identifier. * @alias Blockly.Touch.checkTouchIdentifier */ -export function checkTouchIdentifier(e: Event | PseudoEvent): boolean { +export function checkTouchIdentifier(e: Event|PseudoEvent): boolean { const identifier = getTouchIdentifierFromEvent(e); // if (touchIdentifier_) is insufficient because Android touch @@ -210,7 +210,7 @@ export function checkTouchIdentifier(e: Event | PseudoEvent): boolean { return touchIdentifier_ === identifier; } if (e.type === 'mousedown' || e.type === 'touchstart' || - e.type === 'pointerdown') { + e.type === 'pointerdown') { // No identifier set yet, and this is the start of a drag. Set it and // return. touchIdentifier_ = identifier; @@ -228,11 +228,10 @@ export function checkTouchIdentifier(e: Event | PseudoEvent): boolean { * @param e A touch event. * @alias Blockly.Touch.setClientFromTouch */ -export function setClientFromTouch(e: Event | PseudoEvent) { +export function setClientFromTouch(e: Event|PseudoEvent) { // AnyDuringMigration because: Property 'changedTouches' does not exist on // type 'PseudoEvent | Event'. - if (e.type.startsWith('touch') && - (e as AnyDuringMigration).changedTouches) { + if (e.type.startsWith('touch') && (e as AnyDuringMigration).changedTouches) { // Map the touch event's properties to the event. // AnyDuringMigration because: Property 'changedTouches' does not exist on // type 'PseudoEvent | Event'. @@ -252,10 +251,9 @@ export function setClientFromTouch(e: Event | PseudoEvent) { * @return True if it is a mouse, touch, or pointer event; false otherwise. * @alias Blockly.Touch.isMouseOrTouchEvent */ -export function isMouseOrTouchEvent(e: Event | PseudoEvent): boolean { - return e.type.startsWith('touch') || - e.type.startsWith('mouse') || - e.type.startsWith('pointer'); +export function isMouseOrTouchEvent(e: Event|PseudoEvent): boolean { + return e.type.startsWith('touch') || e.type.startsWith('mouse') || + e.type.startsWith('pointer'); } /** @@ -264,9 +262,8 @@ export function isMouseOrTouchEvent(e: Event | PseudoEvent): boolean { * @return True if it is a touch or pointer event; false otherwise. * @alias Blockly.Touch.isTouchEvent */ -export function isTouchEvent(e: Event | PseudoEvent): boolean { - return e.type.startsWith('touch') || - e.type.startsWith('pointer'); +export function isTouchEvent(e: Event|PseudoEvent): boolean { + return e.type.startsWith('touch') || e.type.startsWith('pointer'); } @@ -279,7 +276,7 @@ export function isTouchEvent(e: Event | PseudoEvent): boolean { * will be no real touch events. * @alias Blockly.Touch.splitEventByTouches */ -export function splitEventByTouches(e: Event): Array { +export function splitEventByTouches(e: Event): Array { const events = []; if (e instanceof TouchEvent) { for (let i = 0; i < e.changedTouches.length; i++) { diff --git a/core/touch_gesture.ts b/core/touch_gesture.ts index f541b45d9..82f4ead28 100644 --- a/core/touch_gesture.ts +++ b/core/touch_gesture.ts @@ -17,11 +17,11 @@ */ import * as browserEvents from './browser_events.js'; -import { Gesture } from './gesture.js'; +import {Gesture} from './gesture.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /* @@ -43,7 +43,7 @@ const ZOOM_OUT_MULTIPLIER = 6; export class TouchGesture extends Gesture { /** Boolean for whether or not this gesture is a multi-touch gesture. */ private isMultiTouch_ = false; - private cachedPoints_: { [key: string]: Coordinate }; + private cachedPoints_: {[key: string]: Coordinate}; /** * This is the ratio between the starting distance between the touch points @@ -61,10 +61,10 @@ export class TouchGesture extends Gesture { * at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. */ - private onStartWrapper_: browserEvents.Data | null = null; + private onStartWrapper_: browserEvents.Data|null = null; /** Boolean for whether or not the workspace supports pinch-zoom. */ - private isPinchZoomEnabled_: boolean | null = null; + private isPinchZoomEnabled_: boolean|null = null; override onMoveWrapper_: AnyDuringMigration; override onUpWrapper_: AnyDuringMigration; @@ -87,7 +87,7 @@ export class TouchGesture extends Gesture { */ override doStart(e: Event) { this.isPinchZoomEnabled_ = this.startWorkspace_.options.zoomOptions && - this.startWorkspace_.options.zoomOptions.pinch; + this.startWorkspace_.options.zoomOptions.pinch; super.doStart(e); if (!this.isEnding_ && Touch.isTouchEvent(e)) { this.handleTouchStart(e); @@ -105,13 +105,13 @@ export class TouchGesture extends Gesture { */ override bindMouseEvents(e: Event) { this.onStartWrapper_ = browserEvents.conditionalBind( - document, 'mousedown', null, this.handleStart.bind(this), + document, 'mousedown', null, this.handleStart.bind(this), /* opt_noCaptureIdentifier */ true); this.onMoveWrapper_ = browserEvents.conditionalBind( - document, 'mousemove', null, this.handleMove.bind(this), + document, 'mousemove', null, this.handleMove.bind(this), /* opt_noCaptureIdentifier */ true); this.onUpWrapper_ = browserEvents.conditionalBind( - document, 'mouseup', null, this.handleUp.bind(this), + document, 'mouseup', null, this.handleUp.bind(this), /* opt_noCaptureIdentifier */ true); e.preventDefault(); @@ -253,10 +253,10 @@ export class TouchGesture extends Gesture { if (this.previousScale_ > 0 && this.previousScale_ < Infinity) { const gestureScale = scale - this.previousScale_; const delta = gestureScale > 0 ? gestureScale * ZOOM_IN_MULTIPLIER : - gestureScale * ZOOM_OUT_MULTIPLIER; + gestureScale * ZOOM_OUT_MULTIPLIER; const workspace = this.startWorkspace_; const position = browserEvents.mouseToSvg( - e, workspace.getParentSvg(), workspace.getInverseScreenCTM()); + e, workspace.getParentSvg(), workspace.getInverseScreenCTM()); workspace.zoom(position.x, position.y, delta); } this.previousScale_ = scale; @@ -283,16 +283,16 @@ export class TouchGesture extends Gesture { * @param e A touch or pointer event. * @return The current touch point coordinate */ - getTouchPoint(e: Event): Coordinate | null { + getTouchPoint(e: Event): Coordinate|null { if (!this.startWorkspace_) { return null; } // TODO(#6097): Make types accurate, possibly by refactoring touch handling. const typelessEvent = e as AnyDuringMigration; return new Coordinate( - typelessEvent.changedTouches ? typelessEvent.changedTouches[0].pageX : - typelessEvent.pageX, - typelessEvent.changedTouches ? typelessEvent.changedTouches[0].pageY : - typelessEvent.pageY); + typelessEvent.changedTouches ? typelessEvent.changedTouches[0].pageX : + typelessEvent.pageX, + typelessEvent.changedTouches ? typelessEvent.changedTouches[0].pageY : + typelessEvent.pageY); } } diff --git a/core/trashcan.ts b/core/trashcan.ts index 386d17065..2ad18ce80 100644 --- a/core/trashcan.ts +++ b/core/trashcan.ts @@ -18,37 +18,37 @@ import './metrics_manager'; import './events/events_trashcan_open'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; +import {BlocklyOptions} from './blockly_options.js'; import * as browserEvents from './browser_events.js'; -import { ComponentManager } from './component_manager.js'; -import { DeleteArea } from './delete_area.js'; +import {ComponentManager} from './component_manager.js'; +import {DeleteArea} from './delete_area.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; +import {Abstract} from './events/events_abstract.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockDelete } from './events/events_block_delete.js'; +import {BlockDelete} from './events/events_block_delete.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IAutoHideable } from './interfaces/i_autohideable.js'; +import {IAutoHideable} from './interfaces/i_autohideable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDraggable } from './interfaces/i_draggable.js'; +import {IDraggable} from './interfaces/i_draggable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPositionable } from './interfaces/i_positionable.js'; -import { UiMetrics } from './metrics_manager.js'; -import { Options } from './options.js'; +import {IPositionable} from './interfaces/i_positionable.js'; +import {UiMetrics} from './metrics_manager.js'; +import {Options} from './options.js'; import * as uiPosition from './positionable_helpers.js'; import * as registry from './registry.js'; /* eslint-disable-next-line no-unused-vars */ import * as blocks from './serialization/blocks.js'; -import { SPRITE } from './sprites.js'; +import {SPRITE} from './sprites.js'; import * as dom from './utils/dom.js'; -import { Rect } from './utils/rect.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Rect} from './utils/rect.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; import * as toolbox from './utils/toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -56,7 +56,7 @@ import { WorkspaceSvg } from './workspace_svg.js'; * @alias Blockly.Trashcan */ export class Trashcan extends DeleteArea implements IAutoHideable, - IPositionable { + IPositionable { /** * The unique id for this component that is used to register with the * ComponentManager. @@ -130,20 +130,20 @@ export class Trashcan extends DeleteArea implements IAutoHideable, // Create vertical or horizontal flyout. if (this.workspace.horizontalLayout) { flyoutWorkspaceOptions.toolboxPosition = - this.workspace.toolboxPosition === toolbox.Position.TOP ? + this.workspace.toolboxPosition === toolbox.Position.TOP ? toolbox.Position.BOTTOM : toolbox.Position.TOP; const HorizontalFlyout = registry.getClassFromOptions( - registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.workspace.options, - true); + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.workspace.options, + true); this.flyout = new HorizontalFlyout!(flyoutWorkspaceOptions); } else { flyoutWorkspaceOptions.toolboxPosition = - this.workspace.toolboxPosition === toolbox.Position.RIGHT ? + this.workspace.toolboxPosition === toolbox.Position.RIGHT ? toolbox.Position.LEFT : toolbox.Position.RIGHT; const VerticalFlyout = registry.getClassFromOptions( - registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.workspace.options, true); + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.workspace.options, true); this.flyout = new VerticalFlyout!(flyoutWorkspaceOptions); } this.workspace.addChangeListener(this.onDelete_.bind(this)); @@ -168,50 +168,50 @@ export class Trashcan extends DeleteArea implements IAutoHideable, clip-path="url(#blocklyTrashLidClipPath837493)"> */ - this.svgGroup_ = dom.createSvgElement(Svg.G, { 'class': 'blocklyTrash' }); + this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyTrash'}); let clip; const rnd = String(Math.random()).substring(2); clip = dom.createSvgElement( - Svg.CLIPPATH, { 'id': 'blocklyTrashBodyClipPath' + rnd }, this.svgGroup_); + Svg.CLIPPATH, {'id': 'blocklyTrashBodyClipPath' + rnd}, this.svgGroup_); dom.createSvgElement( - Svg.RECT, { 'width': WIDTH, 'height': BODY_HEIGHT, 'y': LID_HEIGHT }, - clip); + Svg.RECT, {'width': WIDTH, 'height': BODY_HEIGHT, 'y': LID_HEIGHT}, + clip); const body = dom.createSvgElement( - Svg.IMAGE, { - 'width': SPRITE.width, - 'x': -SPRITE_LEFT, - 'height': SPRITE.height, - 'y': -SPRITE_TOP, - 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')', - }, - this.svgGroup_); + Svg.IMAGE, { + 'width': SPRITE.width, + 'x': -SPRITE_LEFT, + 'height': SPRITE.height, + 'y': -SPRITE_TOP, + 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')', + }, + this.svgGroup_); body.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.workspace.options.pathToMedia + SPRITE.url); + dom.XLINK_NS, 'xlink:href', + this.workspace.options.pathToMedia + SPRITE.url); clip = dom.createSvgElement( - Svg.CLIPPATH, { 'id': 'blocklyTrashLidClipPath' + rnd }, this.svgGroup_); + Svg.CLIPPATH, {'id': 'blocklyTrashLidClipPath' + rnd}, this.svgGroup_); dom.createSvgElement( - Svg.RECT, { 'width': WIDTH, 'height': LID_HEIGHT }, clip); + Svg.RECT, {'width': WIDTH, 'height': LID_HEIGHT}, clip); this.svgLid_ = dom.createSvgElement( - Svg.IMAGE, { - 'width': SPRITE.width, - 'x': -SPRITE_LEFT, - 'height': SPRITE.height, - 'y': -SPRITE_TOP, - 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')', - }, - this.svgGroup_); + Svg.IMAGE, { + 'width': SPRITE.width, + 'x': -SPRITE_LEFT, + 'height': SPRITE.height, + 'y': -SPRITE_TOP, + 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')', + }, + this.svgGroup_); this.svgLid_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.workspace.options.pathToMedia + SPRITE.url); + dom.XLINK_NS, 'xlink:href', + this.workspace.options.pathToMedia + SPRITE.url); // bindEventWithChecks_ quashes events too aggressively. See: // https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s // Using bindEventWithChecks_ for blocking mousedown causes issue in mobile. // See #4303 browserEvents.bind( - this.svgGroup_, 'mousedown', this, this.blockMouseDownWhenOpenable_); + this.svgGroup_, 'mousedown', this, this.blockMouseDownWhenOpenable_); browserEvents.bind(this.svgGroup_, 'mouseup', this, this.click); // Bind to body instead of this.svgGroup_ so that we don't get lid jitters browserEvents.bind(body, 'mouseover', this, this.mouseOver_); @@ -224,7 +224,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, init() { if (this.workspace.options.maxTrashcanContents > 0) { dom.insertAfter( - this.flyout.createDom(Svg.SVG), this.workspace.getParentSvg()); + this.flyout.createDom(Svg.SVG), this.workspace.getParentSvg()); this.flyout.init(this.workspace); } this.workspace.getComponentManager().addComponent({ @@ -284,7 +284,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, if (this.contentsIsOpen()) { return; } - const contents = this.contents_.map(function (string) { + const contents = this.contents_.map(function(string) { return JSON.parse(string); }); this.flyout.show(contents); @@ -341,24 +341,24 @@ export class Trashcan extends DeleteArea implements IAutoHideable, } const cornerPosition = - uiPosition.getCornerOppositeToolbox(this.workspace, metrics); + uiPosition.getCornerOppositeToolbox(this.workspace, metrics); const height = BODY_HEIGHT + LID_HEIGHT; const startRect = uiPosition.getStartPositionRect( - cornerPosition, new Size(WIDTH, height), MARGIN_HORIZONTAL, - MARGIN_VERTICAL, metrics, this.workspace); + cornerPosition, new Size(WIDTH, height), MARGIN_HORIZONTAL, + MARGIN_VERTICAL, metrics, this.workspace); const verticalPosition = cornerPosition.vertical; const bumpDirection = verticalPosition === uiPosition.verticalPosition.TOP ? - uiPosition.bumpDirection.DOWN : - uiPosition.bumpDirection.UP; + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; const positionRect = uiPosition.bumpPositionRect( - startRect, MARGIN_VERTICAL, bumpDirection, savedPositions); + startRect, MARGIN_VERTICAL, bumpDirection, savedPositions); this.top_ = positionRect.top; this.left_ = positionRect.left; this.svgGroup_.setAttribute( - 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); + 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); } /** @@ -367,7 +367,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, * @return The UI elements's bounding box. Null if bounding box should be * ignored by other UI elements. */ - getBoundingRectangle(): Rect | null { + getBoundingRectangle(): Rect|null { const bottom = this.top_ + BODY_HEIGHT + LID_HEIGHT; const right = this.left_ + WIDTH; return new Rect(this.top_, bottom, this.left_, right); @@ -379,7 +379,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, * @return The component's bounding box. Null if drag target area should be * ignored. */ - override getClientRect(): Rect | null { + override getClientRect(): Rect|null { if (!this.svgGroup_) { return null; } @@ -449,7 +449,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) { this.lidTask_ = - setTimeout(this.animateLid_.bind(this), ANIMATION_LENGTH / frames); + setTimeout(this.animateLid_.bind(this), ANIMATION_LENGTH / frames); } } @@ -459,12 +459,12 @@ export class Trashcan extends DeleteArea implements IAutoHideable, */ private setLidAngle_(lidAngle: number) { const openAtRight = - this.workspace.toolboxPosition === toolbox.Position.RIGHT || - this.workspace.horizontalLayout && this.workspace.RTL; + this.workspace.toolboxPosition === toolbox.Position.RIGHT || + this.workspace.horizontalLayout && this.workspace.RTL; this.svgLid_.setAttribute( - 'transform', - 'rotate(' + (openAtRight ? -lidAngle : lidAngle) + ',' + - (openAtRight ? 4 : WIDTH - 4) + ',' + (LID_HEIGHT - 2) + ')'); + 'transform', + 'rotate(' + (openAtRight ? -lidAngle : lidAngle) + ',' + + (openAtRight ? 4 : WIDTH - 4) + ',' + (LID_HEIGHT - 2) + ')'); } /** @@ -502,7 +502,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, */ private fireUiEvent_(trashcanOpen: boolean) { const uiEvent = new (eventUtils.get(eventUtils.TRASHCAN_OPEN))! - (trashcanOpen, this.workspace.id); + (trashcanOpen, this.workspace.id); eventUtils.fire(uiEvent); } @@ -543,7 +543,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, */ private onDelete_(event: Abstract) { if (this.workspace.options.maxTrashcanContents <= 0 || - event.type !== eventUtils.BLOCK_DELETE) { + event.type !== eventUtils.BLOCK_DELETE) { return; } const deleteEvent = event as BlockDelete; @@ -554,7 +554,7 @@ export class Trashcan extends DeleteArea implements IAutoHideable, } this.contents_.unshift(cleanedJson); while (this.contents_.length > - this.workspace.options.maxTrashcanContents) { + this.workspace.options.maxTrashcanContents) { this.contents_.pop(); } diff --git a/core/utils.ts b/core/utils.ts index 5f262d9bd..669815798 100644 --- a/core/utils.ts +++ b/core/utils.ts @@ -12,61 +12,62 @@ * @namespace Blockly.utils */ +/* eslint-disable-next-line no-unused-vars */ +import {Block} from './block.js'; +import * as browserEvents from './browser_events.js'; +import * as common from './common.js'; +import * as extensions from './extensions.js'; import * as aria from './utils/aria.js'; import * as arrayUtils from './utils/array.js'; -import * as browserEvents from './browser_events.js'; import * as colour from './utils/colour.js'; -import * as common from './common.js'; +import {Coordinate} from './utils/coordinate.js'; import * as deprecation from './utils/deprecation.js'; import * as dom from './utils/dom.js'; -import * as extensions from './extensions.js'; import * as idGenerator from './utils/idgenerator.js'; +import {KeyCodes} from './utils/keycodes.js'; import * as math from './utils/math.js'; +import {Metrics} from './utils/metrics.js'; import * as object from './utils/object.js'; import * as parsing from './utils/parsing.js'; +import {Rect} from './utils/rect.js'; +import {Size} from './utils/size.js'; import * as stringUtils from './utils/string.js'; import * as style from './utils/style.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; import * as svgPaths from './utils/svg_paths.js'; import * as toolbox from './utils/toolbox.js'; import * as userAgent from './utils/useragent.js'; import * as xml from './utils/xml.js'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; -import { Coordinate } from './utils/coordinate.js'; -import { KeyCodes } from './utils/keycodes.js'; -import { Metrics } from './utils/metrics.js'; -import { Rect } from './utils/rect.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; -/* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; - -export { aria }; -export { arrayUtils as array }; -export { browserEvents }; -export { colour }; -export { deprecation }; -export { dom }; -export { extensions }; -export { idGenerator }; -export { math }; -export { object }; -export { parsing }; -export { stringUtils as string }; -export { style }; -export { svgMath }; -export { svgPaths }; -export { toolbox }; -export { userAgent }; -export { xml }; -export { Coordinate }; -export { KeyCodes }; -export { Metrics }; -export { Rect }; -export { Size }; -export { Svg }; +export { + aria, + arrayUtils as array, + browserEvents, + colour, + Coordinate, + deprecation, + dom, + extensions, + idGenerator, + KeyCodes, + math, + Metrics, + object, + parsing, + Rect, + Size, + stringUtils as string, + style, + Svg, + svgMath, + svgPaths, + toolbox, + userAgent, + xml +}; /** * Halts the propagation of the event without doing anything else. @@ -77,7 +78,7 @@ export { Svg }; export function noEvent(e: Event) { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn('Blockly.utils.noEvent', 'September 2021', 'September 2022'); + .warn('Blockly.utils.noEvent', 'September 2021', 'September 2022'); // This event has been handled. No need to bubble up to the document. e.preventDefault(); e.stopPropagation(); @@ -93,9 +94,9 @@ export function noEvent(e: Event) { export function isTargetInput(e: Event): boolean { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.isTargetInput', 'September 2021', 'September 2022', - 'Blockly.browserEvents.isTargetInput'); + .warn( + 'Blockly.utils.isTargetInput', 'September 2021', 'September 2022', + 'Blockly.browserEvents.isTargetInput'); return browserEvents.isTargetInput(e); } @@ -110,9 +111,9 @@ export function isTargetInput(e: Event): boolean { export function getRelativeXY(element: Element): Coordinate { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getRelativeXY', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getRelativeXY'); + .warn( + 'Blockly.utils.getRelativeXY', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getRelativeXY'); // AnyDuringMigration because: Property 'getRelativeXY' does not exist on // type 'void'. return (svgMath as AnyDuringMigration).getRelativeXY(element); @@ -130,9 +131,9 @@ export function getRelativeXY(element: Element): Coordinate { function getInjectionDivXY(element: Element): Coordinate { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getInjectionDivXY_', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getInjectionDivXY'); + .warn( + 'Blockly.utils.getInjectionDivXY_', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getInjectionDivXY'); // AnyDuringMigration because: Property 'getInjectionDivXY' does not exist on // type 'void'. return (svgMath as AnyDuringMigration).getInjectionDivXY(element); @@ -149,9 +150,9 @@ export const getInjectionDivXY_ = getInjectionDivXY; export function isRightButton(e: Event): boolean { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.isRightButton', 'September 2021', 'September 2022', - 'Blockly.browserEvents.isRightButton'); + .warn( + 'Blockly.utils.isRightButton', 'September 2021', 'September 2022', + 'Blockly.browserEvents.isRightButton'); return browserEvents.isRightButton(e); } @@ -166,12 +167,12 @@ export function isRightButton(e: Event): boolean { * @alias Blockly.utils.mouseToSvg */ export function mouseToSvg( - e: Event, svg: SVGSVGElement, matrix: SVGMatrix | null): SVGPoint { + e: Event, svg: SVGSVGElement, matrix: SVGMatrix|null): SVGPoint { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.mouseToSvg', 'September 2021', 'September 2022', - 'Blockly.browserEvents.mouseToSvg'); + .warn( + 'Blockly.utils.mouseToSvg', 'September 2021', 'September 2022', + 'Blockly.browserEvents.mouseToSvg'); return browserEvents.mouseToSvg(e, svg, matrix); } @@ -182,12 +183,12 @@ export function mouseToSvg( * @deprecated Use Blockly.browserEvents.getScrollDeltaPixels instead. * @alias Blockly.utils.getScrollDeltaPixels */ -export function getScrollDeltaPixels(e: WheelEvent): { x: number, y: number } { +export function getScrollDeltaPixels(e: WheelEvent): {x: number, y: number} { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getScrollDeltaPixels', 'September 2021', - 'September 2022', 'Blockly.browserEvents.getScrollDeltaPixels'); + .warn( + 'Blockly.utils.getScrollDeltaPixels', 'September 2021', + 'September 2022', 'Blockly.browserEvents.getScrollDeltaPixels'); return browserEvents.getScrollDeltaPixels(e); } @@ -203,12 +204,12 @@ export function getScrollDeltaPixels(e: WheelEvent): { x: number, y: number } { * @deprecated * @alias Blockly.utils.tokenizeInterpolation */ -export function tokenizeInterpolation(message: string): Array { +export function tokenizeInterpolation(message: string): Array { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.tokenizeInterpolation', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.tokenizeInterpolation'); + .warn( + 'Blockly.utils.tokenizeInterpolation', 'December 2021', + 'December 2022', 'Blockly.utils.parsing.tokenizeInterpolation'); // AnyDuringMigration because: Property 'tokenizeInterpolation' does not // exist on type 'void'. return (parsing as AnyDuringMigration).tokenizeInterpolation(message); @@ -224,13 +225,13 @@ export function tokenizeInterpolation(message: string): Array { * @deprecated * @alias Blockly.utils.replaceMessageReferences */ -export function replaceMessageReferences(message: string | - AnyDuringMigration): string { +export function replaceMessageReferences(message: string| + AnyDuringMigration): string { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.replaceMessageReferences', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.replaceMessageReferences'); + .warn( + 'Blockly.utils.replaceMessageReferences', 'December 2021', + 'December 2022', 'Blockly.utils.parsing.replaceMessageReferences'); // AnyDuringMigration because: Property 'replaceMessageReferences' does not // exist on type 'void'. return (parsing as AnyDuringMigration).replaceMessageReferences(message); @@ -248,9 +249,9 @@ export function replaceMessageReferences(message: string | export function checkMessageReferences(message: string): boolean { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.checkMessageReferences', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.checkMessageReferences'); + .warn( + 'Blockly.utils.checkMessageReferences', 'December 2021', + 'December 2022', 'Blockly.utils.parsing.checkMessageReferences'); // AnyDuringMigration because: Property 'checkMessageReferences' does not // exist on type 'void'. return (parsing as AnyDuringMigration).checkMessageReferences(message); @@ -265,9 +266,9 @@ export function checkMessageReferences(message: string): boolean { export function genUid(): string { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.genUid', 'September 2021', 'September 2022', - 'Blockly.utils.idGenerator.genUid'); + .warn( + 'Blockly.utils.genUid', 'September 2021', 'September 2022', + 'Blockly.utils.idGenerator.genUid'); // AnyDuringMigration because: Property 'genUid' does not exist on type // 'void'. return (idGenerator as AnyDuringMigration).genUid(); @@ -283,9 +284,9 @@ export function genUid(): string { export function is3dSupported(): boolean { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.is3dSupported', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.is3dSupported'); + .warn( + 'Blockly.utils.is3dSupported', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.is3dSupported'); // AnyDuringMigration because: Property 'is3dSupported' does not exist on // type 'void'. return (svgMath as AnyDuringMigration).is3dSupported(); @@ -302,9 +303,9 @@ export function is3dSupported(): boolean { export function getViewportBBox(): Rect { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getViewportBBox', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getViewportBBox'); + .warn( + 'Blockly.utils.getViewportBBox', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getViewportBBox'); // AnyDuringMigration because: Property 'getViewportBBox' does not exist on // type 'void'. return (svgMath as AnyDuringMigration).getViewportBBox(); @@ -319,10 +320,10 @@ export function getViewportBBox(): Rect { * @deprecated */ export function arrayRemove( - arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { + arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn('Blockly.utils.arrayRemove', 'December 2021', 'December 2022'); + .warn('Blockly.utils.arrayRemove', 'December 2021', 'December 2022'); return arrayUtils.removeElem(arr, value); } @@ -336,9 +337,9 @@ export function arrayRemove( export function getDocumentScroll(): Coordinate { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getDocumentScroll', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getDocumentScroll'); + .warn( + 'Blockly.utils.getDocumentScroll', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getDocumentScroll'); // AnyDuringMigration because: Property 'getDocumentScroll' does not exist on // type 'void'. return (svgMath as AnyDuringMigration).getDocumentScroll(); @@ -355,12 +356,12 @@ export function getDocumentScroll(): Coordinate { * @alias Blockly.utils.getBlockTypeCounts */ export function getBlockTypeCounts( - block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { + block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getBlockTypeCounts', 'December 2021', 'December 2022', - 'Blockly.common.getBlockTypeCounts'); + .warn( + 'Blockly.utils.getBlockTypeCounts', 'December 2021', 'December 2022', + 'Blockly.common.getBlockTypeCounts'); return common.getBlockTypeCounts(block, opt_stripFollowing); } @@ -373,16 +374,16 @@ export function getBlockTypeCounts( * @return The workspace coordinates. */ export function screenToWsCoordinates( - ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate { + ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.screenToWsCoordinates', 'December 2021', - 'December 2022', 'Blockly.utils.svgMath.screenToWsCoordinates'); + .warn( + 'Blockly.utils.screenToWsCoordinates', 'December 2021', + 'December 2022', 'Blockly.utils.svgMath.screenToWsCoordinates'); // AnyDuringMigration because: Property 'screenToWsCoordinates' does not // exist on type 'void'. return (svgMath as AnyDuringMigration) - .screenToWsCoordinates(ws, screenCoordinates); + .screenToWsCoordinates(ws, screenCoordinates); } /** @@ -396,13 +397,13 @@ export function screenToWsCoordinates( * @deprecated * @alias Blockly.utils.parseBlockColour */ -export function parseBlockColour(colour: number | - string): { hue: number | null, hex: string } { +export function parseBlockColour(colour: number| + string): {hue: number|null, hex: string} { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.parseBlockColour', 'December 2021', 'December 2022', - 'Blockly.utils.parsing.parseBlockColour'); + .warn( + 'Blockly.utils.parseBlockColour', 'December 2021', 'December 2022', + 'Blockly.utils.parsing.parseBlockColour'); // AnyDuringMigration because: Property 'parseBlockColour' does not exist on // type 'void'. return (parsing as AnyDuringMigration).parseBlockColour(colour); @@ -418,6 +419,6 @@ export function parseBlockColour(colour: number | export function runAfterPageLoad(fn: () => AnyDuringMigration) { // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. (deprecation as AnyDuringMigration) - .warn('Blockly.utils.runAfterPageLoad', 'December 2021', 'December 2022'); + .warn('Blockly.utils.runAfterPageLoad', 'December 2021', 'December 2022'); extensions.runAfterPageLoad(fn); } diff --git a/core/utils/aria.ts b/core/utils/aria.ts index d5c37d10b..c273d3ea4 100644 --- a/core/utils/aria.ts +++ b/core/utils/aria.ts @@ -148,7 +148,7 @@ export function setRole(element: Element, roleName: Role) { * @alias Blockly.utils.aria.setState */ export function setState( - element: Element, stateName: State, value: string | boolean | number | string[]) { + element: Element, stateName: State, value: string|boolean|number|string[]) { if (Array.isArray(value)) { value = value.join(' '); } diff --git a/core/utils/array.ts b/core/utils/array.ts index eb7764238..93c48330c 100644 --- a/core/utils/array.ts +++ b/core/utils/array.ts @@ -18,7 +18,7 @@ * @alias Blockly.array.removeElem */ export function removeElem( - arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { + arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { const i = arr.indexOf(value); if (i === -1) { return false; diff --git a/core/utils/colour.ts b/core/utils/colour.ts index 19e9f5e80..817c08298 100644 --- a/core/utils/colour.ts +++ b/core/utils/colour.ts @@ -76,7 +76,7 @@ export function setHsvValue(newValue: number) { * can't be parsed. * @alias Blockly.utils.colour.parse */ -export function parse(str: string | number): string | null { +export function parse(str: string|number): string|null { str = String(str).toLowerCase().trim(); let hex = names[str]; if (hex) { @@ -212,8 +212,8 @@ export function hsvToHex(h: number, s: number, v: number): string { * @return Combined colour represented in hex. * @alias Blockly.utils.colour.blend */ -export function blend(colour1: string, colour2: string, factor: number): string | - null { +export function blend(colour1: string, colour2: string, factor: number): string| + null { const hex1 = parse(colour1); if (!hex1) { return null; @@ -238,7 +238,7 @@ export function blend(colour1: string, colour2: string, factor: number): string * * @alias Blockly.utils.colour.names */ -export const names: { [key: string]: string } = { +export const names: {[key: string]: string} = { 'aqua': '#00ffff', 'black': '#000000', 'blue': '#0000ff', diff --git a/core/utils/coordinate.ts b/core/utils/coordinate.ts index 4f5bd0d7d..8d04b824b 100644 --- a/core/utils/coordinate.ts +++ b/core/utils/coordinate.ts @@ -67,7 +67,7 @@ export class Coordinate { * @param b A Coordinate. * @return True iff the coordinates are equal, or if both are null. */ - static equals(a: Coordinate | null, b: Coordinate | null): boolean { + static equals(a: Coordinate|null, b: Coordinate|null): boolean { if (a === b) { return true; } @@ -105,8 +105,8 @@ export class Coordinate { * @param b An x/y coordinate. * @return A Coordinate representing the difference between `a` and `b`. */ - static difference(a: Coordinate | SVGPoint, b: Coordinate | SVGPoint): - Coordinate { + static difference(a: Coordinate|SVGPoint, b: Coordinate|SVGPoint): + Coordinate { return new Coordinate(a.x - b.x, a.y - b.y); } @@ -116,7 +116,7 @@ export class Coordinate { * @param b An x/y coordinate. * @return A Coordinate representing the sum of the two coordinates. */ - static sum(a: Coordinate | SVGPoint, b: Coordinate | SVGPoint): Coordinate { + static sum(a: Coordinate|SVGPoint, b: Coordinate|SVGPoint): Coordinate { return new Coordinate(a.x + b.x, a.y + b.y); } } diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index 0d73432fc..ec6225f44 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -32,7 +32,7 @@ export function warn( name: string, deprecationDate: string, deletionDate: string, opt_use?: string) { let msg = name + ' was deprecated on ' + deprecationDate + - ' and will be deleted on ' + deletionDate + '.'; + ' and will be deleted on ' + deletionDate + '.'; if (opt_use) { msg += '\nUse ' + opt_use + ' instead.'; } diff --git a/core/utils/dom.ts b/core/utils/dom.ts index aace3f5aa..09beb9c5c 100644 --- a/core/utils/dom.ts +++ b/core/utils/dom.ts @@ -19,7 +19,7 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Svg } from './svg.js'; +import {Svg} from './svg.js'; import * as userAgent from './useragent.js'; @@ -73,7 +73,7 @@ let canvasContext: CanvasRenderingContext2D = null as AnyDuringMigration; * @alias Blockly.utils.dom.createSvgElement */ export function createSvgElement( - name: string | Svg, attrs: AnyDuringMigration, opt_parent?: Element): T { + name: string|Svg, attrs: AnyDuringMigration, opt_parent?: Element): T { const e = document.createElementNS(SVG_NS, String(name)) as T; for (const key in attrs) { e.setAttribute(key, attrs[key]); @@ -172,7 +172,7 @@ export function hasClass(element: Element, className: string): boolean { * @alias Blockly.utils.dom.removeNode */ // Copied from Closure goog.dom.removeNode -export function removeNode(node: Node | null): Node | null { +export function removeNode(node: Node|null): Node|null { return node && node.parentNode ? node.parentNode.removeChild(node) : null; } @@ -205,8 +205,8 @@ export function insertAfter(newNode: Element, refNode: Element) { */ export function containsNode(parent: Node, descendant: Node): boolean { return !!( - parent.compareDocumentPosition(descendant) & - NodeType.DOCUMENT_POSITION_CONTAINED_BY); + parent.compareDocumentPosition(descendant) & + NodeType.DOCUMENT_POSITION_CONTAINED_BY); } /** @@ -301,10 +301,10 @@ export function getTextWidth(textElement: SVGTextElement): number { * @alias Blockly.utils.dom.getFastTextWidth */ export function getFastTextWidth( - textElement: Element, fontSize: number, fontWeight: string, - fontFamily: string): number { + textElement: Element, fontSize: number, fontWeight: string, + fontFamily: string): number { return getFastTextWidthWithSizeString( - textElement, fontSize + 'pt', fontWeight, fontFamily); + textElement, fontSize + 'pt', fontWeight, fontFamily); } /** @@ -321,13 +321,13 @@ export function getFastTextWidth( * @alias Blockly.utils.dom.getFastTextWidthWithSizeString */ export function getFastTextWidthWithSizeString( - textElement: Element, fontSize: string, fontWeight: string, - fontFamily: string): number { + textElement: Element, 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; + text + '\n' + (textElement.className as AnyDuringMigration).baseVal; let width; // Return the cached width if it exists. @@ -374,8 +374,8 @@ export function getFastTextWidthWithSizeString( * @alias Blockly.utils.dom.measureFontMetrics */ export function measureFontMetrics( - text: string, fontSize: string, fontWeight: string, - fontFamily: string): { height: number, baseline: number } { + text: string, fontSize: string, fontWeight: string, + fontFamily: string): {height: number, baseline: number} { const span = (document.createElement('span')); span.style.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; span.textContent = text; diff --git a/core/utils/idgenerator.ts b/core/utils/idgenerator.ts index bf0a048d6..bcf99b785 100644 --- a/core/utils/idgenerator.ts +++ b/core/utils/idgenerator.ts @@ -47,7 +47,7 @@ export function getNextUniqueId(): string { * your own environment. Issues #251, #625, #682, #1304. */ const soup = '!#$%()*+,-./:;=?@[]^_`{|}~' + - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; /** * Generate a random unique ID. This should be globally unique. @@ -55,7 +55,7 @@ const soup = '!#$%()*+,-./:;=?@[]^_`{|}~' + * @return A globally unique ID string. */ // AnyDuringMigration because: Property 'genUid' does not exist on type '{}'. -(internal as AnyDuringMigration).genUid = function (): string { +(internal as AnyDuringMigration).genUid = function(): string { const length = 20; const soupLength = soup.length; const id = []; diff --git a/core/utils/math.ts b/core/utils/math.ts index 1b098723f..a2bef523e 100644 --- a/core/utils/math.ts +++ b/core/utils/math.ts @@ -50,7 +50,7 @@ export function toDegrees(angleRadians: number): number { * @alias Blockly.utils.math.clamp */ export function clamp( - lowerBound: number, number: number, upperBound: number): number { + lowerBound: number, number: number, upperBound: number): number { if (upperBound < lowerBound) { const temp = upperBound; upperBound = lowerBound; diff --git a/core/utils/object.ts b/core/utils/object.ts index 44347918c..0da7b7b4e 100644 --- a/core/utils/object.ts +++ b/core/utils/object.ts @@ -62,8 +62,8 @@ export function mixin(target: AnyDuringMigration, source: AnyDuringMigration) { * @alias Blockly.utils.object.deepMerge */ export function deepMerge( - target: AnyDuringMigration, - source: AnyDuringMigration): AnyDuringMigration { + target: AnyDuringMigration, + source: AnyDuringMigration): AnyDuringMigration { for (const x in source) { if (source[x] !== null && typeof source[x] === 'object') { target[x] = deepMerge(target[x] || Object.create(null), source[x]); @@ -85,7 +85,7 @@ export function values(obj: AnyDuringMigration): AnyDuringMigration[] { return Object.values(obj); } // Fallback for IE. - return Object.keys(obj).map(function (e) { + return Object.keys(obj).map(function(e) { return obj[e]; }); } diff --git a/core/utils/parsing.ts b/core/utils/parsing.ts index 6dd3353f5..ffbfc71e5 100644 --- a/core/utils/parsing.ts +++ b/core/utils/parsing.ts @@ -32,7 +32,8 @@ * @namespace Blockly.utils.parsing */ -import { Msg } from '../msg.js'; +import {Msg} from '../msg.js'; + import * as colourUtils from './colour.js'; @@ -46,18 +47,18 @@ import * as colourUtils from './colour.js'; * @return Array of strings and numbers. */ function tokenizeInterpolationInternal( - message: string, parseInterpolationTokens: boolean): (string | number)[] { + message: string, parseInterpolationTokens: boolean): (string|number)[] { const tokens = []; const chars = message.split(''); chars.push( // End marker. - ''); + ''); // Parse the message with a finite state machine. // 0 - Base case. // 1 - % found. // 2 - Digit found. // 3 - Message ref found. let state = 0; - const buffer = new Array < string > (); + const buffer = new Array(); let number = null; for (let i = 0; i < chars.length; i++) { const c = chars[i]; @@ -126,18 +127,17 @@ function tokenizeInterpolationInternal( // BKY_ is the prefix used to namespace the strings used in // Blockly core files and the predefined blocks in ../blocks/. // These strings are defined in ../msgs/ files. - const bklyKey = keyUpper.startsWith('BKY_') ? - keyUpper.substring(4) : - null; + const bklyKey = + keyUpper.startsWith('BKY_') ? keyUpper.substring(4) : null; if (bklyKey && bklyKey in Msg) { const rawValue = Msg[bklyKey]; if (typeof rawValue === 'string') { // Attempt to dereference substrings, too, appending to the // end. Array.prototype.push.apply( - tokens, - tokenizeInterpolationInternal( - rawValue, parseInterpolationTokens)); + tokens, + tokenizeInterpolationInternal( + rawValue, parseInterpolationTokens)); } else if (parseInterpolationTokens) { // When parsing interpolation tokens, numbers are special // placeholders (%1, %2, etc). Make sure all other values are @@ -202,7 +202,7 @@ function tokenizeInterpolationInternal( * @return Array of strings and numbers. * @alias Blockly.utils.parsing.tokenizeInterpolation */ -export function tokenizeInterpolation(message: string): (string | number)[] { +export function tokenizeInterpolation(message: string): (string|number)[] { return tokenizeInterpolationInternal(message, true); } @@ -215,8 +215,8 @@ export function tokenizeInterpolation(message: string): (string | number)[] { * @return String with message references replaced. * @alias Blockly.utils.parsing.replaceMessageReferences */ -export function replaceMessageReferences(message: string | - AnyDuringMigration): string { +export function replaceMessageReferences(message: string| + AnyDuringMigration): string { if (typeof message !== 'string') { return message; } @@ -265,23 +265,23 @@ export function checkMessageReferences(message: string): boolean { * @throws {Error} If the colour cannot be parsed. * @alias Blockly.utils.parsing.parseBlockColour */ -export function parseBlockColour(colour: number | - string): { hue: number | null, hex: string } { +export function parseBlockColour(colour: number| + string): {hue: number|null, hex: string} { const dereferenced = - typeof colour === 'string' ? replaceMessageReferences(colour) : colour; + typeof colour === 'string' ? replaceMessageReferences(colour) : colour; const hue = Number(dereferenced); if (!isNaN(hue) && 0 <= hue && hue <= 360) { return { hue: hue, hex: colourUtils.hsvToHex( - hue, colourUtils.getHsvSaturation(), colourUtils.getHsvValue() * 255), + hue, colourUtils.getHsvSaturation(), colourUtils.getHsvValue() * 255), }; } else { const hex = colourUtils.parse(dereferenced); if (hex) { // Only store hue if colour is set as a hue. - return { hue: null, hex: hex }; + return {hue: null, hex: hex}; } else { let errorMsg = 'Invalid colour: "' + dereferenced + '"'; if (colour !== dereferenced) { diff --git a/core/utils/rect.ts b/core/utils/rect.ts index 44ff5b931..444fd400a 100644 --- a/core/utils/rect.ts +++ b/core/utils/rect.ts @@ -32,8 +32,8 @@ export class Rect { * @struct */ constructor( - public top: number, public bottom: number, public left: number, - public right: number) {} + public top: number, public bottom: number, public left: number, + public right: number) {} /** * Tests whether this rectangle contains a x/y coordinate. @@ -44,7 +44,7 @@ export class Rect { */ contains(x: number, y: number): boolean { return x >= this.left && x <= this.right && y >= this.top && - y <= this.bottom; + y <= this.bottom; } /** @@ -55,7 +55,7 @@ export class Rect { */ intersects(other: Rect): boolean { return !( - this.left > other.right || this.right < other.left || - this.top > other.bottom || this.bottom < other.top); + this.left > other.right || this.right < other.left || + this.top > other.bottom || this.bottom < other.top); } } diff --git a/core/utils/size.ts b/core/utils/size.ts index 980838fc4..0926f708f 100644 --- a/core/utils/size.ts +++ b/core/utils/size.ts @@ -38,7 +38,7 @@ export class Size { * @return True iff the sizes have equal widths and equal heights, or if both * are null. */ - static equals(a: Size | null, b: Size | null): boolean { + static equals(a: Size|null, b: Size|null): boolean { if (a === b) { return true; } diff --git a/core/utils/string.ts b/core/utils/string.ts index 402a4e702..12e539293 100644 --- a/core/utils/string.ts +++ b/core/utils/string.ts @@ -48,10 +48,10 @@ export function shortestStringLength(array: string[]): number { return 0; } return array - .reduce(function (a, b) { - return a.length < b.length ? a : b; - }) - .length; + .reduce(function(a, b) { + return a.length < b.length ? a : b; + }) + .length; } /** @@ -63,7 +63,7 @@ export function shortestStringLength(array: string[]): number { * @alias Blockly.utils.string.commonWordPrefix */ export function commonWordPrefix( - array: string[], opt_shortest?: number): number { + array: string[], opt_shortest?: number): number { if (!array.length) { return 0; } else if (array.length === 1) { @@ -101,7 +101,7 @@ export function commonWordPrefix( * @alias Blockly.utils.string.commonWordSuffix */ export function commonWordSuffix( - array: string[], opt_shortest?: number): number { + array: string[], opt_shortest?: number): number { if (!array.length) { return 0; } else if (array.length === 1) { @@ -202,7 +202,7 @@ function wrapLine(text: string, limit: number): string { * @return Larger the better. */ function wrapScore( - words: string[], wordBreaks: boolean[], limit: number): number { + words: string[], wordBreaks: boolean[], limit: number): number { // If this function becomes a performance liability, add caching. // Compute the length of each line. const lineLengths = [0]; @@ -239,8 +239,8 @@ function wrapScore( // aaa bbb // ccc ddd eee if (lineLengths.length > 1 && - lineLengths[lineLengths.length - 1] <= - lineLengths[lineLengths.length - 2]) { + lineLengths[lineLengths.length - 1] <= + lineLengths[lineLengths.length - 2]) { score += 0.5; } return score; @@ -254,7 +254,7 @@ function wrapScore( * @return New array of optimal line breaks. */ function wrapMutate( - words: string[], wordBreaks: boolean[], limit: number): boolean[] { + words: string[], wordBreaks: boolean[], limit: number): boolean[] { let bestScore = wrapScore(words, wordBreaks, limit); let bestBreaks; // Try shifting every line break forward or backward. @@ -262,7 +262,7 @@ function wrapMutate( if (wordBreaks[i] === wordBreaks[i + 1]) { continue; } - const mutatedWordBreaks = (new Array < boolean > ()).concat(wordBreaks); + const mutatedWordBreaks = (new Array()).concat(wordBreaks); mutatedWordBreaks[i] = !mutatedWordBreaks[i]; mutatedWordBreaks[i + 1] = !mutatedWordBreaks[i + 1]; const mutatedScore = wrapScore(words, mutatedWordBreaks, limit); diff --git a/core/utils/style.ts b/core/utils/style.ts index 5037aabdd..ad724065f 100644 --- a/core/utils/style.ts +++ b/core/utils/style.ts @@ -18,9 +18,9 @@ * @namespace Blockly.utils.style */ -import { Coordinate } from './coordinate.js'; -import { Rect } from './rect.js'; -import { Size } from './size.js'; +import {Coordinate} from './coordinate.js'; +import {Rect} from './rect.js'; +import {Size} from './size.js'; /** @@ -85,8 +85,8 @@ function getStyle(element: Element, style: string): string { // 'Element'. AnyDuringMigration because: Property 'style' does not exist on // type 'Element'. return getComputedStyle(element, style) || getCascadedStyle(element, style) || - (element as AnyDuringMigration).style && - (element as AnyDuringMigration).style[style]; + (element as AnyDuringMigration).style && + (element as AnyDuringMigration).style[style]; } /** @@ -109,7 +109,7 @@ export function getComputedStyle(element: Element, property: string): string { // element.style[..] is undefined for browser specific styles // as 'filter'. return (styles as AnyDuringMigration)[property] || - styles.getPropertyValue(property) || ''; + styles.getPropertyValue(property) || ''; } } @@ -132,8 +132,8 @@ export function getCascadedStyle(element: Element, style: string): string { // 'Element'. AnyDuringMigration because: Property 'currentStyle' does not // exist on type 'Element'. return (element as AnyDuringMigration).currentStyle ? - (element as AnyDuringMigration).currentStyle[style] : - '' as string; + (element as AnyDuringMigration).currentStyle[style] : + '' as string; } /** @@ -151,8 +151,8 @@ export function getPageOffset(el: Element): Coordinate { // of element since getBoundingClientRect returns relative coordinates to // the viewport. const scrollCoord = new Coordinate( - window.pageXOffset || documentElement.scrollLeft, - window.pageYOffset || documentElement.scrollTop); + window.pageXOffset || documentElement.scrollLeft, + window.pageYOffset || documentElement.scrollTop); pos.x = box.left + scrollCoord.x; pos.y = box.top + scrollCoord.y; @@ -235,7 +235,7 @@ export function getBorderBox(element: Element): Rect { * @alias Blockly.utils.style.scrollIntoContainerView */ export function scrollIntoContainerView( - element: Element, container: Element, opt_center?: boolean) { + element: Element, container: Element, opt_center?: boolean) { const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; @@ -257,7 +257,7 @@ export function scrollIntoContainerView( * @alias Blockly.utils.style.getContainerOffsetToScrollInto */ export function getContainerOffsetToScrollInto( - element: Element, container: Element, opt_center?: boolean): Coordinate { + element: Element, container: Element, opt_center?: boolean): Coordinate { // Absolute position of the element's border's top left corner. const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. diff --git a/core/utils/svg.ts b/core/utils/svg.ts index fa1c8e454..4c0cdc496 100644 --- a/core/utils/svg.ts +++ b/core/utils/svg.ts @@ -22,31 +22,31 @@ * @alias Blockly.utils.Svg */ export class Svg { - static ANIMATE = new Svg < SVGAnimateElement > ('animate'); - static CIRCLE = new Svg < SVGCircleElement > ('circle'); - static CLIPPATH = new Svg < SVGClipPathElement > ('clipPath'); - static DEFS = new Svg < SVGDefsElement > ('defs'); - static FECOMPOSITE = new Svg < SVGFECompositeElement > ('feComposite'); + static ANIMATE = new Svg('animate'); + static CIRCLE = new Svg('circle'); + static CLIPPATH = new Svg('clipPath'); + static DEFS = new Svg('defs'); + static FECOMPOSITE = new Svg('feComposite'); static FECOMPONENTTRANSFER = - new Svg < SVGFEComponentTransferElement > ('feComponentTransfer'); - static FEFLOOD = new Svg < SVGFEFloodElement > ('feFlood'); - static FEFUNCA = new Svg < SVGFEFuncAElement > ('feFuncA'); - static FEGAUSSIANBLUR = new Svg < SVGFEGaussianBlurElement > ('feGaussianBlur'); - static FEPOINTLIGHT = new Svg < SVGFEPointLightElement > ('fePointLight'); + new Svg('feComponentTransfer'); + static FEFLOOD = new Svg('feFlood'); + static FEFUNCA = new Svg('feFuncA'); + static FEGAUSSIANBLUR = new Svg('feGaussianBlur'); + static FEPOINTLIGHT = new Svg('fePointLight'); static FESPECULARLIGHTING = - new Svg < SVGFESpecularLightingElement > ('feSpecularLighting'); - static FILTER = new Svg < SVGFilterElement > ('filter'); - static FOREIGNOBJECT = new Svg < SVGForeignObjectElement > ('foreignObject'); - static G = new Svg < SVGGElement > ('g'); - static IMAGE = new Svg < SVGImageElement > ('image'); - static LINE = new Svg < SVGLineElement > ('line'); - static PATH = new Svg < SVGPathElement > ('path'); - static PATTERN = new Svg < SVGPatternElement > ('pattern'); - static POLYGON = new Svg < SVGPolygonElement > ('polygon'); - static RECT = new Svg < SVGRectElement > ('rect'); - static SVG = new Svg < SVGSVGElement > ('svg'); - static TEXT = new Svg < SVGTextElement > ('text'); - static TSPAN = new Svg < SVGTSpanElement > ('tspan'); + new Svg('feSpecularLighting'); + static FILTER = new Svg('filter'); + static FOREIGNOBJECT = new Svg('foreignObject'); + static G = new Svg('g'); + static IMAGE = new Svg('image'); + static LINE = new Svg('line'); + static PATH = new Svg('path'); + static PATTERN = new Svg('pattern'); + static POLYGON = new Svg('polygon'); + static RECT = new Svg('rect'); + static SVG = new Svg('svg'); + static TEXT = new Svg('text'); + static TSPAN = new Svg('tspan'); /** @param tagName The SVG element tag name. */ constructor(private readonly tagName: string) {} diff --git a/core/utils/svg_math.ts b/core/utils/svg_math.ts index a86dd0f72..795fdf520 100644 --- a/core/utils/svg_math.ts +++ b/core/utils/svg_math.ts @@ -13,11 +13,12 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from '../workspace_svg.js'; -import { Coordinate } from './coordinate.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; + +import {Coordinate} from './coordinate.js'; import * as deprecation from './deprecation.js'; -import { Rect } from './rect.js'; -import { Size } from './size.js'; +import {Rect} from './rect.js'; +import {Size} from './size.js'; import * as style from './style.js'; import * as userAgent from './useragent.js'; @@ -37,7 +38,7 @@ const XY_REGEX: RegExp = /translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/; * Accounts for same exceptions as XY_REGEX. */ const XY_STYLE_REGEX: RegExp = - /transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/; + /transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/; /** @@ -157,7 +158,7 @@ export function is3dSupported(): boolean { return false; } has3d = - computedStyle.getPropertyValue((transforms as AnyDuringMigration)[t]); + computedStyle.getPropertyValue((transforms as AnyDuringMigration)[t]); } } document.body.removeChild(el); @@ -180,8 +181,8 @@ export function getViewportBBox(): Rect { // Pixels, in window coordinates. const scrollOffset = style.getViewportPageOffset(); return new Rect( - scrollOffset.y, document.documentElement.clientHeight + scrollOffset.y, - scrollOffset.x, document.documentElement.clientWidth + scrollOffset.x); + scrollOffset.y, document.documentElement.clientHeight + scrollOffset.y, + scrollOffset.x, document.documentElement.clientWidth + scrollOffset.x); } /** @@ -200,7 +201,7 @@ export function getDocumentScroll(): Coordinate { return new Coordinate(el.scrollLeft, el.scrollTop); } return new Coordinate( - win.pageXOffset || el.scrollLeft, win.pageYOffset || el.scrollTop); + win.pageXOffset || el.scrollLeft, win.pageYOffset || el.scrollTop); } /** @@ -212,7 +213,7 @@ export function getDocumentScroll(): Coordinate { * @alias Blockly.utils.svgMath.screenToWsCoordinates */ export function screenToWsCoordinates( - ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate { + ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate { const screenX = screenCoordinates.x; const screenY = screenCoordinates.y; @@ -224,7 +225,7 @@ export function screenToWsCoordinates( // The client coordinates offset by the injection div's upper left corner. const clientOffsetPixels = - new Coordinate(screenX - boundingRect.left, screenY - boundingRect.top); + new Coordinate(screenX - boundingRect.left, screenY - boundingRect.top); // The offset in pixels between the main workspace's origin and the upper // left corner of the injection div. @@ -233,7 +234,7 @@ export function screenToWsCoordinates( // The position of the new comment in pixels relative to the origin of the // main workspace. const finalOffsetPixels = - Coordinate.difference(clientOffsetPixels, mainOffsetPixels); + Coordinate.difference(clientOffsetPixels, mainOffsetPixels); // The position in main workspace coordinates. const finalOffsetMainWs = finalOffsetPixels.scale(1 / ws.scale); return finalOffsetMainWs; @@ -252,12 +253,12 @@ export function svgSize(svg: SVGElement): Size { // The deprecated name is `Blockly.svgSize` because this function used to be // declared in Blockly.js. deprecation.warn( - 'Blockly.svgSize', 'March 2021', 'March 2022', - 'workspace.getCachedParentSvgSize'); + 'Blockly.svgSize', 'March 2021', 'March 2022', + 'workspace.getCachedParentSvgSize'); svg = svg as AnyDuringMigration; return new Size( - Number(svg.getAttribute('data-cached-width')), - Number(svg.getAttribute('data-cached-height'))); + Number(svg.getAttribute('data-cached-width')), + Number(svg.getAttribute('data-cached-height'))); } diff --git a/core/utils/svg_paths.ts b/core/utils/svg_paths.ts index 158124303..716929b80 100644 --- a/core/utils/svg_paths.ts +++ b/core/utils/svg_paths.ts @@ -134,6 +134,6 @@ export function lineOnAxis(command: string, val: number): string { * @alias Blockly.utils.svgPaths.arc */ export function arc( - command: string, flags: string, radius: number, point: string): string { + command: string, flags: string, radius: number, point: string): string { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; } diff --git a/core/utils/toolbox.ts b/core/utils/toolbox.ts index f586b784f..cdf9b2e0d 100644 --- a/core/utils/toolbox.ts +++ b/core/utils/toolbox.ts @@ -19,9 +19,9 @@ import '../toolbox/category'; import '../toolbox/separator'; /* eslint-disable-next-line no-unused-vars */ -import { ConnectionState } from '../serialization/blocks.js'; -import { CssConfig as CategoryCssConfig } from '../toolbox/category.js'; -import { CssConfig as SeparatorCssConfig } from '../toolbox/separator.js'; +import {ConnectionState} from '../serialization/blocks.js'; +import {CssConfig as CategoryCssConfig} from '../toolbox/category.js'; +import {CssConfig as SeparatorCssConfig} from '../toolbox/separator.js'; import * as Xml from '../xml.js'; import * as userAgent from './useragent.js'; @@ -33,22 +33,22 @@ import * as userAgent from './useragent.js'; */ export interface BlockInfo { kind: string; - blockxml: string | Node | undefined; - type: string | undefined; - gap: string | number | undefined; - disabled: string | boolean | undefined; - enabled: boolean | undefined; - id: string | undefined; - x: number | undefined; - y: number | undefined; - collapsed: boolean | undefined; - inline: boolean | undefined; - data: string | undefined; - extraState: AnyDuringMigration | undefined; - icons: { [key: string]: AnyDuringMigration } | undefined; - fields: { [key: string]: AnyDuringMigration } | undefined; - inputs: { [key: string]: ConnectionState } | undefined; - next: ConnectionState | undefined; + blockxml: string|Node|undefined; + type: string|undefined; + gap: string|number|undefined; + disabled: string|boolean|undefined; + enabled: boolean|undefined; + id: string|undefined; + x: number|undefined; + y: number|undefined; + collapsed: boolean|undefined; + inline: boolean|undefined; + data: string|undefined; + extraState: AnyDuringMigration|undefined; + icons: {[key: string]: AnyDuringMigration}|undefined; + fields: {[key: string]: AnyDuringMigration}|undefined; + inputs: {[key: string]: ConnectionState}|undefined; + next: ConnectionState|undefined; } /** @@ -57,9 +57,9 @@ export interface BlockInfo { */ export interface SeparatorInfo { kind: string; - id: string | undefined; - gap: number | undefined; - cssconfig: SeparatorCssConfig | undefined; + id: string|undefined; + gap: number|undefined; + cssconfig: SeparatorCssConfig|undefined; } /** @@ -79,14 +79,14 @@ export interface ButtonInfo { export interface LabelInfo { kind: string; text: string; - id: string | undefined; + id: string|undefined; } /** * The information needed to create either a button or a label in the flyout. * @alias Blockly.utils.toolbox.ButtonOrLabelInfo */ -export type ButtonOrLabelInfo = ButtonInfo | LabelInfo; +export type ButtonOrLabelInfo = ButtonInfo|LabelInfo; /** * The information needed to create a category in the toolbox. @@ -96,11 +96,11 @@ export interface StaticCategoryInfo { kind: string; name: string; contents: ToolboxItemInfo[]; - id: string | undefined; - categorystyle: string | undefined; - colour: string | undefined; - cssconfig: CategoryCssConfig | undefined; - hidden: string | undefined; + id: string|undefined; + categorystyle: string|undefined; + colour: string|undefined; + cssconfig: CategoryCssConfig|undefined; + hidden: string|undefined; } /** @@ -110,31 +110,31 @@ export interface StaticCategoryInfo { export interface DynamicCategoryInfo { kind: string; custom: string; - id: string | undefined; - categorystyle: string | undefined; - colour: string | undefined; - cssconfig: CategoryCssConfig | undefined; - hidden: string | undefined; + id: string|undefined; + categorystyle: string|undefined; + colour: string|undefined; + cssconfig: CategoryCssConfig|undefined; + hidden: string|undefined; } /** * The information needed to create either a dynamic or static category. * @alias Blockly.utils.toolbox.CategoryInfo */ -export type CategoryInfo = StaticCategoryInfo | DynamicCategoryInfo; +export type CategoryInfo = StaticCategoryInfo|DynamicCategoryInfo; /** * Any information that can be used to create an item in the toolbox. * @alias Blockly.utils.toolbox.ToolboxItemInfo */ -export type ToolboxItemInfo = FlyoutItemInfo | StaticCategoryInfo; +export type ToolboxItemInfo = FlyoutItemInfo|StaticCategoryInfo; /** * All the different types that can be displayed in a flyout. * @alias Blockly.utils.toolbox.FlyoutItemInfo */ export type FlyoutItemInfo = - BlockInfo | SeparatorInfo | ButtonInfo | LabelInfo | DynamicCategoryInfo; + BlockInfo|SeparatorInfo|ButtonInfo|LabelInfo|DynamicCategoryInfo; /** * The JSON definition of a toolbox. @@ -155,13 +155,13 @@ export type FlyoutItemInfoArray = FlyoutItemInfo[]; * All of the different types that can create a toolbox. * @alias Blockly.utils.toolbox.ToolboxDefinition */ -export type ToolboxDefinition = Node | ToolboxInfo | string; +export type ToolboxDefinition = Node|ToolboxInfo|string; /** * All of the different types that can be used to show items in a flyout. * @alias Blockly.utils.toolbox.FlyoutDefinition */ -export type FlyoutDefinition = FlyoutItemInfoArray | NodeList | ToolboxInfo | Node[]; +export type FlyoutDefinition = FlyoutItemInfoArray|NodeList|ToolboxInfo|Node[]; /** * The name used to identify a toolbox that has category like items. @@ -194,8 +194,8 @@ export enum Position { * @return Object holding information for creating a toolbox. * @alias Blockly.utils.toolbox.convertToolboxDefToJson */ -export function convertToolboxDefToJson(toolboxDef: ToolboxDefinition | - null): ToolboxInfo | null { +export function convertToolboxDefToJson(toolboxDef: ToolboxDefinition| + null): ToolboxInfo|null { if (!toolboxDef) { return null; } @@ -223,11 +223,11 @@ function validateToolbox(toolboxJson: ToolboxInfo) { if (toolboxKind) { if (toolboxKind !== FLYOUT_TOOLBOX_KIND && - toolboxKind !== CATEGORY_TOOLBOX_KIND) { + toolboxKind !== CATEGORY_TOOLBOX_KIND) { throw Error( - 'Invalid toolbox kind ' + toolboxKind + '.' + - ' Please supply either ' + FLYOUT_TOOLBOX_KIND + ' or ' + - CATEGORY_TOOLBOX_KIND); + 'Invalid toolbox kind ' + toolboxKind + '.' + + ' Please supply either ' + FLYOUT_TOOLBOX_KIND + ' or ' + + CATEGORY_TOOLBOX_KIND); } } if (!toolboxContents) { @@ -241,8 +241,8 @@ function validateToolbox(toolboxJson: ToolboxInfo) { * @return A list of flyout items. * @alias Blockly.utils.toolbox.convertFlyoutDefToJsonArray */ -export function convertFlyoutDefToJsonArray(flyoutDef: FlyoutDefinition | - null): FlyoutItemInfoArray { +export function convertFlyoutDefToJsonArray(flyoutDef: FlyoutDefinition| + null): FlyoutItemInfoArray { if (!flyoutDef) { return []; } @@ -254,7 +254,7 @@ export function convertFlyoutDefToJsonArray(flyoutDef: FlyoutDefinition | // AnyDuringMigration because: Property 'nodeType' does not exist on type // 'Node | FlyoutItemInfo'. if (Array.isArray(flyoutDef) && flyoutDef.length > 0 && - !((flyoutDef[0]) as AnyDuringMigration).nodeType) { + !((flyoutDef[0]) as AnyDuringMigration).nodeType) { // AnyDuringMigration because: Type 'FlyoutItemInfoArray | Node[]' is not // assignable to type 'FlyoutItemInfoArray'. return flyoutDef as AnyDuringMigration; @@ -271,7 +271,7 @@ export function convertFlyoutDefToJsonArray(flyoutDef: FlyoutDefinition | * @return True if the toolbox has categories. * @alias Blockly.utils.toolbox.hasCategories */ -export function hasCategories(toolboxJson: ToolboxInfo | null): boolean { +export function hasCategories(toolboxJson: ToolboxInfo|null): boolean { if (!toolboxJson) { return false; } @@ -281,7 +281,7 @@ export function hasCategories(toolboxJson: ToolboxInfo | null): boolean { return toolboxKind === CATEGORY_TOOLBOX_KIND; } - const categories = toolboxJson['contents'].filter(function (item) { + const categories = toolboxJson['contents'].filter(function(item) { return item['kind'].toUpperCase() === 'CATEGORY'; }); return !!categories.length; @@ -299,10 +299,10 @@ export function isCategoryCollapsible(categoryInfo: CategoryInfo): boolean { } const categories = - (categoryInfo as AnyDuringMigration)['contents'].filter(function ( - item: AnyDuringMigration) { - return item['kind'].toUpperCase() === 'CATEGORY'; - }); + (categoryInfo as AnyDuringMigration)['contents'].filter(function( + item: AnyDuringMigration) { + return item['kind'].toUpperCase() === 'CATEGORY'; + }); return !!categories.length; } @@ -313,7 +313,7 @@ export function isCategoryCollapsible(categoryInfo: CategoryInfo): boolean { */ function convertToToolboxJson(toolboxDef: Node): ToolboxInfo { const contents = xmlToJsonArray(toolboxDef as Node | Node[]); - const toolboxJson = { 'contents': contents }; + const toolboxJson = {'contents': contents}; if (toolboxDef instanceof Node) { addAttributes(toolboxDef, toolboxJson); } @@ -325,8 +325,8 @@ function convertToToolboxJson(toolboxDef: Node): ToolboxInfo { * @param toolboxDef The definition of the toolbox in one of its many forms. * @return A list of objects in the toolbox. */ -function xmlToJsonArray(toolboxDef: Node | Node[] | NodeList): FlyoutItemInfoArray | - ToolboxItemInfo[] { +function xmlToJsonArray(toolboxDef: Node|Node[]|NodeList): FlyoutItemInfoArray| + ToolboxItemInfo[] { const arr = []; // If it is a node it will have children. // AnyDuringMigration because: Property 'childNodes' does not exist on type @@ -388,8 +388,8 @@ function addAttributes(node: Node, obj: AnyDuringMigration) { * @return DOM tree of blocks, or null. * @alias Blockly.utils.toolbox.parseToolboxTree */ -export function parseToolboxTree(toolboxDef: Element | null | string): Element | - null { +export function parseToolboxTree(toolboxDef: Element|null|string): Element| + null { if (toolboxDef) { if (typeof toolboxDef !== 'string') { if (userAgent.IE && toolboxDef.outerHTML) { diff --git a/core/utils/useragent.ts b/core/utils/useragent.ts index 7643231c6..3dd95f4aa 100644 --- a/core/utils/useragent.ts +++ b/core/utils/useragent.ts @@ -47,49 +47,49 @@ let isTablet: boolean; let isMobile: boolean; -(function (raw) { - rawUserAgent = raw; - const rawUpper = rawUserAgent.toUpperCase(); - /** - * Case-insensitive test of whether name is in the useragent string. - * @param name Name to test. - * @return True if name is present. - */ - function has(name: string): boolean { - return rawUpper.indexOf(name.toUpperCase()) !== -1; - } +(function(raw) { +rawUserAgent = raw; +const rawUpper = rawUserAgent.toUpperCase(); +/** + * Case-insensitive test of whether name is in the useragent string. + * @param name Name to test. + * @return True if name is present. + */ +function has(name: string): boolean { + return rawUpper.indexOf(name.toUpperCase()) !== -1; +} - // Browsers. Logic from: - // https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/browser.js - isIe = has('Trident') || has('MSIE'); - isEdge = has('Edge'); - // Useragent for JavaFX: - // Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44 - // (KHTML, like Gecko) JavaFX/8.0 Safari/537.44 - isJavaFx = has('JavaFX'); - isChrome = (has('Chrome') || has('CriOS')) && !isEdge; +// Browsers. Logic from: +// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/browser.js +isIe = has('Trident') || has('MSIE'); +isEdge = has('Edge'); +// Useragent for JavaFX: +// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44 +// (KHTML, like Gecko) JavaFX/8.0 Safari/537.44 +isJavaFx = has('JavaFX'); +isChrome = (has('Chrome') || has('CriOS')) && !isEdge; - // Engines. Logic from: - // https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/engine.js - isWebKit = has('WebKit') && !isEdge; - isGecko = has('Gecko') && !isWebKit && !isIe && !isEdge; +// Engines. Logic from: +// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/engine.js +isWebKit = has('WebKit') && !isEdge; +isGecko = has('Gecko') && !isWebKit && !isIe && !isEdge; - // Platforms. Logic from: - // https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/platform.js - // and - // https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js - isAndroid = has('Android'); - const maxTouchPoints = +// Platforms. Logic from: +// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/platform.js +// and +// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js +isAndroid = has('Android'); +const maxTouchPoints = globalThis['navigator'] && globalThis['navigator']['maxTouchPoints']; - isIPad = has('iPad') || has('Macintosh') && maxTouchPoints > 0; - isIPod = has('iPod'); - isIPhone = has('iPhone') && !isIPad && !isIPod; - isMac = has('Macintosh'); +isIPad = has('iPad') || has('Macintosh') && maxTouchPoints > 0; +isIPod = has('iPod'); +isIPhone = has('iPhone') && !isIPad && !isIPod; +isMac = has('Macintosh'); - // Devices. Logic from: - // https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js - isTablet = isIPad || isAndroid && !has('Mobile') || has('Silk'); - isMobile = !isTablet && (isIPod || isIPhone || isAndroid || has('IEMobile')); +// Devices. Logic from: +// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js +isTablet = isIPad || isAndroid && !has('Mobile') || has('Silk'); +isMobile = !isTablet && (isIPod || isIPhone || isAndroid || has('IEMobile')); })(globalThis['navigator'] && globalThis['navigator']['userAgent'] || ''); /** @alias Blockly.utils.userAgent.raw */ diff --git a/core/variable_map.ts b/core/variable_map.ts index 35136afc3..250878541 100644 --- a/core/variable_map.ts +++ b/core/variable_map.ts @@ -18,16 +18,16 @@ import './events/events_var_delete'; import './events/events_var_rename'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; import * as dialog from './dialog.js'; import * as eventUtils from './events/utils.js'; -import { Msg } from './msg.js'; -import { Names } from './names.js'; +import {Msg} from './msg.js'; +import {Names} from './names.js'; import * as arrayUtils from './utils/array.js'; import * as idGenerator from './utils/idgenerator.js'; -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -37,7 +37,7 @@ import { Workspace } from './workspace.js'; * @alias Blockly.VariableMap */ export class VariableMap { - private variableMap_: { [key: string]: VariableModel[] }; + private variableMap_: {[key: string]: VariableModel[]}; /** @param workspace The workspace this map belongs to. */ constructor(public workspace: Workspace) { @@ -71,7 +71,7 @@ export class VariableMap { this.renameVariableAndUses_(variable, newName, blocks); } else { this.renameVariableWithConflict_( - variable, newName, conflictVar, blocks); + variable, newName, conflictVar, blocks); } } finally { eventUtils.setGroup(false); @@ -101,9 +101,9 @@ export class VariableMap { * @param blocks The list of all blocks in the workspace. */ private renameVariableAndUses_( - variable: VariableModel, newName: string, blocks: Block[]) { + variable: VariableModel, newName: string, blocks: Block[]) { eventUtils.fire(new (eventUtils.get(eventUtils.VAR_RENAME))! - (variable, newName)); + (variable, newName)); variable.name = newName; for (let i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); @@ -121,8 +121,8 @@ export class VariableMap { * @param blocks The list of all blocks in the workspace. */ private renameVariableWithConflict_( - variable: VariableModel, newName: string, conflictVar: VariableModel, - blocks: Block[]) { + variable: VariableModel, newName: string, conflictVar: VariableModel, + blocks: Block[]) { const type = variable.type; const oldCase = conflictVar.name; @@ -152,15 +152,15 @@ export class VariableMap { * @param opt_id The unique ID of the variable. This will default to a UUID. * @return The newly created variable. */ - createVariable(name: string, opt_type?: string | null, opt_id?: string | null): - VariableModel { + createVariable(name: string, opt_type?: string|null, opt_id?: string|null): + VariableModel { let variable = this.getVariable(name, opt_type); if (variable) { if (opt_id && variable.getId() !== opt_id) { throw Error( - 'Variable "' + name + '" is already in use and its id is "' + - variable.getId() + '" which conflicts with the passed in ' + - 'id, "' + opt_id + '".'); + 'Variable "' + name + '" is already in use and its id is "' + + variable.getId() + '" which conflicts with the passed in ' + + 'id, "' + opt_id + '".'); } // The variable already exists and has the same ID. return variable; @@ -214,11 +214,11 @@ export class VariableMap { const uses = this.getVariableUsesById(id); for (let i = 0, block; block = uses[i]; i++) { if (block.type === 'procedures_defnoreturn' || - block.type === 'procedures_defreturn') { + block.type === 'procedures_defreturn') { const procedureName = String(block.getFieldValue('NAME')); const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE'] - .replace('%1', variableName) - .replace('%2', procedureName); + .replace('%1', variableName) + .replace('%2', procedureName); dialog.alert(deleteText); return; } @@ -228,9 +228,9 @@ export class VariableMap { if (uses.length > 1) { // Confirm before deleting multiple blocks. const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION'] - .replace('%1', String(uses.length)) - .replace('%2', variableName); - dialog.confirm(confirmText, function (ok) { + .replace('%1', String(uses.length)) + .replace('%2', variableName); + dialog.confirm(confirmText, function(ok) { if (ok && variable) { map.deleteVariableInternal(variable, uses); } @@ -275,7 +275,7 @@ export class VariableMap { * the empty string, which is a specific type. * @return The variable with the given name, or null if it was not found. */ - getVariable(name: string, opt_type?: string | null): VariableModel | null { + getVariable(name: string, opt_type?: string|null): VariableModel|null { const type = opt_type || ''; const list = this.variableMap_[type]; if (list) { @@ -293,7 +293,7 @@ export class VariableMap { * @param id The ID to check for. * @return The variable with the given ID. */ - getVariableById(id: string): VariableModel | null { + getVariableById(id: string): VariableModel|null { const keys = Object.keys(this.variableMap_); for (let i = 0; i < keys.length; i++) { const key = keys[i]; @@ -313,7 +313,7 @@ export class VariableMap { * @return The sought after variables of the passed in type. An empty array if * none are found. */ - getVariablesOfType(type: string | null): VariableModel[] { + getVariablesOfType(type: string|null): VariableModel[] { type = type || ''; const variableList = this.variableMap_[type]; if (variableList) { @@ -330,7 +330,7 @@ export class VariableMap { * is a flyout workspace. * @return List of variable types. */ - getVariableTypes(ws: Workspace | null): string[] { + getVariableTypes(ws: Workspace|null): string[] { const variableMap = {}; Object.assign(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { diff --git a/core/variable_model.ts b/core/variable_model.ts index 24b9818d4..40a08f8f2 100644 --- a/core/variable_model.ts +++ b/core/variable_model.ts @@ -18,7 +18,7 @@ import './events/events_var_create'; import * as eventUtils from './events/utils.js'; import * as idGenerator from './utils/idgenerator.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -41,8 +41,8 @@ export class VariableModel { * @param opt_id The unique ID of the variable. This will default to a UUID. */ constructor( - public workspace: Workspace, public name: string, opt_type?: string, - opt_id?: string) { + public workspace: Workspace, public name: string, opt_type?: string, + opt_id?: string) { /** * The type of the variable, such as 'int' or 'sound_effect'. This may be * used to build a list of variables of a specific type. By default this is @@ -74,6 +74,6 @@ export class VariableModel { * greater. */ static compareByName(var1: VariableModel, var2: VariableModel): number { - return var1.name.localeCompare(var2.name, undefined, { sensitivity: 'base' }); + return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'}); } } diff --git a/core/variables.ts b/core/variables.ts index 8e42770f7..504119947 100644 --- a/core/variables.ts +++ b/core/variables.ts @@ -12,15 +12,15 @@ * @namespace Blockly.Variables */ -import { Blocks } from './blocks.js'; +import {Blocks} from './blocks.js'; import * as dialog from './dialog.js'; -import { Msg } from './msg.js'; +import {Msg} from './msg.js'; import * as utilsXml from './utils/xml.js'; -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; import * as Xml from './xml.js'; /** @@ -66,7 +66,7 @@ export function allUsedVarModels(ws: Workspace): VariableModel[] { return variableList; } -const ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE: { [key: string]: boolean } = {}; +const ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE: {[key: string]: boolean} = {}; /** * Find all developer variables used by blocks in the workspace. @@ -103,16 +103,16 @@ export function allDeveloperVariables(workspace: Workspace): string[] { * @alias Blockly.Variables.flyoutCategory */ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { - let xmlList = new Array < Element > (); + let xmlList = new Array(); const button = document.createElement('button'); button.setAttribute('text', '%{BKY_NEW_VARIABLE}'); button.setAttribute('callbackKey', 'CREATE_VARIABLE'); - workspace.registerButtonCallback('CREATE_VARIABLE', function (button) { + workspace.registerButtonCallback('CREATE_VARIABLE', function(button) { // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not // assignable to parameter of type 'Workspace'. createVariableButtonHandler( - button.getTargetWorkspace() as AnyDuringMigration); + button.getTargetWorkspace() as AnyDuringMigration); }); xmlList.push(button); @@ -143,11 +143,11 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. block.setAttribute( - 'gap', (Blocks['math_change'] ? 8 : 24) as AnyDuringMigration); + 'gap', (Blocks['math_change'] ? 8 : 24) as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'Element | null' is not // assignable to parameter of type 'Node'. block.appendChild( - generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); + generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); xmlList.push(block); } if (Blocks['math_change']) { @@ -156,17 +156,17 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { // AnyDuringMigration because: Argument of type 'number' is not // assignable to parameter of type 'string'. block.setAttribute( - 'gap', (Blocks['variables_get'] ? 20 : 8) as AnyDuringMigration); + 'gap', (Blocks['variables_get'] ? 20 : 8) as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'Element | null' is not // assignable to parameter of type 'Node'. block.appendChild( - generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); + generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); const value = Xml.textToDom( - '' + - '' + - '1' + - '' + - ''); + '' + + '' + + '1' + + '' + + ''); block.appendChild(value); xmlList.push(block); } @@ -182,7 +182,7 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { // AnyDuringMigration because: Argument of type 'Element | null' is not // assignable to parameter of type 'Node'. block.appendChild( - generateVariableFieldDom(variable) as AnyDuringMigration); + generateVariableFieldDom(variable) as AnyDuringMigration); xmlList.push(block); } } @@ -204,7 +204,7 @@ export const VAR_LETTER_OPTIONS = 'ijkmnopqrstuvwxyzabcdefgh'; */ export function generateUniqueName(workspace: Workspace): string { return generateUniqueNameFromOptions( - VAR_LETTER_OPTIONS.charAt(0), workspace.getAllVariableNames()); + VAR_LETTER_OPTIONS.charAt(0), workspace.getAllVariableNames()); } /** @@ -217,7 +217,7 @@ export function generateUniqueName(workspace: Workspace): string { * @alias Blockly.Variables.generateUniqueNameFromOptions */ export function generateUniqueNameFromOptions( - startChar: string, usedNames: string[]): string { + startChar: string, usedNames: string[]): string { if (!usedNames.length) { return startChar; } @@ -270,13 +270,13 @@ export function generateUniqueNameFromOptions( * @alias Blockly.Variables.createVariableButtonHandler */ export function createVariableButtonHandler( - workspace: Workspace, - opt_callback?: (p1?: string | null) => AnyDuringMigration, - opt_type?: string) { + workspace: Workspace, + opt_callback?: (p1?: string|null) => AnyDuringMigration, + opt_type?: string) { const type = opt_type || ''; // This function needs to be named so it can be called recursively. function promptAndCheckWithAlert(defaultName: AnyDuringMigration) { - promptName(Msg['NEW_VARIABLE_TITLE'], defaultName, function (text) { + promptName(Msg['NEW_VARIABLE_TITLE'], defaultName, function(text) { if (text) { const existing = nameUsedWithAnyType(text, workspace); if (existing) { @@ -287,9 +287,9 @@ export function createVariableButtonHandler( msg = Msg['VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE']; msg = msg.replace('%1', existing.name).replace('%2', existing.type); } - dialog.alert(msg, function () { + dialog.alert(msg, function() { promptAndCheckWithAlert( // Recurse - text); + text); }); } else // Recurse { @@ -322,23 +322,23 @@ export function createVariableButtonHandler( * @alias Blockly.Variables.renameVariable */ export function renameVariable( - workspace: Workspace, variable: VariableModel, - opt_callback?: (p1?: string | null) => AnyDuringMigration) { + workspace: Workspace, variable: VariableModel, + opt_callback?: (p1?: string|null) => AnyDuringMigration) { // This function needs to be named so it can be called recursively. function promptAndCheckWithAlert(defaultName: AnyDuringMigration) { const promptText = - Msg['RENAME_VARIABLE_TITLE'].replace('%1', variable.name); - promptName(promptText, defaultName, function (newName) { + Msg['RENAME_VARIABLE_TITLE'].replace('%1', variable.name); + promptName(promptText, defaultName, function(newName) { if (newName) { const existing = - nameUsedWithOtherType(newName, variable.type, workspace); + nameUsedWithOtherType(newName, variable.type, workspace); if (existing) { const msg = Msg['VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE'] - .replace('%1', existing.name) - .replace('%2', existing.type); - dialog.alert(msg, function () { + .replace('%1', existing.name) + .replace('%2', existing.type); + dialog.alert(msg, function() { promptAndCheckWithAlert( // Recurse - newName); + newName); }); } else // Recurse { @@ -367,9 +367,9 @@ export function renameVariable( * @alias Blockly.Variables.promptName */ export function promptName( - promptText: string, defaultText: string, - callback: (p1: string | null) => AnyDuringMigration) { - dialog.prompt(promptText, defaultText, function (newVar) { + promptText: string, defaultText: string, + callback: (p1: string|null) => AnyDuringMigration) { + dialog.prompt(promptText, defaultText, function(newVar) { // Merge runs of whitespace. Strip leading and trailing whitespace. // Beyond this, all names are legal. if (newVar) { @@ -392,7 +392,7 @@ export function promptName( * none was found. */ function nameUsedWithOtherType( - name: string, type: string, workspace: Workspace): VariableModel | null { + name: string, type: string, workspace: Workspace): VariableModel|null { const allVariables = workspace.getVariableMap().getAllVariables(); name = name.toLowerCase(); @@ -412,7 +412,7 @@ function nameUsedWithOtherType( * @alias Blockly.Variables.nameUsedWithAnyType */ export function nameUsedWithAnyType( - name: string, workspace: Workspace): VariableModel | null { + name: string, workspace: Workspace): VariableModel|null { const allVariables = workspace.getVariableMap().getAllVariables(); name = name.toLowerCase(); @@ -430,8 +430,8 @@ export function nameUsedWithAnyType( * @return The generated DOM. * @alias Blockly.Variables.generateVariableFieldDom */ -export function generateVariableFieldDom(variableModel: VariableModel): Element | - null { +export function generateVariableFieldDom(variableModel: VariableModel): Element| + null { /* Generates the following XML: * foo */ @@ -457,8 +457,8 @@ export function generateVariableFieldDom(variableModel: VariableModel): Element * @alias Blockly.Variables.getOrCreateVariablePackage */ export function getOrCreateVariablePackage( - workspace: Workspace, id: string | null, opt_name?: string, - opt_type?: string): VariableModel { + workspace: Workspace, id: string|null, opt_name?: string, + opt_type?: string): VariableModel { let variable = getVariable(workspace, id, opt_name, opt_type); if (!variable) { variable = createVariable(workspace, id, opt_name, opt_type); @@ -482,8 +482,8 @@ export function getOrCreateVariablePackage( * @alias Blockly.Variables.getVariable */ export function getVariable( - workspace: Workspace, id: string | null, opt_name?: string, - opt_type?: string): VariableModel | null { + workspace: Workspace, id: string|null, opt_name?: string, + opt_type?: string): VariableModel|null { const potentialVariableMap = workspace.getPotentialVariableMap(); let variable = null; // Try to just get the variable, by ID if possible. @@ -523,14 +523,14 @@ export function getVariable( * combination. */ function createVariable( - workspace: Workspace, id: string | null, opt_name?: string, - opt_type?: string): VariableModel { + workspace: Workspace, id: string|null, opt_name?: string, + opt_type?: string): VariableModel { const potentialVariableMap = workspace.getPotentialVariableMap(); // Variables without names get uniquely named for this workspace. if (!opt_name) { const ws = - (workspace.isFlyout ? (workspace as WorkspaceSvg).targetWorkspace : - workspace); + (workspace.isFlyout ? (workspace as WorkspaceSvg).targetWorkspace : + workspace); // Must call version on exports to allow for mocking in tests. See #5321 // AnyDuringMigration because: Argument of type 'Workspace | WorkspaceSvg' // is not assignable to parameter of type 'Workspace'. @@ -561,7 +561,7 @@ function createVariable( * @alias Blockly.Variables.getAddedVariables */ export function getAddedVariables( - workspace: Workspace, originalVariables: VariableModel[]): VariableModel[] { + workspace: Workspace, originalVariables: VariableModel[]): VariableModel[] { const allCurrentVariables = workspace.getAllVariables(); const addedVariables = []; if (originalVariables.length !== allCurrentVariables.length) { diff --git a/core/variables_dynamic.ts b/core/variables_dynamic.ts index f191ac34c..bf0ef7e93 100644 --- a/core/variables_dynamic.ts +++ b/core/variables_dynamic.ts @@ -13,15 +13,15 @@ * @namespace Blockly.VariablesDynamic */ -import { Blocks } from './blocks.js'; -import { Msg } from './msg.js'; +import {Blocks} from './blocks.js'; +import {Msg} from './msg.js'; import * as xml from './utils/xml.js'; -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -36,18 +36,18 @@ export const CATEGORY_NAME = 'VARIABLE_DYNAMIC'; function stringButtonClickHandler(button: AnyDuringMigration) { Variables.createVariableButtonHandler( - button.getTargetWorkspace(), undefined, 'String'); + button.getTargetWorkspace(), undefined, 'String'); } export const onCreateVariableButtonClick_String = stringButtonClickHandler; function numberButtonClickHandler(button: AnyDuringMigration) { Variables.createVariableButtonHandler( - button.getTargetWorkspace(), undefined, 'Number'); + button.getTargetWorkspace(), undefined, 'Number'); } export const onCreateVariableButtonClick_Number = numberButtonClickHandler; function colourButtonClickHandler(button: AnyDuringMigration) { Variables.createVariableButtonHandler( - button.getTargetWorkspace(), undefined, 'Colour'); + button.getTargetWorkspace(), undefined, 'Colour'); } export const onCreateVariableButtonClick_Colour = colourButtonClickHandler; @@ -59,7 +59,7 @@ export const onCreateVariableButtonClick_Colour = colourButtonClickHandler; * @alias Blockly.VariablesDynamic.flyoutCategory */ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { - let xmlList = new Array < Element > (); + let xmlList = new Array(); let button = document.createElement('button'); button.setAttribute('text', Msg['NEW_STRING_VARIABLE']); button.setAttribute('callbackKey', 'CREATE_VARIABLE_STRING'); @@ -74,11 +74,11 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { xmlList.push(button); workspace.registerButtonCallback( - 'CREATE_VARIABLE_STRING', stringButtonClickHandler); + 'CREATE_VARIABLE_STRING', stringButtonClickHandler); workspace.registerButtonCallback( - 'CREATE_VARIABLE_NUMBER', numberButtonClickHandler); + 'CREATE_VARIABLE_NUMBER', numberButtonClickHandler); workspace.registerButtonCallback( - 'CREATE_VARIABLE_COLOUR', colourButtonClickHandler); + 'CREATE_VARIABLE_COLOUR', colourButtonClickHandler); // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not @@ -109,8 +109,8 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { // AnyDuringMigration because: Argument of type 'Element | null' is not // assignable to parameter of type 'Node'. block.appendChild( - Variables.generateVariableFieldDom(firstVariable) as - AnyDuringMigration); + Variables.generateVariableFieldDom(firstVariable) as + AnyDuringMigration); xmlList.push(block); } if (Blocks['variables_get_dynamic']) { @@ -124,7 +124,7 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { // AnyDuringMigration because: Argument of type 'Element | null' is not // assignable to parameter of type 'Node'. block.appendChild( - Variables.generateVariableFieldDom(variable) as AnyDuringMigration); + Variables.generateVariableFieldDom(variable) as AnyDuringMigration); xmlList.push(block); } } diff --git a/core/warning.ts b/core/warning.ts index ad6d3f020..9fcb6e57e 100644 --- a/core/warning.ts +++ b/core/warning.ts @@ -16,14 +16,14 @@ import './events/events_bubble_open'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; -import { Bubble } from './bubble.js'; +import {BlockSvg} from './block_svg.js'; +import {Bubble} from './bubble.js'; import * as eventUtils from './events/utils.js'; -import { Icon } from './icon.js'; +import {Icon} from './icon.js'; /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; /** @@ -34,7 +34,7 @@ export class Warning extends Icon { text_: AnyDuringMigration; /** The top-level node of the warning text, or null if not created. */ - private paragraphElement_: SVGTextElement | null = null; + private paragraphElement_: SVGTextElement|null = null; /** Does this icon get hidden when the block is collapsed? */ override collapseHidden = false; @@ -55,29 +55,29 @@ export class Warning extends Icon { protected override drawIcon_(group: Element) { // Triangle with rounded corners. dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyIconShape', - 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z', - }, - group); + Svg.PATH, { + 'class': 'blocklyIconShape', + 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z', + }, + group); // Can't use a real '!' text character since different browsers and // operating systems render it differently. Body of exclamation point. dom.createSvgElement( - Svg.PATH, { - 'class': 'blocklyIconSymbol', - 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z', - }, - group); + Svg.PATH, { + 'class': 'blocklyIconSymbol', + 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z', + }, + group); // Dot of exclamation point. dom.createSvgElement( - Svg.RECT, { - 'class': 'blocklyIconSymbol', - 'x': '7', - 'y': '11', - 'height': '2', - 'width': '2', - }, - group); + Svg.RECT, { + 'class': 'blocklyIconSymbol', + 'x': '7', + 'y': '11', + 'height': '2', + 'width': '2', + }, + group); } /** @@ -91,7 +91,7 @@ export class Warning extends Icon { // AnyDuringMigration because: Property 'block_' does not exist on type // 'Warning'. eventUtils.fire(new (eventUtils.get(eventUtils.BUBBLE_OPEN))! - ((this as AnyDuringMigration).block_, visible, 'warning')); + ((this as AnyDuringMigration).block_, visible, 'warning')); if (visible) { this.createBubble_(); } else { @@ -105,8 +105,8 @@ export class Warning extends Icon { // AnyDuringMigration because: Property 'block_' does not exist on type // 'Warning'. this.bubble_ = Bubble.createNonEditableBubble( - this.paragraphElement_, (this as AnyDuringMigration).block_ as BlockSvg, - this.iconXY_ as Coordinate); + this.paragraphElement_, (this as AnyDuringMigration).block_ as BlockSvg, + this.iconXY_ as Coordinate); this.applyColour(); } diff --git a/core/widgetdiv.ts b/core/widgetdiv.ts index 41ef54d11..42f42b1c2 100644 --- a/core/widgetdiv.ts +++ b/core/widgetdiv.ts @@ -22,11 +22,11 @@ import * as common from './common.js'; import * as deprecation from './utils/deprecation.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Rect } from './utils/rect.js'; +import {Rect} from './utils/rect.js'; /* eslint-disable-next-line no-unused-vars */ -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** The object currently using this container. */ @@ -44,14 +44,14 @@ let rendererClassName = ''; let themeClassName = ''; /** The HTML container for popup overlays (e.g. editor widgets). */ -let containerDiv: HTMLDivElement | null; +let containerDiv: HTMLDivElement|null; /** * Returns the HTML container for editor widgets. * @return The editor widget container. * @alias Blockly.WidgetDiv.getDiv */ -export function getDiv(): HTMLDivElement | null { +export function getDiv(): HTMLDivElement|null { return containerDiv; } @@ -61,7 +61,7 @@ export function getDiv(): HTMLDivElement | null { * @alias Blockly.WidgetDiv.testOnly_setDiv * @ignore */ -export function testOnly_setDiv(newDiv: HTMLDivElement | null) { +export function testOnly_setDiv(newDiv: HTMLDivElement|null) { containerDiv = newDiv; } @@ -90,7 +90,7 @@ export function createDom() { * @alias Blockly.WidgetDiv.show */ export function show( - newOwner: AnyDuringMigration, rtl: boolean, newDispose: Function) { + newOwner: AnyDuringMigration, rtl: boolean, newDispose: Function) { hide(); owner = newOwner; dispose = newDispose; @@ -192,7 +192,7 @@ function positionInternal(x: number, y: number, height: number) { * @alias Blockly.WidgetDiv.positionWithAnchor */ export function positionWithAnchor( - viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size, rtl: boolean) { + viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size, rtl: boolean) { const y = calculateY(viewportBBox, anchorBBox, widgetSize); const x = calculateX(viewportBBox, anchorBBox, widgetSize, rtl); @@ -216,8 +216,8 @@ export function positionWithAnchor( * window coordinates. */ function calculateX( - viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size, - rtl: boolean): number { + viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size, + rtl: boolean): number { if (rtl) { // Try to align the right side of the field and the right side of widget. const widgetLeft = anchorBBox.right - widgetSize.width; @@ -246,7 +246,7 @@ function calculateX( * window coordinates. */ function calculateY( - viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size): number { + viewportBBox: Rect, anchorBBox: Rect, widgetSize: Size): number { // Flip the widget vertically if off the bottom. // The widget could go off the top of the window, but it would also go off // the bottom. The window is just too small. diff --git a/core/workspace.ts b/core/workspace.ts index f54497d8f..0507d8528 100644 --- a/core/workspace.ts +++ b/core/workspace.ts @@ -16,30 +16,30 @@ import './connection_checker'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; +import {BlocklyOptions} from './blockly_options.js'; /* eslint-disable-next-line no-unused-vars */ -import { ConnectionDB } from './connection_db.js'; +import {ConnectionDB} from './connection_db.js'; /* eslint-disable-next-line no-unused-vars */ -import { Abstract } from './events/events_abstract.js'; +import {Abstract} from './events/events_abstract.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocation } from './interfaces/i_ast_node_location.js'; +import {IASTNodeLocation} from './interfaces/i_ast_node_location.js'; /* eslint-disable-next-line no-unused-vars */ -import { IConnectionChecker } from './interfaces/i_connection_checker.js'; -import { Options } from './options.js'; +import {IConnectionChecker} from './interfaces/i_connection_checker.js'; +import {Options} from './options.js'; import * as registry from './registry.js'; import * as arrayUtils from './utils/array.js'; import * as idGenerator from './utils/idgenerator.js'; import * as math from './utils/math.js'; /* eslint-disable-next-line no-unused-vars */ import * as toolbox from './utils/toolbox.js'; -import { VariableMap } from './variable_map.js'; +import {VariableMap} from './variable_map.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from './workspace_comment.js'; +import {WorkspaceComment} from './workspace_comment.js'; /** Database of all workspaces. */ @@ -109,7 +109,7 @@ export class Workspace implements IASTNodeLocation { * these by tracking "potential" variables in the flyout. These variables * become real when references to them are dragged into the main workspace. */ - private potentialVariableMap_: VariableMap | null = null; + private potentialVariableMap_: VariableMap|null = null; /** @param opt_options Dictionary of options. */ constructor(opt_options?: Options) { @@ -121,7 +121,7 @@ export class Workspace implements IASTNodeLocation { this.toolboxPosition = this.options.toolboxPosition; const connectionCheckerClass = registry.getClassFromOptions( - registry.Type.CONNECTION_CHECKER, this.options, true); + registry.Type.CONNECTION_CHECKER, this.options, true); /** * An object that encapsulates logic for safety, type, and dragging checks. */ @@ -158,8 +158,8 @@ export class Workspace implements IASTNodeLocation { * @return The comparison value. This tells Array.sort() how to change object * a's index. */ - private sortObjects_(a: Block | WorkspaceComment, b: Block | WorkspaceComment): - number { + private sortObjects_(a: Block|WorkspaceComment, b: Block|WorkspaceComment): + number { // AnyDuringMigration because: Property 'getRelativeToSurfaceXY' does not // exist on type 'Block | WorkspaceComment'. const aXY = (a as AnyDuringMigration).getRelativeToSurfaceXY(); @@ -171,11 +171,11 @@ export class Workspace implements IASTNodeLocation { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => number'. return aXY.y + - (Workspace.prototype.sortObjects_ as AnyDuringMigration).offset * - aXY.x - - (bXY.y + (Workspace.prototype.sortObjects_ as AnyDuringMigration).offset * - bXY.x); + aXY.x - + (bXY.y + + (Workspace.prototype.sortObjects_ as AnyDuringMigration).offset * + bXY.x); } /** @@ -204,12 +204,12 @@ export class Workspace implements IASTNodeLocation { */ getTopBlocks(ordered: boolean): Block[] { // Copy the topBlocks_ list. - const blocks = (new Array < Block > ()).concat(this.topBlocks_); + const blocks = (new Array()).concat(this.topBlocks_); if (ordered && blocks.length > 1) { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => number'. (this.sortObjects_ as AnyDuringMigration).offset = - Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); + Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); if (this.RTL) { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => @@ -259,7 +259,7 @@ export class Workspace implements IASTNodeLocation { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => number'. (this.sortObjects_ as AnyDuringMigration).offset = - Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); + Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); if (this.RTL) { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => @@ -269,7 +269,7 @@ export class Workspace implements IASTNodeLocation { blocks.sort(this.sortObjects_); } - return blocks.filter(function (block: AnyDuringMigration) { + return blocks.filter(function(block: AnyDuringMigration) { return !block.isInsertionMarker(); }); } @@ -285,8 +285,8 @@ export class Workspace implements IASTNodeLocation { // need to move to a separate function. if (this.commentDB_[comment.id]) { console.warn( - 'Overriding an existing comment on this workspace, with id "' + - comment.id + '"'); + 'Overriding an existing comment on this workspace, with id "' + + comment.id + '"'); } this.commentDB_[comment.id] = comment; } @@ -298,8 +298,8 @@ export class Workspace implements IASTNodeLocation { removeTopComment(comment: WorkspaceComment) { if (!arrayUtils.removeElem(this.topComments_, comment)) { throw Error( - 'Comment not present in workspace\'s list of top-most ' + - 'comments.'); + 'Comment not present in workspace\'s list of top-most ' + + 'comments.'); } // Note: If the comment database starts to hold block comments, this may // need to move to a separate function. @@ -314,12 +314,12 @@ export class Workspace implements IASTNodeLocation { */ getTopComments(ordered: boolean): WorkspaceComment[] { // Copy the topComments_ list. - const comments = (new Array < WorkspaceComment > ()).concat(this.topComments_); + const comments = (new Array()).concat(this.topComments_); if (ordered && comments.length > 1) { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => number'. (this.sortObjects_ as AnyDuringMigration).offset = - Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); + Math.sin(math.toRadians(Workspace.SCAN_ANGLE)); if (this.RTL) { // AnyDuringMigration because: Property 'offset' does not exist on type // '(a: Block | WorkspaceComment, b: Block | WorkspaceComment) => @@ -356,7 +356,7 @@ export class Workspace implements IASTNodeLocation { // Insertion markers exist on the workspace for rendering reasons, but // aren't "real" blocks from a developer perspective. - const filtered = blocks.filter(function (block) { + const filtered = blocks.filter(function(block) { return !block.isInsertionMarker(); }); @@ -410,8 +410,8 @@ export class Workspace implements IASTNodeLocation { * @param opt_id The unique ID of the variable. This will default to a UUID. * @return The newly created variable. */ - createVariable(name: string, opt_type?: string | null, opt_id?: string | null): - VariableModel { + createVariable(name: string, opt_type?: string|null, opt_id?: string|null): + VariableModel { return this.variableMap_.createVariable(name, opt_type, opt_id); } @@ -441,7 +441,7 @@ export class Workspace implements IASTNodeLocation { * the empty string, which is a specific type. * @return The variable with the given name. */ - getVariable(name: string, opt_type?: string): VariableModel | null { + getVariable(name: string, opt_type?: string): VariableModel|null { // TODO (#1559): Possibly delete this function after resolving #1559. return this.variableMap_.getVariable(name, opt_type); } @@ -451,7 +451,7 @@ export class Workspace implements IASTNodeLocation { * @param id The ID to check for. * @return The variable with the given ID. */ - getVariableById(id: string): VariableModel | null { + getVariableById(id: string): VariableModel|null { return this.variableMap_.getVariableById(id); } @@ -462,7 +462,7 @@ export class Workspace implements IASTNodeLocation { * @return The sought after variables of the passed in type. An empty array if * none are found. */ - getVariablesOfType(type: string | null): VariableModel[] { + getVariablesOfType(type: string|null): VariableModel[] { return this.variableMap_.getVariablesOfType(type); } @@ -537,8 +537,8 @@ export class Workspace implements IASTNodeLocation { } const maxInstanceOfType = this.options.maxInstances[type] !== undefined ? - this.options.maxInstances[type] : - Infinity; + this.options.maxInstances[type] : + Infinity; return maxInstanceOfType - this.getBlocksByType(type, false).length; } @@ -608,7 +608,7 @@ export class Workspace implements IASTNodeLocation { let events = [inputEvent]; // Do another undo/redo if the next one is of the same group. while (inputStack.length && inputEvent.group && - inputEvent.group === inputStack[inputStack.length - 1].group) { + inputEvent.group === inputStack[inputStack.length - 1].group) { // AnyDuringMigration because: Argument of type 'Abstract | undefined' is // not assignable to parameter of type 'Abstract'. events.push(inputStack.pop() as AnyDuringMigration); @@ -682,7 +682,7 @@ export class Workspace implements IASTNodeLocation { * @param id ID of block to find. * @return The sought after block, or null if not found. */ - getBlockById(id: string): Block | null { + getBlockById(id: string): Block|null { return this.blockDB_[id] || null; } @@ -708,7 +708,7 @@ export class Workspace implements IASTNodeLocation { * @param id ID of comment to find. * @return The sought after comment, or null if not found. */ - getCommentById(id: string): WorkspaceComment | null { + getCommentById(id: string): WorkspaceComment|null { return this.commentDB_[id] || null; } @@ -735,7 +735,7 @@ export class Workspace implements IASTNodeLocation { * These exist in the flyout but not in the workspace. * @return The potential variable map. */ - getPotentialVariableMap(): VariableMap | null { + getPotentialVariableMap(): VariableMap|null { return this.potentialVariableMap_; } @@ -765,7 +765,7 @@ export class Workspace implements IASTNodeLocation { * @param id ID of workspace to find. * @return The sought after workspace or null if not found. */ - static getById(id: string): Workspace | null { + static getById(id: string): Workspace|null { return WorkspaceDB_[id] || null; } diff --git a/core/workspace_audio.ts b/core/workspace_audio.ts index f4e07d269..2f55dfe30 100644 --- a/core/workspace_audio.ts +++ b/core/workspace_audio.ts @@ -18,7 +18,7 @@ import * as userAgent from './utils/useragent.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -102,9 +102,9 @@ export class WorkspaceAudio { // was interrupted) See more: // https://developers.google.com/web/updates/2017/06/play-request-was-interrupted playPromise.then(sound.pause) - .catch( - // Play without user interaction was prevented. - function () {}); + .catch( + // Play without user interaction was prevented. + function() {}); } else { sound.pause(); } @@ -130,7 +130,7 @@ export class WorkspaceAudio { // Don't play one sound on top of another. const now = new Date(); if (this.lastSound_ !== null && - now.getTime() - this.lastSound_.getTime() < SOUND_LIMIT) { + now.getTime() - this.lastSound_.getTime() < SOUND_LIMIT) { return; } this.lastSound_ = now; diff --git a/core/workspace_comment.ts b/core/workspace_comment.ts index 981179770..521ddb309 100644 --- a/core/workspace_comment.ts +++ b/core/workspace_comment.ts @@ -20,13 +20,13 @@ import './events/events_comment_create'; import './events/events_comment_delete'; /* eslint-disable-next-line no-unused-vars */ -import { CommentMove } from './events/events_comment_move.js'; +import {CommentMove} from './events/events_comment_move.js'; import * as eventUtils from './events/utils.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as idGenerator from './utils/idgenerator.js'; import * as xml from './utils/xml.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; +import {Workspace} from './workspace.js'; /** @@ -60,11 +60,11 @@ export class WorkspaceComment { * ID. */ constructor( - public workspace: Workspace, content: string, height: number, - width: number, opt_id?: string) { + public workspace: Workspace, content: string, height: number, + width: number, opt_id?: string) { this.id = opt_id && !workspace.getCommentById(opt_id) ? - opt_id : - idGenerator.genUid(); + opt_id : + idGenerator.genUid(); workspace.addTopComment(this); @@ -158,7 +158,7 @@ export class WorkspaceComment { */ moveBy(dx: number, dy: number) { const event = - new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove; + new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove; this.xy_.translate(dx, dy); event.recordNew(); eventUtils.fire(event); @@ -170,7 +170,7 @@ export class WorkspaceComment { */ isDeletable(): boolean { return this.deletable_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -187,7 +187,7 @@ export class WorkspaceComment { */ isMovable(): boolean { return this.movable_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -204,7 +204,7 @@ export class WorkspaceComment { */ isEditable(): boolean { return this.editable_ && - !(this.workspace && this.workspace.options.readOnly); + !(this.workspace && this.workspace.options.readOnly); } /** @@ -230,7 +230,7 @@ export class WorkspaceComment { setContent(content: string) { if (this.content_ !== content) { eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CHANGE))! - (this, this.content_, content)); + (this, this.content_, content)); this.content_ = content; } } @@ -286,7 +286,7 @@ export class WorkspaceComment { } try { eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CREATE))! - (comment)); + (comment)); } finally { if (!existingGroup) { eventUtils.setGroup(false); @@ -305,16 +305,16 @@ export class WorkspaceComment { const info = WorkspaceComment.parseAttributes(xmlComment); const comment = - new WorkspaceComment(workspace, info.content, info.h, info.w, info.id); + 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); + 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); + parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10); if (!isNaN(commentX) && !isNaN(commentY)) { comment.moveBy(commentX, commentY); } @@ -344,30 +344,30 @@ export class WorkspaceComment { // 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, + 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 + 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, + 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 + xml.getAttribute('x') as AnyDuringMigration, + 10), // 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} + xml.getAttribute('y') as AnyDuringMigration, 10), // @type {string} // AnyDuringMigration because: Type 'string | null' is not assignable to // type 'string'. content: xml.textContent as AnyDuringMigration, diff --git a/core/workspace_comment_svg.ts b/core/workspace_comment_svg.ts index cb3713c95..f00d2210f 100644 --- a/core/workspace_comment_svg.ts +++ b/core/workspace_comment_svg.ts @@ -19,28 +19,28 @@ import './events/events_comment_delete'; import './events/events_selected'; /* eslint-disable-next-line no-unused-vars */ -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; import * as browserEvents from './browser_events.js'; import * as common from './common.js'; import * as ContextMenu from './contextmenu.js'; import * as Css from './css.js'; /* eslint-disable-next-line no-unused-vars */ -import { CommentMove } from './events/events_comment_move.js'; +import {CommentMove} from './events/events_comment_move.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBoundedElement } from './interfaces/i_bounded_element.js'; +import {IBoundedElement} from './interfaces/i_bounded_element.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBubble } from './interfaces/i_bubble.js'; -import { CopyData, ICopyable } from './interfaces/i_copyable.js'; +import {IBubble} from './interfaces/i_bubble.js'; +import {CopyData, ICopyable} from './interfaces/i_copyable.js'; import * as Touch from './touch.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Rect } from './utils/rect.js'; -import { Svg } from './utils/svg.js'; +import {Rect} from './utils/rect.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; -import { WorkspaceComment } from './workspace_comment.js'; +import {WorkspaceComment} from './workspace_comment.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** Size of the resize icon. */ @@ -57,7 +57,7 @@ const TEXTAREA_OFFSET = 2; * @alias Blockly.WorkspaceCommentSvg */ export class WorkspaceCommentSvg extends WorkspaceComment implements - IBoundedElement, IBubble, ICopyable { + IBoundedElement, IBubble, ICopyable { /** * The width and height to use to size a workspace comment when it is first * added, before it has been edited by the user. @@ -69,26 +69,26 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements override workspace: WorkspaceSvg; /** Mouse up event data. */ - private onMouseUpWrapper_: browserEvents.Data | null = null; + private onMouseUpWrapper_: browserEvents.Data|null = null; /** Mouse move event data. */ - private onMouseMoveWrapper_: browserEvents.Data | null = null; + private onMouseMoveWrapper_: browserEvents.Data|null = null; /** Whether event handlers have been initialized. */ private eventsInit_ = false; - private textarea_: HTMLTextAreaElement | null = null; + private textarea_: HTMLTextAreaElement|null = null; - private svgRectTarget_: SVGRectElement | null = null; + private svgRectTarget_: SVGRectElement|null = null; - private svgHandleTarget_: SVGRectElement | null = null; + private svgHandleTarget_: SVGRectElement|null = null; - private foreignObject_: SVGForeignObjectElement | null = null; + private foreignObject_: SVGForeignObjectElement|null = null; - private resizeGroup_: SVGGElement | null = null; + private resizeGroup_: SVGGElement|null = null; - private deleteGroup_: SVGGElement | null = null; + private deleteGroup_: SVGGElement|null = null; - private deleteIconBorder_: SVGCircleElement | null = null; + private deleteIconBorder_: SVGCircleElement|null = null; private focused_ = false; private autoLayout_ = false; @@ -109,10 +109,10 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements * ID. */ constructor( - workspace: WorkspaceSvg, content: string, height: number, width: number, - opt_id?: string) { + workspace: WorkspaceSvg, content: string, height: number, width: number, + opt_id?: string) { super(workspace, content, height, width, opt_id); - this.svgGroup_ = dom.createSvgElement(Svg.G, { 'class': 'blocklyComment' }); + this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyComment'}); (this.svgGroup_ as AnyDuringMigration).translate_ = ''; this.workspace = workspace; @@ -130,7 +130,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements * True if it should move, false if it should be translated directly. */ this.useDragSurface_ = - svgMath.is3dSupported() && !!workspace.getBlockDragSurface(); + svgMath.is3dSupported() && !!workspace.getBlockDragSurface(); this.render(); } @@ -171,11 +171,11 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements } if (!this.workspace.options.readOnly && !this.eventsInit_) { browserEvents.conditionalBind( - this.svgRectTarget_ as SVGRectElement, 'mousedown', this, - this.pathMouseDown_); + this.svgRectTarget_ as SVGRectElement, 'mousedown', this, + this.pathMouseDown_); browserEvents.conditionalBind( - this.svgHandleTarget_ as SVGRectElement, 'mousedown', this, - this.pathMouseDown_); + this.svgHandleTarget_ as SVGRectElement, 'mousedown', this, + this.pathMouseDown_); } this.eventsInit_ = true; @@ -237,7 +237,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements } } const event = new (eventUtils.get(eventUtils.SELECTED))! - (oldId, this.id, this.workspace.id); + (oldId, this.id, this.workspace.id); eventUtils.fire(event); common.setSelected(this); this.addSelect(); @@ -249,7 +249,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements return; } const event = new (eventUtils.get(eventUtils.SELECTED))! - (this.id, null, this.workspace.id); + (this.id, null, this.workspace.id); eventUtils.fire(event); common.setSelected(null); this.removeSelect(); @@ -291,8 +291,8 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements let y = 0; const dragSurfaceGroup = this.useDragSurface_ ? - this.workspace.getBlockDragSurface()!.getGroup() : - null; + this.workspace.getBlockDragSurface()!.getGroup() : + null; let element = this.getSvgRoot(); if (element) { @@ -304,10 +304,10 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements // If this element is the current element on the drag surface, include // the translation of the drag surface itself. if (this.useDragSurface_ && - this.workspace.getBlockDragSurface()!.getCurrentBlock() === - element) { + this.workspace.getBlockDragSurface()!.getCurrentBlock() === + element) { const surfaceTranslation = - this.workspace.getBlockDragSurface()!.getSurfaceTranslation(); + this.workspace.getBlockDragSurface()!.getSurfaceTranslation(); x += surfaceTranslation.x; y += surfaceTranslation.y; } @@ -315,7 +315,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements // assignable to type 'SVGElement'. element = element.parentNode as AnyDuringMigration; } while (element && element !== this.workspace.getBubbleCanvas() && - element !== dragSurfaceGroup); + element !== dragSurfaceGroup); } this.xy_ = new Coordinate(x, y); return this.xy_; @@ -328,7 +328,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements */ override moveBy(dx: number, dy: number) { const event = - new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove; + new (eventUtils.get(eventUtils.COMMENT_MOVE))!(this) as CommentMove; // TODO: Do I need to look up the relative to surface XY position here? const xy = this.getRelativeToSurfaceXY(); this.translate(xy.x + dx, xy.y + dy); @@ -347,7 +347,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements translate(x: number, y: number) { this.xy_ = new Coordinate(x, y); this.getSvgRoot().setAttribute( - 'transform', 'translate(' + x + ',' + y + ')'); + 'transform', 'translate(' + x + ',' + y + ')'); } /** @@ -382,12 +382,12 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements dragSurface.translateSurface(newLoc.x, newLoc.y); } else { (this.svgGroup_ as AnyDuringMigration).translate_ = - 'translate(' + newLoc.x + ',' + newLoc.y + ')'; + 'translate(' + newLoc.x + ',' + newLoc.y + ')'; (this.svgGroup_ as AnyDuringMigration) - .setAttribute( - 'transform', - (this.svgGroup_ as AnyDuringMigration).translate_ + - (this.svgGroup_ as AnyDuringMigration).skew_); + .setAttribute( + 'transform', + (this.svgGroup_ as AnyDuringMigration).translate_ + + (this.svgGroup_ as AnyDuringMigration).skew_); } } @@ -545,9 +545,9 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. element.setAttribute( - 'x', - Math.round(this.workspace.RTL ? width - xy.x : xy.x) as - AnyDuringMigration); + 'x', + Math.round(this.workspace.RTL ? width - xy.x : xy.x) as + AnyDuringMigration); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. element.setAttribute('y', Math.round(xy.y) as AnyDuringMigration); @@ -576,8 +576,8 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements * Returns a bounding box describing the dimensions of this comment. * @return Object with height and width properties in workspace units. */ - getHeightWidth(): { height: number, width: number } { - return { width: this.getWidth(), height: this.getHeight() }; + getHeightWidth(): {height: number, width: number} { + return {width: this.getWidth(), height: this.getHeight()}; } /** Renders the workspace comment. */ @@ -595,7 +595,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements this.svgGroup_.appendChild(this.foreignObject_ as AnyDuringMigration); this.svgHandleTarget_ = dom.createSvgElement( - Svg.RECT, { 'class': 'blocklyCommentHandleTarget', 'x': 0, 'y': 0 }); + Svg.RECT, {'class': 'blocklyCommentHandleTarget', 'x': 0, 'y': 0}); // AnyDuringMigration because: Argument of type 'SVGRectElement | null' is // not assignable to parameter of type 'Node'. this.svgGroup_.appendChild(this.svgHandleTarget_ as AnyDuringMigration); @@ -626,19 +626,19 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements if (this.resizeGroup_) { browserEvents.conditionalBind( - (this.resizeGroup_), 'mousedown', this, this.resizeMouseDown_); + (this.resizeGroup_), 'mousedown', this, this.resizeMouseDown_); } if (this.isDeletable()) { browserEvents.conditionalBind( - this.deleteGroup_ as SVGGElement, 'mousedown', this, - this.deleteMouseDown_); + this.deleteGroup_ as SVGGElement, 'mousedown', this, + this.deleteMouseDown_); browserEvents.conditionalBind( - this.deleteGroup_ as SVGGElement, 'mouseout', this, - this.deleteMouseOut_); + this.deleteGroup_ as SVGGElement, 'mouseout', this, + this.deleteMouseOut_); browserEvents.conditionalBind( - this.deleteGroup_ as SVGGElement, 'mouseup', this, - this.deleteMouseUp_); + this.deleteGroup_ as SVGGElement, 'mouseup', this, + this.deleteMouseUp_); } } @@ -665,7 +665,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; const textarea = document.createElementNS(dom.HTML_NS, 'textarea') as - HTMLTextAreaElement; + HTMLTextAreaElement; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); textarea.readOnly = !this.isEditable(); @@ -674,18 +674,18 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements this.foreignObject_!.appendChild(body); // Don't zoom with mousewheel. browserEvents.conditionalBind( - textarea, 'wheel', this, function (e: AnyDuringMigration) { - e.stopPropagation(); - }); + textarea, 'wheel', this, function(e: AnyDuringMigration) { + e.stopPropagation(); + }); browserEvents.conditionalBind( - textarea, 'change', this, - /** @param e Unused event parameter */ - /* eslint-enable no-unused-vars */ - function ( - this: WorkspaceCommentSvg, + textarea, 'change', this, + /** @param e Unused event parameter */ + /* eslint-enable no-unused-vars */ + function( + this: WorkspaceCommentSvg, /* eslint-disable no-unused-vars */ e: Event) { - this.setContent(textarea.value); - }); + this.setContent(textarea.value); + }); // AnyDuringMigration because: Type 'SVGForeignObjectElement | null' is not // assignable to type 'Element'. return this.foreignObject_ as AnyDuringMigration; @@ -694,73 +694,73 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements /** Add the resize icon to the DOM */ private addResizeDom_() { this.resizeGroup_ = dom.createSvgElement( - Svg.G, { 'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE' }, - this.svgGroup_); + Svg.G, {'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE'}, + this.svgGroup_); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.POLYGON, - { 'points': '0,x x,x x,0'.replace(/x/g, RESIZE_SIZE.toString()) }, - this.resizeGroup_ as AnyDuringMigration); + Svg.POLYGON, + {'points': '0,x x,x x,0'.replace(/x/g, RESIZE_SIZE.toString())}, + this.resizeGroup_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.LINE, { - 'class': 'blocklyResizeLine', - 'x1': RESIZE_SIZE / 3, - 'y1': RESIZE_SIZE - 1, - 'x2': RESIZE_SIZE - 1, - 'y2': RESIZE_SIZE / 3, - }, - this.resizeGroup_ as AnyDuringMigration); + Svg.LINE, { + 'class': 'blocklyResizeLine', + 'x1': RESIZE_SIZE / 3, + 'y1': RESIZE_SIZE - 1, + 'x2': RESIZE_SIZE - 1, + 'y2': RESIZE_SIZE / 3, + }, + this.resizeGroup_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.LINE, { - 'class': 'blocklyResizeLine', - 'x1': RESIZE_SIZE * 2 / 3, - 'y1': RESIZE_SIZE - 1, - 'x2': RESIZE_SIZE - 1, - 'y2': RESIZE_SIZE * 2 / 3, - }, - this.resizeGroup_ as AnyDuringMigration); + Svg.LINE, { + 'class': 'blocklyResizeLine', + 'x1': RESIZE_SIZE * 2 / 3, + 'y1': RESIZE_SIZE - 1, + 'x2': RESIZE_SIZE - 1, + 'y2': RESIZE_SIZE * 2 / 3, + }, + this.resizeGroup_ as AnyDuringMigration); } /** Add the delete icon to the DOM */ private addDeleteDom_() { this.deleteGroup_ = dom.createSvgElement( - Svg.G, { 'class': 'blocklyCommentDeleteIcon' }, this.svgGroup_); + Svg.G, {'class': 'blocklyCommentDeleteIcon'}, this.svgGroup_); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. this.deleteIconBorder_ = dom.createSvgElement( - Svg.CIRCLE, - { 'class': 'blocklyDeleteIconShape', 'r': '7', 'cx': '7.5', 'cy': '7.5' }, - this.deleteGroup_ as AnyDuringMigration); + Svg.CIRCLE, + {'class': 'blocklyDeleteIconShape', 'r': '7', 'cx': '7.5', 'cy': '7.5'}, + this.deleteGroup_ as AnyDuringMigration); // x icon. // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.LINE, { - 'x1': '5', - 'y1': '10', - 'x2': '10', - 'y2': '5', - 'stroke': '#fff', - 'stroke-width': '2', - }, - this.deleteGroup_ as AnyDuringMigration); + Svg.LINE, { + 'x1': '5', + 'y1': '10', + 'x2': '10', + 'y2': '5', + 'stroke': '#fff', + 'stroke-width': '2', + }, + this.deleteGroup_ as AnyDuringMigration); // AnyDuringMigration because: Argument of type 'SVGGElement | null' is not // assignable to parameter of type 'Element | undefined'. dom.createSvgElement( - Svg.LINE, { - 'x1': '5', - 'y1': '5', - 'x2': '10', - 'y2': '10', - 'stroke': '#fff', - 'stroke-width': '2', - }, - this.deleteGroup_ as AnyDuringMigration); + Svg.LINE, { + 'x1': '5', + 'y1': '5', + 'x2': '10', + 'y2': '10', + 'stroke': '#fff', + 'stroke-width': '2', + }, + this.deleteGroup_ as AnyDuringMigration); } /** @@ -776,14 +776,14 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements } // Left-click (or middle click) this.workspace.startDrag( - e, - new Coordinate( - this.workspace.RTL ? -this.width_ : this.width_, this.height_)); + e, + new Coordinate( + this.workspace.RTL ? -this.width_ : this.width_, this.height_)); this.onMouseUpWrapper_ = browserEvents.conditionalBind( - document, 'mouseup', this, this.resizeMouseUp_); + document, 'mouseup', this, this.resizeMouseUp_); this.onMouseMoveWrapper_ = browserEvents.conditionalBind( - document, 'mousemove', this, this.resizeMouseMove_); + document, 'mousemove', this, this.resizeMouseMove_); this.workspace.hideChaff(); // This event has been handled. No need to bubble up to the document. e.stopPropagation(); @@ -796,7 +796,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements private deleteMouseDown_(e: Event) { // Highlight the delete icon. dom.addClass( - this.deleteIconBorder_ as Element, 'blocklyDeleteIconHighlighted'); + this.deleteIconBorder_ as Element, 'blocklyDeleteIconHighlighted'); // This event has been handled. No need to bubble up to the document. e.stopPropagation(); } @@ -808,7 +808,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements private deleteMouseOut_(_e: Event) { // Restore highlight on the delete icon. dom.removeClass( - this.deleteIconBorder_ as Element, 'blocklyDeleteIconHighlighted'); + this.deleteIconBorder_ as Element, 'blocklyDeleteIconHighlighted'); } /** @@ -865,9 +865,9 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.foreignObject_!.setAttribute( - 'width', size.width as AnyDuringMigration); + 'width', size.width as AnyDuringMigration); this.foreignObject_!.setAttribute( - 'height', (size.height - topOffset).toString()); + 'height', (size.height - topOffset).toString()); if (this.RTL) { this.foreignObject_!.setAttribute('x', (-size.width).toString()); } @@ -900,7 +900,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.svgHandleTarget_!.setAttribute( - 'height', WorkspaceCommentSvg.TOP_OFFSET as AnyDuringMigration); + 'height', WorkspaceCommentSvg.TOP_OFFSET as AnyDuringMigration); if (this.RTL) { this.svgRect_.setAttribute('transform', 'scale(-1 1)'); this.svgRectTarget_!.setAttribute('transform', 'scale(-1 1)'); @@ -910,21 +910,21 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements if (this.RTL) { // Mirror the resize group. this.resizeGroup_.setAttribute( - 'transform', - 'translate(' + (-width + RESIZE_SIZE) + ',' + - (height - RESIZE_SIZE) + ') scale(-1 1)'); + 'transform', + 'translate(' + (-width + RESIZE_SIZE) + ',' + + (height - RESIZE_SIZE) + ') scale(-1 1)'); this.deleteGroup_!.setAttribute( - 'transform', - 'translate(' + (-width + RESIZE_SIZE) + ',' + -RESIZE_SIZE + - ') scale(-1 1)'); + 'transform', + 'translate(' + (-width + RESIZE_SIZE) + ',' + -RESIZE_SIZE + + ') scale(-1 1)'); } else { this.resizeGroup_.setAttribute( - 'transform', - 'translate(' + (width - RESIZE_SIZE) + ',' + - (height - RESIZE_SIZE) + ')'); + 'transform', + 'translate(' + (width - RESIZE_SIZE) + ',' + + (height - RESIZE_SIZE) + ')'); this.deleteGroup_!.setAttribute( - 'transform', - 'translate(' + (width - RESIZE_SIZE) + ',' + -RESIZE_SIZE + ')'); + 'transform', + 'translate(' + (width - RESIZE_SIZE) + ',' + -RESIZE_SIZE + ')'); } } @@ -946,18 +946,18 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements const comment = this; this.focused_ = true; // Defer CSS changes. - setTimeout(function () { + setTimeout(function() { if (comment.disposed_) { return; } comment.textarea_!.focus(); comment.addFocus(); dom.addClass( - comment.svgRectTarget_ as SVGRectElement, - 'blocklyCommentTargetFocused'); + comment.svgRectTarget_ as SVGRectElement, + 'blocklyCommentTargetFocused'); dom.addClass( - comment.svgHandleTarget_ as SVGRectElement, - 'blocklyCommentHandleTargetFocused'); + comment.svgHandleTarget_ as SVGRectElement, + 'blocklyCommentHandleTargetFocused'); }, 0); } @@ -966,7 +966,7 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements const comment = this; this.focused_ = false; // Defer CSS changes. - setTimeout(function () { + setTimeout(function() { if (comment.disposed_) { return; } @@ -974,11 +974,11 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements comment.textarea_!.blur(); comment.removeFocus(); dom.removeClass( - comment.svgRectTarget_ as SVGRectElement, - 'blocklyCommentTargetFocused'); + comment.svgRectTarget_ as SVGRectElement, + 'blocklyCommentTargetFocused'); dom.removeClass( - comment.svgHandleTarget_ as SVGRectElement, - 'blocklyCommentHandleTargetFocused'); + comment.svgHandleTarget_ as SVGRectElement, + 'blocklyCommentHandleTargetFocused'); }, 0); } @@ -991,15 +991,15 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements * @return The created workspace comment. */ static fromXmlRendered( - xmlComment: Element, workspace: WorkspaceSvg, - opt_wsWidth?: number): WorkspaceCommentSvg { + xmlComment: Element, workspace: WorkspaceSvg, + opt_wsWidth?: number): WorkspaceCommentSvg { eventUtils.disable(); let comment; try { const info = WorkspaceComment.parseAttributes(xmlComment); comment = new WorkspaceCommentSvg( - workspace, info.content, info.h, info.w, info.id); + workspace, info.content, info.h, info.w, info.id); if (workspace.rendered) { comment.initSvg(true); comment.render(); diff --git a/core/workspace_drag_surface_svg.ts b/core/workspace_drag_surface_svg.ts index 2b6db405e..b5485fbbe 100644 --- a/core/workspace_drag_surface_svg.ts +++ b/core/workspace_drag_surface_svg.ts @@ -22,9 +22,9 @@ */ /* eslint-disable-next-line no-unused-vars */ -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; -import { Svg } from './utils/svg.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; @@ -94,7 +94,7 @@ export class WorkspaceDragSurfaceSvg { this.SVG_.style.display = 'block'; dom.setCssTransform( - this.SVG_, 'translate3d(' + fixedX + 'px, ' + fixedY + 'px, 0)'); + this.SVG_, 'translate3d(' + fixedX + 'px, ' + fixedY + 'px, 0)'); } /** @@ -114,15 +114,15 @@ export class WorkspaceDragSurfaceSvg { clearAndHide(newSurface: SVGElement) { if (!newSurface) { throw Error( - 'Couldn\'t clear and hide the drag surface: missing new surface.'); + 'Couldn\'t clear and hide the drag surface: missing new surface.'); } const blockCanvas = this.SVG_.childNodes[0] as Element; const bubbleCanvas = this.SVG_.childNodes[1] as Element; if (!blockCanvas || !bubbleCanvas || - !dom.hasClass(blockCanvas, 'blocklyBlockCanvas') || - !dom.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { + !dom.hasClass(blockCanvas, 'blocklyBlockCanvas') || + !dom.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { throw Error( - 'Couldn\'t clear and hide the drag surface. A node was missing.'); + 'Couldn\'t clear and hide the drag surface. A node was missing.'); } // If there is a previous sibling, put the blockCanvas back right @@ -161,17 +161,17 @@ export class WorkspaceDragSurfaceSvg { * @param scale The scale of the workspace being dragged. */ setContentsAndShow( - blockCanvas: SVGElement, bubbleCanvas: SVGElement, - previousSibling: Element, width: number, height: number, scale: number) { + blockCanvas: SVGElement, bubbleCanvas: SVGElement, + previousSibling: Element, width: number, height: number, scale: number) { if (this.SVG_.childNodes.length) { throw Error('Already dragging a block.'); } this.previousSibling_ = previousSibling; // Make sure the blocks and bubble canvas are scaled appropriately. blockCanvas.setAttribute( - 'transform', 'translate(0, 0) scale(' + scale + ')'); + 'transform', 'translate(0, 0) scale(' + scale + ')'); bubbleCanvas.setAttribute( - 'transform', 'translate(0, 0) scale(' + scale + ')'); + 'transform', 'translate(0, 0) scale(' + scale + ')'); // AnyDuringMigration because: Argument of type 'number' is not assignable // to parameter of type 'string'. this.SVG_.setAttribute('width', width as AnyDuringMigration); diff --git a/core/workspace_dragger.ts b/core/workspace_dragger.ts index d0b6ed548..8b3d377da 100644 --- a/core/workspace_dragger.ts +++ b/core/workspace_dragger.ts @@ -13,9 +13,9 @@ */ import * as common from './common.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** diff --git a/core/workspace_svg.ts b/core/workspace_svg.ts index f1d48a0ba..1463ad0e1 100644 --- a/core/workspace_svg.ts +++ b/core/workspace_svg.ts @@ -39,88 +39,88 @@ import './metrics_manager'; import './msg'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockDragSurfaceSvg } from './block_drag_surface.js'; -import { BlockSvg } from './block_svg.js'; +import {BlockDragSurfaceSvg} from './block_drag_surface.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlocklyOptions } from './blockly_options.js'; +import {BlocklyOptions} from './blockly_options.js'; import * as browserEvents from './browser_events.js'; import * as common from './common.js'; -import { ComponentManager } from './component_manager.js'; -import { config } from './config.js'; -import { ConnectionDB } from './connection_db.js'; +import {ComponentManager} from './component_manager.js'; +import {config} from './config.js'; +import {ConnectionDB} from './connection_db.js'; import * as ContextMenu from './contextmenu.js'; -import { ContextMenuRegistry } from './contextmenu_registry.js'; +import {ContextMenuRegistry} from './contextmenu_registry.js'; import * as dropDownDiv from './dropdowndiv.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { FlyoutButton } from './flyout_button.js'; -import { Gesture } from './gesture.js'; -import { Grid } from './grid.js'; +import {FlyoutButton} from './flyout_button.js'; +import {Gesture} from './gesture.js'; +import {Grid} from './grid.js'; /* eslint-disable-next-line no-unused-vars */ -import { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js'; +import {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { IBoundedElement } from './interfaces/i_bounded_element.js'; +import {IBoundedElement} from './interfaces/i_bounded_element.js'; /* eslint-disable-next-line no-unused-vars */ -import { ICopyable } from './interfaces/i_copyable.js'; +import {ICopyable} from './interfaces/i_copyable.js'; /* eslint-disable-next-line no-unused-vars */ -import { IDragTarget } from './interfaces/i_drag_target.js'; +import {IDragTarget} from './interfaces/i_drag_target.js'; /* eslint-disable-next-line no-unused-vars */ -import { IFlyout } from './interfaces/i_flyout.js'; +import {IFlyout} from './interfaces/i_flyout.js'; /* eslint-disable-next-line no-unused-vars */ -import { IMetricsManager } from './interfaces/i_metrics_manager.js'; +import {IMetricsManager} from './interfaces/i_metrics_manager.js'; /* eslint-disable-next-line no-unused-vars */ -import { IToolbox } from './interfaces/i_toolbox.js'; +import {IToolbox} from './interfaces/i_toolbox.js'; /* eslint-disable-next-line no-unused-vars */ -import { Cursor } from './keyboard_nav/cursor.js'; +import {Cursor} from './keyboard_nav/cursor.js'; /* eslint-disable-next-line no-unused-vars */ -import { Marker } from './keyboard_nav/marker.js'; -import { MarkerManager } from './marker_manager.js'; -import { Options } from './options.js'; +import {Marker} from './keyboard_nav/marker.js'; +import {MarkerManager} from './marker_manager.js'; +import {Options} from './options.js'; import * as Procedures from './procedures.js'; import * as registry from './registry.js'; import * as blockRendering from './renderers/common/block_rendering.js'; /* eslint-disable-next-line no-unused-vars */ -import { Renderer } from './renderers/common/renderer.js'; +import {Renderer} from './renderers/common/renderer.js'; /* eslint-disable-next-line no-unused-vars */ -import { ScrollbarPair } from './scrollbar_pair.js'; +import {ScrollbarPair} from './scrollbar_pair.js'; import * as blocks from './serialization/blocks.js'; /* eslint-disable-next-line no-unused-vars */ -import { Theme } from './theme.js'; -import { Classic } from './theme/classic.js'; -import { ThemeManager } from './theme_manager.js'; +import {Theme} from './theme.js'; +import {Classic} from './theme/classic.js'; +import {ThemeManager} from './theme_manager.js'; import * as Tooltip from './tooltip.js'; -import { TouchGesture } from './touch_gesture.js'; +import {TouchGesture} from './touch_gesture.js'; /* eslint-disable-next-line no-unused-vars */ -import { Trashcan } from './trashcan.js'; +import {Trashcan} from './trashcan.js'; import * as utils from './utils.js'; import * as arrayUtils from './utils/array.js'; -import { Coordinate } from './utils/coordinate.js'; +import {Coordinate} from './utils/coordinate.js'; import * as dom from './utils/dom.js'; /* eslint-disable-next-line no-unused-vars */ -import { Metrics } from './utils/metrics.js'; -import { Rect } from './utils/rect.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Metrics} from './utils/metrics.js'; +import {Rect} from './utils/rect.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; import * as svgMath from './utils/svg_math.js'; import * as toolbox from './utils/toolbox.js'; import * as userAgent from './utils/useragent.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; import * as VariablesDynamic from './variables_dynamic.js'; import * as WidgetDiv from './widgetdiv.js'; -import { Workspace } from './workspace.js'; -import { WorkspaceAudio } from './workspace_audio.js'; +import {Workspace} from './workspace.js'; +import {WorkspaceAudio} from './workspace_audio.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceComment } from './workspace_comment.js'; +import {WorkspaceComment} from './workspace_comment.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceDragSurfaceSvg } from './workspace_drag_surface_svg.js'; +import {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js'; import * as Xml from './xml.js'; -import { ZoomControls } from './zoom_controls.js'; +import {ZoomControls} from './zoom_controls.js'; /** Margin around the top/bottom/left/right after a zoomToFit call. */ @@ -136,7 +136,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * A wrapper function called when a resize event occurs. * You can pass the result to `eventHandling.unbind`. */ - private resizeHandlerWrapper_: browserEvents.Data | null = null; + private resizeHandlerWrapper_: browserEvents.Data|null = null; /** * The render status of an SVG workspace. @@ -278,13 +278,13 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Type 'null' is not assignable to type // 'BlockDragSurfaceSvg'. private readonly blockDragSurface_: BlockDragSurfaceSvg = - null as AnyDuringMigration; + null as AnyDuringMigration; /** This workspace's drag surface, if it exists. */ // AnyDuringMigration because: Type 'null' is not assignable to type // 'WorkspaceDragSurfaceSvg'. private readonly workspaceDragSurface_: WorkspaceDragSurfaceSvg = - null as AnyDuringMigration; + null as AnyDuringMigration; /** * Whether to move workspace to the drag surface when it is dragged. @@ -335,13 +335,13 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { targetWorkspace: WorkspaceSvg = null as AnyDuringMigration; /** Inverted screen CTM, for use in mouseToSvg. */ - private inverseScreenCTM_: SVGMatrix | null = null; + private inverseScreenCTM_: SVGMatrix|null = null; /** Inverted screen CTM is dirty, recalculate it. */ private inverseScreenCTMDirty_ = true; private metricsManager_: IMetricsManager; getMetrics: () => Metrics; - setMetrics: (p1: { x: number, y: number }) => void; + setMetrics: (p1: {x: number, y: number}) => void; private readonly componentManager_: ComponentManager; /** @@ -353,9 +353,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { private grid_: Grid; private markerManager_: MarkerManager; private toolboxCategoryCallbacks_: - { [key: string]: ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition) | null }; + {[key: string]: ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null}; private flyoutButtonCallbacks_: - { [key: string]: ((p1: FlyoutButton) => AnyDuringMigration) | null }; + {[key: string]: ((p1: FlyoutButton) => AnyDuringMigration)|null}; protected themeManager_: ThemeManager; private readonly renderer_: Renderer; @@ -371,8 +371,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { private topBoundedElements_: IBoundedElement[] = []; /** The recorded drag targets. */ - private dragTargetAreas_: Array<{ component: IDragTarget, clientRect: Rect }> = - []; + private dragTargetAreas_: Array<{component: IDragTarget, clientRect: Rect}> = + []; private readonly cachedParentSvgSize_: Size; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. svgGroup_!: SVGElement; @@ -390,22 +390,22 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param opt_wsDragSurface Drag surface for the workspace. */ constructor( - options: Options, opt_blockDragSurface?: BlockDragSurfaceSvg, - opt_wsDragSurface?: WorkspaceDragSurfaceSvg) { + options: Options, opt_blockDragSurface?: BlockDragSurfaceSvg, + opt_wsDragSurface?: WorkspaceDragSurfaceSvg) { super(options); const MetricsManagerClass = registry.getClassFromOptions( - registry.Type.METRICS_MANAGER, options, true); + registry.Type.METRICS_MANAGER, options, true); /** Object in charge of calculating metrics for the workspace. */ this.metricsManager_ = new MetricsManagerClass!(this); /** Method to get all the metrics that have to do with a workspace. */ this.getMetrics = options.getMetrics || - this.metricsManager_.getMetrics.bind(this.metricsManager_); + this.metricsManager_.getMetrics.bind(this.metricsManager_); /** Translates the workspace. */ this.setMetrics = - options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_; + options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_; this.componentManager_ = new ComponentManager(); @@ -420,20 +420,20 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { } this.useWorkspaceDragSurface_ = - !!this.workspaceDragSurface_ && svgMath.is3dSupported(); + !!this.workspaceDragSurface_ && svgMath.is3dSupported(); /** * Object in charge of loading, storing, and playing audio for a workspace. */ this.audioManager_ = - new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg)); + new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg)); /** This workspace's grid object or null. */ // AnyDuringMigration because: Type 'Grid | null' is not assignable to type // 'Grid'. this.grid_ = (this.options.gridPattern ? - new Grid(this.options.gridPattern, options.gridOptions) : - null) as AnyDuringMigration; + new Grid(this.options.gridPattern, options.gridOptions) : + null) as AnyDuringMigration; /** Manager in charge of markers and cursors. */ this.markerManager_ = new MarkerManager(this); @@ -452,32 +452,32 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { if (Variables && Variables.flyoutCategory) { this.registerToolboxCategoryCallback( - Variables.CATEGORY_NAME, Variables.flyoutCategory); + Variables.CATEGORY_NAME, Variables.flyoutCategory); } if (VariablesDynamic && VariablesDynamic.flyoutCategory) { this.registerToolboxCategoryCallback( - VariablesDynamic.CATEGORY_NAME, VariablesDynamic.flyoutCategory); + VariablesDynamic.CATEGORY_NAME, VariablesDynamic.flyoutCategory); } if (Procedures && Procedures.flyoutCategory) { this.registerToolboxCategoryCallback( - Procedures.CATEGORY_NAME, Procedures.flyoutCategory); + Procedures.CATEGORY_NAME, Procedures.flyoutCategory); this.addChangeListener(Procedures.mutatorOpenListener); } /** Object in charge of storing and updating the workspace theme. */ this.themeManager_ = this.options.parentWorkspace ? - this.options.parentWorkspace.getThemeManager() : - new ThemeManager(this, this.options.theme || Classic); + this.options.parentWorkspace.getThemeManager() : + new ThemeManager(this, this.options.theme || Classic); // AnyDuringMigration because: Argument of type 'this' is not assignable to // parameter of type 'Workspace'. this.themeManager_.subscribeWorkspace(this as AnyDuringMigration); /** The block renderer used for rendering blocks on this workspace. */ this.renderer_ = blockRendering.init( - this.options.renderer || 'geras', this.getTheme(), - this.options.rendererOverrides); + this.options.renderer || 'geras', this.getTheme(), + this.options.rendererOverrides); /** * The cached size of the parent svg element. @@ -509,7 +509,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { setMetricsManager(metricsManager: IMetricsManager) { this.metricsManager_ = metricsManager; this.getMetrics = - this.metricsManager_.getMetrics.bind(this.metricsManager_); + this.metricsManager_.getMetrics.bind(this.metricsManager_); } /** @@ -544,7 +544,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @return The marker with the given ID or null if no marker with the given ID * exists. */ - getMarker(id: string): Marker | null { + getMarker(id: string): Marker|null { if (this.markerManager_) { return this.markerManager_.getMarker(id); } @@ -555,7 +555,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * The cursor for this workspace. * @return The cursor for the workspace. */ - getCursor(): Cursor | null { + getCursor(): Cursor|null { if (this.markerManager_) { return this.markerManager_.getCursor(); } @@ -607,7 +607,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // 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(); }) as AnyDuringMigration); @@ -623,7 +623,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { } const event = new (eventUtils.get(eventUtils.THEME_CHANGE))! - (this.getTheme().name, this.id); + (this.getTheme().name, this.id); eventUtils.fire(event); } @@ -648,7 +648,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * Getter for the inverted screen CTM. * @return The matrix to use in mouseToSvg */ - getInverseScreenCTM(): SVGMatrix | null { + getInverseScreenCTM(): SVGMatrix|null { // Defer getting the screen CTM until we actually need it, this should // avoid forced reflows from any calls to updateInverseScreenCTM. if (this.inverseScreenCTMDirty_) { @@ -688,7 +688,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { let y = 0; let scale = 1; if (dom.containsNode(this.getCanvas(), element) || - dom.containsNode(this.getBubbleCanvas(), element)) { + dom.containsNode(this.getBubbleCanvas(), element)) { // Before the SVG canvas, scale the coordinates. scale = this.scale; } @@ -754,7 +754,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * Get the SVG block canvas for the workspace. * @return The SVG group for the workspace. */ - getBlockCanvas(): SVGElement | null { + getBlockCanvas(): SVGElement|null { return this.svgBlockCanvas_; } @@ -781,46 +781,46 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * * */ - this.svgGroup_ = dom.createSvgElement(Svg.G, { 'class': 'blocklyWorkspace' }); + this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'}); // Note that a alone does not receive mouse events--it must have a // valid target inside it. If no background class is specified, as in the // flyout, the workspace will not receive mouse events. if (opt_backgroundClass) { this.svgBackground_ = dom.createSvgElement( - Svg.RECT, - { 'height': '100%', 'width': '100%', 'class': opt_backgroundClass }, - this.svgGroup_); + Svg.RECT, + {'height': '100%', 'width': '100%', 'class': opt_backgroundClass}, + this.svgGroup_); if (opt_backgroundClass === 'blocklyMainBackground' && this.grid_) { this.svgBackground_.style.fill = - 'url(#' + this.grid_.getPatternId() + ')'; + 'url(#' + this.grid_.getPatternId() + ')'; } else { this.themeManager_.subscribe( - this.svgBackground_, 'workspaceBackgroundColour', 'fill'); + this.svgBackground_, 'workspaceBackgroundColour', 'fill'); } } this.svgBlockCanvas_ = dom.createSvgElement( - Svg.G, { 'class': 'blocklyBlockCanvas' }, this.svgGroup_); + Svg.G, {'class': 'blocklyBlockCanvas'}, this.svgGroup_); this.svgBubbleCanvas_ = dom.createSvgElement( - Svg.G, { 'class': 'blocklyBubbleCanvas' }, this.svgGroup_); + Svg.G, {'class': 'blocklyBubbleCanvas'}, this.svgGroup_); if (!this.isFlyout) { browserEvents.conditionalBind( - this.svgGroup_, 'mousedown', this, this.onMouseDown_, false, true); + this.svgGroup_, 'mousedown', this, this.onMouseDown_, false, true); // This no-op works around https://bugs.webkit.org/show_bug.cgi?id=226683, // which otherwise prevents zoom/scroll events from being observed in // Safari. Once that bug is fixed it should be removed. - document.body.addEventListener('wheel', function () {}); + document.body.addEventListener('wheel', function() {}); browserEvents.conditionalBind( - this.svgGroup_, 'wheel', this, this.onMouseWheel_); + this.svgGroup_, 'wheel', this, this.onMouseWheel_); } // Determine if there needs to be a category tree, or a simple list of // blocks. This cannot be changed later, since the UI is very different. if (this.options.hasCategories) { const ToolboxClass = registry.getClassFromOptions( - registry.Type.TOOLBOX, this.options, true); + registry.Type.TOOLBOX, this.options, true); this.toolbox_ = new ToolboxClass!(this); } if (this.grid_) { @@ -828,7 +828,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { } this.recordDragTargets(); const CursorClass = - registry.getClassFromOptions(registry.Type.CURSOR, this.options); + registry.getClassFromOptions(registry.Type.CURSOR, this.options); CursorClass && this.markerManager_.setCursor(new CursorClass()); @@ -969,7 +969,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param tagName What type of tag the flyout belongs in. * @return The element containing the flyout DOM. */ - addFlyout(tagName: string | Svg | Svg): Element { + addFlyout(tagName: string|Svg|Svg): Element { const workspaceOptions = new Options(({ 'parentWorkspace': this, 'rtl': this.RTL, @@ -984,11 +984,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { workspaceOptions.toolboxPosition = this.options.toolboxPosition; if (this.horizontalLayout) { const HorizontalFlyout = registry.getClassFromOptions( - registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.options, true); + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.options, true); this.flyout_ = new HorizontalFlyout!(workspaceOptions); } else { const VerticalFlyout = registry.getClassFromOptions( - registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.options, true); + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.options, true); this.flyout_ = new VerticalFlyout!(workspaceOptions); } this.flyout_.autoClose = false; @@ -1007,7 +1007,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param opt_own Whether to only return the workspace's own flyout. * @return The flyout on this workspace. */ - getFlyout(opt_own?: boolean): IFlyout | null { + getFlyout(opt_own?: boolean): IFlyout|null { if (this.flyout_ || opt_own) { return this.flyout_; } @@ -1021,7 +1021,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * Getter for the toolbox associated with this workspace, if one exists. * @return The toolbox on this workspace. */ - getToolbox(): IToolbox | null { + getToolbox(): IToolbox|null { return this.toolbox_; } @@ -1065,7 +1065,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { } const positionables = this.componentManager_.getComponents( - ComponentManager.Capability.POSITIONABLE, true); + ComponentManager.Capability.POSITIONABLE, true); const metrics = this.getMetricsManager().getUiMetrics(); const savedPositions = []; for (let i = 0, positionable; positionable = positionables[i]; i++) { @@ -1110,7 +1110,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param width The width of the parent SVG element. * @param height The height of the parent SVG element */ - setCachedParentSvgSize(width: number | null, height: number | null) { + setCachedParentSvgSize(width: number|null, height: number|null) { const svg = this.getParentSvg(); if (width != null) { this.cachedParentSvgSize_.width = width; @@ -1170,13 +1170,13 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { const top = -this.scrollY; const left = -this.scrollX; if (scale === this.oldScale_ && Math.abs(top - this.oldTop_) < 1 && - Math.abs(left - this.oldLeft_) < 1) { + Math.abs(left - this.oldLeft_) < 1) { // Ignore sub-pixel changes in top and left. Due to #4192 there are a lot // of negligible changes in viewport top/left. return; } const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))! - (top, left, scale, this.id, this.oldScale_); + (top, left, scale, this.id, this.oldScale_); this.oldScale_ = scale; this.oldTop_ = top; this.oldLeft_ = left; @@ -1195,7 +1195,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { this.workspaceDragSurface_.translateSurface(x, y); } else { const translation = 'translate(' + x + ',' + y + ') ' + - 'scale(' + this.scale + ')'; + 'scale(' + this.scale + ')'; this.svgBlockCanvas_.setAttribute('transform', translation); this.svgBubbleCanvas_.setAttribute('transform', translation); } @@ -1227,7 +1227,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { const trans = this.workspaceDragSurface_.getSurfaceTranslation(); this.workspaceDragSurface_.clearAndHide(this.svgGroup_); const translation = 'translate(' + trans.x + ',' + trans.y + ') ' + - 'scale(' + this.scale + ')'; + 'scale(' + this.scale + ')'; this.svgBlockCanvas_.setAttribute('transform', translation); this.svgBubbleCanvas_.setAttribute('transform', translation); } @@ -1260,15 +1260,15 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. const width = parseInt( - this.getParentSvg().getAttribute('width') as AnyDuringMigration, 10); + this.getParentSvg().getAttribute('width') as AnyDuringMigration, 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); + this.getParentSvg().getAttribute('height') as AnyDuringMigration, 10); const coord = svgMath.getRelativeXY(this.getCanvas()); this.workspaceDragSurface_.setContentsAndShow( - this.getCanvas(), this.getBubbleCanvas(), previousElement, width, - height, this.scale); + this.getCanvas(), this.getBubbleCanvas(), previousElement, width, + height, this.scale); this.workspaceDragSurface_.translateSurface(coord.x, coord.y); } @@ -1276,7 +1276,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * Gets the drag surface blocks are moved to when a drag is started. * @return This workspace's block drag surface, if one is in use. */ - getBlockDragSurface(): BlockDragSurfaceSvg | null { + getBlockDragSurface(): BlockDragSurfaceSvg|null { return this.blockDragSurface_; } @@ -1362,7 +1362,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * unhighlight all others. If true or false, manually * highlight/unhighlight the specified block. */ - highlightBlock(id: string | null, opt_state?: boolean) { + highlightBlock(id: string|null, opt_state?: boolean) { if (opt_state === undefined) { // Unhighlight all blocks. for (let i = 0, block; block = this.highlightedBlocks_[i]; i++) { @@ -1391,7 +1391,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param state The representation of the thing to paste. * @return The pasted thing, or null if the paste was not successful. */ - paste(state: AnyDuringMigration | Element | DocumentFragment): ICopyable | null { + paste(state: AnyDuringMigration|Element|DocumentFragment): ICopyable|null { if (!this.rendered || !state['type'] && !state['tagName']) { return null; } @@ -1428,8 +1428,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param jsonBlock JSON block representation. * @return The pasted block. */ - private pasteBlock_(xmlBlock: Element | null, jsonBlock: blocks.State | null): - BlockSvg { + private pasteBlock_(xmlBlock: Element|null, jsonBlock: blocks.State|null): + BlockSvg { eventUtils.disable(); let block: BlockSvg; try { @@ -1439,7 +1439,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Argument of type 'this' is not // assignable to parameter of type 'Workspace'. block = - Xml.domToBlock(xmlBlock, this as AnyDuringMigration) as BlockSvg; + 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); @@ -1453,7 +1453,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Argument of type 'this' is not // assignable to parameter of type 'Workspace'. block = - blocks.append(jsonBlock, this as AnyDuringMigration) as BlockSvg; + blocks.append(jsonBlock, this as AnyDuringMigration) as BlockSvg; blockX = jsonBlock['x'] || 10; if (this.RTL) { blockX = this.getWidth() - blockX; @@ -1472,7 +1472,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { for (let i = 0, otherBlock; otherBlock = allBlocks[i]; i++) { const otherXY = otherBlock.getRelativeToSurfaceXY(); if (Math.abs(blockX - otherXY.x) <= 1 && - Math.abs(blockY - otherXY.y) <= 1) { + Math.abs(blockY - otherXY.y) <= 1) { collide = true; break; } @@ -1482,9 +1482,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { const connections = block!.getConnections_(false); for (let i = 0, connection; connection = connections[i]; i++) { const neighbour = - (connection) - .closest( - config.snapRadius, new Coordinate(blockX, blockY)); + (connection) + .closest( + config.snapRadius, new Coordinate(blockX, blockY)); if (neighbour.connection) { collide = true; break; @@ -1530,11 +1530,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. let commentX = - parseInt(xmlComment.getAttribute('x') as AnyDuringMigration, 10); + 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); + parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10); if (!isNaN(commentX) && !isNaN(commentY)) { if (this.RTL) { commentX = -commentX; @@ -1598,8 +1598,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @return The newly created variable. */ override createVariable( - name: string, opt_type?: string | null, - opt_id?: string | null): VariableModel { + name: string, opt_type?: string|null, + opt_id?: string|null): VariableModel { const newVar = super.createVariable(name, opt_type, opt_id); this.refreshToolboxSelection(); return newVar; @@ -1613,16 +1613,16 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Property 'warn' does not exist on type // 'void'. (utils.deprecation as AnyDuringMigration) - .warn( - 'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021', - 'June 2022', 'WorkspaceSvg.prototype.recordDragTargets'); + .warn( + 'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021', + 'June 2022', 'WorkspaceSvg.prototype.recordDragTargets'); this.recordDragTargets(); } /** Make a list of all the delete areas for this workspace. */ recordDragTargets() { const dragTargets = this.componentManager_.getComponents( - ComponentManager.Capability.DRAG_TARGET, true); + ComponentManager.Capability.DRAG_TARGET, true); this.dragTargetAreas_ = []; for (let i = 0, targetArea; targetArea = dragTargets[i]; i++) { @@ -1654,14 +1654,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @return Null if not over a drag target, or the drag target the event is * over. */ - getDragTarget(e: Event): IDragTarget | null { + getDragTarget(e: Event): IDragTarget|null { 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( - (e as AnyDuringMigration).clientX, - (e as AnyDuringMigration).clientY)) { + (e as AnyDuringMigration).clientX, + (e as AnyDuringMigration).clientY)) { return targetArea.component; } } @@ -1687,7 +1687,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { startDrag(e: Event, xy: Coordinate) { // Record the starting offset between the bubble's location and the mouse. const point = browserEvents.mouseToSvg( - e, this.getParentSvg(), this.getInverseScreenCTM()); + e, this.getParentSvg(), this.getInverseScreenCTM()); // Fix scale of mouse event. point.x /= this.scale; point.y /= this.scale; @@ -1701,7 +1701,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { */ moveDrag(e: Event): Coordinate { const point = browserEvents.mouseToSvg( - e, this.getParentSvg(), this.getInverseScreenCTM()); + e, this.getParentSvg(), this.getInverseScreenCTM()); // Fix scale of mouse event. point.x /= this.scale; point.y /= this.scale; @@ -1736,10 +1736,10 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { */ isMovable(): boolean { return this.options.moveOptions && !!this.options.moveOptions.scrollbars || - this.options.moveOptions && this.options.moveOptions.wheel || - this.options.moveOptions && this.options.moveOptions.drag || - this.options.zoomOptions && this.options.zoomOptions.wheel || - this.options.zoomOptions && this.options.zoomOptions.pinch; + this.options.moveOptions && this.options.moveOptions.wheel || + this.options.moveOptions && this.options.moveOptions.drag || + this.options.zoomOptions && this.options.zoomOptions.wheel || + this.options.zoomOptions && this.options.zoomOptions.pinch; } /** @@ -1749,8 +1749,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { isMovableHorizontally(): boolean { const hasScrollbars = !!this.scrollbar; return this.isMovable() && - (!hasScrollbars || - hasScrollbars && this.scrollbar.canScrollHorizontally()); + (!hasScrollbars || + hasScrollbars && this.scrollbar.canScrollHorizontally()); } /** @@ -1760,8 +1760,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { isMovableVertically(): boolean { const hasScrollbars = !!this.scrollbar; return this.isMovable() && - (!hasScrollbars || - hasScrollbars && this.scrollbar.canScrollVertically()); + (!hasScrollbars || + hasScrollbars && this.scrollbar.canScrollVertically()); } /** @@ -1776,9 +1776,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { return; } const canWheelZoom = - this.options.zoomOptions && this.options.zoomOptions.wheel; + this.options.zoomOptions && this.options.zoomOptions.wheel; const canWheelMove = - this.options.moveOptions && this.options.moveOptions.wheel; + this.options.moveOptions && this.options.moveOptions.wheel; if (!canWheelZoom && !canWheelMove) { return; } @@ -1799,7 +1799,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { const PIXELS_PER_ZOOM_STEP = 50; const delta = -scrollDelta.y / PIXELS_PER_ZOOM_STEP; const position = browserEvents.mouseToSvg( - e, this.getParentSvg(), this.getInverseScreenCTM()); + e, this.getParentSvg(), this.getInverseScreenCTM()); this.zoom(position.x, position.y, delta); } else { // Scroll. @@ -1873,8 +1873,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { block.moveBy(-xy.x, cursorY - xy.y); block.snapToGrid(); cursorY = block.getRelativeToSurfaceXY().y + - block.getHeightWidth().height + - this.renderer_.getConstants().MIN_BLOCK_HEIGHT; + block.getHeightWidth().height + + this.renderer_.getConstants().MIN_BLOCK_HEIGHT; } eventUtils.setGroup(false); this.setResizesEnabled(true); @@ -1891,8 +1891,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Argument of type '{ workspace: this; }' is // not assignable to parameter of type 'Scope'. const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions( - ContextMenuRegistry.ScopeType.WORKSPACE, - { workspace: this } as AnyDuringMigration); + ContextMenuRegistry.ScopeType.WORKSPACE, + {workspace: this} as AnyDuringMigration); // Allow the developer to add or modify menuOptions. if (this.configureContextMenu) { @@ -1907,7 +1907,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param toolboxDef DOM tree of toolbox contents, string of toolbox contents, * or JSON representing toolbox definition. */ - updateToolbox(toolboxDef: toolbox.ToolboxDefinition | null) { + updateToolbox(toolboxDef: toolbox.ToolboxDefinition|null) { const parsedToolboxDef = toolbox.convertToolboxDefToJson(toolboxDef); if (!parsedToolboxDef) { @@ -1962,14 +1962,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // AnyDuringMigration because: Property 'blur' does not exist on type // 'Element'. if (document.activeElement && - (document.activeElement as AnyDuringMigration).blur) { + (document.activeElement as AnyDuringMigration).blur) { // AnyDuringMigration because: Property 'blur' does not exist on type // 'Element'. (document.activeElement as AnyDuringMigration).blur(); } try { // Focus the workspace SVG - this is for Chrome and Firefox. - this.getParentSvg().focus({ preventScroll: true }); + this.getParentSvg().focus({preventScroll: true}); } catch (e) { // IE and Edge do not support focus on SVG elements. When that fails // above, get the injectionDiv (the workspace's parent) and focus that @@ -1981,7 +1981,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { } catch (e) { // setActive support was discontinued in Edge so when that fails, call // focus instead. - this.getParentSvg().parentElement!.focus({ preventScroll: true }); + this.getParentSvg().parentElement!.focus({preventScroll: true}); } } } @@ -2030,7 +2030,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // position (relative to the center) after we zoom. // newScale and matrix.a should be identical (within a rounding error). matrix = matrix!.translate(x * (1 - scaleChange), y * (1 - scaleChange)) - .scale(scaleChange); + .scale(scaleChange); // scrollX and scrollY are in pixels. // The scrollX and scrollY still need to have absoluteLeft and absoluteTop // subtracted from them, but we'll leave that for setScale so that they're @@ -2067,8 +2067,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { zoomToFit() { if (!this.isMovable()) { console.warn( - 'Tried to move a non-movable workspace. This could result' + - ' in blocks becoming inaccessible.'); + 'Tried to move a non-movable workspace. This could result' + + ' in blocks becoming inaccessible.'); return; } @@ -2131,8 +2131,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { scrollCenter() { if (!this.isMovable()) { console.warn( - 'Tried to move a non-movable workspace. This could result' + - ' in blocks becoming inaccessible.'); + 'Tried to move a non-movable workspace. This could result' + + ' in blocks becoming inaccessible.'); return; } @@ -2151,11 +2151,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * blocks stacked below it, the workspace will be centered on the stack. * @param id ID of block center on. */ - centerOnBlock(id: string | null) { + centerOnBlock(id: string|null) { if (!this.isMovable()) { console.warn( - 'Tried to move a non-movable workspace. This could result' + - ' in blocks becoming inaccessible.'); + 'Tried to move a non-movable workspace. This could result' + + ' in blocks becoming inaccessible.'); return; } @@ -2208,11 +2208,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { */ setScale(newScale: number) { if (this.options.zoomOptions.maxScale && - newScale > this.options.zoomOptions.maxScale) { + newScale > this.options.zoomOptions.maxScale) { newScale = this.options.zoomOptions.maxScale; } else if ( - this.options.zoomOptions.minScale && - newScale < this.options.zoomOptions.minScale) { + this.options.zoomOptions.minScale && + newScale < this.options.zoomOptions.minScale) { newScale = this.options.zoomOptions.minScale; } this.scale = newScale; @@ -2271,7 +2271,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { */ scroll(x: number, y: number) { this.hideChaff(/* opt_onlyClosePopups= */ - true); + true); // Keep scrolling within the bounds of the content. const metrics = this.getMetrics(); @@ -2280,10 +2280,10 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { x = Math.min(x, -metrics.scrollLeft); y = Math.min(y, -metrics.scrollTop); const maxXDisplacement = - Math.max(0, metrics.scrollWidth - metrics.viewWidth); + Math.max(0, metrics.scrollWidth - metrics.viewWidth); const maxXScroll = metrics.scrollLeft + maxXDisplacement; const maxYDisplacement = - Math.max(0, metrics.scrollHeight - metrics.viewHeight); + Math.max(0, metrics.scrollHeight - metrics.viewHeight); const maxYScroll = metrics.scrollTop + maxYDisplacement; x = Math.max(x, -maxXScroll); y = Math.max(y, -maxYScroll); @@ -2298,7 +2298,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // the content's top-left to the view's top-left, matching the // directionality of the scrollbars. this.scrollbar.set( - -(x + metrics.scrollLeft), -(y + metrics.scrollTop), false); + -(x + metrics.scrollLeft), -(y + metrics.scrollTop), false); } // We have to shift the translation so that when the canvas is at 0, 0 the // workspace origin is not underneath the toolbox. @@ -2312,7 +2312,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param id ID of block to find. * @return The sought after block, or null if not found. */ - override getBlockById(id: string): BlockSvg | null { + override getBlockById(id: string): BlockSvg|null { return super.getBlockById(id) as BlockSvg; } @@ -2393,7 +2393,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @return The top-level bounded elements. */ getTopBoundedElements(): IBoundedElement[] { - return (new Array < IBoundedElement > ()).concat(this.topBoundedElements_); + return (new Array()).concat(this.topBoundedElements_); } /** @@ -2434,7 +2434,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param func The function to call when the given button is clicked. */ registerButtonCallback( - key: string, func: (p1: FlyoutButton) => AnyDuringMigration) { + key: string, func: (p1: FlyoutButton) => AnyDuringMigration) { if (typeof func !== 'function') { throw TypeError('Button callbacks must be functions.'); } @@ -2449,7 +2449,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * null if no callback is registered. */ getButtonCallback(key: string): - ((p1: FlyoutButton) => AnyDuringMigration) | null { + ((p1: FlyoutButton) => AnyDuringMigration)|null { const result = this.flyoutButtonCallbacks_[key]; return result ? result : null; } @@ -2470,7 +2470,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @param func The function to call when the given toolbox category is opened. */ registerToolboxCategoryCallback( - key: string, func: (p1: WorkspaceSvg) => toolbox.FlyoutDefinition) { + key: string, func: (p1: WorkspaceSvg) => toolbox.FlyoutDefinition) { if (typeof func !== 'function') { throw TypeError('Toolbox category callbacks must be functions.'); } @@ -2485,7 +2485,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * null if no function is registered. */ getToolboxCategoryCallback(key: string): - ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition) | null { + ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null { return this.toolboxCategoryCallbacks_[key] || null; } @@ -2504,9 +2504,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * @return The gesture that is tracking this touch stream, or null if no valid * gesture exists. */ - getGesture(e: Event): TouchGesture | null { + getGesture(e: Event): TouchGesture|null { const isStart = e.type === 'mousedown' || e.type === 'touchstart' || - e.type === 'pointerdown'; + e.type === 'pointerdown'; const gesture = this.currentGesture_; if (gesture) { @@ -2556,7 +2556,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * Get the grid object for this workspace, or null if there is none. * @return The grid object for this workspace. */ - getGrid(): Grid | null { + getGrid(): Grid|null { return this.grid_; } @@ -2571,9 +2571,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { const onlyClosePopups = !!opt_onlyClosePopups; const autoHideables = this.getComponentManager().getComponents( - ComponentManager.Capability.AUTOHIDEABLE, true); + ComponentManager.Capability.AUTOHIDEABLE, true); autoHideables.forEach( - (autoHideable) => autoHideable.autoHide(onlyClosePopups)); + (autoHideable) => autoHideable.autoHide(onlyClosePopups)); } /** @@ -2582,18 +2582,18 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { * and 1 specifying the degree of scrolling. */ private static setTopLevelWorkspaceMetrics_( - this: WorkspaceSvg, xyRatio: AnyDuringMigration) { + this: WorkspaceSvg, xyRatio: AnyDuringMigration) { const metrics = this.getMetrics(); if (typeof xyRatio.x === 'number') { this.scrollX = - -(metrics.scrollLeft + - (metrics.scrollWidth - metrics.viewWidth) * xyRatio.x); + -(metrics.scrollLeft + + (metrics.scrollWidth - metrics.viewWidth) * xyRatio.x); } if (typeof xyRatio.y === 'number') { this.scrollY = - -(metrics.scrollTop + - (metrics.scrollHeight - metrics.viewHeight) * xyRatio.y); + -(metrics.scrollTop + + (metrics.scrollHeight - metrics.viewHeight) * xyRatio.y); } // We have to shift the translation so that when the canvas is at 0, 0 the // workspace origin is not underneath the toolbox. diff --git a/core/xml.ts b/core/xml.ts index 01baa12da..0bcce77a0 100644 --- a/core/xml.ts +++ b/core/xml.ts @@ -22,27 +22,27 @@ import './workspace_comment'; import './workspace_comment_svg'; /* eslint-disable-next-line no-unused-vars */ -import { Block } from './block.js'; +import {Block} from './block.js'; /* eslint-disable-next-line no-unused-vars */ -import { BlockSvg } from './block_svg.js'; +import {BlockSvg} from './block_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { Connection } from './connection.js'; +import {Connection} from './connection.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { Field } from './field.js'; -import { inputTypes } from './input_types.js'; +import {Field} from './field.js'; +import {inputTypes} from './input_types.js'; import * as dom from './utils/dom.js'; -import { Size } from './utils/size.js'; +import {Size} from './utils/size.js'; import * as utilsXml from './utils/xml.js'; /* eslint-disable-next-line no-unused-vars */ -import { VariableModel } from './variable_model.js'; +import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; /* eslint-disable-next-line no-unused-vars */ -import { Workspace } from './workspace.js'; -import { WorkspaceComment } from './workspace_comment.js'; -import { WorkspaceCommentSvg } from './workspace_comment_svg.js'; +import {Workspace} from './workspace.js'; +import {WorkspaceComment} from './workspace_comment.js'; +import {WorkspaceCommentSvg} from './workspace_comment_svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -53,10 +53,10 @@ import { WorkspaceSvg } from './workspace_svg.js'; * @alias Blockly.Xml.workspaceToDom */ export function workspaceToDom( - workspace: Workspace, opt_noId?: boolean): Element { + workspace: Workspace, opt_noId?: boolean): Element { const treeXml = utilsXml.createElement('xml'); - const variablesElement = variablesToDom( - Variables.allUsedVarModels(workspace)); + const variablesElement = + variablesToDom(Variables.allUsedVarModels(workspace)); if (variablesElement.hasChildNodes()) { treeXml.appendChild(variablesElement); } @@ -102,8 +102,8 @@ export function variablesToDom(variableList: VariableModel[]): Element { * an insertion marker. * @alias Blockly.Xml.blockToDomWithXY */ -export function blockToDomWithXY(block: Block, opt_noId?: boolean): Element | - DocumentFragment { +export function blockToDomWithXY(block: Block, opt_noId?: boolean): Element| + DocumentFragment { if (block.isInsertionMarker()) { // Skip over insertion markers. block = block.getChildren(false)[0]; @@ -124,8 +124,8 @@ export function blockToDomWithXY(block: Block, opt_noId?: boolean): Element | // AnyDuringMigration because: Property 'setAttribute' does not exist on type // 'Element | DocumentFragment'. (element as AnyDuringMigration) - .setAttribute( - 'x', Math.round(block.workspace?.RTL ? width - xy.x : xy.x)); + .setAttribute( + 'x', Math.round(block.workspace?.RTL ? width - xy.x : xy.x)); // AnyDuringMigration because: Property 'setAttribute' does not exist on type // 'Element | DocumentFragment'. (element as AnyDuringMigration).setAttribute('y', Math.round(xy.y)); @@ -137,7 +137,7 @@ export function blockToDomWithXY(block: Block, opt_noId?: boolean): Element | * @param field The field to encode. * @return XML element, or null if the field did not need to be serialized. */ -function fieldToDom(field: Field): Element | null { +function fieldToDom(field: Field): Element|null { if (field.isSerializable()) { const container = utilsXml.createElement('field'); container.setAttribute('name', field.name || ''); @@ -173,8 +173,8 @@ function allFieldsToDom(block: Block, element: Element) { * an insertion marker. * @alias Blockly.Xml.blockToDom */ -export function blockToDom(block: Block, opt_noId?: boolean): Element | - DocumentFragment { +export function blockToDom(block: Block, opt_noId?: boolean): Element| + DocumentFragment { // Skip over insertion markers. if (block.isInsertionMarker()) { const child = block.getChildren(false)[0]; @@ -260,7 +260,7 @@ export function blockToDom(block: Block, opt_noId?: boolean): Element | } } if (block.inputsInline !== undefined && - block.inputsInline !== block.inputsInlineDefault) { + block.inputsInline !== block.inputsInlineDefault) { element.setAttribute('inline', block.inputsInline.toString()); } if (block.isCollapsed()) { @@ -290,7 +290,7 @@ export function blockToDom(block: Block, opt_noId?: boolean): Element | } } const nextShadow = - block.nextConnection && block.nextConnection.getShadowDom(); + block.nextConnection && block.nextConnection.getShadowDom(); if (nextShadow && (!nextBlock || !nextBlock.isShadow())) { container!.appendChild(cloneShadow(nextShadow, opt_noId)); } @@ -307,7 +307,7 @@ export function blockToDom(block: Block, opt_noId?: boolean): Element | function cloneShadow(shadow: Element, opt_noId?: boolean): Element { shadow = shadow.cloneNode(true) as Element; // Walk the tree looking for whitespace. Don't prune whitespace in a tag. - let node: Node | null = shadow; + let node: Node|null = shadow; let textNode; while (node) { if (opt_noId && node.nodeName === 'shadow') { @@ -322,8 +322,8 @@ function cloneShadow(shadow: Element, opt_noId?: boolean): Element { textNode = node; node = node.parentNode; if (textNode.nodeType === dom.NodeType.TEXT_NODE && - (textNode as Text).data.trim() === '' && - node?.firstChild !== textNode) { + (textNode as Text).data.trim() === '' && + node?.firstChild !== textNode) { // Prune whitespace after a tag. dom.removeNode(textNode); } @@ -332,7 +332,7 @@ function cloneShadow(shadow: Element, opt_noId?: boolean): Element { textNode = node; node = node.nextSibling; if (textNode.nodeType === dom.NodeType.TEXT_NODE && - (textNode as Text).data.trim() === '') { + (textNode as Text).data.trim() === '') { // Prune whitespace before a tag. dom.removeNode(textNode); } @@ -399,7 +399,7 @@ export function domToPrettyText(dom: Node): string { export function textToDom(text: string): Element { const doc = utilsXml.textToDomDocument(text); if (!doc || !doc.documentElement || - doc.getElementsByTagName('parsererror').length) { + doc.getElementsByTagName('parsererror').length) { throw Error('textToDom was unable to parse: ' + text); } return doc.documentElement; @@ -414,7 +414,7 @@ export function textToDom(text: string): Element { * @alias Blockly.Xml.clearWorkspaceAndLoadFromXml */ export function clearWorkspaceAndLoadFromXml( - xml: Element, workspace: WorkspaceSvg): string[] { + xml: Element, workspace: WorkspaceSvg): string[] { workspace.setResizesEnabled(false); workspace.clear(); // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not @@ -458,7 +458,7 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { const name = xmlChild.nodeName.toLowerCase(); const xmlChildElement = xmlChild as Element; if (name === 'block' || - name === 'shadow' && !eventUtils.getRecordUndo()) { + name === 'shadow' && !eventUtils.getRecordUndo()) { // Allow top-level shadow blocks if recordUndo is disabled since // that means an undo is in progress. Such a block is expected // to be moved to a nested destination in the next operation. @@ -467,15 +467,15 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. const blockX = xmlChildElement.hasAttribute('x') ? - parseInt( - xmlChildElement.getAttribute('x') as AnyDuringMigration, 10) : - 10; + parseInt( + xmlChildElement.getAttribute('x') as AnyDuringMigration, 10) : + 10; // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. const blockY = xmlChildElement.hasAttribute('y') ? - parseInt( - xmlChildElement.getAttribute('y') as AnyDuringMigration, 10) : - 10; + parseInt( + xmlChildElement.getAttribute('y') as AnyDuringMigration, 10) : + 10; if (!isNaN(blockX) && !isNaN(blockY)) { block.moveBy(workspace.RTL ? width - blockX : blockX, blockY); } @@ -485,7 +485,7 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { } else if (name === 'comment') { if (workspace.rendered) { WorkspaceCommentSvg.fromXmlRendered( - xmlChildElement, workspace as WorkspaceSvg, width); + xmlChildElement, workspace as WorkspaceSvg, width); } else { WorkspaceComment.fromXml(xmlChildElement, workspace); } @@ -494,9 +494,9 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { domToVariables(xmlChildElement, workspace); } else { throw Error( - '\'variables\' tag must exist once before block and ' + - 'shadow tag elements in the workspace XML, but it was found in ' + - 'another location.'); + '\'variables\' tag must exist once before block and ' + + 'shadow tag elements in the workspace XML, but it was found in ' + + 'another location.'); } variablesFirst = false; } @@ -512,7 +512,7 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { (workspace as WorkspaceSvg).setResizesEnabled(true); } eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))! - (workspace)); + (workspace)); return newBlockIds; } @@ -525,7 +525,7 @@ export function domToWorkspace(xml: Element, workspace: Workspace): string[] { * @alias Blockly.Xml.appendDomToWorkspace */ export function appendDomToWorkspace( - xml: Element, workspace: WorkspaceSvg): string[] { + xml: Element, workspace: WorkspaceSvg): string[] { // First check if we have a WorkspaceSvg, otherwise the blocks have no shape // and the position does not matter. // Assume it is rendered so we can check. @@ -555,7 +555,7 @@ export function appendDomToWorkspace( const ySeparation = 10; for (let i = 0; i < newBlockIds.length; i++) { const blockXY = - workspace.getBlockById(newBlockIds[i])!.getRelativeToSurfaceXY(); + workspace.getBlockById(newBlockIds[i])!.getRelativeToSurfaceXY(); if (blockXY.y < newY) { newY = blockXY.y; } @@ -607,7 +607,7 @@ export function domToBlock(xmlBlock: Element, workspace: Workspace): Block { } // Populating the connection database may be deferred until after the // blocks have rendered. - setTimeout(function () { + setTimeout(function() { if (!topBlockSvg.disposed) { topBlockSvg.setConnectionTracking(true); } @@ -634,7 +634,7 @@ export function domToBlock(xmlBlock: Element, workspace: Workspace): Block { for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))! - (thisVariable)); + (thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. @@ -680,12 +680,12 @@ interface childNodeTagMap { */ function mapSupportedXmlTags(xmlBlock: Element): childNodeTagMap { const childNodeMap = { - mutation: new Array < Element > (), - comment: new Array < Element > (), - data: new Array < Element > (), - field: new Array < Element > (), - input: new Array < Element > (), - next: new Array < Element > () + mutation: new Array(), + comment: new Array(), + data: new Array(), + field: new Array(), + input: new Array(), + next: new Array() }; for (let i = 0; i < xmlBlock.children.length; i++) { const xmlChild = xmlBlock.children[i]; @@ -760,11 +760,11 @@ function applyCommentTagNodes(xmlChildren: Element[], block: Block) { // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. const width = - parseInt(xmlChild.getAttribute('w') as AnyDuringMigration, 10); + parseInt(xmlChild.getAttribute('w') as AnyDuringMigration, 10); // AnyDuringMigration because: Argument of type 'string | null' is not // assignable to parameter of type 'string'. const height = - parseInt(xmlChild.getAttribute('h') as AnyDuringMigration, 10); + parseInt(xmlChild.getAttribute('h') as AnyDuringMigration, 10); block.setCommentText(text); block.commentModel.pinned = pinned; @@ -774,7 +774,7 @@ function applyCommentTagNodes(xmlChildren: Element[], block: Block) { if (pinned && (block as BlockSvg).getCommentIcon && !block.isInFlyout) { const blockSvg = block as BlockSvg; - setTimeout(function () { + setTimeout(function() { blockSvg.getCommentIcon()!.setVisible(true); }, 1); } @@ -813,8 +813,9 @@ function applyFieldTagNodes(xmlChildren: Element[], block: Block) { * @param xmlNode The XML node to extract child block info from. * @return Any found child block. */ -function findChildBlocks(xmlNode: Element): { childBlockElement: Element | null, childShadowElement: Element | null } { - const childBlockInfo = { childBlockElement: null, childShadowElement: null }; +function findChildBlocks(xmlNode: Element): + {childBlockElement: Element|null, childShadowElement: Element|null} { + const childBlockInfo = {childBlockElement: null, childShadowElement: null}; for (let i = 0; i < xmlNode.childNodes.length; i++) { const xmlChild = xmlNode.childNodes[i]; if (xmlChild.nodeType === dom.NodeType.ELEMENT_NODE) { @@ -822,12 +823,12 @@ function findChildBlocks(xmlNode: Element): { childBlockElement: Element | null, // AnyDuringMigration because: Type 'Element' is not assignable to type // 'null'. childBlockInfo.childBlockElement = - xmlChild as Element as AnyDuringMigration; + xmlChild as Element as AnyDuringMigration; } else if (xmlChild.nodeName.toLowerCase() === 'shadow') { // AnyDuringMigration because: Type 'Element' is not assignable to type // 'null'. childBlockInfo.childShadowElement = - xmlChild as Element as AnyDuringMigration; + xmlChild as Element as AnyDuringMigration; } } } @@ -841,8 +842,8 @@ function findChildBlocks(xmlNode: Element): { childBlockElement: Element | null, * @param prototypeName The prototype name of the block. */ function applyInputTagNodes( - xmlChildren: Element[], workspace: Workspace, block: Block, - prototypeName: string) { + xmlChildren: Element[], workspace: Workspace, block: Block, + prototypeName: string) { for (let i = 0; i < xmlChildren.length; i++) { const xmlChild = xmlChildren[i]; const nodeName = xmlChild.getAttribute('name'); @@ -851,8 +852,8 @@ function applyInputTagNodes( const input = block.getInput(nodeName as AnyDuringMigration); if (!input) { console.warn( - 'Ignoring non-existent input ' + nodeName + ' in block ' + - prototypeName); + 'Ignoring non-existent input ' + nodeName + ' in block ' + + prototypeName); break; } const childBlockInfo = findChildBlocks(xmlChild); @@ -861,7 +862,7 @@ function applyInputTagNodes( throw TypeError('Input connection does not exist.'); } domToBlockHeadless( - childBlockInfo.childBlockElement, workspace, input.connection, false); + childBlockInfo.childBlockElement, workspace, input.connection, false); } // Set shadow after so we don't create a shadow we delete immediately. if (childBlockInfo.childShadowElement) { @@ -877,7 +878,7 @@ function applyInputTagNodes( * @param block The block to apply the child nodes on. */ function applyNextTagNodes( - xmlChildren: Element[], workspace: Workspace, block: Block) { + xmlChildren: Element[], workspace: Workspace, block: Block) { for (let i = 0; i < xmlChildren.length; i++) { const xmlChild = xmlChildren[i]; const childBlockInfo = findChildBlocks(xmlChild); @@ -891,8 +892,8 @@ function applyNextTagNodes( } // Create child block. domToBlockHeadless( - childBlockInfo.childBlockElement, workspace, block.nextConnection, - true); + childBlockInfo.childBlockElement, workspace, block.nextConnection, + true); } // Set shadow after so we don't create a shadow we delete immediately. if (childBlockInfo.childShadowElement && block.nextConnection) { @@ -914,8 +915,8 @@ function applyNextTagNodes( * @return The root block created. */ function domToBlockHeadless( - xmlBlock: Element, workspace: Workspace, parentConnection?: Connection, - connectedToParentNext?: boolean): Block { + xmlBlock: Element, workspace: Workspace, parentConnection?: Connection, + connectedToParentNext?: boolean): Block { let block = null; const prototypeName = xmlBlock.getAttribute('type'); if (!prototypeName) { @@ -930,7 +931,7 @@ function domToBlockHeadless( const xmlChildNameMap = mapSupportedXmlTags(xmlBlock); const shouldCallInitSvg = - applyMutationTagNodes(xmlChildNameMap.mutation, block); + applyMutationTagNodes(xmlChildNameMap.mutation, block); applyCommentTagNodes(xmlChildNameMap.comment, block); applyDataTagNodes(xmlChildNameMap.data, block); @@ -949,7 +950,7 @@ function domToBlockHeadless( parentConnection.connect(block.previousConnection); } else { throw TypeError( - 'Child block does not have output or previous statement.'); + 'Child block does not have output or previous statement.'); } } } @@ -1018,7 +1019,7 @@ function domToField(block: Block, fieldName: string, xml: Element) { const field = block.getField(fieldName); if (!field) { console.warn( - 'Ignoring non-existent field ' + fieldName + ' in block ' + block.type); + 'Ignoring non-existent field ' + fieldName + ' in block ' + block.type); return; } field.fromXml(xml); @@ -1030,7 +1031,7 @@ function domToField(block: Block, fieldName: string, xml: Element) { * was an insertion marker. * @alias Blockly.Xml.deleteNext */ -export function deleteNext(xmlBlock: Element | DocumentFragment) { +export function deleteNext(xmlBlock: Element|DocumentFragment) { for (let i = 0; i < xmlBlock.childNodes.length; i++) { const child = xmlBlock.childNodes[i]; if (child.nodeName.toLowerCase() === 'next') { diff --git a/core/zoom_controls.ts b/core/zoom_controls.ts index b2adb43e7..ab7e5e567 100644 --- a/core/zoom_controls.ts +++ b/core/zoom_controls.ts @@ -18,21 +18,21 @@ import './metrics_manager'; import './events/events_click'; import * as browserEvents from './browser_events.js'; -import { ComponentManager } from './component_manager.js'; +import {ComponentManager} from './component_manager.js'; import * as Css from './css.js'; import * as eventUtils from './events/utils.js'; /* eslint-disable-next-line no-unused-vars */ -import { IPositionable } from './interfaces/i_positionable.js'; -import { UiMetrics } from './metrics_manager.js'; +import {IPositionable} from './interfaces/i_positionable.js'; +import {UiMetrics} from './metrics_manager.js'; import * as uiPosition from './positionable_helpers.js'; -import { SPRITE } from './sprites.js'; +import {SPRITE} from './sprites.js'; import * as Touch from './touch.js'; import * as dom from './utils/dom.js'; -import { Rect } from './utils/rect.js'; -import { Size } from './utils/size.js'; -import { Svg } from './utils/svg.js'; +import {Rect} from './utils/rect.js'; +import {Size} from './utils/size.js'; +import {Svg} from './utils/svg.js'; /* eslint-disable-next-line no-unused-vars */ -import { WorkspaceSvg } from './workspace_svg.js'; +import {WorkspaceSvg} from './workspace_svg.js'; /** @@ -50,19 +50,19 @@ export class ZoomControls implements IPositionable { * A handle to use to unbind the mouse down event handler for zoom reset * button. Opaque data returned from browserEvents.conditionalBind. */ - private onZoomResetWrapper_: browserEvents.Data | null = null; + private onZoomResetWrapper_: browserEvents.Data|null = null; /** * A handle to use to unbind the mouse down event handler for zoom in * button. Opaque data returned from browserEvents.conditionalBind. */ - private onZoomInWrapper_: browserEvents.Data | null = null; + private onZoomInWrapper_: browserEvents.Data|null = null; /** * A handle to use to unbind the mouse down event handler for zoom out * button. Opaque data returned from browserEvents.conditionalBind. */ - private onZoomOutWrapper_: browserEvents.Data | null = null; + private onZoomOutWrapper_: browserEvents.Data|null = null; /** The zoom in svg element. */ // AnyDuringMigration because: Type 'null' is not assignable to type @@ -173,7 +173,7 @@ export class ZoomControls implements IPositionable { * @return The UI elements's bounding box. Null if bounding box should be * ignored by other UI elements. */ - getBoundingRectangle(): Rect | null { + getBoundingRectangle(): Rect|null { let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; @@ -197,47 +197,47 @@ export class ZoomControls implements IPositionable { } const cornerPosition = - uiPosition.getCornerOppositeToolbox(this.workspace, metrics); + uiPosition.getCornerOppositeToolbox(this.workspace, metrics); let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } const startRect = uiPosition.getStartPositionRect( - cornerPosition, new Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, - this.MARGIN_VERTICAL_, metrics, this.workspace); + cornerPosition, new Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, + this.MARGIN_VERTICAL_, metrics, this.workspace); const verticalPosition = cornerPosition.vertical; const bumpDirection = verticalPosition === uiPosition.verticalPosition.TOP ? - uiPosition.bumpDirection.DOWN : - uiPosition.bumpDirection.UP; + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; const positionRect = uiPosition.bumpPositionRect( - startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); + startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute( - 'transform', 'translate(0, ' + zoomInTranslateY + ')'); + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { const zoomResetTranslateY = - zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; + zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; this.zoomResetGroup_.setAttribute( - 'transform', 'translate(0, ' + zoomResetTranslateY + ')'); + 'transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { const zoomInTranslateY = - this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; + this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; this.zoomInGroup_.setAttribute( - 'transform', 'translate(0, ' + zoomInTranslateY + ')'); + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); const zoomOutTranslateY = - zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; + zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; this.zoomOutGroup_.setAttribute( - 'transform', 'translate(0, ' + zoomOutTranslateY + ')'); + 'transform', 'translate(0, ' + zoomOutTranslateY + ')'); } this.top_ = positionRect.top; this.left_ = positionRect.left; this.svgGroup_.setAttribute( - 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); + 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); } /** @@ -258,32 +258,32 @@ export class ZoomControls implements IPositionable { */ this.zoomOutGroup_ = - dom.createSvgElement(Svg.G, { 'class': 'blocklyZoom' }, this.svgGroup_); + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd }, - this.zoomOutGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoomoutClipPath' + rnd}, + this.zoomOutGroup_); dom.createSvgElement( - Svg.RECT, { - 'width': 32, - 'height': 32, - }, - clip); + Svg.RECT, { + 'width': 32, + 'height': 32, + }, + clip); const zoomoutSvg = dom.createSvgElement( - Svg.IMAGE, { - 'width': SPRITE.width, - 'height': SPRITE.height, - 'x': -64, - 'y': -92, - 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')', - }, - this.zoomOutGroup_); + Svg.IMAGE, { + 'width': SPRITE.width, + 'height': SPRITE.height, + 'x': -64, + 'y': -92, + 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')', + }, + this.zoomOutGroup_); zoomoutSvg.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.workspace.options.pathToMedia + SPRITE.url); + dom.XLINK_NS, 'xlink:href', + this.workspace.options.pathToMedia + SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = browserEvents.conditionalBind( - this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); + this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); } /** @@ -304,31 +304,31 @@ export class ZoomControls implements IPositionable { */ this.zoomInGroup_ = - dom.createSvgElement(Svg.G, { 'class': 'blocklyZoom' }, this.svgGroup_); + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd }, this.zoomInGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoominClipPath' + rnd}, this.zoomInGroup_); dom.createSvgElement( - Svg.RECT, { - 'width': 32, - 'height': 32, - }, - clip); + Svg.RECT, { + 'width': 32, + 'height': 32, + }, + clip); const zoominSvg = dom.createSvgElement( - Svg.IMAGE, { - 'width': SPRITE.width, - 'height': SPRITE.height, - 'x': -32, - 'y': -92, - 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')', - }, - this.zoomInGroup_); + Svg.IMAGE, { + 'width': SPRITE.width, + 'height': SPRITE.height, + 'x': -32, + 'y': -92, + 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')', + }, + this.zoomInGroup_); zoominSvg.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.workspace.options.pathToMedia + SPRITE.url); + dom.XLINK_NS, 'xlink:href', + this.workspace.options.pathToMedia + SPRITE.url); // Attach listener. this.onZoomInWrapper_ = browserEvents.conditionalBind( - this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); + this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); } /** @@ -367,26 +367,26 @@ export class ZoomControls implements IPositionable { */ this.zoomResetGroup_ = - dom.createSvgElement(Svg.G, { 'class': 'blocklyZoom' }, this.svgGroup_); + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd }, - this.zoomResetGroup_); - dom.createSvgElement(Svg.RECT, { 'width': 32, 'height': 32 }, clip); + Svg.CLIPPATH, {'id': 'blocklyZoomresetClipPath' + rnd}, + this.zoomResetGroup_); + dom.createSvgElement(Svg.RECT, {'width': 32, 'height': 32}, clip); const zoomresetSvg = dom.createSvgElement( - Svg.IMAGE, { - 'width': SPRITE.width, - 'height': SPRITE.height, - 'y': -92, - 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')', - }, - this.zoomResetGroup_); + Svg.IMAGE, { + 'width': SPRITE.width, + 'height': SPRITE.height, + 'y': -92, + 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')', + }, + this.zoomResetGroup_); zoomresetSvg.setAttributeNS( - dom.XLINK_NS, 'xlink:href', - this.workspace.options.pathToMedia + SPRITE.url); + dom.XLINK_NS, 'xlink:href', + this.workspace.options.pathToMedia + SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = browserEvents.conditionalBind( - this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); + this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); } /** @@ -422,7 +422,7 @@ export class ZoomControls implements IPositionable { /** Fires a zoom control UI event. */ private fireZoomEvent_() { const uiEvent = new (eventUtils.get(eventUtils.CLICK))! - (null, this.workspace.id, 'zoom_controls'); + (null, this.workspace.id, 'zoom_controls'); eventUtils.fire(uiEvent); } }