@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,434 @@
1
+ "use client"
2
+
3
+ import React, { useState, useCallback, useRef, useEffect } from "react"
4
+ import { motion } from "framer-motion"
5
+ import { Card, CardContent } from "../ui/card"
6
+ import { Button } from "../ui/button"
7
+ import { Input } from "../ui/input"
8
+ import { Label } from "../ui/label"
9
+ import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"
10
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs"
11
+ import { cn } from "../../lib/utils"
12
+ import { Lock, Sparkles, Palette, Copy, Check, RotateCcw } from "lucide-react"
13
+ import { useSubscription } from "../../hooks/use-subscription"
14
+
15
+ export interface ColorPickerProps {
16
+ value?: string
17
+ onChange?: (color: string) => void
18
+ disabled?: boolean
19
+ showPresets?: boolean
20
+ showAlpha?: boolean
21
+ showInput?: boolean
22
+ showCopy?: boolean
23
+ presetColors?: string[]
24
+ className?: string
25
+ size?: "sm" | "default" | "lg"
26
+ }
27
+
28
+ interface HSV {
29
+ h: number
30
+ s: number
31
+ v: number
32
+ a: number
33
+ }
34
+
35
+ interface RGB {
36
+ r: number
37
+ g: number
38
+ b: number
39
+ a: number
40
+ }
41
+
42
+ const ColorPickerInternal: React.FC<ColorPickerProps> = ({
43
+ value = "#3b82f6",
44
+ onChange,
45
+ disabled = false,
46
+ showPresets = true,
47
+ showAlpha = true,
48
+ showInput = true,
49
+ showCopy = true,
50
+ presetColors = [
51
+ "#ef4444", "#f97316", "#f59e0b", "#eab308", "#84cc16", "#22c55e",
52
+ "#10b981", "#14b8a6", "#06b6d4", "#0ea5e9", "#3b82f6", "#6366f1",
53
+ "#8b5cf6", "#a855f7", "#d946ef", "#ec4899", "#f43f5e", "#000000",
54
+ "#404040", "#737373", "#a3a3a3", "#d4d4d4", "#f5f5f5", "#ffffff"
55
+ ],
56
+ className,
57
+ size = "default"
58
+ }) => {
59
+ const [currentColor, setCurrentColor] = useState(value)
60
+ const [hsv, setHsv] = useState<HSV>({ h: 0, s: 100, v: 100, a: 1 })
61
+ const [inputValue, setInputValue] = useState(value)
62
+ const [copied, setCopied] = useState(false)
63
+ const [isDragging, setIsDragging] = useState<'hue' | 'saturation' | 'alpha' | null>(null)
64
+
65
+ const saturationRef = useRef<HTMLDivElement>(null)
66
+ const hueRef = useRef<HTMLDivElement>(null)
67
+ const alphaRef = useRef<HTMLDivElement>(null)
68
+
69
+ const sizeClasses = {
70
+ sm: "w-8 h-8",
71
+ default: "w-10 h-10",
72
+ lg: "w-12 h-12"
73
+ }
74
+
75
+ // Convert color utilities
76
+ const hexToRgb = (hex: string): RGB => {
77
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
78
+ return result ? {
79
+ r: parseInt(result[1], 16),
80
+ g: parseInt(result[2], 16),
81
+ b: parseInt(result[3], 16),
82
+ a: 1
83
+ } : { r: 0, g: 0, b: 0, a: 1 }
84
+ }
85
+
86
+ const rgbToHex = (r: number, g: number, b: number): string => {
87
+ return "#" + [r, g, b].map(x => {
88
+ const hex = Math.round(x).toString(16)
89
+ return hex.length === 1 ? "0" + hex : hex
90
+ }).join("")
91
+ }
92
+
93
+ const rgbToHsv = (rgb: RGB): HSV => {
94
+ const r = rgb.r / 255
95
+ const g = rgb.g / 255
96
+ const b = rgb.b / 255
97
+
98
+ const max = Math.max(r, g, b)
99
+ const min = Math.min(r, g, b)
100
+ const diff = max - min
101
+
102
+ let h = 0
103
+ if (diff !== 0) {
104
+ if (max === r) h = ((g - b) / diff) % 6
105
+ else if (max === g) h = (b - r) / diff + 2
106
+ else h = (r - g) / diff + 4
107
+ }
108
+ h = Math.round(h * 60)
109
+ if (h < 0) h += 360
110
+
111
+ const s = max === 0 ? 0 : (diff / max) * 100
112
+ const v = max * 100
113
+
114
+ return { h, s, v, a: rgb.a }
115
+ }
116
+
117
+ const hsvToRgb = (hsv: HSV): RGB => {
118
+ const h = hsv.h / 60
119
+ const s = hsv.s / 100
120
+ const v = hsv.v / 100
121
+
122
+ const c = v * s
123
+ const x = c * (1 - Math.abs((h % 2) - 1))
124
+ const m = v - c
125
+
126
+ let r = 0, g = 0, b = 0
127
+
128
+ if (h >= 0 && h < 1) [r, g, b] = [c, x, 0]
129
+ else if (h >= 1 && h < 2) [r, g, b] = [x, c, 0]
130
+ else if (h >= 2 && h < 3) [r, g, b] = [0, c, x]
131
+ else if (h >= 3 && h < 4) [r, g, b] = [0, x, c]
132
+ else if (h >= 4 && h < 5) [r, g, b] = [x, 0, c]
133
+ else if (h >= 5 && h < 6) [r, g, b] = [c, 0, x]
134
+
135
+ return {
136
+ r: Math.round((r + m) * 255),
137
+ g: Math.round((g + m) * 255),
138
+ b: Math.round((b + m) * 255),
139
+ a: hsv.a
140
+ }
141
+ }
142
+
143
+ const updateColor = useCallback((newHsv: HSV) => {
144
+ setHsv(newHsv)
145
+ const rgb = hsvToRgb(newHsv)
146
+ const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
147
+ setCurrentColor(hex)
148
+ setInputValue(hex)
149
+ onChange?.(hex)
150
+ }, [onChange])
151
+
152
+ useEffect(() => {
153
+ const rgb = hexToRgb(currentColor)
154
+ const newHsv = rgbToHsv(rgb)
155
+ setHsv(newHsv)
156
+ }, [currentColor])
157
+
158
+ const handleSaturationChange = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
159
+ if (!saturationRef.current) return
160
+
161
+ const rect = saturationRef.current.getBoundingClientRect()
162
+ const x = Math.max(0, Math.min(rect.width, e.clientX - rect.left))
163
+ const y = Math.max(0, Math.min(rect.height, e.clientY - rect.top))
164
+
165
+ const s = (x / rect.width) * 100
166
+ const v = 100 - (y / rect.height) * 100
167
+
168
+ updateColor({ ...hsv, s, v })
169
+ }, [hsv, updateColor])
170
+
171
+ const handleHueChange = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
172
+ if (!hueRef.current) return
173
+
174
+ const rect = hueRef.current.getBoundingClientRect()
175
+ const x = Math.max(0, Math.min(rect.width, e.clientX - rect.left))
176
+ const h = (x / rect.width) * 360
177
+
178
+ updateColor({ ...hsv, h })
179
+ }, [hsv, updateColor])
180
+
181
+ const handleAlphaChange = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
182
+ if (!alphaRef.current) return
183
+
184
+ const rect = alphaRef.current.getBoundingClientRect()
185
+ const x = Math.max(0, Math.min(rect.width, e.clientX - rect.left))
186
+ const a = x / rect.width
187
+
188
+ updateColor({ ...hsv, a })
189
+ }, [hsv, updateColor])
190
+
191
+ const handleInputChange = (value: string) => {
192
+ setInputValue(value)
193
+ if (/^#[0-9A-F]{6}$/i.test(value)) {
194
+ setCurrentColor(value)
195
+ onChange?.(value)
196
+ }
197
+ }
198
+
199
+ const copyToClipboard = async () => {
200
+ try {
201
+ await navigator.clipboard.writeText(currentColor)
202
+ setCopied(true)
203
+ setTimeout(() => setCopied(false), 2000)
204
+ } catch (err) {
205
+ console.error("Failed to copy color:", err)
206
+ }
207
+ }
208
+
209
+ const handlePresetClick = (color: string) => {
210
+ setCurrentColor(color)
211
+ setInputValue(color)
212
+ onChange?.(color)
213
+ }
214
+
215
+ const resetColor = () => {
216
+ setCurrentColor(value)
217
+ setInputValue(value)
218
+ onChange?.(value)
219
+ }
220
+
221
+ return (
222
+ <Popover>
223
+ <PopoverTrigger asChild>
224
+ <Button
225
+ variant="outline"
226
+ className={cn(
227
+ sizeClasses[size],
228
+ "p-1 border-2 border-muted-foreground/20 hover:border-muted-foreground/40",
229
+ disabled && "opacity-50 cursor-not-allowed",
230
+ className
231
+ )}
232
+ disabled={disabled}
233
+ >
234
+ <div
235
+ className="w-full h-full rounded-sm"
236
+ style={{ backgroundColor: currentColor }}
237
+ />
238
+ </Button>
239
+ </PopoverTrigger>
240
+
241
+ <PopoverContent className="w-80 p-4" side="bottom" align="start">
242
+ <div className="space-y-4">
243
+ {/* Saturation/Brightness Picker */}
244
+ <div className="space-y-2">
245
+ <Label>Color</Label>
246
+ <div
247
+ ref={saturationRef}
248
+ className="relative w-full h-48 rounded-lg cursor-crosshair overflow-hidden"
249
+ style={{
250
+ background: `linear-gradient(to right, white, hsl(${hsv.h}, 100%, 50%)),
251
+ linear-gradient(to top, black, transparent)`
252
+ }}
253
+ onMouseDown={(e) => {
254
+ setIsDragging('saturation')
255
+ handleSaturationChange(e)
256
+ }}
257
+ onMouseMove={(e) => isDragging === 'saturation' && handleSaturationChange(e)}
258
+ >
259
+ <div
260
+ className="absolute w-4 h-4 border-2 border-white rounded-full shadow-lg transform -translate-x-2 -translate-y-2 pointer-events-none"
261
+ style={{
262
+ left: `${hsv.s}%`,
263
+ top: `${100 - hsv.v}%`
264
+ }}
265
+ />
266
+ </div>
267
+ </div>
268
+
269
+ {/* Hue Slider */}
270
+ <div className="space-y-2">
271
+ <Label>Hue</Label>
272
+ <div
273
+ ref={hueRef}
274
+ className="relative w-full h-4 rounded-lg cursor-pointer"
275
+ style={{
276
+ background: "linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"
277
+ }}
278
+ onMouseDown={(e) => {
279
+ setIsDragging('hue')
280
+ handleHueChange(e)
281
+ }}
282
+ onMouseMove={(e) => isDragging === 'hue' && handleHueChange(e)}
283
+ >
284
+ <div
285
+ className="absolute w-4 h-4 bg-white border-2 border-gray-300 rounded-full shadow-lg transform -translate-x-2 -translate-y-0 pointer-events-none"
286
+ style={{ left: `${(hsv.h / 360) * 100}%` }}
287
+ />
288
+ </div>
289
+ </div>
290
+
291
+ {/* Alpha Slider */}
292
+ {showAlpha && (
293
+ <div className="space-y-2">
294
+ <Label>Opacity</Label>
295
+ <div
296
+ ref={alphaRef}
297
+ className="relative w-full h-4 rounded-lg cursor-pointer"
298
+ style={{
299
+ background: `linear-gradient(to right, transparent, ${currentColor}),
300
+ repeating-linear-gradient(45deg, #ccc 0, #ccc 2px, #fff 2px, #fff 4px)`
301
+ }}
302
+ onMouseDown={(e) => {
303
+ setIsDragging('alpha')
304
+ handleAlphaChange(e)
305
+ }}
306
+ onMouseMove={(e) => isDragging === 'alpha' && handleAlphaChange(e)}
307
+ >
308
+ <div
309
+ className="absolute w-4 h-4 bg-white border-2 border-gray-300 rounded-full shadow-lg transform -translate-x-2 -translate-y-0 pointer-events-none"
310
+ style={{ left: `${hsv.a * 100}%` }}
311
+ />
312
+ </div>
313
+ </div>
314
+ )}
315
+
316
+ {/* Color Input and Copy */}
317
+ {showInput && (
318
+ <div className="flex gap-2">
319
+ <div className="flex-1">
320
+ <Label htmlFor="color-input">Hex</Label>
321
+ <Input
322
+ id="color-input"
323
+ value={inputValue}
324
+ onChange={(e) => handleInputChange(e.target.value)}
325
+ placeholder="#000000"
326
+ className="font-mono"
327
+ />
328
+ </div>
329
+
330
+ {showCopy && (
331
+ <div className="flex flex-col gap-2">
332
+ <Label>&nbsp;</Label>
333
+ <Button
334
+ variant="outline"
335
+ size="sm"
336
+ onClick={copyToClipboard}
337
+ className="px-3"
338
+ >
339
+ {copied ? (
340
+ <Check className="h-4 w-4 text-green-500" />
341
+ ) : (
342
+ <Copy className="h-4 w-4" />
343
+ )}
344
+ </Button>
345
+ </div>
346
+ )}
347
+
348
+ <div className="flex flex-col gap-2">
349
+ <Label>&nbsp;</Label>
350
+ <Button
351
+ variant="outline"
352
+ size="sm"
353
+ onClick={resetColor}
354
+ className="px-3"
355
+ >
356
+ <RotateCcw className="h-4 w-4" />
357
+ </Button>
358
+ </div>
359
+ </div>
360
+ )}
361
+
362
+ {/* Preset Colors */}
363
+ {showPresets && (
364
+ <div className="space-y-2">
365
+ <Label>Presets</Label>
366
+ <div className="grid grid-cols-8 gap-2">
367
+ {presetColors.map((color, index) => (
368
+ <motion.button
369
+ key={color}
370
+ className="w-8 h-8 rounded-md border-2 border-muted-foreground/20 hover:border-muted-foreground/40 transition-colors"
371
+ style={{ backgroundColor: color }}
372
+ onClick={() => handlePresetClick(color)}
373
+ whileHover={{ scale: 1.1 }}
374
+ whileTap={{ scale: 0.95 }}
375
+ initial={{ opacity: 0, scale: 0 }}
376
+ animate={{ opacity: 1, scale: 1 }}
377
+ transition={{ delay: index * 0.02 }}
378
+ />
379
+ ))}
380
+ </div>
381
+ </div>
382
+ )}
383
+ </div>
384
+ </PopoverContent>
385
+ </Popover>
386
+ )
387
+
388
+ // Mouse up handler for the entire document
389
+ useEffect(() => {
390
+ const handleMouseUp = () => setIsDragging(null)
391
+ document.addEventListener('mouseup', handleMouseUp)
392
+ return () => document.removeEventListener('mouseup', handleMouseUp)
393
+ }, [])
394
+ }
395
+
396
+ export const ColorPicker: React.FC<ColorPickerProps> = ({ className, ...props }) => {
397
+ // Check if we're in docs mode or have pro access
398
+ const docsProAccess = { hasAccess: true } // Pro access assumed in package
399
+ const { hasProAccess, isLoading } = useSubscription()
400
+
401
+ // In docs mode, always show the component
402
+ const canShowComponent = docsProAccess.isDocsMode || hasProAccess
403
+
404
+ // If not in docs mode and no pro access, show upgrade prompt
405
+ if (!docsProAccess.isDocsMode && !isLoading && !hasProAccess) {
406
+ return (
407
+ <Card className={cn("w-fit", className)}>
408
+ <CardContent className="py-6 text-center">
409
+ <div className="space-y-4">
410
+ <div className="rounded-full bg-purple-100 dark:bg-purple-900/30 p-3 w-fit mx-auto">
411
+ <Lock className="h-6 w-6 text-purple-600 dark:text-purple-400" />
412
+ </div>
413
+ <div>
414
+ <h3 className="font-semibold text-sm mb-2">Pro Feature</h3>
415
+ <p className="text-muted-foreground text-xs mb-4">
416
+ Color Picker is available exclusively to MoonUI Pro subscribers.
417
+ </p>
418
+ <a href="/pricing">
419
+ <Button size="sm">
420
+ <Sparkles className="mr-2 h-4 w-4" />
421
+ Upgrade to Pro
422
+ </Button>
423
+ </a>
424
+ </div>
425
+ </div>
426
+ </CardContent>
427
+ </Card>
428
+ )
429
+ }
430
+
431
+ return <ColorPickerInternal className={className} {...props} />
432
+ }
433
+
434
+ export type { ColorPickerProps }