Turn-key LiveView for Athanor editor consumers.
Usage
defmodule MyApp.PageBuilderLive do
use Athanor.Editor.Live,
page_settings_component: MyApp.PageSettings # optional
@impl Athanor.Editor
def load(params, session, socket) do
page = MyContext.get_page(params["id"])
{:ok, %{content: page.content, metadata: page.metadata,
ctx_assigns: %{account_id: session["account_id"]}}}
end
@impl Athanor.Editor
def save(socket, %{content: c, metadata: m}) do
MyContext.save(socket.assigns.page, content: c, metadata: m)
end
# Optional overrides:
# def render_header(assigns), do: ~H"..."
# def render_top_bar_actions(assigns), do: ~H"..."
# def seed_default_props(component, type, socket), do: component
endWhat the macro injects
mount/3→ reads consumer'sload/3, buildsAthanor.Editor.State, assigns library-owned keys onto the socketrender/1→ composesAthanor.Editor.shell/1with all 4 slots filled with library function components (canvas, components_panel, config_panel, zone_picker_modal). Consumer-overridablerender_header/1+render_top_bar_actions/1are called inside the:headerslot.handle_event/3→ routes editor events (select_component,add_component,save, etc.) to internal handlers in this modulehandle_info/2→ routes:update_component_propsmessages fromAutoEditorForminto either:contentor:metadataassign (page-settings → metadata; everything else → content tree)- Default
render_header/1+render_top_bar_actions/1, bothdefoverridable
The macro stays thin — every real implementation lives in this
module's public functions (build_initial_state/2,
do_select_component/2, etc.) so logic is unit-testable without a
full LiveView mount.
Summary
Functions
Default barebones header — back button + optional page title.
Default top-bar actions — viewport switcher + Save.
Emit a one-time warning if page_settings_component is also listed in
config :athanor, :components. A page-settings module shouldn't show
up in the palette — registering it would pollute the components panel
with a "Page Settings" entry that, if dropped onto the canvas, would
not render anything (it has no render/3).
Functions
Default barebones header — back button + optional page title.
Default top-bar actions — viewport switcher + Save.
Emit a one-time warning if page_settings_component is also listed in
config :athanor, :components. A page-settings module shouldn't show
up in the palette — registering it would pollute the components panel
with a "Page Settings" entry that, if dropped onto the canvas, would
not render anything (it has no render/3).
Called from mount/4; also publicly callable for tests.