Creates an instance of DiagramEditView.
The unique identifier for the diagram.
The HTML element or canvas where the diagram will be rendered.
Optionalinitial: Partial<Omit<Diagram, "id">>Optional initial properties for the diagram.
ProtectedhistoryOptionalfileOptionalpromptsProtectedkeyboardProtectedcurrentProtectedsettingsProtectedfreehandProtectedpalette_ProtectedmodifiedProtectedcan_Protectedcan_Protected OptionalactiveThe unique identifier of the diagram, which is used to reference the diagram within the application and for serialization purposes.
An array of nodes that belong to the diagram, which represent the entities and elements that can be connected and manipulated within the diagram.
An optional array of groups that belong to the diagram, which can be used to organize nodes into visual collections. Grouped nodes maintain their relative positions.
An array of layers that belong to the diagram, which can be used to organize nodes into different visual layers.
Optionalsheet_An optional identifier for the sheet associated with the diagram, which can be used to apply specific styles and configurations to the diagram's nodes and connections.
OptionalbackgroundAn optional background fill style for the diagram, which can be used to set the background color or gradient of the diagram area.
OptionalmetaAn optional metadata object for the diagram, which can be used to store additional information about the diagram that is not part of its core structure. This can include custom properties, annotations, or any other relevant data that is not related to diagram rendering.
Protected ReadonlyownsOptionalcontextOptional context menu invoked when the user right-clicks on the canvas. Assign a DiagramContextMenu or ContextMenu instance here.
ProtectedcoordinatesProtectedcacheProtectedhostProtectedcanvasProtectedcontextProtectedpixelProtectedcanvasProtected Readonlyevent_Protected OptionalresizeProtectedselected_ProtectedselectionProtectedfitProtectedanimationsProtectedguidesProtecteddragProtecteddragProtected Optionalhover_Protected Optionalclick_Protected Optionaldouble_Indicates whether open-diagram operations are available.
True when file dialog integrations are configured.
Indicates whether open-stylesheet operations are available.
True when file dialog integrations are configured.
Indicates whether there is an active stylesheet that can be saved.
True when a current sheet can be resolved from the repository.
Gets the sheet repository used by this diagram.
Sets the sheet repository used by this diagram.
The sheet repository to set.
Gets the currently active sheet, if any.
The current sheet, or undefined if no sheet is active.
Sets the currently active sheet, applying its styles to the diagram and emitting a sheet-loaded event.
The sheet to set as current, or undefined to clear the current sheet.
Gets the active render mode for this view.
Gets the opacity of the first selected node, or the current default if nothing is selected. Returns a value in the range [0, 100].
Sets the default opacity and applies it to the current selection.
Opacity value in the range [0, 1].
Gets the current default line width for borders and connections.
Sets the default line width and applies it to current selection.
Line width value.
Gets the current default line dash pattern for borders and connections.
Sets the default line dash and applies it to the current selection.
Line dash value.
Gets the current arrow direction derived from the settings flags.
Sets the default arrow direction and applies it to current selection.
Arrow direction value.
Gets the current arrow type derived from the settings flags.
Gets the current default stroke color.
Sets the default stroke color and applies it to current selection.
Stroke color value.
Gets the current fill color.
Sets the default fill color and applies it to current selection.
Fill color value.
Gets the current default freehand stroke color.
Sets the default freehand stroke color and applies it to current selection.
Freehand stroke color value.
Gets the current default freehand line width.
Sets the default freehand line width and applies it to current selection.
Freehand line width value.
Gets the current default shadow style.
Sets the default shadow style and applies it to current selection.
Shadow style value.
Gets the current default stroke style as a composed object.
Sets the default stroke style and applies it to current selection.
Stroke style value.
Gets the default node text for newly created text-capable nodes.
Sets the default node text for newly created text-capable nodes.
Text value.
Gets the currently active tool identifier.
Gets whether the diagram has put nodes in the clipboard.
Gets whether the diagram has styles in the clipboard that can be pasted onto selected nodes.
Gets the image asset id shared by the current selection. Returns the common id when all selected nodes agree, or an empty string when the selection is empty, no node has an image, or nodes have different ids.
Returns the shared image_mode of the selection, or '' when mixed.
Returns the shared image_align of the selection, or '' when mixed.
Returns the shared image_padding of the selection, or -1 when mixed.
Returns true if there are actions in the undo stack that can be undone, false otherwise.
A boolean indicating whether an undo operation can be performed.
Returns true if there are actions in the redo stack that can be redone, false otherwise.
A boolean indicating whether a redo operation can be performed.
The diagram's asset store, for registering and resolving image/SVG asset sources.
The AssetStore instance associated with the diagram.
Gets the metadata object for the diagram. If no metadata exists, an empty object is returned.
The metadata object for the diagram.
Sets the metadata object for the diagram. If a null or undefined value is provided, the metadata is cleared.
The metadata object to set for the diagram.
Cleans up resources used by the diagram, such as event listeners and active text editors.
Clears clear.
Nothing.
Clears the current diagram after resolving any unsaved-change prompt. A prompt will be shown if the diagram has unsaved changes.
True when a new empty diagram was created; otherwise false.
Loads a diagram from a live diagram instance, a serialized JSON string, or a deserialized payload. A prompt will be shown if the diagram has unsaved changes.
The diagram source to load.
True when the source was loaded; otherwise false when loading was canceled.
Opens a diagram using configured file dialog behavior after resolving unsaved-change prompts.
Optionaloptions: DiagramOpenOptionsOptional open options or source overrides.
True when a diagram was opened; otherwise false.
Saves diagram.
Optional creation options.
The resolved value, or undefined when it cannot be resolved.
Saves image diagram.
Optional creation options.
The resolved value, or undefined when it cannot be resolved.
Loads a stylesheet payload into the repository and optionally applies it.
Stylesheet source as JSON string or sheet object.
Optional load behavior.
True when loading succeeded; otherwise false.
Opens a stylesheet using configured dialog behavior and delegates to loadStylesheet.
Optional open/load options.
True when loading succeeded; otherwise false.
Saves the current stylesheet (or a targeted sheet id) as JSON.
Optional save behavior.
The resolved filename, or undefined when canceled.
Sets the currently active sheet, applying its styles to the diagram and emitting a sheet-loaded event.
The sheet to set as current, or undefined to clear the current sheet.
Forks the current sheet to a diagram-scoped custom id on first mutation. When no sheet is active at all, creates a fresh empty custom sheet and emits sheet-loaded.
Publishes the current sheet under a new id/name so it can be reused by other diagrams. The current diagram is switched to the published sheet.
Optionaldescription: stringSets the current tool for the diagram. The default tool is 'select', which allows for selection and manipulation of existing nodes.
The name of the tool to set.
Optionaloptions: anyOptional parameters for the tool.
A promise that resolves when the tool is set.
Begins a tool drag-create gesture and lets the canvas own pointer capture.
Partial node data to initialize the draft.
OptionalpointerId: numberOptional pointer id for capture ownership transfer.
ProtectedcreateCreates a draft node for the current tool, if applicable. This is used for tools that create new nodes.
Partial node data to initialize the draft.
Sets the stroke color for the selected nodes and new nodes to be created.
The stroke color to set.
Sets the fill color for the selected nodes and new nodes to be created.
The fill color to set.
Sets background color.
The color value.
Nothing.
Sets or clears the image asset id on all selected nodes.
Asset id to apply, or undefined / empty string to clear the image.
Sets the opacity for the selected nodes and the default for new nodes.
Opacity in the range [0, 100].
Sets the line width for the selected nodes and new nodes to be created.
The line width to set.
Sets the line dash pattern for the selected nodes and new nodes to be created.
The line dash pattern to set, either as a string or an array of numbers.
Sets the arrow direction for the selected nodes and new nodes to be created.
The arrow direction to set.
Sets the arrow type for the selected nodes and new nodes to be created.
The arrow type to set.
Sets the stroke style for the selected nodes and new nodes to be created.
The stroke style to set.
Sets the fill style for the selected nodes and new nodes to be created.
The fill style to set.
Sets the shadow style for the selected nodes and new nodes to be created.
The shadow style to set.
Sets the text style for the selected nodes and new nodes to be created.
The text style to set.
Sets the text for the selected nodes and new nodes to be created.
The text to set.
Applies a flat patch record to all currently selected nodes, adding an undo step. Intended for use by inspector-style editors that produce a key-value diff. Also mirrors patch values into diagram default settings where applicable.
The key-value changes to apply.
The originating property key, used for the styleChanged event.
Applies a flat patch record to the diagram itself, adding an undo step. Intended for inspector-style editors that produce diagram.* key-value diffs.
The key-value changes to apply.
The originating property key, used for the styleChanged event.
List colors used in this diagram in descending order of their usage frequency.
Colors as an array of strings.
Indicates whether the diagram contains unsaved modifications.
Take a snapshot of the current diagram state and push it onto the undo stack.
This should be called before making any changes to the diagram that should be undoable.
After calling this method, the canUndo property will return true, indicating that there is now an action in the undo stack that can be undone.
Undoes the last action performed on the diagram, reverting it to the previous state.
Redoes the last undone action on the diagram, restoring it to the state before the undo was performed.
Copies styles.
Nothing.
Pastes styles.
Nothing.
Cuts the selected nodes, copying them to the clipboard and then deleting them from the diagram.
Copies the selected nodes to the clipboard in JSON format.
The copied data includes all properties of the nodes, allowing for accurate reconstruction when pasted.
After copying, the canPaste flag is set to true, indicating that there is data available in the clipboard that can be pasted into the diagram.
The clipboard operation type, either 'copy' or 'cut'. Defaults to 'copy'.
Pastes nodes from the clipboard into the diagram.
Select a layer to be the target for new nodes and operations.
The layer to set as the current layer.
Adds a new layer to the diagram at the specified position.
The layer ID.
The position to add the new layer ('top' or 'bottom').
Moves the selected nodes to a new layer.
Selects all nodes within the specified layer.
The layer whose nodes should be selected.
Shows the specified layer, making it visible in the diagram.
The layer to show.
Hides the specified layer, making it invisible in the diagram. Hidden layers are not rendered and their nodes cannot be interacted with until they are shown again.
The layer to hide.
Deletes the specified layer from the diagram.
The ID of the layer to delete.
Moves selected nodes one step toward the front, confined within their layers.
Moves selected nodes one step toward the back, confined within their layers.
Moves selected nodes to the front, confined within their layers.
Moves selected nodes to the back, confined within their layers.
Moves a node one step toward the front, confined within its layer.
The target node or node ID.
Moves a node one step toward the back, confined within its layer.
The target node or node ID.
Moves a node to the front, confined within its layer.
The target node or node ID.
Moves a node to the back, confined within its layer.
The target node or node ID.
Moves a layer one step toward the front.
The target layer or layer ID.
Moves a layer one step toward the back.
The target layer or layer ID.
Moves a layer to the front.
The target layer or layer ID.
Moves a layer to the back.
The target layer or layer ID.
Deletes the currently selected nodes from the diagram.
Clones the currently selected nodes in the diagram. The cloned nodes are offset by 24 pixels in both x and y directions. // TODO: Support groups cloning
ProtectedcloneHandles clone node.
The target node.
Optionalid: stringThe identifier value.
The computed result.
ProtectedcloneHandles clone nodes, including id remapping, reconnecting anchors, and handling groups.
The nodes to clone.
The cloned nodes, already inserted into the current layer.
Creates a new group from the currently selected nodes, assigning them a unique group ID.
Ungroups the currently selected nodes, removing them from any group they belong to.
Changes the type of the specified node.
The node or node ID to change the type of.
The new type to assign to the node.
Aligns the currently selected nodes in the specified direction.
The direction to align the nodes ('left', 'right', 'center', 'top', 'bottom', 'middle').
Spreads the currently selected nodes evenly in the specified direction.
The direction to spread the nodes ('row' or 'column').
Renders the diagram and any current drafts.
The rendering scope to perform.
Renders the selection markers for the specified node or all selected nodes if no node is specified.
Optionalnode: INodeThe node to render selection markers for. If not provided, all selected nodes are rendered.
The scope of anchors to show ('selection_handles' or 'connection_handles'). Defaults to 'selection_handles'.
Renders the connection-enabled handles for the specified node.
The node to render connection-enabled handles for.
ProtectedpointerRespond to pointer down events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
The pointer event.
ProtectedpointerRespond to pointer move events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
The pointer event.
ProtectedpointerRespond to pointer up events on the canvas, handling selection, panning, creation, and modification based on the event properties and current selection options.
The pointer event.
ProtecteddblHandles double click.
The mouse event.
ProtectedsetSets keyboard flag.
The keyboard event.
The is down value.
ProtectedkeydownRespond to key down events, handling deletion, copying, pasting, cutting, undoing, and exiting drawing mode based on the event properties and current selection state.
The keyboard event.
ProtectedkeyupHandles keyup.
The keyboard event.
ProtectedcontextmenuRespond to context menu events on the canvas, preventing the default context menu from appearing.
The pointer event.
Initializes the model, creating a default layer if none exist.
Renders preview output for the provided layer.
Optionallayer: ILayerOptional layer to preview.
ProtectedexitExits any current drawing or creating operation.
True when successful, otherwise false.
Zooms the canvas to a given level. Zooming to above 1 zooms in, below 1 zooms out. The zoom is centered on the given center point, or the center of the canvas if no center is provided.
The zoom value.
OptionalcenterX: numberThe center x value.
OptionalcenterY: numberThe center y value.
The animation mode for the zoom operation.
Pans the canvas by given deltas.
Horizontal delta value.
Vertical delta value.
The animation mode for the pan operation.
Moves selected nodes with undo.
Horizontal delta value.
Vertical delta value.
Opens image selection workflow for the current node selection.
Applies a selected image file to the current node selection.
Optionalevent: anyFile input event or undefined to trigger picker flow.
Applies an image source to all currently selected nodes.
The image source URL or data URL.
The image display mode, either 'contain' or 'cover'. Defaults to 'contain'.
OptionalimageId: stringOptional image identifier.
Applies SVG markup or source URL/data URL to all currently selected nodes.
The SVG markup string or source URL/data URL.
The image display mode, either 'contain' or 'cover'. Defaults to 'contain'.
OptionalimageId: stringOptional image identifier.
Clears image source configuration from all currently selected nodes. This does not remove images from the asset store.
Retrieves a node by its ID.
The ID of the node to retrieve.
The node with the specified ID, or undefined if not found.
Returns a group by its ID.
The ID of the group to return.
The group with the specified ID, or undefined if not found.
Retrieves a layer by its ID.
The ID of the layer to retrieve.
The layer with the specified ID, or undefined if not found.
Add or remove a node from a group. If the groupId is undefined, the node is removed from any group it belongs to. A node can only belong to one group at a time. If the node is already in a different group, it will be removed from that group before being added to the new group.
The node or node ID to add to the group.
The ID of the group to add the node to, or undefined to remove the node from any group.
ProtectedgroupAdd or remove a node from a layer. If the layerId is undefined, the node is removed from any layer it belongs to. A node can only belong to one layer at a time. If the node is already in a different layer, it will be removed from that layer before being added to the new layer.
The node or node ID to add to the layer.
The ID of the layer to add the node to, or undefined to remove the node from any layer.
Deletes a group from the diagram. Effectively ungrouping nodes.
The ID of the group to delete.
Resolves the concrete image source for a node image reference.
Clears all in-memory image assets. Intended for teardown paths.
Gets the value of a specific metadata key for the diagram.
Optionalkey: stringThe key of the metadata to retrieve.
The value of the specified metadata key, or undefined if the key does not exist.
Sets the value of a specific metadata key for the diagram.
The key of the metadata to set.
The value to set for the specified metadata key.
Deletes a specific metadata key from the diagram.
Optionalkey: stringThe key of the metadata to delete. If not provided, all metadata for the diagram is deleted.
Gets the value of a specific metadata key for a node.
The node or node ID to retrieve metadata from.
The key of the metadata to retrieve.
The value of the specified metadata key, or undefined if the key does not exist.
Sets the value of a specific metadata key for a node.
The node or node ID to set metadata for.
The key of the metadata to set.
The value to set for the specified metadata key.
Deletes a specific metadata key from a node.
The node or node ID to delete metadata from.
Optionalkey: stringThe key of the metadata to delete. If not provided, all metadata for the node is deleted.
Loads the diagram data from a serialized JSON object.
The serialized diagram data.
Optionalserializer: ISerializerThe serializer to use for reading the data (optional if source is already an object).
The diagram instance.
Writes the diagram data to the specified serializer.
The serializer to use for writing the data.
The serialized diagram data.
Exports the current diagram in a native format. Supported formats are JSON text, UTF-8 bytes, and Blob (browser runtime).
The format to export the diagram in ('json', 'bytes', or 'blob'). (defaults to 'json')
Whether to pretty-print the output (applicable to JSON format). (defaults to true)
The serializer to use for exporting the diagram. (optional)
The exported diagram data in the specified format.
Saves the current diagram directly from the model. In Node.js this writes to the file system; in browsers this triggers a file download.
The options for saving the diagram, including path, file name, serializer, pretty-printing, and MIME type.
A promise that resolves to the path or download URL of the saved file.
ProtectedapplyProtectedserializeProtectedserializeProtectedcreateCreates a new layer with the specified properties.
The ID of the layer.
The name of the layer.
Whether the layer is visible.
The nodes within the layer.
The created layer.
Protected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleProtected ReadonlyhandleReturns the cache used by the DiagramView.
The ViewCache instance storing precomputed values for efficient rendering.
Returns the coordinate system used by the DiagramView.
The CoordinateSystem instance managing transformations for this view.
Returns the keyboard manager used by the DiagramView.
The DiagramKeyboard instance managing keyboard interactions for this view.
Sets the keyboard manager for the DiagramView, allowing custom key mappings.
The DiagramKeyboard instance to set for this view.
Returns the canvas element used by the DiagramView.
Checks if a node is currently selected.
The node to check.
True if the node is selected, false otherwise.
Selects a node.
The node to select.
Determines whether to select related nodes or isolate the selection.
Deselects a node.
The node to deselect.
Determines whether to deselect related nodes or isolate the deselection.
Clears the selection of all nodes.
Selects all nodes in the diagram. Honors the enable_multi selection option to determine whether multiple nodes can be selected at once.
Toggles the selection state of a node.
The node to toggle.
void
Sets the viewport of the diagram with a given pan and/or zoom.
The viewport changes to apply.
Fits the diagram content to the width of the viewport, with optional padding and alignment.
Optionaloptions: { padding?: number; alignment?: FitAlign }Optional configuration for padding and alignment.
Fits the diagram content to the viewport, with optional padding and alignment.
Optionaloptions: { padding?: number; alignment?: FitAlign }Optional configuration for padding and alignment.
Zoom the diagram by multiplying current zoom by a factor, optionally around a canvas-space center point.
The zoom multiplier. Values greater than 1 zoom in and values between 0 and 1 zoom out.
OptionalcenterX: numberThe x coordinate (canvas space) to keep visually stable during zoom.
OptionalcenterY: numberThe y coordinate (canvas space) to keep visually stable during zoom.
The animation mode for the zoom operation.
Deletes a node from the diagram.
The ID of the node to delete.
ProtectedrenderUpdates the grid settings for the diagram and re-renders it to reflect the changes.
A partial object containing the grid properties to update. Only the provided properties will be updated, while the others will remain unchanged.
Updates the guides settings for the diagram.
A partial object containing the guide properties to update. Only the provided properties will be updated, while the others will remain unchanged.
Resets the viewport to the default position and zoom level, and clears the selection.
Exports the full visible diagram content as an image blob. This export is uncropped and ignores the current viewport pan/zoom. The exported image will be sized to fit the bounds of all visible nodes, plus optional padding.
The options for writing the image, including padding and MIME type.
The serializer to use for writing the image.
A promise that resolves to a Blob containing the exported image.
Exports and saves the full visible diagram content as an image file. In Node.js this writes to the file system; in browsers this triggers a download.
Calculate the bounding rectangle that encompasses all visible nodes in the diagram.
The bounding rectangle of all visible nodes, or undefined if there are no visible nodes.
ProtectedstartProtectedstopProtectedstopProtectedhitReturns the first node found at the specified coordinates, if any.
The x-coordinate to test.
The y-coordinate to test.
ProtectedhitReturns all nodes at the specified coordinates. Nodes are returned in order, so the topmost node is first in the array.
The x-coordinate to test.
The y-coordinate to test.
An ordered array of nodes at the specified coordinates.
ProtectedhitReturns the handle at the specified coordinates, if any.
The x-coordinate to test.
The y-coordinate to test.
Optionaltarget: INodeThe target node to test, if any.
The handle at the specified coordinates, or NodeHandle.NONE if none is found.
ProtectedhitReturns the connection-enabled handle at the specified coordinates, if any. Each node type can define its own connection handles, which may differ from the standard resize/move handles.
The x-coordinate to test.
The y-coordinate to test.
Optionaltarget: INodeThe target node to test, if any.
The connection-enabled handle at the specified coordinates, or { handle: NodeHandle.NONE, point: { x: 0, y: 0 } } if none is found.
ProtectedgetSelect the cursor style reflecting a node handle.
The node handle to determine the cursor style for.
The CSS cursor style for the specified node handle.
ProtectedemitProtectedwheelRespond to wheel events on the canvas, handling zooming when the Ctrl or Meta key is pressed and panning otherwise.
The wheel event.
Protectedshould
A class representing a diagram in edit mode. It provides tools for selection of nodes as well as mutation of the diagram's structure by user actions.