Skip to content

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

refactor(web): optimize font preference hierarchy, preview, and layout

tianma-ifc2e3a7aab381
diff --git a/apps/web/src/components/settings/PreferenceCard.test.mjs b/apps/web/src/components/settings/PreferenceCard.test.mjs
index fb1bbc53..54d5fdc0 100644
--- a/apps/web/src/components/settings/PreferenceCard.test.mjs
+++ b/apps/web/src/components/settings/PreferenceCard.test.mjs
@@ -20,6 +20,11 @@ describe("editor body font preference", () => {
expect(fontFaces).toContain("zhi-song.woff2?url");
expect(preferenceCard).toContain('t("settings.uiFontTitle")');
expect(preferenceCard).toContain("applyUiFontPreference");
+ expect(preferenceCard).toContain("getFontChoicePreviewStack");
+ expect(preferenceCard).toContain("BookOpenText");
+ expect(preferenceCard).toContain("AppWindow");
+ expect(preferenceCard).toContain("CUSTOM_FONT_SUGGESTIONS");
+ expect(preferenceCard).toContain('t("settings.editorBodyFontSuggestions")');
expect(editorFonts).toContain("html[data-editor-body-font] .edgeever-editor .ProseMirror");
expect(editorFonts).toContain("html[data-ui-font]");
expect(editorFonts).toContain("html[data-ui-font]:not([data-editor-body-font]) .edgeever-editor[data-editor-theme=\"default\"] .ProseMirror");
diff --git a/apps/web/src/components/settings/PreferenceCard.tsx b/apps/web/src/components/settings/PreferenceCard.tsx
index 6e308fc7..c870fab0 100644
--- a/apps/web/src/components/settings/PreferenceCard.tsx
+++ b/apps/web/src/components/settings/PreferenceCard.tsx
@@ -1,4 +1,4 @@
-import { AlignHorizontalJustifyCenter, ChartNoAxesCombined, Image, Keyboard, Languages, MousePointerClick, Palette, Sparkles, SunMoon, Type } from "lucide-react";
+import { AlignHorizontalJustifyCenter, AppWindow, BookOpenText, ChartNoAxesCombined, Image, Keyboard, Languages, MousePointerClick, Palette, Sparkles, SunMoon } from "lucide-react";
import { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import type { EditorContentAlignment, ShortcutSettings } from "@/lib/app-helpers";
@@ -40,6 +40,7 @@ import {
} from "@/i18n";
import {
applyEditorBodyFontPreference,
+ getFontChoicePreviewStack,
readEditorBodyFontPreference,
writeEditorBodyFontPreference,
type EditorBodyFontChoice,
@@ -61,6 +62,13 @@ import {
type ThemePreference,
} from "../ThemeProvider";
+const CUSTOM_FONT_SUGGESTIONS = [
+ { label: "苹方 (PingFang SC)", family: "PingFang SC" },
+ { label: "微软雅黑 (Microsoft YaHei)", family: "Microsoft YaHei" },
+ { label: "鸿蒙黑体 (HarmonyOS)", family: "HarmonyOS Sans SC" },
+ { label: "冬青黑体 (Hiragino)", family: "Hiragino Sans GB" },
+] as const;
+
const FontChoiceFields = ({
label,
preference,
@@ -82,25 +90,89 @@ const FontChoiceFields = ({
</SelectTrigger>
<SelectContent>
<SelectItem value="system">{t("settings.editorBodyFonts.system")}</SelectItem>
- <SelectItem value="wenkai">{t("settings.editorBodyFonts.wenkai")}</SelectItem>
- <SelectItem value="wenkai-screen">{t("settings.editorBodyFonts.wenkaiScreen")}</SelectItem>
- <SelectItem value="zhuque">{t("settings.editorBodyFonts.zhuque")}</SelectItem>
- <SelectItem value="source-han-serif">{t("settings.editorBodyFonts.sourceHanSerif")}</SelectItem>
- <SelectItem value="neo-zhi-song">{t("settings.editorBodyFonts.neoZhiSong")}</SelectItem>
- <SelectItem value="source-han-sans">{t("settings.editorBodyFonts.sourceHanSans")}</SelectItem>
- <SelectItem value="source-serif">{t("settings.editorBodyFonts.sourceSerif")}</SelectItem>
+ <SelectItem
+ value="wenkai"
+ style={{ fontFamily: getFontChoicePreviewStack("wenkai") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("wenkai") }}>
+ {t("settings.editorBodyFonts.wenkai")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="wenkai-screen"
+ style={{ fontFamily: getFontChoicePreviewStack("wenkai-screen") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("wenkai-screen") }}>
+ {t("settings.editorBodyFonts.wenkaiScreen")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="zhuque"
+ style={{ fontFamily: getFontChoicePreviewStack("zhuque") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("zhuque") }}>
+ {t("settings.editorBodyFonts.zhuque")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="source-han-serif"
+ style={{ fontFamily: getFontChoicePreviewStack("source-han-serif") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("source-han-serif") }}>
+ {t("settings.editorBodyFonts.sourceHanSerif")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="neo-zhi-song"
+ style={{ fontFamily: getFontChoicePreviewStack("neo-zhi-song") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("neo-zhi-song") }}>
+ {t("settings.editorBodyFonts.neoZhiSong")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="source-han-sans"
+ style={{ fontFamily: getFontChoicePreviewStack("source-han-sans") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("source-han-sans") }}>
+ {t("settings.editorBodyFonts.sourceHanSans")}
+ </span>
+ </SelectItem>
+ <SelectItem
+ value="source-serif"
+ style={{ fontFamily: getFontChoicePreviewStack("source-serif") }}
+ >
+ <span style={{ fontFamily: getFontChoicePreviewStack("source-serif") }}>
+ {t("settings.editorBodyFonts.sourceSerif")}
+ </span>
+ </SelectItem>
<SelectItem value="custom">{t("settings.editorBodyFonts.custom")}</SelectItem>
</SelectContent>
</Select>
{preference.choice === "custom" ? (
- <Input
- value={preference.customFamily}
- aria-label={t("settings.editorBodyFontCustomLabel")}
- placeholder={t("settings.editorBodyFontCustomPlaceholder")}
- className="h-9"
- maxLength={200}
- onChange={(event) => onChange({ choice: "custom", customFamily: event.target.value })}
- />
+ <div className="flex flex-col gap-1.5">
+ <Input
+ value={preference.customFamily}
+ aria-label={t("settings.editorBodyFontCustomLabel")}
+ placeholder={t("settings.editorBodyFontCustomPlaceholder")}
+ className="h-9"
+ maxLength={200}
+ onChange={(event) => onChange({ choice: "custom", customFamily: event.target.value })}
+ />
+ <div className="flex flex-wrap items-center gap-1 text-[11px] text-slate-500">
+ <span className="shrink-0 text-slate-400">{t("settings.editorBodyFontSuggestions")}:</span>
+ {CUSTOM_FONT_SUGGESTIONS.map((item) => (
+ <button
+ key={item.family}
+ type="button"
+ className="rounded border border-slate-200 bg-slate-50 px-1.5 py-0.5 text-slate-600 transition-colors hover:border-slate-300 hover:bg-slate-100 hover:text-slate-900"
+ onClick={() => onChange({ choice: "custom", customFamily: item.family })}
+ >
+ {item.label}
+ </button>
+ ))}
+ </div>
+ </div>
) : null}
</div>
);
@@ -327,6 +399,21 @@ export const PreferenceCard = ({
</div>
</div>
+ <div className="flex min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
+ <div className="flex min-w-0 items-start gap-3">
+ <AppWindow className={SETTINGS_ITEM_ICON_CLASSNAME} />
+ <div className="min-w-0">
+ <div className={SETTINGS_ITEM_TITLE_CLASSNAME}>{t("settings.uiFontTitle")}</div>
+ <div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.uiFontDescription")}</div>
+ </div>
+ </div>
+ <FontChoiceFields
+ label={t("settings.uiFontTitle")}
+ preference={uiFont}
+ onChange={updateUiFont}
+ />
+ </div>
+
<div className="hidden min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4 lg:flex">
<div className="flex min-w-0 items-start gap-3">
<AlignHorizontalJustifyCenter className={SETTINGS_ITEM_ICON_CLASSNAME} />
@@ -335,7 +422,7 @@ export const PreferenceCard = ({
<div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.editorContentAlignmentDescription")}</div>
</div>
</div>
- <div className="w-full shrink-0 sm:w-44">
+ <div className="w-full shrink-0 sm:w-80">
<Select
value={editorContentAlignment}
onValueChange={(value) => onEditorContentAlignmentChange(value as EditorContentAlignment)}
@@ -353,7 +440,7 @@ export const PreferenceCard = ({
<div className="flex min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
<div className="flex min-w-0 items-start gap-3">
- <Type className={SETTINGS_ITEM_ICON_CLASSNAME} />
+ <BookOpenText className={SETTINGS_ITEM_ICON_CLASSNAME} />
<div className="min-w-0">
<div className={SETTINGS_ITEM_TITLE_CLASSNAME}>{t("settings.editorBodyFontTitle")}</div>
<div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.editorBodyFontDescription")}</div>
@@ -366,21 +453,6 @@ export const PreferenceCard = ({
/>
</div>
- <div className="flex min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
- <div className="flex min-w-0 items-start gap-3">
- <Type className={SETTINGS_ITEM_ICON_CLASSNAME} />
- <div className="min-w-0">
- <div className={SETTINGS_ITEM_TITLE_CLASSNAME}>{t("settings.uiFontTitle")}</div>
- <div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.uiFontDescription")}</div>
- </div>
- </div>
- <FontChoiceFields
- label={t("settings.uiFontTitle")}
- preference={uiFont}
- onChange={updateUiFont}
- />
- </div>
-
{!isMobile && (
<div className="flex min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
<div className="flex min-w-0 items-start gap-3">
diff --git a/apps/web/src/lib/editor-body-font.test.mjs b/apps/web/src/lib/editor-body-font.test.mjs
index 07608522..7012af8a 100644
--- a/apps/web/src/lib/editor-body-font.test.mjs
+++ b/apps/web/src/lib/editor-body-font.test.mjs
@@ -3,6 +3,7 @@ import {
EDITOR_BODY_FONT_CUSTOM_STORAGE_KEY,
EDITOR_BODY_FONT_STORAGE_KEY,
applyEditorBodyFontPreference,
+ getFontChoicePreviewStack,
readEditorBodyFontPreference,
resolveEditorBodyFontStack,
sanitizeEditorBodyFontFamily,
@@ -104,4 +105,11 @@ describe("editor body font preference", () => {
expect(dataset.editorBodyFont).toBeUndefined();
expect(style.has("--editor-body-font-family")).toBe(false);
});
+
+ test("returns font preview stacks for bundled choices", () => {
+ expect(getFontChoicePreviewStack("system")).toBeUndefined();
+ expect(getFontChoicePreviewStack("custom")).toBeUndefined();
+ expect(getFontChoicePreviewStack("wenkai")).toContain("EdgeEver Kai");
+ expect(getFontChoicePreviewStack("zhuque")).toContain("EdgeEver Fangsong");
+ });
});
diff --git a/apps/web/src/lib/editor-body-font.ts b/apps/web/src/lib/editor-body-font.ts
index 8facfcef..41939f65 100644
--- a/apps/web/src/lib/editor-body-font.ts
+++ b/apps/web/src/lib/editor-body-font.ts
@@ -23,7 +23,7 @@ export type EditorBodyFontPreference = {
const CJK_FALLBACK =
'-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif';
-const BUNDLED_FONT_STACKS: Record<Exclude<EditorBodyFontChoice, "system" | "custom">, string> = {
+export const BUNDLED_FONT_STACKS: Record<Exclude<EditorBodyFontChoice, "system" | "custom">, string> = {
wenkai: `"EdgeEver Kai", ${CJK_FALLBACK}`,
"wenkai-screen": `"EdgeEver Kai Screen", ${CJK_FALLBACK}`,
zhuque: `"EdgeEver Fangsong", ${CJK_FALLBACK}`,
@@ -33,6 +33,11 @@ const BUNDLED_FONT_STACKS: Record<Exclude<EditorBodyFontChoice, "system" | "cust
"source-serif": `"Source Serif 4", ${CJK_FALLBACK}`,
};
+export const getFontChoicePreviewStack = (choice: EditorBodyFontChoice): string | undefined => {
+ if (choice === "system" || choice === "custom") return undefined;
+ return BUNDLED_FONT_STACKS[choice];
+};
+
const CUSTOM_FONT_FAMILY_PATTERN = /^[\p{L}\p{N}\s,'"._-]+$/u;
const MAX_CUSTOM_FONT_FAMILY_LENGTH = 200;
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index b7b4b2b0..151f8ef9 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -759,7 +759,7 @@ export const enUS = {
start: "Align left",
},
editorBodyFontTitle: "Note text font",
- editorBodyFontDescription: "Changes note text on this device.",
+ editorBodyFontDescription: "Applies only to this device; shared and exported notes remain unchanged.",
editorBodyFonts: {
system: "System",
wenkai: "LXGW WenKai",
@@ -773,8 +773,9 @@ export const enUS = {
},
editorBodyFontCustomLabel: "Font name",
editorBodyFontCustomPlaceholder: "LXGW WenKai",
+ editorBodyFontSuggestions: "Common fonts",
uiFontTitle: "Interface font",
- uiFontDescription: "Changes interface text on this device.",
+ uiFontDescription: "Adjusts interface chrome on this device without altering note contents.",
editorThemes: {
default: "Native theme",
letter: "Warm Page",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index b516bf57..0727bf64 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -759,7 +759,7 @@ export const ja = {
start: "左揃え",
},
editorBodyFontTitle: "ノート本文のフォント",
- editorBodyFontDescription: "この端末のノート本文だけを変えます。",
+ editorBodyFontDescription: "この端末の本文表示のみに適用され、共有やエクスポートには影響しません。",
editorBodyFonts: {
system: "システム",
wenkai: "霞鹜文楷",
@@ -773,8 +773,9 @@ export const ja = {
},
editorBodyFontCustomLabel: "フォント名",
editorBodyFontCustomPlaceholder: "LXGW WenKai",
+ editorBodyFontSuggestions: "定番フォント",
uiFontTitle: "画面のフォント",
- uiFontDescription: "この端末の画面の文字だけを変えます。",
+ uiFontDescription: "この端末の操作画面フォントのみを変更し、ノート内容には影響しません。",
editorThemes: {
default: "標準テーマ",
letter: "あたたかな紙",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 595071b6..8dfd7887 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -759,7 +759,7 @@ export const zhCN = {
start: "靠左显示",
},
editorBodyFontTitle: "笔记正文字体",
- editorBodyFontDescription: "只改变本机的笔记正文。",
+ editorBodyFontDescription: "仅在当前设备生效,不影响公开分享与导出排版。",
editorBodyFonts: {
system: "跟随系统",
wenkai: "霞鹜文楷",
@@ -773,8 +773,9 @@ export const zhCN = {
},
editorBodyFontCustomLabel: "字体名称",
editorBodyFontCustomPlaceholder: "例如 LXGW WenKai",
+ editorBodyFontSuggestions: "常用字体推荐",
uiFontTitle: "界面字体",
- uiFontDescription: "只改变本机的界面文字。",
+ uiFontDescription: "仅调整当前设备的操作界面文字,不影响笔记内容。",
editorThemes: {
default: "原生主题",
letter: "日暖素笺",