@object-ui/components 0.5.0 β 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -25
- package/CHANGELOG.md +13 -0
- package/dist/index.css +1 -1
- package/dist/index.js +23366 -22221
- package/dist/index.umd.cjs +30 -30
- package/dist/src/custom/action-param-dialog.d.ts +21 -0
- package/dist/src/custom/index.d.ts +2 -0
- package/dist/src/custom/navigation-overlay.d.ts +50 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/renderers/action/action-button.d.ts +11 -0
- package/dist/src/renderers/action/action-group.d.ts +25 -0
- package/dist/src/renderers/action/action-icon.d.ts +10 -0
- package/dist/src/renderers/action/action-menu.d.ts +19 -0
- package/dist/src/renderers/action/index.d.ts +0 -0
- package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
- package/package.json +9 -8
- package/src/__tests__/PageRendererRegions.test.tsx +664 -55
- package/src/__tests__/compliance.test.tsx +72 -0
- package/src/__tests__/navigation-overlay.test.tsx +273 -0
- package/src/__tests__/view-compliance.test.tsx +153 -0
- package/src/custom/action-param-dialog.tsx +264 -0
- package/src/custom/index.ts +2 -0
- package/src/custom/navigation-overlay.tsx +296 -0
- package/src/index.ts +1 -0
- package/src/renderers/action/action-button.tsx +147 -0
- package/src/renderers/action/action-group.tsx +270 -0
- package/src/renderers/action/action-icon.tsx +150 -0
- package/src/renderers/action/action-menu.tsx +203 -0
- package/src/renderers/action/index.ts +18 -0
- package/src/renderers/action/resolve-icon.ts +35 -0
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
- package/src/renderers/complex/data-table.tsx +242 -21
- package/src/renderers/form/form.tsx +23 -4
- package/src/renderers/index.ts +1 -0
- package/src/renderers/layout/page.tsx +416 -52
- package/src/renderers/navigation/sidebar.tsx +6 -0
- package/src/renderers/placeholders.tsx +2 -2
- package/src/stories/Introduction.mdx +54 -27
- package/src/stories/MockedData.stories.tsx +87 -37
- package/src/stories-json/accordion.stories.tsx +1 -1
- package/src/stories-json/aggrid.stories.tsx +1 -1
- package/src/stories-json/alert.stories.tsx +1 -1
- package/src/stories-json/aspect-ratio.stories.tsx +1 -1
- package/src/stories-json/avatar.stories.tsx +1 -1
- package/src/stories-json/badge.stories.tsx +1 -1
- package/src/stories-json/breadcrumb.stories.tsx +1 -1
- package/src/stories-json/button-group.stories.tsx +1 -1
- package/src/stories-json/button.stories.tsx +1 -1
- package/src/stories-json/calendar.stories.tsx +1 -1
- package/src/stories-json/card.stories.tsx +1 -1
- package/src/stories-json/carousel.stories.tsx +1 -1
- package/src/stories-json/charts.stories.tsx +1 -1
- package/src/stories-json/chatbot.stories.tsx +1 -1
- package/src/stories-json/code-editor.stories.tsx +1 -1
- package/src/stories-json/collapsible.stories.tsx +1 -1
- package/src/stories-json/controls.stories.tsx +1 -1
- package/src/stories-json/crm-live-data.stories.tsx +154 -0
- package/src/stories-json/data-table.stories.tsx +80 -4
- package/src/stories-json/data_display_extras.stories.tsx +1 -1
- package/src/stories-json/date-picker.stories.tsx +1 -1
- package/src/stories-json/detail-view.stories.tsx +1 -1
- package/src/stories-json/dialog.stories.tsx +1 -1
- package/src/stories-json/feedback_extras.stories.tsx +1 -1
- package/src/stories-json/feedback_others.stories.tsx +1 -1
- package/src/stories-json/form-variants.stories.tsx +210 -0
- package/src/stories-json/form_advanced.stories.tsx +1 -1
- package/src/stories-json/form_extras.stories.tsx +1 -1
- package/src/stories-json/grid.stories.tsx +1 -1
- package/src/stories-json/icon.stories.tsx +1 -1
- package/src/stories-json/input.stories.tsx +1 -1
- package/src/stories-json/kanban.stories.tsx +1 -1
- package/src/stories-json/layout_extended.stories.tsx +1 -1
- package/src/stories-json/layout_flex.stories.tsx +1 -1
- package/src/stories-json/list-view.stories.tsx +1 -1
- package/src/stories-json/markdown.stories.tsx +1 -1
- package/src/stories-json/menus.stories.tsx +1 -1
- package/src/stories-json/metric-card.stories.tsx +1 -1
- package/src/stories-json/navigation-menu.stories.tsx +1 -1
- package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
- package/src/stories-json/object-aggrid.stories.tsx +1 -1
- package/src/stories-json/object-form.stories.tsx +1 -1
- package/src/stories-json/object-gantt.stories.tsx +1 -1
- package/src/stories-json/object-grid.stories.tsx +159 -1
- package/src/stories-json/object-map.stories.tsx +1 -1
- package/src/stories-json/object-view.stories.tsx +1 -1
- package/src/stories-json/overlay_extras.stories.tsx +1 -1
- package/src/stories-json/overlay_others.stories.tsx +1 -1
- package/src/stories-json/resizable.stories.tsx +1 -1
- package/src/stories-json/select.stories.tsx +1 -1
- package/src/stories-json/separator.stories.tsx +1 -1
- package/src/stories-json/statistic.stories.tsx +1 -1
- package/src/stories-json/tabs.stories.tsx +1 -1
- package/src/stories-json/timeline.stories.tsx +1 -1
- package/src/stories-json/typography.stories.tsx +1 -1
|
@@ -1,53 +1,396 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ObjectUI
|
|
2
|
+
* ObjectUI β Page Renderer
|
|
3
3
|
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* The Page renderer interprets PageSchema into structured layouts.
|
|
9
|
+
* It supports four page types (record, home, app, utility) and
|
|
10
|
+
* renders named regions (header, sidebar, main, footer, aside) with
|
|
11
|
+
* configurable widths. When no regions are defined, it falls back to
|
|
12
|
+
* body/children for backward compatibility.
|
|
7
13
|
*/
|
|
8
14
|
|
|
9
|
-
import React from 'react';
|
|
10
|
-
import { PageSchema } from '@object-ui/types';
|
|
11
|
-
import { SchemaRenderer } from '@object-ui/react';
|
|
15
|
+
import React, { useMemo } from 'react';
|
|
16
|
+
import type { PageSchema, PageRegion, SchemaNode } from '@object-ui/types';
|
|
17
|
+
import { SchemaRenderer, PageVariablesProvider } from '@object-ui/react';
|
|
12
18
|
import { ComponentRegistry } from '@object-ui/core';
|
|
13
|
-
import { cn } from '../../lib/utils';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
import { cn } from '../../lib/utils';
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Helpers
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/** Map region width enum values to Tailwind width classes */
|
|
26
|
+
function getRegionWidthClass(width?: string): string {
|
|
27
|
+
switch (width) {
|
|
28
|
+
case 'small':
|
|
29
|
+
return 'w-64';
|
|
30
|
+
case 'medium':
|
|
31
|
+
return 'w-80';
|
|
32
|
+
case 'large':
|
|
33
|
+
return 'w-96';
|
|
34
|
+
case 'full':
|
|
35
|
+
return 'w-full';
|
|
36
|
+
default:
|
|
37
|
+
return width ? width : 'w-full';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Max-width constraint by page type */
|
|
42
|
+
function getPageMaxWidth(pageType?: string): string {
|
|
43
|
+
switch (pageType) {
|
|
44
|
+
case 'utility':
|
|
45
|
+
return 'max-w-4xl';
|
|
46
|
+
case 'home':
|
|
47
|
+
return 'max-w-screen-2xl';
|
|
48
|
+
case 'app':
|
|
49
|
+
return 'max-w-screen-xl';
|
|
50
|
+
case 'record':
|
|
51
|
+
default:
|
|
52
|
+
return 'max-w-7xl';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Find a named region (case-insensitive) */
|
|
57
|
+
function findRegion(regions: PageRegion[] | undefined, name: string): PageRegion | undefined {
|
|
58
|
+
return regions?.find((r) => r.name?.toLowerCase() === name.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Get all regions that are NOT in the named set */
|
|
62
|
+
function getRemainingRegions(regions: PageRegion[] | undefined, exclude: string[]): PageRegion[] {
|
|
63
|
+
if (!regions) return [];
|
|
64
|
+
const lowerSet = new Set(exclude.map((n) => n.toLowerCase()));
|
|
65
|
+
return regions.filter((r) => !lowerSet.has(r.name?.toLowerCase() ?? ''));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// RegionContent β renders all components inside a single region
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
const RegionContent: React.FC<{
|
|
73
|
+
region: PageRegion;
|
|
74
|
+
className?: string;
|
|
75
|
+
}> = ({ region, className }) => {
|
|
76
|
+
const components = region.components || [];
|
|
77
|
+
if (components.length === 0) return null;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
className={cn('space-y-4', region.className, className)}
|
|
82
|
+
data-region={region.name}
|
|
83
|
+
>
|
|
84
|
+
{components.map((node: SchemaNode, idx: number) => (
|
|
85
|
+
<SchemaRenderer key={(node as any)?.id || `${region.name}-${idx}`} schema={node} />
|
|
86
|
+
))}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// RegionLayout β structured layout with named slots
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
const RegionLayout: React.FC<{
|
|
96
|
+
regions: PageRegion[];
|
|
97
|
+
pageType?: string;
|
|
98
|
+
className?: string;
|
|
99
|
+
}> = ({ regions, pageType, className }) => {
|
|
100
|
+
const header = findRegion(regions, 'header');
|
|
101
|
+
const sidebar = findRegion(regions, 'sidebar');
|
|
102
|
+
const main = findRegion(regions, 'main');
|
|
103
|
+
const aside = findRegion(regions, 'aside');
|
|
104
|
+
const footer = findRegion(regions, 'footer');
|
|
105
|
+
|
|
106
|
+
// Remaining regions that don't match named slots β append below main
|
|
107
|
+
const extras = getRemainingRegions(regions, ['header', 'sidebar', 'main', 'aside', 'footer']);
|
|
108
|
+
|
|
109
|
+
// If there's no named layout structure, just stack everything
|
|
110
|
+
const hasStructure = header || sidebar || main || aside || footer;
|
|
111
|
+
if (!hasStructure) {
|
|
112
|
+
return (
|
|
113
|
+
<div className={cn('space-y-6', className)} data-page-layout={pageType}>
|
|
114
|
+
{regions.map((region, idx) => (
|
|
115
|
+
<RegionContent key={region.name || idx} region={region} />
|
|
116
|
+
))}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div className={cn('flex flex-col gap-6', className)} data-page-layout={pageType}>
|
|
123
|
+
{/* Header region */}
|
|
124
|
+
{header && (
|
|
125
|
+
<RegionContent
|
|
126
|
+
region={header}
|
|
127
|
+
className={cn(getRegionWidthClass(header.width as string))}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
|
|
131
|
+
{/* Body: sidebar + main + aside */}
|
|
132
|
+
<div className="flex flex-1 gap-6">
|
|
133
|
+
{sidebar && (
|
|
134
|
+
<aside className={cn('shrink-0', getRegionWidthClass(sidebar.width as string || 'small'))}>
|
|
135
|
+
<RegionContent region={sidebar} />
|
|
136
|
+
</aside>
|
|
137
|
+
)}
|
|
138
|
+
|
|
139
|
+
<div className="flex-1 min-w-0 space-y-6">
|
|
140
|
+
{main && <RegionContent region={main} />}
|
|
141
|
+
{extras.map((region, idx) => (
|
|
142
|
+
<RegionContent key={region.name || `extra-${idx}`} region={region} />
|
|
143
|
+
))}
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
{aside && (
|
|
147
|
+
<aside className={cn('shrink-0', getRegionWidthClass(aside.width as string || 'small'))}>
|
|
148
|
+
<RegionContent region={aside} />
|
|
149
|
+
</aside>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
{/* Footer region */}
|
|
154
|
+
{footer && (
|
|
155
|
+
<RegionContent
|
|
156
|
+
region={footer}
|
|
157
|
+
className={cn(getRegionWidthClass(footer.width as string))}
|
|
158
|
+
/>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// FlatContent β legacy body/children fallback
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
const FlatContent: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
169
|
+
const content = schema.body || schema.children;
|
|
170
|
+
const nodes: SchemaNode[] = Array.isArray(content)
|
|
171
|
+
? content
|
|
172
|
+
: content
|
|
173
|
+
? [content as SchemaNode]
|
|
174
|
+
: [];
|
|
175
|
+
|
|
176
|
+
if (nodes.length === 0) return null;
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div className="space-y-6">
|
|
180
|
+
{nodes.map((node: any, index: number) => (
|
|
181
|
+
<SchemaRenderer key={node?.id || index} schema={node} />
|
|
182
|
+
))}
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// Template layouts β predefined layout templates
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
/** Template: full-width single column */
|
|
192
|
+
const FullWidthTemplate: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
193
|
+
if (schema.regions && schema.regions.length > 0) {
|
|
194
|
+
return <RegionLayout regions={schema.regions} pageType={schema.pageType} />;
|
|
195
|
+
}
|
|
196
|
+
return <FlatContent schema={schema} />;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** Template: header-sidebar-main β header spanning full width, sidebar + main below */
|
|
200
|
+
const HeaderSidebarMainTemplate: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
201
|
+
const regions = schema.regions || [];
|
|
202
|
+
if (regions.length === 0) return <FlatContent schema={schema} />;
|
|
203
|
+
|
|
204
|
+
const header = findRegion(regions, 'header');
|
|
205
|
+
const sidebar = findRegion(regions, 'sidebar');
|
|
206
|
+
const main = findRegion(regions, 'main');
|
|
207
|
+
const extras = getRemainingRegions(regions, ['header', 'sidebar', 'main']);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div className="flex flex-col gap-6" data-template="header-sidebar-main">
|
|
211
|
+
{header && <RegionContent region={header} />}
|
|
212
|
+
<div className="flex flex-1 gap-6">
|
|
213
|
+
{sidebar && (
|
|
214
|
+
<aside className={cn('shrink-0', getRegionWidthClass(sidebar.width as string || 'medium'))}>
|
|
215
|
+
<RegionContent region={sidebar} />
|
|
216
|
+
</aside>
|
|
217
|
+
)}
|
|
218
|
+
<div className="flex-1 min-w-0 space-y-6">
|
|
219
|
+
{main && <RegionContent region={main} />}
|
|
220
|
+
{extras.map((region, idx) => (
|
|
221
|
+
<RegionContent key={region.name || `extra-${idx}`} region={region} />
|
|
222
|
+
))}
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/** Template: three-column β sidebar + main + aside */
|
|
230
|
+
const ThreeColumnTemplate: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
231
|
+
const regions = schema.regions || [];
|
|
232
|
+
if (regions.length === 0) return <FlatContent schema={schema} />;
|
|
233
|
+
|
|
234
|
+
const header = findRegion(regions, 'header');
|
|
235
|
+
const sidebar = findRegion(regions, 'sidebar');
|
|
236
|
+
const main = findRegion(regions, 'main');
|
|
237
|
+
const aside = findRegion(regions, 'aside');
|
|
238
|
+
const footer = findRegion(regions, 'footer');
|
|
239
|
+
const extras = getRemainingRegions(regions, ['header', 'sidebar', 'main', 'aside', 'footer']);
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<div className="flex flex-col gap-6" data-template="three-column">
|
|
243
|
+
{header && <RegionContent region={header} />}
|
|
244
|
+
<div className="flex flex-1 gap-6">
|
|
245
|
+
{sidebar && (
|
|
246
|
+
<aside className={cn('shrink-0', getRegionWidthClass(sidebar.width as string || 'small'))}>
|
|
247
|
+
<RegionContent region={sidebar} />
|
|
248
|
+
</aside>
|
|
249
|
+
)}
|
|
250
|
+
<div className="flex-1 min-w-0 space-y-6">
|
|
251
|
+
{main && <RegionContent region={main} />}
|
|
252
|
+
{extras.map((region, idx) => (
|
|
253
|
+
<RegionContent key={region.name || `extra-${idx}`} region={region} />
|
|
254
|
+
))}
|
|
255
|
+
</div>
|
|
256
|
+
{aside && (
|
|
257
|
+
<aside className={cn('shrink-0', getRegionWidthClass(aside.width as string || 'small'))}>
|
|
258
|
+
<RegionContent region={aside} />
|
|
259
|
+
</aside>
|
|
260
|
+
)}
|
|
261
|
+
</div>
|
|
262
|
+
{footer && <RegionContent region={footer} />}
|
|
263
|
+
</div>
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/** Template: dashboard β 2x2 grid of regions */
|
|
268
|
+
const DashboardTemplate: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
269
|
+
const regions = schema.regions || [];
|
|
270
|
+
if (regions.length === 0) return <FlatContent schema={schema} />;
|
|
271
|
+
|
|
272
|
+
const header = findRegion(regions, 'header');
|
|
273
|
+
const footer = findRegion(regions, 'footer');
|
|
274
|
+
const contentRegions = getRemainingRegions(regions, ['header', 'footer']);
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<div className="flex flex-col gap-6" data-template="dashboard">
|
|
278
|
+
{header && <RegionContent region={header} />}
|
|
279
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
280
|
+
{contentRegions.map((region, idx) => (
|
|
281
|
+
<RegionContent key={region.name || `region-${idx}`} region={region} />
|
|
282
|
+
))}
|
|
283
|
+
</div>
|
|
284
|
+
{footer && <RegionContent region={footer} />}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/** Template registry β maps template names to layout components */
|
|
290
|
+
const TEMPLATE_REGISTRY: Record<string, React.FC<{ schema: PageSchema }>> = {
|
|
291
|
+
'default': FullWidthTemplate,
|
|
292
|
+
'full-width': FullWidthTemplate,
|
|
293
|
+
'header-sidebar-main': HeaderSidebarMainTemplate,
|
|
294
|
+
'three-column': ThreeColumnTemplate,
|
|
295
|
+
'dashboard': DashboardTemplate,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/** Resolve template: if the schema specifies a template name, use the matching layout */
|
|
299
|
+
function resolveTemplate(schema: PageSchema): React.FC<{ schema: PageSchema }> | null {
|
|
300
|
+
if (!schema.template) return null;
|
|
301
|
+
return TEMPLATE_REGISTRY[schema.template] || null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// Page type variant layouts
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
|
|
308
|
+
/** Record page β detail-oriented, narrower max-width */
|
|
309
|
+
const RecordPageLayout: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
23
310
|
if (schema.regions && schema.regions.length > 0) {
|
|
24
|
-
|
|
25
|
-
// Ideally, we might want a grid layout here, but linear stacking works for simple single-region pages
|
|
26
|
-
nodes = schema.regions.flatMap(r => r.components || []);
|
|
27
|
-
} else {
|
|
28
|
-
// Fallback to direct children/body
|
|
29
|
-
const content = schema.body || schema.children;
|
|
30
|
-
nodes = Array.isArray(content) ? content : (content ? [content] : []);
|
|
311
|
+
return <RegionLayout regions={schema.regions} pageType="record" />;
|
|
31
312
|
}
|
|
313
|
+
return <FlatContent schema={schema} />;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/** Home page β dashboard-style, wider layout */
|
|
317
|
+
const HomePageLayout: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
318
|
+
if (schema.regions && schema.regions.length > 0) {
|
|
319
|
+
return <RegionLayout regions={schema.regions} pageType="home" />;
|
|
320
|
+
}
|
|
321
|
+
return <FlatContent schema={schema} />;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/** App page β application shell, full-width capable */
|
|
325
|
+
const AppPageLayout: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
326
|
+
if (schema.regions && schema.regions.length > 0) {
|
|
327
|
+
return <RegionLayout regions={schema.regions} pageType="app" />;
|
|
328
|
+
}
|
|
329
|
+
return <FlatContent schema={schema} />;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/** Utility page β compact, focused, narrower */
|
|
333
|
+
const UtilityPageLayout: React.FC<{ schema: PageSchema }> = ({ schema }) => {
|
|
334
|
+
if (schema.regions && schema.regions.length > 0) {
|
|
335
|
+
return <RegionLayout regions={schema.regions} pageType="utility" />;
|
|
336
|
+
}
|
|
337
|
+
return <FlatContent schema={schema} />;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// ---------------------------------------------------------------------------
|
|
341
|
+
// Main PageRenderer
|
|
342
|
+
// ---------------------------------------------------------------------------
|
|
343
|
+
|
|
344
|
+
export const PageRenderer: React.FC<{
|
|
345
|
+
schema: PageSchema;
|
|
346
|
+
className?: string;
|
|
347
|
+
[key: string]: any;
|
|
348
|
+
}> = ({ schema, className, ...props }) => {
|
|
349
|
+
const pageType = schema.pageType || 'record';
|
|
32
350
|
|
|
33
351
|
// Extract designer-related props
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
352
|
+
const {
|
|
353
|
+
'data-obj-id': dataObjId,
|
|
354
|
+
'data-obj-type': dataObjType,
|
|
355
|
+
style,
|
|
356
|
+
...pageProps
|
|
39
357
|
} = props;
|
|
40
358
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
359
|
+
// Select the layout variant based on template or page type
|
|
360
|
+
const layoutElement = useMemo(() => {
|
|
361
|
+
const TemplateLayout = resolveTemplate(schema);
|
|
362
|
+
if (TemplateLayout) {
|
|
363
|
+
// Template takes priority over page type
|
|
364
|
+
// eslint-disable-next-line react-hooks/static-components -- TemplateLayout is resolved from a stable template registry
|
|
365
|
+
return <TemplateLayout schema={schema} />;
|
|
366
|
+
}
|
|
367
|
+
switch (pageType) {
|
|
368
|
+
case 'home':
|
|
369
|
+
return <HomePageLayout schema={schema} />;
|
|
370
|
+
case 'app':
|
|
371
|
+
return <AppPageLayout schema={schema} />;
|
|
372
|
+
case 'utility':
|
|
373
|
+
return <UtilityPageLayout schema={schema} />;
|
|
374
|
+
case 'record':
|
|
375
|
+
default:
|
|
376
|
+
return <RecordPageLayout schema={schema} />;
|
|
377
|
+
}
|
|
378
|
+
}, [schema, pageType]);
|
|
379
|
+
|
|
380
|
+
const pageContent = (
|
|
381
|
+
<div
|
|
382
|
+
className={cn(
|
|
383
|
+
'min-h-full w-full bg-background p-4 md:p-6 lg:p-8',
|
|
384
|
+
className,
|
|
385
|
+
)}
|
|
386
|
+
data-page-type={pageType}
|
|
46
387
|
data-obj-id={dataObjId}
|
|
47
388
|
data-obj-type={dataObjType}
|
|
48
389
|
style={style}
|
|
390
|
+
{...pageProps}
|
|
49
391
|
>
|
|
50
|
-
<div className=
|
|
392
|
+
<div className={cn('mx-auto space-y-8', getPageMaxWidth(pageType))}>
|
|
393
|
+
{/* Page header */}
|
|
51
394
|
{(schema.title || schema.description) && (
|
|
52
395
|
<div className="space-y-2">
|
|
53
396
|
{schema.title && (
|
|
@@ -56,27 +399,33 @@ export const PageRenderer: React.FC<{ schema: PageSchema; className?: string; [k
|
|
|
56
399
|
</h1>
|
|
57
400
|
)}
|
|
58
401
|
{schema.description && (
|
|
59
|
-
<p className="text-muted-foreground">
|
|
60
|
-
{schema.description}
|
|
61
|
-
</p>
|
|
402
|
+
<p className="text-muted-foreground">{schema.description}</p>
|
|
62
403
|
)}
|
|
63
404
|
</div>
|
|
64
405
|
)}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{nodes.map((node: any, index: number) => (
|
|
69
|
-
<SchemaRenderer
|
|
70
|
-
key={node?.id || index}
|
|
71
|
-
schema={node}
|
|
72
|
-
/>
|
|
73
|
-
))}
|
|
74
|
-
</div>
|
|
406
|
+
|
|
407
|
+
{/* Page body β type-specific layout */}
|
|
408
|
+
{layoutElement}
|
|
75
409
|
</div>
|
|
76
410
|
</div>
|
|
77
411
|
);
|
|
412
|
+
|
|
413
|
+
// Wrap with PageVariablesProvider when variables are defined
|
|
414
|
+
if (schema.variables && schema.variables.length > 0) {
|
|
415
|
+
return (
|
|
416
|
+
<PageVariablesProvider definitions={schema.variables}>
|
|
417
|
+
{pageContent}
|
|
418
|
+
</PageVariablesProvider>
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return pageContent;
|
|
78
423
|
};
|
|
79
424
|
|
|
425
|
+
// ---------------------------------------------------------------------------
|
|
426
|
+
// ComponentRegistry registration
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
|
|
80
429
|
const pageMeta: any = {
|
|
81
430
|
namespace: 'ui',
|
|
82
431
|
label: 'Page',
|
|
@@ -85,13 +434,28 @@ const pageMeta: any = {
|
|
|
85
434
|
inputs: [
|
|
86
435
|
{ name: 'title', type: 'string', label: 'Title' },
|
|
87
436
|
{ name: 'description', type: 'string', label: 'Description' },
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
437
|
+
{ name: 'pageType', type: 'string', label: 'Page Type' },
|
|
438
|
+
{ name: 'object', type: 'string', label: 'Object Name' },
|
|
439
|
+
{ name: 'template', type: 'string', label: 'Template' },
|
|
440
|
+
{
|
|
441
|
+
name: 'regions',
|
|
442
|
+
type: 'array',
|
|
443
|
+
label: 'Regions',
|
|
444
|
+
itemType: 'object',
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: 'variables',
|
|
448
|
+
type: 'array',
|
|
449
|
+
label: 'Variables',
|
|
450
|
+
itemType: 'object',
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
name: 'body',
|
|
454
|
+
type: 'array',
|
|
455
|
+
label: 'Content (Legacy)',
|
|
456
|
+
itemType: 'component',
|
|
457
|
+
},
|
|
458
|
+
],
|
|
95
459
|
};
|
|
96
460
|
|
|
97
461
|
ComponentRegistry.register('page', PageRenderer, pageMeta);
|
|
@@ -75,6 +75,7 @@ ComponentRegistry.register('sidebar-header',
|
|
|
75
75
|
<SidebarHeader {...props}>{renderChildren(schema.body)}</SidebarHeader>
|
|
76
76
|
),
|
|
77
77
|
{
|
|
78
|
+
namespace: 'ui',
|
|
78
79
|
label: 'Sidebar Header',
|
|
79
80
|
defaultChildren: [
|
|
80
81
|
{ type: 'text', content: 'Sidebar Header' }
|
|
@@ -87,6 +88,7 @@ ComponentRegistry.register('sidebar-content',
|
|
|
87
88
|
<SidebarContent {...props}>{renderChildren(schema.body)}</SidebarContent>
|
|
88
89
|
),
|
|
89
90
|
{
|
|
91
|
+
namespace: 'ui',
|
|
90
92
|
label: 'Sidebar Content',
|
|
91
93
|
defaultChildren: [
|
|
92
94
|
{ type: 'sidebar-group' }
|
|
@@ -123,6 +125,7 @@ ComponentRegistry.register('sidebar-menu',
|
|
|
123
125
|
<SidebarMenu {...props}>{renderChildren(schema.body)}</SidebarMenu>
|
|
124
126
|
),
|
|
125
127
|
{
|
|
128
|
+
namespace: 'ui',
|
|
126
129
|
label: 'Sidebar Menu',
|
|
127
130
|
defaultChildren: [
|
|
128
131
|
{ type: 'sidebar-menu-item' },
|
|
@@ -136,6 +139,7 @@ ComponentRegistry.register('sidebar-menu-item',
|
|
|
136
139
|
<SidebarMenuItem {...props}>{renderChildren(schema.body)}</SidebarMenuItem>
|
|
137
140
|
),
|
|
138
141
|
{
|
|
142
|
+
namespace: 'ui',
|
|
139
143
|
label: 'Sidebar Menu Item',
|
|
140
144
|
defaultChildren: [
|
|
141
145
|
{ type: 'sidebar-menu-button' }
|
|
@@ -171,6 +175,7 @@ ComponentRegistry.register('sidebar-footer',
|
|
|
171
175
|
<SidebarFooter {...props}>{renderChildren(schema.body)}</SidebarFooter>
|
|
172
176
|
),
|
|
173
177
|
{
|
|
178
|
+
namespace: 'ui',
|
|
174
179
|
label: 'Sidebar Footer',
|
|
175
180
|
defaultChildren: [
|
|
176
181
|
{ type: 'text', content: 'Footer' }
|
|
@@ -183,6 +188,7 @@ ComponentRegistry.register('sidebar-inset',
|
|
|
183
188
|
<SidebarInset {...props}>{renderChildren(schema.body)}</SidebarInset>
|
|
184
189
|
),
|
|
185
190
|
{
|
|
191
|
+
namespace: 'ui',
|
|
186
192
|
label: 'Sidebar Inset',
|
|
187
193
|
defaultChildren: [
|
|
188
194
|
{ type: 'div', className: 'p-4', body: [{ type: 'text', content: 'Main content area' }] }
|
|
@@ -90,8 +90,8 @@ const PROTOCOL_COMPONENTS = [
|
|
|
90
90
|
'widget:metric', 'widget:bar', 'widget:line', 'widget:pie', 'widget:funnel',
|
|
91
91
|
'widget:radar', 'widget:scatter', 'widget:heatmap', 'widget:pivot', 'widget:table', 'widget:text', 'widget:image',
|
|
92
92
|
|
|
93
|
-
// 14. Smart Actions
|
|
94
|
-
'action:button', 'action:group', 'action:menu', 'action:icon',
|
|
93
|
+
// 14. Smart Actions (implemented in ./action/)
|
|
94
|
+
// 'action:button', 'action:group', 'action:menu', 'action:icon',
|
|
95
95
|
|
|
96
96
|
// 15. AI
|
|
97
97
|
'ai:chat_window', 'ai:input', 'ai:suggestion', 'ai:feedback'
|
|
@@ -1,34 +1,61 @@
|
|
|
1
1
|
import { Meta } from "@storybook/blocks";
|
|
2
2
|
|
|
3
|
-
<Meta title="Introduction" />
|
|
3
|
+
<Meta title="Getting Started/Introduction" />
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# ObjectUI β Server-Driven UI Engine
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**ObjectUI** is a universal, server-driven UI (SDUI) engine built on **React + Tailwind + Shadcn**.
|
|
8
|
+
It interprets JSON metadata into pixel-perfect, accessible, and interactive enterprise interfaces.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
## π Architecture
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- **Protocol Agnostic**: Works with any backend via Data Adapters.
|
|
14
|
-
- **Server Driven**: The UI structure is defined by JSON schemas.
|
|
15
|
-
- **Shadcn Compatible**: Uses standard Shadcn UI primitives.
|
|
16
|
-
- **Action System**: declaratively define behavior (clicks, validation, navigation).
|
|
17
|
-
|
|
18
|
-
## Packages
|
|
19
|
-
|
|
20
|
-
| Package | Description |
|
|
12
|
+
| Package | Role |
|
|
21
13
|
|---|---|
|
|
22
|
-
| `@object-ui/
|
|
23
|
-
| `@object-ui/
|
|
24
|
-
| `@object-ui/
|
|
25
|
-
| `@object-ui/
|
|
26
|
-
| `@object-ui/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
| `@object-ui/types` | JSON Protocol β Pure TypeScript interfaces |
|
|
15
|
+
| `@object-ui/core` | Engine β Schema registry, validation, expressions |
|
|
16
|
+
| `@object-ui/components` | Primitives β Shadcn UI wrappers (Button, Card, Badgeβ¦) |
|
|
17
|
+
| `@object-ui/fields` | Field Widgets β 47+ input field renderers |
|
|
18
|
+
| `@object-ui/layout` | Shell β Header, Sidebar, AppShell |
|
|
19
|
+
| `@object-ui/react` | Runtime β `SchemaRenderer`, `useRenderer` |
|
|
20
|
+
| `@object-ui/plugin-*` | Plugins β Grid, Kanban, Charts, Gantt, Mapβ¦ |
|
|
21
|
+
| `@object-ui/data-*` | Data Adapters β REST, ObjectQL, ObjectStack |
|
|
22
|
+
|
|
23
|
+
## π― How It Works
|
|
24
|
+
|
|
25
|
+
Everything is driven by **JSON schemas**. A UI tree is a recursive structure of `UIComponent` nodes:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"type": "page",
|
|
30
|
+
"children": [
|
|
31
|
+
{
|
|
32
|
+
"type": "grid",
|
|
33
|
+
"props": { "cols": 3, "gap": 4 },
|
|
34
|
+
"children": [
|
|
35
|
+
{ "type": "metric", "label": "Revenue", "value": "$45,231" },
|
|
36
|
+
{ "type": "metric", "label": "Users", "value": "2,350" },
|
|
37
|
+
{ "type": "metric", "label": "Growth", "value": "12.5%" }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The `SchemaRenderer` recursively walks this tree and resolves each `type` to a registered React component.
|
|
45
|
+
|
|
46
|
+
## π Storybook Guide
|
|
47
|
+
|
|
48
|
+
This Storybook is organized by capability:
|
|
49
|
+
|
|
50
|
+
- **Getting Started** β Introduction and data binding guides.
|
|
51
|
+
- **Primitives** β Atomic Shadcn UI wrappers driven by JSON (Button, Card, Input, Dialogβ¦).
|
|
52
|
+
- **Fields** β All 47+ field widget renderers (text, number, select, date, lookupβ¦).
|
|
53
|
+
- **Plugins** β Complex views powered by specialized libraries (Grid, Kanban, Gantt, Charts, Mapβ¦).
|
|
54
|
+
- **Templates** β Composed page-level layouts (Dashboard, Page, Reports, Sidebar).
|
|
55
|
+
- **Apps** β Full application demos (CRM) using all of the above.
|
|
56
|
+
|
|
57
|
+
## π Links
|
|
58
|
+
|
|
59
|
+
- [GitHub Repository](https://github.com/objectstack-ai/objectui)
|
|
60
|
+
- [ObjectStack Spec](https://github.com/objectstack-ai/spec)
|
|
61
|
+
- [Shadcn UI](https://ui.shadcn.com/)
|