@chat-js/cli 0.6.1 → 0.6.3
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/index.js +17065 -16667
- package/package.json +1 -1
- package/templates/chat-app/app/(auth)/login/page.tsx +3 -3
- package/templates/chat-app/app/(chat)/api/chat/route.ts +4 -60
- package/templates/chat-app/app/not-found.tsx +2 -2
- package/templates/chat-app/chat.config.ts +3 -0
- package/templates/chat-app/components/ai-elements/actions.tsx +44 -44
- package/templates/chat-app/components/ai-elements/artifact.tsx +92 -92
- package/templates/chat-app/components/ai-elements/code-block.tsx +143 -143
- package/templates/chat-app/components/ai-elements/context.tsx +313 -313
- package/templates/chat-app/components/ai-elements/conversation.tsx +65 -65
- package/templates/chat-app/components/ai-elements/extra/conversation-content-scroll-area.tsx +29 -29
- package/templates/chat-app/components/ai-elements/extra/mcp-tool-header.tsx +27 -27
- package/templates/chat-app/components/ai-elements/message.tsx +341 -344
- package/templates/chat-app/components/ai-elements/parseIncompleteMarkdown.tsx +122 -122
- package/templates/chat-app/components/ai-elements/prompt-input.tsx +1059 -1059
- package/templates/chat-app/components/ai-elements/reasoning.tsx +131 -131
- package/templates/chat-app/components/ai-elements/response.tsx +15 -12
- package/templates/chat-app/components/ai-elements/sandbox.tsx +84 -84
- package/templates/chat-app/components/ai-elements/shimmer.tsx +47 -47
- package/templates/chat-app/components/ai-elements/suggestion.tsx +33 -33
- package/templates/chat-app/components/ai-elements/tool.tsx +118 -118
- package/templates/chat-app/components/app-sidebar-history-conditional.tsx +3 -3
- package/templates/chat-app/components/app-sidebar.tsx +3 -3
- package/templates/chat-app/components/connectors-dropdown.tsx +6 -3
- package/templates/chat-app/components/deep-research-progress.tsx +1 -1
- package/templates/chat-app/components/header-breadcrumb.tsx +14 -11
- package/templates/chat-app/components/internal-link.tsx +73 -0
- package/templates/chat-app/components/login-form.tsx +5 -5
- package/templates/chat-app/components/message-parts.tsx +1 -71
- package/templates/chat-app/components/model-selector.tsx +3 -3
- package/templates/chat-app/components/new-chat-button.tsx +4 -4
- package/templates/chat-app/components/part/document-common.tsx +3 -3
- package/templates/chat-app/components/part/document-tool.tsx +3 -3
- package/templates/chat-app/components/part/message-annotations.tsx +2 -2
- package/templates/chat-app/components/part/tool-part.tsx +92 -0
- package/templates/chat-app/components/project-chat-item.tsx +2 -2
- package/templates/chat-app/components/research-progress.tsx +2 -2
- package/templates/chat-app/components/research-task.tsx +1 -1
- package/templates/chat-app/components/research-tasks.tsx +1 -1
- package/templates/chat-app/components/settings/connectors-settings.tsx +4 -4
- package/templates/chat-app/components/settings/mcp-details-page.tsx +5 -5
- package/templates/chat-app/components/settings/settings-nav.tsx +3 -3
- package/templates/chat-app/components/sidebar-chat-item.tsx +4 -12
- package/templates/chat-app/components/sidebar-project-item.tsx +4 -11
- package/templates/chat-app/components/sidebar-top-row.tsx +7 -7
- package/templates/chat-app/components/sidebar-user-nav.tsx +3 -3
- package/templates/chat-app/components/signup-form.tsx +8 -5
- package/templates/chat-app/components/source-badge.tsx +3 -9
- package/templates/chat-app/components/sources.tsx +1 -1
- package/templates/chat-app/components/ui/accordion.tsx +32 -32
- package/templates/chat-app/components/ui/alert-dialog.tsx +103 -103
- package/templates/chat-app/components/ui/alert.tsx +36 -36
- package/templates/chat-app/components/ui/avatar.tsx +28 -28
- package/templates/chat-app/components/ui/badge.tsx +22 -22
- package/templates/chat-app/components/ui/breadcrumb.tsx +72 -72
- package/templates/chat-app/components/ui/button-group.tsx +58 -58
- package/templates/chat-app/components/ui/button.tsx +45 -45
- package/templates/chat-app/components/ui/card.tsx +65 -65
- package/templates/chat-app/components/ui/checkbox.tsx +16 -16
- package/templates/chat-app/components/ui/collapsible.tsx +1 -1
- package/templates/chat-app/components/ui/command.tsx +137 -137
- package/templates/chat-app/components/ui/dialog.tsx +94 -94
- package/templates/chat-app/components/ui/drawer.tsx +68 -68
- package/templates/chat-app/components/ui/dropdown-menu.tsx +184 -184
- package/templates/chat-app/components/ui/empty.tsx +76 -76
- package/templates/chat-app/components/ui/extra/action-container.tsx +3 -3
- package/templates/chat-app/components/ui/extra/scroll-area-viewport-ref.tsx +24 -24
- package/templates/chat-app/components/ui/form.tsx +112 -112
- package/templates/chat-app/components/ui/hover-card.tsx +25 -25
- package/templates/chat-app/components/ui/input-group.tsx +126 -126
- package/templates/chat-app/components/ui/input.tsx +13 -13
- package/templates/chat-app/components/ui/label.tsx +12 -12
- package/templates/chat-app/components/ui/popover.tsx +25 -25
- package/templates/chat-app/components/ui/progress.tsx +19 -19
- package/templates/chat-app/components/ui/resizable.tsx +27 -27
- package/templates/chat-app/components/ui/scroll-area.tsx +30 -30
- package/templates/chat-app/components/ui/select.tsx +108 -108
- package/templates/chat-app/components/ui/separator.tsx +16 -16
- package/templates/chat-app/components/ui/sheet.tsx +91 -91
- package/templates/chat-app/components/ui/sidebar.tsx +615 -615
- package/templates/chat-app/components/ui/skeleton.tsx +7 -7
- package/templates/chat-app/components/ui/slider.tsx +50 -50
- package/templates/chat-app/components/ui/spinner.tsx +8 -8
- package/templates/chat-app/components/ui/switch.tsx +16 -16
- package/templates/chat-app/components/ui/table.tsx +71 -71
- package/templates/chat-app/components/ui/tabs.tsx +31 -31
- package/templates/chat-app/components/ui/textarea.tsx +10 -10
- package/templates/chat-app/components/ui/toggle.tsx +31 -31
- package/templates/chat-app/components/ui/tooltip.tsx +48 -48
- package/templates/chat-app/components/upgrade-cta/limit-display.tsx +7 -7
- package/templates/chat-app/components/upgrade-cta/login-cta-banner.tsx +3 -3
- package/templates/chat-app/components/upgrade-cta/login-prompt.tsx +3 -3
- package/templates/chat-app/hooks/use-mobile.ts +13 -13
- package/templates/chat-app/lib/ai/core-chat-agent.ts +25 -14
- package/templates/chat-app/lib/ai/eval-agent.ts +4 -5
- package/templates/chat-app/lib/ai/gateway-model-defaults.ts +24 -0
- package/templates/chat-app/lib/ai/installed-tools.ts +12 -0
- package/templates/chat-app/lib/ai/mcp/mcp-client.ts +2 -2
- package/templates/chat-app/lib/ai/models.generated.ts +4236 -4585
- package/templates/chat-app/lib/ai/tool-renderer-registry.ts +31 -0
- package/templates/chat-app/lib/ai/types.ts +15 -20
- package/templates/chat-app/lib/config-requirements.ts +11 -6
- package/templates/chat-app/lib/config-schema.ts +24 -0
- package/templates/chat-app/lib/stores/hooks-message-parts.ts +1 -1
- package/templates/chat-app/lib/utils.ts +157 -157
- package/templates/chat-app/package.json +1 -1
- package/templates/chat-app/scripts/check-env.ts +229 -2
- package/templates/chat-app/tools/chatjs/_shared/lib/tool-part.ts +5 -0
- package/templates/chat-app/{components/part/weather.tsx → tools/chatjs/get-weather/renderer.tsx} +24 -38
- package/templates/chat-app/{components/part/retrieve-url.tsx → tools/chatjs/retrieve-url/renderer.tsx} +20 -15
- package/templates/chat-app/{lib/ai/tools/retrieve-url.ts → tools/chatjs/retrieve-url/tool.ts} +46 -7
- package/templates/chat-app/tools/chatjs/tools.ts +16 -0
- package/templates/chat-app/tools/chatjs/ui.ts +17 -0
- package/templates/chat-app/tools/chatjs/word-count/renderer.tsx +50 -0
- package/templates/chat-app/tools/chatjs/word-count/tool.ts +30 -0
- package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.ts +3 -5
- package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/deep-research.ts +2 -3
- package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/pipeline.ts +1 -1
- package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/types.ts +1 -1
- package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/utils.ts +7 -7
- package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/types.ts +1 -1
- package/templates/chat-app/{lib/ai/tools → tools/platform}/generate-video.ts +4 -6
- package/templates/chat-app/{lib/ai/tools → tools/platform}/read-document.ts +2 -2
- package/templates/chat-app/{lib/ai/tools → tools/platform}/steps/multi-query-web-search.ts +1 -1
- package/templates/chat-app/{lib/ai/tools → tools/platform}/steps/web-search.ts +1 -1
- package/templates/chat-app/{lib/ai/tools → tools/platform}/tools.ts +54 -30
- package/templates/chat-app/{lib/ai/tools → tools/platform}/web-search.ts +7 -5
- package/templates/electron/CHANGELOG.md +16 -2
- package/templates/electron/package.json +1 -1
- package/templates/chat-app/lib/ai/tools/tools-definitions.ts +0 -83
- /package/templates/chat-app/{lib/ai/tools/get-weather.ts → tools/chatjs/get-weather/tool.ts} +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.javascript.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.python.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.shared.test.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.shared.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/code-execution.types.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/configuration.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/prompts.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/researcher-agent.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/deep-research/supervisor-agent.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/code-guidelines.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/create-code-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/create-sheet-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/create-text-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/edit-code-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/edit-sheet-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/edit-text-document.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/sheet-guidelines.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/documents/text-guidelines.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/generate-image.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/research-updates-schema.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/steps/search-utils.ts +0 -0
- /package/templates/chat-app/{lib/ai/tools → tools/platform}/types.ts +0 -0
|
@@ -3,102 +3,102 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
3
3
|
import { cn } from "@/lib/utils";
|
|
4
4
|
|
|
5
5
|
function Empty({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
className={cn(
|
|
9
|
+
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg border-dashed p-6 text-center md:p-12",
|
|
10
|
+
className,
|
|
11
|
+
)}
|
|
12
|
+
data-slot="empty"
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
className={cn(
|
|
22
|
+
"flex max-w-sm flex-col items-center gap-2 text-center",
|
|
23
|
+
className,
|
|
24
|
+
)}
|
|
25
|
+
data-slot="empty-header"
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const emptyMediaVariants = cva(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
variant: {
|
|
36
|
+
default: "bg-transparent",
|
|
37
|
+
icon: "flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: {
|
|
41
|
+
variant: "default",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
function EmptyMedia({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
className,
|
|
48
|
+
variant = "default",
|
|
49
|
+
...props
|
|
50
50
|
}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
className={cn(emptyMediaVariants({ variant, className }))}
|
|
54
|
+
data-slot="empty-icon"
|
|
55
|
+
data-variant={variant}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
className={cn("font-medium text-lg tracking-tight", className)}
|
|
65
|
+
data-slot="empty-title"
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
className={cn(
|
|
75
|
+
"text-muted-foreground text-sm/relaxed [&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
data-slot="empty-description"
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
return (
|
|
86
|
+
<div
|
|
87
|
+
className={cn(
|
|
88
|
+
"flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-balance text-sm",
|
|
89
|
+
className,
|
|
90
|
+
)}
|
|
91
|
+
data-slot="empty-content"
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
Empty,
|
|
99
|
+
EmptyContent,
|
|
100
|
+
EmptyDescription,
|
|
101
|
+
EmptyHeader,
|
|
102
|
+
EmptyMedia,
|
|
103
|
+
EmptyTitle,
|
|
104
104
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import Link from "next/link";
|
|
4
3
|
import type * as React from "react";
|
|
4
|
+
import { InternalLink } from "@/components/internal-link";
|
|
5
5
|
|
|
6
6
|
import { cn } from "@/lib/utils";
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ function ActionContainer({ className, ...props }: ActionContainerProps) {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
type ActionContainerLinkProps = React.ComponentProps<typeof
|
|
22
|
+
type ActionContainerLinkProps = React.ComponentProps<typeof InternalLink>;
|
|
23
23
|
|
|
24
24
|
function ActionContainerLink({
|
|
25
25
|
className,
|
|
@@ -27,7 +27,7 @@ function ActionContainerLink({
|
|
|
27
27
|
...props
|
|
28
28
|
}: ActionContainerLinkProps) {
|
|
29
29
|
return (
|
|
30
|
-
<
|
|
30
|
+
<InternalLink
|
|
31
31
|
className={cn("absolute inset-0 z-10", className)}
|
|
32
32
|
tabIndex={tabIndex ?? -1}
|
|
33
33
|
{...props}
|
|
@@ -12,30 +12,30 @@ import { cn } from "@/lib/utils";
|
|
|
12
12
|
import { ScrollBar } from "../scroll-area";
|
|
13
13
|
|
|
14
14
|
export function ScrollArea({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
className,
|
|
16
|
+
children,
|
|
17
|
+
viewportRef,
|
|
18
|
+
...props
|
|
19
19
|
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root> & {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
viewportRef?: React.Ref<
|
|
21
|
+
React.ComponentRef<typeof ScrollAreaPrimitive.Viewport>
|
|
22
|
+
>;
|
|
23
23
|
}) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
return (
|
|
25
|
+
<ScrollAreaPrimitive.Root
|
|
26
|
+
className={cn("relative", className)}
|
|
27
|
+
data-slot="scroll-area"
|
|
28
|
+
{...props}
|
|
29
|
+
>
|
|
30
|
+
<ScrollAreaPrimitive.Viewport
|
|
31
|
+
className="size-full rounded-[inherit] outline-none transition-[color,box-shadow] focus-visible:outline-1 focus-visible:ring-[3px] focus-visible:ring-ring/50"
|
|
32
|
+
data-slot="scroll-area-viewport"
|
|
33
|
+
ref={viewportRef}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</ScrollAreaPrimitive.Viewport>
|
|
37
|
+
<ScrollBar />
|
|
38
|
+
<ScrollAreaPrimitive.Corner />
|
|
39
|
+
</ScrollAreaPrimitive.Root>
|
|
40
|
+
);
|
|
41
41
|
}
|
|
@@ -4,13 +4,13 @@ import type * as LabelPrimitive from "@radix-ui/react-label";
|
|
|
4
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
Controller,
|
|
8
|
+
type ControllerProps,
|
|
9
|
+
type FieldPath,
|
|
10
|
+
type FieldValues,
|
|
11
|
+
FormProvider,
|
|
12
|
+
useFormContext,
|
|
13
|
+
useFormState,
|
|
14
14
|
} from "react-hook-form";
|
|
15
15
|
import { Label } from "@/components/ui/label";
|
|
16
16
|
import { cn } from "@/lib/utils";
|
|
@@ -18,146 +18,146 @@ import { cn } from "@/lib/utils";
|
|
|
18
18
|
const Form = FormProvider;
|
|
19
19
|
|
|
20
20
|
type FormFieldContextValue<
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
22
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
23
23
|
> = {
|
|
24
|
-
|
|
24
|
+
name: TName;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
|
28
|
-
|
|
28
|
+
{} as FormFieldContextValue,
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
const FormField = <
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
33
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
|
34
34
|
>({
|
|
35
|
-
|
|
35
|
+
...props
|
|
36
36
|
}: ControllerProps<TFieldValues, TName>) => (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
|
38
|
+
<Controller {...props} />
|
|
39
|
+
</FormFieldContext.Provider>
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
const useFormField = () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
44
|
+
const itemContext = React.useContext(FormItemContext);
|
|
45
|
+
const { getFieldState } = useFormContext();
|
|
46
|
+
const formState = useFormState({ name: fieldContext.name });
|
|
47
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
48
|
+
|
|
49
|
+
if (!fieldContext) {
|
|
50
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { id } = itemContext;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
id,
|
|
57
|
+
name: fieldContext.name,
|
|
58
|
+
formItemId: `${id}-form-item`,
|
|
59
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
60
|
+
formMessageId: `${id}-form-item-message`,
|
|
61
|
+
...fieldState,
|
|
62
|
+
};
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
type FormItemContextValue = {
|
|
66
|
-
|
|
66
|
+
id: string;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
const FormItemContext = React.createContext<FormItemContextValue>(
|
|
70
|
-
|
|
70
|
+
{} as FormItemContextValue,
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
const id = React.useId();
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<FormItemContext.Provider value={{ id }}>
|
|
78
|
+
<div
|
|
79
|
+
className={cn("grid gap-2", className)}
|
|
80
|
+
data-slot="form-item"
|
|
81
|
+
{...props}
|
|
82
|
+
/>
|
|
83
|
+
</FormItemContext.Provider>
|
|
84
|
+
);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function FormLabel({
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
className,
|
|
89
|
+
...props
|
|
90
90
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
const { error, formItemId } = useFormField();
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Label
|
|
95
|
+
className={cn("data-[error=true]:text-destructive", className)}
|
|
96
|
+
data-error={!!error}
|
|
97
|
+
data-slot="form-label"
|
|
98
|
+
htmlFor={formItemId}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
const { error, formItemId, formDescriptionId, formMessageId } =
|
|
106
|
+
useFormField();
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<Slot
|
|
110
|
+
aria-describedby={
|
|
111
|
+
error ? `${formDescriptionId} ${formMessageId}` : `${formDescriptionId}`
|
|
112
|
+
}
|
|
113
|
+
aria-invalid={!!error}
|
|
114
|
+
data-slot="form-control"
|
|
115
|
+
id={formItemId}
|
|
116
|
+
{...props}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
const { formDescriptionId } = useFormField();
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<p
|
|
126
|
+
className={cn("text-muted-foreground text-sm", className)}
|
|
127
|
+
data-slot="form-description"
|
|
128
|
+
id={formDescriptionId}
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
135
|
+
const { error, formMessageId } = useFormField();
|
|
136
|
+
const body = error ? String(error?.message ?? "") : props.children;
|
|
137
|
+
|
|
138
|
+
if (!body) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<p
|
|
144
|
+
className={cn("text-destructive text-sm", className)}
|
|
145
|
+
data-slot="form-message"
|
|
146
|
+
id={formMessageId}
|
|
147
|
+
{...props}
|
|
148
|
+
>
|
|
149
|
+
{body}
|
|
150
|
+
</p>
|
|
151
|
+
);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
export {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
Form,
|
|
156
|
+
FormControl,
|
|
157
|
+
FormDescription,
|
|
158
|
+
FormField,
|
|
159
|
+
FormItem,
|
|
160
|
+
FormLabel,
|
|
161
|
+
FormMessage,
|
|
162
|
+
useFormField,
|
|
163
163
|
};
|
|
@@ -6,39 +6,39 @@ import type * as React from "react";
|
|
|
6
6
|
import { cn } from "@/lib/utils";
|
|
7
7
|
|
|
8
8
|
function HoverCard({
|
|
9
|
-
|
|
9
|
+
...props
|
|
10
10
|
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
|
|
11
|
-
|
|
11
|
+
return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function HoverCardTrigger({
|
|
15
|
-
|
|
15
|
+
...props
|
|
16
16
|
}: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return (
|
|
18
|
+
<HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
|
|
19
|
+
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function HoverCardContent({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
className,
|
|
24
|
+
align = "center",
|
|
25
|
+
sideOffset = 4,
|
|
26
|
+
...props
|
|
27
27
|
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
return (
|
|
29
|
+
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
|
|
30
|
+
<HoverCardPrimitive.Content
|
|
31
|
+
align={align}
|
|
32
|
+
className={cn(
|
|
33
|
+
"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 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[state=closed]:animate-out data-[state=open]:animate-in",
|
|
34
|
+
className,
|
|
35
|
+
)}
|
|
36
|
+
data-slot="hover-card-content"
|
|
37
|
+
sideOffset={sideOffset}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
</HoverCardPrimitive.Portal>
|
|
41
|
+
);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export { HoverCard,
|
|
44
|
+
export { HoverCard, HoverCardContent, HoverCardTrigger };
|