@aventoapp/framework 0.1.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/dist/index.js +6 -0
- package/dist/index.js.map +7 -0
- package/dist/native/index.js +2522 -0
- package/dist/native/index.js.map +7 -0
- package/dist/server/index.js +2776 -0
- package/dist/server/index.js.map +7 -0
- package/dist/server/workflow/index.js +537 -0
- package/dist/server/workflow/index.js.map +7 -0
- package/dist/shared/index.js +62 -0
- package/dist/shared/index.js.map +7 -0
- package/dist/web/index.js +7323 -0
- package/dist/web/index.js.map +7 -0
- package/package.json +81 -0
- package/schemas/Workflow.json +14 -0
- package/schemas/WorkflowHistory.json +22 -0
- package/schemas/WorkflowInstance.json +16 -0
- package/schemas/WorkflowState.json +18 -0
- package/schemas/WorkflowTransition.json +27 -0
- package/src/index.js +8 -0
- package/src/native/components/NativeAuthProvider.jsx +249 -0
- package/src/native/components/NativeDetail.jsx +270 -0
- package/src/native/components/NativeForm.jsx +543 -0
- package/src/native/components/NativeGrid.jsx +90 -0
- package/src/native/components/NativeJsonGrid.jsx +213 -0
- package/src/native/components/NativeJsonView.jsx +454 -0
- package/src/native/components/NativeJsonViewContext.js +17 -0
- package/src/native/components/NativeShell.jsx +68 -0
- package/src/native/components/NativeViewComponent.jsx +351 -0
- package/src/native/extensions/NativeExtensionRegistry.js +81 -0
- package/src/native/hooks/useNativeStore.js +72 -0
- package/src/native/index.js +15 -0
- package/src/native/layouts/NativeStackLayout.jsx +30 -0
- package/src/native/layouts/NativeTabLayout.jsx +96 -0
- package/src/native/storage.js +13 -0
- package/src/native/stores/NativeBaseStore.js +348 -0
- package/src/native/stores/NativeStoreContext.jsx +53 -0
- package/src/server/ai/capabilities-routes.js +106 -0
- package/src/server/ai/index.js +1 -0
- package/src/server/cache/MemoryCache.js +153 -0
- package/src/server/cache/index.js +2 -0
- package/src/server/cache/middleware.js +12 -0
- package/src/server/db/index.js +14 -0
- package/src/server/db/mongo.js +137 -0
- package/src/server/db/postgres.js +144 -0
- package/src/server/index.js +38 -0
- package/src/server/middleware/auth.js +682 -0
- package/src/server/middleware/can-flags.js +132 -0
- package/src/server/middleware/entityRoles.js +105 -0
- package/src/server/middleware/index.js +58 -0
- package/src/server/middleware/permissions.js +240 -0
- package/src/server/middleware/tenant.js +203 -0
- package/src/server/realtime/EventBus.js +45 -0
- package/src/server/realtime/WebSocketServer.js +105 -0
- package/src/server/realtime/index.js +3 -0
- package/src/server/realtime/middleware.js +18 -0
- package/src/server/services/email-templates.js +157 -0
- package/src/server/services/email.js +78 -0
- package/src/server/services/index.js +15 -0
- package/src/server/services/storage.js +119 -0
- package/src/server/utils/index.js +16 -0
- package/src/server/utils/paginate.js +65 -0
- package/src/server/utils/query-builder.js +293 -0
- package/src/server/utils/route-loader.js +61 -0
- package/src/server/workflow/WorkflowEngine.js +494 -0
- package/src/server/workflow/index.js +2 -0
- package/src/server/workflow/workflow-routes.js +174 -0
- package/src/shared/index.js +10 -0
- package/src/shared/utils/field-accessor.js +108 -0
- package/src/shared/utils/index.js +7 -0
- package/src/shared/utils/validation-utils.js +83 -0
- package/src/web/components/AppRouter/AppRouter.jsx +130 -0
- package/src/web/components/AppRouter/index.js +1 -0
- package/src/web/components/AppShell/AppShell.jsx +101 -0
- package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -0
- package/src/web/components/AppShell/ShellConfig.js +53 -0
- package/src/web/components/AppShell/index.js +3 -0
- package/src/web/components/AuthProvider.jsx +426 -0
- package/src/web/components/CardList/CardList.jsx +272 -0
- package/src/web/components/CardList/index.js +2 -0
- package/src/web/components/DetailView/DetailView.jsx +281 -0
- package/src/web/components/DetailView/index.js +2 -0
- package/src/web/components/Form/Form.jsx +300 -0
- package/src/web/components/Form/FormField.jsx +226 -0
- package/src/web/components/Form/index.js +3 -0
- package/src/web/components/Grid/Grid.jsx +304 -0
- package/src/web/components/Grid/index.js +2 -0
- package/src/web/components/IconRegistry/IconRegistry.jsx +127 -0
- package/src/web/components/IconRegistry/index.js +1 -0
- package/src/web/components/JsonView/JsonView.jsx +647 -0
- package/src/web/components/JsonView/ViewComponent.jsx +1045 -0
- package/src/web/components/JsonView/ViewToolbar.jsx +141 -0
- package/src/web/components/JsonView/index.js +14 -0
- package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -0
- package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -0
- package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -0
- package/src/web/components/JsonView/layouts/index.js +8 -0
- package/src/web/components/Layout.jsx +265 -0
- package/src/web/components/MobileLayout/MobileLayout.jsx +385 -0
- package/src/web/components/MobileLayout/index.js +1 -0
- package/src/web/components/Navigation/Navigation.jsx +248 -0
- package/src/web/components/Navigation/index.js +1 -0
- package/src/web/components/NotificationProvider.jsx +55 -0
- package/src/web/components/Pagination/InfiniteScroll.jsx +82 -0
- package/src/web/components/Pagination/Pagination.jsx +73 -0
- package/src/web/components/Pagination/index.js +8 -0
- package/src/web/components/SimpleList/SimpleList.jsx +177 -0
- package/src/web/components/SimpleList/index.js +2 -0
- package/src/web/components/TenantProvider.jsx +121 -0
- package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -0
- package/src/web/components/WorkflowActions/index.js +1 -0
- package/src/web/components/WorkflowField/WorkflowField.jsx +176 -0
- package/src/web/components/WorkflowField/index.js +2 -0
- package/src/web/components/WorkflowField/workflowColors.js +32 -0
- package/src/web/components/auth/DevTenantSelector.jsx +90 -0
- package/src/web/components/auth/ForgotPasswordForm.jsx +94 -0
- package/src/web/components/auth/RegisterForm.jsx +168 -0
- package/src/web/components/auth/ResetPasswordForm.jsx +121 -0
- package/src/web/components/auth/VerifyEmailView.jsx +85 -0
- package/src/web/components/auth/index.js +5 -0
- package/src/web/components/index.js +39 -0
- package/src/web/components/layouts/CardListLayout.jsx +68 -0
- package/src/web/components/layouts/FullscreenLayout.jsx +30 -0
- package/src/web/components/layouts/MobileStackLayout.jsx +28 -0
- package/src/web/components/layouts/WizardLayout.jsx +86 -0
- package/src/web/components/layouts/index.js +4 -0
- package/src/web/components/mobile/Badge.jsx +105 -0
- package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -0
- package/src/web/components/mobile/EmptyState.jsx +30 -0
- package/src/web/components/mobile/QuickActionButton.jsx +77 -0
- package/src/web/components/mobile/ServerAutocomplete.jsx +123 -0
- package/src/web/components/mobile/StarRating.jsx +42 -0
- package/src/web/components/mobile/StatCard.jsx +65 -0
- package/src/web/components/mobile/index.js +7 -0
- package/src/web/extensions/ExtensionRegistry.js +79 -0
- package/src/web/extensions/index.js +7 -0
- package/src/web/hooks/index.js +15 -0
- package/src/web/hooks/useApi.js +76 -0
- package/src/web/hooks/useAuth.js +37 -0
- package/src/web/hooks/useDebouncedSave.js +158 -0
- package/src/web/hooks/useIsMobile.js +14 -0
- package/src/web/hooks/useOfflineQueue.js +99 -0
- package/src/web/hooks/useSelectionModel.js +143 -0
- package/src/web/hooks/useServerAutocomplete.js +146 -0
- package/src/web/hooks/useStore.js +107 -0
- package/src/web/hooks/useSubscription.js +130 -0
- package/src/web/hooks/useTenant.js +39 -0
- package/src/web/hooks/useTenantResolver.js +65 -0
- package/src/web/hooks/useUndoRedo.js +77 -0
- package/src/web/hooks/useViews.js +113 -0
- package/src/web/hooks/useWorkflow.js +190 -0
- package/src/web/index.js +117 -0
- package/src/web/stores/BaseStore.js +439 -0
- package/src/web/stores/StoreContext.jsx +93 -0
- package/src/web/stores/index.js +3 -0
- package/src/web/theme/index.js +3 -0
- package/src/web/theme/mui-theme.js +228 -0
- package/src/web/utils/formatTimeAgo.js +22 -0
- package/src/web/utils/index.js +1 -0
- package/src/web/views/ViewRegistry.js +235 -0
- package/src/web/views/index.js +2 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MobileLayout Component
|
|
3
|
+
*
|
|
4
|
+
* Core mobile shell with bottom navigation (mobile viewport) or
|
|
5
|
+
* top AppBar with horizontal tabs (desktop viewport).
|
|
6
|
+
*
|
|
7
|
+
* Derives tabs from ViewRegistry, resolves icons via IconRegistry,
|
|
8
|
+
* and supports fullscreen view detection.
|
|
9
|
+
*
|
|
10
|
+
* Bottom navigation follows a ForeFlight-inspired pattern:
|
|
11
|
+
* [pinned tabs] [recently visited tabs] [...overflow]
|
|
12
|
+
*
|
|
13
|
+
* - Pinned tabs: always shown first (configured via shell.mobile.pinnedTabs)
|
|
14
|
+
* - Recent tabs: recently visited views fill remaining slots
|
|
15
|
+
* - Overflow "...": opens a drawer with all views (when overflowEnabled)
|
|
16
|
+
*/
|
|
17
|
+
import React, { useMemo, useState, useEffect, useCallback, useRef } from 'react';
|
|
18
|
+
import { useNavigate, useLocation, matchPath } from 'react-router-dom';
|
|
19
|
+
import {
|
|
20
|
+
Box,
|
|
21
|
+
BottomNavigation,
|
|
22
|
+
BottomNavigationAction,
|
|
23
|
+
AppBar,
|
|
24
|
+
Toolbar,
|
|
25
|
+
Typography,
|
|
26
|
+
} from '@mui/material';
|
|
27
|
+
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
28
|
+
|
|
29
|
+
import { useViews } from '../../hooks/useViews.js';
|
|
30
|
+
import { useIsMobile } from '../../hooks/useIsMobile.js';
|
|
31
|
+
import { resolveIcon } from '../IconRegistry/index.js';
|
|
32
|
+
import { useShellConfig } from '../AppShell/ShellConfig.js';
|
|
33
|
+
|
|
34
|
+
// localStorage key for persisting recent tabs
|
|
35
|
+
const RECENT_TABS_KEY = 'avento_recent_tabs';
|
|
36
|
+
const MAX_STORED_RECENT = 20;
|
|
37
|
+
|
|
38
|
+
function loadRecentViewIds() {
|
|
39
|
+
try {
|
|
40
|
+
const stored = localStorage.getItem(RECENT_TABS_KEY);
|
|
41
|
+
return stored ? JSON.parse(stored) : [];
|
|
42
|
+
} catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function saveRecentViewIds(ids) {
|
|
48
|
+
try {
|
|
49
|
+
localStorage.setItem(RECENT_TABS_KEY, JSON.stringify(ids.slice(0, MAX_STORED_RECENT)));
|
|
50
|
+
} catch {
|
|
51
|
+
// Ignore storage errors
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build the full tab list from ViewRegistry views.
|
|
57
|
+
*/
|
|
58
|
+
function useAllTabs() {
|
|
59
|
+
const { views: allViews } = useViews({ includeHidden: false });
|
|
60
|
+
|
|
61
|
+
return useMemo(() => {
|
|
62
|
+
return allViews
|
|
63
|
+
.filter(v => !v.parent && !v.hidden && v.icon)
|
|
64
|
+
.sort((a, b) => (a.order || 100) - (b.order || 100))
|
|
65
|
+
.map(v => ({
|
|
66
|
+
id: v.id,
|
|
67
|
+
label: v.label,
|
|
68
|
+
icon: resolveIcon(v.icon),
|
|
69
|
+
path: v.route,
|
|
70
|
+
meta: v.meta || {},
|
|
71
|
+
}));
|
|
72
|
+
}, [allViews]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Determine which view ID is active based on current pathname.
|
|
77
|
+
*/
|
|
78
|
+
function useActiveViewId(allTabs) {
|
|
79
|
+
const location = useLocation();
|
|
80
|
+
const { views: allViews } = useViews({ includeHidden: true });
|
|
81
|
+
|
|
82
|
+
return useMemo(() => {
|
|
83
|
+
const pathname = location.pathname;
|
|
84
|
+
|
|
85
|
+
// Check direct child views (match child route → parent tab)
|
|
86
|
+
const tabIdSet = new Set(allTabs.map(t => t.id));
|
|
87
|
+
for (const view of allViews) {
|
|
88
|
+
if (view.parent && tabIdSet.has(view.parent)) {
|
|
89
|
+
if (matchPath({ path: view.route, end: true }, pathname)) {
|
|
90
|
+
return view.parent;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Check tab routes: exact for '/', prefix for others
|
|
96
|
+
for (const tab of allTabs) {
|
|
97
|
+
if (tab.path === '/') {
|
|
98
|
+
if (pathname === '/') return tab.id;
|
|
99
|
+
} else {
|
|
100
|
+
if (pathname.startsWith(tab.path)) return tab.id;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return allTabs[0]?.id || null;
|
|
105
|
+
}, [location.pathname, allTabs, allViews]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Detect if the current route is a fullscreen view.
|
|
110
|
+
*/
|
|
111
|
+
function useIsFullscreen(shellConfig) {
|
|
112
|
+
const location = useLocation();
|
|
113
|
+
const { views: allViews } = useViews({ includeHidden: true });
|
|
114
|
+
|
|
115
|
+
return useMemo(() => {
|
|
116
|
+
const pathname = location.pathname;
|
|
117
|
+
|
|
118
|
+
for (const view of allViews) {
|
|
119
|
+
if (view.meta?.fullscreen) {
|
|
120
|
+
if (matchPath({ path: view.route, end: true }, pathname)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const routes = shellConfig?.fullscreenRoutes || [];
|
|
127
|
+
for (const route of routes) {
|
|
128
|
+
if (pathname.startsWith(route)) return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
}, [location.pathname, allViews, shellConfig]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Build the visible bottom-nav tab set using ForeFlight-style logic:
|
|
137
|
+
* [pinned...] [recent...] [...overflow]
|
|
138
|
+
*
|
|
139
|
+
* Tabs with meta.overflowHub=true are excluded from all visible slots and
|
|
140
|
+
* from recent history — they are represented by the "..." overflow button,
|
|
141
|
+
* and their children populate the overflow drawer.
|
|
142
|
+
*/
|
|
143
|
+
function useVisibleTabs(allTabs, mobileConfig, recentViewIds) {
|
|
144
|
+
const pinnedIds = mobileConfig?.pinnedTabs || [];
|
|
145
|
+
const maxTabs = mobileConfig?.maxTabs || 5;
|
|
146
|
+
const recentTabsCount = mobileConfig?.recentTabsCount ?? 1;
|
|
147
|
+
const overflowEnabled = mobileConfig?.overflowEnabled !== false;
|
|
148
|
+
|
|
149
|
+
return useMemo(() => {
|
|
150
|
+
// Separate overflowHub tabs from navigable tabs
|
|
151
|
+
const navigableTabs = allTabs.filter(t => !t.meta?.overflowHub);
|
|
152
|
+
const navigableById = new Map(navigableTabs.map(t => [t.id, t]));
|
|
153
|
+
const hasOverflowHub = allTabs.some(t => t.meta?.overflowHub);
|
|
154
|
+
|
|
155
|
+
// 1. Pinned tabs (config order, from navigable tabs only)
|
|
156
|
+
const pinnedTabs = pinnedIds.map(id => navigableById.get(id)).filter(Boolean);
|
|
157
|
+
|
|
158
|
+
// 2. Slots for recent tabs
|
|
159
|
+
const overflowSlot = overflowEnabled ? 1 : 0;
|
|
160
|
+
const availableForRecent = Math.max(0, maxTabs - pinnedTabs.length - overflowSlot);
|
|
161
|
+
const recentSlots = Math.min(recentTabsCount, availableForRecent);
|
|
162
|
+
|
|
163
|
+
// 3. Recent tabs: from history, excluding pinned and overflowHub
|
|
164
|
+
const pinnedIdSet = new Set(pinnedIds);
|
|
165
|
+
const recentTabs = recentViewIds
|
|
166
|
+
.filter(id => !pinnedIdSet.has(id) && navigableById.has(id))
|
|
167
|
+
.slice(0, recentSlots)
|
|
168
|
+
.map(id => navigableById.get(id));
|
|
169
|
+
|
|
170
|
+
const visible = [...pinnedTabs, ...recentTabs];
|
|
171
|
+
|
|
172
|
+
// 4. Determine if overflow is needed
|
|
173
|
+
const visibleIdSet = new Set(visible.map(t => t.id));
|
|
174
|
+
const hasOverflow = overflowEnabled && (
|
|
175
|
+
hasOverflowHub || navigableTabs.some(t => !visibleIdSet.has(t.id))
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
return { visibleTabs: visible, hasOverflow };
|
|
179
|
+
}, [allTabs, pinnedIds, maxTabs, recentTabsCount, overflowEnabled, recentViewIds]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* MobileLayout Component
|
|
185
|
+
*/
|
|
186
|
+
export function MobileLayout({
|
|
187
|
+
children,
|
|
188
|
+
title: titleProp,
|
|
189
|
+
logo: logoProp,
|
|
190
|
+
userMenu,
|
|
191
|
+
shellConfig: shellConfigProp,
|
|
192
|
+
}) {
|
|
193
|
+
const contextConfig = useShellConfig();
|
|
194
|
+
const shellConfig = shellConfigProp || contextConfig;
|
|
195
|
+
const title = titleProp || shellConfig.title || 'Avento App';
|
|
196
|
+
const logo = logoProp || shellConfig.logo;
|
|
197
|
+
const mobileConfig = shellConfig.mobile || {};
|
|
198
|
+
|
|
199
|
+
const allTabs = useAllTabs();
|
|
200
|
+
const [recentViewIds, setRecentViewIds] = useState(() => loadRecentViewIds());
|
|
201
|
+
|
|
202
|
+
const { visibleTabs, hasOverflow } = useVisibleTabs(allTabs, mobileConfig, recentViewIds);
|
|
203
|
+
const activeViewId = useActiveViewId(allTabs);
|
|
204
|
+
const isFullscreen = useIsFullscreen(shellConfig);
|
|
205
|
+
const isMobile = useIsMobile(shellConfig.breakpoint);
|
|
206
|
+
const navigate = useNavigate();
|
|
207
|
+
const location = useLocation();
|
|
208
|
+
|
|
209
|
+
// Track recently visited views (skip overflowHub tabs)
|
|
210
|
+
const prevPathnameRef = useRef(null);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (prevPathnameRef.current === location.pathname) return;
|
|
213
|
+
prevPathnameRef.current = location.pathname;
|
|
214
|
+
if (!activeViewId) return;
|
|
215
|
+
|
|
216
|
+
// Don't track overflowHub views in recent history
|
|
217
|
+
const activeTab = allTabs.find(t => t.id === activeViewId);
|
|
218
|
+
if (activeTab?.meta?.overflowHub) return;
|
|
219
|
+
|
|
220
|
+
setRecentViewIds(prev => {
|
|
221
|
+
const filtered = prev.filter(id => id !== activeViewId);
|
|
222
|
+
const next = [activeViewId, ...filtered];
|
|
223
|
+
saveRecentViewIds(next);
|
|
224
|
+
return next;
|
|
225
|
+
});
|
|
226
|
+
}, [location.pathname, activeViewId, allTabs]);
|
|
227
|
+
|
|
228
|
+
// Prevent body scroll on mobile (iOS rubber-band prevention)
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
if (!isMobile) return;
|
|
231
|
+
document.documentElement.style.overflow = 'hidden';
|
|
232
|
+
document.body.style.overflow = 'hidden';
|
|
233
|
+
return () => {
|
|
234
|
+
document.documentElement.style.overflow = '';
|
|
235
|
+
document.body.style.overflow = '';
|
|
236
|
+
};
|
|
237
|
+
}, [isMobile]);
|
|
238
|
+
|
|
239
|
+
const handleNavigate = useCallback((path) => {
|
|
240
|
+
navigate(path);
|
|
241
|
+
}, [navigate]);
|
|
242
|
+
|
|
243
|
+
// Active tab index in visibleTabs
|
|
244
|
+
const activeTabIndex = useMemo(() => {
|
|
245
|
+
const idx = visibleTabs.findIndex(t => t.id === activeViewId);
|
|
246
|
+
return idx >= 0 ? idx : false;
|
|
247
|
+
}, [visibleTabs, activeViewId]);
|
|
248
|
+
|
|
249
|
+
// Fullscreen: no chrome
|
|
250
|
+
if (isFullscreen) {
|
|
251
|
+
return <>{children}</>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Mobile viewport: bottom navigation
|
|
255
|
+
if (isMobile) {
|
|
256
|
+
return (
|
|
257
|
+
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100dvh', position: 'fixed', inset: 0 }}>
|
|
258
|
+
{/* Main content */}
|
|
259
|
+
<Box sx={{
|
|
260
|
+
flex: 1,
|
|
261
|
+
overflow: 'auto',
|
|
262
|
+
WebkitOverflowScrolling: 'touch',
|
|
263
|
+
// Padding for fixed bottom nav + iOS safe area
|
|
264
|
+
pb: 'calc(56px + env(safe-area-inset-bottom, 0px))',
|
|
265
|
+
}}>
|
|
266
|
+
{children}
|
|
267
|
+
</Box>
|
|
268
|
+
|
|
269
|
+
{/* Fixed bottom navigation */}
|
|
270
|
+
<Box sx={{
|
|
271
|
+
position: 'fixed',
|
|
272
|
+
bottom: 0,
|
|
273
|
+
left: 0,
|
|
274
|
+
right: 0,
|
|
275
|
+
zIndex: 1200,
|
|
276
|
+
borderTop: 1,
|
|
277
|
+
borderColor: 'divider',
|
|
278
|
+
bgcolor: 'background.paper',
|
|
279
|
+
paddingBottom: 'env(safe-area-inset-bottom, 0px)',
|
|
280
|
+
overflow: 'visible',
|
|
281
|
+
}}>
|
|
282
|
+
<BottomNavigation
|
|
283
|
+
value={activeTabIndex}
|
|
284
|
+
onChange={(_, newValue) => {
|
|
285
|
+
if (newValue >= 0 && newValue < visibleTabs.length) {
|
|
286
|
+
handleNavigate(visibleTabs[newValue].path);
|
|
287
|
+
}
|
|
288
|
+
}}
|
|
289
|
+
showLabels
|
|
290
|
+
sx={{ height: 56, overflow: 'visible' }}
|
|
291
|
+
>
|
|
292
|
+
{visibleTabs.map((tab) => (
|
|
293
|
+
<BottomNavigationAction
|
|
294
|
+
key={tab.id}
|
|
295
|
+
label={tab.meta?.fab ? undefined : tab.label}
|
|
296
|
+
icon={
|
|
297
|
+
tab.meta?.fab ? (
|
|
298
|
+
<Box sx={{
|
|
299
|
+
bgcolor: 'primary.main',
|
|
300
|
+
color: 'white',
|
|
301
|
+
borderRadius: '50%',
|
|
302
|
+
width: 56,
|
|
303
|
+
height: 56,
|
|
304
|
+
display: 'flex',
|
|
305
|
+
flexDirection: 'column',
|
|
306
|
+
alignItems: 'center',
|
|
307
|
+
justifyContent: 'center',
|
|
308
|
+
mt: -1.5,
|
|
309
|
+
boxShadow: 3,
|
|
310
|
+
gap: 0.25,
|
|
311
|
+
}}>
|
|
312
|
+
{tab.icon}
|
|
313
|
+
<Typography variant="caption" sx={{ fontSize: '0.6rem', lineHeight: 1, color: 'inherit' }}>
|
|
314
|
+
{tab.label}
|
|
315
|
+
</Typography>
|
|
316
|
+
</Box>
|
|
317
|
+
) : tab.icon
|
|
318
|
+
}
|
|
319
|
+
sx={tab.meta?.fab ? { '&.Mui-selected': { color: 'text.secondary' } } : { minWidth: 0, px: 0.5 }}
|
|
320
|
+
/>
|
|
321
|
+
))}
|
|
322
|
+
|
|
323
|
+
{/* Overflow "..." tab — navigates to the overflowHub's page */}
|
|
324
|
+
{hasOverflow && (() => {
|
|
325
|
+
const hubTab = allTabs.find(t => t.meta?.overflowHub);
|
|
326
|
+
if (!hubTab) return null;
|
|
327
|
+
return (
|
|
328
|
+
<BottomNavigationAction
|
|
329
|
+
label={hubTab.label}
|
|
330
|
+
icon={<MoreHorizIcon />}
|
|
331
|
+
value={-1}
|
|
332
|
+
onClick={() => handleNavigate(hubTab.path)}
|
|
333
|
+
sx={{ minWidth: 0, px: 0.5 }}
|
|
334
|
+
/>
|
|
335
|
+
);
|
|
336
|
+
})()}
|
|
337
|
+
</BottomNavigation>
|
|
338
|
+
</Box>
|
|
339
|
+
</Box>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Desktop viewport: top AppBar with horizontal tabs
|
|
344
|
+
const desktopTabs = allTabs.slice(0, mobileConfig.maxTabs || 8);
|
|
345
|
+
const activeDesktopIdx = desktopTabs.findIndex(t => t.id === activeViewId);
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
|
|
349
|
+
<AppBar position="fixed" color="primary" elevation={1}>
|
|
350
|
+
<Toolbar>
|
|
351
|
+
{logo || (
|
|
352
|
+
<Typography variant="h6" sx={{ mr: 2 }}>
|
|
353
|
+
{title}
|
|
354
|
+
</Typography>
|
|
355
|
+
)}
|
|
356
|
+
<Box sx={{ flexGrow: 1, display: 'flex', overflow: 'hidden' }}>
|
|
357
|
+
{desktopTabs.map((tab, idx) => (
|
|
358
|
+
<Box
|
|
359
|
+
key={tab.id}
|
|
360
|
+
onClick={() => navigate(tab.path)}
|
|
361
|
+
sx={{
|
|
362
|
+
px: 2,
|
|
363
|
+
py: 1,
|
|
364
|
+
cursor: 'pointer',
|
|
365
|
+
whiteSpace: 'nowrap',
|
|
366
|
+
borderBottom: activeDesktopIdx === idx ? '2px solid white' : '2px solid transparent',
|
|
367
|
+
'&:hover': { bgcolor: 'rgba(255,255,255,0.1)' },
|
|
368
|
+
}}
|
|
369
|
+
>
|
|
370
|
+
<Typography variant="body2" color="inherit">{tab.label}</Typography>
|
|
371
|
+
</Box>
|
|
372
|
+
))}
|
|
373
|
+
</Box>
|
|
374
|
+
{userMenu}
|
|
375
|
+
</Toolbar>
|
|
376
|
+
</AppBar>
|
|
377
|
+
<Toolbar /> {/* Spacer for fixed AppBar */}
|
|
378
|
+
<Box sx={{ flex: 1, overflow: 'auto' }}>
|
|
379
|
+
{children}
|
|
380
|
+
</Box>
|
|
381
|
+
</Box>
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export default MobileLayout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MobileLayout } from './MobileLayout.jsx';
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation Component
|
|
3
|
+
*
|
|
4
|
+
* Renders navigation menu from ViewRegistry, filtered by user roles.
|
|
5
|
+
* Works with the Layout component to provide drawer-based navigation.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
8
|
+
import { useNavigate, useLocation } from 'react-router-dom';
|
|
9
|
+
import {
|
|
10
|
+
List,
|
|
11
|
+
ListItem,
|
|
12
|
+
ListItemButton,
|
|
13
|
+
ListItemIcon,
|
|
14
|
+
ListItemText,
|
|
15
|
+
Collapse,
|
|
16
|
+
Divider,
|
|
17
|
+
Typography,
|
|
18
|
+
Box
|
|
19
|
+
} from '@mui/material';
|
|
20
|
+
import ExpandLess from '@mui/icons-material/ExpandLess';
|
|
21
|
+
import ExpandMore from '@mui/icons-material/ExpandMore';
|
|
22
|
+
|
|
23
|
+
import { resolveIcon } from '../IconRegistry/index.js';
|
|
24
|
+
import { useAuth } from '../../hooks/useAuth.js';
|
|
25
|
+
import { viewRegistry } from '../../views/ViewRegistry.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Navigation Item Component
|
|
29
|
+
*/
|
|
30
|
+
function NavigationItem({
|
|
31
|
+
item,
|
|
32
|
+
isActive,
|
|
33
|
+
drawerOpen = true,
|
|
34
|
+
onClick,
|
|
35
|
+
depth = 0
|
|
36
|
+
}) {
|
|
37
|
+
const icon = resolveIcon(item.icon);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ListItem disablePadding sx={{ display: 'block' }}>
|
|
41
|
+
<ListItemButton
|
|
42
|
+
selected={isActive}
|
|
43
|
+
onClick={() => onClick(item)}
|
|
44
|
+
sx={{
|
|
45
|
+
minHeight: 48,
|
|
46
|
+
justifyContent: drawerOpen ? 'initial' : 'center',
|
|
47
|
+
px: 2.5,
|
|
48
|
+
pl: drawerOpen ? 2.5 + depth * 2 : 2.5,
|
|
49
|
+
'&.Mui-selected': {
|
|
50
|
+
backgroundColor: 'primary.main',
|
|
51
|
+
color: 'primary.contrastText',
|
|
52
|
+
'&:hover': {
|
|
53
|
+
backgroundColor: 'primary.dark'
|
|
54
|
+
},
|
|
55
|
+
'& .MuiListItemIcon-root': {
|
|
56
|
+
color: 'primary.contrastText'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{icon && (
|
|
62
|
+
<ListItemIcon
|
|
63
|
+
sx={{
|
|
64
|
+
minWidth: 0,
|
|
65
|
+
mr: drawerOpen ? 2 : 'auto',
|
|
66
|
+
justifyContent: 'center'
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
{icon}
|
|
70
|
+
</ListItemIcon>
|
|
71
|
+
)}
|
|
72
|
+
{drawerOpen && (
|
|
73
|
+
<ListItemText
|
|
74
|
+
primary={item.label}
|
|
75
|
+
primaryTypographyProps={{
|
|
76
|
+
fontWeight: isActive ? 600 : 400,
|
|
77
|
+
fontSize: '0.875rem'
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</ListItemButton>
|
|
82
|
+
</ListItem>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Navigation Group Component (for nested items)
|
|
88
|
+
*/
|
|
89
|
+
function NavigationGroup({
|
|
90
|
+
label,
|
|
91
|
+
icon,
|
|
92
|
+
children,
|
|
93
|
+
drawerOpen = true,
|
|
94
|
+
defaultOpen = false
|
|
95
|
+
}) {
|
|
96
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
97
|
+
const iconComponent = resolveIcon(icon);
|
|
98
|
+
|
|
99
|
+
if (!drawerOpen) {
|
|
100
|
+
// When drawer is collapsed, just show the icon
|
|
101
|
+
return children;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
<ListItemButton onClick={() => setOpen(!open)}>
|
|
107
|
+
{iconComponent && (
|
|
108
|
+
<ListItemIcon sx={{ minWidth: 40 }}>
|
|
109
|
+
{iconComponent}
|
|
110
|
+
</ListItemIcon>
|
|
111
|
+
)}
|
|
112
|
+
<ListItemText primary={label} />
|
|
113
|
+
{open ? <ExpandLess /> : <ExpandMore />}
|
|
114
|
+
</ListItemButton>
|
|
115
|
+
<Collapse in={open} timeout="auto" unmountOnExit>
|
|
116
|
+
<List component="div" disablePadding>
|
|
117
|
+
{children}
|
|
118
|
+
</List>
|
|
119
|
+
</Collapse>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Navigation Component
|
|
126
|
+
*
|
|
127
|
+
* @param {Object} props
|
|
128
|
+
* @param {boolean} props.drawerOpen - Whether drawer is expanded
|
|
129
|
+
* @param {Function} props.onNavigate - Callback when navigation occurs
|
|
130
|
+
* @param {string} props.activePath - Override active path detection
|
|
131
|
+
*/
|
|
132
|
+
export function Navigation({
|
|
133
|
+
drawerOpen = true,
|
|
134
|
+
onNavigate,
|
|
135
|
+
activePath: activePathProp
|
|
136
|
+
}) {
|
|
137
|
+
const navigate = useNavigate();
|
|
138
|
+
const location = useLocation();
|
|
139
|
+
const { user } = useAuth();
|
|
140
|
+
const [views, setViews] = useState([]);
|
|
141
|
+
|
|
142
|
+
// Get user roles
|
|
143
|
+
const userRoles = useMemo(() => {
|
|
144
|
+
return user?.roles || [];
|
|
145
|
+
}, [user]);
|
|
146
|
+
|
|
147
|
+
// Subscribe to view registry changes
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
// Initial load
|
|
150
|
+
setViews(viewRegistry.getViewsForRole(userRoles));
|
|
151
|
+
|
|
152
|
+
// Subscribe to changes
|
|
153
|
+
const unsubscribe = viewRegistry.subscribe(() => {
|
|
154
|
+
setViews(viewRegistry.getViewsForRole(userRoles));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return unsubscribe;
|
|
158
|
+
}, [userRoles]);
|
|
159
|
+
|
|
160
|
+
// Determine active path
|
|
161
|
+
const activePath = activePathProp || location.pathname;
|
|
162
|
+
|
|
163
|
+
// Handle navigation click
|
|
164
|
+
const handleClick = useCallback((item) => {
|
|
165
|
+
navigate(item.path || item.route);
|
|
166
|
+
|
|
167
|
+
if (onNavigate) {
|
|
168
|
+
onNavigate(item);
|
|
169
|
+
}
|
|
170
|
+
}, [navigate, onNavigate]);
|
|
171
|
+
|
|
172
|
+
// Group views by parent (for nested navigation)
|
|
173
|
+
const { topLevel, grouped } = useMemo(() => {
|
|
174
|
+
const topLevel = [];
|
|
175
|
+
const grouped = new Map();
|
|
176
|
+
|
|
177
|
+
for (const view of views) {
|
|
178
|
+
if (view.parent) {
|
|
179
|
+
if (!grouped.has(view.parent)) {
|
|
180
|
+
grouped.set(view.parent, []);
|
|
181
|
+
}
|
|
182
|
+
grouped.get(view.parent).push(view);
|
|
183
|
+
} else {
|
|
184
|
+
topLevel.push(view);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return { topLevel, grouped };
|
|
189
|
+
}, [views]);
|
|
190
|
+
|
|
191
|
+
if (views.length === 0) {
|
|
192
|
+
return (
|
|
193
|
+
<Box sx={{ p: 2, textAlign: 'center' }}>
|
|
194
|
+
<Typography variant="body2" color="text.secondary">
|
|
195
|
+
No views available
|
|
196
|
+
</Typography>
|
|
197
|
+
</Box>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<List component="nav" sx={{ pt: 1 }}>
|
|
203
|
+
{topLevel.map((view) => {
|
|
204
|
+
const childViews = grouped.get(view.id);
|
|
205
|
+
const isActive = activePath === view.route ||
|
|
206
|
+
(childViews && childViews.some(c => activePath === c.route));
|
|
207
|
+
|
|
208
|
+
if (childViews && childViews.length > 0) {
|
|
209
|
+
return (
|
|
210
|
+
<NavigationGroup
|
|
211
|
+
key={view.id}
|
|
212
|
+
label={view.label}
|
|
213
|
+
icon={view.icon}
|
|
214
|
+
drawerOpen={drawerOpen}
|
|
215
|
+
defaultOpen={isActive}
|
|
216
|
+
>
|
|
217
|
+
{childViews.map((child) => (
|
|
218
|
+
<NavigationItem
|
|
219
|
+
key={child.id}
|
|
220
|
+
item={child}
|
|
221
|
+
isActive={activePath === child.route}
|
|
222
|
+
drawerOpen={drawerOpen}
|
|
223
|
+
onClick={handleClick}
|
|
224
|
+
depth={1}
|
|
225
|
+
/>
|
|
226
|
+
))}
|
|
227
|
+
</NavigationGroup>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<NavigationItem
|
|
233
|
+
key={view.id}
|
|
234
|
+
item={{
|
|
235
|
+
...view,
|
|
236
|
+
path: view.route
|
|
237
|
+
}}
|
|
238
|
+
isActive={activePath === view.route}
|
|
239
|
+
drawerOpen={drawerOpen}
|
|
240
|
+
onClick={handleClick}
|
|
241
|
+
/>
|
|
242
|
+
);
|
|
243
|
+
})}
|
|
244
|
+
</List>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export default Navigation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Navigation } from './Navigation.jsx';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useCallback } from 'react';
|
|
2
|
+
import Snackbar from '@mui/material/Snackbar';
|
|
3
|
+
import Alert from '@mui/material/Alert';
|
|
4
|
+
|
|
5
|
+
const NotificationContext = createContext(null);
|
|
6
|
+
|
|
7
|
+
export function NotificationProvider({ children }) {
|
|
8
|
+
const [queue, setQueue] = useState([]);
|
|
9
|
+
|
|
10
|
+
const show = useCallback((severity, message) => {
|
|
11
|
+
setQueue(prev => [...prev, { severity, message, key: Date.now() + Math.random() }]);
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
const notify = {
|
|
15
|
+
success: (msg) => show('success', msg),
|
|
16
|
+
error: (msg) => show('error', msg),
|
|
17
|
+
warning: (msg) => show('warning', msg),
|
|
18
|
+
info: (msg) => show('info', msg),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const handleClose = (key) => {
|
|
22
|
+
setQueue(prev => prev.filter(n => n.key !== key));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<NotificationContext.Provider value={{ notify }}>
|
|
27
|
+
{children}
|
|
28
|
+
{queue.map((n, i) => (
|
|
29
|
+
<Snackbar
|
|
30
|
+
key={n.key}
|
|
31
|
+
open
|
|
32
|
+
autoHideDuration={4000}
|
|
33
|
+
onClose={() => handleClose(n.key)}
|
|
34
|
+
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
|
35
|
+
style={{ bottom: 16 + i * 60 }}
|
|
36
|
+
>
|
|
37
|
+
<Alert
|
|
38
|
+
onClose={() => handleClose(n.key)}
|
|
39
|
+
severity={n.severity}
|
|
40
|
+
variant="filled"
|
|
41
|
+
sx={{ width: '100%' }}
|
|
42
|
+
>
|
|
43
|
+
{n.message}
|
|
44
|
+
</Alert>
|
|
45
|
+
</Snackbar>
|
|
46
|
+
))}
|
|
47
|
+
</NotificationContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function useNotification() {
|
|
52
|
+
const ctx = useContext(NotificationContext);
|
|
53
|
+
if (!ctx) throw new Error('useNotification must be used within a NotificationProvider');
|
|
54
|
+
return ctx;
|
|
55
|
+
}
|