@aventoapp/framework 0.2.0 → 0.2.2
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 +281 -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 +69 -6
- package/dist/server/index.js.map +2 -2
- 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/offline/field-lww.js +98 -6
- 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,90 +1,90 @@
|
|
|
1
|
-
import React, { useState, useCallback } from 'react';
|
|
2
|
-
import { FlatList, View, Text, StyleSheet, RefreshControl, TouchableOpacity } from 'react-native';
|
|
3
|
-
|
|
4
|
-
const styles = StyleSheet.create({
|
|
5
|
-
container: { flex: 1, backgroundColor: '#fff' },
|
|
6
|
-
card: {
|
|
7
|
-
padding: 16,
|
|
8
|
-
marginHorizontal: 12,
|
|
9
|
-
marginVertical: 6,
|
|
10
|
-
backgroundColor: '#fff',
|
|
11
|
-
borderRadius: 8,
|
|
12
|
-
shadowColor: '#000',
|
|
13
|
-
shadowOffset: { width: 0, height: 1 },
|
|
14
|
-
shadowOpacity: 0.1,
|
|
15
|
-
shadowRadius: 2,
|
|
16
|
-
elevation: 2,
|
|
17
|
-
},
|
|
18
|
-
primary: { fontSize: 16, fontWeight: '600', color: '#1a1a1a' },
|
|
19
|
-
secondary: { fontSize: 14, color: '#666', marginTop: 2 },
|
|
20
|
-
empty: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 40 },
|
|
21
|
-
emptyText: { fontSize: 16, color: '#999' },
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
function DefaultRowCard({ item, config, onPress }) {
|
|
25
|
-
const primaryField = config.columns?.[0]?.field;
|
|
26
|
-
const secondaryFields = config.columns?.slice(1, 3) || [];
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<TouchableOpacity style={styles.card} onPress={() => onPress?.(item)} activeOpacity={0.7}>
|
|
30
|
-
<Text style={styles.primary}>
|
|
31
|
-
{primaryField ? item[primaryField] : JSON.stringify(item)}
|
|
32
|
-
</Text>
|
|
33
|
-
{secondaryFields.map(col => (
|
|
34
|
-
<Text key={col.field} style={styles.secondary}>
|
|
35
|
-
{col.header ? `${col.header}: ` : ''}{item[col.field]}
|
|
36
|
-
</Text>
|
|
37
|
-
))}
|
|
38
|
-
</TouchableOpacity>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function NativeGrid({
|
|
43
|
-
config = {},
|
|
44
|
-
data = [],
|
|
45
|
-
loading = false,
|
|
46
|
-
onRefresh,
|
|
47
|
-
onEndReached,
|
|
48
|
-
onRowPress,
|
|
49
|
-
renderItem: renderItemProp,
|
|
50
|
-
keyExtractor,
|
|
51
|
-
}) {
|
|
52
|
-
const [refreshing, setRefreshing] = useState(false);
|
|
53
|
-
|
|
54
|
-
const handleRefresh = useCallback(async () => {
|
|
55
|
-
if (!onRefresh) return;
|
|
56
|
-
setRefreshing(true);
|
|
57
|
-
try { await onRefresh(); } finally { setRefreshing(false); }
|
|
58
|
-
}, [onRefresh]);
|
|
59
|
-
|
|
60
|
-
const defaultKeyExtractor = useCallback((item) => {
|
|
61
|
-
return item.id?.toString() || item._id?.toString() || JSON.stringify(item);
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
const renderItem = useCallback(({ item }) => {
|
|
65
|
-
if (renderItemProp) return renderItemProp({ item, config });
|
|
66
|
-
return <DefaultRowCard item={item} config={config} onPress={onRowPress} />;
|
|
67
|
-
}, [config, onRowPress, renderItemProp]);
|
|
68
|
-
|
|
69
|
-
if (!loading && data.length === 0) {
|
|
70
|
-
return (
|
|
71
|
-
<View style={styles.empty}>
|
|
72
|
-
<Text style={styles.emptyText}>{config.emptyMessage || 'No items found'}</Text>
|
|
73
|
-
</View>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<FlatList
|
|
79
|
-
style={styles.container}
|
|
80
|
-
data={data}
|
|
81
|
-
renderItem={renderItem}
|
|
82
|
-
keyExtractor={keyExtractor || defaultKeyExtractor}
|
|
83
|
-
refreshControl={
|
|
84
|
-
onRefresh ? <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} /> : undefined
|
|
85
|
-
}
|
|
86
|
-
onEndReached={onEndReached}
|
|
87
|
-
onEndReachedThreshold={0.5}
|
|
88
|
-
/>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { FlatList, View, Text, StyleSheet, RefreshControl, TouchableOpacity } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const styles = StyleSheet.create({
|
|
5
|
+
container: { flex: 1, backgroundColor: '#fff' },
|
|
6
|
+
card: {
|
|
7
|
+
padding: 16,
|
|
8
|
+
marginHorizontal: 12,
|
|
9
|
+
marginVertical: 6,
|
|
10
|
+
backgroundColor: '#fff',
|
|
11
|
+
borderRadius: 8,
|
|
12
|
+
shadowColor: '#000',
|
|
13
|
+
shadowOffset: { width: 0, height: 1 },
|
|
14
|
+
shadowOpacity: 0.1,
|
|
15
|
+
shadowRadius: 2,
|
|
16
|
+
elevation: 2,
|
|
17
|
+
},
|
|
18
|
+
primary: { fontSize: 16, fontWeight: '600', color: '#1a1a1a' },
|
|
19
|
+
secondary: { fontSize: 14, color: '#666', marginTop: 2 },
|
|
20
|
+
empty: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 40 },
|
|
21
|
+
emptyText: { fontSize: 16, color: '#999' },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function DefaultRowCard({ item, config, onPress }) {
|
|
25
|
+
const primaryField = config.columns?.[0]?.field;
|
|
26
|
+
const secondaryFields = config.columns?.slice(1, 3) || [];
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<TouchableOpacity style={styles.card} onPress={() => onPress?.(item)} activeOpacity={0.7}>
|
|
30
|
+
<Text style={styles.primary}>
|
|
31
|
+
{primaryField ? item[primaryField] : JSON.stringify(item)}
|
|
32
|
+
</Text>
|
|
33
|
+
{secondaryFields.map(col => (
|
|
34
|
+
<Text key={col.field} style={styles.secondary}>
|
|
35
|
+
{col.header ? `${col.header}: ` : ''}{item[col.field]}
|
|
36
|
+
</Text>
|
|
37
|
+
))}
|
|
38
|
+
</TouchableOpacity>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function NativeGrid({
|
|
43
|
+
config = {},
|
|
44
|
+
data = [],
|
|
45
|
+
loading = false,
|
|
46
|
+
onRefresh,
|
|
47
|
+
onEndReached,
|
|
48
|
+
onRowPress,
|
|
49
|
+
renderItem: renderItemProp,
|
|
50
|
+
keyExtractor,
|
|
51
|
+
}) {
|
|
52
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
53
|
+
|
|
54
|
+
const handleRefresh = useCallback(async () => {
|
|
55
|
+
if (!onRefresh) return;
|
|
56
|
+
setRefreshing(true);
|
|
57
|
+
try { await onRefresh(); } finally { setRefreshing(false); }
|
|
58
|
+
}, [onRefresh]);
|
|
59
|
+
|
|
60
|
+
const defaultKeyExtractor = useCallback((item) => {
|
|
61
|
+
return item.id?.toString() || item._id?.toString() || JSON.stringify(item);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const renderItem = useCallback(({ item }) => {
|
|
65
|
+
if (renderItemProp) return renderItemProp({ item, config });
|
|
66
|
+
return <DefaultRowCard item={item} config={config} onPress={onRowPress} />;
|
|
67
|
+
}, [config, onRowPress, renderItemProp]);
|
|
68
|
+
|
|
69
|
+
if (!loading && data.length === 0) {
|
|
70
|
+
return (
|
|
71
|
+
<View style={styles.empty}>
|
|
72
|
+
<Text style={styles.emptyText}>{config.emptyMessage || 'No items found'}</Text>
|
|
73
|
+
</View>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<FlatList
|
|
79
|
+
style={styles.container}
|
|
80
|
+
data={data}
|
|
81
|
+
renderItem={renderItem}
|
|
82
|
+
keyExtractor={keyExtractor || defaultKeyExtractor}
|
|
83
|
+
refreshControl={
|
|
84
|
+
onRefresh ? <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} /> : undefined
|
|
85
|
+
}
|
|
86
|
+
onEndReached={onEndReached}
|
|
87
|
+
onEndReachedThreshold={0.5}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NativeJsonGrid
|
|
3
|
-
*
|
|
4
|
-
* Grid component for NativeJsonView with selection, pull-to-refresh,
|
|
5
|
-
* load-more pagination, selected row highlight, and long-press actions.
|
|
6
|
-
*/
|
|
7
|
-
import React, { useState, useCallback } from 'react';
|
|
8
|
-
import {
|
|
9
|
-
FlatList, View, Text, StyleSheet, RefreshControl,
|
|
10
|
-
TouchableOpacity, ActivityIndicator, ActionSheetIOS, Platform, Alert
|
|
11
|
-
} from 'react-native';
|
|
12
|
-
import Ionicons from '@expo/vector-icons/Ionicons';
|
|
13
|
-
|
|
14
|
-
function showActionSheet(options, onSelect) {
|
|
15
|
-
if (Platform.OS === 'ios') {
|
|
16
|
-
ActionSheetIOS.showActionSheetWithOptions(
|
|
17
|
-
{
|
|
18
|
-
options: [...options.map(o => o.label), 'Cancel'],
|
|
19
|
-
destructiveButtonIndex: options.findIndex(o => o.destructive),
|
|
20
|
-
cancelButtonIndex: options.length,
|
|
21
|
-
},
|
|
22
|
-
(buttonIndex) => {
|
|
23
|
-
if (buttonIndex < options.length) {
|
|
24
|
-
options[buttonIndex].onPress();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
} else {
|
|
29
|
-
// Android: use Alert as a simple action sheet
|
|
30
|
-
Alert.alert(
|
|
31
|
-
'Actions',
|
|
32
|
-
undefined,
|
|
33
|
-
[
|
|
34
|
-
...options.map(o => ({
|
|
35
|
-
text: o.label,
|
|
36
|
-
style: o.destructive ? 'destructive' : 'default',
|
|
37
|
-
onPress: o.onPress,
|
|
38
|
-
})),
|
|
39
|
-
{ text: 'Cancel', style: 'cancel' },
|
|
40
|
-
]
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function RowCard({ item, config, selected, onPress, onLongPress }) {
|
|
46
|
-
const primaryField = config?.columns?.[0]?.field;
|
|
47
|
-
const secondaryFields = config?.columns?.slice(1, 3) || [];
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<TouchableOpacity
|
|
51
|
-
style={[styles.card, selected && styles.cardSelected]}
|
|
52
|
-
onPress={() => onPress?.(item)}
|
|
53
|
-
onLongPress={() => onLongPress?.(item)}
|
|
54
|
-
activeOpacity={0.7}
|
|
55
|
-
>
|
|
56
|
-
<View style={styles.cardContent}>
|
|
57
|
-
<View style={styles.cardText}>
|
|
58
|
-
<Text style={styles.primary} numberOfLines={1}>
|
|
59
|
-
{primaryField ? item[primaryField] : (item.name || item.title || JSON.stringify(item))}
|
|
60
|
-
</Text>
|
|
61
|
-
{secondaryFields.map(col => (
|
|
62
|
-
<Text key={col.field} style={styles.secondary} numberOfLines={1}>
|
|
63
|
-
{col.header ? `${col.header}: ` : ''}{item[col.field] != null ? String(item[col.field]) : ''}
|
|
64
|
-
</Text>
|
|
65
|
-
))}
|
|
66
|
-
</View>
|
|
67
|
-
<Ionicons name="chevron-forward" size={18} color="#999" />
|
|
68
|
-
</View>
|
|
69
|
-
</TouchableOpacity>
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function NativeJsonGrid({
|
|
74
|
-
config = {},
|
|
75
|
-
data = [],
|
|
76
|
-
loading = false,
|
|
77
|
-
selectedId,
|
|
78
|
-
hasMore = false,
|
|
79
|
-
onRowPress,
|
|
80
|
-
onRefresh,
|
|
81
|
-
onEndReached,
|
|
82
|
-
onEdit,
|
|
83
|
-
onDelete,
|
|
84
|
-
}) {
|
|
85
|
-
const [refreshing, setRefreshing] = useState(false);
|
|
86
|
-
|
|
87
|
-
const handleRefresh = useCallback(async () => {
|
|
88
|
-
if (!onRefresh) return;
|
|
89
|
-
setRefreshing(true);
|
|
90
|
-
try { await onRefresh(); } finally { setRefreshing(false); }
|
|
91
|
-
}, [onRefresh]);
|
|
92
|
-
|
|
93
|
-
const handleLongPress = useCallback((item) => {
|
|
94
|
-
const options = [];
|
|
95
|
-
if (onEdit) {
|
|
96
|
-
options.push({ label: 'Edit', onPress: () => onEdit(item) });
|
|
97
|
-
}
|
|
98
|
-
if (onDelete) {
|
|
99
|
-
options.push({ label: 'Delete', destructive: true, onPress: () => onDelete(item) });
|
|
100
|
-
}
|
|
101
|
-
if (options.length > 0) {
|
|
102
|
-
showActionSheet(options, () => {});
|
|
103
|
-
}
|
|
104
|
-
}, [onEdit, onDelete]);
|
|
105
|
-
|
|
106
|
-
const keyExtractor = useCallback((item) => {
|
|
107
|
-
return item.id?.toString() || item._id?.toString() || JSON.stringify(item);
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
const renderItem = useCallback(({ item }) => {
|
|
111
|
-
return (
|
|
112
|
-
<RowCard
|
|
113
|
-
item={item}
|
|
114
|
-
config={config}
|
|
115
|
-
selected={item.id === selectedId}
|
|
116
|
-
onPress={onRowPress}
|
|
117
|
-
onLongPress={handleLongPress}
|
|
118
|
-
/>
|
|
119
|
-
);
|
|
120
|
-
}, [config, selectedId, onRowPress, handleLongPress]);
|
|
121
|
-
|
|
122
|
-
const renderFooter = useCallback(() => {
|
|
123
|
-
if (!loading || refreshing) return null;
|
|
124
|
-
return (
|
|
125
|
-
<View style={styles.footer}>
|
|
126
|
-
<ActivityIndicator size="small" color="#1b5e20" />
|
|
127
|
-
</View>
|
|
128
|
-
);
|
|
129
|
-
}, [loading, refreshing]);
|
|
130
|
-
|
|
131
|
-
if (!loading && data.length === 0) {
|
|
132
|
-
return (
|
|
133
|
-
<View style={styles.empty}>
|
|
134
|
-
<Ionicons name="file-tray-outline" size={48} color="#ccc" />
|
|
135
|
-
<Text style={styles.emptyText}>{config.emptyMessage || 'No items found'}</Text>
|
|
136
|
-
</View>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<FlatList
|
|
142
|
-
style={styles.container}
|
|
143
|
-
data={data}
|
|
144
|
-
renderItem={renderItem}
|
|
145
|
-
keyExtractor={keyExtractor}
|
|
146
|
-
refreshControl={
|
|
147
|
-
onRefresh
|
|
148
|
-
? <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor="#1b5e20" />
|
|
149
|
-
: undefined
|
|
150
|
-
}
|
|
151
|
-
onEndReached={hasMore ? onEndReached : undefined}
|
|
152
|
-
onEndReachedThreshold={0.5}
|
|
153
|
-
ListFooterComponent={renderFooter}
|
|
154
|
-
/>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const styles = StyleSheet.create({
|
|
159
|
-
container: {
|
|
160
|
-
flex: 1,
|
|
161
|
-
backgroundColor: '#f5f5f5',
|
|
162
|
-
},
|
|
163
|
-
card: {
|
|
164
|
-
padding: 16,
|
|
165
|
-
marginHorizontal: 12,
|
|
166
|
-
marginVertical: 6,
|
|
167
|
-
backgroundColor: '#fff',
|
|
168
|
-
borderRadius: 8,
|
|
169
|
-
shadowColor: '#000',
|
|
170
|
-
shadowOffset: { width: 0, height: 1 },
|
|
171
|
-
shadowOpacity: 0.1,
|
|
172
|
-
shadowRadius: 2,
|
|
173
|
-
elevation: 2,
|
|
174
|
-
},
|
|
175
|
-
cardSelected: {
|
|
176
|
-
borderLeftWidth: 4,
|
|
177
|
-
borderLeftColor: '#1b5e20',
|
|
178
|
-
},
|
|
179
|
-
cardContent: {
|
|
180
|
-
flexDirection: 'row',
|
|
181
|
-
alignItems: 'center',
|
|
182
|
-
},
|
|
183
|
-
cardText: {
|
|
184
|
-
flex: 1,
|
|
185
|
-
},
|
|
186
|
-
primary: {
|
|
187
|
-
fontSize: 16,
|
|
188
|
-
fontWeight: '600',
|
|
189
|
-
color: '#1a1a1a',
|
|
190
|
-
},
|
|
191
|
-
secondary: {
|
|
192
|
-
fontSize: 14,
|
|
193
|
-
color: '#666',
|
|
194
|
-
marginTop: 2,
|
|
195
|
-
},
|
|
196
|
-
empty: {
|
|
197
|
-
flex: 1,
|
|
198
|
-
justifyContent: 'center',
|
|
199
|
-
alignItems: 'center',
|
|
200
|
-
padding: 40,
|
|
201
|
-
},
|
|
202
|
-
emptyText: {
|
|
203
|
-
fontSize: 16,
|
|
204
|
-
color: '#999',
|
|
205
|
-
marginTop: 12,
|
|
206
|
-
},
|
|
207
|
-
footer: {
|
|
208
|
-
paddingVertical: 16,
|
|
209
|
-
alignItems: 'center',
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
export default NativeJsonGrid;
|
|
1
|
+
/**
|
|
2
|
+
* NativeJsonGrid
|
|
3
|
+
*
|
|
4
|
+
* Grid component for NativeJsonView with selection, pull-to-refresh,
|
|
5
|
+
* load-more pagination, selected row highlight, and long-press actions.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useState, useCallback } from 'react';
|
|
8
|
+
import {
|
|
9
|
+
FlatList, View, Text, StyleSheet, RefreshControl,
|
|
10
|
+
TouchableOpacity, ActivityIndicator, ActionSheetIOS, Platform, Alert
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import Ionicons from '@expo/vector-icons/Ionicons';
|
|
13
|
+
|
|
14
|
+
function showActionSheet(options, onSelect) {
|
|
15
|
+
if (Platform.OS === 'ios') {
|
|
16
|
+
ActionSheetIOS.showActionSheetWithOptions(
|
|
17
|
+
{
|
|
18
|
+
options: [...options.map(o => o.label), 'Cancel'],
|
|
19
|
+
destructiveButtonIndex: options.findIndex(o => o.destructive),
|
|
20
|
+
cancelButtonIndex: options.length,
|
|
21
|
+
},
|
|
22
|
+
(buttonIndex) => {
|
|
23
|
+
if (buttonIndex < options.length) {
|
|
24
|
+
options[buttonIndex].onPress();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
// Android: use Alert as a simple action sheet
|
|
30
|
+
Alert.alert(
|
|
31
|
+
'Actions',
|
|
32
|
+
undefined,
|
|
33
|
+
[
|
|
34
|
+
...options.map(o => ({
|
|
35
|
+
text: o.label,
|
|
36
|
+
style: o.destructive ? 'destructive' : 'default',
|
|
37
|
+
onPress: o.onPress,
|
|
38
|
+
})),
|
|
39
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
40
|
+
]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function RowCard({ item, config, selected, onPress, onLongPress }) {
|
|
46
|
+
const primaryField = config?.columns?.[0]?.field;
|
|
47
|
+
const secondaryFields = config?.columns?.slice(1, 3) || [];
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<TouchableOpacity
|
|
51
|
+
style={[styles.card, selected && styles.cardSelected]}
|
|
52
|
+
onPress={() => onPress?.(item)}
|
|
53
|
+
onLongPress={() => onLongPress?.(item)}
|
|
54
|
+
activeOpacity={0.7}
|
|
55
|
+
>
|
|
56
|
+
<View style={styles.cardContent}>
|
|
57
|
+
<View style={styles.cardText}>
|
|
58
|
+
<Text style={styles.primary} numberOfLines={1}>
|
|
59
|
+
{primaryField ? item[primaryField] : (item.name || item.title || JSON.stringify(item))}
|
|
60
|
+
</Text>
|
|
61
|
+
{secondaryFields.map(col => (
|
|
62
|
+
<Text key={col.field} style={styles.secondary} numberOfLines={1}>
|
|
63
|
+
{col.header ? `${col.header}: ` : ''}{item[col.field] != null ? String(item[col.field]) : ''}
|
|
64
|
+
</Text>
|
|
65
|
+
))}
|
|
66
|
+
</View>
|
|
67
|
+
<Ionicons name="chevron-forward" size={18} color="#999" />
|
|
68
|
+
</View>
|
|
69
|
+
</TouchableOpacity>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function NativeJsonGrid({
|
|
74
|
+
config = {},
|
|
75
|
+
data = [],
|
|
76
|
+
loading = false,
|
|
77
|
+
selectedId,
|
|
78
|
+
hasMore = false,
|
|
79
|
+
onRowPress,
|
|
80
|
+
onRefresh,
|
|
81
|
+
onEndReached,
|
|
82
|
+
onEdit,
|
|
83
|
+
onDelete,
|
|
84
|
+
}) {
|
|
85
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
86
|
+
|
|
87
|
+
const handleRefresh = useCallback(async () => {
|
|
88
|
+
if (!onRefresh) return;
|
|
89
|
+
setRefreshing(true);
|
|
90
|
+
try { await onRefresh(); } finally { setRefreshing(false); }
|
|
91
|
+
}, [onRefresh]);
|
|
92
|
+
|
|
93
|
+
const handleLongPress = useCallback((item) => {
|
|
94
|
+
const options = [];
|
|
95
|
+
if (onEdit) {
|
|
96
|
+
options.push({ label: 'Edit', onPress: () => onEdit(item) });
|
|
97
|
+
}
|
|
98
|
+
if (onDelete) {
|
|
99
|
+
options.push({ label: 'Delete', destructive: true, onPress: () => onDelete(item) });
|
|
100
|
+
}
|
|
101
|
+
if (options.length > 0) {
|
|
102
|
+
showActionSheet(options, () => {});
|
|
103
|
+
}
|
|
104
|
+
}, [onEdit, onDelete]);
|
|
105
|
+
|
|
106
|
+
const keyExtractor = useCallback((item) => {
|
|
107
|
+
return item.id?.toString() || item._id?.toString() || JSON.stringify(item);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const renderItem = useCallback(({ item }) => {
|
|
111
|
+
return (
|
|
112
|
+
<RowCard
|
|
113
|
+
item={item}
|
|
114
|
+
config={config}
|
|
115
|
+
selected={item.id === selectedId}
|
|
116
|
+
onPress={onRowPress}
|
|
117
|
+
onLongPress={handleLongPress}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}, [config, selectedId, onRowPress, handleLongPress]);
|
|
121
|
+
|
|
122
|
+
const renderFooter = useCallback(() => {
|
|
123
|
+
if (!loading || refreshing) return null;
|
|
124
|
+
return (
|
|
125
|
+
<View style={styles.footer}>
|
|
126
|
+
<ActivityIndicator size="small" color="#1b5e20" />
|
|
127
|
+
</View>
|
|
128
|
+
);
|
|
129
|
+
}, [loading, refreshing]);
|
|
130
|
+
|
|
131
|
+
if (!loading && data.length === 0) {
|
|
132
|
+
return (
|
|
133
|
+
<View style={styles.empty}>
|
|
134
|
+
<Ionicons name="file-tray-outline" size={48} color="#ccc" />
|
|
135
|
+
<Text style={styles.emptyText}>{config.emptyMessage || 'No items found'}</Text>
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<FlatList
|
|
142
|
+
style={styles.container}
|
|
143
|
+
data={data}
|
|
144
|
+
renderItem={renderItem}
|
|
145
|
+
keyExtractor={keyExtractor}
|
|
146
|
+
refreshControl={
|
|
147
|
+
onRefresh
|
|
148
|
+
? <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor="#1b5e20" />
|
|
149
|
+
: undefined
|
|
150
|
+
}
|
|
151
|
+
onEndReached={hasMore ? onEndReached : undefined}
|
|
152
|
+
onEndReachedThreshold={0.5}
|
|
153
|
+
ListFooterComponent={renderFooter}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const styles = StyleSheet.create({
|
|
159
|
+
container: {
|
|
160
|
+
flex: 1,
|
|
161
|
+
backgroundColor: '#f5f5f5',
|
|
162
|
+
},
|
|
163
|
+
card: {
|
|
164
|
+
padding: 16,
|
|
165
|
+
marginHorizontal: 12,
|
|
166
|
+
marginVertical: 6,
|
|
167
|
+
backgroundColor: '#fff',
|
|
168
|
+
borderRadius: 8,
|
|
169
|
+
shadowColor: '#000',
|
|
170
|
+
shadowOffset: { width: 0, height: 1 },
|
|
171
|
+
shadowOpacity: 0.1,
|
|
172
|
+
shadowRadius: 2,
|
|
173
|
+
elevation: 2,
|
|
174
|
+
},
|
|
175
|
+
cardSelected: {
|
|
176
|
+
borderLeftWidth: 4,
|
|
177
|
+
borderLeftColor: '#1b5e20',
|
|
178
|
+
},
|
|
179
|
+
cardContent: {
|
|
180
|
+
flexDirection: 'row',
|
|
181
|
+
alignItems: 'center',
|
|
182
|
+
},
|
|
183
|
+
cardText: {
|
|
184
|
+
flex: 1,
|
|
185
|
+
},
|
|
186
|
+
primary: {
|
|
187
|
+
fontSize: 16,
|
|
188
|
+
fontWeight: '600',
|
|
189
|
+
color: '#1a1a1a',
|
|
190
|
+
},
|
|
191
|
+
secondary: {
|
|
192
|
+
fontSize: 14,
|
|
193
|
+
color: '#666',
|
|
194
|
+
marginTop: 2,
|
|
195
|
+
},
|
|
196
|
+
empty: {
|
|
197
|
+
flex: 1,
|
|
198
|
+
justifyContent: 'center',
|
|
199
|
+
alignItems: 'center',
|
|
200
|
+
padding: 40,
|
|
201
|
+
},
|
|
202
|
+
emptyText: {
|
|
203
|
+
fontSize: 16,
|
|
204
|
+
color: '#999',
|
|
205
|
+
marginTop: 12,
|
|
206
|
+
},
|
|
207
|
+
footer: {
|
|
208
|
+
paddingVertical: 16,
|
|
209
|
+
alignItems: 'center',
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
export default NativeJsonGrid;
|