@object-ui/react 0.5.0 → 3.0.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +32 -0
- package/dist/LazyPluginLoader.d.ts +44 -0
- package/dist/LazyPluginLoader.js +92 -3
- package/dist/SchemaRenderer.d.ts +20 -1
- package/dist/SchemaRenderer.js +76 -13
- package/dist/components/form/FieldFactory.js +44 -40
- package/dist/components/form/FormRenderer.js +45 -3
- package/dist/context/ActionContext.d.ts +76 -0
- package/dist/context/ActionContext.js +139 -0
- package/dist/context/DndContext.d.ts +135 -0
- package/dist/context/DndContext.js +120 -0
- package/dist/context/NotificationContext.d.ts +113 -0
- package/dist/context/NotificationContext.js +130 -0
- package/dist/context/ThemeContext.d.ts +94 -0
- package/dist/context/ThemeContext.js +215 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.js +4 -0
- package/dist/hooks/index.d.ts +22 -0
- package/dist/hooks/index.js +22 -0
- package/dist/hooks/useActionRunner.d.ts +21 -7
- package/dist/hooks/useActionRunner.js +27 -7
- package/dist/hooks/useAnimation.d.ts +46 -0
- package/dist/hooks/useAnimation.js +59 -0
- package/dist/hooks/useClientNotifications.d.ts +53 -0
- package/dist/hooks/useClientNotifications.js +190 -0
- package/dist/hooks/useColumnSummary.d.ts +38 -0
- package/dist/hooks/useColumnSummary.js +54 -0
- package/dist/hooks/useCrudShortcuts.d.ts +39 -0
- package/dist/hooks/useCrudShortcuts.js +96 -0
- package/dist/hooks/useDensityMode.d.ts +48 -0
- package/dist/hooks/useDensityMode.js +60 -0
- package/dist/hooks/useDiscovery.d.ts +78 -0
- package/dist/hooks/useDiscovery.js +96 -0
- package/dist/hooks/useDynamicApp.d.ts +70 -0
- package/dist/hooks/useDynamicApp.js +92 -0
- package/dist/hooks/useETagCache.d.ts +75 -0
- package/dist/hooks/useETagCache.js +306 -0
- package/dist/hooks/useFocusManagement.d.ts +89 -0
- package/dist/hooks/useFocusManagement.js +188 -0
- package/dist/hooks/useFocusTrap.d.ts +41 -0
- package/dist/hooks/useFocusTrap.js +103 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +49 -0
- package/dist/hooks/useKeyboardShortcuts.js +86 -0
- package/dist/hooks/useNavigationOverlay.d.ts +78 -0
- package/dist/hooks/useNavigationOverlay.js +112 -0
- package/dist/hooks/useOffline.d.ts +96 -0
- package/dist/hooks/useOffline.js +185 -0
- package/dist/hooks/usePageTransition.d.ts +60 -0
- package/dist/hooks/usePageTransition.js +111 -0
- package/dist/hooks/usePageVariables.d.ts +67 -0
- package/dist/hooks/usePageVariables.js +109 -0
- package/dist/hooks/usePerformance.d.ts +87 -0
- package/dist/hooks/usePerformance.js +165 -0
- package/dist/hooks/usePerformanceBudget.d.ts +78 -0
- package/dist/hooks/usePerformanceBudget.js +209 -0
- package/dist/hooks/useReducedMotion.d.ts +28 -0
- package/dist/hooks/useReducedMotion.js +48 -0
- package/dist/hooks/useSchemaPersistence.d.ts +87 -0
- package/dist/hooks/useSchemaPersistence.js +173 -0
- package/dist/hooks/useViewData.d.ts +73 -0
- package/dist/hooks/useViewData.js +135 -0
- package/dist/hooks/useViewSharing.d.ts +57 -0
- package/dist/hooks/useViewSharing.js +74 -0
- package/dist/hooks/useViewTransition.d.ts +54 -0
- package/dist/hooks/useViewTransition.js +83 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/utils/i18n.d.ts +10 -0
- package/dist/utils/i18n.js +12 -0
- package/package.json +7 -5
- package/src/LazyPluginLoader.tsx +129 -7
- package/src/SchemaRenderer.tsx +122 -13
- package/src/__tests__/LazyPluginLoader.test.tsx +97 -1
- package/src/__tests__/SchemaRenderer.aria.test.tsx +118 -0
- package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +114 -0
- package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +132 -0
- package/src/__tests__/ThemeProvider.test.tsx +451 -0
- package/src/__tests__/useNavigationOverlay.test.ts +416 -0
- package/src/__tests__/useOffline.test.ts +198 -0
- package/src/__tests__/usePageTransition.test.ts +214 -0
- package/src/__tests__/usePageVariables.test.tsx +334 -0
- package/src/__tests__/usePerformance.test.ts +137 -0
- package/src/__tests__/useViewData.test.tsx +422 -0
- package/src/__tests__/view-switching.test.tsx +456 -0
- package/src/components/form/FieldFactory.tsx +51 -46
- package/src/components/form/FormRenderer.test.tsx +145 -0
- package/src/components/form/FormRenderer.tsx +52 -3
- package/src/context/ActionContext.tsx +213 -0
- package/src/context/DndContext.tsx +260 -0
- package/src/context/NotificationContext.tsx +280 -0
- package/src/context/ThemeContext.tsx +325 -0
- package/src/context/__tests__/ActionContext.test.tsx +174 -0
- package/src/context/__tests__/DndContext.test.tsx +150 -0
- package/src/context/__tests__/NotificationContext.test.tsx +176 -0
- package/src/context/index.ts +4 -0
- package/src/hooks/__tests__/useActionRunner.test.ts +153 -0
- package/src/hooks/__tests__/useAnimation.test.ts +82 -0
- package/src/hooks/__tests__/useColumnSummary.test.ts +93 -0
- package/src/hooks/__tests__/useDensityMode.test.ts +81 -0
- package/src/hooks/__tests__/useDiscovery.test.tsx +149 -0
- package/src/hooks/__tests__/useDynamicApp.test.ts +161 -0
- package/src/hooks/__tests__/useETagCache.test.ts +153 -0
- package/src/hooks/__tests__/useExpression.test.ts +86 -0
- package/src/hooks/__tests__/useFocusTrap.test.ts +47 -0
- package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +144 -0
- package/src/hooks/__tests__/usePerformanceBudget.test.ts +157 -0
- package/src/hooks/__tests__/useSchemaPersistence.test.ts +220 -0
- package/src/hooks/__tests__/useViewSharing.test.ts +121 -0
- package/src/hooks/__tests__/useViewTransition.test.ts +61 -0
- package/src/hooks/index.ts +22 -1
- package/src/hooks/useActionRunner.ts +49 -11
- package/src/hooks/useAnimation.ts +117 -0
- package/src/hooks/useClientNotifications.ts +251 -0
- package/src/hooks/useColumnSummary.ts +87 -0
- package/src/hooks/useCrudShortcuts.ts +126 -0
- package/src/hooks/useDensityMode.ts +102 -0
- package/src/hooks/useDiscovery.ts +141 -0
- package/src/hooks/useDynamicApp.ts +142 -0
- package/src/hooks/useETagCache.ts +404 -0
- package/src/hooks/useFocusManagement.ts +248 -0
- package/src/hooks/useFocusTrap.ts +138 -0
- package/src/hooks/useKeyboardShortcuts.ts +119 -0
- package/src/hooks/useNavigationOverlay.ts +180 -0
- package/src/hooks/useOffline.ts +301 -0
- package/src/hooks/usePageTransition.ts +187 -0
- package/src/hooks/usePageVariables.tsx +157 -0
- package/src/hooks/usePerformance.ts +246 -0
- package/src/hooks/usePerformanceBudget.ts +313 -0
- package/src/hooks/useReducedMotion.ts +53 -0
- package/src/hooks/useSchemaPersistence.ts +222 -0
- package/src/hooks/useViewData.ts +201 -0
- package/src/hooks/useViewSharing.ts +140 -0
- package/src/hooks/useViewTransition.ts +144 -0
- package/src/index.ts +21 -0
- package/src/utils/i18n.ts +10 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/__tests__/LazyPluginLoader.test.d.ts +0 -8
- package/dist/__tests__/LazyPluginLoader.test.js +0 -49
- package/dist/components/form/FormRenderer.test.d.ts +0 -8
- package/dist/components/form/FormRenderer.test.js +0 -534
- package/dist/index.test.d.ts +0 -8
- package/dist/index.test.js +0 -13
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Online/offline external store (SSR-safe)
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
function subscribeOnline(callback) {
|
|
13
|
+
if (typeof window === 'undefined')
|
|
14
|
+
return () => { };
|
|
15
|
+
window.addEventListener('online', callback);
|
|
16
|
+
window.addEventListener('offline', callback);
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener('online', callback);
|
|
19
|
+
window.removeEventListener('offline', callback);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getOnlineSnapshot() {
|
|
23
|
+
return typeof navigator !== 'undefined' ? navigator.onLine : true;
|
|
24
|
+
}
|
|
25
|
+
function getServerSnapshot() {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Mutation queue storage helpers
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
const QUEUE_STORAGE_KEY = 'objectui-offline-queue';
|
|
32
|
+
function loadQueue() {
|
|
33
|
+
if (typeof localStorage === 'undefined')
|
|
34
|
+
return [];
|
|
35
|
+
try {
|
|
36
|
+
const raw = localStorage.getItem(QUEUE_STORAGE_KEY);
|
|
37
|
+
return raw ? JSON.parse(raw) : [];
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function persistQueue(queue) {
|
|
44
|
+
if (typeof localStorage === 'undefined')
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
localStorage.setItem(QUEUE_STORAGE_KEY, JSON.stringify(queue));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// localStorage full or unavailable — silently ignore
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let idCounter = 0;
|
|
54
|
+
function generateId() {
|
|
55
|
+
idCounter += 1;
|
|
56
|
+
return `mut_${Date.now()}_${idCounter}`;
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// useOffline hook
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
const DEFAULTS = {
|
|
62
|
+
enabled: true,
|
|
63
|
+
strategy: 'network_first',
|
|
64
|
+
offlineIndicator: true,
|
|
65
|
+
offlineMessage: 'You are currently offline. Changes will be synced when reconnected.',
|
|
66
|
+
queueMaxSize: 100,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Hook for offline mode detection and sync queue management.
|
|
70
|
+
* Implements OfflineConfigSchema, SyncConfigSchema, and ConflictResolutionSchema
|
|
71
|
+
* from @objectstack/spec v2.0.7.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* function App() {
|
|
76
|
+
* const offline = useOffline({
|
|
77
|
+
* enabled: true,
|
|
78
|
+
* strategy: 'cache_first',
|
|
79
|
+
* sync: { conflictResolution: 'last_write_wins' },
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* if (!offline.isOnline && offline.showIndicator) {
|
|
83
|
+
* return <Banner>{offline.offlineMessage}</Banner>;
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* return <div>Pending mutations: {offline.pendingCount}</div>;
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function useOffline(config = {}) {
|
|
91
|
+
const { enabled = DEFAULTS.enabled, strategy = DEFAULTS.strategy, offlineIndicator = DEFAULTS.offlineIndicator, offlineMessage = DEFAULTS.offlineMessage, queueMaxSize = DEFAULTS.queueMaxSize, sync: syncConfig, } = config;
|
|
92
|
+
const isOnline = useSyncExternalStore(subscribeOnline, getOnlineSnapshot, getServerSnapshot);
|
|
93
|
+
const [queue, setQueue] = useState(loadQueue);
|
|
94
|
+
const [syncState, setSyncState] = useState('idle');
|
|
95
|
+
const syncConfigRef = useRef(syncConfig);
|
|
96
|
+
syncConfigRef.current = syncConfig;
|
|
97
|
+
// Persist queue to localStorage whenever it changes
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
persistQueue(queue);
|
|
100
|
+
}, [queue]);
|
|
101
|
+
// Update sync state based on online status
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!enabled)
|
|
104
|
+
return;
|
|
105
|
+
if (!isOnline) {
|
|
106
|
+
setSyncState('offline');
|
|
107
|
+
}
|
|
108
|
+
else if (syncState === 'offline') {
|
|
109
|
+
setSyncState('idle');
|
|
110
|
+
}
|
|
111
|
+
}, [isOnline, enabled, syncState]);
|
|
112
|
+
const queueMutation = useCallback((mutation) => {
|
|
113
|
+
if (!enabled)
|
|
114
|
+
return;
|
|
115
|
+
setQueue((prev) => {
|
|
116
|
+
const newEntry = {
|
|
117
|
+
...mutation,
|
|
118
|
+
id: generateId(),
|
|
119
|
+
timestamp: Date.now(),
|
|
120
|
+
};
|
|
121
|
+
const next = [...prev, newEntry];
|
|
122
|
+
// Enforce max queue size (FIFO eviction)
|
|
123
|
+
if (next.length > queueMaxSize) {
|
|
124
|
+
return next.slice(next.length - queueMaxSize);
|
|
125
|
+
}
|
|
126
|
+
return next;
|
|
127
|
+
});
|
|
128
|
+
}, [enabled, queueMaxSize]);
|
|
129
|
+
const clearQueue = useCallback(() => {
|
|
130
|
+
setQueue([]);
|
|
131
|
+
}, []);
|
|
132
|
+
const sync = useCallback(async () => {
|
|
133
|
+
if (!enabled || queue.length === 0)
|
|
134
|
+
return;
|
|
135
|
+
setSyncState('syncing');
|
|
136
|
+
try {
|
|
137
|
+
// In a real implementation, this would batch-send mutations to the server.
|
|
138
|
+
// For now, we simulate a successful sync by clearing the queue.
|
|
139
|
+
const batchSize = syncConfigRef.current?.batchSize ?? queue.length;
|
|
140
|
+
const batch = queue.slice(0, batchSize);
|
|
141
|
+
// Simulate network round-trip
|
|
142
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
143
|
+
// Remove synced mutations from queue
|
|
144
|
+
setQueue((prev) => prev.filter((m) => !batch.some((b) => b.id === m.id)));
|
|
145
|
+
setSyncState('idle');
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
setSyncState('error');
|
|
149
|
+
}
|
|
150
|
+
}, [enabled, queue]);
|
|
151
|
+
// Auto-sync when coming back online (short stabilization delay)
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (!enabled || !isOnline || queue.length === 0)
|
|
154
|
+
return;
|
|
155
|
+
const timer = setTimeout(() => {
|
|
156
|
+
void sync();
|
|
157
|
+
}, 100);
|
|
158
|
+
return () => clearTimeout(timer);
|
|
159
|
+
// Only trigger on isOnline changes, not on every queue change
|
|
160
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
|
+
}, [isOnline, enabled]);
|
|
162
|
+
return useMemo(() => ({
|
|
163
|
+
isOnline,
|
|
164
|
+
enabled,
|
|
165
|
+
syncState,
|
|
166
|
+
strategy,
|
|
167
|
+
pendingCount: queue.length,
|
|
168
|
+
queueMutation,
|
|
169
|
+
sync,
|
|
170
|
+
clearQueue,
|
|
171
|
+
showIndicator: offlineIndicator && !isOnline,
|
|
172
|
+
offlineMessage,
|
|
173
|
+
}), [
|
|
174
|
+
isOnline,
|
|
175
|
+
enabled,
|
|
176
|
+
syncState,
|
|
177
|
+
strategy,
|
|
178
|
+
queue.length,
|
|
179
|
+
queueMutation,
|
|
180
|
+
sync,
|
|
181
|
+
clearQueue,
|
|
182
|
+
offlineIndicator,
|
|
183
|
+
offlineMessage,
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
/** Page transition type. */
|
|
9
|
+
export type PageTransitionType = 'none' | 'fade' | 'slide_up' | 'slide_down' | 'slide_left' | 'slide_right' | 'scale' | 'rotate' | 'flip';
|
|
10
|
+
/** Easing function for page transitions. */
|
|
11
|
+
export type PageTransitionEasing = 'linear' | 'ease' | 'ease_in' | 'ease_out' | 'ease_in_out' | 'spring';
|
|
12
|
+
/** Page transition configuration aligned with PageTransitionSchema. */
|
|
13
|
+
export interface PageTransitionConfig {
|
|
14
|
+
/** Transition type. */
|
|
15
|
+
type?: PageTransitionType;
|
|
16
|
+
/** Duration in milliseconds. */
|
|
17
|
+
duration?: number;
|
|
18
|
+
/** Easing function. */
|
|
19
|
+
easing?: PageTransitionEasing;
|
|
20
|
+
/** Whether entering and exiting pages cross-fade. */
|
|
21
|
+
crossFade?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Resolved CSS classes and styles for a page transition. */
|
|
24
|
+
export interface PageTransitionResult {
|
|
25
|
+
/** Tailwind CSS classes for the enter transition. */
|
|
26
|
+
enterClassName: string;
|
|
27
|
+
/** Tailwind CSS classes for the exit transition. */
|
|
28
|
+
exitClassName: string;
|
|
29
|
+
/** Inline styles for the enter transition. */
|
|
30
|
+
enterStyle: React.CSSProperties;
|
|
31
|
+
/** Inline styles for the exit transition. */
|
|
32
|
+
exitStyle: React.CSSProperties;
|
|
33
|
+
/** Whether the transition is active (not 'none' and motion not reduced). */
|
|
34
|
+
isActive: boolean;
|
|
35
|
+
/** The resolved transition type. */
|
|
36
|
+
type: PageTransitionType;
|
|
37
|
+
/** The resolved duration in ms. */
|
|
38
|
+
duration: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hook for page-level transition animations aligned with
|
|
42
|
+
* PageTransitionSchema from @objectstack/spec v2.0.7.
|
|
43
|
+
*
|
|
44
|
+
* Generates Tailwind CSS animate-in / animate-out classes and inline styles
|
|
45
|
+
* for enter/exit page transitions. Respects `prefers-reduced-motion`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* function PageWrapper({ children }: { children: React.ReactNode }) {
|
|
50
|
+
* const transition = usePageTransition({ type: 'fade', duration: 200 });
|
|
51
|
+
*
|
|
52
|
+
* return (
|
|
53
|
+
* <div className={transition.enterClassName} style={transition.enterStyle}>
|
|
54
|
+
* {children}
|
|
55
|
+
* </div>
|
|
56
|
+
* );
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function usePageTransition(config?: PageTransitionConfig): PageTransitionResult;
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
import { useMemo } from 'react';
|
|
9
|
+
import { useReducedMotion } from './useReducedMotion';
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Constants
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
const EASING_CSS = {
|
|
14
|
+
linear: 'linear',
|
|
15
|
+
ease: 'ease',
|
|
16
|
+
ease_in: 'ease-in',
|
|
17
|
+
ease_out: 'ease-out',
|
|
18
|
+
ease_in_out: 'ease-in-out',
|
|
19
|
+
spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
|
|
20
|
+
};
|
|
21
|
+
const ENTER_CLASSES = {
|
|
22
|
+
none: '',
|
|
23
|
+
fade: 'animate-in fade-in',
|
|
24
|
+
slide_up: 'animate-in slide-in-from-bottom-4',
|
|
25
|
+
slide_down: 'animate-in slide-in-from-top-4',
|
|
26
|
+
slide_left: 'animate-in slide-in-from-right-4',
|
|
27
|
+
slide_right: 'animate-in slide-in-from-left-4',
|
|
28
|
+
scale: 'animate-in zoom-in-95',
|
|
29
|
+
rotate: 'animate-in spin-in-90',
|
|
30
|
+
flip: 'animate-in fade-in zoom-in-95',
|
|
31
|
+
};
|
|
32
|
+
const EXIT_CLASSES = {
|
|
33
|
+
none: '',
|
|
34
|
+
fade: 'animate-out fade-out',
|
|
35
|
+
slide_up: 'animate-out slide-out-to-top-4',
|
|
36
|
+
slide_down: 'animate-out slide-out-to-bottom-4',
|
|
37
|
+
slide_left: 'animate-out slide-out-to-left-4',
|
|
38
|
+
slide_right: 'animate-out slide-out-to-right-4',
|
|
39
|
+
scale: 'animate-out zoom-out-95',
|
|
40
|
+
rotate: 'animate-out spin-out-90',
|
|
41
|
+
flip: 'animate-out fade-out zoom-out-95',
|
|
42
|
+
};
|
|
43
|
+
const DEFAULT_DURATION = 300;
|
|
44
|
+
const DEFAULT_EASING = 'ease_in_out';
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// usePageTransition hook
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
/**
|
|
49
|
+
* Hook for page-level transition animations aligned with
|
|
50
|
+
* PageTransitionSchema from @objectstack/spec v2.0.7.
|
|
51
|
+
*
|
|
52
|
+
* Generates Tailwind CSS animate-in / animate-out classes and inline styles
|
|
53
|
+
* for enter/exit page transitions. Respects `prefers-reduced-motion`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* function PageWrapper({ children }: { children: React.ReactNode }) {
|
|
58
|
+
* const transition = usePageTransition({ type: 'fade', duration: 200 });
|
|
59
|
+
*
|
|
60
|
+
* return (
|
|
61
|
+
* <div className={transition.enterClassName} style={transition.enterStyle}>
|
|
62
|
+
* {children}
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function usePageTransition(config = {}) {
|
|
69
|
+
const { type = 'none', duration = DEFAULT_DURATION, easing = DEFAULT_EASING, crossFade = false, } = config;
|
|
70
|
+
const reducedMotion = useReducedMotion();
|
|
71
|
+
return useMemo(() => {
|
|
72
|
+
const isActive = type !== 'none' && !reducedMotion;
|
|
73
|
+
if (!isActive) {
|
|
74
|
+
return {
|
|
75
|
+
enterClassName: '',
|
|
76
|
+
exitClassName: '',
|
|
77
|
+
enterStyle: {},
|
|
78
|
+
exitStyle: {},
|
|
79
|
+
isActive: false,
|
|
80
|
+
type,
|
|
81
|
+
duration,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const enterClassName = ENTER_CLASSES[type] || '';
|
|
85
|
+
const exitClassName = EXIT_CLASSES[type] || '';
|
|
86
|
+
const baseStyle = {
|
|
87
|
+
animationDuration: `${duration}ms`,
|
|
88
|
+
animationTimingFunction: EASING_CSS[easing] || EASING_CSS.ease_in_out,
|
|
89
|
+
animationFillMode: 'both',
|
|
90
|
+
};
|
|
91
|
+
const enterStyle = { ...baseStyle };
|
|
92
|
+
const exitStyle = { ...baseStyle };
|
|
93
|
+
// When crossFade is enabled, both the entering and exiting pages
|
|
94
|
+
// should overlap and transition opacity simultaneously.
|
|
95
|
+
if (crossFade) {
|
|
96
|
+
enterStyle.position = 'absolute';
|
|
97
|
+
enterStyle.inset = '0';
|
|
98
|
+
exitStyle.position = 'absolute';
|
|
99
|
+
exitStyle.inset = '0';
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
enterClassName,
|
|
103
|
+
exitClassName,
|
|
104
|
+
enterStyle,
|
|
105
|
+
exitStyle,
|
|
106
|
+
isActive: true,
|
|
107
|
+
type,
|
|
108
|
+
duration,
|
|
109
|
+
};
|
|
110
|
+
}, [type, duration, easing, crossFade, reducedMotion]);
|
|
111
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
import React from 'react';
|
|
9
|
+
import type { PageVariable } from '@object-ui/types';
|
|
10
|
+
/**
|
|
11
|
+
* Page variables context value.
|
|
12
|
+
* Provides access to page-level state variables.
|
|
13
|
+
*/
|
|
14
|
+
export interface PageVariablesContextValue {
|
|
15
|
+
/** Current variable values */
|
|
16
|
+
variables: Record<string, any>;
|
|
17
|
+
/** Set a single variable value */
|
|
18
|
+
setVariable: (name: string, value: any) => void;
|
|
19
|
+
/** Set multiple variable values at once */
|
|
20
|
+
setVariables: (updates: Record<string, any>) => void;
|
|
21
|
+
/** Reset all variables to their default values */
|
|
22
|
+
resetVariables: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Props for PageVariablesProvider
|
|
26
|
+
*/
|
|
27
|
+
export interface PageVariablesProviderProps {
|
|
28
|
+
/** Variable definitions from PageSchema.variables */
|
|
29
|
+
definitions?: PageVariable[];
|
|
30
|
+
/** Child components */
|
|
31
|
+
children: React.ReactNode;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* PageVariablesProvider — Provides page-level state variables to the component tree.
|
|
35
|
+
*
|
|
36
|
+
* Initializes variables from their definitions and provides read/write access
|
|
37
|
+
* to all child components via the usePageVariables hook.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <PageVariablesProvider definitions={[
|
|
42
|
+
* { name: 'selectedId', type: 'string', defaultValue: '' },
|
|
43
|
+
* { name: 'count', type: 'number', defaultValue: 0 },
|
|
44
|
+
* ]}>
|
|
45
|
+
* <MyComponents />
|
|
46
|
+
* </PageVariablesProvider>
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const PageVariablesProvider: React.FC<PageVariablesProviderProps>;
|
|
50
|
+
/**
|
|
51
|
+
* Hook to access page-level variables.
|
|
52
|
+
*
|
|
53
|
+
* Returns the current variable values and setter functions.
|
|
54
|
+
* Returns a no-op fallback if used outside a PageVariablesProvider.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const { variables, setVariable } = usePageVariables();
|
|
59
|
+
* const userId = variables.selectedId;
|
|
60
|
+
* setVariable('selectedId', '123');
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function usePageVariables(): PageVariablesContextValue;
|
|
64
|
+
/**
|
|
65
|
+
* Hook to check if a PageVariablesProvider is available.
|
|
66
|
+
*/
|
|
67
|
+
export declare function useHasPageVariables(): boolean;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* ObjectUI
|
|
4
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
import { createContext, useContext, useState, useCallback, useMemo } from 'react';
|
|
10
|
+
const PageVariablesContext = createContext(null);
|
|
11
|
+
/**
|
|
12
|
+
* Initialize page variables from their definitions.
|
|
13
|
+
* Sets each variable to its defaultValue or type-appropriate default.
|
|
14
|
+
*/
|
|
15
|
+
function initializeVariables(definitions) {
|
|
16
|
+
if (!definitions || definitions.length === 0)
|
|
17
|
+
return {};
|
|
18
|
+
const initial = {};
|
|
19
|
+
for (const def of definitions) {
|
|
20
|
+
if (def.defaultValue !== undefined) {
|
|
21
|
+
initial[def.name] = def.defaultValue;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Type-appropriate defaults
|
|
25
|
+
switch (def.type) {
|
|
26
|
+
case 'number':
|
|
27
|
+
initial[def.name] = 0;
|
|
28
|
+
break;
|
|
29
|
+
case 'boolean':
|
|
30
|
+
initial[def.name] = false;
|
|
31
|
+
break;
|
|
32
|
+
case 'object':
|
|
33
|
+
initial[def.name] = {};
|
|
34
|
+
break;
|
|
35
|
+
case 'array':
|
|
36
|
+
initial[def.name] = [];
|
|
37
|
+
break;
|
|
38
|
+
case 'string':
|
|
39
|
+
default:
|
|
40
|
+
initial[def.name] = '';
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return initial;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* PageVariablesProvider — Provides page-level state variables to the component tree.
|
|
49
|
+
*
|
|
50
|
+
* Initializes variables from their definitions and provides read/write access
|
|
51
|
+
* to all child components via the usePageVariables hook.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <PageVariablesProvider definitions={[
|
|
56
|
+
* { name: 'selectedId', type: 'string', defaultValue: '' },
|
|
57
|
+
* { name: 'count', type: 'number', defaultValue: 0 },
|
|
58
|
+
* ]}>
|
|
59
|
+
* <MyComponents />
|
|
60
|
+
* </PageVariablesProvider>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const PageVariablesProvider = ({ definitions, children, }) => {
|
|
64
|
+
const [variables, setVariablesState] = useState(() => initializeVariables(definitions));
|
|
65
|
+
const setVariable = useCallback((name, value) => {
|
|
66
|
+
setVariablesState((prev) => ({ ...prev, [name]: value }));
|
|
67
|
+
}, []);
|
|
68
|
+
const setVariables = useCallback((updates) => {
|
|
69
|
+
setVariablesState((prev) => ({ ...prev, ...updates }));
|
|
70
|
+
}, []);
|
|
71
|
+
const resetVariables = useCallback(() => {
|
|
72
|
+
setVariablesState(initializeVariables(definitions));
|
|
73
|
+
}, [definitions]);
|
|
74
|
+
const value = useMemo(() => ({ variables, setVariable, setVariables, resetVariables }), [variables, setVariable, setVariables, resetVariables]);
|
|
75
|
+
return (_jsx(PageVariablesContext.Provider, { value: value, children: children }));
|
|
76
|
+
};
|
|
77
|
+
PageVariablesProvider.displayName = 'PageVariablesProvider';
|
|
78
|
+
/**
|
|
79
|
+
* Hook to access page-level variables.
|
|
80
|
+
*
|
|
81
|
+
* Returns the current variable values and setter functions.
|
|
82
|
+
* Returns a no-op fallback if used outside a PageVariablesProvider.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* const { variables, setVariable } = usePageVariables();
|
|
87
|
+
* const userId = variables.selectedId;
|
|
88
|
+
* setVariable('selectedId', '123');
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function usePageVariables() {
|
|
92
|
+
const ctx = useContext(PageVariablesContext);
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
// Graceful fallback — allows components to work outside a Page
|
|
95
|
+
return {
|
|
96
|
+
variables: {},
|
|
97
|
+
setVariable: () => { },
|
|
98
|
+
setVariables: () => { },
|
|
99
|
+
resetVariables: () => { },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return ctx;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Hook to check if a PageVariablesProvider is available.
|
|
106
|
+
*/
|
|
107
|
+
export function useHasPageVariables() {
|
|
108
|
+
return useContext(PageVariablesContext) !== null;
|
|
109
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
/** Cache strategy for data fetching. */
|
|
9
|
+
export type CacheStrategyType = 'none' | 'cache-first' | 'network-first' | 'stale-while-revalidate';
|
|
10
|
+
/** Virtual scroll configuration. */
|
|
11
|
+
export interface VirtualScrollConfig {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
itemHeight?: number;
|
|
14
|
+
overscan?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Performance configuration aligned with PerformanceConfigSchema. */
|
|
17
|
+
export interface PerformanceConfig {
|
|
18
|
+
/** Whether to lazy-load components/data. */
|
|
19
|
+
lazyLoad?: boolean;
|
|
20
|
+
/** Virtual scroll settings for large lists. */
|
|
21
|
+
virtualScroll?: VirtualScrollConfig;
|
|
22
|
+
/** Cache strategy for data fetching. */
|
|
23
|
+
cacheStrategy?: CacheStrategyType;
|
|
24
|
+
/** Whether to prefetch linked resources. */
|
|
25
|
+
prefetch?: boolean;
|
|
26
|
+
/** Default page size for paginated views. */
|
|
27
|
+
pageSize?: number;
|
|
28
|
+
/** Debounce interval in milliseconds for user input. */
|
|
29
|
+
debounceMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Web Vitals metrics snapshot. */
|
|
32
|
+
export interface PerformanceMetrics {
|
|
33
|
+
/** Largest Contentful Paint (ms). */
|
|
34
|
+
lcp: number | null;
|
|
35
|
+
/** First Contentful Paint (ms). */
|
|
36
|
+
fcp: number | null;
|
|
37
|
+
/** Time to Interactive (ms). */
|
|
38
|
+
tti: number | null;
|
|
39
|
+
/** Total render count since mount. */
|
|
40
|
+
renderCount: number;
|
|
41
|
+
/** Last render duration (ms). */
|
|
42
|
+
lastRenderDuration: number | null;
|
|
43
|
+
}
|
|
44
|
+
/** Result returned by the usePerformance hook. */
|
|
45
|
+
export interface PerformanceResult {
|
|
46
|
+
/** The resolved performance configuration (with defaults). */
|
|
47
|
+
config: Required<Omit<PerformanceConfig, 'virtualScroll'>> & {
|
|
48
|
+
virtualScroll: Required<VirtualScrollConfig>;
|
|
49
|
+
};
|
|
50
|
+
/** Current performance metrics. */
|
|
51
|
+
metrics: PerformanceMetrics;
|
|
52
|
+
/** Mark a rendering start (returns stop function). */
|
|
53
|
+
markRenderStart: () => () => void;
|
|
54
|
+
/** Create a debounced version of a callback. */
|
|
55
|
+
debounce: <T extends (...args: unknown[]) => void>(fn: T) => T;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Hook for performance monitoring and configuration aligned with
|
|
59
|
+
* PerformanceConfigSchema from @objectstack/spec v2.0.7.
|
|
60
|
+
*
|
|
61
|
+
* Provides resolved config values, Web Vitals metrics, and utility functions
|
|
62
|
+
* (debounce, render marking) for performance-aware components.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* function DataGrid({ data }: { data: unknown[] }) {
|
|
67
|
+
* const perf = usePerformance({
|
|
68
|
+
* lazyLoad: true,
|
|
69
|
+
* virtualScroll: { enabled: true, itemHeight: 40 },
|
|
70
|
+
* debounceMs: 200,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const handleSearch = perf.debounce((query: string) => {
|
|
74
|
+
* // debounced search
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* return (
|
|
78
|
+
* <div>
|
|
79
|
+
* {perf.config.virtualScroll.enabled
|
|
80
|
+
* ? <VirtualList itemHeight={perf.config.virtualScroll.itemHeight} />
|
|
81
|
+
* : <NormalList />}
|
|
82
|
+
* </div>
|
|
83
|
+
* );
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function usePerformance(userConfig?: PerformanceConfig): PerformanceResult;
|