|
| 1 | +# Specialized Designers |
| 2 | + |
| 3 | +Object UI Designer now supports three specialized designer modes, each optimized for specific use cases: |
| 4 | + |
| 5 | +## 🎯 Designer Modes |
| 6 | + |
| 7 | +### 1. Form Designer (`mode="form"`) |
| 8 | + |
| 9 | +A specialized designer for creating object forms with validation and field management. |
| 10 | + |
| 11 | +**Features:** |
| 12 | +- Form-specific component palette (inputs, selects, checkboxes, etc.) |
| 13 | +- Validation rule editor |
| 14 | +- Form layout helpers |
| 15 | +- Field property configuration |
| 16 | +- Optimized for form building workflows |
| 17 | + |
| 18 | +**Usage:** |
| 19 | +```tsx |
| 20 | +import { Designer } from '@object-ui/designer'; |
| 21 | + |
| 22 | +function App() { |
| 23 | + return ( |
| 24 | + <Designer |
| 25 | + mode="form" |
| 26 | + initialSchema={{ |
| 27 | + type: 'div', |
| 28 | + className: 'w-full max-w-2xl mx-auto p-8', |
| 29 | + body: [] |
| 30 | + }} |
| 31 | + onSchemaChange={(schema) => console.log(schema)} |
| 32 | + /> |
| 33 | + ); |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +Or use the dedicated component: |
| 38 | +```tsx |
| 39 | +import { FormDesigner } from '@object-ui/designer'; |
| 40 | + |
| 41 | +function App() { |
| 42 | + return <FormDesigner />; |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +**Available Components:** |
| 47 | +- **Form Fields**: input, textarea, select, checkbox, switch, label |
| 48 | +- **Actions**: button |
| 49 | +- **Layout**: div, card, stack, grid, separator |
| 50 | +- **Display**: text, span, badge |
| 51 | + |
| 52 | +### 2. Layout Designer (`mode="layout"`) |
| 53 | + |
| 54 | +A specialized designer for creating page layouts and structures. |
| 55 | + |
| 56 | +**Features:** |
| 57 | +- Layout-specific component palette |
| 58 | +- Grid and flexbox layout helpers |
| 59 | +- Responsive breakpoint controls |
| 60 | +- Layout templates (planned) |
| 61 | +- Optimized for page structure design |
| 62 | + |
| 63 | +**Usage:** |
| 64 | +```tsx |
| 65 | +import { Designer } from '@object-ui/designer'; |
| 66 | + |
| 67 | +function App() { |
| 68 | + return ( |
| 69 | + <Designer |
| 70 | + mode="layout" |
| 71 | + initialSchema={{ |
| 72 | + type: 'div', |
| 73 | + className: 'h-full w-full flex flex-col', |
| 74 | + body: [] |
| 75 | + }} |
| 76 | + onSchemaChange={(schema) => console.log(schema)} |
| 77 | + /> |
| 78 | + ); |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +Or use the dedicated component: |
| 83 | +```tsx |
| 84 | +import { LayoutDesigner } from '@object-ui/designer'; |
| 85 | + |
| 86 | +function App() { |
| 87 | + return <LayoutDesigner />; |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +**Available Components:** |
| 92 | +- **Containers**: div, card, grid |
| 93 | +- **Layout**: stack, separator |
| 94 | +- **Navigation**: tabs, breadcrumb, menubar, pagination |
| 95 | +- **Content**: text, span, image, button |
| 96 | +- **Data Display**: table, badge, avatar |
| 97 | + |
| 98 | +### 3. General Designer (`mode="general"` or default) |
| 99 | + |
| 100 | +The full-featured, general-purpose designer with all components and capabilities. |
| 101 | + |
| 102 | +**Features:** |
| 103 | +- Complete component library |
| 104 | +- All advanced features (resize, undo/redo, etc.) |
| 105 | +- Maximum flexibility |
| 106 | +- Suitable for any UI design task |
| 107 | + |
| 108 | +**Usage:** |
| 109 | +```tsx |
| 110 | +import { Designer } from '@object-ui/designer'; |
| 111 | + |
| 112 | +function App() { |
| 113 | + return ( |
| 114 | + <Designer |
| 115 | + mode="general" // or omit for default |
| 116 | + initialSchema={{ type: 'div', body: [] }} |
| 117 | + /> |
| 118 | + ); |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +Or use the dedicated component: |
| 123 | +```tsx |
| 124 | +import { GeneralDesigner } from '@object-ui/designer'; |
| 125 | + |
| 126 | +function App() { |
| 127 | + return <GeneralDesigner />; |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +**Available Components:** |
| 132 | +All components from the component registry, including: |
| 133 | +- Layout, Form, Data Display, Feedback, Overlay, Navigation categories |
| 134 | + |
| 135 | +## 🔄 Migration Guide |
| 136 | + |
| 137 | +### From Previous Version |
| 138 | + |
| 139 | +The default `Designer` component now supports a `mode` prop but remains backward compatible: |
| 140 | + |
| 141 | +```tsx |
| 142 | +// Old way (still works) |
| 143 | +import { Designer } from '@object-ui/designer'; |
| 144 | +<Designer initialSchema={schema} /> |
| 145 | + |
| 146 | +// New way - explicit general mode |
| 147 | +<Designer mode="general" initialSchema={schema} /> |
| 148 | + |
| 149 | +// New - specialized modes |
| 150 | +<Designer mode="form" initialSchema={schema} /> |
| 151 | +<Designer mode="layout" initialSchema={schema} /> |
| 152 | +``` |
| 153 | + |
| 154 | +All existing code will continue to work without changes. The default mode is `'general'`, which provides the same functionality as before. |
| 155 | + |
| 156 | +## 🎨 Customization |
| 157 | + |
| 158 | +### Using Filtered Component Palette |
| 159 | + |
| 160 | +You can also use the `FilteredComponentPalette` component directly for custom designer layouts: |
| 161 | + |
| 162 | +```tsx |
| 163 | +import { |
| 164 | + DesignerProvider, |
| 165 | + Canvas, |
| 166 | + FilteredComponentPalette, |
| 167 | + PropertyPanel |
| 168 | +} from '@object-ui/designer'; |
| 169 | + |
| 170 | +function CustomDesigner() { |
| 171 | + return ( |
| 172 | + <DesignerProvider> |
| 173 | + <div className="flex h-screen"> |
| 174 | + <FilteredComponentPalette |
| 175 | + allowedComponents={['input', 'button', 'text']} |
| 176 | + categories={{ |
| 177 | + 'Form': ['input', 'button'], |
| 178 | + 'Display': ['text'] |
| 179 | + }} |
| 180 | + title="My Custom Components" |
| 181 | + /> |
| 182 | + <Canvas /> |
| 183 | + <PropertyPanel /> |
| 184 | + </div> |
| 185 | + </DesignerProvider> |
| 186 | + ); |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +## 📋 Component Comparison |
| 191 | + |
| 192 | +| Feature | Form Designer | Layout Designer | General Designer | |
| 193 | +|---------|--------------|----------------|------------------| |
| 194 | +| Form Components | ✅ Primary | ⚠️ Limited | ✅ Full | |
| 195 | +| Layout Components | ⚠️ Limited | ✅ Primary | ✅ Full | |
| 196 | +| Navigation | ❌ None | ✅ Full | ✅ Full | |
| 197 | +| Data Display | ⚠️ Basic | ⚠️ Basic | ✅ Full | |
| 198 | +| Feedback/Overlay | ❌ None | ❌ None | ✅ Full | |
| 199 | +| Component Count | ~15 | ~15 | ~30+ | |
| 200 | +| Complexity | Low | Medium | High | |
| 201 | +| Use Case | Forms Only | Page Layouts | Everything | |
| 202 | + |
| 203 | +## 🚀 Best Practices |
| 204 | + |
| 205 | +1. **Choose the Right Mode**: Use specialized designers when you know your use case: |
| 206 | + - Building a form? Use `mode="form"` |
| 207 | + - Designing a page structure? Use `mode="layout"` |
| 208 | + - Need everything? Use `mode="general"` or omit the prop |
| 209 | + |
| 210 | +2. **Start Specialized, Upgrade Later**: Begin with a specialized designer for focused work, then export the schema and open it in the general designer if you need additional components. |
| 211 | + |
| 212 | +3. **Component Filtering**: The specialized designers limit available components to reduce cognitive load and improve the design experience for specific tasks. |
| 213 | + |
| 214 | +## 📝 Examples |
| 215 | + |
| 216 | +See the `examples/` directory for complete working examples: |
| 217 | +- `examples/form-designer/` - Form builder example |
| 218 | +- `examples/layout-designer/` - Page layout example |
| 219 | +- `examples/general-designer/` - General purpose example |
| 220 | + |
| 221 | +## 🔧 TypeScript Support |
| 222 | + |
| 223 | +All designer modes are fully typed: |
| 224 | + |
| 225 | +```typescript |
| 226 | +import type { DesignerMode, FormDesignerConfig, LayoutDesignerConfig } from '@object-ui/designer'; |
| 227 | + |
| 228 | +const mode: DesignerMode = 'form'; // 'form' | 'layout' | 'general' |
| 229 | + |
| 230 | +// Form-specific config |
| 231 | +const formConfig: FormDesignerConfig = { |
| 232 | + mode: 'form', |
| 233 | + showValidationRules: true, |
| 234 | + fieldTypes: ['input', 'select'] |
| 235 | +}; |
| 236 | + |
| 237 | +// Layout-specific config |
| 238 | +const layoutConfig: LayoutDesignerConfig = { |
| 239 | + mode: 'layout', |
| 240 | + showBreakpointControls: true, |
| 241 | + layoutTypes: ['grid', 'flex'] |
| 242 | +}; |
| 243 | +``` |
| 244 | + |
| 245 | +## 📚 Related Documentation |
| 246 | + |
| 247 | +- [Main README](./README.md) - Full designer documentation |
| 248 | +- [Drag and Resize Guide](./DRAG_AND_RESIZE_GUIDE.md) - Interaction details |
| 249 | +- [Implementation Guide](./IMPLEMENTATION.zh-CN.md) - Architecture overview |
0 commit comments