Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat: add faster editor toolbar tooltips

tianma77122d6cc77c
diff --git a/AGENTS.md b/AGENTS.md
index 247de763..a56011ed 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -10,6 +10,12 @@
严禁创建新的 Git 分支;所有修改、提交和推送都必须直接在 `main` 分支上完成。
+## 本地启动约束
+
+本地预览或调试时,必须优先使用 `bun run dev` 启动完整开发环境,让 API 通过 `scripts/run-wrangler.mjs` 读取 `.env.local` 中的个性化实例配置。实例名称、D1/R2 资源、账号等本机私有配置均以 `.env.local` 为准,严禁在代理指令或代码中硬编码个人实例名。
+
+除非用户明确要求只启动前端静态界面,否则不要单独运行 `bun run dev:web`;该命令不会启动 API,也不会保证读取 `.env.local` 中的实例配置,容易导致前端请求 `127.0.0.1:8787` 失败或误判环境。
+
## 组件复用与造轮子约束
UI 功能应尽量复用 `shadcn/ui` 等现有 UI 组件。在实现其他功能时,也应优先采用成熟、稳定的开源组件或库,绝对禁止在没有充分必要性的前提下自行从零造轮子。
diff --git a/apps/web/src/components/EditorToolbar.tsx b/apps/web/src/components/EditorToolbar.tsx
index cb66bfe2..b29d5044 100644
--- a/apps/web/src/components/EditorToolbar.tsx
+++ b/apps/web/src/components/EditorToolbar.tsx
@@ -15,6 +15,7 @@ import {
} from "lucide-react";
import { cn } from "@/lib/utils";
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select";
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { getActiveBlockValue } from "@/lib/app-helpers";
const EditorToolbarButton = ({
@@ -30,23 +31,27 @@ const EditorToolbarButton = ({
onClick: () => void;
title: string;
}) => (
- <button
- className={cn(
- "flex h-8 w-8 shrink-0 items-center justify-center rounded-md border text-slate-700 transition disabled:pointer-events-none disabled:opacity-40",
- active
- ? "border-emerald-200 bg-emerald-50 text-emerald-800"
- : "border-transparent bg-transparent hover:border-slate-200 hover:bg-slate-50"
- )}
- type="button"
- title={title}
- aria-label={title}
- aria-pressed={active || undefined}
- disabled={disabled}
- onMouseDown={(event) => event.preventDefault()}
- onClick={onClick}
- >
- {children}
- </button>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ className={cn(
+ "flex h-8 w-8 shrink-0 items-center justify-center rounded-md border text-slate-700 transition disabled:pointer-events-none disabled:opacity-40",
+ active
+ ? "border-emerald-200 bg-emerald-50 text-emerald-800"
+ : "border-transparent bg-transparent hover:border-slate-200 hover:bg-slate-50"
+ )}
+ type="button"
+ aria-label={title}
+ aria-pressed={active || undefined}
+ disabled={disabled}
+ onMouseDown={(event) => event.preventDefault()}
+ onClick={onClick}
+ >
+ {children}
+ </button>
+ </TooltipTrigger>
+ <TooltipContent>{title}</TooltipContent>
+ </Tooltip>
);
const ToolbarDivider = () => <div className="h-6 w-px shrink-0 bg-slate-200" />;
@@ -142,121 +147,123 @@ export const EditorToolbar = ({ editor, readOnly }: { editor: Editor | null; rea
};
return (
- <div className="relative border-t border-slate-200 bg-white">
- <div className="pointer-events-none absolute inset-y-0 left-0 z-10 w-4 bg-gradient-to-r from-white to-transparent sm:hidden" />
- <div className="pointer-events-none absolute inset-y-0 right-0 z-10 w-4 bg-gradient-to-l from-white to-transparent sm:hidden" />
- <div
- className="flex min-h-12 items-center gap-2 overflow-x-auto px-3 py-2 [scrollbar-width:none] sm:px-5 [&::-webkit-scrollbar]:hidden"
- role="toolbar"
- aria-label="编辑器工具栏"
- >
- <Select
- value={blockValue}
- disabled={disabled}
- onValueChange={(value) => setBlock(value)}
+ <TooltipProvider delayDuration={250} skipDelayDuration={100}>
+ <div className="relative border-t border-slate-200 bg-white">
+ <div className="pointer-events-none absolute inset-y-0 left-0 z-10 w-4 bg-gradient-to-r from-white to-transparent sm:hidden" />
+ <div className="pointer-events-none absolute inset-y-0 right-0 z-10 w-4 bg-gradient-to-l from-white to-transparent sm:hidden" />
+ <div
+ className="flex min-h-12 items-center gap-2 overflow-x-auto px-3 py-2 [scrollbar-width:none] sm:px-5 [&::-webkit-scrollbar]:hidden"
+ role="toolbar"
+ aria-label="编辑器工具栏"
>
- <SelectTrigger className="h-8 w-20 shrink-0 whitespace-nowrap border-slate-200 bg-white text-xs text-slate-800 [&>span]:truncate [&>span]:whitespace-nowrap">
- <SelectValue placeholder="正文" />
- </SelectTrigger>
- <SelectContent className="bg-white border border-slate-200 rounded-md py-1 shadow-md">
- <SelectItem value="paragraph">正文</SelectItem>
- <SelectItem value="heading-1">标题 1</SelectItem>
- <SelectItem value="heading-2">标题 2</SelectItem>
- <SelectItem value="heading-3">标题 3</SelectItem>
- </SelectContent>
- </Select>
+ <Select
+ value={blockValue}
+ disabled={disabled}
+ onValueChange={(value) => setBlock(value)}
+ >
+ <SelectTrigger className="h-8 w-20 shrink-0 whitespace-nowrap border-slate-200 bg-white text-xs text-slate-800 [&>span]:truncate [&>span]:whitespace-nowrap">
+ <SelectValue placeholder="正文" />
+ </SelectTrigger>
+ <SelectContent className="bg-white border border-slate-200 rounded-md py-1 shadow-md">
+ <SelectItem value="paragraph">正文</SelectItem>
+ <SelectItem value="heading-1">标题 1</SelectItem>
+ <SelectItem value="heading-2">标题 2</SelectItem>
+ <SelectItem value="heading-3">标题 3</SelectItem>
+ </SelectContent>
+ </Select>
- <ToolbarDivider />
- <EditorToolbarButton
- title="撤销"
- disabled={!canRun((current) => current.can().chain().focus().undo().run())}
- onClick={() => run((current) => current.chain().focus().undo().run())}
- >
- <Undo2 className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="重做"
- disabled={!canRun((current) => current.can().chain().focus().redo().run())}
- onClick={() => run((current) => current.chain().focus().redo().run())}
- >
- <Redo2 className="h-4 w-4" />
- </EditorToolbarButton>
+ <ToolbarDivider />
+ <EditorToolbarButton
+ title="撤销"
+ disabled={!canRun((current) => current.can().chain().focus().undo().run())}
+ onClick={() => run((current) => current.chain().focus().undo().run())}
+ >
+ <Undo2 className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="重做"
+ disabled={!canRun((current) => current.can().chain().focus().redo().run())}
+ onClick={() => run((current) => current.chain().focus().redo().run())}
+ >
+ <Redo2 className="h-4 w-4" />
+ </EditorToolbarButton>
- <ToolbarDivider />
- <EditorToolbarButton
- title="加粗"
- active={isActive("bold")}
- disabled={!canRun((current) => current.can().chain().focus().toggleBold().run())}
- onClick={() => run((current) => current.chain().focus().toggleBold().run())}
- >
- <Bold className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="斜体"
- active={isActive("italic")}
- disabled={!canRun((current) => current.can().chain().focus().toggleItalic().run())}
- onClick={() => run((current) => current.chain().focus().toggleItalic().run())}
- >
- <Italic className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="删除线"
- active={isActive("strike")}
- disabled={!canRun((current) => current.can().chain().focus().toggleStrike().run())}
- onClick={() => run((current) => current.chain().focus().toggleStrike().run())}
- >
- <Strikethrough className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="行内代码"
- active={isActive("code")}
- disabled={!canRun((current) => current.can().chain().focus().toggleCode().run())}
- onClick={() => run((current) => current.chain().focus().toggleCode().run())}
- >
- <Code2 className="h-4 w-4" />
- </EditorToolbarButton>
+ <ToolbarDivider />
+ <EditorToolbarButton
+ title="加粗"
+ active={isActive("bold")}
+ disabled={!canRun((current) => current.can().chain().focus().toggleBold().run())}
+ onClick={() => run((current) => current.chain().focus().toggleBold().run())}
+ >
+ <Bold className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="斜体"
+ active={isActive("italic")}
+ disabled={!canRun((current) => current.can().chain().focus().toggleItalic().run())}
+ onClick={() => run((current) => current.chain().focus().toggleItalic().run())}
+ >
+ <Italic className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="删除线"
+ active={isActive("strike")}
+ disabled={!canRun((current) => current.can().chain().focus().toggleStrike().run())}
+ onClick={() => run((current) => current.chain().focus().toggleStrike().run())}
+ >
+ <Strikethrough className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="行内代码"
+ active={isActive("code")}
+ disabled={!canRun((current) => current.can().chain().focus().toggleCode().run())}
+ onClick={() => run((current) => current.chain().focus().toggleCode().run())}
+ >
+ <Code2 className="h-4 w-4" />
+ </EditorToolbarButton>
- <ToolbarDivider />
- <EditorToolbarButton
- title="无序列表"
- active={isActive("bulletList")}
- disabled={disabled}
- onClick={() => run((current) => current.chain().focus().toggleBulletList().run())}
- >
- <List className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="有序列表"
- active={isActive("orderedList")}
- disabled={disabled}
- onClick={() => run((current) => current.chain().focus().toggleOrderedList().run())}
- >
- <ListOrdered className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="引用"
- active={isActive("blockquote")}
- disabled={disabled}
- onClick={() => run((current) => current.chain().focus().toggleBlockquote().run())}
- >
- <Quote className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="代码块"
- active={isActive("codeBlock")}
- disabled={disabled}
- onClick={() => run(toggleCodeBlock)}
- >
- <SquareCode className="h-4 w-4" />
- </EditorToolbarButton>
- <EditorToolbarButton
- title="分割线"
- disabled={disabled}
- onClick={() => run((current) => current.chain().focus().setHorizontalRule().run())}
- >
- <Minus className="h-4 w-4" />
- </EditorToolbarButton>
+ <ToolbarDivider />
+ <EditorToolbarButton
+ title="无序列表"
+ active={isActive("bulletList")}
+ disabled={disabled}
+ onClick={() => run((current) => current.chain().focus().toggleBulletList().run())}
+ >
+ <List className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="有序列表"
+ active={isActive("orderedList")}
+ disabled={disabled}
+ onClick={() => run((current) => current.chain().focus().toggleOrderedList().run())}
+ >
+ <ListOrdered className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="引用"
+ active={isActive("blockquote")}
+ disabled={disabled}
+ onClick={() => run((current) => current.chain().focus().toggleBlockquote().run())}
+ >
+ <Quote className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="代码块"
+ active={isActive("codeBlock")}
+ disabled={disabled}
+ onClick={() => run(toggleCodeBlock)}
+ >
+ <SquareCode className="h-4 w-4" />
+ </EditorToolbarButton>
+ <EditorToolbarButton
+ title="分割线"
+ disabled={disabled}
+ onClick={() => run((current) => current.chain().focus().setHorizontalRule().run())}
+ >
+ <Minus className="h-4 w-4" />
+ </EditorToolbarButton>
+ </div>
</div>
- </div>
+ </TooltipProvider>
);
};
diff --git a/apps/web/src/components/ui/tooltip.tsx b/apps/web/src/components/ui/tooltip.tsx
new file mode 100644
index 00000000..652c0211
--- /dev/null
+++ b/apps/web/src/components/ui/tooltip.tsx
@@ -0,0 +1,27 @@
+import * as React from "react";
+import * as TooltipPrimitive from "@radix-ui/react-tooltip";
+import { cn } from "@/lib/utils";
+
+const TooltipProvider = TooltipPrimitive.Provider;
+const Tooltip = TooltipPrimitive.Root;
+const TooltipTrigger = TooltipPrimitive.Trigger;
+
+const TooltipContent = React.forwardRef<
+ React.ElementRef<typeof TooltipPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
+>(({ className, sideOffset = 6, ...props }, ref) => (
+ <TooltipPrimitive.Portal>
+ <TooltipPrimitive.Content
+ ref={ref}
+ sideOffset={sideOffset}
+ className={cn(
+ "z-50 overflow-hidden rounded-md bg-slate-950 px-2.5 py-1.5 text-xs text-white shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
+ className
+ )}
+ {...props}
+ />
+ </TooltipPrimitive.Portal>
+));
+TooltipContent.displayName = TooltipPrimitive.Content.displayName;
+
+export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };