# `LivePanels.Canvas.Selection`
[🔗](https://github.com/livepanels/livepanels/blob/v0.1.0/lib/livepanels/canvas/selection.ex#L1)

Actor-scoped canvas item selection.

Selection is runtime state, not layout. It lets applications build item,
graph, and drawing editors with shared target state without turning product
chrome into core.

# `command_result`

```elixir
@type command_result() :: LivePanels.Canvas.Command.result()
```

# `item_ref`

```elixir
@type item_ref() :: LivePanels.Item.ref()
```

# `selection_ref`

```elixir
@type selection_ref() :: t() | [item_ref()] | item_ref()
```

# `socket`

```elixir
@type socket() :: Phoenix.LiveView.Socket.t()
```

# `t`

```elixir
@type t() :: %LivePanels.Canvas.Selection{item_ids: MapSet.t(String.t())}
```

# `target`

```elixir
@type target() :: LivePanels.Canvas.command_target()
```

First argument accepted by selection command helpers.

Pass a LiveView socket for a standalone command, or a
`LivePanels.Canvas.Transaction` context inside `LivePanels.Canvas.transaction/2`.

# `clear`

```elixir
@spec clear(target()) :: command_result()
```

Clears the current actor selection and returns the command result.

# `clear!`

```elixir
@spec clear!(target()) :: target()
```

Clears the current actor selection.

# `count`

```elixir
@spec count(t() | term()) :: non_neg_integer()
```

Returns the number of selected items.

# `empty?`

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

Returns true when the selection contains no items.

# `include`

```elixir
@spec include(target(), selection_ref()) :: command_result()
```

Includes one or more items and returns the command result.

# `include!`

```elixir
@spec include!(target(), selection_ref()) :: target()
```

Includes one or more items in the current actor selection.

# `item_count`

```elixir
@spec item_count(t() | term()) :: non_neg_integer()
```

Returns the number of selected items.

# `select`

```elixir
@spec select(target(), selection_ref()) :: command_result()
```

Replaces the current actor selection and returns the command result.

# `select!`

```elixir
@spec select!(target(), selection_ref()) :: target()
```

Replaces the current actor selection.

# `select_all`

```elixir
@spec select_all(target()) :: command_result()
```

Selects every item and connector item and returns the command result.

# `select_all!`

```elixir
@spec select_all!(target()) :: target()
```

Selects every item and connector item the current actor can select.

# `selected_item?`

```elixir
@spec selected_item?(t(), item_ref()) :: boolean()
```

Returns true when the selection contains the given canvas item.

# `selected_item_ids`

```elixir
@spec selected_item_ids(t() | map() | term()) :: MapSet.t(String.t())
```

Returns selected canvas item ids.

# `toggle`

```elixir
@spec toggle(target(), selection_ref()) :: command_result()
```

Toggles one or more items and returns the command result.

# `toggle!`

```elixir
@spec toggle!(target(), selection_ref()) :: target()
```

Toggles one or more items in the current actor selection.

---

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