Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed opt_ prefix from optional parameters and gave them default value in plugins #775

Merged
merged 8 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/block-plus-minus/src/field_minus.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import * as Blockly from 'blockly/core';

/**
* Creates a minus image field used for mutation.
* @param {Object=} opt_args Untyped args passed to block.minus when the field
* @param {Object=} args Untyped args passed to block.minus when the field
* is clicked.
* @return {Blockly.FieldImage} The minus field.
*/
export function createMinusField(opt_args) {
export function createMinusField(args = undefined) {
const minus = new Blockly.FieldImage(minusImage, 15, 15, undefined, onClick_);
/**
* Untyped args passed to block.minus when the field is clicked.
* @type {Object}
* @type {?(Object|undefined)}
* @private
*/
minus.args_ = opt_args;
minus.args_ = args;
return minus;
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/block-plus-minus/src/field_plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import * as Blockly from 'blockly/core';

/**
* Creates a plus image field used for mutation.
* @param {Object=} opt_args Untyped args passed to block.minus when the field
* @param {Object=} args Untyped args passed to block.minus when the field
* is clicked.
* @return {Blockly.FieldImage} The Plus field.
*/
export function createPlusField(opt_args) {
export function createPlusField(args = undefined) {
const plus = new Blockly.FieldImage(plusImage, 15, 15, undefined, onClick_);
/**
* Untyped args passed to block.plus when the field is clicked.
* @type {Object}
* @type {?(Object|undefined)}
* @private
*/
plus.args_ = opt_args;
plus.args_ = args;
return plus;
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/block-plus-minus/src/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ const controlsIfMutator = {
* Appears to remove the input at the given index. Actually shifts attached
* blocks and then removes the input at the bottom of the block. This is to
* make sure the inputs are always IF0, IF1, etc with no gaps.
* @param {number?} opt_index The index of the input to "remove", or undefined
* @param {?number=} index The index of the input to "remove", or undefined
* to remove the last input.
* @this {Blockly.Block}
* @private
*/
removeElseIf_: function(opt_index) {
removeElseIf_: function(index = undefined) {
// The strategy for removing a part at an index is to:
// - Kick any blocks connected to the relevant inputs.
// - Move all connect blocks from the other inputs up.
// - Remove the last input.
// This makes sure all of our indices are correct.

if (opt_index !== undefined && opt_index!= this.elseIfCount_) {
if (index !== undefined && index!= this.elseIfCount_) {
// Each else-if is two inputs on the block:
// the else-if input and the do input.
const elseIfIndex = opt_index * 2;
const elseIfIndex = index * 2;
const inputs = this.inputList;
let connection = inputs[elseIfIndex].connection; // If connection.
if (connection.isConnected()) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/continuous-toolbox/src/ContinuousMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class ContinuousMetrics extends Blockly.MetricsManager {
* The default viewport includes the flyout.
* @override
*/
getViewMetrics(opt_getWorkspaceCoordinates) {
const scale = opt_getWorkspaceCoordinates ? this.workspace_.scale : 1;
getViewMetrics(getWorkspaceCoordinates = undefined) {
const scale = getWorkspaceCoordinates ? this.workspace_.scale : 1;
const svgMetrics = this.getSvgMetrics();
const toolboxMetrics = this.getToolboxMetrics();
const flyoutMetrics = this.getFlyoutMetrics(false);
Expand Down
14 changes: 8 additions & 6 deletions plugins/continuous-toolbox/src/ContinuousMetricsFlyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export class ContinuousFlyoutMetrics extends Blockly.FlyoutMetricsManager {
* @override
*/
getScrollMetrics(
opt_getWorkspaceCoordinates, opt_viewMetrics, opt_contentMetrics) {
getWorkspaceCoordinates = undefined,
cachedViewMetrics = undefined,
cachedContentMetrics = undefined) {
const scrollMetrics = super.getScrollMetrics(
opt_getWorkspaceCoordinates, opt_viewMetrics, opt_contentMetrics);
const contentMetrics = opt_contentMetrics ||
this.getContentMetrics(opt_getWorkspaceCoordinates);
const viewMetrics = opt_viewMetrics ||
this.getViewMetrics(opt_getWorkspaceCoordinates);
getWorkspaceCoordinates, cachedViewMetrics, cachedContentMetrics);
const contentMetrics = cachedContentMetrics ||
this.getContentMetrics(getWorkspaceCoordinates);
const viewMetrics = cachedViewMetrics ||
this.getViewMetrics(getWorkspaceCoordinates);

if (scrollMetrics) {
scrollMetrics.height +=
Expand Down
40 changes: 20 additions & 20 deletions plugins/field-date/src/field_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ goog.require('goog.ui.DatePicker');

/**
* Class for a date input field.
* @param {string=} opt_value The initial value of the field. Should be in
* @param {string=} value The initial value of the field. Should be in
* 'YYYY-MM-DD' format. Defaults to the current date.
* @param {Function=} opt_validator A function that is called to validate
* @param {Function=} validator A function that is called to validate
* changes to the field's value. Takes in a date string & returns a
* validated date string ('YYYY-MM-DD' format), or null to abort the change.
* @param {?(boolean|string)=} opt_textEdit Whether to enable text editor.
* @param {?(boolean|string)=} textEdit Whether to enable text editor.
* @extends {Blockly.Field}
* @constructor
*/
Blockly.FieldDate = function(opt_value, opt_validator, opt_textEdit = false) {
Blockly.FieldDate = function(value = undefined, validator = undefined, textEdit = false) {
/**
* The default value for this field (current date).
* @type {*}
Expand All @@ -47,15 +47,15 @@ Blockly.FieldDate = function(opt_value, opt_validator, opt_textEdit = false) {
Blockly.FieldDate.prototype.DEFAULT_VALUE =
new goog.date.Date().toIsoString(true);

Blockly.FieldDate.superClass_.constructor.call(this, opt_value,
opt_validator);
Blockly.FieldDate.superClass_.constructor.call(this, value,
validator);

/**
* Whether text editing is enabled on this field.
* @type {boolean}
* @private
*/
this.textEditEnabled_ = opt_textEdit == true || opt_textEdit == 'true';
this.textEditEnabled_ = textEdit == true || textEdit == 'true';
};
Blockly.utils.object.inherits(Blockly.FieldDate, Blockly.FieldTextInput);

Expand Down Expand Up @@ -100,20 +100,20 @@ Blockly.FieldDate.prototype.DROPDOWN_BACKGROUND_COLOUR = 'white';

/**
* Ensures that the input value is a valid date.
* @param {*=} opt_newValue The input value.
* @param {*=} newValue The input value.
* @return {?string} A valid date, or null if invalid.
* @protected
*/
Blockly.FieldDate.prototype.doClassValidation_ = function(opt_newValue) {
if (!opt_newValue) {
Blockly.FieldDate.prototype.doClassValidation_ = function(newValue = undefined) {
if (!newValue) {
return null;
}
// Check if the new value is parsable or not.
var date = goog.date.Date.fromIsoString(opt_newValue);
if (!date || date.toIsoString(true) != opt_newValue) {
var date = goog.date.Date.fromIsoString(newValue);
if (!date || date.toIsoString(true) != newValue) {
return null;
}
return opt_newValue;
return newValue;
};

/**
Expand Down Expand Up @@ -177,20 +177,20 @@ Blockly.FieldDate.prototype.updateEditor_ = function() {
/**
* Shows the inline free-text editor on top of the text along with the date
* editor.
* @param {Event=} opt_e Optional mouse event that triggered the field to
* @param {Event=} e Optional mouse event that triggered the field to
* open, or undefined if triggered programmatically.
* @param {boolean=} _opt_quietInput Quiet input.
* @param {boolean=} _quietInput Quiet input.
* @protected
* @override
*/
Blockly.FieldDate.prototype.showEditor_ = function(opt_e, _opt_quietInput) {
Blockly.FieldDate.prototype.showEditor_ = function(e = undefined, _quietInput = undefined) {
if (this.textEditEnabled_) {
// Mobile browsers have issues with in-line textareas (focus & keyboards).
const noFocus =
Blockly.utils.userAgent.MOBILE ||
Blockly.utils.userAgent.ANDROID ||
Blockly.utils.userAgent.IPAD;
Blockly.FieldDate.superClass_.showEditor_.call(this, opt_e, noFocus);
Blockly.FieldDate.superClass_.showEditor_.call(this, e, noFocus);
}
// Build the DOM.
this.showDropdown_();
Expand Down Expand Up @@ -409,16 +409,16 @@ goog.getMsgOrig = goog.getMsg;
* Overrides the default Closure function to check for a Blockly.Msg first.
* Used infrequently, only known case is TODAY button in date picker.
* @param {string} str Translatable string, places holders in the form {$foo}.
* @param {Object.<string, string>=} opt_values Maps place holder name to value.
* @param {Object.<string, string>=} values Maps place holder name to value.
* @return {string} Message with placeholders filled.
* @suppress {duplicate}
*/
goog.getMsg = function(str, opt_values) {
goog.getMsg = function(str, values = undefined) {
var key = goog.getMsg.blocklyMsgMap[str];
if (key) {
str = Blockly.Msg[key];
}
return goog.getMsgOrig(str, opt_values);
return goog.getMsgOrig(str, values);
};

/**
Expand Down
18 changes: 9 additions & 9 deletions plugins/field-grid-dropdown/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export class FieldGridDropdown extends Blockly.FieldDropdown {
* @param {(!Array.<!Array>|!Function)} menuGenerator A non-empty array of
* options for a dropdown list, or a function which generates these
* options.
* @param {Function=} opt_validator A function that is called to validate
* @param {Function=} validator A function that is called to validate
* changes to the field's value. Takes in a language-neutral dropdown
* option & returns a validated language-neutral dropdown option, or null
* to abort the change.
* @param {Object=} opt_config A map of options used to configure the field.
* @param {Object=} config A map of options used to configure the field.
* See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation}
* for a list of properties this parameter supports.
* @extends {Blockly.Field}
* @constructor
* @throws {TypeError} If `menuGenerator` options are incorrectly structured.
*/
constructor(menuGenerator, opt_validator, opt_config) {
super(menuGenerator, opt_validator, opt_config);
constructor(menuGenerator, validator = undefined, config = undefined) {
super(menuGenerator, validator, config);

/**
* The number of columns in the dropdown grid. Must be an integer value
Expand All @@ -41,8 +41,8 @@ export class FieldGridDropdown extends Blockly.FieldDropdown {
* @private
*/
this.columns_ = 3;
if (opt_config && opt_config['columns']) {
this.setColumnsInternal_(opt_config['columns']);
if (config && config['columns']) {
this.setColumnsInternal_(config['columns']);
}
}

Expand Down Expand Up @@ -85,13 +85,13 @@ export class FieldGridDropdown extends Blockly.FieldDropdown {

/**
* Create a dropdown menu under the text.
* @param {Event=} opt_e Optional mouse event that triggered the field to
* @param {Event=} e Optional mouse event that triggered the field to
* open, or undefined if triggered programmatically.
* @protected
* @override
*/
showEditor_(opt_e) {
super.showEditor_(opt_e);
showEditor_(e = undefined) {
super.showEditor_(e);

// Grid dropdown is always colored.
const primaryColour = (this.sourceBlock_.isShadow()) ?
Expand Down
34 changes: 20 additions & 14 deletions plugins/field-slider/src/field_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ import * as Blockly from 'blockly/core';
export class FieldSlider extends Blockly.FieldNumber {
/**
* Class for an number slider field.
* @param {string|number=} opt_value The initial value of the field. Should
* @param {string|number=} value The initial value of the field. Should
* cast to a number. Defaults to 0.
* @param {?(string|number)=} opt_min Minimum value.
* @param {?(string|number)=} opt_max Maximum value.
* @param {?(string|number)=} opt_precision Precision for value.
* @param {?Function=} opt_validator A function that is called to validate
* @param {?(string|number)=} min Minimum value.
* @param {?(string|number)=} max Maximum value.
* @param {?(string|number)=} precision Precision for value.
* @param {?Function=} validator A function that is called to validate
* changes to the field's value. Takes in a number & returns a validated
* number, or null to abort the change.
* @param {Object=} opt_config A map of options used to configure the field.
* @param {Object=} config A map of options used to configure the field.
* See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation}
* for a list of properties this parameter supports.
* @extends {Blockly.FieldNumber}
* @constructor
*/
constructor(opt_value, opt_min, opt_max, opt_precision,
opt_validator, opt_config) {
super(opt_value, opt_min, opt_max, opt_precision, opt_validator,
opt_config);
constructor(
value = undefined,
min = undefined,
max = undefined,
precision = undefined,
validator = undefined,
config = undefined) {

super(value, min, max, precision, validator,
config);

/**
* Array holding info needed to unbind events.
Expand Down Expand Up @@ -69,19 +75,19 @@ export class FieldSlider extends Blockly.FieldNumber {
/**
* Show the inline free-text editor on top of the text along with the slider
* editor.
* @param {Event=} opt_e Optional mouse event that triggered the field to
* @param {Event=} e Optional mouse event that triggered the field to
* open, or undefined if triggered programmatically.
* @param {boolean=} _opt_quietInput Quiet input.
* @param {boolean=} _quietInput Quiet input.
* @protected
* @override
*/
showEditor_(opt_e, _opt_quietInput) {
showEditor_(e = undefined, _quietInput = undefined) {
// Mobile browsers have issues with in-line textareas (focus & keyboards).
const noFocus =
Blockly.utils.userAgent.MOBILE ||
Blockly.utils.userAgent.ANDROID ||
Blockly.utils.userAgent.IPAD;
super.showEditor_(opt_e, noFocus);
super.showEditor_(e, noFocus);
// Build the DOM.
const editor = this.dropdownCreate_();

Expand Down
6 changes: 3 additions & 3 deletions plugins/fixed-edges/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ export class FixedEdgesMetricsManager extends Blockly.MetricsManager {

/**
* Computes the fixed edges of the scroll area.
* @param {!Blockly.MetricsManager.ContainerRegion=} opt_viewMetrics The view
* @param {!Blockly.MetricsManager.ContainerRegion=} cachedViewMetrics The view
* metrics if they have been previously computed. Passing in null may
* cause the view metrics to be computed again, if it is needed.
* @return {!Blockly.MetricsManager.FixedEdges} The fixed edges of the scroll
* area.
* @protected
* @override
*/
getComputedFixedEdges_(opt_viewMetrics) {
getComputedFixedEdges_(cachedViewMetrics = undefined) {
const hScrollEnabled = this.workspace_.isMovableHorizontally();
const vScrollEnabled = this.workspace_.isMovableVertically();

const viewMetrics = opt_viewMetrics || this.getViewMetrics(false);
const viewMetrics = cachedViewMetrics || this.getViewMetrics(false);

const edges = {
top: fixedEdges.top ? 0 : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ suite('WorkspaceSearch', () => {
/**
* Assert that no extra styling is currently added to these blocks.
* @param {Array.<Blockly.BlockSvg>} blocks The blocks to test.
* @param {Blockly.BlockSvg=} opt_expectedCurrent Optional, block that is
* @param {Blockly.BlockSvg=} expectedCurrent Optional, block that is
* expected.
*/
function assertNoExtraCurrentStyling(blocks, opt_expectedCurrent) {
function assertNoExtraCurrentStyling(blocks, expectedCurrent = undefined) {
for (let block, i = 0; (block = blocks[i]); i++) {
const isCurrentStyled = isBlockCurrentStyled(block);
if (isCurrentStyled) {
assert.equal(opt_expectedCurrent, block,
assert.equal(expectedCurrent, block,
'Unexpected block [' + block.type +
'] found styled as current.');
} else {
assert.notEqual(block, opt_expectedCurrent,
assert.notEqual(block, expectedCurrent,
'Expected block [' + block.type + '] to be styled as current.');
}
}
Expand Down