mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import * as goog from '../../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.blockRendering.InputConnection');
|
|
|
|
import type {BlockSvg} from '../../block_svg.js';
|
|
import type {Input} from '../../inputs/input.js';
|
|
import type {RenderedConnection} from '../../rendered_connection.js';
|
|
import type {ConstantProvider} from '../common/constants.js';
|
|
|
|
import {Connection} from './connection.js';
|
|
import {Types} from './types.js';
|
|
|
|
/**
|
|
* The base class to represent an input that takes up space on a block
|
|
* during rendering.
|
|
*/
|
|
export class InputConnection extends Connection {
|
|
align: number;
|
|
connectedBlock: BlockSvg | null;
|
|
connectedBlockWidth: number;
|
|
connectedBlockHeight: number;
|
|
connectionOffsetX = 0;
|
|
connectionOffsetY = 0;
|
|
|
|
/**
|
|
* @param constants The rendering constants provider.
|
|
* @param input The input to measure and store information for.
|
|
*/
|
|
constructor(constants: ConstantProvider, public input: Input) {
|
|
super(constants, input.connection as RenderedConnection);
|
|
|
|
this.type |= Types.INPUT;
|
|
|
|
this.align = input.align;
|
|
|
|
this.connectedBlock =
|
|
input.connection && input.connection.targetBlock()
|
|
? (input.connection.targetBlock() as BlockSvg)
|
|
: null;
|
|
|
|
if (this.connectedBlock) {
|
|
const bBox = this.connectedBlock.getHeightWidth();
|
|
this.connectedBlockWidth = bBox.width;
|
|
this.connectedBlockHeight = bBox.height;
|
|
} else {
|
|
this.connectedBlockWidth = 0;
|
|
this.connectedBlockHeight = 0;
|
|
}
|
|
}
|
|
}
|