Skip to content

Commit

Permalink
fix: pull in changes from core
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Oct 9, 2023
1 parent 6694eb7 commit fab62bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
14 changes: 7 additions & 7 deletions plugins/field-colour/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions plugins/field-colour/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"@blockly/dev-scripts": "^2.0.1",
"@blockly/dev-tools": "^7.1.0",
"@typescript-eslint/parser": "^5.59.5",
"blockly": "^10.0.0",
"blockly": "^10.2.0",
"chai": "^4.2.0",
"sinon": "^9.0.1",
"typescript": "^5.0.4"
},
"peerDependencies": {
"blockly": "^10.0.0"
"blockly": "^10.2.0"
},
"publishConfig": {
"access": "public",
Expand Down
33 changes: 12 additions & 21 deletions plugins/field-colour/src/field_colour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,9 @@ export class FieldColour extends Blockly.Field<string> {

const block = this.getSourceBlock() as Blockly.BlockSvg | null;
if (!block) throw new Blockly.UnattachedFieldError();
// In general, do *not* let fields control the color of blocks. Having the
// field control the color is unexpected, and could have performance
// impacts.
// Whenever we render, the field may no longer be a full-block-field so
// we need to update the colour.
if (this.getConstants()!.FIELD_COLOUR_FULL_BLOCK) block.applyColour();
// Calling applyColour updates the UI (full-block vs non-full-block) for the
// colour field, and the colour of the field/block.
block.applyColour();
}

/**
Expand All @@ -249,26 +246,20 @@ export class FieldColour extends Blockly.Field<string> {
// eslint-disable-next-line @typescript-eslint/naming-convention
protected updateSize_(margin?: number) {
const constants = this.getConstants();
const xOffset =
margin !== undefined ?
margin : !this.isFullBlockField() ?
constants!.FIELD_BORDER_RECT_X_PADDING : 0;
let totalWidth = xOffset * 2;
let contentWidth = 0;
if (!this.isFullBlockField()) {
contentWidth = constants!.FIELD_COLOUR_DEFAULT_WIDTH;
totalWidth += contentWidth;
}

let totalHeight = constants!.FIELD_TEXT_HEIGHT;
if (!this.isFullBlockField()) {
totalHeight = Math.max(totalHeight, constants!.FIELD_BORDER_RECT_HEIGHT);
let totalWidth;
let totalHeight;
if (this.isFullBlockField()) {
const xOffset = margin ?? 0;
totalWidth = xOffset * 2;
totalHeight = constants!.FIELD_TEXT_HEIGHT;
} else {
totalWidth = constants!.FIELD_COLOUR_DEFAULT_WIDTH;
totalHeight = constants!.FIELD_COLOUR_DEFAULT_HEIGHT;
}

this.size_.height = totalHeight;
this.size_.width = totalWidth;

this.positionTextElement_(xOffset, contentWidth);
this.positionBorderRect_();
}

Expand Down

0 comments on commit fab62bf

Please sign in to comment.