@moontra/moonui-pro 2.0.22 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/index.mjs +215 -214
  2. package/package.json +4 -2
  3. package/src/__tests__/use-intersection-observer.test.tsx +216 -0
  4. package/src/__tests__/use-local-storage.test.tsx +174 -0
  5. package/src/__tests__/use-pro-access.test.tsx +183 -0
  6. package/src/components/advanced-chart/advanced-chart.test.tsx +281 -0
  7. package/src/components/advanced-chart/index.tsx +412 -0
  8. package/src/components/advanced-forms/index.tsx +431 -0
  9. package/src/components/animated-button/index.tsx +202 -0
  10. package/src/components/calendar/event-dialog.tsx +372 -0
  11. package/src/components/calendar/index.tsx +557 -0
  12. package/src/components/color-picker/index.tsx +434 -0
  13. package/src/components/dashboard/index.tsx +334 -0
  14. package/src/components/data-table/data-table.test.tsx +187 -0
  15. package/src/components/data-table/index.tsx +368 -0
  16. package/src/components/draggable-list/index.tsx +100 -0
  17. package/src/components/enhanced/button.tsx +360 -0
  18. package/src/components/enhanced/card.tsx +272 -0
  19. package/src/components/enhanced/dialog.tsx +248 -0
  20. package/src/components/enhanced/index.ts +3 -0
  21. package/src/components/error-boundary/index.tsx +111 -0
  22. package/src/components/file-upload/file-upload.test.tsx +242 -0
  23. package/src/components/file-upload/index.tsx +362 -0
  24. package/src/components/floating-action-button/index.tsx +209 -0
  25. package/src/components/github-stars/index.tsx +414 -0
  26. package/src/components/health-check/index.tsx +441 -0
  27. package/src/components/hover-card-3d/index.tsx +170 -0
  28. package/src/components/index.ts +76 -0
  29. package/src/components/kanban/index.tsx +436 -0
  30. package/src/components/lazy-component/index.tsx +342 -0
  31. package/src/components/magnetic-button/index.tsx +170 -0
  32. package/src/components/memory-efficient-data/index.tsx +352 -0
  33. package/src/components/optimized-image/index.tsx +427 -0
  34. package/src/components/performance-debugger/index.tsx +591 -0
  35. package/src/components/performance-monitor/index.tsx +775 -0
  36. package/src/components/pinch-zoom/index.tsx +172 -0
  37. package/src/components/rich-text-editor/index-old-backup.tsx +443 -0
  38. package/src/components/rich-text-editor/index.tsx +1537 -0
  39. package/src/components/rich-text-editor/slash-commands-extension.ts +220 -0
  40. package/src/components/rich-text-editor/slash-commands.css +35 -0
  41. package/src/components/rich-text-editor/table-styles.css +65 -0
  42. package/src/components/spotlight-card/index.tsx +194 -0
  43. package/src/components/swipeable-card/index.tsx +100 -0
  44. package/src/components/timeline/index.tsx +333 -0
  45. package/src/components/ui/animated-button.tsx +185 -0
  46. package/src/components/ui/avatar.tsx +135 -0
  47. package/src/components/ui/badge.tsx +225 -0
  48. package/src/components/ui/button.tsx +221 -0
  49. package/src/components/ui/card.tsx +141 -0
  50. package/src/components/ui/checkbox.tsx +256 -0
  51. package/src/components/ui/color-picker.tsx +95 -0
  52. package/src/components/ui/dialog.tsx +332 -0
  53. package/src/components/ui/dropdown-menu.tsx +200 -0
  54. package/src/components/ui/hover-card-3d.tsx +103 -0
  55. package/src/components/ui/index.ts +33 -0
  56. package/src/components/ui/input.tsx +219 -0
  57. package/src/components/ui/label.tsx +26 -0
  58. package/src/components/ui/magnetic-button.tsx +129 -0
  59. package/src/components/ui/popover.tsx +183 -0
  60. package/src/components/ui/select.tsx +273 -0
  61. package/src/components/ui/separator.tsx +140 -0
  62. package/src/components/ui/slider.tsx +351 -0
  63. package/src/components/ui/spotlight-card.tsx +119 -0
  64. package/src/components/ui/switch.tsx +83 -0
  65. package/src/components/ui/tabs.tsx +195 -0
  66. package/src/components/ui/textarea.tsx +25 -0
  67. package/src/components/ui/toast.tsx +313 -0
  68. package/src/components/ui/tooltip.tsx +152 -0
  69. package/src/components/virtual-list/index.tsx +369 -0
  70. package/src/hooks/use-chart.ts +205 -0
  71. package/src/hooks/use-data-table.ts +182 -0
  72. package/src/hooks/use-docs-pro-access.ts +13 -0
  73. package/src/hooks/use-license-check.ts +65 -0
  74. package/src/hooks/use-subscription.ts +19 -0
  75. package/src/index.ts +14 -0
  76. package/src/lib/micro-interactions.ts +255 -0
  77. package/src/lib/utils.ts +6 -0
  78. package/src/patterns/login-form/index.tsx +276 -0
  79. package/src/patterns/login-form/types.ts +67 -0
  80. package/src/setupTests.ts +41 -0
  81. package/src/styles/design-system.css +365 -0
  82. package/src/styles/index.css +4 -0
  83. package/src/styles/tailwind.css +6 -0
  84. package/src/styles/tokens.css +453 -0
  85. package/src/types/moonui.d.ts +22 -0
  86. package/src/use-intersection-observer.tsx +154 -0
  87. package/src/use-local-storage.tsx +71 -0
  88. package/src/use-paddle.ts +138 -0
  89. package/src/use-performance-optimizer.ts +379 -0
  90. package/src/use-pro-access.ts +141 -0
  91. package/src/use-scroll-animation.ts +221 -0
  92. package/src/use-subscription.ts +37 -0
  93. package/src/use-toast.ts +32 -0
  94. package/src/utils/chart-helpers.ts +257 -0
  95. package/src/utils/cn.ts +69 -0
  96. package/src/utils/data-processing.ts +151 -0
  97. package/src/utils/license-guard.tsx +177 -0
  98. package/src/utils/license-validator.tsx +183 -0
  99. package/src/utils/package-guard.ts +60 -0
@@ -0,0 +1,427 @@
1
+ "use client"
2
+
3
+ import React, { useState, useRef, useEffect } from "react"
4
+ import { motion, AnimatePresence } from "framer-motion"
5
+ import { Card, CardContent } from "../ui/card"
6
+ import { Button } from "../ui/button"
7
+ import { Badge } from "../ui/badge"
8
+ import { Skeleton } from "@moontra/moonui"
9
+ import { cn } from "../../lib/utils"
10
+ import {
11
+ Image as ImageIcon,
12
+ Maximize2,
13
+ Download,
14
+ Eye,
15
+ EyeOff,
16
+ RotateCw,
17
+ ZoomIn,
18
+ ZoomOut,
19
+ X,
20
+ Lock,
21
+ Sparkles,
22
+ Loader2
23
+ } from "lucide-react"
24
+ import { useSubscription } from "../../hooks/use-subscription"
25
+
26
+ export interface OptimizedImageProps {
27
+ src: string
28
+ alt: string
29
+ width?: number
30
+ height?: number
31
+ quality?: number
32
+ format?: "webp" | "avif" | "jpeg" | "png" | "auto"
33
+ lazy?: boolean
34
+ blur?: boolean
35
+ priority?: boolean
36
+ sizes?: string
37
+ srcSet?: string
38
+ fallbackSrc?: string
39
+ showPreview?: boolean
40
+ showZoom?: boolean
41
+ showDownload?: boolean
42
+ showInfo?: boolean
43
+ zoomLevel?: number
44
+ className?: string
45
+ onLoad?: () => void
46
+ onError?: (error: Error) => void
47
+ onZoom?: (level: number) => void
48
+ }
49
+
50
+ const OptimizedImageInternal: React.FC<OptimizedImageProps> = ({
51
+ src,
52
+ alt,
53
+ width,
54
+ height,
55
+ quality = 75,
56
+ format = "auto",
57
+ lazy = true,
58
+ blur = true,
59
+ priority = false,
60
+ sizes,
61
+ srcSet,
62
+ fallbackSrc,
63
+ showPreview = true,
64
+ showZoom = true,
65
+ showDownload = true,
66
+ showInfo = true,
67
+ zoomLevel = 1,
68
+ className,
69
+ onLoad,
70
+ onError,
71
+ onZoom
72
+ }) => {
73
+ const [isLoaded, setIsLoaded] = useState(false)
74
+ const [isLoading, setIsLoading] = useState(true)
75
+ const [hasError, setHasError] = useState(false)
76
+ const [isPreviewOpen, setIsPreviewOpen] = useState(false)
77
+ const [currentZoom, setCurrentZoom] = useState(zoomLevel)
78
+ const [imageInfo, setImageInfo] = useState<{
79
+ naturalWidth: number
80
+ naturalHeight: number
81
+ fileSize?: number
82
+ } | null>(null)
83
+ const [showImageInfo, setShowImageInfo] = useState(false)
84
+
85
+ const imgRef = useRef<HTMLImageElement>(null)
86
+ const previewRef = useRef<HTMLDivElement>(null)
87
+
88
+ // Generate optimized image URL
89
+ const getOptimizedSrc = (originalSrc: string, options: {
90
+ width?: number
91
+ height?: number
92
+ quality?: number
93
+ format?: string
94
+ } = {}) => {
95
+ // This would typically integrate with image optimization services
96
+ // like Cloudinary, ImageKit, or Next.js Image Optimization
97
+ let optimizedUrl = originalSrc
98
+
99
+ // Example for a generic image optimization service
100
+ const params = new URLSearchParams()
101
+ if (options.width) params.set('w', options.width.toString())
102
+ if (options.height) params.set('h', options.height.toString())
103
+ if (options.quality) params.set('q', options.quality.toString())
104
+ if (options.format && options.format !== 'auto') params.set('f', options.format)
105
+
106
+ // For demo purposes, we'll just return the original URL
107
+ // In production, you'd construct an optimized URL like:
108
+ // return `https://your-image-service.com/transform?${params}&url=${encodeURIComponent(originalSrc)}`
109
+
110
+ return optimizedUrl
111
+ }
112
+
113
+ const optimizedSrc = getOptimizedSrc(src, { width, height, quality, format })
114
+
115
+ const handleImageLoad = () => {
116
+ setIsLoaded(true)
117
+ setIsLoading(false)
118
+
119
+ if (imgRef.current) {
120
+ setImageInfo({
121
+ naturalWidth: imgRef.current.naturalWidth,
122
+ naturalHeight: imgRef.current.naturalHeight
123
+ })
124
+ }
125
+
126
+ onLoad?.()
127
+ }
128
+
129
+ const handleImageError = () => {
130
+ setHasError(true)
131
+ setIsLoading(false)
132
+ onError?.(new Error("Failed to load image"))
133
+ }
134
+
135
+ const handleDownload = async () => {
136
+ try {
137
+ const response = await fetch(optimizedSrc)
138
+ const blob = await response.blob()
139
+ const url = window.URL.createObjectURL(blob)
140
+ const link = document.createElement('a')
141
+ link.href = url
142
+ link.download = alt || 'image'
143
+ document.body.appendChild(link)
144
+ link.click()
145
+ document.body.removeChild(link)
146
+ window.URL.revokeObjectURL(url)
147
+ } catch (error) {
148
+ console.error('Download failed:', error)
149
+ }
150
+ }
151
+
152
+ const handleZoomIn = () => {
153
+ const newZoom = Math.min(currentZoom * 1.2, 5)
154
+ setCurrentZoom(newZoom)
155
+ onZoom?.(newZoom)
156
+ }
157
+
158
+ const handleZoomOut = () => {
159
+ const newZoom = Math.max(currentZoom / 1.2, 0.2)
160
+ setCurrentZoom(newZoom)
161
+ onZoom?.(newZoom)
162
+ }
163
+
164
+ const resetZoom = () => {
165
+ setCurrentZoom(1)
166
+ onZoom?.(1)
167
+ }
168
+
169
+ const formatFileSize = (bytes: number) => {
170
+ if (bytes === 0) return '0 Bytes'
171
+ const k = 1024
172
+ const sizes = ['Bytes', 'KB', 'MB', 'GB']
173
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
174
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
175
+ }
176
+
177
+ // Generate srcSet for responsive images
178
+ const generateSrcSet = () => {
179
+ if (srcSet) return srcSet
180
+
181
+ if (!width) return undefined
182
+
183
+ const widths = [width * 0.5, width, width * 1.5, width * 2]
184
+ return widths
185
+ .map(w => `${getOptimizedSrc(src, { width: Math.round(w), quality })} ${Math.round(w)}w`)
186
+ .join(', ')
187
+ }
188
+
189
+ return (
190
+ <>
191
+ <div className={cn("relative group overflow-hidden", className)}>
192
+ {/* Loading/Error States */}
193
+ {isLoading && (
194
+ <motion.div
195
+ initial={{ opacity: 0 }}
196
+ animate={{ opacity: 1 }}
197
+ className="absolute inset-0 flex items-center justify-center bg-muted"
198
+ >
199
+ {blur ? (
200
+ <Skeleton className="w-full h-full" />
201
+ ) : (
202
+ <div className="text-center">
203
+ <Loader2 className="h-8 w-8 animate-spin text-muted-foreground mx-auto mb-2" />
204
+ <p className="text-sm text-muted-foreground">Loading image...</p>
205
+ </div>
206
+ )}
207
+ </motion.div>
208
+ )}
209
+
210
+ {hasError && (
211
+ <div className="absolute inset-0 flex items-center justify-center bg-muted">
212
+ <div className="text-center">
213
+ <ImageIcon className="h-12 w-12 text-muted-foreground mx-auto mb-2" />
214
+ <p className="text-sm text-muted-foreground">Failed to load image</p>
215
+ {fallbackSrc && (
216
+ <img
217
+ src={fallbackSrc}
218
+ alt={alt}
219
+ className="mt-2 max-w-full max-h-32 object-contain"
220
+ />
221
+ )}
222
+ </div>
223
+ </div>
224
+ )}
225
+
226
+ {/* Optimized Image */}
227
+ <motion.img
228
+ ref={imgRef}
229
+ src={optimizedSrc}
230
+ alt={alt}
231
+ width={width}
232
+ height={height}
233
+ sizes={sizes}
234
+ srcSet={generateSrcSet()}
235
+ loading={lazy ? "lazy" : priority ? "eager" : "lazy"}
236
+ onLoad={handleImageLoad}
237
+ onError={handleImageError}
238
+ className={cn(
239
+ "w-full h-full object-cover transition-opacity duration-300",
240
+ isLoaded ? "opacity-100" : "opacity-0"
241
+ )}
242
+ initial={{ scale: blur && !isLoaded ? 1.1 : 1 }}
243
+ animate={{ scale: 1 }}
244
+ transition={{ duration: 0.3 }}
245
+ />
246
+
247
+ {/* Image Controls Overlay */}
248
+ <AnimatePresence>
249
+ {isLoaded && (
250
+ <motion.div
251
+ initial={{ opacity: 0 }}
252
+ animate={{ opacity: 1 }}
253
+ exit={{ opacity: 0 }}
254
+ className="absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors duration-200"
255
+ >
256
+ <div className="absolute top-2 right-2 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
257
+ {showInfo && (
258
+ <Button
259
+ size="sm"
260
+ variant="secondary"
261
+ className="h-8 w-8 p-0"
262
+ onClick={() => setShowImageInfo(!showImageInfo)}
263
+ >
264
+ {showImageInfo ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
265
+ </Button>
266
+ )}
267
+
268
+ {showDownload && (
269
+ <Button
270
+ size="sm"
271
+ variant="secondary"
272
+ className="h-8 w-8 p-0"
273
+ onClick={handleDownload}
274
+ >
275
+ <Download className="h-4 w-4" />
276
+ </Button>
277
+ )}
278
+
279
+ {showPreview && (
280
+ <Button
281
+ size="sm"
282
+ variant="secondary"
283
+ className="h-8 w-8 p-0"
284
+ onClick={() => setIsPreviewOpen(true)}
285
+ >
286
+ <Maximize2 className="h-4 w-4" />
287
+ </Button>
288
+ )}
289
+ </div>
290
+
291
+ {/* Image Info */}
292
+ <AnimatePresence>
293
+ {showImageInfo && imageInfo && (
294
+ <motion.div
295
+ initial={{ opacity: 0, y: 10 }}
296
+ animate={{ opacity: 1, y: 0 }}
297
+ exit={{ opacity: 0, y: 10 }}
298
+ className="absolute bottom-2 left-2 bg-black/80 text-white text-xs p-2 rounded"
299
+ >
300
+ <div>{imageInfo.naturalWidth} × {imageInfo.naturalHeight}px</div>
301
+ <div>Quality: {quality}%</div>
302
+ <div>Format: {format}</div>
303
+ </motion.div>
304
+ )}
305
+ </AnimatePresence>
306
+ </motion.div>
307
+ )}
308
+ </AnimatePresence>
309
+ </div>
310
+
311
+ {/* Full Screen Preview Modal */}
312
+ <AnimatePresence>
313
+ {isPreviewOpen && (
314
+ <motion.div
315
+ initial={{ opacity: 0 }}
316
+ animate={{ opacity: 1 }}
317
+ exit={{ opacity: 0 }}
318
+ className="fixed inset-0 z-50 bg-black/90 flex items-center justify-center p-4"
319
+ onClick={() => setIsPreviewOpen(false)}
320
+ >
321
+ <div className="relative max-w-full max-h-full" onClick={(e) => e.stopPropagation()}>
322
+ {/* Preview Controls */}
323
+ <div className="absolute top-4 right-4 flex gap-2 z-10">
324
+ {showZoom && (
325
+ <>
326
+ <Button
327
+ size="sm"
328
+ variant="secondary"
329
+ onClick={handleZoomOut}
330
+ disabled={currentZoom <= 0.2}
331
+ >
332
+ <ZoomOut className="h-4 w-4" />
333
+ </Button>
334
+
335
+ <Badge variant="secondary" className="px-2">
336
+ {Math.round(currentZoom * 100)}%
337
+ </Badge>
338
+
339
+ <Button
340
+ size="sm"
341
+ variant="secondary"
342
+ onClick={handleZoomIn}
343
+ disabled={currentZoom >= 5}
344
+ >
345
+ <ZoomIn className="h-4 w-4" />
346
+ </Button>
347
+
348
+ <Button
349
+ size="sm"
350
+ variant="secondary"
351
+ onClick={resetZoom}
352
+ >
353
+ <RotateCw className="h-4 w-4" />
354
+ </Button>
355
+ </>
356
+ )}
357
+
358
+ <Button
359
+ size="sm"
360
+ variant="secondary"
361
+ onClick={() => setIsPreviewOpen(false)}
362
+ >
363
+ <X className="h-4 w-4" />
364
+ </Button>
365
+ </div>
366
+
367
+ {/* Preview Image */}
368
+ <motion.img
369
+ ref={previewRef}
370
+ src={optimizedSrc}
371
+ alt={alt}
372
+ className="max-w-full max-h-full object-contain"
373
+ style={{
374
+ transform: `scale(${currentZoom})`,
375
+ transformOrigin: 'center center'
376
+ }}
377
+ initial={{ scale: 0.9 }}
378
+ animate={{ scale: currentZoom }}
379
+ transition={{ duration: 0.2 }}
380
+ />
381
+ </div>
382
+ </motion.div>
383
+ )}
384
+ </AnimatePresence>
385
+ </>
386
+ )
387
+ }
388
+
389
+ export const OptimizedImage: React.FC<OptimizedImageProps> = ({ className, ...props }) => {
390
+ // Check if we're in docs mode or have pro access
391
+ const docsProAccess = { hasAccess: true } // Pro access assumed in package
392
+ const { hasProAccess, isLoading } = useSubscription()
393
+
394
+ // In docs mode, always show the component
395
+ const canShowComponent = docsProAccess.isDocsMode || hasProAccess
396
+
397
+ // If not in docs mode and no pro access, show upgrade prompt
398
+ if (!docsProAccess.isDocsMode && !isLoading && !hasProAccess) {
399
+ return (
400
+ <Card className={cn("w-fit", className)}>
401
+ <CardContent className="py-6 text-center">
402
+ <div className="space-y-4">
403
+ <div className="rounded-full bg-purple-100 dark:bg-purple-900/30 p-3 w-fit mx-auto">
404
+ <Lock className="h-6 w-6 text-purple-600 dark:text-purple-400" />
405
+ </div>
406
+ <div>
407
+ <h3 className="font-semibold text-sm mb-2">Pro Feature</h3>
408
+ <p className="text-muted-foreground text-xs mb-4">
409
+ Optimized Image is available exclusively to MoonUI Pro subscribers.
410
+ </p>
411
+ <a href="/pricing">
412
+ <Button size="sm">
413
+ <Sparkles className="mr-2 h-4 w-4" />
414
+ Upgrade to Pro
415
+ </Button>
416
+ </a>
417
+ </div>
418
+ </div>
419
+ </CardContent>
420
+ </Card>
421
+ )
422
+ }
423
+
424
+ return <OptimizedImageInternal className={className} {...props} />
425
+ }
426
+
427
+ export type { OptimizedImageProps }