blockly > Workspace

Workspace class

Class for a workspace. This is a data structure that contains blocks. There is no UI, and can be created headlessly.

Signature:

export declare class Workspace implements IASTNodeLocation 

Implements: IASTNodeLocation

Constructors

Constructor Modifiers Description
(constructor)(opt_options) Constructs a new instance of the Workspace class

Properties

Property Modifiers Type Description
connectionChecker IConnectionChecker
connectionDBList ConnectionDB[] Set of databases for rapid lookup of connection locations.
horizontalLayout boolean
id string
isFlyout readonly boolean Is this workspace the surface for a flyout?
isMutator readonly boolean Is this workspace the surface for a mutator?
MAX_UNDO number Maximum number of undo events in stack. 0 turns off undo, Infinity sets it to unlimited.
options Options
redoStack_ protected Abstract[]
rendered boolean Returns true if the workspace is visible and false if it's headless.
RTL boolean
SCAN_ANGLE static number 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
toolboxPosition toolbox.Position
undoStack_ protected Abstract[]

Methods

Method Modifiers Description
addChangeListener(func) 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.
addTopBlock(block) Adds a block to the list of top blocks.
addTypedBlock(block) Add a block to the list of blocks keyed by type.
allInputsFilled(opt_shadowBlocksAreFilled) Checks whether all value and statement inputs in the workspace are filled with blocks.
clear() Dispose of all blocks and comments in workspace.
clearUndo() Clear the undo/redo stacks.
createVariable(name, opt_type, opt_id) Create a variable with a given name, optional type, and optional ID.
deleteVariableById(id) Delete a variables by the passed in ID and all of its uses from this workspace. May prompt the user for confirmation.
dispose() Dispose of this workspace. Unlink from all DOM elements to prevent memory leaks.
fireChangeListener(event) Fire a change event.
getAll() static Find all workspaces.
getAllBlocks(ordered) Find all blocks in workspace. Blocks are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
getAllVariableNames() Returns all variable names of all types.
getAllVariables() Return all variables of all types.
getBlockById(id) Find the block on this workspace with the specified ID.
getBlocksByType(type, ordered) 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).
getById(id) static Find the workspace with the specified ID.
getProcedureMap() Returns the map of all procedures on the workpace.
getRootWorkspace()

Returns the root workspace of this workspace if the workspace has parent(s).

E.g. workspaces in flyouts and mini workspace bubbles have parent workspaces.

getTopBlocks(ordered) Finds the top-level blocks and returns them. Blocks are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
getVariable(name, opt_type) Find the variable by the given name and return it. Return null if not found.
getVariableById(id) Find the variable by the given ID and return it. Return null if not found.
getVariableMap() Return the map of all variables on the workspace.
getVariablesOfType(type) Find the variable with the specified type. If type is null, return list of variables with empty string type.
getVariableUsesById(id) Find all the uses of the given variable, which is identified by ID.
getWidth() Returns the horizontal offset of the workspace. Intended for LTR/RTL compatibility in XML. Not relevant for a headless workspace.
hasBlockLimits() Checks if the workspace has any limits on the maximum number of blocks, or the maximum number of blocks of specific types.
isCapacityAvailable(typeCountsMap) 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.
newBlock(prototypeName, opt_id) Obtain a newly created block.
remainingCapacity() The number of blocks that may be added to the workspace before reaching the maxBlocks.
remainingCapacityOfType(type) The number of blocks of the given type that may be added to the workspace before reaching the maxInstances allowed for that type.
removeChangeListener(func) Stop listening for this workspace's changes.
removeTopBlock(block) Removes a block from the list of top blocks.
removeTypedBlock(block) Remove a block from the list of blocks keyed by type.
renameVariableById(id, newName) Rename a variable by updating its name in the variable map. Identify the variable to rename with the given ID.
undo(redo) Undo or redo the previous action.