Skip to main content

Class: FieldBitmap

Defined in: plugins/field-bitmap/src/field-bitmap.ts:25

Field for inputting a small bitmap image. Includes a grid of clickable pixels that's exported as a bitmap.

Extends​

  • Field<number[][]>

Properties index​

PropertyDescription
ariaTypeNameThe ARIA-friendly label representation of this field's type.
borderRect_The rendered field's SVG border element.
buttonOptions-
clickTarget_The element the click handler is bound to.
constants_Constants associated with the source block's renderer.
DEFAULT_VALUETo overwrite the default value which is set in Field, directly update the prototype.
EDITABLEEditable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.
enabled_Can the field value be changed using the editor on an editable block?
fieldGroup_The rendered field's SVG group element.
fieldHeight-
isDirty_Does this block need to be re-rendered?
maxDisplayLengthMaximum characters of text to display before adding an ellipsis.
nameName of field. Unique within each block. Static labels are usually unnamed.
pixelColours-
pixelSize-
SERIALIZABLESerializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable. This is not the case by default so that SERIALIZABLE is backwards compatible.
sourceBlock_Block this field is attached to. Starts as null, then set in init.
textContent_The rendered field's text content element.
textElement_The rendered field's SVG text element.
validator_Validation function called when user edits an editable field.
value_-
visible_Is the field visible, or hidden due to the block being collapsed?
NBSPNon-breaking space.
SKIP_SETUPA value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead.

Methods index​

MethodDescription
applyColourUpdates the field to match the colour/style of the block.
bindEvents_Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.
canBeFocusedSee IFocusableNode.canBeFocused.
computeAriaLabelComputes a descriptive ARIA label to represent this field with configurable verbosity.
configure_Process the configuration map passed to the field.
createBorderRect_Create a field border rect element. Not to be overridden by subclasses. Instead modify the result of the function inside initView, or create a separate function to call.
createTextElement_Create a field text element. Not to be overridden by subclasses. Instead, modify the result of the function inside initView, or create a separate function to call. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation.
disposeDispose of all DOM objects and events belonging to this editable field.
doClassValidation_Validates that a new value meets the requirements for a valid bitmap array.
doValueInvalid_Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default.
doValueUpdate_Called when a new value has been validated and is about to be set.
dropdownCreateCreates the bitmap editor and add event listeners.
dropdownDisposeDisposes of events belonging to the bitmap editor.
fireIntermediateChangeEvent-
forceRerenderForce a rerender of the block that this field is installed on, which will rerender this field and adjust for any sizing changes. Other fields on the same block will not rerender, because their sizes have already been recorded.
fromXmlSets the field's value based on the given XML element. Should only be called by Blockly.Xml.
getAbsoluteXY_Return the absolute coordinates of the top-left corner of this field. The origin (0,0) is the top-left corner of the page body.
getAriaTypeNameGets an ARIA-friendly label representation of this field's type.
getAriaValueGets an ARIA-friendly label representation of this field's value.
getBorderRectGets the border rectangle element.
getClickTarget_The element to bind the click handler to. If not set explicitly, defaults to the SVG root of the field. When this element is clicked on an editable field, the editor will open.
getConstantsGet the renderer constant provider.
getDisplayText_Get the text from this field to display on the block. May differ from getText due to ellipsis, and other formatting.
getFlipRtlReturns whether or not we should flip the field in RTL.
getFocusableElementSee IFocusableNode.getFocusableElement.
getFocusableTreeSee IFocusableNode.getFocusableTree.
getImageHeightReturns the height of the image in pixels.
getImageWidthReturns the width of the image in pixels.
getScaledBBoxGets the rectangle built out of dimensions matching SVG's element.
getSizeReturns the height and width of the field.
getSourceBlockGet the block this field is attached to.
getSvgRootGets the group element for this editable field. Used for measuring the size and for positioning.
getTextGet the text from this field. Override getText_ to provide a different behavior than simply casting the value to a string.
getText_A developer hook to override the returned text of this field. Override if the text representation of the value of this field is not just a string cast of its value. Return null to resort to a string cast.
getTextContentGets the text content.
getTextElementGets the text element.
getTooltipReturns the tooltip text for this field.
getValidatorGets the validation function for editable fields, or null if not set.
getValueGet the current value of the field.
initModelInitializes the model of the field after it has been installed on a block. No-op by default.
initViewInitializes the on-block display.
isClickableCheck whether this field defines the showEditor_ function.
isClickableInFlyoutCheck whether the field should be clickable while the block is in a flyout. The default is that fields are clickable in always-open flyouts such as the simple toolbox, but not in autoclosing flyouts such as the category toolbox. Subclasses may override this function to change this behavior. Note that isClickable must also return true for this to have any effect.
isCurrentlyEditableCheck whether this field is currently editable. Some fields are never EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on non-editable blocks or be currently disabled.
isEnabledCheck whether this field's value can be changed using the editor when the source block is editable.
isFullBlockFieldDefines whether this field should take up the full block or not.
isSerializableCheck whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.
isVisibleGets whether this editable field is visible or not.
loadLegacyStateLoads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.
loadStateSets the field's state based on the given state value. Should only be called by the serialization system.
onLocationChangeNotifies the field that it has changed locations.
onMouseDown_Handle a pointerdown event on a field.
onNodeBlurSee IFocusableNode.onNodeBlur.
onNodeFocusSee IFocusableNode.onNodeFocus.
onShortcutHandles the given keyboard shortcut.
performActionHandles the user acting on this field via keyboard navigation. Shows and focuses the field editor.
positionBorderRect_Position a field's border rect after a size change.
positionTextElement_Position a field's text element after a size change. This handles both LTR and RTL positioning.
recomputeAriaContextUpdates the ARIA roles and label for this field.
referencesVariablesWhether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization, and this field's value must correspond to the ID of an existing variable. Subclasses may override this.
refreshVariableNameRefresh the variable name referenced by this field if this field references variables.
render_Updates the block display and editor dropdown when the field re-renders.
repositionForWindowResizeA developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.
saveLegacyStateReturns a stringified version of the XML state, if it should be used. Otherwise this returns null, to signal the field should use its own serialization.
saveStateSaves this fields value as something which can be serialized to JSON. Should only be called by the serialization system.
setAriaTypeNameSets the ARIA-friendly label representation of this field's type.
setEnabledSet whether this field's value can be changed using the editor when the source block is editable.
setSourceBlockAttach this field to a block.
setTooltipSets the tooltip for this field.
setValidatorSets a new validation function for editable fields, or clears a previously set validator.
setValueUsed to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.
showEditor_Show the bitmap editor dialog.
toXmlSerializes this field's value to XML. Should only be called by Blockly.Xml.
updateEditableDetermines whether the field is editable.
updateSize_Updates the size of the block based on the size of the underlying image.
fromJsonConstructs a FieldBitmap from a JSON arg object.

Constructors​

Constructor​

new FieldBitmap(
value,
validator?,
config?
): FieldBitmap;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:57

Constructor for the bitmap field.

Parameters​

ParameterTypeDescription
valuenumber[][] | typeof SKIP_SETUP2D rectangular array of 1s and 0s.
validator?FieldValidator<number[][]>A function that is called to validate.
config?FieldBitmapFromJsonConfigConfig A map of options used to configure the field.

Returns​

FieldBitmap

Overrides​

Blockly.Field<number[][]>.constructor

Properties​

ariaTypeName​

protected ariaTypeName: string;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:48

The ARIA-friendly label representation of this field's type.

Overrides​

Blockly.Field.ariaTypeName


borderRect_​

protected borderRect_: SVGRectElement | null;

The rendered field's SVG border element.

Inherited from​

Blockly.Field.borderRect_


buttonOptions​

buttonOptions: Buttons;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:43


clickTarget_​

protected clickTarget_: Element | null;

The element the click handler is bound to.

Inherited from​

Blockly.Field.clickTarget_


constants_​

protected constants_: ConstantProvider | null;

Constants associated with the source block's renderer.

Inherited from​

Blockly.Field.constants_


DEFAULT_VALUE​

DEFAULT_VALUE: number[][] | null;

To overwrite the default value which is set in Field, directly update the prototype.

Example: FieldImage.prototype.DEFAULT_VALUE = null;

Inherited from​

Blockly.Field.DEFAULT_VALUE


EDITABLE​

EDITABLE: boolean;

Editable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.

Inherited from​

Blockly.Field.EDITABLE


enabled_​

protected enabled_: boolean;

Can the field value be changed using the editor on an editable block?

Inherited from​

Blockly.Field.enabled_


fieldGroup_​

protected fieldGroup_: SVGGElement | null;

The rendered field's SVG group element.

Inherited from​

Blockly.Field.fieldGroup_


fieldHeight?​

fieldHeight?: number;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:46


isDirty_​

protected isDirty_: boolean;

Does this block need to be re-rendered?

Inherited from​

Blockly.Field.isDirty_


maxDisplayLength​

maxDisplayLength: number;

Maximum characters of text to display before adding an ellipsis.

Inherited from​

Blockly.Field.maxDisplayLength


name?​

name?: string;

Name of field. Unique within each block. Static labels are usually unnamed.

Inherited from​

Blockly.Field.name


pixelColours​

pixelColours: object;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:45

empty​

empty: string;

filled​

filled: string;

pixelSize​

pixelSize: number;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:44


SERIALIZABLE​

SERIALIZABLE: boolean;

Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable. This is not the case by default so that SERIALIZABLE is backwards compatible.

Inherited from​

Blockly.Field.SERIALIZABLE


sourceBlock_​

protected sourceBlock_: Block | null;

Block this field is attached to. Starts as null, then set in init.

Inherited from​

Blockly.Field.sourceBlock_


textContent_​

protected textContent_: Text | null;

The rendered field's text content element.

Inherited from​

Blockly.Field.textContent_


textElement_​

protected textElement_: SVGTextElement | null;

The rendered field's SVG text element.

Inherited from​

Blockly.Field.textElement_


validator_​

protected validator_: FieldValidator<number[][]> | null;

Validation function called when user edits an editable field.

Inherited from​

Blockly.Field.validator_


value_​

protected value_: number[][] | null;

Inherited from​

Blockly.Field.value_


visible_​

protected visible_: boolean;

Is the field visible, or hidden due to the block being collapsed?

Inherited from​

Blockly.Field.visible_


NBSP​

readonly static NBSP: " " = "\u00A0";

Non-breaking space.

Inherited from​

Blockly.Field.NBSP


SKIP_SETUP​

readonly static SKIP_SETUP: typeof SKIP_SETUP;

A value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead.

Inherited from​

Blockly.Field.SKIP_SETUP

Accessors​

size_​

Get Signature​

get protected size_(): Size;

Gets the size of this field. Because getSize() and updateSize() have side effects, this acts as a shim for subclasses which wish to adjust field bounds when setting/getting the size without triggering unwanted rendering or other side effects. Note that subclasses must override both get and set if either is overridden; the implementation may just call directly through to super, but it must exist per the JS spec.

Returns​

Size

Set Signature​

set protected size_(newValue): void;
Parameters​
ParameterType
newValueSize
Returns​

void

Inherited from​

Blockly.Field.size_

Methods​

applyColour()​

applyColour(): void;

Updates the field to match the colour/style of the block.

Non-abstract sub-classes may wish to implement this if the colour of the field depends on the colour of the block. It will automatically be called at relevant times, such as when the parent block or renderer changes.

See the field documentation for more information, or FieldDropdown for an example.

Returns​

void

Inherited from​

Blockly.Field.applyColour


bindEvents_()​

protected bindEvents_(): void;

Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.

Returns​

void

Inherited from​

Blockly.Field.bindEvents_


canBeFocused()​

canBeFocused(): boolean;

See IFocusableNode.canBeFocused.

Returns​

boolean

Inherited from​

Blockly.Field.canBeFocused


computeAriaLabel()​

computeAriaLabel(includeTypeInfo?): string;

Computes a descriptive ARIA label to represent this field with configurable verbosity.

A 'verbose' label includes type information, if available, whereas a non-verbose label only contains the field's value.

Note that this will always return the latest representation of the field's label which may differ from any previously set ARIA label for the field itself. Implementations are largely responsible for ensuring that the field's ARIA label is set correctly at relevant moments in the field's lifecycle (such as when its value changes).

Finally, it is never guaranteed that implementations use the label returned by this method for their actual ARIA label. Some implementations may rely on other contexts to convey information like the field's value. Example: checkboxes represent their checked/non-checked status (i.e. value) through a separate ARIA property.

If the field's value is empty then it will return a localized placeholder indicating that its value is empty. If this method returns an empty string, the output will be ignored when composing the block-level ARIA label. Make sure you want your label hidden from screenreaders before returning an empty string.

Parameters​

ParameterTypeDescription
includeTypeInfo?booleanWhether to include the field's type information in the returned label, if available.

Returns​

string

Inherited from​

Blockly.Field.computeAriaLabel


configure_()​

protected configure_(config): void;

Process the configuration map passed to the field.

Parameters​

ParameterTypeDescription
configFieldConfigA map of options used to configure the field. See the individual field's documentation for a list of properties this parameter supports.

Returns​

void

Inherited from​

Blockly.Field.configure_


createBorderRect_()​

protected createBorderRect_(): void;

Create a field border rect element. Not to be overridden by subclasses. Instead modify the result of the function inside initView, or create a separate function to call.

Returns​

void

Inherited from​

Blockly.Field.createBorderRect_


createTextElement_()​

protected createTextElement_(): void;

Create a field text element. Not to be overridden by subclasses. Instead, modify the result of the function inside initView, or create a separate function to call. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation.

Returns​

void

Inherited from​

Blockly.Field.createTextElement_


dispose()​

dispose(): void;

Dispose of all DOM objects and events belonging to this editable field.

Returns​

void

Inherited from​

Blockly.Field.dispose


doClassValidation_()​

Call Signature​

protected doClassValidation_(newValue): number[][] | null | undefined;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:147

Validates that a new value meets the requirements for a valid bitmap array.

Parameters​
ParameterTypeDescription
newValuenumber[][]The new value to be tested.
Returns​

number[][] | null | undefined

The new value if it's valid, or null.

Overrides​

Blockly.Field.doClassValidation_

Call Signature​

protected doClassValidation_(newValue?): number[][] | null;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:151

Validates that a new value meets the requirements for a valid bitmap array.

Parameters​
ParameterTypeDescription
newValue?number[][]The new value to be tested.
Returns​

number[][] | null

The new value if it's valid, or null.

Overrides​

Blockly.Field.doClassValidation_


doValueInvalid_()​

protected doValueInvalid_(_invalidValue, _fireChangeEvent?): void;

Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default.

Parameters​

ParameterTypeDescription
_invalidValueanyThe input value that was determined to be invalid.
_fireChangeEvent?booleanWhether to fire a change event if the value changes.

Returns​

void

Inherited from​

Blockly.Field.doValueInvalid_


doValueUpdate_()​

protected doValueUpdate_(newValue): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:200

Called when a new value has been validated and is about to be set.

Parameters​

ParameterTypeDescription
newValuenumber[][]The value that's about to be set.

Returns​

void

Overrides​

Blockly.Field.doValueUpdate_


protected dropdownCreate(): HTMLElement;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:324

Creates the bitmap editor and add event listeners.

Returns​

HTMLElement

The newly created dropdown menu.


protected dropdownDispose(): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:692

Disposes of events belonging to the bitmap editor.

Returns​

void


fireIntermediateChangeEvent()​

protected fireIntermediateChangeEvent(newValue): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:930

Parameters​

ParameterType
newValuenumber[][]

Returns​

void


forceRerender()​

forceRerender(): void;

Force a rerender of the block that this field is installed on, which will rerender this field and adjust for any sizing changes. Other fields on the same block will not rerender, because their sizes have already been recorded.

Returns​

void

Inherited from​

Blockly.Field.forceRerender


fromXml()​

fromXml(fieldElement): void;

Sets the field's value based on the given XML element. Should only be called by Blockly.Xml.

Parameters​

ParameterTypeDescription
fieldElementElementThe element containing info about the field's state.

Returns​

void

Inherited from​

Blockly.Field.fromXml


getAbsoluteXY_()​

protected getAbsoluteXY_(): Coordinate;

Return the absolute coordinates of the top-left corner of this field. The origin (0,0) is the top-left corner of the page body.

Returns​

Coordinate

Object with .x and .y properties.

Inherited from​

Blockly.Field.getAbsoluteXY_


getAriaTypeName()​

getAriaTypeName(): string | null;

Gets an ARIA-friendly label representation of this field's type.

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's type.

Returns​

string | null

An ARIA representation of the field's type or null if it is unspecified.

Inherited from​

Blockly.Field.getAriaTypeName


getAriaValue()​

getAriaValue(): string | null;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:260

Gets an ARIA-friendly label representation of this field's value.

Note that implementations should generally always override this value to ensure a non-null value is returned. The default implementation relies on 'getText' which may return an empty string. A null return value from this function will prompt ARIA label generation to skip the field's value entirely when there may be a better contextual placeholder to use isstead.

For example, to avoid hiding an empty text input field from screen reader, implementations should ensure that if the text is an empty string, this function would return an appropriate, localized value such as "empty text".

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's value.

Returns​

string | null

An ARIA representation of the field's text, or null if no text is currently defined or known for the field.

Overrides​

Blockly.Field.getAriaValue


getBorderRect()​

protected getBorderRect(): SVGRectElement;

Gets the border rectangle element.

Returns​

SVGRectElement

The border rectangle element.

Throws​

An error if the border rectangle element is not defined.

Inherited from​

Blockly.Field.getBorderRect


getClickTarget_()​

protected getClickTarget_(): Element | null;

The element to bind the click handler to. If not set explicitly, defaults to the SVG root of the field. When this element is clicked on an editable field, the editor will open.

Returns​

Element | null

Element to bind click handler to.

Inherited from​

Blockly.Field.getClickTarget_


getConstants()​

getConstants(): ConstantProvider | null;

Get the renderer constant provider.

Returns​

ConstantProvider | null

The renderer constant provider.

Inherited from​

Blockly.Field.getConstants


getDisplayText_()​

protected getDisplayText_(): string;

Get the text from this field to display on the block. May differ from getText due to ellipsis, and other formatting.

Returns​

string

Text to display.

Inherited from​

Blockly.Field.getDisplayText_


getFlipRtl()​

getFlipRtl(): boolean;

Returns whether or not we should flip the field in RTL.

Returns​

boolean

True if we should flip in RTL.

Inherited from​

Blockly.Field.getFlipRtl


getFocusableElement()​

getFocusableElement(): HTMLElement | SVGElement;

See IFocusableNode.getFocusableElement.

Returns​

HTMLElement | SVGElement

Inherited from​

Blockly.Field.getFocusableElement


getFocusableTree()​

getFocusableTree(): IFocusableTree;

See IFocusableNode.getFocusableTree.

Returns​

IFocusableTree

Inherited from​

Blockly.Field.getFocusableTree


getImageHeight()​

getImageHeight(): number;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:116

Returns the height of the image in pixels.

Returns​

number

The height in pixels.


getImageWidth()​

getImageWidth(): number;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:107

Returns the width of the image in pixels.

Returns​

number

The width in pixels.


getScaledBBox()​

getScaledBBox(): Rect;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:306

Gets the rectangle built out of dimensions matching SVG's element.

Returns​

Rect

The newly created rectangle of same size as the SVG element.

Overrides​

Blockly.Field.getScaledBBox


getSize()​

getSize(): Size;

Returns the height and width of the field.

This should in general be the only place render_ gets called from.

Returns​

Size

Height and width.

Inherited from​

Blockly.Field.getSize


getSourceBlock()​

getSourceBlock(): Block | null;

Get the block this field is attached to.

Returns​

Block | null

The block containing this field.

Throws​

An error if the source block is not defined.

Inherited from​

Blockly.Field.getSourceBlock


getSvgRoot()​

getSvgRoot(): SVGGElement | null;

Gets the group element for this editable field. Used for measuring the size and for positioning.

Returns​

SVGGElement | null

The group element.

Inherited from​

Blockly.Field.getSvgRoot


getText()​

getText(): string;

Sealed

Get the text from this field. Override getText_ to provide a different behavior than simply casting the value to a string.

Returns​

string

Current text.

Inherited from​

Blockly.Field.getText


getText_()​

protected getText_(): string | null;

A developer hook to override the returned text of this field. Override if the text representation of the value of this field is not just a string cast of its value. Return null to resort to a string cast.

Returns​

string | null

Current text or null.

Inherited from​

Blockly.Field.getText_


getTextContent()​

protected getTextContent(): Text;

Gets the text content.

Returns​

Text

The text content.

Throws​

An error if the text content is not defined.

Inherited from​

Blockly.Field.getTextContent


getTextElement()​

protected getTextElement(): SVGTextElement;

Gets the text element.

Returns​

SVGTextElement

The text element.

Throws​

An error if the text element is not defined.

Inherited from​

Blockly.Field.getTextElement


getTooltip()​

getTooltip(): string;

Returns the tooltip text for this field.

Returns​

string

The tooltip text for this field.

Inherited from​

Blockly.Field.getTooltip


getValidator()​

getValidator(): FieldValidator<number[][]> | null;

Gets the validation function for editable fields, or null if not set.

Returns​

FieldValidator<number[][]> | null

Validation function, or null.

Inherited from​

Blockly.Field.getValidator


getValue()​

getValue(): number[][] | null;

Get the current value of the field.

Returns​

number[][] | null

Current value.

Inherited from​

Blockly.Field.getValue


initModel()​

initModel(): void;

Initializes the model of the field after it has been installed on a block. No-op by default.

Returns​

void

Inherited from​

Blockly.Field.initModel


initView()​

initView(): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:618

Initializes the on-block display.

Returns​

void

Overrides​

Blockly.Field.initView


isClickable()​

isClickable(): boolean;

Check whether this field defines the showEditor_ function.

Returns​

boolean

Whether this field is clickable.

Inherited from​

Blockly.Field.isClickable


isClickableInFlyout()​

isClickableInFlyout(autoClosingFlyout): boolean;

Check whether the field should be clickable while the block is in a flyout. The default is that fields are clickable in always-open flyouts such as the simple toolbox, but not in autoclosing flyouts such as the category toolbox. Subclasses may override this function to change this behavior. Note that isClickable must also return true for this to have any effect.

Parameters​

ParameterTypeDescription
autoClosingFlyoutbooleantrue if the containing flyout is an auto-closing one.

Returns​

boolean

Whether the field should be clickable while the block is in a flyout.

Inherited from​

Blockly.Field.isClickableInFlyout


isCurrentlyEditable()​

isCurrentlyEditable(): boolean;

Check whether this field is currently editable. Some fields are never EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on non-editable blocks or be currently disabled.

Returns​

boolean

Whether this field is currently enabled, editable and on an editable block.

Inherited from​

Blockly.Field.isCurrentlyEditable


isEnabled()​

isEnabled(): boolean;

Check whether this field's value can be changed using the editor when the source block is editable.

Returns​

boolean

Whether this field is enabled.

Inherited from​

Blockly.Field.isEnabled


isFullBlockField()​

isFullBlockField(): boolean;

Defines whether this field should take up the full block or not.

This is typically only done for certain kinds of fields and in certain renderers. You should only override this if you're sure your field will render correctly in zelos and other renderers that support full-block fields.

Blocks that contain only a single field that is a full-block-field have a special appearance in some renderers and their behavior is unique, because we pretend that the field is a whole block in some cases. This is hacky and you should use caution when attempting to do anything with this method.

Returns​

boolean

Inherited from​

Blockly.Field.isFullBlockField


isSerializable()​

isSerializable(): boolean;

Check whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.

Returns​

boolean

Whether this field should be serialized or not.

Inherited from​

Blockly.Field.isSerializable


isVisible()​

isVisible(): boolean;

Gets whether this editable field is visible or not.

Returns​

boolean

True if visible.

Inherited from​

Blockly.Field.isVisible


loadLegacyState()​

loadLegacyState(callingClass, state): boolean;

Loads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.

Parameters​

ParameterTypeDescription
callingClassFieldProtoThe class calling this method. Used to see if this has overridden any relevant hooks.
stateanyThe state to apply to the field.

Returns​

boolean

Whether the state was applied or not.

Inherited from​

Blockly.Field.loadLegacyState


loadState()​

loadState(state): void;

Sets the field's state based on the given state value. Should only be called by the serialization system.

Parameters​

ParameterTypeDescription
stateanyThe state we want to apply to the field.

Returns​

void

Inherited from​

Blockly.Field.loadState


onLocationChange()​

onLocationChange(_): void;

Notifies the field that it has changed locations.

Parameters​

ParameterTypeDescription
_CoordinateThe location of this field's block's top-start corner in workspace coordinates.

Returns​

void

Inherited from​

Blockly.Field.onLocationChange


onMouseDown_()​

protected onMouseDown_(e): void;

Handle a pointerdown event on a field.

Parameters​

ParameterTypeDescription
ePointerEventPointer down event.

Returns​

void

Inherited from​

Blockly.Field.onMouseDown_


onNodeBlur()​

onNodeBlur(): void;

See IFocusableNode.onNodeBlur.

Returns​

void

Inherited from​

Blockly.Field.onNodeBlur


onNodeFocus()​

onNodeFocus(): void;

See IFocusableNode.onNodeFocus.

Returns​

void

Inherited from​

Blockly.Field.onNodeFocus


onShortcut()​

onShortcut(_shortcut): boolean;

Handles the given keyboard shortcut.

Parameters​

ParameterTypeDescription
_shortcutKeyboardShortcutThe shortcut to be handled.

Returns​

boolean

True if the shortcut has been handled, false otherwise.

Inherited from​

Blockly.Field.onShortcut


performAction()​

performAction(): void;

Handles the user acting on this field via keyboard navigation. Shows and focuses the field editor.

Returns​

void

Inherited from​

Blockly.Field.performAction


positionBorderRect_()​

protected positionBorderRect_(): void;

Position a field's border rect after a size change.

Returns​

void

Inherited from​

Blockly.Field.positionBorderRect_


positionTextElement_()​

protected positionTextElement_(xOffset, contentWidth): void;

Position a field's text element after a size change. This handles both LTR and RTL positioning.

Parameters​

ParameterTypeDescription
xOffsetnumberx offset to use when positioning the text element.
contentWidthnumberThe content width.

Returns​

void

Inherited from​

Blockly.Field.positionTextElement_


recomputeAriaContext()​

recomputeAriaContext(): boolean;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:123

Updates the ARIA roles and label for this field.

Returns​

boolean

Overrides​

Blockly.Field.recomputeAriaContext


referencesVariables()​

referencesVariables(): boolean;

Whether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization, and this field's value must correspond to the ID of an existing variable. Subclasses may override this.

Returns​

boolean

True if this field has any variable references.

Inherited from​

Blockly.Field.referencesVariables


refreshVariableName()​

refreshVariableName(): void;

Refresh the variable name referenced by this field if this field references variables.

Returns​

void

Inherited from​

Blockly.Field.refreshVariableName


render_()​

protected render_(): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:237

Updates the block display and editor dropdown when the field re-renders.

Returns​

void

Overrides​

Blockly.Field.render_


repositionForWindowResize()​

repositionForWindowResize(): boolean;

A developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.

If you want the WidgetDiv to hide itself instead of repositioning, return false. This is the default behavior.

DropdownDivs already handle their own positioning logic, so you do not need to override this function if your field only has a DropdownDiv.

Returns​

boolean

True if the field should be repositioned, false if the WidgetDiv should hide itself instead.

Inherited from​

Blockly.Field.repositionForWindowResize


saveLegacyState()​

protected saveLegacyState(callingClass): string | null;

Returns a stringified version of the XML state, if it should be used. Otherwise this returns null, to signal the field should use its own serialization.

Parameters​

ParameterTypeDescription
callingClassFieldProtoThe class calling this method. Used to see if this has overridden any relevant hooks.

Returns​

string | null

The stringified version of the XML state, or null.

Inherited from​

Blockly.Field.saveLegacyState


saveState()​

saveState(_doFullSerialization?): any;

Saves this fields value as something which can be serialized to JSON. Should only be called by the serialization system.

Parameters​

ParameterTypeDescription
_doFullSerialization?booleanIf true, this signals to the field that if it normally just saves a reference to some state (eg variable fields) it should instead serialize the full state of the thing being referenced. See the field serialization docs for more information.

Returns​

any

JSON serializable state.

Inherited from​

Blockly.Field.saveState


setAriaTypeName()​

setAriaTypeName(ariaTypeName): void;

Sets the ARIA-friendly label representation of this field's type.

Implementations are responsible for, and encouraged to, set a localized version of the ARIA representation of the field's type. To that end, the provided value may contain message references of the form %{BKY_...} (e.g. %{BKY_MY_FIELD_ARIA_TYPE}), which are replaced with the corresponding Blockly.Msg value.

Parameters​

ParameterTypeDescription
ariaTypeNamestringAn ARIA representation of the field's type.

Returns​

void

Inherited from​

Blockly.Field.setAriaTypeName


setEnabled()​

setEnabled(enabled): void;

Set whether this field's value can be changed using the editor when the source block is editable.

Parameters​

ParameterTypeDescription
enabledbooleanTrue if enabled.

Returns​

void

Inherited from​

Blockly.Field.setEnabled


setSourceBlock()​

setSourceBlock(block): void;

Attach this field to a block.

Parameters​

ParameterTypeDescription
blockBlockThe block containing this field.

Returns​

void

Inherited from​

Blockly.Field.setSourceBlock


setTooltip()​

setTooltip(newTip): void;

Sets the tooltip for this field.

Parameters​

ParameterTypeDescription
newTipTipInfo | nullThe text for the tooltip, a function that returns the text for the tooltip, a parent object whose tooltip will be used, or null to display the tooltip of the parent block. To not display a tooltip pass the empty string.

Returns​

void

Inherited from​

Blockly.Field.setTooltip


setValidator()​

setValidator(handler): void;

Sets a new validation function for editable fields, or clears a previously set validator.

The validator function takes in the new field value, and returns validated value. The validated value could be the input value, a modified version of the input value, or null to abort the change.

If the function does not return anything (or returns undefined) the new value is accepted as valid. This is to allow for fields using the validated function as a field-level change event notification.

Parameters​

ParameterTypeDescription
handlerFieldValidator<number[][]>The validator function or null to clear a previous validator.

Returns​

void

Inherited from​

Blockly.Field.setValidator


setValue()​

setValue(newValue, fireChangeEvent?): void;

Sealed

Used to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.

Parameters​

ParameterTypeDescription
newValueanyNew value.
fireChangeEvent?booleanWhether to fire a change event. Defaults to true. Should usually be true unless the change will be reported some other way, e.g. an intermediate field change event.

Returns​

void

Inherited from​

Blockly.Field.setValue


showEditor_()​

protected showEditor_(e?): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:222

Show the bitmap editor dialog.

Parameters​

ParameterTypeDescription
e?EventOptional mouse event that triggered the field to open, or undefined if triggered programmatically.

Returns​

void

Overrides​

Blockly.Field.showEditor_


toXml()​

toXml(fieldElement): Element;

Serializes this field's value to XML. Should only be called by Blockly.Xml.

Parameters​

ParameterTypeDescription
fieldElementElementThe element to populate with info about the field's state.

Returns​

Element

The element containing info about the field's state.

Inherited from​

Blockly.Field.toXml


updateEditable()​

updateEditable(): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:288

Determines whether the field is editable.

Returns​

void

True since it is always editable.

Overrides​

Blockly.Field.updateEditable


updateSize_()​

protected updateSize_(): void;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:657

Updates the size of the block based on the size of the underlying image.

Returns​

void

Overrides​

Blockly.Field.updateSize_


fromJson()​

static fromJson(options): FieldBitmap;

Defined in: plugins/field-bitmap/src/field-bitmap.ts:93

Constructs a FieldBitmap from a JSON arg object.

Parameters​

ParameterTypeDescription
optionsFieldBitmapFromJsonConfigA JSON object with options.

Returns​

FieldBitmap

The new field instance.

Overrides​

Blockly.Field.fromJson