Athanor.Editor.Live (Athanor v0.1.0-beta.1)

Copy Markdown View Source

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
end

What the macro injects

  • mount/3 → reads consumer's load/3, builds Athanor.Editor.State, assigns library-owned keys onto the socket
  • render/1 → composes Athanor.Editor.shell/1 with all 4 slots filled with library function components (canvas, components_panel, config_panel, zone_picker_modal). Consumer-overridable render_header/1 + render_top_bar_actions/1 are called inside the :header slot.
  • handle_event/3 → routes editor events (select_component, add_component, save, etc.) to internal handlers in this module
  • handle_info/2 → routes :update_component_props messages from AutoEditorForm into either :content or :metadata assign (page-settings → metadata; everything else → content tree)
  • Default render_header/1 + render_top_bar_actions/1, both defoverridable

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_render_header(assigns)

Default barebones header — back button + optional page title.

default_render_top_bar_actions(assigns)

Default top-bar actions — viewport switcher + Save.

warn_if_registered(module)

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.