Add register_sx_layout infrastructure, convert account/federation/orders

Phase 0: Add _ctx_to_env() and render_to_sx_with_env() to shared/sx/helpers.py,
register_sx_layout() to shared/sx/layouts.py, and ~root-header/~root-mobile
wrapper defcomps to layout.sx. Convert built-in "root" layout to .sx.

Phases 1-3: Convert account (65→19 lines), federation (105→97 lines),
and orders (88→21 lines) to use register_sx_layout with .sx defcomps
that read ctx values as free variables from the evaluation environment.
No more Python building SX strings via SxExpr(await root_header_sx(ctx)).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 14:39:53 +00:00
parent 28388540d5
commit 45c5e4a0db
9 changed files with 244 additions and 229 deletions

View File

@@ -146,6 +146,33 @@
(when auth-menu
(div :class "p-3 border-t border-stone-200" auth-menu))))
;; ---------------------------------------------------------------------------
;; Root header/mobile wrappers — read ctx values from env free variables
;; Used by register_sx_layout so .sx defcomps compose without Python
;; ---------------------------------------------------------------------------
(defcomp ~root-header (&key oob)
(~header-row-sx :cart-mini cart-mini :blog-url blog-url :site-title site-title
:app-label app-label :nav-tree nav-tree :auth-menu auth-menu
:nav-panel nav-panel :settings-url settings-url :is-admin is-admin
:oob oob))
(defcomp ~root-mobile ()
(~mobile-root-nav :nav-tree nav-tree :auth-menu auth-menu))
;; ---------------------------------------------------------------------------
;; Built-in layout defcomps — used by register_sx_layout("root", ...)
;; ---------------------------------------------------------------------------
(defcomp ~layout-root-full ()
(~root-header))
(defcomp ~layout-root-oob ()
(~oob-header-sx :parent-id "root-header-child" :row (~root-header)))
(defcomp ~layout-root-mobile ()
(~root-mobile))
(defcomp ~error-content (&key errnum message image)
(div :class "text-center p-8 max-w-lg mx-auto"
(div :class "font-bold text-2xl md:text-4xl text-red-500 mb-4" errnum)