@umituz/web-design-system 3.1.22 → 4.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/README.md +137 -469
- package/dist/styles.css +2 -0
- package/package.json +30 -31
- package/src/__tests__/cn.test.ts +24 -0
- package/src/__tests__/components.smoke.test.tsx +78 -0
- package/src/__tests__/styles.contract.test.ts +60 -0
- package/src/domain/tokens/index.ts +8 -49
- package/src/index.ts +8 -10
- package/src/infrastructure/constants/component.constants.ts +3 -17
- package/src/infrastructure/constants/index.ts +4 -2
- package/src/infrastructure/constants/timing.constants.ts +46 -0
- package/src/infrastructure/utils/calculation.utils.ts +74 -0
- package/src/infrastructure/utils/index.ts +12 -0
- package/src/presentation/atoms/IconButton.tsx +55 -0
- package/src/presentation/atoms/Progress.tsx +2 -1
- package/src/presentation/atoms/Spinner.tsx +1 -1
- package/src/presentation/atoms/Switch.tsx +2 -2
- package/src/presentation/atoms/Text.tsx +15 -13
- package/src/presentation/atoms/Tooltip.tsx +2 -1
- package/src/presentation/atoms/index.ts +3 -0
- package/src/presentation/hooks/index.ts +0 -3
- package/src/presentation/hooks/useClickOutside.ts +14 -10
- package/src/presentation/hooks/useClipboard.ts +30 -12
- package/src/presentation/hooks/useDebounce.ts +8 -10
- package/src/presentation/hooks/useLocalStorage.ts +28 -18
- package/src/presentation/hooks/useMediaQuery.ts +2 -1
- package/src/presentation/hooks/useScrollLock.ts +40 -12
- package/src/presentation/hooks/useToggle.ts +8 -6
- package/src/presentation/molecules/ActiveFilterTags.tsx +19 -18
- package/src/presentation/molecules/Avatar.tsx +1 -1
- package/src/presentation/molecules/CodeBlock.tsx +51 -48
- package/src/presentation/molecules/ListItem.tsx +40 -29
- package/src/presentation/molecules/Select.tsx +1 -1
- package/src/presentation/molecules/Toggle.tsx +4 -4
- package/src/presentation/molecules/index.ts +0 -3
- package/src/presentation/organisms/Alert.tsx +1 -1
- package/src/presentation/organisms/DataTable.tsx +24 -11
- package/src/presentation/organisms/Dialog.tsx +1 -1
- package/src/presentation/organisms/DropdownMenu.tsx +2 -2
- package/src/presentation/organisms/HoverCard.tsx +1 -1
- package/src/presentation/organisms/LoadingState.tsx +1 -5
- package/src/presentation/organisms/Popover.tsx +1 -1
- package/src/presentation/organisms/StatCard.tsx +2 -2
- package/src/presentation/organisms/Table.tsx +2 -2
- package/src/presentation/organisms/index.ts +0 -60
- package/src/styles/compile.css +18 -0
- package/src/styles/theme.css +131 -0
- package/src/domain/tokens/animation.tokens.ts +0 -87
- package/src/domain/tokens/color.tokens.ts +0 -95
- package/src/domain/tokens/radius.tokens.ts +0 -27
- package/src/domain/tokens/shadow.tokens.ts +0 -25
- package/src/domain/tokens/spacing.tokens.ts +0 -65
- package/src/domain/tokens/typography.tokens.ts +0 -74
- package/src/infrastructure/error/ErrorBoundary.tsx +0 -258
- package/src/infrastructure/error/ErrorDisplay.tsx +0 -346
- package/src/infrastructure/error/SuspenseWrapper.tsx +0 -133
- package/src/infrastructure/error/index.ts +0 -5
- package/src/infrastructure/performance/index.ts +0 -92
- package/src/infrastructure/performance/useLazyLoading.ts +0 -342
- package/src/infrastructure/performance/useMemoryOptimization.ts +0 -293
- package/src/infrastructure/performance/usePerformanceMonitor.ts +0 -158
- package/src/infrastructure/security/index.ts +0 -10
- package/src/infrastructure/security/security-config.ts +0 -171
- package/src/infrastructure/security/useFormValidation.ts +0 -216
- package/src/infrastructure/security/validation.ts +0 -246
- package/src/presentation/hooks/useLanguage.ts +0 -109
- package/src/presentation/molecules/Breadcrumb.tsx +0 -54
- package/src/presentation/organisms/AlertDialog.tsx +0 -181
- package/src/presentation/organisms/Calendar.tsx +0 -79
- package/src/presentation/organisms/Comments.tsx +0 -103
- package/src/presentation/organisms/ConfirmDialog.tsx +0 -97
- package/src/presentation/organisms/FilterBar.tsx +0 -244
- package/src/presentation/organisms/FilterSidebar.tsx +0 -172
- package/src/presentation/organisms/Footer.tsx +0 -86
- package/src/presentation/organisms/FormModal.tsx +0 -126
- package/src/presentation/organisms/Grid.tsx +0 -128
- package/src/presentation/organisms/ImageLightbox.tsx +0 -252
- package/src/presentation/organisms/MainNavbar.tsx +0 -320
- package/src/presentation/organisms/Modal.tsx +0 -173
- package/src/presentation/organisms/Navbar.tsx +0 -75
- package/src/presentation/organisms/NewsletterSignup.tsx +0 -165
- package/src/presentation/organisms/QuickActionCard.tsx +0 -93
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useCallback, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface MemoryOptimizationConfig {
|
|
4
|
-
enableCleanupLogging?: boolean;
|
|
5
|
-
trackEventListeners?: boolean;
|
|
6
|
-
trackTimers?: boolean;
|
|
7
|
-
trackSubscriptions?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CleanupFunction {
|
|
11
|
-
(): void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useMemoryOptimization = (config: MemoryOptimizationConfig = {}) => {
|
|
15
|
-
const {
|
|
16
|
-
enableCleanupLogging = import.meta.env.DEV,
|
|
17
|
-
trackEventListeners = true,
|
|
18
|
-
trackTimers = true,
|
|
19
|
-
trackSubscriptions = true
|
|
20
|
-
} = config;
|
|
21
|
-
|
|
22
|
-
const cleanupFunctions = useRef<CleanupFunction[]>([]);
|
|
23
|
-
const eventListeners = useRef<Array<{
|
|
24
|
-
element: EventTarget;
|
|
25
|
-
event: string;
|
|
26
|
-
handler: EventListener;
|
|
27
|
-
options?: AddEventListenerOptions;
|
|
28
|
-
}>>([]);
|
|
29
|
-
const timers = useRef<Array<{
|
|
30
|
-
id: number;
|
|
31
|
-
type: 'timeout' | 'interval';
|
|
32
|
-
}>>([]);
|
|
33
|
-
const subscriptions = useRef<Array<{
|
|
34
|
-
name: string;
|
|
35
|
-
unsubscribe: () => void;
|
|
36
|
-
}>>([]);
|
|
37
|
-
|
|
38
|
-
const addCleanup = useCallback((cleanup: CleanupFunction, name?: string) => {
|
|
39
|
-
cleanupFunctions.current.push(cleanup);
|
|
40
|
-
|
|
41
|
-
if (enableCleanupLogging && name) {
|
|
42
|
-
console.log(`[Memory] Added cleanup: ${name}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return () => {
|
|
46
|
-
const index = cleanupFunctions.current.indexOf(cleanup);
|
|
47
|
-
if (index > -1) {
|
|
48
|
-
cleanupFunctions.current.splice(index, 1);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}, [enableCleanupLogging]);
|
|
52
|
-
|
|
53
|
-
const addEventListener = useCallback((
|
|
54
|
-
element: EventTarget,
|
|
55
|
-
event: string,
|
|
56
|
-
handler: EventListener,
|
|
57
|
-
options?: AddEventListenerOptions
|
|
58
|
-
) => {
|
|
59
|
-
if (!trackEventListeners) {
|
|
60
|
-
element.addEventListener(event, handler, options);
|
|
61
|
-
return () => element.removeEventListener(event, handler, options);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
element.addEventListener(event, handler, options);
|
|
65
|
-
|
|
66
|
-
const listenerInfo = { element, event, handler, options };
|
|
67
|
-
eventListeners.current.push(listenerInfo);
|
|
68
|
-
|
|
69
|
-
if (enableCleanupLogging) {
|
|
70
|
-
console.log(`[Memory] Added event listener: ${event}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return () => {
|
|
74
|
-
element.removeEventListener(event, handler, options);
|
|
75
|
-
const index = eventListeners.current.indexOf(listenerInfo);
|
|
76
|
-
if (index > -1) {
|
|
77
|
-
eventListeners.current.splice(index, 1);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}, [trackEventListeners, enableCleanupLogging]);
|
|
81
|
-
|
|
82
|
-
const setTimeout = useCallback((
|
|
83
|
-
callback: () => void,
|
|
84
|
-
delay: number
|
|
85
|
-
) => {
|
|
86
|
-
const id = window.setTimeout(callback, delay);
|
|
87
|
-
|
|
88
|
-
if (trackTimers) {
|
|
89
|
-
timers.current.push({ id, type: 'timeout' });
|
|
90
|
-
|
|
91
|
-
if (enableCleanupLogging) {
|
|
92
|
-
console.log(`[Memory] Added timeout: ${id}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return id;
|
|
97
|
-
}, [trackTimers, enableCleanupLogging]);
|
|
98
|
-
|
|
99
|
-
const setInterval = useCallback((
|
|
100
|
-
callback: () => void,
|
|
101
|
-
delay: number
|
|
102
|
-
) => {
|
|
103
|
-
const id = window.setInterval(callback, delay);
|
|
104
|
-
|
|
105
|
-
if (trackTimers) {
|
|
106
|
-
timers.current.push({ id, type: 'interval' });
|
|
107
|
-
|
|
108
|
-
if (enableCleanupLogging) {
|
|
109
|
-
console.log(`[Memory] Added interval: ${id}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return id;
|
|
114
|
-
}, [trackTimers, enableCleanupLogging]);
|
|
115
|
-
|
|
116
|
-
const clearTimeout = useCallback((id: number) => {
|
|
117
|
-
window.clearTimeout(id);
|
|
118
|
-
|
|
119
|
-
if (trackTimers) {
|
|
120
|
-
const index = timers.current.findIndex(timer => timer.id === id);
|
|
121
|
-
if (index > -1) {
|
|
122
|
-
timers.current.splice(index, 1);
|
|
123
|
-
|
|
124
|
-
if (enableCleanupLogging) {
|
|
125
|
-
console.log(`[Memory] Cleared timeout: ${id}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [trackTimers, enableCleanupLogging]);
|
|
130
|
-
|
|
131
|
-
const clearInterval = useCallback((id: number) => {
|
|
132
|
-
window.clearInterval(id);
|
|
133
|
-
|
|
134
|
-
if (trackTimers) {
|
|
135
|
-
const index = timers.current.findIndex(timer => timer.id === id);
|
|
136
|
-
if (index > -1) {
|
|
137
|
-
timers.current.splice(index, 1);
|
|
138
|
-
|
|
139
|
-
if (enableCleanupLogging) {
|
|
140
|
-
console.log(`[Memory] Cleared interval: ${id}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}, [trackTimers, enableCleanupLogging]);
|
|
145
|
-
|
|
146
|
-
const addSubscription = useCallback((
|
|
147
|
-
name: string,
|
|
148
|
-
unsubscribe: () => void
|
|
149
|
-
) => {
|
|
150
|
-
if (!trackSubscriptions) {
|
|
151
|
-
return unsubscribe;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const subscription = { name, unsubscribe };
|
|
155
|
-
subscriptions.current.push(subscription);
|
|
156
|
-
|
|
157
|
-
if (enableCleanupLogging) {
|
|
158
|
-
console.log(`[Memory] Added subscription: ${name}`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return () => {
|
|
162
|
-
unsubscribe();
|
|
163
|
-
const index = subscriptions.current.indexOf(subscription);
|
|
164
|
-
if (index > -1) {
|
|
165
|
-
subscriptions.current.splice(index, 1);
|
|
166
|
-
|
|
167
|
-
if (enableCleanupLogging) {
|
|
168
|
-
console.log(`[Memory] Unsubscribed: ${name}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}, [trackSubscriptions, enableCleanupLogging]);
|
|
173
|
-
|
|
174
|
-
const getMemoryStats = useCallback(() => {
|
|
175
|
-
return {
|
|
176
|
-
cleanupFunctions: cleanupFunctions.current.length,
|
|
177
|
-
eventListeners: eventListeners.current.length,
|
|
178
|
-
timers: timers.current.length,
|
|
179
|
-
subscriptions: subscriptions.current.length,
|
|
180
|
-
totalTrackedItems:
|
|
181
|
-
cleanupFunctions.current.length +
|
|
182
|
-
eventListeners.current.length +
|
|
183
|
-
timers.current.length +
|
|
184
|
-
subscriptions.current.length
|
|
185
|
-
};
|
|
186
|
-
}, []);
|
|
187
|
-
|
|
188
|
-
const cleanup = useCallback(() => {
|
|
189
|
-
if (enableCleanupLogging) {
|
|
190
|
-
const stats = getMemoryStats();
|
|
191
|
-
console.log(`[Memory] Running cleanup with ${stats.totalTrackedItems} items`);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
eventListeners.current.forEach(({ element, event, handler, options }) => {
|
|
195
|
-
element.removeEventListener(event, handler, options);
|
|
196
|
-
});
|
|
197
|
-
eventListeners.current = [];
|
|
198
|
-
|
|
199
|
-
timers.current.forEach(({ id, type }) => {
|
|
200
|
-
if (type === 'timeout') {
|
|
201
|
-
window.clearTimeout(id);
|
|
202
|
-
} else {
|
|
203
|
-
window.clearInterval(id);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
timers.current = [];
|
|
207
|
-
|
|
208
|
-
subscriptions.current.forEach(({ unsubscribe }) => {
|
|
209
|
-
unsubscribe();
|
|
210
|
-
});
|
|
211
|
-
subscriptions.current = [];
|
|
212
|
-
|
|
213
|
-
cleanupFunctions.current.forEach(cleanup => {
|
|
214
|
-
try {
|
|
215
|
-
cleanup();
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error('[Memory] Cleanup function failed:', error);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
cleanupFunctions.current = [];
|
|
221
|
-
|
|
222
|
-
if (enableCleanupLogging) {
|
|
223
|
-
console.log('[Memory] Cleanup complete');
|
|
224
|
-
}
|
|
225
|
-
}, [enableCleanupLogging, getMemoryStats]);
|
|
226
|
-
|
|
227
|
-
useEffect(() => {
|
|
228
|
-
return () => {
|
|
229
|
-
if (enableCleanupLogging) {
|
|
230
|
-
const stats = getMemoryStats();
|
|
231
|
-
console.log(`[Memory] Unmounting with ${stats.totalTrackedItems} items to clean`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
cleanup();
|
|
235
|
-
};
|
|
236
|
-
}, [cleanup, enableCleanupLogging, getMemoryStats]);
|
|
237
|
-
|
|
238
|
-
return {
|
|
239
|
-
addCleanup,
|
|
240
|
-
addEventListener,
|
|
241
|
-
setTimeout,
|
|
242
|
-
setInterval,
|
|
243
|
-
clearTimeout,
|
|
244
|
-
clearInterval,
|
|
245
|
-
addSubscription,
|
|
246
|
-
getMemoryStats,
|
|
247
|
-
cleanup
|
|
248
|
-
};
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
export const useMemoryLeakDetector = (componentName?: string) => {
|
|
252
|
-
const mountTime = useRef<number>(Date.now());
|
|
253
|
-
const [renderCount, setRenderCount] = useState<number>(0);
|
|
254
|
-
const [lifespan, setLifespan] = useState<number>(0);
|
|
255
|
-
|
|
256
|
-
useEffect(() => {
|
|
257
|
-
setRenderCount(prev => {
|
|
258
|
-
const newCount = prev + 1;
|
|
259
|
-
|
|
260
|
-
if (newCount > 100 && newCount % 10 === 0) {
|
|
261
|
-
console.warn(
|
|
262
|
-
`[Memory Leak] ${componentName || 'Component'} has rendered ${newCount} times. ` +
|
|
263
|
-
'This might indicate a memory leak or unnecessary re-renders.'
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return newCount;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
useEffect(() => {
|
|
272
|
-
const interval = setInterval(() => {
|
|
273
|
-
setLifespan(Date.now() - mountTime.current);
|
|
274
|
-
}, 1000);
|
|
275
|
-
|
|
276
|
-
return () => {
|
|
277
|
-
clearInterval(interval);
|
|
278
|
-
const finalLifespan = Date.now() - mountTime.current;
|
|
279
|
-
|
|
280
|
-
if (import.meta.env.DEV) {
|
|
281
|
-
console.log(
|
|
282
|
-
`[Memory] ${componentName || 'Component'} unmounted after ${finalLifespan}ms ` +
|
|
283
|
-
`with ${renderCount} renders`
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
}, [componentName, renderCount]);
|
|
288
|
-
|
|
289
|
-
return {
|
|
290
|
-
renderCount,
|
|
291
|
-
lifespan
|
|
292
|
-
};
|
|
293
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
export interface PerformanceMetrics {
|
|
4
|
-
renderTime: number;
|
|
5
|
-
mountTime: number;
|
|
6
|
-
updateCount: number;
|
|
7
|
-
lastRenderTime: number;
|
|
8
|
-
averageRenderTime: number;
|
|
9
|
-
memoryUsage?: number;
|
|
10
|
-
componentName?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface PerformanceConfig {
|
|
14
|
-
trackRenders?: boolean;
|
|
15
|
-
trackMemory?: boolean;
|
|
16
|
-
sampleRate?: number;
|
|
17
|
-
componentName?: string;
|
|
18
|
-
onMetricsUpdate?: (metrics: PerformanceMetrics) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const usePerformanceMonitor = (config: PerformanceConfig = {}) => {
|
|
22
|
-
const {
|
|
23
|
-
trackRenders = true,
|
|
24
|
-
trackMemory = false,
|
|
25
|
-
sampleRate = 1.0,
|
|
26
|
-
componentName = 'Unknown',
|
|
27
|
-
onMetricsUpdate
|
|
28
|
-
} = config;
|
|
29
|
-
|
|
30
|
-
const [metrics, setMetrics] = useState<PerformanceMetrics>({
|
|
31
|
-
renderTime: 0,
|
|
32
|
-
mountTime: 0,
|
|
33
|
-
updateCount: 0,
|
|
34
|
-
lastRenderTime: 0,
|
|
35
|
-
averageRenderTime: 0,
|
|
36
|
-
componentName
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const mountTimeRef = useRef<number>(0);
|
|
40
|
-
const renderStartRef = useRef<number>(0);
|
|
41
|
-
const renderTimesRef = useRef<number[]>([]);
|
|
42
|
-
const updateCountRef = useRef<number>(0);
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
mountTimeRef.current = performance.now();
|
|
46
|
-
renderStartRef.current = performance.now();
|
|
47
|
-
|
|
48
|
-
return () => {
|
|
49
|
-
// Component unmount
|
|
50
|
-
};
|
|
51
|
-
}, [componentName]);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!trackRenders || Math.random() > sampleRate) return;
|
|
55
|
-
|
|
56
|
-
const renderEndTime = performance.now();
|
|
57
|
-
const renderTime = renderEndTime - renderStartRef.current;
|
|
58
|
-
|
|
59
|
-
renderTimesRef.current.push(renderTime);
|
|
60
|
-
updateCountRef.current += 1;
|
|
61
|
-
|
|
62
|
-
if (renderTimesRef.current.length > 50) {
|
|
63
|
-
renderTimesRef.current = renderTimesRef.current.slice(-50);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const averageRenderTime = renderTimesRef.current.reduce((sum, time) => sum + time, 0) / renderTimesRef.current.length;
|
|
67
|
-
|
|
68
|
-
let memoryUsage: number | undefined;
|
|
69
|
-
if (trackMemory && 'memory' in performance) {
|
|
70
|
-
memoryUsage = (performance as { memory?: { usedJSHeapSize: number } }).memory?.usedJSHeapSize;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const newMetrics: PerformanceMetrics = {
|
|
74
|
-
renderTime,
|
|
75
|
-
mountTime: renderEndTime - mountTimeRef.current,
|
|
76
|
-
updateCount: updateCountRef.current,
|
|
77
|
-
lastRenderTime: renderTime,
|
|
78
|
-
averageRenderTime,
|
|
79
|
-
memoryUsage,
|
|
80
|
-
componentName
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
setMetrics(newMetrics);
|
|
84
|
-
onMetricsUpdate?.(newMetrics);
|
|
85
|
-
|
|
86
|
-
renderStartRef.current = performance.now();
|
|
87
|
-
|
|
88
|
-
if (import.meta.env.DEV) {
|
|
89
|
-
if (renderTime > 16) {
|
|
90
|
-
console.warn(`[Performance] Slow render detected: ${renderTime.toFixed(2)}ms`);
|
|
91
|
-
}
|
|
92
|
-
if (updateCountRef.current % 10 === 0) {
|
|
93
|
-
console.log({
|
|
94
|
-
renders: updateCountRef.current,
|
|
95
|
-
avgRenderTime: averageRenderTime.toFixed(2) + 'ms',
|
|
96
|
-
lastRenderTime: renderTime.toFixed(2) + 'ms'
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, [trackRenders, sampleRate, trackMemory, componentName, onMetricsUpdate]);
|
|
101
|
-
|
|
102
|
-
const resetMetrics = useCallback(() => {
|
|
103
|
-
renderTimesRef.current = [];
|
|
104
|
-
updateCountRef.current = 0;
|
|
105
|
-
mountTimeRef.current = performance.now();
|
|
106
|
-
renderStartRef.current = performance.now();
|
|
107
|
-
|
|
108
|
-
setMetrics({
|
|
109
|
-
renderTime: 0,
|
|
110
|
-
mountTime: 0,
|
|
111
|
-
updateCount: 0,
|
|
112
|
-
lastRenderTime: 0,
|
|
113
|
-
averageRenderTime: 0,
|
|
114
|
-
componentName
|
|
115
|
-
});
|
|
116
|
-
}, [componentName]);
|
|
117
|
-
|
|
118
|
-
const getPerformanceReport = useCallback(() => {
|
|
119
|
-
return {
|
|
120
|
-
...metrics,
|
|
121
|
-
renderTimes: [...renderTimesRef.current],
|
|
122
|
-
isSlowComponent: metrics.averageRenderTime > 16,
|
|
123
|
-
performanceGrade: metrics.averageRenderTime < 5 ? 'A' :
|
|
124
|
-
metrics.averageRenderTime < 10 ? 'B' :
|
|
125
|
-
metrics.averageRenderTime < 16 ? 'C' : 'D'
|
|
126
|
-
};
|
|
127
|
-
}, [metrics]);
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
metrics,
|
|
131
|
-
resetMetrics,
|
|
132
|
-
getPerformanceReport
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const useRenderPerformance = (componentName?: string) => {
|
|
137
|
-
const renderStartTime = useRef<number>(0);
|
|
138
|
-
const [renderStats, setRenderStats] = useState<{
|
|
139
|
-
lastRenderTime: number;
|
|
140
|
-
renderCount: number;
|
|
141
|
-
}>({
|
|
142
|
-
lastRenderTime: 0,
|
|
143
|
-
renderCount: 0
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const startTime = performance.now();
|
|
147
|
-
|
|
148
|
-
useEffect(() => {
|
|
149
|
-
setRenderStats(prev => ({
|
|
150
|
-
lastRenderTime: performance.now() - startTime,
|
|
151
|
-
renderCount: prev.renderCount + 1
|
|
152
|
-
}));
|
|
153
|
-
|
|
154
|
-
renderStartTime.current = performance.now();
|
|
155
|
-
}, [componentName, renderStats, startTime]);
|
|
156
|
-
|
|
157
|
-
return renderStats;
|
|
158
|
-
};
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import type { ValidationConfig } from './validation';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Content Security Policy configuration
|
|
5
|
-
* Helps prevent XSS attacks by controlling resource loading
|
|
6
|
-
*/
|
|
7
|
-
export const CSP_CONFIG = {
|
|
8
|
-
directives: {
|
|
9
|
-
'default-src': ["'self'"],
|
|
10
|
-
'script-src': ["'self'", "'unsafe-inline'"],
|
|
11
|
-
'style-src': ["'self'", "'unsafe-inline'"],
|
|
12
|
-
'img-src': ["'self'", "data:", "https:"],
|
|
13
|
-
'connect-src': ["'self'", "https:", "wss:"],
|
|
14
|
-
'font-src': ["'self'", "https:", "data:"],
|
|
15
|
-
'object-src': ["'none'"],
|
|
16
|
-
'media-src': ["'self'", "https:"],
|
|
17
|
-
'frame-src': ["'none'"],
|
|
18
|
-
'worker-src': ["'self'"],
|
|
19
|
-
'child-src': ["'none'"],
|
|
20
|
-
'form-action': ["'self'"],
|
|
21
|
-
'base-uri': ["'self'"],
|
|
22
|
-
'manifest-src': ["'self'"
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
} as const;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Validation configurations for different content types
|
|
29
|
-
*/
|
|
30
|
-
export const VALIDATION_CONFIGS: Record<string, ValidationConfig> = {
|
|
31
|
-
PLAIN_TEXT: {
|
|
32
|
-
allowHtml: false,
|
|
33
|
-
stripTags: true,
|
|
34
|
-
allowedTags: [],
|
|
35
|
-
allowedAttributes: []
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
RICH_TEXT: {
|
|
39
|
-
allowHtml: true,
|
|
40
|
-
stripTags: false,
|
|
41
|
-
allowedTags: ['p', 'br', 'strong', 'em', 'u', 'ol', 'ul', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
|
42
|
-
allowedAttributes: ['class']
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
LINK_CONTENT: {
|
|
46
|
-
allowHtml: true,
|
|
47
|
-
stripTags: false,
|
|
48
|
-
allowedTags: ['a', 'p', 'br', 'strong', 'em'],
|
|
49
|
-
allowedAttributes: ['href', 'title', 'target']
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
USER_PROFILE: {
|
|
53
|
-
allowHtml: false,
|
|
54
|
-
stripTags: true,
|
|
55
|
-
allowedTags: [],
|
|
56
|
-
allowedAttributes: []
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
COMMENT: {
|
|
60
|
-
allowHtml: true,
|
|
61
|
-
stripTags: false,
|
|
62
|
-
allowedTags: ['p', 'br', 'strong', 'em'],
|
|
63
|
-
allowedAttributes: []
|
|
64
|
-
}
|
|
65
|
-
} as const;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* File upload security settings
|
|
69
|
-
*/
|
|
70
|
-
export const FILE_SECURITY_CONFIG = {
|
|
71
|
-
allowedMimeTypes: {
|
|
72
|
-
image: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
|
73
|
-
audio: ['audio/mpeg', 'audio/wav', 'audio/mp4', 'audio/flac'],
|
|
74
|
-
video: ['video/mp4', 'video/webm', 'video/quicktime'],
|
|
75
|
-
document: ['application/pdf', 'text/plain'],
|
|
76
|
-
avatar: ['image/jpeg', 'image/png', 'image/webp']
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
maxFileSizes: {
|
|
80
|
-
image: 10 * 1024 * 1024,
|
|
81
|
-
audio: 100 * 1024 * 1024,
|
|
82
|
-
video: 500 * 1024 * 1024,
|
|
83
|
-
document: 5 * 1024 * 1024,
|
|
84
|
-
avatar: 2 * 1024 * 1024
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
blockedExtensions: [
|
|
88
|
-
'.exe', '.bat', '.cmd', '.com', '.pif', '.scr', '.vbs', '.js', '.jar',
|
|
89
|
-
'.app', '.deb', '.pkg', '.dmg', '.rpm', '.msi', '.apk', '.ipa'
|
|
90
|
-
],
|
|
91
|
-
|
|
92
|
-
blockedPatterns: [
|
|
93
|
-
/^\./,
|
|
94
|
-
/\.\.$/,
|
|
95
|
-
/[<>:"|?*]/,
|
|
96
|
-
/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i
|
|
97
|
-
]
|
|
98
|
-
} as const;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Rate limiting configuration
|
|
102
|
-
*/
|
|
103
|
-
export const RATE_LIMIT_CONFIG = {
|
|
104
|
-
api: {
|
|
105
|
-
default: 100,
|
|
106
|
-
auth: 10,
|
|
107
|
-
upload: 20,
|
|
108
|
-
generation: 30,
|
|
109
|
-
export: 10
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
actions: {
|
|
113
|
-
login: 5,
|
|
114
|
-
registration: 3,
|
|
115
|
-
passwordReset: 3,
|
|
116
|
-
contentCreation: 50,
|
|
117
|
-
fileUpload: 100
|
|
118
|
-
}
|
|
119
|
-
} as const;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Session security configuration
|
|
123
|
-
*/
|
|
124
|
-
export const SESSION_CONFIG = {
|
|
125
|
-
timeout: 720,
|
|
126
|
-
refreshThreshold: 60,
|
|
127
|
-
maxSessions: 5,
|
|
128
|
-
cookie: {
|
|
129
|
-
httpOnly: true,
|
|
130
|
-
secure: true,
|
|
131
|
-
sameSite: 'strict' as const,
|
|
132
|
-
maxAge: 720 * 60 * 1000
|
|
133
|
-
}
|
|
134
|
-
} as const;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Security headers configuration
|
|
138
|
-
*/
|
|
139
|
-
export const SECURITY_HEADERS = {
|
|
140
|
-
'X-Content-Type-Options': 'nosniff',
|
|
141
|
-
'X-Frame-Options': 'DENY',
|
|
142
|
-
'X-XSS-Protection': '1; mode=block',
|
|
143
|
-
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
144
|
-
'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
|
|
145
|
-
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
|
|
146
|
-
} as const;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* CORS configuration
|
|
150
|
-
*/
|
|
151
|
-
export const CORS_CONFIG = {
|
|
152
|
-
origin: [
|
|
153
|
-
'http://localhost:3000',
|
|
154
|
-
'http://localhost:5173',
|
|
155
|
-
'https://amaterasu.app'
|
|
156
|
-
],
|
|
157
|
-
credentials: true,
|
|
158
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
159
|
-
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
|
160
|
-
maxAge: 86400
|
|
161
|
-
} as const;
|
|
162
|
-
|
|
163
|
-
export default {
|
|
164
|
-
CSP_CONFIG,
|
|
165
|
-
VALIDATION_CONFIGS,
|
|
166
|
-
FILE_SECURITY_CONFIG,
|
|
167
|
-
RATE_LIMIT_CONFIG,
|
|
168
|
-
SESSION_CONFIG,
|
|
169
|
-
SECURITY_HEADERS,
|
|
170
|
-
CORS_CONFIG
|
|
171
|
-
};
|