mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
fix: remove some attributes from the JSO system (#5356)
* fix: remove some attributes from the JSO system Remove the deletable, movable, and editable attributes. Normally this would be a breaking change, but because this isn't released yet it's just a patch. * fixup: serializer tests
This commit is contained in:
committed by
alschmiedt
parent
07057d087c
commit
9aecac3339
@@ -51,9 +51,6 @@ exports.ConnectionState = ConnectionState;
|
||||
* y: (number|undefined),
|
||||
* collapsed: (boolean|undefined),
|
||||
* disabled: (boolean|undefined),
|
||||
* editable: (boolean|undefined),
|
||||
* deletable: (boolean|undefined),
|
||||
* movable: (boolean|undefined),
|
||||
* inline: (boolean|undefined),
|
||||
* data: (string|undefined),
|
||||
* extra-state: *,
|
||||
@@ -118,7 +115,7 @@ exports.save = save;
|
||||
|
||||
/**
|
||||
* Adds attributes to the given state object based on the state of the block.
|
||||
* Eg collapsed, disabled, editable, etc.
|
||||
* Eg collapsed, disabled, inline, etc.
|
||||
* @param {!Block} block The block to base the attributes on.
|
||||
* @param {!State} state The state object to append to.
|
||||
*/
|
||||
@@ -129,21 +126,10 @@ const saveAttributes = function(block, state) {
|
||||
if (!block.isEnabled()) {
|
||||
state['enabled'] = false;
|
||||
}
|
||||
if (!block.isEditable()) {
|
||||
state['editable'] = false;
|
||||
}
|
||||
if (!block.isDeletable() && !block.isShadow()) {
|
||||
state['deletable'] = false;
|
||||
}
|
||||
if (!block.isMovable() && !block.isShadow()) {
|
||||
state['movable'] = false;
|
||||
}
|
||||
|
||||
if (block.inputsInline !== undefined &&
|
||||
block.inputsInline !== block.inputsInlineDefault) {
|
||||
state['inline'] = block.inputsInline;
|
||||
}
|
||||
|
||||
// Data is a nullable string, so we don't need to worry about falsy values.
|
||||
if (block.data) {
|
||||
state['data'] = block.data;
|
||||
@@ -383,15 +369,6 @@ const loadAttributes = function(block, state) {
|
||||
if (state['enabled'] === false) {
|
||||
block.setEnabled(false);
|
||||
}
|
||||
if (state['editable'] === false) {
|
||||
block.setEditable(false);
|
||||
}
|
||||
if (state['deletable'] === false) {
|
||||
block.setDeletable(false);
|
||||
}
|
||||
if (state['movable'] === false) {
|
||||
block.setMovable(false);
|
||||
}
|
||||
if (state['inline'] !== undefined) {
|
||||
block.setInputsInline(state['inline']);
|
||||
}
|
||||
|
||||
@@ -83,70 +83,6 @@ suite('JSO Serialization', function() {
|
||||
});
|
||||
});
|
||||
|
||||
suite('Deletable', function() {
|
||||
test('False', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setDeletable(false);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertProperty(jso, 'deletable', false);
|
||||
});
|
||||
|
||||
test('True', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setDeletable(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertNoProperty(jso, 'deletable');
|
||||
});
|
||||
|
||||
test('False and Shadow', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setDeletable(false);
|
||||
block.setShadow(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertNoProperty(jso, 'deletable');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Movable', function() {
|
||||
test('False', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setMovable(false);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertProperty(jso, 'movable', false);
|
||||
});
|
||||
|
||||
test('True', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setMovable(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertNoProperty(jso, 'movable');
|
||||
});
|
||||
|
||||
test('False and Shadow', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setMovable(false);
|
||||
block.setShadow(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertNoProperty(jso, 'movable');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Editable', function() {
|
||||
test('False', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setEditable(false);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertProperty(jso, 'editable', false);
|
||||
});
|
||||
|
||||
test('True', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setEditable(true);
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
assertNoProperty(jso, 'editable');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Inline', function() {
|
||||
test('True', function() {
|
||||
const block = this.workspace.newBlock('statement_block');
|
||||
|
||||
@@ -49,7 +49,7 @@ Serializer.Empty = new SerializerTestCase('Empty',
|
||||
);
|
||||
Serializer.Data = new SerializerTestCase('Data',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" editable="false" x="42" y="42">' +
|
||||
'<block type="logic_negate" id="id******************" x="42" y="42">' +
|
||||
'<data>test data</data>' +
|
||||
'</block>' +
|
||||
'</xml>');
|
||||
@@ -71,25 +71,10 @@ Serializer.Attributes.Disabled = new SerializerTestCase('Disabled',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" disabled="true" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.Deletable = new SerializerTestCase('Deletable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" deletable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.Movable = new SerializerTestCase('Movable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" movable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.Editable = new SerializerTestCase('Editable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" editable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.testCases = [
|
||||
Serializer.Attributes.Basic,
|
||||
Serializer.Attributes.Collapsed,
|
||||
Serializer.Attributes.Disabled,
|
||||
Serializer.Attributes.Deletable,
|
||||
Serializer.Attributes.Movable,
|
||||
Serializer.Attributes.Editable,
|
||||
];
|
||||
|
||||
Serializer.Attributes.Inline = new SerializerTestSuite('Inline');
|
||||
|
||||
Reference in New Issue
Block a user