AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
refactor(web): share compact editor toolbar
tianma-if70cd73105fc2
diff --git a/apps/web/src/components/DiagramEditorPane.test.mjs b/apps/web/src/components/DiagramEditorPane.test.mjsindex b7160e95..83447103 100644--- a/apps/web/src/components/DiagramEditorPane.test.mjs+++ b/apps/web/src/components/DiagramEditorPane.test.mjs@@ -108,7 +108,7 @@ describe("diagram editor canvas surface", () => {expect(source).toContain("<DiagramToolbar");expect(source).toContain("leading={!readOnly ? (");expect(toolbarSource).toContain('role="toolbar"');- expect(toolbarSource).toContain("{leading ? <>{leading}<ToolbarDivider /></> : null}");+ expect(toolbarSource).toContain("{leading ? <>{leading}<MemoEditorToolbarDivider /></> : null}");expect(toolbarSource).toContain("{selectionEditor}");});@@ -259,7 +259,7 @@ describe("diagram editor canvas surface", () => {test("keeps the desktop header compact without shrinking mobile controls", () => {expect(source).toContain("MEMO_EDITOR_TOP_ROW_CLASS_NAME");expect(source).toContain("MEMO_EDITOR_TITLE_ROW_CLASS_NAME");- expect(toolbarSource).toContain("MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME");+ expect(toolbarSource).toContain("<MemoEditorToolbarRow");});test("repaints the graph when the application appearance changes", () => {diff --git a/apps/web/src/components/DiagramToolbar.tsx b/apps/web/src/components/DiagramToolbar.tsxindex db2e40d8..3f73eb49 100644--- a/apps/web/src/components/DiagramToolbar.tsx+++ b/apps/web/src/components/DiagramToolbar.tsx@@ -17,7 +17,7 @@ import {import { useTranslation } from "react-i18next";import type { DiagramTheme } from "@edgeever/shared";import { Button } from "@/components/ui/button";-import { MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME } from "@/components/MemoEditorChromeDensity";+import { MemoEditorToolbarDivider, MemoEditorToolbarRow } from "@/components/MemoEditorToolbarChrome";import {DropdownMenu,DropdownMenuContent,@@ -27,7 +27,6 @@ import {import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { resolveDiagramPalette, type DiagramAppearance } from "@/lib/diagram-theme";-import { cn } from "@/lib/utils";type DiagramToolbarProps = {appearance: DiagramAppearance;@@ -52,8 +51,6 @@ type DiagramToolbarProps = {theme: DiagramTheme;};-const ToolbarDivider = () => <span className="mx-1 h-5 w-px shrink-0 bg-slate-200" />;-export const DiagramToolbarAddTrigger = ({onPointerEnter,}: {@@ -95,8 +92,8 @@ export const DiagramToolbar = ({}: DiagramToolbarProps) => {const { t } = useTranslation();return (- <div className={cn("flex shrink-0 flex-wrap items-center gap-1 border-b border-slate-200 bg-white", MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME)} role="toolbar" aria-label={t("diagram.toolbar")}>- {leading ? <>{leading}<ToolbarDivider /></> : null}+ <MemoEditorToolbarRow className="shrink-0 border-b border-slate-200 bg-white" role="toolbar" aria-label={t("diagram.toolbar")}>+ {leading ? <>{leading}<MemoEditorToolbarDivider /></> : null}<Tooltip><TooltipTrigger asChild><Button size="icon" variant="ghost" aria-label={t("diagram.undo")} disabled={!canUndo || readOnly} onClick={onUndo}><Undo2 className="h-4 w-4" /></Button></TooltipTrigger><TooltipContent>{t("diagram.undo")}</TooltipContent></Tooltip><Tooltip><TooltipTrigger asChild><Button size="icon" variant="ghost" aria-label={t("diagram.redo")} disabled={!canRedo || readOnly} onClick={onRedo}><Redo2 className="h-4 w-4" /></Button></TooltipTrigger><TooltipContent>{t("diagram.redo")}</TooltipContent></Tooltip>{!readOnly && <Tooltip><TooltipTrigger asChild><Button size="icon" variant="ghost" aria-label={t("diagram.deleteSelection")} disabled={!hasSelection} onClick={onDeleteSelection}><Trash2 className="h-4 w-4" /></Button></TooltipTrigger><TooltipContent>{t("diagram.deleteSelection")}</TooltipContent></Tooltip>}@@ -111,13 +108,13 @@ export const DiagramToolbar = ({<TooltipContent>{t("diagram.autoLayoutTooltip")}</TooltipContent></Tooltip>)}- <ToolbarDivider />+ <MemoEditorToolbarDivider /><Tooltip><TooltipTrigger asChild><Button size="icon" variant="ghost" aria-label={t("diagram.zoomOut")} onClick={onZoomOut}><ZoomOut className="h-4 w-4" /></Button></TooltipTrigger><TooltipContent>{t("diagram.zoomOut")}</TooltipContent></Tooltip><Tooltip><TooltipTrigger asChild><Button size="sm" variant="ghost" className="w-16 tabular-nums" aria-label={t("diagram.resetZoom")} onClick={onResetZoom}>{zoomPercent}%</Button></TooltipTrigger><TooltipContent>{t("diagram.resetZoom")}</TooltipContent></Tooltip><Tooltip><TooltipTrigger asChild><Button size="icon" variant="ghost" aria-label={t("diagram.zoomIn")} onClick={onZoomIn}><ZoomIn className="h-4 w-4" /></Button></TooltipTrigger><TooltipContent>{t("diagram.zoomIn")}</TooltipContent></Tooltip><Tooltip><TooltipTrigger asChild><Button size="sm" variant="ghost" aria-label={t("diagram.fit")} onClick={onFit}><Scan className="h-4 w-4" /><span>{t("diagram.fit")}</span></Button></TooltipTrigger><TooltipContent>{t("diagram.fit")}</TooltipContent></Tooltip>{onRead ? <Tooltip><TooltipTrigger asChild><Button size="sm" variant="ghost" onClick={onRead}><BookOpen className="h-4 w-4" />{t("diagram.readFlow")}</Button></TooltipTrigger><TooltipContent>{t("diagram.readFlowHint")}</TooltipContent></Tooltip> : null}- <ToolbarDivider />+ <MemoEditorToolbarDivider /><Select value={theme} disabled={readOnly} onValueChange={(value) => onThemeChange(value as DiagramTheme)}><SelectTrigger className="h-8 w-[8.5rem] gap-2" aria-label={t("diagram.theme")}><SelectValue />@@ -138,6 +135,6 @@ export const DiagramToolbar = ({</DropdownMenuContent></DropdownMenu>{selectionEditor}- </div>+ </MemoEditorToolbarRow>);};diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 3e561886..7cb0cbe7 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -4151,7 +4151,7 @@ const RichEditorPane = ({</div><div className={MEMO_EDITOR_TEXT_TITLE_REGION_CLASS_NAME}>- <div className="min-w-0 min-[1600px]:flex-1">+ <div className="min-w-0"><MemoTitleInputvalue={title}readOnly={effectiveReadOnly}@@ -4163,7 +4163,7 @@ const RichEditorPane = ({placeholder={t("common.untitledMemo")}/></div>- <div className="flex flex-wrap items-center gap-1.5 sm:gap-2 min-[1600px]:shrink-0 min-[1600px]:flex-nowrap">+ <div className="flex flex-wrap items-center gap-1.5 sm:gap-2"><buttonclassName="flex h-7 min-w-0 max-w-full items-center gap-1 rounded-md border border-transparent bg-transparent px-1.5 text-xs font-medium text-slate-600 outline-none transition hover:border-slate-200 hover:bg-slate-50 hover:text-slate-900 focus-visible:border-emerald-300 focus-visible:ring-2 focus-visible:ring-emerald-500/20 disabled:opacity-50 sm:hidden"type="button"diff --git a/apps/web/src/components/EditorToolbar.tsx b/apps/web/src/components/EditorToolbar.tsxindex 05fb5efc..e84e3912 100644--- a/apps/web/src/components/EditorToolbar.tsx+++ b/apps/web/src/components/EditorToolbar.tsx@@ -22,7 +22,7 @@ import {ChevronUp,} from "lucide-react";import { cn } from "@/lib/utils";-import { MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME } from "@/components/MemoEditorChromeDensity";+import { MemoEditorToolbarDivider, MemoEditorToolbarRow } from "@/components/MemoEditorToolbarChrome";import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select";import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";import {@@ -72,8 +72,6 @@ const EditorToolbarButton = ({</Tooltip>);-const ToolbarDivider = () => <div className="hidden h-6 w-px shrink-0 bg-slate-200 sm:block" />;-const isToolbarEditorReady = (editor: Editor | null): editor is Editor =>Boolean(editor && !editor.isDestroyed && (editor as { extensionManager?: unknown }).extensionManager);@@ -286,11 +284,9 @@ export const EditorToolbar = ({aria-label={t("editorToolbar.toolbar")}><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+ <MemoEditorToolbarRowref={controlsRef}className={cn(- "flex min-w-0 max-w-full flex-wrap items-center gap-1",- MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME,hasOverflow && "pr-14 sm:pr-16",!expanded && "max-h-12 overflow-hidden")}@@ -325,7 +321,7 @@ export const EditorToolbar = ({)}</TooltipContent></Tooltip>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /></>)}{onPickAttachment && (@@ -337,7 +333,7 @@ export const EditorToolbar = ({><Paperclip className="h-4 w-4" /></EditorToolbarButton>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /></>)}{onPickExternalLink && (@@ -354,7 +350,7 @@ export const EditorToolbar = ({><Link className="h-4 w-4" /></EditorToolbarButton>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /></>)}{onPickNoteLink && (@@ -366,7 +362,7 @@ export const EditorToolbar = ({><Link2 className="h-4 w-4" /></EditorToolbarButton>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /></>)}{markdownMode ? (@@ -389,7 +385,7 @@ export const EditorToolbar = ({</SelectContent></Select>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /><EditorToolbarButtontitle={t("editorToolbar.undo")}disabled={!canRun((current) => current.can().chain().focus().undo().run())}@@ -405,7 +401,7 @@ export const EditorToolbar = ({<Redo2 className="h-4 w-4" /></EditorToolbarButton>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /><EditorToolbarButtontitle={t("editorToolbar.bold")}active={isActive("bold")}@@ -439,7 +435,7 @@ export const EditorToolbar = ({<Code2 className="h-4 w-4" /></EditorToolbarButton>- <ToolbarDivider />+ <MemoEditorToolbarDivider className="hidden sm:block" /><EditorToolbarButtontitle={`${t("editorToolbar.bulletList")} · ${t("editorToolbar.listIndentHint")}`}active={isActive("bulletList")}@@ -521,7 +517,7 @@ export const EditorToolbar = ({<EditorTableMenu editor={editor} readOnly={readOnly} /></>)}- </div>+ </MemoEditorToolbarRow>{hasOverflow && (<div className="absolute right-3 top-2 z-20 flex h-8 items-center bg-gradient-to-l from-white via-white to-transparent pl-5 sm:right-5"><Tooltip>diff --git a/apps/web/src/components/MemoEditorChromeDensity.ts b/apps/web/src/components/MemoEditorChromeDensity.tsindex 65fe9777..8c0ea853 100644--- a/apps/web/src/components/MemoEditorChromeDensity.ts+++ b/apps/web/src/components/MemoEditorChromeDensity.ts@@ -2,10 +2,10 @@ export const MEMO_EDITOR_TOP_ROW_CLASS_NAME ="flex min-h-12 items-center justify-between gap-2 border-b border-slate-100 px-3 py-2 sm:min-h-10 sm:px-5 sm:py-1";export const MEMO_EDITOR_TITLE_ROW_CLASS_NAME =- "flex min-h-12 items-center gap-3 px-4 py-2 sm:min-h-11 sm:px-7 sm:py-1";+ "flex min-h-12 items-center gap-3 px-4 py-2 sm:min-h-10 sm:px-7 sm:py-1";export const MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME ="px-3 py-2 sm:px-5 sm:py-1";export const MEMO_EDITOR_TEXT_TITLE_REGION_CLASS_NAME =- "space-y-1.5 px-4 pb-2.5 pt-2.5 sm:space-y-3 sm:px-7 sm:pb-4 sm:pt-4 lg:space-y-0 lg:py-0 min-[1600px]:flex min-[1600px]:min-h-11 min-[1600px]:items-center min-[1600px]:gap-3 min-[1600px]:py-1";+ "space-y-1.5 px-4 pb-2.5 pt-2.5 sm:space-y-3 sm:px-7 sm:pb-4 sm:pt-4 lg:space-y-0 lg:py-0";diff --git a/apps/web/src/components/MemoEditorHeaderActions.test.mjs b/apps/web/src/components/MemoEditorHeaderActions.test.mjsindex d4430c6f..f8a26ebb 100644--- a/apps/web/src/components/MemoEditorHeaderActions.test.mjs+++ b/apps/web/src/components/MemoEditorHeaderActions.test.mjs@@ -7,6 +7,7 @@ const diagramSource = readFileSync(new URL("./DiagramEditorPane.tsx", import.metconst densitySource = readFileSync(new URL("./MemoEditorChromeDensity.ts", import.meta.url), "utf8");const editorToolbarSource = readFileSync(new URL("./EditorToolbar.tsx", import.meta.url), "utf8");const diagramToolbarSource = readFileSync(new URL("./DiagramToolbar.tsx", import.meta.url), "utf8");+const toolbarChromeSource = readFileSync(new URL("./MemoEditorToolbarChrome.tsx", import.meta.url), "utf8");describe("shared memo editor header actions", () => {test("owns every action shared by text and diagram notes", () => {@@ -31,10 +32,13 @@ describe("shared memo editor header actions", () => {test("applies one shared compact density standard to both editors", () => {expect(editorSource).toContain("MEMO_EDITOR_TOP_ROW_CLASS_NAME");expect(diagramSource).toContain("MEMO_EDITOR_TOP_ROW_CLASS_NAME");- expect(editorToolbarSource).toContain("MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME");- expect(diagramToolbarSource).toContain("MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME");+ expect(editorToolbarSource).toContain("<MemoEditorToolbarRow");+ expect(diagramToolbarSource).toContain("<MemoEditorToolbarRow");+ expect(editorToolbarSource).toContain("<MemoEditorToolbarDivider");+ expect(diagramToolbarSource).toContain("<MemoEditorToolbarDivider");+ expect(toolbarChromeSource).toContain("MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME");expect(densitySource).toContain("sm:min-h-10 sm:px-5 sm:py-1");- expect(densitySource).toContain("min-[1600px]:min-h-11");- expect(densitySource).toContain("min-[1600px]:flex");+ expect(densitySource).toContain("lg:space-y-0 lg:py-0");+ expect(densitySource).not.toContain("min-[1600px]:flex");});});diff --git a/apps/web/src/components/MemoEditorToolbarChrome.tsx b/apps/web/src/components/MemoEditorToolbarChrome.tsxnew file mode 100644index 00000000..c8798c08--- /dev/null+++ b/apps/web/src/components/MemoEditorToolbarChrome.tsx@@ -0,0 +1,24 @@+import { forwardRef, type ComponentPropsWithoutRef } from "react";+import { MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME } from "@/components/MemoEditorChromeDensity";+import { cn } from "@/lib/utils";++export const MemoEditorToolbarRow = forwardRef<+ HTMLDivElement,+ ComponentPropsWithoutRef<"div">+>(({ className, ...props }, ref) => (+ <div+ ref={ref}+ className={cn(+ "flex min-w-0 max-w-full flex-wrap items-center gap-1",+ MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME,+ className,+ )}+ {...props}+ />+));++MemoEditorToolbarRow.displayName = "MemoEditorToolbarRow";++export const MemoEditorToolbarDivider = ({ className }: { className?: string }) => (+ <span aria-hidden="true" className={cn("h-5 w-px shrink-0 bg-slate-200", className)} />+);diff --git a/apps/web/src/components/MemoTitleInput.test.mjs b/apps/web/src/components/MemoTitleInput.test.mjsindex 3173ec87..aec1af03 100644--- a/apps/web/src/components/MemoTitleInput.test.mjs+++ b/apps/web/src/components/MemoTitleInput.test.mjs@@ -8,6 +8,8 @@ const diagramSource = readFileSync(new URL("./DiagramEditorPane.tsx", import.metdescribe("shared memo title input", () => {test("owns the title appearance and input constraints", () => {expect(componentSource).toContain("text-xl font-bold");+ expect(componentSource).toContain("sm:text-2xl");+ expect(componentSource).not.toContain("lg:text-[26px]");expect(componentSource).toContain("focus-visible:bg-muted");expect(componentSource).toContain("maxLength={160}");expect(componentSource).toContain("readOnly={readOnly}");diff --git a/apps/web/src/components/MemoTitleInput.tsx b/apps/web/src/components/MemoTitleInput.tsxindex c5d284c8..916c0bb5 100644--- a/apps/web/src/components/MemoTitleInput.tsx+++ b/apps/web/src/components/MemoTitleInput.tsx@@ -15,7 +15,7 @@ export const MemoTitleInput = ({}: MemoTitleInputProps) => (<inputaria-label={ariaLabel ?? placeholder}- className="block w-full rounded-md border-0 bg-transparent text-xl font-bold leading-snug text-slate-950 outline-none transition placeholder:text-slate-300 focus-visible:bg-muted focus-visible:shadow-[inset_3px_0_0_var(--brand-green)] read-only:text-slate-600 read-only:focus-visible:bg-transparent read-only:focus-visible:shadow-none sm:text-2xl lg:text-[26px]"+ className="block w-full rounded-md border-0 bg-transparent text-xl font-bold leading-snug text-slate-950 outline-none transition placeholder:text-slate-300 focus-visible:bg-muted focus-visible:shadow-[inset_3px_0_0_var(--brand-green)] read-only:text-slate-600 read-only:focus-visible:bg-transparent read-only:focus-visible:shadow-none sm:text-2xl"maxLength={160}onChange={(event) => onValueChange(event.target.value)}placeholder={placeholder}