@object-ui/react 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +21 -1
  3. package/dist/context/AppShellContext.d.ts +26 -0
  4. package/dist/context/AppShellContext.js +67 -0
  5. package/dist/context/index.d.ts +1 -7
  6. package/dist/context/index.js +1 -7
  7. package/package.json +32 -9
  8. package/.turbo/turbo-build.log +0 -4
  9. package/src/LazyPluginLoader.tsx +0 -174
  10. package/src/SchemaRenderer.tsx +0 -266
  11. package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
  12. package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
  13. package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
  14. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
  15. package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
  16. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
  17. package/src/__tests__/ThemeProvider.test.tsx +0 -451
  18. package/src/__tests__/useNavigationOverlay.test.ts +0 -578
  19. package/src/__tests__/useOffline.test.ts +0 -198
  20. package/src/__tests__/usePageTransition.test.ts +0 -214
  21. package/src/__tests__/usePageVariables.test.tsx +0 -334
  22. package/src/__tests__/usePerformance.test.ts +0 -137
  23. package/src/__tests__/useViewData.test.tsx +0 -422
  24. package/src/__tests__/view-switching.test.tsx +0 -456
  25. package/src/components/form/FieldFactory.tsx +0 -516
  26. package/src/components/form/FormRenderer.test.tsx +0 -744
  27. package/src/components/form/FormRenderer.tsx +0 -258
  28. package/src/components/form/README.md +0 -352
  29. package/src/components/form/index.ts +0 -12
  30. package/src/context/ActionContext.tsx +0 -213
  31. package/src/context/DndContext.tsx +0 -260
  32. package/src/context/NotificationContext.tsx +0 -280
  33. package/src/context/SchemaRendererContext.tsx +0 -48
  34. package/src/context/ThemeContext.tsx +0 -325
  35. package/src/context/__tests__/ActionContext.test.tsx +0 -174
  36. package/src/context/__tests__/DndContext.test.tsx +0 -150
  37. package/src/context/__tests__/NotificationContext.test.tsx +0 -176
  38. package/src/context/__tests__/useDataScope.test.tsx +0 -91
  39. package/src/context/index.ts +0 -13
  40. package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
  41. package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
  42. package/src/hooks/__tests__/useAnimation.test.ts +0 -82
  43. package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
  44. package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
  45. package/src/hooks/__tests__/useDataRefresh.test.ts +0 -115
  46. package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
  47. package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
  48. package/src/hooks/__tests__/useDiscovery.test.tsx +0 -247
  49. package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
  50. package/src/hooks/__tests__/useETagCache.test.ts +0 -153
  51. package/src/hooks/__tests__/useExpression.test.ts +0 -86
  52. package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
  53. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
  54. package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
  55. package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
  56. package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
  57. package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
  58. package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
  59. package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
  60. package/src/hooks/index.ts +0 -36
  61. package/src/hooks/useActionEngine.ts +0 -84
  62. package/src/hooks/useActionRunner.ts +0 -119
  63. package/src/hooks/useAnimation.ts +0 -117
  64. package/src/hooks/useClientNotifications.ts +0 -251
  65. package/src/hooks/useColumnSummary.ts +0 -87
  66. package/src/hooks/useCrudShortcuts.ts +0 -126
  67. package/src/hooks/useDataRefresh.ts +0 -58
  68. package/src/hooks/useDebugMode.ts +0 -95
  69. package/src/hooks/useDensityMode.ts +0 -102
  70. package/src/hooks/useDiscovery.ts +0 -168
  71. package/src/hooks/useDynamicApp.ts +0 -142
  72. package/src/hooks/useETagCache.ts +0 -404
  73. package/src/hooks/useExpression.ts +0 -56
  74. package/src/hooks/useFocusManagement.ts +0 -248
  75. package/src/hooks/useFocusTrap.ts +0 -138
  76. package/src/hooks/useGlobalUndo.ts +0 -98
  77. package/src/hooks/useKeyboardShortcuts.ts +0 -119
  78. package/src/hooks/useNavigationOverlay.ts +0 -190
  79. package/src/hooks/useOffline.ts +0 -301
  80. package/src/hooks/usePageTransition.ts +0 -187
  81. package/src/hooks/usePageVariables.tsx +0 -157
  82. package/src/hooks/usePerformance.ts +0 -246
  83. package/src/hooks/usePerformanceBudget.ts +0 -313
  84. package/src/hooks/useReducedMotion.ts +0 -53
  85. package/src/hooks/useSchemaPersistence.ts +0 -222
  86. package/src/hooks/useViewData.ts +0 -201
  87. package/src/hooks/useViewSharing.ts +0 -140
  88. package/src/hooks/useViewTransition.ts +0 -144
  89. package/src/index.ts +0 -41
  90. package/src/spec-bridge/SpecBridge.ts +0 -64
  91. package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
  92. package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
  93. package/src/spec-bridge/bridges/dashboard.ts +0 -180
  94. package/src/spec-bridge/bridges/form-view.ts +0 -109
  95. package/src/spec-bridge/bridges/list-view.ts +0 -187
  96. package/src/spec-bridge/bridges/page.ts +0 -136
  97. package/src/spec-bridge/index.ts +0 -14
  98. package/src/spec-bridge/types.ts +0 -38
  99. package/src/utils/i18n.ts +0 -10
  100. package/tsconfig.json +0 -17
  101. package/tsconfig.tsbuildinfo +0 -1
  102. package/vitest.config.ts +0 -2
@@ -1,102 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { useState, useCallback, useMemo } from 'react';
10
-
11
- /** Density mode aligned with DensityMode from @objectstack/spec v2.0.7 */
12
- export type DensityModeValue = 'compact' | 'comfortable' | 'spacious';
13
-
14
- export interface DensityConfig {
15
- /** Row height in pixels for each density mode */
16
- rowHeights?: Record<DensityModeValue, number>;
17
- /** Padding classes for each density mode */
18
- paddingClasses?: Record<DensityModeValue, string>;
19
- /** Font size classes for each density mode */
20
- fontSizeClasses?: Record<DensityModeValue, string>;
21
- }
22
-
23
- export interface DensityResult {
24
- /** Current density mode */
25
- mode: DensityModeValue;
26
- /** Set the density mode */
27
- setMode: (mode: DensityModeValue) => void;
28
- /** Cycle through density modes */
29
- cycle: () => void;
30
- /** Row height for the current mode (in pixels) */
31
- rowHeight: number;
32
- /** Tailwind padding class for the current mode */
33
- paddingClass: string;
34
- /** Tailwind font-size class for the current mode */
35
- fontSizeClass: string;
36
- }
37
-
38
- const DEFAULT_ROW_HEIGHTS: Record<DensityModeValue, number> = {
39
- compact: 32,
40
- comfortable: 40,
41
- spacious: 52,
42
- };
43
-
44
- const DEFAULT_PADDING_CLASSES: Record<DensityModeValue, string> = {
45
- compact: 'py-1 px-2',
46
- comfortable: 'py-2 px-3',
47
- spacious: 'py-3 px-4',
48
- };
49
-
50
- const DEFAULT_FONT_SIZE_CLASSES: Record<DensityModeValue, string> = {
51
- compact: 'text-xs',
52
- comfortable: 'text-sm',
53
- spacious: 'text-base',
54
- };
55
-
56
- const DENSITY_ORDER: DensityModeValue[] = ['compact', 'comfortable', 'spacious'];
57
-
58
- /**
59
- * Hook for managing view density modes (compact/comfortable/spacious).
60
- * Implements DensityMode from @objectstack/spec v2.0.7.
61
- *
62
- * @example
63
- * ```tsx
64
- * const density = useDensityMode('comfortable');
65
- *
66
- * return (
67
- * <div className={density.paddingClass}>
68
- * <table style={{ rowHeight: density.rowHeight }}>...</table>
69
- * <button onClick={density.cycle}>Toggle Density</button>
70
- * </div>
71
- * );
72
- * ```
73
- */
74
- export function useDensityMode(
75
- initialMode: DensityModeValue = 'comfortable',
76
- config?: DensityConfig
77
- ): DensityResult {
78
- const [mode, setMode] = useState<DensityModeValue>(initialMode);
79
-
80
- const rowHeights = config?.rowHeights ?? DEFAULT_ROW_HEIGHTS;
81
- const paddingClasses = config?.paddingClasses ?? DEFAULT_PADDING_CLASSES;
82
- const fontSizeClasses = config?.fontSizeClasses ?? DEFAULT_FONT_SIZE_CLASSES;
83
-
84
- const cycle = useCallback(() => {
85
- setMode((current) => {
86
- const idx = DENSITY_ORDER.indexOf(current);
87
- return DENSITY_ORDER[(idx + 1) % DENSITY_ORDER.length];
88
- });
89
- }, []);
90
-
91
- return useMemo(
92
- () => ({
93
- mode,
94
- setMode,
95
- cycle,
96
- rowHeight: rowHeights[mode],
97
- paddingClass: paddingClasses[mode],
98
- fontSizeClass: fontSizeClasses[mode],
99
- }),
100
- [mode, cycle, rowHeights, paddingClasses, fontSizeClasses]
101
- );
102
- }
@@ -1,168 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { useState, useEffect, useContext } from 'react';
10
- import { SchemaRendererContext } from '../context/SchemaRendererContext';
11
-
12
- /**
13
- * Discovery service information structure.
14
- * Represents server capabilities and service status.
15
- */
16
- export interface DiscoveryInfo {
17
- /** Server name and version */
18
- name?: string;
19
- version?: string;
20
-
21
- /** Runtime mode (e.g., 'development', 'production', 'preview') */
22
- mode?: string;
23
-
24
- /** Preview mode configuration from the kernel (present when mode is 'preview') */
25
- previewMode?: {
26
- autoLogin?: boolean;
27
- simulatedRole?: 'admin' | 'user' | 'viewer';
28
- simulatedUserName?: string;
29
- readOnly?: boolean;
30
- expiresInSeconds?: number;
31
- bannerMessage?: string;
32
- };
33
-
34
- /** Service availability status */
35
- services?: {
36
- /** Authentication service status */
37
- auth?: {
38
- enabled: boolean;
39
- status?: 'available' | 'unavailable';
40
- message?: string;
41
- };
42
- /** Data access service status */
43
- data?: {
44
- enabled: boolean;
45
- status?: 'available' | 'unavailable';
46
- };
47
- /** Metadata service status */
48
- metadata?: {
49
- enabled: boolean;
50
- status?: 'available' | 'unavailable';
51
- };
52
- /** AI service configuration */
53
- ai?: {
54
- enabled: boolean;
55
- status?: 'available' | 'unavailable';
56
- /** AI service endpoint route (e.g. '/api/v1/ai') */
57
- route?: string;
58
- };
59
- [key: string]: any;
60
- };
61
-
62
- /** API capabilities */
63
- capabilities?: string[];
64
-
65
- /** Additional discovery metadata */
66
- [key: string]: any;
67
- }
68
-
69
- /**
70
- * Hook to access discovery information from the ObjectStack server.
71
- *
72
- * This hook retrieves server capabilities and service status, which can be used
73
- * to conditionally enable/disable features based on server configuration.
74
- *
75
- * @example
76
- * ```tsx
77
- * function App() {
78
- * const { discovery, isLoading } = useDiscovery();
79
- *
80
- * if (isLoading) {
81
- * return <LoadingScreen />;
82
- * }
83
- *
84
- * // Check if auth is enabled on the server
85
- * const authEnabled = discovery?.services?.auth?.enabled ?? true;
86
- *
87
- * return (
88
- * <div>
89
- * {authEnabled ? <AuthProvider>...</AuthProvider> : <App />}
90
- * </div>
91
- * );
92
- * }
93
- * ```
94
- *
95
- * @returns Discovery information and loading state
96
- */
97
- export function useDiscovery() {
98
- const context = useContext(SchemaRendererContext);
99
- const dataSource = context?.dataSource;
100
- const [discovery, setDiscovery] = useState<DiscoveryInfo | null>(null);
101
- const [isLoading, setIsLoading] = useState(true);
102
- const [error, setError] = useState<Error | null>(null);
103
-
104
- useEffect(() => {
105
- let cancelled = false;
106
-
107
- async function fetchDiscovery() {
108
- if (!dataSource) {
109
- setIsLoading(false);
110
- return;
111
- }
112
-
113
- try {
114
- setIsLoading(true);
115
-
116
- // Check if dataSource has getDiscovery method
117
- if (typeof (dataSource as any).getDiscovery === 'function') {
118
- const discoveryData = await (dataSource as any).getDiscovery();
119
-
120
- if (!cancelled) {
121
- setDiscovery(discoveryData);
122
- setError(null);
123
- }
124
- } else {
125
- // DataSource doesn't support discovery
126
- if (!cancelled) {
127
- setDiscovery(null);
128
- setError(null);
129
- }
130
- }
131
- } catch (err) {
132
- if (!cancelled) {
133
- setError(err instanceof Error ? err : new Error('Failed to fetch discovery'));
134
- setDiscovery(null);
135
- }
136
- } finally {
137
- if (!cancelled) {
138
- setIsLoading(false);
139
- }
140
- }
141
- }
142
-
143
- fetchDiscovery();
144
-
145
- return () => {
146
- cancelled = true;
147
- };
148
- }, [dataSource]);
149
-
150
- return {
151
- discovery,
152
- isLoading,
153
- error,
154
- /**
155
- * Check if authentication is enabled on the server.
156
- * Defaults to true if discovery data is not available.
157
- */
158
- isAuthEnabled: discovery?.services?.auth?.enabled ?? true,
159
- /**
160
- * Check if AI service is enabled and available on the server.
161
- * Defaults to false if discovery data is not available.
162
- */
163
- isAiEnabled:
164
- discovery?.services?.ai?.enabled === true &&
165
- discovery?.services?.ai?.status === 'available',
166
- };
167
- }
168
-
@@ -1,142 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { useState, useEffect, useCallback, useRef } from 'react';
10
-
11
- /**
12
- * Options for dynamic app configuration loading.
13
- */
14
- export interface DynamicAppOptions<TAppConfig = unknown> {
15
- /** Application identifier to load */
16
- appId: string;
17
- /**
18
- * Static (fallback) configuration used when the server does not
19
- * provide an app definition or is unreachable.
20
- */
21
- staticConfig?: TAppConfig;
22
- /**
23
- * Data source adapter with `getApp` and `invalidateCache` methods.
24
- * Typically an ObjectStackAdapter instance.
25
- */
26
- adapter?: {
27
- getApp: (appId: string) => Promise<unknown | null>;
28
- invalidateCache?: (key?: string) => void;
29
- getObjectSchema?: (objectName: string) => Promise<unknown>;
30
- };
31
- /** Whether to attempt loading from the server (default: true) */
32
- enabled?: boolean;
33
- }
34
-
35
- /**
36
- * Result returned by useDynamicApp.
37
- */
38
- export interface DynamicAppResult<TAppConfig = unknown> {
39
- /** The resolved app configuration (server or static fallback) */
40
- config: TAppConfig | null;
41
- /** Whether the configuration is currently loading */
42
- isLoading: boolean;
43
- /** Error from the most recent load attempt */
44
- error: Error | null;
45
- /** Whether the config was loaded from the server (vs static fallback) */
46
- isServerConfig: boolean;
47
- /** Re-fetch the app configuration from the server, invalidating cache */
48
- refresh: () => Promise<void>;
49
- }
50
-
51
- /**
52
- * React hook for dynamic app configuration loading.
53
- *
54
- * Fetches app configuration from the server via `adapter.getApp(appId)`,
55
- * falling back to `staticConfig` when the server is unavailable.
56
- * Supports cache-based hot-reload via the `refresh()` callback.
57
- *
58
- * @example
59
- * ```tsx
60
- * import { useDynamicApp } from '@object-ui/react';
61
- * import staticAppConfig from '../config/app.json';
62
- *
63
- * function App() {
64
- * const { config, isLoading, refresh } = useDynamicApp({
65
- * appId: 'crm',
66
- * staticConfig: staticAppConfig,
67
- * adapter: dataSource,
68
- * });
69
- *
70
- * if (isLoading) return <LoadingScreen />;
71
- * return <Console config={config} onRefresh={refresh} />;
72
- * }
73
- * ```
74
- */
75
- export function useDynamicApp<TAppConfig = unknown>(
76
- options: DynamicAppOptions<TAppConfig>,
77
- ): DynamicAppResult<TAppConfig> {
78
- const { appId, staticConfig, adapter, enabled = true } = options;
79
-
80
- const [config, setConfig] = useState<TAppConfig | null>(staticConfig ?? null);
81
- const [isLoading, setIsLoading] = useState(enabled && !!adapter);
82
- const [error, setError] = useState<Error | null>(null);
83
- const [isServerConfig, setIsServerConfig] = useState(false);
84
-
85
- // Ref to track unmount / stale requests
86
- const mountedRef = useRef(true);
87
- useEffect(() => {
88
- mountedRef.current = true;
89
- return () => { mountedRef.current = false; };
90
- }, []);
91
-
92
- const loadConfig = useCallback(async () => {
93
- if (!adapter || !enabled) {
94
- setConfig(staticConfig ?? null);
95
- setIsServerConfig(false);
96
- setIsLoading(false);
97
- return;
98
- }
99
-
100
- setIsLoading(true);
101
- setError(null);
102
-
103
- try {
104
- const serverConfig = await adapter.getApp(appId);
105
-
106
- if (!mountedRef.current) return;
107
-
108
- if (serverConfig) {
109
- setConfig(serverConfig as TAppConfig);
110
- setIsServerConfig(true);
111
- } else {
112
- // Server returned null — fall back to static config
113
- setConfig(staticConfig ?? null);
114
- setIsServerConfig(false);
115
- }
116
- } catch (err) {
117
- if (!mountedRef.current) return;
118
-
119
- setError(err instanceof Error ? err : new Error(String(err)));
120
- // Fall back to static config on error
121
- setConfig(staticConfig ?? null);
122
- setIsServerConfig(false);
123
- } finally {
124
- if (mountedRef.current) {
125
- setIsLoading(false);
126
- }
127
- }
128
- }, [adapter, appId, staticConfig, enabled]);
129
-
130
- // Load on mount and when appId changes
131
- useEffect(() => {
132
- loadConfig();
133
- }, [loadConfig]);
134
-
135
- const refresh = useCallback(async () => {
136
- // Invalidate cache before re-fetching
137
- adapter?.invalidateCache?.(`app:${appId}`);
138
- await loadConfig();
139
- }, [adapter, appId, loadConfig]);
140
-
141
- return { config, isLoading, error, isServerConfig, refresh };
142
- }