From a765a3016e4f9cc341f0b5696be548a5f0e6acfa Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:32:52 -0700 Subject: [PATCH] Migrate core/field_label.js to goog.module --- core/field_label.js | 31 +++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4a19dc07e..4c15d4f96 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabel'); +goog.module('Blockly.FieldLabel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -31,7 +32,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { +const FieldLabel = function(opt_value, opt_class, opt_config) { /** * The html class name to use for this field. * @type {?string} @@ -39,31 +40,31 @@ Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - Blockly.FieldLabel.superClass_.constructor.call( + FieldLabel.superClass_.constructor.call( this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(Blockly.FieldLabel, Blockly.Field); +Blockly.utils.object.inherits(FieldLabel, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; +FieldLabel.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldLabel from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabel} The new field instance. + * @return {!FieldLabel} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabel.fromJson = function(options) { +FieldLabel.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. @@ -75,13 +76,13 @@ Blockly.FieldLabel.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabel.prototype.EDITABLE = false; +FieldLabel.prototype.EDITABLE = false; /** * @override */ -Blockly.FieldLabel.prototype.configure_ = function(config) { - Blockly.FieldLabel.superClass_.configure_.call(this, config); +FieldLabel.prototype.configure_ = function(config) { + FieldLabel.superClass_.configure_.call(this, config); this.class_ = config['class']; }; @@ -89,7 +90,7 @@ Blockly.FieldLabel.prototype.configure_ = function(config) { * Create block UI for this label. * @package */ -Blockly.FieldLabel.prototype.initView = function() { +FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { Blockly.utils.dom.addClass( @@ -103,7 +104,7 @@ Blockly.FieldLabel.prototype.initView = function() { * @return {?string} A valid string, or null if invalid. * @protected */ -Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { +FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -114,7 +115,7 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { * Set the CSS class applied to the field's textElement_. * @param {?string} cssClass The new CSS class name, or null to remove. */ -Blockly.FieldLabel.prototype.setClass = function(cssClass) { +FieldLabel.prototype.setClass = function(cssClass) { if (this.textElement_) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. @@ -128,4 +129,6 @@ Blockly.FieldLabel.prototype.setClass = function(cssClass) { this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel); +Blockly.fieldRegistry.register('field_label', FieldLabel); + +exports = FieldLabel; diff --git a/tests/deps.js b/tests/deps.js index 3dc163ac5..9b2ca48af 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -54,7 +54,7 @@ goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], [' goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});