@pixpilot/shadcn 0.1.11 → 0.3.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/dist/components/ui/OrContinueWithSeparator.d.cts +2 -2
- package/dist/components/ui/OrContinueWithSeparator.d.ts +2 -2
- package/dist/components/ui/alert-dialog.cjs +1 -1
- package/dist/components/ui/alert-dialog.d.cts +12 -12
- package/dist/components/ui/alert-dialog.d.ts +12 -12
- package/dist/components/ui/alert-dialog.js +1 -1
- package/dist/components/ui/alert.d.cts +4 -4
- package/dist/components/ui/alert.d.ts +4 -4
- package/dist/components/ui/avatar.d.cts +4 -4
- package/dist/components/ui/avatar.d.ts +4 -4
- package/dist/components/ui/badge.d.cts +2 -2
- package/dist/components/ui/badge.d.ts +2 -2
- package/dist/components/ui/button.d.cts +2 -2
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/calendar.d.cts +3 -3
- package/dist/components/ui/calendar.d.ts +3 -3
- package/dist/components/ui/card.d.cts +8 -8
- package/dist/components/ui/card.d.ts +8 -8
- package/dist/components/ui/checkbox.d.cts +2 -2
- package/dist/components/ui/checkbox.d.ts +2 -2
- package/dist/components/ui/command.d.cts +10 -10
- package/dist/components/ui/command.d.ts +10 -10
- package/dist/components/ui/dialog.d.cts +11 -11
- package/dist/components/ui/dialog.d.ts +11 -11
- package/dist/components/ui/dropdown-menu.d.cts +16 -16
- package/dist/components/ui/dropdown-menu.d.ts +16 -16
- package/dist/components/ui/file-upload.cjs +1 -1
- package/dist/components/ui/file-upload.d.cts +12 -11
- package/dist/components/ui/file-upload.d.ts +12 -11
- package/dist/components/ui/file-upload.js +1 -1
- package/dist/components/ui/form.d.cts +7 -7
- package/dist/components/ui/form.d.ts +7 -7
- package/dist/components/ui/input.d.cts +2 -2
- package/dist/components/ui/input.d.ts +2 -2
- package/dist/components/ui/label.d.cts +2 -2
- package/dist/components/ui/label.d.ts +2 -2
- package/dist/components/ui/pagination.cjs +1 -1
- package/dist/components/ui/pagination.d.cts +10 -10
- package/dist/components/ui/pagination.d.ts +10 -9
- package/dist/components/ui/pagination.js +1 -1
- package/dist/components/ui/popover.d.cts +5 -5
- package/dist/components/ui/popover.d.ts +5 -5
- package/dist/components/ui/radio-group.d.cts +3 -3
- package/dist/components/ui/radio-group.d.ts +3 -3
- package/dist/components/ui/select.d.cts +11 -11
- package/dist/components/ui/select.d.ts +11 -11
- package/dist/components/ui/separator.d.cts +2 -2
- package/dist/components/ui/separator.d.ts +2 -2
- package/dist/components/ui/shadcn-io/tags/index.d.cts +9 -9
- package/dist/components/ui/shadcn-io/tags/index.d.ts +9 -9
- package/dist/components/ui/shadcn-io/tags-input-inline/index.d.cts +7 -7
- package/dist/components/ui/shadcn-io/tags-input-inline/index.d.ts +7 -7
- package/dist/components/ui/sheet.d.cts +9 -9
- package/dist/components/ui/sheet.d.ts +9 -9
- package/dist/components/ui/slider.d.cts +2 -2
- package/dist/components/ui/slider.d.ts +2 -2
- package/dist/components/ui/switch.d.cts +2 -2
- package/dist/components/ui/switch.d.ts +2 -2
- package/dist/components/ui/tabs.d.cts +5 -5
- package/dist/components/ui/tabs.d.ts +5 -5
- package/dist/components/ui/textarea.d.cts +2 -2
- package/dist/components/ui/tooltip.d.cts +5 -5
- package/dist/components/ui/tooltip.d.ts +5 -5
- package/package.json +13 -9
- package/dist/dist/components/ui/OrContinueWithSeparator.d.cts +0 -1
- package/dist/dist/components/ui/alert-dialog.d.cts +0 -3
- package/dist/dist/components/ui/alert.d.cts +0 -3
- package/dist/dist/components/ui/avatar.d.cts +0 -3
- package/dist/dist/components/ui/badge.d.cts +0 -3
- package/dist/dist/components/ui/button.d.cts +0 -23
- package/dist/dist/components/ui/calendar.d.cts +0 -4
- package/dist/dist/components/ui/card.d.cts +0 -2
- package/dist/dist/components/ui/checkbox.d.cts +0 -3
- package/dist/dist/components/ui/command.d.cts +0 -4
- package/dist/dist/components/ui/dialog.d.cts +0 -3
- package/dist/dist/components/ui/dropdown-menu.d.cts +0 -3
- package/dist/dist/components/ui/file-upload.d.cts +0 -2
- package/dist/dist/components/ui/form.d.cts +0 -5
- package/dist/dist/components/ui/input.d.cts +0 -2
- package/dist/dist/components/ui/label.d.cts +0 -3
- package/dist/dist/components/ui/pagination.d.cts +0 -3
- package/dist/dist/components/ui/popover.d.cts +0 -3
- package/dist/dist/components/ui/radio-group.d.cts +0 -3
- package/dist/dist/components/ui/select.d.cts +0 -3
- package/dist/dist/components/ui/separator.d.cts +0 -3
- package/dist/dist/components/ui/shadcn-io/tags/index.d.cts +0 -6
- package/dist/dist/components/ui/shadcn-io/tags-input-inline/index.d.cts +0 -2
- package/dist/dist/components/ui/sheet.d.cts +0 -3
- package/dist/dist/components/ui/slider.d.cts +0 -3
- package/dist/dist/components/ui/switch.d.cts +0 -3
- package/dist/dist/components/ui/tabs.d.cts +0 -3
- package/dist/dist/components/ui/textarea.d.cts +0 -2
- package/dist/dist/components/ui/tooltip.d.cts +0 -3
- package/dist/dist/index.d.cts +0 -30
- package/dist/dist/lib/utils.d.cts +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime41 from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ui/dialog.d.ts
|
|
6
6
|
declare function Dialog({
|
|
7
7
|
...props
|
|
8
|
-
}: React.ComponentProps<typeof DialogPrimitive.Root>):
|
|
8
|
+
}: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime41.JSX.Element;
|
|
9
9
|
declare function DialogTrigger({
|
|
10
10
|
...props
|
|
11
|
-
}: React.ComponentProps<typeof DialogPrimitive.Trigger>):
|
|
11
|
+
}: React.ComponentProps<typeof DialogPrimitive.Trigger>): react_jsx_runtime41.JSX.Element;
|
|
12
12
|
declare function DialogPortal({
|
|
13
13
|
...props
|
|
14
|
-
}: React.ComponentProps<typeof DialogPrimitive.Portal>):
|
|
14
|
+
}: React.ComponentProps<typeof DialogPrimitive.Portal>): react_jsx_runtime41.JSX.Element;
|
|
15
15
|
declare function DialogClose({
|
|
16
16
|
...props
|
|
17
|
-
}: React.ComponentProps<typeof DialogPrimitive.Close>):
|
|
17
|
+
}: React.ComponentProps<typeof DialogPrimitive.Close>): react_jsx_runtime41.JSX.Element;
|
|
18
18
|
declare function DialogOverlay({
|
|
19
19
|
className,
|
|
20
20
|
...props
|
|
21
|
-
}: React.ComponentProps<typeof DialogPrimitive.Overlay>):
|
|
21
|
+
}: React.ComponentProps<typeof DialogPrimitive.Overlay>): react_jsx_runtime41.JSX.Element;
|
|
22
22
|
declare function DialogContent({
|
|
23
23
|
className,
|
|
24
24
|
children,
|
|
@@ -26,22 +26,22 @@ declare function DialogContent({
|
|
|
26
26
|
...props
|
|
27
27
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
28
28
|
showCloseButton?: boolean;
|
|
29
|
-
}):
|
|
29
|
+
}): react_jsx_runtime41.JSX.Element;
|
|
30
30
|
declare function DialogHeader({
|
|
31
31
|
className,
|
|
32
32
|
...props
|
|
33
|
-
}: React.ComponentProps<'div'>):
|
|
33
|
+
}: React.ComponentProps<'div'>): react_jsx_runtime41.JSX.Element;
|
|
34
34
|
declare function DialogFooter({
|
|
35
35
|
className,
|
|
36
36
|
...props
|
|
37
|
-
}: React.ComponentProps<'div'>):
|
|
37
|
+
}: React.ComponentProps<'div'>): react_jsx_runtime41.JSX.Element;
|
|
38
38
|
declare function DialogTitle({
|
|
39
39
|
className,
|
|
40
40
|
...props
|
|
41
|
-
}: React.ComponentProps<typeof DialogPrimitive.Title>):
|
|
41
|
+
}: React.ComponentProps<typeof DialogPrimitive.Title>): react_jsx_runtime41.JSX.Element;
|
|
42
42
|
declare function DialogDescription({
|
|
43
43
|
className,
|
|
44
44
|
...props
|
|
45
|
-
}: React.ComponentProps<typeof DialogPrimitive.Description>):
|
|
45
|
+
}: React.ComponentProps<typeof DialogPrimitive.Description>): react_jsx_runtime41.JSX.Element;
|
|
46
46
|
//#endregion
|
|
47
47
|
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger };
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime41 from "react/jsx-runtime";
|
|
3
3
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ui/dialog.d.ts
|
|
6
6
|
declare function Dialog({
|
|
7
7
|
...props
|
|
8
|
-
}: React.ComponentProps<typeof DialogPrimitive.Root>):
|
|
8
|
+
}: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime41.JSX.Element;
|
|
9
9
|
declare function DialogTrigger({
|
|
10
10
|
...props
|
|
11
|
-
}: React.ComponentProps<typeof DialogPrimitive.Trigger>):
|
|
11
|
+
}: React.ComponentProps<typeof DialogPrimitive.Trigger>): react_jsx_runtime41.JSX.Element;
|
|
12
12
|
declare function DialogPortal({
|
|
13
13
|
...props
|
|
14
|
-
}: React.ComponentProps<typeof DialogPrimitive.Portal>):
|
|
14
|
+
}: React.ComponentProps<typeof DialogPrimitive.Portal>): react_jsx_runtime41.JSX.Element;
|
|
15
15
|
declare function DialogClose({
|
|
16
16
|
...props
|
|
17
|
-
}: React.ComponentProps<typeof DialogPrimitive.Close>):
|
|
17
|
+
}: React.ComponentProps<typeof DialogPrimitive.Close>): react_jsx_runtime41.JSX.Element;
|
|
18
18
|
declare function DialogOverlay({
|
|
19
19
|
className,
|
|
20
20
|
...props
|
|
21
|
-
}: React.ComponentProps<typeof DialogPrimitive.Overlay>):
|
|
21
|
+
}: React.ComponentProps<typeof DialogPrimitive.Overlay>): react_jsx_runtime41.JSX.Element;
|
|
22
22
|
declare function DialogContent({
|
|
23
23
|
className,
|
|
24
24
|
children,
|
|
@@ -26,22 +26,22 @@ declare function DialogContent({
|
|
|
26
26
|
...props
|
|
27
27
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
28
28
|
showCloseButton?: boolean;
|
|
29
|
-
}):
|
|
29
|
+
}): react_jsx_runtime41.JSX.Element;
|
|
30
30
|
declare function DialogHeader({
|
|
31
31
|
className,
|
|
32
32
|
...props
|
|
33
|
-
}: React.ComponentProps<'div'>):
|
|
33
|
+
}: React.ComponentProps<'div'>): react_jsx_runtime41.JSX.Element;
|
|
34
34
|
declare function DialogFooter({
|
|
35
35
|
className,
|
|
36
36
|
...props
|
|
37
|
-
}: React.ComponentProps<'div'>):
|
|
37
|
+
}: React.ComponentProps<'div'>): react_jsx_runtime41.JSX.Element;
|
|
38
38
|
declare function DialogTitle({
|
|
39
39
|
className,
|
|
40
40
|
...props
|
|
41
|
-
}: React.ComponentProps<typeof DialogPrimitive.Title>):
|
|
41
|
+
}: React.ComponentProps<typeof DialogPrimitive.Title>): react_jsx_runtime41.JSX.Element;
|
|
42
42
|
declare function DialogDescription({
|
|
43
43
|
className,
|
|
44
44
|
...props
|
|
45
|
-
}: React.ComponentProps<typeof DialogPrimitive.Description>):
|
|
45
|
+
}: React.ComponentProps<typeof DialogPrimitive.Description>): react_jsx_runtime41.JSX.Element;
|
|
46
46
|
//#endregion
|
|
47
47
|
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger };
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime51 from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ui/dropdown-menu.d.ts
|
|
6
6
|
declare function DropdownMenu({
|
|
7
7
|
...props
|
|
8
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>):
|
|
8
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>): react_jsx_runtime51.JSX.Element;
|
|
9
9
|
declare function DropdownMenuPortal({
|
|
10
10
|
...props
|
|
11
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>):
|
|
11
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>): react_jsx_runtime51.JSX.Element;
|
|
12
12
|
declare function DropdownMenuTrigger({
|
|
13
13
|
...props
|
|
14
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>):
|
|
14
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>): react_jsx_runtime51.JSX.Element;
|
|
15
15
|
declare function DropdownMenuContent({
|
|
16
16
|
className,
|
|
17
17
|
sideOffset,
|
|
18
18
|
...props
|
|
19
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>):
|
|
19
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>): react_jsx_runtime51.JSX.Element;
|
|
20
20
|
declare function DropdownMenuGroup({
|
|
21
21
|
...props
|
|
22
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>):
|
|
22
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>): react_jsx_runtime51.JSX.Element;
|
|
23
23
|
declare function DropdownMenuItem({
|
|
24
24
|
className,
|
|
25
25
|
inset,
|
|
@@ -28,39 +28,39 @@ declare function DropdownMenuItem({
|
|
|
28
28
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
|
29
29
|
inset?: boolean;
|
|
30
30
|
variant?: 'default' | 'destructive';
|
|
31
|
-
}):
|
|
31
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
32
32
|
declare function DropdownMenuCheckboxItem({
|
|
33
33
|
className,
|
|
34
34
|
children,
|
|
35
35
|
checked,
|
|
36
36
|
...props
|
|
37
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>):
|
|
37
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>): react_jsx_runtime51.JSX.Element;
|
|
38
38
|
declare function DropdownMenuRadioGroup({
|
|
39
39
|
...props
|
|
40
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>):
|
|
40
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>): react_jsx_runtime51.JSX.Element;
|
|
41
41
|
declare function DropdownMenuRadioItem({
|
|
42
42
|
className,
|
|
43
43
|
children,
|
|
44
44
|
...props
|
|
45
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>):
|
|
45
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>): react_jsx_runtime51.JSX.Element;
|
|
46
46
|
declare function DropdownMenuLabel({
|
|
47
47
|
className,
|
|
48
48
|
inset,
|
|
49
49
|
...props
|
|
50
50
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
|
51
51
|
inset?: boolean;
|
|
52
|
-
}):
|
|
52
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
53
53
|
declare function DropdownMenuSeparator({
|
|
54
54
|
className,
|
|
55
55
|
...props
|
|
56
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>):
|
|
56
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>): react_jsx_runtime51.JSX.Element;
|
|
57
57
|
declare function DropdownMenuShortcut({
|
|
58
58
|
className,
|
|
59
59
|
...props
|
|
60
|
-
}: React.ComponentProps<'span'>):
|
|
60
|
+
}: React.ComponentProps<'span'>): react_jsx_runtime51.JSX.Element;
|
|
61
61
|
declare function DropdownMenuSub({
|
|
62
62
|
...props
|
|
63
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>):
|
|
63
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>): react_jsx_runtime51.JSX.Element;
|
|
64
64
|
declare function DropdownMenuSubTrigger({
|
|
65
65
|
className,
|
|
66
66
|
inset,
|
|
@@ -68,10 +68,10 @@ declare function DropdownMenuSubTrigger({
|
|
|
68
68
|
...props
|
|
69
69
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
|
70
70
|
inset?: boolean;
|
|
71
|
-
}):
|
|
71
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
72
72
|
declare function DropdownMenuSubContent({
|
|
73
73
|
className,
|
|
74
74
|
...props
|
|
75
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>):
|
|
75
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>): react_jsx_runtime51.JSX.Element;
|
|
76
76
|
//#endregion
|
|
77
77
|
export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger };
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime51 from "react/jsx-runtime";
|
|
3
3
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ui/dropdown-menu.d.ts
|
|
6
6
|
declare function DropdownMenu({
|
|
7
7
|
...props
|
|
8
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>):
|
|
8
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>): react_jsx_runtime51.JSX.Element;
|
|
9
9
|
declare function DropdownMenuPortal({
|
|
10
10
|
...props
|
|
11
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>):
|
|
11
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>): react_jsx_runtime51.JSX.Element;
|
|
12
12
|
declare function DropdownMenuTrigger({
|
|
13
13
|
...props
|
|
14
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>):
|
|
14
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>): react_jsx_runtime51.JSX.Element;
|
|
15
15
|
declare function DropdownMenuContent({
|
|
16
16
|
className,
|
|
17
17
|
sideOffset,
|
|
18
18
|
...props
|
|
19
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>):
|
|
19
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>): react_jsx_runtime51.JSX.Element;
|
|
20
20
|
declare function DropdownMenuGroup({
|
|
21
21
|
...props
|
|
22
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>):
|
|
22
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>): react_jsx_runtime51.JSX.Element;
|
|
23
23
|
declare function DropdownMenuItem({
|
|
24
24
|
className,
|
|
25
25
|
inset,
|
|
@@ -28,39 +28,39 @@ declare function DropdownMenuItem({
|
|
|
28
28
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
|
29
29
|
inset?: boolean;
|
|
30
30
|
variant?: 'default' | 'destructive';
|
|
31
|
-
}):
|
|
31
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
32
32
|
declare function DropdownMenuCheckboxItem({
|
|
33
33
|
className,
|
|
34
34
|
children,
|
|
35
35
|
checked,
|
|
36
36
|
...props
|
|
37
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>):
|
|
37
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>): react_jsx_runtime51.JSX.Element;
|
|
38
38
|
declare function DropdownMenuRadioGroup({
|
|
39
39
|
...props
|
|
40
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>):
|
|
40
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>): react_jsx_runtime51.JSX.Element;
|
|
41
41
|
declare function DropdownMenuRadioItem({
|
|
42
42
|
className,
|
|
43
43
|
children,
|
|
44
44
|
...props
|
|
45
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>):
|
|
45
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>): react_jsx_runtime51.JSX.Element;
|
|
46
46
|
declare function DropdownMenuLabel({
|
|
47
47
|
className,
|
|
48
48
|
inset,
|
|
49
49
|
...props
|
|
50
50
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
|
51
51
|
inset?: boolean;
|
|
52
|
-
}):
|
|
52
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
53
53
|
declare function DropdownMenuSeparator({
|
|
54
54
|
className,
|
|
55
55
|
...props
|
|
56
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>):
|
|
56
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>): react_jsx_runtime51.JSX.Element;
|
|
57
57
|
declare function DropdownMenuShortcut({
|
|
58
58
|
className,
|
|
59
59
|
...props
|
|
60
|
-
}: React.ComponentProps<'span'>):
|
|
60
|
+
}: React.ComponentProps<'span'>): react_jsx_runtime51.JSX.Element;
|
|
61
61
|
declare function DropdownMenuSub({
|
|
62
62
|
...props
|
|
63
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>):
|
|
63
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>): react_jsx_runtime51.JSX.Element;
|
|
64
64
|
declare function DropdownMenuSubTrigger({
|
|
65
65
|
className,
|
|
66
66
|
inset,
|
|
@@ -68,10 +68,10 @@ declare function DropdownMenuSubTrigger({
|
|
|
68
68
|
...props
|
|
69
69
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
|
70
70
|
inset?: boolean;
|
|
71
|
-
}):
|
|
71
|
+
}): react_jsx_runtime51.JSX.Element;
|
|
72
72
|
declare function DropdownMenuSubContent({
|
|
73
73
|
className,
|
|
74
74
|
...props
|
|
75
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>):
|
|
75
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>): react_jsx_runtime51.JSX.Element;
|
|
76
76
|
//#endregion
|
|
77
77
|
export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/utils.cjs`);require(`../../lib/index.cjs`);let n=require(`react`);n=e.__toESM(n);let r=require(`react/jsx-runtime`);r=e.__toESM(r);let i=require(`@radix-ui/react-slot`);i=e.__toESM(i);let a=require(`lucide-react`);a=e.__toESM(a);let o=require(`@radix-ui/react-direction`);o=e.__toESM(o);const s=`FileUpload`,c=`FileUploadDropzone`,l=`FileUploadTrigger`,u=`FileUploadList`,d=`FileUploadItem`,f=`FileUploadItemPreview`,p=`FileUploadItemMetadata`,m=`FileUploadItemProgress`,h=`FileUploadItemDelete`,g=`FileUploadClear`;function _(e){let t=n.useRef(null);return t.current===null&&(t.current=e()),t}function v(e,t,n,r,i){let a={files:t,dragOver:!1,invalid:r};function o(e,r){switch(r.type){case`ADD_FILES`:for(let e of r.files)t.set(e,{file:e,progress:0,status:`idle`});return i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_FILES`:{let n=new Set(r.files);for(let e of t.keys())n.has(e)||t.delete(e);for(let e of r.files)t.get(e)||t.set(e,{file:e,progress:0,status:`idle`});return{...e,files:t}}case`SET_PROGRESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:r.progress,status:`uploading`}),{...e,files:t}}case`SET_SUCCESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:100,status:`success`}),{...e,files:t}}case`SET_ERROR`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,error:r.error,status:`error`}),{...e,files:t}}case`REMOVE_FILE`:if(n){let e=n.get(r.file);e&&(URL.revokeObjectURL(e),n.delete(r.file))}return t.delete(r.file),i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_DRAG_OVER`:return{...e,dragOver:r.dragOver};case`SET_INVALID`:return{...e,invalid:r.invalid};case`CLEAR`:if(n)for(let e of t.keys()){let t=n.get(e);t&&(URL.revokeObjectURL(t),n.delete(e))}return t.clear(),i&&i([]),{...e,files:t,invalid:!1};default:return e}}function s(){return a}function c(t){a=o(a,t);for(let t of e)t()}function l(t){return e.add(t),()=>e.delete(t)}return{getState:s,dispatch:c,subscribe:l}}const y=n.createContext(null);function b(e){let t=n.use(y);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function x(e){let t=b(`useStore`),r=_(()=>null),i=n.useCallback(()=>{let n=t.getState(),i=r.current;if(i&&i.state===n)return i.value;let a=e(n);return r.current={value:a,state:n},a},[t,e,r]);return n.useSyncExternalStore(t.subscribe,i,i)}const S=n.createContext(null);function C(e){let t=n.use(S);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function w(e){let{value:a,defaultValue:s,onValueChange:c,onAccept:l,onFileAccept:u,onFileReject:d,onFilesReject:f,onFileValidate:p,onUpload:m,accept:h,maxFiles:g,maxSize:b,dir:x,label:C,name:w,asChild:T,disabled:E=!1,invalid:D=!1,multiple:O=!1,required:k=!1,children:A,className:j,...M}=e,N=n.useId(),P=n.useId(),F=n.useId(),I=n.useId(),L=(0,o.useDirection)(x),R=_(()=>new Set).current,z=_(()=>new Map).current,B=_(()=>new WeakMap).current,V=n.useRef(null),H=a!==void 0,U=n.useMemo(()=>v(R,z,B,D,c),[R,z,D,c,B]),W=n.useMemo(()=>h?.split(`,`).map(e=>e.trim())??null,[h]),G=_(()=>{let e=0;return(t,n)=>{e||=requestAnimationFrame(()=>{e=0,U.dispatch({type:`SET_PROGRESS`,file:t,progress:Math.min(Math.max(0,n),100)})})}}).current;n.useEffect(()=>{H?U.dispatch({type:`SET_FILES`,files:a}):s&&s.length>0&&!U.getState().files.size&&U.dispatch({type:`SET_FILES`,files:s})},[a,s,H,U]),n.useEffect(()=>()=>{for(let e of z.keys()){let t=B.get(e);t&&URL.revokeObjectURL(t)}},[z,B]);let K=n.useCallback(async e=>{try{for(let t of e)U.dispatch({type:`SET_PROGRESS`,file:t,progress:0});if(m)await m(e,{onProgress:G,onSuccess:e=>{U.dispatch({type:`SET_SUCCESS`,file:e})},onError:(e,t)=>{U.dispatch({type:`SET_ERROR`,file:e,error:t.message??`Upload failed`})}});else for(let t of e)U.dispatch({type:`SET_SUCCESS`,file:t})}catch(t){let n=t instanceof Error?t.message:`Upload failed`;for(let t of e)U.dispatch({type:`SET_ERROR`,file:t,error:n})}},[U,m,G]),q=n.useCallback(e=>{if(E)return;let t=[...e],n=!1,r=[];if(g){let e=U.getState().files.size,i=Math.max(0,g-e);if(i<t.length){let e=t.slice(i);n=!0,t=t.slice(0,i);for(let t of e){let e=`Maximum ${g} files allowed`;if(p){let n=p(t);n&&(e=n)}d?.(t,e),r.push({file:t,message:e})}}}let i=[],a=[];for(let e of t){let t=!1,r=``;if(p){let i=p(e);if(i){r=i,d?.(e,r),t=!0,n=!0;continue}}if(W){let i=e.type,a=`.${e.name.split(`.`).pop()}`;W.some(e=>e===i||e===a||e.includes(`/*`)&&i.startsWith(e.replace(`/*`,`/`)))||(r=`File type not accepted`,d?.(e,r),t=!0,n=!0)}b&&e.size>b&&(r=`File too large`,d?.(e,r),t=!0,n=!0),t?a.push({file:e,message:r}):i.push(e)}if(r.push(...a),n&&(U.dispatch({type:`SET_INVALID`,invalid:n}),setTimeout(()=>{U.dispatch({type:`SET_INVALID`,invalid:!1})},2e3)),r.length>0&&f?.(r),i.length>0){U.dispatch({type:`ADD_FILES`,files:i}),H&&c&&c([...Array.from(U.getState().files.values()).map(e=>e.file)]),l&&l(i);for(let e of i)u?.(e);m&&requestAnimationFrame(()=>{K(i)})}},[U,H,c,l,u,m,K,g,p,d,f,W,b,E]),J=n.useCallback(e=>{q(Array.from(e.target.files??[])),e.target.value=``},[q]),Y=n.useMemo(()=>({dropzoneId:P,inputId:N,listId:F,labelId:I,dir:L,disabled:E,inputRef:V,urlCache:B}),[P,N,F,I,L,E,B]),X=T?i.Slot:`div`;return(0,r.jsx)(y.Provider,{value:U,children:(0,r.jsx)(S.Provider,{value:Y,children:(0,r.jsxs)(X,{"data-disabled":E?``:void 0,"data-slot":`file-upload`,dir:L,...M,className:t.cn(`relative flex flex-col gap-2`,j),children:[A,(0,r.jsx)(`input`,{type:`file`,id:N,"aria-labelledby":I,"aria-describedby":P,ref:V,tabIndex:-1,accept:h,name:w,className:`sr-only`,disabled:E,multiple:O,required:k,onChange:J}),(0,r.jsx)(`span`,{id:I,className:`sr-only`,children:C??`File upload`})]})})})}function T(e){let{asChild:a,className:o,onClick:s,onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f,onPaste:p,onKeyDown:m,...h}=e,g=C(c),_=b(c),v=x(e=>e.dragOver),y=x(e=>e.invalid),S=n.useCallback(e=>{if(s?.(e),e.defaultPrevented)return;let{target:t}=e;t instanceof HTMLElement&&t.closest(`[data-slot="file-upload-trigger"]`)||g.inputRef.current?.click()},[g.inputRef,s]),w=n.useCallback(e=>{l?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,l]),T=n.useCallback(e=>{u?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,u]),E=n.useCallback(e=>{if(d?.(e),e.defaultPrevented)return;let{relatedTarget:t}=e;t&&t instanceof Node&&e.currentTarget.contains(t)||(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1}))},[_,d]),D=n.useCallback(e=>{if(f?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=Array.from(e.dataTransfer.files),n=g.inputRef.current;if(!n)return;let r=new DataTransfer;for(let e of t)r.items.add(e);n.files=r.files,n.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,f]),O=n.useCallback(e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r?.kind===`file`){let e=r.getAsFile();e&&n.push(e)}}if(n.length===0)return;let r=g.inputRef.current;if(!r)return;let i=new DataTransfer;for(let e of n)i.items.add(e);r.files=i.files,r.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,p]),k=n.useCallback(e=>{m?.(e),!e.defaultPrevented&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g.inputRef.current?.click())},[g.inputRef,m]);return(0,r.jsx)(a?i.Slot:`div`,{role:`region`,id:g.dropzoneId,"aria-controls":`${g.inputId} ${g.listId}`,"aria-disabled":g.disabled,"aria-invalid":y,"data-disabled":g.disabled?``:void 0,"data-dragging":v?``:void 0,"data-invalid":y?``:void 0,"data-slot":`file-upload-dropzone`,dir:g.dir,tabIndex:g.disabled?void 0:0,...h,className:t.cn(`relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20`,o),onClick:S,onDragEnter:T,onDragLeave:E,onDragOver:w,onDrop:D,onKeyDown:k,onPaste:O})}function E(e){let{asChild:t,onClick:a,...o}=e,s=C(`FileUploadTrigger`),c=n.useCallback(e=>{a?.(e),!e.defaultPrevented&&s.inputRef.current?.click()},[s.inputRef,a]);return(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":s.inputId,"data-disabled":s.disabled?``:void 0,"data-slot":`file-upload-trigger`,...o,disabled:s.disabled,onClick:c})}function D(e){let{className:n,orientation:a=`vertical`,asChild:o,forceMount:s,...c}=e,l=C(`FileUploadList`),u=x(e=>e.files.size),d=s||u>0;return d?(0,r.jsx)(o?i.Slot:`div`,{role:`list`,id:l.listId,"aria-orientation":a,"data-orientation":a,"data-slot":`file-upload-list`,"data-state":d?`active`:`inactive`,dir:l.dir,...c,className:t.cn(`data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out`,a===`horizontal`&&`flex-row overflow-x-auto p-1.5`,n)}):null}const O=n.createContext(null);function k(e){let t=n.use(O);if(!t)throw Error(`\`${e}\` must be used within \`${d}\``);return t}function A(e){let{value:a,asChild:o,className:s,...c}=e,l=n.useId(),u=`${l}-status`,f=`${l}-name`,p=`${l}-size`,m=`${l}-message`,h=C(d),g=x(e=>e.files.get(a)),_=x(e=>e.files.size),v=x(e=>Array.from(e.files.keys()).indexOf(a)+1),y=n.useMemo(()=>({id:l,fileState:g,nameId:f,sizeId:p,statusId:u,messageId:m}),[l,g,u,f,p,m]);if(!g)return null;let b=g.error?`Error: ${g.error}`:g.status===`uploading`?`Uploading: ${g.progress}% complete`:g.status===`success`?`Upload complete`:`Ready to upload`,S=o?i.Slot:`div`;return(0,r.jsx)(O.Provider,{value:y,children:(0,r.jsxs)(S,{role:`listitem`,id:l,"aria-setsize":_,"aria-posinset":v,"aria-describedby":`${f} ${p} ${u} ${g.error?m:``}`,"aria-labelledby":f,"data-slot":`file-upload-item`,dir:h.dir,...c,className:t.cn(`relative flex items-center rounded-md border p-3`,s),children:[e.children,(0,r.jsx)(`span`,{id:u,className:`sr-only`,children:b})]})})}function j(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n?1:0)} ${t[n]}`}function M(e){let{type:t}=e,n=e.name.split(`.`).pop()?.toLowerCase()??``;return t.startsWith(`video/`)?(0,r.jsx)(a.FileVideoIcon,{}):t.startsWith(`audio/`)?(0,r.jsx)(a.FileAudioIcon,{}):t.startsWith(`text/`)||[`txt`,`md`,`rtf`,`pdf`].includes(n)?(0,r.jsx)(a.FileTextIcon,{}):[`html`,`css`,`js`,`jsx`,`ts`,`tsx`,`json`,`xml`,`php`,`py`,`rb`,`java`,`c`,`cpp`,`cs`].includes(n)?(0,r.jsx)(a.FileCodeIcon,{}):[`zip`,`rar`,`7z`,`tar`,`gz`,`bz2`].includes(n)?(0,r.jsx)(a.FileArchiveIcon,{}):[`exe`,`msi`,`app`,`apk`,`deb`,`rpm`].includes(n)||t.startsWith(`application/`)?(0,r.jsx)(a.FileCogIcon,{}):(0,r.jsx)(a.FileIcon,{})}function N(e){let{render:a,asChild:o,children:s,className:c,...l}=e,u=k(f),d=C(f),p=n.useCallback(e=>{if(u.fileState?.file.type.startsWith(`image/`)){let t=d.urlCache.get(e);return t||(t=URL.createObjectURL(e),d.urlCache.set(e,t)),(0,r.jsx)(`img`,{src:t,alt:e.name,className:`size-full object-cover`})}return M(e)},[u.fileState?.file.type,d.urlCache]),m=n.useCallback(async e=>a?a(e,()=>p(e)):p(e),[a,p]);return u.fileState?(0,r.jsxs)(o?i.Slot:`div`,{"aria-labelledby":u.nameId,"data-slot":`file-upload-preview`,...l,className:t.cn(`relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10`,c),children:[m(u.fileState.file),s]}):null}function P(e){let{asChild:n,size:a=`default`,children:o,className:s,...c}=e,l=C(p),u=k(p);return u.fileState?(0,r.jsx)(n?i.Slot:`div`,{"data-slot":`file-upload-metadata`,dir:l.dir,...c,className:t.cn(`flex min-w-0 flex-1 flex-col`,s),children:o??(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(`span`,{id:u.nameId,className:t.cn(`truncate font-medium text-sm`,a===`sm`&&`font-normal text-[13px] leading-snug`),children:u.fileState.file.name}),(0,r.jsx)(`span`,{id:u.sizeId,className:t.cn(`truncate text-muted-foreground text-xs`,a===`sm`&&`text-[11px] leading-snug`),children:j(u.fileState.file.size)}),u.fileState.error&&(0,r.jsx)(`span`,{id:u.messageId,className:`text-destructive text-xs`,children:u.fileState.error})]})}):null}function F(e){let{variant:n=`linear`,size:a=40,asChild:o,forceMount:s,className:c,...l}=e,u=k(`FileUploadItemProgress`);if(!u.fileState||!(s||u.fileState.progress!==100))return null;let d=o?i.Slot:`div`;switch(n){case`circular`:{let e=2*Math.PI*((a-4)/2),n=e-u.fileState.progress/100*e;return(0,r.jsx)(d,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":u.fileState.progress,"aria-valuetext":`${u.fileState.progress}%`,"aria-labelledby":u.nameId,"data-slot":`file-upload-progress`,...l,className:t.cn(`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2`,c),children:(0,r.jsxs)(`svg`,{className:`-rotate-90 transform`,width:a,height:a,viewBox:`0 0 ${a} ${a}`,fill:`none`,stroke:`currentColor`,children:[(0,r.jsx)(`circle`,{className:`text-primary/20`,strokeWidth:`2`,cx:a/2,cy:a/2,r:(a-4)/2}),(0,r.jsx)(`circle`,{className:`text-primary transition-[stroke-dashoffset] duration-300 ease-linear`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:e,strokeDashoffset:n,cx:a/2,cy:a/2,r:(a-4)/2})]})})}case`fill`:{let e=u.fileState.progress,n=100-e;return(0,r.jsx)(d,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":e,"aria-valuetext":`${e}%`,"aria-labelledby":u.nameId,"data-slot":`file-upload-progress`,...l,className:t.cn(`absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear`,c),style:{clipPath:`inset(${n}% 0% 0% 0%)`}})}default:return(0,r.jsx)(d,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":u.fileState.progress,"aria-valuetext":`${u.fileState.progress}%`,"aria-labelledby":u.nameId,"data-slot":`file-upload-progress`,...l,className:t.cn(`relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20`,c),children:(0,r.jsx)(`div`,{className:`h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear`,style:{transform:`translateX(-${100-u.fileState.progress}%)`}})})}}function I(e){let{asChild:t,onClick:a,...o}=e,s=b(h),c=k(h),l=n.useCallback(e=>{a?.(e),!(!c.fileState||e.defaultPrevented)&&s.dispatch({type:`REMOVE_FILE`,file:c.fileState.file})},[s,c.fileState,a]);return c.fileState?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":c.id,"aria-describedby":c.nameId,"data-slot":`file-upload-item-delete`,...o,onClick:l}):null}function L(e){let{asChild:t,forceMount:a,disabled:o,onClick:s,...c}=e,l=C(g),u=b(g),d=x(e=>e.files.size),f=o||l.disabled,p=n.useCallback(e=>{s?.(e),!e.defaultPrevented&&u.dispatch({type:`CLEAR`})},[u,s]);return a||d>0?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":l.listId,"data-slot":`file-upload-clear`,"data-disabled":f?``:void 0,...c,disabled:f,onClick:p}):null}exports.FileUploadClear=L,exports.FileUploadDropzone=T,exports.FileUploadItem=A,exports.FileUploadItemDelete=I,exports.FileUploadItemMetadata=P,exports.FileUploadItemPreview=N,exports.FileUploadItemProgress=F,exports.FileUploadList=D,exports.FileUploadRoot=w,exports.FileUploadTrigger=E,exports.useStore=x;
|
|
1
|
+
"use client";const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/utils.cjs`);require(`../../lib/index.cjs`);let n=require(`react`);n=e.__toESM(n);let r=require(`react/jsx-runtime`);r=e.__toESM(r);let i=require(`@radix-ui/react-slot`);i=e.__toESM(i);let a=require(`lucide-react`);a=e.__toESM(a);let o=require(`@radix-ui/react-direction`);o=e.__toESM(o);const s=`FileUpload`,c=`FileUploadDropzone`,l=`FileUploadTrigger`,u=`FileUploadList`,d=`FileUploadItem`,f=`FileUploadItemPreview`,p=`FileUploadItemMetadata`,m=`FileUploadItemProgress`,h=`FileUploadItemDelete`,g=`FileUploadClear`;function _(e){let t=n.useRef(null);return t.current===null&&(t.current=e()),t}function v(e,t,n,r,i){let a={files:t,dragOver:!1,invalid:r};function o(e,r){switch(r.type){case`ADD_FILES`:for(let e of r.files)t.set(e,{file:e,progress:0,status:`idle`});return i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_FILES`:{let n=new Set(r.files);for(let e of t.keys())n.has(e)||t.delete(e);for(let e of r.files)t.get(e)||t.set(e,{file:e,progress:0,status:`idle`});return{...e,files:t}}case`SET_PROGRESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:r.progress,status:`uploading`}),{...e,files:t}}case`SET_SUCCESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:100,status:`success`}),{...e,files:t}}case`SET_ERROR`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,error:r.error,status:`error`}),{...e,files:t}}case`REMOVE_FILE`:if(n){let e=n.get(r.file);e&&(URL.revokeObjectURL(e),n.delete(r.file))}return t.delete(r.file),i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_DRAG_OVER`:return{...e,dragOver:r.dragOver};case`SET_INVALID`:return{...e,invalid:r.invalid};case`CLEAR`:if(n)for(let e of t.keys()){let t=n.get(e);t&&(URL.revokeObjectURL(t),n.delete(e))}return t.clear(),i&&i([]),{...e,files:t,invalid:!1};default:return e}}function s(){return a}function c(t){a=o(a,t);for(let t of e)t()}function l(t){return e.add(t),()=>e.delete(t)}return{getState:s,dispatch:c,subscribe:l}}const y=n.createContext(null);function b(e){let t=n.use(y);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function x(e){let t=b(`useStore`),r=_(()=>null),i=n.useCallback(()=>{let n=t.getState(),i=r.current;if(i&&i.state===n)return i.value;let a=e(n);return r.current={value:a,state:n},a},[t,e,r]);return n.useSyncExternalStore(t.subscribe,i,i)}const S=n.createContext(null);function C(e){let t=n.use(S);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function w(e){let{value:a,defaultValue:s,onValueChange:c,onAccept:l,onFileAccept:u,onFileReject:d,onFilesReject:f,onFileValidate:p,onUpload:m,accept:h,maxFiles:g,maxSize:b,dir:x,label:C,name:w,asChild:T,disabled:E=!1,invalid:D=!1,multiple:O=!1,required:k=!1,children:A,className:j,...M}=e,N=n.useId(),P=n.useId(),F=n.useId(),I=n.useId(),L=(0,o.useDirection)(x),R=_(()=>new Set).current,z=_(()=>new Map).current,B=_(()=>new WeakMap).current,V=n.useRef(null),H=a!==void 0,U=n.useMemo(()=>v(R,z,B,D,c),[R,z,D,c,B]),W=n.useMemo(()=>h?.split(`,`).map(e=>e.trim())??null,[h]),G=_(()=>{let e=0;return(t,n)=>{e||=requestAnimationFrame(()=>{e=0,U.dispatch({type:`SET_PROGRESS`,file:t,progress:Math.min(Math.max(0,n),100)})})}}).current;n.useEffect(()=>{H?U.dispatch({type:`SET_FILES`,files:a}):s&&s.length>0&&!U.getState().files.size&&U.dispatch({type:`SET_FILES`,files:s})},[a,s,H,U]),n.useEffect(()=>()=>{for(let e of z.keys()){let t=B.get(e);t&&URL.revokeObjectURL(t)}},[z,B]);let K=n.useCallback(async e=>{try{for(let t of e)U.dispatch({type:`SET_PROGRESS`,file:t,progress:0});if(m)await m(e,{onProgress:G,onSuccess:e=>{U.dispatch({type:`SET_SUCCESS`,file:e})},onError:(e,t)=>{U.dispatch({type:`SET_ERROR`,file:e,error:t.message??`Upload failed`})}});else for(let t of e)U.dispatch({type:`SET_SUCCESS`,file:t})}catch(t){let n=t instanceof Error?t.message:`Upload failed`;for(let t of e)U.dispatch({type:`SET_ERROR`,file:t,error:n})}},[U,m,G]),q=n.useCallback(e=>{if(E)return;let t=[...e],n=!1,r=[];if(g){let e=U.getState().files.size,i=Math.max(0,g-e);if(i<t.length){let e=t.slice(i);n=!0,t=t.slice(0,i);for(let t of e){let e=`Maximum ${g} files allowed`;if(p){let n=p(t);n&&(e=n)}d?.(t,e),r.push({file:t,message:e})}}}let i=[],a=[];for(let e of t){let t=!1,r=``;if(p){let i=p(e);if(i){r=i,d?.(e,r),t=!0,n=!0;continue}}if(W){let i=e.type,a=`.${e.name.split(`.`).pop()}`;W.some(e=>e===i||e===a||e.includes(`/*`)&&i.startsWith(e.replace(`/*`,`/`)))||(r=`File type not accepted`,d?.(e,r),t=!0,n=!0)}b&&e.size>b&&(r=`File too large`,d?.(e,r),t=!0,n=!0),t?a.push({file:e,message:r}):i.push(e)}if(r.push(...a),n&&(U.dispatch({type:`SET_INVALID`,invalid:n}),setTimeout(()=>{U.dispatch({type:`SET_INVALID`,invalid:!1})},2e3)),r.length>0&&f?.(r),i.length>0){U.dispatch({type:`ADD_FILES`,files:i}),H&&c&&c([...Array.from(U.getState().files.values()).map(e=>e.file)]),l&&l(i);for(let e of i)u?.(e);m&&requestAnimationFrame(()=>{K(i)})}},[U,H,c,l,u,m,K,g,p,d,f,W,b,E]),J=n.useCallback(e=>{q(Array.from(e.target.files??[])),e.target.value=``},[q]),Y=n.useMemo(()=>({dropzoneId:P,inputId:N,listId:F,labelId:I,dir:L,disabled:E,inputRef:V,urlCache:B}),[P,N,F,I,L,E,B]),X=T?i.Slot:`div`;return(0,r.jsx)(y.Provider,{value:U,children:(0,r.jsx)(S.Provider,{value:Y,children:(0,r.jsxs)(X,{"data-disabled":E?``:void 0,"data-slot":`file-upload`,dir:L,...M,className:t.cn(`relative flex flex-col gap-2`,j),children:[A,(0,r.jsx)(`input`,{type:`file`,id:N,"aria-labelledby":I,"aria-describedby":P,ref:V,tabIndex:-1,accept:h,name:w,className:`sr-only`,disabled:E,multiple:O,required:k,onChange:J}),(0,r.jsx)(`span`,{id:I,className:`sr-only`,children:C??`File upload`})]})})})}function T(e){let{asChild:a,className:o,onClick:s,onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f,onPaste:p,onKeyDown:m,...h}=e,g=C(c),_=b(c),v=x(e=>e.dragOver),y=x(e=>e.invalid),S=n.useCallback(e=>{if(s?.(e),e.defaultPrevented)return;let{target:t}=e;t instanceof HTMLElement&&t.closest(`[data-slot="file-upload-trigger"]`)||g.inputRef.current?.click()},[g.inputRef,s]),w=n.useCallback(e=>{l?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,l]),T=n.useCallback(e=>{u?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,u]),E=n.useCallback(e=>{if(d?.(e),e.defaultPrevented)return;let{relatedTarget:t}=e;t&&t instanceof Node&&e.currentTarget.contains(t)||(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1}))},[_,d]),D=n.useCallback(e=>{if(f?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=Array.from(e.dataTransfer.files),n=g.inputRef.current;if(!n)return;let r=new DataTransfer;for(let e of t)r.items.add(e);n.files=r.files,n.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,f]),O=n.useCallback(e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r?.kind===`file`){let e=r.getAsFile();e&&n.push(e)}}if(n.length===0)return;let r=g.inputRef.current;if(!r)return;let i=new DataTransfer;for(let e of n)i.items.add(e);r.files=i.files,r.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,p]),k=n.useCallback(e=>{m?.(e),!e.defaultPrevented&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g.inputRef.current?.click())},[g.inputRef,m]);return(0,r.jsx)(a?i.Slot:`div`,{role:`region`,id:g.dropzoneId,"aria-controls":`${g.inputId} ${g.listId}`,"aria-disabled":g.disabled,"aria-invalid":y,"data-disabled":g.disabled?``:void 0,"data-dragging":v?``:void 0,"data-invalid":y?``:void 0,"data-slot":`file-upload-dropzone`,dir:g.dir,tabIndex:g.disabled?void 0:0,...h,className:t.cn(`relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20`,o),onClick:S,onDragEnter:T,onDragLeave:E,onDragOver:w,onDrop:D,onKeyDown:k,onPaste:O})}function E(e){let{asChild:t,onClick:a,...o}=e,s=C(`FileUploadTrigger`),c=n.useCallback(e=>{a?.(e),!e.defaultPrevented&&s.inputRef.current?.click()},[s.inputRef,a]);return(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":s.inputId,"data-disabled":s.disabled?``:void 0,"data-slot":`file-upload-trigger`,...o,disabled:s.disabled,onClick:c})}function D(e){let{className:n,orientation:a=`vertical`,asChild:o,forceMount:s,...c}=e,l=C(`FileUploadList`),u=x(e=>e.files.size),d=s||u>0;return d?(0,r.jsx)(o?i.Slot:`div`,{role:`list`,id:l.listId,"aria-orientation":a,"data-orientation":a,"data-slot":`file-upload-list`,"data-state":d?`active`:`inactive`,dir:l.dir,...c,className:t.cn(`data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out`,a===`horizontal`&&`flex-row overflow-x-auto p-1.5`,n)}):null}const O=n.createContext(null);function k(e){let t=n.use(O);if(!t)throw Error(`\`${e}\` must be used within \`${d}\``);return t}function A(e){let{value:a,asChild:o,className:s,...c}=e,l=n.useId(),u=`${l}-status`,f=`${l}-name`,p=`${l}-size`,m=`${l}-message`,h=C(d),g=x(e=>e.files.get(a)),_=x(e=>e.files.size),v=x(e=>Array.from(e.files.keys()).indexOf(a)+1),y=n.useMemo(()=>({id:l,fileState:g,nameId:f,sizeId:p,statusId:u,messageId:m}),[l,g,u,f,p,m]);if(!g)return null;let b=g.error?`Error: ${g.error}`:g.status===`uploading`?`Uploading: ${g.progress}% complete`:g.status===`success`?`Upload complete`:`Ready to upload`,S=o?i.Slot:`div`;return(0,r.jsx)(O.Provider,{value:y,children:(0,r.jsxs)(S,{role:`listitem`,id:l,"aria-setsize":_,"aria-posinset":v,"aria-describedby":`${f} ${p} ${u} ${g.error?m:``}`,"aria-labelledby":f,"data-slot":`file-upload-item`,dir:h.dir,...c,className:t.cn(`relative flex items-center rounded-md border p-3`,s),children:[e.children,(0,r.jsx)(`span`,{id:u,className:`sr-only`,children:b})]})})}function j(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n?1:0)} ${t[n]}`}function M(e){let{type:t}=e,n=e.name.split(`.`).pop()?.toLowerCase()??``;return t.startsWith(`video/`)?(0,r.jsx)(a.FileVideoIcon,{}):t.startsWith(`audio/`)?(0,r.jsx)(a.FileAudioIcon,{}):t.startsWith(`text/`)||[`txt`,`md`,`rtf`,`pdf`].includes(n)?(0,r.jsx)(a.FileTextIcon,{}):[`html`,`css`,`js`,`jsx`,`ts`,`tsx`,`json`,`xml`,`php`,`py`,`rb`,`java`,`c`,`cpp`,`cs`].includes(n)?(0,r.jsx)(a.FileCodeIcon,{}):[`zip`,`rar`,`7z`,`tar`,`gz`,`bz2`].includes(n)?(0,r.jsx)(a.FileArchiveIcon,{}):[`exe`,`msi`,`app`,`apk`,`deb`,`rpm`].includes(n)||t.startsWith(`application/`)?(0,r.jsx)(a.FileCogIcon,{}):(0,r.jsx)(a.FileIcon,{})}function N(e){let{render:a,asChild:o,children:s,className:c,...l}=e,u=k(f),d=C(f),p=n.useCallback(e=>{if(u.fileState?.file.type.startsWith(`image/`)){let t=d.urlCache.get(e);return t||(t=URL.createObjectURL(e),d.urlCache.set(e,t)),(0,r.jsx)(`img`,{src:t,alt:e.name,className:`size-full object-cover`})}return M(e)},[u.fileState?.file.type,d.urlCache]),m=n.useCallback(e=>a?a(e,()=>p(e)):p(e),[a,p]);return u.fileState?(0,r.jsxs)(o?i.Slot:`div`,{"aria-labelledby":u.nameId,"data-slot":`file-upload-preview`,...l,className:t.cn(`relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10`,c),children:[m(u.fileState.file),s]}):null}function P(e){let{asChild:n,size:a=`default`,children:o,className:s,...c}=e,l=C(p),u=k(p);return u.fileState?(0,r.jsx)(n?i.Slot:`div`,{"data-slot":`file-upload-metadata`,dir:l.dir,...c,className:t.cn(`flex min-w-0 flex-1 flex-col`,s),children:o??(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(`span`,{id:u.nameId,className:t.cn(`truncate font-medium text-sm`,a===`sm`&&`font-normal text-[13px] leading-snug`),children:u.fileState.file.name}),(0,r.jsx)(`span`,{id:u.sizeId,className:t.cn(`truncate text-muted-foreground text-xs`,a===`sm`&&`text-[11px] leading-snug`),children:j(u.fileState.file.size)}),u.fileState.error&&(0,r.jsx)(`span`,{id:u.messageId,className:`text-destructive text-xs`,children:u.fileState.error})]})}):null}function F(e){let{variant:n=`linear`,size:a=40,strokeWidth:o=2,asChild:s,forceMount:c,className:l,...u}=e,d=k(`FileUploadItemProgress`);if(!d.fileState||!(c||d.fileState.progress!==100))return null;let f=s?i.Slot:`div`;switch(n){case`circular`:{let e=2*Math.PI*((a-4)/2),n=e-d.fileState.progress/100*e;return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2`,l),children:(0,r.jsxs)(`svg`,{className:`-rotate-90 transform`,width:a,height:a,viewBox:`0 0 ${a} ${a}`,fill:`none`,stroke:`currentColor`,children:[(0,r.jsx)(`circle`,{className:`text-primary/20`,strokeWidth:o,cx:a/2,cy:a/2,r:(a-4)/2}),(0,r.jsx)(`circle`,{className:`text-primary transition-[stroke-dashoffset] duration-300 ease-linear`,strokeWidth:o,strokeLinecap:`round`,strokeDasharray:e,strokeDashoffset:n,cx:a/2,cy:a/2,r:(a-4)/2})]})})}case`fill`:{let e=d.fileState.progress,n=100-e;return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":e,"aria-valuetext":`${e}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear`,l),style:{clipPath:`inset(${n}% 0% 0% 0%)`}})}default:return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20`,l),children:(0,r.jsx)(`div`,{className:`h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear`,style:{transform:`translateX(-${100-d.fileState.progress}%)`}})})}}function I(e){let{asChild:t,onClick:a,...o}=e,s=b(h),c=k(h),l=n.useCallback(e=>{a?.(e),!(!c.fileState||e.defaultPrevented)&&s.dispatch({type:`REMOVE_FILE`,file:c.fileState.file})},[s,c.fileState,a]);return c.fileState?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":c.id,"aria-describedby":c.nameId,"data-slot":`file-upload-item-delete`,...o,onClick:l}):null}function L(e){let{asChild:t,forceMount:a,disabled:o,onClick:s,...c}=e,l=C(g),u=b(g),d=x(e=>e.files.size),f=o||l.disabled,p=n.useCallback(e=>{s?.(e),!e.defaultPrevented&&u.dispatch({type:`CLEAR`})},[u,s]);return a||d>0?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":l.listId,"data-slot":`file-upload-clear`,"data-disabled":f?``:void 0,...c,disabled:f,onClick:p}):null}exports.FileUploadClear=L,exports.FileUploadDropzone=T,exports.FileUploadItem=A,exports.FileUploadItemDelete=I,exports.FileUploadItemMetadata=P,exports.FileUploadItemPreview=N,exports.FileUploadItemProgress=F,exports.FileUploadList=D,exports.FileUploadRoot=w,exports.FileUploadTrigger=E,exports.useStore=x;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime66 from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/components/ui/file-upload.d.ts
|
|
@@ -44,51 +44,52 @@ interface FileUploadRootProps extends Omit<React.ComponentProps<'div'>, 'default
|
|
|
44
44
|
multiple?: boolean;
|
|
45
45
|
required?: boolean;
|
|
46
46
|
}
|
|
47
|
-
declare function FileUploadRoot(props: FileUploadRootProps):
|
|
47
|
+
declare function FileUploadRoot(props: FileUploadRootProps): react_jsx_runtime66.JSX.Element;
|
|
48
48
|
interface FileUploadDropzoneProps extends React.ComponentProps<'div'> {
|
|
49
49
|
asChild?: boolean;
|
|
50
50
|
}
|
|
51
|
-
declare function FileUploadDropzone(props: FileUploadDropzoneProps):
|
|
51
|
+
declare function FileUploadDropzone(props: FileUploadDropzoneProps): react_jsx_runtime66.JSX.Element;
|
|
52
52
|
interface FileUploadTriggerProps extends React.ComponentProps<'button'> {
|
|
53
53
|
asChild?: boolean;
|
|
54
54
|
}
|
|
55
|
-
declare function FileUploadTrigger(props: FileUploadTriggerProps):
|
|
55
|
+
declare function FileUploadTrigger(props: FileUploadTriggerProps): react_jsx_runtime66.JSX.Element;
|
|
56
56
|
interface FileUploadListProps extends React.ComponentProps<'div'> {
|
|
57
57
|
orientation?: 'horizontal' | 'vertical';
|
|
58
58
|
asChild?: boolean;
|
|
59
59
|
forceMount?: boolean;
|
|
60
60
|
}
|
|
61
|
-
declare function FileUploadList(props: FileUploadListProps):
|
|
61
|
+
declare function FileUploadList(props: FileUploadListProps): react_jsx_runtime66.JSX.Element | null;
|
|
62
62
|
interface FileUploadItemProps extends React.ComponentProps<'div'> {
|
|
63
63
|
value: File;
|
|
64
64
|
asChild?: boolean;
|
|
65
65
|
}
|
|
66
|
-
declare function FileUploadItem(props: FileUploadItemProps):
|
|
66
|
+
declare function FileUploadItem(props: FileUploadItemProps): react_jsx_runtime66.JSX.Element | null;
|
|
67
67
|
interface FileUploadItemPreviewProps extends React.ComponentProps<'div'> {
|
|
68
68
|
render?: (file: File, fallback: () => React.ReactNode) => React.ReactNode;
|
|
69
69
|
asChild?: boolean;
|
|
70
70
|
}
|
|
71
|
-
declare function FileUploadItemPreview(props: FileUploadItemPreviewProps):
|
|
71
|
+
declare function FileUploadItemPreview(props: FileUploadItemPreviewProps): react_jsx_runtime66.JSX.Element | null;
|
|
72
72
|
interface FileUploadItemMetadataProps extends React.ComponentProps<'div'> {
|
|
73
73
|
asChild?: boolean;
|
|
74
74
|
size?: 'default' | 'sm';
|
|
75
75
|
}
|
|
76
|
-
declare function FileUploadItemMetadata(props: FileUploadItemMetadataProps):
|
|
76
|
+
declare function FileUploadItemMetadata(props: FileUploadItemMetadataProps): react_jsx_runtime66.JSX.Element | null;
|
|
77
77
|
interface FileUploadItemProgressProps extends React.ComponentProps<'div'> {
|
|
78
78
|
variant?: 'linear' | 'circular' | 'fill';
|
|
79
79
|
size?: number;
|
|
80
|
+
strokeWidth?: number;
|
|
80
81
|
asChild?: boolean;
|
|
81
82
|
forceMount?: boolean;
|
|
82
83
|
}
|
|
83
|
-
declare function FileUploadItemProgress(props: FileUploadItemProgressProps):
|
|
84
|
+
declare function FileUploadItemProgress(props: FileUploadItemProgressProps): react_jsx_runtime66.JSX.Element | null;
|
|
84
85
|
interface FileUploadItemDeleteProps extends React.ComponentProps<'button'> {
|
|
85
86
|
asChild?: boolean;
|
|
86
87
|
}
|
|
87
|
-
declare function FileUploadItemDelete(props: FileUploadItemDeleteProps):
|
|
88
|
+
declare function FileUploadItemDelete(props: FileUploadItemDeleteProps): react_jsx_runtime66.JSX.Element | null;
|
|
88
89
|
interface FileUploadClearProps extends React.ComponentProps<'button'> {
|
|
89
90
|
forceMount?: boolean;
|
|
90
91
|
asChild?: boolean;
|
|
91
92
|
}
|
|
92
|
-
declare function FileUploadClear(props: FileUploadClearProps):
|
|
93
|
+
declare function FileUploadClear(props: FileUploadClearProps): react_jsx_runtime66.JSX.Element | null;
|
|
93
94
|
//#endregion
|
|
94
95
|
export { FileUploadClear, FileUploadDropzone, FileUploadItem, FileUploadItemDelete, FileUploadItemMetadata, FileUploadItemPreview, FileUploadItemProgress, FileUploadList, FileUploadRoot, FileUploadRootProps, FileUploadTrigger, useStore };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime66 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/components/ui/file-upload.d.ts
|
|
5
5
|
type Direction = 'ltr' | 'rtl';
|
|
@@ -44,51 +44,52 @@ interface FileUploadRootProps extends Omit<React.ComponentProps<'div'>, 'default
|
|
|
44
44
|
multiple?: boolean;
|
|
45
45
|
required?: boolean;
|
|
46
46
|
}
|
|
47
|
-
declare function FileUploadRoot(props: FileUploadRootProps):
|
|
47
|
+
declare function FileUploadRoot(props: FileUploadRootProps): react_jsx_runtime66.JSX.Element;
|
|
48
48
|
interface FileUploadDropzoneProps extends React.ComponentProps<'div'> {
|
|
49
49
|
asChild?: boolean;
|
|
50
50
|
}
|
|
51
|
-
declare function FileUploadDropzone(props: FileUploadDropzoneProps):
|
|
51
|
+
declare function FileUploadDropzone(props: FileUploadDropzoneProps): react_jsx_runtime66.JSX.Element;
|
|
52
52
|
interface FileUploadTriggerProps extends React.ComponentProps<'button'> {
|
|
53
53
|
asChild?: boolean;
|
|
54
54
|
}
|
|
55
|
-
declare function FileUploadTrigger(props: FileUploadTriggerProps):
|
|
55
|
+
declare function FileUploadTrigger(props: FileUploadTriggerProps): react_jsx_runtime66.JSX.Element;
|
|
56
56
|
interface FileUploadListProps extends React.ComponentProps<'div'> {
|
|
57
57
|
orientation?: 'horizontal' | 'vertical';
|
|
58
58
|
asChild?: boolean;
|
|
59
59
|
forceMount?: boolean;
|
|
60
60
|
}
|
|
61
|
-
declare function FileUploadList(props: FileUploadListProps):
|
|
61
|
+
declare function FileUploadList(props: FileUploadListProps): react_jsx_runtime66.JSX.Element | null;
|
|
62
62
|
interface FileUploadItemProps extends React.ComponentProps<'div'> {
|
|
63
63
|
value: File;
|
|
64
64
|
asChild?: boolean;
|
|
65
65
|
}
|
|
66
|
-
declare function FileUploadItem(props: FileUploadItemProps):
|
|
66
|
+
declare function FileUploadItem(props: FileUploadItemProps): react_jsx_runtime66.JSX.Element | null;
|
|
67
67
|
interface FileUploadItemPreviewProps extends React.ComponentProps<'div'> {
|
|
68
68
|
render?: (file: File, fallback: () => React.ReactNode) => React.ReactNode;
|
|
69
69
|
asChild?: boolean;
|
|
70
70
|
}
|
|
71
|
-
declare function FileUploadItemPreview(props: FileUploadItemPreviewProps):
|
|
71
|
+
declare function FileUploadItemPreview(props: FileUploadItemPreviewProps): react_jsx_runtime66.JSX.Element | null;
|
|
72
72
|
interface FileUploadItemMetadataProps extends React.ComponentProps<'div'> {
|
|
73
73
|
asChild?: boolean;
|
|
74
74
|
size?: 'default' | 'sm';
|
|
75
75
|
}
|
|
76
|
-
declare function FileUploadItemMetadata(props: FileUploadItemMetadataProps):
|
|
76
|
+
declare function FileUploadItemMetadata(props: FileUploadItemMetadataProps): react_jsx_runtime66.JSX.Element | null;
|
|
77
77
|
interface FileUploadItemProgressProps extends React.ComponentProps<'div'> {
|
|
78
78
|
variant?: 'linear' | 'circular' | 'fill';
|
|
79
79
|
size?: number;
|
|
80
|
+
strokeWidth?: number;
|
|
80
81
|
asChild?: boolean;
|
|
81
82
|
forceMount?: boolean;
|
|
82
83
|
}
|
|
83
|
-
declare function FileUploadItemProgress(props: FileUploadItemProgressProps):
|
|
84
|
+
declare function FileUploadItemProgress(props: FileUploadItemProgressProps): react_jsx_runtime66.JSX.Element | null;
|
|
84
85
|
interface FileUploadItemDeleteProps extends React.ComponentProps<'button'> {
|
|
85
86
|
asChild?: boolean;
|
|
86
87
|
}
|
|
87
|
-
declare function FileUploadItemDelete(props: FileUploadItemDeleteProps):
|
|
88
|
+
declare function FileUploadItemDelete(props: FileUploadItemDeleteProps): react_jsx_runtime66.JSX.Element | null;
|
|
88
89
|
interface FileUploadClearProps extends React.ComponentProps<'button'> {
|
|
89
90
|
forceMount?: boolean;
|
|
90
91
|
asChild?: boolean;
|
|
91
92
|
}
|
|
92
|
-
declare function FileUploadClear(props: FileUploadClearProps):
|
|
93
|
+
declare function FileUploadClear(props: FileUploadClearProps): react_jsx_runtime66.JSX.Element | null;
|
|
93
94
|
//#endregion
|
|
94
95
|
export { FileUploadClear, FileUploadDropzone, FileUploadItem, FileUploadItemDelete, FileUploadItemMetadata, FileUploadItemPreview, FileUploadItemProgress, FileUploadList, FileUploadRoot, FileUploadRootProps, FileUploadTrigger, useStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{cn as e}from"../../lib/utils.js";import"../../lib/index.js";import*as t from"react";import{Fragment as n,jsx as r,jsxs as i}from"react/jsx-runtime";import{Slot as a}from"@radix-ui/react-slot";import{FileArchiveIcon as o,FileAudioIcon as s,FileCodeIcon as c,FileCogIcon as l,FileIcon as u,FileTextIcon as d,FileVideoIcon as f}from"lucide-react";import{useDirection as p}from"@radix-ui/react-direction";const m=`FileUpload`,h=`FileUploadDropzone`,g=`FileUploadItem`,_=`FileUploadItemPreview`,v=`FileUploadItemMetadata`,y=`FileUploadItemDelete`,b=`FileUploadClear`;function x(e){let n=t.useRef(null);return n.current===null&&(n.current=e()),n}function S(e,t,n,r,i){let a={files:t,dragOver:!1,invalid:r};function o(e,r){switch(r.type){case`ADD_FILES`:for(let e of r.files)t.set(e,{file:e,progress:0,status:`idle`});return i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_FILES`:{let n=new Set(r.files);for(let e of t.keys())n.has(e)||t.delete(e);for(let e of r.files)t.get(e)||t.set(e,{file:e,progress:0,status:`idle`});return{...e,files:t}}case`SET_PROGRESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:r.progress,status:`uploading`}),{...e,files:t}}case`SET_SUCCESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:100,status:`success`}),{...e,files:t}}case`SET_ERROR`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,error:r.error,status:`error`}),{...e,files:t}}case`REMOVE_FILE`:if(n){let e=n.get(r.file);e&&(URL.revokeObjectURL(e),n.delete(r.file))}return t.delete(r.file),i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_DRAG_OVER`:return{...e,dragOver:r.dragOver};case`SET_INVALID`:return{...e,invalid:r.invalid};case`CLEAR`:if(n)for(let e of t.keys()){let t=n.get(e);t&&(URL.revokeObjectURL(t),n.delete(e))}return t.clear(),i&&i([]),{...e,files:t,invalid:!1};default:return e}}function s(){return a}function c(t){a=o(a,t);for(let t of e)t()}function l(t){return e.add(t),()=>e.delete(t)}return{getState:s,dispatch:c,subscribe:l}}const C=t.createContext(null);function w(e){let n=t.use(C);if(!n)throw Error(`\`${e}\` must be used within \`${m}\``);return n}function T(e){let n=w(`useStore`),r=x(()=>null),i=t.useCallback(()=>{let t=n.getState(),i=r.current;if(i&&i.state===t)return i.value;let a=e(t);return r.current={value:a,state:t},a},[n,e,r]);return t.useSyncExternalStore(n.subscribe,i,i)}const E=t.createContext(null);function D(e){let n=t.use(E);if(!n)throw Error(`\`${e}\` must be used within \`${m}\``);return n}function O(n){let{value:o,defaultValue:s,onValueChange:c,onAccept:l,onFileAccept:u,onFileReject:d,onFilesReject:f,onFileValidate:m,onUpload:h,accept:g,maxFiles:_,maxSize:v,dir:y,label:b,name:w,asChild:T,disabled:D=!1,invalid:O=!1,multiple:k=!1,required:A=!1,children:j,className:M,...N}=n,P=t.useId(),F=t.useId(),I=t.useId(),L=t.useId(),R=p(y),z=x(()=>new Set).current,B=x(()=>new Map).current,V=x(()=>new WeakMap).current,H=t.useRef(null),U=o!==void 0,W=t.useMemo(()=>S(z,B,V,O,c),[z,B,O,c,V]),G=t.useMemo(()=>g?.split(`,`).map(e=>e.trim())??null,[g]),K=x(()=>{let e=0;return(t,n)=>{e||=requestAnimationFrame(()=>{e=0,W.dispatch({type:`SET_PROGRESS`,file:t,progress:Math.min(Math.max(0,n),100)})})}}).current;t.useEffect(()=>{U?W.dispatch({type:`SET_FILES`,files:o}):s&&s.length>0&&!W.getState().files.size&&W.dispatch({type:`SET_FILES`,files:s})},[o,s,U,W]),t.useEffect(()=>()=>{for(let e of B.keys()){let t=V.get(e);t&&URL.revokeObjectURL(t)}},[B,V]);let q=t.useCallback(async e=>{try{for(let t of e)W.dispatch({type:`SET_PROGRESS`,file:t,progress:0});if(h)await h(e,{onProgress:K,onSuccess:e=>{W.dispatch({type:`SET_SUCCESS`,file:e})},onError:(e,t)=>{W.dispatch({type:`SET_ERROR`,file:e,error:t.message??`Upload failed`})}});else for(let t of e)W.dispatch({type:`SET_SUCCESS`,file:t})}catch(t){let n=t instanceof Error?t.message:`Upload failed`;for(let t of e)W.dispatch({type:`SET_ERROR`,file:t,error:n})}},[W,h,K]),J=t.useCallback(e=>{if(D)return;let t=[...e],n=!1,r=[];if(_){let e=W.getState().files.size,i=Math.max(0,_-e);if(i<t.length){let e=t.slice(i);n=!0,t=t.slice(0,i);for(let t of e){let e=`Maximum ${_} files allowed`;if(m){let n=m(t);n&&(e=n)}d?.(t,e),r.push({file:t,message:e})}}}let i=[],a=[];for(let e of t){let t=!1,r=``;if(m){let i=m(e);if(i){r=i,d?.(e,r),t=!0,n=!0;continue}}if(G){let i=e.type,a=`.${e.name.split(`.`).pop()}`;G.some(e=>e===i||e===a||e.includes(`/*`)&&i.startsWith(e.replace(`/*`,`/`)))||(r=`File type not accepted`,d?.(e,r),t=!0,n=!0)}v&&e.size>v&&(r=`File too large`,d?.(e,r),t=!0,n=!0),t?a.push({file:e,message:r}):i.push(e)}if(r.push(...a),n&&(W.dispatch({type:`SET_INVALID`,invalid:n}),setTimeout(()=>{W.dispatch({type:`SET_INVALID`,invalid:!1})},2e3)),r.length>0&&f?.(r),i.length>0){W.dispatch({type:`ADD_FILES`,files:i}),U&&c&&c([...Array.from(W.getState().files.values()).map(e=>e.file)]),l&&l(i);for(let e of i)u?.(e);h&&requestAnimationFrame(()=>{q(i)})}},[W,U,c,l,u,h,q,_,m,d,f,G,v,D]),Y=t.useCallback(e=>{J(Array.from(e.target.files??[])),e.target.value=``},[J]),X=t.useMemo(()=>({dropzoneId:F,inputId:P,listId:I,labelId:L,dir:R,disabled:D,inputRef:H,urlCache:V}),[F,P,I,L,R,D,V]),Z=T?a:`div`;return r(C.Provider,{value:W,children:r(E.Provider,{value:X,children:i(Z,{"data-disabled":D?``:void 0,"data-slot":`file-upload`,dir:R,...N,className:e(`relative flex flex-col gap-2`,M),children:[j,r(`input`,{type:`file`,id:P,"aria-labelledby":L,"aria-describedby":F,ref:H,tabIndex:-1,accept:g,name:w,className:`sr-only`,disabled:D,multiple:k,required:A,onChange:Y}),r(`span`,{id:L,className:`sr-only`,children:b??`File upload`})]})})})}function k(n){let{asChild:i,className:o,onClick:s,onDragOver:c,onDragEnter:l,onDragLeave:u,onDrop:d,onPaste:f,onKeyDown:p,...m}=n,g=D(h),_=w(h),v=T(e=>e.dragOver),y=T(e=>e.invalid),b=t.useCallback(e=>{if(s?.(e),e.defaultPrevented)return;let{target:t}=e;t instanceof HTMLElement&&t.closest(`[data-slot="file-upload-trigger"]`)||g.inputRef.current?.click()},[g.inputRef,s]),x=t.useCallback(e=>{c?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,c]),S=t.useCallback(e=>{l?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,l]),C=t.useCallback(e=>{if(u?.(e),e.defaultPrevented)return;let{relatedTarget:t}=e;t&&t instanceof Node&&e.currentTarget.contains(t)||(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1}))},[_,u]),E=t.useCallback(e=>{if(d?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=Array.from(e.dataTransfer.files),n=g.inputRef.current;if(!n)return;let r=new DataTransfer;for(let e of t)r.items.add(e);n.files=r.files,n.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,d]),O=t.useCallback(e=>{if(f?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r?.kind===`file`){let e=r.getAsFile();e&&n.push(e)}}if(n.length===0)return;let r=g.inputRef.current;if(!r)return;let i=new DataTransfer;for(let e of n)i.items.add(e);r.files=i.files,r.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,f]),k=t.useCallback(e=>{p?.(e),!e.defaultPrevented&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g.inputRef.current?.click())},[g.inputRef,p]);return r(i?a:`div`,{role:`region`,id:g.dropzoneId,"aria-controls":`${g.inputId} ${g.listId}`,"aria-disabled":g.disabled,"aria-invalid":y,"data-disabled":g.disabled?``:void 0,"data-dragging":v?``:void 0,"data-invalid":y?``:void 0,"data-slot":`file-upload-dropzone`,dir:g.dir,tabIndex:g.disabled?void 0:0,...m,className:e(`relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20`,o),onClick:b,onDragEnter:S,onDragLeave:C,onDragOver:x,onDrop:E,onKeyDown:k,onPaste:O})}function A(e){let{asChild:n,onClick:i,...o}=e,s=D(`FileUploadTrigger`),c=t.useCallback(e=>{i?.(e),!e.defaultPrevented&&s.inputRef.current?.click()},[s.inputRef,i]);return r(n?a:`button`,{type:`button`,"aria-controls":s.inputId,"data-disabled":s.disabled?``:void 0,"data-slot":`file-upload-trigger`,...o,disabled:s.disabled,onClick:c})}function j(t){let{className:n,orientation:i=`vertical`,asChild:o,forceMount:s,...c}=t,l=D(`FileUploadList`),u=T(e=>e.files.size),d=s||u>0;return d?r(o?a:`div`,{role:`list`,id:l.listId,"aria-orientation":i,"data-orientation":i,"data-slot":`file-upload-list`,"data-state":d?`active`:`inactive`,dir:l.dir,...c,className:e(`data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out`,i===`horizontal`&&`flex-row overflow-x-auto p-1.5`,n)}):null}const M=t.createContext(null);function N(e){let n=t.use(M);if(!n)throw Error(`\`${e}\` must be used within \`${g}\``);return n}function P(n){let{value:o,asChild:s,className:c,...l}=n,u=t.useId(),d=`${u}-status`,f=`${u}-name`,p=`${u}-size`,m=`${u}-message`,h=D(g),_=T(e=>e.files.get(o)),v=T(e=>e.files.size),y=T(e=>Array.from(e.files.keys()).indexOf(o)+1),b=t.useMemo(()=>({id:u,fileState:_,nameId:f,sizeId:p,statusId:d,messageId:m}),[u,_,d,f,p,m]);if(!_)return null;let x=_.error?`Error: ${_.error}`:_.status===`uploading`?`Uploading: ${_.progress}% complete`:_.status===`success`?`Upload complete`:`Ready to upload`,S=s?a:`div`;return r(M.Provider,{value:b,children:i(S,{role:`listitem`,id:u,"aria-setsize":v,"aria-posinset":y,"aria-describedby":`${f} ${p} ${d} ${_.error?m:``}`,"aria-labelledby":f,"data-slot":`file-upload-item`,dir:h.dir,...l,className:e(`relative flex items-center rounded-md border p-3`,c),children:[n.children,r(`span`,{id:d,className:`sr-only`,children:x})]})})}function F(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n?1:0)} ${t[n]}`}function I(e){let{type:t}=e,n=e.name.split(`.`).pop()?.toLowerCase()??``;return t.startsWith(`video/`)?r(f,{}):t.startsWith(`audio/`)?r(s,{}):t.startsWith(`text/`)||[`txt`,`md`,`rtf`,`pdf`].includes(n)?r(d,{}):[`html`,`css`,`js`,`jsx`,`ts`,`tsx`,`json`,`xml`,`php`,`py`,`rb`,`java`,`c`,`cpp`,`cs`].includes(n)?r(c,{}):[`zip`,`rar`,`7z`,`tar`,`gz`,`bz2`].includes(n)?r(o,{}):[`exe`,`msi`,`app`,`apk`,`deb`,`rpm`].includes(n)||t.startsWith(`application/`)?r(l,{}):r(u,{})}function L(n){let{render:o,asChild:s,children:c,className:l,...u}=n,d=N(_),f=D(_),p=t.useCallback(e=>{if(d.fileState?.file.type.startsWith(`image/`)){let t=f.urlCache.get(e);return t||(t=URL.createObjectURL(e),f.urlCache.set(e,t)),r(`img`,{src:t,alt:e.name,className:`size-full object-cover`})}return I(e)},[d.fileState?.file.type,f.urlCache]),m=t.useCallback(async e=>o?o(e,()=>p(e)):p(e),[o,p]);return d.fileState?i(s?a:`div`,{"aria-labelledby":d.nameId,"data-slot":`file-upload-preview`,...u,className:e(`relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10`,l),children:[m(d.fileState.file),c]}):null}function R(t){let{asChild:o,size:s=`default`,children:c,className:l,...u}=t,d=D(v),f=N(v);return f.fileState?r(o?a:`div`,{"data-slot":`file-upload-metadata`,dir:d.dir,...u,className:e(`flex min-w-0 flex-1 flex-col`,l),children:c??i(n,{children:[r(`span`,{id:f.nameId,className:e(`truncate font-medium text-sm`,s===`sm`&&`font-normal text-[13px] leading-snug`),children:f.fileState.file.name}),r(`span`,{id:f.sizeId,className:e(`truncate text-muted-foreground text-xs`,s===`sm`&&`text-[11px] leading-snug`),children:F(f.fileState.file.size)}),f.fileState.error&&r(`span`,{id:f.messageId,className:`text-destructive text-xs`,children:f.fileState.error})]})}):null}function z(t){let{variant:n=`linear`,size:o=40,asChild:s,forceMount:c,className:l,...u}=t,d=N(`FileUploadItemProgress`);if(!d.fileState||!(c||d.fileState.progress!==100))return null;let f=s?a:`div`;switch(n){case`circular`:{let t=2*Math.PI*((o-4)/2),n=t-d.fileState.progress/100*t;return r(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:e(`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2`,l),children:i(`svg`,{className:`-rotate-90 transform`,width:o,height:o,viewBox:`0 0 ${o} ${o}`,fill:`none`,stroke:`currentColor`,children:[r(`circle`,{className:`text-primary/20`,strokeWidth:`2`,cx:o/2,cy:o/2,r:(o-4)/2}),r(`circle`,{className:`text-primary transition-[stroke-dashoffset] duration-300 ease-linear`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:t,strokeDashoffset:n,cx:o/2,cy:o/2,r:(o-4)/2})]})})}case`fill`:{let t=d.fileState.progress,n=100-t;return r(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t,"aria-valuetext":`${t}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:e(`absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear`,l),style:{clipPath:`inset(${n}% 0% 0% 0%)`}})}default:return r(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:e(`relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20`,l),children:r(`div`,{className:`h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear`,style:{transform:`translateX(-${100-d.fileState.progress}%)`}})})}}function B(e){let{asChild:n,onClick:i,...o}=e,s=w(y),c=N(y),l=t.useCallback(e=>{i?.(e),!(!c.fileState||e.defaultPrevented)&&s.dispatch({type:`REMOVE_FILE`,file:c.fileState.file})},[s,c.fileState,i]);return c.fileState?r(n?a:`button`,{type:`button`,"aria-controls":c.id,"aria-describedby":c.nameId,"data-slot":`file-upload-item-delete`,...o,onClick:l}):null}function V(e){let{asChild:n,forceMount:i,disabled:o,onClick:s,...c}=e,l=D(b),u=w(b),d=T(e=>e.files.size),f=o||l.disabled,p=t.useCallback(e=>{s?.(e),!e.defaultPrevented&&u.dispatch({type:`CLEAR`})},[u,s]);return i||d>0?r(n?a:`button`,{type:`button`,"aria-controls":l.listId,"data-slot":`file-upload-clear`,"data-disabled":f?``:void 0,...c,disabled:f,onClick:p}):null}export{V as FileUploadClear,k as FileUploadDropzone,P as FileUploadItem,B as FileUploadItemDelete,R as FileUploadItemMetadata,L as FileUploadItemPreview,z as FileUploadItemProgress,j as FileUploadList,O as FileUploadRoot,A as FileUploadTrigger,T as useStore};
|
|
1
|
+
"use client";import{cn as e}from"../../lib/utils.js";import"../../lib/index.js";import*as t from"react";import{Fragment as n,jsx as r,jsxs as i}from"react/jsx-runtime";import{Slot as a}from"@radix-ui/react-slot";import{FileArchiveIcon as o,FileAudioIcon as s,FileCodeIcon as c,FileCogIcon as l,FileIcon as u,FileTextIcon as d,FileVideoIcon as f}from"lucide-react";import{useDirection as p}from"@radix-ui/react-direction";const m=`FileUpload`,h=`FileUploadDropzone`,g=`FileUploadItem`,_=`FileUploadItemPreview`,v=`FileUploadItemMetadata`,y=`FileUploadItemDelete`,b=`FileUploadClear`;function x(e){let n=t.useRef(null);return n.current===null&&(n.current=e()),n}function S(e,t,n,r,i){let a={files:t,dragOver:!1,invalid:r};function o(e,r){switch(r.type){case`ADD_FILES`:for(let e of r.files)t.set(e,{file:e,progress:0,status:`idle`});return i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_FILES`:{let n=new Set(r.files);for(let e of t.keys())n.has(e)||t.delete(e);for(let e of r.files)t.get(e)||t.set(e,{file:e,progress:0,status:`idle`});return{...e,files:t}}case`SET_PROGRESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:r.progress,status:`uploading`}),{...e,files:t}}case`SET_SUCCESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:100,status:`success`}),{...e,files:t}}case`SET_ERROR`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,error:r.error,status:`error`}),{...e,files:t}}case`REMOVE_FILE`:if(n){let e=n.get(r.file);e&&(URL.revokeObjectURL(e),n.delete(r.file))}return t.delete(r.file),i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_DRAG_OVER`:return{...e,dragOver:r.dragOver};case`SET_INVALID`:return{...e,invalid:r.invalid};case`CLEAR`:if(n)for(let e of t.keys()){let t=n.get(e);t&&(URL.revokeObjectURL(t),n.delete(e))}return t.clear(),i&&i([]),{...e,files:t,invalid:!1};default:return e}}function s(){return a}function c(t){a=o(a,t);for(let t of e)t()}function l(t){return e.add(t),()=>e.delete(t)}return{getState:s,dispatch:c,subscribe:l}}const C=t.createContext(null);function w(e){let n=t.use(C);if(!n)throw Error(`\`${e}\` must be used within \`${m}\``);return n}function T(e){let n=w(`useStore`),r=x(()=>null),i=t.useCallback(()=>{let t=n.getState(),i=r.current;if(i&&i.state===t)return i.value;let a=e(t);return r.current={value:a,state:t},a},[n,e,r]);return t.useSyncExternalStore(n.subscribe,i,i)}const E=t.createContext(null);function D(e){let n=t.use(E);if(!n)throw Error(`\`${e}\` must be used within \`${m}\``);return n}function O(n){let{value:o,defaultValue:s,onValueChange:c,onAccept:l,onFileAccept:u,onFileReject:d,onFilesReject:f,onFileValidate:m,onUpload:h,accept:g,maxFiles:_,maxSize:v,dir:y,label:b,name:w,asChild:T,disabled:D=!1,invalid:O=!1,multiple:k=!1,required:A=!1,children:j,className:M,...N}=n,P=t.useId(),F=t.useId(),I=t.useId(),L=t.useId(),R=p(y),z=x(()=>new Set).current,B=x(()=>new Map).current,V=x(()=>new WeakMap).current,H=t.useRef(null),U=o!==void 0,W=t.useMemo(()=>S(z,B,V,O,c),[z,B,O,c,V]),G=t.useMemo(()=>g?.split(`,`).map(e=>e.trim())??null,[g]),K=x(()=>{let e=0;return(t,n)=>{e||=requestAnimationFrame(()=>{e=0,W.dispatch({type:`SET_PROGRESS`,file:t,progress:Math.min(Math.max(0,n),100)})})}}).current;t.useEffect(()=>{U?W.dispatch({type:`SET_FILES`,files:o}):s&&s.length>0&&!W.getState().files.size&&W.dispatch({type:`SET_FILES`,files:s})},[o,s,U,W]),t.useEffect(()=>()=>{for(let e of B.keys()){let t=V.get(e);t&&URL.revokeObjectURL(t)}},[B,V]);let q=t.useCallback(async e=>{try{for(let t of e)W.dispatch({type:`SET_PROGRESS`,file:t,progress:0});if(h)await h(e,{onProgress:K,onSuccess:e=>{W.dispatch({type:`SET_SUCCESS`,file:e})},onError:(e,t)=>{W.dispatch({type:`SET_ERROR`,file:e,error:t.message??`Upload failed`})}});else for(let t of e)W.dispatch({type:`SET_SUCCESS`,file:t})}catch(t){let n=t instanceof Error?t.message:`Upload failed`;for(let t of e)W.dispatch({type:`SET_ERROR`,file:t,error:n})}},[W,h,K]),J=t.useCallback(e=>{if(D)return;let t=[...e],n=!1,r=[];if(_){let e=W.getState().files.size,i=Math.max(0,_-e);if(i<t.length){let e=t.slice(i);n=!0,t=t.slice(0,i);for(let t of e){let e=`Maximum ${_} files allowed`;if(m){let n=m(t);n&&(e=n)}d?.(t,e),r.push({file:t,message:e})}}}let i=[],a=[];for(let e of t){let t=!1,r=``;if(m){let i=m(e);if(i){r=i,d?.(e,r),t=!0,n=!0;continue}}if(G){let i=e.type,a=`.${e.name.split(`.`).pop()}`;G.some(e=>e===i||e===a||e.includes(`/*`)&&i.startsWith(e.replace(`/*`,`/`)))||(r=`File type not accepted`,d?.(e,r),t=!0,n=!0)}v&&e.size>v&&(r=`File too large`,d?.(e,r),t=!0,n=!0),t?a.push({file:e,message:r}):i.push(e)}if(r.push(...a),n&&(W.dispatch({type:`SET_INVALID`,invalid:n}),setTimeout(()=>{W.dispatch({type:`SET_INVALID`,invalid:!1})},2e3)),r.length>0&&f?.(r),i.length>0){W.dispatch({type:`ADD_FILES`,files:i}),U&&c&&c([...Array.from(W.getState().files.values()).map(e=>e.file)]),l&&l(i);for(let e of i)u?.(e);h&&requestAnimationFrame(()=>{q(i)})}},[W,U,c,l,u,h,q,_,m,d,f,G,v,D]),Y=t.useCallback(e=>{J(Array.from(e.target.files??[])),e.target.value=``},[J]),X=t.useMemo(()=>({dropzoneId:F,inputId:P,listId:I,labelId:L,dir:R,disabled:D,inputRef:H,urlCache:V}),[F,P,I,L,R,D,V]),Z=T?a:`div`;return r(C.Provider,{value:W,children:r(E.Provider,{value:X,children:i(Z,{"data-disabled":D?``:void 0,"data-slot":`file-upload`,dir:R,...N,className:e(`relative flex flex-col gap-2`,M),children:[j,r(`input`,{type:`file`,id:P,"aria-labelledby":L,"aria-describedby":F,ref:H,tabIndex:-1,accept:g,name:w,className:`sr-only`,disabled:D,multiple:k,required:A,onChange:Y}),r(`span`,{id:L,className:`sr-only`,children:b??`File upload`})]})})})}function k(n){let{asChild:i,className:o,onClick:s,onDragOver:c,onDragEnter:l,onDragLeave:u,onDrop:d,onPaste:f,onKeyDown:p,...m}=n,g=D(h),_=w(h),v=T(e=>e.dragOver),y=T(e=>e.invalid),b=t.useCallback(e=>{if(s?.(e),e.defaultPrevented)return;let{target:t}=e;t instanceof HTMLElement&&t.closest(`[data-slot="file-upload-trigger"]`)||g.inputRef.current?.click()},[g.inputRef,s]),x=t.useCallback(e=>{c?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,c]),S=t.useCallback(e=>{l?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,l]),C=t.useCallback(e=>{if(u?.(e),e.defaultPrevented)return;let{relatedTarget:t}=e;t&&t instanceof Node&&e.currentTarget.contains(t)||(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1}))},[_,u]),E=t.useCallback(e=>{if(d?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=Array.from(e.dataTransfer.files),n=g.inputRef.current;if(!n)return;let r=new DataTransfer;for(let e of t)r.items.add(e);n.files=r.files,n.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,d]),O=t.useCallback(e=>{if(f?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r?.kind===`file`){let e=r.getAsFile();e&&n.push(e)}}if(n.length===0)return;let r=g.inputRef.current;if(!r)return;let i=new DataTransfer;for(let e of n)i.items.add(e);r.files=i.files,r.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,f]),k=t.useCallback(e=>{p?.(e),!e.defaultPrevented&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g.inputRef.current?.click())},[g.inputRef,p]);return r(i?a:`div`,{role:`region`,id:g.dropzoneId,"aria-controls":`${g.inputId} ${g.listId}`,"aria-disabled":g.disabled,"aria-invalid":y,"data-disabled":g.disabled?``:void 0,"data-dragging":v?``:void 0,"data-invalid":y?``:void 0,"data-slot":`file-upload-dropzone`,dir:g.dir,tabIndex:g.disabled?void 0:0,...m,className:e(`relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20`,o),onClick:b,onDragEnter:S,onDragLeave:C,onDragOver:x,onDrop:E,onKeyDown:k,onPaste:O})}function A(e){let{asChild:n,onClick:i,...o}=e,s=D(`FileUploadTrigger`),c=t.useCallback(e=>{i?.(e),!e.defaultPrevented&&s.inputRef.current?.click()},[s.inputRef,i]);return r(n?a:`button`,{type:`button`,"aria-controls":s.inputId,"data-disabled":s.disabled?``:void 0,"data-slot":`file-upload-trigger`,...o,disabled:s.disabled,onClick:c})}function j(t){let{className:n,orientation:i=`vertical`,asChild:o,forceMount:s,...c}=t,l=D(`FileUploadList`),u=T(e=>e.files.size),d=s||u>0;return d?r(o?a:`div`,{role:`list`,id:l.listId,"aria-orientation":i,"data-orientation":i,"data-slot":`file-upload-list`,"data-state":d?`active`:`inactive`,dir:l.dir,...c,className:e(`data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out`,i===`horizontal`&&`flex-row overflow-x-auto p-1.5`,n)}):null}const M=t.createContext(null);function N(e){let n=t.use(M);if(!n)throw Error(`\`${e}\` must be used within \`${g}\``);return n}function P(n){let{value:o,asChild:s,className:c,...l}=n,u=t.useId(),d=`${u}-status`,f=`${u}-name`,p=`${u}-size`,m=`${u}-message`,h=D(g),_=T(e=>e.files.get(o)),v=T(e=>e.files.size),y=T(e=>Array.from(e.files.keys()).indexOf(o)+1),b=t.useMemo(()=>({id:u,fileState:_,nameId:f,sizeId:p,statusId:d,messageId:m}),[u,_,d,f,p,m]);if(!_)return null;let x=_.error?`Error: ${_.error}`:_.status===`uploading`?`Uploading: ${_.progress}% complete`:_.status===`success`?`Upload complete`:`Ready to upload`,S=s?a:`div`;return r(M.Provider,{value:b,children:i(S,{role:`listitem`,id:u,"aria-setsize":v,"aria-posinset":y,"aria-describedby":`${f} ${p} ${d} ${_.error?m:``}`,"aria-labelledby":f,"data-slot":`file-upload-item`,dir:h.dir,...l,className:e(`relative flex items-center rounded-md border p-3`,c),children:[n.children,r(`span`,{id:d,className:`sr-only`,children:x})]})})}function F(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n?1:0)} ${t[n]}`}function I(e){let{type:t}=e,n=e.name.split(`.`).pop()?.toLowerCase()??``;return t.startsWith(`video/`)?r(f,{}):t.startsWith(`audio/`)?r(s,{}):t.startsWith(`text/`)||[`txt`,`md`,`rtf`,`pdf`].includes(n)?r(d,{}):[`html`,`css`,`js`,`jsx`,`ts`,`tsx`,`json`,`xml`,`php`,`py`,`rb`,`java`,`c`,`cpp`,`cs`].includes(n)?r(c,{}):[`zip`,`rar`,`7z`,`tar`,`gz`,`bz2`].includes(n)?r(o,{}):[`exe`,`msi`,`app`,`apk`,`deb`,`rpm`].includes(n)||t.startsWith(`application/`)?r(l,{}):r(u,{})}function L(n){let{render:o,asChild:s,children:c,className:l,...u}=n,d=N(_),f=D(_),p=t.useCallback(e=>{if(d.fileState?.file.type.startsWith(`image/`)){let t=f.urlCache.get(e);return t||(t=URL.createObjectURL(e),f.urlCache.set(e,t)),r(`img`,{src:t,alt:e.name,className:`size-full object-cover`})}return I(e)},[d.fileState?.file.type,f.urlCache]),m=t.useCallback(e=>o?o(e,()=>p(e)):p(e),[o,p]);return d.fileState?i(s?a:`div`,{"aria-labelledby":d.nameId,"data-slot":`file-upload-preview`,...u,className:e(`relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10`,l),children:[m(d.fileState.file),c]}):null}function R(t){let{asChild:o,size:s=`default`,children:c,className:l,...u}=t,d=D(v),f=N(v);return f.fileState?r(o?a:`div`,{"data-slot":`file-upload-metadata`,dir:d.dir,...u,className:e(`flex min-w-0 flex-1 flex-col`,l),children:c??i(n,{children:[r(`span`,{id:f.nameId,className:e(`truncate font-medium text-sm`,s===`sm`&&`font-normal text-[13px] leading-snug`),children:f.fileState.file.name}),r(`span`,{id:f.sizeId,className:e(`truncate text-muted-foreground text-xs`,s===`sm`&&`text-[11px] leading-snug`),children:F(f.fileState.file.size)}),f.fileState.error&&r(`span`,{id:f.messageId,className:`text-destructive text-xs`,children:f.fileState.error})]})}):null}function z(t){let{variant:n=`linear`,size:o=40,strokeWidth:s=2,asChild:c,forceMount:l,className:u,...d}=t,f=N(`FileUploadItemProgress`);if(!f.fileState||!(l||f.fileState.progress!==100))return null;let p=c?a:`div`;switch(n){case`circular`:{let t=2*Math.PI*((o-4)/2),n=t-f.fileState.progress/100*t;return r(p,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":f.fileState.progress,"aria-valuetext":`${f.fileState.progress}%`,"aria-labelledby":f.nameId,"data-slot":`file-upload-progress`,...d,className:e(`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2`,u),children:i(`svg`,{className:`-rotate-90 transform`,width:o,height:o,viewBox:`0 0 ${o} ${o}`,fill:`none`,stroke:`currentColor`,children:[r(`circle`,{className:`text-primary/20`,strokeWidth:s,cx:o/2,cy:o/2,r:(o-4)/2}),r(`circle`,{className:`text-primary transition-[stroke-dashoffset] duration-300 ease-linear`,strokeWidth:s,strokeLinecap:`round`,strokeDasharray:t,strokeDashoffset:n,cx:o/2,cy:o/2,r:(o-4)/2})]})})}case`fill`:{let t=f.fileState.progress,n=100-t;return r(p,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t,"aria-valuetext":`${t}%`,"aria-labelledby":f.nameId,"data-slot":`file-upload-progress`,...d,className:e(`absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear`,u),style:{clipPath:`inset(${n}% 0% 0% 0%)`}})}default:return r(p,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":f.fileState.progress,"aria-valuetext":`${f.fileState.progress}%`,"aria-labelledby":f.nameId,"data-slot":`file-upload-progress`,...d,className:e(`relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20`,u),children:r(`div`,{className:`h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear`,style:{transform:`translateX(-${100-f.fileState.progress}%)`}})})}}function B(e){let{asChild:n,onClick:i,...o}=e,s=w(y),c=N(y),l=t.useCallback(e=>{i?.(e),!(!c.fileState||e.defaultPrevented)&&s.dispatch({type:`REMOVE_FILE`,file:c.fileState.file})},[s,c.fileState,i]);return c.fileState?r(n?a:`button`,{type:`button`,"aria-controls":c.id,"aria-describedby":c.nameId,"data-slot":`file-upload-item-delete`,...o,onClick:l}):null}function V(e){let{asChild:n,forceMount:i,disabled:o,onClick:s,...c}=e,l=D(b),u=w(b),d=T(e=>e.files.size),f=o||l.disabled,p=t.useCallback(e=>{s?.(e),!e.defaultPrevented&&u.dispatch({type:`CLEAR`})},[u,s]);return i||d>0?r(n?a:`button`,{type:`button`,"aria-controls":l.listId,"data-slot":`file-upload-clear`,"data-disabled":f?``:void 0,...c,disabled:f,onClick:p}):null}export{V as FileUploadClear,k as FileUploadDropzone,P as FileUploadItem,B as FileUploadItemDelete,R as FileUploadItemMetadata,L as FileUploadItemPreview,z as FileUploadItemProgress,j as FileUploadList,O as FileUploadRoot,A as FileUploadTrigger,T as useStore};
|