LivePanels.Item (livepanels v0.1.0)

Copy Markdown View Source

Item tracked by the LivePanels runtime.

Every placeable canvas object is an item. Content-bearing items, graph nodes, viewport readouts, and other item shapes all share this struct. Extra behavior hangs off capability buckets rather than separate top-level runtime structs.

The struct is the runtime's canonical record. Applications that need placement, identity, or type checks may read and pattern match on item fields directly; item props and metadata should use LivePanels.Canvas.Item commands. Mutations still belong to owner modules such as LivePanels.Canvas.Item, LivePanels.Graph, and LivePanels.Drawing so commands, authorization, persistence, and shared-canvas coordination stay on the same path.

Summary

Types

An item id or an app-facing item value that carries an :id.

t()

Canonical canvas item state.

Functions

Returns true when the item is attached to a parent item.

Returns true when an attached item dismisses on focus loss.

Normalizes item type values to the canonical runtime shape.

Returns one app-owned prop by atom or string key.

Returns an item's app-owned props map.

Returns true when the item has the requested type.

Returns true when a value can be used as a runtime item type.

Returns true when an item is placed in viewport space.

Returns true when the item is visible to a client id.

Returns true when an item is placed in world space.

Types

item_kind()

@type item_kind() :: atom() | String.t() | nil

item_type()

@type item_type() :: atom() | String.t()

ref()

An item id or an app-facing item value that carries an :id.

t()

@type t() :: %LivePanels.Item{
  added_at: integer() | nil,
  attachment: %{
    children: [String.t()],
    edge: :left | :right | :top | :bottom | nil,
    mode: :flyout | :anchored | :tiling | nil,
    offset_x: integer(),
    offset_y: integer(),
    constrain_to: :canvas | :parent | :none | nil,
    dismiss_on_focus_loss: boolean()
  },
  authority_scope: :canvas | :owner,
  capabilities: map(),
  group_id: String.t() | nil,
  h: integer(),
  icon: String.t() | nil,
  id: String.t(),
  interaction: %{owner: String.t() | nil, state: map() | nil},
  kind: item_kind(),
  label: String.t() | nil,
  opts: map(),
  owner_client_id: String.t() | nil,
  parent_id: String.t() | nil,
  persistent: boolean(),
  placement_anchor: LivePanels.Canvas.Placement.anchor(),
  placement_space: LivePanels.Canvas.Placement.space(),
  props: map(),
  type: item_type(),
  visible: boolean(),
  visible_to: :all | [String.t()],
  w: integer(),
  x: integer(),
  y: integer(),
  z_index: number() | nil
}

Canonical canvas item state.

Identity lives in :id, :type, :kind, :label, and :icon. Host-owned item props live in :props. Runtime behavior state lives in :capabilities, including vector geometry/style and connector endpoints. Geometry lives in :placement_space, :placement_anchor, :x, :y, :w, :h, and :z_index.

Runtime coordination fields are explicit as well: :interaction is %{owner: client_id | nil, state: map | nil}, :attachment records attached placement, and :capabilities carries normalized behavior buckets.

Functions

attached?(item)

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

Returns true when the item is attached to a parent item.

attachment_dismiss_on_focus_loss?(item)

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

Returns true when an attached item dismisses on focus loss.

normalize_type(type)

@spec normalize_type(term()) :: item_type() | nil

Normalizes item type values to the canonical runtime shape.

prop(item_or_props, key, default \\ nil)

@spec prop(t() | map() | term(), atom() | String.t(), term()) :: term()

Returns one app-owned prop by atom or string key.

prop(item, :body) reads both :body and "body" from item.props, and prop(item, "body") does the reverse lookup against existing atoms.

props(props)

@spec props(t() | map() | term()) :: map()

Returns an item's app-owned props map.

Use prop/3 when reading one value from application render code. It accepts atom or string keys and checks both key shapes without creating new atoms.

type?(item, type)

@spec type?(t(), item_type()) :: boolean()

Returns true when the item has the requested type.

valid_type?(type)

@spec valid_type?(term()) :: boolean()

Returns true when a value can be used as a runtime item type.

viewport?(item)

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

Returns true when an item is placed in viewport space.

visible_to_client?(item, client_id)

@spec visible_to_client?(t(), String.t()) :: boolean()

Returns true when the item is visible to a client id.

world?(item)

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

Returns true when an item is placed in world space.