feat!: Invalid Blocks (#7958)

* feat: Invalid Blocks

* Rename the new json property from invalid to invalidReasons.

* Merged isValid into isEnabled.

* Minor fixes.

* More minor fixes.

* Reverting some stuff that didn't need to change.

* Addressing PR feedback.

* Update the BlockInfo interface to match State.

* Make BlockChange.disabledReason private.
This commit is contained in:
John Nesky
2024-04-17 19:47:51 -07:00
committed by GitHub
parent 7d8f88a4f1
commit cee7f916bb
26 changed files with 492 additions and 97 deletions

View File

@@ -880,7 +880,7 @@ function fieldNameCheck(referenceBlock) {
var blocks = referenceBlock.workspace.getAllBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) {
var otherName = block.getFieldValue('FIELDNAME');
if (!block.disabled && !block.getInheritedDisabled() &&
if (block.isEnabled() && !block.getInheritedDisabled() &&
otherName && otherName.toLowerCase() === name) {
count++;
}
@@ -905,7 +905,7 @@ function inputNameCheck(referenceBlock) {
var blocks = referenceBlock.workspace.getAllBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) {
var otherName = block.getFieldValue('INPUTNAME');
if (!block.disabled && !block.getInheritedDisabled() &&
if (block.isEnabled() && !block.getInheritedDisabled() &&
otherName && otherName.toLowerCase() === name) {
count++;
}

View File

@@ -163,7 +163,7 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
var contentsBlock = rootBlock.getInputTargetBlock('INPUTS');
var lastInput = null;
while (contentsBlock) {
if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
if (contentsBlock.isEnabled() && !contentsBlock.getInheritedDisabled()) {
var fields = FactoryUtils.getFieldsJson_(
contentsBlock.getInputTargetBlock('FIELDS'));
for (var i = 0; i < fields.length; i++) {
@@ -247,7 +247,7 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
}
// Generate colour.
var colourBlock = rootBlock.getInputTargetBlock('COLOUR');
if (colourBlock && !colourBlock.disabled) {
if (colourBlock && colourBlock.isEnabled()) {
var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
JS.colour = hue;
}
@@ -277,7 +277,7 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
'input_end_row': 'appendEndRowInput'};
var contentsBlock = rootBlock.getInputTargetBlock('INPUTS');
while (contentsBlock) {
if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
if (contentsBlock.isEnabled() && !contentsBlock.getInheritedDisabled()) {
var name = '';
// Dummy inputs don't have names. Other inputs do.
if (contentsBlock.type !== 'input_dummy' &&
@@ -333,7 +333,7 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
}
// Generate colour.
var colourBlock = rootBlock.getInputTargetBlock('COLOUR');
if (colourBlock && !colourBlock.disabled) {
if (colourBlock && colourBlock.isEnabled()) {
var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
if (!isNaN(hue)) {
code.push(' this.setColour(' + hue + ');');
@@ -377,7 +377,7 @@ FactoryUtils.connectionLineJs_ = function(functionName, typeName, workspace) {
FactoryUtils.getFieldsJs_ = function(block) {
var fields = [];
while (block) {
if (!block.disabled && !block.getInheritedDisabled()) {
if (block.isEnabled() && !block.getInheritedDisabled()) {
switch (block.type) {
case 'field_static':
// Result: 'hello'
@@ -484,7 +484,7 @@ FactoryUtils.getFieldsJs_ = function(block) {
FactoryUtils.getFieldsJson_ = function(block) {
var fields = [];
while (block) {
if (!block.disabled && !block.getInheritedDisabled()) {
if (block.isEnabled() && !block.getInheritedDisabled()) {
switch (block.type) {
case 'field_static':
// Result: 'hello'
@@ -614,7 +614,7 @@ FactoryUtils.getOptTypesFrom = function(block, name) {
FactoryUtils.getTypesFrom_ = function(block, name) {
var typeBlock = block.getInputTargetBlock(name);
var types;
if (!typeBlock || typeBlock.disabled) {
if (!typeBlock || !typeBlock.isEnabled()) {
types = [];
} else if (typeBlock.type === 'type_other') {
types = [JSON.stringify(typeBlock.getFieldValue('TYPE'))];
@@ -1015,7 +1015,7 @@ FactoryUtils.savedBlockChanges = function(blockLibraryController) {
*/
FactoryUtils.getTooltipFromRootBlock_ = function(rootBlock) {
var tooltipBlock = rootBlock.getInputTargetBlock('TOOLTIP');
if (tooltipBlock && !tooltipBlock.disabled) {
if (tooltipBlock && tooltipBlock.isEnabled()) {
return tooltipBlock.getFieldValue('TEXT');
}
return '';
@@ -1029,7 +1029,7 @@ FactoryUtils.getTooltipFromRootBlock_ = function(rootBlock) {
*/
FactoryUtils.getHelpUrlFromRootBlock_ = function(rootBlock) {
var helpUrlBlock = rootBlock.getInputTargetBlock('HELPURL');
if (helpUrlBlock && !helpUrlBlock.disabled) {
if (helpUrlBlock && helpUrlBlock.isEnabled()) {
return helpUrlBlock.getFieldValue('TEXT');
}
return '';