import { useEffect } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import { Control, Controller } from "react-hook-form"; // document editor import { DocumentEditorWithRef, DocumentReadOnlyEditorWithRef, EditorReadOnlyRefApi, EditorRefApi, IMarking, } from "@plane/document-editor"; // types import { IUserLite, TPage } from "@plane/types"; // components import { PageContentBrowser, PageEditorTitle } from "@/components/pages"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { useMember, useMention, useUser, useWorkspace } from "@/hooks/store"; import useReloadConfirmations from "@/hooks/use-reload-confirmation"; // services import { FileService } from "@/services/file.service"; // store import { IPageStore } from "@/store/pages/page.store"; const fileService = new FileService(); type Props = { control: Control; editorRef: React.RefObject; readOnlyEditorRef: React.RefObject; swrPageDetails: TPage | undefined; handleSubmit: () => void; markings: IMarking[]; pageStore: IPageStore; sidePeekVisible: boolean; handleEditorReady: (value: boolean) => void; handleReadOnlyEditorReady: (value: boolean) => void; updateMarkings: (description_html: string) => void; }; export const PageEditorBody: React.FC = observer((props) => { const { control, handleReadOnlyEditorReady, handleEditorReady, editorRef, markings, readOnlyEditorRef, handleSubmit, pageStore, swrPageDetails, sidePeekVisible, updateMarkings, } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { currentUser } = useUser(); const { getWorkspaceBySlug } = useWorkspace(); const { getUserDetails, project: { getProjectMemberIds }, } = useMember(); // derived values const workspaceId = workspaceSlug ? getWorkspaceBySlug(workspaceSlug.toString())?.id ?? "" : ""; const pageTitle = pageStore?.name ?? ""; const pageDescription = pageStore?.description_html ?? "

"; const isFullWidth = !!pageStore?.view_props?.full_width; const { description_html, isContentEditable, updateTitle, isSubmitting, setIsSubmitting } = pageStore; const projectMemberIds = projectId ? getProjectMemberIds(projectId.toString()) : []; const projectMemberDetails = projectMemberIds?.map((id) => getUserDetails(id) as IUserLite); // use-mention const { mentionHighlights, mentionSuggestions } = useMention({ workspaceSlug: workspaceSlug?.toString() ?? "", projectId: projectId?.toString() ?? "", members: projectMemberDetails, user: currentUser ?? undefined, }); const { setShowAlert } = useReloadConfirmations(isSubmitting === "submitting"); useEffect(() => { updateMarkings(description_html ?? "

"); }, [description_html, updateMarkings]); return (
{isContentEditable ? ( (

"} ref={editorRef} containerClassName="p-0 pb-64" editorClassName="lg:px-10 pl-8" onChange={(_description_json, description_html) => { setIsSubmitting("submitting"); setShowAlert(true); onChange(description_html); handleSubmit(); }} mentionHandler={{ highlights: mentionHighlights, suggestions: mentionSuggestions, }} /> )} /> ) : ( )}
); });