From ac33877d7dda5721b8872149e58db0ccfc54131e Mon Sep 17 00:00:00 2001 From: Maribeth Moffatt Date: Mon, 11 May 2026 17:07:55 -0400 Subject: [PATCH] fix!: set full block field status explicitly (#9840) * fix!: set full block field status explicitly * chore: grammar --- packages/blockly/core/field.ts | 24 ++++++++++++++---------- packages/blockly/core/field_dropdown.ts | 15 +++++++++++++++ packages/blockly/core/field_input.ts | 13 ++++++++++--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/packages/blockly/core/field.ts b/packages/blockly/core/field.ts index dbf16edd7..2b48b91f8 100644 --- a/packages/blockly/core/field.ts +++ b/packages/blockly/core/field.ts @@ -441,15 +441,19 @@ export abstract class Field /** * Defines whether this field should take up the full block or not. * - * Be cautious when overriding this function. It may not work as you expect / - * intend because the behavior was kind of hacked in. If you are thinking - * about overriding this function, post on the forum with your intended - * behavior to see if there's another approach. + * This is typically only done for certain kinds of fields and in certain + * renderers. You should only override this if you're sure your field will + * render correctly in zelos and other renderers that support full-block + * fields. * - * @internal + * Blocks that contain only a single field that is a full-block-field + * have a special appearance in some renderers and their behavior is + * unique, because we pretend that the field is a whole block in some cases. + * This is hacky and you should use caution when attempting to do anything + * with this method. */ isFullBlockField(): boolean { - return !this.borderRect_; + return false; } /** @@ -928,7 +932,7 @@ export abstract class Field const xOffset = margin !== undefined ? margin - : !this.isFullBlockField() + : this.borderRect_ ? this.getConstants()!.FIELD_BORDER_RECT_X_PADDING : 0; let totalWidth = xOffset * 2; @@ -939,7 +943,7 @@ export abstract class Field contentWidth = dom.getTextWidth(this.textElement_); totalWidth += contentWidth; } - if (!this.isFullBlockField()) { + if (this.borderRect_) { totalHeight = Math.max(totalHeight, constants!.FIELD_BORDER_RECT_HEIGHT); } @@ -1036,7 +1040,7 @@ export abstract class Field throw new UnattachedFieldError(); } - if (this.isFullBlockField()) { + if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. // - Webkit / Blink: fill-box / object bounding box // - Gecko: stroke-box @@ -1054,7 +1058,7 @@ export abstract class Field xy.y -= 0.5 * scale; } } else { - const bBox = this.borderRect_!.getBoundingClientRect(); + const bBox = this.borderRect_.getBoundingClientRect(); xy = style.getPageOffset(this.borderRect_!); scaledWidth = bBox.width; scaledHeight = bBox.height; diff --git a/packages/blockly/core/field_dropdown.ts b/packages/blockly/core/field_dropdown.ts index d7699606b..8eeea3026 100644 --- a/packages/blockly/core/field_dropdown.ts +++ b/packages/blockly/core/field_dropdown.ts @@ -208,6 +208,21 @@ export class FieldDropdown extends Field { this.isInitialized = true; } + /** + * This is hacky way of determining if a dropdown field is a full-block field or not. + * The constants that control the border rect are the same ones that determine how we + * render full-block dropdown fields. It's a full-block field if it doesn't have the + * border rect (and it's a simple reporter block). + * + * @returns true if this field should be treated as a full-block field + */ + override isFullBlockField(): boolean { + return ( + !this.shouldAddBorderRect_() && + !!this.getSourceBlock()?.isSimpleReporter() + ); + } + /** * Whether or not the dropdown should add a border rect. * diff --git a/packages/blockly/core/field_input.ts b/packages/blockly/core/field_input.ts index 48404b357..731c1ca76 100644 --- a/packages/blockly/core/field_input.ts +++ b/packages/blockly/core/field_input.ts @@ -166,7 +166,15 @@ export abstract class FieldInput extends Field< override initView() { const block = this.getSourceBlock(); if (!block) throw new UnattachedFieldError(); - super.initView(); + + if (!this.isFullBlockField()) { + // Full-block fields don't get the border-rect element. + this.createBorderRect_(); + } + this.createTextElement_(); + if (this.fieldGroup_) { + dom.addClass(this.fieldGroup_, 'blocklyField'); + } if (this.isFullBlockField()) { this.clickTarget_ = (this.sourceBlock_ as BlockSvg).getSvgRoot(); @@ -254,10 +262,9 @@ export abstract class FieldInput extends Field< if (!this.fieldGroup_) return; if (!this.isFullBlockField() && this.borderRect_) { - this.borderRect_!.style.display = 'block'; + this.borderRect_.style.display = 'block'; this.borderRect_.setAttribute('stroke', block.getColourTertiary()); } else { - this.borderRect_!.style.display = 'none'; // In general, do *not* let fields control the color of blocks. Having the // field control the color is unexpected, and could have performance // impacts.