Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

py/facett_demo/demo_payloads.py

"""The gallery's payload table — loaded, not written, here.

The data lives in `demo_payloads.json` beside this file, because TWO readers need
it: this module (python, in the container, driving the Streamlit gallery) and
`xtask/tests/gallery_covers_the_manifest.rs` (Rust, on the host), which proves the
gallery covers every component the shipped registry declares AND that every payload
is accepted and built by the REAL adapter.

A python literal would have forced the Rust guard to parse python, or forced a second
copy of the payloads. One file, two readers, no copy.

Nothing here renders anything. These are payloads; the wasm draws.
"""

from __future__ import annotations

import json
from pathlib import Path
from typing import Any

__all__ = ["DEMO_PAYLOADS", "FEATURE_PAYLOADS", "FIXTURE_ONLY", "payload_for", "is_fixture_only"]

_TABLE_PATH = Path(__file__).parent / "demo_payloads.json"
_TABLE: dict[str, Any] = json.loads(_TABLE_PATH.read_text(encoding="utf-8"))

#: `component name -> payload`, for every component the registry marks data-driven.
DEMO_PAYLOADS: dict[str, Any] = _TABLE["payloads"]

#: Payloads for the components that live in a NON-core bundle group (docs: docview,
#: manual; model3d: model3d), flattened to `{name: payload}`. The JSON keeps them per
#: group under `feature_payloads`; the wheel ships every group and the loader routes
#: each mount to its bundle, so the gallery mounts these exactly like the core ones.
FEATURE_PAYLOADS: dict[str, Any] = {
    name: payload
    for group in _TABLE.get("feature_payloads", {}).values()
    for name, payload in group.items()
}

#: Components with no data seam yet. The gallery mounts these with NO payload and
#: SAYS so, rather than handing them data they will ignore while rendering their own
#: fixture — which looks exactly like success and is the failure the loader's refusal
#: path exists for.
FIXTURE_ONLY: frozenset[str] = frozenset(_TABLE["fixture_only"])


def payload_for(name: str) -> Any | None:
    """The demo payload for `name`, or ``None`` if it has no data seam."""
    if name in DEMO_PAYLOADS:
        return DEMO_PAYLOADS[name]
    return FEATURE_PAYLOADS.get(name)


def is_fixture_only(name: str) -> bool:
    """Whether `name` is a component the registry says takes no data."""
    return name in FIXTURE_ONLY