@tscircuit/cli 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.prettierrc +1 -0
  2. package/README.md +50 -0
  3. package/build-cli.ts +14 -0
  4. package/bun.lockb +0 -0
  5. package/cli.ts +12 -0
  6. package/dev-server-api/README.md +3 -0
  7. package/dev-server-api/bun.lockb +0 -0
  8. package/dev-server-api/edgespec.config.ts +4 -0
  9. package/dev-server-api/index.ts +1 -0
  10. package/dev-server-api/package-lock.json +1201 -0
  11. package/dev-server-api/package.json +24 -0
  12. package/dev-server-api/routes/api/dev_package_examples/create.ts +43 -0
  13. package/dev-server-api/routes/api/dev_package_examples/get.ts +37 -0
  14. package/dev-server-api/routes/api/dev_package_examples/list.ts +29 -0
  15. package/dev-server-api/routes/api/dev_package_examples/update.ts +31 -0
  16. package/dev-server-api/routes/api/health.ts +11 -0
  17. package/dev-server-api/src/db/create-schema.ts +14 -0
  18. package/dev-server-api/src/db/get-db.ts +78 -0
  19. package/dev-server-api/src/middlewares/with-db.ts +14 -0
  20. package/dev-server-api/src/middlewares/with-error-response.ts +24 -0
  21. package/dev-server-api/src/with-edge-spec.ts +8 -0
  22. package/dev-server-api/tsconfig.json +28 -0
  23. package/dev-server-frontend/.eslintrc.cjs +20 -0
  24. package/dev-server-frontend/README.md +3 -0
  25. package/dev-server-frontend/bun.lockb +0 -0
  26. package/dev-server-frontend/components.json +17 -0
  27. package/dev-server-frontend/index.html +13 -0
  28. package/dev-server-frontend/package.json +62 -0
  29. package/dev-server-frontend/postcss.config.js +6 -0
  30. package/dev-server-frontend/src/App.tsx +22 -0
  31. package/dev-server-frontend/src/ExampleContentView.tsx +60 -0
  32. package/dev-server-frontend/src/Header.tsx +53 -0
  33. package/dev-server-frontend/src/HeaderMenu.tsx +188 -0
  34. package/dev-server-frontend/src/components/command-k.tsx +62 -0
  35. package/dev-server-frontend/src/components/global-context-providers.tsx +11 -0
  36. package/dev-server-frontend/src/components/select-example-search.tsx +137 -0
  37. package/dev-server-frontend/src/components/ui/alert-dialog.tsx +139 -0
  38. package/dev-server-frontend/src/components/ui/alert.tsx +59 -0
  39. package/dev-server-frontend/src/components/ui/breadcrumb.tsx +115 -0
  40. package/dev-server-frontend/src/components/ui/button.tsx +57 -0
  41. package/dev-server-frontend/src/components/ui/card.tsx +76 -0
  42. package/dev-server-frontend/src/components/ui/command.tsx +153 -0
  43. package/dev-server-frontend/src/components/ui/context-menu.tsx +202 -0
  44. package/dev-server-frontend/src/components/ui/dialog.tsx +120 -0
  45. package/dev-server-frontend/src/components/ui/menubar.tsx +238 -0
  46. package/dev-server-frontend/src/components/ui/navigation-menu.tsx +128 -0
  47. package/dev-server-frontend/src/components/ui/popover.tsx +31 -0
  48. package/dev-server-frontend/src/components/ui/select.tsx +162 -0
  49. package/dev-server-frontend/src/components/ui/tabs.tsx +53 -0
  50. package/dev-server-frontend/src/components/ui/toggle-group.tsx +59 -0
  51. package/dev-server-frontend/src/components/ui/toggle.tsx +43 -0
  52. package/dev-server-frontend/src/components/ui/tooltip.tsx +28 -0
  53. package/dev-server-frontend/src/hooks/toast-if-api-not-connected.ts +23 -0
  54. package/dev-server-frontend/src/hooks/use-global-store.ts +42 -0
  55. package/dev-server-frontend/src/index.css +76 -0
  56. package/dev-server-frontend/src/lib/utils.ts +6 -0
  57. package/dev-server-frontend/src/main.tsx +13 -0
  58. package/dev-server-frontend/src/vite-env.d.ts +1 -0
  59. package/dev-server-frontend/tailwind.config.js +77 -0
  60. package/dev-server-frontend/tsconfig.json +26 -0
  61. package/dev-server-frontend/tsconfig.node.json +13 -0
  62. package/dev-server-frontend/vite.config.ts +23 -0
  63. package/dist/cli.js +1326 -0
  64. package/lib/cmd-fns/auth-login.ts +59 -0
  65. package/lib/cmd-fns/auth-logout.ts +3 -0
  66. package/lib/cmd-fns/auth-sessions-create.ts +3 -0
  67. package/lib/cmd-fns/auth-sessions-get.ts +3 -0
  68. package/lib/cmd-fns/auth-sessions-list.ts +5 -0
  69. package/lib/cmd-fns/config-print-config.ts +6 -0
  70. package/lib/cmd-fns/config-reveal-location.ts +5 -0
  71. package/lib/cmd-fns/config-set-log-requests.ts +7 -0
  72. package/lib/cmd-fns/config-set-registry.ts +7 -0
  73. package/lib/cmd-fns/config-set-session.ts +7 -0
  74. package/lib/cmd-fns/dev.ts +217 -0
  75. package/lib/cmd-fns/index.ts +27 -0
  76. package/lib/cmd-fns/package-examples-create.ts +33 -0
  77. package/lib/cmd-fns/package-examples-get.ts +20 -0
  78. package/lib/cmd-fns/package-examples-list.ts +18 -0
  79. package/lib/cmd-fns/package-files-create.ts +31 -0
  80. package/lib/cmd-fns/package-files-download.ts +29 -0
  81. package/lib/cmd-fns/package-files-get.ts +3 -0
  82. package/lib/cmd-fns/package-files-list.ts +28 -0
  83. package/lib/cmd-fns/package-files-upload-directory.ts +6 -0
  84. package/lib/cmd-fns/package-releases-create.ts +35 -0
  85. package/lib/cmd-fns/package-releases-get.ts +3 -0
  86. package/lib/cmd-fns/package-releases-list.ts +32 -0
  87. package/lib/cmd-fns/packages-create.ts +16 -0
  88. package/lib/cmd-fns/packages-get.ts +16 -0
  89. package/lib/cmd-fns/packages-list.ts +16 -0
  90. package/lib/cmd-fns/publish.ts +3 -0
  91. package/lib/cmd-fns/soupify.ts +27 -0
  92. package/lib/get-program.ts +191 -0
  93. package/lib/param-handlers/index.ts +16 -0
  94. package/lib/param-handlers/interact-for-local-directory.ts +58 -0
  95. package/lib/param-handlers/interact-for-local-file.ts +59 -0
  96. package/lib/param-handlers/interact-for-package-example-id.ts +25 -0
  97. package/lib/param-handlers/interact-for-package-name-with-version.ts +63 -0
  98. package/lib/param-handlers/interact-for-package-name.ts +45 -0
  99. package/lib/param-handlers/interact-for-package-release-id.ts +16 -0
  100. package/lib/param-handlers/param-handler-type.ts +7 -0
  101. package/lib/soupify.ts +71 -0
  102. package/lib/util/app-context.ts +14 -0
  103. package/lib/util/create-context-and-run-program.ts +116 -0
  104. package/package.json +62 -0
  105. package/tests/assets/example-project/examples/basic-capacitor.tsx +1 -0
  106. package/tests/assets/example-project/examples/basic-resistor.tsx +3 -0
  107. package/tests/assets/example-project/package.json +8 -0
  108. package/tests/assets/example-project/src/MyCircuit.tsx +3 -0
  109. package/tests/soupify.test.ts +9 -0
  110. package/tsconfig.json +109 -0
@@ -0,0 +1,115 @@
1
+ import * as React from "react"
2
+ import { ChevronRightIcon, DotsHorizontalIcon } from "@radix-ui/react-icons"
3
+ import { Slot } from "@radix-ui/react-slot"
4
+
5
+ import { cn } from "src/lib/utils"
6
+
7
+ const Breadcrumb = React.forwardRef<
8
+ HTMLElement,
9
+ React.ComponentPropsWithoutRef<"nav"> & {
10
+ separator?: React.ReactNode
11
+ }
12
+ >(({ ...props }, ref) => <nav ref={ref} aria-label="breadcrumb" {...props} />)
13
+ Breadcrumb.displayName = "Breadcrumb"
14
+
15
+ const BreadcrumbList = React.forwardRef<
16
+ HTMLOListElement,
17
+ React.ComponentPropsWithoutRef<"ol">
18
+ >(({ className, ...props }, ref) => (
19
+ <ol
20
+ ref={ref}
21
+ className={cn(
22
+ "flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",
23
+ className
24
+ )}
25
+ {...props}
26
+ />
27
+ ))
28
+ BreadcrumbList.displayName = "BreadcrumbList"
29
+
30
+ const BreadcrumbItem = React.forwardRef<
31
+ HTMLLIElement,
32
+ React.ComponentPropsWithoutRef<"li">
33
+ >(({ className, ...props }, ref) => (
34
+ <li
35
+ ref={ref}
36
+ className={cn("inline-flex items-center gap-1.5", className)}
37
+ {...props}
38
+ />
39
+ ))
40
+ BreadcrumbItem.displayName = "BreadcrumbItem"
41
+
42
+ const BreadcrumbLink = React.forwardRef<
43
+ HTMLAnchorElement,
44
+ React.ComponentPropsWithoutRef<"a"> & {
45
+ asChild?: boolean
46
+ }
47
+ >(({ asChild, className, ...props }, ref) => {
48
+ const Comp = asChild ? Slot : "a"
49
+
50
+ return (
51
+ <Comp
52
+ ref={ref}
53
+ className={cn("transition-colors hover:text-foreground", className)}
54
+ {...props}
55
+ />
56
+ )
57
+ })
58
+ BreadcrumbLink.displayName = "BreadcrumbLink"
59
+
60
+ const BreadcrumbPage = React.forwardRef<
61
+ HTMLSpanElement,
62
+ React.ComponentPropsWithoutRef<"span">
63
+ >(({ className, ...props }, ref) => (
64
+ <span
65
+ ref={ref}
66
+ role="link"
67
+ aria-disabled="true"
68
+ aria-current="page"
69
+ className={cn("font-normal text-foreground", className)}
70
+ {...props}
71
+ />
72
+ ))
73
+ BreadcrumbPage.displayName = "BreadcrumbPage"
74
+
75
+ const BreadcrumbSeparator = ({
76
+ children,
77
+ className,
78
+ ...props
79
+ }: React.ComponentProps<"li">) => (
80
+ <li
81
+ role="presentation"
82
+ aria-hidden="true"
83
+ className={cn("[&>svg]:size-3.5", className)}
84
+ {...props}
85
+ >
86
+ {children ?? <ChevronRightIcon />}
87
+ </li>
88
+ )
89
+ BreadcrumbSeparator.displayName = "BreadcrumbSeparator"
90
+
91
+ const BreadcrumbEllipsis = ({
92
+ className,
93
+ ...props
94
+ }: React.ComponentProps<"span">) => (
95
+ <span
96
+ role="presentation"
97
+ aria-hidden="true"
98
+ className={cn("flex h-9 w-9 items-center justify-center", className)}
99
+ {...props}
100
+ >
101
+ <DotsHorizontalIcon className="h-4 w-4" />
102
+ <span className="sr-only">More</span>
103
+ </span>
104
+ )
105
+ BreadcrumbEllipsis.displayName = "BreadcrumbElipssis"
106
+
107
+ export {
108
+ Breadcrumb,
109
+ BreadcrumbList,
110
+ BreadcrumbItem,
111
+ BreadcrumbLink,
112
+ BreadcrumbPage,
113
+ BreadcrumbSeparator,
114
+ BreadcrumbEllipsis,
115
+ }
@@ -0,0 +1,57 @@
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "src/lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default:
13
+ "bg-primary text-primary-foreground shadow hover:bg-primary/90",
14
+ destructive:
15
+ "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
16
+ outline:
17
+ "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
18
+ secondary:
19
+ "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
20
+ ghost: "hover:bg-accent hover:text-accent-foreground",
21
+ link: "text-primary underline-offset-4 hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-9 px-4 py-2",
25
+ sm: "h-8 rounded-md px-3 text-xs",
26
+ lg: "h-10 rounded-md px-8",
27
+ icon: "h-9 w-9",
28
+ },
29
+ },
30
+ defaultVariants: {
31
+ variant: "default",
32
+ size: "default",
33
+ },
34
+ }
35
+ )
36
+
37
+ export interface ButtonProps
38
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
39
+ VariantProps<typeof buttonVariants> {
40
+ asChild?: boolean
41
+ }
42
+
43
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
44
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
45
+ const Comp = asChild ? Slot : "button"
46
+ return (
47
+ <Comp
48
+ className={cn(buttonVariants({ variant, size, className }))}
49
+ ref={ref}
50
+ {...props}
51
+ />
52
+ )
53
+ }
54
+ )
55
+ Button.displayName = "Button"
56
+
57
+ export { Button, buttonVariants }
@@ -0,0 +1,76 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "src/lib/utils"
4
+
5
+ const Card = React.forwardRef<
6
+ HTMLDivElement,
7
+ React.HTMLAttributes<HTMLDivElement>
8
+ >(({ className, ...props }, ref) => (
9
+ <div
10
+ ref={ref}
11
+ className={cn(
12
+ "rounded-xl border bg-card text-card-foreground shadow",
13
+ className
14
+ )}
15
+ {...props}
16
+ />
17
+ ))
18
+ Card.displayName = "Card"
19
+
20
+ const CardHeader = React.forwardRef<
21
+ HTMLDivElement,
22
+ React.HTMLAttributes<HTMLDivElement>
23
+ >(({ className, ...props }, ref) => (
24
+ <div
25
+ ref={ref}
26
+ className={cn("flex flex-col space-y-1.5 p-6", className)}
27
+ {...props}
28
+ />
29
+ ))
30
+ CardHeader.displayName = "CardHeader"
31
+
32
+ const CardTitle = React.forwardRef<
33
+ HTMLParagraphElement,
34
+ React.HTMLAttributes<HTMLHeadingElement>
35
+ >(({ className, ...props }, ref) => (
36
+ <h3
37
+ ref={ref}
38
+ className={cn("font-semibold leading-none tracking-tight", className)}
39
+ {...props}
40
+ />
41
+ ))
42
+ CardTitle.displayName = "CardTitle"
43
+
44
+ const CardDescription = React.forwardRef<
45
+ HTMLParagraphElement,
46
+ React.HTMLAttributes<HTMLParagraphElement>
47
+ >(({ className, ...props }, ref) => (
48
+ <p
49
+ ref={ref}
50
+ className={cn("text-sm text-muted-foreground", className)}
51
+ {...props}
52
+ />
53
+ ))
54
+ CardDescription.displayName = "CardDescription"
55
+
56
+ const CardContent = React.forwardRef<
57
+ HTMLDivElement,
58
+ React.HTMLAttributes<HTMLDivElement>
59
+ >(({ className, ...props }, ref) => (
60
+ <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
61
+ ))
62
+ CardContent.displayName = "CardContent"
63
+
64
+ const CardFooter = React.forwardRef<
65
+ HTMLDivElement,
66
+ React.HTMLAttributes<HTMLDivElement>
67
+ >(({ className, ...props }, ref) => (
68
+ <div
69
+ ref={ref}
70
+ className={cn("flex items-center p-6 pt-0", className)}
71
+ {...props}
72
+ />
73
+ ))
74
+ CardFooter.displayName = "CardFooter"
75
+
76
+ export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
@@ -0,0 +1,153 @@
1
+ import * as React from "react"
2
+ import { type DialogProps } from "@radix-ui/react-dialog"
3
+ import { MagnifyingGlassIcon } from "@radix-ui/react-icons"
4
+ import { Command as CommandPrimitive } from "cmdk"
5
+
6
+ import { cn } from "src/lib/utils"
7
+ import { Dialog, DialogContent } from "src/components/ui/dialog"
8
+
9
+ const Command = React.forwardRef<
10
+ React.ElementRef<typeof CommandPrimitive>,
11
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive>
12
+ >(({ className, ...props }, ref) => (
13
+ <CommandPrimitive
14
+ ref={ref}
15
+ className={cn(
16
+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
17
+ className
18
+ )}
19
+ {...props}
20
+ />
21
+ ))
22
+ Command.displayName = CommandPrimitive.displayName
23
+
24
+ interface CommandDialogProps extends DialogProps {}
25
+
26
+ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
27
+ return (
28
+ <Dialog {...props}>
29
+ <DialogContent className="overflow-hidden p-0">
30
+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
31
+ {children}
32
+ </Command>
33
+ </DialogContent>
34
+ </Dialog>
35
+ )
36
+ }
37
+
38
+ const CommandInput = React.forwardRef<
39
+ React.ElementRef<typeof CommandPrimitive.Input>,
40
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
41
+ >(({ className, ...props }, ref) => (
42
+ <div className="flex items-center border-b px-3" cmdk-input-wrapper="">
43
+ <MagnifyingGlassIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" />
44
+ <CommandPrimitive.Input
45
+ ref={ref}
46
+ className={cn(
47
+ "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
48
+ className
49
+ )}
50
+ {...props}
51
+ />
52
+ </div>
53
+ ))
54
+
55
+ CommandInput.displayName = CommandPrimitive.Input.displayName
56
+
57
+ const CommandList = React.forwardRef<
58
+ React.ElementRef<typeof CommandPrimitive.List>,
59
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
60
+ >(({ className, ...props }, ref) => (
61
+ <CommandPrimitive.List
62
+ ref={ref}
63
+ className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
64
+ {...props}
65
+ />
66
+ ))
67
+
68
+ CommandList.displayName = CommandPrimitive.List.displayName
69
+
70
+ const CommandEmpty = React.forwardRef<
71
+ React.ElementRef<typeof CommandPrimitive.Empty>,
72
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
73
+ >((props, ref) => (
74
+ <CommandPrimitive.Empty
75
+ ref={ref}
76
+ className="py-6 text-center text-sm"
77
+ {...props}
78
+ />
79
+ ))
80
+
81
+ CommandEmpty.displayName = CommandPrimitive.Empty.displayName
82
+
83
+ const CommandGroup = React.forwardRef<
84
+ React.ElementRef<typeof CommandPrimitive.Group>,
85
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
86
+ >(({ className, ...props }, ref) => (
87
+ <CommandPrimitive.Group
88
+ ref={ref}
89
+ className={cn(
90
+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
91
+ className
92
+ )}
93
+ {...props}
94
+ />
95
+ ))
96
+
97
+ CommandGroup.displayName = CommandPrimitive.Group.displayName
98
+
99
+ const CommandSeparator = React.forwardRef<
100
+ React.ElementRef<typeof CommandPrimitive.Separator>,
101
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
102
+ >(({ className, ...props }, ref) => (
103
+ <CommandPrimitive.Separator
104
+ ref={ref}
105
+ className={cn("-mx-1 h-px bg-border", className)}
106
+ {...props}
107
+ />
108
+ ))
109
+ CommandSeparator.displayName = CommandPrimitive.Separator.displayName
110
+
111
+ const CommandItem = React.forwardRef<
112
+ React.ElementRef<typeof CommandPrimitive.Item>,
113
+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
114
+ >(({ className, ...props }, ref) => (
115
+ <CommandPrimitive.Item
116
+ ref={ref}
117
+ className={cn(
118
+ "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-[selected='true']:bg-accent aria-[selected='true']:text-accent-foreground data-[disabled='true']:pointer-events-none data-[disabled='true']:opacity-50",
119
+ className
120
+ )}
121
+ {...props}
122
+ />
123
+ ))
124
+
125
+ CommandItem.displayName = CommandPrimitive.Item.displayName
126
+
127
+ const CommandShortcut = ({
128
+ className,
129
+ ...props
130
+ }: React.HTMLAttributes<HTMLSpanElement>) => {
131
+ return (
132
+ <span
133
+ className={cn(
134
+ "ml-auto text-xs tracking-widest text-muted-foreground",
135
+ className
136
+ )}
137
+ {...props}
138
+ />
139
+ )
140
+ }
141
+ CommandShortcut.displayName = "CommandShortcut"
142
+
143
+ export {
144
+ Command,
145
+ CommandDialog,
146
+ CommandInput,
147
+ CommandList,
148
+ CommandEmpty,
149
+ CommandGroup,
150
+ CommandItem,
151
+ CommandShortcut,
152
+ CommandSeparator,
153
+ }
@@ -0,0 +1,202 @@
1
+ import * as React from "react"
2
+ import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
3
+ import {
4
+ CheckIcon,
5
+ ChevronRightIcon,
6
+ DotFilledIcon,
7
+ } from "@radix-ui/react-icons"
8
+
9
+ import { cn } from "src/lib/utils"
10
+
11
+ const ContextMenu = ContextMenuPrimitive.Root
12
+
13
+ const ContextMenuTrigger = ContextMenuPrimitive.Trigger
14
+
15
+ const ContextMenuGroup = ContextMenuPrimitive.Group
16
+
17
+ const ContextMenuPortal = ContextMenuPrimitive.Portal
18
+
19
+ const ContextMenuSub = ContextMenuPrimitive.Sub
20
+
21
+ const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup
22
+
23
+ const ContextMenuSubTrigger = React.forwardRef<
24
+ React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,
25
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
26
+ inset?: boolean
27
+ }
28
+ >(({ className, inset, children, ...props }, ref) => (
29
+ <ContextMenuPrimitive.SubTrigger
30
+ ref={ref}
31
+ className={cn(
32
+ "flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
33
+ inset && "pl-8",
34
+ className
35
+ )}
36
+ {...props}
37
+ >
38
+ {children}
39
+ <ChevronRightIcon className="ml-auto h-4 w-4" />
40
+ </ContextMenuPrimitive.SubTrigger>
41
+ ))
42
+ ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName
43
+
44
+ const ContextMenuSubContent = React.forwardRef<
45
+ React.ElementRef<typeof ContextMenuPrimitive.SubContent>,
46
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
47
+ >(({ className, ...props }, ref) => (
48
+ <ContextMenuPrimitive.SubContent
49
+ ref={ref}
50
+ className={cn(
51
+ "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
52
+ className
53
+ )}
54
+ {...props}
55
+ />
56
+ ))
57
+ ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName
58
+
59
+ const ContextMenuContent = React.forwardRef<
60
+ React.ElementRef<typeof ContextMenuPrimitive.Content>,
61
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
62
+ >(({ className, ...props }, ref) => (
63
+ <ContextMenuPrimitive.Portal>
64
+ <ContextMenuPrimitive.Content
65
+ ref={ref}
66
+ className={cn(
67
+ "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
68
+ className
69
+ )}
70
+ {...props}
71
+ />
72
+ </ContextMenuPrimitive.Portal>
73
+ ))
74
+ ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName
75
+
76
+ const ContextMenuItem = React.forwardRef<
77
+ React.ElementRef<typeof ContextMenuPrimitive.Item>,
78
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {
79
+ inset?: boolean
80
+ }
81
+ >(({ className, inset, ...props }, ref) => (
82
+ <ContextMenuPrimitive.Item
83
+ ref={ref}
84
+ className={cn(
85
+ "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
86
+ inset && "pl-8",
87
+ className
88
+ )}
89
+ {...props}
90
+ />
91
+ ))
92
+ ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName
93
+
94
+ const ContextMenuCheckboxItem = React.forwardRef<
95
+ React.ElementRef<typeof ContextMenuPrimitive.CheckboxItem>,
96
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>
97
+ >(({ className, children, checked, ...props }, ref) => (
98
+ <ContextMenuPrimitive.CheckboxItem
99
+ ref={ref}
100
+ className={cn(
101
+ "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
102
+ className
103
+ )}
104
+ checked={checked}
105
+ {...props}
106
+ >
107
+ <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
108
+ <ContextMenuPrimitive.ItemIndicator>
109
+ <CheckIcon className="h-4 w-4" />
110
+ </ContextMenuPrimitive.ItemIndicator>
111
+ </span>
112
+ {children}
113
+ </ContextMenuPrimitive.CheckboxItem>
114
+ ))
115
+ ContextMenuCheckboxItem.displayName =
116
+ ContextMenuPrimitive.CheckboxItem.displayName
117
+
118
+ const ContextMenuRadioItem = React.forwardRef<
119
+ React.ElementRef<typeof ContextMenuPrimitive.RadioItem>,
120
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>
121
+ >(({ className, children, ...props }, ref) => (
122
+ <ContextMenuPrimitive.RadioItem
123
+ ref={ref}
124
+ className={cn(
125
+ "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
126
+ className
127
+ )}
128
+ {...props}
129
+ >
130
+ <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
131
+ <ContextMenuPrimitive.ItemIndicator>
132
+ <DotFilledIcon className="h-4 w-4 fill-current" />
133
+ </ContextMenuPrimitive.ItemIndicator>
134
+ </span>
135
+ {children}
136
+ </ContextMenuPrimitive.RadioItem>
137
+ ))
138
+ ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName
139
+
140
+ const ContextMenuLabel = React.forwardRef<
141
+ React.ElementRef<typeof ContextMenuPrimitive.Label>,
142
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
143
+ inset?: boolean
144
+ }
145
+ >(({ className, inset, ...props }, ref) => (
146
+ <ContextMenuPrimitive.Label
147
+ ref={ref}
148
+ className={cn(
149
+ "px-2 py-1.5 text-sm font-semibold text-foreground",
150
+ inset && "pl-8",
151
+ className
152
+ )}
153
+ {...props}
154
+ />
155
+ ))
156
+ ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName
157
+
158
+ const ContextMenuSeparator = React.forwardRef<
159
+ React.ElementRef<typeof ContextMenuPrimitive.Separator>,
160
+ React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>
161
+ >(({ className, ...props }, ref) => (
162
+ <ContextMenuPrimitive.Separator
163
+ ref={ref}
164
+ className={cn("-mx-1 my-1 h-px bg-border", className)}
165
+ {...props}
166
+ />
167
+ ))
168
+ ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName
169
+
170
+ const ContextMenuShortcut = ({
171
+ className,
172
+ ...props
173
+ }: React.HTMLAttributes<HTMLSpanElement>) => {
174
+ return (
175
+ <span
176
+ className={cn(
177
+ "ml-auto text-xs tracking-widest text-muted-foreground",
178
+ className
179
+ )}
180
+ {...props}
181
+ />
182
+ )
183
+ }
184
+ ContextMenuShortcut.displayName = "ContextMenuShortcut"
185
+
186
+ export {
187
+ ContextMenu,
188
+ ContextMenuTrigger,
189
+ ContextMenuContent,
190
+ ContextMenuItem,
191
+ ContextMenuCheckboxItem,
192
+ ContextMenuRadioItem,
193
+ ContextMenuLabel,
194
+ ContextMenuSeparator,
195
+ ContextMenuShortcut,
196
+ ContextMenuGroup,
197
+ ContextMenuPortal,
198
+ ContextMenuSub,
199
+ ContextMenuSubContent,
200
+ ContextMenuSubTrigger,
201
+ ContextMenuRadioGroup,
202
+ }