mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
feat: make field initView and initModel more accessible (#7345)
* chore: update loop style to remove any type * feat: make initView protected and initModel public * feat: make image element in image field protected
This commit is contained in:
committed by
GitHub
parent
0ac86c7e68
commit
a0b565724b
@@ -366,8 +366,8 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
* change).
|
||||
*/
|
||||
initModel() {
|
||||
for (let i = 0, input; (input = this.inputList[i]); i++) {
|
||||
for (let j = 0, field; (field = input.fieldRow[j]); j++) {
|
||||
for (const input of this.inputList) {
|
||||
for (const field of input.fieldRow) {
|
||||
if (field.initModel) {
|
||||
field.initModel();
|
||||
}
|
||||
|
||||
@@ -321,10 +321,8 @@ export abstract class Field<T = any>
|
||||
|
||||
/**
|
||||
* Create the block UI for this field.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
initView() {
|
||||
protected initView() {
|
||||
this.createBorderRect_();
|
||||
this.createTextElement_();
|
||||
}
|
||||
@@ -332,8 +330,6 @@ export abstract class Field<T = any>
|
||||
/**
|
||||
* Initializes the model of the field after it has been installed on a block.
|
||||
* No-op by default.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
initModel() {}
|
||||
|
||||
|
||||
@@ -165,8 +165,6 @@ export class FieldAngle extends FieldInput<number> {
|
||||
|
||||
/**
|
||||
* Create the block UI for this field.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
super.initView();
|
||||
|
||||
@@ -110,8 +110,6 @@ export class FieldCheckbox extends Field<CheckboxBool> {
|
||||
|
||||
/**
|
||||
* Create the block UI for this checkbox.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
super.initView();
|
||||
|
||||
@@ -163,8 +163,6 @@ export class FieldColour extends Field<string> {
|
||||
|
||||
/**
|
||||
* Create the block UI for this colour field.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
this.size_ = new Size(
|
||||
|
||||
@@ -185,8 +185,6 @@ export class FieldDropdown extends Field<string> {
|
||||
|
||||
/**
|
||||
* Create the block UI for this dropdown.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
if (this.shouldAddBorderRect_()) {
|
||||
|
||||
@@ -29,13 +29,13 @@ export class FieldImage extends Field<string> {
|
||||
*/
|
||||
private static readonly Y_PADDING = 1;
|
||||
protected override size_: Size;
|
||||
private readonly imageHeight: number;
|
||||
protected readonly imageHeight: number;
|
||||
|
||||
/** The function to be called when this field is clicked. */
|
||||
private clickHandler: ((p1: FieldImage) => void) | null = null;
|
||||
|
||||
/** The rendered field's image element. */
|
||||
private imageElement: SVGImageElement | null = null;
|
||||
protected imageElement: SVGImageElement | null = null;
|
||||
|
||||
/**
|
||||
* Editable fields usually show some sort of UI indicating they are
|
||||
@@ -135,8 +135,6 @@ export class FieldImage extends Field<string> {
|
||||
|
||||
/**
|
||||
* Create the block UI for this image.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
this.imageElement = dom.createSvgElement(
|
||||
|
||||
@@ -141,7 +141,6 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
override initView() {
|
||||
const block = this.getSourceBlock();
|
||||
if (!block) {
|
||||
|
||||
@@ -69,8 +69,6 @@ export class FieldLabel extends Field<string> {
|
||||
|
||||
/**
|
||||
* Create block UI for this label.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
this.createTextElement_();
|
||||
|
||||
@@ -152,8 +152,6 @@ export class FieldMultilineInput extends FieldTextInput {
|
||||
|
||||
/**
|
||||
* Create the block UI for this field.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initView() {
|
||||
this.createBorderRect_();
|
||||
|
||||
@@ -130,8 +130,6 @@ export class FieldVariable extends FieldDropdown {
|
||||
* Initialize the model for this field if it has not already been initialized.
|
||||
* If the value has not been set to a variable by the first render, we make up
|
||||
* a variable rather than let the value be invalid.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
override initModel() {
|
||||
const block = this.getSourceBlock();
|
||||
|
||||
Reference in New Issue
Block a user