LiveFlow.Changes.NodeChange (LiveFlow v0.4.0)

Copy Markdown View Source

Node change event types for LiveFlow.

Node changes describe mutations to nodes that are sent from the JS hook to the LiveView. These follow the xyflow pattern of immutable state changes.

Change Types

  • :position - Node was moved
  • :dimensions - Node dimensions were measured/changed
  • :select - Node selection changed
  • :remove - Node was removed
  • :add - Node was added
  • :replace - Node was replaced entirely

Examples

# Position change from JS drag
%{"type" => "position", "id" => "node-1", "position" => %{"x" => 100, "y" => 200}, "dragging" => false}

# Dimensions change after node render
%{"type" => "dimensions", "id" => "node-1", "width" => 150, "height" => 50}

Summary

Functions

Applies a single change to the state.

Applies a list of changes to the state.

Creates a dimensions change.

Creates a position change.

Creates a remove change.

Creates a selection change.

Types

add_change()

@type add_change() :: %{type: :add, node: map()}

dimensions_change()

@type dimensions_change() :: %{
  type: :dimensions,
  id: String.t(),
  width: number(),
  height: number()
}

position_change()

@type position_change() :: %{
  type: :position,
  id: String.t(),
  position: %{x: number(), y: number()},
  dragging: boolean()
}

remove_change()

@type remove_change() :: %{type: :remove, id: String.t()}

replace_change()

@type replace_change() :: %{type: :replace, node: map()}

selection_change()

@type selection_change() :: %{type: :select, id: String.t(), selected: boolean()}

t()

Functions

apply_change(state, change)

@spec apply_change(LiveFlow.State.t(), map()) :: LiveFlow.State.t()

Applies a single change to the state.

apply_changes(state, changes)

@spec apply_changes(LiveFlow.State.t(), [map()]) :: LiveFlow.State.t()

Applies a list of changes to the state.

dimensions(id, width, height)

@spec dimensions(String.t(), number(), number()) :: map()

Creates a dimensions change.

position(id, position, dragging \\ false)

@spec position(String.t(), map(), boolean()) :: map()

Creates a position change.

remove(id)

@spec remove(String.t()) :: map()

Creates a remove change.

select(id, selected)

@spec select(String.t(), boolean()) :: map()

Creates a selection change.