# `LiveFlow.Node`
[🔗](https://github.com/rocket4ce/live_flow/blob/main/lib/live_flow/core/node.ex#L1)

Node data structure for LiveFlow.

A node represents a visual element in the flow diagram that can be
positioned, connected via handles, and interacted with.

## Fields

  * `:id` - Unique identifier for the node (required)
  * `:type` - Node type atom, used for custom rendering (default: `:default`)
  * `:position` - Position in flow coordinates `%{x: number, y: number}`
  * `:data` - Custom data map passed to the node renderer
  * `:width` - Measured width (set by JS after render)
  * `:height` - Measured height (set by JS after render)
  * `:selected` - Whether the node is currently selected
  * `:draggable` - Whether the node can be dragged
  * `:connectable` - Whether handles can create connections
  * `:selectable` - Whether the node can be selected
  * `:deletable` - Whether the node can be deleted
  * `:hidden` - Whether the node is visible
  * `:dragging` - Whether the node is currently being dragged
  * `:resizing` - Whether the node is currently being resized
  * `:resizable` - Whether the node can be resized
  * `:drag_handle` - CSS selector; when set the node can only be dragged from matching elements
  * `:parent_id` - ID of parent node for grouping
  * `:extent` - Movement constraint (`:parent` or bounds map)
  * `:style` - Custom inline styles map
  * `:class` - Custom CSS classes
  * `:z_index` - Stacking order
  * `:handles` - List of `LiveFlow.Handle` structs
  * `:measured` - Whether dimensions have been measured

## Examples

    iex> LiveFlow.Node.new("node-1", %{x: 100, y: 100}, %{label: "Start"})
    %LiveFlow.Node{id: "node-1", position: %{x: 100, y: 100}, data: %{label: "Start"}}

    iex> LiveFlow.Node.new("node-2", %{x: 200, y: 150}, %{}, type: :input)
    %LiveFlow.Node{id: "node-2", type: :input, position: %{x: 200, y: 150}}

# `t`

```elixir
@type t() :: %LiveFlow.Node{
  class: String.t() | nil,
  connectable: boolean(),
  data: map(),
  deletable: boolean(),
  drag_handle: String.t() | nil,
  draggable: boolean(),
  dragging: boolean(),
  extent: :parent | map() | nil,
  handles: [LiveFlow.Handle.t()],
  height: number() | nil,
  hidden: boolean(),
  id: String.t(),
  measured: boolean(),
  parent_id: String.t() | nil,
  position: %{x: number(), y: number()},
  resizable: boolean(),
  resizing: boolean(),
  selectable: boolean(),
  selected: boolean(),
  style: map(),
  type: atom(),
  width: number() | nil,
  z_index: integer()
}
```

# `add_handle`

```elixir
@spec add_handle(t(), LiveFlow.Handle.t()) :: t()
```

Adds a handle to the node.

# `bounds`

```elixir
@spec bounds(t()) :: map() | nil
```

Gets the bounding box of the node.

Returns `nil` if the node hasn't been measured yet.

# `center`

```elixir
@spec center(t()) :: map() | nil
```

Gets the center point of the node.

Returns `nil` if the node hasn't been measured yet.

# `contains_point?`

```elixir
@spec contains_point?(t(), number(), number()) :: boolean()
```

Checks if a point is inside the node's bounds.

# `move`

```elixir
@spec move(t(), map()) :: t()
```

Moves a node to a new position.

## Examples

    iex> node = LiveFlow.Node.new("1", %{x: 0, y: 0}, %{})
    iex> LiveFlow.Node.move(node, %{x: 50, y: 50})
    %LiveFlow.Node{id: "1", position: %{x: 50.0, y: 50.0}}

# `move_by`

```elixir
@spec move_by(t(), number(), number()) :: t()
```

Moves a node by a delta offset.

## Examples

    iex> node = LiveFlow.Node.new("1", %{x: 100, y: 100}, %{})
    iex> LiveFlow.Node.move_by(node, 10, -20)
    %LiveFlow.Node{id: "1", position: %{x: 110.0, y: 80.0}}

# `new`

```elixir
@spec new(String.t(), map(), map(), keyword()) :: t()
```

Creates a new node with the given id, position, and data.

## Options

  * `:type` - Node type (default: `:default`)
  * `:draggable` - Whether draggable (default: `true`)
  * `:connectable` - Whether connectable (default: `true`)
  * `:selectable` - Whether selectable (default: `true`)
  * `:deletable` - Whether deletable (default: `true`)
  * `:resizable` - Whether resizable (default: `false`)
  * `:hidden` - Whether hidden (default: `false`)
  * `:width` / `:height` - Explicit dimensions. Measured dimensions replace
    them once the node renders (resizable nodes keep them)
  * `:drag_handle` - CSS selector of the element(s) the node can be dragged by
  * `:parent_id` - Parent node ID for grouping
  * `:extent` - Movement constraint
  * `:style` - Custom inline styles
  * `:class` - Custom CSS classes
  * `:z_index` - Stacking order (default: `0`)
  * `:handles` - List of handles (default: `[]`)

## Examples

    iex> LiveFlow.Node.new("1", %{x: 0, y: 0}, %{label: "Hello"})
    %LiveFlow.Node{id: "1", position: %{x: 0, y: 0}, data: %{label: "Hello"}}

    iex> LiveFlow.Node.new("2", %{x: 100, y: 100}, %{}, type: :input, draggable: false)
    %LiveFlow.Node{id: "2", type: :input, position: %{x: 100, y: 100}, draggable: false}

# `select`

```elixir
@spec select(t(), boolean()) :: t()
```

Sets the node's selected state.

# `set_dimensions`

```elixir
@spec set_dimensions(t(), number(), number()) :: t()
```

Sets the node's dimensions after measurement.

# `set_dragging`

```elixir
@spec set_dragging(t(), boolean()) :: t()
```

Sets the node's dragging state.

# `update`

```elixir
@spec update(t(), keyword()) :: t()
```

Updates a node with the given attributes.

## Examples

    iex> node = LiveFlow.Node.new("1", %{x: 0, y: 0}, %{})
    iex> LiveFlow.Node.update(node, position: %{x: 100, y: 100})
    %LiveFlow.Node{id: "1", position: %{x: 100.0, y: 100.0}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
