@moontra/moonui-pro 2.20.0 → 2.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +691 -261
- package/dist/index.mjs +7419 -4935
- package/package.json +4 -3
- package/scripts/postbuild.js +27 -0
- package/src/components/advanced-chart/index.tsx +5 -1
- package/src/components/advanced-forms/index.tsx +175 -16
- package/src/components/calendar/event-dialog.tsx +18 -13
- package/src/components/calendar/index.tsx +197 -50
- package/src/components/dashboard/dashboard-grid.tsx +21 -3
- package/src/components/dashboard/types.ts +3 -0
- package/src/components/dashboard/widgets/activity-feed.tsx +6 -1
- package/src/components/dashboard/widgets/comparison-widget.tsx +177 -0
- package/src/components/dashboard/widgets/index.ts +5 -0
- package/src/components/dashboard/widgets/metric-card.tsx +21 -1
- package/src/components/dashboard/widgets/progress-widget.tsx +113 -0
- package/src/components/error-boundary/index.tsx +160 -37
- package/src/components/form-wizard/form-wizard-context.tsx +54 -26
- package/src/components/form-wizard/form-wizard-progress.tsx +33 -2
- package/src/components/form-wizard/types.ts +2 -1
- package/src/components/github-stars/hooks.ts +1 -0
- package/src/components/github-stars/variants.tsx +3 -1
- package/src/components/health-check/index.tsx +14 -14
- package/src/components/hover-card-3d/index.tsx +2 -3
- package/src/components/index.ts +5 -3
- package/src/components/kanban/kanban.tsx +23 -18
- package/src/components/license-error/index.tsx +2 -0
- package/src/components/magnetic-button/index.tsx +56 -7
- package/src/components/memory-efficient-data/index.tsx +117 -115
- package/src/components/navbar/index.tsx +781 -0
- package/src/components/performance-debugger/index.tsx +62 -38
- package/src/components/performance-monitor/index.tsx +47 -33
- package/src/components/phone-number-input/index.tsx +32 -27
- package/src/components/phone-number-input/phone-number-input-simple.tsx +167 -0
- package/src/components/rich-text-editor/index.tsx +26 -28
- package/src/components/rich-text-editor/slash-commands-extension.ts +15 -5
- package/src/components/sidebar/index.tsx +32 -13
- package/src/components/timeline/index.tsx +84 -49
- package/src/components/ui/accordion.tsx +550 -42
- package/src/components/ui/avatar.tsx +2 -0
- package/src/components/ui/badge.tsx +2 -0
- package/src/components/ui/breadcrumb.tsx +2 -0
- package/src/components/ui/button.tsx +39 -33
- package/src/components/ui/card.tsx +2 -0
- package/src/components/ui/collapsible.tsx +546 -50
- package/src/components/ui/command.tsx +790 -67
- package/src/components/ui/dialog.tsx +510 -92
- package/src/components/ui/dropdown-menu.tsx +540 -52
- package/src/components/ui/index.ts +37 -5
- package/src/components/ui/input.tsx +2 -0
- package/src/components/ui/magnetic-button.tsx +1 -1
- package/src/components/ui/media-gallery.tsx +1 -2
- package/src/components/ui/navigation-menu.tsx +130 -0
- package/src/components/ui/pagination.tsx +2 -0
- package/src/components/ui/select.tsx +6 -2
- package/src/components/ui/spotlight-card.tsx +1 -1
- package/src/components/ui/table.tsx +2 -0
- package/src/components/ui/tabs-pro.tsx +542 -0
- package/src/components/ui/tabs.tsx +23 -167
- package/src/components/ui/toggle.tsx +13 -13
- package/src/index.ts +11 -3
- package/src/styles/index.css +596 -0
- package/src/use-performance-optimizer.ts +1 -1
- package/src/utils/chart-helpers.ts +1 -1
- package/src/__tests__/use-intersection-observer.test.tsx +0 -216
- package/src/__tests__/use-local-storage.test.tsx +0 -174
- package/src/__tests__/use-pro-access.test.tsx +0 -183
- package/src/components/advanced-chart/advanced-chart.test.tsx +0 -281
- package/src/components/data-table/data-table.test.tsx +0 -187
- package/src/components/enhanced/badge.tsx +0 -191
- package/src/components/enhanced/button.tsx +0 -362
- package/src/components/enhanced/card.tsx +0 -266
- package/src/components/enhanced/dialog.tsx +0 -246
- package/src/components/enhanced/index.ts +0 -4
- package/src/components/file-upload/file-upload.test.tsx +0 -243
- package/src/components/rich-text-editor/index-old-backup.tsx +0 -437
- package/src/types/moonui.d.ts +0 -22
|
@@ -5,7 +5,7 @@ import { motion, AnimatePresence } from 'framer-motion'
|
|
|
5
5
|
import { cn } from '../../lib/utils'
|
|
6
6
|
import { Search, Filter, Download, SortAsc, SortDesc, BarChart3, Cpu, Clock, Zap } from 'lucide-react'
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Type definitions for memory configuration
|
|
9
9
|
interface MemoryConfig {
|
|
10
10
|
chunkSize?: number
|
|
11
11
|
maxMemoryItems?: number
|
|
@@ -16,7 +16,7 @@ interface MemoryConfig {
|
|
|
16
16
|
streamingMode?: boolean
|
|
17
17
|
enableAnalytics?: boolean
|
|
18
18
|
analyticsCallback?: (stats: MemoryStats) => void
|
|
19
|
-
//
|
|
19
|
+
// New features
|
|
20
20
|
variableHeight?: boolean
|
|
21
21
|
preloadStrategy?: 'none' | 'aggressive' | 'smart'
|
|
22
22
|
performanceTracking?: boolean
|
|
@@ -27,7 +27,7 @@ interface MemoryConfig {
|
|
|
27
27
|
animations?: boolean
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// Type definition for performance metrics
|
|
31
31
|
interface MemoryPerformanceMetrics {
|
|
32
32
|
fps: number
|
|
33
33
|
renderTime: number
|
|
@@ -36,7 +36,7 @@ interface MemoryPerformanceMetrics {
|
|
|
36
36
|
lastUpdate: number
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// Search/Sort/Filter
|
|
39
|
+
// Type definitions for Search/Sort/Filter
|
|
40
40
|
interface TableFeatures<T> {
|
|
41
41
|
searchTerm?: string
|
|
42
42
|
sortConfig?: {
|
|
@@ -50,14 +50,14 @@ interface TableFeatures<T> {
|
|
|
50
50
|
}>
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
//
|
|
53
|
+
// Type definition for height measurement
|
|
54
54
|
interface ItemHeightInfo {
|
|
55
55
|
index: number
|
|
56
56
|
height: number
|
|
57
57
|
offset: number
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
//
|
|
60
|
+
// Type definition for memory statistics
|
|
61
61
|
interface MemoryStats {
|
|
62
62
|
memoryUsage: number
|
|
63
63
|
itemCount: number
|
|
@@ -67,7 +67,7 @@ interface MemoryStats {
|
|
|
67
67
|
performance?: MemoryPerformanceMetrics
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
//
|
|
70
|
+
// Main component props
|
|
71
71
|
export interface MemoryEfficientDataProps<T = any> {
|
|
72
72
|
data: T[]
|
|
73
73
|
config?: MemoryConfig
|
|
@@ -75,7 +75,7 @@ export interface MemoryEfficientDataProps<T = any> {
|
|
|
75
75
|
height?: number
|
|
76
76
|
onMemoryUpdate?: (stats: MemoryStats) => void
|
|
77
77
|
className?: string
|
|
78
|
-
//
|
|
78
|
+
// New features
|
|
79
79
|
itemHeight?: number | ((item: T, index: number) => number)
|
|
80
80
|
onSearch?: (searchTerm: string) => T[]
|
|
81
81
|
onSort?: (data: T[], key: keyof T, direction: 'asc' | 'desc') => T[]
|
|
@@ -127,7 +127,7 @@ class MemoryCache<T> {
|
|
|
127
127
|
|
|
128
128
|
switch (this.strategy) {
|
|
129
129
|
case 'lru':
|
|
130
|
-
//
|
|
130
|
+
// Delete least recently used
|
|
131
131
|
let oldestTime = Infinity
|
|
132
132
|
for (const [key, node] of this.cache) {
|
|
133
133
|
if (node.timestamp < oldestTime) {
|
|
@@ -138,7 +138,7 @@ class MemoryCache<T> {
|
|
|
138
138
|
break
|
|
139
139
|
|
|
140
140
|
case 'lfu':
|
|
141
|
-
//
|
|
141
|
+
// Delete least frequently used
|
|
142
142
|
let minAccess = Infinity
|
|
143
143
|
for (const [key, node] of this.cache) {
|
|
144
144
|
if (node.accessCount < minAccess) {
|
|
@@ -149,7 +149,7 @@ class MemoryCache<T> {
|
|
|
149
149
|
break
|
|
150
150
|
|
|
151
151
|
case 'fifo':
|
|
152
|
-
//
|
|
152
|
+
// Delete first in
|
|
153
153
|
keyToDelete = this.cache.keys().next().value || null
|
|
154
154
|
break
|
|
155
155
|
}
|
|
@@ -184,7 +184,7 @@ class MemoryCache<T> {
|
|
|
184
184
|
return total === 0 ? 0 : this.hitCount / total
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
//
|
|
187
|
+
// Update for hit/miss tracking
|
|
188
188
|
get(key: string): T[] | null {
|
|
189
189
|
const node = this.cache.get(key)
|
|
190
190
|
if (!node) {
|
|
@@ -214,7 +214,7 @@ class PerformanceTracker {
|
|
|
214
214
|
const renderTime = performance.now() - this.startTime
|
|
215
215
|
this.renderTimes.push(renderTime)
|
|
216
216
|
|
|
217
|
-
//
|
|
217
|
+
// Keep last 60 render times
|
|
218
218
|
if (this.renderTimes.length > 60) {
|
|
219
219
|
this.renderTimes.shift()
|
|
220
220
|
}
|
|
@@ -226,7 +226,7 @@ class PerformanceTracker {
|
|
|
226
226
|
const fps = 1000 / (now - this.lastFrameTime)
|
|
227
227
|
this.frames.push(fps)
|
|
228
228
|
|
|
229
|
-
//
|
|
229
|
+
// Keep last 60 frames
|
|
230
230
|
if (this.frames.length > 60) {
|
|
231
231
|
this.frames.shift()
|
|
232
232
|
}
|
|
@@ -253,12 +253,12 @@ class PerformanceTracker {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
private detectMemoryLeaks(): number {
|
|
256
|
-
//
|
|
256
|
+
// Simple memory leak detection
|
|
257
257
|
return this.renderTimes.filter(time => time > 16).length // 16ms = 60fps threshold
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
private calculateScrollPerformance(): number {
|
|
261
|
-
//
|
|
261
|
+
// Calculate scroll performance (0-100 score)
|
|
262
262
|
const avgFPS = this.frames.length > 0
|
|
263
263
|
? this.frames.reduce((a, b) => a + b, 0) / this.frames.length
|
|
264
264
|
: 60
|
|
@@ -318,7 +318,7 @@ class VariableHeightManager {
|
|
|
318
318
|
let start = 0
|
|
319
319
|
let currentOffset = 0
|
|
320
320
|
|
|
321
|
-
//
|
|
321
|
+
// Count items up to scroll position
|
|
322
322
|
while (start < itemCount && currentOffset < scrollTop) {
|
|
323
323
|
currentOffset += this.getItemHeight(start)
|
|
324
324
|
start++
|
|
@@ -326,7 +326,7 @@ class VariableHeightManager {
|
|
|
326
326
|
|
|
327
327
|
start = Math.max(0, start - 1)
|
|
328
328
|
|
|
329
|
-
//
|
|
329
|
+
// Continue through visible area
|
|
330
330
|
let end = start
|
|
331
331
|
const targetOffset = scrollTop + containerHeight
|
|
332
332
|
currentOffset = this.getOffsetForIndex(start)
|
|
@@ -340,22 +340,22 @@ class VariableHeightManager {
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
//
|
|
344
|
-
|
|
343
|
+
// Main Memory Efficient Data Component
|
|
344
|
+
function MemoryEfficientData<T = any>({
|
|
345
345
|
data,
|
|
346
346
|
config = {},
|
|
347
347
|
renderItem,
|
|
348
348
|
height = 400,
|
|
349
349
|
onMemoryUpdate,
|
|
350
350
|
className,
|
|
351
|
-
//
|
|
351
|
+
// New props
|
|
352
352
|
itemHeight = 60,
|
|
353
353
|
onSearch,
|
|
354
354
|
onSort,
|
|
355
355
|
onFilter,
|
|
356
356
|
onExport,
|
|
357
|
-
searchPlaceholder = "
|
|
358
|
-
emptyStateMessage = "
|
|
357
|
+
searchPlaceholder = "Search...",
|
|
358
|
+
emptyStateMessage = "No data found",
|
|
359
359
|
loadingComponent,
|
|
360
360
|
errorComponent
|
|
361
361
|
}: MemoryEfficientDataProps<T>) {
|
|
@@ -369,7 +369,7 @@ export function MemoryEfficientData<T = any>({
|
|
|
369
369
|
streamingMode = false,
|
|
370
370
|
enableAnalytics = false,
|
|
371
371
|
analyticsCallback,
|
|
372
|
-
//
|
|
372
|
+
// New configurations
|
|
373
373
|
variableHeight = false,
|
|
374
374
|
preloadStrategy = 'smart',
|
|
375
375
|
performanceTracking = false,
|
|
@@ -380,7 +380,7 @@ export function MemoryEfficientData<T = any>({
|
|
|
380
380
|
animations = true
|
|
381
381
|
} = config
|
|
382
382
|
|
|
383
|
-
// State
|
|
383
|
+
// State management
|
|
384
384
|
const [visibleRange, setVisibleRange] = useState({ start: 0, end: Math.min(chunkSize, data.length) })
|
|
385
385
|
const [memoryStats, setMemoryStats] = useState<MemoryStats>({
|
|
386
386
|
memoryUsage: 0,
|
|
@@ -392,8 +392,6 @@ export function MemoryEfficientData<T = any>({
|
|
|
392
392
|
sortConfig: undefined,
|
|
393
393
|
filters: []
|
|
394
394
|
})
|
|
395
|
-
const [isLoading, setIsLoading] = useState(false)
|
|
396
|
-
const [error, setError] = useState<string | null>(null)
|
|
397
395
|
|
|
398
396
|
// Refs
|
|
399
397
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
@@ -403,13 +401,11 @@ export function MemoryEfficientData<T = any>({
|
|
|
403
401
|
const heightManagerRef = useRef(new VariableHeightManager(typeof itemHeight === 'number' ? itemHeight : 60))
|
|
404
402
|
const itemRefs = useRef<Map<number, HTMLDivElement>>(new Map())
|
|
405
403
|
|
|
406
|
-
//
|
|
404
|
+
// Calculate processed data (search, sort, filter)
|
|
407
405
|
const processedData = useMemo(() => {
|
|
408
406
|
let result = [...data]
|
|
409
407
|
|
|
410
408
|
try {
|
|
411
|
-
setIsLoading(true)
|
|
412
|
-
|
|
413
409
|
// Search functionality
|
|
414
410
|
if (enableSearch && tableFeatures.searchTerm && onSearch) {
|
|
415
411
|
result = onSearch(tableFeatures.searchTerm)
|
|
@@ -425,17 +421,14 @@ export function MemoryEfficientData<T = any>({
|
|
|
425
421
|
result = onSort(result, tableFeatures.sortConfig.key, tableFeatures.sortConfig.direction)
|
|
426
422
|
}
|
|
427
423
|
|
|
428
|
-
setError(null)
|
|
429
424
|
return result
|
|
430
425
|
} catch (err) {
|
|
431
|
-
|
|
426
|
+
console.error('Error processing data:', err)
|
|
432
427
|
return data
|
|
433
|
-
} finally {
|
|
434
|
-
setIsLoading(false)
|
|
435
428
|
}
|
|
436
429
|
}, [data, tableFeatures, enableSearch, enableFilter, enableSort, onSearch, onFilter, onSort])
|
|
437
430
|
|
|
438
|
-
//
|
|
431
|
+
// Memoize visible data
|
|
439
432
|
const visibleData = useMemo(() => {
|
|
440
433
|
if (performanceTracking) {
|
|
441
434
|
performanceTrackerRef.current.startRender()
|
|
@@ -444,7 +437,7 @@ export function MemoryEfficientData<T = any>({
|
|
|
444
437
|
const start = visibleRange.start
|
|
445
438
|
const end = Math.min(visibleRange.end, processedData.length)
|
|
446
439
|
|
|
447
|
-
//
|
|
440
|
+
// Check from cache
|
|
448
441
|
const cacheKey = `${start}-${end}-${JSON.stringify(tableFeatures)}`
|
|
449
442
|
const cachedData = cacheRef.current.get(cacheKey)
|
|
450
443
|
|
|
@@ -455,10 +448,10 @@ export function MemoryEfficientData<T = any>({
|
|
|
455
448
|
return cachedData
|
|
456
449
|
}
|
|
457
450
|
|
|
458
|
-
//
|
|
451
|
+
// Create new data slice
|
|
459
452
|
const newData = processedData.slice(start, end)
|
|
460
453
|
|
|
461
|
-
//
|
|
454
|
+
// Save to cache
|
|
462
455
|
cacheRef.current.set(cacheKey, newData, compression)
|
|
463
456
|
|
|
464
457
|
if (performanceTracking) {
|
|
@@ -498,17 +491,17 @@ export function MemoryEfficientData<T = any>({
|
|
|
498
491
|
let newStart: number, newEnd: number
|
|
499
492
|
|
|
500
493
|
if (variableHeight) {
|
|
501
|
-
//
|
|
494
|
+
// Use variable height
|
|
502
495
|
const range = heightManagerRef.current.getVisibleRange(scrollTop, containerHeight, processedData.length)
|
|
503
496
|
newStart = range.start
|
|
504
497
|
newEnd = range.end
|
|
505
498
|
} else {
|
|
506
|
-
//
|
|
499
|
+
// Use fixed height
|
|
507
500
|
const itemHeightValue = typeof itemHeight === 'number' ? itemHeight : 60
|
|
508
501
|
const startIndex = Math.floor(scrollTop / itemHeightValue)
|
|
509
502
|
const visibleCount = Math.ceil(containerHeight / itemHeightValue)
|
|
510
503
|
|
|
511
|
-
//
|
|
504
|
+
// Add buffer
|
|
512
505
|
const bufferSize = Math.floor(visibleCount * 0.5)
|
|
513
506
|
newStart = Math.max(0, startIndex - bufferSize)
|
|
514
507
|
newEnd = Math.min(processedData.length, startIndex + visibleCount + bufferSize)
|
|
@@ -520,7 +513,7 @@ export function MemoryEfficientData<T = any>({
|
|
|
520
513
|
newStart = Math.max(0, newStart - extraBuffer)
|
|
521
514
|
newEnd = Math.min(processedData.length, newEnd + extraBuffer)
|
|
522
515
|
} else if (preloadStrategy === 'smart') {
|
|
523
|
-
//
|
|
516
|
+
// Preload based on scroll direction
|
|
524
517
|
const currentScroll = scrollTop
|
|
525
518
|
const lastScroll = scrollTimeoutRef.current ? parseInt(scrollTimeoutRef.current as any) : 0
|
|
526
519
|
const isScrollingDown = currentScroll > lastScroll
|
|
@@ -547,22 +540,6 @@ export function MemoryEfficientData<T = any>({
|
|
|
547
540
|
setTableFeatures(prev => ({ ...prev, searchTerm }))
|
|
548
541
|
}, [])
|
|
549
542
|
|
|
550
|
-
// Sort handler
|
|
551
|
-
const handleSort = useCallback((key: keyof T) => {
|
|
552
|
-
setTableFeatures(prev => {
|
|
553
|
-
const currentDirection = prev.sortConfig?.key === key && prev.sortConfig?.direction === 'asc' ? 'desc' : 'asc'
|
|
554
|
-
return {
|
|
555
|
-
...prev,
|
|
556
|
-
sortConfig: { key, direction: currentDirection }
|
|
557
|
-
}
|
|
558
|
-
})
|
|
559
|
-
}, [])
|
|
560
|
-
|
|
561
|
-
// Filter handler
|
|
562
|
-
const handleFilter = useCallback((filters: TableFeatures<T>['filters']) => {
|
|
563
|
-
setTableFeatures(prev => ({ ...prev, filters }))
|
|
564
|
-
}, [])
|
|
565
|
-
|
|
566
543
|
// Export handler
|
|
567
544
|
const handleExport = useCallback((format: 'csv' | 'json' | 'xlsx') => {
|
|
568
545
|
if (onExport) {
|
|
@@ -570,30 +547,39 @@ export function MemoryEfficientData<T = any>({
|
|
|
570
547
|
}
|
|
571
548
|
}, [processedData, onExport])
|
|
572
549
|
|
|
573
|
-
//
|
|
550
|
+
// Update memory statistics - debounced to prevent excessive updates
|
|
574
551
|
useEffect(() => {
|
|
575
|
-
|
|
576
|
-
const performanceMetrics = performanceTracking ? performanceTrackerRef.current.getMetrics() : undefined
|
|
552
|
+
if (!enableAnalytics && !onMemoryUpdate) return
|
|
577
553
|
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
554
|
+
const updateStats = () => {
|
|
555
|
+
const cacheStats = cacheRef.current.getStats()
|
|
556
|
+
const performanceMetrics = performanceTracking ? performanceTrackerRef.current.getMetrics() : undefined
|
|
557
|
+
|
|
558
|
+
const newStats: MemoryStats = {
|
|
559
|
+
memoryUsage: cacheStats.memoryUsage,
|
|
560
|
+
itemCount: visibleData.length,
|
|
561
|
+
cacheHitRate: cacheStats.hitRate,
|
|
562
|
+
compressionRatio: compression ? 0.7 : 1.0,
|
|
563
|
+
lastCleanup: Date.now(),
|
|
564
|
+
performance: performanceMetrics
|
|
565
|
+
}
|
|
586
566
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
567
|
+
setMemoryStats(newStats)
|
|
568
|
+
|
|
569
|
+
if (enableAnalytics && analyticsCallback) {
|
|
570
|
+
analyticsCallback(newStats)
|
|
571
|
+
}
|
|
592
572
|
|
|
593
|
-
|
|
594
|
-
|
|
573
|
+
if (onMemoryUpdate) {
|
|
574
|
+
onMemoryUpdate(newStats)
|
|
575
|
+
}
|
|
595
576
|
}
|
|
596
|
-
|
|
577
|
+
|
|
578
|
+
// Debounce updates to prevent loops
|
|
579
|
+
const timeoutId = setTimeout(updateStats, 500)
|
|
580
|
+
|
|
581
|
+
return () => clearTimeout(timeoutId)
|
|
582
|
+
}, [visibleData.length, enableAnalytics, performanceTracking, compression]) // Remove callbacks from deps
|
|
597
583
|
|
|
598
584
|
// Auto cleanup effect
|
|
599
585
|
useEffect(() => {
|
|
@@ -602,29 +588,25 @@ export function MemoryEfficientData<T = any>({
|
|
|
602
588
|
const cleanupInterval = setInterval(() => {
|
|
603
589
|
const memoryUsage = (visibleData.length / maxMemoryItems)
|
|
604
590
|
if (memoryUsage > cleanupThreshold) {
|
|
605
|
-
//
|
|
591
|
+
// Simple cleanup - clear cache
|
|
606
592
|
cacheRef.current.clear()
|
|
607
593
|
}
|
|
608
|
-
}, 5000) //
|
|
594
|
+
}, 5000) // Check every 5 seconds
|
|
609
595
|
|
|
610
596
|
return () => clearInterval(cleanupInterval)
|
|
611
597
|
}, [autoCleanup, cleanupThreshold, maxMemoryItems, visibleData.length])
|
|
612
598
|
|
|
613
|
-
//
|
|
614
|
-
if (
|
|
615
|
-
return
|
|
599
|
+
// Render for loading and error states
|
|
600
|
+
if (loadingComponent && data.length === 0) {
|
|
601
|
+
return <>{loadingComponent}</>
|
|
616
602
|
}
|
|
617
603
|
|
|
618
|
-
|
|
619
|
-
return loadingComponent
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// Total height hesapla
|
|
604
|
+
// Calculate total height
|
|
623
605
|
const totalHeight = variableHeight
|
|
624
606
|
? heightManagerRef.current.getTotalHeight(processedData.length)
|
|
625
607
|
: processedData.length * (typeof itemHeight === 'number' ? itemHeight : 60)
|
|
626
608
|
|
|
627
|
-
//
|
|
609
|
+
// Calculate offset
|
|
628
610
|
const offsetY = variableHeight
|
|
629
611
|
? heightManagerRef.current.getOffsetForIndex(visibleRange.start)
|
|
630
612
|
: visibleRange.start * (typeof itemHeight === 'number' ? itemHeight : 60)
|
|
@@ -655,9 +637,9 @@ export function MemoryEfficientData<T = any>({
|
|
|
655
637
|
<div className="flex items-center gap-1">
|
|
656
638
|
{enableFilter && (
|
|
657
639
|
<button
|
|
658
|
-
onClick={() => {/* Filter modal
|
|
640
|
+
onClick={() => {/* Filter modal will open */}}
|
|
659
641
|
className="p-2 hover:bg-muted rounded-md transition-colors"
|
|
660
|
-
title="
|
|
642
|
+
title="Filter"
|
|
661
643
|
>
|
|
662
644
|
<Filter className="h-4 w-4" />
|
|
663
645
|
</button>
|
|
@@ -668,7 +650,7 @@ export function MemoryEfficientData<T = any>({
|
|
|
668
650
|
<button
|
|
669
651
|
onClick={() => handleExport('csv')}
|
|
670
652
|
className="p-2 hover:bg-muted rounded-md transition-colors"
|
|
671
|
-
title="
|
|
653
|
+
title="Export"
|
|
672
654
|
>
|
|
673
655
|
<Download className="h-4 w-4" />
|
|
674
656
|
</button>
|
|
@@ -770,11 +752,10 @@ interface RealTimePerformanceMonitorProps {
|
|
|
770
752
|
updateInterval?: number
|
|
771
753
|
}
|
|
772
754
|
|
|
773
|
-
|
|
755
|
+
function RealTimePerformanceMonitor({
|
|
774
756
|
memoryStats,
|
|
775
757
|
className,
|
|
776
|
-
showChart = false
|
|
777
|
-
updateInterval = 1000
|
|
758
|
+
showChart = false
|
|
778
759
|
}: RealTimePerformanceMonitorProps) {
|
|
779
760
|
const [history, setHistory] = useState<MemoryStats[]>([])
|
|
780
761
|
const [isActive, setIsActive] = useState(true)
|
|
@@ -784,7 +765,7 @@ export function RealTimePerformanceMonitor({
|
|
|
784
765
|
|
|
785
766
|
setHistory(prev => {
|
|
786
767
|
const newHistory = [...prev, memoryStats]
|
|
787
|
-
//
|
|
768
|
+
// Keep last 60 entries (1 minute)
|
|
788
769
|
return newHistory.length > 60 ? newHistory.slice(-60) : newHistory
|
|
789
770
|
})
|
|
790
771
|
}, [memoryStats, isActive])
|
|
@@ -807,7 +788,7 @@ export function RealTimePerformanceMonitor({
|
|
|
807
788
|
return (
|
|
808
789
|
<div className={cn("p-4 border rounded-lg bg-muted/5", className)}>
|
|
809
790
|
<div className="text-center text-muted-foreground">
|
|
810
|
-
Performance monitoring
|
|
791
|
+
Performance monitoring disabled
|
|
811
792
|
</div>
|
|
812
793
|
</div>
|
|
813
794
|
)
|
|
@@ -823,7 +804,7 @@ export function RealTimePerformanceMonitor({
|
|
|
823
804
|
<div className="flex items-center justify-between">
|
|
824
805
|
<h3 className="font-semibold flex items-center gap-2">
|
|
825
806
|
<BarChart3 className="h-4 w-4" />
|
|
826
|
-
|
|
807
|
+
Real-time Performance
|
|
827
808
|
</h3>
|
|
828
809
|
<button
|
|
829
810
|
onClick={() => setIsActive(!isActive)}
|
|
@@ -834,7 +815,7 @@ export function RealTimePerformanceMonitor({
|
|
|
834
815
|
: "bg-muted text-muted-foreground hover:bg-muted/80"
|
|
835
816
|
)}
|
|
836
817
|
>
|
|
837
|
-
{isActive ? '
|
|
818
|
+
{isActive ? 'Active' : 'Paused'}
|
|
838
819
|
</button>
|
|
839
820
|
</div>
|
|
840
821
|
|
|
@@ -852,7 +833,7 @@ export function RealTimePerformanceMonitor({
|
|
|
852
833
|
|
|
853
834
|
{/* Render Time */}
|
|
854
835
|
<div className="space-y-1">
|
|
855
|
-
<div className="text-xs text-muted-foreground">Render
|
|
836
|
+
<div className="text-xs text-muted-foreground">Render Time</div>
|
|
856
837
|
<div className={cn(
|
|
857
838
|
"text-lg font-mono font-bold",
|
|
858
839
|
memoryStats.performance ? getPerformanceColor(100 - memoryStats.performance.renderTime, { good: 84, warning: 70 }) : ''
|
|
@@ -863,7 +844,7 @@ export function RealTimePerformanceMonitor({
|
|
|
863
844
|
|
|
864
845
|
{/* Memory Usage */}
|
|
865
846
|
<div className="space-y-1">
|
|
866
|
-
<div className="text-xs text-muted-foreground">
|
|
847
|
+
<div className="text-xs text-muted-foreground">Memory Usage</div>
|
|
867
848
|
<div className="text-lg font-mono font-bold">
|
|
868
849
|
{formatBytes(memoryStats.memoryUsage)}
|
|
869
850
|
</div>
|
|
@@ -908,7 +889,7 @@ export function RealTimePerformanceMonitor({
|
|
|
908
889
|
{/* Mini Chart */}
|
|
909
890
|
{showChart && history.length > 1 && (
|
|
910
891
|
<div className="pt-2 border-t">
|
|
911
|
-
<div className="text-xs text-muted-foreground mb-2">FPS
|
|
892
|
+
<div className="text-xs text-muted-foreground mb-2">FPS History (Last 60 updates)</div>
|
|
912
893
|
<div className="h-16 flex items-end gap-1">
|
|
913
894
|
{history.slice(-30).map((stat, index) => {
|
|
914
895
|
const fps = stat.performance?.fps || 0
|
|
@@ -940,7 +921,7 @@ interface MemoryAnalyticsProps {
|
|
|
940
921
|
className?: string
|
|
941
922
|
}
|
|
942
923
|
|
|
943
|
-
|
|
924
|
+
function MemoryAnalytics({
|
|
944
925
|
onStatsUpdate,
|
|
945
926
|
showRealTime = false,
|
|
946
927
|
className
|
|
@@ -951,21 +932,35 @@ export function MemoryAnalytics({
|
|
|
951
932
|
cacheHitRate: 0.95
|
|
952
933
|
})
|
|
953
934
|
|
|
954
|
-
//
|
|
935
|
+
// Simulate real-time updates with realistic data
|
|
955
936
|
useEffect(() => {
|
|
956
937
|
if (!showRealTime) return
|
|
957
938
|
|
|
939
|
+
// Initialize with some realistic base values
|
|
940
|
+
let baseMemory = 10 * 1024 * 1024 // 10MB base
|
|
941
|
+
let currentFPS = 60
|
|
942
|
+
let currentRenderTime = 5
|
|
943
|
+
|
|
958
944
|
const interval = setInterval(() => {
|
|
945
|
+
// Simulate realistic memory usage growth
|
|
946
|
+
baseMemory += Math.random() * 1024 * 1024 - 500 * 1024 // Fluctuate around base
|
|
947
|
+
|
|
948
|
+
// Simulate FPS variations
|
|
949
|
+
currentFPS = Math.min(60, Math.max(30, currentFPS + (Math.random() - 0.5) * 10))
|
|
950
|
+
|
|
951
|
+
// Simulate render time variations
|
|
952
|
+
currentRenderTime = Math.max(1, Math.min(16, currentRenderTime + (Math.random() - 0.5) * 2))
|
|
953
|
+
|
|
959
954
|
const newStats: MemoryStats = {
|
|
960
|
-
memoryUsage: Math.
|
|
961
|
-
itemCount:
|
|
962
|
-
cacheHitRate: 0.
|
|
955
|
+
memoryUsage: Math.max(0, baseMemory),
|
|
956
|
+
itemCount: 50000, // Fixed item count for demo
|
|
957
|
+
cacheHitRate: 0.85 + Math.random() * 0.15, // 85-100% hit rate
|
|
963
958
|
lastCleanup: Date.now(),
|
|
964
959
|
performance: {
|
|
965
|
-
fps: Math.
|
|
966
|
-
renderTime:
|
|
967
|
-
memoryLeaks: Math.floor(
|
|
968
|
-
scrollPerformance:
|
|
960
|
+
fps: Math.round(currentFPS),
|
|
961
|
+
renderTime: parseFloat(currentRenderTime.toFixed(2)),
|
|
962
|
+
memoryLeaks: currentRenderTime > 10 ? Math.floor(currentRenderTime / 5) : 0,
|
|
963
|
+
scrollPerformance: Math.round((currentFPS / 60) * 100),
|
|
969
964
|
lastUpdate: Date.now()
|
|
970
965
|
} as MemoryPerformanceMetrics
|
|
971
966
|
}
|
|
@@ -983,12 +978,12 @@ export function MemoryAnalytics({
|
|
|
983
978
|
}
|
|
984
979
|
|
|
985
980
|
// Utility hook for streaming data
|
|
986
|
-
|
|
981
|
+
function useStreamingData<T>(
|
|
987
982
|
initialData: T[] = [],
|
|
988
|
-
streamingConfig?: {
|
|
983
|
+
streamingConfig?: { maxItems?: number }
|
|
989
984
|
) {
|
|
990
985
|
const [data, setData] = useState<T[]>(initialData)
|
|
991
|
-
const {
|
|
986
|
+
const { maxItems = 10000 } = streamingConfig || {}
|
|
992
987
|
|
|
993
988
|
const addItem = useCallback((newItem: T) => {
|
|
994
989
|
setData(prev => {
|
|
@@ -1004,7 +999,14 @@ export function useStreamingData<T>(
|
|
|
1004
999
|
return { data, addItem, clearData }
|
|
1005
1000
|
}
|
|
1006
1001
|
|
|
1007
|
-
// Export types
|
|
1002
|
+
// Export components and types
|
|
1003
|
+
export {
|
|
1004
|
+
MemoryEfficientData,
|
|
1005
|
+
MemoryAnalytics,
|
|
1006
|
+
RealTimePerformanceMonitor,
|
|
1007
|
+
useStreamingData
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1008
1010
|
export type {
|
|
1009
1011
|
MemoryConfig,
|
|
1010
1012
|
MemoryStats,
|
|
@@ -1013,4 +1015,4 @@ export type {
|
|
|
1013
1015
|
TableFeatures,
|
|
1014
1016
|
ItemHeightInfo,
|
|
1015
1017
|
RealTimePerformanceMonitorProps
|
|
1016
|
-
}
|
|
1018
|
+
};
|