From 520aa600a6532d0786461eca7c88199e92640677 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 2 Dec 2020 14:54:28 -0800 Subject: [PATCH] Remove deprecated field functions (#4489) --- core/field.js | 82 --------------------------------- core/field_textinput.js | 39 ---------------- tests/mocha/field_image_test.js | 9 ---- 3 files changed, 130 deletions(-) diff --git a/core/field.js b/core/field.js index 40bd48b2f..94b67f89f 100644 --- a/core/field.js +++ b/core/field.js @@ -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; }; diff --git a/core/field_textinput.js b/core/field_textinput.js index 9a5d1d574..9c7499723 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -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. diff --git a/tests/mocha/field_image_test.js b/tests/mocha/field_image_test.js index 09eaa2f20..e014f2b9d 100644 --- a/tests/mocha/field_image_test.js +++ b/tests/mocha/field_image_test.js @@ -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');