mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
fix!: refactor mutator icon (#7115)
* feat: add basic mutator icon * feat: add actual mutation behavior to icon * chore: add bumping blocks back into the bubble * fix: add updating block styles * feat: add static methods to mutator icon * chore: delete old mutator code * fix: use the new mutator icon * chore: docs and format * chore: my own comments * chore: first pass at PR comments * chore: make type strings internal * chore: add todo * chore: format * chore: move properties to module level * chore: fix using in demos * chore: move Mutator to icons.MutatorIcon * chore: move reconnect to connection * chore: move findParentWs to workspace * chore: properly override and call super * chore: remove bubbleIsVisible check * chore: change imports to import type * chore: use elvis operator * chore: update renamings * chore: reduce changes to js block files
This commit is contained in:
@@ -15,7 +15,7 @@ import type {Connection} from '../core/connection.js';
|
||||
import type {BlockSvg} from '../core/block_svg.js';
|
||||
import type {FieldDropdown} from '../core/field_dropdown.js';
|
||||
import {Msg} from '../core/msg.js';
|
||||
import {Mutator} from '../core/mutator.js';
|
||||
import {MutatorIcon} from '../core/icons/mutator_icon.js';
|
||||
import type {Workspace} from '../core/workspace.js';
|
||||
import {
|
||||
createBlockDefinitionsFromJsonArray,
|
||||
@@ -130,7 +130,7 @@ const LISTS_CREATE_WITH = {
|
||||
this.updateShape_();
|
||||
this.setOutput(true, 'Array');
|
||||
this.setMutator(
|
||||
new Mutator(['lists_create_with_item'], this as unknown as BlockSvg)
|
||||
new MutatorIcon(['lists_create_with_item'], this as unknown as BlockSvg)
|
||||
); // BUG(#6905)
|
||||
this.setTooltip(Msg['LISTS_CREATE_WITH_TOOLTIP']);
|
||||
},
|
||||
@@ -232,7 +232,7 @@ const LISTS_CREATE_WITH = {
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (let i = 0; i < this.itemCount_; i++) {
|
||||
Mutator.reconnect(connections[i], this, 'ADD' + i);
|
||||
connections[i]?.reconnect(this, 'ADD' + i);
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -24,13 +24,14 @@ const {Block} = goog.requireType('Blockly.Block');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const BlockDefinition = Object;
|
||||
const {Msg} = goog.require('Blockly.Msg');
|
||||
const {Mutator} = goog.require('Blockly.Mutator');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.Mutator');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldDropdown');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldLabel');
|
||||
@@ -519,10 +520,10 @@ const CONTROLS_IF_MUTATOR_MIXIN = {
|
||||
reconnectChildBlocks_: function(
|
||||
valueConnections, statementConnections, elseStatementConnection) {
|
||||
for (let i = 1; i <= this.elseifCount_; i++) {
|
||||
Mutator.reconnect(valueConnections[i], this, 'IF' + i);
|
||||
Mutator.reconnect(statementConnections[i], this, 'DO' + i);
|
||||
valueConnections[i]?.reconnect(this, 'IF' + i);
|
||||
statementConnections[i]?.reconnect(this, 'DO' + i);
|
||||
}
|
||||
Mutator.reconnect(elseStatementConnection, this, 'ELSE');
|
||||
elseStatementConnection?.reconnect(this, 'ELSE');
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ const {Block} = goog.requireType('Blockly.Block');
|
||||
const BlockDefinition = Object;
|
||||
const {config} = goog.require('Blockly.config');
|
||||
const {Msg} = goog.require('Blockly.Msg');
|
||||
const {Mutator} = goog.require('Blockly.Mutator');
|
||||
const {MutatorIcon: Mutator} = goog.require('Blockly.Mutator');
|
||||
const {Names} = goog.require('Blockly.Names');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {VariableModel} = goog.requireType('Blockly.VariableModel');
|
||||
@@ -290,7 +290,7 @@ const PROCEDURE_DEF_COMMON = {
|
||||
if (hasStatements) {
|
||||
this.setStatements_(true);
|
||||
// Restore the stack, if one was saved.
|
||||
Mutator.reconnect(this.statementConnection_, this, 'STACK');
|
||||
this.statementConnection_?.reconnect(this, 'STACK');
|
||||
this.statementConnection_ = null;
|
||||
} else {
|
||||
// Save the stack, then disconnect it.
|
||||
@@ -388,8 +388,9 @@ const PROCEDURE_DEF_COMMON = {
|
||||
displayRenamedVar_: function(oldName, newName) {
|
||||
this.updateParams_();
|
||||
// Update the mutator's variables if the mutator is open.
|
||||
if (this.mutator && this.mutator.isVisible()) {
|
||||
const blocks = this.mutator.workspace_.getAllBlocks(false);
|
||||
const mutator = this.getIcon(Mutator.TYPE);
|
||||
if (mutator && mutator.bubbleIsVisible()) {
|
||||
const blocks = mutator.getWorkspace().getAllBlocks(false);
|
||||
for (let i = 0, block; (block = blocks[i]); i++) {
|
||||
if (block.type === 'procedures_mutatorarg' &&
|
||||
Names.equals(oldName, block.getFieldValue('NAME'))) {
|
||||
@@ -616,7 +617,7 @@ blocks['procedures_mutatorarg'] = {
|
||||
*/
|
||||
validator_: function(varName) {
|
||||
const sourceBlock = this.getSourceBlock();
|
||||
const outerWs = Mutator.findParentWs(sourceBlock.workspace);
|
||||
const outerWs = sourceBlock.workspace.getRootWorkspace();
|
||||
varName = varName.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, '');
|
||||
if (!varName) {
|
||||
return null;
|
||||
@@ -667,7 +668,7 @@ blocks['procedures_mutatorarg'] = {
|
||||
* @this {FieldTextInput}
|
||||
*/
|
||||
deleteIntermediateVars_: function(newText) {
|
||||
const outerWs = Mutator.findParentWs(this.getSourceBlock().workspace);
|
||||
const outerWs = this.getSourceBlock().workspace.getRootWorkspace();
|
||||
if (!outerWs) {
|
||||
return;
|
||||
}
|
||||
@@ -731,8 +732,9 @@ const PROCEDURE_CALL_COMMON = {
|
||||
// which might reappear if a param is reattached in the mutator.
|
||||
const defBlock =
|
||||
Procedures.getDefinition(this.getProcedureCall(), this.workspace);
|
||||
const mutatorIcon = defBlock && defBlock.getIcon(Mutator.TYPE);
|
||||
const mutatorOpen =
|
||||
defBlock && defBlock.mutator && defBlock.mutator.isVisible();
|
||||
mutatorIcon && mutatorIcon.bubbleIsVisible();
|
||||
if (!mutatorOpen) {
|
||||
this.quarkConnections_ = {};
|
||||
this.quarkIds_ = null;
|
||||
@@ -788,7 +790,7 @@ const PROCEDURE_CALL_COMMON = {
|
||||
const quarkId = this.quarkIds_[i];
|
||||
if (quarkId in this.quarkConnections_) {
|
||||
const connection = this.quarkConnections_[quarkId];
|
||||
if (!Mutator.reconnect(connection, this, 'ARG' + i)) {
|
||||
if (!connection?.reconnect(this, 'ARG' + i)) {
|
||||
// Block no longer exists or has been attached elsewhere.
|
||||
delete this.quarkConnections_[quarkId];
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import {FieldImage} from '../core/field_image.js';
|
||||
import {FieldDropdown} from '../core/field_dropdown.js';
|
||||
import {FieldTextInput} from '../core/field_textinput.js';
|
||||
import {Msg} from '../core/msg.js';
|
||||
import {Mutator} from '../core/mutator.js';
|
||||
import {MutatorIcon} from '../core/icons/mutator_icon.js';
|
||||
import type {Workspace} from '../core/workspace.js';
|
||||
import {
|
||||
createBlockDefinitionsFromJsonArray,
|
||||
@@ -832,7 +832,7 @@ const JOIN_MUTATOR_MIXIN = {
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (let i = 0; i < this.itemCount_; i++) {
|
||||
Mutator.reconnect(connections[i]!, this, 'ADD' + i);
|
||||
connections[i]?.reconnect(this, 'ADD' + i);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -892,7 +892,7 @@ const JOIN_EXTENSION = function (this: JoinMutatorBlock) {
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
// Configure the mutator UI.
|
||||
this.setMutator(new Mutator(['text_create_join_item'], this));
|
||||
this.setMutator(new MutatorIcon(['text_create_join_item'], this));
|
||||
};
|
||||
|
||||
// Update the tooltip of 'text_append' block to reference the variable.
|
||||
|
||||
Reference in New Issue
Block a user