Skip to main content

ferro_json_ui/
lib.rs

1//! # Ferro JSON-UI
2//!
3//! JSON-based server-driven UI schema types for the Ferro framework.
4//!
5//! This crate defines the v2 `Spec` foundation: a flat, ID-keyed element map
6//! with parse-time structural validation. Typed `*Props` structs describe
7//! per-component prop shape and feed the Phase 117 catalog via `JsonSchema`.
8//!
9//! ## Schema Structure
10//!
11//! A JSON-UI Spec consists of:
12//! - **Spec** - Top-level container: `$schema`, `root`, `elements`, `title?`, `layout?`, `data?`
13//! - **Element** - Single UI node: `type` (string), `props` (Value), `children` (`Vec<String>` of IDs), `action?`, `visible?`
14//! - **Actions** - Handler references with confirmations and outcomes
15//! - **Visibility** - Conditional rendering based on data conditions
16//!
17//! ## Example
18//!
19//! ```rust
20//! use ferro_json_ui::{Spec, Element};
21//!
22//! let spec = Spec::builder()
23//!     .title("Demo")
24//!     .element("root", Element::new("Text").prop("content", "Hi"))
25//!     .build()
26//!     .unwrap();
27//! ```
28
29pub mod action;
30pub mod assets;
31pub mod catalog;
32pub mod component;
33pub mod config;
34pub mod data;
35pub mod expression;
36pub mod layout;
37pub mod loader;
38pub mod plugin;
39pub mod plugins;
40pub mod render;
41pub mod resolve;
42pub mod spec;
43pub mod visibility;
44
45pub mod runtime;
46
47pub use action::{Action, ActionOutcome, ConfirmDialog, DialogVariant, HttpMethod, NotifyVariant};
48pub use assets::FERRO_BASE_CSS;
49pub use component::{
50    ActionCardProps, ActionCardVariant, AlertProps, AlertVariant, AvatarProps, BadgeProps,
51    BadgeVariant, BreadcrumbItem, BreadcrumbProps, ButtonGroupProps, ButtonProps, ButtonType,
52    ButtonVariant, CardProps, CardVariant, CheckboxListProps, CheckboxProps, ChecklistItem,
53    ChecklistProps, CollapsibleProps, Column, ColumnFormat, DataTableProps, DescriptionItem,
54    DescriptionListProps, DropdownMenuAction, DropdownMenuProps, EmptyStateProps, FormMaxWidth,
55    FormProps, FormSectionProps, GapSize, GridProps, HeaderProps, IconPosition, ImageProps,
56    InputProps, InputType, KanbanBoardProps, KanbanColumnProps, ModalProps,
57    NotificationDropdownProps, NotificationItem, Orientation, PageHeaderProps, PaginationProps,
58    ProductTileProps, ProgressProps, RawHtmlProps, RichTextEditorProps, SelectOption, SelectProps,
59    SeparatorProps, SidebarGroup, SidebarNavItem, SidebarProps, Size, SkeletonProps, SortDirection,
60    StatCardProps, SwitchProps, Tab, TableProps, TabsProps, TextElement, TextProps, ToastProps,
61    ToastVariant,
62};
63pub use config::JsonUiConfig;
64pub use runtime::FERRO_RUNTIME_JS;
65// resolve_path and resolve_path_string are pub(crate) — internal render pipeline helpers
66pub use layout::{
67    register_layout, render_layout, DashboardLayout, DashboardLayoutConfig, Layout, LayoutContext,
68    LayoutRegistry, NavItem, SidebarSection,
69};
70// AppLayout, AuthLayout, DefaultLayout are pub in layout.rs but not user-facing — users select
71// layouts by name string ("dashboard", "app", "auth"), not by struct.
72// navigation, sidebar, footer, global_registry are framework-internal.
73pub use catalog::{global_catalog, Catalog, CatalogError, ComponentSpec};
74pub use expression::resolve_expressions;
75pub use loader::{load_cached, LoadError};
76pub use plugin::{
77    collect_plugin_assets, global_plugin_registry, register_plugin, registered_plugin_types,
78    with_plugin, Asset, CollectedAssets, JsonUiPlugin, PluginRegistry,
79};
80pub use plugins::{register_built_in_plugins, MapPlugin, RichTextEditorPlugin};
81pub use render::{render_spec_to_html, render_spec_to_html_with_plugins, RenderResult};
82pub use resolve::{
83    expand_directives, resolve_actions, resolve_actions_strict, resolve_errors, resolve_errors_all,
84};
85pub use spec::{
86    DataRef, Element, ElementBuilder, Spec, SpecBuilder, SpecError, TitleBinding,
87    MAX_NESTING_DEPTH, SCHEMA_VERSION,
88};
89pub use visibility::{Visibility, VisibilityCondition, VisibilityOperator};
90
91#[cfg(feature = "projections")]
92pub mod projection;
93
94#[cfg(feature = "projections")]
95pub use projection::{JsonUiRenderer, ProjectionError, RenderMode, VisualContext};