diff --git a/core/components/tree/basenode.js b/core/components/tree/basenode.js index e2dc06871..c67805330 100644 --- a/core/components/tree/basenode.js +++ b/core/components/tree/basenode.js @@ -606,7 +606,10 @@ Blockly.tree.BaseNode.prototype.toDom = function() { var nonEmptyAndExpanded = this.getExpanded() && this.hasChildren(); var children = document.createElement('div'); - children.style = this.getLineStyle(); + children.style.backgroundPosition = this.getBackgroundPosition(); + if (!nonEmptyAndExpanded) { + children.style.display = 'none'; + } if (nonEmptyAndExpanded) { // children @@ -635,12 +638,10 @@ Blockly.tree.BaseNode.prototype.getPixelIndent_ = function() { * @protected */ Blockly.tree.BaseNode.prototype.getRowDom = function() { - var style = 'padding-' + (this.isRightToLeft() ? 'right' : 'left') + ':' + - this.getPixelIndent_() + 'px'; - var row = document.createElement('div'); row.className = this.getRowClassName(); - row.style = style; + row.style['padding-' + (this.isRightToLeft() ? 'right' : 'left')] = + this.getPixelIndent_() + 'px'; row.appendChild(this.getIconDom()); row.appendChild(this.getLabelDom()); @@ -690,16 +691,6 @@ Blockly.tree.BaseNode.prototype.getCalculatedIconClass = function() { throw Error('unimplemented abstract method'); }; -/** - * @return {string} The line style. - * @protected - */ -Blockly.tree.BaseNode.prototype.getLineStyle = function() { - var nonEmptyAndExpanded = this.getExpanded() && this.hasChildren(); - return 'background-position: ' + this.getBackgroundPosition() + '; ' + - (nonEmptyAndExpanded ? '' : 'display: none'); -}; - /** * @return {string} The background position style value. * @protected diff --git a/core/css.js b/core/css.js index ebb6cc2fb..85f677907 100644 --- a/core/css.js +++ b/core/css.js @@ -31,23 +31,6 @@ goog.provide('Blockly.Css'); -/** - * List of cursors. - * @enum {string} - */ -Blockly.Css.Cursor = { - OPEN: 'handopen', - CLOSED: 'handclosed', - DELETE: 'handdelete' -}; - -/** - * Current cursor (cached value). - * @type {string} - * @private - */ -Blockly.Css.currentCursor_ = ''; - /** * Has CSS already been injected? * @type {boolean} @@ -105,7 +88,7 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { /** * Set the cursor to be displayed when over something draggable. * See See https://github.com/google/blockly/issues/981 for context. - * @param {Blockly.Css.Cursor} _cursor Enum. + * @param {*} _cursor Enum. * @deprecated April 2017. */ Blockly.Css.setCursor = function(_cursor) { diff --git a/core/requires.js b/core/requires.js index 3690b8d61..a1887c358 100644 --- a/core/requires.js +++ b/core/requires.js @@ -86,3 +86,10 @@ goog.require('Blockly.geras.Renderer'); // The debug renderer, which shows simplified versions of the blocks for // developer use. // goog.require('Blockly.blockRendering.Debug'); + +// Blockly Themes. +// Classic is the default theme. +goog.require('Blockly.Themes.Classic'); +goog.require('Blockly.Themes.Dark'); +goog.require('Blockly.Themes.HighContrast'); +goog.require('Blockly.Themes.Modern'); diff --git a/core/trashcan.js b/core/trashcan.js index 521f9af25..98af6c1ca 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -46,15 +46,8 @@ Blockly.Trashcan = function(workspace) { this.workspace_ = workspace; /** - * True if the trashcan contains blocks, otherwise false. - * @type {boolean} - * @private - */ - this.hasBlocks_ = false; - - /** - * A list of Xml (stored as strings) representing blocks "inside" the trashcan. - * @type {Array} + * A list of XML (stored as strings) representing blocks in the trashcan. + * @type {!Array.} * @private */ this.contents_ = []; @@ -90,7 +83,7 @@ Blockly.Trashcan = function(workspace) { } this.flyout_ = new Blockly.VerticalFlyout(flyoutWorkspaceOptions); } - this.workspace_.addChangeListener(this.onDelete_()); + this.workspace_.addChangeListener(this.onDelete_.bind(this)); }; /** @@ -433,7 +426,7 @@ Blockly.Trashcan.prototype.close = function() { * Inspect the contents of the trash. */ Blockly.Trashcan.prototype.click = function() { - if (!this.hasBlocks_) { + if (!this.contents_.length) { return; } @@ -449,10 +442,9 @@ Blockly.Trashcan.prototype.click = function() { * @private */ Blockly.Trashcan.prototype.mouseOver_ = function() { - if (!this.hasBlocks_) { - return; + if (this.contents_.length) { + this.setOpen_(true); } - this.setOpen_(true); }; /** @@ -468,35 +460,28 @@ Blockly.Trashcan.prototype.mouseOut_ = function() { /** * Handle a BLOCK_DELETE event. Adds deleted blocks oldXml to the content array. - * @return {!Function} Function to call when a block is deleted. + * @param {!Blockly.Events.Abstract} event Workspace event. * @private */ -Blockly.Trashcan.prototype.onDelete_ = function() { - var trashcan = this; - return function(event) { - if (trashcan.workspace_.options.maxTrashcanContents <= 0) { +Blockly.Trashcan.prototype.onDelete_ = function(event) { + if (this.workspace_.options.maxTrashcanContents <= 0) { + return; + } + if (event.type == Blockly.Events.BLOCK_DELETE && + event.oldXml.tagName.toLowerCase() != 'shadow') { + var cleanedXML = this.cleanBlockXML_(event.oldXml); + if (this.contents_.indexOf(cleanedXML) != -1) { return; } - if (event.type == Blockly.Events.BLOCK_DELETE && - event.oldXml.tagName.toLowerCase() != 'shadow') { - var cleanedXML = trashcan.cleanBlockXML_(event.oldXml); - if (trashcan.contents_.indexOf(cleanedXML) != -1) { - return; - } - trashcan.contents_.unshift(cleanedXML); - if (trashcan.contents_.length > - trashcan.workspace_.options.maxTrashcanContents) { - trashcan.contents_.splice( - trashcan.workspace_.options.maxTrashcanContents, - trashcan.contents_.length - - trashcan.workspace_.options.maxTrashcanContents); - } - - trashcan.hasBlocks_ = true; - trashcan.minOpenness_ = trashcan.HAS_BLOCKS_LID_ANGLE; - trashcan.setLidAngle_(trashcan.minOpenness_ * 45); + this.contents_.unshift(cleanedXML); + while (this.contents_.length > + this.workspace_.options.maxTrashcanContents) { + this.contents_.pop(); } - }; + + this.minOpenness_ = this.HAS_BLOCKS_LID_ANGLE; + this.setLidAngle_(this.minOpenness_ * 45); + } }; /** diff --git a/core/xml.js b/core/xml.js index 51a182b3c..f152f0a0f 100644 --- a/core/xml.js +++ b/core/xml.js @@ -433,14 +433,14 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) { if (workspace.rendered) { if (!Blockly.WorkspaceCommentSvg) { console.warn('Missing require for Blockly.WorkspaceCommentSvg, ' + - 'ignoring comment block.'); + 'ignoring workspace comment.'); } else { Blockly.WorkspaceCommentSvg.fromXml(xmlChild, workspace, width); } } else { if (!Blockly.WorkspaceComment) { console.warn('Missing require for Blockly.WorkspaceComment, ' + - 'ignoring comment block.'); + 'ignoring workspace comment.'); } else { Blockly.WorkspaceComment.fromXml(xmlChild, workspace); } @@ -668,6 +668,11 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { } break; case 'comment': + if (!Blockly.Comment) { + console.warn('Missing require for Blockly.Comment, ' + + 'ignoring block comment.'); + break; + } var text = xmlChild.textContent; var pinned = xmlChild.getAttribute('pinned') == 'true'; var width = parseInt(xmlChild.getAttribute('w'), 10); diff --git a/tests/playground.html b/tests/playground.html index b157b4a56..5e3a35a38 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -109,6 +109,7 @@ function start() { horizontalLayout: side == 'top' || side == 'bottom', maxBlocks: Infinity, maxInstances: {'test_basic_limit_instances': 3}, + maxTrashcanContents: 256, media: '../media/', oneBasedIndex: true, readOnly: false, diff --git a/typings/blockly.d.ts b/typings/blockly.d.ts index 8b1f24d52..0ce518ae0 100644 --- a/typings/blockly.d.ts +++ b/typings/blockly.d.ts @@ -2809,12 +2809,6 @@ declare module Blockly.ContextMenu { declare module Blockly.Css { - /** - * List of cursors. - * @enum {string} - */ - enum Cursor { OPEN, CLOSED, DELETE } - /** * Inject the CSS into the DOM. This is preferable over using a regular CSS * file since: @@ -2830,10 +2824,10 @@ declare module Blockly.Css { /** * Set the cursor to be displayed when over something draggable. * See See https://github.com/google/blockly/issues/981 for context. - * @param {Blockly.Css.Cursor} cursor Enum. + * @param {*} cursor Enum. * @deprecated April 2017. */ - function setCursor(cursor: Blockly.Css.Cursor): void; + function setCursor(cursor: any): void; /** * Array making up the CSS content for Blockly.