From a0b565724b4726e7a31f0770acad6b124c09a02b Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 8 Aug 2023 10:18:51 -0700 Subject: [PATCH] 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 --- core/block.ts | 4 ++-- core/field.ts | 6 +----- core/field_angle.ts | 2 -- core/field_checkbox.ts | 2 -- core/field_colour.ts | 2 -- core/field_dropdown.ts | 2 -- core/field_image.ts | 6 ++---- core/field_input.ts | 1 - core/field_label.ts | 2 -- core/field_multilineinput.ts | 2 -- core/field_variable.ts | 2 -- 11 files changed, 5 insertions(+), 26 deletions(-) diff --git a/core/block.ts b/core/block.ts index 7c7de425aae..3e279f79885 100644 --- a/core/block.ts +++ b/core/block.ts @@ -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(); } diff --git a/core/field.ts b/core/field.ts index ba547800822..08aa28486bf 100644 --- a/core/field.ts +++ b/core/field.ts @@ -321,10 +321,8 @@ export abstract class Field /** * Create the block UI for this field. - * - * @internal */ - initView() { + protected initView() { this.createBorderRect_(); this.createTextElement_(); } @@ -332,8 +330,6 @@ export abstract class Field /** * Initializes the model of the field after it has been installed on a block. * No-op by default. - * - * @internal */ initModel() {} diff --git a/core/field_angle.ts b/core/field_angle.ts index 918b885da0b..49eb03b9825 100644 --- a/core/field_angle.ts +++ b/core/field_angle.ts @@ -165,8 +165,6 @@ export class FieldAngle extends FieldInput { /** * Create the block UI for this field. - * - * @internal */ override initView() { super.initView(); diff --git a/core/field_checkbox.ts b/core/field_checkbox.ts index 44dea25fa1c..1b865feef1a 100644 --- a/core/field_checkbox.ts +++ b/core/field_checkbox.ts @@ -110,8 +110,6 @@ export class FieldCheckbox extends Field { /** * Create the block UI for this checkbox. - * - * @internal */ override initView() { super.initView(); diff --git a/core/field_colour.ts b/core/field_colour.ts index d5ea7ee8047..359c9d713ae 100644 --- a/core/field_colour.ts +++ b/core/field_colour.ts @@ -163,8 +163,6 @@ export class FieldColour extends Field { /** * Create the block UI for this colour field. - * - * @internal */ override initView() { this.size_ = new Size( diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index 3f94657624f..0390a1031e1 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -185,8 +185,6 @@ export class FieldDropdown extends Field { /** * Create the block UI for this dropdown. - * - * @internal */ override initView() { if (this.shouldAddBorderRect_()) { diff --git a/core/field_image.ts b/core/field_image.ts index 752ef3e787d..7476498c9cd 100644 --- a/core/field_image.ts +++ b/core/field_image.ts @@ -29,13 +29,13 @@ export class FieldImage extends Field { */ 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 { /** * Create the block UI for this image. - * - * @internal */ override initView() { this.imageElement = dom.createSvgElement( diff --git a/core/field_input.ts b/core/field_input.ts index ee6f669157e..eb64d4493f7 100644 --- a/core/field_input.ts +++ b/core/field_input.ts @@ -141,7 +141,6 @@ export abstract class FieldInput extends Field< } } - /** @internal */ override initView() { const block = this.getSourceBlock(); if (!block) { diff --git a/core/field_label.ts b/core/field_label.ts index 9d3d987446f..b67a10990e3 100644 --- a/core/field_label.ts +++ b/core/field_label.ts @@ -69,8 +69,6 @@ export class FieldLabel extends Field { /** * Create block UI for this label. - * - * @internal */ override initView() { this.createTextElement_(); diff --git a/core/field_multilineinput.ts b/core/field_multilineinput.ts index cb812b428e9..df7d0f3317a 100644 --- a/core/field_multilineinput.ts +++ b/core/field_multilineinput.ts @@ -152,8 +152,6 @@ export class FieldMultilineInput extends FieldTextInput { /** * Create the block UI for this field. - * - * @internal */ override initView() { this.createBorderRect_(); diff --git a/core/field_variable.ts b/core/field_variable.ts index 8c1fa54b6a5..419881fa4a6 100644 --- a/core/field_variable.ts +++ b/core/field_variable.ts @@ -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();