fix: remove old icon handling code (#7141)

* fix: remove old icon handling code

* fix: remove calls to getCommentIcon

* chore: delete the old icon class
This commit is contained in:
Beka Westberg
2023-06-13 15:41:07 -07:00
committed by GitHub
parent c6fbb85a69
commit aeee278767
13 changed files with 38 additions and 326 deletions

View File

@@ -22,7 +22,7 @@ import {Types} from '../measurables/types.js';
import {isDynamicShape} from './constants.js';
import type {ConstantProvider, Notch, PuzzleTab} from './constants.js';
import type {RenderInfo} from './info.js';
import {isIcon} from '../../interfaces/i_icon.js';
import * as deprecation from '../../utils/deprecation.js';
/**
* An object that draws a block based on the given rendering information.
@@ -59,7 +59,6 @@ export class Drawer {
* required.
*/
draw() {
this.hideHiddenIcons_();
this.drawOutline_();
this.drawInternals_();
@@ -70,6 +69,16 @@ export class Drawer {
this.recordSizeOnBlock_();
}
/**
* Hide icons that were marked as hidden.
*
* @deprecated Manually hiding icons is no longer necessary. To be removed
* in v11.
*/
protected hideHiddenIcons_() {
deprecation.warn('hideHiddenIcons_', 'v10', 'v11');
}
/**
* Save sizing information back to the block
* Most of the rendering information can be thrown away at the end of the
@@ -83,13 +92,6 @@ export class Drawer {
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_();
@@ -291,10 +293,6 @@ export class Drawer {
* @param fieldInfo The rendering information for the field or icon.
*/
protected layoutField_(fieldInfo: Icon | Field) {
const svgGroup = Types.isField(fieldInfo)
? (fieldInfo as Field).field.getSvgRoot()!
: (fieldInfo as Icon).icon.iconGroup_!; // Never null in rendered case.
const yPos = fieldInfo.centerline - fieldInfo.height / 2;
let xPos = fieldInfo.xPos;
let scale = '';
@@ -305,36 +303,20 @@ export class Drawer {
scale = 'scale(-1 1)';
}
}
if (Types.isIcon(fieldInfo)) {
const icon = (fieldInfo as Icon).icon;
if (isIcon(icon)) {
icon.setOffsetInBlock(new Coordinate(xPos, yPos));
} else {
// TODO (#7042): Remove old icon handling code.
svgGroup.setAttribute('display', 'block');
svgGroup.setAttribute(
'transform',
'translate(' + xPos + ',' + yPos + ')'
);
(fieldInfo as Icon).icon.computeIconLocation();
icon.setOffsetInBlock(new Coordinate(xPos, yPos));
if (this.info_.isInsertionMarker) {
icon.hideForInsertionMarker();
}
} else {
const svgGroup = (fieldInfo as Field).field.getSvgRoot()!;
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.
// TODO (#7042): Figure out a better way to handle the types here,
// possibly by splitting this method into submethods.
if (Types.isIcon(fieldInfo) && isIcon((fieldInfo as Icon).icon)) {
(
(fieldInfo as Icon).icon as AnyDuringMigration
).hideForInsertionMarker();
} else {
if (this.info_.isInsertionMarker) {
svgGroup.setAttribute('display', 'none');
}
}

View File

@@ -75,8 +75,6 @@ export class RenderInfo {
/** An array of input rows on the block. */
inputRows: InputRow[] = [];
/** An array of measurable objects containing hidden icons. */
hiddenIcons: Icon[] = [];
topRow: TopRow;
bottomRow: BottomRow;
@@ -174,9 +172,7 @@ export class RenderInfo {
const icons = this.block_.getIcons();
for (let i = 0, icon; (icon = icons[i]); i++) {
const iconInfo = new Icon(this.constants_, icon);
if (this.isCollapsed && icon.collapseHidden) {
this.hiddenIcons.push(iconInfo);
} else {
if (!this.isCollapsed || icon.isShownWhenCollapsed()) {
activeRow.elements.push(iconInfo);
}
}

View File

@@ -39,7 +39,6 @@ export class Drawer extends BaseDrawer {
}
override draw() {
this.hideHiddenIcons_();
this.drawOutline_();
this.drawInternals_();

View File

@@ -8,13 +8,12 @@ import * as goog from '../../../closure/goog/goog.js';
goog.declareModuleId('Blockly.blockRendering.Icon');
/* eslint-disable-next-line no-unused-vars */
import type {Icon as BlocklyIcon} from '../../icon_old.js';
import type {IIcon as BlocklyIcon} from '../../interfaces/i_icon.js';
import type {ConstantProvider} from '../common/constants.js';
import {Measurable} from './base.js';
import {Types} from './types.js';
import {hasBubble} from '../../interfaces/i_has_bubble.js';
import {isIcon} from '../../interfaces/i_icon.js';
/**
* An object containing information about the space an icon takes up during
@@ -38,15 +37,10 @@ export class Icon extends Measurable {
constructor(constants: ConstantProvider, public icon: BlocklyIcon) {
super(constants);
// TODO(#7042): Remove references to old icon API.
this.isVisible =
(icon.isVisible && icon.isVisible()) ||
(hasBubble(icon) && icon.bubbleIsVisible());
this.isVisible = hasBubble(icon) && icon.bubbleIsVisible();
this.type |= Types.ICON;
const size =
(icon.getCorrectedSize && icon.getCorrectedSize()) ||
(isIcon(icon) && icon.getSize());
const size = icon.getSize();
this.height = size.height;
this.width = size.width;
}

View File

@@ -40,7 +40,6 @@ export class Drawer extends BaseDrawer {
override draw() {
const pathObject = this.block_.pathObject as PathObject;
pathObject.beginDrawing();
this.hideHiddenIcons_();
this.drawOutline_();
this.drawInternals_();