chore: clean up field default values (#6613)

This commit is contained in:
Blake Thomas Williams
2022-11-11 15:42:09 -06:00
committed by GitHub
parent 78af46e72b
commit 6ce06e6982
8 changed files with 21 additions and 16 deletions

View File

@@ -56,6 +56,17 @@ export abstract class Field<T = unknown> implements IASTNodeLocationSvg,
IASTNodeLocationWithBlock,
IKeyboardAccessible,
IRegistrable {
/**
* To overwrite the default value which is set in **Field**, directly update
* the prototype.
*
* Example:
* ```typescript
* FieldImage.prototype.DEFAULT_VALUE = null;
* ```
*/
DEFAULT_VALUE: T|null = null;
/** Non-breaking space. */
static readonly NBSP = '\u00A0';
@@ -189,9 +200,9 @@ export abstract class Field<T = unknown> implements IASTNodeLocationSvg,
* A generic value possessed by the field.
* Should generally be non-null, only null when the field is created.
*/
this.value_ = ('DEFAULT_VALUE' in (new.target).prototype) ?
((new.target).prototype as AnyDuringMigration).DEFAULT_VALUE :
null;
this.value_ = 'DEFAULT_VALUE' in new.target.prototype ?
new.target.prototype.DEFAULT_VALUE :
this.DEFAULT_VALUE;
/** The size of the area rendered by the field. */
this.size_ = new Size(0, 0);

View File

@@ -35,9 +35,6 @@ export type FieldAngleValidator = FieldInputValidator<number>;
* @alias Blockly.FieldAngle
*/
export class FieldAngle extends FieldInput<number> {
/** The default value for this field. */
// protected override DEFAULT_VALUE = 0;
/**
* The default amount to round angles to when using a mouse or keyboard nav
* input. Must be a positive integer to support keyboard navigation.
@@ -518,7 +515,7 @@ Css.register(`
fieldRegistry.register('field_angle', FieldAngle);
(FieldAngle.prototype as AnyDuringMigration).DEFAULT_VALUE = 0;
FieldAngle.prototype.DEFAULT_VALUE = 0;
/**
* The two main modes of the angle field.

View File

@@ -238,7 +238,7 @@ export class FieldCheckbox extends Field<boolean> {
fieldRegistry.register('field_checkbox', FieldCheckbox);
(FieldCheckbox.prototype as AnyDuringMigration).DEFAULT_VALUE = false;
FieldCheckbox.prototype.DEFAULT_VALUE = false;
/**
* Config options for the checkbox field.

View File

@@ -589,10 +589,7 @@ export class FieldColour extends Field<string> {
}
/** The default value for this field. */
// AnyDuringMigration because: Property 'DEFAULT_VALUE' is protected and only
// accessible within class 'FieldColour' and its subclasses.
(FieldColour.prototype as AnyDuringMigration).DEFAULT_VALUE =
FieldColour.COLOURS[0];
FieldColour.prototype.DEFAULT_VALUE = FieldColour.COLOURS[0];
/** CSS for colour picker. See css.js for use. */
Css.register(`

View File

@@ -268,7 +268,7 @@ export class FieldImage extends Field<string> {
fieldRegistry.register('field_image', FieldImage);
(FieldImage.prototype as AnyDuringMigration).DEFAULT_VALUE = '';
FieldImage.prototype.DEFAULT_VALUE = '';
/**
* Config options for the image field.

View File

@@ -129,7 +129,7 @@ export class FieldLabel extends Field<string> {
fieldRegistry.register('field_label', FieldLabel);
(FieldLabel.prototype as AnyDuringMigration).DEFAULT_VALUE = '';
FieldLabel.prototype.DEFAULT_VALUE = '';
// clang-format off
// Clang does not like the 'class' keyword being used as a property.

View File

@@ -322,7 +322,7 @@ export class FieldNumber extends FieldInput<number> {
fieldRegistry.register('field_number', FieldNumber);
(FieldNumber.prototype as AnyDuringMigration).DEFAULT_VALUE = 0;
FieldNumber.prototype.DEFAULT_VALUE = 0;
/**
* Config options for the number field.

View File

@@ -62,7 +62,7 @@ export class FieldTextInput extends FieldInput<string> {
fieldRegistry.register('field_input', FieldTextInput);
(FieldTextInput.prototype as AnyDuringMigration).DEFAULT_VALUE = '';
FieldTextInput.prototype.DEFAULT_VALUE = '';
/**
* fromJson config options for the text input field.