首次发布git

This commit is contained in:
2026-02-24 09:53:19 +08:00
commit dd97cf6a2c
71 changed files with 14875 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
"use client";
import { useSearchStore } from "@/lib/search-store";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { useEditorStore } from "@/lib/store";
import { Command } from "cmdk";
import { Search, FileText, Folder } from "lucide-react";
export function SearchCommand() {
const { isOpen, setOpen, query, setQuery } = useSearchStore();
const { pages, setActivePageId } = useEditorStore();
const router = useRouter();
useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
setOpen(!isOpen);
}
};
document.addEventListener("keydown", down);
return () => document.removeEventListener("keydown", down);
}, [isOpen, setOpen]);
const runCommand = (command: () => void) => {
setOpen(false);
command();
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-background/80 backdrop-blur-sm animate-in fade-in duration-200">
<div
className="fixed inset-0"
onClick={() => setOpen(false)}
/>
<div className="relative w-full max-w-lg bg-popover border rounded-xl shadow-2xl overflow-hidden animate-in zoom-in-95 duration-200">
<Command className="w-full">
<div className="flex items-center border-b px-3">
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
<Command.Input
placeholder="搜索文档..."
value={query}
onValueChange={setQuery}
className="flex h-12 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
/>
</div>
<Command.List className="max-h-[300px] overflow-y-auto p-2">
<Command.Empty className="py-6 text-center text-sm text-muted-foreground"></Command.Empty>
<Command.Group heading="文档">
{pages.map((page) => (
<Command.Item
key={page.id}
value={`${page.title} ${page.tags?.join(" ")}`} // Search by title AND tags
onSelect={() => runCommand(() => setActivePageId(page.id))}
className="flex items-center gap-2 px-2 py-1.5 text-sm rounded-sm cursor-pointer hover:bg-accent hover:text-accent-foreground aria-selected:bg-accent aria-selected:text-accent-foreground transition-colors"
>
{page.type === 'folder' ? <Folder size={14} className="text-blue-400" /> : <FileText size={14} />}
<span>{page.title || "无标题"}</span>
</Command.Item>
))}
</Command.Group>
</Command.List>
</Command>
</div>
</div>
);
}