Revert "Use Tiptap mobile editor inside workspace"
This reverts commit b48b0c68d6.
This commit is contained in:
1 parent
b48b0c68d6
commit
f11e370c0d
4 files changed
+20
-25
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { lazy, Suspense, useRef, useState, useEffect, useCallback, useMemo, type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
|
import { useRef, useState, useEffect, useCallback, useMemo, type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
|
||||||
import { useQueryClient, useMutation } from "@tanstack/react-query";
|
import { useQueryClient, useMutation } from "@tanstack/react-query";
|
||||||
import { NodeViewWrapper, ReactNodeViewRenderer, useEditor, EditorContent, type Editor, type NodeViewProps } from "@tiptap/react";
|
import { NodeViewWrapper, ReactNodeViewRenderer, useEditor, EditorContent, type Editor, type NodeViewProps } from "@tiptap/react";
|
||||||
import StarterKit from "@tiptap/starter-kit";
|
import StarterKit from "@tiptap/starter-kit";
|
||||||
@@ -50,6 +50,7 @@ import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@
|
|||||||
import { EditorToolbar } from "./EditorToolbar";
|
import { EditorToolbar } from "./EditorToolbar";
|
||||||
import { RevisionHistoryDialog } from "./dialogs/RevisionHistoryDialog";
|
import { RevisionHistoryDialog } from "./dialogs/RevisionHistoryDialog";
|
||||||
import { api } from "@/lib/api";
|
import { api } from "@/lib/api";
|
||||||
|
import { openStandaloneMobileEditor } from "@/lib/mobile-editor";
|
||||||
import { cn, formatDateTime, parseTagsText } from "@/lib/utils";
|
import { cn, formatDateTime, parseTagsText } from "@/lib/utils";
|
||||||
import { docToMarkdown, markdownToDoc, type Notebook, type MemoDetail, type TiptapDoc } from "@edgeever/shared";
|
import { docToMarkdown, markdownToDoc, type Notebook, type MemoDetail, type TiptapDoc } from "@edgeever/shared";
|
||||||
import { compressImageForUpload } from "@/lib/image-compression";
|
import { compressImageForUpload } from "@/lib/image-compression";
|
||||||
@@ -69,10 +70,6 @@ const MIN_IMAGE_WIDTH_PERCENT = 25;
|
|||||||
const MAX_IMAGE_WIDTH_PERCENT = 100;
|
const MAX_IMAGE_WIDTH_PERCENT = 100;
|
||||||
const IMAGE_WIDTH_PRESETS = [35, 50, 72, 100];
|
const IMAGE_WIDTH_PRESETS = [35, 50, 72, 100];
|
||||||
|
|
||||||
const MobileStandaloneTiptapEditor = lazy(() =>
|
|
||||||
import("./MobileStandaloneTiptapEditor").then((module) => ({ default: module.MobileStandaloneTiptapEditor }))
|
|
||||||
);
|
|
||||||
|
|
||||||
type NoteSearchMatch = {
|
type NoteSearchMatch = {
|
||||||
from: number;
|
from: number;
|
||||||
to: number;
|
to: number;
|
||||||
@@ -949,6 +946,12 @@ export const EditorPane = (props: EditorPaneProps) => {
|
|||||||
(mobileDefaultEditRequested || mobileNativeEditMemoId === props.memo.id)
|
(mobileDefaultEditRequested || mobileNativeEditMemoId === props.memo.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isMobileViewport && mobileDefaultEditRequested && props.memo?.id) {
|
||||||
|
openStandaloneMobileEditor(props.memo.id);
|
||||||
|
}
|
||||||
|
}, [isMobileViewport, mobileDefaultEditRequested, props.memo?.id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const mediaQuery = window.matchMedia(MOBILE_EDITOR_QUERY);
|
const mediaQuery = window.matchMedia(MOBILE_EDITOR_QUERY);
|
||||||
const updateMobileViewport = () => setIsMobileViewport(mediaQuery.matches);
|
const updateMobileViewport = () => setIsMobileViewport(mediaQuery.matches);
|
||||||
@@ -963,21 +966,11 @@ export const EditorPane = (props: EditorPaneProps) => {
|
|||||||
setMobileNativeEditMemoId(null);
|
setMobileNativeEditMemoId(null);
|
||||||
}, [props.memo?.id]);
|
}, [props.memo?.id]);
|
||||||
|
|
||||||
if (mobileNativeEditingActive && props.memo) {
|
if (mobileNativeEditingActive) {
|
||||||
const activeMemoId = props.memo.id;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<div className="flex h-full min-h-0 items-center justify-center bg-white text-sm font-medium text-slate-400">加载编辑器</div>}>
|
<div className="flex h-full min-h-0 items-center justify-center bg-white text-sm font-medium text-slate-400">
|
||||||
<MobileStandaloneTiptapEditor
|
打开编辑器
|
||||||
memoId={activeMemoId}
|
</div>
|
||||||
onSaved={props.onSaved}
|
|
||||||
onLeave={() => {
|
|
||||||
props.onMobileDefaultEditConsumed();
|
|
||||||
setMobileNativeEditMemoId(null);
|
|
||||||
props.onBackToList();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,6 +981,7 @@ export const EditorPane = (props: EditorPaneProps) => {
|
|||||||
onRequestMobileNativeEdit={() => {
|
onRequestMobileNativeEdit={() => {
|
||||||
if (props.memo?.id && !readOnly) {
|
if (props.memo?.id && !readOnly) {
|
||||||
setMobileNativeEditMemoId(props.memo.id);
|
setMobileNativeEditMemoId(props.memo.id);
|
||||||
|
openStandaloneMobileEditor(props.memo.id);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import StarterKit from "@tiptap/starter-kit";
|
|||||||
import Image from "@tiptap/extension-image";
|
import Image from "@tiptap/extension-image";
|
||||||
import Placeholder from "@tiptap/extension-placeholder";
|
import Placeholder from "@tiptap/extension-placeholder";
|
||||||
import { docToMarkdown, emptyDoc, type MemoDetail, type Notebook, type TiptapDoc } from "@edgeever/shared";
|
import { docToMarkdown, emptyDoc, type MemoDetail, type Notebook, type TiptapDoc } from "@edgeever/shared";
|
||||||
import "@/styles/mobile-markdown-editor.css";
|
|
||||||
import {
|
import {
|
||||||
MobileEditorFallback,
|
MobileEditorFallback,
|
||||||
MobileEditorHeader,
|
MobileEditorHeader,
|
||||||
@@ -41,14 +40,12 @@ type MobileStandaloneTiptapEditorProps = {
|
|||||||
memoId?: string | null;
|
memoId?: string | null;
|
||||||
returnTo?: string;
|
returnTo?: string;
|
||||||
onLeave?: () => void;
|
onLeave?: () => void;
|
||||||
onSaved?: (memo: MemoDetail) => void | Promise<void>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MobileStandaloneTiptapEditor = ({
|
export const MobileStandaloneTiptapEditor = ({
|
||||||
memoId: memoIdProp,
|
memoId: memoIdProp,
|
||||||
returnTo: returnToProp,
|
returnTo: returnToProp,
|
||||||
onLeave,
|
onLeave,
|
||||||
onSaved,
|
|
||||||
}: MobileStandaloneTiptapEditorProps = {}) => {
|
}: MobileStandaloneTiptapEditorProps = {}) => {
|
||||||
const params = useMemo(() => getMobileEditorParams(), []);
|
const params = useMemo(() => getMobileEditorParams(), []);
|
||||||
const memoId = memoIdProp ?? params.get("memoId");
|
const memoId = memoIdProp ?? params.get("memoId");
|
||||||
@@ -239,7 +236,6 @@ export const MobileStandaloneTiptapEditor = ({
|
|||||||
|
|
||||||
memoRef.current = data.memo;
|
memoRef.current = data.memo;
|
||||||
setMemo(data.memo);
|
setMemo(data.memo);
|
||||||
await onSaved?.(data.memo);
|
|
||||||
lastSavedSnapshotRef.current = currentSnapshot();
|
lastSavedSnapshotRef.current = currentSnapshot();
|
||||||
dirtyRef.current = false;
|
dirtyRef.current = false;
|
||||||
if (draftKey) {
|
if (draftKey) {
|
||||||
@@ -266,7 +262,7 @@ export const MobileStandaloneTiptapEditor = ({
|
|||||||
currentSavePromiseRef.current = null;
|
currentSavePromiseRef.current = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentSnapshot, draftKey, onSaved, persistLocalDraft, setSaveStateStable]
|
[currentSnapshot, draftKey, persistLocalDraft, setSaveStateStable]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -361,7 +357,6 @@ export const MobileStandaloneTiptapEditor = ({
|
|||||||
|
|
||||||
memoRef.current = data.memo;
|
memoRef.current = data.memo;
|
||||||
setMemo(data.memo);
|
setMemo(data.memo);
|
||||||
await onSaved?.(data.memo);
|
|
||||||
setSaveStateStable("saved");
|
setSaveStateStable("saved");
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (!dirtyRef.current && !savingRef.current && !leavingRef.current) {
|
if (!dirtyRef.current && !savingRef.current && !leavingRef.current) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
import { MemoListPane, MemoSelectionActionBar } from "./MemoListPane";
|
import { MemoListPane, MemoSelectionActionBar } from "./MemoListPane";
|
||||||
import { AppConfirmDialog, MemoDeleteConfirmDialog, NotebookNameDialog } from "./dialogs/ConfirmDialogs";
|
import { AppConfirmDialog, MemoDeleteConfirmDialog, NotebookNameDialog } from "./dialogs/ConfirmDialogs";
|
||||||
import { api } from "@/lib/api";
|
import { api } from "@/lib/api";
|
||||||
|
import { openStandaloneMobileEditor } from "@/lib/mobile-editor";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { createExcerpt, docToText, type Notebook, type AuthUser, type MemoSummary, type MemoDetail } from "@edgeever/shared";
|
import { createExcerpt, docToText, type Notebook, type AuthUser, type MemoSummary, type MemoDetail } from "@edgeever/shared";
|
||||||
import type {
|
import type {
|
||||||
@@ -1258,6 +1259,10 @@ export const WorkspaceApp = ({
|
|||||||
setCreatedMemoEditId(data.memo.id);
|
setCreatedMemoEditId(data.memo.id);
|
||||||
setSelectedMemoId(data.memo.id);
|
setSelectedMemoId(data.memo.id);
|
||||||
setActivePane("editor");
|
setActivePane("editor");
|
||||||
|
|
||||||
|
if (!isDesktopViewport()) {
|
||||||
|
openStandaloneMobileEditor(data.memo.id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { MobileStandaloneTiptapEditor } from "@/components/MobileStandaloneTiptapEditor";
|
import { MobileStandaloneTiptapEditor } from "@/components/MobileStandaloneTiptapEditor";
|
||||||
|
import "./styles/mobile-markdown-editor.css";
|
||||||
|
|
||||||
const root = document.getElementById("mobile-editor-root");
|
const root = document.getElementById("mobile-editor-root");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user