Class for a workspace. This is an onscreen area with optional trashcan, scrollbars, bubbles, and dragging.
Dictionary of options.
Optionalopt_blockDragSurface: BlockDragSurfaceSvgDrag surface for blocks.
Optionalopt_wsDragSurface: WorkspaceDragSurfaceSvgDrag surface for the workspace.
An object that encapsulates logic for safety, type, and dragging checks.
Set of databases for rapid lookup of connection locations.
Method to get all the metrics that have to do with a workspace.
Returns true if the workspace is currently in the process of a bulk clear.
Is this workspace the surface for a flyout?
Is this workspace the surface for a mutator?
True if keyboard accessibility mode is on, false otherwise.
Maximum number of undo events in stack. 0 turns off undo, Infinity sets
it to unlimited.
The render status of an SVG workspace.
Returns false for headless workspaces and true for instances of
Blockly.WorkspaceSvg.
Current scale.
This workspace's scrollbars, if they exist.
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.
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.
Translates the workspace.
Horizontal scroll value when scrolling started in pixel units.
Vertical scroll value when scrolling started in pixel units.
In a flyout, the target workspace where blocks should be placed after a drag. Otherwise null.
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.
Function to call.
Obsolete return value, ignore.
Add a flyout element in an element with the given tag name.
What type of tag the flyout belongs in.
The element containing the flyout DOM.
Adds a bounded element to the list of top bounded elements.
Bounded element to add.
Adds a comment to the list of top comments.
comment to add.
Checks whether all value and statement inputs in the workspace are filled with blocks.
Optionalopt_shadowBlocksAreFilled: booleanAn optional argument controlling whether shadow blocks are counted as filled. Defaults to true.
True if all inputs are filled, false otherwise.
Scroll the workspace to center on the given block.
ID of block center on.
Clean up the workspace by ordering all the blocks in a column.
Dispose of all blocks in workspace, with an optimization to prevent resizes.
Clear the undo/redo stacks.
Create the workspace DOM elements.
Optionalopt_backgroundClass: stringEither 'blocklyMainBackground' or 'blocklyMutatorBackground'.
The workspace's SVG group.
Create a new variable with the given name. Update the flyout to show the new variable immediately.
The new variable's name.
Optionalopt_type: stringThe 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.
Optionalopt_id: stringThe unique ID of the variable. This will default to a UUID.
The newly created variable.
Delete a variable by the passed in ID. Update the flyout to show immediately that the variable is deleted.
ID of variable to delete.
Returns all variable names of all types.
List of all variable names of all types.
Get the audio manager for this workspace.
The audio manager for this workspace.
Gets the drag surface blocks are moved to when a drag is started.
This workspace's block drag surface, if one is in use.
Get the callback function associated with a given key, for clicks on buttons and labels in the flyout.
The name to use to look up the function.
The function corresponding to the given key for this workspace; null if no callback is registered.
Find the comment on this workspace with the specified ID.
ID of comment to find.
The sought after comment, or null if not found.
Gets the component manager for this workspace.
The component manager.
Returns the drag target the mouse event is over.
Mouse move event.
Null if not over a drag target, or the drag target the event is over.
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.
Optionalopt_own: booleanWhether to only return the workspace's own flyout.
The flyout on this workspace.
Look up the gesture that is tracking this touch stream on this workspace. May create a new gesture.
Mouse event or touch event.
The gesture that is tracking this touch stream, or null if no valid gesture exists.
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.
The first parent div with 'injectionDiv' in the name.
Get the marker with the given ID.
The ID of the marker.
The marker with the given ID or null if no marker with the given ID exists.
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.
Offset in pixels.
Get the SVG element that contains this workspace. Note: We assume this is only called after the workspace has been injected into the DOM.
SVG element.
Return the variable map that contains "potential" variables. These exist in the flyout but not in the workspace.
The potential variable map.
Get the block renderer attached to this workspace.
The renderer attached to this workspace.
Get the workspace's zoom factor. If the workspace has a parent, we call into the parent to get the workspace scale.
The workspace zoom factor. Units: (pixels / workspaceUnit).
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.
SVG element to find the coordinates of.
Object with .x and .y properties.
Get the theme manager for this workspace.
The theme manager for this workspace.
Getter for the toolbox associated with this workspace, if one exists.
The toolbox on this workspace.
Get the callback function associated with a given key, for populating custom toolbox categories in this workspace.
The name to use to look up the function.
The function corresponding to the given key for this workspace, or null if no function is registered.
Finds the top-level bounded elements and returns them.
The top-level bounded elements.
Finds the top-level comments and returns them. Comments are optionally sorted by position; top to bottom (with slight LTR or RTL bias).
Sort the list if true.
The top-level comment objects.
Find the variable by the given name and return it. Return null if not found.
The name to check for.
Optionalopt_type: stringThe type of the variable. If not provided it defaults to the empty string, which is a specific type.
The variable with the given name.
Find the variable by the given ID and return it. Return null if not found.
The ID to check for.
The variable with the given ID.
Find the variable with the specified type. If type is null, return list of variables with empty string type.
Type of the variables to find.
The sought after variables of the passed in type. An empty array if none are found.
Returns the horizontal offset of the workspace. Intended for LTR/RTL compatibility in XML.
Width.
Checks if the workspace has any limits on the maximum number of blocks, or the maximum number of blocks of specific types.
True if it has block limits, false otherwise.
Highlight or unhighlight a block in the workspace. Block highlighting is often used to visually mark blocks currently being executed.
ID of block to highlight/unhighlight, or null for no block (used to unhighlight all blocks).
Optionalopt_state: booleanIf undefined, highlight specified block and automatically unhighlight all others. If true or false, manually highlight/unhighlight the specified block.
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.
A map of types to counts (usually representing blocks to be created).
True if there is capacity for the given map, false otherwise.
Is this workspace draggable?
True if this workspace may be dragged.
Is the user currently dragging a block or scrolling the flyout/workspace?
True if currently dragging or scrolling.
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.
True if the workspace is movable, false otherwise.
Is this workspace movable horizontally?
True if the workspace is movable horizontally, false otherwise.
Is this workspace movable vertically?
True if the workspace is movable vertically, false otherwise.
Getter for isVisible
Whether the workspace is visible.
False if the workspace has been hidden by calling setVisible(false).
Mark this workspace as the currently focused main workspace.
Track a drag of an object on this workspace.
Mouse move event.
New location of object.
Paste the provided block onto the workspace.
XML block element or an empty DocumentFragment if the block was an insertion marker.
Make a list of all the delete areas for this workspace.
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).
The name to use to look up this function.
The function to call when the given button is clicked.
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.
The number of blocks that may be added to the workspace before reaching the maxBlocks.
Number of blocks left.
The number of blocks of the given type that may be added to the workspace before reaching the maxInstances allowed for that type.
Type of block to return capacity for.
Number of blocks of type left.
Remove a callback for a click on a button in the flyout.
The name associated with the callback function.
Stop listening for this workspace's changes.
Function to stop calling.
Remove a callback for a click on a custom category's name in the toolbox.
The name associated with the callback function.
Removes a bounded element from the list of top bounded elements.
Bounded element to remove.
Removes a comment from the list of top comments.
comment to remove.
Rename a variable by updating its name in the variable map. Update the flyout to show the renamed variable immediately.
ID of the variable to rename.
New variable name.
Render all blocks in workspace.
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).
Center the workspace.
Add the cursor SVG to this workspaces SVG group.
The SVG root of the cursor to be added to the workspace SVG group.
Add the marker SVG to this workspaces SVG group.
The SVG root of the marker to be added to the workspace SVG group.
Sets the metrics manager for the workspace.
The metrics manager.
Save resize handler data so we can delete it later in dispose.
Data that can be passed to eventHandling.unbind.
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.
Whether resizes should be enabled.
Set the workspace's zoom factor.
Zoom factor. Units: (pixels / workspaceUnit).
Set the map of all variables on the workspace.
The variable map.
Toggles the visibility of the workspace. Currently only intended for main workspace.
True if workspace should be visible.
Start tracking a drag of an object on this workspace.
Mouse down event.
Starting location of object.
Translate this workspace to new coordinates.
Horizontal translation, in pixel units relative to the top left of the Blockly div.
Vertical translation, in pixel units relative to the top left of the Blockly div.
Undo or redo the previous action.
False if undo, true if redo.
Mark the inverse screen CTM as dirty.
Modify the block tree on the existing toolbox.
DOM tree of toolbox contents, string of toolbox contents, or JSON representing toolbox definition.
Zooms the workspace in or out relative to/centered on the given (x, y) coordinate.
X coordinate of center, in pixel units relative to the top-left corner of the parentSVG.
Y coordinate of center, in pixel units relative to the top-left corner of the parentSVG.
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.
Zooming the blocks centered in the center of view with zooming in or out.
Type of zooming (-1 zooming out and 1 zooming in).
Zoom the blocks to fit in the workspace if possible.
Fake class which should be extended to avoid inheriting static properties