Skip to main content

Crate cratefield_ui

Crate cratefield_ui 

Source
Expand description

cratefield-ui renders the harness’s UI surface (ADR 0010) as HTML from inside the Worker: full pages at /ui/<module>/<action>, the same as a fragment with ?fragment=1, landing pages at /ui/<module>/<action>/<page>, and the base stylesheet at /ui/cf.css. A form posts to its own /ui route; the handler turns the form into the JSON the module accepts and dispatches it in-process to the /v1 router, then renders the 202, the problem+json or the 303. Modules stay JSON-only.

Mount with Harness::builder().ui(cratefield_ui::Ui::default()).

Web-agnostic like every other crate: no worker, tokio or std::fs; maud builds strings, and the wasm build of examples/venture proves it.

Re-exports§

pub use spec::ActionSpec;
pub use spec::FieldSpec;
pub use spec::ModuleSpec;
pub use spec::PageCopy;
pub use spec::Theme;
pub use spec::UI_SPEC_KEY;
pub use spec::UI_SPEC_VERSION;
pub use spec::UiSpec;

Modules§

render
The markup contract (ADR 0010, docs/UI.md). Every element carries a cf-* class and, where it maps to the surface, a data-cf-* attribute. No shadow DOM, no inline styles, no ids except the ones that tie a <label> to its control. Changing a class name here is a breaking change of the UI contract; the snapshot test guards it.
spec
UiSpec (ADR 0010 §4, issue #75): everything about the UI that is copy, order or theme rather than code. JSON, validated against the module surface so a typo can never be silently ignored, applied by the renderer, and the object a prompt produces later. The schema is committed at schemas/ui-spec-v1.schema.json and a test keeps it in step with these types.

Structs§

Field
One renderable field of a form.
Option_
One choice of a Select.
Ui
Renderer configuration; mounted with HarnessBuilder::ui.

Enums§

JsonType
Widget
The input control a field renders as.

Constants§

CF_CSS
The base stylesheet served at /ui/cf.css: @layer cf, --cf-* custom properties, nothing that an unlayered venture rule cannot beat.
CF_JS
The embed served at /ui/cf.js (issue #73); empty until then.
CF_SW_PUSH
The reference push service worker served at /ui/sw-push.js (issue #183).
TURNSTILE_SITE_KEY
Config key for the Turnstile site key (public; the secret stays with the adapter). Without it a captcha action renders no widget, and the module’s captcha check answers as it does for any missing token.

Functions§

content_security_policy
The Content-Security-Policy for a page this crate or auth-core renders.
fields_of
Reads the fields of an object schema in property order.
form_to_json
Converts a submitted form into the JSON object the module’s handler deserializes. Only declared fields are forwarded; an empty optional string is omitted rather than sent as ""; a checkbox is true when present and false when absent; numbers that do not parse are sent as the raw string so the module’s own validation produces the error.
humanize
referral_code -> Referral code, captchaToken -> Captcha token.

Type Aliases§

Values
Submitted values keyed by control name, whatever the source (form body on a POST, query string on a GET that pre-fills).