LiveFlow.Clipboard (LiveFlow v0.4.0)

Copy Markdown View Source

Copy/paste clipboard for LiveFlow.

Stores copied nodes and edges for paste operations. Handles ID remapping, position offsetting, and edge reconnection on paste.

Usage

# Initialize in mount
clipboard = LiveFlow.Clipboard.new()

# Copy selected nodes/edges
clipboard = LiveFlow.Clipboard.copy(clipboard, flow)

# Cut (copy + delete)
{clipboard, flow} = LiveFlow.Clipboard.cut(clipboard, flow)

# Paste
case LiveFlow.Clipboard.paste(clipboard, flow) do
  {:ok, flow, clipboard} -> ...
  :empty -> ...
end

Notes

  • Only edges where both source and target are in the selection are copied
  • Pasted nodes get new unique IDs and an incremental position offset
  • Pasted items are auto-selected for immediate repositioning
  • Each successive paste increases the offset (+50px per paste)

Summary

Functions

Copies the currently selected nodes and internal edges to the clipboard.

Cuts the currently selected nodes and edges.

Returns true if the clipboard is empty.

Creates a new empty clipboard.

Returns the number of nodes in the clipboard.

Pastes clipboard contents into the flow with new IDs and offset positions.

Types

t()

@type t() :: %LiveFlow.Clipboard{
  edges: [LiveFlow.Edge.t()],
  nodes: [LiveFlow.Node.t()],
  paste_count: non_neg_integer()
}

Functions

copy(clipboard, flow)

@spec copy(t(), LiveFlow.State.t()) :: t()

Copies the currently selected nodes and internal edges to the clipboard.

Only edges where both source and target nodes are in the selection are included. Resets the paste count to 0.

cut(clipboard, flow)

@spec cut(t(), LiveFlow.State.t()) :: {t(), LiveFlow.State.t()}

Cuts the currently selected nodes and edges.

Copies the selection to the clipboard, then deletes it from the flow. Returns {clipboard, updated_flow}.

empty?(clipboard)

@spec empty?(t()) :: boolean()

Returns true if the clipboard is empty.

new()

@spec new() :: t()

Creates a new empty clipboard.

node_count(clipboard)

@spec node_count(t()) :: non_neg_integer()

Returns the number of nodes in the clipboard.

paste(clipboard, flow)

@spec paste(t(), LiveFlow.State.t()) :: {:ok, LiveFlow.State.t(), t()} | :empty

Pastes clipboard contents into the flow with new IDs and offset positions.

Each successive paste increases the position offset by 50px. Pasted nodes and edges are auto-selected. Returns {:ok, updated_flow, updated_clipboard} or :empty.