import { useEffect } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; // document-editor import { DocumentEditorWithRef, DocumentReadOnlyEditorWithRef, EditorReadOnlyRefApi, EditorRefApi, IMarking, } from "@plane/document-editor"; // types import { IUserLite } from "@plane/types"; // components import { PageContentBrowser, PageContentLoader, PageEditorTitle } from "@/components/pages"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { useMember, useMention, useUser, useWorkspace } from "@/hooks/store"; import { usePageDescription } from "@/hooks/use-page-description"; import { usePageFilters } from "@/hooks/use-page-filters"; // services import { FileService } from "@/services/file.service"; // store import { IPageStore } from "@/store/pages/page.store"; const fileService = new FileService(); type Props = { editorRef: React.RefObject; readOnlyEditorRef: React.RefObject; markings: IMarking[]; page: IPageStore; sidePeekVisible: boolean; handleEditorReady: (value: boolean) => void; handleReadOnlyEditorReady: (value: boolean) => void; updateMarkings: (description_html: string) => void; }; export const PageEditorBody: React.FC = observer((props) => { const { handleReadOnlyEditorReady, handleEditorReady, editorRef, markings, readOnlyEditorRef, page, sidePeekVisible, updateMarkings, } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { data: currentUser } = useUser(); const { getWorkspaceBySlug } = useWorkspace(); const { getUserDetails, project: { getProjectMemberIds }, } = useMember(); // derived values const workspaceId = workspaceSlug ? getWorkspaceBySlug(workspaceSlug.toString())?.id ?? "" : ""; const pageId = page?.id; const pageTitle = page?.name ?? ""; const pageDescription = page?.description_html; const { isContentEditable, updateTitle, setIsSubmitting } = page; const projectMemberIds = projectId ? getProjectMemberIds(projectId.toString()) : []; const projectMemberDetails = projectMemberIds?.map((id) => getUserDetails(id) as IUserLite); // project-description const { handleDescriptionChange, isDescriptionReady, pageDescriptionYJS } = usePageDescription({ editorRef, page, projectId, workspaceSlug, }); // use-mention const { mentionHighlights, mentionSuggestions } = useMention({ workspaceSlug: workspaceSlug?.toString() ?? "", projectId: projectId?.toString() ?? "", members: projectMemberDetails, user: currentUser ?? undefined, }); // page filters const { isFullWidth } = usePageFilters(); useEffect(() => { updateMarkings(pageDescription ?? "

"); }, [pageDescription, updateMarkings]); if (pageId === undefined || !pageDescriptionYJS || !isDescriptionReady) return ; return (
{isContentEditable ? ( ) : (

"} handleEditorReady={handleReadOnlyEditorReady} containerClassName="p-0 pb-64 border-none" editorClassName="pl-10" mentionHandler={{ highlights: mentionHighlights, }} /> )}
); });