From b7014759841d66fc623261b6bb024802996be17b Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 27 Sep 2019 11:43:56 -0700 Subject: [PATCH 1/4] Simplify trashcan code (#3110) Also delete unused props in CSS. --- core/css.js | 19 +------------- core/trashcan.js | 61 ++++++++++++++++--------------------------- tests/playground.html | 1 + typings/blockly.d.ts | 10 ++----- 4 files changed, 27 insertions(+), 64 deletions(-) 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/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/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. From a2e6cfffcc42e34968fc82f1ae2307c3c1d34954 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 27 Sep 2019 11:40:55 -0700 Subject: [PATCH 2/4] Block comments from XML not fatal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …if Blockly.Comment was not compiled in. --- core/xml.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); From 41e5914bd74c28e76d10ebbae3ae40d605826e2c Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 27 Sep 2019 12:21:08 -0700 Subject: [PATCH 3/4] el.style is readonly in strict mode IE. Fixing crash in IE. (#3119) --- core/components/tree/basenode.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) 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 From b5a076d2b3740d101ecf27fe6d24e7bde731ad5a Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 27 Sep 2019 12:36:16 -0700 Subject: [PATCH 4/4] Add theme requires (#3114) --- core/requires.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/requires.js b/core/requires.js index a55245b72..dc76807c4 100644 --- a/core/requires.js +++ b/core/requires.js @@ -83,3 +83,10 @@ goog.require('Blockly.FieldVariable'); goog.require('Blockly.geras.Renderer'); goog.require('Blockly.thrasos.Renderer'); goog.require('Blockly.zelos.Renderer'); + +// 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');