Skip to content

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

Add mobile rich text editor webview

yoma4024f2917b5d
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index f1a6e2f0..df0571a7 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -31,7 +31,8 @@
"react-native-reanimated": "4.5.0",
"react-native-safe-area-context": "~5.7.0",
"react-native-screens": "latest",
- "react-native-svg": "15.15.4"
+ "react-native-svg": "15.15.4",
+ "react-native-webview": "13.16.1"
},
"devDependencies": {
"@types/react": "latest",
diff --git a/apps/mobile/src/screens/WorkspaceScreen.tsx b/apps/mobile/src/screens/WorkspaceScreen.tsx
index 574acc82..e6f6f5bf 100644
--- a/apps/mobile/src/screens/WorkspaceScreen.tsx
+++ b/apps/mobile/src/screens/WorkspaceScreen.tsx
@@ -64,6 +64,7 @@ import {
View,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
+import { WebView } from "react-native-webview";
import type { ApiToken, MemoDetail, MemoRevision, MemoSummary, Notebook, ResourceListItem, TagSummary } from "@edgeever/shared";
import { clearMobileMemoDraft, readMobileMemoDraft, writeMobileMemoDraft } from "../lib/mobile-drafts";
import {
@@ -199,6 +200,7 @@ export const WorkspaceScreen = () => {
const [createOpen, setCreateOpen] = useState(false);
const [templatesOpen, setTemplatesOpen] = useState(false);
const [editingMemo, setEditingMemo] = useState<MemoDetail | null>(null);
+ const [richEditingMemo, setRichEditingMemo] = useState<MemoDetail | null>(null);
const [notebookManagerOpen, setNotebookManagerOpen] = useState(false);
const [tagsManagerOpen, setTagsManagerOpen] = useState(false);
const [resourcesOpen, setResourcesOpen] = useState(false);
@@ -319,6 +321,15 @@ export const WorkspaceScreen = () => {
setSelectedMemoId(null);
};
+ const closeRichEditor = () => {
+ const memoId = richEditingMemo?.id ?? null;
+ setRichEditingMemo(null);
+ if (memoId) {
+ setSelectedMemoId(memoId);
+ }
+ void invalidateWorkspace();
+ };
+
const memoCount = notebooks.reduce((total, notebook) => total + notebook.memoCount, 0);
const memos = memosQuery.data?.memos ?? [];
const searchResults = searchQuery.data?.memos ?? [];
@@ -752,6 +763,7 @@ export const WorkspaceScreen = () => {
onClose={closeDetail}
onDelete={handleDeleteMemo}
onEdit={setEditingMemo}
+ onRichEdit={setRichEditingMemo}
onOpenResources={() => setResourcesOpen(true)}
onOpenRevisions={setRevisionMemo}
onRestore={(memo) => restoreMemoMutation.mutate(memo)}
@@ -775,6 +787,7 @@ export const WorkspaceScreen = () => {
}}
updateMutation={updateMemoMutation}
/>
+ <RichEditorModal baseUrl={session?.baseUrl ?? ""} memo={richEditingMemo} onClose={closeRichEditor} token={session?.token ?? ""} />
<NotebookManagerModal
notebookSortMode={notebookSortMode}
@@ -1202,7 +1215,7 @@ const SettingsView = ({
</View>
</View>
<SyncQueuePanel isSyncing={isSyncingQueue} message={syncQueueMessage} onOpen={onOpenSyncQueue} onSync={onSyncQueuedChanges} summary={syncQueueSummary} />
- <PanelRow label="富文本编辑器" value="待接入 WebView TipTap" />
+ <PanelRow label="富文本编辑器" value="已接入 PWA TipTap WebView" />
</ScrollView>
);
@@ -2757,6 +2770,7 @@ const MemoDetailModal = ({
onClose,
onDelete,
onEdit,
+ onRichEdit,
onOpenResources,
onOpenRevisions,
onRestore,
@@ -2771,6 +2785,7 @@ const MemoDetailModal = ({
onClose: () => void;
onDelete: (memo: MemoDetail) => void;
onEdit: (memo: MemoDetail) => void;
+ onRichEdit: (memo: MemoDetail) => void;
onOpenResources: () => void;
onOpenRevisions: (memo: MemoDetail) => void;
onRestore: (memo: MemoDetail) => void;
@@ -2813,6 +2828,9 @@ const MemoDetailModal = ({
<ActionButton label="编辑" onPress={() => onEdit(memo)}>
<Pencil color="#0f172a" size={16} />
</ActionButton>
+ <ActionButton label="富文本" onPress={() => onRichEdit(memo)}>
+ <Bold color="#0f172a" size={16} />
+ </ActionButton>
<ActionButton label="历史" onPress={() => onOpenRevisions(memo)}>
<History color="#0f172a" size={16} />
</ActionButton>
@@ -2845,6 +2863,87 @@ const MemoDetailModal = ({
</Modal>
);
+const RichEditorModal = ({
+ baseUrl,
+ memo,
+ onClose,
+ token,
+}: {
+ baseUrl: string;
+ memo: MemoDetail | null;
+ onClose: () => void;
+ token: string;
+}) => {
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(false);
+ const editorUrl = memo && baseUrl ? buildRichEditorUrl(baseUrl, memo.id) : "";
+ const injectedJavaScriptBeforeContentLoaded = buildRichEditorAuthScript(token);
+
+ useEffect(() => {
+ if (memo) {
+ setLoading(true);
+ setError(false);
+ }
+ }, [memo]);
+
+ return (
+ <Modal animationType="slide" onRequestClose={onClose} presentationStyle="fullScreen" visible={Boolean(memo)}>
+ <SafeAreaView style={styles.richEditorSafeArea}>
+ <View style={styles.modalHeader}>
+ <IconButton onPress={onClose}>
+ <X color="#0f172a" size={20} />
+ </IconButton>
+ <Text numberOfLines={1} style={styles.modalTitle}>
+ 富文本编辑器
+ </Text>
+ <IconButton onPress={() => editorUrl && Linking.openURL(editorUrl)}>
+ <ExternalLink color="#0f172a" size={18} />
+ </IconButton>
+ </View>
+
+ {editorUrl ? (
+ <View style={styles.richEditorContainer}>
+ {loading ? (
+ <View style={styles.richEditorLoading}>
+ <ActivityIndicator color="#0f172a" />
+ <Text style={styles.mutedText}>正在加载 TipTap 编辑器</Text>
+ </View>
+ ) : null}
+ {error ? (
+ <View style={styles.centerState}>
+ <Text style={styles.errorText}>富文本编辑器加载失败</Text>
+ <Text style={styles.mutedText}>请确认实例已部署最新版 Web/PWA 资源。</Text>
+ </View>
+ ) : (
+ <WebView
+ allowsBackForwardNavigationGestures
+ injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded}
+ onError={() => {
+ setLoading(false);
+ setError(true);
+ }}
+ onLoadEnd={() => setLoading(false)}
+ onNavigationStateChange={(state) => {
+ if (state.url && !state.url.includes("/mobile-edit.html") && !state.url.startsWith("about:")) {
+ onClose();
+ }
+ }}
+ originWhitelist={["http://*", "https://*"]}
+ source={{ uri: editorUrl }}
+ style={styles.richEditorWebView}
+ />
+ )}
+ </View>
+ ) : (
+ <View style={styles.centerState}>
+ <Text style={styles.errorText}>缺少实例地址,无法打开富文本编辑器</Text>
+ </View>
+ )}
+ </SafeAreaView>
+ </Modal>
+ );
+};
+
const EditMemoModal = ({
imageCompressionEnabled,
memo,
@@ -3863,6 +3962,57 @@ const formatRevisionActor = (actor: string) => {
return actor || "system";
};
+const buildRichEditorUrl = (baseUrl: string, memoId: string) => {
+ const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
+ const params = new URLSearchParams({
+ memoId,
+ returnTo: "/",
+ });
+
+ return `${normalizedBaseUrl}/mobile-edit.html#${params.toString()}`;
+};
+
+const buildRichEditorAuthScript = (token: string) => `
+(() => {
+ const token = ${JSON.stringify(token)};
+ if (!token) {
+ return true;
+ }
+
+ const applyAuthHeader = (headers) => {
+ const nextHeaders = new Headers(headers || {});
+ if (!nextHeaders.has("Authorization")) {
+ nextHeaders.set("Authorization", "Bearer " + token);
+ }
+ return nextHeaders;
+ };
+
+ const shouldAuthorize = (input) => {
+ const url = typeof input === "string" ? input : input && "url" in input ? input.url : "";
+ if (!url) {
+ return true;
+ }
+ return url.startsWith("/api/") || url.includes("/api/");
+ };
+
+ const originalFetch = window.fetch.bind(window);
+ window.fetch = (input, init = {}) => {
+ if (!shouldAuthorize(input)) {
+ return originalFetch(input, init);
+ }
+
+ if (input instanceof Request) {
+ const headers = applyAuthHeader(init.headers || input.headers);
+ return originalFetch(new Request(input, { ...init, headers }));
+ }
+
+ return originalFetch(input, { ...init, headers: applyAuthHeader(init.headers) });
+ };
+
+ true;
+})();
+`;
+
const getSyncQueueStatusLabel = (status: MobileSyncQueueItem["status"]) => {
const labels: Record<MobileSyncQueueItem["status"], string> = {
pending: "待同步",
@@ -4355,6 +4505,30 @@ const styles = StyleSheet.create({
backgroundColor: "#f8fafc",
flex: 1,
},
+ richEditorSafeArea: {
+ backgroundColor: "#ffffff",
+ flex: 1,
+ },
+ richEditorContainer: {
+ backgroundColor: "#ffffff",
+ flex: 1,
+ },
+ richEditorLoading: {
+ alignItems: "center",
+ backgroundColor: "#ffffff",
+ bottom: 0,
+ gap: 10,
+ justifyContent: "center",
+ left: 0,
+ position: "absolute",
+ right: 0,
+ top: 0,
+ zIndex: 2,
+ },
+ richEditorWebView: {
+ backgroundColor: "#ffffff",
+ flex: 1,
+ },
modalHeader: {
alignItems: "center",
borderBottomColor: "#e2e8f0",
diff --git a/bun.lock b/bun.lock
index eb75b54a..cb0be390 100644
--- a/bun.lock
+++ b/bun.lock
@@ -91,6 +91,7 @@
"react-native-safe-area-context": "~5.7.0",
"react-native-screens": "latest",
"react-native-svg": "15.15.4",
+ "react-native-webview": "13.16.1",
},
"devDependencies": {
"@types/react": "latest",
@@ -2427,6 +2428,8 @@
"react-native-svg": ["[email protected]", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-boT/vIRgj6zZKBpfTPJJiYWMbZE9duBMOwPK6kCSTgxsS947IFMOq9OgIFkpWZTB7t229H24pDRkh3W9ZK/J1A=="],
+ "react-native-webview": ["[email protected]", "", { "dependencies": { "escape-string-regexp": "^4.0.0", "invariant": "2.2.4" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-If0eHhoEdOYDcHsX+xBFwHMbWBGK1BvGDQDQdVkwtSIXiq1uiqjkpWVP2uQ1as94J0CzvFE9PUNDuhiX0Z6ubw=="],
+
"react-native-worklets": ["[email protected]", "", { "dependencies": { "@babel/plugin-transform-arrow-functions": "^7.27.1", "@babel/plugin-transform-class-properties": "^7.28.6", "@babel/plugin-transform-classes": "^7.28.6", "@babel/plugin-transform-nullish-coalescing-operator": "^7.28.6", "@babel/plugin-transform-optional-chaining": "^7.28.6", "@babel/plugin-transform-shorthand-properties": "^7.27.1", "@babel/plugin-transform-template-literals": "^7.27.1", "@babel/plugin-transform-unicode-regex": "^7.27.1", "@babel/preset-typescript": "^7.28.5", "@babel/types": "^7.27.1", "convert-source-map": "^2.0.0", "semver": "^7.7.4" }, "peerDependencies": { "@babel/core": "*", "@react-native/metro-config": "*", "react": "*", "react-native": "0.83 - 0.86" } }, "sha512-LX27ejYI8veeDp59Z3rjo2pYyPa9euzSH8GUlem7cnNqfsDtGum8PQpkbzrqhLsWH0CjdeHR7p3sncCyYbwaVw=="],
"react-refresh": ["[email protected]", "", {}, "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA=="],