@samatawy/diagrams
    Preparing search index...

    Class DocumentAdapter

    DocumentAdapter is a node adapter responsible for rendering document nodes in the diagram. It extends the RectangleAdapter to leverage basic rectangle rendering capabilities while adding specific logic for handling document shapes and hit testing. Registers with the NodeRegistry under the name 'document'.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    TYPE: string = 'document'
    hollow_mode: HollowMode = 'if_transparent'

    The hollow mode determines how the node's hollow property is calculated based on its fill style.

    • 'always': The node is always hollow regardless of its fill style.
    • 'never': The node is never hollow regardless of its fill style.
    • 'if_transparent': The node is hollow if its fill style is 'transparent', otherwise it is not hollow.
    min_width: number = 24
    min_height: number = 16
    is_connector: boolean = false

    Indicates whether the adapter is for a connector node, which may require special handling for rendering and hit testing.

    multistep_create: boolean = false

    Indicates whether the node creation process involves multiple steps, such as defining multiple points for a polyline or curve. If true, the diagram control may need to handle additional user interactions during node creation.

    drag_create: boolean = true

    Indicates whether the node can be created by dragging from the tool palette onto the canvas. If true, the adapter should implement the onCreateDraft method to provide the initial geometry of the draft node to be dragged.

    has_text: boolean = true

    Indicates whether the adapter supports rendering text within the node, which may affect how the node is rendered and whether text-related interactions are enabled.

    single_line_text: boolean = false

    Indicates whether the adapter supports single-line text rendering within the node. If true, the text will be rendered on a single line, and any overflow will be handled according to the text_overflow property. If false or undefined, multi-line text rendering may be supported.

    text_overflow: TextOverflowMode = 'hidden'

    The text overflow mode determines how text that exceeds the node's bounding box is handled.

    • 'visible': Text is allowed to overflow the node's bounding box and will be fully visible.
    • 'hidden': Text that exceeds the node's bounding box is clipped and not visible.
    • 'ellipsis': Text that exceeds the node's bounding box is truncated and an ellipsis ("...") is displayed to indicate that there is more text. This property is used to control the visual appearance of text within the node and how it behaves when the text content is too large for the available space.
    text_orientations: ITextOrientation[] = ...

    Returns the text orientation values this node type supports. Only relevant for nodes that support text (has_text === true). When not defined, all orientations are assumed to be supported. Adapters that render text differently (e.g. curved text) should override this to return a restricted subset.

    text_baselines: ITextBaseline[] = ...

    Returns the text baseline values this node type supports. Only relevant for nodes that support text (has_text === true). When not defined, all baselines are assumed to be supported. Adapters that render text differently (e.g. curved text) should override this to return a restricted subset. The baseline determines how the text is aligned vertically relative to its bounding box or path. For example, 'top' aligns the top of the text with the top of the bounding box, 'middle' centers the text vertically, and 'bottom' aligns the bottom of the text with the bottom of the bounding box.

    connection_handles: NodeHandle[] = ...

    Specifies the connection handles that this node type supports for connecting to other nodes. Each handle is represented by a NodeHandle value, which indicates the position or type of the handle on the node. This property is used to determine where connections can be made to this node and how the diagram control should render connection points. Adapters that support connections should override this to return the appropriate handles for their node type.

    can_rotate: boolean = true

    Indicates whether the adapter supports rotation of the node. If true, the diagram control may provide rotation handles and allow the user to rotate the node.

    can_snap: boolean = true

    Indicates whether the adapter supports snapping the node to a grid or guides when moving or resizing. If true, the diagram control may adjust the node's position and size to align with the grid or guides.

    Accessors

    • get type(): string

      The unique type name of the adapter, which is used to associate it with nodes of a specific type. This type is typically registered with the NodeRegistry to enable the diagram control to find the appropriate adapter for each node.

      Returns string

    Methods

    • Returns the visual bounding rect of the node's rendered path in world coordinates. For most nodes this equals the rect computed from their points. Adapters whose paths extend beyond that rect (e.g. a document node whose wavy bottom dips below the bottom edge) should override this to return the true visual bounds so that cover-mode images fill the entire visible shape.

      The default implementation returns rect unchanged.

      Parameters

      • node: INode
      • rect: IRect

        The rect derived from the node's control points.

      Returns IRect

      The visual bounding rect.

    • Render the handle used to define a custom waveheight at the bottom left of the shape. It has the shape of a downward semicircle to indicate its function for adjusting the waveheight. No transformation necessary here.

      Parameters

      • node: INode

        The node being rendered.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      • rect: IRect

        The bounding rectangle of the node.

      Returns void

    • Sliding the ALTER handle sets the waveheight as the distance between the handle start and the left of the bounding rect. Transformation is necessary here.

      Parameters

      • node: INode

        The node being altered.

      • point: IPoint

        The point where the handle is currently at.

      Returns void

    • Creates and returns a new draft node for the given tool when the user initiates a drag-create action from the tool palette. This will only be called if the adapter's drag_create property is true.

      Parameters

      • tool: string

        The tool identifier for which to create the draft node.

      Returns Partial<INode> | undefined

      The newly created draft node, or undefined if the draft node should not be created.

    • Additional logic to determine whether a connection can be made to this node from the specified direction and handle. This method is called during connection creation to validate whether a connection is allowed based on the node's state, geometry, or other criteria. The target can also be used to decide whether a connection can be made. The target can be the connection iteself or the node that is being connected to. The point parameter can be used to determine the world-space coordinates of the connection point, if available. Adapters that support connections should override this to implement custom connection rules.

      Parameters

      • node: INode

        The node to which the connection is being made.

      • handle: NodeHandle

        The connection handle on the node.

      • direction: "from" | "to" | "any"

        The direction of the connection, either 'from' (outgoing) or 'to' (incoming).

      • Optionaltarget: Partial<INode>

        The target node or connection that is being connected to, if available. This can be used to determine whether the connection is allowed based on the target's type or state.

      • Optionalpoint: IPoint

        The world-space coordinates of the connection point, if available.

      Returns boolean

    • Writes the given node to a JSON-serializable format using the provided serializer.

      Parameters

      • node: INode

        The node to serialize.

      • serializer: any

        The serializer to use for converting the node to JSON.

      Returns any

      The JSON-serializable representation of the node.

    • Reads a node from the given JSON data using the provided serializer.

      Parameters

      • json: any

        The JSON data to read the node from.

      • serializer: any

        The serializer to use for converting the JSON data to a node.

      Returns Promise<INode>

      A promise that resolves to the deserialized node.