Blockly. WorkspaceSvg
Class for a workspace. This is an onscreen area with optional trashcan, scrollbars, bubbles, and dragging.
Constructor
WorkspaceSvg
new WorkspaceSvg(options, opt_blockDragSurface, opt_wsDragSurface)
Parameter |
|
---|---|
options |
Dictionary of options. Value must not be null. |
opt_blockDragSurface |
Optional Drag surface for blocks. |
opt_wsDragSurface |
Optional Drag surface for the workspace. |
- Extends
- Blockly.Workspace
- Implements
- Blockly.IASTNodeLocationSvg
Properties
cachedParentSvg_
non-null SVGElement
configureContextMenu
Developers may define this function to add custom menu options to the workspace's context menu or edit the workspace-created set of menu options.
Parameter |
|
---|---|
options |
Array of non-null Object List of menu options to add to. Value must not be null. |
e |
Event The right-click event that triggered the context menu. Value must not be null. |
connectionChecker
unknown
An object that encapsulates logic for safety, type, and dragging checks.
- Inherited from
- Blockly.Workspace#connectionChecker
connectionDBList
unknown
Set of databases for rapid lookup of connection locations.
- Inherited from
- Blockly.Workspace#connectionDBList
currentGesture_
TouchBlockly.Gesture
The current gesture in progress on this workspace, if any.
dragDeltaXY_
non-null Blockly.utils.Coordinate
getMetrics
function() returns non-null Blockly.utils.Metrics
Method to get all the metrics that have to do with a workspace.
horizontalLayout
unknown
- Inherited from
- Blockly.Workspace#horizontalLayout
id
unknown
- Inherited from
- Blockly.Workspace#id
injectionDiv_
non-null Element
isClearing
unknown
Returns true
if the workspace is currently in the process of a bulk
clear.
- Inherited from
- Blockly.Workspace#isClearing
isFlyout
unknown
Is this workspace the surface for a flyout?
- Inherited from
- Blockly.Workspace#isFlyout
isMutator
unknown
Is this workspace the surface for a mutator?
- Inherited from
- Blockly.Workspace#isMutator
keyboardAccessibilityMode
boolean
True if keyboard accessibility mode is on, false otherwise.
MAX_UNDO
unknown
Maximum number of undo events in stack. 0
turns off undo, Infinity
sets it to unlimited.
- Inherited from
- Blockly.Workspace#MAX_UNDO
options
unknown
- Inherited from
- Blockly.Workspace#options
redoStack_
unknown
- Inherited from
- Blockly.Workspace#redoStack_
rendered
boolean
The render status of an SVG workspace.
Returns false
for headless workspaces and true for instances of
WorkspaceSvg
.
RTL
unknown
- Inherited from
- Blockly.Workspace#RTL
scale
number
Current scale.
scrollbar
This workspace's scrollbars, if they exist.
scrollX
number
Current horizontal scrolling offset in pixel units, relative to the workspace origin.
It is useful to think about a view, and a canvas moving beneath that view. As the canvas moves right, this value becomes more positive, and the view is now "seeing" the left side of the canvas. As the canvas moves left, this value becomes more negative, and the view is now "seeing" the right side of the canvas.
The confusing thing about this value is that it does not, and must not include the absoluteLeft offset. This is because it is used to calculate the viewLeft value.
The viewLeft is relative to the workspace origin (although in pixel units). The workspace origin is the top-left corner of the workspace (at least when it is enabled). It is shifted from the top-left of the blocklyDiv so as not to be beneath the toolbox.
When the workspace is enabled the viewLeft and workspace origin are at the same X location. As the canvas slides towards the right beneath the view this value (scrollX) becomes more positive, and the viewLeft becomes more negative relative to the workspace origin (imagine the workspace origin as a dot on the canvas sliding to the right as the canvas moves).
So if the scrollX were to include the absoluteLeft this would in a way "unshift" the workspace origin. This means that the viewLeft would be representing the left edge of the blocklyDiv, rather than the left edge of the workspace.
scrollY
number
Current vertical scrolling offset in pixel units, relative to the workspace origin.
It is useful to think about a view, and a canvas moving beneath that view. As the canvas moves down, this value becomes more positive, and the view is now "seeing" the upper part of the canvas. As the canvas moves up, this value becomes more negative, and the view is "seeing" the lower part of the canvas.
This confusing thing about this value is that it does not, and must not include the absoluteTop offset. This is because it is used to calculate the viewTop value.
The viewTop is relative to the workspace origin (although in pixel units). The workspace origin is the top-left corner of the workspace (at least when it is enabled). It is shifted from the top-left of the blocklyDiv so as not to be beneath the toolbox.
When the workspace is enabled the viewTop and workspace origin are at the same Y location. As the canvas slides towards the bottom this value (scrollY) becomes more positive, and the viewTop becomes more negative relative to the workspace origin (image in the workspace origin as a dot on the canvas sliding downwards as the canvas moves).
So if the scrollY were to include the absoluteTop this would in a way "unshift" the workspace origin. This means that the viewTop would be representing the top edge of the blocklyDiv, rather than the top edge of the workspace.
setMetrics
function(non-null {x:number, y:number}) returns void
Translates the workspace.
startScrollX
number
Horizontal scroll value when scrolling started in pixel units.
startScrollY
number
Vertical scroll value when scrolling started in pixel units.
svgBackground_
SVGElement
svgBlockCanvas_
SVGElement
svgBlockCanvas_
non-null SVGGElement
svgBlockCanvas_
non-null SVGElement
svgBlockCanvas_
non-null SVGElement
svgBubbleCanvas_
SVGElement
svgBubbleCanvas_
non-null SVGGElement
svgBubbleCanvas_
non-null SVGElement
svgBubbleCanvas_
non-null SVGElement
svgGroup_
SVGElement
targetWorkspace
In a flyout, the target workspace where blocks should be placed after a drag. Otherwise null.
themeManager_
non-null Blockly.ThemeManager
Object in charge of storing and updating the workspace theme.
toolboxPosition
unknown
- Inherited from
- Blockly.Workspace#toolboxPosition
trashcan
The workspace's trashcan (if any).
trashcan
undoStack_
unknown
- Inherited from
- Blockly.Workspace#undoStack_
zoomControls_
Methods
resizeSvgContents
resizeSvgContents(workspace)
Size the workspace when the contents change. This also updates scrollbars accordingly.
Parameter |
|
---|---|
workspace |
The workspace to resize. Value must not be null. |
addChangeListener
addChangeListener(func) returns function()
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.
Parameter |
|
---|---|
func |
Function to call. Value must not be null. |
- Inherited from
- Blockly.Workspace#addChangeListener
- Returns
-
Obsolete return value, ignore.
addFlyout
addFlyout(tagName) returns Element
Add a flyout element in an element with the given tag name.
Parameter |
|
---|---|
tagName |
(string, non-null Blockly.utils.Svg containing non-null SVGSVGElement, or non-null Blockly.utils.Svg containing non-null SVGGElement) What type of tag the flyout belongs in. |
- Returns
-
non-null Element
The element containing the flyout DOM.
addTopBlock
addTopBlock(block)
Adds a block to the list of top blocks.
Parameter |
|
---|---|
block |
Block to add. Value must not be null. |
addTopBoundedElement
addTopBoundedElement(element)
Adds a bounded element to the list of top bounded elements.
Parameter |
|
---|---|
element |
Bounded element to add. Value must not be null. |
addTopComment
addTopComment(comment)
Adds a comment to the list of top comments.
Parameter |
|
---|---|
comment |
comment to add. Value must not be null. |
addTrashcan
addTrashcan()
Add a trashcan.
addTypedBlock
addTypedBlock(block)
Add a block to the list of blocks keyed by type.
Parameter |
|
---|---|
block |
Block to add. Value must not be null. |
- Inherited from
- Blockly.Workspace#addTypedBlock
addZoomControls
addZoomControls()
Add zoom controls.
allInputsFilled
allInputsFilled(opt_shadowBlocksAreFilled) returns boolean
Checks whether all value and statement inputs in the workspace are filled with blocks.
Parameter |
|
---|---|
opt_shadowBlocksAreFilled |
Optional An optional argument controlling whether shadow blocks are counted as filled. Defaults to true. |
- Inherited from
- Blockly.Workspace#allInputsFilled
- Returns
-
True if all inputs are filled, false otherwise.
beginCanvasTransition
beginCanvasTransition()
Add a transition class to the block and bubble canvas, to animate any transform changes.
cancelCurrentGesture
cancelCurrentGesture()
Cancel the current gesture, if one exists.
centerOnBlock
centerOnBlock(id)
Scroll the workspace to center on the given block. If the block has other blocks stacked below it, the workspace will be centered on the stack.
Parameter |
|
---|---|
id |
string ID of block center on. Value may be null. |
cleanUp
cleanUp()
Clean up the workspace by ordering all the blocks in a column.
clear
clear()
Dispose of all blocks in workspace, with an optimization to prevent resizes.
clearGesture
clearGesture()
Clear the reference to the current gesture.
clearUndo
clearUndo()
Clear the undo/redo stacks.
- Inherited from
- Blockly.Workspace#clearUndo
createDom
createDom(opt_backgroundClass) returns Element
Create the workspace DOM elements.
Parameter |
|
---|---|
opt_backgroundClass |
Optional string Either 'blocklyMainBackground' or 'blocklyMutatorBackground'. |
- Returns
-
non-null Element
The workspace's SVG group.
createPotentialVariableMap
createPotentialVariableMap()
Create and store the potential variable map for this workspace.
- Inherited from
- Blockly.Workspace#createPotentialVariableMap
createVariable
createVariable(name, opt_type, opt_id) returns Blockly.VariableModel
Create a new variable with the given name. Update the flyout to show the new variable immediately.
Parameter |
|
---|---|
name |
string The new variable's name. |
opt_type |
Optional string 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. Value may be null. |
opt_id |
Optional string The unique ID of the variable. This will default to a UUID. Value may be null. |
- Returns
-
non-null Blockly.VariableModel
The newly created variable.
deleteVariableById
deleteVariableById(id)
Delete a variable by the passed in ID. Update the flyout to show immediately that the variable is deleted.
Parameter |
|
---|---|
id |
string ID of variable to delete. |
dispose
dispose()
Dispose of this workspace. Unlink from all DOM elements to prevent memory leaks.
endCanvasTransition
endCanvasTransition()
Remove transition class from the block and bubble canvas.
fireChangeListener
fireChangeListener(event)
Fire a change event.
Parameter |
|
---|---|
event |
Event to fire. Value must not be null. |
- Inherited from
- Blockly.Workspace#fireChangeListener
getAllBlocks
getAllBlocks(ordered) returns Array of non-null Blockly.BlockSvg
Find all blocks in workspace. Blocks are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
Parameter |
|
---|---|
ordered |
boolean Sort the list if true. |
- Returns
-
non-null Array of non-null Blockly.BlockSvg
Array of blocks.
getAllVariableNames
getAllVariableNames() returns Array of string
Returns all variable names of all types.
- Inherited from
- Blockly.Workspace#getAllVariableNames
- Returns
-
List of all variable names of all types.
getAllVariables
getAllVariables() returns Array of non-null Blockly.VariableModel
Return all variables of all types.
- Inherited from
- Blockly.Workspace#getAllVariables
- Returns
-
List of variable models.
getAudioManager
getAudioManager() returns Blockly.WorkspaceAudio
Get the audio manager for this workspace.
- Returns
-
non-null Blockly.WorkspaceAudio
The audio manager for this workspace.
getBlockById
getBlockById(id) returns Blockly.BlockSvg
Find the block on this workspace with the specified ID.
Parameter |
|
---|---|
id |
ID of block to find. |
- Inherited from
- Blockly.WorkspaceSvg#getBlockById
- Returns
-
The sought after block, or null if not found.
getBlockCanvas
getBlockCanvas() returns SVGElement
Get the SVG block canvas for the workspace.
- Returns
-
nullable SVGElement
The SVG group for the workspace.
getBlockDragSurface
getBlockDragSurface() returns Blockly.BlockDragSurfaceSvg
Gets the drag surface blocks are moved to when a drag is started.
- Returns
-
nullable Blockly.BlockDragSurfaceSvg
This workspace's block drag surface, if one is in use.
getBlocksBoundingBox
getBlocksBoundingBox() returns Blockly.utils.Rect
Calculate the bounding box for the blocks on the workspace. Coordinate system: workspace coordinates.
- Returns
-
non-null Blockly.utils.Rect
Contains the position and size of the bounding box containing the blocks on the workspace.
getBlocksByType
getBlocksByType(type, ordered) returns Array of non-null Blockly.Block
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).
Parameter |
|
---|---|
type |
The type of block to search for. |
ordered |
Sort the list if true. |
- Inherited from
- Blockly.Workspace#getBlocksByType
- Returns
-
The blocks of the given type.
getBubbleCanvas
getBubbleCanvas() returns SVGGElement
Get the SVG element that forms the bubble surface.
- Returns
-
non-null SVGGElement
SVG group element.
getButtonCallback
getButtonCallback(key) returns function()
Get the callback function associated with a given key, for clicks on buttons and labels in the flyout.
Parameter |
|
---|---|
key |
string The name to use to look up the function. |
- Returns
-
nullable function(non-null Blockly.FlyoutButton)
The function corresponding to the given key for this workspace; null if no callback is registered.
getCachedParentSvgSize
getCachedParentSvgSize() returns Blockly.utils.Size
Gets the size of the workspace's parent SVG element.
- Returns
-
non-null Blockly.utils.Size
The cached width and height of the workspace's parent SVG element.
getCanvas
getCanvas() returns SVGGElement
Get the SVG element that forms the drawing surface.
- Returns
-
non-null SVGGElement
SVG group element.
getCommentById
getCommentById(id) returns Blockly.WorkspaceComment
Find the comment on this workspace with the specified ID.
Parameter |
|
---|---|
id |
ID of comment to find. |
- Inherited from
- Blockly.Workspace#getCommentById
- Returns
-
The sought after comment, or null if not found.
getComponentManager
getComponentManager() returns Blockly.ComponentManager
Gets the component manager for this workspace.
- Returns
-
non-null Blockly.ComponentManager
The component manager.
getCursor
getCursor() returns Blockly.Cursor
The cursor for this workspace.
- Returns
-
nullable Blockly.Cursor
The cursor for the workspace.
getDragTarget
getDragTarget(e) returns Blockly.IDragTarget
Returns the drag target the mouse event is over.
Parameter |
|
---|---|
e |
Event Mouse move event. Value must not be null. |
- Returns
-
nullable Blockly.IDragTarget
Null if not over a drag target, or the drag target the event is over.
getFlyout
getFlyout(opt_own) returns Blockly.IFlyout
Getter for the flyout associated with this workspace. This flyout may be owned by either the toolbox or the workspace, depending on toolbox configuration. It will be null if there is no flyout.
Parameter |
|
---|---|
opt_own |
Optional boolean Whether to only return the workspace's own flyout. |
- Returns
-
nullable Blockly.IFlyout
The flyout on this workspace.
getGesture
getGesture(e) returns Blockly.TouchGesture
Look up the gesture that is tracking this touch stream on this workspace. May create a new gesture.
Parameter |
|
---|---|
e |
Event Mouse event or touch event. Value must not be null. |
- Returns
-
nullable Blockly.TouchGesture
The gesture that is tracking this touch stream, or null if no valid gesture exists.
getGrid
getGrid() returns Blockly.Grid
Get the grid object for this workspace, or null if there is none.
- Returns
-
nullable Blockly.Grid
The grid object for this workspace.
getInjectionDiv
getInjectionDiv() returns Element
Return the injection div that is a parent of this workspace. Walks the DOM the first time it's called, then returns a cached value. Note: We assume this is only called after the workspace has been injected into the DOM.
- Returns
-
non-null Element
The first parent div with 'injectionDiv' in the name.
getInverseScreenCTM
getInverseScreenCTM() returns SVGMatrix
Getter for the inverted screen CTM.
- Returns
-
nullable SVGMatrix
The matrix to use in mouseToSvg
getMarker
getMarker(id) returns Blockly.Marker
Get the marker with the given ID.
Parameter |
|
---|---|
id |
string The ID of the marker. |
- Returns
-
nullable Blockly.Marker
The marker with the given ID or null if no marker with the given ID exists.
getMarkerManager
getMarkerManager() returns Blockly.MarkerManager
Get the marker manager for this workspace.
- Returns
-
non-null Blockly.MarkerManager
The marker manager.
getMetricsManager
getMetricsManager() returns Blockly.IMetricsManager
Gets the metrics manager for this workspace.
- Returns
-
non-null Blockly.IMetricsManager
The metrics manager.
getOriginOffsetInPixels
getOriginOffsetInPixels() returns Blockly.utils.Coordinate
Return the position of the workspace origin relative to the injection div origin in pixels. The workspace origin is where a block would render at position (0, 0). It is not the upper left corner of the workspace SVG.
- Returns
-
non-null Blockly.utils.Coordinate
Offset in pixels.
getParentSvg
getParentSvg() returns SVGElement
Get the SVG element that contains this workspace. Note: We assume this is only called after the workspace has been injected into the DOM.
- Returns
-
non-null SVGElement
SVG element.
getPotentialVariableMap
getPotentialVariableMap() returns Blockly.VariableMap
Return the variable map that contains "potential" variables. These exist in the flyout but not in the workspace.
- Inherited from
- Blockly.Workspace#getPotentialVariableMap
- Returns
-
The potential variable map.
getRedoStack
getRedoStack() returns Array of non-null Blockly.Events.Abstract
Gets the redo stack for workplace.
- Inherited from
- Blockly.Workspace#getRedoStack
- Returns
-
redo stack
getRenderer
getRenderer() returns Blockly.blockRendering.Renderer
Get the block renderer attached to this workspace.
- Returns
-
non-null Blockly.blockRendering.Renderer
The renderer attached to this workspace.
getScale
getScale() returns number
Get the workspace's zoom factor. If the workspace has a parent, we call into the parent to get the workspace scale.
- Returns
-
number
The workspace zoom factor. Units: (pixels / workspaceUnit).
getSvgXY
getSvgXY(element) returns Blockly.utils.Coordinate
Return the absolute coordinates of the top-left corner of this element, scales that after canvas SVG element, if it's a descendant. The origin (0,0) is the top-left corner of the Blockly SVG.
Parameter |
|
---|---|
element |
SVGElement SVG element to find the coordinates of. Value must not be null. |
- Returns
-
non-null Blockly.utils.Coordinate
Object with .x and .y properties.
getTheme
getTheme() returns Blockly.Theme
Get the workspace theme object.
- Returns
-
non-null Blockly.Theme
The workspace theme object.
getThemeManager
getThemeManager() returns Blockly.ThemeManager
Get the theme manager for this workspace.
- Returns
-
non-null Blockly.ThemeManager
The theme manager for this workspace.
getToolbox
getToolbox() returns Blockly.IToolbox
Getter for the toolbox associated with this workspace, if one exists.
- Returns
-
nullable Blockly.IToolbox
The toolbox on this workspace.
getToolboxCategoryCallback
getToolboxCategoryCallback(key) returns function()
Get the callback function associated with a given key, for populating custom toolbox categories in this workspace.
Parameter |
|
---|---|
key |
string The name to use to look up the function. |
- Returns
-
nullable function(non-null Blockly.WorkspaceSvg) returns non-null Blockly.utils.toolbox.FlyoutDefinition
The function corresponding to the given key for this workspace, or null if no function is registered.
getTopBlocks
getTopBlocks(ordered) returns Array of non-null Blockly.BlockSvg
Finds the top-level blocks and returns them. Blocks are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
Parameter |
|
---|---|
ordered |
Sort the list if true. |
- Inherited from
- Blockly.WorkspaceSvg#getTopBlocks
- Returns
-
The top-level block objects.
getTopBoundedElements
getTopBoundedElements() returns Array of non-null Blockly.IBoundedElement
Finds the top-level bounded elements and returns them.
- Returns
-
non-null Array of non-null Blockly.IBoundedElement
The top-level bounded elements.
getTopComments
getTopComments(ordered) returns Array of non-null Blockly.WorkspaceComment
Finds the top-level comments and returns them. Comments are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
Parameter |
|
---|---|
ordered |
Sort the list if true. |
- Inherited from
- Blockly.Workspace#getTopComments
- Returns
-
The top-level comment objects.
getUndoStack
getUndoStack() returns Array of non-null Blockly.Events.Abstract
Gets the undo stack for workplace.
- Inherited from
- Blockly.Workspace#getUndoStack
- Returns
-
undo stack
getVariable
getVariable(name, opt_type) returns Blockly.VariableModel
Find the variable by the given name and return it. Return null if not found.
Parameter |
|
---|---|
name |
The name to check for. |
opt_type |
Optional The type of the variable. If not provided it defaults to the empty string, which is a specific type. |
- Inherited from
- Blockly.Workspace#getVariable
- Returns
-
The variable with the given name.
getVariableById
getVariableById(id) returns Blockly.VariableModel
Find the variable by the given ID and return it. Return null if not found.
Parameter |
|
---|---|
id |
The ID to check for. |
- Inherited from
- Blockly.Workspace#getVariableById
- Returns
-
The variable with the given ID.
getVariableMap
getVariableMap() returns Blockly.VariableMap
Return the map of all variables on the workspace.
- Inherited from
- Blockly.Workspace#getVariableMap
- Returns
-
The variable map.
getVariablesOfType
getVariablesOfType(type) returns Array of non-null Blockly.VariableModel
Find the variable with the specified type. If type is null, return list of variables with empty string type.
Parameter |
|
---|---|
type |
Type of the variables to find. Value may be null. |
- Inherited from
- Blockly.Workspace#getVariablesOfType
- Returns
-
The sought after variables of the passed in type. An empty array if none are found.
getVariableTypes
getVariableTypes() returns Array of string
Return all variable types.
- Inherited from
- Blockly.Workspace#getVariableTypes
- Returns
-
List of variable types.
getVariableUsesById
getVariableUsesById(id) returns Array of non-null Blockly.Block
Find all the uses of the given variable, which is identified by ID.
Parameter |
|
---|---|
id |
ID of the variable to find. |
- Inherited from
- Blockly.Workspace#getVariableUsesById
- Returns
-
Array of block usages.
getWidth
getWidth() returns number
Returns the horizontal offset of the workspace. Intended for LTR/RTL compatibility in XML.
- Returns
-
number
Width.
hasBlockLimits
hasBlockLimits() returns boolean
Checks if the workspace has any limits on the maximum number of blocks, or the maximum number of blocks of specific types.
- Inherited from
- Blockly.Workspace#hasBlockLimits
- Returns
-
True if it has block limits, false otherwise.
hideChaff
hideChaff(opt_onlyClosePopups)
Close tooltips, context menus, dropdown selections, etc.
Parameter |
|
---|---|
opt_onlyClosePopups |
Optional boolean Whether only popups should be closed. |
highlightBlock
highlightBlock(id, opt_state)
Highlight or unhighlight a block in the workspace. Block highlighting is often used to visually mark blocks currently being executed.
Parameter |
|
---|---|
id |
string ID of block to highlight/unhighlight, or null for no block (used to unhighlight all blocks). Value may be null. |
opt_state |
Optional boolean If undefined, highlight specified block and automatically unhighlight all others. If true or false, manually highlight/unhighlight the specified block. |
isCapacityAvailable
isCapacityAvailable(typeCountsMap) returns boolean
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.
Parameter |
|
---|---|
typeCountsMap |
A map of types to counts (usually representing blocks to be created). Value must not be null. |
- Inherited from
- Blockly.Workspace#isCapacityAvailable
- Returns
-
True if there is capacity for the given map, false otherwise.
isDraggable
isDraggable() returns boolean
Is this workspace draggable?
- Returns
-
boolean
True if this workspace may be dragged.
isDragging
isDragging() returns boolean
Is the user currently dragging a block or scrolling the flyout/workspace?
- Returns
-
boolean
True if currently dragging or scrolling.
isMovable
isMovable() returns boolean
Is this workspace movable?
This means the user can reposition the X Y coordinates of the workspace through input. This can be through scrollbars, scroll wheel, dragging, or through zooming with the scroll wheel or pinch (since the zoom is centered on the mouse position). This does not include zooming with the zoom controls since the X Y coordinates are decided programmatically.
- Returns
-
boolean
True if the workspace is movable, false otherwise.
isMovableHorizontally
isMovableHorizontally() returns boolean
Is this workspace movable horizontally?
- Returns
-
boolean
True if the workspace is movable horizontally, false otherwise.
isMovableVertically
isMovableVertically() returns boolean
Is this workspace movable vertically?
- Returns
-
boolean
True if the workspace is movable vertically, false otherwise.
isVisible
isVisible() returns boolean
Getter for isVisible
- Returns
-
boolean
Whether the workspace is visible. False if the workspace has been hidden by callingsetVisible(false)
.
markFocused
markFocused()
Mark this workspace as the currently focused main workspace.
maybeFireViewportChangeEvent
maybeFireViewportChangeEvent()
Fires a viewport event if events are enabled and there is a change in viewport values.
moveDrag
moveDrag(e) returns Blockly.utils.Coordinate
Track a drag of an object on this workspace.
Parameter |
|
---|---|
e |
Event Mouse move event. Value must not be null. |
- Returns
-
non-null Blockly.utils.Coordinate
New location of object.
newBlock
newBlock(prototypeName, opt_id) returns Blockly.BlockSvg
Obtain a newly created block.
This block's SVG must still be initialized (initSvg) and it must be rendered (render) before the block will be visible.
Parameter |
|
---|---|
prototypeName |
Name of the language object containing type-specific functions for this block. Value must not be null. |
opt_id |
Optional Optional ID. Use this ID if provided, otherwise create a new ID. |
- Inherited from
- Blockly.WorkspaceSvg#newBlock
- Returns
-
The created block.
paste
paste(state) returns (Blockly.ICopyable or null)
Pastes the provided block or workspace comment onto the workspace. Does not check whether there is remaining capacity for the object, that should be done before calling this method.
Parameter |
|
---|---|
state |
(non-null Object, non-null Element, or non-null DocumentFragment) The representation of the thing to paste. |
- Returns
-
(non-null Blockly.ICopyable or null)
The pasted thing, or null if the paste was not successful.
recordDeleteAreas
recordDeleteAreas()
Make a list of all the delete areas for this workspace.
- Deprecated
- Use workspace.recordDragTargets. (2021 June)
recordDragTargets
recordDragTargets()
Make a list of all the delete areas for this workspace.
refreshTheme
refreshTheme()
Refresh all blocks on the workspace after a theme update.
refreshToolboxSelection
refreshToolboxSelection()
Refresh the toolbox unless there's a drag in progress.
registerButtonCallback
registerButtonCallback(key, func)
Register a callback function associated with a given key, for clicks on buttons and labels in the flyout. For instance, a button specified by the XML should be matched by a call to registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
Parameter |
|
---|---|
key |
string The name to use to look up this function. |
func |
function(non-null Blockly.FlyoutButton) The function to call when the given button is clicked. |
registerToolboxCategoryCallback
registerToolboxCategoryCallback(key, func)
Register a callback function associated with a given key, for populating custom toolbox categories in this workspace. See the variable and procedure categories as an example.
Parameter |
|
---|---|
key |
string The name to use to look up this function. |
func |
function(non-null Blockly.WorkspaceSvg) The function to call when the given toolbox category is opened. |
remainingCapacity
remainingCapacity() returns number
The number of blocks that may be added to the workspace before reaching the maxBlocks.
- Inherited from
- Blockly.Workspace#remainingCapacity
- Returns
-
Number of blocks left.
remainingCapacityOfType
remainingCapacityOfType(type) returns number
The number of blocks of the given type that may be added to the workspace before reaching the maxInstances allowed for that type.
Parameter |
|
---|---|
type |
Type of block to return capacity for. |
- Inherited from
- Blockly.Workspace#remainingCapacityOfType
- Returns
-
Number of blocks of type left.
removeBlockById
removeBlockById(id)
Delete a block off this workspace with the specified ID.
Parameter |
|
---|---|
id |
ID of block to delete. |
- Inherited from
- Blockly.Workspace#removeBlockById
removeButtonCallback
removeButtonCallback(key)
Remove a callback for a click on a button in the flyout.
Parameter |
|
---|---|
key |
string The name associated with the callback function. |
removeChangeListener
removeChangeListener(func)
Stop listening for this workspace's changes.
Parameter |
|
---|---|
func |
Function to stop calling. Value must not be null. |
- Inherited from
- Blockly.Workspace#removeChangeListener
removeToolboxCategoryCallback
removeToolboxCategoryCallback(key)
Remove a callback for a click on a custom category's name in the toolbox.
Parameter |
|
---|---|
key |
string The name associated with the callback function. |
removeTopBlock
removeTopBlock(block)
Removes a block from the list of top blocks.
Parameter |
|
---|---|
block |
Block to remove. Value must not be null. |
removeTopBoundedElement
removeTopBoundedElement(element)
Removes a bounded element from the list of top bounded elements.
Parameter |
|
---|---|
element |
Bounded element to remove. Value must not be null. |
removeTopComment
removeTopComment(comment)
Removes a comment from the list of top comments.
Parameter |
|
---|---|
comment |
comment to remove. Value must not be null. |
removeTypedBlock
removeTypedBlock(block)
Remove a block from the list of blocks keyed by type.
Parameter |
|
---|---|
block |
Block to remove. Value must not be null. |
- Inherited from
- Blockly.Workspace#removeTypedBlock
renameVariableById
renameVariableById(id, newName)
Rename a variable by updating its name in the variable map. Update the flyout to show the renamed variable immediately.
Parameter |
|
---|---|
id |
string ID of the variable to rename. |
newName |
string New variable name. |
render
render()
Render all blocks in workspace.
resetDragSurface
resetDragSurface()
Called at the end of a workspace drag to take the contents out of the drag surface and put them back into the workspace SVG. Does nothing if the workspace drag surface is not enabled.
resize
resize()
Resize and reposition all of the workspace chrome (toolbox, trash, scrollbars etc.) This should be called when something changes that requires recalculating dimensions and positions of the trash, zoom, toolbox, etc. (e.g. window resize).
resizeContents
resizeContents()
If enabled, resize the parts of the workspace that change when the workspace contents (e.g. block positions) change. This will also scroll the workspace contents if needed.
scroll
scroll(x, y)
Scroll the workspace to a specified offset (in pixels), keeping in the workspace bounds. See comment on workspaceSvg.scrollX for more detail on the meaning of these values.
Parameter |
|
---|---|
x |
number Target X to scroll to. |
y |
number Target Y to scroll to. |
scrollCenter
scrollCenter()
Center the workspace.
setBlockById
setBlockById(id, block)
Set a block on this workspace with the specified ID.
Parameter |
|
---|---|
id |
ID of block to set. |
block |
The block to set. |
- Inherited from
- Blockly.Workspace#setBlockById
setCachedParentSvgSize
setCachedParentSvgSize(width, height)
Caches the width and height of the workspace's parent SVG element for use with getSvgMetrics.
Parameter |
|
---|---|
width |
number The width of the parent SVG element. Value may be null. |
height |
number The height of the parent SVG element Value may be null. |
setCursorSvg
setCursorSvg(cursorSvg)
Add the cursor SVG to this workspaces SVG group.
Parameter |
|
---|---|
cursorSvg |
SVGElement The SVG root of the cursor to be added to the workspace SVG group. |
- Implements
- Blockly.IASTNodeLocationSvg#setCursorSvg
setMarkerSvg
setMarkerSvg(markerSvg)
Add the marker SVG to this workspaces SVG group.
Parameter |
|
---|---|
markerSvg |
SVGElement The SVG root of the marker to be added to the workspace SVG group. |
- Implements
- Blockly.IASTNodeLocationSvg#setMarkerSvg
setMetricsManager
setMetricsManager(metricsManager)
Sets the metrics manager for the workspace.
Parameter |
|
---|---|
metricsManager |
The metrics manager. Value must not be null. |
setResizeHandlerWrapper
setResizeHandlerWrapper(handler)
Save resize handler data so we can delete it later in dispose.
Parameter |
|
---|---|
handler |
Data that can be passed to eventHandling.unbind. Value must not be null. |
setResizesEnabled
setResizesEnabled(enabled)
Update whether this workspace has resizes enabled. If enabled, workspace will resize when appropriate. If disabled, workspace will not resize until re-enabled. Use to avoid resizing during a batch operation, for performance.
Parameter |
|
---|---|
enabled |
boolean Whether resizes should be enabled. |
setScale
setScale(newScale)
Set the workspace's zoom factor.
Parameter |
|
---|---|
newScale |
number Zoom factor. Units: (pixels / workspaceUnit). |
setTheme
setTheme(theme)
Set the workspace theme object.
If no theme is passed, default to the Classic
theme.
Parameter |
|
---|---|
theme |
The workspace theme object. |
setupDragSurface
setupDragSurface()
Called at the beginning of a workspace drag to move contents of the workspace to the drag surface. Does nothing if the drag surface is not enabled.
setVariableMap
setVariableMap(variableMap)
Set the map of all variables on the workspace.
Parameter |
|
---|---|
variableMap |
The variable map. Value must not be null. |
- Inherited from
- Blockly.Workspace#setVariableMap
setVisible
setVisible(isVisible)
Toggles the visibility of the workspace. Currently only intended for main workspace.
Parameter |
|
---|---|
isVisible |
boolean True if workspace should be visible. |
showContextMenu
showContextMenu(e)
Show the context menu for the workspace.
Parameter |
|
---|---|
e |
Event Mouse event. Value must not be null. |
startDrag
startDrag(e, xy)
Start tracking a drag of an object on this workspace.
Parameter |
|
---|---|
e |
Event Mouse down event. Value must not be null. |
xy |
Starting location of object. Value must not be null. |
translate
translate(x, y)
Translate this workspace to new coordinates.
Parameter |
|
---|---|
x |
number Horizontal translation, in pixel units relative to the top left of the Blockly div. |
y |
number Vertical translation, in pixel units relative to the top left of the Blockly div. |
undo
undo(redo)
Undo or redo the previous action.
Parameter |
|
---|---|
redo |
False if undo, true if redo. |
- Inherited from
- Blockly.Workspace#undo
updateInverseScreenCTM
updateInverseScreenCTM()
Mark the inverse screen CTM as dirty.
updateScreenCalculationsIfScrolled
updateScreenCalculationsIfScrolled()
Resizes and repositions workspace chrome if the page has a new scroll position.
updateToolbox
updateToolbox(toolboxDef)
Modify the block tree on the existing toolbox.
Parameter |
|
---|---|
toolboxDef |
Blockly.utils.toolbox.ToolboxDefinition DOM tree of toolbox contents, string of toolbox contents, or JSON representing toolbox definition. Value may be null. |
zoom
zoom(x, y, amount)
Zooms the workspace in or out relative to/centered on the given (x, y) coordinate.
Parameter |
|
---|---|
x |
number X coordinate of center, in pixel units relative to the top-left corner of the parentSVG. |
y |
number Y coordinate of center, in pixel units relative to the top-left corner of the parentSVG. |
amount |
number Amount of zooming. The formula for the new scale is newScale = currentScale * (scaleSpeed^amount). scaleSpeed is set in the workspace options. Negative amount values zoom out, and positive amount values zoom in. |
zoomCenter
zoomCenter(type)
Zooming the blocks centered in the center of view with zooming in or out.
Parameter |
|
---|---|
type |
number Type of zooming (-1 zooming out and 1 zooming in). |
zoomToFit
zoomToFit()
Zoom the blocks to fit in the workspace if possible.