Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make field initView and initModel more accessible #7345

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading