Skip to content

Commit

Permalink
feat: make field initView and initModel more accessible (#7345)
Browse files Browse the repository at this point in the history
* chore: update loop style to remove any type

* feat: make initView protected and initModel public

* feat: make image element in image field protected
  • Loading branch information
maribethb authored Aug 8, 2023
1 parent 0ac86c7 commit a0b5657
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 26 deletions.
4 changes: 2 additions & 2 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 1 addition & 5 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,15 @@ export abstract class Field<T = any>

/**
* Create the block UI for this field.
*
* @internal
*/
initView() {
protected initView() {
this.createBorderRect_();
this.createTextElement_();
}

/**
* Initializes the model of the field after it has been installed on a block.
* No-op by default.
*
* @internal
*/
initModel() {}

Expand Down
2 changes: 0 additions & 2 deletions core/field_angle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ export class FieldAngle extends FieldInput<number> {

/**
* Create the block UI for this field.
*
* @internal
*/
override initView() {
super.initView();
Expand Down
2 changes: 0 additions & 2 deletions core/field_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export class FieldCheckbox extends Field<CheckboxBool> {

/**
* Create the block UI for this checkbox.
*
* @internal
*/
override initView() {
super.initView();
Expand Down
2 changes: 0 additions & 2 deletions core/field_colour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions core/field_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ export class FieldDropdown extends Field<string> {

/**
* Create the block UI for this dropdown.
*
* @internal
*/
override initView() {
if (this.shouldAddBorderRect_()) {
Expand Down
6 changes: 2 additions & 4 deletions core/field_image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,8 +135,6 @@ export class FieldImage extends Field<string> {

/**
* Create the block UI for this image.
*
* @internal
*/
override initView() {
this.imageElement = dom.createSvgElement(
Expand Down
1 change: 0 additions & 1 deletion core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
}
}

/** @internal */
override initView() {
const block = this.getSourceBlock();
if (!block) {
Expand Down
2 changes: 0 additions & 2 deletions core/field_label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export class FieldLabel extends Field<string> {

/**
* Create block UI for this label.
*
* @internal
*/
override initView() {
this.createTextElement_();
Expand Down
2 changes: 0 additions & 2 deletions core/field_multilineinput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ export class FieldMultilineInput extends FieldTextInput {

/**
* Create the block UI for this field.
*
* @internal
*/
override initView() {
this.createBorderRect_();
Expand Down
2 changes: 0 additions & 2 deletions core/field_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a0b5657

Please sign in to comment.