Fix 19 warnings in theme-related code. (#2523)

* Fix 19 warnings in theme-related code.

Resolves #2414

* Remove suppressPrefixSuffix property definition

The mixin code throws an error if property exists on both objects.

* eslint has strange ideas about indentation.
This commit is contained in:
Neil Fraser
2019-05-30 10:05:06 -07:00
committed by GitHub
parent 73ff710a4d
commit dce0b77424
8 changed files with 99 additions and 85 deletions

View File

@@ -265,7 +265,6 @@ Blockly.Block.prototype.colourTertiary_ = null;
*/
Blockly.Block.prototype.styleName_ = null;
/**
* Dispose of this block.
* @param {boolean} healStack If true, then try to heal any gap by connecting

View File

@@ -691,11 +691,11 @@ Blockly.checkBlockColourConstant_ = function(
* @param {!Blockly.Theme} theme Theme for Blockly.
*/
Blockly.setTheme = function(theme) {
this.theme_ = theme;
Blockly.theme_ = theme;
var ws = Blockly.getMainWorkspace();
if (ws) {
this.refreshTheme_(ws);
Blockly.refreshTheme_(ws);
}
};
@@ -706,7 +706,7 @@ Blockly.setTheme = function(theme) {
*/
Blockly.refreshTheme_ = function(ws) {
// Update all blocks in workspace that have a style name.
this.updateBlockStyles_(ws.getAllBlocks().filter(
Blockly.updateBlockStyles_(ws.getAllBlocks().filter(
function(block) {
return block.getStyleName() !== undefined;
}
@@ -714,7 +714,7 @@ Blockly.refreshTheme_ = function(ws) {
// Update blocks in the flyout.
if (!ws.toolbox_ && ws.flyout_ && ws.flyout_.workspace_) {
this.updateBlockStyles_(ws.flyout_.workspace_.getAllBlocks());
Blockly.updateBlockStyles_(ws.flyout_.workspace_.getAllBlocks());
} else {
ws.refreshToolboxSelection();
}
@@ -750,7 +750,7 @@ Blockly.updateBlockStyles_ = function(blocks) {
* @return {Blockly.Theme} Theme for Blockly.
*/
Blockly.getTheme = function() {
return this.theme_;
return Blockly.theme_;
};
// Export symbols that would otherwise be renamed by Closure compiler.

View File

@@ -26,11 +26,17 @@
goog.provide('Blockly.Theme');
/**
* A block style or a category style.
* @typedef {!Object.<string, string>}
*/
Blockly.Theme.Style;
/**
* Class for a theme.
* @param {Object.<string, Blockly.BlockStyle>} blockStyles A map from style
* @param {!Object.<string, Blockly.Theme.Style>} blockStyles A map from style
* names (strings) to objects with style attributes relating to blocks.
* @param {Object.<string, Blockly.CategoryStyle>} categoryStyles A map from
* @param {!Object.<string, Blockly.Theme.Style>} categoryStyles A map from
* style names (strings) to objects with style attributes relating to
* categories.
* @constructor
@@ -42,8 +48,8 @@ Blockly.Theme = function(blockStyles, categoryStyles) {
/**
* Overrides or adds all values from blockStyles to blockStyles_
* @param {Object.<string, Blockly.BlockStyle>} blockStyles List of
* block styles.
* @param {Object.<string, Blockly.Theme.Style>} blockStyles Map of
* block styles.
*/
Blockly.Theme.prototype.setAllBlockStyles = function(blockStyles) {
for (var key in blockStyles) {
@@ -52,8 +58,8 @@ Blockly.Theme.prototype.setAllBlockStyles = function(blockStyles) {
};
/**
* Gets a list of all the block style names.
* @return {Array.<String>} List of blockstyle names.
* Gets a map of all the block style names.
* @return {!Object.<string, Blockly.Theme.Style>} Map of block styles.
*/
Blockly.Theme.prototype.getAllBlockStyles = function() {
return this.blockStyles_;
@@ -62,7 +68,7 @@ Blockly.Theme.prototype.getAllBlockStyles = function() {
/**
* Gets the BlockStyle for the given block style name.
* @param {string} blockStyleName The name of the block style.
* @return {Blockly.BlockStyle} The style with the block style name.
* @return {Blockly.Theme.Style|undefined} The named block style.
*/
Blockly.Theme.prototype.getBlockStyle = function(blockStyleName) {
return this.blockStyles_[blockStyleName];
@@ -71,7 +77,7 @@ Blockly.Theme.prototype.getBlockStyle = function(blockStyleName) {
/**
* Overrides or adds a style to the blockStyles map.
* @param {string} blockStyleName The name of the block style.
* @param {Blockly.BlockStyle} blockStyle The block style
* @param {Blockly.Theme.Style} blockStyle The block style.
*/
Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) {
this.blockStyles_[blockStyleName] = blockStyle;
@@ -79,8 +85,8 @@ Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) {
/**
* Gets the CategoryStyle for the given category style name.
* @param {string} categoryStyleName The name of the block style.
* @return {Blockly.CategoryStyle} The style with the block style name.
* @param {string} categoryStyleName The name of the category style.
* @return {Blockly.Theme.Style|undefined} The named category style.
*/
Blockly.Theme.prototype.getCategoryStyle = function(categoryStyleName) {
return this.categoryStyles_[categoryStyleName];
@@ -89,8 +95,9 @@ Blockly.Theme.prototype.getCategoryStyle = function(categoryStyleName) {
/**
* Overrides or adds a style to the categoryStyles map.
* @param {string} categoryStyleName The name of the category style.
* @param {Blockly.CategoryStyle} categoryStyle The category style
* @param {Blockly.Theme.Style} categoryStyle The category style.
*/
Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) {
Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName,
categoryStyle) {
this.categoryStyles_[categoryStyleName] = categoryStyle;
};

View File

@@ -20,7 +20,7 @@
/**
* @fileoverview Classic theme.
* Contains multi colored border to create shadow effect.
* Contains multi-coloured border to create shadow effect.
*/
'use strict';
@@ -30,8 +30,8 @@ goog.provide('Blockly.Themes.Classic');
goog.require('Blockly.Theme');
var defaultBlockStyles = {
"colour_blocks":{
Blockly.Themes.Classic.defaultBlockStyles = {
"colour_blocks": {
"colourPrimary": "20"
},
"list_blocks": {
@@ -55,17 +55,17 @@ var defaultBlockStyles = {
"variable_blocks": {
"colourPrimary": "330"
},
"variable_dynamic_blocks":{
"variable_dynamic_blocks": {
"colourPrimary": "310"
},
"hat_blocks":{
"colourPrimary":"330",
"hat":"cap"
"hat_blocks": {
"colourPrimary": "330",
"hat": "cap"
}
};
var categoryStyles = {
"colour_category":{
Blockly.Themes.Classic.categoryStyles = {
"colour_category": {
"colour": "20"
},
"list_category": {
@@ -89,9 +89,11 @@ var categoryStyles = {
"variable_category": {
"colour": "330"
},
"variable_dynamic_category":{
"variable_dynamic_category": {
"colour": "310"
}
};
Blockly.Themes.Classic = new Blockly.Theme(defaultBlockStyles, categoryStyles);
Blockly.Themes.Classic =
new Blockly.Theme(Blockly.Themes.Classic.defaultBlockStyles,
Blockly.Themes.Classic.categoryStyles);

View File

@@ -20,7 +20,7 @@
/**
* @fileoverview High contrast theme.
* Darker colors to contrast the white font.
* Darker colours to contrast the white font.
*/
'use strict';
@@ -29,89 +29,91 @@ goog.provide('Blockly.Themes.HighContrast');
goog.require('Blockly.Theme');
var defaultBlockStyles = {
"colour_blocks":{
Blockly.Themes.HighContrast.defaultBlockStyles = {
"colour_blocks": {
"colourPrimary": "#a52714",
"colourSecondary":"#FB9B8C",
"colourTertiary":"#FBE1DD"
"colourSecondary": "#FB9B8C",
"colourTertiary": "#FBE1DD"
},
"list_blocks": {
"colourPrimary": "#4a148c",
"colourSecondary":"#AD7BE9",
"colourTertiary":"#CDB6E9"
"colourSecondary": "#AD7BE9",
"colourTertiary": "#CDB6E9"
},
"logic_blocks": {
"colourPrimary": "#01579b",
"colourSecondary":"#64C7FF",
"colourTertiary":"#C5EAFF"
"colourSecondary": "#64C7FF",
"colourTertiary": "#C5EAFF"
},
"loop_blocks": {
"colourPrimary": "#33691e",
"colourSecondary":"#9AFF78",
"colourTertiary":"#E1FFD7"
"colourSecondary": "#9AFF78",
"colourTertiary": "#E1FFD7"
},
"math_blocks": {
"colourPrimary": "#1a237e",
"colourSecondary":"#8A9EFF",
"colourTertiary":"#DCE2FF"
"colourSecondary": "#8A9EFF",
"colourTertiary": "#DCE2FF"
},
"procedure_blocks": {
"colourPrimary": "#006064",
"colourSecondary":"#77E6EE",
"colourTertiary":"#CFECEE"
"colourSecondary": "#77E6EE",
"colourTertiary": "#CFECEE"
},
"text_blocks": {
"colourPrimary": "#004d40",
"colourSecondary":"#5ae27c",
"colourTertiary":"#D2FFDD"
"colourSecondary": "#5ae27c",
"colourTertiary": "#D2FFDD"
},
"variable_blocks": {
"colourPrimary": "#880e4f",
"colourSecondary":"#FF73BE",
"colourTertiary":"#FFD4EB"
"colourSecondary": "#FF73BE",
"colourTertiary": "#FFD4EB"
},
"variable_dynamic_blocks": {
"colourPrimary": "#880e4f",
"colourSecondary":"#FF73BE",
"colourTertiary":"#FFD4EB"
"colourSecondary": "#FF73BE",
"colourTertiary": "#FFD4EB"
},
"hat_blocks" : {
"hat_blocks": {
"colourPrimary": "#880e4f",
"colourSecondary":"#FF73BE",
"colourTertiary":"#FFD4EB",
"colourSecondary": "#FF73BE",
"colourTertiary": "#FFD4EB",
"hat": "cap"
}
};
var categoryStyles = {
"colour_category":{
"colour": "#a52714",
Blockly.Themes.HighContrast.categoryStyles = {
"colour_category": {
"colour": "#a52714"
},
"list_category": {
"colour": "#4a148c",
"colour": "#4a148c"
},
"logic_category": {
"colour": "#01579b",
"colour": "#01579b"
},
"loop_category": {
"colour": "#33691e",
"colour": "#33691e"
},
"math_category": {
"colour": "#1a237e",
"colour": "#1a237e"
},
"procedure_category": {
"colour": "#006064",
"colour": "#006064"
},
"text_category": {
"colour": "#004d40",
"colour": "#004d40"
},
"variable_category": {
"colour": "#880e4f",
"colour": "#880e4f"
},
"variable_dynamic_category":{
"colour": "#880e4f",
"variable_dynamic_category": {
"colour": "#880e4f"
}
};
//This style is still being fleshed out and may change.
Blockly.Themes.HighContrast = new Blockly.Theme(defaultBlockStyles, categoryStyles);
// This style is still being fleshed out and may change.
Blockly.Themes.HighContrast =
new Blockly.Theme(Blockly.Themes.HighContrast.defaultBlockStyles,
Blockly.Themes.HighContrast.categoryStyles);

View File

@@ -20,7 +20,7 @@
/**
* @fileoverview Modern theme.
* Same colors as classic, but single colored border.
* Same colours as classic, but single coloured border.
*/
'use strict';
@@ -29,7 +29,7 @@ goog.provide('Blockly.Themes.Modern');
goog.require('Blockly.Theme');
var defaultBlockStyles = {
Blockly.Themes.Modern.defaultBlockStyles = {
"colour_blocks": {
"colourPrimary": "#a5745b",
"colourSecondary": "#dbc7bd",
@@ -83,35 +83,37 @@ var defaultBlockStyles = {
}
};
var categoryStyles = {
"colour_category":{
"colour": "#a5745b",
Blockly.Themes.Modern.categoryStyles = {
"colour_category": {
"colour": "#a5745b"
},
"list_category": {
"colour": "#745ba5",
"colour": "#745ba5"
},
"logic_category": {
"colour": "#5b80a5",
"colour": "#5b80a5"
},
"loop_category": {
"colour": "#5ba55b",
"colour": "#5ba55b"
},
"math_category": {
"colour": "#5b67a5",
"colour": "#5b67a5"
},
"procedure_category": {
"colour": "#995ba5",
"colour": "#995ba5"
},
"text_category": {
"colour": "#5ba58c",
"colour": "#5ba58c"
},
"variable_category": {
"colour": "#a55b99",
"colour": "#a55b99"
},
"variable_dynamic_category":{
"colour": "#a55b99",
"variable_dynamic_category": {
"colour": "#a55b99"
}
};
//This style is still being fleshed out and may change.
Blockly.Themes.Modern = new Blockly.Theme(defaultBlockStyles, categoryStyles);
// This style is still being fleshed out and may change.
Blockly.Themes.Modern =
new Blockly.Theme(Blockly.Themes.Modern.defaultBlockStyles,
Blockly.Themes.Modern.categoryStyles);

View File

@@ -424,7 +424,8 @@ Blockly.Toolbox.prototype.setColourFromStyle_ = function(
if (style && style.colour) {
this.setColour_(style.colour, childOut, categoryName);
} else {
console.warn('Style "' + styleName + '" must exist and contain a colour value');
console.warn('Style "' + styleName +
'" must exist and contain a colour value');
}
}
};

View File

@@ -201,7 +201,8 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
element.appendChild(container);
}
}
if (block.inputsInlineDefault != block.inputsInline) {
if (block.inputsInline != undefined &&
block.inputsInline != block.inputsInlineDefault) {
element.setAttribute('inline', block.inputsInline);
}
if (block.isCollapsed()) {