Blockly. Extensions
Methods
apply
apply(name, block, isMutator)
Applies an extension method to a block. This should only be called during block construction.
Parameter |
|
---|---|
name |
string The name of the extension. |
block |
The block to apply the named extension to. Value must not be null. |
isMutator |
boolean True if this extension defines a mutator. |
- Throws
-
Error
if the extension is not found.
buildTooltipForDropdown
buildTooltipForDropdown(dropdownName, lookupTable) returns function()
Builds an extension function that will map a dropdown value to a tooltip string.
This method includes multiple checks to ensure tooltips, dropdown options, and message references are aligned. This aims to catch errors as early as possible, without requiring developers to manually test tooltips under each option. After the page is loaded, each tooltip text string will be checked for matching message keys in the internationalized string table. Deferring this until the page is loaded decouples loading dependencies. Later, upon loading the first block of any given type, the extension will validate every dropdown option has a matching tooltip in the lookupTable. Errors are reported as warnings in the console, and are never fatal.
Parameter |
|
---|---|
dropdownName |
string The name of the field whose value is the key to the lookup table. |
lookupTable |
Object with string properties The table of field values to tooltip text. Value must not be null. |
- Returns
-
non-null function()
The extension function.
buildTooltipWithFieldText
buildTooltipWithFieldText(msgTemplate, fieldName) returns function()
Builds an extension function that will install a dynamic tooltip. The tooltip message should include the string '%1' and that string will be replaced with the text of the named field.
Parameter |
|
---|---|
msgTemplate |
string The template form to of the message text, with %1 placeholder. |
fieldName |
string The field with the replacement text. |
- Returns
-
non-null function()
The extension function.
register
register(name, initFn)
Registers a new extension function. Extensions are functions that help initialize blocks, usually adding dynamic behavior such as onchange handlers and mutators. These are applied using Block.applyExtension(), or the JSON "extensions" array attribute.
Parameter |
|
---|---|
name |
string The name of this extension. |
initFn |
function() The function to initialize an extended block. |
- Throws
-
Error
if the extension name is empty, the extension is already registered, or extensionFn is not a function.
registerMixin
registerMixin(name, mixinObj)
Registers a new extension function that adds all key/value of mixinObj.
Parameter |
|
---|---|
name |
string The name of this extension. |
mixinObj |
Object The values to mix in. Value must not be null. |
- Throws
-
Error
if the extension name is empty or the extension is already registered.
registerMutator
registerMutator(name, mixinObj, opt_helperFn, opt_blockList)
Registers a new extension function that adds a mutator to the block. At register time this performs some basic sanity checks on the mutator. The wrapper may also add a mutator dialog to the block, if both compose and decompose are defined on the mixin.
Parameter |
|
---|---|
name |
string The name of this mutator extension. |
mixinObj |
Object The values to mix in. Value must not be null. |
opt_helperFn |
Optional function() An optional function to apply after mixing in the object. |
opt_blockList |
Optional Array of string A list of blocks to appear in the flyout of the mutator dialog. Value must not be null. |
- Throws
-
Error
if the mutation is invalid or can't be applied to the block.
unregister
unregister(name)
Unregisters the extension registered with the given name.
Parameter |
|
---|---|
name |
string The name of the extension to unregister. |