mirror of
https://github.com/google/blockly.git
synced 2026-01-24 09:10:09 +01:00
* fix: convert files to typescript * fix: add alias for AnyDuringMigration so that tsc will run * chore: format * chore: enable ts for the clang-format workflow (#6233) * chore: Restore @fileoverview comment locations (#6237) * chore: add declareModuleId (#6238) * fix: Revert comment change to app_controller.js (#6241) * fix: Add missing import goog statements (#6240) I've added the import statement immediately before the goog.declareModuleId calls that depend on it. There is an argument to be made that we should put the import statement in their normal place amongst any other imports, and move the declareModuleId statement to below the double blank line below the imports, but as these are so tightly coupled, replace the previous goog.module calls, and will both be deleted at the same time once the transition to TypeScript is fully complete I think it's fine (and certainly much easier) to do it this way. * chore: Fix whitespace (#6243) * fix: Remove spurious blank lines Remove extraneous blank lines introduced by deletion of 'use strict'; pragmas. Also fix the location of the goog.declareModuleId call in core/utils/array.ts. * fix: Add missing double-blank-line before body of modules Our convention is to have two blank lines between the imports (or module ID, if there are no imports) and the beginning of the body of the module. Enforce this. * fix: one addition format error for PR #6243 * fix(build): Skip npm prepare when running in CI (#6244) Have npm prepare do nothing when running in CI. We don't need to do any building, because npm test will build everything needed in the workflows in which it is run, and we don't want to build anything in other workflows because a tsc error would prevent those workflows from completing. * fix: re-add `@package` annotations as `@internal` annotations (#6232) * fix: add ~70% of internal attributes * fix: work on manually adding more @internal annotations * fix: add more manual internal annotations * fix: rename package typos to internal * fix: final manual fixes for internal annotations * chore: format * chore: make unnecessary multiline jsdoc a single line * fix: fix internal tags in serialization exceptions * fix: tsc errors picked up from develop (#6224) * fix: relative path for deprecation utils * fix: checking if properties exist in svg_math * fix: set all timeout PIDs to AnyDuringMigration * fix: make nullability errors explicity in block drag surface * fix: make null check in events_block_change explicit * fix: make getEventWorkspace_ internal so we can access it from CommentCreateDeleteHelper * fix: rename DIV -> containerDiv in tooltip * fix: ignore backwards compat check in category * fix: set block styles to AnyDuringMigration * fix: type typo in KeyboardShortcut * fix: constants name in row measurables * fix: typecast in mutator * fix: populateProcedures type of flattened array * fix: ignore errors related to workspace comment deserialization * chore: format files * fix: renaming imports missing file extensions * fix: remove check for sound.play * fix: temporarily remove bad requireType. All `export type` statements are stripped when tsc is run. This means that when we attempt to require BlockDefinition from the block files, we get an error because it does not exist. We decided to temporarily remove the require, because this will no longer be a problem when we conver the blocks to typescript, and everything gets compiled together. * fix: bad jsdoc in array * fix: silence missing property errors Closure was complaining about inexistant properties, but they actually do exist, they're just not being transpiled by tsc in a way that closure understands. I.E. if things are initialized in a function called by the constructor, rather than in a class field or in the custructor itself, closure would error. It would also error on enums, because they are transpiled to a weird IIFE. * fix: context menu action handler not knowing the type of this. this: TypeX information gets stripped when tsc is run, so closure could not know that this was not global. Fixed this by reorganizing to use the option object directly instead of passing it to onAction to be bound to this. * fix: readd getDeveloperVars checks (should not be part of migration) This was found because ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE was no longer being accessed. * fix: silence closure errors about overriding supertype props We propertly define the overrides in typescript, but these get removed from the compiled output, so closure doesn't know they exist. * fix: silence globalThis errors this: TypeX annotations get stripped from the compiled output, so closure can't know that we're accessing the correct things. However, typescript makes sure that this always has the correct properties, so silencing this should be fine. * fix: bad jsdoc name * chore: attempt compiling with blockly.js * fix: attempt moving the import statement above the namespace line * chore: add todo comments to block def files * chore: remove todo from context menu * chore: add comments abotu disabled errors * chore: move comments back to their correct positions (#6249) * fix: work on fixing comments * chore: finish moving all comments * chore: format * chore: move some other messed up comments * chore: format * fix: Correct enum formatting, use merged `namespace`s for types that are class static members (#6246) * fix: formatting of enum KeyCodes * fix: Use merged namespace for ContextMenuRegistry static types - Create a namespace to be merged with the ContextMenuRegistry class containing the types that were formerly declared as static properties on that class. - Use type aliases to export them individually as well, for compatibility with the changes made by MigranTS (and/or @gonfunko) to how other modules in core/ now import these types. - Update renamings.json5 to reflect the availability of the direct exports for modules that import this module directly (though they are not available to, and will not be used by, code that imports only via blockly.js/blockly.ts.) * fix: Use merged namespace for Input.Align - Create a merged namespace for the Input.Align enum. - Use type/const aliases to export it as Input too. - Update renamings.json5 to reflect the availability of the direct export. * fix: Use merged namespace for Names.NameType - Create a merged namespace for the Names.NameType enum. - Use type/const aliases to export it as NameType too. - Update renamings.json5 to reflect the availability of the direct export. (This ought to have happened in an earlier version as it was already available by both routes.) * chore: Fix minor issues for PR #6246 - Use `Align` instead of `Input.Align` where possible. * fix(build): Suppress irrelevant JSC_UNUSED_LOCAL_ASSIGNMENT errors tsc generates code for merged namespaces that looks like: (function (ClassName) { let EnumName; (function (EnumName) { EnumName[EnumNameAlign["v1"] = 0] = "v1"; // etc. })(EnumName = ClassName.EnumName || (ClassName.EnumName = {})); })(ClassName || (ClassName = {})); and Closure Compiler complains about the fact that the EnumName let binding is initialised but never used. (It exists so that any other code that was in the namespace could see the enum.) Suppress this message, since it is not actionable and lint and/or tsc should tell us if we have actual unused variables in our .ts files. * chore(build): Suppress spurious warnings from closure-make-deps (#6253) A little bit of an ugly hack, but it works: pipe stderr through grep -v to suppress error output starting with "WARNING in". * fix: remaining enums that weren't properly exported (#6251) * fix: remaining enums that weren't properly exported * chore: format * fix: add enum value exports * chore: format * fix: properly export interfaces that were typedefs (#6250) * fix: properly export interfaces that were typedefs * fix: allowCollsion -> allowCollision * fix: convert unconverted enums * fix: enums that were/are instance properties * fix: revert changes to property enums * fix: renamed protected parameter properties (#6252) * fix: bad protected parameter properties * chore:format * fix: gesture constructor * fix: overridden properties that were renamed * refactor: Migrate `blockly.js` to TypeScript (#6261) * chore: Apply changes to blockly.js to blockly.ts * fix: Build using core/blockly.ts instead of .js Compiles and runs in compressed mode correctly! * fix(build): Don't depend on execSync running bash (#6262) For some reason on Github CI servers execSync uses /bin/sh, which is (on Ubuntu) dash rather than bash, and does not understand the pipefail option. So remove the grep pipe on stderr and just discard all error output at all. This is not ideal as errors in test deps will go unreported AND not even cause test failure, but it's not clear that it's worth investing more time to fix this at the moment. * chore: use `import type` where possible (#6279) * chore: automatically change imports to import types * chore: revert changes that actually need to be imports * chore: format * chore: add more import type statements based on importsNotUsedAsValues * chore: fix tsconfig * chore: add link to compiler issue * fix: add type information to blockly options (#6283) * fix: add type information to blockly options * chore: format * chore: remove erroneous comment * fix: bugs revealed by getting the built output working (#6282) * fix: types of compose and decompose in block * fix: workspace naming in toolbox * chore: add jsdoc * chore: restore registry comments to better positions * chore: pr comments' * fix(variables): Revert inadvertent change to allDeveloperVariables (#6290) It appears that a function call got modified incorrectly (probably in an effort to fix a typing issue). This fix trivially reverts the line in question to match the original JS version from develop. This causes the generator tests to pass. * fix: circular dependencies (#6281) * chore: fix circular dependencies w/ static workspace funcs * remove preserved imports that aren't currently necessary (probably) * fix circular dependency with workspaces and block using stub * fix dependency between variables and xml by moving function to utils * add stub for trashcan as well * fix line endings from rebase * fix goog/base order * add trashcan patch * fix: types of compose and decompose in block * fix: workspace naming in toolbox * chore: add jsdoc * chore: restore registry comments to better positions * chore: remove implementations in goog.js * chore: fix types of stubs * chore: remove added AnyDuringMigration casts * chore: remove modifications to xml and variables * chore: format * chore: remove event requirements in workspace comments * chore: fix circular dependency with xml and workspace comments * fixup remove ContextMenu import * chore: fix dependency between mutator and workspace * chore: break circular dependency between names and procedures * chore: get tests to run? * chore: pr comments' * chore: fix stubbing field registry fromJson * chore: fix spying on fire * chore: fix stubbing parts of connection checker * chore: fix stubbing dialog * chore: fix stubbing style * chore: fix spying on duplicate * chore: fix stubbing variables * chore: fix stubbing copy * chore: fix stubbing in workspace * chore: remove unnecessary stubs * chore: fix formatting * chore: fix other formatting * chore: add backwards compatible static properties to workspace * chore: move static type properties * chore: move and comment stubs * chore: add newlines at EOF * chore: improve errors for monkey patched functions * chore: update comment with a pointer to the doc * chore: update comment with a pointer to the doc * chore: format * chore: revert changes to playground used for testing (#6292) * chore: get mocha tests to pass. (#6291) * chore: fix undo and empty code blocks * chore: skip IE test * chore: fix gesture test * chore: fix replace message references test * chore: fix string table interpolation * chore: skip getById tests * chore: fix field tests * chore: fix console errors by making workspace nullable * chore: format * chore: fix definition overwrite warning * chore: update metadata * chore: temporarily modify the the advanced compile test * chore: fix gestures by fixing test instead Co-authored-by: Neil Fraser <fraser@google.com> Co-authored-by: Christopher Allen <cpcallen+git@google.com>
451 lines
16 KiB
TypeScript
451 lines
16 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Methods for graphically rendering a block as SVG.
|
|
*/
|
|
|
|
/**
|
|
* Methods for graphically rendering a block as SVG.
|
|
* @class
|
|
*/
|
|
import * as goog from '../../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.blockRendering.Drawer');
|
|
|
|
import type {BlockSvg} from '../../block_svg.js';
|
|
import * as svgPaths from '../../utils/svg_paths.js';
|
|
import {Connection} from '../measurables/connection.js';
|
|
import type {ExternalValueInput} from '../measurables/external_value_input.js';
|
|
import type {Field} from '../measurables/field.js';
|
|
import type {Icon} from '../measurables/icon.js';
|
|
import type {InlineInput} from '../measurables/inline_input.js';
|
|
import type {PreviousConnection} from '../measurables/previous_connection.js';
|
|
import type {Row} from '../measurables/row.js';
|
|
import {Types} from '../measurables/types.js';
|
|
|
|
import type {ConstantProvider, Notch, PuzzleTab} from './constants.js';
|
|
import * as debug from './debug.js';
|
|
import type {RenderInfo} from './info.js';
|
|
|
|
|
|
/**
|
|
* An object that draws a block based on the given rendering information.
|
|
* @alias Blockly.blockRendering.Drawer
|
|
*/
|
|
export class Drawer {
|
|
block_: AnyDuringMigration;
|
|
info_: AnyDuringMigration;
|
|
topLeft_: AnyDuringMigration;
|
|
outlinePath_ = '';
|
|
inlinePath_ = '';
|
|
protected constants_: ConstantProvider;
|
|
|
|
/**
|
|
* @param block The block to render.
|
|
* @param info An object containing all information needed to render this
|
|
* block.
|
|
* @internal
|
|
*/
|
|
constructor(block: BlockSvg, info: RenderInfo) {
|
|
this.block_ = block;
|
|
this.info_ = info;
|
|
this.topLeft_ = block.getRelativeToSurfaceXY();
|
|
|
|
/** The renderer's constant provider. */
|
|
this.constants_ = info.getRenderer().getConstants();
|
|
}
|
|
|
|
/**
|
|
* Draw the block to the workspace. Here "drawing" means setting SVG path
|
|
* elements and moving fields, icons, and connections on the screen.
|
|
*
|
|
* The pieces of the paths are pushed into arrays of "steps", which are then
|
|
* joined with spaces and set directly on the block. This guarantees that
|
|
* the steps are separated by spaces for improved readability, but isn't
|
|
* required.
|
|
* @internal
|
|
*/
|
|
draw() {
|
|
this.hideHiddenIcons_();
|
|
this.drawOutline_();
|
|
this.drawInternals_();
|
|
|
|
this.block_.pathObject.setPath(this.outlinePath_ + '\n' + this.inlinePath_);
|
|
if (this.info_.RTL) {
|
|
this.block_.pathObject.flipRTL();
|
|
}
|
|
if (debug.isDebuggerEnabled()) {
|
|
this.block_.renderingDebugger.drawDebug(this.block_, this.info_);
|
|
}
|
|
this.recordSizeOnBlock_();
|
|
}
|
|
|
|
/**
|
|
* Save sizing information back to the block
|
|
* Most of the rendering information can be thrown away at the end of the
|
|
* render. Anything that needs to be kept around should be set in this
|
|
* function.
|
|
*/
|
|
protected recordSizeOnBlock_() {
|
|
// This is used when the block is reporting its size to anyone else.
|
|
// The dark path adds to the size of the block in both X and Y.
|
|
this.block_.height = this.info_.height;
|
|
this.block_.width = this.info_.widthWithChildren;
|
|
}
|
|
|
|
/** Hide icons that were marked as hidden. */
|
|
protected hideHiddenIcons_() {
|
|
for (let i = 0, iconInfo; iconInfo = this.info_.hiddenIcons[i]; i++) {
|
|
iconInfo.icon.iconGroup_.setAttribute('display', 'none');
|
|
}
|
|
}
|
|
|
|
/** Create the outline of the block. This is a single continuous path. */
|
|
protected drawOutline_() {
|
|
this.drawTop_();
|
|
for (let r = 1; r < this.info_.rows.length - 1; r++) {
|
|
const row = this.info_.rows[r];
|
|
if (row.hasJaggedEdge) {
|
|
this.drawJaggedEdge_(row);
|
|
} else if (row.hasStatement) {
|
|
this.drawStatementInput_(row);
|
|
} else if (row.hasExternalInput) {
|
|
this.drawValueInput_(row);
|
|
} else {
|
|
this.drawRightSideRow_(row);
|
|
}
|
|
}
|
|
this.drawBottom_();
|
|
this.drawLeft_();
|
|
}
|
|
|
|
/**
|
|
* Add steps for the top corner of the block, taking into account
|
|
* details such as hats and rounded corners.
|
|
*/
|
|
protected drawTop_() {
|
|
const topRow = this.info_.topRow;
|
|
const elements = topRow.elements;
|
|
|
|
this.positionPreviousConnection_();
|
|
this.outlinePath_ += svgPaths.moveBy(topRow.xPos, this.info_.startY);
|
|
for (let i = 0, elem; elem = elements[i]; i++) {
|
|
if (Types.isLeftRoundedCorner(elem)) {
|
|
this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft;
|
|
} else if (Types.isRightRoundedCorner(elem)) {
|
|
this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight;
|
|
} else if (
|
|
Types.isPreviousConnection(elem) && elem instanceof Connection) {
|
|
this.outlinePath_ +=
|
|
((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)) {
|
|
this.outlinePath_ += this.constants_.START_HAT.path;
|
|
} else if (Types.isSpacer(elem)) {
|
|
this.outlinePath_ += svgPaths.lineOnAxis('h', elem.width);
|
|
}
|
|
}
|
|
// No branch for a square corner, because it's a no-op.
|
|
this.outlinePath_ += svgPaths.lineOnAxis('v', topRow.height);
|
|
}
|
|
|
|
/**
|
|
* Add steps for the jagged edge of a row on a collapsed block.
|
|
* @param row The row to draw the side of.
|
|
*/
|
|
protected drawJaggedEdge_(row: Row) {
|
|
const remainder = row.height - this.constants_.JAGGED_TEETH.height;
|
|
this.outlinePath_ +=
|
|
this.constants_.JAGGED_TEETH.path + svgPaths.lineOnAxis('v', remainder);
|
|
}
|
|
|
|
/**
|
|
* Add steps for an external value input, rendered as a notch in the side
|
|
* of the block.
|
|
* @param row The row that this input belongs to.
|
|
*/
|
|
protected drawValueInput_(row: Row) {
|
|
const input = row.getLastInput() as ExternalValueInput | InlineInput;
|
|
this.positionExternalValueConnection_(row);
|
|
|
|
// AnyDuringMigration because: Property 'pathDown' does not exist on type
|
|
// 'Shape'. AnyDuringMigration because: Property 'pathDown' does not exist
|
|
// on type 'Shape'. AnyDuringMigration because: Property 'pathDown' does
|
|
// not exist on type 'Shape'.
|
|
const pathDown =
|
|
typeof (input.shape as AnyDuringMigration).pathDown === 'function' ?
|
|
((input.shape as AnyDuringMigration).pathDown as (p1: number) =>
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Add steps for a statement input.
|
|
* @param row The row that this input belongs to.
|
|
*/
|
|
protected drawStatementInput_(row: Row) {
|
|
const input = row.getLastInput();
|
|
// Where to start drawing the notch, which is on the right side in LTR.
|
|
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;
|
|
|
|
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);
|
|
|
|
this.positionStatementInputConnection_(row);
|
|
}
|
|
|
|
/**
|
|
* Add steps for the right side of a row that does not have value or
|
|
* statement input connections.
|
|
* @param row The row to draw the side of.
|
|
*/
|
|
protected drawRightSideRow_(row: Row) {
|
|
this.outlinePath_ += svgPaths.lineOnAxis('V', row.yPos + row.height);
|
|
}
|
|
|
|
/**
|
|
* Add steps for the bottom edge of a block, possibly including a notch
|
|
* for the next connection.
|
|
*/
|
|
protected drawBottom_() {
|
|
const bottomRow = this.info_.bottomRow;
|
|
const elems = bottomRow.elements;
|
|
this.positionNextConnection_();
|
|
|
|
let rightCornerYOffset = 0;
|
|
let outlinePath = '';
|
|
for (let i = elems.length - 1, elem; elem = elems[i]; i--) {
|
|
if (Types.isNextConnection(elem) && elem instanceof Connection) {
|
|
outlinePath += (elem.shape as Notch).pathRight;
|
|
} else if (Types.isLeftSquareCorner(elem)) {
|
|
outlinePath += svgPaths.lineOnAxis('H', bottomRow.xPos);
|
|
} else if (Types.isLeftRoundedCorner(elem)) {
|
|
outlinePath += this.constants_.OUTSIDE_CORNERS.bottomLeft;
|
|
} else if (Types.isRightRoundedCorner(elem)) {
|
|
outlinePath += this.constants_.OUTSIDE_CORNERS.bottomRight;
|
|
rightCornerYOffset = this.constants_.OUTSIDE_CORNERS.rightHeight;
|
|
} else if (Types.isSpacer(elem)) {
|
|
outlinePath += svgPaths.lineOnAxis('h', elem.width * -1);
|
|
}
|
|
}
|
|
|
|
this.outlinePath_ +=
|
|
svgPaths.lineOnAxis('V', bottomRow.baseline - rightCornerYOffset);
|
|
this.outlinePath_ += outlinePath;
|
|
}
|
|
|
|
/**
|
|
* Add steps for the left side of the block, which may include an output
|
|
* connection
|
|
*/
|
|
protected drawLeft_() {
|
|
const outputConnection = this.info_.outputConnection;
|
|
this.positionOutputConnection_();
|
|
|
|
if (outputConnection) {
|
|
const tabBottom =
|
|
outputConnection.connectionOffsetY + outputConnection.height;
|
|
const pathUp = typeof outputConnection.shape.pathUp === 'function' ?
|
|
(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;
|
|
}
|
|
// 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.
|
|
this.outlinePath_ += 'z';
|
|
}
|
|
|
|
/**
|
|
* Draw the internals of the block: inline inputs, fields, and icons. These
|
|
* do not depend on the outer path for placement.
|
|
*/
|
|
protected drawInternals_() {
|
|
for (let i = 0, row; row = this.info_.rows[i]; i++) {
|
|
for (let j = 0, elem; elem = row.elements[j]; j++) {
|
|
if (Types.isInlineInput(elem)) {
|
|
this.drawInlineInput_(elem as InlineInput);
|
|
} else if (Types.isIcon(elem) || Types.isField(elem)) {
|
|
this.layoutField_(elem as Field | Icon);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
let svgGroup;
|
|
if (Types.isField(fieldInfo)) {
|
|
// AnyDuringMigration because: Property 'field' does not exist on type
|
|
// 'Icon | Field'.
|
|
svgGroup = (fieldInfo as AnyDuringMigration).field.getSvgRoot();
|
|
} else if (Types.isIcon(fieldInfo)) {
|
|
// AnyDuringMigration because: Property 'icon' does not exist on type
|
|
// 'Icon | Field'.
|
|
svgGroup = (fieldInfo as AnyDuringMigration).icon.iconGroup_;
|
|
}
|
|
|
|
const yPos = fieldInfo.centerline - fieldInfo.height / 2;
|
|
let xPos = fieldInfo.xPos;
|
|
let scale = '';
|
|
if (this.info_.RTL) {
|
|
xPos = -(xPos + fieldInfo.width);
|
|
// AnyDuringMigration because: Property 'flipRtl' does not exist on type
|
|
// 'Icon | Field'.
|
|
if ((fieldInfo as AnyDuringMigration).flipRtl) {
|
|
xPos += fieldInfo.width;
|
|
scale = 'scale(-1 1)';
|
|
}
|
|
}
|
|
if (Types.isIcon(fieldInfo)) {
|
|
svgGroup.setAttribute('display', 'block');
|
|
svgGroup.setAttribute(
|
|
'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);
|
|
}
|
|
|
|
if (this.info_.isInsertionMarker) {
|
|
// Fields and icons are invisible on insertion marker. They still have to
|
|
// be rendered so that the block can be sized correctly.
|
|
svgGroup.setAttribute('display', 'none');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add steps for an inline input.
|
|
* @param input The information about the input to render.
|
|
*/
|
|
protected drawInlineInput_(input: InlineInput) {
|
|
const width = input.width;
|
|
const height = input.height;
|
|
const yPos = input.centerline - height / 2;
|
|
|
|
const connectionTop = input.connectionOffsetY;
|
|
const connectionBottom = input.connectionHeight + connectionTop;
|
|
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';
|
|
|
|
this.positionInlineInputConnection_(input);
|
|
}
|
|
|
|
/**
|
|
* Position the connection on an inline value input, taking into account
|
|
* RTL and the small gap between the parent block and child block which lets
|
|
* the parent block's dark path show through.
|
|
* @param input The information about the input that the connection is on.
|
|
*/
|
|
protected positionInlineInputConnection_(input: InlineInput) {
|
|
const yPos = input.centerline - input.height / 2;
|
|
// Move the connection.
|
|
if (input.connectionModel) {
|
|
// xPos already contains info about startX
|
|
let connX = input.xPos + input.connectionWidth + input.connectionOffsetX;
|
|
if (this.info_.RTL) {
|
|
connX *= -1;
|
|
}
|
|
input.connectionModel.setOffsetInBlock(
|
|
connX, yPos + input.connectionOffsetY);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Position the connection on a statement input, taking into account
|
|
* RTL and the small gap between the parent block and child block which lets
|
|
* the parent block's dark path show through.
|
|
* @param row The row that the connection is on.
|
|
*/
|
|
protected positionStatementInputConnection_(row: Row) {
|
|
const input = row.getLastInput();
|
|
if (input.connectionModel) {
|
|
let connX = row.xPos + row.statementEdge + input.notchOffset;
|
|
if (this.info_.RTL) {
|
|
connX *= -1;
|
|
}
|
|
input.connectionModel.setOffsetInBlock(connX, row.yPos);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Position the connection on an external value input, taking into account
|
|
* RTL and the small gap between the parent block and child block which lets
|
|
* the parent block's dark path show through.
|
|
* @param row The row that the connection is on.
|
|
*/
|
|
protected positionExternalValueConnection_(row: Row) {
|
|
const input = row.getLastInput();
|
|
if (input.connectionModel) {
|
|
let connX = row.xPos + row.width;
|
|
if (this.info_.RTL) {
|
|
connX *= -1;
|
|
}
|
|
input.connectionModel.setOffsetInBlock(connX, row.yPos);
|
|
}
|
|
}
|
|
|
|
/** Position the previous connection on a block. */
|
|
protected positionPreviousConnection_() {
|
|
const topRow = this.info_.topRow;
|
|
if (topRow.connection) {
|
|
const x = topRow.xPos + topRow.notchOffset;
|
|
const connX = this.info_.RTL ? -x : x;
|
|
topRow.connection.connectionModel.setOffsetInBlock(connX, 0);
|
|
}
|
|
}
|
|
|
|
/** Position the next connection on a block. */
|
|
protected positionNextConnection_() {
|
|
const bottomRow = this.info_.bottomRow;
|
|
|
|
if (bottomRow.connection) {
|
|
const connInfo = bottomRow.connection;
|
|
const x = connInfo.xPos; // Already contains info about startX.
|
|
const connX = this.info_.RTL ? -x : x;
|
|
connInfo.connectionModel.setOffsetInBlock(connX, bottomRow.baseline);
|
|
}
|
|
}
|
|
|
|
/** Position the output connection on a block. */
|
|
protected positionOutputConnection_() {
|
|
if (this.info_.outputConnection) {
|
|
const x =
|
|
this.info_.startX + this.info_.outputConnection.connectionOffsetX;
|
|
const connX = this.info_.RTL ? -x : x;
|
|
this.block_.outputConnection.setOffsetInBlock(
|
|
connX, this.info_.outputConnection.connectionOffsetY);
|
|
}
|
|
}
|
|
}
|