cloud-blocks
Version:
Cloud Blocks is a library for building scratch computing interfaces with Luxrobo MODI.
1,548 lines (1,341 loc) • 687 kB
TypeScript
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Type definitions for Blockly.
* @author samelh@google.com (Sam El-Husseini)
*/
export = Blockly;
declare module Blockly {
interface BlocklyOptions {
toolbox?: HTMLElement | string;
readOnly?: boolean;
trashcan?: boolean;
maxInstances?: { [type: string]: number };
maxTrashcanContents?: number;
collapse?: boolean;
comments?: boolean;
disable?: boolean;
sounds?: boolean;
rtl?: boolean;
horizontalLayout?: boolean;
toolboxPosition?: string;
css?: boolean;
oneBasedIndex?: boolean;
media?: string;
theme?: Blockly.Theme | BlocklyThemeOptions;
move?: {
scrollbars?: boolean;
drag?: boolean;
wheel?: boolean;
};
grid?: {
spacing?: number;
colour?: string;
length?: number;
snap?: boolean;
};
zoom?: {
controls?: boolean;
wheel?: boolean;
startScale?: number;
maxScale?: number;
minScale?: number;
scaleSpeed?: number;
pinch?: boolean;
};
renderer?: string;
parentWorkspace?: Blockly.WorkspaceSvg;
}
interface BlocklyThemeOptions {
base?: string;
blockStyles?: { [blocks: string]: Blockly.Theme.BlockStyle };
categoryStyles?: { [category: string]: Blockly.Theme.CategoryStyle };
componentStyles?: { [component: string]: any };
fontStyle?: Blockly.Theme.FontStyle;
startHats?: boolean;
}
/**
* Set the Blockly locale.
* Note: this method is only available in the npm release of Blockly.
* @param {!Object} msg An object of Blockly message strings in the desired
* language.
*/
function setLocale(msg: { [key: string]: string }): void;
}
declare module Blockly.utils {
interface Metrics {
viewHeight: number;
viewWidth: number;
contentHeight: number;
contentWidth: number;
viewTop: number;
viewLeft: number;
contentTop: number;
contentLeft: number;
absoluteTop: number;
absoluteLeft: number;
svgHeight?: number;
svgWidth?: number;
toolboxWidth?: number;
toolboxHeight?: number;
flyoutWidth?: number;
flyoutHeight?: number;
toolboxPosition?: number;
}
}
declare module Blockly {
class Block extends Block__Class {}
/** Fake class which should be extended to avoid inheriting static properties */
class Block__Class implements Blockly.IASTNodeLocation {
/**
* Class for one block.
* Not normally called directly, workspace.newBlock() is preferred.
* @param {!Blockly.Workspace} workspace The block's workspace.
* @param {!string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new ID.
* @constructor
* @implements {Blockly.IASTNodeLocation}
* @throws When the prototypeName is not valid or not allowed.
*/
constructor(
workspace: Blockly.Workspace,
prototypeName: string,
opt_id?: string
);
/** @type {string} */
id: string;
/** @type {Blockly.Connection} */
outputConnection: Blockly.Connection;
/** @type {Blockly.Connection} */
nextConnection: Blockly.Connection;
/** @type {Blockly.Connection} */
previousConnection: Blockly.Connection;
/** @type {!Array.<!Blockly.Input>} */
inputList: Blockly.Input[];
/** @type {boolean|undefined} */
inputsInline: boolean | any /*undefined*/;
/** @type {!Blockly.Tooltip.TipInfo} */
tooltip: Blockly.Tooltip.TipInfo;
/** @type {boolean} */
contextMenu: boolean;
/**
* @type {Blockly.Block}
* @protected
*/
parentBlock_: Blockly.Block;
/**
* @type {!Array.<!Blockly.Block>}
* @protected
*/
childBlocks_: Blockly.Block[];
/**
* @type {boolean}
* @protected
*/
collapsed_: boolean;
/**
* @type {?number}
* @protected
*/
outputShape_: number;
/**
* A string representing the comment attached to this block.
* @type {string|Blockly.Comment}
* @deprecated August 2019. Use getCommentText instead.
*/
comment: string | Blockly.Comment;
/**
* A model of the comment attached to this block.
* @type {!Blockly.Block.CommentModel}
* @package
*/
commentModel: Blockly.Block.CommentModel;
/** @type {!Blockly.Workspace} */
workspace: Blockly.Workspace;
/** @type {boolean} */
isInFlyout: boolean;
/** @type {boolean} */
isInMutator: boolean;
/** @type {boolean} */
RTL: boolean;
/**
* True if this block is an insertion marker.
* @type {boolean}
* @protected
*/
isInsertionMarker_: boolean;
/**
* Name of the type of hat.
* @type {string|undefined}
*/
hat: string | any /*undefined*/;
/** @type {?boolean} */
rendered: boolean;
/**
* A count of statement inputs on the block.
* @type {number}
* @package
*/
statementInputCount: number;
/** @type {string} */
type: string;
/** @type {boolean|undefined} */
inputsInlineDefault: boolean | any /*undefined*/;
/**
* Optional text data that round-trips between blocks and XML.
* Has no effect. May be used by 3rd parties for meta information.
* @type {?string}
*/
data: string;
/**
* Has this block been disposed of?
* @type {boolean}
* @package
*/
disposed: boolean;
/**
* Colour of the block in '#RRGGBB' format.
* @type {string}
* @protected
*/
colour_: string;
/**
* Name of the block style.
* @type {?string}
* @protected
*/
styleName_: string;
/**
* An optional method called during initialization.
* @type {?function()}
*/
init: { (): any /*missing*/ };
/**
* An optional callback method to use whenever the block's parent workspace
* changes. This is usually only called from the constructor, the block type
* initializer function, or an extension initializer function.
* @type {?function(Blockly.Events.Abstract)}
*/
onchange: { (_0: Blockly.Events.Abstract): any /*missing*/ };
/**
* An optional serialization method for defining how to serialize the
* mutation state. This must be coupled with defining `domToMutation`.
* @type {?function(...):!Element}
*/
mutationToDom: any /*missing*/;
/**
* An optional deserialization method for defining how to deserialize the
* mutation state. This must be coupled with defining `mutationToDom`.
* @type {?function(!Element)}
*/
domToMutation: { (_0: Element): any /*missing*/ };
/**
* An optional property for suppressing adding STATEMENT_PREFIX and
* STATEMENT_SUFFIX to generated code.
* @type {?boolean}
*/
suppressPrefixSuffix: boolean;
/**
* An optional property for declaring developer variables. Return a list of
* variable names for use by generators. Developer variables are never shown to
* the user, but are declared as global variables in the generated code.
* @type {?function():!Array.<string>}
*/
getDeveloperVariables: { (): string[] };
/**
* Dispose of this block.
* @param {boolean} healStack If true, then try to heal any gap by connecting
* the next statement with the previous statement. Otherwise, dispose of
* all children of this block.
* @suppress {checkTypes}
*/
dispose(healStack: boolean): void;
/**
* Call initModel on all fields on the block.
* May be called more than once.
* Either initModel or initSvg must be called after creating a block and before
* the first interaction with it. Interactions include UI actions
* (e.g. clicking and dragging) and firing events (e.g. create, delete, and
* change).
* @public
*/
initModel(): void;
/**
* Unplug this block from its superior block. If this block is a statement,
* optionally reconnect the block underneath with the block on top.
* @param {boolean=} opt_healStack Disconnect child statement and reconnect
* stack. Defaults to false.
*/
unplug(opt_healStack?: boolean): void;
/**
* Returns all connections originating from this block.
* @param {boolean} _all If true, return all connections even hidden ones.
* @return {!Array.<!Blockly.Connection>} Array of connections.
* @package
*/
getConnections_(_all: boolean): Blockly.Connection[];
/**
* Walks down a stack of blocks and finds the last next connection on the stack.
* @return {Blockly.Connection} The last next connection on the stack, or null.
* @package
*/
lastConnectionInStack(): Blockly.Connection;
/**
* Bump unconnected blocks out of alignment. Two blocks which aren't actually
* connected should not coincidentally line up on screen.
*/
bumpNeighbours(): void;
/**
* Return the parent block or null if this block is at the top level. The parent
* block is either the block connected to the previous connection (for a statement
* block) or the block connected to the output connection (for a value block).
* @return {Blockly.Block} The block that holds the current block.
*/
getParent(): Blockly.Block;
/**
* Return the input that connects to the specified block.
* @param {!Blockly.Block} block A block connected to an input on this block.
* @return {Blockly.Input} The input that connects to the specified block.
*/
getInputWithBlock(block: Blockly.Block): Blockly.Input;
/**
* Return the parent block that surrounds the current block, or null if this
* block has no surrounding block. A parent block might just be the previous
* statement, whereas the surrounding block is an if statement, while loop, etc.
* @return {Blockly.Block} The block that surrounds the current block.
*/
getSurroundParent(): Blockly.Block;
/**
* Return the next statement block directly connected to this block.
* @return {Blockly.Block} The next statement block or null.
*/
getNextBlock(): Blockly.Block;
/**
* Returns the block connected to the previous connection.
* @return {Blockly.Block} The previous statement block or null.
*/
getPreviousBlock(): Blockly.Block;
/**
* Return the connection on the first statement input on this block, or null if
* there are none.
* @return {Blockly.Connection} The first statement connection or null.
* @package
*/
getFirstStatementConnection(): Blockly.Connection;
/**
* Return the top-most block in this block's tree.
* This will return itself if this block is at the top level.
* @return {!Blockly.Block} The root block.
*/
getRootBlock(): Blockly.Block;
/**
* Walk up from the given block up through the stack of blocks to find
* the top block of the sub stack. If we are nested in a statement input only
* find the top-most nested block. Do not go all the way to the root block.
* @return {!Blockly.Block} The top block in a stack.
* @package
*/
getTopStackBlock(): Blockly.Block;
/**
* Find all the blocks that are directly nested inside this one.
* Includes value and statement inputs, as well as any following statement.
* Excludes any connection on an output tab or any preceding statement.
* Blocks are optionally sorted by position; top to bottom.
* @param {boolean} ordered Sort the list if true.
* @return {!Array.<!Blockly.Block>} Array of blocks.
*/
getChildren(ordered: boolean): Blockly.Block[];
/**
* Set parent of this block to be a new block or null.
* @param {Blockly.Block} newParent New parent block.
*/
setParent(newParent: Blockly.Block): void;
/**
* Find all the blocks that are directly or indirectly nested inside this one.
* Includes this block in the list.
* Includes value and statement inputs, as well as any following statements.
* Excludes any connection on an output tab or any preceding statements.
* Blocks are optionally sorted by position; top to bottom.
* @param {boolean} ordered Sort the list if true.
* @return {!Array.<!Blockly.Block>} Flattened array of blocks.
*/
getDescendants(ordered: boolean): Blockly.Block[];
/**
* Get whether this block is deletable or not.
* @return {boolean} True if deletable.
*/
isDeletable(): boolean;
/**
* Set whether this block is deletable or not.
* @param {boolean} deletable True if deletable.
*/
setDeletable(deletable: boolean): void;
/**
* Get whether this block is movable or not.
* @return {boolean} True if movable.
*/
isMovable(): boolean;
/**
* Set whether this block is movable or not.
* @param {boolean} movable True if movable.
*/
setMovable(movable: boolean): void;
/**
* Get whether is block is duplicatable or not. If duplicating this block and
* descendants will put this block over the workspace's capacity this block is
* not duplicatable. If duplicating this block and descendants will put any
* type over their maxInstances this block is not duplicatable.
* @return {boolean} True if duplicatable.
*/
isDuplicatable(): boolean;
/**
* Get whether this block is a shadow block or not.
* @return {boolean} True if a shadow.
*/
isShadow(): boolean;
/**
* Set whether this block is a shadow block or not.
* @param {boolean} shadow True if a shadow.
*/
setShadow(shadow: boolean): void;
/**
* Get whether this block is an insertion marker block or not.
* @return {boolean} True if an insertion marker.
*/
isInsertionMarker(): boolean;
/**
* Set whether this block is an insertion marker block or not.
* Once set this cannot be unset.
* @param {boolean} insertionMarker True if an insertion marker.
* @package
*/
setInsertionMarker(insertionMarker: boolean): void;
/**
* Get whether this block is editable or not.
* @return {boolean} True if editable.
*/
isEditable(): boolean;
/**
* Set whether this block is editable or not.
* @param {boolean} editable True if editable.
*/
setEditable(editable: boolean): void;
/**
* Returns if this block has been disposed of / deleted.
* @return {boolean} True if this block has been disposed of / deleted.
*/
isDisposed(): boolean;
/**
* Find the connection on this block that corresponds to the given connection
* on the other block.
* Used to match connections between a block and its insertion marker.
* @param {!Blockly.Block} otherBlock The other block to match against.
* @param {!Blockly.Connection} conn The other connection to match.
* @return {Blockly.Connection} The matching connection on this block, or null.
* @package
*/
getMatchingConnection(
otherBlock: Blockly.Block,
conn: Blockly.Connection
): Blockly.Connection;
/**
* Set the URL of this block's help page.
* @param {string|Function} url URL string for block help, or function that
* returns a URL. Null for no help.
*/
setHelpUrl(url: string | Function): void;
/**
* Sets the tooltip for this block.
* @param {!Blockly.Tooltip.TipInfo} newTip The text for the tooltip, a function
* that returns the text for the tooltip, or a parent object whose tooltip
* will be used. To not display a tooltip pass the empty string.
*/
setTooltip(newTip: Blockly.Tooltip.TipInfo): void;
/**
* Returns the tooltip text for this block.
* @returns {!string} The tooltip text for this block.
*/
getTooltip(): string;
/**
* Get the colour of a block.
* @return {string} #RRGGBB string.
*/
getColour(): string;
/**
* Get the name of the block style.
* @return {?string} Name of the block style.
*/
getStyleName(): string;
/**
* Get the HSV hue value of a block. Null if hue not set.
* @return {?number} Hue value (0-360).
*/
getHue(): number;
/**
* Change the colour of a block.
* @param {number|string} colour HSV hue value (0 to 360), #RRGGBB string,
* or a message reference string pointing to one of those two values.
*/
setColour(colour: number | string): void;
/**
* Set the style and colour values of a block.
* @param {string} blockStyleName Name of the block style
*/
setStyle(blockStyleName: string): void;
/**
* Sets a callback function to use whenever the block's parent workspace
* changes, replacing any prior onchange handler. This is usually only called
* from the constructor, the block type initializer function, or an extension
* initializer function.
* @param {function(Blockly.Events.Abstract)} onchangeFn The callback to call
* when the block's workspace changes.
* @throws {Error} if onchangeFn is not falsey and not a function.
*/
setOnChange(onchangeFn: {
(_0: Blockly.Events.Abstract): any /*missing*/;
}): void;
/**
* Returns the named field from a block.
* @param {string} name The name of the field.
* @return {Blockly.Field} Named field, or null if field does not exist.
*/
getField(name: string): Blockly.Field;
/**
* Return all variables referenced by this block.
* @return {!Array.<string>} List of variable names.
*/
getVars(): string[];
/**
* Return all variables referenced by this block.
* @return {!Array.<!Blockly.VariableModel>} List of variable models.
* @package
*/
getVarModels(): Blockly.VariableModel[];
/**
* Notification that a variable is renaming but keeping the same ID. If the
* variable is in use on this block, rerender to show the new name.
* @param {!Blockly.VariableModel} variable The variable being renamed.
* @package
*/
updateVarName(variable: Blockly.VariableModel): void;
/**
* Notification that a variable is renaming.
* If the ID matches one of this block's variables, rename it.
* @param {string} oldId ID of variable to rename.
* @param {string} newId ID of new variable. May be the same as oldId, but with
* an updated name.
*/
renameVarById(oldId: string, newId: string): void;
/**
* Returns the language-neutral value of the given field.
* @param {string} name The name of the field.
* @return {*} Value of the field or null if field does not exist.
*/
getFieldValue(name: string): any;
/**
* Sets the value of the given field for this block.
* @param {*} newValue The value to set.
* @param {!string} name The name of the field to set the value of.
*/
setFieldValue(newValue: any, name: string): void;
/**
* Set whether this block can chain onto the bottom of another block.
* @param {boolean} newBoolean True if there can be a previous statement.
* @param {(string|Array.<string>|null)=} opt_check Statement type or
* list of statement types. Null/undefined if any type could be connected.
*/
setPreviousStatement(
newBoolean: boolean,
opt_check?: string | string[] | any /*null*/
): void;
/**
* Set whether another block can chain onto the bottom of this block.
* @param {boolean} newBoolean True if there can be a next statement.
* @param {(string|Array.<string>|null)=} opt_check Statement type or
* list of statement types. Null/undefined if any type could be connected.
*/
setNextStatement(
newBoolean: boolean,
opt_check?: string | string[] | any /*null*/
): void;
/**
* Set whether this block returns a value.
* @param {boolean} newBoolean True if there is an output.
* @param {(string|Array.<string>|null)=} opt_check Returned type or list
* of returned types. Null or undefined if any type could be returned
* (e.g. variable get).
*/
setOutput(
newBoolean: boolean,
opt_check?: string | string[] | any /*null*/
): void;
/**
* Set whether value inputs are arranged horizontally or vertically.
* @param {boolean} newBoolean True if inputs are horizontal.
*/
setInputsInline(newBoolean: boolean): void;
/**
* Get whether value inputs are arranged horizontally or vertically.
* @return {boolean} True if inputs are horizontal.
*/
getInputsInline(): boolean;
/**
* Set the block's output shape.
* @param {?number} outputShape Value representing an output shape.
*/
setOutputShape(outputShape: number): void;
/**
* Get the block's output shape.
* @return {?number} Value representing output shape if one exists.
*/
getOutputShape(): number;
/**
* Get whether this block is enabled or not.
* @return {boolean} True if enabled.
*/
isEnabled(): boolean;
/**
* Set whether the block is enabled or not.
* @param {boolean} enabled True if enabled.
*/
setEnabled(enabled: boolean): void;
/**
* Get whether the block is disabled or not due to parents.
* The block's own disabled property is not considered.
* @return {boolean} True if disabled.
*/
getInheritedDisabled(): boolean;
/**
* Get whether the block is collapsed or not.
* @return {boolean} True if collapsed.
*/
isCollapsed(): boolean;
/**
* Set whether the block is collapsed or not.
* @param {boolean} collapsed True if collapsed.
*/
setCollapsed(collapsed: boolean): void;
/**
* Create a human-readable text representation of this block and any children.
* @param {number=} opt_maxLength Truncate the string to this length.
* @param {string=} opt_emptyToken The placeholder string used to denote an
* empty field. If not specified, '?' is used.
* @return {string} Text of block.
*/
toString(opt_maxLength?: number, opt_emptyToken?: string): string;
/**
* Shortcut for appending a value input row.
* @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created.
*/
appendValueInput(name: string): Blockly.Input;
/**
* Shortcut for appending a statement input row.
* @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created.
*/
appendStatementInput(name: string): Blockly.Input;
/**
* Shortcut for appending a dummy input row.
* @param {string=} opt_name Language-neutral identifier which may used to find
* this input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created.
*/
appendDummyInput(opt_name?: string): Blockly.Input;
/**
* Initialize this block using a cross-platform, internationalization-friendly
* JSON description.
* @param {!Object} json Structured data describing the block.
*/
jsonInit(json: Object): void;
/**
* Add key/values from mixinObj to this block object. By default, this method
* will check that the keys in mixinObj will not overwrite existing values in
* the block, including prototype values. This provides some insurance against
* mixin / extension incompatibilities with future block features. This check
* can be disabled by passing true as the second argument.
* @param {!Object} mixinObj The key/values pairs to add to this block object.
* @param {boolean=} opt_disableCheck Option flag to disable overwrite checks.
*/
mixin(mixinObj: Object, opt_disableCheck?: boolean): void;
/**
* Add a value input, statement input or local variable to this block.
* @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or
* Blockly.DUMMY_INPUT.
* @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created.
* @protected
*/
appendInput_(type: number, name: string): Blockly.Input;
/**
* Move a named input to a different location on this block.
* @param {string} name The name of the input to move.
* @param {?string} refName Name of input that should be after the moved input,
* or null to be the input at the end.
*/
moveInputBefore(name: string, refName: string): void;
/**
* Move a numbered input to a different location on this block.
* @param {number} inputIndex Index of the input to move.
* @param {number} refIndex Index of input that should be after the moved input.
*/
moveNumberedInputBefore(inputIndex: number, refIndex: number): void;
/**
* Remove an input from this block.
* @param {string} name The name of the input.
* @param {boolean=} opt_quiet True to prevent an error if input is not present.
* @return {boolean} True if operation succeeds, false if input is not present and opt_quiet is true
* @throws {Error} if the input is not present and opt_quiet is not true.
*/
removeInput(name: string, opt_quiet?: boolean): boolean;
/**
* Fetches the named input object.
* @param {string} name The name of the input.
* @return {Blockly.Input} The input object, or null if input does not exist.
*/
getInput(name: string): Blockly.Input;
/**
* Fetches the block attached to the named input.
* @param {string} name The name of the input.
* @return {Blockly.Block} The attached value block, or null if the input is
* either disconnected or if the input does not exist.
*/
getInputTargetBlock(name: string): Blockly.Block;
/**
* Returns the comment on this block (or null if there is no comment).
* @return {?string} Block's comment.
*/
getCommentText(): string;
/**
* Set this block's comment text.
* @param {?string} text The text, or null to delete.
*/
setCommentText(text: string): void;
/**
* Set this block's warning text.
* @param {?string} _text The text, or null to delete.
* @param {string=} _opt_id An optional ID for the warning text to be able to
* maintain multiple warnings.
*/
setWarningText(_text: string, _opt_id?: string): void;
/**
* Give this block a mutator dialog.
* @param {Blockly.Mutator} _mutator A mutator dialog instance or null to
* remove.
*/
setMutator(_mutator: Blockly.Mutator): void;
/**
* Return the coordinates of the top-left corner of this block relative to the
* drawing surface's origin (0,0), in workspace units.
* @return {!Blockly.utils.Coordinate} Object with .x and .y properties.
*/
getRelativeToSurfaceXY(): Blockly.utils.Coordinate;
/**
* Move a block by a relative offset.
* @param {number} dx Horizontal offset, in workspace units.
* @param {number} dy Vertical offset, in workspace units.
*/
moveBy(dx: number, dy: number): void;
/**
* Create a connection of the specified type.
* @param {number} type The type of the connection to create.
* @return {!Blockly.Connection} A new connection of the specified type.
* @protected
*/
makeConnection_(type: number): Blockly.Connection;
/**
* Recursively checks whether all statement and value inputs are filled with
* blocks. Also checks all following statement blocks in this stack.
* @param {boolean=} opt_shadowBlocksAreFilled An optional argument controlling
* whether shadow blocks are counted as filled. Defaults to true.
* @return {boolean} True if all inputs are filled, false otherwise.
*/
allInputsFilled(opt_shadowBlocksAreFilled?: boolean): boolean;
/**
* This method returns a string describing this Block in developer terms (type
* name and ID; English only).
*
* Intended to on be used in console logs and errors. If you need a string that
* uses the user's native language (including block text, field values, and
* child blocks), use [toString()]{@link Blockly.Block#toString}.
* @return {string} The description.
*/
toDevString(): string;
}
}
declare module Blockly.Block {
/**
* @typedef {{
* text:?string,
* pinned:boolean,
* size:Blockly.utils.Size
* }}
*/
interface CommentModel {
text: string;
pinned: boolean;
size: Blockly.utils.Size;
}
/**
* The language-neutral id given to the collapsed input.
* @const {string}
*/
var COLLAPSED_INPUT_NAME: any /*missing*/;
/**
* The language-neutral id given to the collapsed field.
* @const {string}
*/
var COLLAPSED_FIELD_NAME: any /*missing*/;
}
declare module Blockly.blockAnimations {
/**
* Play some UI effects (sound, animation) when disposing of a block.
* @param {!Blockly.BlockSvg} block The block being disposed of.
* @package
*/
function disposeUiEffect(block: Blockly.BlockSvg): void;
/**
* Play some UI effects (sound, ripple) after a connection has been established.
* @param {!Blockly.BlockSvg} block The block being connected.
* @package
*/
function connectionUiEffect(block: Blockly.BlockSvg): void;
/**
* Play some UI effects (sound, animation) when disconnecting a block.
* @param {!Blockly.BlockSvg} block The block being disconnected.
* @package
*/
function disconnectUiEffect(block: Blockly.BlockSvg): void;
/**
* Stop the disconnect UI animation immediately.
* @package
*/
function disconnectUiStop(): void;
}
declare module Blockly {
class BlockDragSurfaceSvg extends BlockDragSurfaceSvg__Class {}
/** Fake class which should be extended to avoid inheriting static properties */
class BlockDragSurfaceSvg__Class {
/**
* Class for a drag surface for the currently dragged block. This is a separate
* SVG that contains only the currently moving block, or nothing.
* @param {!Element} container Containing element.
* @constructor
*/
constructor(container: Element);
/**
* Create the drag surface and inject it into the container.
*/
createDom(): void;
/**
* Set the SVG blocks on the drag surface's group and show the surface.
* Only one block group should be on the drag surface at a time.
* @param {!SVGElement} blocks Block or group of blocks to place on the drag
* surface.
*/
setBlocksAndShow(blocks: SVGElement): void;
/**
* Translate and scale the entire drag surface group to the given position, to
* keep in sync with the workspace.
* @param {number} x X translation in workspace coordinates.
* @param {number} y Y translation in workspace coordinates.
* @param {number} scale Scale of the group.
*/
translateAndScaleGroup(x: number, y: number, scale: number): void;
/**
* Translate the entire drag surface during a drag.
* We translate the drag surface instead of the blocks inside the surface
* so that the browser avoids repainting the SVG.
* Because of this, the drag coordinates must be adjusted by scale.
* @param {number} x X translation for the entire surface.
* @param {number} y Y translation for the entire surface.
*/
translateSurface(x: number, y: number): void;
/**
* Reports the surface translation in scaled workspace coordinates.
* Use this when finishing a drag to return blocks to the correct position.
* @return {!Blockly.utils.Coordinate} Current translation of the surface.
*/
getSurfaceTranslation(): Blockly.utils.Coordinate;
/**
* Provide a reference to the drag group (primarily for
* BlockSvg.getRelativeToSurfaceXY).
* @return {SVGElement} Drag surface group element.
*/
getGroup(): SVGElement;
/**
* Get the current blocks on the drag surface, if any (primarily
* for BlockSvg.getRelativeToSurfaceXY).
* @return {Element} Drag surface block DOM element, or undefined if no blocks
* exist.
*/
getCurrentBlock(): Element;
/**
* Clear the group and hide the surface; move the blocks off onto the provided
* element.
* If the block is being deleted it doesn't need to go back to the original
* surface, since it would be removed immediately during dispose.
* @param {Element=} opt_newSurface Surface the dragging blocks should be moved
* to, or null if the blocks should be removed from this surface without
* being moved to a different surface.
*/
clearAndHide(opt_newSurface?: Element): void;
}
}
declare module Blockly {
class BlockDragger extends BlockDragger__Class {}
/** Fake class which should be extended to avoid inheriting static properties */
class BlockDragger__Class {
/**
* Class for a block dragger. It moves blocks around the workspace when they
* are being dragged by a mouse or touch.
* @param {!Blockly.BlockSvg} block The block to drag.
* @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on.
* @constructor
*/
constructor(block: Blockly.BlockSvg, workspace: Blockly.WorkspaceSvg);
/**
* Sever all links from this object.
* @package
*/
dispose(): void;
/**
* Start dragging a block. This includes moving it to the drag surface.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at mouse down, in pixel units.
* @param {boolean} healStack Whether or not to heal the stack after
* disconnecting.
* @package
*/
startBlockDrag(
currentDragDeltaXY: Blockly.utils.Coordinate,
healStack: boolean
): void;
/**
* Execute a step of block dragging, based on the given event. Update the
* display accordingly.
* @param {!Event} e The most recent move event.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at the start of the drag, in pixel units.
* @package
*/
dragBlock(e: Event, currentDragDeltaXY: Blockly.utils.Coordinate): void;
/**
* Finish a block drag and put the block back on the workspace.
* @param {!Event} e The mouseup/touchend event.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at the start of the drag, in pixel units.
* @package
*/
endBlockDrag(e: Event, currentDragDeltaXY: Blockly.utils.Coordinate): void;
/**
* Get a list of the insertion markers that currently exist. Drags have 0, 1,
* or 2 insertion markers.
* @return {!Array.<!Blockly.BlockSvg>} A possibly empty list of insertion
* marker blocks.
* @package
*/
getInsertionMarkers(): Blockly.BlockSvg[];
}
}
declare module Blockly {
class BlockSvg extends BlockSvg__Class {}
/** Fake class which should be extended to avoid inheriting static properties */
class BlockSvg__Class
extends Blockly.Block__Class
implements
Blockly.IASTNodeLocationSvg,
Blockly.IBoundedElement,
Blockly.ICopyable {
/**
* Class for a block's SVG representation.
* Not normally called directly, workspace.newBlock() is preferred.
* @param {!Blockly.WorkspaceSvg} workspace The block's workspace.
* @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new ID.
* @extends {Blockly.Block}
* @implements {Blockly.IASTNodeLocationSvg}
* @implements {Blockly.IBoundedElement}
* @implements {Blockly.ICopyable}
* @constructor
*/
constructor(
workspace: Blockly.WorkspaceSvg,
prototypeName: string,
opt_id?: string
);
/**
* A block style object.
* @type {!Blockly.Theme.BlockStyle}
*/
style: Blockly.Theme.BlockStyle;
/**
* The renderer's path object.
* @type {Blockly.blockRendering.IPathObject}
* @package
*/
pathObject: Blockly.blockRendering.IPathObject;
/** @type {boolean} */
rendered: boolean;
/** @type {!Blockly.WorkspaceSvg} */
workspace: Blockly.WorkspaceSvg;
/** @type {Blockly.RenderedConnection} */
outputConnection: Blockly.RenderedConnection;
/** @type {Blockly.RenderedConnection} */
nextConnection: Blockly.RenderedConnection;
/** @type {Blockly.RenderedConnection} */
previousConnection: Blockly.RenderedConnection;
/**
* Height of this block, not including any statement blocks above or below.
* Height is in workspace units.
*/
height: any /*missing*/;
/**
* Width of this block, including any connected value blocks.
* Width is in workspace units.
*/
width: any /*missing*/;
/**
* An optional method called when a mutator dialog is first opened.
* This function must create and initialize a top-level block for the mutator
* dialog, and return it. This function should also populate this top-level
* block with any sub-blocks which are appropriate. This method must also be
* coupled with defining a `compose` method for the default mutation dialog
* button and UI to appear.
* @type {?function(Blockly.WorkspaceSvg):!Blockly.BlockSvg}
*/
decompose: { (_0: Blockly.WorkspaceSvg): Blockly.BlockSvg };
/**
* An optional method called when a mutator dialog saves its content.
* This function is called to modify the original block according to new
* settings. This method must also be coupled with defining a `decompose`
* method for the default mutation dialog button and UI to appear.
* @type {?function(!Blockly.BlockSvg)}
*/
compose: { (_0: Blockly.BlockSvg): any /*missing*/ };
/**
* An optional method for defining custom block context menu items.
* @type {?function(!Array.<!Object>)}
*/
customContextMenu: { (_0: Object[]): any /*missing*/ };
/**
* An property used internally to reference the block's rendering debugger.
* @type {?Blockly.blockRendering.Debug}
* @package
*/
renderingDebugger: Blockly.blockRendering.Debug;
/**
* Create and initialize the SVG representation of the block.
* May be called more than once.
*/
initSvg(): void;
/**
* Get the secondary colour of a block.
* @return {?string} #RRGGBB string.
*/
getColourSecondary(): string;
/**
* Get the tertiary colour of a block.
* @return {?string} #RRGGBB string.
*/
getColourTertiary(): string;
/**
* Get the shadow colour of a block.
* @return {?string} #RRGGBB string.
* @deprecated Use style.colourSecondary. (2020 January 21)
*/
getColourShadow(): string;
/**
* Get the border colour(s) of a block.
* @return {{colourDark, colourLight, colourBorder}} An object containing
* colour values for the border(s) of the block. If the block is using a
* style the colourBorder will be defined and equal to the tertiary colour
* of the style (#RRGGBB string). Otherwise the colourDark and colourLight
* attributes will be defined (#RRGGBB strings).
* @deprecated Use style.colourTertiary. (2020 January 21)
*/
getColourBorder(): {
colourDark: any /*missing*/;
colourLight: any /*missing*/;
colourBorder: any /*missing*/;
};
/**
* Select this block. Highlight it visually.
*/
select(): void;
/**
* Unselect this block. Remove its highlighting.
*/
unselect(): void;
/**
* Block's mutator icon (if any).
* @type {Blockly.Mutator}
*/
mutator: Blockly.Mutator;
/**
* Block's comment icon (if any).
* @type {Blockly.Comment}
* @deprecated August 2019. Use getCommentIcon instead.
*/
comment: Blockly.Comment;
/**
* Block's warning icon (if any).
* @type {Blockly.Warning}
*/
warning: Blockly.Warning;
/**
* Returns a list of mutator, comment, and warning icons.
* @return {!Array} List of icons.
*/
getIcons(): any[];
/**
* Return the coordinates of the top-left corner of this block relative to the
* drawing surface's origin (0,0), in workspace units.
* If the block is on the workspace, (0, 0) is the origin of the workspace
* coordinate system.
* This does not change with workspace scale.
* @return {!Blockly.utils.Coordinate} Object with .x and .y properties in
* workspace coordinates.
*/
getRelativeToSurfaceXY(): Blockly.utils.Coordinate;
/**
* Move a block by a relative offset.
* @param {number} dx Horizontal offset in workspace units.
* @param {number} dy Vertical offset in workspace units.
*/
moveBy(dx: number, dy: number): void;
/**
* Transforms a block by setting the translation on the transform attribute
* of the block's SVG.
* @param {number} x The x coordinate of the translation in workspace units.
* @param {number} y The y coordinate of the translation in workspace units.
*/
translate(x: number, y: number): void;
/**
* Move this block to its workspace's drag surface, accounting for positioning.
* Generally should be called at the same time as setDragging_(true).
* Does nothing if useDragSurface_ is false.
* @package
*/
moveToDragSurface(): void;
/**
* Move a block to a position.
* @param {Blockly.utils.Coordinate} xy The position to move to in workspace units.
*/
moveTo(xy: Blockly.utils.Coordinate): void;
/**
* Move this block back to the workspace block canvas.
* Generally should be called at the same time as setDragging_(false).
* Does nothing if useDragSurface_ is false.
* @param {!Blockly.utils.Coordinate} newXY The position the block should take on
* on the workspace canvas, in workspace coordinates.
* @package
*/
moveOffDragSurface(newXY: Blockly.utils.Coordinate): void;
/**
* Move this block during a drag, taking into account whether we are using a
* drag surface to translate blocks.
* This block must be a top-level block.
* @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in
* workspace coordinates.
* @package
*/
moveDuringDrag(newLoc: Blockly.utils.Coordinate): void;
/**
* Snap this block to the nearest grid point.
*/
snapToGrid(): void;
/**
* Returns the coordinates of a bounding box describing the dimensions of this
* block and any blocks stacked below it.
* Coordinate system: workspace coordinates.
* @return {!Blockly.utils.Rect} Object with coordinates of the bounding box.
*/
getBoundingRectangle(): Blockly.utils.Rect;
/**
* Notify every input on this block to mark its fields as dirty.
* A dirty field is a field that needs to be re-rendered.
*/
markDirty(): void;
/**
* Set whether the block is collapsed or not.
* @param {boolean} collapsed True if collapsed.
*/
setCollapsed(collapsed: boolean): void;
/**
* Open the next (or previous) FieldTextInput.
* @param {!Blockly.Field} start Current field.
* @param {boolean} forward If true go forward, otherwise backward.
*/
tab(start: Blockly.Field, forward: boolean): void;
/**
* Load the block's help page in a new window.
* @package
*/
showHelp(): void;
/**
* Generate the context menu for this block.
* @protected
* @return {Array.<!Object>} Context menu options
*/
generateContextMenu(): Object[];
/**
* Show the context menu for this block.
* @param {!Event} e Mouse event.
* @package
*/
showContextMenu(e: Event): void;
/**
* Move the connections for this block and all blocks attached under it.
* Also update any attached bubbles.
* @param {number} dx Horizontal offset from current location, in workspace
* units.
* @param {number} dy Vertical offset from current location, in workspace
* units.
* @package
*/
moveConnections(dx: number, dy: number): void;
/**
* Recursively adds or removes the dragging class to this node and its children.
* @param {boolean} adding True if adding, false if removing.
* @package
*/
setDragging(adding: boolean): void;
/**
* Set whether this block is movable or not.
* @param {boolean} movable True if movable.
*/
setMovable(movable: boolean): void;
/**
* Set whether this block is editable or not.
* @param {boolean} editable True if editable.
*/
setEditable(editable: boolean): void;
/**
* Set whether this block is a shadow block or not.
* @param {boolean} shadow True if a shadow.
*/
setShadow(shadow: boolean): void;
/**
* Set whether this block is an insertion marker block or not.
* Once set this cannot be unset.
* @param {boolean} insertionMarker True if an insertion marker.
* @package
*/
setInsertionMarker(insertionMarker: boolean): void;
/**
* Return the root node of the SVG or null if none exists.
* @return {!SVGGElement} The root SVG node (probably a group).
*/
getSvgRoot(): SVGGElement;
/**
* Dispose of this block.
* @param {boolean=} healStack If true, then try to heal any gap by connecting
* the next statement with the previous statement. Otherwise, dispose of
* all children of this block.
* @param {boolean=} animate If true, show a disposal animation and sound.
* @suppress {checkTypes}
*/
dispose(healStack?: boolean, animate?: boolean): void;
/**
* Encode a block for copying.
* @return {?Blockly.ICopyable.CopyData} Copy metadata, or null if the block is
* an insertion marker.
* @package
*/
toCopyData(): Blockly.ICopyable.CopyData;
/**
* Change the colour of a block.
* @package
*/
applyColour(): void;
/**
* Enable or disable a block.
*/
updateDisabled(): void;
/**
* Get the comment icon attached to this block, or null if the block has no
* comment.
* @return {Blockly.Comment} The comment icon attached to this block, or null.
*/
getCommentIcon(): Blockly.Comment;
/**
* Set this block's comment text.
* @param {?string} text The text, or null to delete.
*/
setCommentText(text: string): void;
/**
* Set this block's warning text.
* @param {?string} text The text, or null to delete.
* @param {string=} opt_id An optional ID for the warning text to be able to
* maintain multiple warnings.
*/
setWarningText(text: string, opt_id?: string): void;
/**
* Give this block a mutator dialog.
* @param {Blockly.Mutator} mutator A mutator dialog instance or null to remove.
*/
setMutator(mutator: Blockly.Mutator): void;
/**
* Set whether the block is enabled or not.
* @param {boolean} enabled True if enabled.
*/
setEnabled(enabled: boolean): void;
/**
* Set whether the block is highlighted or not. Block highlighting is
* often used to visually mark blocks currently being executed.
* @param {boolean} highlighted True if highlighted.
*/
setHighlighted(highlighted: boolean): void;
/**
* Select this block. Highlight it visually.
*/
addSelect(): void;
/**
* Unselect this block. Remove its highlighting.
*/
removeSelect(): void;
/**
* Update the cursor over this block by adding or removing a class.
* @param {boolean} enable True if the delete cursor should be shown, false
* otherwise.
* @package
*/
setDeleteStyle(enable: boolean): void;
/**
* Get the colour of a block.
* @return {string} #RRGGBB string.
*/
getColour(): string;
/**
* Change the colour of a block.
* @param {number|string} colour HSV hue value, or #RRGGBB string.
*/
setColour(colour: number | string): void;
/**
* Set the style and colour values of a block.
* @param {string} blockStyleName Name of the block style
* @throws {Error} if the block style does not exist.
*/
setStyle(blockStyleName: string): void;
/**
* Move this block to the front of the visible workspace.
* <g> tags do not respect z-index so SVG renders them in the
* order that they are in the DOM. By placing this block first within the
* block group's <g>, it will render on top of any other blocks.
* @package
*/
bringToFront(): void;
/**
* Set whether this block can chain onto the bottom of another block.
*