PhiaUiDesign.Codegen.LiveviewEmitter (phia_ui v0.1.17)

Copy Markdown View Source

Generates a complete Phoenix LiveView module source string from a scene graph.

The output is a ready-to-paste .ex file containing:

  • use MyAppWeb, :live_view
  • import statements for every PhiaUI module referenced by components in the scene
  • A mount/3 callback that assigns any specified initial state
  • A render/1 callback containing the emitted HEEx template
  • Optional handle_event/3 callbacks

Also provides helpers to list required JS hooks and mix phia.add commands so the consumer app can install everything the design needs.

Summary

Functions

Generate a complete LiveView module source string.

Generate import statements for the modules that provide the used components.

Return the mix phia.add commands needed to install all used components.

Return the list of JS hook names required by the given component keys.

Functions

emit(scene, module_name, opts \\ [])

@spec emit(reference(), String.t(), keyword()) :: String.t()

Generate a complete LiveView module source string.

Parameters

  • scene - the ETS scene reference
  • module_name - fully-qualified module name string, e.g. "MyAppWeb.DashboardLive"

Options

  • :web_module - the Phoenix web module (default: "MyAppWeb")
  • :assigns - map of assigns to set in mount/3 (default: %{})
  • :events - list of {event_name, body_string} tuples for handle_event/3 callbacks (default: [])

generate_imports(component_keys)

@spec generate_imports([atom()]) :: String.t()

Generate import statements for the modules that provide the used components.

Looks up each component key in PhiaUi.ComponentRegistry, collects the unique modules, and returns a list of import Module lines.

required_add_commands(component_keys)

@spec required_add_commands([atom()]) :: [String.t()]

Return the mix phia.add commands needed to install all used components.

required_hooks(component_keys)

@spec required_hooks([atom()]) :: [String.t()]

Return the list of JS hook names required by the given component keys.

The hooks must be registered in the LiveSocket on the client side.