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
feat(mobile): add collapsed font selector with preview list
tianma-ifd4d3df562c0a
diff --git a/apps/mobile/src/components/MobileNoteImageFontPicker.tsx b/apps/mobile/src/components/MobileNoteImageFontPicker.tsxnew file mode 100644index 00000000..8dfe5b80--- /dev/null+++ b/apps/mobile/src/components/MobileNoteImageFontPicker.tsx@@ -0,0 +1,102 @@+'use dom';++import { useEffect, useRef, useState } from "react";+import type { DOMProps } from "expo/dom";+import { isRemoteNoteImageFont } from "@edgeever/shared/font-catalog";+import { resolveNoteImageTypography, type NoteImageFontStyle, type NoteImageTheme } from "@edgeever/shared/note-image-card";+import { prepareNoteImageAssets } from "@edgeever/shared/note-image-fonts";+import { MOBILE_FONT_OPTIONS } from "../lib/note-image-font-options";+import { noteImageAssetUrls } from "./note-image-asset-urls";++type Props = {+ selected: NoteImageFontStyle;+ theme: NoteImageTheme;+ chinese: boolean;+ onSelect: (font: NoteImageFontStyle) => Promise<void>;+ dom?: DOMProps;+};++// Latin-only fonts need Latin characters to make their appearance comparable.+const LATIN_FONTS = new Set(["anton", "inter", "dmserif", "bebas", "spacegrotesk", "jetbrains", "mono"]);++export default function MobileNoteImageFontPicker({ selected, theme, chinese, onSelect }: Props) {+ const listRef = useRef<HTMLDivElement>(null);+ const selectingRef = useRef(false);+ const [previews, setPreviews] = useState<Record<string, "ready" | "error">>({});+ const sampleFor = (id: string) => chinese && !LATIN_FONTS.has(id) ? "记录此刻的灵感" : "Capture a little inspiration";++ useEffect(() => {+ const list = listRef.current;+ if (!list) return;+ let active = true;+ setPreviews({});+ list.querySelector('[aria-checked="true"]')?.scrollIntoView({ block: "center" });+ const observer = new IntersectionObserver((entries) => {+ for (const entry of entries) {+ if (!entry.isIntersecting) continue;+ observer.unobserve(entry.target);+ const id = entry.target.getAttribute("data-font") as NoteImageFontStyle;+ const text = chinese && !LATIN_FONTS.has(id) ? "记录此刻的灵感" : "Capture a little inspiration";+ void prepareNoteImageAssets({ theme, fontStyle: id, text, urls: noteImageAssetUrls, embed: false })+ .then(() => { if (active) setPreviews(previous => ({ ...previous, [id]: "ready" })); })+ .catch(() => { if (active) setPreviews(previous => ({ ...previous, [id]: "error" })); });+ }+ }, { root: list });+ list.querySelectorAll("[data-font]").forEach(node => observer.observe(node));+ return () => { active = false; observer.disconnect(); };+ // The selection is fixed during this panel's lifetime; selecting closes it.+ }, [theme, chinese, selected]);++ return (+ <>+ <style>{`+ html, body, #root { margin: 0; height: 100%; background: #fff; }+ * { box-sizing: border-box; }+ .font-list { height: 100dvh; overflow-y: auto; overscroll-behavior: contain; font-family: system-ui, sans-serif; padding: 0 0 12px; }+ .font-option { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 88px; padding: 14px 12px; border: 0; border-bottom: 1px solid #e2e8f0; background: #fff; text-align: left; color: #0f172a; }+ .font-option[aria-checked="true"] { background: #ecfdf5; }+ .font-option:focus-visible { outline: 2px solid #16a06e; outline-offset: -2px; }+ .font-option-copy { min-width: 0; }+ .font-name { display: block; font: 600 14px/1.5 system-ui, sans-serif; }+ .font-sample { display: block; margin-top: 6px; font-size: 20px; line-height: 1.5; overflow-wrap: anywhere; }+ .font-status { display: block; margin-top: 6px; color: #64748b; font: 13px/1.5 system-ui, sans-serif; }+ .font-check { flex: 0 0 24px; color: #16a06e; font: 700 24px/1 system-ui, sans-serif; }+ `}</style>+ <div className="font-list" role="radiogroup" aria-label={chinese ? "字体风格" : "Typography"} ref={listRef}>+ {MOBILE_FONT_OPTIONS.map(item => {+ const loaded = previews[item.id] === "ready";+ const failed = previews[item.id] === "error";+ const needsFont = item.id === "auto" || isRemoteNoteImageFont(item.id);+ return (+ <button+ key={item.id}+ type="button"+ role="radio"+ aria-checked={selected === item.id}+ aria-label={chinese ? item.labelZh : item.labelEn}+ className="font-option"+ data-font={item.id}+ onClick={async () => {+ if (selectingRef.current) return;+ selectingRef.current = true;+ try { await onSelect(item.id); } finally { selectingRef.current = false; }+ }}+ >+ <span className="font-option-copy">+ <span className="font-name">{chinese ? item.labelZh : item.labelEn}</span>+ {loaded || !needsFont ? (+ <span className="font-sample" style={{ fontFamily: resolveNoteImageTypography(theme, item.id).bodyFamily }}>{sampleFor(item.id)}</span>+ ) : (+ <span className="font-status">{failed+ ? (chinese ? "示例暂不可用,仍可选择" : "Preview unavailable; you can still select this font")+ : (chinese ? "正在加载示例…" : "Loading preview…")}</span>+ )}+ </span>+ <span className="font-check" aria-hidden="true">{selected === item.id ? "✓" : ""}</span>+ </button>+ );+ })}+ </div>+ </>+ );+}diff --git a/apps/mobile/src/lib/note-image-font-options.ts b/apps/mobile/src/lib/note-image-font-options.tsnew file mode 100644index 00000000..07e5c28d--- /dev/null+++ b/apps/mobile/src/lib/note-image-font-options.ts@@ -0,0 +1,11 @@+import { FONT_CATALOG, FONT_IDS } from "@edgeever/shared/font-catalog";+import type { NoteImageFontStyle } from "@edgeever/shared/note-image-card";++export const MOBILE_FONT_OPTIONS: Array<{ id: NoteImageFontStyle; labelZh: string; labelEn: string }> = [+ { id: "auto", labelZh: "跟随主题", labelEn: "Follow Theme" },+ { id: "kai", labelZh: "文楷手书", labelEn: "Handwritten Kai" },+ { id: "serif", labelZh: "文艺衬线", labelEn: "Serif" },+ { id: "sans", labelZh: "现代无衬线", labelEn: "Sans" },+ { id: "mono", labelZh: "极客等宽", labelEn: "Mono" },+ ...FONT_IDS.map(id => ({ id, labelZh: FONT_CATALOG[id].zh, labelEn: FONT_CATALOG[id].en })),+];diff --git a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx b/apps/mobile/src/screens/WorkspaceMemoDetail.tsxindex 386dcf0d..a283ae35 100644--- a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx+++ b/apps/mobile/src/screens/WorkspaceMemoDetail.tsx@@ -1,4 +1,3 @@-import { FONT_CATALOG, FONT_IDS } from "@edgeever/shared/font-catalog";import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";import { DEFAULT_MEMO_TITLE, parseDiagramDocument, type MemoDetail, type Notebook, type TiptapDoc } from "@edgeever/shared";import {@@ -22,6 +21,8 @@ import { ActivityIndicator, ChevronDown, ChevronLeft, ChevronUp, Copy, Download,import { Alert, Pressable, Text, TextInput } from "../components/LocalizedText";import LocalTiptapEditor, { type LocalTiptapEditorRef } from "../components/LocalTiptapEditor";import { MobileAiAssistantModal } from "../components/MobileAiAssistantModal";+import MobileNoteImageFontPicker from "../components/MobileNoteImageFontPicker";+import { MOBILE_FONT_OPTIONS } from "../lib/note-image-font-options";import { MobileResourceActions } from "../components/MobileResourceActions";import { ZoomableImagePreview } from "../components/ZoomableImagePreview";import type { ImageSize } from "../lib/mobile-image-zoom";@@ -234,14 +235,7 @@ const MOBILE_THEME_OPTIONS = NOTE_IMAGE_THEME_OPTIONS.map((id) => ({id, ...MOBILE_THEME_LABELS[id], previewBg: NOTE_IMAGE_BACKGROUND_COLORS[id],}));-const MOBILE_FONT_OPTIONS: Array<{ id: NoteImageFontStyle; labelZh: string; labelEn: string }> = [- { id: "auto", labelZh: "跟随主题", labelEn: "Follow Theme" },- { id: "kai", labelZh: "文楷手书", labelEn: "Handwritten Kai" },- { id: "serif", labelZh: "文艺衬线", labelEn: "Serif" },- { id: "sans", labelZh: "现代无衬线", labelEn: "Sans" },- { id: "mono", labelZh: "极客等宽", labelEn: "Mono" },- ...FONT_IDS.map(id => ({ id, labelZh: FONT_CATALOG[id].zh, labelEn: FONT_CATALOG[id].en })),-];+const AuthenticatedResourceImage = ({alt,@@ -526,6 +520,7 @@ export const MemoDetailModal = ({const [isExportingImage, setIsExportingImage] = useState(false);const [imageExportStage, setImageExportStage] = useState<"prepare" | "render" | "transfer">("prepare");const [imageShareOptionsOpen, setImageShareOptionsOpen] = useState(false);+ const [imageShareFontPickerOpen, setImageShareFontPickerOpen] = useState(false);const { preferences: imageSharePreferences, ready: imageSharePreferencesReady, setPreference: setImageSharePreference } = useMobileNoteImagePreferences();const {format: imageShareFormat, theme: imageShareTheme, fontStyle: imageShareFontStyle,@@ -740,7 +735,10 @@ export const MemoDetailModal = ({}, []);useEffect(() => {- if (!visible) setTitleCollapsed(false);+ if (!visible) {+ setTitleCollapsed(false);+ setImageShareFontPickerOpen(false);+ }}, [visible]);useEffect(() => {@@ -754,6 +752,7 @@ export const MemoDetailModal = ({}, [imageShareFromList, memo, viewerReady, visible]);const closeImageShareOptions = () => {+ setImageShareFontPickerOpen(false);setImageShareOptionsOpen(false);if (imageShareFromList) onClose();};@@ -1565,7 +1564,7 @@ export const MemoDetailModal = ({</Pressable></Modal>) : null}- <Modal animationType="fade" onRequestClose={preparedNoteImage ? closeImagePreview : closeImageShareOptions} transparent visible={!imageSavePickerOpen && (imageShareOptionsOpen || Boolean(preparedNoteImage))}>+ <Modal animationType="fade" onRequestClose={preparedNoteImage ? closeImagePreview : imageShareFontPickerOpen ? () => setImageShareFontPickerOpen(false) : closeImageShareOptions} transparent visible={!imageSavePickerOpen && (imageShareOptionsOpen || Boolean(preparedNoteImage))}>{preparedNoteImage ? (<SafeAreaView style={imageShareStyles.previewSafeArea}><View style={imageShareStyles.previewHeader}>@@ -1621,7 +1620,7 @@ export const MemoDetailModal = ({</SafeAreaView>) : (<Pressable- onPress={closeImageShareOptions}+ onPress={imageShareFontPickerOpen ? () => setImageShareFontPickerOpen(false) : closeImageShareOptions}style={[styles.actionSheetBackdrop,{ paddingBottom: Math.max(safeAreaInsets.bottom, Platform.OS === "android" ? ANDROID_SYSTEM_NAVIGATION_FALLBACK : 0) },@@ -1629,6 +1628,27 @@ export const MemoDetailModal = ({><Pressable style={[styles.actionSheet, imageShareStyles.sheetContainer]}><View style={styles.actionSheetHandle} />+ {imageShareFontPickerOpen ? (+ <View style={imageShareStyles.fontPicker}>+ <View style={imageShareStyles.fontPickerHeader}>+ <Pressable accessibilityRole="button" accessibilityLabel={resolvedLocale === "zh-CN" ? "返回分享设置" : "Back to share settings"} onPress={() => setImageShareFontPickerOpen(false)} style={imageShareStyles.previewCloseButton}>+ <ChevronLeft color="#0f172a" size={22} />+ </Pressable>+ <Text style={imageShareStyles.previewTitle}>{resolvedLocale === "zh-CN" ? "字体风格" : "Typography"}</Text>+ </View>+ <MobileNoteImageFontPicker+ selected={imageShareFontStyle}+ theme={imageShareTheme}+ chinese={resolvedLocale === "zh-CN"}+ onSelect={async (font) => {+ setImageSharePreference("fontStyle", font);+ setImageShareFontPickerOpen(false);+ }}+ dom={{ ...SAFE_DOM_WEBVIEW_PROPS, scrollEnabled: false, style: { flex: 1 } }}+ />+ </View>+ ) : null}+ <View style={[imageShareStyles.settingsContent, imageShareFontPickerOpen && imageShareStyles.hidden]}><Text style={styles.actionSheetTitle}>{resolvedLocale !== "zh-CN" ? "Share as image" : "分享为图片"}</Text><ScrollView contentContainerStyle={imageShareStyles.optionsContent} showsVerticalScrollIndicator={false} style={imageShareStyles.optionsScroll}>@@ -1689,28 +1709,19 @@ export const MemoDetailModal = ({))}</View>- <Text style={styles.actionSheetSectionTitle}>{resolvedLocale !== "zh-CN" ? "Typography" : "字体风格"}</Text>- <View style={imageShareStyles.fontGrid}>- {MOBILE_FONT_OPTIONS.map((item) => {- const isSelected = imageShareFontStyle === item.id;- const label = resolvedLocale !== "zh-CN" ? item.labelEn : item.labelZh;- return (- <Pressable- key={item.id}- accessibilityRole="button"- accessibilityState={{ selected: isSelected }}- onPress={() => setImageSharePreference("fontStyle", item.id)}- style={[- imageShareStyles.choice,- imageShareStyles.fontChoice,- isSelected && imageShareStyles.choiceActive,- ]}- >- <Text style={[imageShareStyles.choiceText, isSelected && imageShareStyles.choiceTextActive]}>{label}</Text>- </Pressable>- );- })}- </View>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`${resolvedLocale === "zh-CN" ? "字体风格" : "Typography"}: ${MOBILE_FONT_OPTIONS.find(item => item.id === imageShareFontStyle)?.[resolvedLocale === "zh-CN" ? "labelZh" : "labelEn"] ?? ""}`}+ accessibilityHint={resolvedLocale === "zh-CN" ? "打开字体选择列表" : "Open font selection"}+ onPress={() => setImageShareFontPickerOpen(true)}+ style={imageShareStyles.fontSelector}+ >+ <Text style={imageShareStyles.optionLabel}>{resolvedLocale === "zh-CN" ? "字体风格" : "Typography"}</Text>+ <Text style={imageShareStyles.fontSelectorValue}>+ {MOBILE_FONT_OPTIONS.find(item => item.id === imageShareFontStyle)?.[resolvedLocale === "zh-CN" ? "labelZh" : "labelEn"]}+ </Text>+ <ChevronDown color="#64748b" size={18} />+ </Pressable><Text style={imageShareStyles.choiceText}>{resolvedLocale === "zh-CN"? "下载型字体首次使用需联网,下载后缓存;普惠体等推荐字体保留完整文件,首次下载较大。"@@ -1778,6 +1789,7 @@ export const MemoDetailModal = ({</Text></Pressable></View>+ </View></Pressable></Pressable>)}@@ -2005,17 +2017,40 @@ const imageShareStyles = StyleSheet.create({flexDirection: "row",gap: 8,},- fontGrid: {+ settingsContent: {+ flex: 1,+ },+ hidden: {+ display: "none",+ },+ fontPicker: {+ flex: 1,+ },+ fontPickerHeader: {flexDirection: "row",- flexWrap: "wrap",+ alignItems: "center",gap: 8,+ paddingBottom: 12,},- fontChoice: {- flex: 0,- flexBasis: "47%",- flexGrow: 1,- minWidth: 120,+ fontSelector: {+ flexDirection: "row",+ alignItems: "center",+ gap: 12,+ minHeight: 52,+ marginTop: 16,+ marginBottom: 8,+ paddingHorizontal: 12,paddingVertical: 10,+ borderWidth: 1,+ borderColor: "#cbd5e1",+ borderRadius: 8,+ backgroundColor: "#f8fafc",+ },+ fontSelectorValue: {+ color: "#64748b",+ fontSize: 14,+ flexShrink: 1,+ textAlign: "right",},choiceText: {color: "#64748b",