PhiaUiDesign.Canvas.Persistence (phia_ui v0.1.17)

Copy Markdown View Source

Save and load design scenes to/from .phia.json files.

Scenes are serialized as JSON containing a flat list of nodes with their parent-child relationships. On load, the nodes are inserted back into a fresh ETS scene table.

File format

{
  "version": 1,
  "name": "My Dashboard",
  "theme": "zinc",
  "nodes": [
    {
      "id": "abc123",
      "type": "phia_component",
      "component": "button",
      "attrs": {"variant": ":default"},
      "slots": {"inner_block": "Click me"},
      "parent_id": null,
      "children": ["def456"],
      "name": "My Button"
    }
  ],
  "root_children": ["abc123"]
}

Summary

Functions

List all .phia.json files in a directory.

Load a scene from a .phia.json file.

Save a scene to a .phia.json file.

Functions

list_projects(dir)

@spec list_projects(Path.t()) :: [map()]

List all .phia.json files in a directory.

load(path)

@spec load(Path.t()) :: {:ok, reference(), map()} | {:error, term()}

Load a scene from a .phia.json file.

Returns {:ok, scene, metadata} where metadata includes :theme and :name.

save(scene, path, opts \\ [])

@spec save(reference(), Path.t(), keyword()) :: :ok | {:error, term()}

Save a scene to a .phia.json file.

Options:

  • :theme — current theme atom (default: :zinc)