@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.
Files changed (160) hide show
  1. package/dist/index.js +6 -0
  2. package/dist/index.js.map +7 -0
  3. package/dist/native/index.js +2522 -0
  4. package/dist/native/index.js.map +7 -0
  5. package/dist/server/index.js +2776 -0
  6. package/dist/server/index.js.map +7 -0
  7. package/dist/server/workflow/index.js +537 -0
  8. package/dist/server/workflow/index.js.map +7 -0
  9. package/dist/shared/index.js +62 -0
  10. package/dist/shared/index.js.map +7 -0
  11. package/dist/web/index.js +7323 -0
  12. package/dist/web/index.js.map +7 -0
  13. package/package.json +81 -0
  14. package/schemas/Workflow.json +14 -0
  15. package/schemas/WorkflowHistory.json +22 -0
  16. package/schemas/WorkflowInstance.json +16 -0
  17. package/schemas/WorkflowState.json +18 -0
  18. package/schemas/WorkflowTransition.json +27 -0
  19. package/src/index.js +8 -0
  20. package/src/native/components/NativeAuthProvider.jsx +249 -0
  21. package/src/native/components/NativeDetail.jsx +270 -0
  22. package/src/native/components/NativeForm.jsx +543 -0
  23. package/src/native/components/NativeGrid.jsx +90 -0
  24. package/src/native/components/NativeJsonGrid.jsx +213 -0
  25. package/src/native/components/NativeJsonView.jsx +454 -0
  26. package/src/native/components/NativeJsonViewContext.js +17 -0
  27. package/src/native/components/NativeShell.jsx +68 -0
  28. package/src/native/components/NativeViewComponent.jsx +351 -0
  29. package/src/native/extensions/NativeExtensionRegistry.js +81 -0
  30. package/src/native/hooks/useNativeStore.js +72 -0
  31. package/src/native/index.js +15 -0
  32. package/src/native/layouts/NativeStackLayout.jsx +30 -0
  33. package/src/native/layouts/NativeTabLayout.jsx +96 -0
  34. package/src/native/storage.js +13 -0
  35. package/src/native/stores/NativeBaseStore.js +348 -0
  36. package/src/native/stores/NativeStoreContext.jsx +53 -0
  37. package/src/server/ai/capabilities-routes.js +106 -0
  38. package/src/server/ai/index.js +1 -0
  39. package/src/server/cache/MemoryCache.js +153 -0
  40. package/src/server/cache/index.js +2 -0
  41. package/src/server/cache/middleware.js +12 -0
  42. package/src/server/db/index.js +14 -0
  43. package/src/server/db/mongo.js +137 -0
  44. package/src/server/db/postgres.js +144 -0
  45. package/src/server/index.js +38 -0
  46. package/src/server/middleware/auth.js +682 -0
  47. package/src/server/middleware/can-flags.js +132 -0
  48. package/src/server/middleware/entityRoles.js +105 -0
  49. package/src/server/middleware/index.js +58 -0
  50. package/src/server/middleware/permissions.js +240 -0
  51. package/src/server/middleware/tenant.js +203 -0
  52. package/src/server/realtime/EventBus.js +45 -0
  53. package/src/server/realtime/WebSocketServer.js +105 -0
  54. package/src/server/realtime/index.js +3 -0
  55. package/src/server/realtime/middleware.js +18 -0
  56. package/src/server/services/email-templates.js +157 -0
  57. package/src/server/services/email.js +78 -0
  58. package/src/server/services/index.js +15 -0
  59. package/src/server/services/storage.js +119 -0
  60. package/src/server/utils/index.js +16 -0
  61. package/src/server/utils/paginate.js +65 -0
  62. package/src/server/utils/query-builder.js +293 -0
  63. package/src/server/utils/route-loader.js +61 -0
  64. package/src/server/workflow/WorkflowEngine.js +494 -0
  65. package/src/server/workflow/index.js +2 -0
  66. package/src/server/workflow/workflow-routes.js +174 -0
  67. package/src/shared/index.js +10 -0
  68. package/src/shared/utils/field-accessor.js +108 -0
  69. package/src/shared/utils/index.js +7 -0
  70. package/src/shared/utils/validation-utils.js +83 -0
  71. package/src/web/components/AppRouter/AppRouter.jsx +130 -0
  72. package/src/web/components/AppRouter/index.js +1 -0
  73. package/src/web/components/AppShell/AppShell.jsx +101 -0
  74. package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -0
  75. package/src/web/components/AppShell/ShellConfig.js +53 -0
  76. package/src/web/components/AppShell/index.js +3 -0
  77. package/src/web/components/AuthProvider.jsx +426 -0
  78. package/src/web/components/CardList/CardList.jsx +272 -0
  79. package/src/web/components/CardList/index.js +2 -0
  80. package/src/web/components/DetailView/DetailView.jsx +281 -0
  81. package/src/web/components/DetailView/index.js +2 -0
  82. package/src/web/components/Form/Form.jsx +300 -0
  83. package/src/web/components/Form/FormField.jsx +226 -0
  84. package/src/web/components/Form/index.js +3 -0
  85. package/src/web/components/Grid/Grid.jsx +304 -0
  86. package/src/web/components/Grid/index.js +2 -0
  87. package/src/web/components/IconRegistry/IconRegistry.jsx +127 -0
  88. package/src/web/components/IconRegistry/index.js +1 -0
  89. package/src/web/components/JsonView/JsonView.jsx +647 -0
  90. package/src/web/components/JsonView/ViewComponent.jsx +1045 -0
  91. package/src/web/components/JsonView/ViewToolbar.jsx +141 -0
  92. package/src/web/components/JsonView/index.js +14 -0
  93. package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -0
  94. package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -0
  95. package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -0
  96. package/src/web/components/JsonView/layouts/index.js +8 -0
  97. package/src/web/components/Layout.jsx +265 -0
  98. package/src/web/components/MobileLayout/MobileLayout.jsx +385 -0
  99. package/src/web/components/MobileLayout/index.js +1 -0
  100. package/src/web/components/Navigation/Navigation.jsx +248 -0
  101. package/src/web/components/Navigation/index.js +1 -0
  102. package/src/web/components/NotificationProvider.jsx +55 -0
  103. package/src/web/components/Pagination/InfiniteScroll.jsx +82 -0
  104. package/src/web/components/Pagination/Pagination.jsx +73 -0
  105. package/src/web/components/Pagination/index.js +8 -0
  106. package/src/web/components/SimpleList/SimpleList.jsx +177 -0
  107. package/src/web/components/SimpleList/index.js +2 -0
  108. package/src/web/components/TenantProvider.jsx +121 -0
  109. package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -0
  110. package/src/web/components/WorkflowActions/index.js +1 -0
  111. package/src/web/components/WorkflowField/WorkflowField.jsx +176 -0
  112. package/src/web/components/WorkflowField/index.js +2 -0
  113. package/src/web/components/WorkflowField/workflowColors.js +32 -0
  114. package/src/web/components/auth/DevTenantSelector.jsx +90 -0
  115. package/src/web/components/auth/ForgotPasswordForm.jsx +94 -0
  116. package/src/web/components/auth/RegisterForm.jsx +168 -0
  117. package/src/web/components/auth/ResetPasswordForm.jsx +121 -0
  118. package/src/web/components/auth/VerifyEmailView.jsx +85 -0
  119. package/src/web/components/auth/index.js +5 -0
  120. package/src/web/components/index.js +39 -0
  121. package/src/web/components/layouts/CardListLayout.jsx +68 -0
  122. package/src/web/components/layouts/FullscreenLayout.jsx +30 -0
  123. package/src/web/components/layouts/MobileStackLayout.jsx +28 -0
  124. package/src/web/components/layouts/WizardLayout.jsx +86 -0
  125. package/src/web/components/layouts/index.js +4 -0
  126. package/src/web/components/mobile/Badge.jsx +105 -0
  127. package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -0
  128. package/src/web/components/mobile/EmptyState.jsx +30 -0
  129. package/src/web/components/mobile/QuickActionButton.jsx +77 -0
  130. package/src/web/components/mobile/ServerAutocomplete.jsx +123 -0
  131. package/src/web/components/mobile/StarRating.jsx +42 -0
  132. package/src/web/components/mobile/StatCard.jsx +65 -0
  133. package/src/web/components/mobile/index.js +7 -0
  134. package/src/web/extensions/ExtensionRegistry.js +79 -0
  135. package/src/web/extensions/index.js +7 -0
  136. package/src/web/hooks/index.js +15 -0
  137. package/src/web/hooks/useApi.js +76 -0
  138. package/src/web/hooks/useAuth.js +37 -0
  139. package/src/web/hooks/useDebouncedSave.js +158 -0
  140. package/src/web/hooks/useIsMobile.js +14 -0
  141. package/src/web/hooks/useOfflineQueue.js +99 -0
  142. package/src/web/hooks/useSelectionModel.js +143 -0
  143. package/src/web/hooks/useServerAutocomplete.js +146 -0
  144. package/src/web/hooks/useStore.js +107 -0
  145. package/src/web/hooks/useSubscription.js +130 -0
  146. package/src/web/hooks/useTenant.js +39 -0
  147. package/src/web/hooks/useTenantResolver.js +65 -0
  148. package/src/web/hooks/useUndoRedo.js +77 -0
  149. package/src/web/hooks/useViews.js +113 -0
  150. package/src/web/hooks/useWorkflow.js +190 -0
  151. package/src/web/index.js +117 -0
  152. package/src/web/stores/BaseStore.js +439 -0
  153. package/src/web/stores/StoreContext.jsx +93 -0
  154. package/src/web/stores/index.js +3 -0
  155. package/src/web/theme/index.js +3 -0
  156. package/src/web/theme/mui-theme.js +228 -0
  157. package/src/web/utils/formatTimeAgo.js +22 -0
  158. package/src/web/utils/index.js +1 -0
  159. package/src/web/views/ViewRegistry.js +235 -0
  160. package/src/web/views/index.js +2 -0
@@ -0,0 +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;
@@ -0,0 +1,454 @@
1
+ /**
2
+ * NativeJsonView
3
+ *
4
+ * Main orchestrator for JSON-declared views on React Native.
5
+ * Port of web JsonView — same reducer, same context shape, RN rendering.
6
+ */
7
+ import React, { useReducer, useEffect, useMemo, useCallback } from 'react';
8
+ import { View, Text, ActivityIndicator, StyleSheet } from 'react-native';
9
+ import { useNativeStore } from '../hooks/useNativeStore.js';
10
+ import { NativeStackLayout } from '../layouts/NativeStackLayout.jsx';
11
+ import { NativeTabLayout } from '../layouts/NativeTabLayout.jsx';
12
+ import { nativeExtensionRegistry } from '../extensions/NativeExtensionRegistry.js';
13
+ import { NativeJsonViewContext, useNativeJsonView } from './NativeJsonViewContext.js';
14
+
15
+ const ActionTypes = {
16
+ SET_SELECTION: 'SET_SELECTION',
17
+ CLEAR_SELECTION: 'CLEAR_SELECTION',
18
+ SET_EDIT_ITEM: 'SET_EDIT_ITEM',
19
+ CLEAR_EDIT_ITEM: 'CLEAR_EDIT_ITEM',
20
+ OPEN_DIALOG: 'OPEN_DIALOG',
21
+ CLOSE_DIALOG: 'CLOSE_DIALOG',
22
+ SET_COMPONENT_STATE: 'SET_COMPONENT_STATE',
23
+ SET_PAGINATION: 'SET_PAGINATION',
24
+ };
25
+
26
+ function getInitialPaginationState(paginationConfig) {
27
+ if (!paginationConfig || paginationConfig.mode === 'none') {
28
+ return null;
29
+ }
30
+ return {
31
+ mode: paginationConfig.mode || 'infinite',
32
+ page: 1,
33
+ pageSize: paginationConfig.pageSize || 25,
34
+ total: 0,
35
+ totalPages: 0,
36
+ hasNext: false,
37
+ hasPrev: false
38
+ };
39
+ }
40
+
41
+ const initialState = {
42
+ selections: {},
43
+ editItems: {},
44
+ dialogs: {},
45
+ componentStates: {},
46
+ pagination: null,
47
+ };
48
+
49
+ function viewReducer(state, action) {
50
+ switch (action.type) {
51
+ case ActionTypes.SET_SELECTION:
52
+ return {
53
+ ...state,
54
+ selections: { ...state.selections, [action.componentId]: action.data }
55
+ };
56
+
57
+ case ActionTypes.CLEAR_SELECTION:
58
+ return {
59
+ ...state,
60
+ selections: { ...state.selections, [action.componentId]: null }
61
+ };
62
+
63
+ case ActionTypes.SET_EDIT_ITEM:
64
+ return {
65
+ ...state,
66
+ editItems: { ...state.editItems, [action.componentId]: action.data }
67
+ };
68
+
69
+ case ActionTypes.CLEAR_EDIT_ITEM:
70
+ return {
71
+ ...state,
72
+ editItems: { ...state.editItems, [action.componentId]: null }
73
+ };
74
+
75
+ case ActionTypes.OPEN_DIALOG:
76
+ return {
77
+ ...state,
78
+ dialogs: { ...state.dialogs, [action.dialogId]: { open: true, data: action.data } }
79
+ };
80
+
81
+ case ActionTypes.CLOSE_DIALOG:
82
+ return {
83
+ ...state,
84
+ dialogs: { ...state.dialogs, [action.dialogId]: { open: false, data: null } }
85
+ };
86
+
87
+ case ActionTypes.SET_COMPONENT_STATE:
88
+ return {
89
+ ...state,
90
+ componentStates: {
91
+ ...state.componentStates,
92
+ [action.componentId]: {
93
+ ...state.componentStates[action.componentId],
94
+ ...action.state
95
+ }
96
+ }
97
+ };
98
+
99
+ case ActionTypes.SET_PAGINATION:
100
+ return {
101
+ ...state,
102
+ pagination: { ...state.pagination, ...action.pagination }
103
+ };
104
+
105
+ default:
106
+ return state;
107
+ }
108
+ }
109
+
110
+ const LAYOUTS = {
111
+ stack: NativeStackLayout,
112
+ tabs: NativeTabLayout,
113
+ single: NativeStackLayout,
114
+ split: NativeStackLayout,
115
+ };
116
+
117
+ function NativeJsonViewWithStore({ config, storeName }) {
118
+ const store = useNativeStore(storeName);
119
+
120
+ const {
121
+ id: viewId,
122
+ layout = 'stack',
123
+ layoutConfig = {},
124
+ dataSource = {},
125
+ components = [],
126
+ extension: extensionName
127
+ } = config || {};
128
+
129
+ // Get extension hook if specified
130
+ const useExtension = extensionName ? nativeExtensionRegistry.get(extensionName) : null;
131
+
132
+ const initialStateWithPagination = useMemo(() => ({
133
+ ...initialState,
134
+ pagination: getInitialPaginationState(dataSource?.pagination)
135
+ }), []);
136
+
137
+ const [viewState, dispatch] = useReducer(viewReducer, initialStateWithPagination);
138
+
139
+ const storeLoading = store.loading;
140
+ const storeError = store.error;
141
+ const storePagination = store.pagination;
142
+
143
+ const storeActions = useMemo(() => ({
144
+ list: store.list,
145
+ get: store.get,
146
+ create: store.create,
147
+ update: store.update,
148
+ delete: store.delete,
149
+ select: store.select,
150
+ clearSelection: store.clearSelection,
151
+ loadMore: store.loadMore,
152
+ setPageSize: store.setPageSize
153
+ }), [store]);
154
+
155
+ // Sync store pagination to view state
156
+ useEffect(() => {
157
+ if (viewState.pagination && storePagination) {
158
+ dispatch({
159
+ type: ActionTypes.SET_PAGINATION,
160
+ pagination: {
161
+ page: storePagination.page,
162
+ pageSize: storePagination.pageSize,
163
+ total: storePagination.total,
164
+ totalPages: storePagination.totalPages,
165
+ hasNext: storePagination.hasNext,
166
+ hasPrev: storePagination.hasPrev
167
+ }
168
+ });
169
+ }
170
+ }, [storePagination, viewState.pagination !== null]);
171
+
172
+ // Sync selections with store items after edits
173
+ const storeItems = store.items;
174
+ useEffect(() => {
175
+ if (!storeItems?.length) return;
176
+
177
+ Object.entries(viewState.selections).forEach(([componentId, selectedItem]) => {
178
+ if (!selectedItem?.id) return;
179
+
180
+ const updatedItem = storeItems.find(item => item.id === selectedItem.id);
181
+ if (updatedItem && updatedItem !== selectedItem) {
182
+ dispatch({
183
+ type: ActionTypes.SET_SELECTION,
184
+ componentId,
185
+ data: updatedItem
186
+ });
187
+ }
188
+ });
189
+ }, [storeItems]);
190
+
191
+ // Auto-load data on mount
192
+ useEffect(() => {
193
+ if (dataSource?.autoLoad) {
194
+ const loadOptions = {};
195
+ if (viewState.pagination) {
196
+ loadOptions.page = viewState.pagination.page;
197
+ loadOptions.pageSize = viewState.pagination.pageSize;
198
+ }
199
+ if (dataSource.sliceId) {
200
+ loadOptions.sliceId = dataSource.sliceId;
201
+ }
202
+ store.list(loadOptions);
203
+ }
204
+ }, []);
205
+
206
+ return (
207
+ <NativeJsonViewInner
208
+ config={config}
209
+ viewId={viewId}
210
+ layout={layout}
211
+ layoutConfig={layoutConfig}
212
+ dataSource={dataSource}
213
+ components={components}
214
+ viewState={viewState}
215
+ dispatch={dispatch}
216
+ storeData={store}
217
+ storeLoading={storeLoading}
218
+ storeError={storeError}
219
+ storeActions={storeActions}
220
+ useExtension={useExtension}
221
+ />
222
+ );
223
+ }
224
+
225
+ function NativeJsonViewWithoutStore({ config }) {
226
+ const [viewState, dispatch] = useReducer(viewReducer, initialState);
227
+
228
+ const {
229
+ id: viewId,
230
+ layout = 'stack',
231
+ layoutConfig = {},
232
+ dataSource = {},
233
+ components = [],
234
+ extension: extensionName
235
+ } = config || {};
236
+
237
+ const useExtension = extensionName ? nativeExtensionRegistry.get(extensionName) : null;
238
+
239
+ return (
240
+ <NativeJsonViewInner
241
+ config={config}
242
+ viewId={viewId}
243
+ layout={layout}
244
+ layoutConfig={layoutConfig}
245
+ dataSource={dataSource}
246
+ components={components}
247
+ viewState={viewState}
248
+ dispatch={dispatch}
249
+ storeData={null}
250
+ storeLoading={false}
251
+ storeError={null}
252
+ storeActions={{}}
253
+ useExtension={useExtension}
254
+ />
255
+ );
256
+ }
257
+
258
+ export function NativeJsonView({ config }) {
259
+ const storeName = config?.dataSource?.store;
260
+
261
+ if (storeName) {
262
+ return <NativeJsonViewWithStore config={config} storeName={storeName} />;
263
+ }
264
+ return <NativeJsonViewWithoutStore config={config} />;
265
+ }
266
+
267
+ function NativeJsonViewInner({
268
+ config,
269
+ viewId,
270
+ layout,
271
+ layoutConfig,
272
+ dataSource,
273
+ components,
274
+ viewState,
275
+ dispatch,
276
+ storeData,
277
+ storeLoading,
278
+ storeError,
279
+ storeActions,
280
+ useExtension,
281
+ }) {
282
+ const setSelection = useCallback((componentId, data) => {
283
+ dispatch({ type: ActionTypes.SET_SELECTION, componentId, data });
284
+ }, []);
285
+
286
+ const clearSelection = useCallback((componentId) => {
287
+ dispatch({ type: ActionTypes.CLEAR_SELECTION, componentId });
288
+ }, []);
289
+
290
+ const setEditItem = useCallback((componentId, data) => {
291
+ dispatch({ type: ActionTypes.SET_EDIT_ITEM, componentId, data });
292
+ }, []);
293
+
294
+ const clearEditItem = useCallback((componentId) => {
295
+ dispatch({ type: ActionTypes.CLEAR_EDIT_ITEM, componentId });
296
+ }, []);
297
+
298
+ const openDialog = useCallback((dialogId, data = null) => {
299
+ dispatch({ type: ActionTypes.OPEN_DIALOG, dialogId, data });
300
+ }, []);
301
+
302
+ const closeDialog = useCallback((dialogId) => {
303
+ dispatch({ type: ActionTypes.CLOSE_DIALOG, dialogId });
304
+ }, []);
305
+
306
+ const setComponentState = useCallback((componentId, state) => {
307
+ dispatch({ type: ActionTypes.SET_COMPONENT_STATE, componentId, state });
308
+ }, []);
309
+
310
+ const handleLoadMore = useCallback(() => {
311
+ storeActions.loadMore?.();
312
+ }, [storeActions]);
313
+
314
+ // Call extension hook if provided
315
+ const extensionContext = useMemo(() => ({
316
+ store: storeData,
317
+ storeActions,
318
+ viewState,
319
+ openDialog,
320
+ closeDialog,
321
+ setSelection,
322
+ setEditItem
323
+ }), [storeData, storeActions, viewState, openDialog, closeDialog, setSelection, setEditItem]);
324
+
325
+ const extension = useExtension ? useExtension(extensionContext) : null;
326
+ const extensionActions = extension?.actions || {};
327
+ const extensionComponents = extension?.components || {};
328
+
329
+ // Execute a custom action (from extension or server-side)
330
+ const executeCustomAction = useCallback(async (actionConfig, data) => {
331
+ if (actionConfig.handler && extensionActions[actionConfig.handler]) {
332
+ return extensionActions[actionConfig.handler](data);
333
+ }
334
+
335
+ if (actionConfig.serverAction) {
336
+ const endpoint = actionConfig.endpoint.replace(':id', data?.id);
337
+ const method = actionConfig.method || 'POST';
338
+
339
+ const response = await fetch(endpoint, {
340
+ method,
341
+ headers: { 'Content-Type': 'application/json' },
342
+ body: method !== 'GET' ? JSON.stringify(data) : undefined
343
+ });
344
+
345
+ if (!response.ok) {
346
+ throw new Error(`Server action failed: ${response.statusText}`);
347
+ }
348
+
349
+ if (actionConfig.refreshAfter !== false) {
350
+ storeActions.list?.(dataSource?.sliceId ? { sliceId: dataSource.sliceId } : undefined);
351
+ }
352
+
353
+ return response.json().catch(() => ({}));
354
+ }
355
+ }, [extensionActions, storeActions, dataSource?.sliceId]);
356
+
357
+ const contextValue = useMemo(() => ({
358
+ viewId,
359
+ config,
360
+ components,
361
+
362
+ viewState,
363
+ selections: viewState.selections,
364
+ editItems: viewState.editItems,
365
+ dialogs: viewState.dialogs,
366
+
367
+ pagination: viewState.pagination,
368
+ paginationConfig: dataSource?.pagination,
369
+ onLoadMore: handleLoadMore,
370
+
371
+ setSelection,
372
+ clearSelection,
373
+ setEditItem,
374
+ clearEditItem,
375
+ openDialog,
376
+ closeDialog,
377
+ setComponentState,
378
+
379
+ store: storeData,
380
+ storeActions,
381
+ items: storeData?.items || [],
382
+ loading: storeLoading,
383
+ error: storeError,
384
+
385
+ // Extension data
386
+ extension,
387
+ extensionActions,
388
+ extensionComponents,
389
+ executeCustomAction,
390
+ }), [
391
+ viewId,
392
+ config,
393
+ components,
394
+ viewState,
395
+ dataSource?.pagination,
396
+ storeData,
397
+ storeLoading,
398
+ storeError,
399
+ setSelection,
400
+ clearSelection,
401
+ setEditItem,
402
+ clearEditItem,
403
+ openDialog,
404
+ closeDialog,
405
+ setComponentState,
406
+ storeActions,
407
+ handleLoadMore,
408
+ extension,
409
+ extensionActions,
410
+ extensionComponents,
411
+ executeCustomAction,
412
+ ]);
413
+
414
+ if (storeError && !storeData?.items?.length) {
415
+ return (
416
+ <View style={styles.errorContainer}>
417
+ <Text style={styles.errorText}>{storeError}</Text>
418
+ </View>
419
+ );
420
+ }
421
+
422
+ const LayoutComponent = LAYOUTS[layout] || NativeStackLayout;
423
+
424
+ return (
425
+ <NativeJsonViewContext.Provider value={contextValue}>
426
+ <View style={styles.container}>
427
+ <LayoutComponent
428
+ config={layoutConfig}
429
+ components={components}
430
+ />
431
+ </View>
432
+ </NativeJsonViewContext.Provider>
433
+ );
434
+ }
435
+
436
+ const styles = StyleSheet.create({
437
+ container: {
438
+ flex: 1,
439
+ backgroundColor: '#f5f5f5',
440
+ },
441
+ errorContainer: {
442
+ flex: 1,
443
+ justifyContent: 'center',
444
+ alignItems: 'center',
445
+ padding: 24,
446
+ },
447
+ errorText: {
448
+ fontSize: 16,
449
+ color: '#d32f2f',
450
+ textAlign: 'center',
451
+ },
452
+ });
453
+
454
+ export default NativeJsonView;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * NativeJsonViewContext
3
+ *
4
+ * Extracted from NativeJsonView to break the require cycle:
5
+ * NativeJsonView → NativeStackLayout → NativeViewComponent → NativeJsonView
6
+ */
7
+ import { createContext, useContext } from 'react';
8
+
9
+ export const NativeJsonViewContext = createContext(null);
10
+
11
+ export function useNativeJsonView() {
12
+ const context = useContext(NativeJsonViewContext);
13
+ if (!context) {
14
+ throw new Error('useNativeJsonView must be used within a NativeJsonView');
15
+ }
16
+ return context;
17
+ }