Skip to content

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

Add minimal mobile editor toolbar

yoma8936a3493e15
diff --git a/apps/web/src/mobile-edit.tsx b/apps/web/src/mobile-edit.tsx
index 22dd60f8..9e36087b 100644
--- a/apps/web/src/mobile-edit.tsx
+++ b/apps/web/src/mobile-edit.tsx
@@ -4,7 +4,7 @@ import { EditorContent, useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import Image from "@tiptap/extension-image";
import Placeholder from "@tiptap/extension-placeholder";
-import { ImagePlus } from "lucide-react";
+import { Bold, ImagePlus, List, Minus, Quote } from "lucide-react";
import { docToMarkdown, emptyDoc, markdownToDoc, type MemoDetail, type Notebook, type Resource, type TiptapDoc } from "@edgeever/shared";
import { getNotebookMoveOptions } from "@/lib/app-helpers";
import { compressImageForUpload } from "@/lib/image-compression";
@@ -113,6 +113,7 @@ const MobileTiptapEditorApp = () => {
const saveStateRef = useRef<SaveState>("loading");
const [error, setError] = useState<string | null>(null);
const notebookOptions = useMemo(() => getNotebookMoveOptions(notebooks), [notebooks]);
+ const [, setToolbarVersion] = useState(0);
const dirtyRef = useRef(false);
const leavingRef = useRef(false);
const savingRef = useRef(false);
@@ -211,6 +212,26 @@ const MobileTiptapEditorApp = () => {
const saveNowRef = useRef<({ keepalive }?: { keepalive?: boolean }) => Promise<boolean>>(async () => false);
+ useEffect(() => {
+ if (!editor) {
+ return;
+ }
+
+ const refreshToolbar = () => setToolbarVersion((version) => version + 1);
+
+ editor.on("selectionUpdate", refreshToolbar);
+ editor.on("transaction", refreshToolbar);
+ editor.on("focus", refreshToolbar);
+ editor.on("blur", refreshToolbar);
+
+ return () => {
+ editor.off("selectionUpdate", refreshToolbar);
+ editor.off("transaction", refreshToolbar);
+ editor.off("focus", refreshToolbar);
+ editor.off("blur", refreshToolbar);
+ };
+ }, [editor]);
+
useEffect(() => {
memoRef.current = memo;
}, [memo]);
@@ -601,9 +622,20 @@ const MobileTiptapEditorApp = () => {
: saveState === "dirty" || saveState === "saving" || saveState === "compressing" || saveState === "uploading" || saveState === "leaving"
? "active"
: "";
+ const editorActionDisabled =
+ !memo || !editor || saveState === "loading" || saveState === "compressing" || saveState === "uploading" || saveState === "leaving";
const fallbackMarkdown = memo ? docToMarkdown(contentJsonRef.current) : "";
+ const runEditorCommand = (command: () => boolean) => {
+ if (editorActionDisabled || !editor) {
+ return;
+ }
+
+ command();
+ editor.commands.focus();
+ };
+
return (
<div className="mobile-editor-shell">
<header className="mobile-editor-header">
@@ -660,14 +692,63 @@ const MobileTiptapEditorApp = () => {
<div className="mobile-editor-tool-row">
<button
+ className="mobile-editor-tool-button"
type="button"
aria-label="上传图片"
title="上传图片"
- disabled={!memo || saveState === "loading" || saveState === "compressing" || saveState === "uploading"}
+ disabled={editorActionDisabled}
+ onPointerDown={(event) => event.preventDefault()}
onClick={() => imageInputRef.current?.click()}
>
<ImagePlus aria-hidden="true" size={18} strokeWidth={2} />
</button>
+ <button
+ className="mobile-editor-tool-button"
+ type="button"
+ aria-label="加粗"
+ title="加粗"
+ aria-pressed={Boolean(editor?.isActive("bold"))}
+ disabled={editorActionDisabled}
+ onPointerDown={(event) => event.preventDefault()}
+ onClick={() => runEditorCommand(() => editor?.chain().focus().toggleBold().run() ?? false)}
+ >
+ <Bold aria-hidden="true" size={17} strokeWidth={2.4} />
+ </button>
+ <button
+ className="mobile-editor-tool-button"
+ type="button"
+ aria-label="无序列表"
+ title="无序列表"
+ aria-pressed={Boolean(editor?.isActive("bulletList"))}
+ disabled={editorActionDisabled}
+ onPointerDown={(event) => event.preventDefault()}
+ onClick={() => runEditorCommand(() => editor?.chain().focus().toggleBulletList().run() ?? false)}
+ >
+ <List aria-hidden="true" size={18} strokeWidth={2.2} />
+ </button>
+ <button
+ className="mobile-editor-tool-button"
+ type="button"
+ aria-label="引用"
+ title="引用"
+ aria-pressed={Boolean(editor?.isActive("blockquote"))}
+ disabled={editorActionDisabled}
+ onPointerDown={(event) => event.preventDefault()}
+ onClick={() => runEditorCommand(() => editor?.chain().focus().toggleBlockquote().run() ?? false)}
+ >
+ <Quote aria-hidden="true" size={17} strokeWidth={2.2} />
+ </button>
+ <button
+ className="mobile-editor-tool-button"
+ type="button"
+ aria-label="分割线"
+ title="分割线"
+ disabled={editorActionDisabled}
+ onPointerDown={(event) => event.preventDefault()}
+ onClick={() => runEditorCommand(() => editor?.chain().focus().setHorizontalRule().run() ?? false)}
+ >
+ <Minus aria-hidden="true" size={18} strokeWidth={2.4} />
+ </button>
</div>
<input
ref={imageInputRef}
diff --git a/apps/web/src/styles/mobile-markdown-editor.css b/apps/web/src/styles/mobile-markdown-editor.css
index ec69b6d1..52ad22ff 100644
--- a/apps/web/src/styles/mobile-markdown-editor.css
+++ b/apps/web/src/styles/mobile-markdown-editor.css
@@ -50,7 +50,7 @@ select {
.mobile-editor-back,
.mobile-editor-done,
-.mobile-editor-tool-row button {
+.mobile-editor-tool-button {
border: 0;
border-radius: 999px;
background: transparent;
@@ -82,7 +82,7 @@ select {
}
.mobile-editor-done:disabled,
-.mobile-editor-tool-row button:disabled {
+.mobile-editor-tool-button:disabled {
background: #e2e8f0;
color: #64748b;
}
@@ -181,31 +181,51 @@ select {
.mobile-editor-tool-row {
display: flex;
align-items: center;
- gap: 8px;
- min-height: 34px;
+ gap: 4px;
+ min-height: 38px;
+ overflow-x: auto;
+ border-block: 1px solid #f1f5f9;
+ margin-inline: -12px;
+ padding: 6px 12px;
+ scrollbar-width: none;
}
-.mobile-editor-tool-row button {
+.mobile-editor-tool-row::-webkit-scrollbar {
+ display: none;
+}
+
+.mobile-editor-tool-button {
display: inline-flex;
align-items: center;
justify-content: center;
- border: 1px solid #e2e8f0;
- background: #f8fafc;
+ flex: 0 0 auto;
+ border: 1px solid transparent;
+ background: transparent;
color: #64748b;
- min-height: 34px;
- width: 34px;
+ min-height: 32px;
+ width: 36px;
padding: 0;
}
-.mobile-editor-tool-row button:active {
- background: #eef2f7;
+.mobile-editor-tool-button:active,
+.mobile-editor-tool-button[aria-pressed="true"] {
+ background: #ecfdf5;
+ border-color: #bbf7d0;
+ color: #047857;
+}
+
+.mobile-editor-tool-button:disabled {
+ border-color: transparent;
+}
+
+.mobile-editor-tool-button:disabled:active {
+ background: #e2e8f0;
color: #334155;
}
.edgeever-mobile-tiptap-editor {
min-height: calc(100dvh - 14rem);
- border-top: 1px solid #f1f5f9;
- margin: 4px -12px 0;
+ margin: 0 -12px;
}
.edgeever-mobile-tiptap-content {
@@ -245,6 +265,12 @@ select {
padding-left: 0.9em;
}
+.edgeever-mobile-tiptap-content hr {
+ border: 0;
+ border-top: 1px solid #e2e8f0;
+ margin: 1.2rem 0;
+}
+
.edgeever-mobile-tiptap-content img {
height: auto;
max-width: 100%;