From f38a4519878a0e6c70218af505c4aaf5a01eaef7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:11:19 -0700 Subject: [PATCH 1/7] Migrate core/comment.js to ES6 const/let --- core/comment.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7917b2ec5..5e867d9df 100644 --- a/core/comment.js +++ b/core/comment.js @@ -152,13 +152,13 @@ Blockly.Comment.prototype.createEditor_ = function() { {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, null); - var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); + const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( Blockly.utils.dom.HTML_NS, 'textarea'); - var textarea = this.textarea_; + const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); textarea.value = this.model_.text; @@ -228,10 +228,10 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * @private */ Blockly.Comment.prototype.resizeTextarea_ = function() { - var size = this.model_.size; - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - var widthMinusBorder = size.width - doubleBorderWidth; - var heightMinusBorder = size.height - doubleBorderWidth; + const size = this.model_.size; + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const widthMinusBorder = size.width - doubleBorderWidth; + const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); this.foreignObject_.setAttribute('height', heightMinusBorder); this.textarea_.style.width = (widthMinusBorder - 4) + 'px'; From 530964e03b83a26f0e6880040bc73dcdad8dabed Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:15:42 -0700 Subject: [PATCH 2/7] Migrate core/comment.js to goog.module --- core/comment.js | 43 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/core/comment.js b/core/comment.js index 5e867d9df..1e585d63c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Comment'); +goog.module('Blockly.Comment'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Bubble'); @@ -41,8 +42,8 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Comment = function(block) { - Blockly.Comment.superClass_.constructor.call(this, block); +const Comment = function(block) { + Comment.superClass_.constructor.call(this, block); /** * The model for this comment. @@ -92,14 +93,14 @@ Blockly.Comment = function(block) { this.createIcon(); }; -Blockly.utils.object.inherits(Blockly.Comment, Blockly.Icon); +Blockly.utils.object.inherits(Comment, Blockly.Icon); /** * Draw the comment icon. * @param {!Element} group The icon group. * @protected */ -Blockly.Comment.prototype.drawIcon_ = function(group) { +Comment.prototype.drawIcon_ = function(group) { // Circle. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CIRCLE, @@ -134,7 +135,7 @@ Blockly.Comment.prototype.drawIcon_ = function(group) { * @return {!SVGElement} The top-level node of the editor. * @private */ -Blockly.Comment.prototype.createEditor_ = function() { +Comment.prototype.createEditor_ = function() { /* Create the editor. Here's the markup that will be generated in * editable mode: @@ -200,8 +201,8 @@ Blockly.Comment.prototype.createEditor_ = function() { * Add or remove editability of the comment. * @override */ -Blockly.Comment.prototype.updateEditable = function() { - Blockly.Comment.superClass_.updateEditable.call(this); +Comment.prototype.updateEditable = function() { + Comment.superClass_.updateEditable.call(this); if (this.isVisible()) { // Recreate the bubble with the correct UI. this.disposeBubble_(); @@ -214,7 +215,7 @@ Blockly.Comment.prototype.updateEditable = function() { * Resize the text area accordingly. * @private */ -Blockly.Comment.prototype.onBubbleResize_ = function() { +Comment.prototype.onBubbleResize_ = function() { if (!this.isVisible()) { return; } @@ -227,7 +228,7 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * the size of the bubble). * @private */ -Blockly.Comment.prototype.resizeTextarea_ = function() { +Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; @@ -242,7 +243,7 @@ Blockly.Comment.prototype.resizeTextarea_ = function() { * Show or hide the comment bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Comment.prototype.setVisible = function(visible) { +Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } @@ -260,7 +261,7 @@ Blockly.Comment.prototype.setVisible = function(visible) { * Show the bubble. Handles deciding if it should be editable or not. * @private */ -Blockly.Comment.prototype.createBubble_ = function() { +Comment.prototype.createBubble_ = function() { if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 @@ -275,7 +276,7 @@ Blockly.Comment.prototype.createBubble_ = function() { * Show an editable bubble. * @private */ -Blockly.Comment.prototype.createEditableBubble_ = function() { +Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Blockly.Bubble( /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, @@ -292,7 +293,7 @@ Blockly.Comment.prototype.createEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.createNonEditableBubble_ = function() { +Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); this.bubble_ = Blockly.Bubble.createNonEditableBubble( @@ -306,7 +307,7 @@ Blockly.Comment.prototype.createNonEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.disposeBubble_ = function() { +Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { Blockly.browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; @@ -338,7 +339,7 @@ Blockly.Comment.prototype.disposeBubble_ = function() { * @param {!Event} _e Mouse up event. * @private */ -Blockly.Comment.prototype.startEdit_ = function(_e) { +Comment.prototype.startEdit_ = function(_e) { if (this.bubble_.promote()) { // Since the act of moving this node within the DOM causes a loss of focus, // we need to reapply the focus. @@ -352,7 +353,7 @@ Blockly.Comment.prototype.startEdit_ = function(_e) { * Get the dimensions of this comment's bubble. * @return {Blockly.utils.Size} Object with width and height properties. */ -Blockly.Comment.prototype.getBubbleSize = function() { +Comment.prototype.getBubbleSize = function() { return this.model_.size; }; @@ -361,7 +362,7 @@ Blockly.Comment.prototype.getBubbleSize = function() { * @param {number} width Width of the bubble. * @param {number} height Height of the bubble. */ -Blockly.Comment.prototype.setBubbleSize = function(width, height) { +Comment.prototype.setBubbleSize = function(width, height) { if (this.bubble_) { this.bubble_.setBubbleSize(width, height); } else { @@ -374,7 +375,7 @@ Blockly.Comment.prototype.setBubbleSize = function(width, height) { * Update the comment's view to match the model. * @package */ -Blockly.Comment.prototype.updateText = function() { +Comment.prototype.updateText = function() { if (this.textarea_) { this.textarea_.value = this.model_.text; } else if (this.paragraphElement_) { @@ -390,7 +391,7 @@ Blockly.Comment.prototype.updateText = function() { * If you want to receive a comment "delete" event (newValue: null), then this * should not be called directly. Instead call block.setCommentText(null); */ -Blockly.Comment.prototype.dispose = function() { +Comment.prototype.dispose = function() { this.block_.comment = null; Blockly.Icon.prototype.dispose.call(this); }; @@ -412,3 +413,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = Comment; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..f04468cf7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -17,7 +17,7 @@ goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6 goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); From 30a6948a9a30a04ad60de79831d56a3a0ea79e82 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:37:05 -0700 Subject: [PATCH 3/7] Migrate core/comment.js to named requires --- core/comment.js | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/core/comment.js b/core/comment.js index 1e585d63c..18615d669 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,33 +13,33 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Block = goog.requireType('Blockly.Block'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const Bubble = goog.require('Blockly.Bubble'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const Css = goog.require('Blockly.Css'); +const dom = goog.require('Blockly.utils.dom'); +const Events = goog.require('Blockly.Events'); +const Icon = goog.require('Blockly.Icon'); +const Size = goog.requireType('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utilsObject = goog.require('Blockly.utils.object'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {CommentModel} = goog.requireType('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); -goog.require('Blockly.Icon'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Warning'); -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.utils.Size'); -goog.requireType('Blockly.WorkspaceSvg'); - /** * Class for a comment. - * @param {!Blockly.Block} block The block associated with this comment. - * @extends {Blockly.Icon} + * @param {!Block} block The block associated with this comment. + * @extends {Icon} * @constructor */ const Comment = function(block) { @@ -47,7 +47,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!Blockly.Block.CommentModel} + * @type {!CommentModel} * @private */ this.model_ = block.commentModel; @@ -65,35 +65,35 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onInputWrapper_ = null; this.createIcon(); }; -Blockly.utils.object.inherits(Comment, Blockly.Icon); +utilsObject.inherits(Comment, Icon); /** * Draw the comment icon. @@ -102,15 +102,15 @@ Blockly.utils.object.inherits(Comment, Blockly.Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + dom.createSvgElement( + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -118,8 +118,8 @@ Comment.prototype.drawIcon_ = function(group) { '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, group); // Dot of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -148,17 +148,17 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FOREIGNOBJECT, - {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, + this.foreignObject_ = dom.createSvgElement( + Svg.FOREIGNOBJECT, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); - body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); + const body = document.createElementNS(dom.HTML_NS, 'body'); + body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( - Blockly.utils.dom.HTML_NS, 'textarea'); + dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -171,23 +171,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = Blockly.browserEvents.conditionalBind( + this.onWheelWrapper_ = browserEvents.conditionalBind( textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = Blockly.browserEvents.conditionalBind( + this.onChangeWrapper_ = browserEvents.conditionalBind( textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire( + new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onInputWrapper_ = browserEvents.conditionalBind( textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -230,7 +230,7 @@ Comment.prototype.onBubbleResize_ = function() { */ Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); @@ -247,7 +247,7 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { @@ -262,7 +262,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -277,10 +277,10 @@ Comment.prototype.createBubble_ = function() { * @private */ Comment.prototype.createEditableBubble_ = function() { - this.bubble_ = new Blockly.Bubble( - /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), + this.bubble_ = new Bubble( + /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_), + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); @@ -295,10 +295,10 @@ Comment.prototype.createEditableBubble_ = function() { */ Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. - this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); - this.bubble_ = Blockly.Bubble.createNonEditableBubble( - this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_)); + this.paragraphElement_ = Bubble.textToDom(this.block_.getCommentText()); + this.bubble_ = Bubble.createNonEditableBubble( + this.paragraphElement_, /** @type {!BlockSvg} */ (this.block_), + /** @type {!Coordinate} */ (this.iconXY_)); this.applyColour(); }; @@ -309,19 +309,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - Blockly.browserEvents.unbind(this.onWheelWrapper_); + browserEvents.unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - Blockly.browserEvents.unbind(this.onChangeWrapper_); + browserEvents.unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - Blockly.browserEvents.unbind(this.onInputWrapper_); + browserEvents.unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -351,7 +351,7 @@ Comment.prototype.startEdit_ = function(_e) { /** * Get the dimensions of this comment's bubble. - * @return {Blockly.utils.Size} Object with width and height properties. + * @return {Size} Object with width and height properties. */ Comment.prototype.getBubbleSize = function() { return this.model_.size; @@ -393,13 +393,13 @@ Comment.prototype.updateText = function() { */ Comment.prototype.dispose = function() { this.block_.comment = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; /** * CSS for block comment. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From d1ae27eb6071981e60751fa44244790e15c9bfa1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:38:00 -0700 Subject: [PATCH 4/7] clang-format core/comment.js --- core/comment.js | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/core/comment.js b/core/comment.js index 18615d669..fe0c940a6 100644 --- a/core/comment.js +++ b/core/comment.js @@ -103,24 +103,22 @@ utilsObject.inherits(Comment, Icon); Comment.prototype.drawIcon_ = function(group) { // Circle. dom.createSvgElement( - Svg.CIRCLE, - {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + - '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + - '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, + '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + + '-1.201,0.998 -1.201,1.528 -1.204,2.19z' + }, group); // Dot of question mark. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', 'y': '10.78', @@ -149,16 +147,14 @@ Comment.prototype.createEditor_ = function() { */ this.foreignObject_ = dom.createSvgElement( - Svg.FOREIGNOBJECT, - {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, + Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); const body = document.createElementNS(dom.HTML_NS, 'body'); body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS( - dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -174,21 +170,20 @@ Comment.prototype.createEditor_ = function() { this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = browserEvents.conditionalBind( - textarea, 'wheel', this, function(e) { + this.onWheelWrapper_ = + browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = browserEvents.conditionalBind( - textarea, 'change', this, function(_e) { + this.onChangeWrapper_ = + browserEvents.conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Events.fire( - new (Events.get(Events.BLOCK_CHANGE))( - this.block_, 'comment', null, this.cachedText_, - this.model_.text)); + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( + this.block_, 'comment', null, this.cachedText_, + this.model_.text)); } }); - this.onInputWrapper_ = browserEvents.conditionalBind( - textarea, 'input', this, function(_e) { + this.onInputWrapper_ = + browserEvents.conditionalBind(textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -247,8 +242,8 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'comment')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { this.createBubble_(); @@ -280,8 +275,8 @@ Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Bubble( /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Coordinate} */ (this.iconXY_), - this.model_.size.width, this.model_.size.height); + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, + this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerResizeEvent(this.onBubbleResize_.bind(this)); From c6112df77a17f8e130c43cd1959e3391cea41fdf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:16:29 -0700 Subject: [PATCH 5/7] Switch some requires in core/comment.js to destructuring --- core/comment.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/core/comment.js b/core/comment.js index fe0c940a6..de947fa5f 100644 --- a/core/comment.js +++ b/core/comment.js @@ -15,19 +15,17 @@ goog.module.declareLegacyNamespace(); const Block = goog.requireType('Blockly.Block'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const browserEvents = goog.require('Blockly.browserEvents'); const Bubble = goog.require('Blockly.Bubble'); const Coordinate = goog.requireType('Blockly.utils.Coordinate'); -const Css = goog.require('Blockly.Css'); -const dom = goog.require('Blockly.utils.dom'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); -const userAgent = goog.require('Blockly.utils.userAgent'); -const utilsObject = goog.require('Blockly.utils.object'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const {CommentModel} = goog.requireType('Blockly.Block'); +const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); +const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {register} = goog.require('Blockly.Css'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -65,28 +63,28 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onInputWrapper_ = null; @@ -167,25 +165,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = browserEvents.conditionalBind( - textarea, 'mouseup', this, this.startEdit_, true, true); + this.onMouseUpWrapper_ = + conditionalBind(textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = - browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); + this.onWheelWrapper_ = conditionalBind(textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); this.onChangeWrapper_ = - browserEvents.conditionalBind(textarea, 'change', this, function(_e) { + conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = - browserEvents.conditionalBind(textarea, 'input', this, function(_e) { - this.model_.text = textarea.value; - }); + this.onInputWrapper_ = conditionalBind(textarea, 'input', this, function(_e) { + this.model_.text = textarea.value; + }); setTimeout(textarea.focus.bind(textarea), 0); @@ -304,19 +300,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - browserEvents.unbind(this.onMouseUpWrapper_); + unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - browserEvents.unbind(this.onWheelWrapper_); + unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - browserEvents.unbind(this.onChangeWrapper_); + unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - browserEvents.unbind(this.onInputWrapper_); + unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -394,7 +390,7 @@ Comment.prototype.dispose = function() { /** * CSS for block comment. See css.js for use. */ -Css.register([ +register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From ac1fb9a4ddd628d630ce0a049371f15b42884623 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 13:53:47 -0700 Subject: [PATCH 6/7] Revise imports in core/comment.js --- core/comment.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/core/comment.js b/core/comment.js index de947fa5f..7caf61614 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,10 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {CommentModel} = goog.requireType('Blockly.Block'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); -const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); +const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -45,7 +46,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!CommentModel} + * @type {!Block.CommentModel} * @private */ this.model_ = block.commentModel; @@ -91,7 +92,7 @@ const Comment = function(block) { this.createIcon(); }; -utilsObject.inherits(Comment, Icon); +inherits(Comment, Icon); /** * Draw the comment icon. @@ -100,13 +101,13 @@ utilsObject.inherits(Comment, Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - dom.createSvgElement( + createSvgElement( Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - dom.createSvgElement( + createSvgElement( Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -115,7 +116,7 @@ Comment.prototype.drawIcon_ = function(group) { }, group); // Dot of question mark. - dom.createSvgElement( + createSvgElement( Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -144,15 +145,15 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = dom.createSvgElement( + this.foreignObject_ = createSvgElement( Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(dom.HTML_NS, 'body'); - body.setAttribute('xmlns', dom.HTML_NS); + const body = document.createElementNS(HTML_NS, 'body'); + body.setAttribute('xmlns', HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -253,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || userAgent.IE) { + if (!this.block_.isEditable() || IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -392,16 +393,9 @@ Comment.prototype.dispose = function() { */ register([ /* eslint-disable indent */ - '.blocklyCommentTextarea {', - 'background-color: #fef49c;', - 'border: 0;', - 'outline: 0;', - 'margin: 0;', - 'padding: 3px;', - 'resize: none;', - 'display: block;', - 'text-overflow: hidden;', - '}' + '.blocklyCommentTextarea {', 'background-color: #fef49c;', 'border: 0;', + 'outline: 0;', 'margin: 0;', 'padding: 3px;', 'resize: none;', + 'display: block;', 'text-overflow: hidden;', '}' /* eslint-enable indent */ ]); From d9625b1cafd3b94afa0ced4061527d2ad406e04b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 09:38:06 -0700 Subject: [PATCH 7/7] Require userAgent module instead of destructuring in core/comment.js --- core/comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7caf61614..7f4085faf 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,11 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); -const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -254,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable.