mirror of
https://github.com/google/blockly.git
synced 2026-01-06 08:30:13 +01:00
chore: Reduce delta on ports to blockly-samples (#6886)
* Reduce usage of obsolete .keyCode property.
* Rename private properties/methods which violate eslint rules.
* Use arrays of bound events rather than individual properties.
* Improve typing info.
* Also fix O(n^2) recursive performance issue in theme's getComponentStyle function.
* And replace String(...) with '${...}' (smaller, faster).
* .toString() is considered harmful.
This commit is contained in:
@@ -25,7 +25,6 @@ import {Field, FieldConfig, FieldValidator, UnattachedFieldError} from './field.
|
||||
import {Msg} from './msg.js';
|
||||
import * as aria from './utils/aria.js';
|
||||
import {Coordinate} from './utils/coordinate.js';
|
||||
import {KeyCodes} from './utils/keycodes.js';
|
||||
import type {Sentinel} from './utils/sentinel.js';
|
||||
import * as userAgent from './utils/useragent.js';
|
||||
import * as WidgetDiv from './widgetdiv.js';
|
||||
@@ -90,31 +89,31 @@ export abstract class FieldInput<T extends InputTypes> extends Field<string|T> {
|
||||
override CURSOR = 'text';
|
||||
|
||||
/**
|
||||
* @param opt_value The initial value of the field. Should cast to a string.
|
||||
* @param value The initial value of the field. Should cast to a string.
|
||||
* Defaults to an empty string if null or undefined. Also accepts
|
||||
* Field.SKIP_SETUP if you wish to skip setup (only used by subclasses
|
||||
* that want to handle configuration and setting the field value after
|
||||
* their own constructors have run).
|
||||
* @param opt_validator A function that is called to validate changes to the
|
||||
* @param validator A function that is called to validate changes to the
|
||||
* field's value. Takes in a string & returns a validated string, or null
|
||||
* to abort the change.
|
||||
* @param opt_config A map of options used to configure the field.
|
||||
* @param 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/text-input#creation}
|
||||
* for a list of properties this parameter supports.
|
||||
*/
|
||||
constructor(
|
||||
opt_value?: string|Sentinel, opt_validator?: FieldInputValidator<T>|null,
|
||||
opt_config?: FieldInputConfig) {
|
||||
value?: string|Sentinel, validator?: FieldInputValidator<T>|null,
|
||||
config?: FieldInputConfig) {
|
||||
super(Field.SKIP_SETUP);
|
||||
|
||||
if (Field.isSentinel(opt_value)) return;
|
||||
if (opt_config) {
|
||||
this.configure_(opt_config);
|
||||
if (Field.isSentinel(value)) return;
|
||||
if (config) {
|
||||
this.configure_(config);
|
||||
}
|
||||
this.setValue(opt_value);
|
||||
if (opt_validator) {
|
||||
this.setValidator(opt_validator);
|
||||
this.setValue(value);
|
||||
if (validator) {
|
||||
this.setValidator(validator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,14 +261,13 @@ export abstract class FieldInput<T extends InputTypes> extends Field<string|T> {
|
||||
* Shows a prompt editor for mobile browsers if the modalInputs option is
|
||||
* enabled.
|
||||
*
|
||||
* @param _opt_e Optional mouse event that triggered the field to open, or
|
||||
* @param _e Optional mouse event that triggered the field to open, or
|
||||
* undefined if triggered programmatically.
|
||||
* @param opt_quietInput True if editor should be created without focus.
|
||||
* @param quietInput True if editor should be created without focus.
|
||||
* Defaults to false.
|
||||
*/
|
||||
protected override showEditor_(_opt_e?: Event, opt_quietInput?: boolean) {
|
||||
protected override showEditor_(_e?: Event, quietInput = false) {
|
||||
this.workspace_ = (this.sourceBlock_ as BlockSvg).workspace;
|
||||
const quietInput = opt_quietInput || false;
|
||||
if (!quietInput && this.workspace_.options.modalInputs &&
|
||||
(userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) {
|
||||
this.showPromptEditor_();
|
||||
@@ -358,7 +356,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<string|T> {
|
||||
div!.style.transition = 'box-shadow 0.25s ease 0s';
|
||||
if (this.getConstants()!.FIELD_TEXTINPUT_BOX_SHADOW) {
|
||||
div!.style.boxShadow =
|
||||
'rgba(255, 255, 255, 0.3) 0 0 0 ' + 4 * scale + 'px';
|
||||
'rgba(255, 255, 255, 0.3) 0 0 0 ' + (4 * scale) + 'px';
|
||||
}
|
||||
}
|
||||
htmlInput.style.borderRadius = borderRadius;
|
||||
@@ -444,15 +442,15 @@ export abstract class FieldInput<T extends InputTypes> extends Field<string|T> {
|
||||
* @param e Keyboard event.
|
||||
*/
|
||||
protected onHtmlInputKeyDown_(e: KeyboardEvent) {
|
||||
if (e.keyCode === KeyCodes.ENTER) {
|
||||
if (e.key === 'Enter') {
|
||||
WidgetDiv.hide();
|
||||
dropDownDiv.hideWithoutAnimation();
|
||||
} else if (e.keyCode === KeyCodes.ESC) {
|
||||
} else if (e.key === 'Esc') {
|
||||
this.setValue(
|
||||
this.htmlInput_!.getAttribute('data-untyped-default-value'));
|
||||
WidgetDiv.hide();
|
||||
dropDownDiv.hideWithoutAnimation();
|
||||
} else if (e.keyCode === KeyCodes.TAB) {
|
||||
} else if (e.key === 'Tab') {
|
||||
WidgetDiv.hide();
|
||||
dropDownDiv.hideWithoutAnimation();
|
||||
(this.sourceBlock_ as BlockSvg).tab(this, !e.shiftKey);
|
||||
@@ -543,7 +541,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<string|T> {
|
||||
* @returns The text to show on the HTML input.
|
||||
*/
|
||||
protected getEditorText_(value: AnyDuringMigration): string {
|
||||
return String(value);
|
||||
return `${value}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user