@weirdfingers/baseboards 0.6.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/index.js +54 -28
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/templates/README.md +2 -0
  5. package/templates/api/.env.example +3 -0
  6. package/templates/api/config/generators.yaml +58 -0
  7. package/templates/api/pyproject.toml +1 -1
  8. package/templates/api/src/boards/__init__.py +1 -1
  9. package/templates/api/src/boards/api/endpoints/storage.py +85 -4
  10. package/templates/api/src/boards/api/endpoints/uploads.py +1 -2
  11. package/templates/api/src/boards/database/connection.py +98 -58
  12. package/templates/api/src/boards/generators/implementations/fal/audio/__init__.py +4 -0
  13. package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_text_to_speech.py +176 -0
  14. package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_tts_turbo.py +195 -0
  15. package/templates/api/src/boards/generators/implementations/fal/image/__init__.py +14 -0
  16. package/templates/api/src/boards/generators/implementations/fal/image/bytedance_seedream_v45_edit.py +219 -0
  17. package/templates/api/src/boards/generators/implementations/fal/image/gemini_25_flash_image_edit.py +208 -0
  18. package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_15_edit.py +216 -0
  19. package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_1_5.py +177 -0
  20. package/templates/api/src/boards/generators/implementations/fal/image/reve_edit.py +178 -0
  21. package/templates/api/src/boards/generators/implementations/fal/image/reve_text_to_image.py +155 -0
  22. package/templates/api/src/boards/generators/implementations/fal/image/seedream_v45_text_to_image.py +180 -0
  23. package/templates/api/src/boards/generators/implementations/fal/video/__init__.py +18 -0
  24. package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_pro.py +168 -0
  25. package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_standard.py +159 -0
  26. package/templates/api/src/boards/generators/implementations/fal/video/veed_fabric_1_0.py +180 -0
  27. package/templates/api/src/boards/generators/implementations/fal/video/veo31.py +190 -0
  28. package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast.py +190 -0
  29. package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast_image_to_video.py +191 -0
  30. package/templates/api/src/boards/generators/implementations/fal/video/veo31_first_last_frame_to_video.py +13 -6
  31. package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_image_to_video.py +212 -0
  32. package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_text_to_video.py +208 -0
  33. package/templates/api/src/boards/generators/implementations/kie/__init__.py +11 -0
  34. package/templates/api/src/boards/generators/implementations/kie/base.py +316 -0
  35. package/templates/api/src/boards/generators/implementations/kie/image/__init__.py +3 -0
  36. package/templates/api/src/boards/generators/implementations/kie/image/nano_banana_edit.py +190 -0
  37. package/templates/api/src/boards/generators/implementations/kie/utils.py +98 -0
  38. package/templates/api/src/boards/generators/implementations/kie/video/__init__.py +8 -0
  39. package/templates/api/src/boards/generators/implementations/kie/video/veo3.py +161 -0
  40. package/templates/api/src/boards/graphql/resolvers/upload.py +1 -1
  41. package/templates/web/package.json +4 -1
  42. package/templates/web/src/app/boards/[boardId]/page.tsx +156 -24
  43. package/templates/web/src/app/globals.css +3 -0
  44. package/templates/web/src/app/layout.tsx +15 -5
  45. package/templates/web/src/components/boards/ArtifactInputSlots.tsx +9 -9
  46. package/templates/web/src/components/boards/ArtifactPreview.tsx +34 -18
  47. package/templates/web/src/components/boards/GenerationGrid.tsx +101 -7
  48. package/templates/web/src/components/boards/GenerationInput.tsx +21 -21
  49. package/templates/web/src/components/boards/GeneratorSelector.tsx +232 -30
  50. package/templates/web/src/components/boards/UploadArtifact.tsx +385 -75
  51. package/templates/web/src/components/header.tsx +3 -1
  52. package/templates/web/src/components/theme-provider.tsx +10 -0
  53. package/templates/web/src/components/theme-toggle.tsx +75 -0
  54. package/templates/web/src/components/ui/alert-dialog.tsx +157 -0
  55. package/templates/web/src/components/ui/toast.tsx +128 -0
  56. package/templates/web/src/components/ui/toaster.tsx +35 -0
  57. package/templates/web/src/components/ui/use-toast.ts +186 -0
@@ -0,0 +1,75 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Moon, Sun, Monitor } from "lucide-react";
5
+ import { useTheme } from "next-themes";
6
+
7
+ import {
8
+ DropdownMenu,
9
+ DropdownMenuContent,
10
+ DropdownMenuItem,
11
+ DropdownMenuTrigger,
12
+ } from "@/components/ui/dropdown-menu";
13
+
14
+ export function ThemeToggle() {
15
+ const { theme, setTheme } = useTheme();
16
+ const [mounted, setMounted] = React.useState(false);
17
+
18
+ // useEffect only runs on the client, so now we can safely show the UI
19
+ React.useEffect(() => {
20
+ setMounted(true);
21
+ }, []);
22
+
23
+ if (!mounted) {
24
+ return (
25
+ <button className="inline-flex items-center justify-center w-9 h-9 rounded-md hover:bg-accent hover:text-accent-foreground">
26
+ <Sun className="h-[1.2rem] w-[1.2rem]" />
27
+ <span className="sr-only">Toggle theme</span>
28
+ </button>
29
+ );
30
+ }
31
+
32
+ return (
33
+ <DropdownMenu>
34
+ <DropdownMenuTrigger asChild>
35
+ <button className="inline-flex items-center justify-center w-9 h-9 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
36
+ <Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
37
+ <Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
38
+ <span className="sr-only">Toggle theme</span>
39
+ </button>
40
+ </DropdownMenuTrigger>
41
+ <DropdownMenuContent align="end">
42
+ <DropdownMenuItem
43
+ onClick={() => setTheme("light")}
44
+ className="cursor-pointer"
45
+ >
46
+ <Sun className="mr-2 h-4 w-4" />
47
+ <span>Light</span>
48
+ {theme === "light" && (
49
+ <span className="ml-auto text-xs">✓</span>
50
+ )}
51
+ </DropdownMenuItem>
52
+ <DropdownMenuItem
53
+ onClick={() => setTheme("dark")}
54
+ className="cursor-pointer"
55
+ >
56
+ <Moon className="mr-2 h-4 w-4" />
57
+ <span>Dark</span>
58
+ {theme === "dark" && (
59
+ <span className="ml-auto text-xs">✓</span>
60
+ )}
61
+ </DropdownMenuItem>
62
+ <DropdownMenuItem
63
+ onClick={() => setTheme("system")}
64
+ className="cursor-pointer"
65
+ >
66
+ <Monitor className="mr-2 h-4 w-4" />
67
+ <span>System</span>
68
+ {theme === "system" && (
69
+ <span className="ml-auto text-xs">✓</span>
70
+ )}
71
+ </DropdownMenuItem>
72
+ </DropdownMenuContent>
73
+ </DropdownMenu>
74
+ );
75
+ }
@@ -0,0 +1,157 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
5
+
6
+ import { cn } from "@/lib/utils"
7
+ import { buttonVariants } from "@/components/ui/button"
8
+
9
+ function AlertDialog({
10
+ ...props
11
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
12
+ return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
13
+ }
14
+
15
+ function AlertDialogTrigger({
16
+ ...props
17
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
18
+ return (
19
+ <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
20
+ )
21
+ }
22
+
23
+ function AlertDialogPortal({
24
+ ...props
25
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
26
+ return (
27
+ <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
28
+ )
29
+ }
30
+
31
+ function AlertDialogOverlay({
32
+ className,
33
+ ...props
34
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
35
+ return (
36
+ <AlertDialogPrimitive.Overlay
37
+ data-slot="alert-dialog-overlay"
38
+ className={cn(
39
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
40
+ className
41
+ )}
42
+ {...props}
43
+ />
44
+ )
45
+ }
46
+
47
+ function AlertDialogContent({
48
+ className,
49
+ ...props
50
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
51
+ return (
52
+ <AlertDialogPortal>
53
+ <AlertDialogOverlay />
54
+ <AlertDialogPrimitive.Content
55
+ data-slot="alert-dialog-content"
56
+ className={cn(
57
+ "bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
58
+ className
59
+ )}
60
+ {...props}
61
+ />
62
+ </AlertDialogPortal>
63
+ )
64
+ }
65
+
66
+ function AlertDialogHeader({
67
+ className,
68
+ ...props
69
+ }: React.ComponentProps<"div">) {
70
+ return (
71
+ <div
72
+ data-slot="alert-dialog-header"
73
+ className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
74
+ {...props}
75
+ />
76
+ )
77
+ }
78
+
79
+ function AlertDialogFooter({
80
+ className,
81
+ ...props
82
+ }: React.ComponentProps<"div">) {
83
+ return (
84
+ <div
85
+ data-slot="alert-dialog-footer"
86
+ className={cn(
87
+ "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
88
+ className
89
+ )}
90
+ {...props}
91
+ />
92
+ )
93
+ }
94
+
95
+ function AlertDialogTitle({
96
+ className,
97
+ ...props
98
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
99
+ return (
100
+ <AlertDialogPrimitive.Title
101
+ data-slot="alert-dialog-title"
102
+ className={cn("text-lg font-semibold", className)}
103
+ {...props}
104
+ />
105
+ )
106
+ }
107
+
108
+ function AlertDialogDescription({
109
+ className,
110
+ ...props
111
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
112
+ return (
113
+ <AlertDialogPrimitive.Description
114
+ data-slot="alert-dialog-description"
115
+ className={cn("text-muted-foreground text-sm", className)}
116
+ {...props}
117
+ />
118
+ )
119
+ }
120
+
121
+ function AlertDialogAction({
122
+ className,
123
+ ...props
124
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
125
+ return (
126
+ <AlertDialogPrimitive.Action
127
+ className={cn(buttonVariants(), className)}
128
+ {...props}
129
+ />
130
+ )
131
+ }
132
+
133
+ function AlertDialogCancel({
134
+ className,
135
+ ...props
136
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
137
+ return (
138
+ <AlertDialogPrimitive.Cancel
139
+ className={cn(buttonVariants({ variant: "outline" }), className)}
140
+ {...props}
141
+ />
142
+ )
143
+ }
144
+
145
+ export {
146
+ AlertDialog,
147
+ AlertDialogPortal,
148
+ AlertDialogOverlay,
149
+ AlertDialogTrigger,
150
+ AlertDialogContent,
151
+ AlertDialogHeader,
152
+ AlertDialogFooter,
153
+ AlertDialogTitle,
154
+ AlertDialogDescription,
155
+ AlertDialogAction,
156
+ AlertDialogCancel,
157
+ }
@@ -0,0 +1,128 @@
1
+ import * as React from "react"
2
+ import * as ToastPrimitives from "@radix-ui/react-toast"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "@/lib/utils"
6
+
7
+ const ToastProvider = ToastPrimitives.Provider
8
+
9
+ const ToastViewport = React.forwardRef<
10
+ React.ElementRef<typeof ToastPrimitives.Viewport>,
11
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
12
+ >(({ className, ...props }, ref) => (
13
+ <ToastPrimitives.Viewport
14
+ ref={ref}
15
+ className={cn(
16
+ "fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
17
+ className
18
+ )}
19
+ {...props}
20
+ />
21
+ ))
22
+ ToastViewport.displayName = ToastPrimitives.Viewport.displayName
23
+
24
+ const toastVariants = cva(
25
+ "group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
26
+ {
27
+ variants: {
28
+ variant: {
29
+ default: "border bg-background text-foreground",
30
+ destructive:
31
+ "destructive group border-destructive bg-destructive text-destructive-foreground",
32
+ },
33
+ },
34
+ defaultVariants: {
35
+ variant: "default",
36
+ },
37
+ }
38
+ )
39
+
40
+ const Toast = React.forwardRef<
41
+ React.ElementRef<typeof ToastPrimitives.Root>,
42
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
43
+ VariantProps<typeof toastVariants>
44
+ >(({ className, variant, ...props }, ref) => {
45
+ return (
46
+ <ToastPrimitives.Root
47
+ ref={ref}
48
+ className={cn(toastVariants({ variant }), className)}
49
+ {...props}
50
+ />
51
+ )
52
+ })
53
+ Toast.displayName = ToastPrimitives.Root.displayName
54
+
55
+ const ToastAction = React.forwardRef<
56
+ React.ElementRef<typeof ToastPrimitives.Action>,
57
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
58
+ >(({ className, ...props }, ref) => (
59
+ <ToastPrimitives.Action
60
+ ref={ref}
61
+ className={cn(
62
+ "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-muted focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/40 group-[.destructive]:hover:border-destructive/60 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
63
+ className
64
+ )}
65
+ {...props}
66
+ />
67
+ ))
68
+ ToastAction.displayName = ToastPrimitives.Action.displayName
69
+
70
+ const ToastClose = React.forwardRef<
71
+ React.ElementRef<typeof ToastPrimitives.Close>,
72
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
73
+ >(({ className, ...props }, ref) => (
74
+ <ToastPrimitives.Close
75
+ ref={ref}
76
+ className={cn(
77
+ "absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-destructive-foreground/70 group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive group-[.destructive]:focus:ring-offset-destructive",
78
+ className
79
+ )}
80
+ toast-close=""
81
+ {...props}
82
+ >
83
+ <svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
84
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
85
+ </svg>
86
+ </ToastPrimitives.Close>
87
+ ))
88
+ ToastClose.displayName = ToastPrimitives.Close.displayName
89
+
90
+ const ToastTitle = React.forwardRef<
91
+ React.ElementRef<typeof ToastPrimitives.Title>,
92
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
93
+ >(({ className, ...props }, ref) => (
94
+ <ToastPrimitives.Title
95
+ ref={ref}
96
+ className={cn("text-sm font-semibold", className)}
97
+ {...props}
98
+ />
99
+ ))
100
+ ToastTitle.displayName = ToastPrimitives.Title.displayName
101
+
102
+ const ToastDescription = React.forwardRef<
103
+ React.ElementRef<typeof ToastPrimitives.Description>,
104
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
105
+ >(({ className, ...props }, ref) => (
106
+ <ToastPrimitives.Description
107
+ ref={ref}
108
+ className={cn("text-sm opacity-90", className)}
109
+ {...props}
110
+ />
111
+ ))
112
+ ToastDescription.displayName = ToastPrimitives.Description.displayName
113
+
114
+ type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
115
+
116
+ type ToastActionElement = React.ReactElement<typeof ToastAction>
117
+
118
+ export {
119
+ type ToastProps,
120
+ type ToastActionElement,
121
+ ToastProvider,
122
+ ToastViewport,
123
+ Toast,
124
+ ToastTitle,
125
+ ToastDescription,
126
+ ToastClose,
127
+ ToastAction,
128
+ }
@@ -0,0 +1,35 @@
1
+ "use client"
2
+
3
+ import {
4
+ Toast,
5
+ ToastClose,
6
+ ToastDescription,
7
+ ToastProvider,
8
+ ToastTitle,
9
+ ToastViewport,
10
+ } from "@/components/ui/toast"
11
+ import { useToast } from "@/components/ui/use-toast"
12
+
13
+ export function Toaster() {
14
+ const { toasts } = useToast()
15
+
16
+ return (
17
+ <ToastProvider>
18
+ {toasts.map(function ({ id, title, description, action, ...props }) {
19
+ return (
20
+ <Toast key={id} {...props}>
21
+ <div className="grid gap-1">
22
+ {title && <ToastTitle>{title}</ToastTitle>}
23
+ {description && (
24
+ <ToastDescription>{description}</ToastDescription>
25
+ )}
26
+ </div>
27
+ {action}
28
+ <ToastClose />
29
+ </Toast>
30
+ )
31
+ })}
32
+ <ToastViewport />
33
+ </ToastProvider>
34
+ )
35
+ }
@@ -0,0 +1,186 @@
1
+ import * as React from "react"
2
+
3
+ import type { ToastActionElement, ToastProps } from "@/components/ui/toast"
4
+
5
+ const TOAST_LIMIT = 5
6
+ const TOAST_REMOVE_DELAY = 1000000
7
+
8
+ type ToasterToast = ToastProps & {
9
+ id: string
10
+ title?: React.ReactNode
11
+ description?: React.ReactNode
12
+ action?: ToastActionElement
13
+ }
14
+
15
+ const actionTypes = {
16
+ ADD_TOAST: "ADD_TOAST",
17
+ UPDATE_TOAST: "UPDATE_TOAST",
18
+ DISMISS_TOAST: "DISMISS_TOAST",
19
+ REMOVE_TOAST: "REMOVE_TOAST",
20
+ } as const
21
+
22
+ let count = 0
23
+
24
+ function genId() {
25
+ count = (count + 1) % Number.MAX_SAFE_INTEGER
26
+ return count.toString()
27
+ }
28
+
29
+ type ActionType = typeof actionTypes
30
+
31
+ type Action =
32
+ | {
33
+ type: ActionType["ADD_TOAST"]
34
+ toast: ToasterToast
35
+ }
36
+ | {
37
+ type: ActionType["UPDATE_TOAST"]
38
+ toast: Partial<ToasterToast>
39
+ }
40
+ | {
41
+ type: ActionType["DISMISS_TOAST"]
42
+ toastId?: ToasterToast["id"]
43
+ }
44
+ | {
45
+ type: ActionType["REMOVE_TOAST"]
46
+ toastId?: ToasterToast["id"]
47
+ }
48
+
49
+ interface State {
50
+ toasts: ToasterToast[]
51
+ }
52
+
53
+ const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
54
+
55
+ const addToRemoveQueue = (toastId: string) => {
56
+ if (toastTimeouts.has(toastId)) {
57
+ return
58
+ }
59
+
60
+ const timeout = setTimeout(() => {
61
+ toastTimeouts.delete(toastId)
62
+ dispatch({
63
+ type: "REMOVE_TOAST",
64
+ toastId: toastId,
65
+ })
66
+ }, TOAST_REMOVE_DELAY)
67
+
68
+ toastTimeouts.set(toastId, timeout)
69
+ }
70
+
71
+ export const reducer = (state: State, action: Action): State => {
72
+ switch (action.type) {
73
+ case "ADD_TOAST":
74
+ return {
75
+ ...state,
76
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
77
+ }
78
+
79
+ case "UPDATE_TOAST":
80
+ return {
81
+ ...state,
82
+ toasts: state.toasts.map((t) =>
83
+ t.id === action.toast.id ? { ...t, ...action.toast } : t
84
+ ),
85
+ }
86
+
87
+ case "DISMISS_TOAST": {
88
+ const { toastId } = action
89
+
90
+ if (toastId) {
91
+ addToRemoveQueue(toastId)
92
+ } else {
93
+ state.toasts.forEach((toast) => {
94
+ addToRemoveQueue(toast.id)
95
+ })
96
+ }
97
+
98
+ return {
99
+ ...state,
100
+ toasts: state.toasts.map((t) =>
101
+ t.id === toastId || toastId === undefined
102
+ ? {
103
+ ...t,
104
+ open: false,
105
+ }
106
+ : t
107
+ ),
108
+ }
109
+ }
110
+ case "REMOVE_TOAST":
111
+ if (action.toastId === undefined) {
112
+ return {
113
+ ...state,
114
+ toasts: [],
115
+ }
116
+ }
117
+ return {
118
+ ...state,
119
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
120
+ }
121
+ }
122
+ }
123
+
124
+ const listeners: Array<(state: State) => void> = []
125
+
126
+ let memoryState: State = { toasts: [] }
127
+
128
+ function dispatch(action: Action) {
129
+ memoryState = reducer(memoryState, action)
130
+ listeners.forEach((listener) => {
131
+ listener(memoryState)
132
+ })
133
+ }
134
+
135
+ interface Toast extends Omit<ToasterToast, "id"> {}
136
+
137
+ function toast({ ...props }: Toast) {
138
+ const id = genId()
139
+
140
+ const update = (props: ToasterToast) =>
141
+ dispatch({
142
+ type: "UPDATE_TOAST",
143
+ toast: { ...props, id },
144
+ })
145
+ const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
146
+
147
+ dispatch({
148
+ type: "ADD_TOAST",
149
+ toast: {
150
+ ...props,
151
+ id,
152
+ open: true,
153
+ onOpenChange: (open) => {
154
+ if (!open) dismiss()
155
+ },
156
+ },
157
+ })
158
+
159
+ return {
160
+ id: id,
161
+ dismiss,
162
+ update,
163
+ }
164
+ }
165
+
166
+ function useToast() {
167
+ const [state, setState] = React.useState<State>(memoryState)
168
+
169
+ React.useEffect(() => {
170
+ listeners.push(setState)
171
+ return () => {
172
+ const index = listeners.indexOf(setState)
173
+ if (index > -1) {
174
+ listeners.splice(index, 1)
175
+ }
176
+ }
177
+ }, [state])
178
+
179
+ return {
180
+ ...state,
181
+ toast,
182
+ dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
183
+ }
184
+ }
185
+
186
+ export { useToast, toast }