create-sidekick-app 0.0.0-stage → 2.0.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 +202 -0
- package/NOTICE +27 -0
- package/README.md +30 -2
- package/dist/index.js +59 -0
- package/package.json +69 -3
- package/template/base/ai-chat/.env.example +6 -0
- package/template/base/ai-chat/.prettierignore +2 -0
- package/template/base/ai-chat/.prettierrc.json +5 -0
- package/template/base/ai-chat/README.md +38 -0
- package/template/base/ai-chat/_gitignore +41 -0
- package/template/base/ai-chat/components.json +23 -0
- package/template/base/ai-chat/next.config.ts +5 -0
- package/template/base/ai-chat/package.json +61 -0
- package/template/base/ai-chat/postcss.config.mjs +5 -0
- package/template/base/ai-chat/src/app/api/chat/route.ts +141 -0
- package/template/base/ai-chat/src/app/api/instant/route.ts +5 -0
- package/template/base/ai-chat/src/app/chat/[id]/page.tsx +20 -0
- package/template/base/ai-chat/src/app/globals.css +124 -0
- package/template/base/ai-chat/src/app/layout.tsx +34 -0
- package/template/base/ai-chat/src/app/page.tsx +6 -0
- package/template/base/ai-chat/src/components/AuthGate.tsx +15 -0
- package/template/base/ai-chat/src/components/Chat.tsx +228 -0
- package/template/base/ai-chat/src/components/InstantProvider.tsx +18 -0
- package/template/base/ai-chat/src/components/Login.tsx +163 -0
- package/template/base/ai-chat/src/components/Sidebar.tsx +100 -0
- package/template/base/ai-chat/src/components/ai-elements/agent.tsx +142 -0
- package/template/base/ai-chat/src/components/ai-elements/artifact.tsx +149 -0
- package/template/base/ai-chat/src/components/ai-elements/attachments.tsx +427 -0
- package/template/base/ai-chat/src/components/ai-elements/audio-player.tsx +229 -0
- package/template/base/ai-chat/src/components/ai-elements/canvas.tsx +26 -0
- package/template/base/ai-chat/src/components/ai-elements/chain-of-thought.tsx +223 -0
- package/template/base/ai-chat/src/components/ai-elements/checkpoint.tsx +72 -0
- package/template/base/ai-chat/src/components/ai-elements/code-block.tsx +556 -0
- package/template/base/ai-chat/src/components/ai-elements/commit.tsx +449 -0
- package/template/base/ai-chat/src/components/ai-elements/confirmation.tsx +173 -0
- package/template/base/ai-chat/src/components/ai-elements/connection.tsx +28 -0
- package/template/base/ai-chat/src/components/ai-elements/context.tsx +410 -0
- package/template/base/ai-chat/src/components/ai-elements/controls.tsx +19 -0
- package/template/base/ai-chat/src/components/ai-elements/conversation.tsx +167 -0
- package/template/base/ai-chat/src/components/ai-elements/edge.tsx +144 -0
- package/template/base/ai-chat/src/components/ai-elements/environment-variables.tsx +325 -0
- package/template/base/ai-chat/src/components/ai-elements/file-tree.tsx +298 -0
- package/template/base/ai-chat/src/components/ai-elements/image.tsx +25 -0
- package/template/base/ai-chat/src/components/ai-elements/inline-citation.tsx +294 -0
- package/template/base/ai-chat/src/components/ai-elements/jsx-preview.tsx +250 -0
- package/template/base/ai-chat/src/components/ai-elements/message.tsx +356 -0
- package/template/base/ai-chat/src/components/ai-elements/mic-selector.tsx +372 -0
- package/template/base/ai-chat/src/components/ai-elements/model-selector.tsx +214 -0
- package/template/base/ai-chat/src/components/ai-elements/node.tsx +72 -0
- package/template/base/ai-chat/src/components/ai-elements/open-in-chat.tsx +367 -0
- package/template/base/ai-chat/src/components/ai-elements/package-info.tsx +235 -0
- package/template/base/ai-chat/src/components/ai-elements/panel.tsx +16 -0
- package/template/base/ai-chat/src/components/ai-elements/persona.tsx +280 -0
- package/template/base/ai-chat/src/components/ai-elements/plan.tsx +144 -0
- package/template/base/ai-chat/src/components/ai-elements/prompt-input.tsx +1341 -0
- package/template/base/ai-chat/src/components/ai-elements/queue.tsx +275 -0
- package/template/base/ai-chat/src/components/ai-elements/reasoning.tsx +229 -0
- package/template/base/ai-chat/src/components/ai-elements/sandbox.tsx +128 -0
- package/template/base/ai-chat/src/components/ai-elements/schema-display.tsx +473 -0
- package/template/base/ai-chat/src/components/ai-elements/shimmer.tsx +78 -0
- package/template/base/ai-chat/src/components/ai-elements/snippet.tsx +141 -0
- package/template/base/ai-chat/src/components/ai-elements/sources.tsx +78 -0
- package/template/base/ai-chat/src/components/ai-elements/speech-input.tsx +324 -0
- package/template/base/ai-chat/src/components/ai-elements/stack-trace.tsx +531 -0
- package/template/base/ai-chat/src/components/ai-elements/suggestion.tsx +55 -0
- package/template/base/ai-chat/src/components/ai-elements/task.tsx +88 -0
- package/template/base/ai-chat/src/components/ai-elements/terminal.tsx +277 -0
- package/template/base/ai-chat/src/components/ai-elements/test-results.tsx +497 -0
- package/template/base/ai-chat/src/components/ai-elements/tool.tsx +174 -0
- package/template/base/ai-chat/src/components/ai-elements/toolbar.tsx +17 -0
- package/template/base/ai-chat/src/components/ai-elements/transcription.tsx +126 -0
- package/template/base/ai-chat/src/components/ai-elements/voice-selector.tsx +525 -0
- package/template/base/ai-chat/src/components/ai-elements/web-preview.tsx +282 -0
- package/template/base/ai-chat/src/components/ui/accordion.tsx +66 -0
- package/template/base/ai-chat/src/components/ui/alert.tsx +66 -0
- package/template/base/ai-chat/src/components/ui/avatar.tsx +109 -0
- package/template/base/ai-chat/src/components/ui/badge.tsx +48 -0
- package/template/base/ai-chat/src/components/ui/button-group.tsx +83 -0
- package/template/base/ai-chat/src/components/ui/button.tsx +64 -0
- package/template/base/ai-chat/src/components/ui/card.tsx +92 -0
- package/template/base/ai-chat/src/components/ui/carousel.tsx +241 -0
- package/template/base/ai-chat/src/components/ui/collapsible.tsx +33 -0
- package/template/base/ai-chat/src/components/ui/command.tsx +184 -0
- package/template/base/ai-chat/src/components/ui/dialog.tsx +158 -0
- package/template/base/ai-chat/src/components/ui/dropdown-menu.tsx +257 -0
- package/template/base/ai-chat/src/components/ui/hover-card.tsx +44 -0
- package/template/base/ai-chat/src/components/ui/input-group.tsx +170 -0
- package/template/base/ai-chat/src/components/ui/input.tsx +21 -0
- package/template/base/ai-chat/src/components/ui/popover.tsx +89 -0
- package/template/base/ai-chat/src/components/ui/progress.tsx +31 -0
- package/template/base/ai-chat/src/components/ui/scroll-area.tsx +58 -0
- package/template/base/ai-chat/src/components/ui/select.tsx +190 -0
- package/template/base/ai-chat/src/components/ui/separator.tsx +28 -0
- package/template/base/ai-chat/src/components/ui/spinner.tsx +16 -0
- package/template/base/ai-chat/src/components/ui/switch.tsx +35 -0
- package/template/base/ai-chat/src/components/ui/tabs.tsx +91 -0
- package/template/base/ai-chat/src/components/ui/textarea.tsx +18 -0
- package/template/base/ai-chat/src/components/ui/tooltip.tsx +57 -0
- package/template/base/ai-chat/src/instant.perms.ts +34 -0
- package/template/base/ai-chat/src/instant.schema.ts +107 -0
- package/template/base/ai-chat/src/lib/adminDb.ts +8 -0
- package/template/base/ai-chat/src/lib/db.ts +8 -0
- package/template/base/ai-chat/src/lib/mockModel.ts +119 -0
- package/template/base/ai-chat/src/lib/utils.ts +6 -0
- package/template/base/ai-chat/tsconfig.json +33 -0
- package/template/base/bun-react/.env.example +2 -0
- package/template/base/bun-react/README.md +12 -0
- package/template/base/bun-react/_gitignore +34 -0
- package/template/base/bun-react/bun-env.d.ts +17 -0
- package/template/base/bun-react/bunfig.toml +4 -0
- package/template/base/bun-react/package.json +22 -0
- package/template/base/bun-react/src/App.tsx +168 -0
- package/template/base/bun-react/src/frontend.tsx +20 -0
- package/template/base/bun-react/src/getUnusedPort.ts +32 -0
- package/template/base/bun-react/src/index.css +25 -0
- package/template/base/bun-react/src/index.html +13 -0
- package/template/base/bun-react/src/index.ts +21 -0
- package/template/base/bun-react/src/instant.perms.ts +24 -0
- package/template/base/bun-react/src/instant.schema.ts +46 -0
- package/template/base/bun-react/src/lib/db.ts +8 -0
- package/template/base/bun-react/src/logo.svg +1 -0
- package/template/base/bun-react/tsconfig.json +36 -0
- package/template/base/expo/.env.example +2 -0
- package/template/base/expo/README.md +18 -0
- package/template/base/expo/_gitignore +41 -0
- package/template/base/expo/app/+not-found.tsx +16 -0
- package/template/base/expo/app/_layout.tsx +37 -0
- package/template/base/expo/app/index.tsx +64 -0
- package/template/base/expo/app.json +42 -0
- package/template/base/expo/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/template/base/expo/assets/images/adaptive-icon.png +0 -0
- package/template/base/expo/assets/images/favicon.png +0 -0
- package/template/base/expo/assets/images/icon.png +0 -0
- package/template/base/expo/assets/images/partial-react-logo.png +0 -0
- package/template/base/expo/assets/images/react-logo.png +0 -0
- package/template/base/expo/assets/images/react-logo@2x.png +0 -0
- package/template/base/expo/assets/images/react-logo@3x.png +0 -0
- package/template/base/expo/assets/images/splash-icon.png +0 -0
- package/template/base/expo/babel.config.js +12 -0
- package/template/base/expo/constants/Colors.ts +26 -0
- package/template/base/expo/eslint.config.js +10 -0
- package/template/base/expo/global.css +3 -0
- package/template/base/expo/hooks/useColorScheme.ts +1 -0
- package/template/base/expo/hooks/useColorScheme.web.ts +21 -0
- package/template/base/expo/hooks/useThemeColor.ts +21 -0
- package/template/base/expo/instant.perms.ts +24 -0
- package/template/base/expo/instant.schema.ts +44 -0
- package/template/base/expo/lib/db.ts +7 -0
- package/template/base/expo/metro.config.js +6 -0
- package/template/base/expo/nativewind-env.d.ts +1 -0
- package/template/base/expo/package.json +57 -0
- package/template/base/expo/scripts/reset-project.js +112 -0
- package/template/base/expo/tailwind.config.js +9 -0
- package/template/base/expo/tsconfig.json +18 -0
- package/template/base/next-js-app-dir/.env.example +2 -0
- package/template/base/next-js-app-dir/README.md +18 -0
- package/template/base/next-js-app-dir/_gitignore +41 -0
- package/template/base/next-js-app-dir/next.config.ts +7 -0
- package/template/base/next-js-app-dir/package.json +27 -0
- package/template/base/next-js-app-dir/postcss.config.mjs +5 -0
- package/template/base/next-js-app-dir/public/file.svg +1 -0
- package/template/base/next-js-app-dir/public/globe.svg +1 -0
- package/template/base/next-js-app-dir/public/next.svg +1 -0
- package/template/base/next-js-app-dir/public/vercel.svg +1 -0
- package/template/base/next-js-app-dir/public/window.svg +1 -0
- package/template/base/next-js-app-dir/src/app/favicon.ico +0 -0
- package/template/base/next-js-app-dir/src/app/globals.css +26 -0
- package/template/base/next-js-app-dir/src/app/layout.tsx +34 -0
- package/template/base/next-js-app-dir/src/app/page.tsx +169 -0
- package/template/base/next-js-app-dir/src/instant.perms.ts +24 -0
- package/template/base/next-js-app-dir/src/instant.schema.ts +50 -0
- package/template/base/next-js-app-dir/src/lib/db.ts +8 -0
- package/template/base/next-js-app-dir/tsconfig.json +41 -0
- package/template/base/solidjs-vite/README.md +15 -0
- package/template/base/solidjs-vite/_gitignore +25 -0
- package/template/base/solidjs-vite/index.html +15 -0
- package/template/base/solidjs-vite/package.json +25 -0
- package/template/base/solidjs-vite/src/App.tsx +171 -0
- package/template/base/solidjs-vite/src/index.css +25 -0
- package/template/base/solidjs-vite/src/index.tsx +16 -0
- package/template/base/solidjs-vite/src/instant.perms.ts +24 -0
- package/template/base/solidjs-vite/src/instant.schema.ts +46 -0
- package/template/base/solidjs-vite/src/lib/db.ts +8 -0
- package/template/base/solidjs-vite/tsconfig.json +20 -0
- package/template/base/solidjs-vite/vite.config.ts +11 -0
- package/template/base/sveltekit/README.md +15 -0
- package/template/base/sveltekit/_gitignore +26 -0
- package/template/base/sveltekit/package.json +25 -0
- package/template/base/sveltekit/src/app.css +25 -0
- package/template/base/sveltekit/src/app.html +11 -0
- package/template/base/sveltekit/src/instant.perms.ts +24 -0
- package/template/base/sveltekit/src/instant.schema.ts +46 -0
- package/template/base/sveltekit/src/lib/db.ts +8 -0
- package/template/base/sveltekit/src/routes/+layout.svelte +6 -0
- package/template/base/sveltekit/src/routes/+page.svelte +236 -0
- package/template/base/sveltekit/src/routes/+page.ts +1 -0
- package/template/base/sveltekit/svelte.config.js +10 -0
- package/template/base/sveltekit/tsconfig.json +14 -0
- package/template/base/sveltekit/vite.config.ts +7 -0
- package/template/base/tanstack-start/.cta.json +12 -0
- package/template/base/tanstack-start/README.md +17 -0
- package/template/base/tanstack-start/_gitignore +13 -0
- package/template/base/tanstack-start/package.json +43 -0
- package/template/base/tanstack-start/public/favicon.ico +0 -0
- package/template/base/tanstack-start/public/logo192.png +0 -0
- package/template/base/tanstack-start/public/logo512.png +0 -0
- package/template/base/tanstack-start/public/manifest.json +25 -0
- package/template/base/tanstack-start/public/robots.txt +3 -0
- package/template/base/tanstack-start/public/tanstack-circle-logo.png +0 -0
- package/template/base/tanstack-start/public/tanstack-word-logo-white.svg +1 -0
- package/template/base/tanstack-start/src/components/Header.tsx +21 -0
- package/template/base/tanstack-start/src/instant.perms.ts +24 -0
- package/template/base/tanstack-start/src/instant.schema.ts +50 -0
- package/template/base/tanstack-start/src/lib/adminDb.ts +12 -0
- package/template/base/tanstack-start/src/lib/db.ts +9 -0
- package/template/base/tanstack-start/src/logo.svg +12 -0
- package/template/base/tanstack-start/src/routeTree.gen.ts +104 -0
- package/template/base/tanstack-start/src/router.tsx +22 -0
- package/template/base/tanstack-start/src/routes/__root.tsx +70 -0
- package/template/base/tanstack-start/src/routes/api/instant.ts +18 -0
- package/template/base/tanstack-start/src/routes/index.tsx +238 -0
- package/template/base/tanstack-start/src/routes/login.tsx +140 -0
- package/template/base/tanstack-start/src/styles.css +18 -0
- package/template/base/tanstack-start/tsconfig.json +28 -0
- package/template/base/tanstack-start/vite.config.ts +33 -0
- package/template/base/tanstack-start-with-tanstack-query/.cta.json +12 -0
- package/template/base/tanstack-start-with-tanstack-query/README.md +18 -0
- package/template/base/tanstack-start-with-tanstack-query/_gitignore +13 -0
- package/template/base/tanstack-start-with-tanstack-query/package.json +46 -0
- package/template/base/tanstack-start-with-tanstack-query/public/favicon.ico +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/logo192.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/logo512.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/manifest.json +25 -0
- package/template/base/tanstack-start-with-tanstack-query/public/robots.txt +3 -0
- package/template/base/tanstack-start-with-tanstack-query/public/tanstack-circle-logo.png +0 -0
- package/template/base/tanstack-start-with-tanstack-query/public/tanstack-word-logo-white.svg +1 -0
- package/template/base/tanstack-start-with-tanstack-query/src/components/Header.tsx +21 -0
- package/template/base/tanstack-start-with-tanstack-query/src/instant.perms.ts +24 -0
- package/template/base/tanstack-start-with-tanstack-query/src/instant.schema.ts +50 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/adminDb.ts +9 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/db.ts +11 -0
- package/template/base/tanstack-start-with-tanstack-query/src/lib/instantQuery.ts +93 -0
- package/template/base/tanstack-start-with-tanstack-query/src/logo.svg +12 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routeTree.gen.ts +104 -0
- package/template/base/tanstack-start-with-tanstack-query/src/router.tsx +108 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/__root.tsx +76 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/api/instant.ts +16 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/index.tsx +231 -0
- package/template/base/tanstack-start-with-tanstack-query/src/routes/login.tsx +140 -0
- package/template/base/tanstack-start-with-tanstack-query/src/styles.css +17 -0
- package/template/base/tanstack-start-with-tanstack-query/tsconfig.json +28 -0
- package/template/base/tanstack-start-with-tanstack-query/vite.config.ts +33 -0
- package/template/base/vite-react/README.md +16 -0
- package/template/base/vite-react/_gitignore +26 -0
- package/template/base/vite-react/eslint.config.js +23 -0
- package/template/base/vite-react/index.html +13 -0
- package/template/base/vite-react/package.json +35 -0
- package/template/base/vite-react/public/favicon.svg +1 -0
- package/template/base/vite-react/src/App.tsx +167 -0
- package/template/base/vite-react/src/index.css +1 -0
- package/template/base/vite-react/src/instant.perms.ts +24 -0
- package/template/base/vite-react/src/instant.schema.ts +51 -0
- package/template/base/vite-react/src/lib/db.ts +8 -0
- package/template/base/vite-react/src/main.tsx +10 -0
- package/template/base/vite-react/tsconfig.app.json +25 -0
- package/template/base/vite-react/tsconfig.json +7 -0
- package/template/base/vite-react/tsconfig.node.json +24 -0
- package/template/base/vite-react/vite.config.ts +8 -0
- package/template/base/vite-vanilla/.env.example +2 -0
- package/template/base/vite-vanilla/README.md +17 -0
- package/template/base/vite-vanilla/_gitignore +25 -0
- package/template/base/vite-vanilla/index.html +13 -0
- package/template/base/vite-vanilla/package.json +20 -0
- package/template/base/vite-vanilla/pnpm-lock.yaml +707 -0
- package/template/base/vite-vanilla/public/vite.svg +1 -0
- package/template/base/vite-vanilla/src/instant.perms.ts +24 -0
- package/template/base/vite-vanilla/src/instant.schema.ts +50 -0
- package/template/base/vite-vanilla/src/lib/db.ts +11 -0
- package/template/base/vite-vanilla/src/main.ts +242 -0
- package/template/base/vite-vanilla/src/style.css +96 -0
- package/template/base/vite-vanilla/src/typescript.svg +1 -0
- package/template/base/vite-vanilla/src/vite-env.d.ts +1 -0
- package/template/base/vite-vanilla/tsconfig.json +24 -0
- package/template/base/vue-vite/README.md +15 -0
- package/template/base/vue-vite/_gitignore +43 -0
- package/template/base/vue-vite/env.d.ts +1 -0
- package/template/base/vue-vite/index.html +12 -0
- package/template/base/vue-vite/package.json +34 -0
- package/template/base/vue-vite/src/App.vue +238 -0
- package/template/base/vue-vite/src/assets/main.css +25 -0
- package/template/base/vue-vite/src/instant.perms.ts +24 -0
- package/template/base/vue-vite/src/instant.schema.ts +46 -0
- package/template/base/vue-vite/src/lib/db.ts +8 -0
- package/template/base/vue-vite/src/main.ts +6 -0
- package/template/base/vue-vite/tsconfig.app.json +15 -0
- package/template/base/vue-vite/tsconfig.json +11 -0
- package/template/base/vue-vite/tsconfig.node.json +27 -0
- package/template/base/vue-vite/vite.config.ts +16 -0
- package/template/rules/AGENTS.md +436 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, HTMLAttributes } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Badge } from '@/components/ui/badge';
|
|
6
|
+
import {
|
|
7
|
+
Collapsible,
|
|
8
|
+
CollapsibleContent,
|
|
9
|
+
CollapsibleTrigger,
|
|
10
|
+
} from '@/components/ui/collapsible';
|
|
11
|
+
import { cn } from '@/lib/utils';
|
|
12
|
+
import { ChevronRightIcon } from 'lucide-react';
|
|
13
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
14
|
+
|
|
15
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
16
|
+
|
|
17
|
+
interface SchemaParameter {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
description?: string;
|
|
22
|
+
location?: 'path' | 'query' | 'header';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface SchemaProperty {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
description?: string;
|
|
30
|
+
properties?: SchemaProperty[];
|
|
31
|
+
items?: SchemaProperty;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface SchemaDisplayContextType {
|
|
35
|
+
method: HttpMethod;
|
|
36
|
+
path: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
parameters?: SchemaParameter[];
|
|
39
|
+
requestBody?: SchemaProperty[];
|
|
40
|
+
responseBody?: SchemaProperty[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const SchemaDisplayContext = createContext<SchemaDisplayContextType>({
|
|
44
|
+
method: 'GET',
|
|
45
|
+
path: '',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export type SchemaDisplayProps = HTMLAttributes<HTMLDivElement> & {
|
|
49
|
+
method: HttpMethod;
|
|
50
|
+
path: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
parameters?: SchemaParameter[];
|
|
53
|
+
requestBody?: SchemaProperty[];
|
|
54
|
+
responseBody?: SchemaProperty[];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const SchemaDisplay = ({
|
|
58
|
+
method,
|
|
59
|
+
path,
|
|
60
|
+
description,
|
|
61
|
+
parameters,
|
|
62
|
+
requestBody,
|
|
63
|
+
responseBody,
|
|
64
|
+
className,
|
|
65
|
+
children,
|
|
66
|
+
...props
|
|
67
|
+
}: SchemaDisplayProps) => {
|
|
68
|
+
const contextValue = useMemo(
|
|
69
|
+
() => ({
|
|
70
|
+
description,
|
|
71
|
+
method,
|
|
72
|
+
parameters,
|
|
73
|
+
path,
|
|
74
|
+
requestBody,
|
|
75
|
+
responseBody,
|
|
76
|
+
}),
|
|
77
|
+
[description, method, parameters, path, requestBody, responseBody],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<SchemaDisplayContext.Provider value={contextValue}>
|
|
82
|
+
<div
|
|
83
|
+
className={cn(
|
|
84
|
+
'bg-background overflow-hidden rounded-lg border',
|
|
85
|
+
className,
|
|
86
|
+
)}
|
|
87
|
+
{...props}
|
|
88
|
+
>
|
|
89
|
+
{children ?? (
|
|
90
|
+
<>
|
|
91
|
+
<SchemaDisplayHeader>
|
|
92
|
+
<div className="flex items-center gap-3">
|
|
93
|
+
<SchemaDisplayMethod />
|
|
94
|
+
<SchemaDisplayPath />
|
|
95
|
+
</div>
|
|
96
|
+
</SchemaDisplayHeader>
|
|
97
|
+
{description && <SchemaDisplayDescription />}
|
|
98
|
+
<SchemaDisplayContent>
|
|
99
|
+
{parameters && parameters.length > 0 && (
|
|
100
|
+
<SchemaDisplayParameters />
|
|
101
|
+
)}
|
|
102
|
+
{requestBody && requestBody.length > 0 && (
|
|
103
|
+
<SchemaDisplayRequest />
|
|
104
|
+
)}
|
|
105
|
+
{responseBody && responseBody.length > 0 && (
|
|
106
|
+
<SchemaDisplayResponse />
|
|
107
|
+
)}
|
|
108
|
+
</SchemaDisplayContent>
|
|
109
|
+
</>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
</SchemaDisplayContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type SchemaDisplayHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
117
|
+
|
|
118
|
+
export const SchemaDisplayHeader = ({
|
|
119
|
+
className,
|
|
120
|
+
children,
|
|
121
|
+
...props
|
|
122
|
+
}: SchemaDisplayHeaderProps) => (
|
|
123
|
+
<div
|
|
124
|
+
className={cn('flex items-center gap-3 border-b px-4 py-3', className)}
|
|
125
|
+
{...props}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const methodStyles: Record<HttpMethod, string> = {
|
|
132
|
+
DELETE: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400',
|
|
133
|
+
GET: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400',
|
|
134
|
+
PATCH:
|
|
135
|
+
'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400',
|
|
136
|
+
POST: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400',
|
|
137
|
+
PUT: 'bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400',
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type SchemaDisplayMethodProps = ComponentProps<typeof Badge>;
|
|
141
|
+
|
|
142
|
+
export const SchemaDisplayMethod = ({
|
|
143
|
+
className,
|
|
144
|
+
children,
|
|
145
|
+
...props
|
|
146
|
+
}: SchemaDisplayMethodProps) => {
|
|
147
|
+
const { method } = useContext(SchemaDisplayContext);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<Badge
|
|
151
|
+
className={cn('font-mono text-xs', methodStyles[method], className)}
|
|
152
|
+
variant="secondary"
|
|
153
|
+
{...props}
|
|
154
|
+
>
|
|
155
|
+
{children ?? method}
|
|
156
|
+
</Badge>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type SchemaDisplayPathProps = HTMLAttributes<HTMLSpanElement>;
|
|
161
|
+
|
|
162
|
+
export const SchemaDisplayPath = ({
|
|
163
|
+
className,
|
|
164
|
+
children,
|
|
165
|
+
...props
|
|
166
|
+
}: SchemaDisplayPathProps) => {
|
|
167
|
+
const { path } = useContext(SchemaDisplayContext);
|
|
168
|
+
|
|
169
|
+
// Highlight path parameters
|
|
170
|
+
const highlightedPath = path.replaceAll(
|
|
171
|
+
/\{([^}]+)\}/g,
|
|
172
|
+
'<span class="text-blue-600 dark:text-blue-400">{$1}</span>',
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<span
|
|
177
|
+
className={cn('font-mono text-sm', className)}
|
|
178
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: "needed for parameter highlighting"
|
|
179
|
+
// oxlint-disable-next-line eslint-plugin-react(no-danger)
|
|
180
|
+
dangerouslySetInnerHTML={{ __html: children ?? highlightedPath }}
|
|
181
|
+
{...props}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type SchemaDisplayDescriptionProps =
|
|
187
|
+
HTMLAttributes<HTMLParagraphElement>;
|
|
188
|
+
|
|
189
|
+
export const SchemaDisplayDescription = ({
|
|
190
|
+
className,
|
|
191
|
+
children,
|
|
192
|
+
...props
|
|
193
|
+
}: SchemaDisplayDescriptionProps) => {
|
|
194
|
+
const { description } = useContext(SchemaDisplayContext);
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<p
|
|
198
|
+
className={cn(
|
|
199
|
+
'text-muted-foreground border-b px-4 py-3 text-sm',
|
|
200
|
+
className,
|
|
201
|
+
)}
|
|
202
|
+
{...props}
|
|
203
|
+
>
|
|
204
|
+
{children ?? description}
|
|
205
|
+
</p>
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export type SchemaDisplayContentProps = HTMLAttributes<HTMLDivElement>;
|
|
210
|
+
|
|
211
|
+
export const SchemaDisplayContent = ({
|
|
212
|
+
className,
|
|
213
|
+
children,
|
|
214
|
+
...props
|
|
215
|
+
}: SchemaDisplayContentProps) => (
|
|
216
|
+
<div className={cn('divide-y', className)} {...props}>
|
|
217
|
+
{children}
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
export type SchemaDisplayParametersProps = ComponentProps<typeof Collapsible>;
|
|
222
|
+
|
|
223
|
+
export const SchemaDisplayParameters = ({
|
|
224
|
+
className,
|
|
225
|
+
children,
|
|
226
|
+
...props
|
|
227
|
+
}: SchemaDisplayParametersProps) => {
|
|
228
|
+
const { parameters } = useContext(SchemaDisplayContext);
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<Collapsible className={cn(className)} defaultOpen {...props}>
|
|
232
|
+
<CollapsibleTrigger className="group hover:bg-muted/50 flex w-full items-center gap-2 px-4 py-3 text-left transition-colors">
|
|
233
|
+
<ChevronRightIcon className="text-muted-foreground size-4 shrink-0 transition-transform group-data-[state=open]:rotate-90" />
|
|
234
|
+
<span className="text-sm font-medium">Parameters</span>
|
|
235
|
+
<Badge className="ml-auto text-xs" variant="secondary">
|
|
236
|
+
{parameters?.length}
|
|
237
|
+
</Badge>
|
|
238
|
+
</CollapsibleTrigger>
|
|
239
|
+
<CollapsibleContent>
|
|
240
|
+
<div className="divide-y border-t">
|
|
241
|
+
{children ??
|
|
242
|
+
parameters?.map((param) => (
|
|
243
|
+
<SchemaDisplayParameter key={param.name} {...param} />
|
|
244
|
+
))}
|
|
245
|
+
</div>
|
|
246
|
+
</CollapsibleContent>
|
|
247
|
+
</Collapsible>
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export type SchemaDisplayParameterProps = HTMLAttributes<HTMLDivElement> &
|
|
252
|
+
SchemaParameter;
|
|
253
|
+
|
|
254
|
+
export const SchemaDisplayParameter = ({
|
|
255
|
+
name,
|
|
256
|
+
type,
|
|
257
|
+
required,
|
|
258
|
+
description,
|
|
259
|
+
location,
|
|
260
|
+
className,
|
|
261
|
+
...props
|
|
262
|
+
}: SchemaDisplayParameterProps) => (
|
|
263
|
+
<div className={cn('px-4 py-3 pl-10', className)} {...props}>
|
|
264
|
+
<div className="flex items-center gap-2">
|
|
265
|
+
<span className="font-mono text-sm">{name}</span>
|
|
266
|
+
<Badge className="text-xs" variant="outline">
|
|
267
|
+
{type}
|
|
268
|
+
</Badge>
|
|
269
|
+
{location && (
|
|
270
|
+
<Badge className="text-xs" variant="secondary">
|
|
271
|
+
{location}
|
|
272
|
+
</Badge>
|
|
273
|
+
)}
|
|
274
|
+
{required && (
|
|
275
|
+
<Badge
|
|
276
|
+
className="bg-red-100 text-xs text-red-700 dark:bg-red-900/30 dark:text-red-400"
|
|
277
|
+
variant="secondary"
|
|
278
|
+
>
|
|
279
|
+
required
|
|
280
|
+
</Badge>
|
|
281
|
+
)}
|
|
282
|
+
</div>
|
|
283
|
+
{description && (
|
|
284
|
+
<p className="text-muted-foreground mt-1 text-sm">{description}</p>
|
|
285
|
+
)}
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
export type SchemaDisplayRequestProps = ComponentProps<typeof Collapsible>;
|
|
290
|
+
|
|
291
|
+
export const SchemaDisplayRequest = ({
|
|
292
|
+
className,
|
|
293
|
+
children,
|
|
294
|
+
...props
|
|
295
|
+
}: SchemaDisplayRequestProps) => {
|
|
296
|
+
const { requestBody } = useContext(SchemaDisplayContext);
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<Collapsible className={cn(className)} defaultOpen {...props}>
|
|
300
|
+
<CollapsibleTrigger className="group hover:bg-muted/50 flex w-full items-center gap-2 px-4 py-3 text-left transition-colors">
|
|
301
|
+
<ChevronRightIcon className="text-muted-foreground size-4 shrink-0 transition-transform group-data-[state=open]:rotate-90" />
|
|
302
|
+
<span className="text-sm font-medium">Request Body</span>
|
|
303
|
+
</CollapsibleTrigger>
|
|
304
|
+
<CollapsibleContent>
|
|
305
|
+
<div className="border-t">
|
|
306
|
+
{children ??
|
|
307
|
+
requestBody?.map((prop) => (
|
|
308
|
+
<SchemaDisplayProperty key={prop.name} {...prop} depth={0} />
|
|
309
|
+
))}
|
|
310
|
+
</div>
|
|
311
|
+
</CollapsibleContent>
|
|
312
|
+
</Collapsible>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export type SchemaDisplayResponseProps = ComponentProps<typeof Collapsible>;
|
|
317
|
+
|
|
318
|
+
export const SchemaDisplayResponse = ({
|
|
319
|
+
className,
|
|
320
|
+
children,
|
|
321
|
+
...props
|
|
322
|
+
}: SchemaDisplayResponseProps) => {
|
|
323
|
+
const { responseBody } = useContext(SchemaDisplayContext);
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<Collapsible className={cn(className)} defaultOpen {...props}>
|
|
327
|
+
<CollapsibleTrigger className="group hover:bg-muted/50 flex w-full items-center gap-2 px-4 py-3 text-left transition-colors">
|
|
328
|
+
<ChevronRightIcon className="text-muted-foreground size-4 shrink-0 transition-transform group-data-[state=open]:rotate-90" />
|
|
329
|
+
<span className="text-sm font-medium">Response</span>
|
|
330
|
+
</CollapsibleTrigger>
|
|
331
|
+
<CollapsibleContent>
|
|
332
|
+
<div className="border-t">
|
|
333
|
+
{children ??
|
|
334
|
+
responseBody?.map((prop) => (
|
|
335
|
+
<SchemaDisplayProperty key={prop.name} {...prop} depth={0} />
|
|
336
|
+
))}
|
|
337
|
+
</div>
|
|
338
|
+
</CollapsibleContent>
|
|
339
|
+
</Collapsible>
|
|
340
|
+
);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export type SchemaDisplayBodyProps = HTMLAttributes<HTMLDivElement>;
|
|
344
|
+
|
|
345
|
+
export const SchemaDisplayBody = ({
|
|
346
|
+
className,
|
|
347
|
+
children,
|
|
348
|
+
...props
|
|
349
|
+
}: SchemaDisplayBodyProps) => (
|
|
350
|
+
<div className={cn('divide-y', className)} {...props}>
|
|
351
|
+
{children}
|
|
352
|
+
</div>
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
export type SchemaDisplayPropertyProps = HTMLAttributes<HTMLDivElement> &
|
|
356
|
+
SchemaProperty & {
|
|
357
|
+
depth?: number;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export const SchemaDisplayProperty = ({
|
|
361
|
+
name,
|
|
362
|
+
type,
|
|
363
|
+
required,
|
|
364
|
+
description,
|
|
365
|
+
properties,
|
|
366
|
+
items,
|
|
367
|
+
depth = 0,
|
|
368
|
+
className,
|
|
369
|
+
...props
|
|
370
|
+
}: SchemaDisplayPropertyProps) => {
|
|
371
|
+
const hasChildren = properties || items;
|
|
372
|
+
const paddingLeft = 40 + depth * 16;
|
|
373
|
+
|
|
374
|
+
if (hasChildren) {
|
|
375
|
+
return (
|
|
376
|
+
<Collapsible defaultOpen={depth < 2}>
|
|
377
|
+
<CollapsibleTrigger
|
|
378
|
+
className={cn(
|
|
379
|
+
'group hover:bg-muted/50 flex w-full items-center gap-2 py-3 text-left transition-colors',
|
|
380
|
+
className,
|
|
381
|
+
)}
|
|
382
|
+
style={{ paddingLeft }}
|
|
383
|
+
>
|
|
384
|
+
<ChevronRightIcon className="text-muted-foreground size-4 shrink-0 transition-transform group-data-[state=open]:rotate-90" />
|
|
385
|
+
<span className="font-mono text-sm">{name}</span>
|
|
386
|
+
<Badge className="text-xs" variant="outline">
|
|
387
|
+
{type}
|
|
388
|
+
</Badge>
|
|
389
|
+
{required && (
|
|
390
|
+
<Badge
|
|
391
|
+
className="bg-red-100 text-xs text-red-700 dark:bg-red-900/30 dark:text-red-400"
|
|
392
|
+
variant="secondary"
|
|
393
|
+
>
|
|
394
|
+
required
|
|
395
|
+
</Badge>
|
|
396
|
+
)}
|
|
397
|
+
</CollapsibleTrigger>
|
|
398
|
+
{description && (
|
|
399
|
+
<p
|
|
400
|
+
className="text-muted-foreground pb-2 text-sm"
|
|
401
|
+
style={{ paddingLeft: paddingLeft + 24 }}
|
|
402
|
+
>
|
|
403
|
+
{description}
|
|
404
|
+
</p>
|
|
405
|
+
)}
|
|
406
|
+
<CollapsibleContent>
|
|
407
|
+
<div className="divide-y border-t">
|
|
408
|
+
{properties?.map((prop) => (
|
|
409
|
+
<SchemaDisplayProperty
|
|
410
|
+
key={prop.name}
|
|
411
|
+
{...prop}
|
|
412
|
+
depth={depth + 1}
|
|
413
|
+
/>
|
|
414
|
+
))}
|
|
415
|
+
{items && (
|
|
416
|
+
<SchemaDisplayProperty
|
|
417
|
+
{...items}
|
|
418
|
+
depth={depth + 1}
|
|
419
|
+
name={`${name}[]`}
|
|
420
|
+
/>
|
|
421
|
+
)}
|
|
422
|
+
</div>
|
|
423
|
+
</CollapsibleContent>
|
|
424
|
+
</Collapsible>
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<div
|
|
430
|
+
className={cn('py-3 pr-4', className)}
|
|
431
|
+
style={{ paddingLeft }}
|
|
432
|
+
{...props}
|
|
433
|
+
>
|
|
434
|
+
<div className="flex items-center gap-2">
|
|
435
|
+
{/* Spacer for alignment */}
|
|
436
|
+
<span className="size-4" />
|
|
437
|
+
<span className="font-mono text-sm">{name}</span>
|
|
438
|
+
<Badge className="text-xs" variant="outline">
|
|
439
|
+
{type}
|
|
440
|
+
</Badge>
|
|
441
|
+
{required && (
|
|
442
|
+
<Badge
|
|
443
|
+
className="bg-red-100 text-xs text-red-700 dark:bg-red-900/30 dark:text-red-400"
|
|
444
|
+
variant="secondary"
|
|
445
|
+
>
|
|
446
|
+
required
|
|
447
|
+
</Badge>
|
|
448
|
+
)}
|
|
449
|
+
</div>
|
|
450
|
+
{description && (
|
|
451
|
+
<p className="text-muted-foreground mt-1 pl-6 text-sm">{description}</p>
|
|
452
|
+
)}
|
|
453
|
+
</div>
|
|
454
|
+
);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
export type SchemaDisplayExampleProps = HTMLAttributes<HTMLPreElement>;
|
|
458
|
+
|
|
459
|
+
export const SchemaDisplayExample = ({
|
|
460
|
+
className,
|
|
461
|
+
children,
|
|
462
|
+
...props
|
|
463
|
+
}: SchemaDisplayExampleProps) => (
|
|
464
|
+
<pre
|
|
465
|
+
className={cn(
|
|
466
|
+
'bg-muted mx-4 mb-4 overflow-auto rounded-md p-4 font-mono text-sm',
|
|
467
|
+
className,
|
|
468
|
+
)}
|
|
469
|
+
{...props}
|
|
470
|
+
>
|
|
471
|
+
{children}
|
|
472
|
+
</pre>
|
|
473
|
+
);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { MotionProps } from 'motion/react';
|
|
4
|
+
import type { CSSProperties, ElementType, JSX } from 'react';
|
|
5
|
+
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
import { motion } from 'motion/react';
|
|
8
|
+
import { memo, useMemo } from 'react';
|
|
9
|
+
|
|
10
|
+
type MotionHTMLProps = MotionProps & Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
// Cache motion components at module level to avoid creating during render
|
|
13
|
+
const motionComponentCache = new Map<
|
|
14
|
+
keyof JSX.IntrinsicElements,
|
|
15
|
+
React.ComponentType<MotionHTMLProps>
|
|
16
|
+
>();
|
|
17
|
+
|
|
18
|
+
const getMotionComponent = (element: keyof JSX.IntrinsicElements) => {
|
|
19
|
+
let component = motionComponentCache.get(element);
|
|
20
|
+
if (!component) {
|
|
21
|
+
component = motion.create(element);
|
|
22
|
+
motionComponentCache.set(element, component);
|
|
23
|
+
}
|
|
24
|
+
return component;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface TextShimmerProps {
|
|
28
|
+
children: string;
|
|
29
|
+
as?: ElementType;
|
|
30
|
+
className?: string;
|
|
31
|
+
duration?: number;
|
|
32
|
+
spread?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ShimmerComponent = ({
|
|
36
|
+
children,
|
|
37
|
+
as: Component = 'p',
|
|
38
|
+
className,
|
|
39
|
+
duration = 2,
|
|
40
|
+
spread = 2,
|
|
41
|
+
}: TextShimmerProps) => {
|
|
42
|
+
const MotionComponent = getMotionComponent(
|
|
43
|
+
Component as keyof JSX.IntrinsicElements,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const dynamicSpread = useMemo(
|
|
47
|
+
() => (children?.length ?? 0) * spread,
|
|
48
|
+
[children, spread],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<MotionComponent
|
|
53
|
+
animate={{ backgroundPosition: '0% center' }}
|
|
54
|
+
className={cn(
|
|
55
|
+
'relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent',
|
|
56
|
+
'[background-repeat:no-repeat,padding-box] [--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))]',
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
initial={{ backgroundPosition: '100% center' }}
|
|
60
|
+
style={
|
|
61
|
+
{
|
|
62
|
+
'--spread': `${dynamicSpread}px`,
|
|
63
|
+
backgroundImage:
|
|
64
|
+
'var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))',
|
|
65
|
+
} as CSSProperties
|
|
66
|
+
}
|
|
67
|
+
transition={{
|
|
68
|
+
duration,
|
|
69
|
+
ease: 'linear',
|
|
70
|
+
repeat: Number.POSITIVE_INFINITY,
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</MotionComponent>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const Shimmer = memo(ShimmerComponent);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
InputGroup,
|
|
7
|
+
InputGroupAddon,
|
|
8
|
+
InputGroupButton,
|
|
9
|
+
InputGroupInput,
|
|
10
|
+
InputGroupText,
|
|
11
|
+
} from '@/components/ui/input-group';
|
|
12
|
+
import { cn } from '@/lib/utils';
|
|
13
|
+
import { CheckIcon, CopyIcon } from 'lucide-react';
|
|
14
|
+
import {
|
|
15
|
+
createContext,
|
|
16
|
+
useCallback,
|
|
17
|
+
useContext,
|
|
18
|
+
useEffect,
|
|
19
|
+
useRef,
|
|
20
|
+
useState,
|
|
21
|
+
} from 'react';
|
|
22
|
+
|
|
23
|
+
interface SnippetContextType {
|
|
24
|
+
code: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SnippetContext = createContext<SnippetContextType>({
|
|
28
|
+
code: '',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type SnippetProps = ComponentProps<typeof InputGroup> & {
|
|
32
|
+
code: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const Snippet = ({
|
|
36
|
+
code,
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
...props
|
|
40
|
+
}: SnippetProps) => (
|
|
41
|
+
<SnippetContext.Provider value={{ code }}>
|
|
42
|
+
<InputGroup className={cn('font-mono', className)} {...props}>
|
|
43
|
+
{children}
|
|
44
|
+
</InputGroup>
|
|
45
|
+
</SnippetContext.Provider>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export type SnippetAddonProps = ComponentProps<typeof InputGroupAddon>;
|
|
49
|
+
|
|
50
|
+
export const SnippetAddon = (props: SnippetAddonProps) => (
|
|
51
|
+
<InputGroupAddon {...props} />
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export type SnippetTextProps = ComponentProps<typeof InputGroupText>;
|
|
55
|
+
|
|
56
|
+
export const SnippetText = ({ className, ...props }: SnippetTextProps) => (
|
|
57
|
+
<InputGroupText
|
|
58
|
+
className={cn('text-muted-foreground pl-2 font-normal', className)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export type SnippetInputProps = Omit<
|
|
64
|
+
ComponentProps<typeof InputGroupInput>,
|
|
65
|
+
'readOnly' | 'value'
|
|
66
|
+
>;
|
|
67
|
+
|
|
68
|
+
export const SnippetInput = ({ className, ...props }: SnippetInputProps) => {
|
|
69
|
+
const { code } = useContext(SnippetContext);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<InputGroupInput
|
|
73
|
+
className={cn('text-foreground', className)}
|
|
74
|
+
readOnly
|
|
75
|
+
value={code}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type SnippetCopyButtonProps = ComponentProps<typeof InputGroupButton> & {
|
|
82
|
+
onCopy?: () => void;
|
|
83
|
+
onError?: (error: Error) => void;
|
|
84
|
+
timeout?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const SnippetCopyButton = ({
|
|
88
|
+
onCopy,
|
|
89
|
+
onError,
|
|
90
|
+
timeout = 2000,
|
|
91
|
+
children,
|
|
92
|
+
className,
|
|
93
|
+
...props
|
|
94
|
+
}: SnippetCopyButtonProps) => {
|
|
95
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
96
|
+
const timeoutRef = useRef<number>(0);
|
|
97
|
+
const { code } = useContext(SnippetContext);
|
|
98
|
+
|
|
99
|
+
const copyToClipboard = useCallback(async () => {
|
|
100
|
+
if (typeof window === 'undefined' || !navigator?.clipboard?.writeText) {
|
|
101
|
+
onError?.(new Error('Clipboard API not available'));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
if (!isCopied) {
|
|
107
|
+
await navigator.clipboard.writeText(code);
|
|
108
|
+
setIsCopied(true);
|
|
109
|
+
onCopy?.();
|
|
110
|
+
timeoutRef.current = window.setTimeout(
|
|
111
|
+
() => setIsCopied(false),
|
|
112
|
+
timeout,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
onError?.(error as Error);
|
|
117
|
+
}
|
|
118
|
+
}, [code, onCopy, onError, timeout, isCopied]);
|
|
119
|
+
|
|
120
|
+
useEffect(
|
|
121
|
+
() => () => {
|
|
122
|
+
window.clearTimeout(timeoutRef.current);
|
|
123
|
+
},
|
|
124
|
+
[],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<InputGroupButton
|
|
131
|
+
aria-label="Copy"
|
|
132
|
+
className={className}
|
|
133
|
+
onClick={copyToClipboard}
|
|
134
|
+
size="icon-sm"
|
|
135
|
+
title="Copy"
|
|
136
|
+
{...props}
|
|
137
|
+
>
|
|
138
|
+
{children ?? <Icon className="size-3.5" size={14} />}
|
|
139
|
+
</InputGroupButton>
|
|
140
|
+
);
|
|
141
|
+
};
|