Skip to content

Commit c592efe

Browse files
Copilothuangyiirene
andcommitted
feat: create comprehensive @object-ui/types package with all component schemas
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 1cd315f commit c592efe

14 files changed

Lines changed: 4592 additions & 0 deletions

File tree

packages/types/README.md

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
# @object-ui/types
2+
3+
Pure TypeScript type definitions for Object UI - **The Protocol Layer**.
4+
5+
## Features
6+
7+
- 🎯 **Complete Type Coverage** - Every component has full TypeScript definitions
8+
- 📦 **Zero Dependencies** - Pure types with no runtime dependencies
9+
- 🔌 **Framework Agnostic** - Use with React, Vue, or any framework
10+
- 🌍 **Backend Agnostic** - Works with REST, GraphQL, ObjectQL, or local data
11+
- 🎨 **Tailwind Native** - Designed for Tailwind CSS styling
12+
- 📚 **Comprehensive JSDoc** - Every type is fully documented
13+
14+
## Installation
15+
16+
```bash
17+
npm install @object-ui/types
18+
# or
19+
yarn add @object-ui/types
20+
# or
21+
pnpm add @object-ui/types
22+
```
23+
24+
**Important:** This package has **ZERO runtime dependencies**. It's pure TypeScript types.
25+
26+
## Philosophy
27+
28+
Object UI follows a **"Protocol First"** approach:
29+
30+
```
31+
@object-ui/types (Protocol)
32+
33+
@object-ui/core (Engine)
34+
35+
@object-ui/react (Framework)
36+
37+
@object-ui/components (UI Implementation)
38+
```
39+
40+
This separation allows:
41+
- ✅ Multiple UI implementations (Shadcn, Material, Ant Design)
42+
- ✅ Multiple framework bindings (React, Vue, Svelte)
43+
- ✅ Multiple backend adapters (REST, GraphQL, ObjectQL)
44+
- ✅ Static analysis and validation without runtime dependencies
45+
46+
## Usage
47+
48+
### Basic Example
49+
50+
```typescript
51+
import type { FormSchema, InputSchema, ButtonSchema } from '@object-ui/types';
52+
53+
const loginForm: FormSchema = {
54+
type: 'form',
55+
fields: [
56+
{
57+
name: 'email',
58+
type: 'input',
59+
inputType: 'email',
60+
label: 'Email',
61+
required: true,
62+
},
63+
{
64+
name: 'password',
65+
type: 'input',
66+
inputType: 'password',
67+
label: 'Password',
68+
required: true,
69+
}
70+
],
71+
submitLabel: 'Sign In'
72+
};
73+
```
74+
75+
### Advanced Example
76+
77+
```typescript
78+
import type { DataTableSchema, FlexSchema, CardSchema } from '@object-ui/types';
79+
80+
const dashboard: CardSchema = {
81+
type: 'card',
82+
title: 'User Management',
83+
content: {
84+
type: 'data-table',
85+
columns: [
86+
{ header: 'Name', accessorKey: 'name' },
87+
{ header: 'Email', accessorKey: 'email' },
88+
{ header: 'Role', accessorKey: 'role' }
89+
],
90+
data: [], // Connected to data source
91+
pagination: true,
92+
searchable: true,
93+
selectable: true
94+
}
95+
};
96+
```
97+
98+
### Type Narrowing
99+
100+
```typescript
101+
import type { AnySchema, SchemaByType } from '@object-ui/types';
102+
103+
function renderComponent(schema: AnySchema) {
104+
if (schema.type === 'input') {
105+
// TypeScript automatically narrows to InputSchema
106+
console.log(schema.placeholder);
107+
}
108+
}
109+
110+
// Or use the utility type
111+
type ButtonSchema = SchemaByType<'button'>;
112+
```
113+
114+
## Type Categories
115+
116+
### Base Types
117+
118+
Foundation types that all components build upon:
119+
120+
- `BaseSchema` - The base interface for all components
121+
- `SchemaNode` - Union type for schema nodes (objects, strings, numbers, etc.)
122+
- `ComponentMeta` - Metadata for component registration
123+
- `ComponentInput` - Input field definitions for designers/editors
124+
125+
### Layout Components
126+
127+
Structure and organization:
128+
129+
- `ContainerSchema` - Max-width container
130+
- `FlexSchema` - Flexbox layout
131+
- `GridSchema` - CSS Grid layout
132+
- `CardSchema` - Card container
133+
- `TabsSchema` - Tabbed interface
134+
135+
### Form Components
136+
137+
User input and interaction:
138+
139+
- `FormSchema` - Complete form with validation
140+
- `InputSchema` - Text input field
141+
- `SelectSchema` - Dropdown select
142+
- `CheckboxSchema` - Checkbox input
143+
- `RadioGroupSchema` - Radio button group
144+
- `DatePickerSchema` - Date selection
145+
- And 10+ more form components
146+
147+
### Data Display Components
148+
149+
Information presentation:
150+
151+
- `DataTableSchema` - Enterprise data table with sorting, filtering, pagination
152+
- `TableSchema` - Simple table
153+
- `ListSchema` - List with items
154+
- `ChartSchema` - Charts and graphs
155+
- `TreeViewSchema` - Hierarchical tree
156+
- `TimelineSchema` - Timeline visualization
157+
158+
### Feedback Components
159+
160+
Status and progress:
161+
162+
- `LoadingSchema` - Loading spinner
163+
- `ProgressSchema` - Progress bar
164+
- `SkeletonSchema` - Loading placeholder
165+
- `ToastSchema` - Toast notifications
166+
167+
### Overlay Components
168+
169+
Modals and popovers:
170+
171+
- `DialogSchema` - Modal dialog
172+
- `SheetSchema` - Side panel/drawer
173+
- `PopoverSchema` - Popover
174+
- `TooltipSchema` - Tooltip
175+
- `DropdownMenuSchema` - Dropdown menu
176+
177+
### Navigation Components
178+
179+
Menus and navigation:
180+
181+
- `HeaderBarSchema` - Top navigation bar
182+
- `SidebarSchema` - Side navigation
183+
- `BreadcrumbSchema` - Breadcrumb navigation
184+
- `PaginationSchema` - Pagination controls
185+
186+
### Complex Components
187+
188+
Advanced composite components:
189+
190+
- `KanbanSchema` - Kanban board
191+
- `CalendarViewSchema` - Calendar with events
192+
- `FilterBuilderSchema` - Advanced filter builder
193+
- `CarouselSchema` - Image/content carousel
194+
- `ChatbotSchema` - Chat interface
195+
196+
### Data Management
197+
198+
Backend integration:
199+
200+
- `DataSource` - Universal data adapter interface
201+
- `QueryParams` - Query parameters (OData-style)
202+
- `QueryResult` - Paginated query results
203+
- `DataBinding` - Data binding configuration
204+
205+
## Design Principles
206+
207+
### 1. Protocol Agnostic
208+
209+
Types don't assume any specific backend:
210+
211+
```typescript
212+
interface DataSource<T = any> {
213+
find(resource: string, params?: QueryParams): Promise<QueryResult<T>>;
214+
create(resource: string, data: Partial<T>): Promise<T>;
215+
// Works with REST, GraphQL, ObjectQL, or anything
216+
}
217+
```
218+
219+
### 2. Tailwind Native
220+
221+
All components support `className` for Tailwind styling:
222+
223+
```typescript
224+
const button: ButtonSchema = {
225+
type: 'button',
226+
label: 'Click Me',
227+
className: 'bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded'
228+
};
229+
```
230+
231+
### 3. Type Safe
232+
233+
Full TypeScript support with discriminated unions:
234+
235+
```typescript
236+
type AnySchema =
237+
| InputSchema
238+
| ButtonSchema
239+
| FormSchema
240+
| /* 50+ more */;
241+
242+
function render(schema: AnySchema) {
243+
switch (schema.type) {
244+
case 'input': /* schema is InputSchema */ break;
245+
case 'button': /* schema is ButtonSchema */ break;
246+
}
247+
}
248+
```
249+
250+
### 4. Composable
251+
252+
Components can nest indefinitely:
253+
254+
```typescript
255+
const page: FlexSchema = {
256+
type: 'flex',
257+
direction: 'col',
258+
children: [
259+
{ type: 'header-bar', title: 'My App' },
260+
{
261+
type: 'flex',
262+
direction: 'row',
263+
children: [
264+
{ type: 'sidebar', nav: [...] },
265+
{ type: 'container', children: [...] }
266+
]
267+
}
268+
]
269+
};
270+
```
271+
272+
## Comparison
273+
274+
### vs Amis Types
275+
276+
-**Lighter** - No runtime dependencies
277+
-**Tailwind Native** - Built for Tailwind CSS
278+
-**Better TypeScript** - Full type inference
279+
-**Framework Agnostic** - Not tied to React
280+
281+
### vs Formily Types
282+
283+
-**Full Pages** - Not just forms, entire UIs
284+
-**Simpler** - More straightforward API
285+
-**Better Docs** - Comprehensive JSDoc
286+
287+
## Contributing
288+
289+
We follow these constraints for this package:
290+
291+
1. **ZERO runtime dependencies** - Only TypeScript types
292+
2. **No React imports** - Framework agnostic
293+
3. **Comprehensive JSDoc** - Every property documented
294+
4. **Protocol first** - Types define the contract
295+
296+
## License
297+
298+
MIT
299+
300+
## Links
301+
302+
- [Documentation](https://objectui.org/docs/types)
303+
- [GitHub](https://github.com/objectstack-ai/objectui)
304+
- [NPM](https://www.npmjs.com/package/@object-ui/types)

packages/types/package.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "@object-ui/types",
3+
"version": "0.1.0",
4+
"description": "Pure TypeScript type definitions for Object UI - The Protocol Layer",
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"module": "./dist/index.js",
8+
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.js",
13+
"require": "./dist/index.cjs"
14+
},
15+
"./base": {
16+
"types": "./dist/base.d.ts",
17+
"import": "./dist/base.js"
18+
},
19+
"./layout": {
20+
"types": "./dist/layout.d.ts",
21+
"import": "./dist/layout.js"
22+
},
23+
"./form": {
24+
"types": "./dist/form.d.ts",
25+
"import": "./dist/form.js"
26+
},
27+
"./data-display": {
28+
"types": "./dist/data-display.d.ts",
29+
"import": "./dist/data-display.js"
30+
},
31+
"./feedback": {
32+
"types": "./dist/feedback.d.ts",
33+
"import": "./dist/feedback.js"
34+
},
35+
"./overlay": {
36+
"types": "./dist/overlay.d.ts",
37+
"import": "./dist/overlay.js"
38+
},
39+
"./navigation": {
40+
"types": "./dist/navigation.d.ts",
41+
"import": "./dist/navigation.js"
42+
},
43+
"./complex": {
44+
"types": "./dist/complex.d.ts",
45+
"import": "./dist/complex.js"
46+
},
47+
"./data": {
48+
"types": "./dist/data.d.ts",
49+
"import": "./dist/data.js"
50+
}
51+
},
52+
"files": [
53+
"dist",
54+
"src",
55+
"README.md",
56+
"LICENSE"
57+
],
58+
"scripts": {
59+
"build": "tsc",
60+
"clean": "rm -rf dist",
61+
"type-check": "tsc --noEmit"
62+
},
63+
"keywords": [
64+
"object-ui",
65+
"types",
66+
"typescript",
67+
"schema",
68+
"json-schema",
69+
"protocol"
70+
],
71+
"author": "Object UI Team",
72+
"license": "MIT",
73+
"repository": {
74+
"type": "git",
75+
"url": "https://github.com/objectstack-ai/objectui.git",
76+
"directory": "packages/types"
77+
},
78+
"devDependencies": {
79+
"typescript": "^5.0.0"
80+
}
81+
}

0 commit comments

Comments
 (0)