@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,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NavigationContainer } from '@react-navigation/native';
|
|
3
|
+
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
|
4
|
+
import Ionicons from '@expo/vector-icons/Ionicons';
|
|
5
|
+
import { useNativeAuth } from './NativeAuthProvider.jsx';
|
|
6
|
+
|
|
7
|
+
const Tab = createBottomTabNavigator();
|
|
8
|
+
|
|
9
|
+
const ICON_MAP = {
|
|
10
|
+
home: 'home',
|
|
11
|
+
settings: 'settings',
|
|
12
|
+
list: 'list',
|
|
13
|
+
person: 'person',
|
|
14
|
+
golf: 'golf',
|
|
15
|
+
map: 'map',
|
|
16
|
+
stats: 'stats-chart',
|
|
17
|
+
add: 'add-circle',
|
|
18
|
+
search: 'search',
|
|
19
|
+
trophy: 'trophy',
|
|
20
|
+
calendar: 'calendar',
|
|
21
|
+
flag: 'flag',
|
|
22
|
+
disc: 'disc',
|
|
23
|
+
'ellipsis-horizontal': 'ellipsis-horizontal',
|
|
24
|
+
'bar-chart': 'bar-chart',
|
|
25
|
+
play: 'play',
|
|
26
|
+
navigate: 'navigate',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function resolveIcon(name) {
|
|
30
|
+
return ICON_MAP[name] || name;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Disable deep-link handling to avoid the RN 0.81 read-only URL.protocol error
|
|
34
|
+
const linking = { enabled: false };
|
|
35
|
+
|
|
36
|
+
export function NativeShell({ title = 'App', tabs = [], loginScreen: LoginScreen }) {
|
|
37
|
+
const { isAuthenticated, loading } = useNativeAuth();
|
|
38
|
+
|
|
39
|
+
if (loading) return null;
|
|
40
|
+
|
|
41
|
+
if (!isAuthenticated && LoginScreen) {
|
|
42
|
+
return <LoginScreen />;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<NavigationContainer linking={linking}>
|
|
47
|
+
<Tab.Navigator
|
|
48
|
+
screenOptions={({ route }) => ({
|
|
49
|
+
headerTitle: title,
|
|
50
|
+
tabBarIcon: ({ focused, color, size }) => {
|
|
51
|
+
const tab = tabs.find(t => t.id === route.name);
|
|
52
|
+
const iconName = resolveIcon(tab?.icon || 'home');
|
|
53
|
+
return <Ionicons name={focused ? iconName : `${iconName}-outline`} size={size} color={color} />;
|
|
54
|
+
},
|
|
55
|
+
})}
|
|
56
|
+
>
|
|
57
|
+
{tabs.map(tab => (
|
|
58
|
+
<Tab.Screen
|
|
59
|
+
key={tab.id}
|
|
60
|
+
name={tab.id}
|
|
61
|
+
component={tab.screen}
|
|
62
|
+
options={{ tabBarLabel: tab.label }}
|
|
63
|
+
/>
|
|
64
|
+
))}
|
|
65
|
+
</Tab.Navigator>
|
|
66
|
+
</NavigationContainer>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeViewComponent
|
|
3
|
+
*
|
|
4
|
+
* Renders the appropriate native component based on type configuration.
|
|
5
|
+
* Handles listenTo bindings, showWhen visibility, and delete confirmation.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useMemo, useCallback } from 'react';
|
|
8
|
+
import { View, Text, Alert, StyleSheet } from 'react-native';
|
|
9
|
+
import { useNativeJsonView } from './NativeJsonViewContext.js';
|
|
10
|
+
import { NativeJsonGrid } from './NativeJsonGrid.jsx';
|
|
11
|
+
import { NativeForm } from './NativeForm.jsx';
|
|
12
|
+
import { NativeDetail } from './NativeDetail.jsx';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolve listenTo binding to actual data
|
|
16
|
+
*/
|
|
17
|
+
function resolveListenTo(listenTo, viewState) {
|
|
18
|
+
if (!listenTo) return {};
|
|
19
|
+
|
|
20
|
+
const resolved = {};
|
|
21
|
+
|
|
22
|
+
Object.entries(listenTo).forEach(([binding, targetProp]) => {
|
|
23
|
+
const [componentId, property] = binding.split('.');
|
|
24
|
+
|
|
25
|
+
let value = null;
|
|
26
|
+
switch (property) {
|
|
27
|
+
case 'selection':
|
|
28
|
+
value = viewState.selections[componentId];
|
|
29
|
+
break;
|
|
30
|
+
case 'editItem':
|
|
31
|
+
value = viewState.editItems[componentId];
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
value = viewState.componentStates[componentId]?.[property];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
resolved[targetProp] = value;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return resolved;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Evaluate showWhen condition
|
|
45
|
+
*/
|
|
46
|
+
function evaluateShowWhen(showWhen, viewState) {
|
|
47
|
+
if (!showWhen) return true;
|
|
48
|
+
|
|
49
|
+
const [componentId, property] = showWhen.split('.');
|
|
50
|
+
|
|
51
|
+
switch (property) {
|
|
52
|
+
case 'selection':
|
|
53
|
+
return !!viewState.selections[componentId];
|
|
54
|
+
case 'editItem':
|
|
55
|
+
return !!viewState.editItems[componentId];
|
|
56
|
+
default:
|
|
57
|
+
return !!viewState.componentStates[componentId]?.[property];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* GridComponent - Renders NativeJsonGrid with JsonView bindings
|
|
63
|
+
*/
|
|
64
|
+
function GridComponent({ componentConfig }) {
|
|
65
|
+
const {
|
|
66
|
+
items,
|
|
67
|
+
loading,
|
|
68
|
+
storeActions,
|
|
69
|
+
setSelection,
|
|
70
|
+
setEditItem,
|
|
71
|
+
openDialog,
|
|
72
|
+
viewState,
|
|
73
|
+
pagination,
|
|
74
|
+
paginationConfig,
|
|
75
|
+
onLoadMore,
|
|
76
|
+
config: viewConfig
|
|
77
|
+
} = useNativeJsonView();
|
|
78
|
+
|
|
79
|
+
const { id, config, onAction } = componentConfig;
|
|
80
|
+
|
|
81
|
+
const handleRowPress = useCallback((row) => {
|
|
82
|
+
setSelection(id, row);
|
|
83
|
+
storeActions.select?.(row);
|
|
84
|
+
}, [id, setSelection, storeActions]);
|
|
85
|
+
|
|
86
|
+
const handleRefresh = useCallback(() => {
|
|
87
|
+
const sliceId = viewConfig?.dataSource?.sliceId;
|
|
88
|
+
return storeActions.list?.(sliceId ? { sliceId } : undefined);
|
|
89
|
+
}, [storeActions, viewConfig?.dataSource?.sliceId]);
|
|
90
|
+
|
|
91
|
+
const handleLoadMore = useCallback(() => {
|
|
92
|
+
onLoadMore?.();
|
|
93
|
+
}, [onLoadMore]);
|
|
94
|
+
|
|
95
|
+
const handleEdit = useCallback((row) => {
|
|
96
|
+
setEditItem(id, row);
|
|
97
|
+
const actionConfig = onAction?.edit;
|
|
98
|
+
if (actionConfig?.open) {
|
|
99
|
+
openDialog(actionConfig.open, row);
|
|
100
|
+
} else {
|
|
101
|
+
// Default: open a form dialog with the component id
|
|
102
|
+
openDialog(`${id}_form`, row);
|
|
103
|
+
}
|
|
104
|
+
}, [id, setEditItem, onAction, openDialog]);
|
|
105
|
+
|
|
106
|
+
const handleDelete = useCallback((row) => {
|
|
107
|
+
const entityName = config?.entityName || viewConfig?.dataSource?.entityName || 'item';
|
|
108
|
+
Alert.alert(
|
|
109
|
+
'Confirm Delete',
|
|
110
|
+
`Are you sure you want to delete this ${entityName.toLowerCase()}?${row.title ? ` "${row.title}"` : row.name ? ` "${row.name}"` : ''}`,
|
|
111
|
+
[
|
|
112
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
113
|
+
{
|
|
114
|
+
text: 'Delete',
|
|
115
|
+
style: 'destructive',
|
|
116
|
+
onPress: () => {
|
|
117
|
+
storeActions.delete?.(row.id).then(() => {
|
|
118
|
+
const sliceId = viewConfig?.dataSource?.sliceId;
|
|
119
|
+
storeActions.list?.(sliceId ? { sliceId } : undefined);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
);
|
|
125
|
+
}, [config?.entityName, viewConfig?.dataSource, storeActions]);
|
|
126
|
+
|
|
127
|
+
const selectedId = viewState.selections[id]?.id;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<NativeJsonGrid
|
|
131
|
+
config={config}
|
|
132
|
+
data={items}
|
|
133
|
+
loading={loading}
|
|
134
|
+
selectedId={selectedId}
|
|
135
|
+
hasMore={pagination?.hasNext || false}
|
|
136
|
+
onRowPress={handleRowPress}
|
|
137
|
+
onRefresh={handleRefresh}
|
|
138
|
+
onEndReached={handleLoadMore}
|
|
139
|
+
onEdit={handleEdit}
|
|
140
|
+
onDelete={handleDelete}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* FormComponent - Renders NativeForm with JsonView bindings
|
|
147
|
+
*/
|
|
148
|
+
function FormComponent({ componentConfig, boundData }) {
|
|
149
|
+
const {
|
|
150
|
+
storeActions,
|
|
151
|
+
clearEditItem,
|
|
152
|
+
closeDialog,
|
|
153
|
+
dialogs,
|
|
154
|
+
config: viewConfig
|
|
155
|
+
} = useNativeJsonView();
|
|
156
|
+
|
|
157
|
+
const { id, config, onSubmit } = componentConfig;
|
|
158
|
+
|
|
159
|
+
const dialogState = dialogs[id];
|
|
160
|
+
const formData = boundData?.data || dialogState?.data || null;
|
|
161
|
+
const isOpen = dialogState?.open || false;
|
|
162
|
+
|
|
163
|
+
const sliceId = viewConfig?.dataSource?.sliceId;
|
|
164
|
+
|
|
165
|
+
const handleSubmit = useCallback(async (data, editId) => {
|
|
166
|
+
try {
|
|
167
|
+
if (editId) {
|
|
168
|
+
await storeActions.update?.(editId, data);
|
|
169
|
+
} else {
|
|
170
|
+
await storeActions.create?.(data);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
storeActions.list?.(sliceId ? { sliceId } : undefined);
|
|
174
|
+
|
|
175
|
+
if (onSubmit?.closeOnSuccess !== false) {
|
|
176
|
+
clearEditItem(id);
|
|
177
|
+
closeDialog(id);
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
}, [id, storeActions, clearEditItem, closeDialog, onSubmit, sliceId]);
|
|
183
|
+
|
|
184
|
+
const handleClose = useCallback(() => {
|
|
185
|
+
clearEditItem(id);
|
|
186
|
+
closeDialog(id);
|
|
187
|
+
}, [id, clearEditItem, closeDialog]);
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<NativeForm
|
|
191
|
+
config={config}
|
|
192
|
+
data={formData}
|
|
193
|
+
visible={isOpen}
|
|
194
|
+
onClose={handleClose}
|
|
195
|
+
onSubmit={handleSubmit}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* DetailComponent - Renders NativeDetail with JsonView bindings
|
|
202
|
+
*/
|
|
203
|
+
function DetailComponent({ componentConfig, boundData }) {
|
|
204
|
+
const {
|
|
205
|
+
storeActions,
|
|
206
|
+
setEditItem,
|
|
207
|
+
openDialog,
|
|
208
|
+
closeDialog,
|
|
209
|
+
config: viewConfig
|
|
210
|
+
} = useNativeJsonView();
|
|
211
|
+
|
|
212
|
+
const { id, config, onAction } = componentConfig;
|
|
213
|
+
const detailData = boundData?.data || null;
|
|
214
|
+
|
|
215
|
+
const handleEdit = useCallback((data) => {
|
|
216
|
+
setEditItem(id, data);
|
|
217
|
+
const actionConfig = onAction?.edit;
|
|
218
|
+
if (actionConfig?.open) {
|
|
219
|
+
openDialog(actionConfig.open, data);
|
|
220
|
+
} else {
|
|
221
|
+
openDialog(`${id}_form`, data);
|
|
222
|
+
}
|
|
223
|
+
}, [id, setEditItem, onAction, openDialog]);
|
|
224
|
+
|
|
225
|
+
const handleDelete = useCallback((data) => {
|
|
226
|
+
const entityName = config?.entityName || viewConfig?.dataSource?.entityName || 'item';
|
|
227
|
+
Alert.alert(
|
|
228
|
+
'Confirm Delete',
|
|
229
|
+
`Are you sure you want to delete this ${entityName.toLowerCase()}?${data.title ? ` "${data.title}"` : data.name ? ` "${data.name}"` : ''}`,
|
|
230
|
+
[
|
|
231
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
232
|
+
{
|
|
233
|
+
text: 'Delete',
|
|
234
|
+
style: 'destructive',
|
|
235
|
+
onPress: () => {
|
|
236
|
+
storeActions.delete?.(data.id).then(() => {
|
|
237
|
+
const sliceId = viewConfig?.dataSource?.sliceId;
|
|
238
|
+
storeActions.list?.(sliceId ? { sliceId } : undefined);
|
|
239
|
+
closeDialog(id);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
);
|
|
245
|
+
}, [id, config?.entityName, viewConfig?.dataSource, storeActions, closeDialog]);
|
|
246
|
+
|
|
247
|
+
const handleClose = useCallback(() => {
|
|
248
|
+
closeDialog(id);
|
|
249
|
+
}, [id, closeDialog]);
|
|
250
|
+
|
|
251
|
+
if (!detailData) return null;
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<NativeDetail
|
|
255
|
+
config={config}
|
|
256
|
+
data={detailData}
|
|
257
|
+
visible={true}
|
|
258
|
+
onEdit={handleEdit}
|
|
259
|
+
onDelete={handleDelete}
|
|
260
|
+
onClose={handleClose}
|
|
261
|
+
/>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* NativeViewComponent
|
|
267
|
+
*
|
|
268
|
+
* Routes to the appropriate native component based on type.
|
|
269
|
+
*/
|
|
270
|
+
export function NativeViewComponent({ componentConfig }) {
|
|
271
|
+
const { viewState, extensionComponents, dialogs, closeDialog, executeCustomAction } = useNativeJsonView();
|
|
272
|
+
|
|
273
|
+
const { id, type, listenTo, showWhen } = componentConfig;
|
|
274
|
+
|
|
275
|
+
const boundData = useMemo(
|
|
276
|
+
() => resolveListenTo(listenTo, viewState),
|
|
277
|
+
[listenTo, viewState]
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
const isVisible = useMemo(
|
|
281
|
+
() => evaluateShowWhen(showWhen, viewState),
|
|
282
|
+
[showWhen, viewState]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
let content;
|
|
286
|
+
switch (type) {
|
|
287
|
+
case 'grid':
|
|
288
|
+
content = <GridComponent componentConfig={componentConfig} />;
|
|
289
|
+
break;
|
|
290
|
+
|
|
291
|
+
case 'form':
|
|
292
|
+
content = <FormComponent componentConfig={componentConfig} boundData={boundData} />;
|
|
293
|
+
break;
|
|
294
|
+
|
|
295
|
+
case 'detail':
|
|
296
|
+
if (!isVisible) return null;
|
|
297
|
+
content = <DetailComponent componentConfig={componentConfig} boundData={boundData} />;
|
|
298
|
+
break;
|
|
299
|
+
|
|
300
|
+
case 'custom': {
|
|
301
|
+
const CustomComponent = extensionComponents?.[componentConfig.component];
|
|
302
|
+
if (CustomComponent) {
|
|
303
|
+
const dialogState = dialogs[id];
|
|
304
|
+
const isDialogOpen = dialogState?.open || false;
|
|
305
|
+
const dialogData = dialogState?.data || boundData?.data;
|
|
306
|
+
|
|
307
|
+
content = (
|
|
308
|
+
<CustomComponent
|
|
309
|
+
id={id}
|
|
310
|
+
config={componentConfig.config}
|
|
311
|
+
data={dialogData}
|
|
312
|
+
boundData={boundData}
|
|
313
|
+
open={isDialogOpen}
|
|
314
|
+
onClose={() => closeDialog(id)}
|
|
315
|
+
/>
|
|
316
|
+
);
|
|
317
|
+
} else {
|
|
318
|
+
content = (
|
|
319
|
+
<View style={styles.unknownType}>
|
|
320
|
+
<Text style={styles.unknownTypeText}>
|
|
321
|
+
Custom component not found: {componentConfig.component}
|
|
322
|
+
</Text>
|
|
323
|
+
</View>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
default:
|
|
330
|
+
content = (
|
|
331
|
+
<View style={styles.unknownType}>
|
|
332
|
+
<Text style={styles.unknownTypeText}>Unknown component type: {type}</Text>
|
|
333
|
+
</View>
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return content;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const styles = StyleSheet.create({
|
|
341
|
+
unknownType: {
|
|
342
|
+
padding: 16,
|
|
343
|
+
alignItems: 'center',
|
|
344
|
+
},
|
|
345
|
+
unknownTypeText: {
|
|
346
|
+
fontSize: 14,
|
|
347
|
+
color: '#d32f2f',
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
export default NativeViewComponent;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeExtensionRegistry
|
|
3
|
+
*
|
|
4
|
+
* Registry for NativeJsonView extensions. Extensions provide custom actions,
|
|
5
|
+
* components, and state for JSON-defined views on React Native.
|
|
6
|
+
*
|
|
7
|
+
* Same API as web ExtensionRegistry.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* // Register an extension
|
|
11
|
+
* nativeExtensionRegistry.register('userManagement', useUserManagementExtension);
|
|
12
|
+
*
|
|
13
|
+
* // In JSON config
|
|
14
|
+
* { extension: 'userManagement', ... }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class NativeExtensionRegistry {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._extensions = new Map();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Register an extension hook
|
|
24
|
+
* @param {string} name - Extension name (referenced in JSON config)
|
|
25
|
+
* @param {Function} useExtension - Hook function that returns { actions, components, ...state }
|
|
26
|
+
*/
|
|
27
|
+
register(name, useExtension) {
|
|
28
|
+
if (typeof useExtension !== 'function') {
|
|
29
|
+
throw new Error(`Extension "${name}" must be a function (hook)`);
|
|
30
|
+
}
|
|
31
|
+
this._extensions.set(name, useExtension);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Register multiple extensions at once
|
|
36
|
+
* @param {Object} extensions - Object of { name: useExtension }
|
|
37
|
+
*/
|
|
38
|
+
registerAll(extensions) {
|
|
39
|
+
Object.entries(extensions).forEach(([name, hook]) => {
|
|
40
|
+
this.register(name, hook);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get an extension hook by name
|
|
46
|
+
* @param {string} name - Extension name
|
|
47
|
+
* @returns {Function|null} Extension hook or null if not found
|
|
48
|
+
*/
|
|
49
|
+
get(name) {
|
|
50
|
+
return this._extensions.get(name) || null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if an extension is registered
|
|
55
|
+
* @param {string} name - Extension name
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
has(name) {
|
|
59
|
+
return this._extensions.has(name);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get all registered extension names
|
|
64
|
+
* @returns {string[]}
|
|
65
|
+
*/
|
|
66
|
+
getNames() {
|
|
67
|
+
return Array.from(this._extensions.keys());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Clear all registered extensions
|
|
72
|
+
*/
|
|
73
|
+
clear() {
|
|
74
|
+
this._extensions.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Singleton instance
|
|
79
|
+
export const nativeExtensionRegistry = new NativeExtensionRegistry();
|
|
80
|
+
|
|
81
|
+
export default NativeExtensionRegistry;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useNativeStore Hook
|
|
3
|
+
*
|
|
4
|
+
* Hook to access a store and subscribe to its state changes.
|
|
5
|
+
* Mirror of web useStore.js for React Native.
|
|
6
|
+
*/
|
|
7
|
+
import { useContext, useEffect, useState, useCallback } from 'react';
|
|
8
|
+
import { NativeStoreContext } from '../stores/NativeStoreContext.jsx';
|
|
9
|
+
|
|
10
|
+
export function useNativeStore(storeOrName) {
|
|
11
|
+
const context = useContext(NativeStoreContext);
|
|
12
|
+
|
|
13
|
+
const store = typeof storeOrName === 'string'
|
|
14
|
+
? context?.getStore(storeOrName)
|
|
15
|
+
: storeOrName;
|
|
16
|
+
|
|
17
|
+
if (!store) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
typeof storeOrName === 'string'
|
|
20
|
+
? `Store "${storeOrName}" not found. Make sure it's registered with NativeStoreProvider.`
|
|
21
|
+
: 'useNativeStore requires a valid store name or store instance'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [state, setState] = useState(() => store.getState());
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setState(store.getState());
|
|
29
|
+
|
|
30
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
31
|
+
setState(newState);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return unsubscribe;
|
|
35
|
+
}, [store]);
|
|
36
|
+
|
|
37
|
+
const list = useCallback((options) => store.list(options), [store]);
|
|
38
|
+
const get = useCallback((id) => store.get(id), [store]);
|
|
39
|
+
const create = useCallback((data) => store.create(data), [store]);
|
|
40
|
+
const update = useCallback((id, data) => store.update(id, data), [store]);
|
|
41
|
+
const remove = useCallback((id) => store.delete(id), [store]);
|
|
42
|
+
const select = useCallback((item) => store.select(item), [store]);
|
|
43
|
+
const clearSelection = useCallback(() => store.clearSelection(), [store]);
|
|
44
|
+
const clearError = useCallback(() => store.clearError(), [store]);
|
|
45
|
+
const reset = useCallback(() => store.reset(), [store]);
|
|
46
|
+
const loadMore = useCallback(() => store.loadMore(), [store]);
|
|
47
|
+
const setPageSize = useCallback((size) => store.setPageSize(size), [store]);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
items: state.items,
|
|
51
|
+
selectedItem: state.selectedItem,
|
|
52
|
+
loading: state.loading,
|
|
53
|
+
error: state.error,
|
|
54
|
+
pagination: state.pagination,
|
|
55
|
+
|
|
56
|
+
list,
|
|
57
|
+
get,
|
|
58
|
+
create,
|
|
59
|
+
update,
|
|
60
|
+
delete: remove,
|
|
61
|
+
select,
|
|
62
|
+
clearSelection,
|
|
63
|
+
clearError,
|
|
64
|
+
reset,
|
|
65
|
+
loadMore,
|
|
66
|
+
setPageSize,
|
|
67
|
+
|
|
68
|
+
store
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default useNativeStore;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { NativeAuthProvider, NativeAuthContext, useNativeAuth } from './components/NativeAuthProvider.jsx';
|
|
2
|
+
export { NativeShell } from './components/NativeShell.jsx';
|
|
3
|
+
export { NativeGrid } from './components/NativeGrid.jsx';
|
|
4
|
+
export { NativeJsonView } from './components/NativeJsonView.jsx';
|
|
5
|
+
export { NativeJsonViewContext, useNativeJsonView } from './components/NativeJsonViewContext.js';
|
|
6
|
+
export { NativeForm } from './components/NativeForm.jsx';
|
|
7
|
+
export { NativeDetail } from './components/NativeDetail.jsx';
|
|
8
|
+
export { NativeJsonGrid } from './components/NativeJsonGrid.jsx';
|
|
9
|
+
export { NativeViewComponent } from './components/NativeViewComponent.jsx';
|
|
10
|
+
export { NativeStoreProvider, NativeStoreContext } from './stores/NativeStoreContext.jsx';
|
|
11
|
+
export { NativeBaseStore } from './stores/NativeBaseStore.js';
|
|
12
|
+
export { useNativeStore } from './hooks/useNativeStore.js';
|
|
13
|
+
export { NativeStackLayout } from './layouts/NativeStackLayout.jsx';
|
|
14
|
+
export { NativeTabLayout } from './layouts/NativeTabLayout.jsx';
|
|
15
|
+
export { nativeExtensionRegistry, default as NativeExtensionRegistry } from './extensions/NativeExtensionRegistry.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeStackLayout
|
|
3
|
+
*
|
|
4
|
+
* Default layout for NativeJsonView. Renders grid as primary content
|
|
5
|
+
* with detail/form modals overlaying on top when triggered by state.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { View, StyleSheet } from 'react-native';
|
|
9
|
+
import { NativeViewComponent } from '../components/NativeViewComponent.jsx';
|
|
10
|
+
|
|
11
|
+
export function NativeStackLayout({ config = {}, components = [] }) {
|
|
12
|
+
return (
|
|
13
|
+
<View style={styles.container}>
|
|
14
|
+
{components.map((componentConfig) => (
|
|
15
|
+
<NativeViewComponent
|
|
16
|
+
key={componentConfig.id}
|
|
17
|
+
componentConfig={componentConfig}
|
|
18
|
+
/>
|
|
19
|
+
))}
|
|
20
|
+
</View>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const styles = StyleSheet.create({
|
|
25
|
+
container: {
|
|
26
|
+
flex: 1,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default NativeStackLayout;
|