mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Migrate core/field_checkbox.js to goog.module
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.FieldCheckbox');
|
||||
goog.module('Blockly.FieldCheckbox');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.Events.BlockChange');
|
||||
@@ -34,7 +35,7 @@ goog.require('Blockly.utils.object');
|
||||
* @extends {Blockly.Field}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) {
|
||||
const FieldCheckbox = function(opt_value, opt_validator, opt_config) {
|
||||
/**
|
||||
* Character for the check mark. Used to apply a different check mark
|
||||
* character to individual fields.
|
||||
@@ -43,26 +44,26 @@ Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) {
|
||||
*/
|
||||
this.checkChar_ = null;
|
||||
|
||||
Blockly.FieldCheckbox.superClass_.constructor.call(
|
||||
FieldCheckbox.superClass_.constructor.call(
|
||||
this, opt_value, opt_validator, opt_config);
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.FieldCheckbox, Blockly.Field);
|
||||
Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field);
|
||||
|
||||
/**
|
||||
* The default value for this field.
|
||||
* @type {*}
|
||||
* @protected
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.DEFAULT_VALUE = false;
|
||||
FieldCheckbox.prototype.DEFAULT_VALUE = false;
|
||||
|
||||
/**
|
||||
* Construct a FieldCheckbox from a JSON arg object.
|
||||
* @param {!Object} options A JSON object with options (checked).
|
||||
* @return {!Blockly.FieldCheckbox} The new field instance.
|
||||
* @return {!FieldCheckbox} The new field instance.
|
||||
* @package
|
||||
* @nocollapse
|
||||
*/
|
||||
Blockly.FieldCheckbox.fromJson = function(options) {
|
||||
FieldCheckbox.fromJson = function(options) {
|
||||
// `this` might be a subclass of FieldCheckbox if that class doesn't override
|
||||
// the static fromJson method.
|
||||
return new this(options['checked'], undefined, options);
|
||||
@@ -73,19 +74,19 @@ Blockly.FieldCheckbox.fromJson = function(options) {
|
||||
* @type {string}
|
||||
* @const
|
||||
*/
|
||||
Blockly.FieldCheckbox.CHECK_CHAR = '\u2713';
|
||||
FieldCheckbox.CHECK_CHAR = '\u2713';
|
||||
|
||||
/**
|
||||
* Serializable fields are saved by the XML renderer, non-serializable fields
|
||||
* are not. Editable fields should also be serializable.
|
||||
* @type {boolean}
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.SERIALIZABLE = true;
|
||||
FieldCheckbox.prototype.SERIALIZABLE = true;
|
||||
|
||||
/**
|
||||
* Mouse cursor style when over the hotspot that initiates editability.
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.CURSOR = 'default';
|
||||
FieldCheckbox.prototype.CURSOR = 'default';
|
||||
|
||||
/**
|
||||
* Configure the field based on the given map of options.
|
||||
@@ -93,8 +94,8 @@ Blockly.FieldCheckbox.prototype.CURSOR = 'default';
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.configure_ = function(config) {
|
||||
Blockly.FieldCheckbox.superClass_.configure_.call(this, config);
|
||||
FieldCheckbox.prototype.configure_ = function(config) {
|
||||
FieldCheckbox.superClass_.configure_.call(this, config);
|
||||
if (config['checkCharacter']) {
|
||||
this.checkChar_ = config['checkCharacter'];
|
||||
}
|
||||
@@ -104,8 +105,8 @@ Blockly.FieldCheckbox.prototype.configure_ = function(config) {
|
||||
* Create the block UI for this checkbox.
|
||||
* @package
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.initView = function() {
|
||||
Blockly.FieldCheckbox.superClass_.initView.call(this);
|
||||
FieldCheckbox.prototype.initView = function() {
|
||||
FieldCheckbox.superClass_.initView.call(this);
|
||||
|
||||
Blockly.utils.dom.addClass(
|
||||
/** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox');
|
||||
@@ -115,7 +116,7 @@ Blockly.FieldCheckbox.prototype.initView = function() {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.render_ = function() {
|
||||
FieldCheckbox.prototype.render_ = function() {
|
||||
if (this.textContent_) {
|
||||
this.textContent_.nodeValue = this.getDisplayText_();
|
||||
}
|
||||
@@ -125,8 +126,8 @@ Blockly.FieldCheckbox.prototype.render_ = function() {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.getDisplayText_ = function() {
|
||||
return this.checkChar_ || Blockly.FieldCheckbox.CHECK_CHAR;
|
||||
FieldCheckbox.prototype.getDisplayText_ = function() {
|
||||
return this.checkChar_ || FieldCheckbox.CHECK_CHAR;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -134,7 +135,7 @@ Blockly.FieldCheckbox.prototype.getDisplayText_ = function() {
|
||||
* @param {?string} character The character to use for the check mark, or
|
||||
* null to use the default.
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) {
|
||||
FieldCheckbox.prototype.setCheckCharacter = function(character) {
|
||||
this.checkChar_ = character;
|
||||
this.forceRerender();
|
||||
};
|
||||
@@ -143,7 +144,7 @@ Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) {
|
||||
* Toggle the state of the checkbox on click.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.showEditor_ = function() {
|
||||
FieldCheckbox.prototype.showEditor_ = function() {
|
||||
this.setValue(!this.value_);
|
||||
};
|
||||
|
||||
@@ -153,7 +154,7 @@ Blockly.FieldCheckbox.prototype.showEditor_ = function() {
|
||||
* @return {?string} A valid value ('TRUE' or 'FALSE), or null if invalid.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
if (opt_newValue === true || opt_newValue === 'TRUE') {
|
||||
return 'TRUE';
|
||||
}
|
||||
@@ -169,7 +170,7 @@ Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
* that this is a either 'TRUE' or 'FALSE'.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) {
|
||||
FieldCheckbox.prototype.doValueUpdate_ = function(newValue) {
|
||||
this.value_ = this.convertValueToBool_(newValue);
|
||||
// Update visual.
|
||||
if (this.textElement_) {
|
||||
@@ -181,7 +182,7 @@ Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) {
|
||||
* Get the value of this field, either 'TRUE' or 'FALSE'.
|
||||
* @return {string} The value of this field.
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.getValue = function() {
|
||||
FieldCheckbox.prototype.getValue = function() {
|
||||
return this.value_ ? 'TRUE' : 'FALSE';
|
||||
};
|
||||
|
||||
@@ -189,7 +190,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() {
|
||||
* Get the boolean value of this field.
|
||||
* @return {boolean} The boolean value of this field.
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.getValueBoolean = function() {
|
||||
FieldCheckbox.prototype.getValueBoolean = function() {
|
||||
return /** @type {boolean} */ (this.value_);
|
||||
};
|
||||
|
||||
@@ -198,7 +199,7 @@ Blockly.FieldCheckbox.prototype.getValueBoolean = function() {
|
||||
* @return {string} Text representing the value of this field
|
||||
* ('true' or 'false').
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.getText = function() {
|
||||
FieldCheckbox.prototype.getText = function() {
|
||||
return String(this.convertValueToBool_(this.value_));
|
||||
};
|
||||
|
||||
@@ -211,7 +212,7 @@ Blockly.FieldCheckbox.prototype.getText = function() {
|
||||
* @return {boolean} The converted value.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) {
|
||||
FieldCheckbox.prototype.convertValueToBool_ = function(value) {
|
||||
if (typeof value == 'string') {
|
||||
return value == 'TRUE';
|
||||
} else {
|
||||
@@ -219,4 +220,6 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) {
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.fieldRegistry.register('field_checkbox', Blockly.FieldCheckbox);
|
||||
Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox);
|
||||
|
||||
exports = FieldCheckbox;
|
||||
|
||||
@@ -50,7 +50,7 @@ goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.Co
|
||||
goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'});
|
||||
goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
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']);
|
||||
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']);
|
||||
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']);
|
||||
|
||||
Reference in New Issue
Block a user