Macaw.Surface.Cell (macaw v0.6.0)

Copy Markdown View Source

A cell: one component placed in a surface (spec/06 §3.2).

  • component, the component's name as its package registers it, matched by spelling;
  • kind, the kind it renders as, or nil, the default, for the kind its placement gives it (spec/06 §2.6): :navigation in a navigation region, :content elsewhere;
  • settings, its settings by parameter name, inline, each the term it is, checked against the component's parameter types where the component is known (spec/06 §3.4);
  • preset, the name of a preset its settings stack over (spec/07 §1), or nil, the default, for settings carried inline: the component's defaults, then the preset, then settings, one fragment stack (Macaw.Preset.stack/2);
  • slots, each slot bound to a source: %{source: name, fields: %{role => field}, params: %{name => value}}, a many role's fields a list, each param the term it is;
  • place, where it sits, as its surface's layout reads it: %{x, y, w, h} on the grid (spec/06 §3.3);
  • actions, what its component's events do: a list, each %{on: event, set: state, value: {:event, path}} (spec/03 §1.3), %{on: event, reset: target}, the states it takes back to where the page started, :view, :page, :all or a list of names (spec/03 §1.3), %{on: event, add: source} or %{on: event, remove: source}, a row added to or removed from the visitor's overlay of a source (spec/13 §3), or %{on: event, navigate: page, params: %{name => value}} (spec/06 §5); nil, the default, for its component's default actions, and [] for none;
  • exports, its own state it makes public (spec/03 §5.1): a map of an export's name to one of its parameters, whose per-cell state <cell>.<param> the surface exports under that name; %{} by default;
  • panes, a container's panes in order (spec/05 §5.1), each %{name:, label:, surface:}: the value of its open that shows it, the text naming it, and the surface it shows by name; nil, the default, for a cell that isn't a container.

A setting, a request param or a slot's source may be {:state, name}, a binding to a state source (spec/03 §1.4), its name read as its spelling.

Names are strings, normalized once here; an atom is read as its spelling, and no atom is made from one. A cell checks only its own shape: the types of its settings and params are its component's and its sources' (spec/06 §3.4).

Summary

Types

An action: the event it runs on, and either the state it sets and from what (spec/03 §1.3), the states it resets (spec/03 §1.3), the source whose overlay a row is added to or removed from (spec/13 §3), or the page it navigates to and its params, each an event path or a literal (spec/06 §5).

A container's pane (spec/05 §5.1): its name, its label and its surface's name.

Where a cell sits, as its layout reads it: %{x, y, w, h} on the grid.

t()

Functions

A cell's keys, in order.

A cell from a keyword list or a map with atom keys: {:ok, cell} or every fault at once, by path from the cell. layout is the layout that judges its place (Macaw.Layout), the grid by default; nil holds a place as given, for a layout only the host's registry knows, judged when the surface is validated. A cell with no place is a cell; whether its surface's layout needs one is the surface's question.

Types

action()

@type action() ::
  %{on: String.t(), set: String.t(), value: {:event, atom() | list()}}
  | %{on: String.t(), reset: :view | :page | :all | [String.t(), ...]}
  | %{on: String.t(), add: String.t()}
  | %{on: String.t(), remove: String.t()}
  | %{
      on: String.t(),
      navigate: String.t(),
      params: %{required(String.t()) => term()}
    }

An action: the event it runs on, and either the state it sets and from what (spec/03 §1.3), the states it resets (spec/03 §1.3), the source whose overlay a row is added to or removed from (spec/13 §3), or the page it navigates to and its params, each an event path or a literal (spec/06 §5).

pane()

@type pane() :: %{name: String.t(), label: String.t(), surface: String.t()}

A container's pane (spec/05 §5.1): its name, its label and its surface's name.

place()

@type place() :: term()

Where a cell sits, as its layout reads it: %{x, y, w, h} on the grid.

slot()

@type slot() :: %{
  source: String.t() | {:state, String.t()},
  fields: %{required(String.t()) => String.t() | [String.t()]},
  params: map()
}

t()

@type t() :: %Macaw.Surface.Cell{
  actions: [action()] | nil,
  component: String.t(),
  exports: %{required(String.t()) => String.t()},
  kind: Macaw.Component.kind() | nil,
  panes: [pane(), ...] | nil,
  place: place() | nil,
  preset: String.t() | nil,
  settings: %{required(String.t()) => term()},
  slots: %{required(String.t()) => slot()},
  source: slot() | nil
}

Functions

keys()

@spec keys() :: [atom(), ...]

A cell's keys, in order.

new(attrs, layout \\ Macaw.Layout.default())

@spec new(keyword() | map(), module() | nil) ::
  {:ok, t()} | {:error, [Macaw.Base.Fault.t(), ...]}

A cell from a keyword list or a map with atom keys: {:ok, cell} or every fault at once, by path from the cell. layout is the layout that judges its place (Macaw.Layout), the grid by default; nil holds a place as given, for a layout only the host's registry knows, judged when the surface is validated. A cell with no place is a cell; whether its surface's layout needs one is the surface's question.