Compare commits
23 Commits
d1f88e3f91
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e19b1811d8 | ||
|
|
3269b2eef3 | ||
| 52fa9c5b42 | |||
| 08294e0c7f | |||
| cf2baecb3c | |||
| 3edd6b2a69 | |||
| 5562296ad7 | |||
| 7489b8f1ab | |||
| 91f5f17028 | |||
| a281a0e6e2 | |||
| 689460193b | |||
| db30d8eb23 | |||
| 59319b849c | |||
| eafe815d8f | |||
| 94047cd45f | |||
| 0b9d4dfce3 | |||
| ebd8a7e8be | |||
| d88056bf3c | |||
| 754814d08a | |||
| 8e29fe4545 | |||
| 8ba90c00be | |||
|
|
b2f315a459 | ||
| 62b5c5841a |
7
.env.example
Normal file
7
.env.example
Normal file
@@ -0,0 +1,7 @@
|
||||
## 本地环境
|
||||
|
||||
# VITE_API_URL = "http://localhost:8000"
|
||||
### 开发环境
|
||||
VITE_API_URL = "https://kevisual.xiongxiao.me"
|
||||
### 生产环境
|
||||
# VITE_API_URL = "https://kevisual.cn"
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1 +1,6 @@
|
||||
node_modules
|
||||
.pnpm-store
|
||||
dist
|
||||
.env*
|
||||
!.env*example
|
||||
.next
|
||||
55
AGENTS.md
Normal file
55
AGENTS.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# AGENTS.md
|
||||
|
||||
本指南为在此仓库中工作的 AI 编码代理提供关键信息。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── components/ui/ # shadcn/ui 组件(Base UI 基础组件)
|
||||
├── lib/ # 工具函数(cn() 函数用于 className 合并)
|
||||
├── modules/ # 应用模块(query client、basename)
|
||||
├── pages/ # 页面组件(默认导出)
|
||||
├── routes/ # TanStack Router 基于文件的路由
|
||||
├── styles/ # 全局样式、主题 CSS
|
||||
└── main.tsx # 应用入口
|
||||
```
|
||||
|
||||
|
||||
## 代码风格指南
|
||||
|
||||
### 模块目录结构
|
||||
|
||||
每个新模块(如 `page-app`)应遵循以下结构:
|
||||
|
||||
```
|
||||
pages/page-app/
|
||||
├── components/ # 模块专属组件
|
||||
├── store/ # 模块状态管理
|
||||
└── module/ # 模块功能函数
|
||||
```
|
||||
|
||||
### 状态和数据获取
|
||||
|
||||
- **Zustand** 用于全局状态管理
|
||||
- **@kevisual/query** 用于数据获取(QueryClient 实例位于 `src/modules/query.ts`)
|
||||
- **React Hook Form** 用于表单管理
|
||||
|
||||
## 核心依赖
|
||||
|
||||
- **@base-ui/react**: Headless UI 基础组件
|
||||
- **@tanstack/react-router**: 基于 TanStack Router 插件的文件路由
|
||||
- **class-variance-authority**: 基于变体的样式系统
|
||||
- **clsx + tailwind-merge**: 通过 `cn()` 提供 className 工具函数
|
||||
- **lucide-react**: 图标库
|
||||
- **react-hook-form**: 表单处理
|
||||
- **sonner**: Toast 通知
|
||||
- **zustand**: 状态管理
|
||||
- **tailwindcss v4**: 使用 @tailwindcss/vite 插件进行样式处理
|
||||
|
||||
## 主题系统
|
||||
|
||||
- **主题配色**: 采用黑白配色方案,提供简洁优雅的视觉体验
|
||||
- **主题模式**: 支持 light(浅色)和 dark(深色)模式切换
|
||||
- **主题实现**: 使用 `next-themes` 进行主题管理
|
||||
- **CSS 变量**: 主题相关的 CSS 变量定义在 `src/styles/theme.css` 中
|
||||
@@ -1,14 +1,13 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "new-york",
|
||||
"style": "base-nova",
|
||||
"rsc": false,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "src/styles/global.css",
|
||||
"config": "tailwind.config.ts",
|
||||
"css": "src/index.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
"cssVariables": true
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"aliases": {
|
||||
@@ -17,6 +16,5 @@
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"registries": {}
|
||||
}
|
||||
}
|
||||
32
index.html
Normal file
32
index.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/jpg" href="https://kevisual.cn/root/center/panda.jpg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Route Studio Viewer</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
62
package.json
62
package.json
@@ -1,7 +1,65 @@
|
||||
{
|
||||
"name": "@kevisual/router-studio",
|
||||
"version": "0.1.8",
|
||||
"basename": "/root/router-studio",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"ui": "bunx shadcn@latest add ",
|
||||
"pub": "envision deploy ./dist -k router-studio -v 0.1.8 -y y -u"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.2.0",
|
||||
"@kevisual/router": "0.1.1",
|
||||
"@tanstack/react-router": "^1.166.7",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"@uiw/react-codemirror": "^4.25.8",
|
||||
"@uiw/react-md-editor": "^4.0.11",
|
||||
"antd": "^6.3.2",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.1.1",
|
||||
"dayjs": "^1.11.19",
|
||||
"eruda": "^3.4.3",
|
||||
"es-toolkit": "^1.45.1",
|
||||
"fuse.js": "^7.1.0",
|
||||
"idb-keyval": "^6.2.2",
|
||||
"lucide-react": "^0.577.0",
|
||||
"nanoid": "^5.1.6",
|
||||
"zod": "^4.2.1",
|
||||
"zod-to-json-schema": "^3.25.1"
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4",
|
||||
"react-hook-form": "^7.71.2",
|
||||
"react-resizable-panels": "^4.7.2",
|
||||
"sonner": "^2.0.7",
|
||||
"valtio": "^2.3.1",
|
||||
"zod": "^4.3.6",
|
||||
"zustand": "^5.0.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/ai": "^0.0.28",
|
||||
"@kevisual/api": "^0.0.62",
|
||||
"@kevisual/context": "^0.0.8",
|
||||
"@kevisual/js-filter": "^0.0.6",
|
||||
"@kevisual/kv-login": "^0.1.17",
|
||||
"@kevisual/query": "^0.0.53",
|
||||
"@kevisual/types": "^0.0.12",
|
||||
"@tailwindcss/vite": "^4.2.1",
|
||||
"@tanstack/react-router-devtools": "^1.166.7",
|
||||
"@tanstack/router-plugin": "^1.166.7",
|
||||
"@types/node": "^25.4.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"dotenv": "^17.3.1",
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"tailwindcss": "^4.2.1",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "v8.0.0-beta.16"
|
||||
}
|
||||
}
|
||||
|
||||
5367
pnpm-lock.yaml
generated
5367
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
8
src/agents/app.ts
Normal file
8
src/agents/app.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { QueryRouterServer } from '@kevisual/router/browser'
|
||||
import { use } from '@kevisual/context'
|
||||
export const app = use('app', new QueryRouterServer())
|
||||
|
||||
import { useLayoutStore } from '@/pages/auth/store'
|
||||
|
||||
const layoutStore = useLayoutStore.getState()
|
||||
layoutStore.setShowBaseHeader(false)
|
||||
7
src/agents/index.ts
Normal file
7
src/agents/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { app } from './app.ts';
|
||||
|
||||
import './routes/left-panel.ts';
|
||||
import { Load } from '@kevisual/context/load'
|
||||
Load.npm({ pkg: 'eruda' });
|
||||
|
||||
export { app };
|
||||
@@ -1,4 +1,4 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { app } from '../app.ts';
|
||||
import { use } from '@kevisual/context'
|
||||
|
||||
app.route({
|
||||
48
src/components/ui/badge.tsx
Normal file
48
src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { mergeProps } from "@base-ui/react/merge-props"
|
||||
import { useRender } from "@base-ui/react/use-render"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
||||
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
||||
destructive: "bg-destructive/10 [a]:hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 text-destructive dark:bg-destructive/20",
|
||||
outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
||||
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant = "default",
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {
|
||||
return useRender({
|
||||
defaultTagName: "span",
|
||||
props: mergeProps<"span">(
|
||||
{
|
||||
className: cn(badgeVariants({ className, variant })),
|
||||
},
|
||||
props
|
||||
),
|
||||
render,
|
||||
state: {
|
||||
slot: "badge",
|
||||
variant,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
125
src/components/ui/breadcrumb.tsx
Normal file
125
src/components/ui/breadcrumb.tsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import * as React from "react"
|
||||
import { mergeProps } from "@base-ui/react/merge-props"
|
||||
import { useRender } from "@base-ui/react/use-render"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ChevronRightIcon, MoreHorizontalIcon } from "lucide-react"
|
||||
|
||||
function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) {
|
||||
return (
|
||||
<nav
|
||||
aria-label="breadcrumb"
|
||||
data-slot="breadcrumb"
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||
return (
|
||||
<ol
|
||||
data-slot="breadcrumb-list"
|
||||
className={cn(
|
||||
"text-muted-foreground gap-1.5 text-sm flex flex-wrap items-center wrap-break-word",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-item"
|
||||
className={cn("gap-1 inline-flex items-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbLink({
|
||||
className,
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<"a">) {
|
||||
return useRender({
|
||||
defaultTagName: "a",
|
||||
props: mergeProps<"a">(
|
||||
{
|
||||
className: cn("hover:text-foreground transition-colors", className),
|
||||
},
|
||||
props
|
||||
),
|
||||
render,
|
||||
state: {
|
||||
slot: "breadcrumb-link",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-page"
|
||||
role="link"
|
||||
aria-disabled="true"
|
||||
aria-current="page"
|
||||
className={cn("text-foreground font-normal", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-separator"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn("[&>svg]:size-3.5", className)}
|
||||
{...props}
|
||||
>
|
||||
{children ?? (
|
||||
<ChevronRightIcon />
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-ellipsis"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-5 [&>svg]:size-4 flex items-center justify-center",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontalIcon
|
||||
/>
|
||||
<span className="sr-only">More</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Breadcrumb,
|
||||
BreadcrumbList,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
BreadcrumbEllipsis,
|
||||
}
|
||||
51
src/components/ui/button.tsx
Normal file
51
src/components/ui/button.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Button as ButtonPrimitive } from "@base-ui/react/button"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 rounded-lg border border-transparent bg-clip-padding text-sm font-medium focus-visible:ring-3 aria-invalid:ring-3 [&_svg:not([class*='size-'])]:size-4 inline-flex items-center justify-center whitespace-nowrap transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none group/button select-none",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
||||
outline: "border-border bg-background hover:bg-muted hover:text-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50 aria-expanded:bg-muted aria-expanded:text-foreground",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
||||
ghost: "hover:bg-muted hover:text-foreground dark:hover:bg-muted/50 aria-expanded:bg-muted aria-expanded:text-foreground",
|
||||
destructive: "bg-destructive/10 hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/20 text-destructive focus-visible:border-destructive/40 dark:hover:bg-destructive/30",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
||||
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
|
||||
icon: "size-8",
|
||||
"icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
||||
"icon-lg": "size-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
...props
|
||||
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
||||
return (
|
||||
<ButtonPrimitive
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
94
src/components/ui/card.tsx
Normal file
94
src/components/ui/card.tsx
Normal file
@@ -0,0 +1,94 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Card({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
data-size={size}
|
||||
className={cn("ring-foreground/10 bg-card text-card-foreground gap-4 overflow-hidden rounded-xl py-4 text-sm ring-1 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl group/card flex flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3 group/card-header @container/card-header grid auto-rows-min items-start has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn("text-base leading-snug font-medium group-data-[size=sm]/card:text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("bg-muted/50 rounded-b-xl border-t p-4 group-data-[size=sm]/card:p-3 flex items-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
29
src/components/ui/checkbox.tsx
Normal file
29
src/components/ui/checkbox.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
|
||||
import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
|
||||
function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"border-input dark:bg-input/30 data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary data-checked:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 flex size-4 items-center justify-center rounded-[4px] border transition-colors group-has-disabled/field:opacity-50 focus-visible:ring-3 aria-invalid:ring-3 peer relative shrink-0 outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="[&>svg]:size-3.5 grid place-content-center text-current transition-none"
|
||||
>
|
||||
<CheckIcon
|
||||
/>
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Checkbox }
|
||||
188
src/components/ui/command.tsx
Normal file
188
src/components/ui/command.tsx
Normal file
@@ -0,0 +1,188 @@
|
||||
import * as React from "react"
|
||||
import { Command as CommandPrimitive } from "cmdk"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
} from "@/components/ui/input-group"
|
||||
import { SearchIcon, CheckIcon } from "lucide-react"
|
||||
|
||||
function Command({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive>) {
|
||||
return (
|
||||
<CommandPrimitive
|
||||
data-slot="command"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground rounded-xl! p-1 flex size-full flex-col overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandDialog({
|
||||
title = "Command Palette",
|
||||
description = "Search for a command to run...",
|
||||
children,
|
||||
className,
|
||||
showCloseButton = false,
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof Dialog>, "children"> & {
|
||||
title?: string
|
||||
description?: string
|
||||
className?: string
|
||||
showCloseButton?: boolean
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogHeader className="sr-only">
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogContent
|
||||
className={cn(
|
||||
"rounded-xl! top-1/3 translate-y-0 overflow-hidden p-0",
|
||||
className
|
||||
)}
|
||||
showCloseButton={showCloseButton}
|
||||
>
|
||||
{children}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
||||
return (
|
||||
<div data-slot="command-input-wrapper" className="p-1 pb-0">
|
||||
<InputGroup className="bg-input/30 border-input/30 h-8! rounded-lg! shadow-none! *:data-[slot=input-group-addon]:pl-2!">
|
||||
<CommandPrimitive.Input
|
||||
data-slot="command-input"
|
||||
className={cn(
|
||||
"w-full text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
<InputGroupAddon>
|
||||
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
||||
return (
|
||||
<CommandPrimitive.List
|
||||
data-slot="command-list"
|
||||
className={cn(
|
||||
"no-scrollbar max-h-72 scroll-py-1 outline-none overflow-x-hidden overflow-y-auto",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandEmpty({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
||||
return (
|
||||
<CommandPrimitive.Empty
|
||||
data-slot="command-empty"
|
||||
className={cn("py-6 text-center text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
||||
return (
|
||||
<CommandPrimitive.Group
|
||||
data-slot="command-group"
|
||||
className={cn("text-foreground **:[[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
||||
return (
|
||||
<CommandPrimitive.Separator
|
||||
data-slot="command-separator"
|
||||
className={cn("bg-border -mx-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
||||
return (
|
||||
<CommandPrimitive.Item
|
||||
data-slot="command-item"
|
||||
className={cn(
|
||||
"data-selected:bg-muted data-selected:text-foreground data-selected:*:[svg]:text-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none in-data-[slot=dialog-content]:rounded-lg! [&_svg:not([class*='size-'])]:size-4 group/command-item data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<CheckIcon className="ml-auto opacity-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-data-[checked=true]/command-item:opacity-100" />
|
||||
</CommandPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="command-shortcut"
|
||||
className={cn("text-muted-foreground group-data-selected/command-item:text-foreground ml-auto text-xs tracking-widest", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Command,
|
||||
CommandDialog,
|
||||
CommandInput,
|
||||
CommandList,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandItem,
|
||||
CommandShortcut,
|
||||
CommandSeparator,
|
||||
}
|
||||
151
src/components/ui/dialog.tsx
Normal file
151
src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,151 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
function Dialog({ ...props }: DialogPrimitive.Root.Props) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||
}
|
||||
|
||||
function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||
}
|
||||
|
||||
function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: DialogPrimitive.Backdrop.Props) {
|
||||
return (
|
||||
<DialogPrimitive.Backdrop
|
||||
data-slot="dialog-overlay"
|
||||
className={cn("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 isolate z-50", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: DialogPrimitive.Popup.Props & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Popup
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-sm ring-1 duration-100 sm:max-w-sm fixed top-1/2 left-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 outline-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close
|
||||
data-slot="dialog-close"
|
||||
render={
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="absolute top-2 right-2"
|
||||
size="icon-sm"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<XIcon
|
||||
/>
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Popup>
|
||||
</DialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("gap-2 flex flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogFooter({
|
||||
className,
|
||||
showCloseButton = false,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"bg-muted/50 -mx-4 -mb-4 rounded-b-xl border-t p-4 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close render={<Button variant="outline" />}>
|
||||
Close
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-base leading-none font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: DialogPrimitive.Description.Props) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
}
|
||||
262
src/components/ui/dropdown-menu.tsx
Normal file
262
src/components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,262 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ChevronRightIcon, CheckIcon } from "lucide-react"
|
||||
|
||||
function DropdownMenu({ ...props }: MenuPrimitive.Root.Props) {
|
||||
return <MenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({ ...props }: MenuPrimitive.Portal.Props) {
|
||||
return <MenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({ ...props }: MenuPrimitive.Trigger.Props) {
|
||||
return <MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
align = "start",
|
||||
alignOffset = 0,
|
||||
side = "bottom",
|
||||
sideOffset = 4,
|
||||
className,
|
||||
...props
|
||||
}: MenuPrimitive.Popup.Props &
|
||||
Pick<
|
||||
MenuPrimitive.Positioner.Props,
|
||||
"align" | "alignOffset" | "side" | "sideOffset"
|
||||
>) {
|
||||
return (
|
||||
<MenuPrimitive.Portal>
|
||||
<MenuPrimitive.Positioner
|
||||
className="isolate z-50 outline-none"
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
>
|
||||
<MenuPrimitive.Popup
|
||||
data-slot="dropdown-menu-content"
|
||||
className={cn("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-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 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden", className )}
|
||||
{...props}
|
||||
/>
|
||||
</MenuPrimitive.Positioner>
|
||||
</MenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({ ...props }: MenuPrimitive.Group.Props) {
|
||||
return <MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: MenuPrimitive.GroupLabel.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.GroupLabel
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn("text-muted-foreground px-1.5 py-1 text-xs font-medium data-inset:pl-7", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: MenuPrimitive.Item.Props & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props) {
|
||||
return <MenuPrimitive.SubmenuRoot data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: MenuPrimitive.SubmenuTrigger.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.SubmenuTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 data-popup-open:bg-accent data-popup-open:text-accent-foreground flex cursor-default items-center outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</MenuPrimitive.SubmenuTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
align = "start",
|
||||
alignOffset = -3,
|
||||
side = "right",
|
||||
sideOffset = 0,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuContent>) {
|
||||
return (
|
||||
<DropdownMenuContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-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 ring-foreground/10 bg-popover text-popover-foreground min-w-[96px] rounded-lg p-1 shadow-lg ring-1 duration-100 w-auto", className)}
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
inset,
|
||||
...props
|
||||
}: MenuPrimitive.CheckboxItem.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="absolute right-2 flex items-center justify-center pointer-events-none"
|
||||
data-slot="dropdown-menu-checkbox-item-indicator"
|
||||
>
|
||||
<MenuPrimitive.CheckboxItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</MenuPrimitive.CheckboxItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props) {
|
||||
return (
|
||||
<MenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
inset,
|
||||
...props
|
||||
}: MenuPrimitive.RadioItem.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="absolute right-2 flex items-center justify-center pointer-events-none"
|
||||
data-slot="dropdown-menu-radio-item-indicator"
|
||||
>
|
||||
<MenuPrimitive.RadioItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</MenuPrimitive.RadioItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: MenuPrimitive.Separator.Props) {
|
||||
return (
|
||||
<MenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn("text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ml-auto text-xs tracking-widest", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
149
src/components/ui/input-group.tsx
Normal file
149
src/components/ui/input-group.tsx
Normal file
@@ -0,0 +1,149 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
|
||||
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="input-group"
|
||||
role="group"
|
||||
className={cn(
|
||||
"border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-disabled:bg-input/50 dark:has-disabled:bg-input/80 h-8 rounded-lg border transition-colors in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-3 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const inputGroupAddonVariants = cva(
|
||||
"text-muted-foreground h-auto gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none",
|
||||
{
|
||||
variants: {
|
||||
align: {
|
||||
"inline-start": "pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem] order-first",
|
||||
"inline-end": "pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem] order-last",
|
||||
"block-start":
|
||||
"px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start",
|
||||
"block-end":
|
||||
"px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2 order-last w-full justify-start",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
align: "inline-start",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function InputGroupAddon({
|
||||
className,
|
||||
align = "inline-start",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="input-group-addon"
|
||||
data-align={align}
|
||||
className={cn(inputGroupAddonVariants({ align }), className)}
|
||||
onClick={(e) => {
|
||||
if ((e.target as HTMLElement).closest("button")) {
|
||||
return
|
||||
}
|
||||
e.currentTarget.parentElement?.querySelector("input")?.focus()
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const inputGroupButtonVariants = cva(
|
||||
"gap-2 text-sm shadow-none flex items-center",
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
||||
sm: "",
|
||||
"icon-xs": "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
|
||||
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "xs",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function InputGroupButton({
|
||||
className,
|
||||
type = "button",
|
||||
variant = "ghost",
|
||||
size = "xs",
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof Button>, "size" | "type"> &
|
||||
VariantProps<typeof inputGroupButtonVariants> & {
|
||||
type?: "button" | "submit" | "reset"
|
||||
}) {
|
||||
return (
|
||||
<Button
|
||||
type={type}
|
||||
data-size={size}
|
||||
variant={variant}
|
||||
className={cn(inputGroupButtonVariants({ size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"text-muted-foreground gap-2 text-sm [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="input-group-control"
|
||||
className={cn("rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupTextarea({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<Textarea
|
||||
data-slot="input-group-control"
|
||||
className={cn("rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1 resize-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupText,
|
||||
InputGroupInput,
|
||||
InputGroupTextarea,
|
||||
}
|
||||
20
src/components/ui/input.tsx
Normal file
20
src/components/ui/input.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import * as React from "react"
|
||||
import { Input as InputPrimitive } from "@base-ui/react/input"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<InputPrimitive
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 h-8 rounded-lg border bg-transparent px-2.5 py-1 text-base transition-colors file:h-6 file:text-sm file:font-medium focus-visible:ring-3 aria-invalid:ring-3 md:text-sm file:text-foreground placeholder:text-muted-foreground w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
26
src/components/ui/kbd.tsx
Normal file
26
src/components/ui/kbd.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
|
||||
return (
|
||||
<kbd
|
||||
data-slot="kbd"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 h-5 w-fit min-w-5 gap-1 rounded-sm px-1 font-sans text-xs font-medium [&_svg:not([class*='size-'])]:size-3 pointer-events-none inline-flex items-center justify-center select-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function KbdGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<kbd
|
||||
data-slot="kbd-group"
|
||||
className={cn("gap-1 inline-flex items-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Kbd, KbdGroup }
|
||||
18
src/components/ui/label.tsx
Normal file
18
src/components/ui/label.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({ className, ...props }: React.ComponentProps<"label">) {
|
||||
return (
|
||||
<label
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"gap-2 text-sm leading-none font-medium group-data-[disabled=true]:opacity-50 peer-disabled:opacity-50 flex items-center select-none group-data-[disabled=true]:pointer-events-none peer-disabled:cursor-not-allowed",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
263
src/components/ui/menubar.tsx
Normal file
263
src/components/ui/menubar.tsx
Normal file
@@ -0,0 +1,263 @@
|
||||
import * as React from "react"
|
||||
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
|
||||
import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
|
||||
function Menubar({ className, ...props }: MenubarPrimitive.Props) {
|
||||
return (
|
||||
<MenubarPrimitive
|
||||
data-slot="menubar"
|
||||
className={cn("bg-background h-8 gap-0.5 rounded-lg border p-[3px] flex items-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarMenu({ ...props }: React.ComponentProps<typeof DropdownMenu>) {
|
||||
return <DropdownMenu data-slot="menubar-menu" {...props} />
|
||||
}
|
||||
|
||||
function MenubarGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuGroup>) {
|
||||
return <DropdownMenuGroup data-slot="menubar-group" {...props} />
|
||||
}
|
||||
|
||||
function MenubarPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPortal>) {
|
||||
return <DropdownMenuPortal data-slot="menubar-portal" {...props} />
|
||||
}
|
||||
|
||||
function MenubarTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuTrigger>) {
|
||||
return (
|
||||
<DropdownMenuTrigger
|
||||
data-slot="menubar-trigger"
|
||||
className={cn(
|
||||
"hover:bg-muted aria-expanded:bg-muted rounded-sm px-1.5 py-[2px] text-sm font-medium flex items-center outline-hidden select-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarContent({
|
||||
className,
|
||||
align = "start",
|
||||
alignOffset = -4,
|
||||
sideOffset = 8,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuContent>) {
|
||||
return (
|
||||
<DropdownMenuContent
|
||||
data-slot="menubar-content"
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
sideOffset={sideOffset}
|
||||
className={cn("bg-popover text-popover-foreground data-open:animate-in data-open:fade-in-0 data-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 ring-foreground/10 min-w-36 rounded-lg p-1 shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2", className )}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuItem>) {
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
data-slot="menubar-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive! not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-disabled:opacity-50 data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 group/menubar-item", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
inset,
|
||||
...props
|
||||
}: MenuPrimitive.CheckboxItem.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.CheckboxItem
|
||||
data-slot="menubar-checkbox-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-1.5 pl-7 text-sm data-inset:pl-7 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="left-1.5 size-4 [&_svg:not([class*='size-'])]:size-4 pointer-events-none absolute flex items-center justify-center">
|
||||
<MenuPrimitive.CheckboxItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</MenuPrimitive.CheckboxItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuRadioGroup>) {
|
||||
return <DropdownMenuRadioGroup data-slot="menubar-radio-group" {...props} />
|
||||
}
|
||||
|
||||
function MenubarRadioItem({
|
||||
className,
|
||||
children,
|
||||
inset,
|
||||
...props
|
||||
}: MenuPrimitive.RadioItem.Props & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.RadioItem
|
||||
data-slot="menubar-radio-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-1.5 pl-7 text-sm data-disabled:opacity-50 data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="left-1.5 size-4 [&_svg:not([class*='size-'])]:size-4 pointer-events-none absolute flex items-center justify-center">
|
||||
<MenuPrimitive.RadioItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</MenuPrimitive.RadioItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuLabel> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuLabel
|
||||
data-slot="menubar-label"
|
||||
data-inset={inset}
|
||||
className={cn("px-1.5 py-1 text-sm font-medium data-inset:pl-7", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuSeparator>) {
|
||||
return (
|
||||
<DropdownMenuSeparator
|
||||
data-slot="menubar-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuShortcut>) {
|
||||
return (
|
||||
<DropdownMenuShortcut
|
||||
data-slot="menubar-shortcut"
|
||||
className={cn("text-muted-foreground group-focus/menubar-item:text-accent-foreground text-xs tracking-widest ml-auto", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuSub>) {
|
||||
return <DropdownMenuSub data-slot="menubar-sub" {...props} />
|
||||
}
|
||||
|
||||
function MenubarSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuSubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuSubTrigger
|
||||
data-slot="menubar-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn("focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuSubContent>) {
|
||||
return (
|
||||
<DropdownMenuSubContent
|
||||
data-slot="menubar-sub-content"
|
||||
className={cn("bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-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 ring-foreground/10 min-w-32 rounded-lg p-1 shadow-lg ring-1 duration-100", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Menubar,
|
||||
MenubarPortal,
|
||||
MenubarMenu,
|
||||
MenubarTrigger,
|
||||
MenubarContent,
|
||||
MenubarGroup,
|
||||
MenubarSeparator,
|
||||
MenubarLabel,
|
||||
MenubarItem,
|
||||
MenubarShortcut,
|
||||
MenubarCheckboxItem,
|
||||
MenubarRadioGroup,
|
||||
MenubarRadioItem,
|
||||
MenubarSub,
|
||||
MenubarSubTrigger,
|
||||
MenubarSubContent,
|
||||
}
|
||||
88
src/components/ui/popover.tsx
Normal file
88
src/components/ui/popover.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import * as React from "react"
|
||||
import { Popover as PopoverPrimitive } from "@base-ui/react/popover"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Popover({ ...props }: PopoverPrimitive.Root.Props) {
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />
|
||||
}
|
||||
|
||||
function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) {
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
className,
|
||||
align = "center",
|
||||
alignOffset = 0,
|
||||
side = "bottom",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: PopoverPrimitive.Popup.Props &
|
||||
Pick<
|
||||
PopoverPrimitive.Positioner.Props,
|
||||
"align" | "alignOffset" | "side" | "sideOffset"
|
||||
>) {
|
||||
return (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Positioner
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
className="isolate z-50"
|
||||
>
|
||||
<PopoverPrimitive.Popup
|
||||
data-slot="popover-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-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 ring-foreground/10 flex flex-col gap-2.5 rounded-lg p-2.5 text-sm shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 w-72 origin-(--transform-origin) outline-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Positioner>
|
||||
</PopoverPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="popover-header"
|
||||
className={cn("flex flex-col gap-0.5 text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
|
||||
return (
|
||||
<PopoverPrimitive.Title
|
||||
data-slot="popover-title"
|
||||
className={cn("font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverDescription({
|
||||
className,
|
||||
...props
|
||||
}: PopoverPrimitive.Description.Props) {
|
||||
return (
|
||||
<PopoverPrimitive.Description
|
||||
data-slot="popover-description"
|
||||
className={cn("text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDescription,
|
||||
PopoverHeader,
|
||||
PopoverTitle,
|
||||
PopoverTrigger,
|
||||
}
|
||||
191
src/components/ui/select.tsx
Normal file
191
src/components/ui/select.tsx
Normal file
@@ -0,0 +1,191 @@
|
||||
import * as React from "react"
|
||||
import { Select as SelectPrimitive } from "@base-ui/react/select"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react"
|
||||
|
||||
const Select = SelectPrimitive.Root
|
||||
|
||||
function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
|
||||
return (
|
||||
<SelectPrimitive.Group
|
||||
data-slot="select-group"
|
||||
className={cn("scroll-my-1 p-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
|
||||
return (
|
||||
<SelectPrimitive.Value
|
||||
data-slot="select-value"
|
||||
className={cn("flex flex-1 text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: SelectPrimitive.Trigger.Props & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-lg border bg-transparent py-2 pr-2 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:gap-1.5 [&_svg:not([class*='size-'])]:size-4 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon
|
||||
render={
|
||||
<ChevronDownIcon className="text-muted-foreground size-4 pointer-events-none" />
|
||||
}
|
||||
/>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
side = "bottom",
|
||||
sideOffset = 4,
|
||||
align = "center",
|
||||
alignOffset = 0,
|
||||
alignItemWithTrigger = true,
|
||||
...props
|
||||
}: SelectPrimitive.Popup.Props &
|
||||
Pick<
|
||||
SelectPrimitive.Positioner.Props,
|
||||
"align" | "alignOffset" | "side" | "sideOffset" | "alignItemWithTrigger"
|
||||
>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Positioner
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
alignItemWithTrigger={alignItemWithTrigger}
|
||||
className="isolate z-50"
|
||||
>
|
||||
<SelectPrimitive.Popup
|
||||
data-slot="select-content"
|
||||
data-align-trigger={alignItemWithTrigger}
|
||||
className={cn("bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-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 ring-foreground/10 min-w-36 rounded-lg shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto data-[align-trigger=true]:animate-none", className )}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.List>{children}</SelectPrimitive.List>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Popup>
|
||||
</SelectPrimitive.Positioner>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: SelectPrimitive.GroupLabel.Props) {
|
||||
return (
|
||||
<SelectPrimitive.GroupLabel
|
||||
data-slot="select-label"
|
||||
className={cn("text-muted-foreground px-1.5 py-1 text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: SelectPrimitive.Item.Props) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SelectPrimitive.ItemText className="flex flex-1 gap-2 shrink-0 whitespace-nowrap">
|
||||
{children}
|
||||
</SelectPrimitive.ItemText>
|
||||
<SelectPrimitive.ItemIndicator
|
||||
render={<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center" />}
|
||||
>
|
||||
<CheckIcon className="pointer-events-none" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: SelectPrimitive.Separator.Props) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px pointer-events-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpArrow>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpArrow
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn("bg-popover z-10 flex cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4 top-0 w-full", className)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon
|
||||
/>
|
||||
</SelectPrimitive.ScrollUpArrow>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownArrow>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownArrow
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn("bg-popover z-10 flex cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4 bottom-0 w-full", className)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon
|
||||
/>
|
||||
</SelectPrimitive.ScrollDownArrow>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
129
src/components/ui/sheet.tsx
Normal file
129
src/components/ui/sheet.tsx
Normal file
@@ -0,0 +1,129 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Dialog as SheetPrimitive } from "@base-ui/react/dialog"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
function Sheet({ ...props }: SheetPrimitive.Root.Props) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||
}
|
||||
|
||||
function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||
}
|
||||
|
||||
function SheetClose({ ...props }: SheetPrimitive.Close.Props) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||
}
|
||||
|
||||
function SheetPortal({ ...props }: SheetPrimitive.Portal.Props) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||
}
|
||||
|
||||
function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Backdrop
|
||||
data-slot="sheet-overlay"
|
||||
className={cn("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 duration-100 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 z-50", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
className,
|
||||
children,
|
||||
side = "right",
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: SheetPrimitive.Popup.Props & {
|
||||
side?: "top" | "right" | "bottom" | "left"
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Popup
|
||||
data-slot="sheet-content"
|
||||
data-side={side}
|
||||
className={cn("bg-background data-open:animate-in data-closed:animate-out data-[side=right]:data-closed:slide-out-to-right-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=top]:data-closed:slide-out-to-top-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:fade-out-0 data-open:fade-in-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=bottom]:data-open:slide-in-from-bottom-10 fixed z-50 flex flex-col gap-4 bg-clip-padding text-sm shadow-lg transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<SheetPrimitive.Close
|
||||
data-slot="sheet-close"
|
||||
render={
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="absolute top-3 right-3"
|
||||
size="icon-sm"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<XIcon
|
||||
/>
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
)}
|
||||
</SheetPrimitive.Popup>
|
||||
</SheetPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-header"
|
||||
className={cn("gap-0.5 p-4 flex flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-footer"
|
||||
className={cn("gap-2 p-4 mt-auto flex flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Title
|
||||
data-slot="sheet-title"
|
||||
className={cn("text-foreground text-base font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetDescription({
|
||||
className,
|
||||
...props
|
||||
}: SheetPrimitive.Description.Props) {
|
||||
return (
|
||||
<SheetPrimitive.Description
|
||||
data-slot="sheet-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
||||
49
src/components/ui/sonner.tsx
Normal file
49
src/components/ui/sonner.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
"use client"
|
||||
|
||||
import { useTheme } from "next-themes"
|
||||
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme()
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
success: (
|
||||
<CircleCheckIcon className="size-4" />
|
||||
),
|
||||
info: (
|
||||
<InfoIcon className="size-4" />
|
||||
),
|
||||
warning: (
|
||||
<TriangleAlertIcon className="size-4" />
|
||||
),
|
||||
error: (
|
||||
<OctagonXIcon className="size-4" />
|
||||
),
|
||||
loading: (
|
||||
<Loader2Icon className="size-4 animate-spin" />
|
||||
),
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
"--border-radius": "var(--radius)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
toastOptions={{
|
||||
classNames: {
|
||||
toast: "cn-toast",
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
80
src/components/ui/tabs.tsx
Normal file
80
src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
...props
|
||||
}: TabsPrimitive.Root.Props) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
data-orientation={orientation}
|
||||
className={cn(
|
||||
"gap-2 group/tabs flex data-horizontal:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const tabsListVariants = cva(
|
||||
"rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-muted",
|
||||
line: "gap-1 bg-transparent",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
data-variant={variant}
|
||||
className={cn(tabsListVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
|
||||
return (
|
||||
<TabsPrimitive.Tab
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*='size-'])]:size-4 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent",
|
||||
"data-active:bg-background dark:data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 data-active:text-foreground",
|
||||
"after:bg-foreground after:absolute after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
|
||||
return (
|
||||
<TabsPrimitive.Panel
|
||||
data-slot="tabs-content"
|
||||
className={cn("text-sm flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }
|
||||
18
src/components/ui/textarea.tsx
Normal file
18
src/components/ui/textarea.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-3 aria-invalid:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Textarea }
|
||||
64
src/components/ui/tooltip.tsx
Normal file
64
src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function TooltipProvider({
|
||||
delay = 0,
|
||||
...props
|
||||
}: TooltipPrimitive.Provider.Props) {
|
||||
return (
|
||||
<TooltipPrimitive.Provider
|
||||
data-slot="tooltip-provider"
|
||||
delay={delay}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
|
||||
return <TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||
}
|
||||
|
||||
function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
className,
|
||||
side = "top",
|
||||
sideOffset = 4,
|
||||
align = "center",
|
||||
alignOffset = 0,
|
||||
children,
|
||||
...props
|
||||
}: TooltipPrimitive.Popup.Props &
|
||||
Pick<
|
||||
TooltipPrimitive.Positioner.Props,
|
||||
"align" | "alignOffset" | "side" | "sideOffset"
|
||||
>) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Positioner
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
className="isolate z-50"
|
||||
>
|
||||
<TooltipPrimitive.Popup
|
||||
data-slot="tooltip-content"
|
||||
className={cn(
|
||||
"data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-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 rounded-md px-3 py-1.5 text-xs data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 bg-foreground text-background z-50 w-fit max-w-xs origin-(--transform-origin)",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<TooltipPrimitive.Arrow className="size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 bg-foreground fill-foreground z-50 data-[side=bottom]:top-1 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" />
|
||||
</TooltipPrimitive.Popup>
|
||||
</TooltipPrimitive.Positioner>
|
||||
</TooltipPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
@@ -1,50 +1,54 @@
|
||||
@import 'tailwindcss';
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "./styles/theme.css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--radius-2xl: calc(var(--radius) + 8px);
|
||||
--radius-3xl: calc(var(--radius) + 12px);
|
||||
--radius-4xl: calc(var(--radius) + 16px);
|
||||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.625rem;
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
@@ -74,6 +78,8 @@
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
}
|
||||
|
||||
.dark {
|
||||
27
src/main.tsx
Normal file
27
src/main.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import { RouterProvider, createRouter } from '@tanstack/react-router'
|
||||
import { routeTree } from './routeTree.gen'
|
||||
import './index.css'
|
||||
import { getDynamicBasename } from './modules/basename'
|
||||
import './agents/index.ts';
|
||||
// Set up a Router instance
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
basepath: getDynamicBasename(),
|
||||
defaultPreload: 'intent',
|
||||
scrollRestoration: true,
|
||||
})
|
||||
|
||||
// Register things for typesafety
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: typeof router
|
||||
}
|
||||
}
|
||||
|
||||
const rootElement = document.getElementById('root')!
|
||||
|
||||
if (!rootElement.innerHTML) {
|
||||
const root = ReactDOM.createRoot(rootElement)
|
||||
root.render(<RouterProvider router={router} />)
|
||||
}
|
||||
22
src/modules/basename.ts
Normal file
22
src/modules/basename.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// @ts-ignore
|
||||
export const basename = BASE_NAME;
|
||||
|
||||
export const wrapBasename = (path: string) => {
|
||||
const hasEnd = path.endsWith('/')
|
||||
if (basename) {
|
||||
return `${basename}${path}` + (hasEnd ? '' : '/');
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
// 动态计算 basename,根据当前 URL 路径
|
||||
export const getDynamicBasename = (): string => {
|
||||
const path = window.location.pathname
|
||||
const [user, key, id] = path.split('/').filter(Boolean)
|
||||
if (key === 'v1' && id) {
|
||||
return `/${user}/v1/${id}`
|
||||
}
|
||||
// 默认使用构建时的 basename
|
||||
return basename
|
||||
}
|
||||
20
src/modules/query.ts
Normal file
20
src/modules/query.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Query } from '@kevisual/query';
|
||||
import { QueryLoginBrowser } from '@kevisual/api/query-login'
|
||||
import { useContextKey } from '@kevisual/context';
|
||||
export const query = useContextKey('query', () => {
|
||||
return new Query({
|
||||
url: '/api/router',
|
||||
});
|
||||
});
|
||||
|
||||
export const queryClient = useContextKey('queryClient', () => {
|
||||
return new Query({
|
||||
url: '/client/router',
|
||||
});
|
||||
});
|
||||
|
||||
export const queryLogin = useContextKey('queryLogin', () => {
|
||||
return new QueryLoginBrowser({
|
||||
query: query
|
||||
});
|
||||
});
|
||||
9
src/pages/about/page.tsx
Normal file
9
src/pages/about/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
export default function AboutPage() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
About Light Code
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
58
src/pages/auth/index.tsx
Normal file
58
src/pages/auth/index.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import { useEffect } from "react"
|
||||
import { useLayoutStore } from "./store"
|
||||
import { useShallow } from "zustand/shallow"
|
||||
import { LogIn, LockKeyhole } from "lucide-react"
|
||||
export { BaseHeader } from './modules/BaseHeader'
|
||||
import { useMemo } from 'react';
|
||||
import { useLocation, useNavigate } from '@tanstack/react-router';
|
||||
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode,
|
||||
mustLogin?: boolean,
|
||||
}
|
||||
export const AuthProvider = ({ children, mustLogin }: Props) => {
|
||||
const store = useLayoutStore(useShallow(state => ({
|
||||
init: state.init,
|
||||
me: state.me,
|
||||
openLinkList: state.openLinkList,
|
||||
})));
|
||||
useEffect(() => {
|
||||
store.init()
|
||||
}, [])
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate();
|
||||
const isOpen = useMemo(() => {
|
||||
return store.openLinkList.some(item => location.pathname.startsWith(item))
|
||||
}, [location.pathname])
|
||||
const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href);
|
||||
if (mustLogin && !store.me && !isOpen) {
|
||||
return (
|
||||
<div className="w-full h-full min-h-screen flex items-center justify-center bg-background">
|
||||
<div className="flex flex-col items-center gap-6 p-10 rounded-2xl border border-border bg-card shadow-lg max-w-sm w-full mx-4">
|
||||
<div className="flex items-center justify-center w-16 h-16 rounded-full bg-muted">
|
||||
<LockKeyhole className="w-8 h-8 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="flex flex-col items-center gap-2 text-center">
|
||||
<h2 className="text-xl font-semibold text-foreground">需要登录</h2>
|
||||
<p className="text-sm text-muted-foreground">请先登录以继续访问此页面</p>
|
||||
</div>
|
||||
<div
|
||||
className="inline-flex items-center justify-center gap-2 w-full px-6 py-2.5 rounded-lg bg-foreground text-background text-sm font-medium transition-opacity hover:opacity-80 active:opacity-70"
|
||||
onClick={() => {
|
||||
// window.open(loginUrl, '_blank');
|
||||
navigate({ to: '/login' });
|
||||
}}
|
||||
>
|
||||
<LogIn className="w-4 h-4" />
|
||||
立即登录
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return <>
|
||||
{children}
|
||||
</>
|
||||
}
|
||||
93
src/pages/auth/modules/BaseHeader.tsx
Normal file
93
src/pages/auth/modules/BaseHeader.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Home, User, LogIn, LogOut } from 'lucide-react';
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import { useLayoutStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const BaseHeader = (props: { main?: React.ComponentType | null }) => {
|
||||
const store = useLayoutStore(useShallow(state => ({
|
||||
me: state.me,
|
||||
clearMe: state.clearMe,
|
||||
links: state.links,
|
||||
showBaseHeader: state.showBaseHeader,
|
||||
})));
|
||||
const navigate = useNavigate();
|
||||
const meInfo = useMemo(() => {
|
||||
if (!store.me) {
|
||||
return (
|
||||
<button
|
||||
onClick={() => navigate({ to: '/login' })}
|
||||
className="flex items-center gap-2 px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors cursor-pointer"
|
||||
>
|
||||
<LogIn className="w-4 h-4" />
|
||||
<span>去登录</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{store.me.avatar && (
|
||||
<img
|
||||
src={store.me.avatar}
|
||||
alt="Avatar"
|
||||
className="w-8 h-8 rounded-full object-cover"
|
||||
/>
|
||||
)}
|
||||
{!store.me.avatar && (
|
||||
<div className="w-8 h-8 rounded-full bg-gray-200 flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-gray-500" />
|
||||
</div>
|
||||
)}
|
||||
<span className="font-medium text-gray-700">{store.me?.username}</span>
|
||||
<button
|
||||
onClick={() => store.clearMe?.()}
|
||||
className="flex items-center gap-1 px-2 py-1 text-sm text-gray-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors cursor-pointer"
|
||||
title="退出登录"
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}, [store.me, store.clearMe])
|
||||
if (!store.showBaseHeader) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div className="flex gap-2 text-lg w-full h-12 items-center justify-between bg-gray-200">
|
||||
<div className='px-2 flex items-center gap-1'>
|
||||
{
|
||||
store.links.map(link => (
|
||||
<div key={link.key || link.title}
|
||||
className="cursor-pointer flex items-center justify-center gap-1 p-2 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors"
|
||||
onClick={() => {
|
||||
if (!link.href) return;
|
||||
if (link.href.startsWith('http') || link.isRoot) {
|
||||
window.open(link.href, '_blank');
|
||||
return;
|
||||
}
|
||||
navigate({
|
||||
to: link.href
|
||||
})
|
||||
}}
|
||||
>
|
||||
{link.key === 'home' && <Home className="w-4 h-4" />}
|
||||
{link.icon && <>{link.icon}</>}
|
||||
{!link.icon && link.title}
|
||||
</div>
|
||||
|
||||
))
|
||||
}
|
||||
</div>
|
||||
<div className='mr-4'>
|
||||
{meInfo}
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export const LayoutMain = () => {
|
||||
return <BaseHeader />
|
||||
}
|
||||
81
src/pages/auth/page.tsx
Normal file
81
src/pages/auth/page.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import { useContextKey } from '@kevisual/context';
|
||||
import '@kevisual/kv-login';
|
||||
import { checkPluginLogin } from '@kevisual/kv-login'
|
||||
import { useEffect } from 'react';
|
||||
import { useLayoutStore } from './store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
|
||||
export const LoginComponent = ({ onLoginSuccess }: { onLoginSuccess: () => void }) => {
|
||||
useEffect(() => {
|
||||
// 监听登录成功事件
|
||||
const handleLoginSuccess = () => {
|
||||
console.log('监听到登录成功事件,关闭弹窗');
|
||||
onLoginSuccess();
|
||||
};
|
||||
const loginEmitter = useContextKey('login-emitter')
|
||||
console.log('KvLogin Types:', loginEmitter);
|
||||
|
||||
loginEmitter.on('login-success', handleLoginSuccess);
|
||||
|
||||
// 清理监听器
|
||||
return () => {
|
||||
loginEmitter.off('login-success', handleLoginSuccess);
|
||||
};
|
||||
}, [onLoginSuccess]);
|
||||
|
||||
// @ts-ignore
|
||||
return (<kv-login></kv-login>)
|
||||
}
|
||||
export const App = () => {
|
||||
const store = useLayoutStore(useShallow((state) => ({
|
||||
init: state.init,
|
||||
loginPageConfig: state.loginPageConfig,
|
||||
})));
|
||||
useEffect(() => {
|
||||
checkPluginLogin();
|
||||
}, []);
|
||||
const navigate = useNavigate();
|
||||
const handleLoginSuccess = async () => {
|
||||
await store.init()
|
||||
navigate({ to: '/' })
|
||||
};
|
||||
const { title, subtitle, footer } = store.loginPageConfig;
|
||||
return (
|
||||
<div className='w-full h-full relative overflow-hidden bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900'>
|
||||
{/* 背景装饰 - 圆形光晕 */}
|
||||
<div className='absolute top-1/4 -left-32 w-96 h-96 bg-purple-500/30 rounded-full blur-3xl'></div>
|
||||
<div className='absolute bottom-1/4 -right-32 w-96 h-96 bg-blue-500/30 rounded-full blur-3xl'></div>
|
||||
<div className='absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[600px] bg-indigo-500/20 rounded-full blur-3xl'></div>
|
||||
|
||||
{/* 背景装饰 - 网格图案 */}
|
||||
<div className='absolute inset-0 opacity-[0.03] bg-[linear-gradient(rgba(255,255,255,0.1)_1px,transparent_1px),linear-gradient(90deg,rgba(255,255,255,0.1)_1px,transparent_1px)] bg-[size:50px_50px]'></div>
|
||||
|
||||
{/* 顶部装饰文字 */}
|
||||
<div className='absolute top-10 left-0 right-0 text-center'>
|
||||
<h1 className='text-4xl font-bold text-white/90 tracking-wider'>{title}</h1>
|
||||
<p className='mt-2 text-white/50 text-sm tracking-widest'>{subtitle}</p>
|
||||
</div>
|
||||
|
||||
{/* 登录卡片容器 */}
|
||||
<div className='w-full h-full flex items-center justify-center p-8'>
|
||||
<div className='relative'>
|
||||
{/* 卡片外圈光效 */}
|
||||
<div className='absolute -inset-1 bg-gradient-to-r from-purple-500 via-blue-500 to-indigo-500 rounded-2xl blur opacity-30'></div>
|
||||
|
||||
{/* 登录组件容器 */}
|
||||
<div className='relative bg-slate-900/80 backdrop-blur-xl rounded-2xl border border-white/10 shadow-2xl overflow-hidden'>
|
||||
<LoginComponent onLoginSuccess={handleLoginSuccess} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部装饰 */}
|
||||
<div className='absolute bottom-6 left-0 right-0 text-center'>
|
||||
<p className='text-white/30 text-xs'>{footer}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App;
|
||||
110
src/pages/auth/store.ts
Normal file
110
src/pages/auth/store.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
import { queryLogin } from '@/modules/query';
|
||||
import { create } from 'zustand';
|
||||
import { toast } from 'sonner';
|
||||
type UserInfo = {
|
||||
id?: string;
|
||||
username?: string;
|
||||
nickname?: string | null;
|
||||
needChangePassword?: boolean;
|
||||
description?: string | null;
|
||||
type?: 'user' | 'org';
|
||||
orgs?: string[];
|
||||
avatar?: string;
|
||||
};
|
||||
export type LayoutStore = {
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
openUser: boolean;
|
||||
setOpenUser: (openUser: boolean) => void;
|
||||
me?: UserInfo;
|
||||
setMe: (me: UserInfo) => void;
|
||||
clearMe: () => void;
|
||||
getMe: () => Promise<void>;
|
||||
switchOrg: (username?: string) => Promise<void>;
|
||||
isAdmin: boolean;
|
||||
setIsAdmin: (isAdmin: boolean) => void
|
||||
init: () => Promise<void>;
|
||||
openLinkList: string[];
|
||||
setOpenLinkList: (openLinkList: string[]) => void;
|
||||
loginPageConfig: {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
footer: string;
|
||||
};
|
||||
setLoginPageConfig: (config: Partial<LayoutStore['loginPageConfig']>) => void;
|
||||
links: HeaderLink[];
|
||||
setLinks: (links: HeaderLink[]) => void;
|
||||
showBaseHeader: boolean;
|
||||
setShowBaseHeader: (showBaseHeader: boolean) => void;
|
||||
};
|
||||
type HeaderLink = {
|
||||
title?: string;
|
||||
href: string;
|
||||
description?: string;
|
||||
icon?: React.ReactNode;
|
||||
key?: string;
|
||||
isRoot?: boolean;
|
||||
};
|
||||
|
||||
export const useLayoutStore = create<LayoutStore>((set, get) => ({
|
||||
open: false,
|
||||
setOpen: (open) => set({ open }),
|
||||
openUser: false,
|
||||
setOpenUser: (openUser) => set({ openUser }),
|
||||
me: undefined,
|
||||
setMe: (me) => set({ me }),
|
||||
clearMe: () => {
|
||||
set({ me: undefined, isAdmin: false });
|
||||
window.location.href = '/root/login/?redirect=' + encodeURIComponent(window.location.href);
|
||||
},
|
||||
getMe: async () => {
|
||||
const res = await queryLogin.getMe();
|
||||
if (res.code === 200) {
|
||||
set({ me: res.data });
|
||||
set({ isAdmin: res.data.orgs?.includes?.('admin') || false });
|
||||
}
|
||||
},
|
||||
switchOrg: async (username?: string) => {
|
||||
const res = await queryLogin.switchUser(username || '');
|
||||
if (res.code === 200) {
|
||||
toast.success('切换成功');
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
toast.error(res.message || '请求失败');
|
||||
}
|
||||
},
|
||||
isAdmin: false,
|
||||
setIsAdmin: (isAdmin) => set({ isAdmin }),
|
||||
init: async () => {
|
||||
const token = await queryLogin.getToken();
|
||||
if (token) {
|
||||
set({ me: {} })
|
||||
const me = await queryLogin.getMe();
|
||||
// const user = await queryLogin.checkLocalUser() as UserInfo;
|
||||
const user = me.code === 200 ? me.data : undefined;
|
||||
if (user) {
|
||||
set({ me: user });
|
||||
set({ isAdmin: user.orgs?.includes?.('admin') || false });
|
||||
} else {
|
||||
set({ me: undefined, isAdmin: false });
|
||||
}
|
||||
}
|
||||
},
|
||||
openLinkList: ['/login'],
|
||||
setOpenLinkList: (openLinkList) => set({ openLinkList }),
|
||||
loginPageConfig: {
|
||||
title: '可视化管理平台',
|
||||
subtitle: '让工具和智能化触手可及',
|
||||
footer: '欢迎使用可视化管理平台 · 连接您的工具',
|
||||
},
|
||||
setLoginPageConfig: (config) => set((state) => ({
|
||||
loginPageConfig: { ...state.loginPageConfig, ...config },
|
||||
})),
|
||||
links: [{ title: '', href: '/', key: 'home' }],
|
||||
setLinks: (links) => set({ links }),
|
||||
showBaseHeader: true,
|
||||
setShowBaseHeader: (showBaseHeader) => set({ showBaseHeader }),
|
||||
}));
|
||||
@@ -1,10 +1,10 @@
|
||||
import { app } from '@/index.ts'
|
||||
import { app } from '@/agents'
|
||||
import { useStudioStore } from '../studio/store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useState } from 'react';
|
||||
import { query } from '@/modules/query.ts'
|
||||
import { QueryViewMessages } from '../query-view';
|
||||
import { toast } from 'react-toastify';
|
||||
import { toast } from 'sonner';
|
||||
export const Chat = () => {
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
routes: state.routes,
|
||||
@@ -19,8 +19,14 @@ export const Chat = () => {
|
||||
setIsLoading(true);
|
||||
const { routes } = studioStore;
|
||||
let callPrompts = '';
|
||||
const toolsList = routes.map((r, index) =>
|
||||
`${index + 1}. 工具名称: ${r.id}\n 描述: ${r.description}`
|
||||
const toolsList = routes.map((r, index) => {
|
||||
const args = r.metadata?.args || {};
|
||||
let argsDescription = '';
|
||||
if (Object.keys(args).length > 0) {
|
||||
argsDescription = ',参数: ' + JSON.stringify(args);
|
||||
}
|
||||
return `${index + 1}. 工具名称: path: ${r.path} key: ${r.key}\n 描述: ${r.description}${argsDescription}`;
|
||||
}
|
||||
).join('\n\n');
|
||||
|
||||
callPrompts = `你是一个 AI 助手,你可以使用以下工具来帮助用户完成任务:
|
||||
@@ -34,7 +40,8 @@ ${toolsList}
|
||||
## JSON 数据格式
|
||||
\`\`\`json
|
||||
{
|
||||
"id": "工具的id",
|
||||
"path": "工具的path",
|
||||
"key": "工具的key",
|
||||
"payload": {
|
||||
// 工具所需的参数(如果需要)
|
||||
// 例如: "id": "xxx", "name": "xxx"
|
||||
@@ -45,7 +52,7 @@ ${toolsList}
|
||||
注意:
|
||||
- payload 中包含工具执行所需的所有参数
|
||||
- 如果工具不需要参数,payload 可以为空对象 {}
|
||||
- 确保返回的 id 与上述工具列表中的工具名称完全匹配`
|
||||
- 确保返回的 path 和 key 与上述工具列表中的工具名称完全匹配`
|
||||
|
||||
const res = await query.post({
|
||||
path: 'ai',
|
||||
@@ -69,7 +76,7 @@ ${toolsList}
|
||||
// 处理返回结果
|
||||
const payload = res.data?.action;
|
||||
if (payload) {
|
||||
const route = routes.find(r => r.id === payload.id);
|
||||
const route = routes.find(r => r.path === payload.path && r.key === payload.key);
|
||||
const { path, key } = route || {};
|
||||
const { id, ...otherParams } = payload.payload || {};
|
||||
const action = { path, key, ...otherParams }
|
||||
@@ -101,7 +108,7 @@ ${toolsList}
|
||||
}
|
||||
return <div className="h-full flex flex-col border-l border-gray-300 bg-white">
|
||||
<div style={{ height: '3rem' }} className="flex items-center justify-between px-4 border-b border-gray-300 bg-gray-50">
|
||||
<div className="text-sm text-gray-600">智能体</div>
|
||||
<div className="text-sm text-gray-600">执行体</div>
|
||||
</div>
|
||||
<div style={{ height: 'calc(100% - 3rem)' }} className="overflow-auto">
|
||||
<QueryViewMessages type="component" />
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import MDEditor from '@uiw/react-md-editor'
|
||||
import { ToastContainer, Slide } from 'react-toastify'
|
||||
import { Save, Download, Printer, Eye, Edit, RotateCcw } from 'lucide-react'
|
||||
import 'github-markdown-css/github-markdown-light.css'
|
||||
import './index.css'
|
||||
@@ -71,7 +70,6 @@ export const AppProvider = () => {
|
||||
return (
|
||||
<div>
|
||||
<App />
|
||||
<ToastContainer transition={Slide} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
7
src/pages/id/page.tsx
Normal file
7
src/pages/id/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
export default function IdPage() {
|
||||
return (
|
||||
<div>
|
||||
<h1>V1 ID Page</h1>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
8
src/pages/page.tsx
Normal file
8
src/pages/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import { AppProvider } from './studio/index.tsx';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<AppProvider />
|
||||
);
|
||||
}
|
||||
589
src/pages/query-view/components/DetailsDialog.tsx
Normal file
589
src/pages/query-view/components/DetailsDialog.tsx
Normal file
@@ -0,0 +1,589 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { DetailsTab, useQueryViewStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useStudioStore, filterRouteInfo, getPayload } from '@/pages/studio/store';
|
||||
import { QueryView } from '..';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { pickRouterViewData, RouterViewData, RouterViewItem } from '@kevisual/api/proxy';
|
||||
import { RouteInfo, fromJSONSchema } from '@kevisual/router/browser';
|
||||
import { pick } from 'es-toolkit';
|
||||
import { toast } from 'sonner';
|
||||
import { Play } from 'lucide-react';
|
||||
// 视图信息表格组件
|
||||
export const ViewInfoTable = ({ currentView }: { currentView?: RouterViewData }) => {
|
||||
|
||||
if (!currentView || !currentView.views || currentView.views.length === 0) {
|
||||
return (
|
||||
<div className="text-sm text-gray-500 text-center py-8">
|
||||
当前视图没有子视图信息
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* 当前选中的视图 ID */}
|
||||
{currentView.viewId && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">当前视图 ID</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{currentView.viewId}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Link */}
|
||||
{currentView.link && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">链接</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md break-all">
|
||||
{currentView.link}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Summary */}
|
||||
{currentView.summary && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">摘要</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{currentView.summary}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tags */}
|
||||
{currentView.tags && currentView.tags.length > 0 && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">标签</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{currentView.tags.map((tag: string, index: number) => (
|
||||
<span
|
||||
key={index}
|
||||
className="px-2 py-1 text-xs bg-gray-900 text-white rounded-md"
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Title */}
|
||||
{currentView.title && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">标题</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{currentView.title}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Description */}
|
||||
{currentView.description && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">描述</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md whitespace-pre-wrap">
|
||||
{currentView.description}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 子视图列表表格 */}
|
||||
<div>
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-2">视图列表</label>
|
||||
<div className="border border-gray-300 rounded-md overflow-hidden">
|
||||
<table className="w-full">
|
||||
<thead className="bg-gray-100 border-b border-gray-300">
|
||||
<tr>
|
||||
<th className="px-4 py-2 text-left text-xs font-semibold text-gray-700">ID</th>
|
||||
<th className="px-4 py-2 text-left text-xs font-semibold text-gray-700">标题</th>
|
||||
<th className="px-4 py-2 text-left text-xs font-semibold text-gray-700">查询</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{currentView.views.map((view: any, index: number) => {
|
||||
const isSelected = view.id === currentView.viewId;
|
||||
return (
|
||||
<tr
|
||||
key={view.id || index}
|
||||
className={`border-b border-gray-200 transition-colors ${isSelected
|
||||
? 'bg-gray-500 hover:bg-gray-900'
|
||||
: index % 2 === 0
|
||||
? 'bg-white hover:bg-gray-50'
|
||||
: 'bg-gray-50 hover:bg-gray-100'
|
||||
}`}
|
||||
>
|
||||
<td className={`px-4 py-2 text-sm ${isSelected ? 'text-white font-semibold' : 'text-gray-900'}`}>
|
||||
<div className="flex items-center gap-2">
|
||||
{view.id || '-'}
|
||||
{isSelected && (
|
||||
<span className="px-2 py-0.5 text-xs bg-white text-gray-900 rounded-full font-medium">
|
||||
当前
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className={`px-4 py-2 text-sm ${isSelected ? 'text-white' : 'text-gray-900'}`}>{view.title || '-'}</td>
|
||||
<td className={`px-4 py-2 text-sm font-mono ${isSelected ? 'text-gray-200' : 'text-gray-600'}`}>
|
||||
{view.query || '-'}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const DetailsInfoPanel = ({ detailsData }: { detailsData: RouterViewItem | null }) => {
|
||||
const queryViewStore = useQueryViewStore(useShallow((state) => ({
|
||||
editing: state.editing,
|
||||
setEditing: state.setEditing,
|
||||
setDetailsData: state.setDetailsData,
|
||||
setDetailsActiveTab: state.setDetailsActiveTab
|
||||
})));
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
queryProxy: state.queryProxy,
|
||||
})));
|
||||
if (!detailsData) {
|
||||
return (
|
||||
<div className="text-sm text-gray-500 text-center py-8">
|
||||
无法获取详情信息
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const [action, setAction] = useState(detailsData.action ? JSON.stringify(detailsData.action, null, 2) : '');
|
||||
const otherFilds = useMemo(() => {
|
||||
const { type } = detailsData;
|
||||
if (type === 'api') {
|
||||
{/* 其他字段 */ }
|
||||
return <>{
|
||||
detailsData.api && (
|
||||
<div className="border-b border-gray-200 pb-3 w-full scrollbar">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">API</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
<pre className="text-xs w-full">
|
||||
{JSON.stringify(detailsData.api, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</>
|
||||
}
|
||||
if (type === 'context') {
|
||||
return <>{
|
||||
detailsData.context && (
|
||||
<div className="border-b border-gray-200 pb-3 w-full scrollbar">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">上下文</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
<pre className="text-xs w-full">
|
||||
{JSON.stringify(detailsData.context, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</>
|
||||
}
|
||||
if (type === 'page') {
|
||||
return <>{
|
||||
detailsData.page && (
|
||||
<div className="border-b border-gray-200 pb-3 w-full scrollbar">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">页面信息</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
<pre className="text-xs w-full">
|
||||
{JSON.stringify(detailsData.page, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</>
|
||||
}
|
||||
return null;
|
||||
}, [detailsData]);
|
||||
const onRun = useCallback(async () => {
|
||||
let _action = detailsData?.action;
|
||||
const isEditing = queryViewStore.editing;
|
||||
if (isEditing) {
|
||||
try {
|
||||
_action = JSON.parse(action as string);
|
||||
} catch (error) {
|
||||
toast.error('操作信息必须是合法的 JSON 格式');
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (!_action) {
|
||||
toast.error('没有操作信息可供执行');
|
||||
return;
|
||||
}
|
||||
if (!studioStore.queryProxy) {
|
||||
toast.error('没有可用的查询代理,无法执行操作');
|
||||
return;
|
||||
}
|
||||
const payload = getPayload(_action as any);
|
||||
const res = await studioStore.queryProxy.run({
|
||||
..._action,
|
||||
// @ts-ignore
|
||||
payload,
|
||||
})
|
||||
console.log('执行结果', res);
|
||||
if (res?.code === 200) {
|
||||
queryViewStore.setDetailsData({
|
||||
...detailsData,
|
||||
action: _action,
|
||||
response: res,
|
||||
});
|
||||
toast.success('操作执行成功', {
|
||||
action: {
|
||||
label: '查看数据',
|
||||
onClick: () => queryViewStore.setDetailsActiveTab('response'),
|
||||
},
|
||||
closeButton: true,
|
||||
duration: 2000,
|
||||
position: 'top-center',
|
||||
});
|
||||
} else {
|
||||
toast.error(`操作执行失败: ${res?.message || '未知错误'}`);
|
||||
}
|
||||
}, [queryViewStore.editing, studioStore.queryProxy, action]);
|
||||
const runCom = (
|
||||
<button
|
||||
className="inline-flex items-center gap-1 ml-2 px-2 py-0.5 text-xs rounded-md bg-gray-900 text-white hover:bg-gray-700 transition-colors align-middle cursor-pointer"
|
||||
onClick={() => {
|
||||
console.log('点击执行', detailsData.action);
|
||||
onRun();
|
||||
}}
|
||||
>
|
||||
<Play className="w-3 h-3" />
|
||||
执行
|
||||
</button>
|
||||
)
|
||||
const editCom = (<>
|
||||
{queryViewStore.editing && <button
|
||||
className="inline-flex items-center gap-1 ml-2 px-2 py-0.5 text-xs rounded-md bg-gray-900 text-white hover:bg-gray-700 transition-colors align-middle cursor-pointer"
|
||||
onClick={() => {
|
||||
if (queryViewStore.editing) {
|
||||
// 保存操作
|
||||
try {
|
||||
const parsedAction = JSON.parse(action);
|
||||
detailsData.action = parsedAction;
|
||||
queryViewStore.setEditing(false);
|
||||
queryViewStore.setDetailsData({ ...detailsData });
|
||||
toast.success('操作信息已更新');
|
||||
} catch (error) {
|
||||
toast.error('操作信息必须是合法的 JSON 格式');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}}>保存</button>}
|
||||
<button
|
||||
className="inline-flex items-center gap-1 ml-2 px-2 py-0.5 text-xs rounded-md border border-gray-300 hover:bg-gray-50 transition-colors align-middle cursor-pointer"
|
||||
onClick={() => {
|
||||
if (queryViewStore.editing) {
|
||||
setAction(detailsData.action ? JSON.stringify(detailsData.action, null, 2) : '');
|
||||
}
|
||||
queryViewStore.setEditing(!queryViewStore.editing);
|
||||
}}
|
||||
>
|
||||
{queryViewStore.editing ? '取消' : '编辑'}
|
||||
</button>
|
||||
</>)
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Type */}
|
||||
{detailsData.type && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">类型</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{detailsData.type}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Title */}
|
||||
{detailsData.title && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">标题</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{detailsData.title}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Description */}
|
||||
{detailsData.description && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">描述</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md whitespace-pre-wrap">
|
||||
{detailsData.description}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Action */}
|
||||
{!queryViewStore.editing && detailsData.action && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<div className="text-sm font-semibold text-gray-700 block mb-1 py-2 cursor-pointer">操作 {runCom} {editCom}</div>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
<pre className="text-xs overflow-auto cursor-pointer" onClick={() => queryViewStore.setEditing(true)}>
|
||||
{JSON.stringify(detailsData.action, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{queryViewStore.editing && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<div className="text-sm font-semibold text-gray-700 block mb-1 py-2">操作 {runCom} {editCom} </div>
|
||||
<textarea
|
||||
className="text-sm text-gray-900 bg-gray-100 px-3 py-2 rounded-md w-full h-32 font-mono border-gray-600 focus:ring-2 focus:ring-gray-500 focus:outline-none scrollbar"
|
||||
value={action}
|
||||
onChange={(e) => {
|
||||
setAction(e.target.value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{otherFilds}
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const RouterInfoPanel = ({ routeInfo }: { routeInfo: RouteInfo | null }) => {
|
||||
if (!routeInfo) {
|
||||
return (
|
||||
<div className="text-sm text-gray-500 text-center py-8">
|
||||
无法获取路由信息
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const _routeInfo = pick(routeInfo, ['id', 'path', 'key', 'description', 'metadata']);
|
||||
const metadata = useMemo(() => {
|
||||
if (!_routeInfo.metadata) return null;
|
||||
const _metadata = _routeInfo.metadata;
|
||||
if (_metadata.viewItem) {
|
||||
_metadata.viewItem = filterRouteInfo(_metadata.viewItem);
|
||||
}
|
||||
return _metadata;
|
||||
}, [_routeInfo.metadata]);
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* ID */}
|
||||
{_routeInfo.id && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">ID{_routeInfo?.id.startsWith("rand") ? ' (当前id会随机变化)' : ''}</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{_routeInfo.id}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Path */}
|
||||
{_routeInfo.path && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">路径</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{_routeInfo.path}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Key */}
|
||||
{_routeInfo.key && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">Key</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
{_routeInfo.key}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Description */}
|
||||
{_routeInfo.description && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">描述</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md whitespace-pre-wrap">
|
||||
{_routeInfo.description}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Metadata */}
|
||||
{metadata && (
|
||||
<div className="border-b border-gray-200 pb-3">
|
||||
<label className="text-sm font-semibold text-gray-700 block mb-1">Metadata</label>
|
||||
<div className="text-sm text-gray-900 bg-gray-50 px-3 py-2 rounded-md">
|
||||
<pre className="text-xs overflow-auto">
|
||||
{JSON.stringify(metadata, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>);
|
||||
}
|
||||
|
||||
export const DetailsDialog = () => {
|
||||
const queryViewStore = useQueryViewStore(
|
||||
useShallow((state) => ({
|
||||
showDetailsDialog: state.showDetailsDialog,
|
||||
setShowDetailsDialog: state.setShowDetailsDialog,
|
||||
detailsData: state.detailsData,
|
||||
detailsActiveTab: state.detailsActiveTab,
|
||||
setDetailsActiveTab: state.setDetailsActiveTab,
|
||||
allDetailsTabs: state.allDetailsTabs,
|
||||
setAllDetailsTabs: state.setAllDetailsTabs,
|
||||
editing: state.editing,
|
||||
setEditing: state.setEditing,
|
||||
}))
|
||||
);
|
||||
|
||||
const { currentView, queryProxy } = useStudioStore(useShallow((state) => ({
|
||||
currentView: state.currentView,
|
||||
queryProxy: state.queryProxy,
|
||||
})));
|
||||
const [isFullscreen, setIsFullscreen] = useState(false)
|
||||
const [forceViewDialogOpen, setForceViewDialogOpen] = useState(false)
|
||||
const routeInfo = useMemo(() => {
|
||||
const action = queryViewStore?.detailsData?.action;
|
||||
if (!action) return null;
|
||||
if (!queryProxy) return null;
|
||||
const router = queryProxy!.router?.findRoute?.(action)
|
||||
if (!router) return null;
|
||||
return router as RouteInfo;
|
||||
}, [queryProxy, queryViewStore.detailsData]);
|
||||
console.log('metadata', queryViewStore.detailsData?._id, queryViewStore.detailsData);
|
||||
const onChangeTab = useCallback((key) => {
|
||||
if (key !== 'response') {
|
||||
queryViewStore.setDetailsActiveTab(key);
|
||||
return;
|
||||
}
|
||||
let needCheck = true;
|
||||
const action = queryViewStore?.detailsData?.action;
|
||||
if (!action) {
|
||||
needCheck = false
|
||||
toast.error('没有操作信息,无法查看响应数据');
|
||||
return
|
||||
}
|
||||
|
||||
const args = routeInfo?.metadata?.args || [];
|
||||
const keys = Object.keys(args);
|
||||
if (keys.length === 0) {
|
||||
needCheck = false;
|
||||
}
|
||||
if (!needCheck) {
|
||||
queryViewStore.setDetailsActiveTab(key);
|
||||
return;
|
||||
}
|
||||
console.log('args', args);
|
||||
|
||||
const payload = getPayload(action as any);
|
||||
payload.data = {}
|
||||
const schema = fromJSONSchema<true>(args, { mergeObject: true });
|
||||
console.log('payload', payload);
|
||||
console.log('schema', schema);
|
||||
const validateResult = schema.safeParse(payload);
|
||||
console.log('validateResult', validateResult);
|
||||
if (!validateResult.success) {
|
||||
// 参数不合法,无法查看响应数据,需要提示用户强制查看还是取消,如果用户选择强制查看,则直接切换到响应标签页,如果用户选择取消,则保持在当前标签页
|
||||
setForceViewDialogOpen(true);
|
||||
} else {
|
||||
queryViewStore.setDetailsActiveTab(key);
|
||||
}
|
||||
|
||||
}, [routeInfo])
|
||||
if (!queryViewStore.detailsData) return null;
|
||||
return (
|
||||
<>
|
||||
<Dialog open={forceViewDialogOpen} onOpenChange={setForceViewDialogOpen}>
|
||||
<DialogContent className="max-w-sm!">
|
||||
<DialogHeader>
|
||||
<DialogTitle>参数不合法</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="text-sm text-gray-600 py-2">
|
||||
当前参数不合法,可能导致请求失败。是否仍要强制查看响应数据?
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 mt-2">
|
||||
<button
|
||||
className="px-4 py-2 text-sm rounded-md border border-gray-300 hover:bg-gray-50 transition-colors"
|
||||
onClick={() => {
|
||||
setForceViewDialogOpen(false);
|
||||
queryViewStore.setEditing(true);
|
||||
queryViewStore.setDetailsActiveTab('details');
|
||||
}}
|
||||
>
|
||||
去编辑
|
||||
</button>
|
||||
<button
|
||||
className="px-4 py-2 text-sm rounded-md border border-gray-300 hover:bg-gray-50 transition-colors"
|
||||
onClick={() => setForceViewDialogOpen(false)}
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
className="px-4 py-2 text-sm rounded-md bg-gray-900 text-white hover:bg-gray-700 transition-colors"
|
||||
onClick={() => {
|
||||
setForceViewDialogOpen(false);
|
||||
queryViewStore.setDetailsActiveTab('response');
|
||||
}}
|
||||
>
|
||||
强制查看
|
||||
</button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={queryViewStore.showDetailsDialog} onOpenChange={queryViewStore.setShowDetailsDialog}>
|
||||
<DialogContent className={`flex flex-col max-h-[85vh] ${isFullscreen ? 'w-screen! h-screen! max-w-screen! max-h-screen! ' : 'max-w-4xl! '}`}>
|
||||
<DialogHeader className="flex-shrink-0">
|
||||
<DialogTitle>详情信息</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex gap-2 border-b border-gray-200 flex-shrink-0">
|
||||
{queryViewStore.allDetailsTabs.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
onClick={() => onChangeTab(tab.key as DetailsTab)}
|
||||
className={`px-4 py-2 text-sm font-medium transition-colors relative ${queryViewStore.detailsActiveTab === tab.key
|
||||
? 'text-gray-900 border-b-2 border-gray-900'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-auto scrollbar px-2 min-h-0">
|
||||
{/* 第一个标签页:详情信息 */}
|
||||
{queryViewStore.detailsActiveTab === 'details' && (
|
||||
<DetailsInfoPanel detailsData={queryViewStore.detailsData} />
|
||||
)}
|
||||
|
||||
{/* 第二个标签页:当前视图 */}
|
||||
{queryViewStore.detailsActiveTab === 'view' && (
|
||||
<ViewInfoTable currentView={currentView} />
|
||||
)}
|
||||
|
||||
{/* 第三个标签页:路由信息 */}
|
||||
{queryViewStore.detailsActiveTab === 'router' && (
|
||||
<RouterInfoPanel routeInfo={routeInfo} />
|
||||
)}
|
||||
|
||||
{/* 第四个标签页:响应 */}
|
||||
{queryViewStore.detailsActiveTab === 'response' && (
|
||||
<div className="space-y-4 h-full">
|
||||
<QueryView viewData={queryViewStore.detailsData} type={'message'} setIsFullscreen={setIsFullscreen} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog >
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,9 +1,8 @@
|
||||
import { QueryProxy, RouterViewItem } from '@kevisual/api/proxy'
|
||||
import { app } from '@/index.ts'
|
||||
import { use, useEffect, useState } from 'react'
|
||||
import { app } from '@/agents'
|
||||
import { use, useEffect, useState, useRef, useId, useMemo } from 'react'
|
||||
import { flexRender, useReactTable, getCoreRowModel, ColumnDef } from '@tanstack/react-table'
|
||||
import { RefreshCw, Info, MoreVertical, Edit, Trash2, Download, Save, ExternalLink, Code } from 'lucide-react'
|
||||
import { toast, ToastContainer, Slide } from 'react-toastify'
|
||||
import { RefreshCw, Info, MoreVertical, Edit, Trash2, Download, Save, ExternalLink, Code, Delete, Maximize, Minimize } from 'lucide-react'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
@@ -11,13 +10,18 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { useStudioStore } from '../studio/store'
|
||||
import { filterRouteInfo, Message, useStudioStore } from '../studio/store'
|
||||
import { useQueryViewStore } from './store'
|
||||
import { DetailsDialog } from './components/DetailsDialog'
|
||||
import { useShallow } from 'zustand/shallow'
|
||||
import { cloneDeep } from 'es-toolkit'
|
||||
|
||||
import { toast } from 'sonner'
|
||||
import { Result } from '@kevisual/query'
|
||||
export const QueryViewTypes = ['component', 'page', 'message'] as const
|
||||
type Props = {
|
||||
type: 'component' | 'page',
|
||||
viewData?: any
|
||||
type: typeof QueryViewTypes[number],
|
||||
viewData?: RouterViewItem,
|
||||
setIsFullscreen?: (isFullscreen: boolean) => void,
|
||||
}
|
||||
|
||||
const queryProxy = new QueryProxy({
|
||||
@@ -26,13 +30,15 @@ const queryProxy = new QueryProxy({
|
||||
export const QueryView = (props: Props) => {
|
||||
const [data, setData] = useState<any[]>([])
|
||||
const [columns, setColumns] = useState<ColumnDef<any>[]>([])
|
||||
const [type] = useState<'component' | 'page'>(props.type || 'page')
|
||||
const [type] = useState<Props['type']>(props.type || 'page')
|
||||
const [viewData, setViewData] = useState<RouterViewItem | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [showMoreMenu, setShowMoreMenu] = useState(false)
|
||||
const [selectedRow, setSelectedRow] = useState<any | null>(null)
|
||||
const [isList, setIsList] = useState(true)
|
||||
const [obj, setObj] = useState<any>(null)
|
||||
const [isFullscreen, setIsFullscreen] = useState(false)
|
||||
const routeViewRef = useRef<HTMLDivElement>(null)
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns: columns,
|
||||
@@ -41,12 +47,16 @@ export const QueryView = (props: Props) => {
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
deleteMessage: state.deleteMessage
|
||||
})))
|
||||
const main = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const res = await queryProxy.runByRouteView(viewData!)
|
||||
const response = res.response;
|
||||
console.log('response', response, viewData);
|
||||
const queryViewStore = useQueryViewStore(useShallow((state) => ({
|
||||
setShowDetailsDialog: state.setShowDetailsDialog,
|
||||
setDetailsData: state.setDetailsData,
|
||||
setEditing: state.setEditing,
|
||||
})))
|
||||
const isPage = type === 'page'
|
||||
const isMessage = type === 'message'
|
||||
const id = useId()
|
||||
|
||||
const handleResponse = (response: Result) => {
|
||||
const list = response.data?.list
|
||||
if (!list) {
|
||||
setIsList(false);
|
||||
@@ -57,8 +67,7 @@ export const QueryView = (props: Props) => {
|
||||
setIsList(true);
|
||||
}
|
||||
setData(response.data.list)
|
||||
console.log('res', res);
|
||||
const [_, firstItem] = response.data.list || []
|
||||
const [firstItem] = response.data.list || []
|
||||
if (firstItem) {
|
||||
const cols: ColumnDef<any>[] = Object.keys(firstItem).map(key => ({
|
||||
accessorKey: key,
|
||||
@@ -67,6 +76,13 @@ export const QueryView = (props: Props) => {
|
||||
}))
|
||||
setColumns(cols)
|
||||
}
|
||||
}
|
||||
const main = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const res = await queryProxy.runByRouteView(viewData!)
|
||||
const response = res.response;
|
||||
handleResponse(response)
|
||||
toast.success('数据获取成功')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
@@ -79,27 +95,19 @@ export const QueryView = (props: Props) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleShowDetails = () => {
|
||||
console.log('Show details for row:', props.viewData)
|
||||
const data = cloneDeep(props.viewData)
|
||||
delete data.api?.proxy;
|
||||
delete data.context?.router;
|
||||
delete data.worker?.worker;
|
||||
const str = JSON.stringify(data, null, 2)
|
||||
toast.info(<pre className='max-h-96 overflow-auto'>{str}</pre>, {
|
||||
autoClose: 5000,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
icon: false
|
||||
});
|
||||
const handleShowDetails = (editing?: boolean) => {
|
||||
const data = filterRouteInfo(props.viewData!)
|
||||
queryViewStore.setDetailsData(data, 'details');
|
||||
queryViewStore.setShowDetailsDialog(true);
|
||||
if (typeof editing === 'boolean') {
|
||||
queryViewStore.setEditing(editing);
|
||||
} else {
|
||||
queryViewStore.setEditing(false);
|
||||
}
|
||||
}
|
||||
|
||||
const handleEdit = () => {
|
||||
if (selectedRow) {
|
||||
console.log('Edit row:', selectedRow)
|
||||
// 在这里添加编辑逻辑
|
||||
}
|
||||
handleShowDetails(true)
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
@@ -107,7 +115,7 @@ export const QueryView = (props: Props) => {
|
||||
console.log('Delete row:', selectedRow)
|
||||
// 在这里添加删除逻辑
|
||||
}
|
||||
studioStore.deleteMessage(props.viewData!)
|
||||
studioStore.deleteMessage(props.viewData! as Message)
|
||||
}
|
||||
|
||||
const handleExport = () => {
|
||||
@@ -133,15 +141,33 @@ export const QueryView = (props: Props) => {
|
||||
// 在这里添加保存并打开逻辑
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
if (viewData) {
|
||||
main()
|
||||
|
||||
const handleToggleFullscreen = () => {
|
||||
setIsFullscreen(!isFullscreen)
|
||||
if (props.setIsFullscreen) {
|
||||
props.setIsFullscreen(!isFullscreen)
|
||||
}
|
||||
}, [viewData])
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
props.viewData && setViewData(props.viewData as RouterViewItem)
|
||||
}, [])
|
||||
if (viewData && props.type !== 'message') {
|
||||
main()
|
||||
} else if (viewData && props.type === 'message' && !viewData.response) {
|
||||
main()
|
||||
}
|
||||
}, [viewData, props.type])
|
||||
|
||||
useEffect(() => {
|
||||
if (props.viewData) {
|
||||
const detailsData = cloneDeep(props.viewData) as RouterViewItem
|
||||
setViewData(detailsData)
|
||||
// 如果是 message 类型且有 response,直接处理响应
|
||||
if (props.type === 'message' && props.viewData.response) {
|
||||
handleResponse(props.viewData.response)
|
||||
}
|
||||
}
|
||||
}, [props.viewData])
|
||||
const RenderTable = () => {
|
||||
if (!isList) {
|
||||
return <pre className='bg-gray-100 p-4 rounded-lg overflow-auto'>
|
||||
@@ -186,29 +212,53 @@ export const QueryView = (props: Props) => {
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
const isPage = type === 'page'
|
||||
return <div id='route-view' className={`w-full ${type === 'component' ? 'max-h-[600px] overflow-y-auto' : 'h-full overflow-auto'} p-4`}>
|
||||
|
||||
const typeClass = useMemo(() => {
|
||||
if (isFullscreen && type !== 'message') {
|
||||
return 'fixed inset-0 z-50 bg-white dark:bg-gray-900 w-screen h-screen'
|
||||
} else if (isFullscreen && type === 'message') {
|
||||
return 'absolute inset-0 z-50 bg-white dark:bg-gray-900 w-full h-full p-4'
|
||||
}
|
||||
switch (type) {
|
||||
case 'component':
|
||||
return 'max-h-150 overflow-y-auto'
|
||||
case 'page':
|
||||
return 'h-full overflow-auto'
|
||||
case 'message':
|
||||
return 'h-full overflow-auto'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}, [type, isFullscreen])
|
||||
|
||||
const content = <div ref={routeViewRef} id={'route-view-' + id} className={`w-full route-view ${typeClass} p-4 `}>
|
||||
<div className='mb-4'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<h2 className={`font-bold ${type === 'component' ? 'text-lg' : 'text-2xl'} truncate`} title={`路由视图 - ${viewData?.title || '未命名'}`}>路由视图 - {viewData?.title || '未命名'}</h2>
|
||||
<div className='flex items-center gap-2 relative'>
|
||||
|
||||
<button
|
||||
onClick={handleRefresh}
|
||||
disabled={isLoading}
|
||||
className='p-2 hover:bg-gray-200 rounded-lg transition-colors disabled:opacity-50'
|
||||
title='刷新'
|
||||
>
|
||||
<RefreshCw size={20} className={isLoading ? 'animate-spin' : ''} />
|
||||
<RefreshCw size={20} className={isLoading ? 'animate-spin' : 'cursor-pointer'} />
|
||||
</button>
|
||||
{!isPage && !isMessage && <button
|
||||
onClick={handleDelete}
|
||||
disabled={isLoading}
|
||||
className='p-2 hover:bg-gray-200 rounded-lg transition-colors disabled:opacity-50'
|
||||
>
|
||||
<Trash2 size={20} className='cursor-pointer' />
|
||||
</button>}
|
||||
|
||||
<DropdownMenu open={showMoreMenu} onOpenChange={setShowMoreMenu}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
<DropdownMenuTrigger
|
||||
className='p-2 hover:bg-gray-200 rounded-lg transition-colors'
|
||||
title='更多选项'
|
||||
>
|
||||
<MoreVertical size={20} />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align='end' className='w-48 border-gray-300'>
|
||||
{!isPage && (
|
||||
@@ -228,18 +278,24 @@ export const QueryView = (props: Props) => {
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
{!isMessage && (
|
||||
<DropdownMenuItem onClick={() => handleShowDetails()}>
|
||||
<Info size={16} className='mr-2' />
|
||||
<span>详情</span>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem onClick={handleEdit}>
|
||||
<Edit size={16} className='mr-2' />
|
||||
<span>编辑</span>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handleDelete} variant='destructive'>
|
||||
<DropdownMenuItem onClick={handleToggleFullscreen}>
|
||||
{isFullscreen ? <Minimize size={16} className='mr-2' /> : <Maximize size={16} className='mr-2' />}
|
||||
<span>{isFullscreen ? '退出全屏' : '全屏'}</span>
|
||||
</DropdownMenuItem>
|
||||
{!isMessage && <DropdownMenuItem onClick={handleDelete} variant='destructive'>
|
||||
<Trash2 size={16} className='mr-2' />
|
||||
<span>{!isPage ? '移除' : '删除'}</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuItem>}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={handleExport}>
|
||||
<Download size={16} className='mr-2' />
|
||||
@@ -254,10 +310,12 @@ export const QueryView = (props: Props) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-full overflow-x-auto rounded-lg shadow-md border border-gray-300'>
|
||||
<div className='w-full overflow-x-auto scrollbar rounded-lg shadow-md border border-gray-300'>
|
||||
<RenderTable />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
return content
|
||||
}
|
||||
export const QueryViewMessages = (props: Props) => {
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
@@ -267,27 +325,31 @@ export const QueryViewMessages = (props: Props) => {
|
||||
const initPage = async () => {
|
||||
const url = new URL(window.location.href)
|
||||
const id = url.searchParams.get('id') || ''
|
||||
const message = studioStore.messages.find(msg => msg.id === id)
|
||||
if (!id) {
|
||||
setTimeout(() => {
|
||||
toast.error('缺少查询视图ID参数')
|
||||
// return
|
||||
console.error('Missing query view ID parameter')
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
// 查询query-view的保存的id,赋值后然后执行查询
|
||||
// @ts-ignore
|
||||
const DemoRouterView: RouterViewItem = {
|
||||
const DemoRouterView: Message = {
|
||||
id: 'getData',
|
||||
description: '获取数据',
|
||||
title: '获取数据',
|
||||
type: 'api',
|
||||
api: {
|
||||
// url: "/api/router",
|
||||
url: "http://localhost:52000/api/router",
|
||||
url: "/api/router",
|
||||
// url: "http://localhost:52000/api/router",
|
||||
},
|
||||
action: {
|
||||
path: 'router',
|
||||
key: 'list'
|
||||
}
|
||||
}
|
||||
studioStore.setMessages([DemoRouterView])
|
||||
studioStore.setMessages([DemoRouterView as Message])
|
||||
}
|
||||
useEffect(() => {
|
||||
const type = props.type || 'page'
|
||||
@@ -295,7 +357,7 @@ export const QueryViewMessages = (props: Props) => {
|
||||
initPage()
|
||||
}
|
||||
}, [props.type])
|
||||
return <div>
|
||||
return <div className='w-full h-full flex flex-col scrollbar'>
|
||||
{studioStore.messages.map((msg, index) => (
|
||||
<div key={msg._id || msg.id} className="p-4 border-b border-gray-200">
|
||||
<QueryView viewData={msg} type={props.type} />
|
||||
@@ -304,8 +366,8 @@ export const QueryViewMessages = (props: Props) => {
|
||||
</div>
|
||||
}
|
||||
export const AppProvider = () => {
|
||||
return <main className='w-full h-screen flex flex-col overflow-auto'>
|
||||
return <div className='w-full h-full flex flex-col overflow-hidden'>
|
||||
<DetailsDialog />
|
||||
<QueryViewMessages type="page" />
|
||||
<ToastContainer position="top-center" autoClose={1000} hideProgressBar={false} newestOnTop={false} closeOnClick rtl={false} pauseOnFocusLoss draggable pauseOnHover transition={Slide} />
|
||||
</main>
|
||||
</div>
|
||||
}
|
||||
6
src/pages/query-view/page.tsx
Normal file
6
src/pages/query-view/page.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { AppProvider } from './index'
|
||||
export default function App() {
|
||||
return (
|
||||
<AppProvider />
|
||||
)
|
||||
}
|
||||
60
src/pages/query-view/store/index.ts
Normal file
60
src/pages/query-view/store/index.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { RouterViewItem } from '@kevisual/api/proxy';
|
||||
import { create } from 'zustand';
|
||||
|
||||
export const detailsTabs = ['details', 'view', 'router', 'response'] as const;
|
||||
export const AllTabs = [
|
||||
{
|
||||
key: 'details',
|
||||
label: '详情',
|
||||
},
|
||||
{
|
||||
key: 'view',
|
||||
label: '视图',
|
||||
},
|
||||
{
|
||||
key: 'router',
|
||||
label: '路由',
|
||||
},
|
||||
{
|
||||
key: 'response',
|
||||
label: '响应',
|
||||
},
|
||||
]
|
||||
export type DetailsTab = (typeof detailsTabs)[number];
|
||||
type QueryViewState = {
|
||||
showDataDialog: boolean;
|
||||
setShowDataDialog: (show: boolean) => void;
|
||||
dataDialogContent: any;
|
||||
setDataDialogContent: (content: any) => void;
|
||||
showDetailsDialog: boolean;
|
||||
setShowDetailsDialog: (show: boolean) => void;
|
||||
detailsData: RouterViewItem | null;
|
||||
setDetailsData: (data: RouterViewItem | null, tab?: DetailsTab) => void;
|
||||
detailsActiveTab: DetailsTab;
|
||||
setDetailsActiveTab: (tab: DetailsTab) => void;
|
||||
allDetailsTabs: typeof AllTabs;
|
||||
setAllDetailsTabs: (tabs: typeof AllTabs) => void;
|
||||
editing: boolean;
|
||||
setEditing: (editing: boolean) => void;
|
||||
};
|
||||
export const useQueryViewStore = create<QueryViewState>((set) => ({
|
||||
showDataDialog: false,
|
||||
setShowDataDialog: (show) => set({ showDataDialog: show }),
|
||||
dataDialogContent: null,
|
||||
setDataDialogContent: (content) => set({ dataDialogContent: content }),
|
||||
showDetailsDialog: false,
|
||||
setShowDetailsDialog: (show) => set({ showDetailsDialog: show }),
|
||||
detailsData: null,
|
||||
setDetailsData: (data, tab) => {
|
||||
if (typeof tab !== 'undefined') {
|
||||
set({ detailsActiveTab: tab });
|
||||
}
|
||||
set({ detailsData: data })
|
||||
},
|
||||
detailsActiveTab: 'details',
|
||||
setDetailsActiveTab: (tab) => set({ detailsActiveTab: tab }),
|
||||
editing: false,
|
||||
setEditing: (editing) => set({ editing }),
|
||||
allDetailsTabs: AllTabs,
|
||||
setAllDetailsTabs: (tabs) => set({ allDetailsTabs: tabs }),
|
||||
}));
|
||||
5
src/pages/setting/index.tsx
Normal file
5
src/pages/setting/index.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
export const App = () => {
|
||||
return (
|
||||
<div>Studio App</div>
|
||||
)
|
||||
}
|
||||
158
src/pages/studio/components/ExportDialog.tsx
Normal file
158
src/pages/studio/components/ExportDialog.tsx
Normal file
@@ -0,0 +1,158 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
|
||||
import { useStudioStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { createQueryByRoutes } from '@kevisual/query/api'
|
||||
import { useMemo } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Copy, Check } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { clone, cloneDeep, pick } from 'es-toolkit';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Label } from '@/components/ui/label';
|
||||
type CreateOptions = {
|
||||
removeViewItem?: boolean;
|
||||
before?: string;
|
||||
after?: string;
|
||||
}
|
||||
export const ExportDialog = () => {
|
||||
const { showExportDialog, setShowExportDialog, exportRoutes } = useStudioStore(
|
||||
useShallow((state) => ({
|
||||
showExportDialog: state.showExportDialog,
|
||||
setShowExportDialog: state.setShowExportDialog,
|
||||
exportRoutes: state.exportRoutes,
|
||||
}))
|
||||
);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [before, setBefore] = useState(() => {
|
||||
const defaultBefore = `import { createQueryApi } from '@kevisual/query/api';`;
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('exportBefore') || defaultBefore;
|
||||
}
|
||||
return defaultBefore;
|
||||
});
|
||||
const [after, setAfter] = useState(() => {
|
||||
const defaultAfter = `const queryApi = createQueryApi({ api });\n\nexport { queryApi };`;
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('exportAfter') || defaultAfter;
|
||||
}
|
||||
return defaultAfter;
|
||||
});
|
||||
const [removeViewItem, setRemoveViewItem] = useState(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('exportRemoveViewItem') === 'true';
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// 保存配置到 localStorage
|
||||
useEffect(() => {
|
||||
localStorage.setItem('exportBefore', before);
|
||||
}, [before]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('exportAfter', after);
|
||||
}, [after]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('exportRemoveViewItem', String(removeViewItem));
|
||||
}, [removeViewItem]);
|
||||
|
||||
const code = useMemo(() => {
|
||||
if (!exportRoutes) return '';
|
||||
let routeInfo = exportRoutes.map(route => pick(route, ['path', 'key', 'id', 'description', 'metadata']));
|
||||
const options: CreateOptions = {
|
||||
before,
|
||||
after,
|
||||
removeViewItem,
|
||||
};
|
||||
const query = createQueryByRoutes(cloneDeep(routeInfo as any), options);
|
||||
return query;
|
||||
}, [exportRoutes, before, after, removeViewItem]);
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(code);
|
||||
setCopied(true);
|
||||
toast.success('代码已复制到剪贴板');
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch (err) {
|
||||
toast.error('复制失败,请重试');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showExportDialog} onOpenChange={setShowExportDialog}>
|
||||
<DialogContent className="max-w-4xl! max-h-[80vh] overflow-hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle>导出API代码</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex gap-4 w-full overflow-hidden">
|
||||
<div className="w-90 shrink-0 space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="before">Before (import)</Label>
|
||||
<Textarea
|
||||
id="before"
|
||||
value={before}
|
||||
onChange={(e) => setBefore(e.target.value)}
|
||||
placeholder="import ..."
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="after">After (export)</Label>
|
||||
<Textarea
|
||||
id="after"
|
||||
value={after}
|
||||
onChange={(e) => setAfter(e.target.value)}
|
||||
placeholder="export ..."
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="removeViewItem"
|
||||
checked={removeViewItem}
|
||||
onCheckedChange={(checked) => {
|
||||
const value = checked === true;
|
||||
setRemoveViewItem(value);
|
||||
}}
|
||||
/>
|
||||
<Label htmlFor="removeViewItem">Remove View Item</Label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 p-4 border border-gray-300 rounded-md bg-gray-50">
|
||||
<pre className="text-xs max-h-[60vh] overflow-auto scrollbar">
|
||||
{code}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowExportDialog(false)}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleCopy}
|
||||
className="gap-2"
|
||||
>
|
||||
{copied ? (
|
||||
<>
|
||||
<Check size={16} />
|
||||
已复制
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Copy size={16} />
|
||||
复制代码
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
135
src/pages/studio/components/ProxyStatusDialog.tsx
Normal file
135
src/pages/studio/components/ProxyStatusDialog.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { useStudioStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { Activity, RefreshCw, CheckCircle, XCircle } from 'lucide-react';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { cloneDeep } from 'es-toolkit';
|
||||
import { RouterViewItem } from '@kevisual/api/proxy';
|
||||
|
||||
export const ProxyStatusDialog = () => {
|
||||
const { showProxyStatus, setShowProxyStatus, getQueryProxyStatus } = useStudioStore(
|
||||
useShallow((state) => ({
|
||||
showProxyStatus: state.showProxyStatus,
|
||||
setShowProxyStatus: state.setShowProxyStatus,
|
||||
getQueryProxyStatus: state.getQueryProxyStatus,
|
||||
}))
|
||||
);
|
||||
|
||||
const [statusList, setStatusList] = useState<RouterViewItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
const loadStatus = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const status = await getQueryProxyStatus();
|
||||
console.log('Loaded proxy status:', status);
|
||||
setStatusList(cloneDeep(status));
|
||||
} catch (error) {
|
||||
console.error('Failed to load proxy status:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (showProxyStatus) {
|
||||
loadStatus();
|
||||
// 每5秒刷新一次
|
||||
intervalRef.current = setInterval(loadStatus, 5000);
|
||||
} else {
|
||||
// 关闭弹窗时清除定时器
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [showProxyStatus]);
|
||||
|
||||
const getStatusStyle = (status?: string) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return {
|
||||
icon: <CheckCircle size={14} />,
|
||||
className: 'bg-green-100 text-green-700 border-green-200',
|
||||
};
|
||||
case 'error':
|
||||
return {
|
||||
icon: <XCircle size={14} />,
|
||||
className: 'bg-red-100 text-red-700 border-red-200',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
icon: null,
|
||||
className: 'bg-gray-100 text-gray-700 border-gray-200',
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showProxyStatus} onOpenChange={setShowProxyStatus}>
|
||||
<DialogContent className="max-w-2xl! max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<DialogHeader className="flex flex-row items-center justify-between">
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Activity size={20} />
|
||||
Proxy Router 状态
|
||||
<button
|
||||
className="p-1 rounded-md text-gray-500 hover:text-gray-700 hover:bg-gray-200 transition-colors"
|
||||
title="刷新"
|
||||
onClick={loadStatus}
|
||||
disabled={loading}
|
||||
>
|
||||
<RefreshCw size={16} className={loading ? 'animate-spin' : ''} />
|
||||
</button>
|
||||
</DialogTitle>
|
||||
|
||||
</DialogHeader>
|
||||
<div className="flex-1 overflow-auto">
|
||||
{loading ? (
|
||||
<div className="text-center text-gray-500 py-8">加载中...</div>
|
||||
) : statusList.length === 0 ? (
|
||||
<div className="text-center text-gray-500 py-8">暂无数据</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{statusList.map((item) => {
|
||||
const statusStyle = getStatusStyle(item.routerStatus);
|
||||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className="p-3 border border-gray-200 rounded-md hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium text-gray-900">{item.title}</span>
|
||||
<span className="text-xs text-gray-500">{item.id}</span>
|
||||
</div>
|
||||
{item.type === 'api' && item.api?.url && (
|
||||
<div className="mt-2">
|
||||
<span className="text-xs text-gray-500">URL: </span>
|
||||
<span className="text-xs font-mono text-gray-700">{item.api?.url}</span>
|
||||
</div>
|
||||
)}
|
||||
{item.routerStatus && (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded text-xs border ${statusStyle.className}`}>
|
||||
{statusStyle.icon}
|
||||
{item.routerStatus}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
196
src/pages/studio/components/RouterGroupDialog.tsx
Normal file
196
src/pages/studio/components/RouterGroupDialog.tsx
Normal file
@@ -0,0 +1,196 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { useStudioStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { FolderClosed, FolderOpen, Search, List } from 'lucide-react';
|
||||
import { useState, useMemo, useEffect } from 'react';
|
||||
|
||||
interface RouteItem {
|
||||
id: string;
|
||||
path?: string;
|
||||
key?: string;
|
||||
description?: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
interface GroupedRoutes {
|
||||
[group: string]: RouteItem[];
|
||||
}
|
||||
|
||||
type TabType = 'grouped' | 'all';
|
||||
|
||||
export const RouterGroupDialog = () => {
|
||||
const { showRouterGroup, setShowRouterGroup, routes, allRoutes, searchRoutes, setShowFilter, getAllRoutes } = useStudioStore(
|
||||
useShallow((state) => ({
|
||||
showRouterGroup: state.showRouterGroup,
|
||||
setShowRouterGroup: state.setShowRouterGroup,
|
||||
routes: state.routes,
|
||||
allRoutes: state.allRoutes,
|
||||
searchRoutes: state.searchRoutes,
|
||||
setShowFilter: state.setShowFilter,
|
||||
getAllRoutes: state.getAllRoutes,
|
||||
}))
|
||||
);
|
||||
|
||||
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(new Set());
|
||||
const [activeTab, setActiveTab] = useState<TabType>('grouped');
|
||||
|
||||
useEffect(() => {
|
||||
if (showRouterGroup && activeTab === 'all') {
|
||||
getAllRoutes();
|
||||
}
|
||||
}, [showRouterGroup, activeTab, getAllRoutes]);
|
||||
|
||||
const displayRoutes = activeTab === 'grouped' ? routes : allRoutes;
|
||||
|
||||
// 按 path 分组
|
||||
const groupedRoutes = useMemo(() => {
|
||||
const groups: GroupedRoutes = {};
|
||||
displayRoutes.forEach((route: RouteItem) => {
|
||||
if (!route.path) return;
|
||||
// 获取第一级路径作为分组
|
||||
const firstSegment = route.path.split('/').filter(Boolean)[0] || 'root';
|
||||
if (!groups[firstSegment]) {
|
||||
groups[firstSegment] = [];
|
||||
}
|
||||
groups[firstSegment].push(route);
|
||||
});
|
||||
return groups;
|
||||
}, [displayRoutes]);
|
||||
|
||||
const toggleGroup = (group: string) => {
|
||||
const newExpanded = new Set(expandedGroups);
|
||||
if (newExpanded.has(group)) {
|
||||
newExpanded.delete(group);
|
||||
} else {
|
||||
newExpanded.add(group);
|
||||
}
|
||||
setExpandedGroups(newExpanded);
|
||||
};
|
||||
|
||||
const handleSearchByPath = (e: React.MouseEvent, path: string) => {
|
||||
e.stopPropagation();
|
||||
const keyword = `WHERE path='${path}'`;
|
||||
searchRoutes(keyword);
|
||||
setShowFilter(true);
|
||||
setShowRouterGroup(false);
|
||||
};
|
||||
|
||||
const handleSearchByKey = (e: React.MouseEvent, path: string, key: string) => {
|
||||
e.stopPropagation();
|
||||
const keyword = `WHERE path='${path}' AND key='${key}'`;
|
||||
searchRoutes(keyword);
|
||||
setShowFilter(true);
|
||||
setShowRouterGroup(false);
|
||||
};
|
||||
|
||||
const sortedGroups = Object.keys(groupedRoutes).sort();
|
||||
|
||||
const renderRouteItem = (route: RouteItem) => (
|
||||
<div
|
||||
key={route.id}
|
||||
className="px-4 py-2 hover:bg-gray-50 transition-colors flex items-center justify-between"
|
||||
>
|
||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
||||
<span className="font-mono text-sm text-gray-800 truncate">{route.path}</span>
|
||||
{route.key && (
|
||||
<>
|
||||
<span className="text-xs text-gray-500">/</span>
|
||||
<span className="text-sm text-gray-600 truncate">{route.key}</span>
|
||||
<button
|
||||
className="p-1 rounded text-gray-400 hover:text-gray-700 hover:bg-gray-200 transition-colors shrink-0"
|
||||
title="搜索此路径和key"
|
||||
onClick={(e) => handleSearchByKey(e, route.path!, route.key!)}
|
||||
>
|
||||
<Search size={14} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{route.description && (
|
||||
<span className="text-xs text-gray-500 truncate max-w-xs ml-2 shrink-0">
|
||||
{route.description}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const renderGroup = (group: string) => {
|
||||
const isExpanded = expandedGroups.has(group);
|
||||
const groupRoutes = groupedRoutes[group];
|
||||
// 使用分组的第一个路由的完整 path 作为搜索关键词
|
||||
const searchPath = groupRoutes[0]?.path || `/${group}`;
|
||||
|
||||
return (
|
||||
<div key={group} className="border border-gray-200 rounded-md overflow-hidden">
|
||||
<div
|
||||
className="flex items-center gap-2 px-3 py-2 bg-gray-50 cursor-pointer hover:bg-gray-100 transition-colors"
|
||||
onClick={() => toggleGroup(group)}
|
||||
>
|
||||
{isExpanded ? (
|
||||
<FolderOpen size={18} className="text-gray-600" />
|
||||
) : (
|
||||
<FolderClosed size={18} className="text-gray-600" />
|
||||
)}
|
||||
<span className="font-medium text-gray-900">/{group}</span>
|
||||
<span className="text-xs text-gray-500">({groupRoutes.length} 个路由)</span>
|
||||
<button
|
||||
className="ml-auto p-1 rounded text-gray-400 hover:text-gray-700 hover:bg-gray-200 transition-colors"
|
||||
title="搜索此路径"
|
||||
onClick={(e) => handleSearchByPath(e, searchPath)}
|
||||
>
|
||||
<Search size={14} />
|
||||
</button>
|
||||
</div>
|
||||
{isExpanded && (
|
||||
<div className="divide-y divide-gray-100">
|
||||
{groupRoutes.map(renderRouteItem)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showRouterGroup} onOpenChange={setShowRouterGroup}>
|
||||
<DialogContent className="max-w-3xl! max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<DialogHeader>
|
||||
<DialogTitle>路由分组</DialogTitle>
|
||||
</DialogHeader>
|
||||
{/* Tabs */}
|
||||
<div className="flex border-b border-gray-200">
|
||||
<button
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-colors ${
|
||||
activeTab === 'grouped'
|
||||
? 'text-gray-900 border-b-2 border-gray-900'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
}`}
|
||||
onClick={() => setActiveTab('grouped')}
|
||||
>
|
||||
<FolderClosed size={16} />
|
||||
当前分组
|
||||
</button>
|
||||
<button
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-colors ${
|
||||
activeTab === 'all'
|
||||
? 'text-gray-900 border-b-2 border-gray-900'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
}`}
|
||||
onClick={() => setActiveTab('all')}
|
||||
>
|
||||
<List size={16} />
|
||||
全部路由 ({allRoutes.length})
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-auto space-y-2 p-2">
|
||||
{sortedGroups.length === 0 ? (
|
||||
<div className="text-center text-gray-500 py-8">
|
||||
{activeTab === 'all' && allRoutes.length === 0 ? '加载中...' : '暂无路由数据'}
|
||||
</div>
|
||||
) : (
|
||||
sortedGroups.map(renderGroup)
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -1,18 +1,27 @@
|
||||
import { toast, ToastContainer, Slide } from 'react-toastify';
|
||||
import { useStudioStore } from './store.ts';
|
||||
import { filterRouteInfo, useStudioStore } from './store.ts';
|
||||
import { use, useEffect, useState } from 'react';
|
||||
import { MonitorPlay, Play, PanelLeft, PanelLeftClose, PanelRight, PanelRightClose, Filter, FilterX, Search, X } from 'lucide-react';
|
||||
import { MonitorPlay, Play, PanelLeft, PanelLeftClose, PanelRight, PanelRightClose, PanelTop, PanelTopClose, Filter, FilterX, Search, X, MoreHorizontal, Info, Code, RotateCcw, Book, FolderClosed, Activity } from 'lucide-react';
|
||||
import { Panel, Group } from 'react-resizable-panels'
|
||||
import { ViewList } from '../view/list.tsx';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { Chat } from '../chat/index.tsx';
|
||||
import { Input } from '@/components/ui/input.tsx';
|
||||
import { Button } from '@/components/ui/button.tsx';
|
||||
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu.tsx';
|
||||
import { ExportDialog } from './components/ExportDialog';
|
||||
import { RouterGroupDialog } from './components/RouterGroupDialog';
|
||||
import { ProxyStatusDialog } from './components/ProxyStatusDialog';
|
||||
import { useQueryViewStore } from '../query-view/store/index.ts';
|
||||
import { toast } from 'sonner';
|
||||
import { DetailsDialog } from '../query-view/components/DetailsDialog.tsx';
|
||||
import { useLayoutStore } from '../auth/store.ts';
|
||||
export const AppProvider = () => {
|
||||
const { showLeftPanel, showRightPanel } = useStudioStore(useShallow((state) => ({
|
||||
showLeftPanel: state.showLeftPanel,
|
||||
showRightPanel: state.showRightPanel,
|
||||
})));
|
||||
return <main className='w-full h-screen flex flex-col overflow-hidden'>
|
||||
return <div className='w-full h-full flex flex-col overflow-hidden'>
|
||||
<DetailsDialog />
|
||||
<Group className="h-full flex-1 overflow-hidden">
|
||||
{showLeftPanel && <Panel defaultSize={300} minSize={250} maxSize={500} className="border-r border-gray-300 overflow-auto">
|
||||
<ViewList />
|
||||
@@ -31,19 +40,7 @@ export const AppProvider = () => {
|
||||
</Panel>
|
||||
|
||||
</Group>
|
||||
<ToastContainer
|
||||
position="top-right"
|
||||
autoClose={3000}
|
||||
hideProgressBar
|
||||
newestOnTop
|
||||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable
|
||||
pauseOnHover
|
||||
theme="light"
|
||||
transition={Slide} />
|
||||
</main>
|
||||
</div>
|
||||
}
|
||||
export const WrapperHeader = (props: { children: React.ReactNode }) => {
|
||||
const showLeftPanel = useStudioStore(state => state.showLeftPanel);
|
||||
@@ -55,13 +52,27 @@ export const WrapperHeader = (props: { children: React.ReactNode }) => {
|
||||
showRightPanel: state.showRightPanel,
|
||||
setShowRightPanel: state.setShowRightPanel,
|
||||
})));
|
||||
const layoutStore = useLayoutStore(useShallow((state) => ({
|
||||
showBaseHeader: state.showBaseHeader,
|
||||
setShowBaseHeader: state.setShowBaseHeader,
|
||||
})));
|
||||
return <div className='h-full'>
|
||||
<div className="w-full h-12 flex items-center justify-between px-4 border-b border-gray-200 bg-white">
|
||||
<div className='flex gap-2'>
|
||||
|
||||
<div className="cursor-pointer text-gray-600 hover:text-gray-900 transition-colors" title="Kevisual Router Studio" onClick={() => {
|
||||
store.setShowLeftPanel(!store.showLeftPanel);
|
||||
}}>
|
||||
{showLeftPanel ? <PanelLeftClose size={16} /> : <PanelLeft size={16} />}
|
||||
</div>
|
||||
<div className='cursor-pointer text-gray-600 hover:text-gray-900 transition-colors" title={layoutStore.showBaseHeader ? "隐藏BaseHeader" : "显示BaseHeader"}' onClick={
|
||||
() => {
|
||||
layoutStore.setShowBaseHeader(!layoutStore.showBaseHeader)
|
||||
}
|
||||
}>
|
||||
{layoutStore.showBaseHeader ? <PanelTopClose size={16} /> : <PanelTop size={16} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
className="p-1.5 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-200 transition-all duration-200 cursor-pointer"
|
||||
@@ -79,7 +90,7 @@ export const WrapperHeader = (props: { children: React.ReactNode }) => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ height: 'calc(100% - 3rem)' }} className="overflow-auto">
|
||||
<div style={{ height: 'calc(100% - 3rem)' }} className="overflow-auto ">
|
||||
{props.children}
|
||||
</div>
|
||||
</div >
|
||||
@@ -96,19 +107,30 @@ export const App = () => {
|
||||
const { routes, queryRouteList, run, loading, searchRoutes, ...store } = useStudioStore(useShallow((state) => ({
|
||||
routes: state.routes,
|
||||
searchRoutes: state.searchRoutes,
|
||||
searchKeyword: state.searchKeyword,
|
||||
setSearchKeyword: state.setSearchKeyword,
|
||||
queryRouteList: state.queryRouteList,
|
||||
run: state.run,
|
||||
loading: state.loading,
|
||||
showFilter: state.showFilter,
|
||||
currentView: state.currentView,
|
||||
setShowFilter: state.setShowFilter,
|
||||
setShowExportDialog: state.setShowExportDialog,
|
||||
setExportRoutes: state.setExportRoutes,
|
||||
setShowRouterGroup: state.setShowRouterGroup,
|
||||
setShowProxyStatus: state.setShowProxyStatus,
|
||||
})));
|
||||
const queryViewStore = useQueryViewStore(useShallow((state) => ({
|
||||
setShowDetailsDialog: state.setShowDetailsDialog,
|
||||
setDetailsData: state.setDetailsData,
|
||||
setEditing: state.setEditing,
|
||||
})))
|
||||
const [expandedIds, setExpandedIds] = useState<Set<string>>(new Set());
|
||||
const [visibleIds, setVisibleIds] = useState<Set<string>>(new Set());
|
||||
const [searchKeyword, setSearchKeyword] = useState<string>('');
|
||||
|
||||
const { searchKeyword, setSearchKeyword } = store
|
||||
const [defaultKeyword, setDefaultKeyword] = useState<string>('');
|
||||
useEffect(() => {
|
||||
queryRouteList();
|
||||
queryRouteList(true);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (store.showFilter) {
|
||||
@@ -126,16 +148,13 @@ export const App = () => {
|
||||
const viewItem = store.currentView.views.find(v => v.id === viewId);
|
||||
if (viewItem && viewItem.query) {
|
||||
setSearchKeyword(viewItem.query);
|
||||
setDefaultKeyword(viewItem.query);
|
||||
}
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [store.showFilter, store.currentView?.viewId]);
|
||||
const handleSearch = async (keyword: string) => {
|
||||
if (keyword.trim()) {
|
||||
await searchRoutes(keyword);
|
||||
} else {
|
||||
await queryRouteList();
|
||||
}
|
||||
await searchRoutes(keyword.trim());
|
||||
};
|
||||
|
||||
const handleKeyDown = async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
@@ -146,7 +165,7 @@ export const App = () => {
|
||||
|
||||
const handleClear = async () => {
|
||||
setSearchKeyword('');
|
||||
await queryRouteList();
|
||||
handleSearch('');
|
||||
};
|
||||
|
||||
const toggleDescription = (id: string) => {
|
||||
@@ -171,23 +190,38 @@ export const App = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="max-w-5xl mx-auto p-6 h-full overflow-auto">
|
||||
<div className="max-w-5xl mx-auto p-6 h-full overflow-hidden flex flex-col relative">
|
||||
<ExportDialog />
|
||||
<RouterGroupDialog />
|
||||
<ProxyStatusDialog />
|
||||
{loading && <div className="text-center text-gray-500 mb-4">加载中...</div>}
|
||||
{store.showFilter && (
|
||||
<div className="mb-3 animate-in fade-in slide-in-from-top-2 duration-300">
|
||||
<div className="flex items-center gap-2 px-3 py-1.5 rounded-md border border-gray-300 bg-white focus-within:ring-2 focus-within:ring-gray-400 focus-within:ring-offset-1 focus-within:border-gray-400">
|
||||
<Search size={16} className="text-gray-700 flex-shrink-0" strokeWidth={2} />
|
||||
<Search size={16} className="text-gray-700 shrink-0" strokeWidth={2} />
|
||||
<Input
|
||||
placeholder="输入路由关键词进行搜索..."
|
||||
className="w-full !border-0 !shadow-none !outline-none bg-transparent focus-visible:!outline-none focus-visible:!ring-0 focus-visible:!ring-offset-0 text-sm text-gray-900 placeholder:text-gray-500"
|
||||
className="w-full border-0! shadow-none! outline-none! bg-transparent focus-visible:outline-none! focus-visible:ring-0! focus-visible:ring-offset-0! text-sm text-gray-900 placeholder:text-gray-500"
|
||||
value={searchKeyword}
|
||||
onChange={(e) => setSearchKeyword(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
{defaultKeyword && searchKeyword !== defaultKeyword && (
|
||||
<button
|
||||
onClick={async () => {
|
||||
setSearchKeyword(defaultKeyword);
|
||||
await handleSearch(defaultKeyword);
|
||||
}}
|
||||
className="p-1 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-200 active:bg-gray-300 transition-all duration-150 cursor-pointer shrink-0"
|
||||
title="重置为默认关键词"
|
||||
>
|
||||
<RotateCcw size={16} />
|
||||
</button>
|
||||
)}
|
||||
{searchKeyword && (
|
||||
<button
|
||||
onClick={handleClear}
|
||||
className="p-1 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-200 active:bg-gray-300 transition-all duration-150 cursor-pointer flex-shrink-0"
|
||||
className="p-1 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-200 active:bg-gray-300 transition-all duration-150 cursor-pointer shrink-0"
|
||||
title="清空搜索"
|
||||
>
|
||||
<X size={16} />
|
||||
@@ -196,7 +230,7 @@ export const App = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className={`space-y-1 ${loading ? "opacity-50 pointer-events-none" : ""}`}>
|
||||
<div className={`space-y-1 ${loading ? "opacity-50 pointer-events-none" : ""} flex-1 overflow-auto scrollbar mb-10`}>
|
||||
{routes.map((route: RouteItem) => {
|
||||
const isExpanded = expandedIds.has(route.id);
|
||||
const isIdVisible = visibleIds.has(route.id);
|
||||
@@ -205,7 +239,7 @@ export const App = () => {
|
||||
return (
|
||||
<div
|
||||
key={route.id}
|
||||
className="px-4 py-3 border-b border-gray-100 hover:bg-gray-50/50 transition-all duration-200 animate-in fade-in slide-in-from-top-1 duration-400"
|
||||
className="px-4 py-3 border-b border-gray-100 hover:bg-gray-50/50 transition-all animate-in fade-in slide-in-from-top-1 duration-400"
|
||||
>
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{/* ID and Path/Key in one line */}
|
||||
@@ -236,9 +270,53 @@ export const App = () => {
|
||||
|
||||
<button className="p-1.5 rounded-md text-gray-20 hover:text-gray-900 hover:bg-gray-200 transition-all duration-200 cursor-pointer"
|
||||
title="高级运行"
|
||||
onClick={() => run(route)}>
|
||||
onClick={() => run(route, 'custom')}>
|
||||
<MonitorPlay size={14} strokeWidth={2.5} />
|
||||
</button>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
className="p-1.5 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-200 transition-all duration-200 cursor-pointer"
|
||||
title="更多选项"
|
||||
>
|
||||
<MoreHorizontal size={14} strokeWidth={2.5} />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="border-gray-300">
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const viewItem = route.metadata?.viewItem;
|
||||
if (!viewItem) {
|
||||
toast.error('路由没有关联的视图数据');
|
||||
return;
|
||||
}
|
||||
const _viewItem = filterRouteInfo(viewItem);
|
||||
_viewItem.action = {
|
||||
path: route.path,
|
||||
key: route.key,
|
||||
}
|
||||
queryViewStore.setDetailsData(_viewItem, 'router');
|
||||
queryViewStore.setShowDetailsDialog(true);
|
||||
}}
|
||||
>
|
||||
<Info size={14} className="mr-2" />
|
||||
显示详情
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
store.setExportRoutes([route]);
|
||||
store.setShowExportDialog(true);
|
||||
}}
|
||||
>
|
||||
<Code size={14} className="mr-2" />
|
||||
导出代码
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -291,6 +369,38 @@ export const App = () => {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className='h-12 absolute bottom-0 left-0 right-0 bg-white border-t border-gray-200 flex items-center justify-end px-4 gap-2'>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
store.setShowProxyStatus(true);
|
||||
}}
|
||||
className="gap-2"
|
||||
title="Proxy 状态"
|
||||
>
|
||||
<Activity size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
store.setShowRouterGroup(true);
|
||||
}}
|
||||
className="gap-2"
|
||||
title="路由分组"
|
||||
>
|
||||
<FolderClosed size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
store.setExportRoutes(routes);
|
||||
store.setShowExportDialog(true);
|
||||
}}
|
||||
className="gap-2"
|
||||
>
|
||||
<Code size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
'use client';
|
||||
import { create } from 'zustand';
|
||||
import { QueryProxy, RouterViewData, RouterViewItem, pickRouterViewData } from '@kevisual/api'
|
||||
import { QueryProxy, RouterViewData, RouterViewItem, pickRouterViewData } from '@kevisual/api/query-proxy'
|
||||
import { query } from '@/modules/query.ts'
|
||||
import { toast } from 'react-toastify';
|
||||
import { toast } from 'sonner';
|
||||
import { use } from '@kevisual/context'
|
||||
import { MyCache } from '@kevisual/cache'
|
||||
// import { MyCache } from '@kevisual/cache'
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { app } from '@/index.ts'
|
||||
import { cloneDeep, random } from 'es-toolkit'
|
||||
import { nanoid } from 'nanoid';
|
||||
import { app } from '@/agents'
|
||||
import { cloneDeep } from 'es-toolkit'
|
||||
import { nanoid, customAlphabet } from 'nanoid';
|
||||
import { Result } from '@kevisual/query';
|
||||
const letterAndNumber = 'abcdefghijklmnopqrstuvwxy';
|
||||
const nanoid8 = customAlphabet(letterAndNumber, 8);
|
||||
const historyReplace = (url: string) => {
|
||||
if (window.history.replaceState) {
|
||||
window.history.replaceState(null, '', url);
|
||||
@@ -23,18 +27,31 @@ type RouteItem = {
|
||||
|
||||
type RouteViewList = Array<RouterViewData>;
|
||||
|
||||
type MessageAction = {
|
||||
path?: string;
|
||||
key?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
export type Message = RouterViewItem<{
|
||||
_id: string;
|
||||
action: MessageAction;
|
||||
description?: string;
|
||||
response?: Result;
|
||||
}>
|
||||
|
||||
interface StudioState {
|
||||
loading: boolean;
|
||||
setLoading: (loading: boolean) => void;
|
||||
routes: Array<RouteItem>;
|
||||
searchRoutes: (keyword: string) => Promise<void>;
|
||||
run: (route: RouteItem) => Promise<void>;
|
||||
allRoutes: Array<RouteItem>;
|
||||
getAllRoutes: () => Promise<void>;
|
||||
run: (route: RouteItem, type?: 'normal' | 'custom') => Promise<void>;
|
||||
queryProxy?: QueryProxy;
|
||||
init: (force?: boolean) => Promise<{ queryProxy: QueryProxy }>;
|
||||
routeViewList: RouteViewList;
|
||||
getViewList: () => Promise<void>;
|
||||
queryRouteList: () => Promise<void>;
|
||||
queryRouteList: (first?: boolean) => Promise<void>;
|
||||
getCurrentView: () => Promise<void>;
|
||||
updateRouteView: (view: RouterViewData) => Promise<void>;
|
||||
deleteRouteView: (id: string) => Promise<void>;
|
||||
@@ -47,13 +64,47 @@ interface StudioState {
|
||||
setShowFilter: (show: boolean) => void;
|
||||
showRightPanel: boolean;
|
||||
setShowRightPanel: (show: boolean) => void;
|
||||
messages: any[];
|
||||
setMessages: (messages: any[]) => void;
|
||||
addMessage: (message: any) => void;
|
||||
deleteMessage: (message: any) => void;
|
||||
messages: Message[];
|
||||
setMessages: (messages: Message[]) => void;
|
||||
addMessage: (message: Message) => void;
|
||||
deleteMessage: (message: Message) => void;
|
||||
searchKeyword: string;
|
||||
setSearchKeyword: (keyword: string) => void;
|
||||
showExportDialog: boolean;
|
||||
setShowExportDialog: (show: boolean) => void;
|
||||
exportRoutes?: RouteItem[];
|
||||
setExportRoutes: (routes?: RouteItem[]) => void;
|
||||
showApiDocs: boolean;
|
||||
setShowApiDocs: (show: boolean) => void;
|
||||
showRouterGroup: boolean;
|
||||
setShowRouterGroup: (show: boolean) => void;
|
||||
showProxyStatus: boolean;
|
||||
setShowProxyStatus: (show: boolean) => void;
|
||||
getQueryProxyStatus: () => Promise<RouterViewItem[]>;
|
||||
}
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
export const filterRouteInfo = (viewData: RouterViewItem) => {
|
||||
const data = cloneDeep(viewData) as RouterViewItem
|
||||
// 删除可能过大的字段,避免在详情弹窗展示
|
||||
if (data.type === 'api') {
|
||||
delete data?.api?.query;
|
||||
}
|
||||
if (data.type === 'worker') {
|
||||
delete data?.worker?.worker;
|
||||
}
|
||||
if (data.type === 'context') {
|
||||
delete data?.context?.router;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export const getPayload = (value: { path?: string, key?: string, id?: string, payload?: any, [key: string]: any }): Record<string, any> => {
|
||||
const { path, key, id, payload, ...rest } = value;
|
||||
return {
|
||||
...rest,
|
||||
...payload,
|
||||
}
|
||||
}
|
||||
export const useStudioStore = create<StudioState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
@@ -61,20 +112,40 @@ export const useStudioStore = create<StudioState>()(
|
||||
setLoading: (loading: boolean) => set({ loading }),
|
||||
routes: [],
|
||||
searchRoutes: async (keyword: string) => {
|
||||
const state = await get().init();
|
||||
let queryProxy = state.queryProxy;
|
||||
let queryProxy = get().queryProxy!;
|
||||
console.log('[queryProxy] 搜索路由', keyword);
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true, { query: keyword });
|
||||
set({ routes });
|
||||
set({ routes, searchKeyword: keyword });
|
||||
},
|
||||
allRoutes: [],
|
||||
getAllRoutes: async () => {
|
||||
let queryProxy = get().queryProxy!;
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true);
|
||||
set({ allRoutes: routes });
|
||||
},
|
||||
searchKeyword: '',
|
||||
setSearchKeyword: (keyword: string) => set({ searchKeyword: keyword }),
|
||||
currentView: undefined,
|
||||
queryRouteList: async () => {
|
||||
await get().getCurrentView();
|
||||
queryRouteList: async (first: boolean = false) => {
|
||||
first && await get().getCurrentView();
|
||||
const state = await get().init();
|
||||
let currentView: RouterViewData | undefined = get().currentView;
|
||||
let queryProxy = state.queryProxy;
|
||||
|
||||
console.log('开始查询路由列表,当前视图:', queryProxy.emitter.eventNames());
|
||||
if (first) return;
|
||||
let searchKeyword = ''
|
||||
const viewId = currentView?.viewId ?? ''
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true, { viewId });
|
||||
set({ routes });
|
||||
if (viewId && currentView) {
|
||||
const query = currentView?.views?.find(v => v.id === viewId)?.query || '';
|
||||
if (query) {
|
||||
searchKeyword = query;
|
||||
}
|
||||
}
|
||||
// console.log('视图ID:', currentView, searchKeyword);
|
||||
// console.log('查询路由列表,视图ID:', viewId, queryProxy.router?.routes?.length);
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true, { query: searchKeyword });
|
||||
set({ routes, searchKeyword });
|
||||
},
|
||||
setCurrentView: async (view?: RouterViewData) => {
|
||||
const beforeView = get().currentView;
|
||||
@@ -151,10 +222,11 @@ export const useStudioStore = create<StudioState>()(
|
||||
set({ routeViewList: [...newList] });
|
||||
console.log('删除视图项', id, newList);
|
||||
},
|
||||
run: async (route: RouteItem) => {
|
||||
run: async (route: RouteItem, type?: 'normal' | 'custom') => {
|
||||
const state = await get().init();
|
||||
const isCustom = type === 'custom';
|
||||
let queryProxy = state.queryProxy;
|
||||
const showRightPanel = get().showRightPanel;
|
||||
let showRightPanel = get().showRightPanel;
|
||||
const action = {
|
||||
path: route.path,
|
||||
key: route.key
|
||||
@@ -163,7 +235,14 @@ export const useStudioStore = create<StudioState>()(
|
||||
if (res.code !== 200) {
|
||||
toast.error(`运行失败:${res.message || '未知错误'}`);
|
||||
} else if (res.code === 200) {
|
||||
//
|
||||
if (!showRightPanel) {
|
||||
if (isCustom) {
|
||||
showRightPanel = true;
|
||||
set({ showRightPanel: true });
|
||||
} else {
|
||||
toast.success('运行成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showRightPanel) {
|
||||
if (route.metadata && route.metadata?.viewItem) {
|
||||
@@ -174,7 +253,7 @@ export const useStudioStore = create<StudioState>()(
|
||||
viewItem.description = route.description || viewItem.description;
|
||||
// @ts-ignore
|
||||
viewItem._id = nanoid(16);
|
||||
set({ messages: [...messages, viewItem] });
|
||||
set({ messages: [...messages, viewItem as Message] });
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -189,6 +268,14 @@ export const useStudioStore = create<StudioState>()(
|
||||
return { queryProxy };
|
||||
}
|
||||
let currentView: RouterViewData | undefined = get().currentView;
|
||||
let url = '/api/router';
|
||||
const _url = new URL(location.href)
|
||||
const pathname = _url.pathname
|
||||
const [user, repo] = pathname.split('/').filter(Boolean)
|
||||
if (repo === 'v1') {
|
||||
url = pathname;
|
||||
}
|
||||
console.log('初始化 QueryProxy,URL:', url);
|
||||
// @ts-ignore
|
||||
const routerViewData: RouterViewData = currentView || {
|
||||
_id: nanoid(16),
|
||||
@@ -205,24 +292,36 @@ export const useStudioStore = create<StudioState>()(
|
||||
description: '',
|
||||
type: 'api',
|
||||
api: {
|
||||
url: '/api/router'
|
||||
url: url
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
viewId: '',
|
||||
}
|
||||
let searchKeyword = '';
|
||||
const viewId = currentView?.viewId ?? ''
|
||||
if (viewId && currentView) {
|
||||
const query = currentView?.views?.find(v => v.id === viewId)?.query || '';
|
||||
if (query) {
|
||||
searchKeyword = query;
|
||||
}
|
||||
}
|
||||
console.log('初始化 QueryProxy', routerViewData);
|
||||
queryProxy = new QueryProxy({
|
||||
routerViewData,
|
||||
router: app as any,
|
||||
});
|
||||
console.log('初始化 QueryProxy 完成', queryProxy.token);
|
||||
set({ queryProxy, searchKeyword });
|
||||
queryProxy.emitter.once("initComplete", async () => {
|
||||
console.log('[queryProxy] QueryProxy 初始化完成事件,重新查询路由列表');
|
||||
await sleep(1000);
|
||||
get().searchRoutes(searchKeyword);
|
||||
});
|
||||
set({ loading: true });
|
||||
await sleep(1000); // 保证 loading 状态更新
|
||||
await queryProxy.init();
|
||||
set({ loading: false });
|
||||
set({ queryProxy });
|
||||
|
||||
return { queryProxy }
|
||||
},
|
||||
showLeftPanel: false,
|
||||
@@ -246,6 +345,26 @@ export const useStudioStore = create<StudioState>()(
|
||||
addMessage: (message: any) => {
|
||||
const messages = get().messages;
|
||||
set({ messages: [...messages, message] });
|
||||
},
|
||||
showExportDialog: false,
|
||||
setShowExportDialog: (show: boolean) => set({ showExportDialog: show }),
|
||||
exportRoutes: undefined,
|
||||
setExportRoutes: (routes?: RouteItem[]) => set({ exportRoutes: routes }),
|
||||
showApiDocs: false,
|
||||
setShowApiDocs: (show: boolean) => set({ showApiDocs: show }),
|
||||
showRouterGroup: false,
|
||||
setShowRouterGroup: (show: boolean) => set({ showRouterGroup: show }),
|
||||
showProxyStatus: false,
|
||||
setShowProxyStatus: (show: boolean) => set({ showProxyStatus: show }),
|
||||
getQueryProxyStatus: async () => {
|
||||
let queryProxy = get().queryProxy!;
|
||||
const status = queryProxy.routerViewItems.map(item => {
|
||||
return {
|
||||
id: item.id || nanoid8(),
|
||||
...item,
|
||||
}
|
||||
})
|
||||
return status;
|
||||
}
|
||||
}),
|
||||
{
|
||||
@@ -2,7 +2,7 @@ import { Label } from "@/components/ui/label"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { Query } from "@kevisual/query"
|
||||
import { QueryRouterServer } from "@kevisual/router"
|
||||
import { QueryRouterServer } from "@kevisual/router/browser"
|
||||
import { nanoid } from "nanoid"
|
||||
|
||||
export type RouterViewItem = RouterViewApi | RouterViewContext | RouterViewWorker;
|
||||
@@ -72,7 +72,7 @@ export const DataItemForm = ({ item, onChange, onRemove }: DataItemFormProps) =>
|
||||
}
|
||||
|
||||
const handleNestedChange = (parent: string, field: string, value: any) => {
|
||||
const parentValue = item[parent as keyof RouterViewItem] as Record<string, any> | undefined
|
||||
const parentValue = item[parent as keyof RouterViewItem] as any
|
||||
const newParentValue: Record<string, any> = {
|
||||
...(parentValue || {}),
|
||||
[field]: value
|
||||
@@ -81,7 +81,7 @@ export const DataItemForm = ({ item, onChange, onRemove }: DataItemFormProps) =>
|
||||
}
|
||||
|
||||
const handleNestedDeepChange = (parent: string, nestedParent: string, field: string, value: any) => {
|
||||
const parentValue = item[parent as keyof RouterViewItem] as Record<string, any> | undefined
|
||||
const parentValue = item[parent as keyof RouterViewItem] as any
|
||||
const nestedValue = parentValue?.[nestedParent] as Record<string, any> | undefined
|
||||
const newNestedValue: Record<string, any> = {
|
||||
...(nestedValue || {}),
|
||||
34
src/pages/view/components/DocsModal.tsx
Normal file
34
src/pages/view/components/DocsModal.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useStudioStore } from "@/pages/studio/store";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export const DocsModal = () => {
|
||||
const store = useStudioStore(useShallow((state) => ({
|
||||
showApiDocs: state.showApiDocs,
|
||||
setShowApiDocs: state.setShowApiDocs,
|
||||
})));
|
||||
|
||||
return (
|
||||
<Dialog open={store.showApiDocs} onOpenChange={store.setShowApiDocs}>
|
||||
<DialogContent className="max-w-3xl! max-h-[80vh] overflow-hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-xl">API 文档</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex-1 overflow-auto">
|
||||
<p>这里是 API 文档的内容...</p>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button onClick={() => store.setShowApiDocs(false)}>关闭</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -4,8 +4,8 @@ import { Label } from "@/components/ui/label"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { DataItemForm } from "@/apps/view/components/DataItemForm"
|
||||
import { ViewFormItem } from "@/apps/view/components/ViewFormItem"
|
||||
import { DataItemForm } from "@/pages/view/components/DataItemForm"
|
||||
import { ViewFormItem } from "@/pages/view/components/ViewFormItem"
|
||||
import { nanoid } from "nanoid"
|
||||
|
||||
interface ViewEditorProps {
|
||||
@@ -117,7 +117,7 @@ export const ViewEditor = ({ open, onOpenChange, data, onSave }: ViewEditorProps
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-3xl">
|
||||
<DialogContent className="max-w-3xl! max-h-[80vh] overflow-hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{isUpdate ? '编辑视图' : '新增视图'}</DialogTitle>
|
||||
</DialogHeader>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { toast } from "react-toastify"
|
||||
import { toast } from "sonner"
|
||||
|
||||
interface ViewFormProps {
|
||||
view: any
|
||||
@@ -15,7 +15,7 @@ export const ViewFormItem = ({ view, onChange, onRemove }: ViewFormProps) => {
|
||||
const handleCopyId = async (id: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(id);
|
||||
toast.success('已复制到剪贴板', { autoClose: 1000 });
|
||||
toast.success('已复制到剪贴板', { duration: 1000 });
|
||||
} catch (err) {
|
||||
console.error('复制失败', err);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useStudioStore } from '../studio/store.ts';
|
||||
import { Search, RotateCw, Plus, MoreHorizontal, Layout, Edit2, Trash2 } from "lucide-react";
|
||||
import { Search, RotateCw, Plus, MoreHorizontal, Layout, Edit2, Trash2, MousePointer2, Book } from "lucide-react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -11,12 +11,16 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { ViewEditor } from "@/apps/view/components/ViewEditor.tsx";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
import { ViewEditor } from "@/pages/view/components/ViewEditor.tsx";
|
||||
import { toast } from "sonner";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { DocsModal } from './components/DocsModal.tsx'
|
||||
const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onEdit: (view: any) => void; onDelete: (id: string) => void; onDeleteViewItem: (id: string, viewId: string) => void }) => {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const studioStore = useStudioStore();
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
currentView: state.currentView,
|
||||
searchRoutes: state.searchRoutes
|
||||
})));
|
||||
useEffect(() => {
|
||||
const currentViewId = studioStore.currentView?.viewId;
|
||||
if (view.views.some((v: any) => v.id === currentViewId)) {
|
||||
@@ -24,7 +28,10 @@ const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onE
|
||||
}
|
||||
}, [studioStore.currentView?.viewId]);
|
||||
const ShowViews = (props: { views: { id: string, title: string, query?: any }[] }) => {
|
||||
const studioStore = useStudioStore();
|
||||
const studioStore = useStudioStore(useShallow((state) => ({
|
||||
currentView: state.currentView,
|
||||
setCurrentView: state.setCurrentView,
|
||||
})));
|
||||
const currentViewId = studioStore.currentView?.viewId;
|
||||
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
@@ -42,7 +49,7 @@ const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onE
|
||||
>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<TooltipTrigger>
|
||||
<span>{v.title || '未命名视图'}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right" className="max-w-xs">
|
||||
@@ -58,7 +65,7 @@ const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onE
|
||||
setDeleteTargetId(null);
|
||||
}
|
||||
}}>
|
||||
<PopoverTrigger asChild>
|
||||
<PopoverTrigger>
|
||||
<Trash2
|
||||
className="h-4 w-4 text-gray-400 hover:text-gray-600 transition-colors cursor-pointer opacity-0 group-hover:opacity-100"
|
||||
onClick={(e) => {
|
||||
@@ -110,14 +117,20 @@ const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onE
|
||||
</div>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
}}>
|
||||
<DropdownMenuTrigger
|
||||
className="inline-flex items-center justify-center h-8 w-8 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="border-gray-300">
|
||||
<DropdownMenuItem className="cursor-pointer" onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
studioStore.searchRoutes('')
|
||||
}}>
|
||||
<MousePointer2 className="h-4 w-4 mr-2" />
|
||||
选中
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="cursor-pointer" onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onEdit(view);
|
||||
@@ -145,23 +158,32 @@ const ViewItem = ({ view, onEdit, onDelete, onDeleteViewItem }: { view: any; onE
|
||||
</div>
|
||||
}
|
||||
export const ViewList = () => {
|
||||
const { routeViewList, updateRouteView, deleteRouteView, deleteRouteViewItem, getViewList } = useStudioStore();
|
||||
const store = useStudioStore(useShallow((state) => ({
|
||||
routeViewList: state.routeViewList,
|
||||
updateRouteView: state.updateRouteView,
|
||||
deleteRouteView: state.deleteRouteView,
|
||||
deleteRouteViewItem: state.deleteRouteViewItem,
|
||||
getViewList: state.getViewList,
|
||||
setShowApiDocs: state.setShowApiDocs,
|
||||
})));
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [editorOpen, setEditorOpen] = useState(false);
|
||||
const [editingView, setEditingView] = useState<any>(null);
|
||||
|
||||
const filteredViews = routeViewList.filter(view =>
|
||||
const filteredViews = store.routeViewList.filter(view =>
|
||||
(view.title || '未命名视图').toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
(view.description || '').toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
useEffect(() => {
|
||||
getViewList();
|
||||
store.getViewList();
|
||||
}, [])
|
||||
|
||||
const handleRefresh = async () => {
|
||||
const toastId = toast.loading('正在刷新视图列表...');
|
||||
await getViewList();
|
||||
toast.update(toastId, { render: '视图列表已刷新', type: 'success', isLoading: false, autoClose: 1000 });
|
||||
await store.getViewList();
|
||||
// toast.update(toastId, { render: '视图列表已刷新', type: 'success', id: false, autoClose: 1000 });
|
||||
toast.success('视图列表已刷新', { duration: 1000 });
|
||||
toast.dismiss(toastId);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
@@ -175,17 +197,20 @@ export const ViewList = () => {
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
if (confirm('确定要删除这个视图吗?')) {
|
||||
deleteRouteView(id);
|
||||
store.deleteRouteView(id);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveView = (viewData: any) => {
|
||||
updateRouteView(viewData);
|
||||
store.updateRouteView(viewData);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full h-full max-w-4xl p-4 border border-gray-200 rounded-md shadow-sm">
|
||||
<div className="flex items-center space-x-2 mb-4">
|
||||
<div className="w-full h-full max-w-4xl py-4 border border-gray-200 rounded-md shadow-sm overflow-hidden">
|
||||
<div className="flex items-center px-4 space-x-2 mb-4">
|
||||
<Button onClick={() => store.setShowApiDocs(true)} title='文档' variant="outline" size="icon" className="h-8 w-8 cursor-pointer border-gray-300">
|
||||
<Book size={16} />
|
||||
</Button>
|
||||
<div className="relative flex-1">
|
||||
<Input
|
||||
placeholder="搜索视图..."
|
||||
@@ -195,15 +220,15 @@ export const ViewList = () => {
|
||||
/>
|
||||
<Search className="absolute right-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
</div>
|
||||
<Button variant="outline" size="icon" className="h-10 w-10 cursor-pointer border-gray-300" onClick={handleRefresh}>
|
||||
<Button variant="outline" size="icon" className="h-8 w-8 cursor-pointer border-gray-300" onClick={handleRefresh}>
|
||||
<RotateCw className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="outline" size="icon" className="h-10 w-10 cursor-pointer border-gray-300" onClick={handleAdd}>
|
||||
<Button variant="outline" size="icon" className="h-8 w-8 cursor-pointer border-gray-300" onClick={handleAdd}>
|
||||
<Plus className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col">
|
||||
<div className="flex flex-col px-4 overscroll-auto scrollbar" style={{ height: 'calc(100% - 32px)' }}>
|
||||
{filteredViews.length === 0 ? (
|
||||
<div className="text-center py-4 text-gray-500">
|
||||
{searchTerm ? '未找到匹配的视图' : '暂无视图'}
|
||||
@@ -215,7 +240,7 @@ export const ViewList = () => {
|
||||
view={view}
|
||||
onEdit={handleEdit}
|
||||
onDelete={handleDelete}
|
||||
onDeleteViewItem={deleteRouteViewItem}
|
||||
onDeleteViewItem={store.deleteRouteViewItem}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
@@ -227,6 +252,7 @@ export const ViewList = () => {
|
||||
data={editingView}
|
||||
onSave={handleSaveView}
|
||||
/>
|
||||
<DocsModal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
131
src/routeTree.gen.ts
Normal file
131
src/routeTree.gen.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
/* eslint-disable */
|
||||
|
||||
// @ts-nocheck
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
|
||||
// This file was automatically generated by TanStack Router.
|
||||
// You should NOT make any changes in this file as it will be overwritten.
|
||||
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
||||
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as ViewRouteImport } from './routes/view'
|
||||
import { Route as LoginRouteImport } from './routes/login'
|
||||
import { Route as ConsoleRouteImport } from './routes/console'
|
||||
import { Route as IdRouteImport } from './routes/$id'
|
||||
import { Route as IndexRouteImport } from './routes/index'
|
||||
|
||||
const ViewRoute = ViewRouteImport.update({
|
||||
id: '/view',
|
||||
path: '/view',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const LoginRoute = LoginRouteImport.update({
|
||||
id: '/login',
|
||||
path: '/login',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ConsoleRoute = ConsoleRouteImport.update({
|
||||
id: '/console',
|
||||
path: '/console',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const IdRoute = IdRouteImport.update({
|
||||
id: '/$id',
|
||||
path: '/$id',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const IndexRoute = IndexRouteImport.update({
|
||||
id: '/',
|
||||
path: '/',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'/$id': typeof IdRoute
|
||||
'/console': typeof ConsoleRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/view': typeof ViewRoute
|
||||
}
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'/$id': typeof IdRoute
|
||||
'/console': typeof ConsoleRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/view': typeof ViewRoute
|
||||
}
|
||||
export interface FileRoutesById {
|
||||
__root__: typeof rootRouteImport
|
||||
'/': typeof IndexRoute
|
||||
'/$id': typeof IdRoute
|
||||
'/console': typeof ConsoleRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/view': typeof ViewRoute
|
||||
}
|
||||
export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths: '/' | '/$id' | '/console' | '/login' | '/view'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to: '/' | '/$id' | '/console' | '/login' | '/view'
|
||||
id: '__root__' | '/' | '/$id' | '/console' | '/login' | '/view'
|
||||
fileRoutesById: FileRoutesById
|
||||
}
|
||||
export interface RootRouteChildren {
|
||||
IndexRoute: typeof IndexRoute
|
||||
IdRoute: typeof IdRoute
|
||||
ConsoleRoute: typeof ConsoleRoute
|
||||
LoginRoute: typeof LoginRoute
|
||||
ViewRoute: typeof ViewRoute
|
||||
}
|
||||
|
||||
declare module '@tanstack/react-router' {
|
||||
interface FileRoutesByPath {
|
||||
'/view': {
|
||||
id: '/view'
|
||||
path: '/view'
|
||||
fullPath: '/view'
|
||||
preLoaderRoute: typeof ViewRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/login': {
|
||||
id: '/login'
|
||||
path: '/login'
|
||||
fullPath: '/login'
|
||||
preLoaderRoute: typeof LoginRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/console': {
|
||||
id: '/console'
|
||||
path: '/console'
|
||||
fullPath: '/console'
|
||||
preLoaderRoute: typeof ConsoleRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/$id': {
|
||||
id: '/$id'
|
||||
path: '/$id'
|
||||
fullPath: '/$id'
|
||||
preLoaderRoute: typeof IdRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/': {
|
||||
id: '/'
|
||||
path: '/'
|
||||
fullPath: '/'
|
||||
preLoaderRoute: typeof IndexRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rootRouteChildren: RootRouteChildren = {
|
||||
IndexRoute: IndexRoute,
|
||||
IdRoute: IdRoute,
|
||||
ConsoleRoute: ConsoleRoute,
|
||||
LoginRoute: LoginRoute,
|
||||
ViewRoute: ViewRoute,
|
||||
}
|
||||
export const routeTree = rootRouteImport
|
||||
._addFileChildren(rootRouteChildren)
|
||||
._addFileTypes<FileRouteTypes>()
|
||||
10
src/routes/$id.tsx
Normal file
10
src/routes/$id.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import App from '@/pages/page'
|
||||
|
||||
export const Route = createFileRoute('/$id')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
return <App />
|
||||
}
|
||||
36
src/routes/__root.tsx
Normal file
36
src/routes/__root.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { LayoutMain } from '@/pages/auth/modules/BaseHeader';
|
||||
import { Outlet, createRootRoute } from '@tanstack/react-router'
|
||||
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
|
||||
import { Toaster } from '@/components/ui/sonner'
|
||||
import { AuthProvider } from '@/pages/auth'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { useLayoutStore } from '@/pages/auth/store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import clsx from 'clsx';
|
||||
export const Route = createRootRoute({
|
||||
component: RootComponent,
|
||||
})
|
||||
|
||||
|
||||
function RootComponent() {
|
||||
const store = useLayoutStore(useShallow(state => ({
|
||||
showBaseHeader: state.showBaseHeader,
|
||||
})));
|
||||
return (
|
||||
<div className='h-full overflow-hidden'>
|
||||
<LayoutMain />
|
||||
<AuthProvider mustLogin={true}>
|
||||
<TooltipProvider>
|
||||
<main className={clsx('overflow-auto scrollbar', {
|
||||
'h-[calc(100%-3rem)]': store.showBaseHeader,
|
||||
'h-full': !store.showBaseHeader,
|
||||
})}>
|
||||
<Outlet />
|
||||
</main>
|
||||
</TooltipProvider>
|
||||
</AuthProvider>
|
||||
<TanStackRouterDevtools position="bottom-right" />
|
||||
<Toaster />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
45
src/routes/console.tsx
Normal file
45
src/routes/console.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useContextKey } from '@kevisual/context';
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import type Eruda from 'eruda';
|
||||
import { useEffect, useRef } from 'react';
|
||||
export const Route = createFileRoute('/console')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
|
||||
function RouteComponent() {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
init();
|
||||
return () => {
|
||||
deinit();
|
||||
}
|
||||
}, [])
|
||||
const deinit = async () => {
|
||||
const eruda: typeof Eruda = await useContextKey('eruda');
|
||||
eruda.destroy();
|
||||
}
|
||||
const init = async () => {
|
||||
console.log('正在初始化控制台...');
|
||||
const eruda: typeof Eruda = await useContextKey('eruda');
|
||||
console.log('eruda', eruda);
|
||||
if (!ref.current) return;
|
||||
eruda.init({
|
||||
container: ref.current!,
|
||||
tool: ['console'],
|
||||
inline: true,
|
||||
});
|
||||
const consoleTool = eruda.get('console');
|
||||
consoleTool.html('<span style="color:red">Red</span>');
|
||||
}
|
||||
|
||||
return <div className='w-full overflow-hidden' style={{
|
||||
height: 'calc(100% - 48px)'
|
||||
}} >
|
||||
<div className='min-w-150 w-[80%] mx-auto h-full py-4'>
|
||||
<div className='relative w-full h-full border'>
|
||||
<div ref={ref}></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
9
src/routes/index.tsx
Normal file
9
src/routes/index.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import App from '@/pages/page'
|
||||
export const Route = createFileRoute('/')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
return <App />
|
||||
}
|
||||
9
src/routes/login.tsx
Normal file
9
src/routes/login.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import App from '@/pages/auth/page'
|
||||
export const Route = createFileRoute('/login')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
return <App />
|
||||
}
|
||||
9
src/routes/view.tsx
Normal file
9
src/routes/view.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import App from '@/pages/query-view/page'
|
||||
export const Route = createFileRoute('/view')({
|
||||
component: RouteComponent,
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
return <App />
|
||||
}
|
||||
20
src/vite-env.d.ts
vendored
Normal file
20
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference types="vite/client" />
|
||||
type SimpleObject = {
|
||||
[key: string | number]: any;
|
||||
};
|
||||
|
||||
declare let BASE_NAME: string;
|
||||
interface ViteTypeOptions {
|
||||
// 添加这行代码,你就可以将 ImportMetaEnv 的类型设为严格模式,
|
||||
// 这样就不允许有未知的键值了。
|
||||
// strictImportMetaEnv: unknown
|
||||
}
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_APP_TITLE: string;
|
||||
// 更多环境变量...
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
@@ -1,18 +1,15 @@
|
||||
{
|
||||
"extends": "@kevisual/types/json/frontend.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"baseUrl": "./",
|
||||
"jsx": "react-jsx",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
],
|
||||
"@/agent": [
|
||||
"./src/agent"
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"agent/**/*"
|
||||
],
|
||||
"src",
|
||||
]
|
||||
}
|
||||
46
vite.config.ts
Normal file
46
vite.config.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import pkgs from './package.json';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { tanstackRouter } from '@tanstack/router-plugin/vite'
|
||||
import 'dotenv/config'
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const basename = isDev ? '/' : pkgs?.basename || '/';
|
||||
let target = process.env.VITE_API_URL || 'http://localhost:51515';
|
||||
|
||||
const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' };
|
||||
let proxy = {
|
||||
'/root/': apiProxy,
|
||||
'/api': apiProxy,
|
||||
'/client': apiProxy,
|
||||
};
|
||||
/**
|
||||
* @see https://vitejs.dev/config/
|
||||
*/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
// Please make sure that '@tanstack/router-plugin' is passed before '@vitejs/plugin-react'
|
||||
tanstackRouter({
|
||||
target: 'react',
|
||||
autoCodeSplitting: true,
|
||||
}),
|
||||
react(),
|
||||
tailwindcss()
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
base: basename,
|
||||
define: {
|
||||
BASE_NAME: JSON.stringify(basename),
|
||||
},
|
||||
server: {
|
||||
port: 7008,
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: true,
|
||||
proxy,
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
VITE_API_URL='http://localhost:4005'
|
||||
32
web/.github/prompts/astro.prompt.md
vendored
32
web/.github/prompts/astro.prompt.md
vendored
@@ -1,32 +0,0 @@
|
||||
---
|
||||
agent: agent
|
||||
tags: ["astro", "react", "tailwindcss", "shadcn/ui", "typescript"]
|
||||
createdAt: 2026-01-03
|
||||
---
|
||||
|
||||
# 项目技术栈和上下文
|
||||
|
||||
## 核心框架和库
|
||||
- **Astro** - 静态站点生成框架,用于构建高性能网站
|
||||
- **React** - 用于构建交互式 UI 组件
|
||||
- **TypeScript** - 项目使用 TypeScript 编写,有 tsconfig.json 配置
|
||||
|
||||
## UI 和样式
|
||||
- **TailwindCSS** - CSS 框架,已集成
|
||||
- **shadcn/ui** - 高质量 React 组件库,已安装
|
||||
|
||||
## 项目结构特点
|
||||
- 使用 pnpm 工作区管理
|
||||
- `src/` 目录包含主要源代码
|
||||
- `apps/` - 应用模块(chat、cv、studio、query-view 等)
|
||||
- `components/` - React组件
|
||||
- `pages/` - Astro 页面
|
||||
- `layouts/` - Astro 布局
|
||||
- `slides/` - 演示幻灯片内容
|
||||
|
||||
## 开发指南
|
||||
- 修改代码时遵循项目现有的代码结构和命名约定
|
||||
- React 组件通常使用 `.tsx` 后缀
|
||||
- Astro 组件使用 `.astro` 后缀
|
||||
- 样式优先使用 TailwindCSS 类
|
||||
- 复用已有的 shadcn/ui 组件库中的组件
|
||||
9
web/.gitignore
vendored
9
web/.gitignore
vendored
@@ -1,9 +0,0 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
|
||||
.astro
|
||||
|
||||
dist
|
||||
|
||||
.env
|
||||
!.env*example
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"tools": {
|
||||
"skill": true
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
title: git-commit
|
||||
description: 获取需要diff的代码,总结和提交代码的技能
|
||||
license: MIT
|
||||
compatibility: opencode
|
||||
metadata:
|
||||
audience: maintainers
|
||||
---
|
||||
|
||||
## 我的工作
|
||||
|
||||
- 获取代码变更的diff
|
||||
- 总结代码变更内容
|
||||
- 创建git提交
|
||||
- 推送代码到远程仓库
|
||||
|
||||
## 何时使用我
|
||||
|
||||
在需要提交代码变更时使用我。
|
||||
@@ -1,45 +0,0 @@
|
||||
import { defineConfig } from 'astro/config';
|
||||
import mdx from '@astrojs/mdx';
|
||||
import react from '@astrojs/react';
|
||||
import sitemap from '@astrojs/sitemap';
|
||||
import pkgs from './package.json';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import dotenv from 'dotenv';
|
||||
// import vue from '@astrojs/vue';
|
||||
|
||||
dotenv.config();
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
let target = process.env.VITE_API_URL || 'http://localhost:51515';
|
||||
console.log('API Proxy Target:', target);
|
||||
const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' };
|
||||
let proxy = {
|
||||
'/root/': apiProxy,
|
||||
'/api': apiProxy,
|
||||
'/client': apiProxy,
|
||||
};
|
||||
|
||||
const basename = isDev ? undefined : `${pkgs.basename}`;
|
||||
export default defineConfig({
|
||||
base: basename,
|
||||
integrations: [
|
||||
mdx(),
|
||||
react(), //
|
||||
// vue(),
|
||||
// sitemap(), // sitemap must be site has a domain
|
||||
],
|
||||
server: {
|
||||
port: 7008,
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: true,
|
||||
},
|
||||
vite: {
|
||||
plugins: [tailwindcss()],
|
||||
define: {
|
||||
BASE_NAME: JSON.stringify(basename || ''),
|
||||
},
|
||||
server: {
|
||||
proxy,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "kevisual",
|
||||
"share": "public"
|
||||
},
|
||||
"registry": "https://kevisual.cn/root/ai/kevisual/frontend/simple-astro-template",
|
||||
"clone": {
|
||||
".": {
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"syncd": [
|
||||
{
|
||||
"files": [
|
||||
"**/*"
|
||||
],
|
||||
"registry": ""
|
||||
}
|
||||
],
|
||||
"sync": {
|
||||
".gitignore": {
|
||||
"url": "/gitignore.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
{
|
||||
"name": "@kevisual/router-studio",
|
||||
"version": "0.0.2",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"basename": "/root/router-studio",
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview",
|
||||
"pub": "envision deploy ./dist -k router-studio -v 0.0.2 -u -y yes",
|
||||
"slide:dev": "slidev --open slides/index.md",
|
||||
"slide:build": "slidev build slides/index.md --base /root/router-studio-slide/",
|
||||
"slide:pub": "envision deploy ./slides/dist -k router-studio-slide -v 0.0.2 -u -y yes",
|
||||
"ui": "pnpm dlx shadcn@latest add "
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@astrojs/mdx": "^4.3.13",
|
||||
"@astrojs/react": "^4.4.2",
|
||||
"@astrojs/sitemap": "^3.6.0",
|
||||
"@astrojs/vue": "^5.1.3",
|
||||
"@kevisual/cache": "^0.0.5",
|
||||
"@kevisual/context": "^0.0.4",
|
||||
"@kevisual/query": "^0.0.35",
|
||||
"@kevisual/query-login": "^0.0.7",
|
||||
"@kevisual/registry": "^0.0.1",
|
||||
"@kevisual/router": "^0.0.52",
|
||||
"@radix-ui/react-checkbox": "^1.3.3",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||
"@radix-ui/react-label": "^2.1.8",
|
||||
"@radix-ui/react-popover": "^1.1.15",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"@tailwindcss/vite": "^4.1.18",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"@uiw/react-md-editor": "^4.0.11",
|
||||
"antd": "^6.1.3",
|
||||
"astro": "^5.16.6",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.1.1",
|
||||
"dayjs": "^1.11.19",
|
||||
"es-toolkit": "^1.43.0",
|
||||
"github-markdown-css": "^5.8.1",
|
||||
"handsontable": "^16.2.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"lucide-react": "^0.562.0",
|
||||
"marked": "^17.0.1",
|
||||
"marked-highlight": "^2.2.3",
|
||||
"nanoid": "^5.1.6",
|
||||
"papaparse": "^5.5.3",
|
||||
"react": "^19.2.3",
|
||||
"react-dom": "^19.2.3",
|
||||
"react-hook-form": "^7.70.0",
|
||||
"react-resizable-panels": "^4.2.1",
|
||||
"react-toastify": "^11.0.5",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"vue": "^3.5.26",
|
||||
"zustand": "^5.0.9"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/api": "^0.0.17",
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"@types/react": "^19.2.7",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"baseline-browser-mapping": "^2.9.11",
|
||||
"dotenv": "^17.2.3",
|
||||
"tailwindcss": "^4.1.18",
|
||||
"tw-animate-css": "^1.4.0"
|
||||
},
|
||||
"packageManager": "pnpm@10.27.0",
|
||||
"onlyBuiltDependencies": [
|
||||
"@tailwindcss/oxide",
|
||||
"esbuild",
|
||||
"sharp"
|
||||
]
|
||||
}
|
||||
8346
web/pnpm-lock.yaml
generated
8346
web/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,2 +0,0 @@
|
||||
onlyBuiltDependencies:
|
||||
- core-js
|
||||
@@ -1,29 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
count: {
|
||||
default: 0,
|
||||
},
|
||||
})
|
||||
|
||||
const counter = ref(props.count)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-min border border-main rounded-md">
|
||||
<button
|
||||
class="border-r border-main p-2 font-mono outline-none hover:bg-gray-400 hover:bg-opacity-20"
|
||||
@click="counter -= 1"
|
||||
>
|
||||
-
|
||||
</button>
|
||||
<span class="m-auto p-2">{{ counter }}</span>
|
||||
<button
|
||||
class="border-l border-main p-2 font-mono outline-none hover:bg-gray-400 hover:bg-opacity-20"
|
||||
@click="counter += 1"
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,611 +0,0 @@
|
||||
# Welcome to Slidev
|
||||
|
||||
Presentation slides for developers
|
||||
|
||||
<div @click="$slidev.nav.next" class="mt-12 py-1" hover:bg="white op-10">
|
||||
Press Space for next page <carbon:arrow-right />
|
||||
</div>
|
||||
|
||||
<div class="abs-br m-6 text-xl">
|
||||
<button @click="$slidev.nav.openInEditor()" title="Open in Editor" class="slidev-icon-btn">
|
||||
<carbon:edit />
|
||||
</button>
|
||||
<a href="https://github.com/slidevjs/slidev" target="_blank" class="slidev-icon-btn">
|
||||
<carbon:logo-github />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
The last comment block of each slide will be treated as slide notes. It will be visible and editable in Presenter Mode along with the slide. [Read more in the docs](https://sli.dev/guide/syntax.html#notes)
|
||||
-->
|
||||
|
||||
---
|
||||
transition: fade-out
|
||||
---
|
||||
|
||||
# What is Slidev?
|
||||
|
||||
Slidev is a slides maker and presenter designed for developers, consist of the following features
|
||||
|
||||
- 📝 **Text-based** - focus on the content with Markdown, and then style them later
|
||||
- 🎨 **Themable** - themes can be shared and re-used as npm packages
|
||||
- 🧑💻 **Developer Friendly** - code highlighting, live coding with autocompletion
|
||||
- 🤹 **Interactive** - embed Vue components to enhance your expressions
|
||||
- 🎥 **Recording** - built-in recording and camera view
|
||||
- 📤 **Portable** - export to PDF, PPTX, PNGs, or even a hostable SPA
|
||||
- 🛠 **Hackable** - virtually anything that's possible on a webpage is possible in Slidev
|
||||
<br>
|
||||
<br>
|
||||
|
||||
Read more about [Why Slidev?](https://sli.dev/guide/why)
|
||||
|
||||
<!--
|
||||
You can have `style` tag in markdown to override the style for the current page.
|
||||
Learn more: https://sli.dev/features/slide-scope-style
|
||||
-->
|
||||
|
||||
<style>
|
||||
h1 {
|
||||
background-color: #2B90B6;
|
||||
background-image: linear-gradient(45deg, #4EC5D4 10%, #146b8c 20%);
|
||||
background-size: 100%;
|
||||
-webkit-background-clip: text;
|
||||
-moz-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
-moz-text-fill-color: transparent;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!--
|
||||
Here is another comment.
|
||||
-->
|
||||
|
||||
---
|
||||
transition: slide-up
|
||||
level: 2
|
||||
---
|
||||
|
||||
# Navigation
|
||||
|
||||
Hover on the bottom-left corner to see the navigation's controls panel, [learn more](https://sli.dev/guide/ui#navigation-bar)
|
||||
|
||||
## Keyboard Shortcuts
|
||||
|
||||
| | |
|
||||
| --------------------------------------------------- | --------------------------- |
|
||||
| <kbd>right</kbd> / <kbd>space</kbd> | next animation or slide |
|
||||
| <kbd>left</kbd> / <kbd>shift</kbd><kbd>space</kbd> | previous animation or slide |
|
||||
| <kbd>up</kbd> | previous slide |
|
||||
| <kbd>down</kbd> | next slide |
|
||||
|
||||
<!-- https://sli.dev/guide/animations.html#click-animation -->
|
||||
<img
|
||||
v-click
|
||||
class="absolute -bottom-9 -left-7 w-80 opacity-50"
|
||||
src="https://sli.dev/assets/arrow-bottom-left.svg"
|
||||
alt=""
|
||||
/>
|
||||
<p v-after class="absolute bottom-23 left-45 opacity-30 transform -rotate-10">Here!</p>
|
||||
|
||||
---
|
||||
layout: two-cols
|
||||
layoutClass: gap-16
|
||||
---
|
||||
|
||||
# Table of contents
|
||||
|
||||
You can use the `Toc` component to generate a table of contents for your slides:
|
||||
|
||||
```html
|
||||
<Toc minDepth="1" maxDepth="1" />
|
||||
```
|
||||
|
||||
The title will be inferred from your slide content, or you can override it with `title` and `level` in your frontmatter.
|
||||
|
||||
::right::
|
||||
|
||||
<Toc text-sm minDepth="1" maxDepth="2" />
|
||||
|
||||
---
|
||||
layout: image-right
|
||||
image: https://cover.sli.dev
|
||||
---
|
||||
|
||||
# Code
|
||||
|
||||
Use code snippets and get the highlighting directly, and even types hover!
|
||||
|
||||
```ts [filename-example.ts] {all|4|6|6-7|9|all} twoslash
|
||||
// TwoSlash enables TypeScript hover information
|
||||
// and errors in markdown code blocks
|
||||
// More at https://shiki.style/packages/twoslash
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
const count = ref(0)
|
||||
const doubled = computed(() => count.value * 2)
|
||||
|
||||
doubled.value = 2
|
||||
```
|
||||
|
||||
<arrow v-click="[4, 5]" x1="350" y1="310" x2="195" y2="342" color="#953" width="2" arrowSize="1" />
|
||||
|
||||
<!-- This allow you to embed external code blocks -->
|
||||
<!-- <<< @/snippets/external.ts#snippet -->
|
||||
|
||||
<!-- Footer -->
|
||||
|
||||
[Learn more](https://sli.dev/features/line-highlighting)
|
||||
|
||||
<!-- Inline style -->
|
||||
<style>
|
||||
.footnotes-sep {
|
||||
@apply mt-5 opacity-10;
|
||||
}
|
||||
.footnotes {
|
||||
@apply text-sm opacity-75;
|
||||
}
|
||||
.footnote-backref {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!--
|
||||
Notes can also sync with clicks
|
||||
|
||||
[click] This will be highlighted after the first click
|
||||
|
||||
[click] Highlighted with `count = ref(0)`
|
||||
|
||||
[click:3] Last click (skip two clicks)
|
||||
-->
|
||||
|
||||
---
|
||||
level: 2
|
||||
---
|
||||
|
||||
# Shiki Magic Move
|
||||
|
||||
Powered by [shiki-magic-move](https://shiki-magic-move.netlify.app/), Slidev supports animations across multiple code snippets.
|
||||
|
||||
Add multiple code blocks and wrap them with <code>````md magic-move</code> (four backticks) to enable the magic move. For example:
|
||||
|
||||
````md magic-move {lines: true}
|
||||
```ts {*|2|*}
|
||||
// step 1
|
||||
const author = reactive({
|
||||
name: 'John Doe',
|
||||
books: [
|
||||
'Vue 2 - Advanced Guide',
|
||||
'Vue 3 - Basic Guide',
|
||||
'Vue 4 - The Mystery'
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
```ts {*|1-2|3-4|3-4,8}
|
||||
// step 2
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
author: {
|
||||
name: 'John Doe',
|
||||
books: [
|
||||
'Vue 2 - Advanced Guide',
|
||||
'Vue 3 - Basic Guide',
|
||||
'Vue 4 - The Mystery'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
// step 3
|
||||
export default {
|
||||
data: () => ({
|
||||
author: {
|
||||
name: 'John Doe',
|
||||
books: [
|
||||
'Vue 2 - Advanced Guide',
|
||||
'Vue 3 - Basic Guide',
|
||||
'Vue 4 - The Mystery'
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Non-code blocks are ignored.
|
||||
|
||||
```vue
|
||||
<!-- step 4 -->
|
||||
<script setup>
|
||||
const author = {
|
||||
name: 'John Doe',
|
||||
books: [
|
||||
'Vue 2 - Advanced Guide',
|
||||
'Vue 3 - Basic Guide',
|
||||
'Vue 4 - The Mystery'
|
||||
]
|
||||
}
|
||||
</script>
|
||||
```
|
||||
````
|
||||
|
||||
---
|
||||
|
||||
# Components
|
||||
|
||||
<div grid="~ cols-2 gap-4">
|
||||
<div>
|
||||
|
||||
You can use Vue components directly inside your slides.
|
||||
|
||||
We have provided a few built-in components like `<Tweet/>` and `<Youtube/>` that you can use directly. And adding your custom components is also super easy.
|
||||
|
||||
```html
|
||||
<Counter :count="10" />
|
||||
```
|
||||
|
||||
<!-- ../components/Counter.vue -->
|
||||
<Counter :count="10" m="t-4" />
|
||||
|
||||
Check out [the guides](https://sli.dev/builtin/components.html) for more.
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
```html
|
||||
<Tweet id="1390115482657726468" />
|
||||
```
|
||||
|
||||
<Tweet id="1390115482657726468" scale="0.65" />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
Presenter note with **bold**, *italic*, and ~~striked~~ text.
|
||||
|
||||
Also, HTML elements are valid:
|
||||
<div class="flex w-full">
|
||||
<span style="flex-grow: 1;">Left content</span>
|
||||
<span>Right content</span>
|
||||
</div>
|
||||
-->
|
||||
|
||||
---
|
||||
class: px-20
|
||||
---
|
||||
|
||||
# Themes
|
||||
|
||||
Slidev comes with powerful theming support. Themes can provide styles, layouts, components, or even configurations for tools. Switching between themes by just **one edit** in your frontmatter:
|
||||
|
||||
<div grid="~ cols-2 gap-2" m="t-2">
|
||||
|
||||
```yaml
|
||||
---
|
||||
theme: default
|
||||
---
|
||||
```
|
||||
|
||||
```yaml
|
||||
---
|
||||
theme: seriph
|
||||
---
|
||||
```
|
||||
|
||||
<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-default/01.png?raw=true" alt="">
|
||||
|
||||
<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-seriph/01.png?raw=true" alt="">
|
||||
|
||||
</div>
|
||||
|
||||
Read more about [How to use a theme](https://sli.dev/guide/theme-addon#use-theme) and
|
||||
check out the [Awesome Themes Gallery](https://sli.dev/resources/theme-gallery).
|
||||
|
||||
---
|
||||
|
||||
# Clicks Animations
|
||||
|
||||
You can add `v-click` to elements to add a click animation.
|
||||
|
||||
<div v-click>
|
||||
|
||||
This shows up when you click the slide:
|
||||
|
||||
```html
|
||||
<div v-click>This shows up when you click the slide.</div>
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<v-click>
|
||||
|
||||
The <span v-mark.red="3"><code>v-mark</code> directive</span>
|
||||
also allows you to add
|
||||
<span v-mark.circle.orange="4">inline marks</span>
|
||||
, powered by [Rough Notation](https://roughnotation.com/):
|
||||
|
||||
```html
|
||||
<span v-mark.underline.orange>inline markers</span>
|
||||
```
|
||||
|
||||
</v-click>
|
||||
|
||||
<div mt-20 v-click>
|
||||
|
||||
[Learn more](https://sli.dev/guide/animations#click-animation)
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
# Motions
|
||||
|
||||
Motion animations are powered by [@vueuse/motion](https://motion.vueuse.org/), triggered by `v-motion` directive.
|
||||
|
||||
```html
|
||||
<div
|
||||
v-motion
|
||||
:initial="{ x: -80 }"
|
||||
:enter="{ x: 0 }"
|
||||
:click-3="{ x: 80 }"
|
||||
:leave="{ x: 1000 }"
|
||||
>
|
||||
Slidev
|
||||
</div>
|
||||
```
|
||||
|
||||
<div class="w-60 relative">
|
||||
<div class="relative w-40 h-40">
|
||||
<img
|
||||
v-motion
|
||||
:initial="{ x: 800, y: -100, scale: 1.5, rotate: -50 }"
|
||||
:enter="final"
|
||||
class="absolute inset-0"
|
||||
src="https://sli.dev/logo-square.png"
|
||||
alt=""
|
||||
/>
|
||||
<img
|
||||
v-motion
|
||||
:initial="{ y: 500, x: -100, scale: 2 }"
|
||||
:enter="final"
|
||||
class="absolute inset-0"
|
||||
src="https://sli.dev/logo-circle.png"
|
||||
alt=""
|
||||
/>
|
||||
<img
|
||||
v-motion
|
||||
:initial="{ x: 600, y: 400, scale: 2, rotate: 100 }"
|
||||
:enter="final"
|
||||
class="absolute inset-0"
|
||||
src="https://sli.dev/logo-triangle.png"
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="text-5xl absolute top-14 left-40 text-[#2B90B6] -z-1"
|
||||
v-motion
|
||||
:initial="{ x: -80, opacity: 0}"
|
||||
:enter="{ x: 0, opacity: 1, transition: { delay: 2000, duration: 1000 } }">
|
||||
Slidev
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- vue script setup scripts can be directly used in markdown, and will only affects current page -->
|
||||
<script setup lang="ts">
|
||||
const final = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
rotate: 0,
|
||||
scale: 1,
|
||||
transition: {
|
||||
type: 'spring',
|
||||
damping: 10,
|
||||
stiffness: 20,
|
||||
mass: 2
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
v-motion
|
||||
:initial="{ x:35, y: 30, opacity: 0}"
|
||||
:enter="{ y: 0, opacity: 1, transition: { delay: 3500 } }">
|
||||
|
||||
[Learn more](https://sli.dev/guide/animations.html#motion)
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
# LaTeX
|
||||
|
||||
LaTeX is supported out-of-box. Powered by [KaTeX](https://katex.org/).
|
||||
|
||||
<div h-3 />
|
||||
|
||||
Inline $\sqrt{3x-1}+(1+x)^2$
|
||||
|
||||
Block
|
||||
$$ {1|3|all}
|
||||
\begin{aligned}
|
||||
\nabla \cdot \vec{E} &= \frac{\rho}{\varepsilon_0} \\
|
||||
\nabla \cdot \vec{B} &= 0 \\
|
||||
\nabla \times \vec{E} &= -\frac{\partial\vec{B}}{\partial t} \\
|
||||
\nabla \times \vec{B} &= \mu_0\vec{J} + \mu_0\varepsilon_0\frac{\partial\vec{E}}{\partial t}
|
||||
\end{aligned}
|
||||
$$
|
||||
|
||||
[Learn more](https://sli.dev/features/latex)
|
||||
|
||||
---
|
||||
|
||||
# Diagrams
|
||||
|
||||
You can create diagrams / graphs from textual descriptions, directly in your Markdown.
|
||||
|
||||
<div class="grid grid-cols-4 gap-5 pt-4 -mb-6">
|
||||
|
||||
```mermaid {scale: 0.5, alt: 'A simple sequence diagram'}
|
||||
sequenceDiagram
|
||||
Alice->John: Hello John, how are you?
|
||||
Note over Alice,John: A typical interaction
|
||||
```
|
||||
|
||||
```mermaid {theme: 'neutral', scale: 0.8}
|
||||
graph TD
|
||||
B[Text] --> C{Decision}
|
||||
C -->|One| D[Result 1]
|
||||
C -->|Two| E[Result 2]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
mindmap
|
||||
root((mindmap))
|
||||
Origins
|
||||
Long history
|
||||
::icon(fa fa-book)
|
||||
Popularisation
|
||||
British popular psychology author Tony Buzan
|
||||
Research
|
||||
On effectiveness<br/>and features
|
||||
On Automatic creation
|
||||
Uses
|
||||
Creative techniques
|
||||
Strategic planning
|
||||
Argument mapping
|
||||
Tools
|
||||
Pen and paper
|
||||
Mermaid
|
||||
```
|
||||
|
||||
```plantuml {scale: 0.7}
|
||||
@startuml
|
||||
|
||||
package "Some Group" {
|
||||
HTTP - [First Component]
|
||||
[Another Component]
|
||||
}
|
||||
|
||||
node "Other Groups" {
|
||||
FTP - [Second Component]
|
||||
[First Component] --> FTP
|
||||
}
|
||||
|
||||
cloud {
|
||||
[Example 1]
|
||||
}
|
||||
|
||||
database "MySql" {
|
||||
folder "This is my folder" {
|
||||
[Folder 3]
|
||||
}
|
||||
frame "Foo" {
|
||||
[Frame 4]
|
||||
}
|
||||
}
|
||||
|
||||
[Another Component] --> [Example 1]
|
||||
[Example 1] --> [Folder 3]
|
||||
[Folder 3] --> [Frame 4]
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
Learn more: [Mermaid Diagrams](https://sli.dev/features/mermaid) and [PlantUML Diagrams](https://sli.dev/features/plantuml)
|
||||
|
||||
---
|
||||
foo: bar
|
||||
dragPos:
|
||||
square: 691,32,167,_,-16
|
||||
---
|
||||
|
||||
# Draggable Elements
|
||||
|
||||
Double-click on the draggable elements to edit their positions.
|
||||
|
||||
<br>
|
||||
|
||||
###### Directive Usage
|
||||
|
||||
```md
|
||||
<img v-drag="'square'" src="https://sli.dev/logo.png">
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
###### Component Usage
|
||||
|
||||
```md
|
||||
<v-drag text-3xl>
|
||||
<div class="i-carbon:arrow-up" />
|
||||
Use the `v-drag` component to have a draggable container!
|
||||
</v-drag>
|
||||
```
|
||||
|
||||
<v-drag pos="640,212,261,_,-15">
|
||||
<div text-center text-3xl border border-main rounded>
|
||||
Double-click me!
|
||||
</div>
|
||||
</v-drag>
|
||||
|
||||
<img v-drag="'square'" src="https://sli.dev/logo.png">
|
||||
|
||||
###### Draggable Arrow
|
||||
|
||||
```md
|
||||
<v-drag-arrow two-way />
|
||||
```
|
||||
|
||||
<v-drag-arrow pos="360,319,253,46" two-way op70 />
|
||||
|
||||
---
|
||||
src: ./pages/imported-slides.md
|
||||
hide: false
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
# Monaco Editor
|
||||
|
||||
Slidev provides built-in Monaco Editor support.
|
||||
|
||||
Add `{monaco}` to the code block to turn it into an editor:
|
||||
|
||||
```ts {monaco}
|
||||
import { ref } from 'vue'
|
||||
import { emptyArray } from './external'
|
||||
|
||||
const arr = ref(emptyArray(10))
|
||||
```
|
||||
|
||||
Use `{monaco-run}` to create an editor that can execute the code directly in the slide:
|
||||
|
||||
```ts {monaco-run}
|
||||
import { version } from 'vue'
|
||||
import { emptyArray, sayHello } from './external'
|
||||
|
||||
sayHello()
|
||||
console.log(`vue ${version}`)
|
||||
console.log(emptyArray<number>(10).reduce(fib => [...fib, fib.at(-1)! + fib.at(-2)!], [1, 1]))
|
||||
```
|
||||
|
||||
---
|
||||
layout: center
|
||||
class: text-center
|
||||
---
|
||||
|
||||
# Learn More
|
||||
|
||||
[Documentation](https://sli.dev) · [GitHub](https://github.com/slidevjs/slidev) · [Showcases](https://sli.dev/resources/showcases)
|
||||
|
||||
<PoweredBySlidev mt-10 />
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
theme: default
|
||||
# random image from a curated Unsplash collection by Anthony
|
||||
background: https://cover.sli.dev
|
||||
# 介绍文档: https://sli.dev
|
||||
title: Welcome to Slidev
|
||||
info: |
|
||||
## 关于Slidev的介绍
|
||||
演示稿
|
||||
class: text-center
|
||||
# https://sli.dev/features/drawing
|
||||
drawings:
|
||||
persist: false
|
||||
# slide transition: https://sli.dev/guide/animations.html#slide-transitions
|
||||
transition: slide-left
|
||||
# enable MDC Syntax: https://sli.dev/features/mdc
|
||||
mdc: true
|
||||
htmlAttrs:
|
||||
dir: ltr
|
||||
lang: zh-CN
|
||||
# duration of the presentation
|
||||
duration: 35min
|
||||
---
|
||||
# slide 是一个 所见即所得的幻灯片制作工具
|
||||
---
|
||||
src: ./demos/contents.md
|
||||
hide: false
|
||||
---
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: '例子'
|
||||
---
|
||||
|
||||
# 常用语法结构
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
# 第二个
|
||||
@@ -1,3 +0,0 @@
|
||||
import { QueryRouterServer } from '@kevisual/router/browser'
|
||||
import { use } from '@kevisual/context'
|
||||
export const app = use('app', new QueryRouterServer())
|
||||
@@ -1,41 +0,0 @@
|
||||
import { wrapBasename } from "@/modules/basename"
|
||||
|
||||
export const Footer = () => {
|
||||
|
||||
const links = [
|
||||
{
|
||||
href: wrapBasename('/'),
|
||||
label: '主页',
|
||||
},
|
||||
{
|
||||
href: wrapBasename('/docs'),
|
||||
label: '文档',
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<footer className="fixed bottom-0 w-full bg-white border-t border-gray-200 shadow-lg">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
||||
{/* 链接区域 */}
|
||||
<nav className="flex flex-wrap justify-center items-center gap-2 sm:gap-4 mb-3">
|
||||
{links.map((link) => (
|
||||
<a
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className="relative px-4 py-2 text-sm sm:text-base font-medium text-gray-600 hover:text-blue-600 transition-all duration-300 ease-in-out
|
||||
before:absolute before:bottom-0 before:left-0 before:w-0 before:h-0.5 before:bg-blue-600 before:transition-all before:duration-300
|
||||
hover:before:w-full active:scale-95"
|
||||
>
|
||||
{link.label}
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* 版权信息 */}
|
||||
<div className="text-center text-xs sm:text-sm text-gray-500">
|
||||
© 2025 Daily Question
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
export type MenuProps = {
|
||||
items: MenuItem[];
|
||||
basename?: string;
|
||||
};
|
||||
export type MenuItem = {
|
||||
id: string;
|
||||
data: {
|
||||
title: string;
|
||||
tags: string[];
|
||||
hideInMenu?: boolean;
|
||||
}
|
||||
}
|
||||
export const Menu = (props: MenuProps) => {
|
||||
const { items, basename = '' } = props;
|
||||
const list = useMemo(() => {
|
||||
return items.filter(item => !item.data?.hideInMenu);
|
||||
}, [items]);
|
||||
if (list.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<nav className='flex-1 overflow-y-auto scrollbar bg-sidebar border border-sidebar-border rounded-lg p-4 shadow-sm'>
|
||||
<h2 className="text-sm font-semibold text-sidebar-foreground">列表</h2>
|
||||
<div className="space-y-1">
|
||||
{list.map(item => (
|
||||
<a
|
||||
key={item.id}
|
||||
href={`${basename}/docs/${item.id}/`}
|
||||
className="group block rounded-md hover:bg-sidebar-accent transition-all duration-200 ease-in-out"
|
||||
>
|
||||
<div className="px-3 py-2.5">
|
||||
<h3 className="text-sm font-semibold text-sidebar-foreground group-hover:text-sidebar-accent-foreground transition-colors">
|
||||
{item.data?.title}
|
||||
</h3>
|
||||
{item.data?.tags && item.data.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5 mt-2">
|
||||
{item.data.tags.map(tag => (
|
||||
<span
|
||||
key={tag}
|
||||
className="text-xs px-2 py-0.5 rounded-full bg-muted/60 text-muted-foreground font-medium hover:bg-muted transition-colors"
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { toast, ToastContainer, Slide } from 'react-toastify';
|
||||
|
||||
export const AppProvider = () => {
|
||||
return <main className='w-full'>
|
||||
<App />
|
||||
<ToastContainer
|
||||
position="top-right"
|
||||
autoClose={3000}
|
||||
hideProgressBar
|
||||
newestOnTop
|
||||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable
|
||||
pauseOnHover
|
||||
theme="light"
|
||||
transition={Slide} />
|
||||
</main>
|
||||
}
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
<div>Studio App</div>
|
||||
)
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Marked } from 'marked';
|
||||
import hljs from 'highlight.js';
|
||||
import { markedHighlight } from 'marked-highlight';
|
||||
|
||||
const markedAndHighlight = new Marked(
|
||||
markedHighlight({
|
||||
emptyLangClass: 'hljs',
|
||||
langPrefix: 'hljs language-',
|
||||
highlight(code, lang, info) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export const md2html = async (md: string) => {
|
||||
const html = markedAndHighlight.parse(md);
|
||||
return html;
|
||||
};
|
||||
|
||||
export const clearMeta = (markdown?: string) => {
|
||||
if (!markdown) return '';
|
||||
// Remove YAML front matter if present
|
||||
const yamlRegex = /^---\n[\s\S]*?\n---\n/;
|
||||
return markdown.replace(yamlRegex, '');
|
||||
};
|
||||
type Props = {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
content?: string; // Optional content prop for markdown text
|
||||
[key: string]: any; // Allow any additional props
|
||||
};
|
||||
export const MarkdownPreview = (props: Props) => {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'markdown-body scrollbar h-full overflow-auto w-full px-6 py-2 max-w-[800px] border my-4 flex flex-col justify-self-center rounded-md shadow-md',
|
||||
props.className,
|
||||
)}
|
||||
style={props.style}>
|
||||
{props.children ? <WrapperText>{props.children}</WrapperText> : <MarkdownPreviewWrapper content={clearMeta(props.content)} />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const WrapperText = (props: { children?: React.ReactNode; html?: string }) => {
|
||||
if (props.html) {
|
||||
return <div className='w-full' dangerouslySetInnerHTML={{ __html: props.html }} />;
|
||||
}
|
||||
return <div className='w-full h-full'>{props.children}</div>;
|
||||
};
|
||||
|
||||
export const MarkdownPreviewWrapper = (props: Props) => {
|
||||
const [html, setHtml] = useState<string>('');
|
||||
useEffect(() => {
|
||||
init();
|
||||
}, [props.content]);
|
||||
const init = async () => {
|
||||
if (props.content) {
|
||||
const htmlContent = await md2html(props.content);
|
||||
setHtml(htmlContent);
|
||||
} else {
|
||||
setHtml('');
|
||||
}
|
||||
};
|
||||
return <WrapperText html={html} />;
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
---
|
||||
import '../styles/global.css';
|
||||
import '../styles/theme.css';
|
||||
export interface Props {
|
||||
title?: string;
|
||||
description?: string;
|
||||
lang?: string;
|
||||
charset?: string;
|
||||
}
|
||||
|
||||
const { title = 'Light Code', description = 'A lightweight code editor', lang = 'zh-CN', charset = 'UTF-8' } = Astro.props;
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang={lang}>
|
||||
<head>
|
||||
<meta charset={charset} />
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
|
||||
<meta name='description' content={description} />
|
||||
<title>{title}</title>
|
||||
<!-- 样式 -->
|
||||
<slot name='head' />
|
||||
</head>
|
||||
<body>
|
||||
<slot />
|
||||
|
||||
<!-- 脚本 -->
|
||||
<slot name='scripts' />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
html {
|
||||
font-family: system-ui, sans-serif;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
@@ -1,62 +0,0 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9",
|
||||
"icon-sm": "size-8",
|
||||
"icon-lg": "size-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
data-variant={variant}
|
||||
data-size={size}
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
@@ -1,30 +0,0 @@
|
||||
import * as React from "react"
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Checkbox({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="grid place-content-center text-current transition-none"
|
||||
>
|
||||
<CheckIcon className="size-3.5" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Checkbox }
|
||||
@@ -1,42 +0,0 @@
|
||||
import * as React from "react"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
const Dialog = ({ open, onOpenChange, children }: { open: boolean; onOpenChange: (open: boolean) => void; children: React.ReactNode }) => {
|
||||
if (!open) return null
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
||||
<div className="fixed inset-0 bg-black/50" onClick={() => onOpenChange(false)} />
|
||||
<div className="relative z-50 w-full max-w-2xl max-h-[90vh] overflow-auto bg-white rounded-lg shadow-lg p-6">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const DialogHeader = ({ className, children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex flex-col space-y-1.5 text-center sm:text-left mb-4", className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
|
||||
const DialogTitle = ({ className, children, ...props }: React.HTMLAttributes<HTMLHeadingElement>) => (
|
||||
<h2 className={cn("text-lg font-semibold leading-none tracking-tight", className)} {...props}>
|
||||
{children}
|
||||
</h2>
|
||||
)
|
||||
|
||||
const DialogContent = ({ className, children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("", className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
|
||||
const DialogFooter = ({ className, children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 mt-4", className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
|
||||
export { Dialog, DialogHeader, DialogTitle, DialogContent, DialogFooter }
|
||||
@@ -1,255 +0,0 @@
|
||||
import * as React from "react"
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 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 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto size-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 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 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
@@ -1,22 +0,0 @@
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user