mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
Migrate core/field_number.js to goog.module
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.FieldNumber');
|
||||
goog.module('Blockly.FieldNumber');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.fieldRegistry');
|
||||
goog.require('Blockly.FieldTextInput');
|
||||
@@ -34,7 +35,7 @@ goog.require('Blockly.utils.object');
|
||||
* @extends {Blockly.FieldTextInput}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision,
|
||||
const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision,
|
||||
opt_validator, opt_config) {
|
||||
|
||||
/**
|
||||
@@ -66,31 +67,31 @@ Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision,
|
||||
*/
|
||||
this.decimalPlaces_ = null;
|
||||
|
||||
Blockly.FieldNumber.superClass_.constructor.call(
|
||||
FieldNumber.superClass_.constructor.call(
|
||||
this, opt_value, opt_validator, opt_config);
|
||||
|
||||
if (!opt_config) { // Only do one kind of configuration or the other.
|
||||
this.setConstraints(opt_min, opt_max, opt_precision);
|
||||
}
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.FieldNumber, Blockly.FieldTextInput);
|
||||
Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput);
|
||||
|
||||
/**
|
||||
* The default value for this field.
|
||||
* @type {*}
|
||||
* @protected
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.DEFAULT_VALUE = 0;
|
||||
FieldNumber.prototype.DEFAULT_VALUE = 0;
|
||||
|
||||
/**
|
||||
* Construct a FieldNumber from a JSON arg object.
|
||||
* @param {!Object} options A JSON object with options (value, min, max, and
|
||||
* precision).
|
||||
* @return {!Blockly.FieldNumber} The new field instance.
|
||||
* @return {!FieldNumber} The new field instance.
|
||||
* @package
|
||||
* @nocollapse
|
||||
*/
|
||||
Blockly.FieldNumber.fromJson = function(options) {
|
||||
FieldNumber.fromJson = function(options) {
|
||||
// `this` might be a subclass of FieldNumber if that class doesn't override
|
||||
// the static fromJson method.
|
||||
return new this(options['value'],
|
||||
@@ -102,7 +103,7 @@ Blockly.FieldNumber.fromJson = function(options) {
|
||||
* are not. Editable fields should also be serializable.
|
||||
* @type {boolean}
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.SERIALIZABLE = true;
|
||||
FieldNumber.prototype.SERIALIZABLE = true;
|
||||
|
||||
/**
|
||||
* Configure the field based on the given map of options.
|
||||
@@ -110,8 +111,8 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true;
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.configure_ = function(config) {
|
||||
Blockly.FieldNumber.superClass_.configure_.call(this, config);
|
||||
FieldNumber.prototype.configure_ = function(config) {
|
||||
FieldNumber.superClass_.configure_.call(this, config);
|
||||
this.setMinInternal_(config['min']);
|
||||
this.setMaxInternal_(config['max']);
|
||||
this.setPrecisionInternal_(config['precision']);
|
||||
@@ -128,7 +129,7 @@ Blockly.FieldNumber.prototype.configure_ = function(config) {
|
||||
* @param {?(number|string|undefined)} max Maximum value.
|
||||
* @param {?(number|string|undefined)} precision Precision for value.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) {
|
||||
FieldNumber.prototype.setConstraints = function(min, max, precision) {
|
||||
this.setMinInternal_(min);
|
||||
this.setMaxInternal_(max);
|
||||
this.setPrecisionInternal_(precision);
|
||||
@@ -139,7 +140,7 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) {
|
||||
* Sets the minimum value this field can contain. Updates the value to reflect.
|
||||
* @param {?(number|string|undefined)} min Minimum value.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setMin = function(min) {
|
||||
FieldNumber.prototype.setMin = function(min) {
|
||||
this.setMinInternal_(min);
|
||||
this.setValue(this.getValue());
|
||||
};
|
||||
@@ -150,7 +151,7 @@ Blockly.FieldNumber.prototype.setMin = function(min) {
|
||||
* @param {?(number|string|undefined)} min Minimum value.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setMinInternal_ = function(min) {
|
||||
FieldNumber.prototype.setMinInternal_ = function(min) {
|
||||
if (min == null) {
|
||||
this.min_ = -Infinity;
|
||||
} else {
|
||||
@@ -166,7 +167,7 @@ Blockly.FieldNumber.prototype.setMinInternal_ = function(min) {
|
||||
* -Infinity.
|
||||
* @return {number} The current minimum value this field can contain.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.getMin = function() {
|
||||
FieldNumber.prototype.getMin = function() {
|
||||
return this.min_;
|
||||
};
|
||||
|
||||
@@ -174,7 +175,7 @@ Blockly.FieldNumber.prototype.getMin = function() {
|
||||
* Sets the maximum value this field can contain. Updates the value to reflect.
|
||||
* @param {?(number|string|undefined)} max Maximum value.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setMax = function(max) {
|
||||
FieldNumber.prototype.setMax = function(max) {
|
||||
this.setMaxInternal_(max);
|
||||
this.setValue(this.getValue());
|
||||
};
|
||||
@@ -185,7 +186,7 @@ Blockly.FieldNumber.prototype.setMax = function(max) {
|
||||
* @param {?(number|string|undefined)} max Maximum value.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) {
|
||||
FieldNumber.prototype.setMaxInternal_ = function(max) {
|
||||
if (max == null) {
|
||||
this.max_ = Infinity;
|
||||
} else {
|
||||
@@ -201,7 +202,7 @@ Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) {
|
||||
* Infinity.
|
||||
* @return {number} The current maximum value this field can contain.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.getMax = function() {
|
||||
FieldNumber.prototype.getMax = function() {
|
||||
return this.max_;
|
||||
};
|
||||
|
||||
@@ -211,7 +212,7 @@ Blockly.FieldNumber.prototype.getMax = function() {
|
||||
* @param {?(number|string|undefined)} precision The number to which the
|
||||
* field's value is rounded.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setPrecision = function(precision) {
|
||||
FieldNumber.prototype.setPrecision = function(precision) {
|
||||
this.setPrecisionInternal_(precision);
|
||||
this.setValue(this.getValue());
|
||||
};
|
||||
@@ -223,7 +224,7 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) {
|
||||
* field's value is rounded.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) {
|
||||
FieldNumber.prototype.setPrecisionInternal_ = function(precision) {
|
||||
this.precision_ = Number(precision) || 0;
|
||||
let precisionString = String(this.precision_);
|
||||
if (precisionString.indexOf('e') != -1) {
|
||||
@@ -248,7 +249,7 @@ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) {
|
||||
* the value is not rounded.
|
||||
* @return {number} The number to which this field's value is rounded.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.getPrecision = function() {
|
||||
FieldNumber.prototype.getPrecision = function() {
|
||||
return this.precision_;
|
||||
};
|
||||
|
||||
@@ -260,7 +261,7 @@ Blockly.FieldNumber.prototype.getPrecision = function() {
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
FieldNumber.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
if (opt_newValue === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -299,8 +300,8 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.widgetCreate_ = function() {
|
||||
const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this);
|
||||
FieldNumber.prototype.widgetCreate_ = function() {
|
||||
const htmlInput = FieldNumber.superClass_.widgetCreate_.call(this);
|
||||
|
||||
// Set the accessibility state
|
||||
if (this.min_ > -Infinity) {
|
||||
@@ -314,4 +315,6 @@ Blockly.FieldNumber.prototype.widgetCreate_ = function() {
|
||||
return htmlInput;
|
||||
};
|
||||
|
||||
Blockly.fieldRegistry.register('field_number', Blockly.FieldNumber);
|
||||
Blockly.fieldRegistry.register('field_number', FieldNumber);
|
||||
|
||||
exports = FieldNumber;
|
||||
|
||||
@@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl
|
||||
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_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']);
|
||||
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': 'es5'});
|
||||
goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'});
|
||||
goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']);
|
||||
goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']);
|
||||
|
||||
Reference in New Issue
Block a user