AshSDUI.Layout (ash_sdui v0.2.0)

Copy Markdown View Source

Unified API for named UI layouts.

Layouts can be registered in code or stored as UINode records. Callers should use fetch/2 when they do not need to care where a layout lives.

AshSDUI.Layout.Node represents a layout definition tree: component name, subject binding, static props, and child layout nodes. Rendering happens one step later through AshSDUI.Renderer, which converts the definition tree into %AshSDUI.Renderer.TreeNode{} structs for LiveView rendering.

Source precedence:

  • source: :registered only reads code-registered layouts.
  • source: :stored only reads persisted layouts.
  • source: :any checks registered layouts first, then stored layouts.

The built-in AshSDUI.UINode is suitable for tests, demos, and prototypes. Production apps can pass node_resource: to use a compatible Ash resource. A compatible node resource is expected to expose:

  • layout fields matching component_name, static_props, subject_resource, subject_id, region, order, status, name, and parent_id
  • :create, :read, :destroy, and :publish actions
  • an :update action when callers intend to update stored nodes directly

Summary

Types

Persisted-layout storage resource. Defaults to AshSDUI.UINode.

Functions

Returns a named layout from the requested source.

Returns stored layout nodes for a layout name.

Marks all stored nodes for a layout name as published.

Stores a layout tree as UINode records.

Types

layout_opt()

@type layout_opt() ::
  {:source, source()}
  | {:status, status() | :any}
  | {:node_resource, node_resource()}
  | {:resource, module()}
  | {:replace?, boolean()}

node_resource()

@type node_resource() :: module()

Persisted-layout storage resource. Defaults to AshSDUI.UINode.

Compatible resources should expose the fields and actions documented in the module docs for AshSDUI.Layout.

source()

@type source() :: :registered | :stored | :any

status()

@type status() :: :draft | :published | :archived

Functions

all()

fetch(name, opts \\ [])

@spec fetch(String.t(), [layout_opt()]) ::
  {:ok, AshSDUI.Layout.LayoutDef.t()} | {:error, :not_found}

Returns a named layout from the requested source.

By default registered layouts are checked first, then stored layouts.

get(name)

load_nodes(name, opts \\ [])

@spec load_nodes(String.t(), [layout_opt()]) :: {:ok, [struct()]} | {:error, term()}

Returns stored layout nodes for a layout name.

publish(name, opts \\ [])

@spec publish(String.t(), [layout_opt()]) :: {:ok, [struct()]} | {:error, term()}

Marks all stored nodes for a layout name as published.

register(name, root)

save(name, root, opts \\ [])

@spec save(String.t(), AshSDUI.Layout.Node.t(), [layout_opt()]) ::
  {:ok, [struct()]} | {:error, term()}

Stores a layout tree as UINode records.