### Initialize and Run Local Development Source: https://github.com/yuniqueunic/schemaui/blob/main/web/ui/README.md Commands to install dependencies and start the Vite development server. ```bash cd web/ui pnpm install # once pnpm dev # launches Vite on http://127.0.0.1:5173 ``` -------------------------------- ### SchemaUI CLI Command Example Source: https://github.com/yuniqueunic/schemaui/blob/main/README.ZH.md Example of running the schemaui CLI with schema, config, and output options, including reading from stdin and writing to multiple files. ```bash schemaui \ --schema ./schema.json \ --config ./defaults.yaml \ -o - \ -o ./config.toml ./config.json ``` -------------------------------- ### SchemaUI Web Mode Example Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Launch SchemaUI in web mode, serving a UI in the browser. This example configures schema, config, and output, binding to a random available port. ```bash schemaui web \ --schema ./schema.json \ --config ./defaults.json \ --host 127.0.0.1 --port 0 \ -o - ``` -------------------------------- ### Install schemaui-cli using Cargo binstall Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Installs prebuilt schemaui-cli binaries from GitHub releases using cargo-binstall. ```bash cargo binstall schemaui-cli ``` -------------------------------- ### Basic SchemaUI Runtime Example Source: https://github.com/yuniqueunic/schemaui/blob/main/README.md This example demonstrates how to initialize and run the SchemaUI TUI with a predefined JSON schema and default options. It requires the `color_eyre` crate for error handling. ```rust use schemaui::prelude::*; use serde_json::json; fn main() -> color_eyre::Result<()> { color_eyre::install()?; let schema = json!({ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Service Runtime", "type": "object", "properties": { "metadata": { "type": "object", "properties": { "serviceName": {"type": "string"}, "environment": { "type": "string", "enum": ["dev", "staging", "prod"] } }, "required": ["serviceName"] }, "runtime": { "type": "object", "properties": { "http": { "type": "object", "properties": { "host": {"type": "string", "default": "0.0.0.0"}, "port": {"type": "integer", "minimum": 1024, "maximum": 65535} } } } } }, "required": ["metadata", "runtime"] }); let options = UiOptions::default(); let ui = SchemaUI::new(schema) .with_title("SchemaUI Demo") .with_options(options.clone()); let frontend = TuiFrontend { options }; let value = ui.run_with_frontend(frontend)?; println!("{}", serde_json::to_string_pretty(&value)?); Ok(()) } ``` -------------------------------- ### Install schemaui-cli using Scoop Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Installs the schemaui-cli tool on Windows using the Scoop package manager. ```bash scoop install https://raw.githubusercontent.com/YuniqueUnic/schemaui/main/packaging/scoop/schemaui-cli.json ``` -------------------------------- ### Install schemaui-cli using Homebrew Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Installs the schemaui-cli tool on macOS or Linux using the Homebrew package manager. ```bash brew install YuniqueUnic/schemaui/schemaui ``` -------------------------------- ### Install schemaui-cli using Cargo Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Installs the schemaui-cli tool from crates.io using the Cargo package manager. ```bash cargo install schemaui-cli ``` -------------------------------- ### Get schemaui-cli help Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Displays the help message for the schemaui binary, showing available commands and options. ```bash schemaui --help # binary is named `schemaui` via the clap metadata ``` -------------------------------- ### Run schemaui-cli from source Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Installs and runs the schemaui-cli tool directly from the source code using Cargo. ```bash cargo run -p schemaui-cli -- tui --schema ./schema.json --config ./config.yaml ``` -------------------------------- ### SchemaUI Library Interoperability Example Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md This Rust code demonstrates how to initialize and configure the SchemaUI library programmatically, mirroring CLI functionality. ```rust let mut ui = SchemaUI::new(schema); if let Some(title) = cli.title.as_ref() { ui = ui.with_title(title.clone()); } if let Some(defaults) = config_value.as_ref() { ui = ui.with_default_data(defaults); } if let Some(options) = output_settings { ui = ui.with_output(options); } ui.run()?; ``` -------------------------------- ### React Start Transition Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Marks a state update as a non-urgent transition. This allows the UI to remain responsive during the update. ```javascript e.startTransition = function(e) { var t = w.T, n = {}, r = w.T = n try { var i = e(), a = w.S a !== null && a(n, i), typeof i == "object" && i && typeof i.then == "function" && i.then(C, P) } catch (e) { P(e) } finally { t !== null && n.types !== null && (t.types = n.types), w.T = t } } ``` -------------------------------- ### Basic Web UI Session Setup Source: https://github.com/yuniqueunic/schemaui/blob/main/README.md Use this to host a browser-based UI for schema configuration. It requires a JSON schema and provides a local address to access the UI. The session runs until explicitly exited or an error occurs. ```rust use schemaui::web::session::{ ServeOptions, WebSessionBuilder, bind_session, }; # async fn run() -> anyhow::Result<()> { let schema = serde_json::json!({ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "host": {"type": "string", "default": "127.0.0.1"}, "port": {"type": "integer", "default": 8080} }, "required": ["host", "port"] }); let config = WebSessionBuilder::new(schema) .with_title("Service Config") .build()?; let session = bind_session(config, ServeOptions::default()).await?; println!("visit http://{}/", session.local_addr()); let value = session.run().await?; println!("final JSON: {}", serde_json::to_string_pretty(&value)?); # Ok(()) # } ``` -------------------------------- ### Keymap JSON Example Source: https://github.com/yuniqueunic/schemaui/blob/main/README.ZH.md Defines a keyboard shortcut with an ID, English and Chinese descriptions, applicable contexts, an action, and a list of key combinations. ```json { "id": "list.move.up", "description": "Move entry up", "descriptionZh": "条目上移", "contexts": ["collection", "overlay"], "action": { "kind": "ListMove", "delta": -1 }, "combos": ["Ctrl+Up"] } ``` -------------------------------- ### Define Keymap JSON Entry Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/tui-architecture-overview.md Example of a single key binding definition in the default keymap JSON file. ```json { "id": "list.move.up", "description": "Move entry up", "contexts": ["collection", "overlay"], "dispatch": true, "action": { "kind": "listMove", "delta": -1 }, "combos": ["Ctrl+Up"] } ``` -------------------------------- ### Get Current Help Text Based on Contexts Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/tui-architecture-overview.md Retrieves help text by determining current keymap contexts based on application focus and options. ```rust fn current_help_text(&self) -> Option { if !self.options.show_help { return None; } let contexts = self.current_help_contexts(); self.keymap_store.help_text_for_contexts(&contexts) } ``` -------------------------------- ### Event Flow from KeyEvent to AppCommand/FormCommand Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/tui-architecture-overview.md Illustrates the simplified event processing pipeline, starting from a crossterm KeyEvent to either an AppCommand or FormCommand. ```text KeyEvent (crossterm) │ ▼ InputRouter::classify │ uses KeymapStore::classify (KeyPattern match) ▼ KeyAction │ ▼ KeyBindingMap::resolve │ ▼ CommandDispatch::{Form(FormCommand), App(AppCommand)} │ ├─ FormCommand → FormEngine & FormState └─ AppCommand → App::handle_app_command / handle_overlay_app_command ``` -------------------------------- ### Application Initialization Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Entry point for rendering the React application root. ```javascript (0,g.createRoot)(document.getElementById("root")).render((0,z.jsx)(_.StrictMode,{children:(0,z.jsxs)(ze,{children:[(0,z.jsx)(xm,{}),(0,z.jsx)(le,{richColors:!0,position:"bottom-right"})]})})); ``` -------------------------------- ### Initialize JIT Engine Configuration Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Sets up the JIT engine's configuration, including caching, class name parsing, and modifier sorting. ```javascript At=e=>({cache:Ct(e.cacheSize),parseClassName:Ot(e),sortModifiers:kt(e),...dt(e)}) ``` -------------------------------- ### Get Element Dimensions Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Retrieves the width and height of an element. This is a simple wrapper around `getBoundingClientRect()`. ```javascript function qo(e){let{width:t,height:n}=Oo(e);return{width:t,height:n}} ``` -------------------------------- ### Get Document Element Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Retrieves the document element of a given element. This is typically the `` element. ```javascript function ao(e){return e.ownerDocument.documentElement} ``` -------------------------------- ### Get Form Action Value Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Safely retrieves the action value from a form element or submitter. ```javascript function dd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Yt(""+e)} ``` -------------------------------- ### Get Current Context Value Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Retrieves the current value of a context, initializing tracking if necessary. ```javascript function qi(e){return Yi(Ri,e)} ``` -------------------------------- ### Execute TUI Pipeline in Rust Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/structure_design.md Demonstrates the initialization of a SchemaPipeline and execution via the TuiFrontend. ```rust fn run_tui(schema: Value, defaults: Option) -> Result { let pipeline = SchemaPipeline::new(schema) .with_title(Some("Title".into())) .with_defaults(defaults); let frontend = TuiFrontend { options: UiOptions::default() }; pipeline.run_with_frontend(frontend) } ``` -------------------------------- ### Initialize Popper.js Configuration Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Sets up the initial configuration for Popper.js, including platform-specific utilities and a map for caching offset parents. ```javascript var ds=(e,t,n)=>{let r=new Map,i={platform:es,...n},a={...i.platform,_c:r} ``` -------------------------------- ### Getting DOM Node from Fiber Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Returns the DOM node associated with a React Fiber node. ```javascript function ht(e){var t=e[ut];return t||=e[ut]={hoistableStyles:new Map,hoistableScripts:new Map},t} ``` -------------------------------- ### GET /api/session Source: https://context7.com/yuniqueunic/schemaui/llms.txt Retrieves the current session state, including the schema, UI AST, and current data. ```APIDOC ## GET /api/session ### Description Retrieves the current session state, including the schema, UI AST, and current data. ### Method GET ### Endpoint /api/session ``` -------------------------------- ### Initialize WebSessionBuilder Source: https://context7.com/yuniqueunic/schemaui/llms.txt Creates a browser-based configuration editor served via Axum. The session provides endpoints for management and validation. ```rust use schemaui::web::session::{ WebSessionBuilder, ServeOptions, bind_session, }; use serde_json::json; async fn run_web_ui() -> anyhow::Result<()> { let schema = json!({ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "host": {"type": "string", "default": "127.0.0.1"}, "port": {"type": "integer", "default": 8080} }, "required": ["host", "port"] }); // Build web session configuration let config = WebSessionBuilder::new(schema) .with_title("Service Config") .with_initial_data(json!({"host": "0.0.0.0", "port": 3000})) .build()?; // Configure serve options (0 = random port) let options = ServeOptions { host: "127.0.0.1".parse()?, port: 0, }; // Bind and run the session let session = bind_session(config, options).await?; println!("Web UI available at http://{}/", session.local_addr()); // Block until user saves and exits let result = session.run().await?; println!("Final config: {}", serde_json::to_string_pretty(&result)?); Ok(()) } ``` -------------------------------- ### Get Clipping Ancestors Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Retrieves the list of ancestors that clip the given element. This is used to determine the clipping rectangle. ```javascript function Go(e,t){let n=t.get(e);if(n)return n;let r=Eo(e,[],!1).filter(e=>so(e)&&J(e)!==\`body\`),i=null,a=So(e).position===\`fixed\`,o=a?wo(e):e;for(;so(o)&&!xo(o);){let t=So(o),n=vo(o);!n&&t.position===\`fixed\`&&(i=null),(a?!n&&!i:!n&&t.position===\`static\`&&i&&(i.position===\`absolute\`||i.position===\`fixed\`)||uo(o)&&!n&&Wo(e,o))?r=r.filter(e=>e!==o):i=t,o=wo(o)}return t.set(e,r),r} ``` -------------------------------- ### Run WebFrontend via SchemaUI Source: https://context7.com/yuniqueunic/schemaui/llms.txt Provides a direct method to launch the web UI mode using the SchemaUI builder. ```rust use schemaui::{SchemaUI, WebFrontend}; use schemaui::web::session::ServeOptions; use serde_json::json; let schema = json!({ "type": "object", "properties": { "api_key": {"type": "string"}, "endpoint": {"type": "string", "default": "https://api.example.com"} } }); let serve_options = ServeOptions { host: "127.0.0.1".parse()?, port: 8080, }; let result = SchemaUI::new(schema) .with_title("API Configuration") .run_web(serve_options)?; println!("Configured: {}", serde_json::to_string_pretty(&result)?); ``` -------------------------------- ### Getting React Fiber Node Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Retrieves the React Fiber node from a given element, checking for specific tags. ```javascript function mt(e){var t=e[it]||e[ot];if(t){var n=t.tag;if(n===5||n===6||n===13||n===31||n===26||n===27||n===3)return t}return null} ``` -------------------------------- ### SchemaUI TUI with Schema, Config, and Dual Outputs Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Use this command to run the SchemaUI TUI with both a schema and configuration file, outputting to both stdout and a file. ```bash schemaui tui \ --schema ./schema.json \ --config ./config.yaml \ -o - \ -o ./edited.toml ``` -------------------------------- ### React useTransition Hook Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Hook for managing transitions. Returns a function to start a transition and a boolean indicating if a transition is in progress. ```javascript e.useTransition = function() { return w.H.useTransition() } ``` -------------------------------- ### SchemaUI with Config Only (Schema Inferred) Source: https://github.com/yuniqueunic/schemaui/blob/main/docs/en/cli_usage.md Run SchemaUI using only a configuration file, inferring the schema from the input. The configuration is read from stdin. ```bash cat defaults.yaml | schemaui --config - --output ./edited.json ``` -------------------------------- ### Get Element Rects Relative to Document Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html Calculates the position and dimensions of an element relative to the document. This is a core function for positioning. ```javascript function Jo(e,t,n){let r=co(t),i=ao(t),a=n===\`fixed\`,o=Po(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=ba(0);function l(){c.x=Fo(i)}if(r||!r&&!a)if((J(t)!==\`body\`||uo(i))&&(s=Co(t)),r){let e=Po(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Io(i,s):ba(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}} ``` -------------------------------- ### Handle Host Component Creation (React) Source: https://github.com/yuniqueunic/schemaui/blob/main/web/dist/index.html This snippet handles the creation and initial mounting of host components (like `div`, `span`, `svg`). It includes logic for setting attributes, appending children, and handling specific elements like `script` and `select`. Use this for understanding how React creates DOM elements internally. ```javascript case 5:if(fe(t),a=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Dc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Mc(t),null}if(o=ae.current,Ni(t))ji(t,o);else{var s=Bd(se.current);switch(o){case 1:o=s.createElementNS(\`http://www.w3.org/2000/svg\`,a);break;case 2:o=s.createElementNS(\`http://www.w3.org/1998/Math/MathML\`,a);break;default:switch(a){case\ svg\ :o=s.createElementNS(\`http://www.w3.org/2000/svg\`,a);break;case\ math\ :o=s.createElementNS(\`http://www.w3.org/1998/Math/MathML\`,a);break;case\ script\ :o=s.createElement(\`div\ ),o.innerHTML=\`