+
+ {isApiKeysPending && selectedProject && (
+
Loading API keys...
+ )}
+ {isApiKeysError && selectedProject && (
+
Failed to load API keys for this project.
+ )}
+ {missingAnonKey && selectedProject && (
+
+ This project does not have an anon key. Please enable the anon key in your project's
+ API settings to use this block.
+
+ )}
+
+ )
+}
diff --git a/apps/ui-library/components/tanstack-db-generator/index.tsx b/apps/ui-library/components/tanstack-db-generator/index.tsx
new file mode 100644
index 00000000000..586cfd06576
--- /dev/null
+++ b/apps/ui-library/components/tanstack-db-generator/index.tsx
@@ -0,0 +1,152 @@
+'use client'
+
+import { useIsLoggedIn, useIsUserLoading } from 'common'
+import { Check, Copy, Loader2 } from 'lucide-react'
+import { useCallback, useState } from 'react'
+import {
+ Button,
+ cn,
+ copyToClipboard,
+ Tabs_Shadcn_ as Tabs,
+ TabsContent_Shadcn_ as TabsContent,
+ TabsList_Shadcn_ as TabsList,
+ TabsTrigger_Shadcn_ as TabsTrigger,
+} from 'ui'
+
+import { useLocalStorage } from '../use-local-storage'
+import { ProjectPicker } from './ProjectPicker'
+
+type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'
+
+const LOCAL_STORAGE_KEY = 'package-manager-tanstack-db'
+
+const getBaseUrl = () => {
+ if (process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV === 'production') {
+ return 'https://supabase.com/ui'
+ } else if (process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV === 'preview') {
+ return `https://${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL}`
+ } else {
+ return 'http://localhost:3004/ui'
+ }
+}
+
+export function TanstackDBGenerator() {
+ const isUserLoading = useIsUserLoading()
+ const isLoggedIn = useIsLoggedIn()
+
+ const [resolvedProject, setResolvedProject] = useState<{
+ projectRef: string
+ anonKey: string
+ } | null>(null)
+ const [hasCopied, setHasCopied] = useState(false)
+ const [packageManager, setPackageManager] = useLocalStorage(LOCAL_STORAGE_KEY, 'npm')
+
+ const handleProjectResolved = useCallback(
+ (data: { projectRef: string; anonKey: string } | null) => {
+ setResolvedProject(data)
+ },
+ []
+ )
+
+ const baseUrl = getBaseUrl()
+ const apiUrl = resolvedProject
+ ? `${baseUrl}${process.env.NEXT_PUBLIC_BASE_PATH ?? ''}/api/registry/tanstack-db?ref=${encodeURIComponent(resolvedProject.projectRef)}&anonKey=${encodeURIComponent(resolvedProject.anonKey)}`
+ : ''
+
+ const commands: Record