pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
1,388 lines (1,242 loc) • 941 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)
*/
// pxt-blockly
// export = Blockly;
declare module Blockly {
export interface BlocklyOptions {
toolbox?: Blockly.utils.toolbox.ToolboxDefinition;
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;
// PXT specific:
toolboxOptions?: ToolboxOptions;
hasCategories?: boolean;
}
// PXT specific:
interface ToolboxOptions {
colour?: boolean;
border?: boolean;
inverted?: boolean;
invertedMultiplier?: number;
disabledOpacity?: number;
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;
}
// pxt-blockly specific
namespace ContextMenu {
interface Option {
enabled?: boolean;
text?: string;
callback?: () => void;
}
}
/**
* 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 namespace goog {
function require(name: string): void;
function provide(name: string): void;
function isFunction(f: any): boolean;
function isString(s: any): boolean;
class Disposable {
dispose(): void;
}
namespace string {
let caseInsensitiveCompare: (a: string, b: string) => number;
}
namespace array {
function remove(ar: string[], v: string): void;
}
namespace dom {
function createDom(tagName: string, opt_attributes?: Object, ...var_args: Object[]): Element;
function createDom(name: string, ns?: string, children?: any): HTMLElement;
function removeChildren(el: Element): void;
function removeNode(node: Node): void;
function getViewportSize(): any;
namespace classlist {
function add(el: Element, className: string): void;
}
class DomHelper {
}
}
namespace math {
class Box {
top: number;
right: number;
bottom: number;
left: number;
constructor(top: number, right: number, bottom: number, left: number);
}
class Rect {
}
class Coordinate {
x: number;
y: number;
constructor(x: number, y: number);
clone(): Coordinate;
static difference(a: Coordinate, b: Coordinate): Coordinate;
static sum(a: Coordinate, b: Coordinate): Coordinate;
static magnitude(a: Coordinate): number;
}
class Size {
width: number;
height: number;
constructor(width: number, height: number);
}
function clamp(n: number, min: number, max: number): number;
function toRadians(n: number): number;
function toDegrees(n: number): number;
}
namespace color {
function lighten(rgb: number[], factor: number): number[];
function darken(rgb: number[], factor: number): number[];
function rgbArrayToHex(rgb: number[]): string;
function hexToRgb(hex: string): number[];
function hsvToHex(hue: number, sat: number, val: number): string;
}
namespace ui {
class Control extends Component {
getChildCount(): number;
getContent(): string | Node | Array<Node>;
getContentElement(): Element;
setChecked(checked: boolean): void;
setContent(content: string | Node | Array<Node>): void;
setVisible(visible: boolean, opt_force?: boolean): boolean;
}
class Component {
static EventType: {
BEFORE_SHOW: string;
SHOW: string;
HIDE: string;
DISABLE: string;
ENABLE: string;
HIGHLIGHT: string;
UNHIGHLIGHT: string;
ACTIVATE: string;
DEACTIVATE: string;
SELECT: string;
UNSELECT: string;
CHECK: string;
UNCHECK: string;
FOCUS: string;
BLUR: string;
OPEN: string;
CLOSE: string;
ENTER: string;
LEAVE: string;
ACTION: string;
CHANGE: string;
};
getHandler<T>(): events.EventHandler<T>;
getElement(): Element;
render(opt_parentElement?: Element): void;
setId(id: string): void;
setRightToLeft(rightToLeft: boolean): void;
addChild(child: Component, opt_render?: boolean): void;
getChildAt(index: number): Component;
removeChildren(opt_unrender: boolean): void;
}
class CustomButton extends Control {
title: string;
}
class Container extends Component {
}
class Menu extends Container implements events.Listenable {
listen: () => events.ListenableKey;
setAllowAutoFocus(allow: boolean): void;
}
class MenuItem extends Control {
constructor(content: (string | Node));
setCheckable(checkable: boolean): void;
setValue(value: any): void;
getValue(): any;
addClassName(className: string): void;
}
class Popup extends PopupBase {
setPosition(position: positioning.ClientPosition): void;
}
class PopupBase extends events.EventTarget {
}
class Tooltip extends Popup {
className: string;
cursorPosition: math.Coordinate;
constructor(opt_el?: Node | string, opt_str?: string);
onShow(): void;
setShowDelayMs(ms: number): void;
}
class Slider extends Component {
setMoveToPointEnabled(val: boolean): void;
setMinimum(min: number): void;
setMaximum(max: number): void;
setUnitIncrement(increments: number): void;
setRightToLeft(rightToLeft: boolean): void;
setValue(value: number): void;
animatedSetValue(value: number): void;
setOrientation(orientation: any): void;
setVisible(visible: boolean): void;
}
class ColorPicker extends Component {
static SIMPLE_GRID_COLORS: Array<string>;
setSize(value: goog.math.Size | number): void;
setColors(colurs: Array<string>): void;
setSelectedColor(color: string): void;
}
class ColorPalette extends Control {
constructor(opt_colors?: Array<string>);
setSize(value: goog.math.Size | number): void;
}
class DatePicker extends Component {
}
}
namespace ui.tree {
class BaseNode {
}
class TreeControl__Class {
}
class TreeNode__Class {
}
}
namespace style {
let backgroundColor: number;
function getBorderBox(element: Element): math.Box;
function getMarginBox(element: Element): math.Box;
function getPaddingBox(element: Element): math.Box;
function getSize(element: Element): math.Size;
function getViewportPageOffset(doc: Document): math.Coordinate;
function scrollIntoContainerView(element: Element, opt_container?: Element, opt_center?: boolean): void;
function setHeight(element: Element, height: number | string): void;
function setWidth(element: Element, width: number | string): void;
function getPageOffset(element: Element): math.Coordinate;
function setStyle(element: Element, style: string, value: string): void;
}
namespace events {
function listen(eventSource: Element | Listenable, eventType: EventType, listener: any, capturePhase?: boolean, handler?: Object): void;
function unlistenByKey(key: any): void;
interface ListenableKey {
key: number;
}
interface Listenable {
listen: () => ListenableKey;
}
type EventType = string;
let EventType: {
CLICK: EventType;
RIGHTCLICK: EventType;
DBLCLICK: EventType;
MOUSEDOWN: EventType;
MOUSEUP: EventType;
MOUSEOVER: EventType;
MOUSEOUT: EventType;
MOUSEMOVE: EventType;
MOUSEENTER: EventType;
MOUSELEAVE: EventType;
SELECTSTART: EventType;
WHEEL: EventType;
KEYPRESS: EventType;
KEYDOWN: EventType;
KEYUP: EventType;
BLUR: EventType;
FOCUS: EventType;
DEACTIVATE: EventType;
FOCUSIN: EventType;
FOCUSOUT: EventType;
CHANGE: EventType;
SELECT: EventType;
SUBMIT: EventType;
INPUT: EventType;
PROPERTYCHANGE: EventType;
DRAGSTART: EventType;
DRAG: EventType;
DRAGENTER: EventType;
DRAGOVER: EventType;
DRAGLEAVE: EventType;
DROP: EventType;
DRAGEND: EventType;
TOUCHSTART: EventType;
TOUCHMOVE: EventType;
TOUCHEND: EventType;
TOUCHCANCEL: EventType;
BEFOREUNLOAD: EventType;
CONSOLEMESSAGE: EventType;
CONTEXTMENU: EventType;
DOMCONTENTLOADED: EventType;
ERROR: EventType;
HELP: EventType;
LOAD: EventType;
LOSECAPTURE: EventType;
ORIENTATIONCHANGE: EventType;
READYSTATECHANGE: EventType;
RESIZE: EventType;
SCROLL: EventType;
UNLOAD: EventType;
HASHCHANGE: EventType;
PAGEHIDE: EventType;
PAGESHOW: EventType;
POPSTATE: EventType;
COPY: EventType;
PASTE: EventType;
CUT: EventType;
BEFORECOPY: EventType;
BEFORECUT: EventType;
BEFOREPASTE: EventType;
ONLINE: EventType;
OFFLINE: EventType;
MESSAGE: EventType;
CONNECT: EventType;
ANIMATIONSTART: EventType;
ANIMATIONEND: EventType;
ANIMATIONITERATION: EventType;
TRANSITIONEND: EventType;
POINTERDOWN: EventType;
POINTERUP: EventType;
POINTERCANCEL: EventType;
POINTERMOVE: EventType;
POINTEROVER: EventType;
POINTEROUT: EventType;
POINTERENTER: EventType;
POINTERLEAVE: EventType;
GOTPOINTERCAPTURE: EventType;
LOSTPOINTERCAPTURE: EventType;
MSGESTURECHANGE: EventType;
MSGESTUREEND: EventType;
MSGESTUREHOLD: EventType;
MSGESTURESTART: EventType;
MSGESTURETAP: EventType;
MSGOTPOINTERCAPTURE: EventType;
MSINERTIASTART: EventType;
MSLOSTPOINTERCAPTURE: EventType;
MSPOINTERCANCEL: EventType;
MSPOINTERDOWN: EventType;
MSPOINTERENTER: EventType;
MSPOINTERHOVER: EventType;
MSPOINTERLEAVE: EventType;
MSPOINTERMOVE: EventType;
MSPOINTEROUT: EventType;
MSPOINTEROVER: EventType;
MSPOINTERUP: EventType;
TEXT: EventType;
TEXTINPUT: EventType;
COMPOSITIONSTART: EventType;
COMPOSITIONUPDATE: EventType;
COMPOSITIONEND: EventType;
EXIT: EventType;
LOADABORT: EventType;
LOADCOMMIT: EventType;
LOADREDIRECT: EventType;
LOADSTART: EventType;
LOADSTOP: EventType;
RESPONSIVE: EventType;
SIZECHANGED: EventType;
UNRESPONSIVE: EventType;
VISIBILITYCHANGE: EventType;
STORAGE: EventType;
DOMSUBTREEMODIFIED: EventType;
DOMNODEINSERTED: EventType;
DOMNODEREMOVED: EventType;
DOMNODEREMOVEDFROMDOCUMENT: EventType;
DOMNODEINSERTEDINTODOCUMENT: EventType;
DOMATTRMODIFIED: EventType;
DOMCHARACTERDATAMODIFIED: EventType;
};
let KeyCodes: {
A: number,
ALT: number,
APOSTROPHE: number,
AT_SIGN: number,
B: number,
BACKSLASH: number,
BACKSPACE: number,
C: number,
CAPS_LOCK: number,
CLOSE_SQUARE_BRACKET: number,
COMMA: number,
CONTEXT_MENU: number,
CTRL: number,
D: number,
DASH: number,
DELETE: number,
DOWN: number,
E: number,
EIGHT: number,
END: number,
ENTER: number,
EQUALS: number,
ESC: number,
F: number,
F1: number,
F10: number,
F11: number,
F12: number,
F2: number,
F3: number,
F4: number,
F5: number,
F6: number,
F7: number,
F8: number,
F9: number,
FF_DASH: number,
FF_EQUALS: number,
FF_SEMICOLON: number,
FIRST_MEDIA_KEY: number,
FIVE: number,
FOUR: number,
G: number,
H: number,
HOME: number,
I: number,
INSERT: number,
J: number,
K: number,
L: number,
LAST_MEDIA_KEY: number,
LEFT: number,
M: number,
MAC_ENTER: number,
MAC_FF_META: number,
MAC_WK_CMD_LEFT: number,
MAC_WK_CMD_RIGHT: number,
META: number,
N: number,
NINE: number,
NUMLOCK: number,
NUM_CENTER: number,
NUM_DIVISION: number,
NUM_EIGHT: number,
NUM_FIVE: number,
NUM_FOUR: number,
NUM_MINUS: number,
NUM_MULTIPLY: number,
NUM_NINE: number,
NUM_ONE: number,
NUM_PERIOD: number,
NUM_PLUS: number,
NUM_SEVEN: number,
NUM_SIX: number,
NUM_THREE: number,
NUM_TWO: number,
NUM_ZERO: number,
O: number,
ONE: number,
OPEN_SQUARE_BRACKET: number,
P: number,
PAGE_DOWN: number,
PAGE_UP: number,
PAUSE: number,
PERIOD: number,
PHANTOM: number,
PLUS_SIGN: number,
PRINT_SCREEN: number,
Q: number,
QUESTION_MARK: number,
R: number,
RIGHT: number,
S: number,
SCROLL_LOCK: number,
SEMICOLON: number,
SEVEN: number,
SHIFT: number,
SINGLE_QUOTE: number,
SIX: number,
SLASH: number,
SPACE: number,
T: number,
TAB: number,
THREE: number,
TILDE: number,
TWO: number,
U: number,
UP: number,
V: number,
VK_NONAME: number,
W: number,
WIN_IME: number,
WIN_KEY: number,
WIN_KEY_FF_LINUX: number,
WIN_KEY_RIGHT: number,
X: number,
Y: number,
Z: number,
ZERO: number
}
class EventTarget extends Disposable {
}
class EventHandler<T> {
handleEvent(e: any): void;
listen(src: Element | Listenable, type: string, opt_fn?: any): EventHandler<T>;
}
/**
* Accepts a browser event object and creates a patched, cross browser event
* object.
* The content of this object will not be initialized if no event object is
* provided. If this is the case, init() needs to be invoked separately.
* @param {Event=} opt_e Browser event object.
* @param {EventTarget=} opt_currentTarget Current target for event.
*/
class BrowserEvent {
constructor(opt_e?: Event, opt_currentTarget?: EventTarget);
}
}
namespace userAgent {
/**
* Whether the user agent is running on a mobile device.
*
* TODO(nnaze): Consider deprecating MOBILE when labs.userAgent
* is promoted as the gecko/webkit logic is likely inaccurate.
*
* @type {boolean}
*/
var MOBILE: boolean;
/**
* Whether the user agent is running on Android.
* @type {boolean}
*/
var ANDROID: boolean;
/**
* Whether the user agent is running on an iPhone.
* @type {boolean}
*/
var IPHONE: boolean;
/**
* Whether the user agent is running on an iPad.
* @type {boolean}
*/
var IPAD: boolean;
}
namespace html {
class SafeHtml {
}
}
namespace positioning {
class ClientPosition {
constructor(x: number, y: number);
}
}
}
declare module Blockly {
interface Colours {
text: string;
workspace: string;
toolboxHover: string;
toolboxSelected: string;
toolboxText: string;
toolbox: string;
flyout: string;
scrollbar: string;
scrollbarHover: string;
textField: string;
insertionMarker: string;
insertionMarkerOpacity: number;
dragShadowOpacity: number;
stackGlow: string;
stackGlowSize: number;
stackGlowOpacity: number;
replacementGlow: string;
replacementGlowSize: number;
replacementGlowOpacity: number;
highlightGlow: string;
highlightGlowSize: number;
highlightGlowOpacity: number;
selectedGlow: string;
selectedGlowSize: number;
warningGlow: string;
warningGlowSize: number;
warningGlowOpacity: number;
colourPickerStroke: string;
// CSS colours: support RGBA
fieldShadow: string;
dropDownShadow: string;
numPadBackground: string;
numPadBorder: string;
numPadActiveBackground: string;
numPadText: string;
valueReportBackground: string;
valueReportBorder: string;
// Center on block transition
canvasTransitionLength: 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, Blockly.IDeletable {
/**
* 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}
* @implements {Blockly.IDeletable}
* @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 {boolean|undefined} */
startHat: 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;
/**
* The block's position in workspace units. (0, 0) is at the workspace's
* origin; scale does not change this value.
* @type {!Blockly.utils.Coordinate}
* @package pxt-blockly
*/
xy_: Blockly.utils.Coordinate;
/** @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.
* @param {boolean} ignoreShadows If true,the last connection on a non-shadow
* block will be returned. If false, this will follow shadows to find the
* last connection.
* @return {?Blockly.Connection} The last next connection on the stack, or null.
* @package
*/
lastConnectionInStack(ignoreShadows: boolean): 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 (if any) 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 (if any) that connects to the specified
* block.
*/
getInputWithBlock(block: Blockly.Block): Blockly.Input;
/**
* Return the input that contains the specified connection
* @param {!Blockly.Connection} conn A connection on this block.
* @return {Blockly.Input} The input that contains the specified connection.
*/
getInputWithConnection(conn: Blockly.Connection): 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 (if any) 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|Blockly.BlockSvg} newParent New parent block.
*/
setParent(newParent: Blockly.Block|Blockly.BlockSvg): 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.
* @param {boolean=} opt_ignoreShadows If set, don't include shadow blocks.
* @return {!Array<!Blockly.Block>} Flattened array of blocks.
*/
getDescendants(ordered: boolean, opt_ignoreShadows?: boolean): Blockly.Block[];
/**
* Get whether this block is deletable or not.
* @return {boolean} True if deletable.
*/
isDeletable(): boolean;
/**
* Get whether this block is in a workspace with the debugMode option set or not.
* @return {boolean} True if deletable.
*/
inDebugWorkspace(): 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;
/**
* Get whether we should persist this block as movable or not.
* @return {boolean} True if movable.
*/
isMovablePersisted(): 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.
* @param {boolean} insertionMarker True if an insertion marker.
*/
setInsertionMarker(insertionMarker: boolean): void;
/**
* Get whether this block is editable or not.
* @return {boolean} True if editable.
*/
isEditable(): boolean;
/**
* Get whether we should persist this block as editable.
* @return {boolean} True if editable.
*/
isEditablePersisted(): 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.
* @return {!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, 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.
*/
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 whether value statements have a start hat or not.
* @param {boolean} newBoolean True if statement should have a start hat.
*/
setStartHat(newBoolean: boolean): void;
/**
* Set whether value statements have a start hat or not.
* @return {boolean} True if statement has a start hat.
*/
getStartHat(): boolean;
/**
* Set this block's output shape.
* e.g., null, OUTPUT_SHAPE_HEXAGONAL, OUTPUT_SHAPE_ROUND, OUTPUT_SHAPE_SQUARE.
* @param {?number} outputShape Value representing output shape
* (see constants.js).
*/
setOutputShape(outputShape: number): void;
/**
* Get this block's output shape.
* @return {?number} Value representing output shape (see constants.js).
*/
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.
* @param {boolean=} opt_firstRow pxt-blockly Only include text from first row
* @return {string} Text of block.
*/
toString(opt_maxLength?: number, opt_emptyToken?: string, opt_firstRow?: boolean): 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 One of Blockly.inputTypes.