phation 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +15 -0
- package/README.md +142 -2
- package/animate/core/feels.js +11 -0
- package/animate/core/recipes/index.js +84 -0
- package/animate/core/recipes/resolve.js +96 -0
- package/animate/detect.mjs +201 -0
- package/animate/index.mjs +266 -0
- package/animate/testset/eval.mjs +24 -0
- package/animate/testset/expected.json +23 -0
- package/animate/testset/holdout/commerce-delete-item-button.tsx +38 -0
- package/animate/testset/holdout/commerce-gallery.tsx +96 -0
- package/animate/testset/holdout/commerce-tile.tsx +50 -0
- package/animate/testset/holdout/shadcn-button-group-demo.tsx +114 -0
- package/animate/testset/holdout/shadcn-card-demo.tsx +63 -0
- package/animate/testset/holdout/shadcn-command-dialog.tsx +87 -0
- package/animate/testset/holdout/shadcn-drawer-dialog.tsx +90 -0
- package/animate/testset/holdout/shadcn-field-switch.tsx +24 -0
- package/animate/testset/holdout/shadcn-hover-card-demo.tsx +40 -0
- package/animate/testset/holdout/shadcn-mode-toggle.tsx +40 -0
- package/animate/testset/holdout/shadcn-toggle-group-demo.tsx +22 -0
- package/animate/testset/holdout.json +14 -0
- package/animate/testset/holdout2/chatbot-artifact-close-button.tsx +30 -0
- package/animate/testset/holdout2/chatbot-message-actions.tsx +211 -0
- package/animate/testset/holdout2/chatbot-sidebar-history-item.tsx +132 -0
- package/animate/testset/holdout2/chatbot-sidebar-toggle.tsx +35 -0
- package/animate/testset/holdout2/chatbot-suggested-actions.tsx +82 -0
- package/animate/testset/holdout2/chatbot-weather.tsx +434 -0
- package/animate/testset/holdout2/site-code-tabs.tsx +26 -0
- package/animate/testset/holdout2/site-copy-button.tsx +121 -0
- package/animate/testset/holdout2/site-github-link.tsx +38 -0
- package/animate/testset/holdout2/site-mobile-nav.tsx +220 -0
- package/animate/testset/holdout2/site-mode-switcher.tsx +97 -0
- package/animate/testset/holdout2/site-page-nav.tsx +15 -0
- package/animate/testset/holdout2.json +15 -0
- package/animate/testset/screens/commerce-cart-add-to-cart.tsx +94 -0
- package/animate/testset/screens/commerce-cart-modal.tsx +256 -0
- package/animate/testset/screens/commerce-navbar-mobile-menu.tsx +104 -0
- package/animate/testset/screens/commerce-product-variant-selector.tsx +106 -0
- package/animate/testset/screens/shadcn-accordion-demo.tsx +61 -0
- package/animate/testset/screens/shadcn-alert-dialog-demo.tsx +35 -0
- package/animate/testset/screens/shadcn-card-with-form.tsx +59 -0
- package/animate/testset/screens/shadcn-collapsible-demo.tsx +46 -0
- package/animate/testset/screens/shadcn-dialog-demo.tsx +50 -0
- package/animate/testset/screens/shadcn-drawer-demo.tsx +136 -0
- package/animate/testset/screens/shadcn-login-form.tsx +71 -0
- package/animate/testset/screens/shadcn-nav-main.tsx +73 -0
- package/animate/testset/screens/shadcn-section-cards.tsx +102 -0
- package/animate/testset/screens/shadcn-sheet-demo.tsx +47 -0
- package/animate/testset/screens/shadcn-switch-demo.tsx +11 -0
- package/animate/testset/screens/shadcn-tabs-demo.tsx +80 -0
- package/animate/testset/screens/taxonomy-main-nav.tsx +61 -0
- package/animate/testset/screens/taxonomy-post-item.tsx +42 -0
- package/animate/testset/screens/taxonomy-pricing.tsx +69 -0
- package/animate/testset/screens/taxonomy-user-account-nav.tsx +65 -0
- package/audit.mjs +456 -0
- package/bin/cli.mjs +113 -0
- package/bin/server.mjs +147 -0
- package/data/entries.json +864 -0
- package/data/standard/CORE.md +21 -0
- package/data/standard/STANDARD.md +185 -0
- package/data/standard/claude/CLAUDE.block.md +5 -0
- package/data/standard/claude/SKILL.md +26 -0
- package/data/standard/codex/AGENTS.block.md +25 -0
- package/data/standard/cursor/phation.mdc +27 -0
- package/data/standard/meta.json +4 -0
- package/data/standard/vscode/phation.instructions.md +25 -0
- package/data/standard/windsurf/phation.md +26 -0
- package/lib.mjs +214 -0
- package/package.json +41 -4
- package/share.mjs +72 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
2
|
+
import {
|
|
3
|
+
Card,
|
|
4
|
+
CardAction,
|
|
5
|
+
CardContent,
|
|
6
|
+
CardDescription,
|
|
7
|
+
CardFooter,
|
|
8
|
+
CardHeader,
|
|
9
|
+
CardTitle,
|
|
10
|
+
} from "@/registry/new-york-v4/ui/card"
|
|
11
|
+
import { Input } from "@/registry/new-york-v4/ui/input"
|
|
12
|
+
import { Label } from "@/registry/new-york-v4/ui/label"
|
|
13
|
+
|
|
14
|
+
export default function CardDemo() {
|
|
15
|
+
return (
|
|
16
|
+
<Card className="w-full max-w-sm">
|
|
17
|
+
<CardHeader>
|
|
18
|
+
<CardTitle>Login to your account</CardTitle>
|
|
19
|
+
<CardDescription>
|
|
20
|
+
Enter your email below to login to your account
|
|
21
|
+
</CardDescription>
|
|
22
|
+
<CardAction>
|
|
23
|
+
<Button variant="link">Sign Up</Button>
|
|
24
|
+
</CardAction>
|
|
25
|
+
</CardHeader>
|
|
26
|
+
<CardContent>
|
|
27
|
+
<form>
|
|
28
|
+
<div className="flex flex-col gap-6">
|
|
29
|
+
<div className="grid gap-2">
|
|
30
|
+
<Label htmlFor="email">Email</Label>
|
|
31
|
+
<Input
|
|
32
|
+
id="email"
|
|
33
|
+
type="email"
|
|
34
|
+
placeholder="m@example.com"
|
|
35
|
+
required
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
<div className="grid gap-2">
|
|
39
|
+
<div className="flex items-center">
|
|
40
|
+
<Label htmlFor="password">Password</Label>
|
|
41
|
+
<a
|
|
42
|
+
href="#"
|
|
43
|
+
className="ml-auto inline-block text-sm underline-offset-4 hover:underline"
|
|
44
|
+
>
|
|
45
|
+
Forgot your password?
|
|
46
|
+
</a>
|
|
47
|
+
</div>
|
|
48
|
+
<Input id="password" type="password" required />
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</form>
|
|
52
|
+
</CardContent>
|
|
53
|
+
<CardFooter className="flex-col gap-2">
|
|
54
|
+
<Button type="submit" className="w-full">
|
|
55
|
+
Login
|
|
56
|
+
</Button>
|
|
57
|
+
<Button variant="outline" className="w-full">
|
|
58
|
+
Login with Google
|
|
59
|
+
</Button>
|
|
60
|
+
</CardFooter>
|
|
61
|
+
</Card>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import {
|
|
5
|
+
Calculator,
|
|
6
|
+
Calendar,
|
|
7
|
+
CreditCard,
|
|
8
|
+
Settings,
|
|
9
|
+
Smile,
|
|
10
|
+
User,
|
|
11
|
+
} from "lucide-react"
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
CommandDialog,
|
|
15
|
+
CommandEmpty,
|
|
16
|
+
CommandGroup,
|
|
17
|
+
CommandInput,
|
|
18
|
+
CommandItem,
|
|
19
|
+
CommandList,
|
|
20
|
+
CommandSeparator,
|
|
21
|
+
CommandShortcut,
|
|
22
|
+
} from "@/registry/new-york-v4/ui/command"
|
|
23
|
+
|
|
24
|
+
export default function CommandDialogDemo() {
|
|
25
|
+
const [open, setOpen] = React.useState(false)
|
|
26
|
+
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
const down = (e: KeyboardEvent) => {
|
|
29
|
+
if (e.key === "j" && (e.metaKey || e.ctrlKey)) {
|
|
30
|
+
e.preventDefault()
|
|
31
|
+
setOpen((open) => !open)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
document.addEventListener("keydown", down)
|
|
36
|
+
return () => document.removeEventListener("keydown", down)
|
|
37
|
+
}, [])
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<p className="text-sm text-muted-foreground">
|
|
42
|
+
Press{" "}
|
|
43
|
+
<kbd className="pointer-events-none inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100 select-none">
|
|
44
|
+
<span className="text-xs">⌘</span>J
|
|
45
|
+
</kbd>
|
|
46
|
+
</p>
|
|
47
|
+
<CommandDialog open={open} onOpenChange={setOpen}>
|
|
48
|
+
<CommandInput placeholder="Type a command or search..." />
|
|
49
|
+
<CommandList>
|
|
50
|
+
<CommandEmpty>No results found.</CommandEmpty>
|
|
51
|
+
<CommandGroup heading="Suggestions">
|
|
52
|
+
<CommandItem>
|
|
53
|
+
<Calendar />
|
|
54
|
+
<span>Calendar</span>
|
|
55
|
+
</CommandItem>
|
|
56
|
+
<CommandItem>
|
|
57
|
+
<Smile />
|
|
58
|
+
<span>Search Emoji</span>
|
|
59
|
+
</CommandItem>
|
|
60
|
+
<CommandItem>
|
|
61
|
+
<Calculator />
|
|
62
|
+
<span>Calculator</span>
|
|
63
|
+
</CommandItem>
|
|
64
|
+
</CommandGroup>
|
|
65
|
+
<CommandSeparator />
|
|
66
|
+
<CommandGroup heading="Settings">
|
|
67
|
+
<CommandItem>
|
|
68
|
+
<User />
|
|
69
|
+
<span>Profile</span>
|
|
70
|
+
<CommandShortcut>⌘P</CommandShortcut>
|
|
71
|
+
</CommandItem>
|
|
72
|
+
<CommandItem>
|
|
73
|
+
<CreditCard />
|
|
74
|
+
<span>Billing</span>
|
|
75
|
+
<CommandShortcut>⌘B</CommandShortcut>
|
|
76
|
+
</CommandItem>
|
|
77
|
+
<CommandItem>
|
|
78
|
+
<Settings />
|
|
79
|
+
<span>Settings</span>
|
|
80
|
+
<CommandShortcut>⌘S</CommandShortcut>
|
|
81
|
+
</CommandItem>
|
|
82
|
+
</CommandGroup>
|
|
83
|
+
</CommandList>
|
|
84
|
+
</CommandDialog>
|
|
85
|
+
</>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "cn"
|
|
5
|
+
|
|
6
|
+
import { useMediaQuery } from "@/hooks/use-media-query"
|
|
7
|
+
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogContent,
|
|
11
|
+
DialogDescription,
|
|
12
|
+
DialogHeader,
|
|
13
|
+
DialogTitle,
|
|
14
|
+
DialogTrigger,
|
|
15
|
+
} from "@/registry/new-york-v4/ui/dialog"
|
|
16
|
+
import {
|
|
17
|
+
Drawer,
|
|
18
|
+
DrawerClose,
|
|
19
|
+
DrawerContent,
|
|
20
|
+
DrawerDescription,
|
|
21
|
+
DrawerFooter,
|
|
22
|
+
DrawerHeader,
|
|
23
|
+
DrawerTitle,
|
|
24
|
+
DrawerTrigger,
|
|
25
|
+
} from "@/registry/new-york-v4/ui/drawer"
|
|
26
|
+
import { Input } from "@/registry/new-york-v4/ui/input"
|
|
27
|
+
import { Label } from "@/registry/new-york-v4/ui/label"
|
|
28
|
+
|
|
29
|
+
export default function DrawerDialogDemo() {
|
|
30
|
+
const [open, setOpen] = React.useState(false)
|
|
31
|
+
const isDesktop = useMediaQuery("(min-width: 768px)")
|
|
32
|
+
|
|
33
|
+
if (isDesktop) {
|
|
34
|
+
return (
|
|
35
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
36
|
+
<DialogTrigger asChild>
|
|
37
|
+
<Button variant="outline">Edit Profile</Button>
|
|
38
|
+
</DialogTrigger>
|
|
39
|
+
<DialogContent className="sm:max-w-[425px]">
|
|
40
|
+
<DialogHeader>
|
|
41
|
+
<DialogTitle>Edit profile</DialogTitle>
|
|
42
|
+
<DialogDescription>
|
|
43
|
+
Make changes to your profile here. Click save when you're
|
|
44
|
+
done.
|
|
45
|
+
</DialogDescription>
|
|
46
|
+
</DialogHeader>
|
|
47
|
+
<ProfileForm />
|
|
48
|
+
</DialogContent>
|
|
49
|
+
</Dialog>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Drawer open={open} onOpenChange={setOpen}>
|
|
55
|
+
<DrawerTrigger asChild>
|
|
56
|
+
<Button variant="outline">Edit Profile</Button>
|
|
57
|
+
</DrawerTrigger>
|
|
58
|
+
<DrawerContent>
|
|
59
|
+
<DrawerHeader className="text-left">
|
|
60
|
+
<DrawerTitle>Edit profile</DrawerTitle>
|
|
61
|
+
<DrawerDescription>
|
|
62
|
+
Make changes to your profile here. Click save when you're done.
|
|
63
|
+
</DrawerDescription>
|
|
64
|
+
</DrawerHeader>
|
|
65
|
+
<ProfileForm className="px-4" />
|
|
66
|
+
<DrawerFooter className="pt-2">
|
|
67
|
+
<DrawerClose asChild>
|
|
68
|
+
<Button variant="outline">Cancel</Button>
|
|
69
|
+
</DrawerClose>
|
|
70
|
+
</DrawerFooter>
|
|
71
|
+
</DrawerContent>
|
|
72
|
+
</Drawer>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function ProfileForm({ className }: React.ComponentProps<"form">) {
|
|
77
|
+
return (
|
|
78
|
+
<form className={cn("grid items-start gap-6", className)}>
|
|
79
|
+
<div className="grid gap-3">
|
|
80
|
+
<Label htmlFor="email">Email</Label>
|
|
81
|
+
<Input type="email" id="email" defaultValue="shadcn@example.com" />
|
|
82
|
+
</div>
|
|
83
|
+
<div className="grid gap-3">
|
|
84
|
+
<Label htmlFor="username">Username</Label>
|
|
85
|
+
<Input id="username" defaultValue="@shadcn" />
|
|
86
|
+
</div>
|
|
87
|
+
<Button type="submit">Save changes</Button>
|
|
88
|
+
</form>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
FieldContent,
|
|
4
|
+
FieldDescription,
|
|
5
|
+
FieldLabel,
|
|
6
|
+
} from "@/registry/new-york-v4/ui/field"
|
|
7
|
+
import { Switch } from "@/registry/new-york-v4/ui/switch"
|
|
8
|
+
|
|
9
|
+
export default function FieldSwitch() {
|
|
10
|
+
return (
|
|
11
|
+
<div className="w-full max-w-md">
|
|
12
|
+
<Field orientation="horizontal">
|
|
13
|
+
<FieldContent>
|
|
14
|
+
<FieldLabel htmlFor="2fa">Multi-factor authentication</FieldLabel>
|
|
15
|
+
<FieldDescription>
|
|
16
|
+
Enable multi-factor authentication. If you do not have a two-factor
|
|
17
|
+
device, you can use a one-time code sent to your email.
|
|
18
|
+
</FieldDescription>
|
|
19
|
+
</FieldContent>
|
|
20
|
+
<Switch id="2fa" />
|
|
21
|
+
</Field>
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CalendarIcon } from "lucide-react"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Avatar,
|
|
5
|
+
AvatarFallback,
|
|
6
|
+
AvatarImage,
|
|
7
|
+
} from "@/registry/new-york-v4/ui/avatar"
|
|
8
|
+
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
9
|
+
import {
|
|
10
|
+
HoverCard,
|
|
11
|
+
HoverCardContent,
|
|
12
|
+
HoverCardTrigger,
|
|
13
|
+
} from "@/registry/new-york-v4/ui/hover-card"
|
|
14
|
+
|
|
15
|
+
export default function HoverCardDemo() {
|
|
16
|
+
return (
|
|
17
|
+
<HoverCard>
|
|
18
|
+
<HoverCardTrigger asChild>
|
|
19
|
+
<Button variant="link">@nextjs</Button>
|
|
20
|
+
</HoverCardTrigger>
|
|
21
|
+
<HoverCardContent className="w-80">
|
|
22
|
+
<div className="flex justify-between gap-4">
|
|
23
|
+
<Avatar>
|
|
24
|
+
<AvatarImage src="https://github.com/vercel.png" />
|
|
25
|
+
<AvatarFallback>VC</AvatarFallback>
|
|
26
|
+
</Avatar>
|
|
27
|
+
<div className="space-y-1">
|
|
28
|
+
<h4 className="text-sm font-semibold">@nextjs</h4>
|
|
29
|
+
<p className="text-sm">
|
|
30
|
+
The React Framework – created and maintained by @vercel.
|
|
31
|
+
</p>
|
|
32
|
+
<div className="text-xs text-muted-foreground">
|
|
33
|
+
Joined December 2021
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</HoverCardContent>
|
|
38
|
+
</HoverCard>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Moon, Sun } from "lucide-react"
|
|
5
|
+
import { useTheme } from "next-themes"
|
|
6
|
+
|
|
7
|
+
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
8
|
+
import {
|
|
9
|
+
DropdownMenu,
|
|
10
|
+
DropdownMenuContent,
|
|
11
|
+
DropdownMenuItem,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
} from "@/registry/new-york-v4/ui/dropdown-menu"
|
|
14
|
+
|
|
15
|
+
export default function ModeToggle() {
|
|
16
|
+
const { setTheme } = useTheme()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<DropdownMenu>
|
|
20
|
+
<DropdownMenuTrigger asChild>
|
|
21
|
+
<Button variant="outline" size="icon">
|
|
22
|
+
<Sun className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
|
23
|
+
<Moon className="absolute h-[1.2rem] w-[1.2rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
|
24
|
+
<span className="sr-only">Toggle theme</span>
|
|
25
|
+
</Button>
|
|
26
|
+
</DropdownMenuTrigger>
|
|
27
|
+
<DropdownMenuContent align="end">
|
|
28
|
+
<DropdownMenuItem onClick={() => setTheme("light")}>
|
|
29
|
+
Light
|
|
30
|
+
</DropdownMenuItem>
|
|
31
|
+
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
|
32
|
+
Dark
|
|
33
|
+
</DropdownMenuItem>
|
|
34
|
+
<DropdownMenuItem onClick={() => setTheme("system")}>
|
|
35
|
+
System
|
|
36
|
+
</DropdownMenuItem>
|
|
37
|
+
</DropdownMenuContent>
|
|
38
|
+
</DropdownMenu>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Bold, Italic, Underline } from "lucide-react"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ToggleGroup,
|
|
5
|
+
ToggleGroupItem,
|
|
6
|
+
} from "@/registry/new-york-v4/ui/toggle-group"
|
|
7
|
+
|
|
8
|
+
export default function ToggleGroupDemo() {
|
|
9
|
+
return (
|
|
10
|
+
<ToggleGroup variant="outline" type="multiple">
|
|
11
|
+
<ToggleGroupItem value="bold" aria-label="Toggle bold">
|
|
12
|
+
<Bold className="h-4 w-4" />
|
|
13
|
+
</ToggleGroupItem>
|
|
14
|
+
<ToggleGroupItem value="italic" aria-label="Toggle italic">
|
|
15
|
+
<Italic className="h-4 w-4" />
|
|
16
|
+
</ToggleGroupItem>
|
|
17
|
+
<ToggleGroupItem value="strikethrough" aria-label="Toggle strikethrough">
|
|
18
|
+
<Underline className="h-4 w-4" />
|
|
19
|
+
</ToggleGroupItem>
|
|
20
|
+
</ToggleGroup>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_about": "Holdout: 11 screens labelled BEFORE the detector was run on them (shadcn examples + vercel/commerce, fetched 2026-11-18). Rules were not tuned on these.",
|
|
3
|
+
"commerce-delete-item-button.tsx": { "26": ["icon-button"] },
|
|
4
|
+
"commerce-gallery.tsx": { "49": ["icon-button"], "57": ["icon-button"], "75": ["list"], "76": ["button"] },
|
|
5
|
+
"commerce-tile.tsx": { "21": ["card"] },
|
|
6
|
+
"shadcn-button-group-demo.tsx": { "38": ["icon-button"], "43": ["button"], "44": ["button"], "47": ["button"], "50": ["icon-button"] },
|
|
7
|
+
"shadcn-card-demo.tsx": { "16": ["card"], "23": ["button"], "31": ["input"], "48": ["input"], "54": ["button"], "57": ["button"] },
|
|
8
|
+
"shadcn-command-dialog.tsx": { "47": ["modal"], "48": ["input"] },
|
|
9
|
+
"shadcn-drawer-dialog.tsx": { "37": ["button"], "39": ["modal"], "56": ["button"], "58": ["sheet"], "68": ["button"], "81": ["input"], "85": ["input"], "87": ["button"] },
|
|
10
|
+
"shadcn-field-switch.tsx": { "20": ["toggle"] },
|
|
11
|
+
"shadcn-hover-card-demo.tsx": { "19": ["button"] },
|
|
12
|
+
"shadcn-mode-toggle.tsx": { "21": ["icon-button"] },
|
|
13
|
+
"shadcn-toggle-group-demo.tsx": { "11": ["toggle"], "14": ["toggle"], "17": ["toggle"] }
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { memo, useCallback } from "react";
|
|
2
|
+
import { initialArtifactData, useArtifact } from "@/hooks/use-artifact";
|
|
3
|
+
import { CrossIcon } from "./icons";
|
|
4
|
+
|
|
5
|
+
function PureArtifactCloseButton() {
|
|
6
|
+
const { setArtifact } = useArtifact();
|
|
7
|
+
const handleClick = useCallback(() => {
|
|
8
|
+
setArtifact((currentArtifact) =>
|
|
9
|
+
currentArtifact.status === "streaming"
|
|
10
|
+
? {
|
|
11
|
+
...currentArtifact,
|
|
12
|
+
isVisible: false,
|
|
13
|
+
}
|
|
14
|
+
: { ...initialArtifactData, status: "idle" }
|
|
15
|
+
);
|
|
16
|
+
}, [setArtifact]);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<button
|
|
20
|
+
className="group flex size-8 items-center justify-center rounded-lg border border-transparent text-muted-foreground transition-all duration-150 hover:border-border hover:bg-muted hover:text-foreground active:scale-95"
|
|
21
|
+
data-testid="artifact-close-button"
|
|
22
|
+
onClick={handleClick}
|
|
23
|
+
type="button"
|
|
24
|
+
>
|
|
25
|
+
<CrossIcon size={16} />
|
|
26
|
+
</button>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const ArtifactCloseButton = memo(PureArtifactCloseButton, () => true);
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import equal from "fast-deep-equal";
|
|
2
|
+
import { memo, useCallback } from "react";
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { useSWRConfig } from "swr";
|
|
5
|
+
import { useCopyToClipboard } from "usehooks-ts";
|
|
6
|
+
import type { Vote } from "@/lib/db/schema";
|
|
7
|
+
import type { ChatMessage } from "@/lib/types";
|
|
8
|
+
import {
|
|
9
|
+
MessageAction as Action,
|
|
10
|
+
MessageActions as Actions,
|
|
11
|
+
} from "../ai-elements/message";
|
|
12
|
+
import { CopyIcon, PencilEditIcon, ThumbDownIcon, ThumbUpIcon } from "./icons";
|
|
13
|
+
|
|
14
|
+
export function PureMessageActions({
|
|
15
|
+
chatId,
|
|
16
|
+
message,
|
|
17
|
+
vote,
|
|
18
|
+
isLoading,
|
|
19
|
+
onEdit,
|
|
20
|
+
}: {
|
|
21
|
+
chatId: string;
|
|
22
|
+
message: ChatMessage;
|
|
23
|
+
vote: Vote | undefined;
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
onEdit?: () => void;
|
|
26
|
+
}) {
|
|
27
|
+
const { mutate } = useSWRConfig();
|
|
28
|
+
const [_, copyToClipboard] = useCopyToClipboard();
|
|
29
|
+
|
|
30
|
+
const textFromParts = message.parts
|
|
31
|
+
?.filter((part) => part.type === "text")
|
|
32
|
+
.map((part) => part.text)
|
|
33
|
+
.join("\n")
|
|
34
|
+
.trim();
|
|
35
|
+
|
|
36
|
+
const handleCopy = useCallback(async () => {
|
|
37
|
+
if (!textFromParts) {
|
|
38
|
+
toast.error("There's no text to copy!");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await copyToClipboard(textFromParts);
|
|
43
|
+
toast.success("Copied to clipboard!");
|
|
44
|
+
}, [copyToClipboard, textFromParts]);
|
|
45
|
+
|
|
46
|
+
const handleUpvote = useCallback(() => {
|
|
47
|
+
const upvote = fetch(
|
|
48
|
+
`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote`,
|
|
49
|
+
{
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
chatId,
|
|
52
|
+
messageId: message.id,
|
|
53
|
+
type: "up",
|
|
54
|
+
}),
|
|
55
|
+
method: "PATCH",
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
toast.promise(upvote, {
|
|
60
|
+
error: "Failed to upvote response.",
|
|
61
|
+
loading: "Upvoting Response...",
|
|
62
|
+
success: () => {
|
|
63
|
+
mutate<Vote[]>(
|
|
64
|
+
`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote?chatId=${chatId}`,
|
|
65
|
+
(currentVotes) => {
|
|
66
|
+
if (!currentVotes) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const votesWithoutCurrent = currentVotes.filter(
|
|
71
|
+
(currentVote) => currentVote.messageId !== message.id
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return [
|
|
75
|
+
...votesWithoutCurrent,
|
|
76
|
+
{
|
|
77
|
+
chatId,
|
|
78
|
+
isUpvoted: true,
|
|
79
|
+
messageId: message.id,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
},
|
|
83
|
+
{ revalidate: false }
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return "Upvoted Response!";
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}, [chatId, message.id, mutate]);
|
|
90
|
+
|
|
91
|
+
const handleDownvote = useCallback(() => {
|
|
92
|
+
const downvote = fetch(
|
|
93
|
+
`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote`,
|
|
94
|
+
{
|
|
95
|
+
body: JSON.stringify({
|
|
96
|
+
chatId,
|
|
97
|
+
messageId: message.id,
|
|
98
|
+
type: "down",
|
|
99
|
+
}),
|
|
100
|
+
method: "PATCH",
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
toast.promise(downvote, {
|
|
105
|
+
error: "Failed to downvote response.",
|
|
106
|
+
loading: "Downvoting Response...",
|
|
107
|
+
success: () => {
|
|
108
|
+
mutate<Vote[]>(
|
|
109
|
+
`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/vote?chatId=${chatId}`,
|
|
110
|
+
(currentVotes) => {
|
|
111
|
+
if (!currentVotes) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const votesWithoutCurrent = currentVotes.filter(
|
|
116
|
+
(currentVote) => currentVote.messageId !== message.id
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return [
|
|
120
|
+
...votesWithoutCurrent,
|
|
121
|
+
{
|
|
122
|
+
chatId,
|
|
123
|
+
isUpvoted: false,
|
|
124
|
+
messageId: message.id,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
},
|
|
128
|
+
{ revalidate: false }
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return "Downvoted Response!";
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}, [chatId, message.id, mutate]);
|
|
135
|
+
|
|
136
|
+
if (isLoading) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (message.role === "user") {
|
|
141
|
+
return (
|
|
142
|
+
<Actions className="-mr-0.5 justify-end opacity-0 transition-opacity duration-150 group-hover/message:opacity-100">
|
|
143
|
+
<div className="flex items-center gap-0.5">
|
|
144
|
+
{onEdit ? (
|
|
145
|
+
<Action
|
|
146
|
+
className="size-7 text-muted-foreground/50 hover:text-foreground"
|
|
147
|
+
data-testid="message-edit-button"
|
|
148
|
+
onClick={onEdit}
|
|
149
|
+
tooltip="Edit"
|
|
150
|
+
>
|
|
151
|
+
<PencilEditIcon />
|
|
152
|
+
</Action>
|
|
153
|
+
) : null}
|
|
154
|
+
<Action
|
|
155
|
+
className="size-7 text-muted-foreground/50 hover:text-foreground"
|
|
156
|
+
onClick={handleCopy}
|
|
157
|
+
tooltip="Copy"
|
|
158
|
+
>
|
|
159
|
+
<CopyIcon />
|
|
160
|
+
</Action>
|
|
161
|
+
</div>
|
|
162
|
+
</Actions>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<Actions className="-ml-0.5 opacity-0 transition-opacity duration-150 group-hover/message:opacity-100">
|
|
168
|
+
<Action
|
|
169
|
+
className="text-muted-foreground/50 hover:text-foreground"
|
|
170
|
+
onClick={handleCopy}
|
|
171
|
+
tooltip="Copy"
|
|
172
|
+
>
|
|
173
|
+
<CopyIcon />
|
|
174
|
+
</Action>
|
|
175
|
+
|
|
176
|
+
<Action
|
|
177
|
+
className="text-muted-foreground/50 hover:text-foreground"
|
|
178
|
+
data-testid="message-upvote"
|
|
179
|
+
disabled={vote?.isUpvoted}
|
|
180
|
+
onClick={handleUpvote}
|
|
181
|
+
tooltip="Upvote Response"
|
|
182
|
+
>
|
|
183
|
+
<ThumbUpIcon />
|
|
184
|
+
</Action>
|
|
185
|
+
|
|
186
|
+
<Action
|
|
187
|
+
className="text-muted-foreground/50 hover:text-foreground"
|
|
188
|
+
data-testid="message-downvote"
|
|
189
|
+
disabled={vote && !vote.isUpvoted}
|
|
190
|
+
onClick={handleDownvote}
|
|
191
|
+
tooltip="Downvote Response"
|
|
192
|
+
>
|
|
193
|
+
<ThumbDownIcon />
|
|
194
|
+
</Action>
|
|
195
|
+
</Actions>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export const MessageActions = memo(
|
|
200
|
+
PureMessageActions,
|
|
201
|
+
(prevProps, nextProps) => {
|
|
202
|
+
if (!equal(prevProps.vote, nextProps.vote)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (prevProps.isLoading !== nextProps.isLoading) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
);
|