# `MishkaCmsCore.Runtime.ContentEditorStyles`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.1/lib/mishka_cms_core/runtime/content_editor_styles.ex#L5)

The stylesheet the content editor draws its previews with: the site's own, and the classes of
every component its palette offers.

The admin's stylesheet is built from the admin's templates, and a site's from the templates its
pages reach and the components its saved content names. Neither holds a component an author has
just placed, nor the variant or colour they just picked — `chelekom-blockquote` turned `shadow`
and `secondary` in the settings, and its preview stayed as it was. This builds, ahead, what the
site's pages will be styled with once content using any of those components is saved.

It is built with `MishkaCmsCore.Runtime.Compilers.TailwindCompiler.compile_preview/4`, against a
template naming each component the palette offers, kept in `AssetsState` under `key/1` and served
by `MishkaCmsCoreWeb.AssetsController` at `href/2` — to a master admin, or an admin of that site.
It is built again only when the site's own stylesheet or the palette's components change, and
stays as it is otherwise.

A record with no site — only a master edits one — is previewed with the base every site starts
from and the global components, built the same way under `key(nil)`.

The editor draws each preview in a shadow root, so a theme variable the stylesheet declares on
`:root` alone is declared on `:host` too, and so is the starting value of every variable it
registers with `@property` — a rule a shadow root ignores, which left a border with no style and
an `::after` with no content: a timeline drew without the line joining its items.

# `ensure`

```elixir
@spec ensure(String.t() | nil, [String.t()]) :: {:ok, String.t()} | {:error, term()}
```

The stylesheet for the site `site_id` and the components `names`, built when it is missing or
was built from another site stylesheet or other components: `{:ok, href}`, or `{:error, reason}`
when it does not build or the site is unknown.

# `href`

```elixir
@spec href(String.t(), String.t()) :: String.t()
```

The address the stylesheet kept under `key` with `hash` is served at.

# `key`

```elixir
@spec key(String.t() | nil) :: String.t()
```

The `AssetsState` id the editor's stylesheet for the site `site_id` is kept under, `nil` for a
record with no site.

# `site_of`

```elixir
@spec site_of(String.t()) :: {:ok, String.t()} | :error
```

The site id of an `AssetsState` id `key/1` made for a site, or `:error` for any other — the one
for no site among them.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
