# `Hakushi.Live`
[🔗](https://github.com/hattoriai/hakushi/blob/v0.6.0/lib/hakushi/live.ex#L1)

The `on_mount` hook of a LiveView with a shared canvas (`issho`), and the
app's own changes to a canvas.

    live_session :default, on_mount: [Hakushi.Live] do

or, in one LiveView:

    on_mount Hakushi.Live

A shared canvas is a session of an Issho room (see `Hakushi.Issho`): this
hook is Issho's (`Issho.Live`), which takes the room's events in the
LiveView's process and gives them to its canvases, so the LiveView needs
no `handle_info` of its own for them. A LiveView that has `on_mount
Issho.Live` already needs no other. A canvas with `issho` in a LiveView
without the hook raises, saying so.

# `change`

```elixir
@spec change(String.t(), Hakushi.Change.t()) :: :ok
```

Makes the app's own change on the canvas `canvas` of this LiveView: a
node of a form, a label set from a menu, a step a job finished. The
change goes the way of a person's (the graph, the rules, `on_change`),
to everyone on a shared canvas, and cannot be undone by the people
(`by` is `nil`).

    def handle_event("add_table", %{"name" => name}, socket) do
      node = %Hakushi.Node{id: name, type: "table", x: 0, y: 0, data: %{name: name, columns: []}}
      Hakushi.Live.change("schema", Hakushi.Change.add([node]))
      {:noreply, socket}
    end

A change the canvas refuses shows its reason on the canvas. From outside
the LiveView (a job), change a shared canvas with
`Hakushi.Issho.change/4`.

# `export`

```elixir
@spec export(String.t(), keyword()) :: :ok
```

Downloads the canvas `canvas` of this LiveView as an image, in the
person's browser: `format: :png` (the default) or `:svg`, `filename`
(the canvas's id unless given), without its extension, and `paper:
true` for the canvas's paper behind the nodes (none unless asked).

# `layout`

```elixir
@spec layout(String.t(), keyword()) :: :ok
```

Tidies up the canvas `canvas` of this LiveView, as its tidy up button
does: `algorithm: :layered` (in layers along the edges, `direction:
:right` or `:down`), `:force` (by forces) or `:grid`; the canvas's
`layout` (or the way the person chose in its menu) unless given. The
person's browser lays the nodes out, and the new places are a change as
any: checked, shared, and undone with ⌘Z.

    Hakushi.Live.layout("schema", algorithm: :force)

---

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