@object-ui/components 0.3.1 → 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.
Files changed (326) hide show
  1. package/.turbo/turbo-build.log +34 -0
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +13 -0
  4. package/dist/index.css +1 -1
  5. package/dist/index.js +36430 -25529
  6. package/dist/index.umd.cjs +53 -32
  7. package/dist/src/SchemaRenderer.d.ts +3 -0
  8. package/dist/src/custom/action-param-dialog.d.ts +21 -0
  9. package/dist/src/{ui → custom}/button-group.d.ts +1 -1
  10. package/dist/src/custom/field.d.ts +19 -0
  11. package/dist/src/custom/index.d.ts +14 -0
  12. package/dist/src/custom/input-group.d.ts +14 -0
  13. package/dist/src/{ui → custom}/item.d.ts +1 -1
  14. package/dist/src/custom/native-select.d.ts +12 -0
  15. package/dist/src/custom/navigation-overlay.d.ts +50 -0
  16. package/dist/src/custom/sort-builder.d.ts +22 -0
  17. package/dist/src/index.d.ts +2 -0
  18. package/dist/src/renderers/action/action-button.d.ts +11 -0
  19. package/dist/src/renderers/action/action-group.d.ts +25 -0
  20. package/dist/src/renderers/action/action-icon.d.ts +10 -0
  21. package/dist/src/renderers/action/action-menu.d.ts +19 -0
  22. package/dist/src/renderers/action/index.d.ts +0 -0
  23. package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
  24. package/dist/src/renderers/data-display/table.d.ts +1 -1
  25. package/dist/src/renderers/layout/page.d.ts +1 -1
  26. package/dist/src/renderers/placeholders.d.ts +1 -1
  27. package/dist/src/ui/accordion.d.ts +4 -4
  28. package/dist/src/ui/alert-dialog.d.ts +17 -11
  29. package/dist/src/ui/alert.d.ts +4 -5
  30. package/dist/src/ui/aspect-ratio.d.ts +1 -1
  31. package/dist/src/ui/avatar.d.ts +3 -3
  32. package/dist/src/ui/badge.d.ts +3 -3
  33. package/dist/src/ui/breadcrumb.d.ts +16 -8
  34. package/dist/src/ui/calendar.d.ts +7 -7
  35. package/dist/src/ui/card.d.ts +7 -8
  36. package/dist/src/ui/carousel.d.ts +5 -6
  37. package/dist/src/ui/chart.d.ts +62 -0
  38. package/dist/src/ui/checkbox.d.ts +1 -1
  39. package/dist/src/ui/collapsible.d.ts +3 -3
  40. package/dist/src/ui/command.d.ts +78 -16
  41. package/dist/src/ui/context-menu.d.ts +14 -12
  42. package/dist/src/ui/dialog.d.ts +17 -13
  43. package/dist/src/ui/drawer.d.ts +19 -10
  44. package/dist/src/ui/dropdown-menu.d.ts +20 -18
  45. package/dist/src/ui/form.d.ts +6 -7
  46. package/dist/src/ui/hover-card.d.ts +3 -3
  47. package/dist/src/ui/index.d.ts +2 -8
  48. package/dist/src/ui/input-otp.d.ts +30 -7
  49. package/dist/src/ui/label.d.ts +2 -1
  50. package/dist/src/ui/menubar.d.ts +19 -17
  51. package/dist/src/ui/navigation-menu.d.ts +9 -11
  52. package/dist/src/ui/pagination.d.ts +25 -10
  53. package/dist/src/ui/popover.d.ts +4 -5
  54. package/dist/src/ui/progress.d.ts +1 -1
  55. package/dist/src/ui/radio-group.d.ts +2 -2
  56. package/dist/src/ui/resizable.d.ts +5 -8
  57. package/dist/src/ui/scroll-area.d.ts +2 -2
  58. package/dist/src/ui/select.d.ts +11 -13
  59. package/dist/src/ui/sheet.d.ts +23 -11
  60. package/dist/src/ui/sidebar.d.ts +27 -29
  61. package/dist/src/ui/skeleton.d.ts +1 -1
  62. package/dist/src/ui/slider.d.ts +1 -1
  63. package/dist/src/ui/sonner.d.ts +2 -1
  64. package/dist/src/ui/switch.d.ts +2 -2
  65. package/dist/src/ui/tabs.d.ts +1 -1
  66. package/dist/src/ui/textarea.d.ts +1 -1
  67. package/dist/src/ui/toast.d.ts +22 -0
  68. package/dist/src/ui/toggle-group.d.ts +8 -3
  69. package/dist/src/ui/toggle.d.ts +4 -1
  70. package/dist/src/ui/tooltip.d.ts +4 -4
  71. package/dist/src/ui/typography.d.ts +21 -0
  72. package/package.json +20 -9
  73. package/shadcn-components.json +52 -47
  74. package/src/SchemaRenderer.tsx +28 -0
  75. package/src/__tests__/PageRendererRegions.test.tsx +668 -0
  76. package/src/__tests__/Registry.test.ts +21 -0
  77. package/src/__tests__/basic-renderers.test.tsx +1 -1
  78. package/src/__tests__/complex-disclosure-renderers.test.tsx +3 -2
  79. package/src/__tests__/compliance.test.tsx +72 -0
  80. package/src/__tests__/feedback-overlay-renderers.test.tsx +1 -1
  81. package/src/__tests__/form-renderers.test.tsx +1 -1
  82. package/src/__tests__/layout-data-renderers.test.tsx +1 -1
  83. package/src/__tests__/navigation-overlay.test.tsx +273 -0
  84. package/src/__tests__/view-compliance.test.tsx +153 -0
  85. package/src/custom/action-param-dialog.tsx +264 -0
  86. package/src/{ui → custom}/button-group.tsx +1 -1
  87. package/src/{ui → custom}/combobox.tsx +3 -3
  88. package/src/{ui → custom}/date-picker.tsx +3 -3
  89. package/src/custom/field.tsx +81 -0
  90. package/src/{ui → custom}/filter-builder.tsx +3 -3
  91. package/src/custom/index.ts +14 -0
  92. package/src/custom/input-group.tsx +53 -0
  93. package/src/{ui → custom}/item.tsx +1 -1
  94. package/src/custom/native-select.tsx +33 -0
  95. package/src/custom/navigation-overlay.tsx +296 -0
  96. package/src/custom/sort-builder.tsx +129 -0
  97. package/src/index.css +20 -1
  98. package/src/index.ts +2 -0
  99. package/src/renderers/action/action-button.tsx +147 -0
  100. package/src/renderers/action/action-group.tsx +270 -0
  101. package/src/renderers/action/action-icon.tsx +150 -0
  102. package/src/renderers/action/action-menu.tsx +203 -0
  103. package/src/renderers/action/index.ts +18 -0
  104. package/src/renderers/action/resolve-icon.ts +35 -0
  105. package/src/renderers/basic/button-group.tsx +1 -0
  106. package/src/renderers/basic/div.tsx +12 -1
  107. package/src/renderers/basic/html.tsx +1 -0
  108. package/src/renderers/basic/icon.tsx +1 -0
  109. package/src/renderers/basic/image.tsx +1 -0
  110. package/src/renderers/basic/navigation-menu.tsx +1 -0
  111. package/src/renderers/basic/pagination.tsx +31 -4
  112. package/src/renderers/basic/separator.tsx +1 -0
  113. package/src/renderers/basic/span.tsx +12 -1
  114. package/src/renderers/basic/text.tsx +4 -2
  115. package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
  116. package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
  117. package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
  118. package/src/renderers/complex/carousel.tsx +1 -0
  119. package/src/renderers/complex/data-table.tsx +355 -95
  120. package/src/renderers/complex/filter-builder.tsx +2 -1
  121. package/src/renderers/complex/resizable.tsx +2 -1
  122. package/src/renderers/complex/scroll-area.tsx +25 -7
  123. package/src/renderers/complex/table.tsx +1 -0
  124. package/src/renderers/data-display/alert.tsx +1 -0
  125. package/src/renderers/data-display/avatar.tsx +1 -0
  126. package/src/renderers/data-display/badge.tsx +1 -0
  127. package/src/renderers/data-display/breadcrumb.tsx +1 -0
  128. package/src/renderers/data-display/kbd.tsx +1 -0
  129. package/src/renderers/data-display/list.tsx +21 -49
  130. package/src/renderers/data-display/statistic.tsx +21 -5
  131. package/src/renderers/data-display/table.tsx +21 -11
  132. package/src/renderers/data-display/tree-view.tsx +7 -1
  133. package/src/renderers/disclosure/accordion.tsx +1 -0
  134. package/src/renderers/disclosure/collapsible.tsx +1 -0
  135. package/src/renderers/disclosure/toggle-group.tsx +2 -0
  136. package/src/renderers/feedback/empty.tsx +1 -0
  137. package/src/renderers/feedback/loading.tsx +2 -1
  138. package/src/renderers/feedback/progress.tsx +1 -0
  139. package/src/renderers/feedback/skeleton.tsx +1 -0
  140. package/src/renderers/feedback/sonner.tsx +1 -0
  141. package/src/renderers/feedback/spinner.tsx +1 -0
  142. package/src/renderers/feedback/toast.tsx +1 -0
  143. package/src/renderers/feedback/toaster.tsx +1 -0
  144. package/src/renderers/form/button.tsx +35 -1
  145. package/src/renderers/form/calendar.tsx +1 -0
  146. package/src/renderers/form/checkbox.tsx +38 -16
  147. package/src/renderers/form/combobox.tsx +2 -1
  148. package/src/renderers/form/command.tsx +1 -0
  149. package/src/renderers/form/date-picker.tsx +1 -0
  150. package/src/renderers/form/file-upload.tsx +1 -0
  151. package/src/renderers/form/form.tsx +115 -19
  152. package/src/renderers/form/input-otp.tsx +1 -0
  153. package/src/renderers/form/input.tsx +3 -0
  154. package/src/renderers/form/label.tsx +1 -0
  155. package/src/renderers/form/radio-group.tsx +1 -0
  156. package/src/renderers/form/select.tsx +35 -15
  157. package/src/renderers/form/slider.tsx +1 -0
  158. package/src/renderers/form/switch.tsx +1 -0
  159. package/src/renderers/form/textarea.tsx +50 -27
  160. package/src/renderers/form/toggle.tsx +3 -45
  161. package/src/renderers/index.ts +1 -0
  162. package/src/renderers/layout/aspect-ratio.tsx +2 -1
  163. package/src/renderers/layout/card.tsx +10 -2
  164. package/src/renderers/layout/container.tsx +1 -0
  165. package/src/renderers/layout/flex.tsx +1 -0
  166. package/src/renderers/layout/grid.tsx +23 -8
  167. package/src/renderers/layout/page.tsx +433 -57
  168. package/src/renderers/layout/semantic.tsx +1 -0
  169. package/src/renderers/layout/stack.tsx +2 -1
  170. package/src/renderers/layout/tabs.tsx +43 -17
  171. package/src/renderers/navigation/header-bar.tsx +1 -0
  172. package/src/renderers/navigation/sidebar.tsx +11 -0
  173. package/src/renderers/overlay/alert-dialog.tsx +1 -0
  174. package/src/renderers/overlay/context-menu.tsx +1 -0
  175. package/src/renderers/overlay/dialog.tsx +1 -0
  176. package/src/renderers/overlay/drawer.tsx +1 -0
  177. package/src/renderers/overlay/dropdown-menu.tsx +1 -0
  178. package/src/renderers/overlay/hover-card.tsx +1 -0
  179. package/src/renderers/overlay/menubar.tsx +1 -0
  180. package/src/renderers/overlay/popover.tsx +1 -0
  181. package/src/renderers/overlay/sheet.tsx +1 -0
  182. package/src/renderers/overlay/tooltip.tsx +1 -0
  183. package/src/renderers/placeholders.tsx +4 -4
  184. package/src/stories/CRMApp.stories.tsx +706 -0
  185. package/src/stories/Guide.mdx +55 -0
  186. package/src/stories/Introduction.mdx +61 -0
  187. package/src/stories/MockedData.stories.tsx +121 -0
  188. package/src/stories/assets/accessibility.png +0 -0
  189. package/src/stories/assets/accessibility.svg +1 -0
  190. package/src/stories/assets/addon-library.png +0 -0
  191. package/src/stories/assets/assets.png +0 -0
  192. package/src/stories/assets/avif-test-image.avif +0 -0
  193. package/src/stories/assets/context.png +0 -0
  194. package/src/stories/assets/discord.svg +1 -0
  195. package/src/stories/assets/docs.png +0 -0
  196. package/src/stories/assets/figma-plugin.png +0 -0
  197. package/src/stories/assets/github.svg +1 -0
  198. package/src/stories/assets/share.png +0 -0
  199. package/src/stories/assets/styling.png +0 -0
  200. package/src/stories/assets/testing.png +0 -0
  201. package/src/stories/assets/theming.png +0 -0
  202. package/src/stories/assets/tutorials.svg +1 -0
  203. package/src/stories/assets/youtube.svg +1 -0
  204. package/src/stories/button.css +30 -0
  205. package/src/stories/header.css +32 -0
  206. package/src/stories/page.css +68 -0
  207. package/src/stories-json/accordion.stories.tsx +43 -0
  208. package/src/stories-json/aggrid.stories.tsx +103 -0
  209. package/src/stories-json/alert.stories.tsx +39 -0
  210. package/src/stories-json/aspect-ratio.stories.tsx +34 -0
  211. package/src/stories-json/avatar.stories.tsx +38 -0
  212. package/src/stories-json/badge.stories.tsx +53 -0
  213. package/src/stories-json/breadcrumb.stories.tsx +30 -0
  214. package/src/stories-json/button-group.stories.tsx +43 -0
  215. package/src/stories-json/button.stories.tsx +73 -0
  216. package/src/stories-json/calendar.stories.tsx +85 -0
  217. package/src/stories-json/card.stories.tsx +48 -0
  218. package/src/stories-json/carousel.stories.tsx +33 -0
  219. package/src/stories-json/charts.stories.tsx +195 -0
  220. package/src/stories-json/chatbot.stories.tsx +248 -0
  221. package/src/stories-json/code-editor.stories.tsx +92 -0
  222. package/src/stories-json/collapsible.stories.tsx +40 -0
  223. package/src/stories-json/controls.stories.tsx +36 -0
  224. package/src/stories-json/crm-live-data.stories.tsx +154 -0
  225. package/src/stories-json/dashboard.stories.tsx +318 -0
  226. package/src/stories-json/data-table.stories.tsx +136 -0
  227. package/src/stories-json/data_display_extras.stories.tsx +102 -0
  228. package/src/stories-json/date-picker.stories.tsx +28 -0
  229. package/src/stories-json/detail-view.stories.tsx +258 -0
  230. package/src/stories-json/dialog.stories.tsx +43 -0
  231. package/src/stories-json/feedback_extras.stories.tsx +40 -0
  232. package/src/stories-json/feedback_others.stories.tsx +46 -0
  233. package/src/stories-json/form-variants.stories.tsx +210 -0
  234. package/src/stories-json/form_advanced.stories.tsx +117 -0
  235. package/src/stories-json/form_extras.stories.tsx +123 -0
  236. package/src/stories-json/grid.stories.tsx +56 -0
  237. package/src/stories-json/icon.stories.tsx +36 -0
  238. package/src/stories-json/input.stories.tsx +52 -0
  239. package/src/stories-json/kanban.stories.tsx +295 -0
  240. package/src/stories-json/layout_extended.stories.tsx +76 -0
  241. package/src/stories-json/layout_flex.stories.tsx +107 -0
  242. package/src/stories-json/list-view.stories.tsx +97 -0
  243. package/src/stories-json/markdown.stories.tsx +129 -0
  244. package/src/stories-json/menus.stories.tsx +63 -0
  245. package/src/stories-json/metric-card.stories.tsx +143 -0
  246. package/src/stories-json/navigation-menu.stories.tsx +37 -0
  247. package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
  248. package/src/stories-json/object-aggrid.stories.tsx +252 -0
  249. package/src/stories-json/object-form.stories.tsx +130 -0
  250. package/src/stories-json/object-gantt.stories.tsx +114 -0
  251. package/src/stories-json/object-grid.stories.tsx +315 -0
  252. package/src/stories-json/object-map.stories.tsx +116 -0
  253. package/src/stories-json/object-view.stories.tsx +118 -0
  254. package/src/stories-json/overlay_extras.stories.tsx +113 -0
  255. package/src/stories-json/overlay_others.stories.tsx +76 -0
  256. package/src/stories-json/page.stories.tsx +55 -0
  257. package/src/stories-json/reports.stories.tsx +163 -0
  258. package/src/stories-json/resizable.stories.tsx +44 -0
  259. package/src/stories-json/select.stories.tsx +34 -0
  260. package/src/stories-json/separator.stories.tsx +41 -0
  261. package/src/stories-json/sidebar.stories.tsx +147 -0
  262. package/src/stories-json/statistic.stories.tsx +44 -0
  263. package/src/stories-json/tabs.stories.tsx +51 -0
  264. package/src/stories-json/timeline.stories.tsx +188 -0
  265. package/src/stories-json/typography.stories.tsx +45 -0
  266. package/src/ui/accordion.tsx +47 -53
  267. package/src/ui/alert-dialog.tsx +103 -117
  268. package/src/ui/alert.tsx +35 -36
  269. package/src/ui/aspect-ratio.tsx +1 -5
  270. package/src/ui/avatar.tsx +41 -42
  271. package/src/ui/badge.tsx +6 -15
  272. package/src/ui/breadcrumb.tsx +81 -75
  273. package/src/ui/button.tsx +10 -11
  274. package/src/ui/calendar.tsx +178 -51
  275. package/src/ui/card.tsx +51 -110
  276. package/src/ui/carousel.tsx +136 -113
  277. package/src/ui/chart.tsx +367 -0
  278. package/src/ui/checkbox.tsx +20 -22
  279. package/src/ui/collapsible.tsx +5 -25
  280. package/src/ui/command.tsx +106 -135
  281. package/src/ui/context-menu.tsx +69 -116
  282. package/src/ui/dialog.tsx +94 -113
  283. package/src/ui/drawer.tsx +82 -99
  284. package/src/ui/dropdown-menu.tsx +134 -188
  285. package/src/ui/form.tsx +51 -40
  286. package/src/ui/hover-card.tsx +18 -33
  287. package/src/ui/index.ts +2 -8
  288. package/src/ui/input-otp.tsx +42 -52
  289. package/src/ui/input.tsx +13 -15
  290. package/src/ui/label.tsx +17 -15
  291. package/src/ui/menubar.tsx +188 -206
  292. package/src/ui/navigation-menu.tsx +96 -136
  293. package/src/ui/pagination.tsx +86 -96
  294. package/src/ui/popover.tsx +24 -41
  295. package/src/ui/progress.tsx +21 -22
  296. package/src/ui/radio-group.tsx +19 -20
  297. package/src/ui/resizable.tsx +32 -42
  298. package/src/ui/scroll-area.tsx +38 -48
  299. package/src/ui/select.tsx +129 -157
  300. package/src/ui/separator.tsx +2 -2
  301. package/src/ui/sheet.tsx +110 -107
  302. package/src/ui/sidebar.tsx +442 -408
  303. package/src/ui/skeleton.tsx +6 -11
  304. package/src/ui/slider.tsx +19 -54
  305. package/src/ui/sonner.tsx +19 -1
  306. package/src/ui/switch.tsx +19 -21
  307. package/src/ui/tabs.tsx +6 -37
  308. package/src/ui/textarea.tsx +8 -4
  309. package/src/ui/toast.tsx +137 -0
  310. package/src/ui/toggle-group.tsx +28 -37
  311. package/src/ui/toggle.tsx +19 -19
  312. package/src/ui/tooltip.tsx +21 -52
  313. package/src/ui/typography.tsx +85 -0
  314. package/tsconfig.json +1 -1
  315. package/vite.config.ts +9 -1
  316. package/vitest.config.ts +5 -0
  317. package/ISSUES_FOUND.md +0 -128
  318. /package/dist/src/{ui → custom}/combobox.d.ts +0 -0
  319. /package/dist/src/{ui → custom}/date-picker.d.ts +0 -0
  320. /package/dist/src/{ui → custom}/empty.d.ts +0 -0
  321. /package/dist/src/{ui → custom}/filter-builder.d.ts +0 -0
  322. /package/dist/src/{ui → custom}/kbd.d.ts +0 -0
  323. /package/dist/src/{ui → custom}/spinner.d.ts +0 -0
  324. /package/src/{ui → custom}/empty.tsx +0 -0
  325. /package/src/{ui → custom}/kbd.tsx +0 -0
  326. /package/src/{ui → custom}/spinner.tsx +0 -0
@@ -50,13 +50,27 @@ const GAPS: Record<number, string> = {
50
50
  ComponentRegistry.register('grid',
51
51
  ({ schema, className, ...props }: { schema: GridSchema & { smColumns?: number, mdColumns?: number, lgColumns?: number, xlColumns?: number }; className?: string; [key: string]: any }) => {
52
52
  // Determine columns configuration
53
- // Supports direct number or responsive object logic if schema allows,
54
- // but here we primarily handle the flat properties supported by the designer inputs
55
- const baseCols = typeof schema.columns === 'number' ? schema.columns : 2;
56
- const smCols = schema.smColumns;
57
- const mdCols = schema.mdColumns;
58
- const lgCols = schema.lgColumns;
59
- const xlCols = schema.xlColumns;
53
+ // Supports detailed object configuration from schema
54
+ let baseCols = 2;
55
+ let smCols, mdCols, lgCols, xlCols;
56
+
57
+ if (typeof schema.columns === 'number') {
58
+ baseCols = schema.columns;
59
+ } else if (typeof schema.columns === 'object' && schema.columns !== null) {
60
+ // Handle responsive object: { xs: 1, sm: 2, md: 3, lg: 4 }
61
+ // Note: 'xs' corresponds to base (mobile-first)
62
+ baseCols = schema.columns.xs ?? 1;
63
+ smCols = schema.columns.sm;
64
+ mdCols = schema.columns.md;
65
+ lgCols = schema.columns.lg;
66
+ xlCols = schema.columns.xl;
67
+ }
68
+
69
+ // Fallback to legacy flat props if provided (from designer)
70
+ if (schema.smColumns) smCols = schema.smColumns;
71
+ if (schema.mdColumns) mdCols = schema.mdColumns;
72
+ if (schema.lgColumns) lgCols = schema.lgColumns;
73
+ if (schema.xlColumns) xlCols = schema.xlColumns;
60
74
 
61
75
  const gap = schema.gap ?? 4;
62
76
 
@@ -71,7 +85,7 @@ ComponentRegistry.register('grid',
71
85
  lgCols && GRID_COLS_LG[lgCols],
72
86
  xlCols && GRID_COLS_XL[xlCols],
73
87
  // Gap
74
- GAPS[gap] || 'gap-4',
88
+ GAPS[gap] || `gap-[${gap * 0.25}rem]`, // Fallback for arbitrary values if not in map
75
89
  className
76
90
  );
77
91
 
@@ -97,6 +111,7 @@ ComponentRegistry.register('grid',
97
111
  );
98
112
  },
99
113
  {
114
+ namespace: 'ui',
100
115
  label: 'Grid Layout',
101
116
  inputs: [
102
117
  {
@@ -1,44 +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'; // Keep internal import for utils
14
-
15
- export const PageRenderer: React.FC<{ schema: PageSchema; className?: string; [key: string]: any }> = ({
16
- schema,
17
- className,
18
- ...props
19
- }) => {
20
- // Support both body (legacy/playground) and children
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 }) => {
21
169
  const content = schema.body || schema.children;
22
- const nodes = Array.isArray(content) ? content : (content ? [content] : []);
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 }) => {
310
+ if (schema.regions && schema.regions.length > 0) {
311
+ return <RegionLayout regions={schema.regions} pageType="record" />;
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';
23
350
 
24
351
  // Extract designer-related props
25
- const {
26
- 'data-obj-id': dataObjId,
27
- 'data-obj-type': dataObjType,
28
- style,
29
- ...pageProps
352
+ const {
353
+ 'data-obj-id': dataObjId,
354
+ 'data-obj-type': dataObjType,
355
+ style,
356
+ ...pageProps
30
357
  } = props;
31
358
 
32
- return (
33
- <div
34
- className={cn("min-h-full w-full bg-background p-4 md:p-6 lg:p-8", className)}
35
- {...pageProps}
36
- // Apply designer props
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}
37
387
  data-obj-id={dataObjId}
38
388
  data-obj-type={dataObjType}
39
389
  style={style}
390
+ {...pageProps}
40
391
  >
41
- <div className="mx-auto max-w-7xl space-y-8">
392
+ <div className={cn('mx-auto space-y-8', getPageMaxWidth(pageType))}>
393
+ {/* Page header */}
42
394
  {(schema.title || schema.description) && (
43
395
  <div className="space-y-2">
44
396
  {schema.title && (
@@ -47,44 +399,68 @@ export const PageRenderer: React.FC<{ schema: PageSchema; className?: string; [k
47
399
  </h1>
48
400
  )}
49
401
  {schema.description && (
50
- <p className="text-muted-foreground">
51
- {schema.description}
52
- </p>
402
+ <p className="text-muted-foreground">{schema.description}</p>
53
403
  )}
54
404
  </div>
55
405
  )}
56
-
57
- <div className="space-y-6">
58
- {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
59
- {nodes.map((node: any, index: number) => (
60
- <SchemaRenderer
61
- key={node?.id || index}
62
- schema={node}
63
- />
64
- ))}
65
- </div>
406
+
407
+ {/* Page body — type-specific layout */}
408
+ {layoutElement}
66
409
  </div>
67
410
  </div>
68
411
  );
69
- };
70
412
 
71
- ComponentRegistry.register(
72
- 'page',
73
- PageRenderer,
74
- {
75
- label: 'Page',
76
- icon: 'Layout',
77
- category: 'layout',
78
- inputs: [
79
- { name: 'title', type: 'string', label: 'Title' },
80
- { name: 'description', type: 'string', label: 'Description' },
81
- {
82
- name: 'body',
83
- type: 'array',
84
- label: 'Content',
85
- // @ts-expect-error - itemType is experimental/extended metadata
86
- itemType: 'component'
87
- }
88
- ]
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
+ );
89
420
  }
90
- );
421
+
422
+ return pageContent;
423
+ };
424
+
425
+ // ---------------------------------------------------------------------------
426
+ // ComponentRegistry registration
427
+ // ---------------------------------------------------------------------------
428
+
429
+ const pageMeta: any = {
430
+ namespace: 'ui',
431
+ label: 'Page',
432
+ icon: 'Layout',
433
+ category: 'layout',
434
+ inputs: [
435
+ { name: 'title', type: 'string', label: 'Title' },
436
+ { name: 'description', type: 'string', label: 'Description' },
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
+ ],
459
+ };
460
+
461
+ ComponentRegistry.register('page', PageRenderer, pageMeta);
462
+ ComponentRegistry.register('app', PageRenderer, { ...pageMeta, label: 'App Page' });
463
+ ComponentRegistry.register('utility', PageRenderer, { ...pageMeta, label: 'Utility Page' });
464
+ ComponentRegistry.register('home', PageRenderer, { ...pageMeta, label: 'Home Page' });
465
+ ComponentRegistry.register('record', PageRenderer, { ...pageMeta, label: 'Record Page' });
466
+
@@ -38,6 +38,7 @@ tags.forEach(tag => {
38
38
  Component.displayName = `Semantic${tag.charAt(0).toUpperCase() + tag.slice(1)}`;
39
39
 
40
40
  ComponentRegistry.register(tag, Component, {
41
+ namespace: 'ui',
41
42
  label: tag.charAt(0).toUpperCase() + tag.slice(1),
42
43
  category: 'layout',
43
44
  inputs: [
@@ -19,7 +19,7 @@ const StackRenderer = forwardRef<HTMLDivElement, { schema: StackSchema; classNam
19
19
  const direction = schema.direction || 'col';
20
20
  const justify = schema.justify || 'start';
21
21
  const align = schema.align || 'stretch'; // Stack items usually stretch
22
- const gap = schema.gap || 2;
22
+ const gap = schema.gap ?? (schema as any).spacing ?? 2;
23
23
  const wrap = schema.wrap || false;
24
24
 
25
25
  const stackClass = cn(
@@ -82,6 +82,7 @@ const StackRenderer = forwardRef<HTMLDivElement, { schema: StackSchema; classNam
82
82
  ComponentRegistry.register('stack',
83
83
  StackRenderer,
84
84
  {
85
+ namespace: 'ui',
85
86
  label: 'Stack',
86
87
  inputs: [
87
88
  {
@@ -15,39 +15,65 @@ import {
15
15
  TabsTrigger,
16
16
  TabsContent
17
17
  } from '../../ui';
18
+ import { cn } from '../../lib/utils';
19
+ import React from 'react';
18
20
 
19
- ComponentRegistry.register('tabs',
20
- ({ schema, className, ...props }: { schema: TabsSchema; className?: string; [key: string]: any }) => {
21
- // Extract designer-related props
22
- const {
23
- 'data-obj-id': dataObjId,
24
- 'data-obj-type': dataObjType,
25
- style,
26
- ...tabsProps
27
- } = props;
21
+ const TabsRenderer = ({ schema, className, onChange, value, ...props }: { schema: TabsSchema; className?: string; onChange?: (val: string) => void; value?: string; [key: string]: any }) => {
22
+ // Extract designer-related props
23
+ const {
24
+ 'data-obj-id': dataObjId,
25
+ 'data-obj-type': dataObjType,
26
+ style,
27
+ ...tabsProps
28
+ } = props;
28
29
 
29
- return (
30
+ const handleValueChange = (val: string) => {
31
+ if (onChange) {
32
+ onChange(val);
33
+ }
34
+ };
35
+
36
+ const isVertical = schema.orientation === 'vertical';
37
+
38
+ return (
30
39
  <Tabs
31
- defaultValue={schema.defaultValue}
32
- className={className}
40
+ defaultValue={value === undefined ? schema.defaultValue : undefined}
41
+ value={value ?? schema.value}
42
+ onValueChange={handleValueChange}
43
+ orientation={schema.orientation || 'horizontal'}
44
+ className={cn(className, isVertical && "flex gap-2")}
33
45
  {...tabsProps}
34
46
  // Apply designer props
35
47
  {...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
36
48
  >
37
- <TabsList>
49
+ <TabsList className={cn(isVertical && "flex-col h-auto items-stretch bg-muted/50 p-1")}>
38
50
  {schema.items?.map((item) => (
39
- <TabsTrigger key={item.value} value={item.value}>{item.label}</TabsTrigger>
51
+ <TabsTrigger
52
+ key={item.value}
53
+ value={item.value}
54
+ disabled={item.disabled}
55
+ className={cn(isVertical && "justify-start")}
56
+ >
57
+ {item.label}
58
+ </TabsTrigger>
40
59
  ))}
41
60
  </TabsList>
42
61
  {schema.items?.map((item) => (
43
- <TabsContent key={item.value} value={item.value}>
44
- {renderChildren((item as any).body)}
62
+ <TabsContent
63
+ key={item.value}
64
+ value={item.value}
65
+ className={cn("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", isVertical && "mt-0 flex-1")}
66
+ >
67
+ {renderChildren(item.content || (item as any).body)}
45
68
  </TabsContent>
46
69
  ))}
47
70
  </Tabs>
48
71
  );
49
- },
72
+ };
73
+
74
+ ComponentRegistry.register('tabs', TabsRenderer,
50
75
  {
76
+ namespace: 'ui',
51
77
  label: 'Tabs',
52
78
  inputs: [
53
79
  { name: 'defaultValue', type: 'string', label: 'Default Value', required: true },