Macaw.Frame.Keyboard (macaw_frame v0.1.0)

Copy Markdown View Source

The keyboard's request and answer (spec/11 §5.6), the server side of visualize's Visualize.Hooks.Keyboard, carried on macaw_component's request transition (request/2, macaw_component spec/02 §7.3): the Frame declares the requests "arm", "disarm" and "key", and its hook (FrameKeyboard, proposal #12) sends them on the runtime's request path.

  • "key" carries {from, moves, seq}: from the point the hook stands on ([series, index]) or null, moves the moves of Macaw.Frame.Reach.move/3 as strings ("next", "previous", "next_series", "previous_series", "first", "last", {"at": [x, y]}, {"key": item}), seq a counting number. request/1 reads it, each move matched from its string and never made an atom. The answer is payload/1 of answer/3: %{seq, at, point, series, points}.
  • "arm" and "disarm": the hook arms the keyboard on focus and disarms it on blur, and the Frame indexes its reach only while armed (Macaw.Frame.Reach), so a page of Frames pays nothing for points nobody reads. An armed reach follows each realization: the point stood on is found again (Reach.find/2), and the render writes the following answer (data-mw-point, numbered as the last request applied), which the hook marks and does not read.
  • A key request on an unarmed Frame is answered from a reach built for it alone and not held. A payload the Frame cannot read is answered %{"error" => "bad_request"}, a value, never a raise.

attrs/2 are the keyboard element's attributes in live mode: the one tab stop (tabindex="0", role="group", an aria-label of <name>, chart: arrow keys move between points) and the focus marker's look, the theme's "focused" style resolved over a 2-unit stroke in the theme's text color dashed 4 2 (data-mw-focused). The keyboard needs a socket: no other mode renders it (spec/11 §1). A Frame that lays out a diagram is named <name>, diagram: arrow keys follow edges and writes its walk (Macaw.Frame.Keyboard.Graph, data-mw-graph), which the hook follows on the client (spec/11 §5.7).

Summary

Types

An answer: the request's number, where it landed, its point, and the counts.

A keyboard request read: where it stands, the moves since, and its number.

Functions

The answer to a request numbered seq whose moves landed on at (§5.6): %{seq, at, point, series, points}, point Macaw.Frame.Reach.point/2's without its row (its series, index, readout text, position x and y, layer, key and cell) or nil, and how many series and points the Frame has. A nil reach answers no point of none.

The keyboard element's attributes in live mode (§5.6): the tab stop, its name, the requests' focus marker look and, while armed on a point, the following answer.

A request of the Frame's hook answered by its value: {answer, value}. "arm" indexes the reach and holds it, "disarm" drops it, "key" answers the moves (and, armed, holds the point landed on so the next realization follows it). Any other request, or a payload the Frame cannot read, is answered %{"error" => …} with the value as it was.

An answer as the hook reads it (§5.6): string keys, pairs as lists, so JSON carries it as it is.

A "key" request's payload read (§5.6): {:ok, %{from, moves, seq}}, from {series, index} or nil, each move one of Macaw.Frame.Reach.move/3's, matched from its string and never made an atom, seq the request's number; :error for a payload that is not one.

The requests the Frame's keyboard hook may ask its value, in order.

Types

answer()

@type answer() :: %{
  seq: integer(),
  at: Macaw.Frame.Reach.at() | nil,
  point: map() | nil,
  series: non_neg_integer(),
  points: non_neg_integer()
}

An answer: the request's number, where it landed, its point, and the counts.

request()

@type request() :: %{
  from: Macaw.Frame.Reach.at() | nil,
  moves: [Macaw.Frame.Reach.move()],
  seq: integer()
}

A keyboard request read: where it stands, the moves since, and its number.

Functions

answer(reach, seq, at)

@spec answer(term(), term(), term()) :: answer()

The answer to a request numbered seq whose moves landed on at (§5.6): %{seq, at, point, series, points}, point Macaw.Frame.Reach.point/2's without its row (its series, index, readout text, position x and y, layer, key and cell) or nil, and how many series and points the Frame has. A nil reach answers no point of none.

attrs(value, name)

@spec attrs(Macaw.Frame.Value.t(), String.t()) :: [{String.t(), String.t()}]

The keyboard element's attributes in live mode (§5.6): the tab stop, its name, the requests' focus marker look and, while armed on a point, the following answer.

handle(value, arg2)

@spec handle(Macaw.Frame.Value.t(), term()) :: {map(), Macaw.Frame.Value.t()}

A request of the Frame's hook answered by its value: {answer, value}. "arm" indexes the reach and holds it, "disarm" drops it, "key" answers the moves (and, armed, holds the point landed on so the next realization follows it). Any other request, or a payload the Frame cannot read, is answered %{"error" => …} with the value as it was.

payload(arg1)

@spec payload(term()) :: map()

An answer as the hook reads it (§5.6): string keys, pairs as lists, so JSON carries it as it is.

request(payload)

@spec request(term()) :: {:ok, request()} | :error

A "key" request's payload read (§5.6): {:ok, %{from, moves, seq}}, from {series, index} or nil, each move one of Macaw.Frame.Reach.move/3's, matched from its string and never made an atom, seq the request's number; :error for a payload that is not one.

requests()

@spec requests() :: [String.t(), ...]

The requests the Frame's keyboard hook may ask its value, in order.