UNPKG

pxt-core

Version:

Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors

1,298 lines • 60.3 kB
/// <reference path="../localtypings/pxtblockly.d.ts" /> /// <reference path="pxtlib.d.ts" /> /// <reference path="../localtypings/blockly.d.ts" /> /// <reference path="pxtsim.d.ts" /> declare let iface: pxt.worker.Iface; declare namespace pxt.blocks { function workerOpAsync(op: string, arg: pxtc.service.OpArg): Promise<any>; class Point { link: Point; type: string; parentType?: Point; childType?: Point; isArrayType?: boolean; constructor(link: Point, type: string, parentType?: Point, childType?: Point, isArrayType?: boolean); } interface Scope { parent?: Scope; firstStatement: Blockly.Block; declaredVars: Map<VarInfo>; referencedVars: number[]; assignedVars: number[]; children: Scope[]; } enum BlockDeclarationType { None = 0, Argument = 1, Assigned = 2, Implicit = 3 } interface BlockDiagnostic { blockId: string; message: string; } interface VarInfo { name: string; id: number; escapedName?: string; type?: Point; alreadyDeclared?: BlockDeclarationType; firstReference?: Blockly.Block; isAssigned?: boolean; isFunctionParameter?: boolean; } function compileExpression(e: Environment, b: Blockly.Block, comments: string[]): JsNode; interface Environment { workspace: Blockly.Workspace; options: BlockCompileOptions; stdCallTable: pxt.Map<StdFunc>; userFunctionReturnValues: pxt.Map<Point>; diagnostics: BlockDiagnostic[]; errors: Blockly.Block[]; renames: RenameMap; stats: pxt.Map<number>; enums: pxtc.EnumInfo[]; kinds: pxtc.KindInfo[]; idToScope: pxt.Map<Scope>; blockDeclarations: pxt.Map<VarInfo[]>; blocksInfo: pxtc.BlocksInfo; allVariables: VarInfo[]; } interface RenameMap { oldToNew: Map<string>; takenNames: Map<boolean>; oldToNewFunctions: Map<string>; } function escapeVarName(name: string, e: Environment, isFunction?: boolean): string; interface StdFunc { f: string; comp: BlockCompileInfo; attrs: ts.pxtc.CommentAttrs; isExtensionMethod?: boolean; isExpression?: boolean; imageLiteral?: number; imageLiteralColumns?: number; imageLiteralRows?: number; hasHandler?: boolean; property?: boolean; namespace?: string; isIdentity?: boolean; } function mkEnv(w: Blockly.Workspace, blockInfo?: pxtc.BlocksInfo, options?: BlockCompileOptions): Environment; function compileBlockAsync(b: Blockly.Block, blockInfo: pxtc.BlocksInfo): Promise<BlockCompilationResult>; function callKey(e: Environment, b: Blockly.Block): string; interface BlockCompilationResult { source: string; sourceMap: BlockSourceInterval[]; stats: pxt.Map<number>; diagnostics: BlockDiagnostic[]; } interface BlockCompileOptions { emitTilemapLiterals?: boolean; } function findBlockIdByPosition(sourceMap: BlockSourceInterval[], loc: { start: number; length: number; }): string; function findBlockIdByLine(sourceMap: BlockSourceInterval[], loc: { start: number; length: number; }): string; function compileAsync(b: Blockly.Workspace, blockInfo: pxtc.BlocksInfo, opts?: BlockCompileOptions): Promise<BlockCompilationResult>; } declare namespace pxt.blocks { function initFieldEditors(): void; function registerFieldEditor(selector: string, field: Blockly.FieldCustomConstructor, validator?: any): void; function createFieldEditor(selector: string, text: string, params: any): Blockly.FieldCustom; } declare namespace pxt.blocks { interface DiffOptions { hideDeletedTopBlocks?: boolean; hideDeletedBlocks?: boolean; renderOptions?: BlocksRenderOptions; statementsOnly?: boolean; } interface DiffResult { ws?: Blockly.WorkspaceSvg; message?: string; error?: any; svg?: Element; deleted: number; added: number; modified: number; } function needsDecompiledDiff(oldXml: string, newXml: string): boolean; function diffXml(oldXml: string, newXml: string, options?: DiffOptions): DiffResult; function mergeXml(xmlA: string, xmlO: string, xmlB: string): string; function decompiledDiffAsync(oldTs: string, oldResp: pxtc.CompileResult, newTs: string, newResp: pxtc.CompileResult, options?: DiffOptions): DiffResult; } declare namespace pxt.blocks { interface BlockSnippet { target: string; versions: pxt.TargetVersions; xml: string[]; extensions?: string[]; } interface DomToWorkspaceOptions { applyHideMetaComment?: boolean; keepMetaComments?: boolean; } /** * Converts a DOM into workspace without triggering any Blockly event. Returns the new block ids * @param dom * @param workspace */ function domToWorkspaceNoEvents(dom: Element, workspace: Blockly.Workspace, opts?: DomToWorkspaceOptions): string[]; function clearWithoutEvents(workspace: Blockly.Workspace): void; function saveWorkspaceXml(ws: Blockly.Workspace, keepIds?: boolean): string; function saveBlocksXml(ws: Blockly.Workspace, keepIds?: boolean): string[]; function getDirectChildren(parent: Element, tag: string): Element[]; function getBlocksWithType(parent: Document | Element, type: string): Element[]; function getChildrenWithAttr(parent: Document | Element, tag: string, attr: string, value: string): Element[]; function getFirstChildWithAttr(parent: Document | Element, tag: string, attr: string, value: string): Element; function loadBlocksXml(ws: Blockly.WorkspaceSvg, text: string): void; /** * Loads the xml into a off-screen workspace (not suitable for size computations) */ function loadWorkspaceXml(xml: string, skipReport?: boolean, opts?: DomToWorkspaceOptions): Blockly.Workspace; /** * This callback is populated from the editor extension result. * Allows a target to provide version specific blockly updates */ let extensionBlocklyPatch: (pkgTargetVersion: string, dom: Element) => void; function importXml(pkgTargetVersion: string, xml: string, info: pxtc.BlocksInfo, skipReport?: boolean): string; function validateAllReferencedBlocksExist(xml: string): boolean; } declare namespace pxt.blocks.layout { interface FlowOptions { ratio?: number; useViewWidth?: boolean; } function patchBlocksFromOldWorkspace(blockInfo: ts.pxtc.BlocksInfo, oldWs: Blockly.Workspace, newXml: string): string; /** * Splits a blockly SVG AFTER a vertical layout. This function relies on the ordering * of blocks / comments to get as getTopBlock(true)/getTopComment(true) */ function splitSvg(svg: SVGSVGElement, ws: Blockly.WorkspaceSvg, emPixels?: number): Element; function verticalAlign(ws: Blockly.WorkspaceSvg, emPixels: number): void; function setCollapsedAll(ws: Blockly.WorkspaceSvg, collapsed: boolean): void; function flow(ws: Blockly.WorkspaceSvg, opts?: FlowOptions): void; function screenshotEnabled(): boolean; function screenshotAsync(ws: Blockly.WorkspaceSvg, pixelDensity?: number, encodeBlocks?: boolean): Promise<string>; function toPngAsync(ws: Blockly.WorkspaceSvg, pixelDensity?: number, encodeBlocks?: boolean): Promise<string>; function toSvgAsync(ws: Blockly.WorkspaceSvg, pixelDensity: number): Promise<{ width: number; height: number; xml: string; }>; function serializeNode(sg: Node): string; function serializeSvgString(xmlString: string): string; interface BlockSvg { width: number; height: number; svg: string; xml: string; css: string; } function cleanUpBlocklySvg(svg: SVGElement): SVGElement; function blocklyToSvgAsync(sg: SVGElement, x: number, y: number, width: number, height: number, scale?: number): Promise<BlockSvg>; function documentToSvg(xsg: Node): string; } declare namespace pxt.blocks { let promptTranslateBlock: (blockId: string, blockTranslationIds: string[]) => void; interface GrayBlock extends Blockly.Block { setPythonEnabled(enabled: boolean): void; } interface GrayBlockStatement extends GrayBlock { domToMutation(xmlElement: Element): void; mutationToDom(): Element; getLines: () => string[]; declaredVariables: string; } interface PXTBlockData { commentRefs: string[]; fieldData: pxt.Map<string>; } const optionalDummyInputPrefix = "0_optional_dummy"; const optionalInputWithFieldPrefix = "0_optional_field"; function isArrayType(type: string): string; function isTupleType(type: string): string[]; function builtinBlocks(): Map<{ block: Blockly.BlockDefinition; symbol?: pxtc.SymbolInfo; }>; const buildinBlockStatements: Map<boolean>; function blockSymbol(type: string): pxtc.SymbolInfo; function createShadowValue(info: pxtc.BlocksInfo, p: pxt.blocks.BlockParameter, shadowId?: string, defaultV?: string): Element; function createFlyoutHeadingLabel(name: string, color?: string, icon?: string, iconClass?: string): HTMLElement; function createFlyoutGroupLabel(name: string, icon?: string, labelLineWidth?: string, helpCallback?: string): HTMLElement; function createFlyoutButton(callbackKey: string, label: string): Element; function createToolboxBlock(info: pxtc.BlocksInfo, fn: pxtc.SymbolInfo, comp: pxt.blocks.BlockCompileInfo): HTMLElement; function injectBlocks(blockInfo: pxtc.BlocksInfo): pxtc.SymbolInfo[]; function hasArrowFunction(fn: pxtc.SymbolInfo): boolean; function cleanBlocks(): void; /** * Used by pxtrunner to initialize blocks in the docs */ function initializeAndInject(blockInfo: pxtc.BlocksInfo): void; /** * Used by main app to initialize blockly blocks. * Blocks are injected separately by called injectBlocks */ function initialize(blockInfo: pxtc.BlocksInfo): void; function installHelpResources(id: string, name: string, tooltip: any, url: string, colour: string, colourSecondary?: string, colourTertiary?: string): void; let openHelpUrl: (url: string) => void; let onShowContextMenu: (workspace: Blockly.Workspace, items: Blockly.ContextMenu.Option[]) => void; /** * <block type="pxt_wait_until"> * <value name="PREDICATE"> * <shadow type="logic_boolean"> * <field name="BOOL">TRUE</field> * </shadow> * </value> * </block> */ function mkPredicateBlock(type: string): HTMLElement; function mkFieldBlock(type: string, fieldName: string, fieldValue: string, isShadow: boolean): HTMLElement; function mkReturnStatementBlock(): HTMLElement; function getFixedInstanceDropdownValues(apis: pxtc.ApisInfo, qName: string): pxtc.SymbolInfo[]; function generateIcons(instanceSymbols: pxtc.SymbolInfo[]): void; /** * Blockly variable fields can't be set directly; you either have to use the * variable ID or set the value of the model and not the field */ function setVarFieldValue(block: Blockly.Block, fieldName: string, newName: string): void; function getBlockData(block: Blockly.Block): PXTBlockData; function setBlockData(block: Blockly.Block, data: PXTBlockData): void; function setBlockDataForField(block: Blockly.Block, field: string, data: string): void; function getBlockDataForField(block: Blockly.Block, field: string): string; class PxtWorkspaceSearch extends WorkspaceSearch { protected createDom_(): void; /** * onKeyDown_ is a private method in WorkspaceSearch, overwrite it to allow searching backwards. * https://github.com/microsoft/pxt-arcade/issues/5716 */ onKeyDown_(e: KeyboardEvent): void; protected highlightSearchGroup_(blocks: Blockly.BlockSvg[]): void; protected unhighlightSearchGroup_(blocks: Blockly.BlockSvg[]): void; /** * https://github.com/google/blockly-samples/blob/master/plugins/workspace-search/src/WorkspaceSearch.js#L633 * * Modified to center offscreen blocks. */ protected scrollToVisible_(block: Blockly.BlockSvg): void; open(): void; close(): void; } } declare namespace pxt.blocks { /** * This interface defines the optionally defined functions for mutations that Blockly * will call if they exist. */ interface MutatingBlock extends Blockly.Block { mutation: Mutation; mutationToDom(): Element; domToMutation(xmlElement: Element): void; compose(topBlock: Blockly.Block): void; decompose(workspace: Blockly.Workspace): Blockly.Block; } /** * Represents a mutation of a block */ interface Mutation { /** * Get the unique identifier for this type of mutation */ getMutationType(): string; /** * Compile the mutation of the block into a node representation */ compileMutation(e: Environment, comments: string[]): JsNode; /** * Get a mapping of variables that were declared by this mutation and their types. */ getDeclaredVariables(): pxt.Map<string>; /** * Returns true if a variable with the given name was declared in the mutation's compiled node */ isDeclaredByMutation(varName: string): boolean; } namespace MutatorTypes { const ObjectDestructuringMutator = "objectdestructuring"; const RestParameterMutator = "restparameter"; const DefaultInstanceMutator = "defaultinstance"; } function addMutation(b: MutatingBlock, info: pxtc.SymbolInfo, mutationType: string): void; function mutateToolboxBlock(block: Node, mutationType: string, mutation: string): void; } declare namespace pxt.blocks { enum BlockLayout { None = 0, Align = 1, Clean = 3, Flow = 4 } interface BlocksRenderOptions { emPixels?: number; layout?: BlockLayout; clean?: boolean; aspectRatio?: number; packageId?: string; package?: string; snippetMode?: boolean; useViewWidth?: boolean; splitSvg?: boolean; forceCompilation?: boolean; generateSourceMap?: boolean; assets?: pxt.Map<string>; } function initRenderingWorkspace(): Blockly.WorkspaceSvg; function cleanRenderingWorkspace(): void; function renderWorkspace(options?: BlocksRenderOptions): Element; function render(blocksXml: string, options?: BlocksRenderOptions): Element; function blocksMetrics(ws: Blockly.WorkspaceSvg): { width: number; height: number; }; } declare namespace pxt.blocks { function findRootBlocks(xmlDOM: Element, type?: string): Element[]; function findRootBlock(xmlDOM: Element, type?: string): Element; } declare namespace pxt.docs.codeCard { interface CodeCardRenderOptions { hideHeader?: boolean; shortName?: boolean; } function render(card: pxt.CodeCard, options?: CodeCardRenderOptions): HTMLElement; } declare namespace Blockly.Xml { function domToBlock(xml: Element, workspace: Blockly.Workspace): Blockly.Block; } declare namespace pxt.blocks { interface ComposableMutation { mutationToDom(mutationElement: Element): Element; domToMutation(savedElement: Element): void; } function appendMutation(block: Blockly.Block, mutation: ComposableMutation): void; function initVariableArgsBlock(b: Blockly.Block, handlerArgs: pxt.blocks.HandlerArg[]): void; function initExpandableBlock(info: pxtc.BlocksInfo, b: Blockly.Block, def: pxtc.ParsedBlockDef, comp: BlockCompileInfo, toggle: boolean, addInputs: () => void): void; function initReturnStatement(b: Blockly.Block): void; } declare namespace Blockly { interface Block { moveInputBefore(nameToMove: string, refName: string): void; getInput(inputName: string): Blockly.Input; } } declare namespace pxt.blocks { function initMathOpBlock(): void; } declare namespace pxt.blocks { function initMathRoundBlock(): void; } declare namespace pxtblockly { abstract class FieldBase<U> extends Blockly.Field implements Blockly.FieldCustom { isFieldCustom_: true; SERIALIZABLE: boolean; options: U; protected valueText: string; protected loaded: boolean; protected workspace: Blockly.Workspace; constructor(text: string, params: U, validator?: Function); protected abstract onInit(): void; protected abstract onDispose(): void; protected abstract onValueChanged(newValue: string): string; init(): void; dispose(): void; getValue(): string; doValueUpdate_(newValue: string): void; getDisplayText_(): string; onLoadedIntoWorkspace(): void; protected getAnchorDimensions(): any; protected isInitialized(): boolean; protected getBlockData(): string; protected setBlockData(value: string): void; protected getSiblingBlock(inputName: string, useGrandparent?: boolean): Blockly.Block; protected getSiblingField(fieldName: string, useGrandparent?: boolean): Blockly.Field; } } declare namespace pxtblockly { export interface FieldAssetEditorOptions { initWidth?: string; initHeight?: string; disableResize?: string; } interface ParsedFieldAssetEditorOptions { initWidth?: number; initHeight?: number; disableResize?: boolean; lightMode?: boolean; } export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V extends ParsedFieldAssetEditorOptions> extends FieldBase<U> { protected asset: pxt.Asset; protected params: V; protected blocksInfo: pxtc.BlocksInfo; protected lightMode: boolean; protected undoRedoState: any; protected pendingEdit: boolean; protected isEmpty: boolean; isGreyBlock: boolean; constructor(text: string, params: any, validator?: Function); protected abstract getAssetType(): pxt.AssetType; protected abstract createNewAsset(text?: string): pxt.Asset; protected abstract getValueText(): string; onInit(): void; onValueChanged(newValue: string): string; showEditor_(): void; protected showEditorFullscreen(editorKind: string, params: any): void; protected showEditorInWidgetDiv(editorKind: string, params: any): void; protected onFieldEditorHide(fv: pxt.react.FieldEditorView<pxt.Asset>): void; render_(): void; getDisplayText_(): string; updateEditable(): void; getValue(): string; onDispose(): void; disposeOfTemporaryAsset(): void; clearTemporaryAssetData(): void; isTemporaryAsset(): boolean; getAsset(): pxt.Asset; updateAsset(asset: pxt.Asset): void; protected onEditorClose(newValue: pxt.Asset): void; protected redrawPreview(): void; protected parseValueText(newText: string): void; protected parseFieldOptions(opts: U): V; protected updateAssetMeta(): void; protected updateAssetListener(): void; protected assetChangeListener: () => void; protected isFullscreen(): boolean; } export class BlocklyTilemapChange extends Blockly.Events.BlockChange { protected oldRevision: number; protected newRevision: number; oldAssetId: string; newAssetId: string; fieldName: string; constructor(block: Blockly.Block, element: string, name: string, oldValue: any, newValue: any, oldRevision: number, newRevision: number); isNull(): boolean; run(forward: boolean): void; } export {}; } declare namespace pxtblockly { import svg = pxt.svgUtil; interface FieldAnimationOptions { initWidth: string; initHeight: string; disableResize: string; filter?: string; lightMode: boolean; } interface ParsedFieldAnimationOptions { initWidth: number; initHeight: number; disableResize: boolean; filter?: string; lightMode: boolean; } class FieldAnimationEditor extends FieldAssetEditor<FieldAnimationOptions, ParsedFieldAnimationOptions> { protected frames: string[]; protected preview: svg.Image; protected animateRef: any; protected asset: pxt.Animation; protected initInterval: number; initView(): void; showEditor_(): void; render_(): void; protected getAssetType(): pxt.AssetType; protected createNewAsset(text?: string): pxt.Asset; protected onEditorClose(newValue: pxt.Animation): void; protected getValueText(): string; protected redrawPreview(): void; protected onMouseEnter: () => void; protected onMouseLeave: () => void; protected getParentIntervalBlock(): Blockly.Block; protected setParentInterval(interval: number): void; protected getParentInterval(): number; protected parseFieldOptions(opts: FieldAnimationOptions): ParsedFieldAnimationOptions; } } declare namespace pxtblockly { /** * Subclass of FieldVariable to filter out the "delete" option when * variables are part of a function argument (or else the whole function * gets deleted). */ class FieldArgumentVariable extends Blockly.FieldVariable { constructor(varName: string); dropdownCreate(): any; } } declare namespace pxtblockly { interface FieldTextDropdownOptions extends Blockly.FieldCustomOptions { values: any; } class FieldTextDropdown extends Blockly.FieldTextDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; constructor(text: string, options: FieldTextDropdownOptions, opt_validator?: Function); } } declare namespace Blockly { interface FieldTextDropdown { showDropdown_(): void; isTextValid_: boolean; } } declare namespace pxtblockly { interface FieldAutoCompleteOptions extends Blockly.FieldCustomOptions { key: string; } class FieldAutoComplete extends Blockly.FieldTextDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; protected key: string; protected parsedValue: string; protected quoteSize_: number; protected quoteWidth_: number; protected quoteLeftX_: number; protected quoteRightX_: number; protected quoteY_: number; protected quoteLeft_: SVGTextElement; protected quoteRight_: SVGTextElement; constructor(text: string, options: FieldAutoCompleteOptions, opt_validator?: Function); isOptionListDynamic(): boolean; getDisplayText_(): string; doValueUpdate_(newValue: string): void; getValue(): string; getOptions(): [string, string][]; showDropdown_(): void; getKey(): string; initView(): void; updateSize_(): void; positionRight(x: number): number; positionLeft(x: number): number; createSVGArrow_(): void; showPromptEditor_(): void; } } declare namespace pxtblockly { class FieldBreakpoint extends Blockly.FieldNumber implements Blockly.FieldCustom { isFieldCustom_: boolean; private params; private state_; private checkElement_; private toggleThumb_; CURSOR: string; private type_; constructor(state: string, params: Blockly.FieldCustomOptions, opt_validator?: Function); initView(): void; updateSize_(): void; /** * Return 'TRUE' if the toggle is ON, 'FALSE' otherwise. * @return {string} Current state. */ getValue(): string; /** * Set the checkbox to be checked if newBool is 'TRUE' or true, * unchecks otherwise. * @param {string|boolean} newBool New state. */ setValue(newBool: string): void; switchToggle(newState: boolean): void; updateDisplay_(newValue: string): void; render_(): void; /** * Toggle the state of the toggle. * @private */ showEditor_(): void; private toVal; private fromVal; } } declare namespace pxtblockly { class FieldColorWheel extends Blockly.FieldSlider implements Blockly.FieldCustom { isFieldCustom_: boolean; private params; private channel_; /** * Class for a color wheel field. * @param {number|string} value The initial content of the field. * @param {Function=} opt_validator An optional function that is called * to validate any constraints on what the user entered. Takes the new * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @extends {Blockly.FieldNumber} * @constructor */ constructor(value_: any, params: any, opt_validator?: Function); /** * Set the gradient CSS properties for the given node and channel * @param {Node} node - The DOM node the gradient will be set on. * @private */ setBackground_(node: Element): void; setReadout_(readout: Element, value: string): void; createColourStops_(): string[]; colorWheel(wheelPos: number, channel?: string): string; hsvFast(hue: number, sat: number, val: number): string; private hex; private componentToHex; } } declare namespace pxtblockly { /** * The value modes: * hex - Outputs an HTML color string: "#ffffff" (with quotes) * rgb - Outputs an RGB number in hex: 0xffffff * index - Outputs the index of the color in the list of colors: 0 */ type FieldColourValueMode = "hex" | "rgb" | "index"; interface FieldColourNumberOptions extends Blockly.FieldCustomOptions { colours?: string; columns?: string; className?: string; valueMode?: FieldColourValueMode; } class FieldColorNumber extends Blockly.FieldColour implements Blockly.FieldCustom { isFieldCustom_: boolean; protected colour_: string; private valueMode_; constructor(text: string, params: FieldColourNumberOptions, opt_validator?: Function); /** * @override */ applyColour(): void; doClassValidation_(colour: string): string; /** * Return the current colour. * @param {boolean} opt_asHex optional field if the returned value should be a hex * @return {string} Current colour in '#rrggbb' format. */ getValue(opt_asHex?: boolean): any; /** * Set the colour. * @param {string} colour The new colour in '#rrggbb' format. */ doValueUpdate_(colour: string): void; showEditor_(): void; getColours_(): string[]; } } declare namespace pxtblockly { interface FieldGridPickerToolTipConfig { yOffset?: number; xOffset?: number; } interface FieldGridPickerOptions extends Blockly.FieldCustomDropdownOptions { columns?: string; maxRows?: string; width?: string; tooltips?: string; tooltipsXOffset?: string; tooltipsYOffset?: string; hasSearchBar?: boolean; hideRect?: boolean; } class FieldGridPicker extends Blockly.FieldDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; private width_; private columns_; private maxRows_; protected backgroundColour_: string; protected borderColour_: string; private tooltipConfig_; private gridTooltip_; private firstItem_; private hasSearchBar_; private hideRect_; private observer; private selectedItemDom; private closeModal_; private selectedBar_; private selectedImg_; private selectedBarText_; private selectedBarValue_; private static DEFAULT_IMG; constructor(text: string, options: FieldGridPickerOptions, validator?: Function); /** * When disposing the grid picker, make sure the tooltips are disposed too. * @public */ dispose(): void; private createTooltip_; /** * Create blocklyGridPickerRows and add them to table container * @param options * @param tableContainer */ private populateTableContainer; /** * Populate a single row and add it to table container * @param row * @param options * @param tableContainer */ private populateRow; /** * Callback for when a button is clicked inside the drop-down. * Should be bound to the FieldIconMenu. * @param {Event} e DOM event for the click/touch * @private */ protected buttonClick_: (e: any) => void; protected buttonClickAndClose_: (e: any) => void; /** * Whether or not to show a box around the dropdown menu. * @return {boolean} True if we should show a box (rect) around the dropdown menu. Otherwise false. * @private */ shouldShowRect_(): boolean; doClassValidation_(newValue: string): string; /** * Closes the gridpicker. */ private close; /** * Getter method */ private getFirstItem; /** * Highlight first item in menu, de-select and de-highlight all others */ private highlightFirstItem; /** * Scroll menu to item that equals current value of gridpicker */ private highlightAndScrollSelected; /** * Create a dropdown menu under the text. * @private */ showEditor_(): void; private positionMenu_; private shouldShowTooltips; private getAnchorDimensions_; private createWidget_; private createSearchBar_; private createSelectedBar_; private updateSelectedBar_; private setupIntersectionObserver_; private disposeIntersectionObserver; /** * Disposes the tooltip DOM. * @private */ private disposeTooltip; private onClose_; } } declare namespace pxtblockly { interface FieldImageDropdownOptions extends Blockly.FieldCustomDropdownOptions { columns?: string; maxRows?: string; width?: string; } class FieldImageDropdown extends Blockly.FieldDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; protected width_: number; protected columns_: number; protected maxRows_: number; protected backgroundColour_: string; protected borderColour_: string; protected savedPrimary_: string; constructor(text: string, options: FieldImageDropdownOptions, validator?: Function); /** * Create a dropdown menu under the text. * @private */ showEditor_(): void; /** * Callback for when a button is clicked inside the drop-down. * Should be bound to the FieldIconMenu. * @param {Event} e DOM event for the click/touch * @private */ protected buttonClick_: (e: any) => void; /** * Callback for when the drop-down is hidden. */ protected onHide_(): void; } } declare namespace pxtblockly { interface FieldImagesOptions extends pxtblockly.FieldImageDropdownOptions { sort?: boolean; addLabel?: string; } class FieldImages extends pxtblockly.FieldImageDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; private shouldSort_; protected addLabel_: boolean; constructor(text: string, options: FieldImagesOptions, validator?: Function); /** * Create a dropdown menu under the text. * @private */ showEditor_(): void; protected onHideCallback(): void; protected createTextNode_(text: string): HTMLSpanElement; } } declare namespace pxtblockly { class FieldKind extends Blockly.FieldDropdown { private opts; constructor(opts: pxtc.KindInfo); initView(): void; onItemSelected_(menu: Blockly.Menu, menuItem: Blockly.MenuItem): void; doClassValidation_(value: any): string; getOptions(opt_useCache?: boolean): any[][]; private initVariables; } } declare const rowRegex: RegExp; declare enum LabelMode { None = 0, Number = 1, Letter = 2 } declare namespace pxtblockly { class FieldMatrix extends Blockly.Field implements Blockly.FieldCustom { private static CELL_WIDTH; private static CELL_HORIZONTAL_MARGIN; private static CELL_VERTICAL_MARGIN; private static CELL_CORNER_RADIUS; private static BOTTOM_MARGIN; private static Y_AXIS_WIDTH; private static X_AXIS_HEIGHT; private static TAB; isFieldCustom_: boolean; SERIALIZABLE: boolean; private params; private onColor; private offColor; private static DEFAULT_OFF_COLOR; private scale; private matrixWidth; private matrixHeight; private yAxisLabel; private xAxisLabel; private cellState; private cells; private elt; private currentDragState_; constructor(text: string, params: any, validator?: Function); /** * Show the inline free-text editor on top of the text. * @private */ showEditor_(): void; private initMatrix; private getLabel; private dontHandleMouseEvent_; private clearLedDragHandler; private createCell; private toggleRect; private handleRootMouseMoveListener; private getColor; private getOpacity; private updateCell; setValue(newValue: string | number, restoreState?: boolean): void; render_(): void; getValue(): string; private restoreStateFromString; private updateValue; private getYAxisWidth; private getXAxisHeight; } } declare namespace pxtblockly { import svg = pxt.svgUtil; const HEADER_HEIGHT = 50; const TOTAL_WIDTH = 300; class FieldCustomMelody<U extends Blockly.FieldCustomOptions> extends Blockly.Field implements Blockly.FieldCustom { isFieldCustom_: boolean; SERIALIZABLE: boolean; protected params: U; private melody; private soundingKeys; private numRow; private numCol; private tempo; private stringRep; private isPlaying; private timeouts; private invalidString; private prevString; private topDiv; private editorDiv; private gridDiv; private bottomDiv; private doneButton; private playButton; private playIcon; private tempoInput; private static CELL_WIDTH; private static CELL_HORIZONTAL_MARGIN; private static CELL_VERTICAL_MARGIN; private static CELL_CORNER_RADIUS; private elt; private cells; private static VIEWBOX_WIDTH; private static VIEWBOX_HEIGHT; private static COLOR_BLOCK_WIDTH; private static COLOR_BLOCK_HEIGHT; private static COLOR_BLOCK_X; private static COLOR_BLOCK_Y; private static COLOR_BLOCK_SPACING; private static MUSIC_ICON_WIDTH; private toggle; private root; private gallery; constructor(value: string, params: U, validator?: Function); init(): void; showEditor_(): void; getValue(): string; doValueUpdate_(newValue: string): void; getText_(): string; protected onInit(): void; render_(): void; protected renderEditor(div: HTMLDivElement): void; protected onEditorClose(): void; private onDone; private clearDomReferences; protected getTypeScriptValue(): string; protected parseTypeScriptValue(value: string): void; private isValidNote; protected getPreviewWidth(): number; protected getPreviewHeight(): number; protected getDropdownBackgroundColour(): string; protected getDropdownBorderColour(): string; private updateFieldLabel; private setTempo; private syncTempoField; private getDuration; private createMelodyIfDoesntExist; private onNoteSelect; private updateGrid; private playNote; protected queueToneForColumn(column: number, delay: number, duration: number): void; protected playToneCore(row: number): void; private highlightColumn; private createGridDisplay; private createCell; private togglePlay; private updatePlayButton; private playMelody; private stopMelody; private showGallery; private hideGallery; } interface ButtonGroup { root: svg.Group; cx: number; cy: number; } } declare namespace pxtblockly { export interface FieldMusicEditorOptions { } interface ParsedFieldMusicEditorOptions { } export class FieldMusicEditor extends FieldAssetEditor<FieldMusicEditorOptions, ParsedFieldMusicEditorOptions> { protected getAssetType(): pxt.AssetType; protected createNewAsset(text?: string): pxt.Asset; render_(): void; protected getValueText(): string; protected parseFieldOptions(opts: FieldMusicEditorOptions): ParsedFieldMusicEditorOptions; protected redrawPreview(): void; protected previewWidth(): number; } export {}; } declare namespace pxtblockly { interface FieldNoteOptions extends Blockly.FieldCustomOptions { editorColour?: string; minNote?: string; maxNote?: string; eps?: string; } class FieldNote extends Blockly.FieldNumber implements Blockly.FieldCustom { isFieldCustom_: boolean; SERIALIZABLE: boolean; isTextValid_: boolean; private static Notes; protected static readonly keyWidth = 22; protected static readonly keyHeight = 90; protected static readonly labelHeight = 24; protected static readonly prevNextHeight = 20; protected static readonly notesPerOctave = 12; protected static readonly blackKeysPerOctave = 5; /** * default number of piano keys */ protected nKeys_: number; protected minNote_: number; protected maxNote_: number; /** Absolute error for note frequency identification (Hz) **/ protected eps: number; protected primaryColour: string; protected borderColour: string; protected isExpanded: Boolean; protected totalPlayCount: number; protected currentPage: number; protected piano: HTMLDivElement[]; protected noteLabel: HTMLDivElement; protected currentSelectedKey: HTMLDivElement; constructor(text: string, params: FieldNoteOptions, validator?: Function); /** * Ensure that only a non negative number may be entered. * @param {string} text The user's text. * @return A string representing a valid positive number, or null if invalid. */ doClassValidation_(text: string): string; /** * Return the current note frequency. * @return Current note in string format. */ getValue(): string; /** * Called by setValue if the text input is valid. Updates the value of the * field, and updates the text of the field if it is not currently being * edited (i.e. handled by the htmlInput_). * @param {string} note The new note in string format. */ doValueUpdate_(note: string): void; /** * Get the text from this field * @return Current text. */ getText(): string; /** * This block shows up differently when it's being edited; * on any transition between `editing <--> not-editing` * or other change in state, * refresh the text to get back into a valid state. **/ protected refreshText(): void; onHtmlInputChange_(e: any): void; onFinishEditing_(text: string): void; protected onHide(): void; /** * Create a piano under the note field. */ showEditor_(e: Event): void; protected playKey(key: HTMLDivElement, frequency: number): void; /** * Close the note picker if this input is being deleted. */ dispose(): void; private updateColor; protected setPage(page: number): void; /** * create a DOM to assign a style to the previous and next buttons * @param pianoWidth the width of the containing piano * @param isPrev true if is previous button, false otherwise * @return DOM with the new css style.s */ protected getNextPrevDiv(isPrev: boolean, pianoWidth: number): HTMLDivElement; protected getKeyDiv(keyInd: number, leftPosition: number): HTMLDivElement; /** * @param idx index of the key * @return true if idx is white */ protected isWhite(idx: number): boolean; protected whiteKeysBefore(idx: number): number; /** * get width of the piano key * @param idx index of the key * @return width of the key */ protected getKeyWidth(idx: number): number; /** * get height of the piano key * @param idx index of the key * @return height of the key */ protected getKeyHeight(idx: number): number; protected getKeyFreq(keyIndex: number): number; protected getKeyName(keyIndex: number): string; private getKeyNoteData; /** * get the position of the key in the piano * @param idx index of the key * @return position of the key */ protected getPosition(idx: number): number; private prepareNotes; } } declare namespace pxtblockly { interface FieldNumberDropdownOptions extends Blockly.FieldCustomDropdownOptions { min?: number; max?: number; precision?: any; } class FieldNumberDropdown extends Blockly.FieldNumberDropdown implements Blockly.FieldCustom { isFieldCustom_: boolean; private menuGenerator_; constructor(value: number | string, options: FieldNumberDropdownOptions, opt_validator?: Function); getOptions(): string[][]; } } declare namespace pxtblockly { interface FieldPositionOptions extends Blockly.FieldCustomOptions { min?: string; max?: string; screenWidth?: number; screenHeight?: number; xInputName?: string; yInputName?: string; } class FieldPosition extends Blockly.FieldSlider implements Blockly.FieldCustom { isFieldCustom_: boolean; private params; private selectorDiv_; private resetCrosshair; constructor(text: string, params: FieldPositionOptions, validator?: Function); showEditor_(_opt_e?: Event): void; doValueUpdate_(value: string): void; protected renderScreenPicker(): void; private resizeHandler; private setXY; private getFieldByName; private getXY; private getTargetField; widgetDispose_(): void; private close; } } declare namespace pxtblockly { class FieldProcedure extends Blockly.FieldDropdown { constructor(funcname: string, opt_validator?: Function); getOptions(): string[][]; init(): void; setSourceBlock(block: Blockly.Block): void; /** * Return a sorted list of variable names for procedure dropdown menus. * Include a special option at the end for creating a new function name. * @return {!Array.<string>} Array of procedure names. * @this {pxtblockly.FieldProcedure} */ dropdownCreate(): string[][]; onItemSelected(menu: any, menuItem: any): void; } } declare namespace pxtblockly { interface FieldProtractorOptions extends Blockly.FieldCustomOptions { } class FieldProtractor extends Blockly.FieldSlider implements Blockly.FieldCustom { isFieldCustom_: boolean; private params; private circleSVG; private circleBar; private reporter; /** * Class for a color wheel field. * @param {number|string} value The initial content of the field. * @param {Function=} opt_validator An optional function that is called * to validate any constraints on what the user entered. Takes the new * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @extends {Blockly.FieldNumber} * @constructor */ constructor(value_: any, params: FieldProtractorOptions, opt_validator?: Function); createLabelDom_(labelText: string): HTMLSpanElement[]; setReadout_(readout: Element, value: string): void; private updateAngle; } } declare namespace pxtblockly { interface FieldSoundEffectParams extends Blockly.FieldCustomOptions { durationInputName: string; startFrequencyInputName: string; endFrequencyInputName: string; startVolumeInputName: string; endVolumeInputName: string; waveFieldName: string; interpolationFieldName: string; effectFieldName: string; useMixerSynthesizer: any; } class FieldSoundEffect extends FieldBase<FieldSoundEffectParams> { protected mostRecentValue: pxt.assets.Sound; protected drawnSound: pxt.assets.Sound; protected workspace: Blockly.Workspace; protected registeredChangeListener: boolean; protected onInit(): void; protected onDispose(): void; protected onValueChanged(newValue: string): string; redrawPreview(): void; showEditor_(): void; render_(): void; protected updateSiblingBlocks(sound: pxt.assets.Sound): void; protected setNumberInputValue(name: string, value: number): void; protected getNumberInputValue(name: string, defaultValue: number): number; protected fireNumberInputUpdate(name: string, oldValue: number): void; protected setFieldDropdownValue(name: string, value: string): void; protected getFieldDropdownValue(name: string): string; protected fireFieldDropdownUpdate(name: string, oldValue: string): void; protected readCurrentSound(): pxt.assets.Sound; protected readBlockDataSound(): pxt.assets.Sound; protected onWorkspaceChange: (ev: Blockly.Events.BlockChange) => void; } } declare namespace pxtblockly { interface FieldSpeedOptions extends Blockly.FieldCustomOptions { min?: string; max?: string; format?: string; label?: string; } class FieldSpeed extends Blockly.FieldSlider implements Blockly.FieldCustom { isFieldCustom_: boolean; private params; private speedSVG; private circleBar; private reporter; /** * Class for a color wheel field. * @param {number|string} value The initial content of the field. * @param {Function=} opt_validator An optional function that is called * to validate any constraints on what the user entered. Takes the new * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @extends {Blockly.FieldNumber} * @constructor */ constructor(value_: any, params: FieldSpeedOptions, opt_validator?: Function); createLabelDom_(labelText: string): HTMLSpanElement[]; setReadout_(readout: Element, value: string): void; private updateSpeed; private sign; } } declare namespace pxtblockly { export interface FieldSpriteEditorOptions { sizes: string; initColor: string; initWidth: string; initHeight: string; disableResize: string; filter?: string; lightMode: boolean; } interface ParsedSpriteEditorOptions { initColor: number; initWidth: number; initHeight: number; disableResize: boolean; filter?: string; lightMode: boolean; } export class FieldSpriteEditor extends FieldAssetEditor<FieldSpriteEditorOptions, ParsedSpriteEditorOptions> { protected getAssetType(): pxt.AssetType; protected createNewAsset(text?: string): pxt.Asset; protected getValueText(): string; protected parseField