|
| 1 | +--- |
| 2 | +title: ObjectUI - The Interface Engine |
| 3 | +description: Declarative UI engine with data-driven rendering and protocol-based components |
| 4 | +--- |
| 5 | + |
| 6 | +# ObjectUI - The Interface Engine |
| 7 | + |
| 8 | +ObjectUI is the presentation layer of ObjectStack, providing a declarative UI engine that renders interfaces from JSON protocols. It transforms UI development from imperative code to data-driven declarations. |
| 9 | + |
| 10 | +## What is ObjectUI? |
| 11 | + |
| 12 | +ObjectUI is a **declarative UI engine** that allows you to define user interfaces as JSON protocols instead of writing component code. It provides a complete set of pre-built components that render automatically based on data specifications. |
| 13 | + |
| 14 | +### Key Capabilities |
| 15 | + |
| 16 | +- 🎨 **Declarative UI** - Define interfaces with JSON instead of JSX/code |
| 17 | +- 🔄 **Data-Driven Rendering** - UI automatically reflects data changes |
| 18 | +- 📦 **Component Protocol** - Rich set of pre-built components |
| 19 | +- 🎭 **Theme Support** - Customizable styles and themes |
| 20 | +- ⚡ **Performance Optimized** - Smart rendering and updates |
| 21 | +- 🔌 **Framework Agnostic** - React renderer with others planned |
| 22 | + |
| 23 | +## How It Works |
| 24 | + |
| 25 | +ObjectUI operates on a simple principle: **UI as Data**. |
| 26 | + |
| 27 | +### 1. Define UI Protocol |
| 28 | + |
| 29 | +Describe your interface using JSON: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "type": "page", |
| 34 | + "title": "Todo List", |
| 35 | + "body": { |
| 36 | + "type": "form", |
| 37 | + "fields": [ |
| 38 | + { |
| 39 | + "name": "title", |
| 40 | + "type": "input", |
| 41 | + "label": "Task Name", |
| 42 | + "required": true |
| 43 | + }, |
| 44 | + { |
| 45 | + "name": "priority", |
| 46 | + "type": "select", |
| 47 | + "label": "Priority", |
| 48 | + "options": ["High", "Medium", "Low"] |
| 49 | + } |
| 50 | + ] |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### 2. Render with ObjectUI |
| 56 | + |
| 57 | +Pass the protocol to the renderer: |
| 58 | + |
| 59 | +```tsx |
| 60 | +import { ObjectUIRenderer } from '@objectstack/react-renderer' |
| 61 | + |
| 62 | +function App() { |
| 63 | + return <ObjectUIRenderer schema={uiProtocol} /> |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +### 3. Automatic UI Generation |
| 68 | + |
| 69 | +ObjectUI renders a fully functional interface with forms, validation, actions, and state management—all from the JSON protocol. |
| 70 | + |
| 71 | +## Architecture Overview |
| 72 | + |
| 73 | +``` |
| 74 | +┌─────────────────────────────────────────┐ |
| 75 | +│ Application Layer │ |
| 76 | +│ (Business Logic) │ |
| 77 | +└────────────────┬────────────────────────┘ |
| 78 | + │ |
| 79 | + │ UI Protocol (JSON) |
| 80 | + │ |
| 81 | +┌────────────────▼────────────────────────┐ |
| 82 | +│ ObjectUI Engine │ |
| 83 | +│ ┌────────────┬──────────────────────┐ │ |
| 84 | +│ │ Protocol │ Component │ │ |
| 85 | +│ │ Parser │ Registry │ │ |
| 86 | +│ └────────────┴──────────────────────┘ │ |
| 87 | +│ ┌──────────────────────────────────┐ │ |
| 88 | +│ │ Render Coordinator │ │ |
| 89 | +│ │ (State & Actions) │ │ |
| 90 | +│ └──────────────────────────────────┘ │ |
| 91 | +└────────────────┬────────────────────────┘ |
| 92 | + │ |
| 93 | + │ Component Instances |
| 94 | + │ |
| 95 | +┌────────────────▼────────────────────────┐ |
| 96 | +│ React Renderer │ |
| 97 | +│ ┌──────┬──────┬──────┬──────┬──────┐ │ |
| 98 | +│ │Input │Select│Table │Form │Page │ │ |
| 99 | +│ │ │ │ │ │ │ │ |
| 100 | +│ └──────┴──────┴──────┴──────┴──────┘ │ |
| 101 | +└─────────────────────────────────────────┘ |
| 102 | +``` |
| 103 | + |
| 104 | +## Core Concepts |
| 105 | + |
| 106 | +### Declarative vs Imperative |
| 107 | + |
| 108 | +**Imperative UI (Traditional):** |
| 109 | +```tsx |
| 110 | +// Write code to describe HOW to build UI |
| 111 | +function TodoForm() { |
| 112 | + const [title, setTitle] = useState('') |
| 113 | + const [priority, setPriority] = useState('') |
| 114 | + |
| 115 | + const handleSubmit = (e) => { |
| 116 | + e.preventDefault() |
| 117 | + // Submit logic... |
| 118 | + } |
| 119 | + |
| 120 | + return ( |
| 121 | + <form onSubmit={handleSubmit}> |
| 122 | + <input |
| 123 | + value={title} |
| 124 | + onChange={(e) => setTitle(e.target.value)} |
| 125 | + /> |
| 126 | + <select |
| 127 | + value={priority} |
| 128 | + onChange={(e) => setPriority(e.target.value)} |
| 129 | + > |
| 130 | + <option>High</option> |
| 131 | + <option>Medium</option> |
| 132 | + <option>Low</option> |
| 133 | + </select> |
| 134 | + <button type="submit">Submit</button> |
| 135 | + </form> |
| 136 | + ) |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +**Declarative UI (ObjectUI):** |
| 141 | +```json |
| 142 | +{ |
| 143 | + "type": "form", |
| 144 | + "api": "/api/todos", |
| 145 | + "fields": [ |
| 146 | + { "name": "title", "type": "input", "required": true }, |
| 147 | + { "name": "priority", "type": "select", "options": ["High", "Medium", "Low"] } |
| 148 | + ] |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +The declarative approach: |
| 153 | +- ✅ Less code to write and maintain |
| 154 | +- ✅ Easier to understand and modify |
| 155 | +- ✅ Can be generated, stored, and versioned as data |
| 156 | +- ✅ Enables dynamic UI generation |
| 157 | + |
| 158 | +### Data-Driven Rendering |
| 159 | + |
| 160 | +ObjectUI components are **data-driven**: |
| 161 | + |
| 162 | +1. **Protocol defines structure** - JSON describes what to render |
| 163 | +2. **Data defines content** - Component fetches or receives data |
| 164 | +3. **State triggers updates** - Changes automatically re-render |
| 165 | + |
| 166 | +```json |
| 167 | +{ |
| 168 | + "type": "table", |
| 169 | + "api": "/api/users", |
| 170 | + "columns": [ |
| 171 | + { "name": "name", "label": "Name" }, |
| 172 | + { "name": "email", "label": "Email" }, |
| 173 | + { "name": "status", "label": "Status" } |
| 174 | + ] |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +This table: |
| 179 | +- Automatically fetches data from `/api/users` |
| 180 | +- Renders columns as specified |
| 181 | +- Handles pagination, sorting, filtering |
| 182 | +- Updates when data changes |
| 183 | + |
| 184 | +## Use Cases |
| 185 | + |
| 186 | +### Admin Panels |
| 187 | + |
| 188 | +Build complete admin interfaces without writing UI code: |
| 189 | + |
| 190 | +```json |
| 191 | +{ |
| 192 | + "type": "page", |
| 193 | + "title": "User Management", |
| 194 | + "body": { |
| 195 | + "type": "crud", |
| 196 | + "api": "/api/users", |
| 197 | + "columns": [...], |
| 198 | + "filters": [...], |
| 199 | + "actions": [...] |
| 200 | + } |
| 201 | +} |
| 202 | +``` |
| 203 | + |
| 204 | +### Dynamic Forms |
| 205 | + |
| 206 | +Create forms that adapt based on configuration: |
| 207 | + |
| 208 | +```json |
| 209 | +{ |
| 210 | + "type": "form", |
| 211 | + "api": "/api/submit", |
| 212 | + "fields": [ |
| 213 | + { "name": "name", "type": "input", "required": true }, |
| 214 | + { |
| 215 | + "name": "country", |
| 216 | + "type": "select", |
| 217 | + "api": "/api/countries" |
| 218 | + }, |
| 219 | + { |
| 220 | + "name": "state", |
| 221 | + "type": "select", |
| 222 | + "api": "/api/states", |
| 223 | + "dependsOn": "country" |
| 224 | + } |
| 225 | + ] |
| 226 | +} |
| 227 | +``` |
| 228 | + |
| 229 | +### Low-Code Platforms |
| 230 | + |
| 231 | +Enable users to build interfaces through configuration: |
| 232 | + |
| 233 | +```typescript |
| 234 | +// Store UI protocol in database |
| 235 | +await db.mutation('pages', { |
| 236 | + action: 'insert', |
| 237 | + data: { |
| 238 | + name: 'dashboard', |
| 239 | + protocol: { type: 'page', ... } |
| 240 | + } |
| 241 | +}) |
| 242 | + |
| 243 | +// Render from database |
| 244 | +const page = await db.query('pages', { filters: [['name', '=', 'dashboard']] }) |
| 245 | +return <ObjectUIRenderer schema={page.protocol} /> |
| 246 | +``` |
| 247 | + |
| 248 | +## What You'll Learn |
| 249 | + |
| 250 | +In this section, you will discover: |
| 251 | + |
| 252 | +- ✅ **Core Concepts** - Understanding declarative UI and data-driven rendering |
| 253 | +- ✅ **Component Specification** - Complete protocol reference for all components |
| 254 | +- ✅ **Renderer Usage** - How to integrate ObjectUI in React applications |
| 255 | +- ✅ **Customization** - Theming, styling, and extending components |
| 256 | + |
| 257 | +## Getting Started |
| 258 | + |
| 259 | +Ready to dive in? Start with: |
| 260 | + |
| 261 | +1. **[Core Concepts](./core-concepts)** - Understand declarative UI principles |
| 262 | +2. **[Component Spec](./component-spec)** - Learn the component protocols |
| 263 | +3. **[Renderer Usage](./renderer-usage)** - Integrate in your application |
| 264 | + |
| 265 | +## Quick Example |
| 266 | + |
| 267 | +Here's a complete example to get you started: |
| 268 | + |
| 269 | +```tsx |
| 270 | +import { ObjectUIRenderer } from '@objectstack/react-renderer' |
| 271 | +
|
| 272 | +// 1. Define UI Protocol |
| 273 | +const todoApp = { |
| 274 | + type: 'page', |
| 275 | + title: 'My Todos', |
| 276 | + body: { |
| 277 | + type: 'grid', |
| 278 | + columns: 2, |
| 279 | + items: [ |
| 280 | + { |
| 281 | + type: 'form', |
| 282 | + title: 'Add Todo', |
| 283 | + api: '/api/todos', |
| 284 | + method: 'POST', |
| 285 | + fields: [ |
| 286 | + { |
| 287 | + name: 'title', |
| 288 | + type: 'input', |
| 289 | + label: 'Task', |
| 290 | + required: true |
| 291 | + }, |
| 292 | + { |
| 293 | + name: 'completed', |
| 294 | + type: 'switch', |
| 295 | + label: 'Completed', |
| 296 | + defaultValue: false |
| 297 | + } |
| 298 | + ], |
| 299 | + submitText: 'Add Task' |
| 300 | + }, |
| 301 | + { |
| 302 | + type: 'table', |
| 303 | + title: 'Todo List', |
| 304 | + api: '/api/todos', |
| 305 | + columns: [ |
| 306 | + { name: 'title', label: 'Task' }, |
| 307 | + { name: 'completed', label: 'Done', type: 'boolean' } |
| 308 | + ], |
| 309 | + actions: [ |
| 310 | + { label: 'Delete', api: '/api/todos/${id}', method: 'DELETE' } |
| 311 | + ] |
| 312 | + } |
| 313 | + ] |
| 314 | + } |
| 315 | +} |
| 316 | +
|
| 317 | +// 2. Render |
| 318 | +function App() { |
| 319 | + return <ObjectUIRenderer schema={todoApp} /> |
| 320 | +} |
| 321 | +``` |
| 322 | + |
| 323 | +This creates a fully functional todo application with: |
| 324 | +- A form to add todos |
| 325 | +- A table showing all todos |
| 326 | +- Delete actions for each todo |
| 327 | +- Automatic data fetching and updates |
| 328 | + |
| 329 | +## Next Steps |
| 330 | + |
| 331 | +Begin your ObjectUI journey: |
| 332 | + |
| 333 | +- **New to declarative UI?** Start with [Core Concepts](./core-concepts) |
| 334 | +- **Need component reference?** Jump to [Component Spec](./component-spec) |
| 335 | +- **Ready to build?** Check [Renderer Usage](./renderer-usage) |
0 commit comments