diff --git a/typings/blockly.d.ts b/typings/blockly.d.ts index 09563ccd0d5..291f472fdfc 100644 --- a/typings/blockly.d.ts +++ b/typings/blockly.d.ts @@ -1,4018 +1,25596 @@ -/** - * @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?: 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; - } - - 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 "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 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 "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 Block { - +declare module "connection_type" { /** - * @typedef {{ - * text:?string, - * pinned:boolean, - * size:Size - * }} + * * */ - interface CommentModel { - text: string; - pinned: boolean; - size: Size + 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" { /** - * The language-neutral ID given to the collapsed input. - * @const {string} + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var COLLAPSED_INPUT_NAME: any /*missing*/; - /** - * The language-neutral ID given to the collapsed field. - * @const {string} + * @fileoverview Provides a reference to the global object. */ - var COLLAPSED_FIELD_NAME: any /*missing*/; -} - - - - - -declare module BlockSvg { - /** - * Constant for identifying rows that are to be rendered inline. - * Don't collide with Blockly.inputTypes. - * @const + * Provides a reference to the global object. + * @namespace Blockly.utils.global */ - var INLINE: any /*missing*/; - /** - * ID to give the "collapsed warnings" warning. Allows us to remove the - * "collapsed warnings" warning without removing any warnings that belong to - * the block. - * @type {string} - * @const + * Reference to the global object. + * + * More info on this implementation here: + * https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI */ - var COLLAPSED_WARNING_ID: string; + export const globalThis: any; } - - -declare module exports { - +declare module "utils/useragent" { /** - * Blockly core version. - * This constant is overridden by the build script (npm run build) to the value - * of the version in package.json. This is done by the Closure Compiler in the - * buildCompressed gulp task. - * For local builds, you can pass --define='Blockly.VERSION=X.Y.Z' to the - * compiler to override this constant. - * @define {string} - * @alias Blockly.VERSION + * The raw useragent string. + * @type {string} */ - var VERSION: any /*missing*/; - + 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" { /** - * Copy a block or workspace comment onto the local clipboard. - * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. - * @package - * @alias Blockly.copy + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function copy(toCopy: ICopyable): void; - /** - * Paste a block or workspace comment on to the main workspace. - * @return {boolean} True if the paste was successful, false otherwise. - * @package - * @alias Blockly.paste + * @fileoverview Defines the Svg class. Its constants enumerate + * all SVG tag names used by Blockly. */ - function paste(): boolean; - /** - * Duplicate this block and its children, or a workspace comment. - * @param {!ICopyable} toDuplicate Block or Workspace Comment to be - * copied. - * @package - * @alias Blockly.duplicate + * Defines the Svg class. Its constants enumerate + * all SVG tag names used by Blockly. + * @class */ - function duplicate(toDuplicate: ICopyable): void; - /** - * Returns the main workspace. Returns the last used main workspace (based on - * focus). Try not to use this function, particularly if there are multiple - * Blockly instances on a page. - * @return {!Workspace} The main workspace. - * @alias Blockly.getMainWorkspace + * 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 */ - function getMainWorkspace(): Workspace; - + export class Svg { + 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; + const CIRCLE: Svg; + const CLIPPATH: Svg; + const DEFS: Svg; + const FECOMPOSITE: Svg; + const FECOMPONENTTRANSFER: Svg; + const FEFLOOD: Svg; + const FEFUNCA: Svg; + const FEGAUSSIANBLUR: Svg; + const FEPOINTLIGHT: Svg; + const FESPECULARLIGHTING: Svg; + const FILTER: Svg; + const FOREIGNOBJECT: Svg; + const G: Svg; + const IMAGE: Svg; + const LINE: Svg; + const PATH: Svg; + const PATTERN: Svg; + const POLYGON: Svg; + const RECT: Svg; + const SVG: Svg; + const TEXT: Svg; + const TSPAN: Svg; + } +} +declare module "utils/dom" { /** - * Set the parent container. This is the container element that the WidgetDiv, - * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` - * is called. - * This method is a NOP if called after the first ``Blockly.inject``. - * @param {!Element} container The container element. - * @alias Blockly.setParentContainer + * Required name space for SVG elements. + * @const + * @alias Blockly.utils.dom.SVG_NS */ - function setParentContainer(container: Element): void; - + export const SVG_NS: "http://www.w3.org/2000/svg"; /** - * @see colour.hueToHex - * @deprecated Use Blockly.utils.colour.hueToHex (September 2021). - * @alias Blockly.hueToHex + * Required name space for HTML elements. + * @const + * @alias Blockly.utils.dom.HTML_NS */ - var hueToHex: any /*missing*/; - + export const HTML_NS: "http://www.w3.org/1999/xhtml"; /** - * @see browserEvents.bind - * @alias Blockly.bindEvent_ + * Required name space for XLINK elements. + * @const + * @alias Blockly.utils.dom.XLINK_NS */ - var bindEvent_: any /*missing*/; - + export const XLINK_NS: "http://www.w3.org/1999/xlink"; /** - * @see browserEvents.unbind - * @alias Blockly.unbindEvent_ + * * */ - var unbindEvent_: any /*missing*/; - + 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; + } /** - * @see browserEvents.conditionalBind - * @alias Blockly.bindEventWithChecks_ + * Helper method for creating SVG elements. + * @param {string|Svg} 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 */ - var bindEventWithChecks_: any /*missing*/; - + export function createSvgElement(name: string | Svg, attrs: any, opt_parent?: Element | undefined): T; /** - * @see constants.ALIGN.LEFT - * @alias Blockly.ALIGN_LEFT + * 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 */ - var ALIGN_LEFT: any /*missing*/; - + export function addClass(element: Element, className: string): boolean; /** - * @see constants.ALIGN.CENTRE - * @alias Blockly.ALIGN_CENTRE + * 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 */ - var ALIGN_CENTRE: any /*missing*/; - + export function removeClasses(element: Element, classNames: string): void; /** - * @see constants.ALIGN.RIGHT - * @alias Blockly.ALIGN_RIGHT + * 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 */ - var ALIGN_RIGHT: any /*missing*/; - + export function removeClass(element: Element, className: string): boolean; /** - * @see common.svgResize + * 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 */ - var svgResize: any /*missing*/; - + export function hasClass(element: Element, className: string): boolean; /** - * @see ConnectionType.INPUT_VALUE - * @alias Blockly.INPUT_VALUE + * 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 */ - var INPUT_VALUE: any /*missing*/; - + export function removeNode(node: Node | null): Node | null; /** - * @see ConnectionType.OUTPUT_VALUE - * @alias Blockly.OUTPUT_VALUE + * 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 */ - var OUTPUT_VALUE: any /*missing*/; - + export function insertAfter(newNode: Element, refNode: Element): void; /** - * @see ConnectionType.NEXT_STATEMENT - * @alias Blockly.NEXT_STATEMENT + * 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 */ - var NEXT_STATEMENT: any /*missing*/; - + export function containsNode(parent: Node, descendant: Node): boolean; /** - * @see ConnectionType.PREVIOUS_STATEMENT - * @alias Blockly.PREVIOUS_STATEMENT + * 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 */ - var PREVIOUS_STATEMENT: any /*missing*/; - + export function setCssTransform(element: Element, transform: string): void; /** - * @see inputTypes.DUMMY_INPUT - * @alias Blockly.DUMMY_INPUT + * 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 */ - var DUMMY_INPUT: any /*missing*/; - + export function startTextWidthCache(): void; /** - * @see toolbox.Position.TOP - * @alias Blockly.TOOLBOX_AT_TOP + * Stop caching field widths. Unless caching was already on when the + * corresponding call to startTextWidthCache was made. + * @alias Blockly.utils.dom.stopTextWidthCache */ - var TOOLBOX_AT_TOP: any /*missing*/; - + export function stopTextWidthCache(): void; /** - * @see toolbox.Position.BOTTOM - * @alias Blockly.TOOLBOX_AT_BOTTOM + * 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 */ - var TOOLBOX_AT_BOTTOM: any /*missing*/; - + export function getTextWidth(textElement: Element): number; /** - * @see toolbox.Position.LEFT - * @alias Blockly.TOOLBOX_AT_LEFT + * 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 */ - var TOOLBOX_AT_LEFT: any /*missing*/; - + export function getFastTextWidth(textElement: Element, fontSize: number, fontWeight: string, fontFamily: string): number; /** - * @see toolbox.Position.RIGHT - * @alias Blockly.TOOLBOX_AT_RIGHT + * 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 */ - var TOOLBOX_AT_RIGHT: any /*missing*/; - - /** @deprecated Use Blockly.ConnectionType instead. */ - var connectionTypes: any /*missing*/; -} - - - - - -declare module Bubble { - + export function getFastTextWidthWithSizeString(textElement: Element, fontSize: string, fontWeight: string, fontFamily: string): number; /** - * Width of the border around the bubble. + * 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 */ - var BORDER_WIDTH: any /*missing*/; - + export function measureFontMetrics(text: string, fontSize: string, fontWeight: string, fontFamily: string): { + height: number; + baseline: number; + }; + import { Svg } from "utils/svg"; +} +declare module "utils/xml" { /** - * Determines the thickness of the base of the arrow in relation to the size - * of the bubble. Higher numbers result in thinner arrows. + * Namespace for Blockly's XML. + * @alias Blockly.utils.xml.NAME_SPACE */ - var ARROW_THICKNESS: any /*missing*/; - + export const NAME_SPACE: "https://developers.google.com/blockly/xml"; /** - * The number of degrees that the arrow bends counter-clockwise. + * Get the document object to use for XML serialization. + * @return {!Document} The document object. + * @alias Blockly.utils.xml.getDocument */ - var ARROW_ANGLE: any /*missing*/; - + export function getDocument(): Document; /** - * The sharpness of the arrow's bend. Higher numbers result in smoother arrows. + * Get the document object to use for XML serialization. + * @param {!Document} document The document object to use. + * @alias Blockly.utils.xml.setDocument */ - var ARROW_BEND: any /*missing*/; - + export function setDocument(document: Document): void; /** - * Distance between arrow point and anchor point. + * Create DOM element for XML. + * @param {string} tagName Name of DOM element. + * @return {!Element} New DOM element. + * @alias Blockly.utils.xml.createElement */ - var ANCHOR_RADIUS: any /*missing*/; - + export function createElement(tagName: string): Element; /** - * Create the text for a non editable bubble. - * @param {string} text The text to display. - * @return {!SVGTextElement} The top-level node of the text. - * @package + * Create text element for XML. + * @param {string} text Text content. + * @return {!Text} New DOM text node. + * @alias Blockly.utils.xml.createTextNode */ - function textToDom(text: string): SVGTextElement; - + export function createTextNode(text: string): Text; /** - * Creates a bubble that can not be edited. - * @param {!SVGTextElement} paragraphElement The text element for the non - * editable bubble. - * @param {!BlockSvg} block The block that the bubble is attached to. - * @param {!Coordinate} iconXY The coordinate of the icon. - * @return {!Bubble} The non editable bubble. - * @package + * 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 */ - function createNonEditableBubble(paragraphElement: SVGTextElement, block: BlockSvg, iconXY: Coordinate): Bubble; -} - - - - - - -declare module exports { - + export function textToDomDocument(text: string): Document; /** - * All of the connections on blocks that are currently being dragged. - * @type {!Array} + * 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 */ - var draggingConnections: Connection[]; + export function domToText(dom: Node): string; } - - -declare module ComponentManager { - - class Capability extends Capability__Class { } - /** Fake class which should be extended to avoid inheriting static properties */ - class Capability__Class { - - /** - * A name with the capability of the element stored in the generic. - * @param {string} name The name of the component capability. - * @constructor - * @template T - */ - constructor(name: string); - } - - +declare module "utils/string" { /** - * An object storing component information. - * @typedef {{ - * component: !IComponent, - * capabilities: ( - * !Array> - * ), - * weight: number - * }} + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - interface ComponentDatum { - component: IComponent; - capabilities: string|ComponentManager.Capability[]; - weight: number - } -} - -declare module ComponentManager.Capability { - - /** @type {!ComponentManager.Capability} */ - var POSITIONABLE: ComponentManager.Capability; - - /** @type {!ComponentManager.Capability} */ - var DRAG_TARGET: ComponentManager.Capability; - - /** @type {!ComponentManager.Capability} */ - var DELETE_AREA: ComponentManager.Capability; - - /** @type {!ComponentManager.Capability} */ - var AUTOHIDEABLE: ComponentManager.Capability; -} - - -declare module Connection { - /** - * Constants for checking whether two connections are compatible. + * @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. */ - var CAN_CONNECT: any /*missing*/; - /** - * Returns the connection (starting at the startBlock) which will accept - * the given connection. This includes compatible connection types and - * connection checks. - * @param {!Block} startBlock The block on which to start the search. - * @param {!Connection} orphanConnection The connection that is looking - * for a home. - * @return {?Connection} The suitable connection point on the chain of - * blocks, or null. + * 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 */ - function getConnectionForOrphanedConnection(startBlock: Block, orphanConnection: Connection): Connection; -} - - - -declare module ConnectionDB { - /** - * Initialize a set of connection DBs for a workspace. - * @param {!IConnectionChecker} checker The workspace's - * connection checker, used to decide if connections are valid during a - * drag. - * @return {!Array} Array of databases. + * 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 */ - function init(checker: IConnectionChecker): ConnectionDB[]; -} - - - - - - -declare module ContextMenuRegistry { - + export function startsWith(str: string, prefix: string): boolean; /** - * Where this menu item should be rendered. If the menu item should be rendered - * in multiple scopes, e.g. on both a block and a workspace, it should be - * registered for each scope. - * @enum {string} + * Given an array of strings, return the length of the shortest one. + * @param {!Array} array Array of strings. + * @return {number} Length of shortest string. + * @alias Blockly.utils.string.shortestStringLength */ - enum ScopeType { BLOCK, WORKSPACE } - + export function shortestStringLength(array: Array): number; /** - * The actual workspace/block where the menu is being rendered. This is passed - * to callback and displayText functions that depend on this information. - * @typedef {{ - * block: (BlockSvg|undefined), - * workspace: (WorkspaceSvg|undefined) - * }} + * 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} array Array of strings. + * @param {number=} opt_shortest Length of shortest string. + * @return {number} Length of common prefix. + * @alias Blockly.utils.string.commonWordPrefix */ - interface Scope { - block: BlockSvg|any /*undefined*/; - workspace: WorkspaceSvg|any /*undefined*/ - } - + export function commonWordPrefix(array: Array, opt_shortest?: number | undefined): number; /** - * A menu item as entered in the registry. - * @typedef {{ - * callback: function(!ContextMenuRegistry.Scope), - * scopeType: !ContextMenuRegistry.ScopeType, - * displayText: ((function(!ContextMenuRegistry.Scope):string)|string), - * preconditionFn: function(!ContextMenuRegistry.Scope):string, - * weight: number, - * id: string - * }} + * 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} array Array of strings. + * @param {number=} opt_shortest Length of shortest string. + * @return {number} Length of common suffix. + * @alias Blockly.utils.string.commonWordSuffix */ - interface RegistryItem { - callback: { (_0: ContextMenuRegistry.Scope): any /*missing*/ }; - scopeType: ContextMenuRegistry.ScopeType; - displayText: { (_0: ContextMenuRegistry.Scope): string }|string; - preconditionFn: { (_0: ContextMenuRegistry.Scope): string }; - weight: number; - id: string - } - + export function commonWordSuffix(array: Array, opt_shortest?: number | undefined): number; /** - * A menu item as presented to contextmenu.js. - * @typedef {{ - * text: string, - * enabled: boolean, - * callback: function(!ContextMenuRegistry.Scope), - * scope: !ContextMenuRegistry.Scope, - * weight: 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 */ - interface ContextMenuOption { - text: string; - enabled: boolean; - callback: { (_0: ContextMenuRegistry.Scope): any /*missing*/ }; - scope: ContextMenuRegistry.Scope; - weight: number - } - + export function wrap(text: string, limit: number): string; /** - * Singleton instance of this class. All interactions with this class should be - * done on this object. - * @type {?ContextMenuRegistry} + * 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 */ - var registry: ContextMenuRegistry; + export function isNumber(str: string): boolean; } - - - - - - -declare module DropDownDiv { - +declare module "internal_constants" { /** - * Arrow size in px. Should match the value in CSS - * (need to position pre-render). + * The multiplier for scroll wheel deltas using the line delta mode. * @type {number} - * @const + * @alias Blockly.internalConstants.LINE_MODE_MULTIPLIER */ - var ARROW_SIZE: number; - + export const LINE_MODE_MULTIPLIER: number; /** - * Drop-down border size in px. Should match the value in CSS (need to position - * the arrow). + * The multiplier for scroll wheel deltas using the page delta mode. * @type {number} - * @const + * @alias Blockly.internalConstants.PAGE_MODE_MULTIPLIER */ - var BORDER_SIZE: number; - + export const PAGE_MODE_MULTIPLIER: number; /** - * Amount the arrow must be kept away from the edges of the main drop-down div, - * in px. - * @type {number} - * @const + * Number of pixels the mouse must move before a drag starts. + * @alias Blockly.internalConstants.DRAG_RADIUS */ - var ARROW_HORIZONTAL_PADDING: number; - + export const DRAG_RADIUS: 5; /** - * Amount drop-downs should be padded away from the source, in px. - * @type {number} - * @const + * 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 */ - var PADDING_Y: number; - + export const FLYOUT_DRAG_RADIUS: 10; /** - * Length of animations in seconds. - * @type {number} - * @const + * Maximum misalignment between connections for them to snap together. + * @alias Blockly.internalConstants.SNAP_RADIUS */ - var ANIMATION_TIME: number; - + export const SNAP_RADIUS: 28; /** - * Dropdown bounds info object used to encapsulate sizing information about a - * bounding element (bounding box and width/height). - * @typedef {{ - * top:number, - * left:number, - * bottom:number, - * right:number, - * width:number, - * height:number - * }} + * Maximum misalignment between connections for them to snap together, + * when a connection is already highlighted. + * @alias Blockly.internalConstants.CONNECTING_SNAP_RADIUS */ - interface BoundsInfo { - top: number; - left: number; - bottom: number; - right: number; - width: number; - height: number - } - + export const CONNECTING_SNAP_RADIUS: 28; /** - * Dropdown position metrics. - * @typedef {{ - * initialX:number, - * initialY:number, - * finalX:number, - * finalY:number, - * arrowX:?number, - * arrowY:?number, - * arrowAtTop:?boolean, - * arrowVisible:boolean - * }} + * 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 */ - interface PositionMetrics { - initialX: number; - initialY: number; - finalX: number; - finalY: number; - arrowX: number; - arrowY: number; - arrowAtTop: boolean; - arrowVisible: boolean - } - + export const CURRENT_CONNECTION_PREFERENCE: 8; /** - * Create and insert the DOM element for this div. - * @package + * Delay in ms between trigger and bumping unconnected block out of alignment. + * @alias Blockly.internalConstants.BUMP_DELAY */ - function createDom(): void; - + export const BUMP_DELAY: 250; /** - * Set an element to maintain bounds within. Drop-downs will appear - * within the box of this element if possible. - * @param {?Element} boundsElement Element to bind drop-down to. + * Maximum randomness in workspace units for bumping a block. + * @alias Blockly.internalConstants.BUMP_RANDOMNESS */ - function setBoundsElement(boundsElement: Element): void; - + export const BUMP_RANDOMNESS: 10; /** - * Provide the div for inserting content into the drop-down. - * @return {!Element} Div to populate with content. + * Number of characters to truncate a collapsed block to. + * @alias Blockly.internalConstants.COLLAPSE_CHARS */ - function getContentDiv(): Element; - + export const COLLAPSE_CHARS: 30; /** - * Clear the content of the drop-down. + * Length in ms for a touch to become a long press. + * @alias Blockly.internalConstants.LONGPRESS */ - function clearContent(): void; - + export const LONGPRESS: 750; /** - * Set the colour for the drop-down. - * @param {string} backgroundColour Any CSS colour for the background. - * @param {string} borderColour Any CSS colour for the border. + * Prevent a sound from playing if another sound preceded it within this many + * milliseconds. + * @alias Blockly.internalConstants.SOUND_LIMIT */ - function setColour(backgroundColour: string, borderColour: string): void; - + export const SOUND_LIMIT: 100; /** - * Shortcut to show and place the drop-down with positioning determined - * by a particular block. The primary position will be below the block, - * and the secondary position above the block. Drop-down will be - * constrained to the block's workspace. - * @param {!Field} field The field showing the drop-down. - * @param {!BlockSvg} block Block to position the drop-down around. - * @param {Function=} opt_onHide Optional callback for when the drop-down is - * hidden. - * @param {number=} opt_secondaryYOffset Optional Y offset for above-block - * positioning. - * @return {boolean} True if the menu rendered below block; false if above. - */ - function showPositionedByBlock(field: Field, block: BlockSvg, opt_onHide?: Function, opt_secondaryYOffset?: number): boolean; - + * 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; /** - * Shortcut to show and place the drop-down with positioning determined - * by a particular field. The primary position will be below the field, - * and the secondary position above the field. Drop-down will be - * constrained to the block's workspace. - * @param {!Field} field The field to position the dropdown against. - * @param {Function=} opt_onHide Optional callback for when the drop-down is - * hidden. - * @param {number=} opt_secondaryYOffset Optional Y offset for above-block - * positioning. - * @return {boolean} True if the menu rendered below block; false if above. - */ - function showPositionedByField(field: Field, opt_onHide?: Function, opt_secondaryYOffset?: number): boolean; - + * 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; /** - * Show and place the drop-down. - * The drop-down is placed with an absolute "origin point" (x, y) - i.e., - * the arrow will point at this origin and box will positioned below or above - * it. If we can maintain the container bounds at the primary point, the arrow - * will point there, and the container will be positioned below it. - * If we can't maintain the container bounds at the primary point, fall-back to - * the secondary point and position above. - * @param {?Object} owner The object showing the drop-down - * @param {boolean} rtl Right-to-left (true) or left-to-right (false). - * @param {number} primaryX Desired origin point x, in absolute px. - * @param {number} primaryY Desired origin point y, in absolute px. - * @param {number} secondaryX Secondary/alternative origin point x, in absolute - * px. - * @param {number} secondaryY Secondary/alternative origin point y, in absolute - * px. - * @param {Function=} opt_onHide Optional callback for when the drop-down is - * hidden. - * @return {boolean} True if the menu rendered at the primary origin point. - * @package - */ - function show(owner: Object, rtl: boolean, primaryX: number, primaryY: number, secondaryX: number, secondaryY: number, opt_onHide?: Function): boolean; - + * 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; + } /** - * Get the x positions for the left side of the DropDownDiv and the arrow, - * accounting for the bounds of the workspace. - * @param {number} sourceX Desired origin point x, in absolute px. - * @param {number} boundsLeft The left edge of the bounding element, in - * absolute px. - * @param {number} boundsRight The right edge of the bounding element, in - * absolute px. - * @param {number} divWidth The width of the div in px. - * @return {{divX: number, arrowX: number}} An object containing metrics for - * the x positions of the left side of the DropDownDiv and the arrow. - * @package + * ENUM for no drag operation. + * @const + * @alias Blockly.internalConstants.DRAG_NONE */ - function getPositionX(sourceX: number, boundsLeft: number, boundsRight: number, divWidth: number): { divX: number; arrowX: number }; - + export const DRAG_NONE: 0; /** - * Is the container visible? - * @return {boolean} True if visible. + * ENUM for inside the sticky DRAG_RADIUS. + * @const + * @alias Blockly.internalConstants.DRAG_STICKY */ - function isVisible(): boolean; - + export const DRAG_STICKY: 1; /** - * Hide the menu only if it is owned by the provided object. - * @param {?Object} owner Object which must be owning the drop-down to hide. - * @param {boolean=} opt_withoutAnimation True if we should hide the dropdown - * without animating. - * @return {boolean} True if hidden. + * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between + * clicks and drags. + * @const + * @alias Blockly.internalConstants.DRAG_BEGIN */ - function hideIfOwner(owner: Object, opt_withoutAnimation?: boolean): boolean; - + export const DRAG_BEGIN: 1; /** - * Hide the menu, triggering animation. + * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). + * @const + * @alias Blockly.internalConstants.DRAG_FREE */ - function hide(): void; - + export const DRAG_FREE: 2; /** - * Hide the menu, without animation. + * Lookup table for determining the opposite type of a connection. + * @const + * @alias Blockly.internalConstants.OPPOSITE_TYPE */ - function hideWithoutAnimation(): void; - + export const OPPOSITE_TYPE: any[]; /** - * Repositions the dropdownDiv on window resize. If it doesn't know how to - * calculate the new position, it will just hide it instead. - * @package + * 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 */ - function repositionForWindowResize(): void; -} - -declare module internal { - + export const VARIABLE_CATEGORY_NAME: "VARIABLE"; /** - * Get sizing info about the bounding element. - * @return {!DropDownDiv.BoundsInfo} An object containing size - * information about the bounding element (bounding box and width/height). + * 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 */ - function getBoundsInfo(): DropDownDiv.BoundsInfo; - + export const VARIABLE_DYNAMIC_CATEGORY_NAME: "VARIABLE_DYNAMIC"; /** - * Helper to position the drop-down and the arrow, maintaining bounds. - * See explanation of origin points in DropDownDiv.show. - * @param {number} primaryX Desired origin point x, in absolute px. - * @param {number} primaryY Desired origin point y, in absolute px. - * @param {number} secondaryX Secondary/alternative origin point x, - * in absolute px. - * @param {number} secondaryY Secondary/alternative origin point y, - * in absolute px. - * @return {!DropDownDiv.PositionMetrics} Various final metrics, - * including rendered positions for drop-down and arrow. + * 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 */ - function getPositionMetrics(primaryX: number, primaryY: number, secondaryX: number, secondaryY: number): DropDownDiv.PositionMetrics; -} - - - -declare module Field { - + export const PROCEDURE_CATEGORY_NAME: "PROCEDURE"; /** - * Non-breaking space. - * @const + * 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 */ - var NBSP: any /*missing*/; -} - - -declare module FieldAngle { - + export const RENAME_VARIABLE_ID: "RENAME_VARIABLE_ID"; /** - * Construct a FieldAngle from a JSON arg object. - * @param {!Object} options A JSON object with options (angle). - * @return {!FieldAngle} The new field instance. - * @package - * @nocollapse + * 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 */ - function fromJson(options: Object): FieldAngle; - + export const DELETE_VARIABLE_ID: "DELETE_VARIABLE_ID"; +} +declare module "msg" { + export {}; +} +declare module "blocks" { /** - * The default amount to round angles to when using a mouse or keyboard nav - * input. Must be a positive integer to support keyboard navigation. - * @const {number} + * @license + * Copyright 2013 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var ROUND: any /*missing*/; - /** - * Half the width of protractor image. - * @const {number} + * @fileoverview A mapping of block type names to block prototype objects. */ - var HALF: any /*missing*/; - /** - * Default property describing which direction makes an angle field's value - * increase. Angle increases clockwise (true) or counterclockwise (false). - * @const {boolean} + * A mapping of block type names to block prototype objects. + * @namespace Blockly.blocks */ - var CLOCKWISE: any /*missing*/; - /** - * The default offset of 0 degrees (and all angles). Always offsets in the - * counterclockwise direction, regardless of the field's clockwise property. - * Usually either 0 (0 = right) or 90 (0 = up). - * @const {number} + * A mapping of block type names to block prototype objects. + * @type {!Object} + * @alias Blockly.blocks.Blocks */ - var OFFSET: any /*missing*/; - + export const Blocks: { + [x: string]: any; + }; +} +declare module "interfaces/i_deletable" { /** - * The default maximum angle to allow before wrapping. - * Usually either 360 (for 0 to 359.9) or 180 (for -179.9 to 180). - * @const {number} + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var WRAP: any /*missing*/; - /** - * Radius of protractor circle. Slightly smaller than protractor size since - * otherwise SVG crops off half the border at the edges. - * @const {number} + * @fileoverview The interface for an object that is deletable. */ - var RADIUS: any /*missing*/; -} - - -declare module FieldCheckbox { - /** - * Construct a FieldCheckbox from a JSON arg object. - * @param {!Object} options A JSON object with options (checked). - * @return {!FieldCheckbox} The new field instance. - * @package - * @nocollapse + * The interface for an object that is deletable. + * @namespace Blockly.IDeletable */ - function fromJson(options: Object): FieldCheckbox; - /** - * Default character for the checkmark. - * @type {string} - * @const + * The interface for an object that can be deleted. + * @interface + * @alias Blockly.IDeletable */ - var CHECK_CHAR: string; + export class IDeletable { + } } - - -declare module FieldColour { - +declare module "interfaces/i_movable" { /** - * Construct a FieldColour from a JSON arg object. - * @param {!Object} options A JSON object with options (colour). - * @return {!FieldColour} The new field instance. - * @package - * @nocollapse + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function fromJson(options: Object): FieldColour; - /** - * An array of colour strings for the palette. - * Copied from goog.ui.ColorPicker.SIMPLE_GRID_COLORS - * All colour pickers use this unless overridden with setColours. - * @type {!Array} + * @fileoverview The interface for an object that is movable. */ - var COLOURS: string[]; - /** - * An array of tooltip strings for the palette. If not the same length as - * COLOURS, the colour's hex code will be used for any missing titles. - * All colour pickers use this unless overridden with setColours. - * @type {!Array} + * The interface for an object that is movable. + * @namespace Blockly.IMovable */ - var TITLES: string[]; - /** - * Number of columns in the palette. - * All colour pickers use this unless overridden with setColumns. + * The interface for an object that is movable. + * @interface + * @alias Blockly.IMovable */ - var COLUMNS: any /*missing*/; + export class IMovable { + } } - - -declare module FieldDropdown { - +declare module "interfaces/i_selectable" { /** - * Dropdown image properties. - * @typedef {{ - * src:string, - * alt:string, - * width:number, - * height:number - * }} + * The interface for an object that is selectable. + * @extends {IDeletable} + * @extends {IMovable} + * @interface + * @alias Blockly.ISelectable */ - interface ImageProperties { - src: string; - alt: string; - width: number; - height: number + export class ISelectable { + /** + * @type {string} + */ + id: string; } - +} +declare module "dialog" { /** - * Construct a FieldDropdown from a JSON arg object. - * @param {!Object} options A JSON object with options (options). - * @return {!FieldDropdown} The new field instance. - * @package - * @nocollapse + * 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 */ - function fromJson(options: Object): FieldDropdown; - + export function alert(message: string, opt_callback?: (() => any) | undefined): void; /** - * Horizontal distance that a checkmark overhangs the dropdown. + * 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 */ - var CHECKMARK_OVERHANG: any /*missing*/; - + export function setAlert(alertFunction: (arg0: string, arg1: (() => any) | undefined) => any): void; /** - * Maximum height of the dropdown menu, as a percentage of the viewport height. + * 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 */ - var MAX_MENU_HEIGHT_VH: any /*missing*/; - + export function confirm(message: string, callback: (arg0: boolean) => any): void; /** - * Android can't (in 2014) display "▾", so use "▼" instead. + * 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 */ - var ARROW_CHAR: any /*missing*/; - + export function setConfirm(confirmFunction: (arg0: string, arg1: (arg0: boolean) => any) => any): void; /** - * Use the calculated prefix and suffix lengths to trim all of the options in - * the given array. - * @param {!Array} options Array of option tuples: - * (human-readable text or image, language-neutral name). - * @param {number} prefixLength The length of the common prefix. - * @param {number} suffixLength The length of the common suffix - * @return {!Array} A new array with all of the option text trimmed. + * 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 */ - function applyTrim_(options: any[][], prefixLength: number, suffixLength: number): any[][]; -} - - -declare module FieldImage { - + export function prompt(message: string, defaultValue: string, callback: (arg0: string | null) => any): void; /** - * Construct a FieldImage from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (src, width, height, - * alt, and flipRtl). - * @return {!FieldImage} The new field instance. - * @package - * @nocollapse + * 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 */ - function fromJson(options: Object): FieldImage; + export function setPrompt(promptFunction: (arg0: string, arg1: string, arg2: (arg0: string | null) => any) => any): void; } - - -declare module FieldLabel { - +declare module "utils/array" { /** - * Construct a FieldLabel from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, and class). - * @return {!FieldLabel} The new field instance. - * @package - * @nocollapse + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function fromJson(options: Object): FieldLabel; -} - - -declare module FieldLabelSerializable { - /** - * Construct a FieldLabelSerializable from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, and class). - * @return {!FieldLabelSerializable} The new field instance. - * @package - * @nocollapse + * @fileoverview Utility methods related to arrays. */ - function fromJson(options: Object): FieldLabelSerializable; -} - - -declare module FieldMultilineInput { - /** - * Construct a FieldMultilineInput from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!FieldMultilineInput} The new field instance. - * @package - * @nocollapse + * @namespace Blockly.utils.array */ - function fromJson(options: Object): FieldMultilineInput; -} - - -declare module FieldNumber { - /** - * Construct a FieldNumber from a JSON arg object. - * @param {!Object} options A JSON object with options (value, min, max, and - * precision). - * @return {!FieldNumber} The new field instance. + * 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 - * @nocollapse */ - function fromJson(options: Object): FieldNumber; + export function removeElem(arr: any[], value: any): boolean; } - - - -declare module FieldTextInput { - +declare module "utils/math" { /** - * Construct a FieldTextInput from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!FieldTextInput} The new field instance. - * @package - * @nocollapse + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function fromJson(options: Object): FieldTextInput; - /** - * Pixel size of input border radius. - * Should match blocklyText's border-radius in CSS. + * @fileoverview Utility methods for math. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. */ - var BORDERRADIUS: any /*missing*/; -} - - -declare module FieldVariable { - /** - * Construct a FieldVariable from a JSON arg object, - * dereferencing any string table references. - * @param {!Object} options A JSON object with options (variable, - * variableTypes, and defaultType). - * @return {!FieldVariable} The new field instance. - * @package - * @nocollapse + * 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 */ - function fromJson(options: Object): FieldVariable; - /** - * Return a sorted list of variable names for variable dropdown menus. - * Include a special option at the end for creating a new variable name. - * @return {!Array} Array of variable names/id tuples. - * @this {FieldVariable} + * 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 */ - function dropdownCreate(): any[][]; -} - - - -declare module FlyoutButton { - + export function toRadians(angleDegrees: number): number; /** - * The horizontal margin around the text in the button. + * 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 */ - var MARGIN_X: any /*missing*/; - + export function toDegrees(angleRadians: number): number; /** - * The vertical margin around the text in the button. + * 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 */ - var MARGIN_Y: any /*missing*/; + export function clamp(lowerBound: number, number: number, upperBound: number): number; } - - - - -declare module VerticalFlyout { - +declare module "serialization/priorities" { /** - * The name of the vertical flyout in the registry. - * @type {string} + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var registryName: string; -} - - - -declare module Gesture { - /** - * Is a drag or other gesture currently in progress on any workspace? - * @return {boolean} True if gesture is occurring. + * @fileoverview The top level namespace for priorities of plugin serializers. + * Includes constants for the priorities of different plugin + * serializers. Higher priorities are deserialized first. */ - function inProgress(): boolean; -} - - -declare module Grid { - /** - * Create the DOM for the grid described by options. - * @param {string} rnd A random ID to append to the pattern's ID. - * @param {!Object} gridOptions The object containing grid configuration. - * @param {!SVGElement} defs The root SVG element for this workspace's defs. - * @return {!SVGElement} The SVG element for the grid pattern. - * @package + * 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 */ - function createDom(rnd: string, gridOptions: Object, defs: SVGElement): SVGElement; -} - - - - - - -declare module InsertionMarkerManager { - /** - * An enum describing different kinds of previews the InsertionMarkerManager - * could display. - * @enum {number} + * The priority for deserializing variables. + * @type {number} + * @const + * @alias Blockly.serialization.priorities.VARIABLES */ - enum PREVIEW_TYPE { INSERTION_MARKER, INPUT_OUTLINE, REPLACEMENT_FADE } - + export const VARIABLES: number; /** - * An error message to throw if the block created by createMarkerBlock_ is - * missing any components. - * @type {string} + * The priority for deserializing blocks. + * @type {number} * @const + * @alias Blockly.serialization.priorities.BLOCKS */ - var DUPLICATE_BLOCK_ERROR: string; + export const BLOCKS: number; } - - - -declare module MarkerManager { - +declare module "interfaces/i_serializer" { /** - * The name of the local marker. - * @type {string} - * @const + * Serializes and deserializes a plugin or system. + * @interface + * @alias Blockly.serialization.ISerializer.ISerializer */ - var LOCAL_MARKER: string; + 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 MetricsManager { - +declare module "serialization/registry" { /** - * Describes the width, height and location of the toolbox on the main - * workspace. - * @typedef {{ - * width: number, - * height: number, - * position: !toolboxUtils.Position - * }} + * 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 */ - interface ToolboxMetrics { - width: number; - height: number; - position: toolboxUtils.Position + 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 { } - /** - * Describes where the viewport starts in relation to the workspace SVG. - * @typedef {{ - * left: number, - * top: number - * }} + * Represents an error where the serialized state is expected to provide a + * block type, but it is not provided. + * @alias Blockly.serialization.exceptions.MissingBlockType */ - interface AbsoluteMetrics { - left: number; - top: number + 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; } - /** - * All the measurements needed to describe the size and location of a container. - * @typedef {{ - * height: number, - * width: number, - * top: number, - * left: number - * }} + * 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 */ - interface ContainerRegion { - height: number; - width: number; - top: number; - left: number + 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; } - /** - * Describes fixed edges of the workspace. - * @typedef {{ - * top: (number|undefined), - * bottom: (number|undefined), - * left: (number|undefined), - * right: (number|undefined) - * }} + * Represents an error where deserialization tried to connect two connections + * that were not compatible. + * @alias Blockly.serialization.exceptions.BadConnectionCheck */ - interface FixedEdges { - top: number|any /*undefined*/; - bottom: number|any /*undefined*/; - left: number|any /*undefined*/; - right: number|any /*undefined*/ + 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; } - /** - * Common metrics used for UI elements. - * @typedef {{ - * viewMetrics: !MetricsManager.ContainerRegion, - * absoluteMetrics: !MetricsManager.AbsoluteMetrics, - * toolboxMetrics: !MetricsManager.ToolboxMetrics - * }} + * 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 */ - interface UiMetrics { - viewMetrics: MetricsManager.ContainerRegion; - absoluteMetrics: MetricsManager.AbsoluteMetrics; - toolboxMetrics: MetricsManager.ToolboxMetrics + 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 Mutator { - +declare module "utils/size" { /** - * Reconnect an block to a mutated input. - * @param {Connection} connectionChild Connection on child block. - * @param {!Block} block Parent block. - * @param {string} inputName Name of input on parent block. - * @return {boolean} True iff a reconnection was made, false otherwise. + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function reconnect(connectionChild: Connection, block: Block, inputName: string): boolean; - /** - * Get the parent workspace of a workspace that is inside a mutator, taking into - * account whether it is a flyout. - * @param {Workspace} workspace The workspace that is inside a mutator. - * @return {?Workspace} The mutator's parent workspace or null. - * @public + * @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. */ - function findParentWs(workspace: Workspace): Workspace; -} - - -declare module Names { - /** - * Constant to separate developer variable names from user-defined variable - * names when running generators. - * A developer variable will be declared as a global in the generated code, but - * will never be shown to the user in the workspace or stored in the variable - * map. + * 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 */ - var DEVELOPER_VARIABLE_TYPE: any /*missing*/; - /** - * Do the given two entity names refer to the same entity? - * Blockly names are case-insensitive. - * @param {string} name1 First name. - * @param {string} name2 Second name. - * @return {boolean} True if names are the same. + * Class for representing sizes consisting of a width and height. + * @param {number} width Width. + * @param {number} height Height. + * @struct + * @constructor + * @alias Blockly.utils.Size */ - function equals(name1: string, name2: string): boolean; + 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 Options { - +declare module "input_types" { /** - * Grid Options. - * @typedef {{ - * colour: string, - * length: number, - * snap: boolean, - * spacing: number - * }} + * * */ - interface GridOptions { - colour: string; - length: number; - snap: boolean; - spacing: number + export type inputTypes = number; + export namespace inputTypes { + const VALUE: number; + const STATEMENT: number; + const DUMMY: number; } - +} +declare module "serialization/blocks" { /** - * Move Options. - * @typedef {{ - * drag: boolean, - * scrollbars: (boolean | !Options.ScrollbarOptions), - * wheel: boolean - * }} + * Represents the state of a connection. */ - interface MoveOptions { - drag: boolean; - scrollbars: boolean|Options.ScrollbarOptions; - wheel: boolean - } - + export type ConnectionState = { + shadow: (any | undefined); + block: (any | undefined); + }; /** - * Scrollbar Options. + * Represents the state of a connection. * @typedef {{ - * horizontal: boolean, - * vertical: boolean + * shadow: (!State|undefined), + * block: (!State|undefined) * }} + * @alias Blockly.serialization.blocks.ConnectionState */ - interface ScrollbarOptions { - horizontal: boolean; - vertical: boolean - } - + export let ConnectionState: any; /** - * Zoom Options. + * Represents the state of a given block. * @typedef {{ - * controls: boolean, - * maxScale: number, - * minScale: number, - * pinch: boolean, - * scaleSpeed: number, - * startScale: number, - * wheel: boolean + * 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|undefined), + * fields: (!Object|undefined), + * inputs: (!Object|undefined), + * next: (!ConnectionState|undefined) * }} + * @alias Blockly.serialization.blocks.State */ - interface ZoomOptions { - controls: boolean; - maxScale: number; - minScale: number; - pinch: boolean; - scaleSpeed: number; - startScale: number; - wheel: boolean - } + 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 Type { - - /** @type {!Type} */ - var CONNECTION_CHECKER: Type; - - /** @type {!Type} */ - var CURSOR: Type; - - /** @type {!Type} */ - var EVENT: Type; - - /** @type {!Type} */ - var FIELD: Type; - - /** @type {!Type} */ - var RENDERER: Type; - - /** @type {!Type} */ - var TOOLBOX: Type; - - /** @type {!Type} */ - var THEME: Type; - - /** @type {!Type} */ - var TOOLBOX_ITEM: Type; - - /** @type {!Type} */ - var FLYOUTS_VERTICAL_TOOLBOX: Type; - - /** @type {!Type} */ - var FLYOUTS_HORIZONTAL_TOOLBOX: Type; - - /** @type {!Type} */ - var METRICS_MANAGER: Type; - - /** @type {!Type} */ - var BLOCK_DRAGGER: Type; - +declare module "utils/deprecation" { /** - * @type {!Type} - * @package + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var SERIALIZER: Type; -} - - -declare module RenderedConnection { - /** - * Enum for different kinds of tracked states. - * - * WILL_TRACK means that this connection will add itself to - * the db on the next moveTo call it receives. - * - * UNTRACKED means that this connection will not add - * itself to the database until setTracking(true) is explicitly called. - * - * TRACKED means that this connection is currently being tracked. - * @enum {number} + * @fileoverview Helper function for warning developers about deprecations. + * This method is not specific to Blockly. */ - enum TrackedState { WILL_TRACK, UNTRACKED, TRACKED } -} - - - -declare module Scrollbar { - /** - * Width of vertical scrollbar or height of horizontal scrollbar in CSS pixels. - * Scrollbars should be larger on touch devices. + * Helper function for warning developers about deprecations. + * This method is not specific to Blockly. + * @namespace Blockly.utils.deprecation */ - var scrollbarThickness: any /*missing*/; - /** - * Default margin around the scrollbar (between the scrollbar and the edge of - * the viewport in pixels). - * @type {number} - * @const + * 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 */ - var DEFAULT_SCROLLBAR_MARGIN: number; + export function warn(name: string, deprecationDate: string, deletionDate: string, opt_use?: string | undefined): void; } - - - - -declare module ShortcutRegistry { - +declare module "css" { /** - * Enum of valid modifiers. - * @enum {!KeyCodes} + * 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} cssContent Multiline CSS string or an array of + * single lines of CSS. + * @alias Blockly.Css.register */ - enum modifierKeys { Shift, Control, Alt, Meta } - + export function register(cssContent: string | Array): void; /** - * A keyboard shortcut. - * @typedef {{ - * callback: ((function(!Workspace, Event, - * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), - * name: string, - * preconditionFn: ((function(!Workspace):boolean)|undefined), - * metadata: (Object|undefined) - * }} + * 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 */ - interface KeyboardShortcut { - callback: { (_0: Workspace, _1: Event, _2: ShortcutRegistry.KeyboardShortcut): boolean }|any /*undefined*/; - name: string; - preconditionFn: { (_0: Workspace): boolean }|any /*undefined*/; - metadata: Object|any /*undefined*/ - } -} - - -declare module Theme { - + export function inject(hasCss: boolean, pathToMedia: string): void; /** - * A block style. - * @typedef {{ - * colourPrimary:string, - * colourSecondary:string, - * colourTertiary:string, - * hat:string - * }} + * The CSS content for Blockly. + * @alias Blockly.Css.content */ - interface BlockStyle { - colourPrimary: string; - colourSecondary: string; - colourTertiary: string; - hat: string - } - + export let content: string; +} +declare module "utils/aria" { /** - * A category style. - * @typedef {{ - * colour:string - * }} + * * */ - interface CategoryStyle { - colour: string + 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; } - /** - * A component style. - * @typedef {{ - * workspaceBackgroundColour:?string, - * toolboxBackgroundColour:?string, - * toolboxForegroundColour:?string, - * flyoutBackgroundColour:?string, - * flyoutForegroundColour:?string, - * flyoutOpacity:?number, - * scrollbarColour:?string, - * scrollbarOpacity:?number, - * insertionMarkerColour:?string, - * insertionMarkerOpacity:?number, - * markerColour:?string, - * cursorColour:?string, - * selectedGlowColour:?string, - * selectedGlowOpacity:?number, - * replacementGlowColour:?string, - * replacementGlowOpacity:?number - * }} + * * */ - interface ComponentStyle { - workspaceBackgroundColour: string; - toolboxBackgroundColour: string; - toolboxForegroundColour: string; - flyoutBackgroundColour: string; - flyoutForegroundColour: string; - flyoutOpacity: number; - scrollbarColour: string; - scrollbarOpacity: number; - insertionMarkerColour: string; - insertionMarkerOpacity: number; - markerColour: string; - cursorColour: string; - selectedGlowColour: string; - selectedGlowOpacity: number; - replacementGlowColour: string; - replacementGlowOpacity: number + 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; } - /** - * A font style. - * @typedef {{ - * family:?string, - * weight:?string, - * size:?number - * }} + * 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 */ - interface FontStyle { - family: string; - weight: string; - size: number - } - + export function setRole(element: Element, roleName: Role): void; /** - * Define a new Blockly theme. - * @param {string} name The name of the theme. - * @param {!Object} themeObj An object containing theme properties. - * @return {!Theme} A new Blockly theme. + * 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} value Value + * for the state attribute. + * @alias Blockly.utils.aria.setState */ - function defineTheme(name: string, themeObj: Object): Theme; + export function setState(element: Element, stateName: State, value: string | boolean | number | Array): void; } - - -declare module ThemeManager { - +declare module "utils/colour" { /** - * A Blockly UI component type. - * @typedef {{ - * element:!Element, - * propertyName:string - * }} + * Parses a colour from a string. + * .parse('red') -> '#ff0000' + * .parse('#f00') -> '#ff0000' + * .parse('#ff0000') -> '#ff0000' + * .parse('0xff0000') -> '#ff0000' + * .parse('rgb(255, 0, 0)') -> '#ff0000' + * @param {string|number} str Colour in some CSS format. + * @return {?string} A string containing a hex representation of the colour, + * or null if can't be parsed. + * @alias Blockly.utils.colour.parse */ - interface Component { - element: Element; - propertyName: string - } -} - - - - -declare module TouchGesture { - + export function parse(str: string | number): string | null; /** - * A multiplier used to convert the gesture scale to a zoom in delta. - * @const + * Converts a colour from RGB to hex representation. + * @param {number} r Amount of red, int between 0 and 255. + * @param {number} g Amount of green, int between 0 and 255. + * @param {number} b Amount of blue, int between 0 and 255. + * @return {string} Hex representation of the colour. + * @alias Blockly.utils.colour.rgbToHex */ - var ZOOM_IN_MULTIPLIER: any /*missing*/; - + export function rgbToHex(r: number, g: number, b: number): string; /** - * A multiplier used to convert the gesture scale to a zoom out delta. - * @const + * Converts a colour to RGB. + * @param {string} colour String representing colour in any + * colour format ('#ff0000', 'red', '0xff000', etc). + * @return {!Array} RGB representation of the colour. + * @alias Blockly.utils.colour.hexToRgb */ - var ZOOM_OUT_MULTIPLIER: any /*missing*/; -} - - - - - -declare module VariableModel { - + export function hexToRgb(colour: string): Array; /** - * A custom compare function for the VariableModel objects. - * @param {VariableModel} var1 First variable to compare. - * @param {VariableModel} var2 Second variable to compare. - * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, - * and 1 if greater. - * @package + * Converts an HSV triplet to hex representation. + * @param {number} h Hue value in [0, 360]. + * @param {number} s Saturation value in [0, 1]. + * @param {number} v Brightness in [0, 255]. + * @return {string} Hex representation of the colour. + * @alias Blockly.utils.colour.hsvToHex */ - function compareByName(var1: VariableModel, var2: VariableModel): number; -} - - - - - - -declare module Workspace { - + export function hsvToHex(h: number, s: number, v: number): string; /** - * Angle away from the horizontal to sweep for blocks. Order of execution is - * generally top to bottom, but a small angle changes the scan to give a bit of - * a left to right bias (reversed in RTL). Units are in degrees. - * See: https://tvtropes.org/pmwiki/pmwiki.php/Main/DiagonalBilling + * Blend two colours together, using the specified factor to indicate the + * weight given to the first colour. + * @param {string} colour1 First colour. + * @param {string} colour2 Second colour. + * @param {number} factor The weight to be given to colour1 over colour2. + * Values should be in the range [0, 1]. + * @return {?string} Combined colour represented in hex. + * @alias Blockly.utils.colour.blend */ - var SCAN_ANGLE: any /*missing*/; - + export function blend(colour1: string, colour2: string, factor: number): string | null; /** - * Find the workspace with the specified ID. - * @param {string} id ID of workspace to find. - * @return {?Workspace} The sought after workspace or null if not found. + * A map that contains the 16 basic colour keywords as defined by W3C: + * https://www.w3.org/TR/2018/REC-css-color-3-20180619/#html4 + * The keys of this map are the lowercase "readable" names of the colours, + * while the values are the "hex" values. + * + * @type {!Object} + * @alias Blockly.utils.colour.names */ - function getById(id: string): Workspace; - + export const names: { + [x: string]: string; + }; /** - * Find all workspaces. - * @return {!Array} Array of workspaces. + * Convert a hue (HSV model) into an RGB hex triplet. + * @param {number} hue Hue on a colour wheel (0-360). + * @return {string} RGB code, e.g. '#5ba65b'. + * @alias Blockly.utils.colour.hueToHex */ - function getAll(): Workspace[]; + export function hueToHex(hue: number): string; } - - - -declare module WorkspaceComment { - - /** - * Fire a create event for the given workspace comment, if comments are enabled. - * @param {!WorkspaceComment} comment The comment that was just created. - * @package - */ - function fireCreateEvent(comment: WorkspaceComment): void; - +declare module "utils/parsing" { /** - * Decode an XML comment tag and create a comment on the workspace. - * @param {!Element} xmlComment XML comment element. - * @param {!Workspace} workspace The workspace. - * @return {!WorkspaceComment} The created workspace comment. - * @package + * Parse a string with any number of interpolation tokens (%1, %2, ...). + * It will also replace string table references (e.g., %{bky_my_msg} and + * %{BKY_MY_MSG} will both be replaced with the value in + * Msg['MY_MSG']). Percentage sign characters '%' may be self-escaped + * (e.g., '%%'). + * @param {string} message Text which might contain string table references and + * interpolation tokens. + * @return {!Array} Array of strings and numbers. + * @alias Blockly.parsing.tokenizeInterpolation */ - function fromXml(xmlComment: Element, workspace: Workspace): WorkspaceComment; - + export function tokenizeInterpolation(message: string): Array; /** - * Decode an XML comment tag and return the results in an object. - * @param {!Element} xml XML comment element. - * @return {{w: number, h: number, x: number, y: number, content: string}} An - * object containing the id, size, position, and comment string. - * @package + * Replaces string table references in a message, if the message is a string. + * For example, "%{bky_my_msg}" and "%{BKY_MY_MSG}" will both be replaced with + * the value in Msg['MY_MSG']. + * @param {string|?} message Message, which may be a string that contains + * string table references. + * @return {string} String with message references replaced. + * @alias Blockly.parsing.replaceMessageReferences */ - function parseAttributes(xml: Element): { w: number; h: number; x: number; y: number; content: string }; -} - - -declare module WorkspaceCommentSvg { - + export function replaceMessageReferences(message: string | unknown): string; /** - * The width and height to use to size a workspace comment when it is first - * added, before it has been edited by the user. - * @type {number} - * @package + * Validates that any %{MSG_KEY} references in the message refer to keys of + * the Msg string table. + * @param {string} message Text which might contain string table references. + * @return {boolean} True if all message references have matching values. + * Otherwise, false. + * @alias Blockly.parsing.checkMessageReferences */ - var DEFAULT_SIZE: number; - + export function checkMessageReferences(message: string): boolean; /** - * Decode an XML comment tag and create a rendered comment on the workspace. - * @param {!Element} xmlComment XML comment element. - * @param {!WorkspaceSvg} workspace The workspace. - * @param {number=} opt_wsWidth The width of the workspace, which is used to - * position comments correctly in RTL. - * @return {!WorkspaceCommentSvg} The created workspace comment. - * @package + * Parse a block colour from a number or string, as provided in a block + * definition. + * @param {number|string} colour HSV hue value (0 to 360), #RRGGBB string, + * or a message reference string pointing to one of those two values. + * @return {{hue: ?number, hex: string}} An object containing the colour as + * a #RRGGBB string, and the hue if the input was an HSV hue value. + * @throws {Error} If the colour cannot be parsed. + * @alias Blockly.parsing.parseBlockColour */ - function fromXml(xmlComment: Element, workspace: WorkspaceSvg, opt_wsWidth?: number): WorkspaceCommentSvg; + export function parseBlockColour(colour: number | string): { + hue: number | null; + hex: string; + }; } - - - - - - - - - - -declare module BlockChange { - +declare module "interfaces/i_toolbox_item" { /** - * Returns the extra state of the given block (either as XML or a JSO, depending - * on the block's definition). - * @param {!BlockSvg} block The block to get the extra state of. - * @return {string} A stringified version of the extra state of the given block. - * @package + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function getExtraBlockState_(block: BlockSvg): string; -} - - - - - - - - -declare module CommentBase { - /** - * Helper function for Comment[Create|Delete] - * @param {!CommentCreate|!CommentDelete} event - * The event to run. - * @param {boolean} create if True then Create, if False then Delete + * @fileoverview The interface for a toolbox item. */ - function CommentCreateDeleteHelper(event: CommentCreate|CommentDelete, create: boolean): void; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - -declare module IComponent { - /** - * The unique id for this component that is used to register with the - * ComponentManager. - * @type {string} + * The interface for a toolbox item. + * @namespace Blockly.IToolboxItem */ - var id: string; -} - - - - -declare module ICopyable { - /** - * Copy Metadata. - * @typedef {{ - * saveInfo:(!Object|!Element), - * source:WorkspaceSvg, - * typeCounts:?Object - * }} + * Interface for an item in the toolbox. + * @interface + * @alias Blockly.IToolboxItem */ - interface CopyData { - saveInfo: Object|Element; - source: WorkspaceSvg; - typeCounts: Object + export class IToolboxItem { } } - - - - - - - - - - - - -declare module IRegistrableField { - +declare module "interfaces/i_selectable_toolbox_item" { /** - * @typedef {function(!Object): Field} + * Interface for an item in the toolbox that can be selected. + * @extends {IToolboxItem} + * @interface + * @alias Blockly.ISelectableToolboxItem */ - interface fromJson { - (_0: Object): Field + export class ISelectableToolboxItem { } } - - - - - - - - -declare module ASTNode { - +declare module "interfaces/i_collapsible_toolbox_item" { /** - * @typedef {{ - * wsCoordinate: Coordinate - * }} + * Interface for an item in the toolbox that can be collapsed. + * @extends {ISelectableToolboxItem} + * @interface + * @alias Blockly.ICollapsibleToolboxItem */ - interface Params { - wsCoordinate: Coordinate + export class ICollapsibleToolboxItem { } - +} +declare module "utils/coordinate" { /** - * Object holding different types for an AST node. - * @enum {string} + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - enum types { FIELD, BLOCK, INPUT, OUTPUT, NEXT, PREVIOUS, STACK, WORKSPACE } - /** - * True to navigate to all fields. False to only navigate to clickable fields. - * @type {boolean} + * @fileoverview Utility methods for coordinate manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. */ - var NAVIGATE_ALL_FIELDS: boolean; - /** - * Create an AST node pointing to a field. - * @param {Field} field The location of the AST node. - * @return {ASTNode} An AST node pointing to a field. + * Utility methods for coordinate manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. + * @class */ - function createFieldNode(field: Field): ASTNode; - /** - * Creates an AST node pointing to a connection. If the connection has a parent - * input then create an AST node of type input that will hold the connection. - * @param {Connection} connection This is the connection the node will - * point to. - * @return {ASTNode} An AST node pointing to a connection. + * Class for representing coordinates and positions. + * @param {number} x Left. + * @param {number} y Top. + * @struct + * @constructor + * @alias Blockly.utils.Coordinate */ - function createConnectionNode(connection: Connection): ASTNode; - + export class Coordinate { + /** + * Compares coordinates for equality. + * @param {?Coordinate} a A Coordinate. + * @param {?Coordinate} b A Coordinate. + * @return {boolean} True iff the coordinates are equal, or if both are null. + */ + static equals(a: Coordinate | null, b: Coordinate | null): boolean; + /** + * Returns the distance between two coordinates. + * @param {!Coordinate} a A Coordinate. + * @param {!Coordinate} b A Coordinate. + * @return {number} The distance between `a` and `b`. + */ + static distance(a: Coordinate, b: Coordinate): number; + /** + * Returns the magnitude of a coordinate. + * @param {!Coordinate} a A Coordinate. + * @return {number} The distance between the origin and `a`. + */ + static magnitude(a: Coordinate): number; + /** + * Returns the difference between two coordinates as a new + * Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the difference + * between `a` and `b`. + */ + static difference(a: Coordinate | SVGPoint, b: Coordinate | SVGPoint): Coordinate; + /** + * Returns the sum of two coordinates as a new Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the sum of + * the two coordinates. + */ + static sum(a: Coordinate | SVGPoint, b: Coordinate | SVGPoint): Coordinate; + constructor(x: any, y: any); + /** + * X-value + * @type {number} + */ + x: number; + /** + * Y-value + * @type {number} + */ + y: number; + /** + * Creates a new copy of this coordinate. + * @return {!Coordinate} A copy of this coordinate. + */ + clone(): Coordinate; + /** + * Scales this coordinate by the given scale factor. + * @param {number} s The scale factor to use for both x and y dimensions. + * @return {!Coordinate} This coordinate after scaling. + */ + scale(s: number): Coordinate; + /** + * Translates this coordinate by the given offsets. + * respectively. + * @param {number} tx The value to translate x by. + * @param {number} ty The value to translate y by. + * @return {!Coordinate} This coordinate after translating. + */ + translate(tx: number, ty: number): Coordinate; + } +} +declare module "interfaces/i_registrable" { /** - * Creates an AST node pointing to an input. Stores the input connection as the - * location. - * @param {Input} input The input used to create an AST node. - * @return {ASTNode} An AST node pointing to a input. + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - function createInputNode(input: Input): ASTNode; - /** - * Creates an AST node pointing to a block. - * @param {Block} block The block used to create an AST node. - * @return {ASTNode} An AST node pointing to a block. + * @fileoverview The interface for a Blockly component that can be registered. + * (Ex. Toolbox, Fields, Renderers) */ - function createBlockNode(block: Block): ASTNode; - /** - * Create an AST node of type stack. A stack, represented by its top block, is - * the set of all blocks connected to a top block, including the top block. - * @param {Block} topBlock A top block has no parent and can be found - * in the list returned by workspace.getTopBlocks(). - * @return {ASTNode} An AST node of type stack that points to the top - * block on the stack. + * The interface for a Blockly component that can be registered. + * (Ex. Toolbox, Fields, Renderers) + * @namespace Blockly.IRegistrable */ - function createStackNode(topBlock: Block): ASTNode; - /** - * Creates an AST node pointing to a workspace. - * @param {!Workspace} workspace The workspace that we are on. - * @param {Coordinate} wsCoordinate The position on the workspace - * for this node. - * @return {ASTNode} An AST node pointing to a workspace and a position - * on the workspace. + * The interface for a Blockly component that can be registered. + * @interface + * @alias Blockly.IRegistrable */ - function createWorkspaceNode(workspace: Workspace, wsCoordinate: Coordinate): ASTNode; - + export class IRegistrable { + } +} +declare module "interfaces/i_flyout" { /** - * Creates an AST node for the top position on a block. - * This is either an output connection, previous connection, or block. - * @param {!Block} block The block to find the top most AST node on. - * @return {ASTNode} The AST node holding the top most position on the - * block. + * Interface for a flyout. + * @extends {IRegistrable} + * @interface + * @alias Blockly.IFlyout */ - function createTopNode(block: Block): ASTNode; + export class IFlyout { + /** + * Whether the flyout is laid out horizontally or not. + * @type {boolean} + */ + horizontalLayout: boolean; + /** + * Is RTL vs LTR. + * @type {boolean} + */ + RTL: boolean; + /** + * The target workspace + * @type {?WorkspaceSvg} + */ + targetWorkspace: WorkspaceSvg | null; + /** + * Margin around the edges of the blocks in the flyout. + * @type {number} + * @const + */ + MARGIN: number; + /** + * Does the flyout automatically close when a block is created? + * @type {boolean} + */ + autoClose: boolean; + /** + * Corner radius of the flyout background. + * @type {number} + * @const + */ + CORNER_RADIUS: number; + } + import { WorkspaceSvg } from "workspace_svg"; } - - -declare module BasicCursor { - +declare module "interfaces/i_toolbox" { /** - * Name used for registering a basic cursor. - * @const {string} + * Interface for a toolbox. + * @extends {IRegistrable} + * @interface + * @alias Blockly.IToolbox */ - var registrationName: any /*missing*/; + export class IToolbox { + } } - - - - - - - -declare module exports { - +declare module "toolbox/toolbox_item" { /** - * The priority for deserializing variables. - * @type {number} - * @const - * @alias Blockly.serialization.priorities.VARIABLES + * Class for an item in the toolbox. + * @param {!toolbox.ToolboxItemInfo} toolboxItemDef The JSON defining the + * toolbox item. + * @param {!IToolbox} toolbox The toolbox that holds the toolbox item. + * @param {ICollapsibleToolboxItem=} opt_parent The parent toolbox item + * or null if the category does not have a parent. + * @constructor + * @implements {IToolboxItem} + * @alias Blockly.ToolboxItem */ - var VARIABLES: number; - + export class ToolboxItem implements IToolboxItem { + constructor(toolboxItemDef: any, toolbox: any, opt_parent: any); + /** + * The id for the category. + * @type {string} + * @protected + */ + protected id_: string; + /** + * The parent of the category. + * @type {?ICollapsibleToolboxItem} + * @protected + */ + protected parent_: ICollapsibleToolboxItem | null; + /** + * The level that the category is nested at. + * @type {number} + * @protected + */ + protected level_: number; + /** + * The JSON definition of the toolbox item. + * @type {!toolbox.ToolboxItemInfo} + * @protected + */ + protected toolboxItemDef_: any; + /** + * The toolbox this category belongs to. + * @type {!IToolbox} + * @protected + */ + protected parentToolbox_: IToolbox; + /** + * The workspace of the parent toolbox. + * @type {!WorkspaceSvg} + * @protected + */ + protected workspace_: WorkspaceSvg; + /** + * Initializes the toolbox item. + * This includes creating the DOM and updating the state of any items based + * on the info object. + * @public + */ + public init(): void; + /** + * Gets the div for the toolbox item. + * @return {?Element} The div for the toolbox item. + * @public + */ + public getDiv(): Element | null; + /** + * Gets a unique identifier for this toolbox item. + * @return {string} The ID for the toolbox item. + * @public + */ + public getId(): string; + /** + * Gets the parent if the toolbox item is nested. + * @return {?IToolboxItem} The parent toolbox item, or null if + * this toolbox item is not nested. + * @public + */ + public getParent(): IToolboxItem | null; + /** + * Gets the nested level of the category. + * @return {number} The nested level of the category. + * @package + */ + getLevel(): number; + /** + * Whether the toolbox item is selectable. + * @return {boolean} True if the toolbox item can be selected. + * @public + */ + public isSelectable(): boolean; + /** + * Whether the toolbox item is collapsible. + * @return {boolean} True if the toolbox item is collapsible. + * @public + */ + public isCollapsible(): boolean; + /** + * Dispose of this toolbox item. No-op by default. + * @public + */ + public dispose(): void; + } + import { IToolboxItem } from "interfaces/i_toolbox_item"; + import { ICollapsibleToolboxItem } from "interfaces/i_collapsible_toolbox_item"; + import { IToolbox } from "interfaces/i_toolbox"; + import { WorkspaceSvg } from "workspace_svg"; +} +declare module "toolbox/category" { + import { ToolboxItem } from "toolbox/toolbox_item"; + export class ToolboxCategory extends ToolboxItem { + /** + * Class for a category in a toolbox. + * @param {!toolbox.CategoryInfo} categoryDef The information needed + * to create a category in the toolbox. + * @param {!IToolbox} toolbox The parent toolbox for the category. + * @param {ICollapsibleToolboxItem=} opt_parent The parent category or null if + * the category does not have a parent. + * @constructor + * @extends {ToolboxItem} + * @implements {ISelectableToolboxItem} + * @alias Blockly.ToolboxCategory + */ + constructor(categoryDef: toolbox.CategoryInfo, toolbox: IToolbox, opt_parent?: ICollapsibleToolboxItem | undefined); + /** + * The name that will be displayed on the category. + * @type {string} + * @protected + */ + protected name_: string; + /** + * The colour of the category. + * @type {string} + * @protected + */ + protected colour_: string; + /** + * The html container for the category. + * @type {?Element} + * @protected + */ + protected htmlDiv_: Element | null; + /** + * The html element for the category row. + * @type {?Element} + * @protected + */ + protected rowDiv_: Element | null; + /** + * The html element that holds children elements of the category row. + * @type {?Element} + * @protected + */ + protected rowContents_: Element | null; + /** + * The html element for the toolbox icon. + * @type {?Element} + * @protected + */ + protected iconDom_: Element | null; + /** + * The html element for the toolbox label. + * @type {?Element} + * @protected + */ + protected labelDom_: Element | null; + /** + * All the css class names that are used to create a category. + * @type {!ToolboxCategory.CssConfig} + * @protected + */ + protected cssConfig_: ToolboxCategory.CssConfig; + /** + * True if the category is meant to be hidden, false otherwise. + * @type {boolean} + * @protected + */ + protected isHidden_: boolean; + /** + * True if this category is disabled, false otherwise. + * @type {boolean} + * @protected + */ + protected isDisabled_: boolean; + /** + * The flyout items for this category. + * @type {string|!toolbox.FlyoutItemInfoArray} + * @protected + */ + protected flyoutItems_: string | toolbox.FlyoutItemInfoArray; + /** + * Creates an object holding the default classes for a category. + * @return {!ToolboxCategory.CssConfig} The configuration object holding + * all the CSS classes for a category. + * @protected + */ + protected makeDefaultCssConfig_(): ToolboxCategory.CssConfig; + /** + * Parses the contents array depending on if the category is a dynamic category, + * or if its contents are meant to be shown in the flyout. + * @param {!toolbox.CategoryInfo} categoryDef The information needed + * to create a category. + * @protected + */ + protected parseContents_(categoryDef: toolbox.CategoryInfo): void; + /** + * @override + */ + override init(): void; + /** + * Creates the DOM for the category. + * @return {!Element} The parent element for the category. + * @protected + */ + protected createDom_(): Element; + /** + * Creates the container that holds the row and any subcategories. + * @return {!Element} The div that holds the icon and the label. + * @protected + */ + protected createContainer_(): Element; + /** + * Creates the parent of the contents container. All clicks will happen on this + * div. + * @return {!Element} The div that holds the contents container. + * @protected + */ + protected createRowContainer_(): Element; + /** + * Creates the container for the label and icon. + * This is necessary so we can set all subcategory pointer events to none. + * @return {!Element} The div that holds the icon and the label. + * @protected + */ + protected createRowContentsContainer_(): Element; + /** + * Creates the span that holds the category icon. + * @return {!Element} The span that holds the category icon. + * @protected + */ + protected createIconDom_(): Element; + /** + * Creates the span that holds the category label. + * This should have an ID for accessibility purposes. + * @param {string} name The name of the category. + * @return {!Element} The span that holds the category label. + * @protected + */ + protected createLabelDom_(name: string): Element; + /** + * Updates the colour for this category. + * @public + */ + public refreshTheme(): void; + /** + * Add the strip of colour to the toolbox category. + * @param {string} colour The category colour. + * @protected + */ + protected addColourBorder_(colour: string): void; + /** + * Gets either the colour or the style for a category. + * @param {!toolbox.CategoryInfo} categoryDef The object holding + * information on the category. + * @return {string} The hex colour for the category. + * @protected + */ + protected getColour_(categoryDef: toolbox.CategoryInfo): string; + /** + * Sets the colour for the category using the style name and returns the new + * colour as a hex string. + * @param {string} styleName Name of the style. + * @return {string} The hex colour for the category. + * @private + */ + private getColourfromStyle_; + /** + * Gets the HTML element that is clickable. + * The parent toolbox element receives clicks. The parent toolbox will add an ID + * to this element so it can pass the onClick event to the correct toolboxItem. + * @return {!Element} The HTML element that receives clicks. + * @public + */ + public getClickTarget(): Element; + /** + * Parses the colour on the category. + * @param {number|string} colourValue HSV hue value (0 to 360), #RRGGBB string, + * or a message reference string pointing to one of those two values. + * @return {string} The hex colour for the category. + * @private + */ + private parseColour_; + /** + * Adds appropriate classes to display an open icon. + * @param {?Element} iconDiv The div that holds the icon. + * @protected + */ + protected openIcon_(iconDiv: Element | null): void; + /** + * Adds appropriate classes to display a closed icon. + * @param {?Element} iconDiv The div that holds the icon. + * @protected + */ + protected closeIcon_(iconDiv: Element | null): void; + /** + * Sets whether the category is visible or not. + * For a category to be visible its parent category must also be expanded. + * @param {boolean} isVisible True if category should be visible. + * @protected + */ + protected setVisible_(isVisible: boolean): void; + /** + * Hide the category. + */ + hide(): void; + /** + * Show the category. Category will only appear if its parent category is also + * expanded. + */ + show(): void; + /** + * Whether the category is visible. + * A category is only visible if all of its ancestors are expanded and isHidden_ + * is false. + * @return {boolean} True if the category is visible, false otherwise. + * @public + */ + public isVisible(): boolean; + /** + * Whether all ancestors of a category (parent and parent's parent, etc.) are + * expanded. + * @return {boolean} True only if every ancestor is expanded + * @protected + */ + protected allAncestorsExpanded_(): boolean; + /** + * @override + */ + override isSelectable(): boolean; + /** + * Handles when the toolbox item is clicked. + * @param {!Event} _e Click event to handle. + * @public + */ + public onClick(_e: Event): void; + /** + * Sets the current category as selected. + * @param {boolean} isSelected True if this category is selected, false + * otherwise. + * @public + */ + public setSelected(isSelected: boolean): void; + /** + * Sets whether the category is disabled. + * @param {boolean} isDisabled True to disable the category, false otherwise. + */ + setDisabled(isDisabled: boolean): void; + /** + * Gets the name of the category. Used for emitting events. + * @return {string} The name of the toolbox item. + * @public + */ + public getName(): string; + /** + * @override + */ + override getParent(): any; + /** + * @override + */ + override getDiv(): Element; + /** + * Gets the contents of the category. These are items that are meant to be + * displayed in the flyout. + * @return {!toolbox.FlyoutItemInfoArray|string} The definition + * of items to be displayed in the flyout. + * @public + */ + public getContents(): any | string; + /** + * Updates the contents to be displayed in the flyout. + * If the flyout is open when the contents are updated, refreshSelection on the + * toolbox must also be called. + * @param {!toolbox.FlyoutDefinition|string} contents The contents + * to be displayed in the flyout. A string can be supplied to create a + * dynamic category. + * @public + */ + public updateFlyoutContents(contents: toolbox.FlyoutDefinition | string): void; + /** + * @override + */ + override dispose(): void; + } + export namespace ToolboxCategory { + const registrationName: string; + const nestedPadding: number; + const borderWidth: number; + const defaultBackgroundColour: string; + /** + * All the CSS class names that are used to create a category. + */ + type CssConfig = { + container: (string | undefined); + row: (string | undefined); + rowcontentcontainer: (string | undefined); + icon: (string | undefined); + label: (string | undefined); + selected: (string | undefined); + openicon: (string | undefined); + closedicon: (string | undefined); + }; + } + import * as toolbox from "utils/toolbox"; + import { IToolbox } from "interfaces/i_toolbox"; + import { ICollapsibleToolboxItem } from "interfaces/i_collapsible_toolbox_item"; +} +declare module "toolbox/separator" { + import { ToolboxItem } from "toolbox/toolbox_item"; /** - * The priority for deserializing blocks. - * @type {number} - * @const - * @alias Blockly.serialization.priorities.BLOCKS + * Class for a toolbox separator. This is the thin visual line that appears on + * the toolbox. This item is not interactable. + * @param {!toolbox.SeparatorInfo} separatorDef The information + * needed to create a separator. + * @param {!IToolbox} toolbox The parent toolbox for the separator. + * @constructor + * @extends {ToolboxItem} + * @alias Blockly.ToolboxSeparator */ - var BLOCKS: number; + export class ToolboxSeparator extends ToolboxItem { + constructor(separatorDef: any, toolbox: any); + /** + * All the CSS class names that are used to create a separator. + * @type {!ToolboxSeparator.CssConfig} + * @protected + */ + protected cssConfig_: ToolboxSeparator.CssConfig; + /** + * @override + */ + override init(): void; + /** + * Creates the DOM for a separator. + * @return {!Element} The parent element for the separator. + * @protected + */ + protected createDom_(): Element; + htmlDiv_: HTMLDivElement; + /** + * @override + */ + override getDiv(): HTMLDivElement; + /** + * @override + */ + override dispose(): void; + } + export namespace ToolboxSeparator { + const registrationName: string; + /** + * All the CSS class names that are used to create a separator. + */ + type CssConfig = { + container: (string | undefined); + }; + } } - - - - - - - - -declare module ToolboxCategory { +declare module "utils/toolbox" { +/** + * The information needed to create a block in the toolbox. + * Note that disabled has a different type for backwards compatibility. + * @typedef {{ + * kind:string, + * blockxml:(string|!Node|undefined), + * type:(string|undefined), + * gap:(string|number|undefined), + * disabled: (string|boolean|undefined), + * enabled: (boolean|undefined), + * id: (string|undefined), + * x: (number|undefined), + * y: (number|undefined), + * collapsed: (boolean|undefined), + * inline: (boolean|undefined), + * data: (string|undefined), + * extra-state: (*|undefined), + * icons: (!Object|undefined), + * fields: (!Object|undefined), + * inputs: (!Object|undefined), + * next: (!ConnectionState|undefined) + * }} + * @alias Blockly.utils.toolbox.BlockInfo + */ +export type BlockInfo = any; + /** + * An array holding flyout items. + * @typedef { + * Array + * } + * @alias Blockly.utils.toolbox.FlyoutItemInfoArray + */ + export type FlyoutItemInfoArray = any; /** - * All the CSS class names that are used to create a category. - * @typedef {{ - * container:(string|undefined), - * row:(string|undefined), - * rowcontentcontainer:(string|undefined), - * icon:(string|undefined), - * label:(string|undefined), - * selected:(string|undefined), - * openicon:(string|undefined), - * closedicon:(string|undefined) - * }} + * The information needed to create a separator in the toolbox. */ - interface CssConfig { - container: string|any /*undefined*/; - row: string|any /*undefined*/; - rowcontentcontainer: string|any /*undefined*/; - icon: string|any /*undefined*/; - label: string|any /*undefined*/; - selected: string|any /*undefined*/; - openicon: string|any /*undefined*/; - closedicon: string|any /*undefined*/ - } - + export type SeparatorInfo = { + kind: string; + id: (string | undefined); + gap: (number | undefined); + cssconfig: (ToolboxSeparator.CssConfig | undefined); + }; /** - * Name used for registering a toolbox category. - * @const {string} + * The information needed to create a separator in the toolbox. + * @typedef {{ + * kind:string, + * id:(string|undefined), + * gap:(number|undefined), + * cssconfig:(!ToolboxSeparator.CssConfig|undefined) + * }} + * @alias Blockly.utils.toolbox.SeparatorInfo */ - var registrationName: any /*missing*/; - + export let SeparatorInfo: any; /** - * The number of pixels to move the category over at each nested level. - * @type {number} + * The information needed to create a button in the toolbox. */ - var nestedPadding: number; - + export type ButtonInfo = { + kind: string; + text: string; + callbackkey: string; + }; /** - * The width in pixels of the strip of colour next to each category. - * @type {number} + * The information needed to create a button in the toolbox. + * @typedef {{ + * kind:string, + * text:string, + * callbackkey:string + * }} + * @alias Blockly.utils.toolbox.ButtonInfo */ - var borderWidth: number; - + export let ButtonInfo: any; /** - * The default colour of the category. This is used as the background colour of - * the category when it is selected. - * @type {string} + * The information needed to create a label in the toolbox. */ - var defaultBackgroundColour: string; -} - - -declare module CollapsibleToolboxCategory { - + export type LabelInfo = { + kind: string; + text: string; + id: (string | undefined); + }; /** - * All the CSS class names that are used to create a collapsible - * category. This is all the properties from the regular category plus contents. + * The information needed to create a label in the toolbox. * @typedef {{ - * container:?string, - * row:?string, - * rowcontentcontainer:?string, - * icon:?string, - * label:?string, - * selected:?string, - * openicon:?string, - * closedicon:?string, - * contents:?string + * kind:string, + * text:string, + * id:(string|undefined) * }} + * @alias Blockly.utils.toolbox.LabelInfo */ - interface CssConfig { - container: string; - row: string; - rowcontentcontainer: string; - icon: string; - label: string; - selected: string; - openicon: string; - closedicon: string; - contents: string - } - + export let LabelInfo: any; /** - * Name used for registering a collapsible toolbox category. - * @const {string} + * The information needed to create either a button or a label in the flyout. */ - var registrationName: any /*missing*/; -} - - -declare module ToolboxSeparator { - + export type ButtonOrLabelInfo = ButtonInfo | LabelInfo; + /** + * The information needed to create either a button or a label in the flyout. + * @typedef {ButtonInfo| + * LabelInfo} + * @alias Blockly.utils.toolbox.ButtonOrLabelInfo + */ + export let ButtonOrLabelInfo: any; + /** + * The information needed to create a category in the toolbox. + */ + export type StaticCategoryInfo = { + kind: string; + name: string; + contents: Array; + id: (string | undefined); + categorystyle: (string | undefined); + colour: (string | undefined); + cssconfig: (ToolboxCategory.CssConfig | undefined); + hidden: (string | undefined); + }; /** - * All the CSS class names that are used to create a separator. + * The information needed to create a category in the toolbox. * @typedef {{ - * container:(string|undefined) + * kind:string, + * name:string, + * contents:!Array, + * id:(string|undefined), + * categorystyle:(string|undefined), + * colour:(string|undefined), + * cssconfig:(!ToolboxCategory.CssConfig|undefined), + * hidden:(string|undefined) * }} + * @alias Blockly.utils.toolbox.StaticCategoryInfo */ - interface CssConfig { - container: string|any /*undefined*/ - } - + export let StaticCategoryInfo: any; /** - * Name used for registering a toolbox separator. - * @const {string} + * The information needed to create a custom category. */ - var registrationName: any /*missing*/; -} - - - - - - -declare module Coordinate { - + export type DynamicCategoryInfo = { + kind: string; + custom: string; + id: (string | undefined); + categorystyle: (string | undefined); + colour: (string | undefined); + cssconfig: (ToolboxCategory.CssConfig | undefined); + hidden: (string | undefined); + }; /** - * Compares coordinates for equality. - * @param {?Coordinate} a A Coordinate. - * @param {?Coordinate} b A Coordinate. - * @return {boolean} True iff the coordinates are equal, or if both are null. + * The information needed to create a custom category. + * @typedef {{ + * kind:string, + * custom:string, + * id:(string|undefined), + * categorystyle:(string|undefined), + * colour:(string|undefined), + * cssconfig:(!ToolboxCategory.CssConfig|undefined), + * hidden:(string|undefined) + * }} + * @alias Blockly.utils.toolbox.DynamicCategoryInfo */ - function equals(a: Coordinate, b: Coordinate): boolean; - + export let DynamicCategoryInfo: any; /** - * Returns the distance between two coordinates. - * @param {!Coordinate} a A Coordinate. - * @param {!Coordinate} b A Coordinate. - * @return {number} The distance between `a` and `b`. + * The information needed to create either a dynamic or static category. */ - function distance(a: Coordinate, b: Coordinate): number; - + export type CategoryInfo = StaticCategoryInfo | DynamicCategoryInfo; /** - * Returns the magnitude of a coordinate. - * @param {!Coordinate} a A Coordinate. - * @return {number} The distance between the origin and `a`. + * The information needed to create either a dynamic or static category. + * @typedef {StaticCategoryInfo| + * DynamicCategoryInfo} + * @alias Blockly.utils.toolbox.CategoryInfo */ - function magnitude(a: Coordinate): number; - + export let CategoryInfo: any; /** - * Returns the difference between two coordinates as a new - * Coordinate. - * @param {!Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Coordinate} A Coordinate representing the difference - * between `a` and `b`. + * Any information that can be used to create an item in the toolbox. */ - function difference(a: Coordinate|SVGPoint, b: Coordinate|SVGPoint): Coordinate; - + export type ToolboxItemInfo = FlyoutItemInfo | StaticCategoryInfo; /** - * Returns the sum of two coordinates as a new Coordinate. - * @param {!Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Coordinate} A Coordinate representing the sum of - * the two coordinates. + * Any information that can be used to create an item in the toolbox. + * @typedef {FlyoutItemInfo| + * StaticCategoryInfo} + * @alias Blockly.utils.toolbox.ToolboxItemInfo */ - function sum(a: Coordinate|SVGPoint, b: Coordinate|SVGPoint): Coordinate; -} - - - - -declare module exports { - + export let ToolboxItemInfo: any; /** - * Reference to the global object. - * - * More info on this implementation here: - * https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI + * All the different types that can be displayed in a flyout. */ - var globalThis: any /*missing*/; -} - - -declare module internal { - + export type FlyoutItemInfo = any | SeparatorInfo | ButtonInfo | LabelInfo | DynamicCategoryInfo; /** - * 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. + * All the different types that can be displayed in a flyout. + * @typedef {BlockInfo| + * SeparatorInfo| + * ButtonInfo| + * LabelInfo| + * DynamicCategoryInfo} + * @alias Blockly.utils.toolbox.FlyoutItemInfo */ - function genUid(): string; -} - - - - - - - -declare module Size { - + export let FlyoutItemInfo: any; /** - * 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. + * The JSON definition of a toolbox. */ - function equals(a: Size, b: Size): boolean; -} - - - - -declare module Svg { - + export type ToolboxInfo = { + kind: (string | undefined); + contents: Array; + }; /** - * @type {!Svg} - * @package + * The JSON definition of a toolbox. + * @typedef {{ + * kind:(string|undefined), + * contents:!Array + * }} + * @alias Blockly.utils.toolbox.ToolboxInfo */ - var ANIMATE: Svg; - + export let ToolboxInfo: any; /** - * @type {!Svg} - * @package + * An array holding flyout items. + * @typedef { + * Array + * } + * @alias Blockly.utils.toolbox.FlyoutItemInfoArray */ - var CIRCLE: Svg; - + export let FlyoutItemInfoArray: any; /** - * @type {!Svg} - * @package + * All of the different types that can create a toolbox. */ - var CLIPPATH: Svg; - + export type ToolboxDefinition = Node | ToolboxInfo | string; /** - * @type {!Svg} - * @package + * All of the different types that can create a toolbox. + * @typedef {Node| + * ToolboxInfo| + * string} + * @alias Blockly.utils.toolbox.ToolboxDefinition */ - var DEFS: Svg; - + export let ToolboxDefinition: any; /** - * @type {!Svg} - * @package + * All of the different types that can be used to show items in a flyout. */ - var FECOMPOSITE: Svg; - + export type FlyoutDefinition = any | NodeList | ToolboxInfo | Array; /** - * @type {!Svg} - * @package + * All of the different types that can be used to show items in a flyout. + * @typedef {FlyoutItemInfoArray| + * NodeList| + * ToolboxInfo| + * Array} + * @alias Blockly.utils.toolbox.FlyoutDefinition */ - var FECOMPONENTTRANSFER: Svg; - + export let FlyoutDefinition: any; /** - * @type {!Svg} - * @package + * * */ - var FEFLOOD: Svg; - + export type Position = number; + export namespace Position { + const TOP: number; + const BOTTOM: number; + const LEFT: number; + const RIGHT: number; + } /** - * @type {!Svg} + * Converts the toolbox definition into toolbox JSON. + * @param {?ToolboxDefinition} toolboxDef The definition + * of the toolbox in one of its many forms. + * @return {?ToolboxInfo} Object holding information + * for creating a toolbox. + * @alias Blockly.utils.toolbox.convertToolboxDefToJson * @package */ - var FEFUNCA: Svg; - + export function convertToolboxDefToJson(toolboxDef: ToolboxDefinition | null): ToolboxInfo | null; /** - * @type {!Svg} + * Converts the flyout definition into a list of flyout items. + * @param {?FlyoutDefinition} flyoutDef The definition of + * the flyout in one of its many forms. + * @return {!FlyoutItemInfoArray} A list of flyout items. + * @alias Blockly.utils.toolbox.convertFlyoutDefToJsonArray * @package */ - var FEGAUSSIANBLUR: Svg; - + export function convertFlyoutDefToJsonArray(flyoutDef: FlyoutDefinition | null): any; /** - * @type {!Svg} + * Whether or not the toolbox definition has categories. + * @param {?ToolboxInfo} toolboxJson Object holding + * information for creating a toolbox. + * @return {boolean} True if the toolbox has categories. + * @alias Blockly.utils.toolbox.hasCategories * @package */ - var FEPOINTLIGHT: Svg; - + export function hasCategories(toolboxJson: ToolboxInfo | null): boolean; /** - * @type {!Svg} + * Whether or not the category is collapsible. + * @param {!CategoryInfo} categoryInfo Object holing + * information for creating a category. + * @return {boolean} True if the category has subcategories. + * @alias Blockly.utils.toolbox.isCategoryCollapsible * @package */ - var FESPECULARLIGHTING: Svg; - + export function isCategoryCollapsible(categoryInfo: CategoryInfo): boolean; /** - * @type {!Svg} - * @package + * Parse the provided toolbox tree into a consistent DOM format. + * @param {?Node|?string} toolboxDef DOM tree of blocks, or text representation + * of same. + * @return {?Node} DOM tree of blocks, or null. + * @alias Blockly.utils.toolbox.parseToolboxTree */ - var FILTER: Svg; - + export function parseToolboxTree(toolboxDef: (Node | (string | null)) | null): Node | null; + import { ToolboxSeparator } from "toolbox/separator"; + import { ToolboxCategory } from "toolbox/category"; +} +declare module "blockly_options" { /** - * @type {!Svg} - * @package + * @license + * Copyright 2016 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var FOREIGNOBJECT: Svg; - /** - * @type {!Svg} - * @package + * @fileoverview Object that defines user-specified options for the workspace. */ - var G: Svg; - /** - * @type {!Svg} - * @package + * Object that defines user-specified options for the workspace. + * @namespace Blockly.BlocklyOptions */ - var IMAGE: Svg; - /** - * @type {!Svg} - * @package + * Blockly options. + * This interface is further described in + * `typings/parts/blockly-interfaces.d.ts`. + * @interface + * @alias Blockly.BlocklyOptions */ - var LINE: Svg; - + export class BlocklyOptions { + } +} +declare module "utils/svg_paths" { /** - * @type {!Svg} - * @package + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var PATH: Svg; - /** - * @type {!Svg} - * @package + * @fileoverview Methods for creating parts of SVG path strings. See + * developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths */ - var PATTERN: Svg; - /** - * @type {!Svg} - * @package + * Methods for creating parts of SVG path strings. See + * @namespace Blockly.utils.svgPaths */ - var POLYGON: Svg; - /** - * @type {!Svg} - * @package + * Create a string representing the given x, y pair. It does not matter whether + * the coordinate is relative or absolute. The result has leading + * and trailing spaces, and separates the x and y coordinates with a comma but + * no space. + * @param {number} x The x coordinate. + * @param {number} y The y coordinate. + * @return {string} A string of the format ' x,y ' + * @alias Blockly.utils.svgPaths.point */ - var RECT: Svg; - + export function point(x: number, y: number): string; /** - * @type {!Svg} - * @package + * Draw a cubic or quadratic curve. See + * developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#Cubic_B%C3%A9zier_Curve + * These coordinates are unitless and hence in the user coordinate system. + * @param {string} command The command to use. + * Should be one of: c, C, s, S, q, Q. + * @param {!Array} points An array containing all of the points to pass + * to the curve command, in order. The points are represented as strings of + * the format ' x, y '. + * @return {string} A string defining one or more Bezier curves. See the MDN + * documentation for exact format. + * @alias Blockly.utils.svgPaths.curve */ - var SVG: Svg; - + export function curve(command: string, points: Array): string; /** - * @type {!Svg} - * @package + * Move the cursor to the given position without drawing a line. + * The coordinates are absolute. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands + * @param {number} x The absolute x coordinate. + * @param {number} y The absolute y coordinate. + * @return {string} A string of the format ' M x,y ' + * @alias Blockly.utils.svgPaths.moveTo */ - var TEXT: Svg; - + export function moveTo(x: number, y: number): string; /** - * @type {!Svg} - * @package + * Move the cursor to the given position without drawing a line. + * Coordinates are relative. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands + * @param {number} dx The relative x coordinate. + * @param {number} dy The relative y coordinate. + * @return {string} A string of the format ' m dx,dy ' + * @alias Blockly.utils.svgPaths.moveBy */ - var TSPAN: Svg; -} - - - - -declare module exports { - - /** @const {string} - * @alias Blockly.utils.userAgent.raw + export function moveBy(dx: number, dy: number): string; + /** + * Draw a line from the current point to the end point, which is the current + * point shifted by dx along the x-axis and dy along the y-axis. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands + * @param {number} dx The relative x coordinate. + * @param {number} dy The relative y coordinate. + * @return {string} A string of the format ' l dx,dy ' + * @alias Blockly.utils.svgPaths.lineTo */ - var raw: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.IE + export function lineTo(dx: number, dy: number): string; + /** + * Draw multiple lines connecting all of the given points in order. This is + * equivalent to a series of 'l' commands. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Line_commands + * @param {!Array} points An array containing all of the points to + * draw lines to, in order. The points are represented as strings of the + * format ' dx,dy '. + * @return {string} A string of the format ' l (dx,dy)+ ' + * @alias Blockly.utils.svgPaths.line */ - var IE: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.EDGE + export function line(points: Array): string; + /** + * Draw a horizontal or vertical line. + * The first argument specifies the direction and whether the given position is + * relative or absolute. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#LineTo_path_commands + * @param {string} command The command to prepend to the coordinate. This + * should be one of: V, v, H, h. + * @param {number} val The coordinate to pass to the command. It may be + * absolute or relative. + * @return {string} A string of the format ' command val ' + * @alias Blockly.utils.svgPaths.lineOnAxis */ - var EDGE: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.JavaFx + export function lineOnAxis(command: string, val: number): string; + /** + * Draw an elliptical arc curve. + * These coordinates are unitless and hence in the user coordinate system. + * See developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#Elliptical_Arc_Curve + * @param {string} command The command string. Either 'a' or 'A'. + * @param {string} flags The flag string. See the MDN documentation for a + * description and examples. + * @param {number} radius The radius of the arc to draw. + * @param {string} point The point to move the cursor to after drawing the arc, + * specified either in absolute or relative coordinates depending on the + * command. + * @return {string} A string of the format 'command radius radius flags point' + * @alias Blockly.utils.svgPaths.arc */ - var JavaFx: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.CHROME + export function arc(command: string, flags: string, radius: number, point: string): string; +} +declare module "utils/style" { + /** + * Gets the height and width of an element. + * Similar to Closure's goog.style.getSize + * @param {!Element} element Element to get size of. + * @return {!Size} Object with width/height properties. + * @alias Blockly.utils.style.getSize */ - var CHROME: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.WEBKIT + export function getSize(element: Element): Size; + /** + * Retrieves a computed style value of a node. It returns empty string if the + * value cannot be computed (which will be the case in Internet Explorer) or + * "none" if the property requested is an SVG one and it has not been + * explicitly set (firefox and webkit). + * + * Copied from Closure's goog.style.getComputedStyle + * + * @param {!Element} element Element to get style of. + * @param {string} property Property to get (camel-case). + * @return {string} Style value. + * @alias Blockly.utils.style.getComputedStyle */ - var WEBKIT: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.GECKO + export function getComputedStyle(element: Element, property: string): string; + /** + * Gets the cascaded style value of a node, or null if the value cannot be + * computed (only Internet Explorer can do this). + * + * Copied from Closure's goog.style.getCascadedStyle + * + * @param {!Element} element Element to get style of. + * @param {string} style Property to get (camel-case). + * @return {string} Style value. + * @alias Blockly.utils.style.getCascadedStyle */ - var GECKO: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.ANDROID + export function getCascadedStyle(element: Element, style: string): string; + /** + * Returns a Coordinate object relative to the top-left of the HTML document. + * Similar to Closure's goog.style.getPageOffset + * @param {!Element} el Element to get the page offset for. + * @return {!Coordinate} The page offset. + * @alias Blockly.utils.style.getPageOffset */ - var ANDROID: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.IPAD + export function getPageOffset(el: Element): Coordinate; + /** + * Calculates the viewport coordinates relative to the document. + * Similar to Closure's goog.style.getViewportPageOffset + * @return {!Coordinate} The page offset of the viewport. + * @alias Blockly.utils.style.getViewportPageOffset */ - var IPAD: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.IPOD + export function getViewportPageOffset(): Coordinate; + /** + * Shows or hides an element from the page. Hiding the element is done by + * setting the display property to "none", removing the element from the + * rendering hierarchy so it takes up no space. To show the element, the default + * inherited display property is restored (defined either in stylesheets or by + * the browser's default style rules). + * Copied from Closure's goog.style.getViewportPageOffset + * + * @param {!Element} el Element to show or hide. + * @param {*} isShown True to render the element in its default style, + * false to disable rendering the element. + * @alias Blockly.utils.style.setElementShown */ - var IPOD: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.IPHONE + export function setElementShown(el: Element, isShown: any): void; + /** + * Returns true if the element is using right to left (RTL) direction. + * Copied from Closure's goog.style.isRightToLeft + * + * @param {!Element} el The element to test. + * @return {boolean} True for right to left, false for left to right. + * @alias Blockly.utils.style.isRightToLeft */ - var IPHONE: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.MAC + export function isRightToLeft(el: Element): boolean; + /** + * Gets the computed border widths (on all sides) in pixels + * Copied from Closure's goog.style.getBorderBox + * @param {!Element} element The element to get the border widths for. + * @return {!Object} The computed border widths. + * @alias Blockly.utils.style.getBorderBox */ - var MAC: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.TABLET + export function getBorderBox(element: Element): any; + /** + * Changes the scroll position of `container` with the minimum amount so + * that the content and the borders of the given `element` become visible. + * If the element is bigger than the container, its top left corner will be + * aligned as close to the container's top left corner as possible. + * Copied from Closure's goog.style.scrollIntoContainerView + * + * @param {!Element} element The element to make visible. + * @param {!Element} container The container to scroll. If not set, then the + * document scroll element will be used. + * @param {boolean=} opt_center Whether to center the element in the container. + * Defaults to false. + * @alias Blockly.utils.style.scrollIntoContainerView */ - var TABLET: any /*missing*/; - - /** @const {boolean} - * @alias Blockly.utils.userAgent.MOBILE + export function scrollIntoContainerView(element: Element, container: Element, opt_center?: boolean | undefined): void; + /** + * Calculate the scroll position of `container` with the minimum amount so + * that the content and the borders of the given `element` become visible. + * If the element is bigger than the container, its top left corner will be + * aligned as close to the container's top left corner as possible. + * Copied from Closure's goog.style.getContainerOffsetToScrollInto + * + * @param {!Element} element The element to make visible. + * @param {!Element} container The container to scroll. If not set, then the + * document scroll element will be used. + * @param {boolean=} opt_center Whether to center the element in the container. + * Defaults to false. + * @return {!Coordinate} The new scroll position of the container, + * in form of goog.math.Coordinate(scrollLeft, scrollTop). + * @alias Blockly.utils.style.getContainerOffsetToScrollInto */ - var MOBILE: any /*missing*/; + export function getContainerOffsetToScrollInto(element: Element, container: Element, opt_center?: boolean | undefined): Coordinate; + import { Size } from "utils/size"; + import { Coordinate } from "utils/coordinate"; } - - - - - - -declare module Debug { - +declare module "utils/rect" { /** - * Configuration object containing booleans to enable and disable debug - * rendering of specific rendering components. - * @type {!Object} + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 */ - var config: { [key: string]: boolean }; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -declare module Types { - /** - * A Left Corner Union Type. - * @type {number} - * @const - * @package + * @fileoverview Utility methods for rectangle manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. */ - var LEFT_CORNER: number; - /** - * A Right Corner Union Type. - * @type {number} - * @const - * @package + * Utility methods for rectangle manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. + * @class */ - var RIGHT_CORNER: number; - /** - * Get the enum flag value of an existing type or register a new type. - * @param {!string} type The name of the type. - * @return {!number} The enum flag value associated with that type. - * @package + * Class for representing rectangular regions. + * @param {number} top Top. + * @param {number} bottom Bottom. + * @param {number} left Left. + * @param {number} right Right. + * @struct + * @constructor + * @alias Blockly.utils.Rect */ - function getType(type: string): number; - + export class Rect { + constructor(top: any, bottom: any, left: any, right: any); + /** @type {number} */ + top: number; + /** @type {number} */ + bottom: number; + /** @type {number} */ + left: number; + /** @type {number} */ + right: number; + /** + * Tests whether this rectangle contains a x/y coordinate. + * + * @param {number} x The x coordinate to test for containment. + * @param {number} y The y coordinate to test for containment. + * @return {boolean} Whether this rectangle contains given coordinate. + */ + contains(x: number, y: number): boolean; + /** + * Tests whether this rectangle intersects the provided rectangle. + * Assumes that the coordinate system increases going down and left. + * @param {!Rect} other The other rectangle to check for + * intersection with. + * @return {boolean} Whether this rectangle intersects the provided rectangle. + */ + intersects(other: Rect): boolean; + } +} +declare module "utils/svg_math" { + export namespace TEST_ONLY { + export { XY_REGEX }; + export { XY_STYLE_REGEX }; + } /** - * Whether a measurable stores information about a field. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a field. - * @package + * Return the coordinates of the top-left corner of this element relative to + * its parent. Only for SVG elements and children (e.g. rect, g, path). + * @param {!Element} element SVG element to find the coordinates of. + * @return {!Coordinate} Object with .x and .y properties. + * @alias Blockly.svgMath.getRelativeXY */ - function isField(elem: Measurable): number; - + export function getRelativeXY(element: Element): Coordinate; /** - * Whether a measurable stores information about a hat. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a hat. - * @package + * Return the coordinates of the top-left corner of this element relative to + * the div Blockly was injected into. + * @param {!Element} element SVG element to find the coordinates of. If this is + * not a child of the div Blockly was injected into, the behaviour is + * undefined. + * @return {!Coordinate} Object with .x and .y properties. + * @alias Blockly.svgMath.getInjectionDivXY */ - function isHat(elem: Measurable): number; - + export function getInjectionDivXY(element: Element): Coordinate; /** - * Whether a measurable stores information about an icon. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about an icon. - * @package + * Check if 3D transforms are supported by adding an element + * and attempting to set the property. + * @return {boolean} True if 3D transforms are supported. + * @alias Blockly.svgMath.is3dSupported */ - function isIcon(elem: Measurable): number; - + export function is3dSupported(): boolean; /** - * Whether a measurable stores information about a spacer. - * @param {!Measurable|!Row} elem - * The element to check. - * @return {number} 1 if the object stores information about a spacer. + * Get the position of the current viewport in window coordinates. This takes + * scroll into account. + * @return {!Rect} An object containing window width, height, and + * scroll position in window coordinates. + * @alias Blockly.svgMath.getViewportBBox * @package */ - function isSpacer(elem: Measurable|Row): number; - + export function getViewportBBox(): Rect; /** - * Whether a measurable stores information about an in-row spacer. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about an - * in-row spacer. - * @package + * Gets the document scroll distance as a coordinate object. + * Copied from Closure's goog.dom.getDocumentScroll. + * @return {!Coordinate} Object with values 'x' and 'y'. + * @alias Blockly.svgMath.getDocumentScroll */ - function isInRowSpacer(elem: Measurable): number; - + export function getDocumentScroll(): Coordinate; /** - * Whether a measurable stores information about an input. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about an input. - * @package + * Converts screen coordinates to workspace coordinates. + * @param {!WorkspaceSvg} ws The workspace to find the coordinates on. + * @param {!Coordinate} screenCoordinates The screen coordinates to + * be converted to workspace coordinates + * @return {!Coordinate} The workspace coordinates. + * @alias Blockly.svgMath.screenToWsCoordinates */ - function isInput(elem: Measurable): number; - + export function screenToWsCoordinates(ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate; /** - * Whether a measurable stores information about an external input. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about an - * external input. - * @package + * Returns the dimensions of the specified SVG image. + * @param {!SVGElement} svg SVG image. + * @return {!Size} Contains width and height properties. + * @deprecated Use workspace.getCachedParentSvgSize. (2021 March 5) + * @alias Blockly.utils.svgMath.svgSize */ - function isExternalInput(elem: Measurable): number; - + export function svgSize(svg: SVGElement): Size; /** - * Whether a measurable stores information about an inline input. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about an - * inline input. - * @package + * Static regex to pull the x,y values out of an SVG translate() directive. + * Note that Firefox and IE (9,10) return 'translate(12)' instead of + * 'translate(12, 0)'. + * Note that IE (9,10) returns 'translate(16 8)' instead of 'translate(16, 8)'. + * Note that IE has been reported to return scientific notation (0.123456e-42). + * @type {!RegExp} */ - function isInlineInput(elem: Measurable): number; - + const XY_REGEX: RegExp; /** - * Whether a measurable stores information about a statement input. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * statement input. - * @package + * Static regex to pull the x,y values out of a translate() or translate3d() + * style property. + * Accounts for same exceptions as XY_REGEX. + * @type {!RegExp} */ - function isStatementInput(elem: Measurable): number; - + const XY_STYLE_REGEX: RegExp; + import { Coordinate } from "utils/coordinate"; + import { Rect } from "utils/rect"; + import { WorkspaceSvg } from "workspace_svg"; + import { Size } from "utils/size"; + export {}; +} +declare module "rendered_connection" { + export class RenderedConnection extends Connection { + /** + * Class for a connection between blocks that may be rendered on screen. + * @param {!BlockSvg} source The block establishing this connection. + * @param {number} type The type of the connection. + * @extends {Connection} + * @constructor + * @alias Blockly.RenderedConnection + */ + constructor(source: BlockSvg, type: number); + /** + * Connection database for connections of this type on the current workspace. + * @const {!ConnectionDB} + * @private + */ + private db_; + /** + * Connection database for connections compatible with this type on the + * current workspace. + * @const {!ConnectionDB} + * @private + */ + private dbOpposite_; + /** + * Workspace units, (0, 0) is top left of block. + * @type {!Coordinate} + * @private + */ + private offsetInBlock_; + /** + * Describes the state of this connection's tracked-ness. + * @type {RenderedConnection.TrackedState} + * @private + */ + private trackedState_; + /** + * Connection this connection connects to. Null if not connected. + * @type {RenderedConnection} + */ + targetConnection: RenderedConnection; + /** + * Dispose of this connection. Remove it from the database (if it is + * tracked) and call the super-function to deal with connected blocks. + * @override + * @package + */ + override dispose(): void; + /** + * Get the source block for this connection. + * @return {!BlockSvg} The source block. + * @override + */ + override getSourceBlock(): BlockSvg; + /** + * Returns the block that this connection connects to. + * @return {?BlockSvg} The connected block or null if none is connected. + * @override + */ + override targetBlock(): BlockSvg | null; + /** + * Returns the distance between this connection and another connection in + * workspace units. + * @param {!Connection} otherConnection The other connection to measure + * the distance to. + * @return {number} The distance between connections, in workspace units. + */ + distanceFrom(otherConnection: Connection): number; + /** + * Move the block(s) belonging to the connection to a point where they don't + * visually interfere with the specified connection. + * @param {!Connection} staticConnection The connection to move away + * from. + * @package + */ + bumpAwayFrom(staticConnection: Connection): void; + /** + * Change the connection's coordinates. + * @param {number} x New absolute x coordinate, in workspace coordinates. + * @param {number} y New absolute y coordinate, in workspace coordinates. + */ + moveTo(x: number, y: number): void; + x: number; + y: number; + /** + * Change the connection's coordinates. + * @param {number} dx Change to x coordinate, in workspace units. + * @param {number} dy Change to y coordinate, in workspace units. + */ + moveBy(dx: number, dy: number): void; + /** + * Move this connection to the location given by its offset within the block and + * the location of the block's top left corner. + * @param {!Coordinate} blockTL The location of the top left + * corner of the block, in workspace coordinates. + */ + moveToOffset(blockTL: Coordinate): void; + /** + * Set the offset of this connection relative to the top left of its block. + * @param {number} x The new relative x, in workspace units. + * @param {number} y The new relative y, in workspace units. + */ + setOffsetInBlock(x: number, y: number): void; + /** + * Get the offset of this connection relative to the top left of its block. + * @return {!Coordinate} The offset of the connection. + * @package + */ + getOffsetInBlock(): Coordinate; + /** + * Move the blocks on either side of this connection right next to each other. + * @package + */ + tighten(): void; + /** + * Find the closest compatible connection to this connection. + * All parameters are in workspace units. + * @param {number} maxLimit The maximum radius to another connection. + * @param {!Coordinate} dxy Offset between this connection's location + * in the database and the current location (as a result of dragging). + * @return {!{connection: ?Connection, radius: number}} Contains two + * properties: 'connection' which is either another connection or null, + * and 'radius' which is the distance. + */ + closest(maxLimit: number, dxy: Coordinate): { + connection: Connection | null; + radius: number; + }; + /** + * Add highlighting around this connection. + */ + highlight(): void; + /** + * Remove the highlighting around this connection. + */ + unhighlight(): void; + /** + * Set whether this connections is tracked in the database or not. + * @param {boolean} doTracking If true, start tracking. If false, stop tracking. + * @package + */ + setTracking(doTracking: boolean): void; + /** + * Stop tracking this connection, as well as all down-stream connections on + * any block attached to this connection. This happens when a block is + * collapsed. + * + * Also closes down-stream icons/bubbles. + * @package + */ + stopTrackingAll(): void; + /** + * Start tracking this connection, as well as all down-stream connections on + * any block attached to this connection. This happens when a block is expanded. + * @return {!Array} List of blocks to render. + */ + startTrackingAll(): Array; + /** + * Check if the two connections can be dragged to connect to each other. + * @param {!Connection} candidate A nearby connection to check. + * @param {number=} maxRadius The maximum radius allowed for connections, in + * workspace units. + * @return {boolean} True if the connection is allowed, false otherwise. + * @deprecated July 2020 + */ + isConnectionAllowed(candidate: Connection, maxRadius?: number | undefined): boolean; + /** + * Behavior after a connection attempt fails. + * Bumps this connection away from the other connection. Called when an + * attempted connection fails. + * @param {!Connection} otherConnection Connection that this connection + * failed to connect to. + * @package + */ + onFailedConnect(otherConnection: Connection): void; + /** + * Disconnect two blocks that are connected by this connection. + * @param {!Block} parentBlock The superior block. + * @param {!Block} childBlock The inferior block. + * @protected + * @override + */ + protected override disconnectInternal_(parentBlock: Block, childBlock: Block): void; + /** + * Respawn the shadow block if there was one connected to the this connection. + * Render/rerender blocks as needed. + * @protected + * @override + */ + protected override respawnShadow_(): void; + /** + * Find all nearby compatible connections to this connection. + * Type checking does not apply, since this function is used for bumping. + * @param {number} maxLimit The maximum radius to another connection, in + * workspace units. + * @return {!Array} List of connections. + * @package + */ + neighbours(maxLimit: number): Array; + /** + * Connect two connections together. This is the connection on the superior + * block. Rerender blocks as needed. + * @param {!Connection} childConnection Connection on inferior block. + * @protected + */ + protected connect_(childConnection: Connection): void; + /** + * Function to be called when this connection's compatible types have changed. + * @protected + */ + protected onCheckChanged_(): void; + } + export namespace RenderedConnection { + namespace TrackedState { + const WILL_TRACK: number; + const UNTRACKED: number; + const TRACKED: number; + } + /** + * Enum for different kinds of tracked states. + * + * WILL_TRACK means that this connection will add itself to + * the db on the next moveTo call it receives. + * + * UNTRACKED means that this connection will not add + * itself to the database until setTracking(true) is explicitly called. + * + * TRACKED means that this connection is currently being tracked. + */ + type TrackedState = number; + } + import { BlockSvg } from "block_svg"; + import { Connection } from "connection"; + import { Coordinate } from "utils/coordinate"; + import { Block } from "block"; +} +declare module "interfaces/i_connection_checker" { /** - * Whether a measurable stores information about a previous connection. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * previous connection. - * @package + * Class for connection type checking logic. + * @interface + * @alias Blockly.IConnectionChecker */ - function isPreviousConnection(elem: Measurable): number; - + export class IConnectionChecker { + } +} +declare module "constants" { + /** + * * + */ + export type ALIGN = number; + export namespace ALIGN { + const LEFT: number; + const CENTRE: number; + const RIGHT: number; + } + /** + * The language-neutral ID given to the collapsed input. + * @const {string} + * @alias Blockly.constants.COLLAPSED_INPUT_NAME + */ + export const COLLAPSED_INPUT_NAME: "_TEMP_COLLAPSED_INPUT"; + /** + * The language-neutral ID given to the collapsed field. + * @const {string} + * @alias Blockly.constants.COLLAPSED_FIELD_NAME + */ + export const COLLAPSED_FIELD_NAME: "_TEMP_COLLAPSED_FIELD"; +} +declare module "connection_db" { + export class ConnectionDB { + /** + * Initialize a set of connection DBs for a workspace. + * @param {!IConnectionChecker} checker The workspace's + * connection checker, used to decide if connections are valid during a + * drag. + * @return {!Array} Array of databases. + */ + static init(checker: IConnectionChecker): Array; + /** + * Database of connections. + * Connections are stored in order of their vertical component. This way + * connections in an area may be looked up quickly using a binary search. + * @param {!IConnectionChecker} checker The workspace's + * connection type checker, used to decide if connections are valid during a + * drag. + * @constructor + * @alias Blockly.ConnectionDB + */ + constructor(checker: IConnectionChecker); + /** + * Array of connections sorted by y position in workspace units. + * @type {!Array} + * @private + */ + private connections_; + /** + * The workspace's connection type checker, used to decide if connections are + * valid during a drag. + * @type {!IConnectionChecker} + * @private + */ + private connectionChecker_; + /** + * Add a connection to the database. Should not already exist in the database. + * @param {!RenderedConnection} connection The connection to be added. + * @param {number} yPos The y position used to decide where to insert the + * connection. + * @package + */ + addConnection(connection: RenderedConnection, yPos: number): void; + /** + * Finds the index of the given connection. + * + * Starts by doing a binary search to find the approximate location, then + * linearly searches nearby for the exact connection. + * @param {!RenderedConnection} conn The connection to find. + * @param {number} yPos The y position used to find the index of the connection. + * @return {number} The index of the connection, or -1 if the connection was + * not found. + * @private + */ + private findIndexOfConnection_; + /** + * Finds the correct index for the given y position. + * @param {number} yPos The y position used to decide where to + * insert the connection. + * @return {number} The candidate index. + * @private + */ + private calculateIndexForYPos_; + /** + * Remove a connection from the database. Must already exist in DB. + * @param {!RenderedConnection} connection The connection to be removed. + * @param {number} yPos The y position used to find the index of the connection. + * @throws {Error} If the connection cannot be found in the database. + */ + removeConnection(connection: RenderedConnection, yPos: number): void; + /** + * Find all nearby connections to the given connection. + * Type checking does not apply, since this function is used for bumping. + * @param {!RenderedConnection} connection The connection whose + * neighbours should be returned. + * @param {number} maxRadius The maximum radius to another connection. + * @return {!Array} List of connections. + */ + getNeighbours(connection: RenderedConnection, maxRadius: number): Array; + /** + * Is the candidate connection close to the reference connection. + * Extremely fast; only looks at Y distance. + * @param {number} index Index in database of candidate connection. + * @param {number} baseY Reference connection's Y value. + * @param {number} maxRadius The maximum radius to another connection. + * @return {boolean} True if connection is in range. + * @private + */ + private isInYRange_; + /** + * Find the closest compatible connection to this connection. + * @param {!RenderedConnection} conn The connection searching for a compatible + * mate. + * @param {number} maxRadius The maximum radius to another connection. + * @param {!Coordinate} dxy Offset between this connection's + * location in the database and the current location (as a result of + * dragging). + * @return {!{connection: RenderedConnection, radius: number}} + * Contains two properties: 'connection' which is either another + * connection or null, and 'radius' which is the distance. + */ + searchForClosest(conn: RenderedConnection, maxRadius: number, dxy: Coordinate): { + connection: RenderedConnection; + radius: number; + }; + } + import { RenderedConnection } from "rendered_connection"; + import { Coordinate } from "utils/coordinate"; + import { IConnectionChecker } from "interfaces/i_connection_checker"; +} +declare module "interfaces/i_ast_node_location" { + /** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + /** + * @fileoverview The interface for an AST node location. + */ + /** + * The interface for an AST node location. + * @namespace Blockly.IASTNodeLocation + */ + /** + * An AST node location interface. + * @interface + * @alias Blockly.IASTNodeLocation + */ + export class IASTNodeLocation { + } +} +declare module "theme" { + /** + * Class for a theme. + * @param {string} name Theme name. + * @param {!Object=} opt_blockStyles A map + * from style names (strings) to objects with style attributes for blocks. + * @param {!Object=} opt_categoryStyles A + * map from style names (strings) to objects with style attributes for + * categories. + * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly + * component names to style value. + * @constructor + * @alias Blockly.Theme + */ + export class Theme { + /** + * Define a new Blockly theme. + * @param {string} name The name of the theme. + * @param {!Object} themeObj An object containing theme properties. + * @return {!Theme} A new Blockly theme. + */ + static defineTheme(name: string, themeObj: any): Theme; + constructor(name: any, opt_blockStyles: any, opt_categoryStyles: any, opt_componentStyles: any); + /** + * The theme name. This can be used to reference a specific theme in CSS. + * @type {string} + */ + name: string; + /** + * The block styles map. + * @type {!Object} + * @package + */ + blockStyles: { + [x: string]: Theme.BlockStyle; + }; + /** + * The category styles map. + * @type {!Object} + * @package + */ + categoryStyles: { + [x: string]: Theme.CategoryStyle; + }; + /** + * The UI components styles map. + * @type {!Theme.ComponentStyle} + * @package + */ + componentStyles: Theme.ComponentStyle; + /** + * The font style. + * @type {!Theme.FontStyle} + * @package + */ + fontStyle: Theme.FontStyle; + /** + * Whether or not to add a 'hat' on top of all blocks with no previous or + * output connections. + * @type {?boolean} + * @package + */ + startHats: boolean | null; + /** + * Gets the class name that identifies this theme. + * @return {string} The CSS class name. + * @package + */ + getClassName(): string; + /** + * Overrides or adds a style to the blockStyles map. + * @param {string} blockStyleName The name of the block style. + * @param {Theme.BlockStyle} blockStyle The block style. + */ + setBlockStyle(blockStyleName: string, blockStyle: Theme.BlockStyle): void; + /** + * Overrides or adds a style to the categoryStyles map. + * @param {string} categoryStyleName The name of the category style. + * @param {Theme.CategoryStyle} categoryStyle The category style. + */ + setCategoryStyle(categoryStyleName: string, categoryStyle: Theme.CategoryStyle): void; + /** + * Gets the style for a given Blockly UI component. If the style value is a + * string, we attempt to find the value of any named references. + * @param {string} componentName The name of the component. + * @return {?string} The style value. + */ + getComponentStyle(componentName: string): string | null; + /** + * Configure a specific Blockly UI component with a style value. + * @param {string} componentName The name of the component. + * @param {*} styleValue The style value. + */ + setComponentStyle(componentName: string, styleValue: any): void; + /** + * Configure a theme's font style. + * @param {Theme.FontStyle} fontStyle The font style. + */ + setFontStyle(fontStyle: Theme.FontStyle): void; + /** + * Configure a theme's start hats. + * @param {boolean} startHats True if the theme enables start hats, false + * otherwise. + */ + setStartHats(startHats: boolean): void; + } + export namespace Theme { + /** + * A block style. + */ + type BlockStyle = { + colourPrimary: string; + colourSecondary: string; + colourTertiary: string; + hat: string; + }; + /** + * A category style. + */ + type CategoryStyle = { + colour: string; + }; + /** + * A component style. + */ + type ComponentStyle = { + workspaceBackgroundColour: string | null; + toolboxBackgroundColour: string | null; + toolboxForegroundColour: string | null; + flyoutBackgroundColour: string | null; + flyoutForegroundColour: string | null; + flyoutOpacity: number | null; + scrollbarColour: string | null; + scrollbarOpacity: number | null; + insertionMarkerColour: string | null; + insertionMarkerOpacity: number | null; + markerColour: string | null; + cursorColour: string | null; + selectedGlowColour: string | null; + selectedGlowOpacity: number | null; + replacementGlowColour: string | null; + replacementGlowOpacity: number | null; + }; + /** + * A font style. + */ + type FontStyle = { + family: string | null; + weight: string | null; + size: number | null; + }; + } +} +declare module "theme/classic" { + /** + * Classic theme. + * Contains multi-coloured border to create shadow effect. + * @type {Theme} + * @alias Blockly.Themes.Classic + */ + export const Classic: Theme; + import { Theme } from "theme"; +} +declare module "utils/metrics" { + /** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + /** + * @fileoverview Workspace metrics definitions. + */ + /** + * Workspace metrics definitions. + * @namespace Blockly.utils.Metrics + */ + /** + * @record + * @alias Blockly.utils.Metrics + */ + export class Metrics { + /** + * Height of the visible portion of the workspace. + * @type {number} + */ + viewHeight: number; + /** + * Width of the visible portion of the workspace. + * @type {number} + */ + viewWidth: number; + /** + * Height of the content. + * @type {number} + */ + contentHeight: number; + /** + * Width of the content. + * @type {number} + */ + contentWidth: number; + /** + * Height of the scroll area. + * @type {number} + */ + scrollHeight: number; + /** + * Width of the scroll area. + * @type {number} + */ + scrollWidth: number; + /** + * Top-edge of the visible portion of the workspace, relative to the workspace + * origin. + * @type {number} + */ + viewTop: number; + /** + * Left-edge of the visible portion of the workspace, relative to the workspace + * origin. + * @type {number} + */ + viewLeft: number; + /** + * Top-edge of the content, relative to the workspace origin. + * @type {number} + */ + contentTop: number; + /** + * Left-edge of the content relative to the workspace origin. + * @type {number} + */ + contentLeft: number; + /** + * Top-edge of the scroll area, relative to the workspace origin. + * @type {number} + */ + scrollTop: number; + /** + * Left-edge of the scroll area relative to the workspace origin. + * @type {number} + */ + scrollLeft: number; + /** + * Top-edge of the visible portion of the workspace, relative to the blocklyDiv. + * @type {number} + */ + absoluteTop: number; + /** + * Left-edge of the visible portion of the workspace, relative to the + * blocklyDiv. + * @type {number} + */ + absoluteLeft: number; + /** + * Height of the Blockly div (the view + the toolbox, simple of otherwise). + * @type {number} + */ + svgHeight: number; + /** + * Width of the Blockly div (the view + the toolbox, simple or otherwise). + * @type {number} + */ + svgWidth: number; + /** + * Width of the toolbox, if it exists. Otherwise zero. + * @type {number} + */ + toolboxWidth: number; + /** + * Height of the toolbox, if it exists. Otherwise zero. + * @type {number} + */ + toolboxHeight: number; + /** + * Top, bottom, left or right. Use TOOLBOX_AT constants to compare. + * @type {number} + */ + toolboxPosition: number; + /** + * Width of the flyout if it is always open. Otherwise zero. + * @type {number} + */ + flyoutWidth: number; + /** + * Height of the flyout if it is always open. Otherwise zero. + * @type {number} + */ + flyoutHeight: number; + } +} +declare module "options" { + export class Options { + /** + * Parse the user-specified move options, using reasonable defaults where + * behaviour is unspecified. + * @param {!Object} options Dictionary of options. + * @param {boolean} hasCategories Whether the workspace has categories or not. + * @return {!Options.MoveOptions} Normalized move options. + * @private + */ + private static parseMoveOptions_; + /** + * Parse the user-specified zoom options, using reasonable defaults where + * behaviour is unspecified. See zoom documentation: + * https://developers.google.com/blockly/guides/configure/web/zoom + * @param {!Object} options Dictionary of options. + * @return {!Options.ZoomOptions} Normalized zoom options. + * @private + */ + private static parseZoomOptions_; + /** + * Parse the user-specified grid options, using reasonable defaults where + * behaviour is unspecified. See grid documentation: + * https://developers.google.com/blockly/guides/configure/web/grid + * @param {!Object} options Dictionary of options. + * @return {!Options.GridOptions} Normalized grid options. + * @private + */ + private static parseGridOptions_; + /** + * Parse the user-specified theme options, using the classic theme as a default. + * https://developers.google.com/blockly/guides/configure/web/themes + * @param {!Object} options Dictionary of options. + * @return {!Theme} A Blockly Theme. + * @private + */ + private static parseThemeOptions_; + /** + * Parse the user-specified options, using reasonable defaults where behaviour + * is unspecified. + * @param {!BlocklyOptions} options Dictionary of options. + * Specification: + * https://developers.google.com/blockly/guides/get-started/web#configuration + * @constructor + * @alias Blockly.Options + */ + constructor(options: BlocklyOptions); + /** @type {boolean} */ + RTL: boolean; + /** @type {boolean} */ + oneBasedIndex: boolean; + /** @type {boolean} */ + collapse: boolean; + /** @type {boolean} */ + comments: boolean; + /** @type {boolean} */ + disable: boolean; + /** @type {boolean} */ + readOnly: boolean; + /** @type {number} */ + maxBlocks: number; + /** @type {?Object} */ + maxInstances: { + [x: string]: number; + } | null; + /** @type {string} */ + pathToMedia: string; + /** @type {boolean} */ + hasCategories: boolean; + /** @type {!Options.MoveOptions} */ + moveOptions: Options.MoveOptions; + /** @deprecated January 2019 */ + hasScrollbars: boolean; + /** @type {boolean} */ + hasTrashcan: boolean; + /** @type {number} */ + maxTrashcanContents: number; + /** @type {boolean} */ + hasSounds: boolean; + /** @type {boolean} */ + hasCss: boolean; + /** @type {boolean} */ + horizontalLayout: boolean; + /** @type {?toolbox.ToolboxInfo} */ + languageTree: toolbox.ToolboxInfo | null; + /** @type {!Options.GridOptions} */ + gridOptions: Options.GridOptions; + /** @type {!Options.ZoomOptions} */ + zoomOptions: Options.ZoomOptions; + /** @type {!toolbox.Position} */ + toolboxPosition: toolbox.Position; + /** @type {!Theme} */ + theme: Theme; + /** @type {string} */ + renderer: string; + /** @type {?Object} */ + rendererOverrides: any | null; + /** + * The SVG element for the grid pattern. + * Created during injection. + * @type {?SVGElement} + */ + gridPattern: SVGElement | null; + /** + * The parent of the current workspace, or null if there is no parent + * workspace. We can assert that this is of type WorkspaceSvg as opposed to + * Workspace as this is only used in a rendered workspace. + * @type {WorkspaceSvg} + */ + parentWorkspace: WorkspaceSvg; + /** + * Map of plugin type to name of registered plugin or plugin class. + * @type {!Object} + */ + plugins: { + [x: string]: ((new (...args: unknown[]) => unknown) | string); + }; + } + export namespace Options { + /** + * Grid Options. + */ + type GridOptions = { + colour: string; + length: number; + snap: boolean; + spacing: number; + }; + /** + * Move Options. + */ + type MoveOptions = { + drag: boolean; + scrollbars: (boolean | Options.ScrollbarOptions); + wheel: boolean; + }; + /** + * Scrollbar Options. + */ + type ScrollbarOptions = { + horizontal: boolean; + vertical: boolean; + }; + /** + * Zoom Options. + */ + type ZoomOptions = { + controls: boolean; + maxScale: number; + minScale: number; + pinch: boolean; + scaleSpeed: number; + startScale: number; + wheel: boolean; + }; + } + import * as toolbox from "utils/toolbox"; + import { Theme } from "theme"; + import { WorkspaceSvg } from "workspace_svg"; + import { BlocklyOptions } from "blockly_options"; +} +declare module "names" { + export class Names { + /** + * Do the given two entity names refer to the same entity? + * Blockly names are case-insensitive. + * @param {string} name1 First name. + * @param {string} name2 Second name. + * @return {boolean} True if names are the same. + */ + static equals(name1: string, name2: string): boolean; + /** + * Class for a database of entity names (variables, procedures, etc). + * @param {string} reservedWords A comma-separated string of words that are + * illegal for use as names in a language (e.g. 'new,if,this,...'). + * @param {string=} opt_variablePrefix Some languages need a '$' or a namespace + * before all variable names (but not procedure names). + * @constructor + * @alias Blockly.Names + */ + constructor(reservedWords: string, opt_variablePrefix?: string | undefined); + variablePrefix_: string; + reservedDict_: any; + /** + * When JavaScript (or most other languages) is generated, variable 'foo' and + * procedure 'foo' would collide. However, Blockly has no such problems since + * variable get 'foo' and procedure call 'foo' are unambiguous. + * Therefore, Blockly keeps a separate realm name to disambiguate. + * getName('foo', 'VARIABLE') -> 'foo' + * getName('foo', 'PROCEDURE') -> 'foo2' + */ + /** + * Empty the database and start from scratch. The reserved words are kept. + */ + reset(): void; + db_: any; + dbReverse_: any; + variableMap_: VariableMap; + /** + * Set the variable map that maps from variable name to variable object. + * @param {!VariableMap} map The map to track. + */ + setVariableMap(map: VariableMap): void; + /** + * Get the name for a user-defined variable, based on its ID. + * This should only be used for variables of realm + * internalConstants.VARIABLE_CATEGORY_NAME. + * @param {string} id The ID to look up in the variable map. + * @return {?string} The name of the referenced variable, or null if there was + * no variable map or the variable was not found in the map. + * @private + */ + private getNameForUserVariable_; + /** + * Generate names for user variables, but only ones that are being used. + * @param {!Workspace} workspace Workspace to generate variables from. + */ + populateVariables(workspace: Workspace): void; + /** + * Generate names for procedures. + * @param {!Workspace} workspace Workspace to generate procedures from. + */ + populateProcedures(workspace: Workspace): void; + /** + * Convert a Blockly entity name to a legal exportable entity name. + * @param {string} nameOrId The Blockly entity name (no constraints) or + * variable ID. + * @param {string} realm The realm of entity in Blockly + * ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...). + * @return {string} An entity name that is legal in the exported language. + */ + getName(nameOrId: string, realm: string): string; + /** + * Return a list of all known user-created names in a specified realm. + * @param {string} realm The realm of entity in Blockly + * ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...). + * @return {!Array} A list of Blockly entity names (no constraints). + */ + getUserNames(realm: string): Array; + /** + * Convert a Blockly entity name to a legal exportable entity name. + * Ensure that this is a new name not overlapping any previously defined name. + * Also check against list of reserved words for the current language and + * ensure name doesn't collide. + * @param {string} name The Blockly entity name (no constraints). + * @param {string} realm The realm of entity in Blockly + * ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...). + * @return {string} An entity name that is legal in the exported language. + */ + getDistinctName(name: string, realm: string): string; + /** + * Given a proposed entity name, generate a name that conforms to the + * [_A-Za-z][_A-Za-z0-9]* format that most languages consider legal for + * variable and function names. + * @param {string} name Potentially illegal entity name. + * @return {string} Safe entity name. + * @private + */ + private safeName_; + } + export namespace Names { + const DEVELOPER_VARIABLE_TYPE: string; + } + import { VariableMap } from "variable_map"; + import { Workspace } from "workspace"; +} +declare module "events/events_var_base" { + /** + * Abstract class for a variable event. + * @param {!VariableModel=} opt_variable The variable this event + * corresponds to. Undefined for a blank event. + * @extends {Abstract} + * @constructor + * @alias Blockly.Events.VarBase + */ + export class VarBase { + constructor(opt_variable: any); + isBlank: boolean; + /** + * The variable id for the variable this event pertains to. + * @type {string} + */ + varId: string; + /** + * The workspace identifier for this event. + * @type {string} + */ + workspaceId: string; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + } +} +declare module "events/events_var_delete" { + /** + * Class for a variable deletion event. + * @param {!VariableModel=} opt_variable The deleted variable. Undefined + * for a blank event. + * @extends {VarBase} + * @constructor + * @alias Blockly.Events.VarDelete + */ + export class VarDelete { + constructor(opt_variable: any); + varType: any; + varName: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Run a variable deletion event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "events/events_var_rename" { + /** + * Class for a variable rename event. + * @param {!VariableModel=} opt_variable The renamed variable. Undefined + * for a blank event. + * @param {string=} newName The new name the variable will be changed to. + * @extends {VarBase} + * @constructor + * @alias Blockly.Events.VarRename + */ + export class VarRename { + constructor(opt_variable: any, newName: any); + oldName: any; + newName: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Run a variable rename event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "variable_map" { + export class VariableMap { + /** + * Class for a variable map. This contains a dictionary data structure with + * variable types as keys and lists of variables as values. The list of + * variables are the type indicated by the key. + * @param {!Workspace} workspace The workspace this map belongs to. + * @constructor + * @alias Blockly.VariableMap + */ + constructor(workspace: Workspace); + /** + * A map from variable type to list of variable names. The lists contain all + * of the named variables in the workspace, including variables + * that are not currently in use. + * @type {!Object>} + * @private + */ + private variableMap_; + /** + * The workspace this map belongs to. + * @type {!Workspace} + */ + workspace: Workspace; + /** + * Clear the variable map. + */ + clear(): void; + /** + * Rename the given variable by updating its name in the variable map. + * @param {!VariableModel} variable Variable to rename. + * @param {string} newName New variable name. + * @package + */ + renameVariable(variable: VariableModel, newName: string): void; + /** + * Rename a variable by updating its name in the variable map. Identify the + * variable to rename with the given ID. + * @param {string} id ID of the variable to rename. + * @param {string} newName New variable name. + */ + renameVariableById(id: string, newName: string): void; + /** + * Update the name of the given variable and refresh all references to it. + * The new name must not conflict with any existing variable names. + * @param {!VariableModel} variable Variable to rename. + * @param {string} newName New variable name. + * @param {!Array} blocks The list of all blocks in the + * workspace. + * @private + */ + private renameVariableAndUses_; + /** + * Update the name of the given variable to the same name as an existing + * variable. The two variables are coalesced into a single variable with the ID + * of the existing variable that was already using newName. + * Refresh all references to the variable. + * @param {!VariableModel} variable Variable to rename. + * @param {string} newName New variable name. + * @param {!VariableModel} conflictVar The variable that was already + * using newName. + * @param {!Array} blocks The list of all blocks in the + * workspace. + * @private + */ + private renameVariableWithConflict_; + /** + * Create a variable with a given name, optional type, and optional ID. + * @param {string} name The name of the variable. This must be unique across + * variables and procedures. + * @param {?string=} opt_type The type of the variable like 'int' or 'string'. + * Does not need to be unique. Field_variable can filter variables based on + * their type. This will default to '' which is a specific type. + * @param {?string=} opt_id The unique ID of the variable. This will default to + * a UUID. + * @return {!VariableModel} The newly created variable. + */ + createVariable(name: string, opt_type?: (string | null) | undefined, opt_id?: (string | null) | undefined): VariableModel; + /** + * Delete a variable. + * @param {!VariableModel} variable Variable to delete. + */ + deleteVariable(variable: VariableModel): void; + /** + * Delete a variables by the passed in ID and all of its uses from this + * workspace. May prompt the user for confirmation. + * @param {string} id ID of variable to delete. + */ + deleteVariableById(id: string): void; + /** + * Deletes a variable and all of its uses from this workspace without asking the + * user for confirmation. + * @param {!VariableModel} variable Variable to delete. + * @param {!Array} uses An array of uses of the variable. + * @package + */ + deleteVariableInternal(variable: VariableModel, uses: Array): void; + /** + * Find the variable by the given name and type and return it. Return null if + * it is not found. + * @param {string} name The name to check for. + * @param {?string=} opt_type The type of the variable. If not provided it + * defaults to the empty string, which is a specific type. + * @return {?VariableModel} The variable with the given name, or null if + * it was not found. + */ + getVariable(name: string, opt_type?: (string | null) | undefined): VariableModel | null; + /** + * Find the variable by the given ID and return it. Return null if not found. + * @param {string} id The ID to check for. + * @return {?VariableModel} The variable with the given ID. + */ + getVariableById(id: string): VariableModel | null; + /** + * Get a list containing all of the variables of a specified type. If type is + * null, return list of variables with empty string type. + * @param {?string} type Type of the variables to find. + * @return {!Array} The sought after variables of the + * passed in type. An empty array if none are found. + */ + getVariablesOfType(type: string | null): Array; + /** + * Return all variable and potential variable types. This list always contains + * the empty string. + * @param {?Workspace} ws The workspace used to look for potential + * variables. This can be different than the workspace stored on this object + * if the passed in ws is a flyout workspace. + * @return {!Array} List of variable types. + * @package + */ + getVariableTypes(ws: Workspace | null): Array; + /** + * Return all variables of all types. + * @return {!Array} List of variable models. + */ + getAllVariables(): Array; + /** + * Returns all of the variable names of all types. + * @return {!Array} All of the variable names of all types. + */ + getAllVariableNames(): Array; + /** + * Find all the uses of a named variable. + * @param {string} id ID of the variable to find. + * @return {!Array} Array of block usages. + */ + getVariableUsesById(id: string): Array; + } + import { Workspace } from "workspace"; + import { VariableModel } from "variable_model"; + import { Block } from "block"; +} +declare module "events/events_comment_create" { + /** + * Class for a comment creation event. + * @param {!WorkspaceComment=} opt_comment The created comment. + * Undefined for a blank event. + * @extends {CommentBase} + * @constructor + * @alias Blockly.Events.CommentCreate + */ + export class CommentCreate { + constructor(opt_comment: any); + xml: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Run a creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "events/events_comment_delete" { + /** + * Class for a comment deletion event. + * @param {!WorkspaceComment=} opt_comment The deleted comment. + * Undefined for a blank event. + * @extends {CommentBase} + * @constructor + * @alias Blockly.Events.CommentDelete + */ + export class CommentDelete { + constructor(opt_comment: any); + xml: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Run a creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "events/events_comment_base" { + /** + * Abstract class for a comment event. + * @param {!WorkspaceComment=} opt_comment The comment this event + * corresponds to. Undefined for a blank event. + * @extends {AbstractEvents} + * @constructor + * @alias Blockly.Events.CommentBase + */ + export class CommentBase { + /** + * Helper function for Comment[Create|Delete] + * @param {!CommentCreate|!CommentDelete} event + * The event to run. + * @param {boolean} create if True then Create, if False then Delete + */ + static CommentCreateDeleteHelper(event: CommentCreate | CommentDelete, create: boolean): void; + constructor(opt_comment: any); + /** + * Whether or not an event is blank. + * @type {boolean} + */ + isBlank: boolean; + /** + * The ID of the comment this event pertains to. + * @type {string} + */ + commentId: string; + /** + * The workspace identifier for this event. + * @type {string} + */ + workspaceId: string; + /** + * The event group id for the group this event belongs to. Groups define + * events that should be treated as an single action from the user's + * perspective, and should be undone together. + * @type {string} + */ + group: string; + /** + * Sets whether the event should be added to the undo stack. + * @type {boolean} + */ + recordUndo: boolean; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + } + import { CommentCreate } from "events/events_comment_create"; + import { CommentDelete } from "events/events_comment_delete"; +} +declare module "events/events_comment_change" { + /** + * Class for a comment change event. + * @param {!WorkspaceComment=} opt_comment The comment that is being + * changed. Undefined for a blank event. + * @param {string=} opt_oldContents Previous contents of the comment. + * @param {string=} opt_newContents New contents of the comment. + * @extends {CommentBase} + * @constructor + * @alias Blockly.Events.CommentChange + */ + export class CommentChange { + constructor(opt_comment: any, opt_oldContents: any, opt_newContents: any); + oldContents_: any; + newContents_: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull(): boolean; + /** + * Run a change event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "events/events_comment_move" { + /** + * Class for a comment move event. Created before the move. + * @param {!WorkspaceComment=} opt_comment The comment that is being + * moved. Undefined for a blank event. + * @extends {CommentBase} + * @constructor + * @alias Blockly.Events.CommentMove + */ + export class CommentMove { + constructor(opt_comment: any); + /** + * The comment that is being moved. Will be cleared after recording the new + * location. + * @type {WorkspaceComment} + */ + comment_: WorkspaceComment; + /** + * The location before the move, in workspace coordinates. + * @type {!Coordinate} + */ + oldCoordinate_: Coordinate; + /** + * The location after the move, in workspace coordinates. + * @type {Coordinate} + */ + newCoordinate_: Coordinate; + /** + * Record the comment's new location. Called after the move. Can only be + * called once. + */ + recordNew(): void; + /** + * Override the location before the move. Use this if you don't create the + * event until the end of the move, but you know the original location. + * @param {!Coordinate} xy The location before the move, + * in workspace coordinates. + */ + setOldCoordinate(xy: Coordinate): void; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull(): boolean; + /** + * Run a move event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } + import { WorkspaceComment } from "workspace_comment"; + import { Coordinate } from "utils/coordinate"; +} +declare module "workspace_comment" { + /** + * Class for a workspace comment. + * @param {!Workspace} workspace The block's workspace. + * @param {string} content The content of this workspace comment. + * @param {number} height Height of the comment. + * @param {number} width Width of the comment. + * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise + * create a new ID. + * @constructor + * @alias Blockly.WorkspaceComment + */ + export class WorkspaceComment { + /** + * Fire a create event for the given workspace comment, if comments are enabled. + * @param {!WorkspaceComment} comment The comment that was just created. + * @package + */ + static fireCreateEvent(comment: WorkspaceComment): void; + /** + * Decode an XML comment tag and create a comment on the workspace. + * @param {!Element} xmlComment XML comment element. + * @param {!Workspace} workspace The workspace. + * @return {!WorkspaceComment} The created workspace comment. + * @package + */ + static fromXml(xmlComment: Element, workspace: Workspace): WorkspaceComment; + /** + * Decode an XML comment tag and return the results in an object. + * @param {!Element} xml XML comment element. + * @return {{w: number, h: number, x: number, y: number, content: string}} An + * object containing the id, size, position, and comment string. + * @package + */ + static parseAttributes(xml: Element): { + w: number; + h: number; + x: number; + y: number; + content: string; + }; + constructor(workspace: any, content: any, height: any, width: any, opt_id: any); + /** @type {string} */ + id: string; + /** + * The comment's position in workspace units. (0, 0) is at the workspace's + * origin; scale does not change this value. + * @type {!Coordinate} + * @protected + */ + protected xy_: Coordinate; + /** + * The comment's height in workspace units. Scale does not change this value. + * @type {number} + * @protected + */ + protected height_: number; + /** + * The comment's width in workspace units. Scale does not change this value. + * @type {number} + * @protected + */ + protected width_: number; + /** + * @type {!Workspace} + */ + workspace: Workspace; + /** + * @protected + * @type {boolean} + */ + protected RTL: boolean; + /** + * @type {boolean} + * @private + */ + private deletable_; + /** + * @type {boolean} + * @private + */ + private movable_; + /** + * @type {boolean} + * @private + */ + private editable_; + /** + * @protected + * @type {string} + */ + protected content_: string; + /** + * Whether this comment has been disposed. + * @protected + * @type {boolean} + */ + protected disposed_: boolean; + /** + * @package + * @type {boolean} + */ + isComment: boolean; + /** + * Dispose of this comment. + * @package + */ + dispose(): void; + /** + * Get comment height. + * @return {number} Comment height. + * @package + */ + getHeight(): number; + /** + * Set comment height. + * @param {number} height Comment height. + * @package + */ + setHeight(height: number): void; + /** + * Get comment width. + * @return {number} Comment width. + * @package + */ + getWidth(): number; + /** + * Set comment width. + * @param {number} width comment width. + * @package + */ + setWidth(width: number): void; + /** + * Get stored location. + * @return {!Coordinate} The comment's stored location. + * This is not valid if the comment is currently being dragged. + * @package + */ + getXY(): Coordinate; + /** + * Move a comment by a relative offset. + * @param {number} dx Horizontal offset, in workspace units. + * @param {number} dy Vertical offset, in workspace units. + * @package + */ + moveBy(dx: number, dy: number): void; + /** + * Get whether this comment is deletable or not. + * @return {boolean} True if deletable. + * @package + */ + isDeletable(): boolean; + /** + * Set whether this comment is deletable or not. + * @param {boolean} deletable True if deletable. + * @package + */ + setDeletable(deletable: boolean): void; + /** + * Get whether this comment is movable or not. + * @return {boolean} True if movable. + * @package + */ + isMovable(): boolean; + /** + * Set whether this comment is movable or not. + * @param {boolean} movable True if movable. + * @package + */ + setMovable(movable: boolean): void; + /** + * Get whether this comment is editable or not. + * @return {boolean} True if editable. + */ + isEditable(): boolean; + /** + * Set whether this comment is editable or not. + * @param {boolean} editable True if editable. + */ + setEditable(editable: boolean): void; + /** + * Returns this comment's text. + * @return {string} Comment text. + * @package + */ + getContent(): string; + /** + * Set this comment's content. + * @param {string} content Comment content. + * @package + */ + setContent(content: string): void; + /** + * Encode a comment subtree as XML with XY coordinates. + * @param {boolean=} opt_noId True if the encoder should skip the comment ID. + * @return {!Element} Tree of XML elements. + * @package + */ + toXmlWithXY(opt_noId?: boolean | undefined): Element; + /** + * Encode a comment subtree as XML, but don't serialize the XY coordinates. + * This method avoids some expensive metrics-related calls that are made in + * toXmlWithXY(). + * @param {boolean=} opt_noId True if the encoder should skip the comment ID. + * @return {!Element} Tree of XML elements. + * @package + */ + toXml(opt_noId?: boolean | undefined): Element; + } + import { Coordinate } from "utils/coordinate"; + import { Workspace } from "workspace"; +} +declare module "connection_checker" { + /** + * Class for connection type checking logic. + * @implements {IConnectionChecker} + * @constructor + * @alias Blockly.ConnectionChecker + */ + export class ConnectionChecker implements IConnectionChecker { + /** + * Check whether the current connection can connect with the target + * connection. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. + * @param {boolean} isDragging True if the connection is being made by dragging + * a block. + * @param {number=} opt_distance The max allowable distance between the + * connections for drag checks. + * @return {boolean} Whether the connection is legal. + * @public + */ + public canConnect(a: Connection, b: Connection, isDragging: boolean, opt_distance?: number | undefined): boolean; + /** + * Checks whether the current connection can connect with the target + * connection, and return an error code if there are problems. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. + * @param {boolean} isDragging True if the connection is being made by dragging + * a block. + * @param {number=} opt_distance The max allowable distance between the + * connections for drag checks. + * @return {number} Connection.CAN_CONNECT if the connection is legal, + * an error code otherwise. + * @public + */ + public canConnectWithReason(a: Connection, b: Connection, isDragging: boolean, opt_distance?: number | undefined): number; + /** + * Helper method that translates a connection error code into a string. + * @param {number} errorCode The error code. + * @param {Connection} a One of the two connections being checked. + * @param {Connection} b The second of the two connections being + * checked. + * @return {string} A developer-readable error string. + * @public + */ + public getErrorMessage(errorCode: number, a: Connection, b: Connection): string; + /** + * Check that connecting the given connections is safe, meaning that it would + * not break any of Blockly's basic assumptions (e.g. no self connections). + * @param {Connection} a The first of the connections to check. + * @param {Connection} b The second of the connections to check. + * @return {number} An enum with the reason this connection is safe or unsafe. + * @public + */ + public doSafetyChecks(a: Connection, b: Connection): number; + /** + * Check whether this connection is compatible with another connection with + * respect to the value type system. E.g. square_root("Hello") is not + * compatible. + * @param {!Connection} a Connection to compare. + * @param {!Connection} b Connection to compare against. + * @return {boolean} True if the connections share a type. + * @public + */ + public doTypeChecks(a: Connection, b: Connection): boolean; + /** + * Check whether this connection can be made by dragging. + * @param {!RenderedConnection} a Connection to compare. + * @param {!RenderedConnection} b Connection to compare against. + * @param {number} distance The maximum allowable distance between connections. + * @return {boolean} True if the connection is allowed during a drag. + * @public + */ + public doDragChecks(a: RenderedConnection, b: RenderedConnection, distance: number): boolean; + /** + * Helper function for drag checking. + * @param {!Connection} a The connection to check, which must be a + * statement input or next connection. + * @param {!Connection} b A nearby connection to check, which + * must be a previous connection. + * @return {boolean} True if the connection is allowed, false otherwise. + * @protected + */ + protected canConnectToPrevious_(a: Connection, b: Connection): boolean; + } + import { IConnectionChecker } from "interfaces/i_connection_checker"; + import { Connection } from "connection"; + import { RenderedConnection } from "rendered_connection"; +} +declare module "workspace" { + export class Workspace { + /** + * Find the workspace with the specified ID. + * @param {string} id ID of workspace to find. + * @return {?Workspace} The sought after workspace or null if not found. + */ + static getById(id: string): Workspace | null; + /** + * Find all workspaces. + * @return {!Array} Array of workspaces. + */ + static getAll(): Array; + /** + * Class for a workspace. This is a data structure that contains blocks. + * There is no UI, and can be created headlessly. + * @param {!Options=} opt_options Dictionary of options. + * @constructor + * @implements {IASTNodeLocation} + * @alias Blockly.Workspace + */ + constructor(opt_options?: Options | undefined); + /** @type {string} */ + id: string; + /** @type {!Options} */ + options: Options; + /** @type {boolean} */ + RTL: boolean; + /** @type {boolean} */ + horizontalLayout: boolean; + /** @type {toolbox.Position} */ + toolboxPosition: toolbox.Position; + /** + * An object that encapsulates logic for safety, type, and dragging checks. + * @type {!IConnectionChecker} + */ + connectionChecker: IConnectionChecker; + /** + * @type {!Array} + * @private + */ + private topBlocks_; + /** + * @type {!Array} + * @private + */ + private topComments_; + /** + * @type {!Object} + * @private + */ + private commentDB_; + /** + * @type {!Array} + * @private + */ + private listeners_; + /** + * @type {!Array} + * @protected + */ + protected undoStack_: Array; + /** + * @type {!Array} + * @protected + */ + protected redoStack_: Array; + /** + * @type {!Object} + * @private + */ + private blockDB_; + /** + * @type {!Object} + * @private + */ + private typedBlocksDB_; + /** + * A map from variable type to list of variable names. The lists contain all + * of the named variables in the workspace, including variables + * that are not currently in use. + * @type {!VariableMap} + * @private + */ + private variableMap_; + /** + * Blocks in the flyout can refer to variables that don't exist in the main + * workspace. For instance, the "get item in list" block refers to an "item" + * variable regardless of whether the variable has been created yet. + * A FieldVariable must always refer to a VariableModel. We reconcile + * these by tracking "potential" variables in the flyout. These variables + * become real when references to them are dragged into the main workspace. + * @type {?VariableMap} + * @private + */ + private potentialVariableMap_; + /** + * Dispose of this workspace. + * Unlink from all DOM elements to prevent memory leaks. + * @suppress {checkTypes} + */ + dispose(): void; + /** + * Compare function for sorting objects (blocks, comments, etc) by position; + * top to bottom (with slight LTR or RTL bias). + * @param {!Block | !WorkspaceComment} a The first object to + * compare. + * @param {!Block | !WorkspaceComment} b The second object to + * compare. + * @return {number} The comparison value. This tells Array.sort() how to change + * object a's index. + * @private + */ + private sortObjects_; + /** + * Adds a block to the list of top blocks. + * @param {!Block} block Block to add. + */ + addTopBlock(block: Block): void; + /** + * Removes a block from the list of top blocks. + * @param {!Block} block Block to remove. + */ + removeTopBlock(block: Block): void; + /** + * Finds the top-level blocks and returns them. Blocks are optionally sorted + * by position; top to bottom (with slight LTR or RTL bias). + * @param {boolean} ordered Sort the list if true. + * @return {!Array} The top-level block objects. + */ + getTopBlocks(ordered: boolean): Array; + /** + * Add a block to the list of blocks keyed by type. + * @param {!Block} block Block to add. + */ + addTypedBlock(block: Block): void; + /** + * Remove a block from the list of blocks keyed by type. + * @param {!Block} block Block to remove. + */ + removeTypedBlock(block: Block): void; + /** + * Finds the blocks with the associated type and returns them. Blocks are + * optionally sorted by position; top to bottom (with slight LTR or RTL bias). + * @param {string} type The type of block to search for. + * @param {boolean} ordered Sort the list if true. + * @return {!Array} The blocks of the given type. + */ + getBlocksByType(type: string, ordered: boolean): Array; + /** + * Adds a comment to the list of top comments. + * @param {!WorkspaceComment} comment comment to add. + * @package + */ + addTopComment(comment: WorkspaceComment): void; + /** + * Removes a comment from the list of top comments. + * @param {!WorkspaceComment} comment comment to remove. + * @package + */ + removeTopComment(comment: WorkspaceComment): void; + /** + * Finds the top-level comments and returns them. Comments are optionally + * sorted by position; top to bottom (with slight LTR or RTL bias). + * @param {boolean} ordered Sort the list if true. + * @return {!Array} The top-level comment objects. + * @package + */ + getTopComments(ordered: boolean): Array; + /** + * Find all blocks in workspace. Blocks are optionally sorted + * by position; top to bottom (with slight LTR or RTL bias). + * @param {boolean} ordered Sort the list if true. + * @return {!Array} Array of blocks. + */ + getAllBlocks(ordered: boolean): Array; + /** + * Dispose of all blocks and comments in workspace. + */ + clear(): void; + isClearing: boolean; + /** + * Rename a variable by updating its name in the variable map. Identify the + * variable to rename with the given ID. + * @param {string} id ID of the variable to rename. + * @param {string} newName New variable name. + */ + renameVariableById(id: string, newName: string): void; + /** + * Create a variable with a given name, optional type, and optional ID. + * @param {string} name The name of the variable. This must be unique across + * variables and procedures. + * @param {?string=} opt_type The type of the variable like 'int' or 'string'. + * Does not need to be unique. Field_variable can filter variables based on + * their type. This will default to '' which is a specific type. + * @param {?string=} opt_id The unique ID of the variable. This will default to + * a UUID. + * @return {!VariableModel} The newly created variable. + */ + createVariable(name: string, opt_type?: (string | null) | undefined, opt_id?: (string | null) | undefined): VariableModel; + /** + * Find all the uses of the given variable, which is identified by ID. + * @param {string} id ID of the variable to find. + * @return {!Array} Array of block usages. + */ + getVariableUsesById(id: string): Array; + /** + * Delete a variables by the passed in ID and all of its uses from this + * workspace. May prompt the user for confirmation. + * @param {string} id ID of variable to delete. + */ + deleteVariableById(id: string): void; + /** + * Find the variable by the given name and return it. Return null if not found. + * @param {string} name The name to check for. + * @param {string=} opt_type The type of the variable. If not provided it + * defaults to the empty string, which is a specific type. + * @return {?VariableModel} The variable with the given name. + */ + getVariable(name: string, opt_type?: string | undefined): VariableModel | null; + /** + * Find the variable by the given ID and return it. Return null if not found. + * @param {string} id The ID to check for. + * @return {?VariableModel} The variable with the given ID. + */ + getVariableById(id: string): VariableModel | null; + /** + * Find the variable with the specified type. If type is null, return list of + * variables with empty string type. + * @param {?string} type Type of the variables to find. + * @return {!Array} The sought after variables of the + * passed in type. An empty array if none are found. + */ + getVariablesOfType(type: string | null): Array; + /** + * Return all variable types. + * @return {!Array} List of variable types. + * @package + */ + getVariableTypes(): Array; + /** + * Return all variables of all types. + * @return {!Array} List of variable models. + */ + getAllVariables(): Array; + /** + * Returns all variable names of all types. + * @return {!Array} List of all variable names of all types. + */ + getAllVariableNames(): Array; + /** + * Returns the horizontal offset of the workspace. + * Intended for LTR/RTL compatibility in XML. + * Not relevant for a headless workspace. + * @return {number} Width. + */ + getWidth(): number; + /** + * Obtain a newly created block. + * @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. + * @return {!Block} The created block. + */ + newBlock(prototypeName: string, opt_id?: string | undefined): Block; + /** + * The number of blocks that may be added to the workspace before reaching + * the maxBlocks. + * @return {number} Number of blocks left. + */ + remainingCapacity(): number; + /** + * The number of blocks of the given type that may be added to the workspace + * before reaching the maxInstances allowed for that type. + * @param {string} type Type of block to return capacity for. + * @return {number} Number of blocks of type left. + */ + remainingCapacityOfType(type: string): number; + /** + * Check if there is remaining capacity for blocks of the given counts to be + * created. If the total number of blocks represented by the map is more than + * the total remaining capacity, it returns false. If a type count is more + * than the remaining capacity for that type, it returns false. + * @param {!Object} typeCountsMap A map of types to counts (usually representing + * blocks to be created). + * @return {boolean} True if there is capacity for the given map, + * false otherwise. + */ + isCapacityAvailable(typeCountsMap: any): boolean; + /** + * Checks if the workspace has any limits on the maximum number of blocks, + * or the maximum number of blocks of specific types. + * @return {boolean} True if it has block limits, false otherwise. + */ + hasBlockLimits(): boolean; + /** + * Gets the undo stack for workplace. + * @return {!Array} undo stack + * @package + */ + getUndoStack(): Array; + /** + * Gets the redo stack for workplace. + * @return {!Array} redo stack + * @package + */ + getRedoStack(): Array; + /** + * Undo or redo the previous action. + * @param {boolean} redo False if undo, true if redo. + */ + undo(redo: boolean): void; + /** + * Clear the undo/redo stacks. + */ + clearUndo(): void; + /** + * When something in this workspace changes, call a function. + * Note that there may be a few recent events already on the stack. Thus the + * new change listener might be called with events that occurred a few + * milliseconds before the change listener was added. + * @param {!Function} func Function to call. + * @return {!Function} Obsolete return value, ignore. + */ + addChangeListener(func: Function): Function; + /** + * Stop listening for this workspace's changes. + * @param {!Function} func Function to stop calling. + */ + removeChangeListener(func: Function): void; + /** + * Fire a change event. + * @param {!Abstract} event Event to fire. + */ + fireChangeListener(event: typeof Abstract): void; + /** + * Find the block on this workspace with the specified ID. + * @param {string} id ID of block to find. + * @return {?Block} The sought after block, or null if not found. + */ + getBlockById(id: string): Block | null; + /** + * Set a block on this workspace with the specified ID. + * @param {string} id ID of block to set. + * @param {Block} block The block to set. + * @package + */ + setBlockById(id: string, block: Block): void; + /** + * Delete a block off this workspace with the specified ID. + * @param {string} id ID of block to delete. + * @package + */ + removeBlockById(id: string): void; + /** + * Find the comment on this workspace with the specified ID. + * @param {string} id ID of comment to find. + * @return {?WorkspaceComment} The sought after comment, or null if not + * found. + * @package + */ + getCommentById(id: string): WorkspaceComment | null; + /** + * Checks whether all value and statement inputs in the workspace are filled + * with blocks. + * @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 | undefined): boolean; + /** + * Return the variable map that contains "potential" variables. + * These exist in the flyout but not in the workspace. + * @return {?VariableMap} The potential variable map. + * @package + */ + getPotentialVariableMap(): VariableMap | null; + /** + * Create and store the potential variable map for this workspace. + * @package + */ + createPotentialVariableMap(): void; + /** + * Return the map of all variables on the workspace. + * @return {!VariableMap} The variable map. + */ + getVariableMap(): VariableMap; + /** + * Set the map of all variables on the workspace. + * @param {!VariableMap} variableMap The variable map. + * @package + */ + setVariableMap(variableMap: VariableMap): void; + /** + * Returns `true` if the workspace is visible and `false` if it's headless. + * @type {boolean} + */ + rendered: boolean; + /** + * Maximum number of undo events in stack. `0` turns off undo, `Infinity` sets + * it to unlimited. + * @type {number} + */ + MAX_UNDO: number; + /** + * Set of databases for rapid lookup of connection locations. + * @type {Array} + */ + connectionDBList: Array; + } + export namespace Workspace { + const SCAN_ANGLE: number; + } + import { Options } from "options"; + import * as toolbox from "utils/toolbox"; + import { IConnectionChecker } from "interfaces/i_connection_checker"; + import * as Abstract from "events/events_abstract"; + import { Block } from "block"; + import { WorkspaceComment } from "workspace_comment"; + import { VariableModel } from "variable_model"; + import { VariableMap } from "variable_map"; + import { ConnectionDB } from "connection_db"; +} +declare module "events/events_var_create" { + /** + * Class for a variable creation event. + * @param {!VariableModel=} opt_variable The created variable. Undefined + * for a blank event. + * @extends {VarBase} + * @constructor + * @alias Blockly.Events.VarCreate + */ + export class VarCreate { + constructor(opt_variable: any); + varType: any; + varName: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Run a variable creation event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } +} +declare module "variable_model" { + /** + * Class for a variable model. + * Holds information for the variable including name, ID, and type. + * @param {!Workspace} workspace The variable's workspace. + * @param {string} name The name of the variable. This is the user-visible name + * (e.g. 'my var' or '私の変数'), not the generated name. + * @param {string=} opt_type The type of the variable like 'int' or 'string'. + * Does not need to be unique. Field_variable can filter variables based on + * their type. This will default to '' which is a specific type. + * @param {string=} opt_id The unique ID of the variable. This will default to + * a UUID. + * @see {Blockly.FieldVariable} + * @constructor + * @alias Blockly.VariableModel + */ + export class VariableModel { + /** + * A custom compare function for the VariableModel objects. + * @param {VariableModel} var1 First variable to compare. + * @param {VariableModel} var2 Second variable to compare. + * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, + * and 1 if greater. + * @package + */ + static compareByName(var1: VariableModel, var2: VariableModel): number; + constructor(workspace: any, name: any, opt_type: any, opt_id: any); + /** + * The workspace the variable is in. + * @type {!Workspace} + */ + workspace: Workspace; + /** + * The name of the variable, typically defined by the user. It may be + * changed by the user. + * @type {string} + */ + name: string; + /** + * The type of the variable, such as 'int' or 'sound_effect'. This may be + * used to build a list of variables of a specific type. By default this is + * the empty string '', which is a specific type. + * @see {Blockly.FieldVariable} + * @type {string} + */ + type: string; + /** + * A unique ID for the variable. This should be defined at creation and + * not change, even if the name changes. In most cases this should be a + * UUID. + * @type {string} + * @private + */ + private id_; + /** + * @return {string} The ID for the variable. + */ + getId(): string; + } + import { Workspace } from "workspace"; +} +declare module "variables" { + /** + * Find all user-created variables that are in use in the workspace. + * For use by generators. + * To get a list of all variables on a workspace, including unused variables, + * call Workspace.getAllVariables. + * @param {!Workspace} ws The workspace to search for variables. + * @return {!Array} Array of variable models. + * @alias Blockly.Variables.allUsedVarModels + */ + export function allUsedVarModels(ws: Workspace): Array; + /** + * Find all developer variables used by blocks in the workspace. + * Developer variables are never shown to the user, but are declared as global + * variables in the generated code. + * To declare developer variables, define the getDeveloperVariables function on + * your block and return a list of variable names. + * For use by generators. + * @param {!Workspace} workspace The workspace to search. + * @return {!Array} A list of non-duplicated variable names. + * @alias Blockly.Variables.allDeveloperVariables + */ + export function allDeveloperVariables(workspace: Workspace): Array; + /** + * Construct the elements (blocks and button) required by the flyout for the + * variable category. + * @param {!Workspace} workspace The workspace containing variables. + * @return {!Array} Array of XML elements. + * @alias Blockly.Variables.flyoutCategory + */ + export function flyoutCategory(workspace: Workspace): Array; + /** + * Construct the blocks required by the flyout for the variable category. + * @param {!Workspace} workspace The workspace containing variables. + * @return {!Array} Array of XML block elements. + * @alias Blockly.Variables.flyoutCategoryBlocks + */ + export function flyoutCategoryBlocks(workspace: Workspace): Array; + /** + * @alias Blockly.Variables.VAR_LETTER_OPTIONS + */ + export const VAR_LETTER_OPTIONS: "ijkmnopqrstuvwxyzabcdefgh"; + /** + * Return a new variable name that is not yet being used. This will try to + * generate single letter variable names in the range 'i' to 'z' to start with. + * If no unique name is located it will try 'i' to 'z', 'a' to 'h', + * then 'i2' to 'z2' etc. Skip 'l'. + * @param {!Workspace} workspace The workspace to be unique in. + * @return {string} New variable name. + * @alias Blockly.Variables.generateUniqueName + */ + export function generateUniqueName(workspace: Workspace): string; + /** + * Returns a unique name that is not present in the usedNames array. This + * will try to generate single letter names in the range a -> z (skip l). It + * will start with the character passed to startChar. + * @param {string} startChar The character to start the search at. + * @param {!Array} usedNames A list of all of the used names. + * @return {string} A unique name that is not present in the usedNames array. + * @alias Blockly.Variables.generateUniqueNameFromOptions + */ + export function generateUniqueNameFromOptions(startChar: string, usedNames: Array): string; + /** + * Handles "Create Variable" button in the default variables toolbox category. + * It will prompt the user for a variable name, including re-prompts if a name + * is already in use among the workspace's variables. + * + * Custom button handlers can delegate to this function, allowing variables + * types and after-creation processing. More complex customization (e.g., + * prompting for variable type) is beyond the scope of this function. + * + * @param {!Workspace} workspace The workspace on which to create the + * variable. + * @param {function(?string=)=} opt_callback A callback. It will be passed an + * acceptable new variable name, or null if change is to be aborted (cancel + * button), or undefined if an existing variable was chosen. + * @param {string=} opt_type The type of the variable like 'int', 'string', or + * ''. This will default to '', which is a specific type. + * @alias Blockly.Variables.createVariableButtonHandler + */ + export function createVariableButtonHandler(workspace: Workspace, opt_callback?: ((arg0: (string | null) | undefined) => any) | undefined, opt_type?: string | undefined): void; + /** + * Opens a prompt that allows the user to enter a new name for a variable. + * Triggers a rename if the new name is valid. Or re-prompts if there is a + * collision. + * @param {!Workspace} workspace The workspace on which to rename the + * variable. + * @param {!VariableModel} variable Variable to rename. + * @param {function(?string=)=} opt_callback A callback. It will + * be passed an acceptable new variable name, or null if change is to be + * aborted (cancel button), or undefined if an existing variable was chosen. + * @alias Blockly.Variables.renameVariable + */ + export function renameVariable(workspace: Workspace, variable: VariableModel, opt_callback?: ((arg0: (string | null) | undefined) => any) | undefined): void; + /** + * Prompt the user for a new variable name. + * @param {string} promptText The string of the prompt. + * @param {string} defaultText The default value to show in the prompt's field. + * @param {function(?string)} callback A callback. It will return the new + * variable name, or null if the user picked something illegal. + * @alias Blockly.Variables.promptName + */ + export function promptName(promptText: string, defaultText: string, callback: (arg0: string | null) => any): void; /** - * Whether a measurable stores information about a next connection. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * next connection. + * Check whether there exists a variable with the given name of any type. + * @param {string} name The name to search for. + * @param {!Workspace} workspace The workspace to search for the + * variable. + * @return {?VariableModel} The variable with the given name, + * or null if none was found. + * @alias Blockly.Variables.nameUsedWithAnyType + */ + export function nameUsedWithAnyType(name: string, workspace: Workspace): VariableModel | null; + /** + * Generate DOM objects representing a variable field. + * @param {!VariableModel} variableModel The variable model to + * represent. + * @return {?Element} The generated DOM. + * @alias Blockly.Variables.generateVariableFieldDom + */ + export function generateVariableFieldDom(variableModel: VariableModel): Element | null; + /** + * Helper function to look up or create a variable on the given workspace. + * If no variable exists, creates and returns it. + * @param {!Workspace} workspace The workspace to search for the + * variable. It may be a flyout workspace or main workspace. + * @param {?string} id The ID to use to look up or create the variable, or null. + * @param {string=} opt_name The string to use to look up or create the + * variable. + * @param {string=} opt_type The type to use to look up or create the variable. + * @return {!VariableModel} The variable corresponding to the given ID + * or name + type combination. + * @alias Blockly.Variables.getOrCreateVariablePackage + */ + export function getOrCreateVariablePackage(workspace: Workspace, id: string | null, opt_name?: string | undefined, opt_type?: string | undefined): VariableModel; + /** + * Look up a variable on the given workspace. + * Always looks in the main workspace before looking in the flyout workspace. + * Always prefers lookup by ID to lookup by name + type. + * @param {!Workspace} workspace The workspace to search for the + * variable. It may be a flyout workspace or main workspace. + * @param {?string} id The ID to use to look up the variable, or null. + * @param {string=} opt_name The string to use to look up the variable. + * Only used if lookup by ID fails. + * @param {string=} opt_type The type to use to look up the variable. + * Only used if lookup by ID fails. + * @return {?VariableModel} The variable corresponding to the given ID + * or name + type combination, or null if not found. + * @alias Blockly.Variables.getVariable + */ + export function getVariable(workspace: Workspace, id: string | null, opt_name?: string | undefined, opt_type?: string | undefined): VariableModel | null; + /** + * Helper function to get the list of variables that have been added to the + * workspace after adding a new block, using the given list of variables that + * were in the workspace before the new block was added. + * @param {!Workspace} workspace The workspace to inspect. + * @param {!Array} originalVariables The array of + * variables that existed in the workspace before adding the new block. + * @return {!Array} The new array of variables that + * were freshly added to the workspace after creating the new block, + * or [] if no new variables were added to the workspace. + * @alias Blockly.Variables.getAddedVariables * @package */ - function isNextConnection(elem: Measurable): number; - + export function getAddedVariables(workspace: Workspace, originalVariables: Array): Array; + import { Workspace } from "workspace"; + import { VariableModel } from "variable_model"; +} +declare module "events/events_block_base" { + /** + * Abstract class for a block event. + * @param {!Block=} opt_block The block this event corresponds to. + * Undefined for a blank event. + * @extends {Abstract} + * @constructor + * @alias Blockly.Events.BlockBase + */ + export class BlockBase { + constructor(opt_block: any); + isBlank: boolean; + /** + * The block ID for the block this event pertains to + * @type {string} + */ + blockId: string; + /** + * The workspace identifier for this event. + * @type {string} + */ + workspaceId: string; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + } +} +declare module "events/events_block_change" { + export class BlockChange { + /** + * Returns the extra state of the given block (either as XML or a JSO, depending + * on the block's definition). + * @param {!BlockSvg} block The block to get the extra state of. + * @return {string} A stringified version of the extra state of the given block. + * @package + */ + static getExtraBlockState_(block: BlockSvg): string; + /** + * Class for a block change event. + * @param {!Block=} opt_block The changed block. Undefined for a blank + * event. + * @param {string=} opt_element One of 'field', 'comment', 'disabled', etc. + * @param {?string=} opt_name Name of input or field affected, or null. + * @param {*=} opt_oldValue Previous value of element. + * @param {*=} opt_newValue New value of element. + * @extends {BlockBase} + * @constructor + * @alias Blockly.Events.BlockChange + */ + constructor(opt_block?: Block | undefined, opt_element?: string | undefined, opt_name?: (string | null) | undefined, opt_oldValue?: any | undefined, opt_newValue?: any | undefined); + element: string; + name: string; + oldValue: any; + newValue: any; + /** + * Encode the event as JSON. + * @return {!Object} JSON representation. + */ + toJson(): any; + /** + * Decode the JSON event. + * @param {!Object} json JSON representation. + */ + fromJson(json: any): void; + /** + * Does this event record any change of state? + * @return {boolean} False if something changed. + */ + isNull(): boolean; + /** + * Run a change event. + * @param {boolean} forward True if run forward, false if run backward (undo). + */ + run(forward: boolean): void; + /** + * Type of this event. + * @type {string} + */ + type: string; + } + import { BlockSvg } from "block_svg"; + import { Block } from "block"; +} +declare module "procedures" { + /** + * The default argument for a procedures_mutatorarg block. + * @type {string} + * @alias Blockly.Procedures.DEFAULT_ARG + */ + export const DEFAULT_ARG: string; + /** + * Procedure block type. + */ + export type ProcedureBlock = { + getProcedureCall: () => string; + renameProcedure: (arg0: string, arg1: string) => any; + getProcedureDef: () => any[]; + }; + /** + * Procedure block type. + * @typedef {{ + * getProcedureCall: function():string, + * renameProcedure: function(string,string), + * getProcedureDef: function():!Array + * }} + * @alias Blockly.Procedures.ProcedureBlock + */ + export let ProcedureBlock: any; + /** + * Find all user-created procedure definitions in a workspace. + * @param {!Workspace} root Root workspace. + * @return {!Array>} Pair of arrays, the + * first contains procedures without return variables, the second with. + * Each procedure is defined by a three-element list of name, parameter + * list, and return value boolean. + * @alias Blockly.Procedures.allProcedures + */ + export function allProcedures(root: Workspace): Array>; + /** + * Ensure two identically-named procedures don't exist. + * Take the proposed procedure name, and return a legal name i.e. one that + * is not empty and doesn't collide with other procedures. + * @param {string} name Proposed procedure name. + * @param {!Block} block Block to disambiguate. + * @return {string} Non-colliding name. + * @alias Blockly.Procedures.findLegalName + */ + export function findLegalName(name: string, block: Block): string; + /** + * Return if the given name is already a procedure name. + * @param {string} name The questionable name. + * @param {!Workspace} workspace The workspace to scan for collisions. + * @param {Block=} opt_exclude Optional block to exclude from + * comparisons (one doesn't want to collide with oneself). + * @return {boolean} True if the name is used, otherwise return false. + * @alias Blockly.Procedures.isNameUsed + */ + export function isNameUsed(name: string, workspace: Workspace, opt_exclude?: Block | undefined): boolean; + /** + * Rename a procedure. Called by the editable field. + * @param {string} name The proposed new name. + * @return {string} The accepted name. + * @this {Field} + * @alias Blockly.Procedures.rename + */ + export function rename(name: string): string; + /** + * Construct the blocks required by the flyout for the procedure category. + * @param {!Workspace} workspace The workspace containing procedures. + * @return {!Array} Array of XML block elements. + * @alias Blockly.Procedures.flyoutCategory + */ + export function flyoutCategory(workspace: Workspace): Array; /** - * Whether a measurable stores information about a previous or next connection. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a previous or - * next connection. + * Listens for when a procedure mutator is opened. Then it triggers a flyout + * update and adds a mutator change listener to the mutator workspace. + * @param {!Abstract} e The event that triggered this listener. + * @alias Blockly.Procedures.mutatorOpenListener * @package */ - function isPreviousOrNextConnection(elem: Measurable): number; - + export function mutatorOpenListener(e: typeof Abstract): void; + /** + * Find all the callers of a named procedure. + * @param {string} name Name of procedure. + * @param {!Workspace} workspace The workspace to find callers in. + * @return {!Array} Array of caller blocks. + * @alias Blockly.Procedures.getCallers + */ + export function getCallers(name: string, workspace: Workspace): Array; + /** + * When a procedure definition changes its parameters, find and edit all its + * callers. + * @param {!Block} defBlock Procedure definition block. + * @alias Blockly.Procedures.mutateCallers + */ + export function mutateCallers(defBlock: Block): void; + /** + * Find the definition block for the named procedure. + * @param {string} name Name of procedure. + * @param {!Workspace} workspace The workspace to search. + * @return {?Block} The procedure definition block, or null not found. + * @alias Blockly.Procedures.getDefinition + */ + export function getDefinition(name: string, workspace: Workspace): Block | null; + import { Workspace } from "workspace"; + import { Block } from "block"; + import * as Abstract from "events/events_abstract"; +} +declare module "variables_dynamic" { + function stringButtonClickHandler(button: any): void; + function numberButtonClickHandler(button: any): void; + function colourButtonClickHandler(button: any): void; + /** + * Construct the elements (blocks and button) required by the flyout for the + * variable category. + * @param {!Workspace} workspace The workspace containing variables. + * @return {!Array} Array of XML elements. + * @alias Blockly.VariablesDynamic.flyoutCategory + */ + export function flyoutCategory(workspace: Workspace): Array; + /** + * Construct the blocks required by the flyout for the variable category. + * @param {!Workspace} workspace The workspace containing variables. + * @return {!Array} Array of XML block elements. + * @alias Blockly.VariablesDynamic.flyoutCategoryBlocks + */ + export function flyoutCategoryBlocks(workspace: Workspace): Array; + import { Workspace } from "workspace"; + export { stringButtonClickHandler as onCreateVariableButtonClick_String, numberButtonClickHandler as onCreateVariableButtonClick_Number, colourButtonClickHandler as onCreateVariableButtonClick_Colour }; +} +declare module "renderers/common/debug" { /** - * Whether a measurable stores information about a left round corner. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * left round corner. + * Returns whether the debugger is turned on. + * @return {boolean} Whether the debugger is turned on. + * @alias Blockly.blockRendering.debug.isDebuggerEnabled * @package */ - function isLeftRoundedCorner(elem: Measurable): number; - + export function isDebuggerEnabled(): boolean; /** - * Whether a measurable stores information about a right round corner. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * right round corner. + * Turn on the blocks debugger. * @package + * @alias Blockly.blockRendering.debug.startDebugger */ - function isRightRoundedCorner(elem: Measurable): number; - + export function startDebugger(): void; /** - * Whether a measurable stores information about a left square corner. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * left square corner. + * Turn off the blocks debugger. * @package + * @alias Blockly.blockRendering.debug.stopDebugger */ - function isLeftSquareCorner(elem: Measurable): number; - + export function stopDebugger(): void; +} +declare module "renderers/common/constants" { /** - * Whether a measurable stores information about a right square corner. - * @param {!Measurable} elem The element to check. - * @return {number} 1 if the object stores information about a - * right square corner. + * An object that provides constants for rendering blocks. + * @constructor * @package + * @alias Blockly.blockRendering.ConstantProvider */ - function isRightSquareCorner(elem: Measurable): number; - + export class ConstantProvider { + /** + * The size of an empty spacer. + * @type {number} + */ + NO_PADDING: number; + /** + * The size of small padding. + * @type {number} + */ + SMALL_PADDING: number; + /** + * The size of medium padding. + * @type {number} + */ + MEDIUM_PADDING: number; + /** + * The size of medium-large padding. + * @type {number} + */ + MEDIUM_LARGE_PADDING: number; + /** + * The size of large padding. + * @type {number} + */ + LARGE_PADDING: number; + /** + * Offset from the top of the row for placing fields on inline input rows + * and statement input rows. + * Matches existing rendering (in 2019). + * @type {number} + */ + TALL_INPUT_FIELD_OFFSET_Y: number; + /** + * The height of the puzzle tab used for input and output connections. + * @type {number} + */ + TAB_HEIGHT: number; + /** + * The offset from the top of the block at which a puzzle tab is positioned. + * @type {number} + */ + TAB_OFFSET_FROM_TOP: number; + /** + * Vertical overlap of the puzzle tab, used to make it look more like a puzzle + * piece. + * @type {number} + */ + TAB_VERTICAL_OVERLAP: number; + /** + * The width of the puzzle tab used for input and output connections. + * @type {number} + */ + TAB_WIDTH: number; + /** + * The width of the notch used for previous and next connections. + * @type {number} + */ + NOTCH_WIDTH: number; + /** + * The height of the notch used for previous and next connections. + * @type {number} + */ + NOTCH_HEIGHT: number; + /** + * The minimum width of the block. + * @type {number} + */ + MIN_BLOCK_WIDTH: number; + EMPTY_BLOCK_SPACER_HEIGHT: number; + /** + * The minimum height of a dummy input row. + * @type {number} + */ + DUMMY_INPUT_MIN_HEIGHT: number; + /** + * The minimum height of a dummy input row in a shadow block. + * @type {number} + */ + DUMMY_INPUT_SHADOW_MIN_HEIGHT: number; + /** + * Rounded corner radius. + * @type {number} + */ + CORNER_RADIUS: number; + /** + * Offset from the left side of a block or the inside of a statement input to + * the left side of the notch. + * @type {number} + */ + NOTCH_OFFSET_LEFT: number; + /** + * Additional offset added to the statement input's width to account for the + * notch. + * @type {number} + */ + STATEMENT_INPUT_NOTCH_OFFSET: number; + STATEMENT_BOTTOM_SPACER: number; + STATEMENT_INPUT_PADDING_LEFT: number; + /** + * Vertical padding between consecutive statement inputs. + * @type {number} + */ + BETWEEN_STATEMENT_PADDING_Y: number; + /** + * The top row's minimum height. + * @type {number} + */ + TOP_ROW_MIN_HEIGHT: number; + /** + * The top row's minimum height if it precedes a statement. + * @type {number} + */ + TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT: number; + /** + * The bottom row's minimum height. + * @type {number} + */ + BOTTOM_ROW_MIN_HEIGHT: number; + /** + * The bottom row's minimum height if it follows a statement input. + * @type {number} + */ + BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT: number; + /** + * Whether to add a 'hat' on top of all blocks with no previous or output + * connections. Can be overridden by 'hat' property on Theme.BlockStyle. + * @type {boolean} + */ + ADD_START_HATS: boolean; + /** + * Height of the top hat. + * @type {number} + */ + START_HAT_HEIGHT: number; + /** + * Width of the top hat. + * @type {number} + */ + START_HAT_WIDTH: number; + SPACER_DEFAULT_HEIGHT: number; + MIN_BLOCK_HEIGHT: number; + EMPTY_INLINE_INPUT_PADDING: number; + /** + * The height of an empty inline input. + * @type {number} + */ + EMPTY_INLINE_INPUT_HEIGHT: number; + EXTERNAL_VALUE_INPUT_PADDING: number; + /** + * The height of an empty statement input. Note that in the old rendering + * this varies slightly depending on whether the block has external or inline + * inputs. In the new rendering this is consistent. It seems unlikely that + * the old behaviour was intentional. + * @type {number} + */ + EMPTY_STATEMENT_INPUT_HEIGHT: number; + START_POINT: string; + /** + * Height of SVG path for jagged teeth at the end of collapsed blocks. + * @type {number} + */ + JAGGED_TEETH_HEIGHT: number; + /** + * Width of SVG path for jagged teeth at the end of collapsed blocks. + * @type {number} + */ + JAGGED_TEETH_WIDTH: number; + /** + * Point size of text. + * @type {number} + */ + FIELD_TEXT_FONTSIZE: number; + /** + * Text font weight. + * @type {string} + */ + FIELD_TEXT_FONTWEIGHT: string; + /** + * Text font family. + * @type {string} + */ + FIELD_TEXT_FONTFAMILY: string; + /** + * Height of text. This constant is dynamically set in ``setFontConstants_`` + * to be the height of the text based on the font used. + * @type {number} + */ + FIELD_TEXT_HEIGHT: number; + /** + * Text baseline. This constant is dynamically set in ``setFontConstants_`` + * to be the baseline of the text based on the font used. + * @type {number} + */ + FIELD_TEXT_BASELINE: number; + /** + * A field's border rect corner radius. + * @type {number} + */ + FIELD_BORDER_RECT_RADIUS: number; + /** + * A field's border rect default height. + * @type {number} + */ + FIELD_BORDER_RECT_HEIGHT: number; + /** + * A field's border rect X padding. + * @type {number} + */ + FIELD_BORDER_RECT_X_PADDING: number; + /** + * A field's border rect Y padding. + * @type {number} + */ + FIELD_BORDER_RECT_Y_PADDING: number; + /** + * The backing colour of a field's border rect. + * @type {string} + * @package + */ + FIELD_BORDER_RECT_COLOUR: string; + /** + * A field's text element's dominant baseline. + * @type {boolean} + */ + FIELD_TEXT_BASELINE_CENTER: boolean; + /** + * A dropdown field's border rect height. + * @type {number} + */ + FIELD_DROPDOWN_BORDER_RECT_HEIGHT: number; + /** + * Whether or not a dropdown field should add a border rect when in a shadow + * block. + * @type {boolean} + */ + FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW: boolean; + /** + * Whether or not a dropdown field's div should be coloured to match the + * block colours. + * @type {boolean} + */ + FIELD_DROPDOWN_COLOURED_DIV: boolean; + /** + * Whether or not a dropdown field uses a text or SVG arrow. + * @type {boolean} + */ + FIELD_DROPDOWN_SVG_ARROW: boolean; + /** + * A dropdown field's SVG arrow padding. + * @type {number} + */ + FIELD_DROPDOWN_SVG_ARROW_PADDING: number; + /** + * A dropdown field's SVG arrow size. + * @type {number} + */ + FIELD_DROPDOWN_SVG_ARROW_SIZE: number; + /** + * A dropdown field's SVG arrow datauri. + * @type {string} + */ + FIELD_DROPDOWN_SVG_ARROW_DATAURI: string; + /** + * Whether or not to show a box shadow around the widget div. This is only a + * feature of full block fields. + * @type {boolean} + */ + FIELD_TEXTINPUT_BOX_SHADOW: boolean; + /** + * Whether or not the colour field should display its colour value on the + * entire block. + * @type {boolean} + */ + FIELD_COLOUR_FULL_BLOCK: boolean; + /** + * A colour field's default width. + * @type {number} + */ + FIELD_COLOUR_DEFAULT_WIDTH: number; + /** + * A colour field's default height. + * @type {number} + */ + FIELD_COLOUR_DEFAULT_HEIGHT: number; + /** + * A checkbox field's X offset. + * @type {number} + */ + FIELD_CHECKBOX_X_OFFSET: number; + /** + * A random identifier used to ensure a unique ID is used for each + * filter/pattern for the case of multiple Blockly instances on a page. + * @type {string} + * @package + */ + randomIdentifier: string; + /** + * The defs tag that contains all filters and patterns for this Blockly + * instance. + * @type {?SVGElement} + * @private + */ + private defs_; + /** + * The ID of the emboss filter, or the empty string if no filter is set. + * @type {string} + * @package + */ + embossFilterId: string; + /** + * The element to use for highlighting, or null if not set. + * @type {SVGElement} + * @private + */ + private embossFilter_; + /** + * The ID of the disabled pattern, or the empty string if no pattern is set. + * @type {string} + * @package + */ + disabledPatternId: string; + /** + * The element to use for disabled blocks, or null if not set. + * @type {SVGElement} + * @private + */ + private disabledPattern_; + /** + * The ID of the debug filter, or the empty string if no pattern is set. + * @type {string} + * @package + */ + debugFilterId: string; + /** + * The element to use for a debug highlight, or null if not set. + * @type {SVGElement} + * @private + */ + private debugFilter_; + /** + * The