blockly
Version:
Blockly is a library for building visual programming editors.
1,318 lines • 979 kB
TypeScript
declare module "utils/idgenerator" {
namespace internal {
/**
* Generate a random unique ID. This should be globally unique.
* 87 characters ^ 20 length > 128 bits (better than a UUID).
* @return {string} A globally unique ID string.
*/
function genUid(): string;
}
/**
* Generate the next unique element IDs.
* IDs are compatible with the HTML4 id attribute restrictions:
* Use only ASCII letters, digits, '_', '-' and '.'
*
* For UUIDs use genUid (below) instead; this ID generator should
* primarily be used for IDs that end up in the DOM.
*
* @return {string} The next unique identifier.
* @alias Blockly.utils.idGenerator.getNextUniqueId
*/
export function getNextUniqueId(): string;
/**
* Generate a random unique ID.
* @see internal.genUid
* @return {string} A globally unique ID string.
* @alias Blockly.utils.idGenerator.genUid
*/
export function genUid(): string;
export { internal as TEST_ONLY };
}
declare module "utils/object" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Utility methods for objects.
*/
/**
* Utility methods for objects.
* @namespace Blockly.utils.object
*/
/**
* Inherit the prototype methods from one constructor into another.
* @param {!Function} childCtor Child class.
* @param {!Function} parentCtor Parent class.
* @suppress {strictMissingProperties} superClass_ is not defined on Function.
* @alias Blockly.utils.object.inherits
*/
export function inherits(childCtor: Function, parentCtor: Function): void;
/**
* Copies all the members of a source object to a target object.
* @param {!Object} target Target.
* @param {!Object} source Source.
* @alias Blockly.utils.object.mixin
*/
export function mixin(target: any, source: any): void;
/**
* Complete a deep merge of all members of a source object with a target object.
* @param {!Object} target Target.
* @param {!Object} source Source.
* @return {!Object} The resulting object.
* @alias Blockly.utils.object.deepMerge
*/
export function deepMerge(target: any, source: any): any;
/**
* Returns an array of a given object's own enumerable property values.
* @param {!Object} obj Object containing values.
* @return {!Array} Array of values.
* @alias Blockly.utils.object.values
*/
export function values(obj: any): any[];
}
declare module "connection_type" {
/**
* *
*/
export type ConnectionType = number;
export namespace ConnectionType {
const INPUT_VALUE: number;
const OUTPUT_VALUE: number;
const NEXT_STATEMENT: number;
const PREVIOUS_STATEMENT: number;
}
}
declare module "utils/global" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Provides a reference to the global object.
*/
/**
* Provides a reference to the global object.
* @namespace Blockly.utils.global
*/
/**
* Reference to the global object.
*
* More info on this implementation here:
* https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI
*/
export const globalThis: any;
}
declare module "utils/useragent" {
/**
* The raw useragent string.
* @type {string}
*/
let rawUserAgent: string;
/** @type {boolean} */
let isIe: boolean;
/** @type {boolean} */
let isEdge: boolean;
/** @type {boolean} */
let isJavaFx: boolean;
/** @type {boolean} */
let isChrome: boolean;
/** @type {boolean} */
let isWebKit: boolean;
/** @type {boolean} */
let isGecko: boolean;
/** @type {boolean} */
let isAndroid: boolean;
/** @type {boolean} */
let isIPad: boolean;
/** @type {boolean} */
let isIPod: boolean;
/** @type {boolean} */
let isIPhone: boolean;
/** @type {boolean} */
let isMac: boolean;
/** @type {boolean} */
let isTablet: boolean;
/** @type {boolean} */
let isMobile: boolean;
export { rawUserAgent as raw, isIe as IE, isEdge as EDGE, isJavaFx as JavaFx, isChrome as CHROME, isWebKit as WEBKIT, isGecko as GECKO, isAndroid as ANDROID, isIPad as IPAD, isIPod as IPOD, isIPhone as IPHONE, isMac as MAC, isTablet as TABLET, isMobile as MOBILE };
}
declare module "utils/svg" {
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Defines the Svg class. Its constants enumerate
* all SVG tag names used by Blockly.
*/
/**
* Defines the Svg class. Its constants enumerate
* all SVG tag names used by Blockly.
* @class
*/
/**
* A name with the type of the SVG element stored in the generic.
* @param {string} tagName The SVG element tag name.
* @constructor
* @template T
* @private
* @alias Blockly.utils.Svg
*/
export class Svg<T> {
constructor(tagName: any);
/**
* @type {string}
* @private
*/
private tagName_;
/**
* Returns the SVG element tag name.
* @return {string} The name.
* @override
*/
toString(): string;
}
export namespace Svg {
const ANIMATE: Svg<SVGAnimateElement>;
const CIRCLE: Svg<SVGCircleElement>;
const CLIPPATH: Svg<SVGClipPathElement>;
const DEFS: Svg<SVGDefsElement>;
const FECOMPOSITE: Svg<SVGFECompositeElement>;
const FECOMPONENTTRANSFER: Svg<SVGFEComponentTransferElement>;
const FEFLOOD: Svg<SVGFEFloodElement>;
const FEFUNCA: Svg<SVGFEFuncAElement>;
const FEGAUSSIANBLUR: Svg<SVGFEGaussianBlurElement>;
const FEPOINTLIGHT: Svg<SVGFEPointLightElement>;
const FESPECULARLIGHTING: Svg<SVGFESpecularLightingElement>;
const FILTER: Svg<SVGFilterElement>;
const FOREIGNOBJECT: Svg<SVGForeignObjectElement>;
const G: Svg<SVGGElement>;
const IMAGE: Svg<SVGImageElement>;
const LINE: Svg<SVGLineElement>;
const PATH: Svg<SVGPathElement>;
const PATTERN: Svg<SVGPatternElement>;
const POLYGON: Svg<SVGPolygonElement>;
const RECT: Svg<SVGRectElement>;
const SVG: Svg<SVGSVGElement>;
const TEXT: Svg<SVGTextElement>;
const TSPAN: Svg<SVGTSpanElement>;
}
}
declare module "utils/dom" {
/**
* Required name space for SVG elements.
* @const
* @alias Blockly.utils.dom.SVG_NS
*/
export const SVG_NS: "http://www.w3.org/2000/svg";
/**
* Required name space for HTML elements.
* @const
* @alias Blockly.utils.dom.HTML_NS
*/
export const HTML_NS: "http://www.w3.org/1999/xhtml";
/**
* Required name space for XLINK elements.
* @const
* @alias Blockly.utils.dom.XLINK_NS
*/
export const XLINK_NS: "http://www.w3.org/1999/xlink";
/**
* *
*/
export type NodeType = number;
export namespace NodeType {
const ELEMENT_NODE: number;
const TEXT_NODE: number;
const COMMENT_NODE: number;
const DOCUMENT_POSITION_CONTAINED_BY: number;
}
/**
* Helper method for creating SVG elements.
* @param {string|Svg<T>} name Element's tag name.
* @param {!Object} attrs Dictionary of attribute names and values.
* @param {Element=} opt_parent Optional parent on which to append the element.
* @return {T} Newly created SVG element. The return type is {!SVGElement} if
* name is a string or a more specific type if it a member of Svg.
* @template T
* @alias Blockly.utils.dom.createSvgElement
*/
export function createSvgElement<T>(name: string | Svg<T>, attrs: any, opt_parent?: Element | undefined): T;
/**
* Add a CSS class to a element.
* Similar to Closure's goog.dom.classes.add, except it handles SVG elements.
* @param {!Element} element DOM element to add class to.
* @param {string} className Name of class to add.
* @return {boolean} True if class was added, false if already present.
* @alias Blockly.utils.dom.addClass
*/
export function addClass(element: Element, className: string): boolean;
/**
* Removes multiple calsses from an element.
* @param {!Element} element DOM element to remove classes from.
* @param {string} classNames A string of one or multiple class names for an
* element.
* @alias Blockly.utils.dom.removeClasses
*/
export function removeClasses(element: Element, classNames: string): void;
/**
* Remove a CSS class from a element.
* Similar to Closure's goog.dom.classes.remove, except it handles SVG elements.
* @param {!Element} element DOM element to remove class from.
* @param {string} className Name of class to remove.
* @return {boolean} True if class was removed, false if never present.
* @alias Blockly.utils.dom.removeClass
*/
export function removeClass(element: Element, className: string): boolean;
/**
* Checks if an element has the specified CSS class.
* Similar to Closure's goog.dom.classes.has, except it handles SVG elements.
* @param {!Element} element DOM element to check.
* @param {string} className Name of class to check.
* @return {boolean} True if class exists, false otherwise.
* @alias Blockly.utils.dom.hasClass
*/
export function hasClass(element: Element, className: string): boolean;
/**
* Removes a node from its parent. No-op if not attached to a parent.
* @param {?Node} node The node to remove.
* @return {?Node} The node removed if removed; else, null.
* @alias Blockly.utils.dom.removeNode
*/
export function removeNode(node: Node | null): Node | null;
/**
* Insert a node after a reference node.
* Contrast with node.insertBefore function.
* @param {!Element} newNode New element to insert.
* @param {!Element} refNode Existing element to precede new node.
* @alias Blockly.utils.dom.insertAfter
*/
export function insertAfter(newNode: Element, refNode: Element): void;
/**
* Whether a node contains another node.
* @param {!Node} parent The node that should contain the other node.
* @param {!Node} descendant The node to test presence of.
* @return {boolean} Whether the parent node contains the descendant node.
* @alias Blockly.utils.dom.containsNode
*/
export function containsNode(parent: Node, descendant: Node): boolean;
/**
* Sets the CSS transform property on an element. This function sets the
* non-vendor-prefixed and vendor-prefixed versions for backwards compatibility
* with older browsers. See https://caniuse.com/#feat=transforms2d
* @param {!Element} element Element to which the CSS transform will be applied.
* @param {string} transform The value of the CSS `transform` property.
* @alias Blockly.utils.dom.setCssTransform
*/
export function setCssTransform(element: Element, transform: string): void;
/**
* Start caching text widths. Every call to this function MUST also call
* stopTextWidthCache. Caches must not survive between execution threads.
* @alias Blockly.utils.dom.startTextWidthCache
*/
export function startTextWidthCache(): void;
/**
* Stop caching field widths. Unless caching was already on when the
* corresponding call to startTextWidthCache was made.
* @alias Blockly.utils.dom.stopTextWidthCache
*/
export function stopTextWidthCache(): void;
/**
* Gets the width of a text element, caching it in the process.
* @param {!Element} textElement An SVG 'text' element.
* @return {number} Width of element.
* @alias Blockly.utils.dom.getTextWidth
*/
export function getTextWidth(textElement: Element): number;
/**
* Gets the width of a text element using a faster method than `getTextWidth`.
* This method requires that we know the text element's font family and size in
* advance. Similar to `getTextWidth`, we cache the width we compute.
* @param {!Element} textElement An SVG 'text' element.
* @param {number} fontSize The font size to use.
* @param {string} fontWeight The font weight to use.
* @param {string} fontFamily The font family to use.
* @return {number} Width of element.
* @alias Blockly.utils.dom.getFastTextWidth
*/
export function getFastTextWidth(textElement: Element, fontSize: number, fontWeight: string, fontFamily: string): number;
/**
* Gets the width of a text element using a faster method than `getTextWidth`.
* This method requires that we know the text element's font family and size in
* advance. Similar to `getTextWidth`, we cache the width we compute.
* This method is similar to ``getFastTextWidth`` but expects the font size
* parameter to be a string.
* @param {!Element} textElement An SVG 'text' element.
* @param {string} fontSize The font size to use.
* @param {string} fontWeight The font weight to use.
* @param {string} fontFamily The font family to use.
* @return {number} Width of element.
* @alias Blockly.utils.dom.getFastTextWidthWithSizeString
*/
export function getFastTextWidthWithSizeString(textElement: Element, fontSize: string, fontWeight: string, fontFamily: string): number;
/**
* Measure a font's metrics. The height and baseline values.
* @param {string} text Text to measure the font dimensions of.
* @param {string} fontSize The font size to use.
* @param {string} fontWeight The font weight to use.
* @param {string} fontFamily The font family to use.
* @return {{height: number, baseline: number}} Font measurements.
* @alias Blockly.utils.dom.measureFontMetrics
*/
export function measureFontMetrics(text: string, fontSize: string, fontWeight: string, fontFamily: string): {
height: number;
baseline: number;
};
import { Svg } from "utils/svg";
}
declare module "utils/xml" {
/**
* Namespace for Blockly's XML.
* @alias Blockly.utils.xml.NAME_SPACE
*/
export const NAME_SPACE: "https://developers.google.com/blockly/xml";
/**
* Get the document object to use for XML serialization.
* @return {!Document} The document object.
* @alias Blockly.utils.xml.getDocument
*/
export function getDocument(): Document;
/**
* Get the document object to use for XML serialization.
* @param {!Document} document The document object to use.
* @alias Blockly.utils.xml.setDocument
*/
export function setDocument(document: Document): void;
/**
* Create DOM element for XML.
* @param {string} tagName Name of DOM element.
* @return {!Element} New DOM element.
* @alias Blockly.utils.xml.createElement
*/
export function createElement(tagName: string): Element;
/**
* Create text element for XML.
* @param {string} text Text content.
* @return {!Text} New DOM text node.
* @alias Blockly.utils.xml.createTextNode
*/
export function createTextNode(text: string): Text;
/**
* Converts an XML string into a DOM tree.
* @param {string} text XML string.
* @return {Document} The DOM document.
* @throws if XML doesn't parse.
* @alias Blockly.utils.xml.textToDomDocument
*/
export function textToDomDocument(text: string): Document;
/**
* Converts a DOM structure into plain text.
* Currently the text format is fairly ugly: all one line with no whitespace.
* @param {!Node} dom A tree of XML nodes.
* @return {string} Text representation.
* @alias Blockly.utils.xml.domToText
*/
export function domToText(dom: Node): string;
}
declare module "utils/string" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Utility methods for string manipulation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
*/
/**
* Utility methods for string manipulation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @namespace Blockly.utils.string
*/
/**
* Fast prefix-checker.
* Copied from Closure's goog.string.startsWith.
* @param {string} str The string to check.
* @param {string} prefix A string to look for at the start of `str`.
* @return {boolean} True if `str` begins with `prefix`.
* @alias Blockly.utils.string.startsWith
*/
export function startsWith(str: string, prefix: string): boolean;
/**
* Given an array of strings, return the length of the shortest one.
* @param {!Array<string>} array Array of strings.
* @return {number} Length of shortest string.
* @alias Blockly.utils.string.shortestStringLength
*/
export function shortestStringLength(array: Array<string>): number;
/**
* Given an array of strings, return the length of the common prefix.
* Words may not be split. Any space after a word is included in the length.
* @param {!Array<string>} array Array of strings.
* @param {number=} opt_shortest Length of shortest string.
* @return {number} Length of common prefix.
* @alias Blockly.utils.string.commonWordPrefix
*/
export function commonWordPrefix(array: Array<string>, opt_shortest?: number | undefined): number;
/**
* Given an array of strings, return the length of the common suffix.
* Words may not be split. Any space after a word is included in the length.
* @param {!Array<string>} array Array of strings.
* @param {number=} opt_shortest Length of shortest string.
* @return {number} Length of common suffix.
* @alias Blockly.utils.string.commonWordSuffix
*/
export function commonWordSuffix(array: Array<string>, opt_shortest?: number | undefined): number;
/**
* Wrap text to the specified width.
* @param {string} text Text to wrap.
* @param {number} limit Width to wrap each line.
* @return {string} Wrapped text.
* @alias Blockly.utils.string.wrap
*/
export function wrap(text: string, limit: number): string;
/**
* Is the given string a number (includes negative and decimals).
* @param {string} str Input string.
* @return {boolean} True if number, false otherwise.
* @alias Blockly.utils.string.isNumber
*/
export function isNumber(str: string): boolean;
}
declare module "internal_constants" {
/**
* The multiplier for scroll wheel deltas using the line delta mode.
* @type {number}
* @alias Blockly.internalConstants.LINE_MODE_MULTIPLIER
*/
export const LINE_MODE_MULTIPLIER: number;
/**
* The multiplier for scroll wheel deltas using the page delta mode.
* @type {number}
* @alias Blockly.internalConstants.PAGE_MODE_MULTIPLIER
*/
export const PAGE_MODE_MULTIPLIER: number;
/**
* Number of pixels the mouse must move before a drag starts.
* @alias Blockly.internalConstants.DRAG_RADIUS
*/
export const DRAG_RADIUS: 5;
/**
* Number of pixels the mouse must move before a drag/scroll starts from the
* flyout. Because the drag-intention is determined when this is reached, it is
* larger than DRAG_RADIUS so that the drag-direction is clearer.
* @alias Blockly.internalConstants.FLYOUT_DRAG_RADIUS
*/
export const FLYOUT_DRAG_RADIUS: 10;
/**
* Maximum misalignment between connections for them to snap together.
* @alias Blockly.internalConstants.SNAP_RADIUS
*/
export const SNAP_RADIUS: 28;
/**
* Maximum misalignment between connections for them to snap together,
* when a connection is already highlighted.
* @alias Blockly.internalConstants.CONNECTING_SNAP_RADIUS
*/
export const CONNECTING_SNAP_RADIUS: 28;
/**
* How much to prefer staying connected to the current connection over moving to
* a new connection. The current previewed connection is considered to be this
* much closer to the matching connection on the block than it actually is.
* @alias Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE
*/
export const CURRENT_CONNECTION_PREFERENCE: 8;
/**
* Delay in ms between trigger and bumping unconnected block out of alignment.
* @alias Blockly.internalConstants.BUMP_DELAY
*/
export const BUMP_DELAY: 250;
/**
* Maximum randomness in workspace units for bumping a block.
* @alias Blockly.internalConstants.BUMP_RANDOMNESS
*/
export const BUMP_RANDOMNESS: 10;
/**
* Number of characters to truncate a collapsed block to.
* @alias Blockly.internalConstants.COLLAPSE_CHARS
*/
export const COLLAPSE_CHARS: 30;
/**
* Length in ms for a touch to become a long press.
* @alias Blockly.internalConstants.LONGPRESS
*/
export const LONGPRESS: 750;
/**
* Prevent a sound from playing if another sound preceded it within this many
* milliseconds.
* @alias Blockly.internalConstants.SOUND_LIMIT
*/
export const SOUND_LIMIT: 100;
/**
* When dragging a block out of a stack, split the stack in two (true), or drag
* out the block healing the stack (false).
* @alias Blockly.internalConstants.DRAG_STACK
*/
export const DRAG_STACK: true;
/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.internalConstants.HSV_SATURATION
*/
export const HSV_SATURATION: 0.45;
/**
* The intensity of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @alias Blockly.internalConstants.HSV_VALUE
*/
export const HSV_VALUE: 0.65;
export namespace SPRITE {
const width: number;
const height: number;
const url: string;
}
/**
* ENUM for no drag operation.
* @const
* @alias Blockly.internalConstants.DRAG_NONE
*/
export const DRAG_NONE: 0;
/**
* ENUM for inside the sticky DRAG_RADIUS.
* @const
* @alias Blockly.internalConstants.DRAG_STICKY
*/
export const DRAG_STICKY: 1;
/**
* ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
* clicks and drags.
* @const
* @alias Blockly.internalConstants.DRAG_BEGIN
*/
export const DRAG_BEGIN: 1;
/**
* ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
* @const
* @alias Blockly.internalConstants.DRAG_FREE
*/
export const DRAG_FREE: 2;
/**
* Lookup table for determining the opposite type of a connection.
* @const
* @alias Blockly.internalConstants.OPPOSITE_TYPE
*/
export const OPPOSITE_TYPE: any[];
/**
* String for use in the "custom" attribute of a category in toolbox XML.
* This string indicates that the category should be dynamically populated with
* variable blocks.
* @const {string}
* @alias Blockly.internalConstants.VARIABLE_CATEGORY_NAME
*/
export const VARIABLE_CATEGORY_NAME: "VARIABLE";
/**
* String for use in the "custom" attribute of a category in toolbox XML.
* This string indicates that the category should be dynamically populated with
* variable blocks.
* @const {string}
* @alias Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME
*/
export const VARIABLE_DYNAMIC_CATEGORY_NAME: "VARIABLE_DYNAMIC";
/**
* String for use in the "custom" attribute of a category in toolbox XML.
* This string indicates that the category should be dynamically populated with
* procedure blocks.
* @const {string}
* @alias Blockly.internalConstants.PROCEDURE_CATEGORY_NAME
*/
export const PROCEDURE_CATEGORY_NAME: "PROCEDURE";
/**
* String for use in the dropdown created in field_variable.
* This string indicates that this option in the dropdown is 'Rename
* variable...' and if selected, should trigger the prompt to rename a variable.
* @const {string}
* @alias Blockly.internalConstants.RENAME_VARIABLE_ID
*/
export const RENAME_VARIABLE_ID: "RENAME_VARIABLE_ID";
/**
* String for use in the dropdown created in field_variable.
* This string indicates that this option in the dropdown is 'Delete the "%1"
* variable' and if selected, should trigger the prompt to delete a variable.
* @const {string}
* @alias Blockly.internalConstants.DELETE_VARIABLE_ID
*/
export const DELETE_VARIABLE_ID: "DELETE_VARIABLE_ID";
}
declare module "msg" {
export {};
}
declare module "blocks" {
/**
* @license
* Copyright 2013 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview A mapping of block type names to block prototype objects.
*/
/**
* A mapping of block type names to block prototype objects.
* @namespace Blockly.blocks
*/
/**
* A mapping of block type names to block prototype objects.
* @type {!Object<string,!Object>}
* @alias Blockly.blocks.Blocks
*/
export const Blocks: {
[x: string]: any;
};
}
declare module "interfaces/i_deletable" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an object that is deletable.
*/
/**
* The interface for an object that is deletable.
* @namespace Blockly.IDeletable
*/
/**
* The interface for an object that can be deleted.
* @interface
* @alias Blockly.IDeletable
*/
export class IDeletable {
}
}
declare module "interfaces/i_movable" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an object that is movable.
*/
/**
* The interface for an object that is movable.
* @namespace Blockly.IMovable
*/
/**
* The interface for an object that is movable.
* @interface
* @alias Blockly.IMovable
*/
export class IMovable {
}
}
declare module "interfaces/i_selectable" {
/**
* The interface for an object that is selectable.
* @extends {IDeletable}
* @extends {IMovable}
* @interface
* @alias Blockly.ISelectable
*/
export class ISelectable {
/**
* @type {string}
*/
id: string;
}
}
declare module "dialog" {
/**
* Wrapper to window.alert() that app developers may override via setAlert to
* provide alternatives to the modal browser window.
* @param {string} message The message to display to the user.
* @param {function()=} opt_callback The callback when the alert is dismissed.
* @alias Blockly.dialog.alert
*/
export function alert(message: string, opt_callback?: (() => any) | undefined): void;
/**
* Sets the function to be run when Blockly.dialog.alert() is called.
* @param {!function(string, function()=)} alertFunction The function to be run.
* @see Blockly.dialog.alert
* @alias Blockly.dialog.setAlert
*/
export function setAlert(alertFunction: (arg0: string, arg1: (() => any) | undefined) => any): void;
/**
* Wrapper to window.confirm() that app developers may override via setConfirm
* to provide alternatives to the modal browser window.
* @param {string} message The message to display to the user.
* @param {!function(boolean)} callback The callback for handling user response.
* @alias Blockly.dialog.confirm
*/
export function confirm(message: string, callback: (arg0: boolean) => any): void;
/**
* Sets the function to be run when Blockly.dialog.confirm() is called.
* @param {!function(string, !function(boolean))} confirmFunction The function
* to be run.
* @see Blockly.dialog.confirm
* @alias Blockly.dialog.setConfirm
*/
export function setConfirm(confirmFunction: (arg0: string, arg1: (arg0: boolean) => any) => any): void;
/**
* Wrapper to window.prompt() that app developers may override via setPrompt to
* provide alternatives to the modal browser window. Built-in browser prompts
* are often used for better text input experience on mobile device. We strongly
* recommend testing mobile when overriding this.
* @param {string} message The message to display to the user.
* @param {string} defaultValue The value to initialize the prompt with.
* @param {!function(?string)} callback The callback for handling user response.
* @alias Blockly.dialog.prompt
*/
export function prompt(message: string, defaultValue: string, callback: (arg0: string | null) => any): void;
/**
* Sets the function to be run when Blockly.dialog.prompt() is called.
* @param {!function(string, string, !function(?string))} promptFunction The
* function to be run.
* @see Blockly.dialog.prompt
* @alias Blockly.dialog.setPrompt
*/
export function setPrompt(promptFunction: (arg0: string, arg1: string, arg2: (arg0: string | null) => any) => any): void;
}
declare module "utils/array" {
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Utility methods related to arrays.
*/
/**
* @namespace Blockly.utils.array
*/
/**
* Removes the first occurrence of a particular value from an array.
* @param {!Array} arr Array from which to remove value.
* @param {*} value Value to remove.
* @return {boolean} True if an element was removed.
* @alias Blockly.array.removeElem
* @package
*/
export function removeElem(arr: any[], value: any): boolean;
}
declare module "utils/math" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Utility methods for math.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
*/
/**
* Utility methods for math.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @namespace Blockly.utils.math
*/
/**
* Converts degrees to radians.
* Copied from Closure's goog.math.toRadians.
* @param {number} angleDegrees Angle in degrees.
* @return {number} Angle in radians.
* @alias Blockly.utils.math.toRadians
*/
export function toRadians(angleDegrees: number): number;
/**
* Converts radians to degrees.
* Copied from Closure's goog.math.toDegrees.
* @param {number} angleRadians Angle in radians.
* @return {number} Angle in degrees.
* @alias Blockly.utils.math.toDegrees
*/
export function toDegrees(angleRadians: number): number;
/**
* Clamp the provided number between the lower bound and the upper bound.
* @param {number} lowerBound The desired lower bound.
* @param {number} number The number to clamp.
* @param {number} upperBound The desired upper bound.
* @return {number} The clamped number.
* @alias Blockly.utils.math.clamp
*/
export function clamp(lowerBound: number, number: number, upperBound: number): number;
}
declare module "serialization/priorities" {
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The top level namespace for priorities of plugin serializers.
* Includes constants for the priorities of different plugin
* serializers. Higher priorities are deserialized first.
*/
/**
* The top level namespace for priorities of plugin serializers.
* Includes constants for the priorities of different plugin serializers. Higher
* priorities are deserialized first.
* @namespace Blockly.serialization.priorities
*/
/**
* The priority for deserializing variables.
* @type {number}
* @const
* @alias Blockly.serialization.priorities.VARIABLES
*/
export const VARIABLES: number;
/**
* The priority for deserializing blocks.
* @type {number}
* @const
* @alias Blockly.serialization.priorities.BLOCKS
*/
export const BLOCKS: number;
}
declare module "interfaces/i_serializer" {
/**
* Serializes and deserializes a plugin or system.
* @interface
* @alias Blockly.serialization.ISerializer.ISerializer
*/
export class ISerializer {
/**
* A priority value used to determine the order of deserializing state.
* More positive priorities are deserialized before less positive
* priorities. Eg if you have priorities (0, -10, 10, 100) the order of
* deserialiation will be (100, 10, 0, -10).
* If two serializers have the same priority, they are deserialized in an
* arbitrary order relative to each other.
* @type {number}
*/
priority: number;
/**
* Saves the state of the plugin or system.
* @param {!Workspace} workspace The workspace the system to serialize is
* associated with.
* @return {?} A JS object containing the system's state, or null if
* there is no state to record.
*/
save(workspace: Workspace): unknown;
/**
* Loads the state of the plugin or system.
* @param {?} state The state of the system to deserialize. This will always
* be non-null.
* @param {!Workspace} workspace The workspace the system to deserialize is
* associated with.
*/
load(state: unknown, workspace: Workspace): void;
/**
* Clears the state of the plugin or system.
* @param {!Workspace} workspace The workspace the system to clear the state
* of is associated with.
*/
clear(workspace: Workspace): void;
}
import { Workspace } from "workspace";
}
declare module "serialization/registry" {
/**
* Registers the given serializer so that it can be used for serialization and
* deserialization.
* @param {string} name The name of the serializer to register.
* @param {ISerializer} serializer The serializer to register.
* @alias Blockly.serialization.registry.register
*/
export function register(name: string, serializer: ISerializer): void;
/**
* Unregisters the serializer associated with the given name.
* @param {string} name The name of the serializer to unregister.
* @alias Blockly.serialization.registry.unregister
*/
export function unregister(name: string): void;
import { ISerializer } from "interfaces/i_serializer";
}
declare module "serialization/exceptions" {
/**
* @alias Blockly.serialization.exceptions.DeserializationError
*/
export class DeserializationError extends Error {
}
/**
* Represents an error where the serialized state is expected to provide a
* block type, but it is not provided.
* @alias Blockly.serialization.exceptions.MissingBlockType
*/
export class MissingBlockType extends DeserializationError {
/**
* @param {!State} state The state object which is missing the block type.
* @package
*/
constructor(state: any);
/**
* The state object containing the bad name.
* @type {!State}
*/
state: any;
}
/**
* Represents an error where deserialization encountered a block that did
* not have a connection that was defined in the serialized state.
* @alias Blockly.serialization.exceptions.MissingConnection
*/
export class MissingConnection extends DeserializationError {
/**
* @param {string} connection The name of the connection that is missing. E.g.
* 'IF0', or 'next'.
* @param {!Block} block The block missing the connection.
* @param {!State} state The state object containing the bad connection.
* @package
*/
constructor(connection: string, block: Block, state: any);
/**
* The block missing the connection.
* @type {!Block}
*/
block: Block;
/**
* The state object containing the bad name.
* @type {!State}
*/
state: any;
}
/**
* Represents an error where deserialization tried to connect two connections
* that were not compatible.
* @alias Blockly.serialization.exceptions.BadConnectionCheck
*/
export class BadConnectionCheck extends DeserializationError {
/**
* @param {string} reason The reason the connections were not compatible.
* @param {string} childConnection The name of the incompatible child
* connection. E.g. 'output' or 'previous'.
* @param {!Block} childBlock The child block that could not connect
* to its parent.
* @param {!State} childState The state object representing the child block.
* @package
*/
constructor(reason: string, childConnection: string, childBlock: Block, childState: any);
/**
* The block that could not connect to its parent.
* @type {!Block}
*/
childBlock: Block;
/**
* The state object representing the block that could not connect to its
* parent.
* @type {!State}
*/
childState: any;
}
/**
* Represents an error where deserialization encountered a real block as it
* was deserializing children of a shadow.
* This is an error because it is an invariant of Blockly that shadow blocks
* do not have real children.
* @alias Blockly.serialization.exceptions.RealChildOfShadow
*/
export class RealChildOfShadow extends DeserializationError {
/**
* @param {!State} state The state object representing the real block.
* @package
*/
constructor(state: any);
/**
* The state object representing the real block.
* @type {!State}
*/
state: any;
}
import { Block } from "block";
}
declare module "utils/size" {
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Utility methods for size calculation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
*/
/**
* Utility methods for size calculation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @class
*/
/**
* Class for representing sizes consisting of a width and height.
* @param {number} width Width.
* @param {number} height Height.
* @struct
* @constructor
* @alias Blockly.utils.Size
*/
export class Size {
/**
* Compares sizes for equality.
* @param {?Size} a A Size.
* @param {?Size} b A Size.
* @return {boolean} True iff the sizes have equal widths and equal
* heights, or if both are null.
*/
static equals(a: Size | null, b: Size | null): boolean;
constructor(width: any, height: any);
/**
* Width
* @type {number}
*/
width: number;
/**
* Height
* @type {number}
*/
height: number;
}
}
declare module "input_types" {
/**
* *
*/
export type inputTypes = number;
export namespace inputTypes {
const VALUE: number;
const STATEMENT: number;
const DUMMY: number;
}
}
declare module "serialization/blocks" {
/**
* Represents the state of a connection.
*/
export type ConnectionState = {
shadow: (any | undefined);
block: (any | undefined);
};
/**
* Represents the state of a connection.
* @typedef {{
* shadow: (!State|undefined),
* block: (!State|undefined)
* }}
* @alias Blockly.serialization.blocks.ConnectionState
*/
export let ConnectionState: any;
/**
* Represents the state of a given block.
* @typedef {{
* type: string,
* id: (string|undefined),
* x: (number|undefined),
* y: (number|undefined),
* collapsed: (boolean|undefined),
* enabled: (boolean|undefined),
* inline: (boolean|undefined),
* data: (string|undefined),
* extra-state: (*|undefined),
* icons: (!Object<string, *>|undefined),
* fields: (!Object<string, *>|undefined),
* inputs: (!Object<string, !ConnectionState>|undefined),
* next: (!ConnectionState|undefined)
* }}
* @alias Blockly.serialization.blocks.State
*/
export let State: any;
/**
* Returns the state of the given block as a plain JavaScript object.
* @param {!Block} block The block to serialize.
* @param {{addCoordinates: (boolean|undefined), addInputBlocks:
* (boolean|undefined), addNextBlocks: (boolean|undefined),
* doFullSerialization: (boolean|undefined)}=} param1
* addCoordinates: If true, the coordinates of the block are added to the
* serialized state. False by default.
* addinputBlocks: If true, children of the block which are connected to
* inputs will be serialized. True by default.
* addNextBlocks: If true, children of the block which are connected to the
* block's next connection (if it exists) will be serialized.
* True by default.
* doFullSerialization: If true, fields that normally just save a reference
* to some external state (eg variables) will instead serialize all of the
* info about that state. This supports deserializing the block into a
* workspace where that state doesn't yet exist. True by default.
* @return {?State} The serialized state of the block, or null if the block
* could not be serialied (eg it was an insertion marker).
* @alias Blockly.serialization.blocks.save
*/
export function save(block: Block, { addCoordinates, addInputBlocks, addNextBlocks, doFullSerialization, }?: {
addCoordinates: (boolean | undefined);
addInputBlocks: (boolean | undefined);
addNextBlocks: (boolean | undefined);
doFullSerialization: (boolean | undefined);
} | undefined): any | null;
/**
* Loads the block represented by the given state into the given workspace.
* @param {!State} state The state of a block to deserialize into the workspace.
* @param {!Workspace} workspace The workspace to add the block to.
* @param {{recordUndo: (boolean|undefined)}=} param1
* recordUndo: If true, events triggered by this function will be undo-able
* by the user. False by default.
* @return {!Block} The block that was just loaded.
* @alias Blockly.serialization.blocks.append
*/
export function append(state: any, workspace: Workspace, { recordUndo }?: {
recordUndo: (boolean | undefined);
} | undefined): Block;
/**
* Loads the block represented by the given state into the given workspace.
* This is defined internally so that the extra parameters don't clutter our
* external API.
* But it is exported so that other places within Blockly can call it directly
* with the extra parameters.
* @param {!State} state The state of a block to deserialize into the workspace.
* @param {!Workspace} workspace The workspace to add the block to.
* @param {{parentConnection: (!Connection|undefined), isShadow:
* (boolean|undefined), recordUndo: (boolean|undefined)}=} param1
* parentConnection: If provided, the system will attempt to connect the
* block to this connection after it is created. Undefined by default.
* isShadow: If true, the block will be set to a shadow block after it is
* created. False by default.
* recordUndo: If true, events triggered by this function will be undo-able
* by the user. False by default.
* @return {!Block} The block that was just appended.
* @alias Blockly.serialization.blocks.appendInternal
* @package
*/
export function appendInternal(state: any, workspace: Workspace, { parentConnection, isShadow, recordUndo, }?: {
parentConnection: (Connection | undefined);
isShadow: (boolean | undefined);
recordUndo: (boolean | undefined);
} | undefined): Block;
import { Block } from "block";
import { Workspace } from "workspace";
import { Connection } from "connection";
}
declare module "utils/deprecation" {
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Helper function for warning developers about deprecations.
* This method is not specific to Blockly.
*/
/**
* Helper function for warning developers about deprecations.
* This method is not specific to Blockly.
* @namespace Blockly.utils.deprecation
*/
/**
* Warn developers that a function or property is deprecated.
* @param {string} name The name of the function or property.
* @param {string} deprecationDate The date of deprecation.
* Prefer 'month yyyy' or 'quarter yyyy' format.
* @param {string} deletionDate The date of deletion, in the same format as the
* deprecation date.
* @param {string=} opt_use The name of a function or property to use instead,
* if any.
* @alias Blockly.utils.deprecation.warn
* @package
*/
export function warn(name: string, deprecationDate: string, deletionDate: string, opt_use?: string | undefined): void;
}
declare module "css" {
/**
* Add some CSS to the blob that will be injected later. Allows optional
* components such as fields and the toolbox to store separate CSS.
* @param {string|!Array<string>} cssContent Multiline CSS string or an array of
* single lines of CSS.
* @alias Blockly.Css.register
*/
export function register(cssContent: string | Array<string>): void;
/**
* Inject the CSS into the DOM. This is preferable over using a regular CSS
* file since:
* a) It loads synchronously and doesn't force a redraw later.
* b) It speeds up loading by not blocking on a separate HTTP transfer.
* c) The CSS content may be made dynamic depending on init options.
* @param {boolean} hasCss If false, don't inject CSS
* (providing CSS becomes the document's responsibility).
* @param {string} pathToMedia Path from page to the Blockly media directory.
* @alias Blockly.Css.inject
*/
export function inject(hasCss: boolean, pathToMedia: string): void;
/**
* The CSS content for Blockly.
* @alias Blockly.Css.content
*/
export let content: string;
}
declare module "utils/aria" {
/**
* *
*/
export type Role = string;
export namespace Role {
const GRID: string;
const GRIDCELL: string;
const GROUP: string;
const LISTBOX: string;
const MENU: string;
const MENUITEM: string;
const MENUITEMCHECKBOX: string;
const OPTION: string;
const PRESENTATION: string;
const ROW: string;
const TREE: string;
const TREEITEM: string;
}
/**
* *
*/
export type State = string;
export namespace State {
const ACTIVEDESCENDANT: string;
const COLCOUNT: string;
const DISABLED: string;
const EXPANDED: string;
const INVALID: string;
const LABEL: string;
const LABELLEDBY: string;
const LEVEL: string;
const ORIENTATION: string;
const POSINSET: string;
const ROWCOUNT: string;
const SELECTED: string;
const SETSIZE: string;
const VALUEMAX: string;
const VALUEMIN: string;
}
/**
* Sets the role of an element.
*
* Similar to Closure's goog.a11y.aria
*
* @param {!Element} element DOM node to set role of.
* @param {!Role} roleName Role name.
* @alias Blockly.utils.aria.setRole
*/
export function setRole(element: Element, roleName: Role): void;
/**
* Sets the state or property of an element.
* Copied from Closure's goog.a11y.aria
* @param {!Element} element DOM node where we set state.
* @param {!State} stateName State attribute being set.
* Automatically adds prefix 'aria-' to the state name if the attribute is
* not an extra attribute.
* @param {string|boolean|number|!Array<string>} value Value
* for the state attribute.
* @alias Blockly.u