Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/google/blockly into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel committed Sep 29, 2022
2 parents bba3b27 + 8530e6d commit 7ec0670
Show file tree
Hide file tree
Showing 233 changed files with 2,801 additions and 2,864 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: source ./tests/scripts/update_metadata.sh

- name: Create Pull Request
uses: peter-evans/create-pull-request@18f90432bedd2afd6a825469ffd38aa24712a91d
uses: peter-evans/create-pull-request@171dd555b9ab6b18fa02519fdfacbb8bf671e1b4
with:
commit-message: Update build artifact sizes in check_metadata.sh
delete-branch: true
Expand Down
18 changes: 9 additions & 9 deletions blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ blocks['lists_create_with'] = {
this.itemCount_ = 3;
this.updateShape_();
this.setOutput(true, 'Array');
this.setMutator(new Mutator(['lists_create_with_item']));
this.setMutator(new Mutator(['lists_create_with_item'], this));
this.setTooltip(Msg['LISTS_CREATE_WITH_TOOLTIP']);
},
/**
Expand Down Expand Up @@ -858,23 +858,23 @@ blocks['lists_sort'] = {
*/
init: function() {
this.jsonInit({
'message0': Msg['LISTS_SORT_TITLE'],
'message0': '%{BKY_LISTS_SORT_TITLE}',
'args0': [
{
'type': 'field_dropdown',
'name': 'TYPE',
'options': [
[Msg['LISTS_SORT_TYPE_NUMERIC'], 'NUMERIC'],
[Msg['LISTS_SORT_TYPE_TEXT'], 'TEXT'],
[Msg['LISTS_SORT_TYPE_IGNORECASE'], 'IGNORE_CASE'],
['%{BKY_LISTS_SORT_TYPE_NUMERIC}', 'NUMERIC'],
['%{BKY_LISTS_SORT_TYPE_TEXT}', 'TEXT'],
['%{BKY_LISTS_SORT_TYPE_IGNORECASE}', 'IGNORE_CASE'],
],
},
{
'type': 'field_dropdown',
'name': 'DIRECTION',
'options': [
[Msg['LISTS_SORT_ORDER_ASCENDING'], '1'],
[Msg['LISTS_SORT_ORDER_DESCENDING'], '-1'],
['%{BKY_LISTS_SORT_ORDER_ASCENDING}', '1'],
['%{BKY_LISTS_SORT_ORDER_DESCENDING}', '-1'],
],
},
{
Expand All @@ -885,8 +885,8 @@ blocks['lists_sort'] = {
],
'output': 'Array',
'style': 'list_blocks',
'tooltip': Msg['LISTS_SORT_TOOLTIP'],
'helpUrl': Msg['LISTS_SORT_HELPURL'],
'tooltip': '%{BKY_LISTS_SORT_TOOLTIP}',
'helpUrl': '%{BKY_LISTS_SORT_HELPURL}',
});
},
};
Expand Down
4 changes: 2 additions & 2 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ blocks['procedures_defnoreturn'] = {
.appendField(Msg['PROCEDURES_DEFNORETURN_TITLE'])
.appendField(nameField, 'NAME')
.appendField('', 'PARAMS');
this.setMutator(new Mutator(['procedures_mutatorarg']));
this.setMutator(new Mutator(['procedures_mutatorarg'], this));
if ((this.workspace.options.comments ||
(this.workspace.options.parentWorkspace &&
this.workspace.options.parentWorkspace.options.comments)) &&
Expand Down Expand Up @@ -507,7 +507,7 @@ blocks['procedures_defreturn'] = {
this.appendValueInput('RETURN')
.setAlign(Align.RIGHT)
.appendField(Msg['PROCEDURES_DEFRETURN_RETURN']);
this.setMutator(new Mutator(['procedures_mutatorarg']));
this.setMutator(new Mutator(['procedures_mutatorarg'], this));
if ((this.workspace.options.comments ||
(this.workspace.options.parentWorkspace &&
this.workspace.options.parentWorkspace.options.comments)) &&
Expand Down
2 changes: 1 addition & 1 deletion blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ const TEXT_JOIN_EXTENSION = function() {
this.itemCount_ = 2;
this.updateShape_();
// Configure the mutator UI.
this.setMutator(new Mutator(['text_create_join_item']));
this.setMutator(new Mutator(['text_create_join_item'], this));
};

// Update the tooltip of 'text_append' block to reference the variable.
Expand Down
31 changes: 23 additions & 8 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export class Block implements IASTNodeLocation, IDeletable {
protected collapsed_ = false;
protected outputShape_: number|null = null;

/**
* Is the current block currently in the process of being disposed?
*/
private disposing = false;

/**
* A string representing the comment attached to this block.
*
Expand Down Expand Up @@ -316,7 +321,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @suppress {checkTypes}
*/
dispose(healStack: boolean) {
if (this.disposed) {
if (this.isDeadOrDying()) {
return;
}

Expand All @@ -338,6 +343,7 @@ export class Block implements IASTNodeLocation, IDeletable {
this.workspace.removeTypedBlock(this);
// Remove from block database.
this.workspace.removeBlockById(this.id);
this.disposing = true;

// First, dispose of all my children.
for (let i = this.childBlocks_.length - 1; i >= 0; i--) {
Expand All @@ -360,6 +366,16 @@ export class Block implements IASTNodeLocation, IDeletable {
}
}

/**
* Returns true if the block is either in the process of being disposed, or
* is disposed.
*
* @internal
*/
isDeadOrDying(): boolean {
return this.disposing || this.disposed;
}

/**
* Call initModel on all fields on the block.
* May be called more than once.
Expand Down Expand Up @@ -580,13 +596,11 @@ export class Block implements IASTNodeLocation, IDeletable {
*/
getSurroundParent(): this|null {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block = this;
let block: this|null = this;
let prevBlock;
do {
prevBlock = block;
// AnyDuringMigration because: Type 'Block | null' is not assignable to
// type 'this'.
block = block.getParent() as AnyDuringMigration;
block = block.getParent();
if (!block) {
// Ran off the top.
return null;
Expand Down Expand Up @@ -774,7 +788,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @returns True if deletable.
*/
isDeletable(): boolean {
return this.deletable_ && !this.isShadow_ && !this.disposed &&
return this.deletable_ && !this.isShadow_ && !this.isDeadOrDying() &&
!this.workspace.options.readOnly;
}

Expand All @@ -793,7 +807,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @returns True if movable.
*/
isMovable(): boolean {
return this.movable_ && !this.isShadow_ && !this.disposed &&
return this.movable_ && !this.isShadow_ && !this.isDeadOrDying() &&
!this.workspace.options.readOnly;
}

Expand Down Expand Up @@ -867,7 +881,8 @@ export class Block implements IASTNodeLocation, IDeletable {
* @returns True if editable.
*/
isEditable(): boolean {
return this.editable_ && !this.disposed && !this.workspace.options.readOnly;
return this.editable_ && !this.isDeadOrDying() &&
!this.workspace.options.readOnly;
}

/**
Expand Down
43 changes: 19 additions & 24 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
*
* @returns #RRGGBB string.
*/
getColourSecondary(): string|null {
getColourSecondary(): string|undefined {
return this.style.colourSecondary;
}

Expand All @@ -250,7 +250,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
*
* @returns #RRGGBB string.
*/
getColourTertiary(): string|null {
getColourTertiary(): string|undefined {
return this.style.colourTertiary;
}

Expand Down Expand Up @@ -525,7 +525,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,

/** Snap this block to the nearest grid point. */
snapToGrid() {
if (this.disposed) {
if (this.isDeadOrDying()) {
return; // Deleted block.
}
if (this.workspace.isDragging()) {
Expand Down Expand Up @@ -778,10 +778,10 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
(group as AnyDuringMigration).translate_ = '';
(group as AnyDuringMigration).skew_ = '';
common.draggingConnections.push(...this.getConnections_(true));
this.svgGroup_.classList.add('blocklyDragging');
dom.addClass(this.svgGroup_, 'blocklyDragging');
} else {
common.draggingConnections.length = 0;
this.svgGroup_.classList.remove('blocklyDragging');
dom.removeClass(this.svgGroup_, 'blocklyDragging');
}
// Recurse through all blocks attached under this one.
for (let i = 0; i < this.childBlocks_.length; i++) {
Expand Down Expand Up @@ -861,8 +861,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
* @suppress {checkTypes}
*/
override dispose(healStack?: boolean, animate?: boolean) {
if (this.disposed) {
// The block has already been deleted.
if (this.isDeadOrDying()) {
return;
}
Tooltip.dispose();
Expand Down Expand Up @@ -952,9 +951,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
return null;
}
return {
saveInfo: blocks.save(
this,
{addCoordinates: true, addNextBlocks: false}) as
saveInfo:
blocks.save(this, {addCoordinates: true, addNextBlocks: false}) as
blocks.State,
source: this.workspace,
typeCounts: common.getBlockTypeCounts(this, true),
Expand Down Expand Up @@ -1068,13 +1066,12 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
if (this.workspace.isDragging()) {
// Don't change the warning text during a drag.
// Wait until the drag finishes.
this.warningTextDb.set(
id, setTimeout(() => {
if (!this.disposed) { // Check block wasn't deleted.
this.warningTextDb.delete(id);
this.setWarningText(text, id);
}
}, 100));
this.warningTextDb.set(id, setTimeout(() => {
if (!this.isDeadOrDying()) {
this.warningTextDb.delete(id);
this.setWarningText(text, id);
}
}, 100));
return;
}
if (this.isInFlyout) {
Expand Down Expand Up @@ -1268,7 +1265,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
*/
bringToFront() {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block = this;
let block: this|null = this;
do {
const root = block.getSvgRoot();
const parent = root.parentNode;
Expand All @@ -1277,9 +1274,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
if (childNodes[childNodes.length - 1] !== root) {
parent!.appendChild(root);
}
// AnyDuringMigration because: Type 'BlockSvg | null' is not assignable
// to type 'this'.
block = block.getParent() as AnyDuringMigration;
block = block.getParent();
} while (block);
}

Expand Down Expand Up @@ -1544,11 +1539,11 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
* connected should not coincidentally line up on screen.
*/
override bumpNeighbours() {
if (this.disposed) {
return; // Deleted block.
if (this.isDeadOrDying()) {
return;
}
if (this.workspace.isDragging()) {
return; // Don't bump blocks during a drag.
return;
}
const rootBlock = this.getRootBlock();
if (rootBlock.isInFlyout) {
Expand Down
5 changes: 3 additions & 2 deletions core/blockly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ import {MarkerManager} from './marker_manager.js';
import {Menu} from './menu.js';
import {MenuItem} from './menuitem.js';
import {MetricsManager} from './metrics_manager.js';
import {Msg} from './msg.js';
import {Msg, setLocale} from './msg.js';
import {Mutator} from './mutator.js';
import {Names} from './names.js';
import {Options} from './options.js';
Expand Down Expand Up @@ -560,6 +560,7 @@ export const VARIABLE_DYNAMIC_CATEGORY_NAME: string =
*/
export const PROCEDURE_CATEGORY_NAME: string = Procedures.CATEGORY_NAME;


// Context for why we need to monkey-patch in these functions (internal):
// https://docs.google.com/document/d/1MbO0LEA-pAyx1ErGLJnyUqTLrcYTo-5zga9qplnxeXo/edit?usp=sharing&resourcekey=0-5h_32-i-dHwHjf_9KYEVKg

Expand Down Expand Up @@ -720,7 +721,7 @@ export {Menu};
export {MenuItem};
export {MetricsManager};
export {Mutator};
export {Msg};
export {Msg, setLocale};
export {Names};
export {Options};
export {RenderedConnection};
Expand Down
8 changes: 4 additions & 4 deletions core/bump_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ function extractObjectFromEvent(
switch (e.type) {
case eventUtils.BLOCK_CREATE:
case eventUtils.BLOCK_MOVE:
object = workspace.getBlockById((e as BlockCreate | BlockMove).blockId);
object = workspace.getBlockById((e as BlockCreate | BlockMove).blockId!);
if (object) {
object = object.getRootBlock();
}
break;
case eventUtils.COMMENT_CREATE:
case eventUtils.COMMENT_MOVE:
object = workspace.getCommentById(
(e as CommentCreate | CommentMove).commentId) as
WorkspaceCommentSvg |
object =
workspace.getCommentById((e as CommentCreate | CommentMove).commentId!
) as WorkspaceCommentSvg |
null;
break;
}
Expand Down
Loading

0 comments on commit 7ec0670

Please sign in to comment.