mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Remove deprecated field functions (#4489)
This commit is contained in:
@@ -19,7 +19,6 @@ goog.require('Blockly.Events.BlockChange');
|
||||
goog.require('Blockly.Gesture');
|
||||
goog.require('Blockly.Tooltip');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.deprecation');
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.Rect');
|
||||
goog.require('Blockly.utils.Size');
|
||||
@@ -533,54 +532,6 @@ Blockly.Field.prototype.getValidator = function() {
|
||||
return this.validator_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a change. Does nothing. Subclasses may override this.
|
||||
* @param {string} text The user's text.
|
||||
* @return {string} No change needed.
|
||||
* @deprecated May 2019. Override doClassValidation and other relevant 'do'
|
||||
* functions instead.
|
||||
*/
|
||||
Blockly.Field.prototype.classValidator = function(text) {
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Field.prototype.classValidator',
|
||||
'May 2019',
|
||||
'December 2020',
|
||||
'Blockly.Field.prototype.doClassValidation_');
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls the validation function for this field, as well as all the validation
|
||||
* function for the field's class and its parents.
|
||||
* @param {string} text Proposed text.
|
||||
* @return {?string} Revised text, or null if invalid.
|
||||
* @deprecated May 2019. setValue now contains all relevant logic.
|
||||
*/
|
||||
Blockly.Field.prototype.callValidator = function(text) {
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Field.prototype.callValidator',
|
||||
'May 2019',
|
||||
'December 2020');
|
||||
var classResult = this.classValidator(text);
|
||||
if (classResult === null) {
|
||||
// Class validator rejects value. Game over.
|
||||
return null;
|
||||
} else if (classResult !== undefined) {
|
||||
text = classResult;
|
||||
}
|
||||
var userValidator = this.getValidator();
|
||||
if (userValidator) {
|
||||
var userResult = userValidator.call(this, text);
|
||||
if (userResult === null) {
|
||||
// User validator rejects value. Game over.
|
||||
return null;
|
||||
} else if (userResult !== undefined) {
|
||||
text = userResult;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the group element for this editable field.
|
||||
* Used for measuring the size and for positioning.
|
||||
@@ -625,22 +576,6 @@ Blockly.Field.prototype.showEditor = function(opt_e) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the width of the field. Redirects to updateSize_().
|
||||
* @deprecated May 2019 Use Blockly.Field.updateSize_() to force an update
|
||||
* to the size of the field, or Blockly.utils.dom.getTextWidth() to
|
||||
* check the size of the field.
|
||||
*/
|
||||
Blockly.Field.prototype.updateWidth = function() {
|
||||
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Field.prototype.updateWidth',
|
||||
'May 2019',
|
||||
'December 2020',
|
||||
'Blockly.Field.prototype.updateSize_ or Blockly.utils.dom.getTextWidth');
|
||||
this.updateSize_();
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the size of the field based on the text.
|
||||
* @param {number=} opt_margin margin to use when positioning the text element.
|
||||
@@ -818,20 +753,6 @@ Blockly.Field.prototype.getText = function() {
|
||||
return String(this.getValue());
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the text in this field. Trigger a rerender of the source block.
|
||||
* @param {*} _newText New text.
|
||||
* @deprecated 2019 setText should not be used directly. Use setValue instead.
|
||||
*/
|
||||
Blockly.Field.prototype.setText = function(_newText) {
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Field.prototype.setText',
|
||||
'May 2019',
|
||||
'December 2020',
|
||||
'Blockly.Field.prototype.setValue');
|
||||
throw Error('setText method is deprecated');
|
||||
};
|
||||
|
||||
/**
|
||||
* Force a rerender of the block that this field is installed on, which will
|
||||
* rerender this field and adjust for any sizing changes.
|
||||
@@ -951,14 +872,11 @@ Blockly.Field.prototype.getValue = function() {
|
||||
* @param {*=} opt_newValue The value to be validated.
|
||||
* @return {*} The validated value, same as input by default.
|
||||
* @protected
|
||||
* @suppress {deprecated} Suppress deprecated this.classValidator call.
|
||||
*/
|
||||
Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
if (opt_newValue === null || opt_newValue === undefined) {
|
||||
return null;
|
||||
}
|
||||
// For backwards compatibility.
|
||||
opt_newValue = this.classValidator(/** @type {string} */ (opt_newValue));
|
||||
return opt_newValue;
|
||||
};
|
||||
|
||||
|
||||
@@ -523,45 +523,6 @@ Blockly.FieldTextInput.prototype.resizeEditor_ = function() {
|
||||
div.style.top = xy.y + 'px';
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensure that only a number may be entered.
|
||||
* @param {string} text The user's text.
|
||||
* @return {?string} A string representing a valid number, or null if invalid.
|
||||
* @deprecated
|
||||
*/
|
||||
Blockly.FieldTextInput.numberValidator = function(text) {
|
||||
Blockly.utils.deprecation.warn(
|
||||
'FieldTextInput.numberValidator',
|
||||
'May 2019',
|
||||
'December 2020',
|
||||
'Blockly.FieldNumber');
|
||||
if (text === null) {
|
||||
return null;
|
||||
}
|
||||
text = String(text);
|
||||
// TODO: Handle cases like 'ten', '1.203,14', etc.
|
||||
// 'O' is sometimes mistaken for '0' by inexperienced users.
|
||||
text = text.replace(/O/ig, '0');
|
||||
// Strip out thousands separators.
|
||||
text = text.replace(/,/g, '');
|
||||
var n = Number(text || 0);
|
||||
return isNaN(n) ? null : String(n);
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensure that only a non-negative integer may be entered.
|
||||
* @param {string} text The user's text.
|
||||
* @return {?string} A string representing a valid int, or null if invalid.
|
||||
* @deprecated
|
||||
*/
|
||||
Blockly.FieldTextInput.nonnegativeIntegerValidator = function(text) {
|
||||
var n = Blockly.FieldTextInput.numberValidator(text);
|
||||
if (n) {
|
||||
n = String(Math.max(0, Math.floor(n)));
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns whether or not the field is tab navigable.
|
||||
* @return {boolean} True if the field is tab navigable.
|
||||
|
||||
@@ -115,15 +115,6 @@ suite('Image Fields', function() {
|
||||
});
|
||||
chai.assert.equal(field.altText_, 'alt');
|
||||
});
|
||||
test('Deprecated - setText', function() {
|
||||
var deprecateWarnSpy = createDeprecationWarningStub();
|
||||
var field = new Blockly.FieldImage('src', 10, 10, 'alt');
|
||||
chai.assert.throws(function() {
|
||||
field.setText('newAlt');
|
||||
});
|
||||
assertSingleDeprecationWarningCall(deprecateWarnSpy,
|
||||
'Field.prototype.setText');
|
||||
});
|
||||
suite('SetAlt', function() {
|
||||
setup(function() {
|
||||
this.imageField = new Blockly.FieldImage('src', 10, 10, 'alt');
|
||||
|
||||
Reference in New Issue
Block a user