An embeddable editor of typed fragments (spec/14 §18, §19).
A Phoenix.LiveComponent, not a Phoenix.LiveView: a LiveView owns a route and a
session, and this embeds in whatever page a host already has.
<.live_component module={Visualize.Chart.Builder} id="builder"
layers={@layers} sources={@sources} on_save={:design_saved} />The host owns the route, the layers the builder starts with, the pool of sample sources
the preview binds to, the library of saved fragments (Visualize.Chart.Builder.Store)
and what saving means. The builder owns the editing state alone: a stack of use
sites (§19.3) — each a fragment used at a position, with what is masked, bound and
added there — and, when a library entry is opened, that entry's fragment. The one thing
that leaves it is a message: saving sends {on_save, id, structure} to the host
LiveView process, where structure is the stack as a composite (§19.6); a host that
wants a flat design flattens it with Visualize.Chart.flatten/2. It pushes no event
and patches no URL (D-85).
Assigns
id- the component id (required)layers- the fragments the stack starts with, in precedence order, the higher later: a design map, aVisualize.Chartor a{name, layer}pair (default[]). Each is seeded as an inline-only use site (§19.9).sources- the pool of sample sources the preview binds the design's slots to, asVisualize.Chart.apply/2takes it (default%{})vars- the values the preview applies the design's variables with (default%{})theme- aVisualize.Themefor the preview,nilfor the design's ownstore- a module implementingVisualize.Chart.Builder.Store, or{module, context}with what the host wants every callback told (spec/14 §19.7), ornilfor no library (defaultnil)on_save- the tag of the message saving sends (default:visualize_chart_saved)styles- render the stylesheet in a<style>element (defaulttrue);falsewhen the host shipsVisualize.Chart.Builder.css/0through its own asset pipelineclass- appended to the builder's root class
Handling the message
def handle_info({:design_saved, "builder", structure}, socket) do
{:ok, design, _missing} = Visualize.Chart.flatten(structure, &MyStore.fetch/1)
{:noreply, assign(socket, design: design)}
endThis module compiles only when Phoenix.Component is loaded: phoenix_live_view is an
optional dependency, so an application that only renders predefined charts never
compiles a line of the builder, which scripts/consumer_check.exs proves on every
pipeline (spec/10 §1.1, D-45, D-85).
Summary
Functions
Returns the builder's stylesheet as a binary (spec/14 §18.13).
Renders the stylesheet in a <style> element (spec/14 §18.13).
The host's one line for the signals' tick (spec/14 §18.2): forwards the message the
builder scheduled to itself, {:visualize_chart_tick, id}, as an update.
Functions
@spec css() :: binary()
Returns the builder's stylesheet as a binary (spec/14 §18.13).
The builder renders this itself unless the host passes styles={false};
Visualize.Chart.Builder.Styles.install!/0 writes it beside the hooks for a host that
would rather own the file.
Attributes
id(:string) (required) - the component id.layers(:list) - the fragments the stack starts with, the higher later. Defaults to[].sources(:map) - the pool the preview binds the design's slots to. Defaults to%{}.vars(:map) - the values the preview applies the variables with. Defaults to%{}.theme(:any) - aVisualize.Themefor the preview. Defaults tonil.source_defaults(:boolean) - whether a source'sdefaultis offered in the form (spec/14 §18.1, §19.10). Defaults totrue.tick_ms(:integer) - the period of the signals' tick while playing (spec/14 §19.10). Defaults to500.store(:any) - aVisualize.Chart.Builder.Store, or{module, context}. Defaults tonil.on_save(:any) - the tag of the save message. Defaults to:visualize_chart_saved.on_deploy(:any) - the tag of the deploy message: the flat design, where save's carries structure. Defaults to:visualize_chart_deployed.styles(:boolean) - render the stylesheet,falseif the host ships it. Defaults totrue.class(:string) - appended to the builder's root class. Defaults tonil.library_folded(:any) - the library's top-level headers folded at the start, a set of names; a person's folds are the builder's own after that (spec/14 §18.16, #355).
Renders the stylesheet in a <style> element (spec/14 §18.13).
@spec tick(String.t(), Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
The host's one line for the signals' tick (spec/14 §18.2): forwards the message the
builder scheduled to itself, {:visualize_chart_tick, id}, as an update.
def handle_info({:visualize_chart_tick, id}, socket),
do: {:noreply, Visualize.Chart.Builder.tick(id, socket)}