mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
* fix(build): Restore erroneously-deleted filter function This was deleted in PR #7406 as it was mainly being used to filter core/ vs. test/mocha/ deps into separate deps files - but it turns out also to be used for filtering error messages too. Oops. * refactor(tests): Migrate advanced compilation test to ES Modules * refactor(build): Migrate main.js to TypeScript This turns out to be pretty straight forward, even if it would cause crashing if one actually tried to import this module instead of just feeding it to Closure Compiler. * chore(build): Remove goog.declareModuleId calls Replace goog.declareModuleId calls with a comment recording the former module ID for posterity (or at least until we decide how to reformat the renamings file. * chore(tests): Delete closure/goog/* For the moment we still need something to serve as base.js for the benefit of closure-make-deps, so we keep a vestigial base.js around, containing only the @provideGoog declaration. * refactor(build): Remove vestigial base.js By changing slightly the command line arguments to closure-make-deps and closure-calculate-chunks the need to have any base.js is eliminated. * chore: Typo fix for PR #7415
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
// Former goog.module ID: Blockly.blockRendering.TopRow
|
|
|
|
import type {BlockSvg} from '../../block_svg.js';
|
|
import type {ConstantProvider} from '../common/constants.js';
|
|
|
|
import {Hat} from './hat.js';
|
|
import type {PreviousConnection} from './previous_connection.js';
|
|
import {Row} from './row.js';
|
|
import {Types} from './types.js';
|
|
|
|
/**
|
|
* An object containing information about what elements are in the top row of a
|
|
* block as well as sizing information for the top row.
|
|
* Elements in a top row can consist of corners, hats, spacers, and previous
|
|
* connections.
|
|
* After this constructor is called, the row will contain all non-spacer
|
|
* elements it needs.
|
|
*/
|
|
export class TopRow extends Row {
|
|
/**
|
|
* The starting point for drawing the row, in the y direction.
|
|
* This allows us to draw hats and similar shapes that don't start at the
|
|
* origin. Must be non-negative (see #2820).
|
|
*/
|
|
capline = 0;
|
|
|
|
/** How much the row extends up above its capline. */
|
|
ascenderHeight = 0;
|
|
|
|
/** Whether the block has a previous connection. */
|
|
hasPreviousConnection = false;
|
|
|
|
/** The previous connection on the block, if any. */
|
|
connection: PreviousConnection | null = null;
|
|
|
|
/**
|
|
* @param constants The rendering constants provider.
|
|
*/
|
|
constructor(constants: ConstantProvider) {
|
|
super(constants);
|
|
|
|
this.type |= Types.TOP_ROW;
|
|
}
|
|
|
|
/**
|
|
* Returns whether or not the top row has a left square corner.
|
|
*
|
|
* @param block The block whose top row this represents.
|
|
* @returns Whether or not the top row has a left square corner.
|
|
*/
|
|
hasLeftSquareCorner(block: BlockSvg): boolean {
|
|
const hasHat =
|
|
(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)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns whether or not the top row has a right square corner.
|
|
*
|
|
* @param _block The block whose top row this represents.
|
|
* @returns Whether or not the top row has a right square corner.
|
|
*/
|
|
hasRightSquareCorner(_block: BlockSvg): boolean {
|
|
return true;
|
|
}
|
|
|
|
override measure() {
|
|
let height = 0;
|
|
let width = 0;
|
|
let ascenderHeight = 0;
|
|
for (let i = 0; i < this.elements.length; i++) {
|
|
const elem = this.elements[i];
|
|
width += elem.width;
|
|
if (!Types.isSpacer(elem)) {
|
|
if (Types.isHat(elem) && elem instanceof Hat) {
|
|
ascenderHeight = Math.max(ascenderHeight, elem.ascenderHeight);
|
|
} else {
|
|
height = Math.max(height, elem.height);
|
|
}
|
|
}
|
|
}
|
|
this.width = Math.max(this.minWidth, width);
|
|
this.height = Math.max(this.minHeight, height) + ascenderHeight;
|
|
this.ascenderHeight = ascenderHeight;
|
|
this.capline = this.ascenderHeight;
|
|
this.widthWithConnectedBlocks = this.width;
|
|
}
|
|
|
|
override startsWithElemSpacer() {
|
|
return false;
|
|
}
|
|
|
|
override endsWithElemSpacer() {
|
|
return false;
|
|
}
|
|
}
|