Macaw.Builtin.Table.Rows (macaw v0.6.0)

Copy Markdown View Source

The built-in table's render as keyed parts (spec/05 §6.1, #434): its head (a capped or stale notice, the caption, the header and the opening <tbody>), its rows in the order drawn, each {key, version, markup}, its tail, and its scope.

It is safe HTML (Phoenix.HTML.Safe): flattened, it is the head, each row's markup and the tail, the table's bytes in every mode, so a runtime that places a render whole places this one as it did before. A runtime that places rows by key (macaw_live's keyed comprehension) reads rows, so a change re-sends only the rows whose markup changed and a re-sort moves rows rather than drawing them again.

A row's key is unique within the render: its identity's spelling (a binary, what its id spells), or, for a row with no identity field, no identity, or an identity an earlier row in the render already has, its position in the delivery (an integer).

A row's version (#439) is what its markup reads beyond the scope: {chunk version, place, mark}, the version of the delivery's chunk holding the row (Macaw.Data.Table.Chunk.version/1, its content digest or its derivation digest), the row's place in that chunk, and its selection mark (:selected, :muted or nil). It is nil where the chunk has no version, and such a row's markup is never to be reused. The scope is what every row's markup reads besides: {instance, events?, columns, identity field, remove}, its remove control's words and form or nil. Two rows with equal versions in renders with equal scopes have equal markup, so a runtime may keep a row's markup by {scope, version} and reuse it, and hand it back as macaw_component's held assign: the table then answers that row's markup as held and doesn't draw it (#465).

A chunk's version covers all of its rows, so a change to one row changes the version of every row its chunk holds (up to Macaw.Data.Table.chunk_rows/0), and rows of a chunk left unchanged (an append's earlier chunks) keep theirs.

A live table's range (#435): in :live, a table draws a range of its rows, from its first row, its visible rows and an overscan on each side; range is {from, count, total}, the first row drawn in drawn order, how many, and the rows in all, and gap_before and gap_after are the gaps standing for the rows not drawn: the rows' <tbody> between an empty <tbody class="mw-gap" data-mw-gap="N" aria-hidden="true"> before and after it, each counting its rows, for a client to size. Drawing every row, as every other mode does, range is nil, gap_before and gap_after are empty and the rows' <tbody> is in the head and the tail.

Summary

Types

A row's key: its identity's spelling, else its position in the delivery.

A live table's range: the first row drawn, how many, and the rows in all.

What every row's markup reads: the instance, whether events work, the columns, the identity field, the remove control.

t()

A row's content version: its chunk's version, its place in it, its mark; or none.

Functions

The keyed parts flattened: the head, the gap before, each row's markup in order, the gap after, the tail.

Types

key()

@type key() :: String.t() | non_neg_integer()

A row's key: its identity's spelling, else its position in the delivery.

range()

@type range() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()} | nil

A live table's range: the first row drawn, how many, and the rows in all.

scope()

@type scope() :: {String.t(), boolean(), [String.t()], String.t() | nil, term()}

What every row's markup reads: the instance, whether events work, the columns, the identity field, the remove control.

t()

@type t() :: %Macaw.Builtin.Table.Rows{
  gap_after: iodata(),
  gap_before: iodata(),
  head: iodata(),
  range: range(),
  rows: [{key(), version(), iodata()}],
  scope: scope(),
  tail: iodata()
}

version()

@type version() :: {String.t(), non_neg_integer(), :selected | :muted | nil} | nil

A row's content version: its chunk's version, its place in it, its mark; or none.

Functions

to_iodata(rows)

@spec to_iodata(t()) :: iodata()

The keyed parts flattened: the head, the gap before, each row's markup in order, the gap after, the tail.