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: :registeredonly reads code-registered layouts.source: :storedonly reads persisted layouts.source: :anychecks 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, andparent_id :create,:read,:destroy, and:publishactions- an
:updateaction 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
@type layout_opt() :: {:source, source()} | {:status, status() | :any} | {:node_resource, node_resource()} | {:resource, module()} | {:replace?, boolean()}
@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.
@type source() :: :registered | :stored | :any
@type status() :: :draft | :published | :archived
Functions
@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.
@spec load_nodes(String.t(), [layout_opt()]) :: {:ok, [struct()]} | {:error, term()}
Returns stored layout nodes for a layout name.
@spec publish(String.t(), [layout_opt()]) :: {:ok, [struct()]} | {:error, term()}
Marks all stored nodes for a layout name as published.
@spec save(String.t(), AshSDUI.Layout.Node.t(), [layout_opt()]) :: {:ok, [struct()]} | {:error, term()}
Stores a layout tree as UINode records.