@aventoapp/framework 0.2.0 → 0.2.1
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/README.md +260 -0
- package/dist/index.js.map +1 -1
- package/dist/native/index.js.map +1 -1
- package/dist/offline/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/workflow/index.js.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +84 -79
- package/schemas/Workflow.json +14 -14
- package/schemas/WorkflowHistory.json +22 -22
- package/schemas/WorkflowInstance.json +16 -16
- package/schemas/WorkflowState.json +18 -18
- package/schemas/WorkflowTransition.json +27 -27
- package/src/index.js +8 -8
- package/src/native/components/NativeAuthProvider.jsx +249 -249
- package/src/native/components/NativeDetail.jsx +270 -270
- package/src/native/components/NativeForm.jsx +543 -543
- package/src/native/components/NativeGrid.jsx +90 -90
- package/src/native/components/NativeJsonGrid.jsx +213 -213
- package/src/native/components/NativeJsonView.jsx +454 -454
- package/src/native/components/NativeJsonViewContext.js +17 -17
- package/src/native/components/NativeShell.jsx +68 -68
- package/src/native/components/NativeViewComponent.jsx +351 -351
- package/src/native/extensions/NativeExtensionRegistry.js +81 -81
- package/src/native/hooks/useNativeStore.js +72 -72
- package/src/native/index.js +15 -15
- package/src/native/layouts/NativeStackLayout.jsx +30 -30
- package/src/native/layouts/NativeTabLayout.jsx +96 -96
- package/src/native/storage.js +13 -13
- package/src/native/stores/NativeBaseStore.js +348 -348
- package/src/native/stores/NativeStoreContext.jsx +53 -53
- package/src/offline/index.js +1 -1
- package/src/server/ai/capabilities-routes.js +106 -106
- package/src/server/ai/index.js +1 -1
- package/src/server/cache/MemoryCache.js +153 -153
- package/src/server/cache/index.js +2 -2
- package/src/server/cache/middleware.js +12 -12
- package/src/server/db/index.js +14 -14
- package/src/server/db/mongo.js +137 -137
- package/src/server/db/postgres.js +144 -144
- package/src/server/index.js +42 -42
- package/src/server/middleware/auth.js +682 -682
- package/src/server/middleware/can-flags.js +132 -132
- package/src/server/middleware/entityRoles.js +105 -105
- package/src/server/middleware/index.js +58 -58
- package/src/server/middleware/permissions.js +240 -240
- package/src/server/middleware/tenant.js +203 -203
- package/src/server/realtime/EventBus.js +45 -45
- package/src/server/realtime/WebSocketServer.js +105 -105
- package/src/server/realtime/index.js +3 -3
- package/src/server/realtime/middleware.js +18 -18
- package/src/server/services/email-templates.js +157 -157
- package/src/server/services/email.js +78 -78
- package/src/server/services/index.js +15 -15
- package/src/server/services/storage.js +119 -119
- package/src/server/utils/index.js +16 -16
- package/src/server/utils/paginate.js +65 -65
- package/src/server/utils/query-builder.js +293 -293
- package/src/server/utils/route-loader.js +61 -61
- package/src/server/workflow/WorkflowEngine.js +494 -494
- package/src/server/workflow/index.js +2 -2
- package/src/server/workflow/workflow-routes.js +174 -174
- package/src/shared/index.js +10 -10
- package/src/shared/utils/field-accessor.js +108 -108
- package/src/shared/utils/index.js +7 -7
- package/src/shared/utils/validation-utils.js +83 -83
- package/src/web/components/AppRouter/AppRouter.jsx +130 -130
- package/src/web/components/AppRouter/index.js +1 -1
- package/src/web/components/AppShell/AppShell.jsx +101 -101
- package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -54
- package/src/web/components/AppShell/ShellConfig.js +53 -53
- package/src/web/components/AppShell/index.js +3 -3
- package/src/web/components/AuthProvider.jsx +426 -426
- package/src/web/components/CardList/CardList.jsx +272 -272
- package/src/web/components/CardList/index.js +2 -2
- package/src/web/components/DetailView/DetailView.jsx +281 -281
- package/src/web/components/DetailView/index.js +2 -2
- package/src/web/components/Form/Form.jsx +300 -300
- package/src/web/components/Form/FormField.jsx +226 -226
- package/src/web/components/Form/index.js +3 -3
- package/src/web/components/Grid/Grid.jsx +304 -304
- package/src/web/components/Grid/index.js +2 -2
- package/src/web/components/IconRegistry/IconRegistry.jsx +127 -127
- package/src/web/components/IconRegistry/index.js +1 -1
- package/src/web/components/JsonView/JsonView.jsx +647 -647
- package/src/web/components/JsonView/ViewComponent.jsx +1045 -1045
- package/src/web/components/JsonView/ViewToolbar.jsx +141 -141
- package/src/web/components/JsonView/index.js +14 -14
- package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -41
- package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -122
- package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -112
- package/src/web/components/JsonView/layouts/index.js +8 -8
- package/src/web/components/Layout.jsx +265 -265
- package/src/web/components/MobileLayout/MobileLayout.jsx +385 -385
- package/src/web/components/MobileLayout/index.js +1 -1
- package/src/web/components/Navigation/Navigation.jsx +248 -248
- package/src/web/components/Navigation/index.js +1 -1
- package/src/web/components/NotificationProvider.jsx +55 -55
- package/src/web/components/Pagination/InfiniteScroll.jsx +82 -82
- package/src/web/components/Pagination/Pagination.jsx +73 -73
- package/src/web/components/Pagination/index.js +8 -8
- package/src/web/components/SimpleList/SimpleList.jsx +177 -177
- package/src/web/components/SimpleList/index.js +2 -2
- package/src/web/components/TenantProvider.jsx +121 -121
- package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -71
- package/src/web/components/WorkflowActions/index.js +1 -1
- package/src/web/components/WorkflowField/WorkflowField.jsx +176 -176
- package/src/web/components/WorkflowField/index.js +2 -2
- package/src/web/components/WorkflowField/workflowColors.js +32 -32
- package/src/web/components/auth/DevTenantSelector.jsx +90 -90
- package/src/web/components/auth/ForgotPasswordForm.jsx +94 -94
- package/src/web/components/auth/RegisterForm.jsx +168 -168
- package/src/web/components/auth/ResetPasswordForm.jsx +121 -121
- package/src/web/components/auth/VerifyEmailView.jsx +85 -85
- package/src/web/components/auth/index.js +5 -5
- package/src/web/components/index.js +39 -39
- package/src/web/components/layouts/CardListLayout.jsx +68 -68
- package/src/web/components/layouts/FullscreenLayout.jsx +30 -30
- package/src/web/components/layouts/MobileStackLayout.jsx +28 -28
- package/src/web/components/layouts/WizardLayout.jsx +86 -86
- package/src/web/components/layouts/index.js +4 -4
- package/src/web/components/mobile/Badge.jsx +105 -105
- package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -104
- package/src/web/components/mobile/EmptyState.jsx +30 -30
- package/src/web/components/mobile/QuickActionButton.jsx +77 -77
- package/src/web/components/mobile/ServerAutocomplete.jsx +123 -123
- package/src/web/components/mobile/StarRating.jsx +42 -42
- package/src/web/components/mobile/StatCard.jsx +65 -65
- package/src/web/components/mobile/index.js +7 -7
- package/src/web/extensions/ExtensionRegistry.js +79 -79
- package/src/web/extensions/index.js +7 -7
- package/src/web/hooks/index.js +15 -15
- package/src/web/hooks/useApi.js +76 -76
- package/src/web/hooks/useAuth.js +37 -37
- package/src/web/hooks/useDebouncedSave.js +158 -158
- package/src/web/hooks/useIsMobile.js +14 -14
- package/src/web/hooks/useOfflineQueue.js +99 -99
- package/src/web/hooks/useSelectionModel.js +143 -143
- package/src/web/hooks/useServerAutocomplete.js +146 -146
- package/src/web/hooks/useStore.js +107 -107
- package/src/web/hooks/useSubscription.js +130 -130
- package/src/web/hooks/useTenant.js +39 -39
- package/src/web/hooks/useTenantResolver.js +65 -65
- package/src/web/hooks/useUndoRedo.js +77 -77
- package/src/web/hooks/useViews.js +113 -113
- package/src/web/hooks/useWorkflow.js +190 -190
- package/src/web/index.js +117 -117
- package/src/web/stores/BaseStore.js +439 -439
- package/src/web/stores/StoreContext.jsx +93 -93
- package/src/web/stores/index.js +3 -3
- package/src/web/theme/index.js +3 -3
- package/src/web/theme/mui-theme.js +228 -228
- package/src/web/utils/formatTimeAgo.js +22 -22
- package/src/web/utils/index.js +1 -1
- package/src/web/views/ViewRegistry.js +235 -235
- package/src/web/views/index.js +2 -2
|
@@ -1,265 +1,265 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layout Component
|
|
3
|
-
*
|
|
4
|
-
* Main application layout with AppBar, collapsible Drawer navigation,
|
|
5
|
-
* and main content area.
|
|
6
|
-
*/
|
|
7
|
-
import React, { useState, useCallback } from 'react';
|
|
8
|
-
import {
|
|
9
|
-
AppBar,
|
|
10
|
-
Box,
|
|
11
|
-
Drawer,
|
|
12
|
-
IconButton,
|
|
13
|
-
List,
|
|
14
|
-
ListItem,
|
|
15
|
-
ListItemButton,
|
|
16
|
-
ListItemIcon,
|
|
17
|
-
ListItemText,
|
|
18
|
-
Toolbar,
|
|
19
|
-
Typography,
|
|
20
|
-
Divider,
|
|
21
|
-
useTheme,
|
|
22
|
-
useMediaQuery
|
|
23
|
-
} from '@mui/material';
|
|
24
|
-
import MenuIcon from '@mui/icons-material/Menu';
|
|
25
|
-
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Default drawer width
|
|
29
|
-
*/
|
|
30
|
-
const DRAWER_WIDTH = 240;
|
|
31
|
-
const DRAWER_WIDTH_COLLAPSED = 64;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* App Layout Component
|
|
35
|
-
*
|
|
36
|
-
* @param {Object} props
|
|
37
|
-
* @param {React.ReactNode} props.children - Main content
|
|
38
|
-
* @param {string} props.title - App title shown in AppBar
|
|
39
|
-
* @param {Array} props.navItems - Navigation items [{icon, label, path, onClick}]
|
|
40
|
-
* @param {React.ReactNode} props.logo - Optional logo component
|
|
41
|
-
* @param {React.ReactNode} props.headerActions - Actions to show in AppBar (right side)
|
|
42
|
-
* @param {React.ReactNode} props.userMenu - User menu component (avatar, dropdown)
|
|
43
|
-
* @param {string} props.activePath - Currently active navigation path
|
|
44
|
-
* @param {Function} props.onNavigate - Callback when nav item clicked
|
|
45
|
-
*/
|
|
46
|
-
export function Layout({
|
|
47
|
-
children,
|
|
48
|
-
title = 'Avento App',
|
|
49
|
-
navItems = [],
|
|
50
|
-
logo,
|
|
51
|
-
headerActions,
|
|
52
|
-
userMenu,
|
|
53
|
-
activePath,
|
|
54
|
-
onNavigate
|
|
55
|
-
}) {
|
|
56
|
-
const theme = useTheme();
|
|
57
|
-
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
58
|
-
const [drawerOpen, setDrawerOpen] = useState(!isMobile);
|
|
59
|
-
const [mobileOpen, setMobileOpen] = useState(false);
|
|
60
|
-
|
|
61
|
-
const handleDrawerToggle = useCallback(() => {
|
|
62
|
-
if (isMobile) {
|
|
63
|
-
setMobileOpen(prev => !prev);
|
|
64
|
-
} else {
|
|
65
|
-
setDrawerOpen(prev => !prev);
|
|
66
|
-
}
|
|
67
|
-
}, [isMobile]);
|
|
68
|
-
|
|
69
|
-
const handleNavClick = useCallback((item) => {
|
|
70
|
-
if (item.onClick) {
|
|
71
|
-
item.onClick(item);
|
|
72
|
-
}
|
|
73
|
-
if (onNavigate) {
|
|
74
|
-
onNavigate(item.path, item);
|
|
75
|
-
}
|
|
76
|
-
if (isMobile) {
|
|
77
|
-
setMobileOpen(false);
|
|
78
|
-
}
|
|
79
|
-
}, [onNavigate, isMobile]);
|
|
80
|
-
|
|
81
|
-
const drawerWidth = drawerOpen ? DRAWER_WIDTH : DRAWER_WIDTH_COLLAPSED;
|
|
82
|
-
|
|
83
|
-
const drawerContent = (
|
|
84
|
-
<Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
|
85
|
-
{/* Drawer Header */}
|
|
86
|
-
<Toolbar
|
|
87
|
-
sx={{
|
|
88
|
-
display: 'flex',
|
|
89
|
-
alignItems: 'center',
|
|
90
|
-
justifyContent: drawerOpen ? 'space-between' : 'center',
|
|
91
|
-
px: drawerOpen ? 2 : 1
|
|
92
|
-
}}
|
|
93
|
-
>
|
|
94
|
-
{drawerOpen && (
|
|
95
|
-
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
96
|
-
{logo}
|
|
97
|
-
{!logo && (
|
|
98
|
-
<Typography variant="h6" noWrap>
|
|
99
|
-
{title}
|
|
100
|
-
</Typography>
|
|
101
|
-
)}
|
|
102
|
-
</Box>
|
|
103
|
-
)}
|
|
104
|
-
{!isMobile && (
|
|
105
|
-
<IconButton onClick={handleDrawerToggle} size="small">
|
|
106
|
-
<ChevronLeftIcon
|
|
107
|
-
sx={{
|
|
108
|
-
transform: drawerOpen ? 'rotate(0deg)' : 'rotate(180deg)',
|
|
109
|
-
transition: theme.transitions.create('transform')
|
|
110
|
-
}}
|
|
111
|
-
/>
|
|
112
|
-
</IconButton>
|
|
113
|
-
)}
|
|
114
|
-
</Toolbar>
|
|
115
|
-
|
|
116
|
-
<Divider />
|
|
117
|
-
|
|
118
|
-
{/* Navigation Items */}
|
|
119
|
-
<List sx={{ flex: 1, pt: 1 }}>
|
|
120
|
-
{navItems.map((item, index) => (
|
|
121
|
-
<ListItem key={item.path || index} disablePadding sx={{ display: 'block' }}>
|
|
122
|
-
<ListItemButton
|
|
123
|
-
selected={activePath === item.path}
|
|
124
|
-
onClick={() => handleNavClick(item)}
|
|
125
|
-
sx={{
|
|
126
|
-
minHeight: 48,
|
|
127
|
-
justifyContent: drawerOpen ? 'initial' : 'center',
|
|
128
|
-
px: 2.5,
|
|
129
|
-
'&.Mui-selected': {
|
|
130
|
-
backgroundColor: theme.palette.primary.main + '14',
|
|
131
|
-
borderRight: `3px solid ${theme.palette.primary.main}`,
|
|
132
|
-
'&:hover': {
|
|
133
|
-
backgroundColor: theme.palette.primary.main + '20'
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}}
|
|
137
|
-
>
|
|
138
|
-
{item.icon && (
|
|
139
|
-
<ListItemIcon
|
|
140
|
-
sx={{
|
|
141
|
-
minWidth: 0,
|
|
142
|
-
mr: drawerOpen ? 2 : 'auto',
|
|
143
|
-
justifyContent: 'center',
|
|
144
|
-
color: activePath === item.path ? theme.palette.primary.main : 'inherit'
|
|
145
|
-
}}
|
|
146
|
-
>
|
|
147
|
-
{item.icon}
|
|
148
|
-
</ListItemIcon>
|
|
149
|
-
)}
|
|
150
|
-
{drawerOpen && (
|
|
151
|
-
<ListItemText
|
|
152
|
-
primary={item.label}
|
|
153
|
-
primaryTypographyProps={{
|
|
154
|
-
fontWeight: activePath === item.path ? 600 : 400
|
|
155
|
-
}}
|
|
156
|
-
/>
|
|
157
|
-
)}
|
|
158
|
-
</ListItemButton>
|
|
159
|
-
</ListItem>
|
|
160
|
-
))}
|
|
161
|
-
</List>
|
|
162
|
-
</Box>
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<Box sx={{ display: 'flex', minHeight: '100vh' }}>
|
|
167
|
-
{/* AppBar */}
|
|
168
|
-
<AppBar
|
|
169
|
-
position="fixed"
|
|
170
|
-
sx={{
|
|
171
|
-
width: { md: `calc(100% - ${drawerWidth}px)` },
|
|
172
|
-
ml: { md: `${drawerWidth}px` },
|
|
173
|
-
transition: theme.transitions.create(['width', 'margin'], {
|
|
174
|
-
easing: theme.transitions.easing.sharp,
|
|
175
|
-
duration: theme.transitions.duration.leavingScreen
|
|
176
|
-
}),
|
|
177
|
-
backgroundColor: 'background.paper',
|
|
178
|
-
color: 'text.primary'
|
|
179
|
-
}}
|
|
180
|
-
>
|
|
181
|
-
<Toolbar>
|
|
182
|
-
<IconButton
|
|
183
|
-
color="inherit"
|
|
184
|
-
edge="start"
|
|
185
|
-
onClick={handleDrawerToggle}
|
|
186
|
-
sx={{ mr: 2, display: { md: 'none' } }}
|
|
187
|
-
>
|
|
188
|
-
<MenuIcon />
|
|
189
|
-
</IconButton>
|
|
190
|
-
|
|
191
|
-
<Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}>
|
|
192
|
-
{title}
|
|
193
|
-
</Typography>
|
|
194
|
-
|
|
195
|
-
{headerActions && (
|
|
196
|
-
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mr: 2 }}>
|
|
197
|
-
{headerActions}
|
|
198
|
-
</Box>
|
|
199
|
-
)}
|
|
200
|
-
|
|
201
|
-
{userMenu}
|
|
202
|
-
</Toolbar>
|
|
203
|
-
</AppBar>
|
|
204
|
-
|
|
205
|
-
{/* Mobile Drawer */}
|
|
206
|
-
<Drawer
|
|
207
|
-
variant="temporary"
|
|
208
|
-
open={mobileOpen}
|
|
209
|
-
onClose={handleDrawerToggle}
|
|
210
|
-
ModalProps={{ keepMounted: true }}
|
|
211
|
-
sx={{
|
|
212
|
-
display: { xs: 'block', md: 'none' },
|
|
213
|
-
'& .MuiDrawer-paper': {
|
|
214
|
-
boxSizing: 'border-box',
|
|
215
|
-
width: DRAWER_WIDTH
|
|
216
|
-
}
|
|
217
|
-
}}
|
|
218
|
-
>
|
|
219
|
-
{drawerContent}
|
|
220
|
-
</Drawer>
|
|
221
|
-
|
|
222
|
-
{/* Desktop Drawer */}
|
|
223
|
-
<Drawer
|
|
224
|
-
variant="permanent"
|
|
225
|
-
sx={{
|
|
226
|
-
display: { xs: 'none', md: 'block' },
|
|
227
|
-
'& .MuiDrawer-paper': {
|
|
228
|
-
boxSizing: 'border-box',
|
|
229
|
-
width: drawerWidth,
|
|
230
|
-
transition: theme.transitions.create('width', {
|
|
231
|
-
easing: theme.transitions.easing.sharp,
|
|
232
|
-
duration: theme.transitions.duration.enteringScreen
|
|
233
|
-
}),
|
|
234
|
-
overflowX: 'hidden'
|
|
235
|
-
}
|
|
236
|
-
}}
|
|
237
|
-
open
|
|
238
|
-
>
|
|
239
|
-
{drawerContent}
|
|
240
|
-
</Drawer>
|
|
241
|
-
|
|
242
|
-
{/* Main Content */}
|
|
243
|
-
<Box
|
|
244
|
-
component="main"
|
|
245
|
-
sx={{
|
|
246
|
-
flexGrow: 1,
|
|
247
|
-
p: 3,
|
|
248
|
-
ml: { md: `${drawerWidth}px` },
|
|
249
|
-
width: { xs: '100%', md: `calc(100% - ${drawerWidth}px)` },
|
|
250
|
-
minHeight: '100vh',
|
|
251
|
-
backgroundColor: 'background.default',
|
|
252
|
-
transition: theme.transitions.create(['width', 'margin'], {
|
|
253
|
-
easing: theme.transitions.easing.sharp,
|
|
254
|
-
duration: theme.transitions.duration.leavingScreen
|
|
255
|
-
})
|
|
256
|
-
}}
|
|
257
|
-
>
|
|
258
|
-
<Toolbar /> {/* Spacer for AppBar */}
|
|
259
|
-
{children}
|
|
260
|
-
</Box>
|
|
261
|
-
</Box>
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export default Layout;
|
|
1
|
+
/**
|
|
2
|
+
* Layout Component
|
|
3
|
+
*
|
|
4
|
+
* Main application layout with AppBar, collapsible Drawer navigation,
|
|
5
|
+
* and main content area.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useState, useCallback } from 'react';
|
|
8
|
+
import {
|
|
9
|
+
AppBar,
|
|
10
|
+
Box,
|
|
11
|
+
Drawer,
|
|
12
|
+
IconButton,
|
|
13
|
+
List,
|
|
14
|
+
ListItem,
|
|
15
|
+
ListItemButton,
|
|
16
|
+
ListItemIcon,
|
|
17
|
+
ListItemText,
|
|
18
|
+
Toolbar,
|
|
19
|
+
Typography,
|
|
20
|
+
Divider,
|
|
21
|
+
useTheme,
|
|
22
|
+
useMediaQuery
|
|
23
|
+
} from '@mui/material';
|
|
24
|
+
import MenuIcon from '@mui/icons-material/Menu';
|
|
25
|
+
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Default drawer width
|
|
29
|
+
*/
|
|
30
|
+
const DRAWER_WIDTH = 240;
|
|
31
|
+
const DRAWER_WIDTH_COLLAPSED = 64;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* App Layout Component
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} props
|
|
37
|
+
* @param {React.ReactNode} props.children - Main content
|
|
38
|
+
* @param {string} props.title - App title shown in AppBar
|
|
39
|
+
* @param {Array} props.navItems - Navigation items [{icon, label, path, onClick}]
|
|
40
|
+
* @param {React.ReactNode} props.logo - Optional logo component
|
|
41
|
+
* @param {React.ReactNode} props.headerActions - Actions to show in AppBar (right side)
|
|
42
|
+
* @param {React.ReactNode} props.userMenu - User menu component (avatar, dropdown)
|
|
43
|
+
* @param {string} props.activePath - Currently active navigation path
|
|
44
|
+
* @param {Function} props.onNavigate - Callback when nav item clicked
|
|
45
|
+
*/
|
|
46
|
+
export function Layout({
|
|
47
|
+
children,
|
|
48
|
+
title = 'Avento App',
|
|
49
|
+
navItems = [],
|
|
50
|
+
logo,
|
|
51
|
+
headerActions,
|
|
52
|
+
userMenu,
|
|
53
|
+
activePath,
|
|
54
|
+
onNavigate
|
|
55
|
+
}) {
|
|
56
|
+
const theme = useTheme();
|
|
57
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
58
|
+
const [drawerOpen, setDrawerOpen] = useState(!isMobile);
|
|
59
|
+
const [mobileOpen, setMobileOpen] = useState(false);
|
|
60
|
+
|
|
61
|
+
const handleDrawerToggle = useCallback(() => {
|
|
62
|
+
if (isMobile) {
|
|
63
|
+
setMobileOpen(prev => !prev);
|
|
64
|
+
} else {
|
|
65
|
+
setDrawerOpen(prev => !prev);
|
|
66
|
+
}
|
|
67
|
+
}, [isMobile]);
|
|
68
|
+
|
|
69
|
+
const handleNavClick = useCallback((item) => {
|
|
70
|
+
if (item.onClick) {
|
|
71
|
+
item.onClick(item);
|
|
72
|
+
}
|
|
73
|
+
if (onNavigate) {
|
|
74
|
+
onNavigate(item.path, item);
|
|
75
|
+
}
|
|
76
|
+
if (isMobile) {
|
|
77
|
+
setMobileOpen(false);
|
|
78
|
+
}
|
|
79
|
+
}, [onNavigate, isMobile]);
|
|
80
|
+
|
|
81
|
+
const drawerWidth = drawerOpen ? DRAWER_WIDTH : DRAWER_WIDTH_COLLAPSED;
|
|
82
|
+
|
|
83
|
+
const drawerContent = (
|
|
84
|
+
<Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
|
85
|
+
{/* Drawer Header */}
|
|
86
|
+
<Toolbar
|
|
87
|
+
sx={{
|
|
88
|
+
display: 'flex',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
justifyContent: drawerOpen ? 'space-between' : 'center',
|
|
91
|
+
px: drawerOpen ? 2 : 1
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{drawerOpen && (
|
|
95
|
+
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
96
|
+
{logo}
|
|
97
|
+
{!logo && (
|
|
98
|
+
<Typography variant="h6" noWrap>
|
|
99
|
+
{title}
|
|
100
|
+
</Typography>
|
|
101
|
+
)}
|
|
102
|
+
</Box>
|
|
103
|
+
)}
|
|
104
|
+
{!isMobile && (
|
|
105
|
+
<IconButton onClick={handleDrawerToggle} size="small">
|
|
106
|
+
<ChevronLeftIcon
|
|
107
|
+
sx={{
|
|
108
|
+
transform: drawerOpen ? 'rotate(0deg)' : 'rotate(180deg)',
|
|
109
|
+
transition: theme.transitions.create('transform')
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
</IconButton>
|
|
113
|
+
)}
|
|
114
|
+
</Toolbar>
|
|
115
|
+
|
|
116
|
+
<Divider />
|
|
117
|
+
|
|
118
|
+
{/* Navigation Items */}
|
|
119
|
+
<List sx={{ flex: 1, pt: 1 }}>
|
|
120
|
+
{navItems.map((item, index) => (
|
|
121
|
+
<ListItem key={item.path || index} disablePadding sx={{ display: 'block' }}>
|
|
122
|
+
<ListItemButton
|
|
123
|
+
selected={activePath === item.path}
|
|
124
|
+
onClick={() => handleNavClick(item)}
|
|
125
|
+
sx={{
|
|
126
|
+
minHeight: 48,
|
|
127
|
+
justifyContent: drawerOpen ? 'initial' : 'center',
|
|
128
|
+
px: 2.5,
|
|
129
|
+
'&.Mui-selected': {
|
|
130
|
+
backgroundColor: theme.palette.primary.main + '14',
|
|
131
|
+
borderRight: `3px solid ${theme.palette.primary.main}`,
|
|
132
|
+
'&:hover': {
|
|
133
|
+
backgroundColor: theme.palette.primary.main + '20'
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
{item.icon && (
|
|
139
|
+
<ListItemIcon
|
|
140
|
+
sx={{
|
|
141
|
+
minWidth: 0,
|
|
142
|
+
mr: drawerOpen ? 2 : 'auto',
|
|
143
|
+
justifyContent: 'center',
|
|
144
|
+
color: activePath === item.path ? theme.palette.primary.main : 'inherit'
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{item.icon}
|
|
148
|
+
</ListItemIcon>
|
|
149
|
+
)}
|
|
150
|
+
{drawerOpen && (
|
|
151
|
+
<ListItemText
|
|
152
|
+
primary={item.label}
|
|
153
|
+
primaryTypographyProps={{
|
|
154
|
+
fontWeight: activePath === item.path ? 600 : 400
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
)}
|
|
158
|
+
</ListItemButton>
|
|
159
|
+
</ListItem>
|
|
160
|
+
))}
|
|
161
|
+
</List>
|
|
162
|
+
</Box>
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<Box sx={{ display: 'flex', minHeight: '100vh' }}>
|
|
167
|
+
{/* AppBar */}
|
|
168
|
+
<AppBar
|
|
169
|
+
position="fixed"
|
|
170
|
+
sx={{
|
|
171
|
+
width: { md: `calc(100% - ${drawerWidth}px)` },
|
|
172
|
+
ml: { md: `${drawerWidth}px` },
|
|
173
|
+
transition: theme.transitions.create(['width', 'margin'], {
|
|
174
|
+
easing: theme.transitions.easing.sharp,
|
|
175
|
+
duration: theme.transitions.duration.leavingScreen
|
|
176
|
+
}),
|
|
177
|
+
backgroundColor: 'background.paper',
|
|
178
|
+
color: 'text.primary'
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<Toolbar>
|
|
182
|
+
<IconButton
|
|
183
|
+
color="inherit"
|
|
184
|
+
edge="start"
|
|
185
|
+
onClick={handleDrawerToggle}
|
|
186
|
+
sx={{ mr: 2, display: { md: 'none' } }}
|
|
187
|
+
>
|
|
188
|
+
<MenuIcon />
|
|
189
|
+
</IconButton>
|
|
190
|
+
|
|
191
|
+
<Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}>
|
|
192
|
+
{title}
|
|
193
|
+
</Typography>
|
|
194
|
+
|
|
195
|
+
{headerActions && (
|
|
196
|
+
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mr: 2 }}>
|
|
197
|
+
{headerActions}
|
|
198
|
+
</Box>
|
|
199
|
+
)}
|
|
200
|
+
|
|
201
|
+
{userMenu}
|
|
202
|
+
</Toolbar>
|
|
203
|
+
</AppBar>
|
|
204
|
+
|
|
205
|
+
{/* Mobile Drawer */}
|
|
206
|
+
<Drawer
|
|
207
|
+
variant="temporary"
|
|
208
|
+
open={mobileOpen}
|
|
209
|
+
onClose={handleDrawerToggle}
|
|
210
|
+
ModalProps={{ keepMounted: true }}
|
|
211
|
+
sx={{
|
|
212
|
+
display: { xs: 'block', md: 'none' },
|
|
213
|
+
'& .MuiDrawer-paper': {
|
|
214
|
+
boxSizing: 'border-box',
|
|
215
|
+
width: DRAWER_WIDTH
|
|
216
|
+
}
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{drawerContent}
|
|
220
|
+
</Drawer>
|
|
221
|
+
|
|
222
|
+
{/* Desktop Drawer */}
|
|
223
|
+
<Drawer
|
|
224
|
+
variant="permanent"
|
|
225
|
+
sx={{
|
|
226
|
+
display: { xs: 'none', md: 'block' },
|
|
227
|
+
'& .MuiDrawer-paper': {
|
|
228
|
+
boxSizing: 'border-box',
|
|
229
|
+
width: drawerWidth,
|
|
230
|
+
transition: theme.transitions.create('width', {
|
|
231
|
+
easing: theme.transitions.easing.sharp,
|
|
232
|
+
duration: theme.transitions.duration.enteringScreen
|
|
233
|
+
}),
|
|
234
|
+
overflowX: 'hidden'
|
|
235
|
+
}
|
|
236
|
+
}}
|
|
237
|
+
open
|
|
238
|
+
>
|
|
239
|
+
{drawerContent}
|
|
240
|
+
</Drawer>
|
|
241
|
+
|
|
242
|
+
{/* Main Content */}
|
|
243
|
+
<Box
|
|
244
|
+
component="main"
|
|
245
|
+
sx={{
|
|
246
|
+
flexGrow: 1,
|
|
247
|
+
p: 3,
|
|
248
|
+
ml: { md: `${drawerWidth}px` },
|
|
249
|
+
width: { xs: '100%', md: `calc(100% - ${drawerWidth}px)` },
|
|
250
|
+
minHeight: '100vh',
|
|
251
|
+
backgroundColor: 'background.default',
|
|
252
|
+
transition: theme.transitions.create(['width', 'margin'], {
|
|
253
|
+
easing: theme.transitions.easing.sharp,
|
|
254
|
+
duration: theme.transitions.duration.leavingScreen
|
|
255
|
+
})
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
<Toolbar /> {/* Spacer for AppBar */}
|
|
259
|
+
{children}
|
|
260
|
+
</Box>
|
|
261
|
+
</Box>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export default Layout;
|