mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
* feat: added heading 3 in the editor summary markings * feat: fixed editor and summary bar sizing * feat: added `issue-embed` extension * feat: exposed issue embed extension * feat: added main embed config configuration to document editor body * feat: added peek overview and issue embed fetch function * feat: enabled slash commands to take additonal suggestions from editors * chore: replaced `IssueEmbedWidget` into widget extension * chore: removed issue embed from previous places * feat: added issue embed suggestion extension * feat: added issue embed suggestion renderer * feat: added issue embed suggestions into extensions module * feat: added issues in issueEmbedConfiguration in document editor * chore: package fixes * chore: removed log statements * feat: added title updation logic into document editor * fix: issue suggestion items, not rendering issue widget on enter * feat: added error card for issue widget * feat: improved focus logic for issue search and navigate * feat: appended transactionid for issueWidgetTransaction * chore: packages update * feat: disabled editing of title in readonly mode * feat: added issueEmbedConfig in readonly editor * fix: issue suggestions not loading after structure changed to object * feat: added toast messages for success/error messages from doc editor * fix: issue suggestions sorting issue * fix: formatting errors resolved * fix: infinite reloading of the readonly document editor * fix: css in avatar of issue widget card * feat: added show alert on pages reload * feat: added saving state for the pages editor * fix: issue with heading 3 in side bar view * style: updated issue suggestions dropdown ui * fix: Pages intiliazation and mutation with updated MobX store * fixed image uploads being cancelled on refocus due to swr * fix: issue with same description rerendering empty content fixed * fix: scroll in issue suggestion view * fix: added submission prop * fix: Updated the comment update to take issue id in inbox issues * feat:changed date representation in IssueEmbedCard * fix: page details mutation with optimistic updates using swr * fix: menu options in read only editor with auth fixed * fix: add error handling for title and page desc * fixed yarn.lock * fix: read-only editor title wrapping * fix: build error with rich text editor --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com> Co-authored-by: Palanikannan1437 <73993394+Palanikannan1437@users.noreply.github.com>
197 lines
5.5 KiB
TypeScript
197 lines
5.5 KiB
TypeScript
"use client";
|
|
import React, { useState } from "react";
|
|
import { getEditorClassNames, useEditor } from "@plane/editor-core";
|
|
import { DocumentEditorExtensions } from "./extensions";
|
|
import {
|
|
IDuplicationConfig,
|
|
IPageArchiveConfig,
|
|
IPageLockConfig,
|
|
} from "./types/menu-actions";
|
|
import { EditorHeader } from "./components/editor-header";
|
|
import { useEditorMarkings } from "./hooks/use-editor-markings";
|
|
import { SummarySideBar } from "./components/summary-side-bar";
|
|
import { DocumentDetails } from "./types/editor-types";
|
|
import { PageRenderer } from "./components/page-renderer";
|
|
import { getMenuOptions } from "./utils/menu-options";
|
|
import { useRouter } from "next/router";
|
|
import { IEmbedConfig } from "./extensions/widgets/IssueEmbedWidget/types";
|
|
import { UploadImage, DeleteImage, RestoreImage } from "@plane/editor-types";
|
|
|
|
interface IDocumentEditor {
|
|
// document info
|
|
documentDetails: DocumentDetails;
|
|
value: string;
|
|
rerenderOnPropsChange: {
|
|
id: string;
|
|
description_html: string;
|
|
};
|
|
|
|
// file operations
|
|
uploadFile: UploadImage;
|
|
deleteFile: DeleteImage;
|
|
restoreFile: RestoreImage;
|
|
cancelUploadImage: () => any;
|
|
|
|
// editor state managers
|
|
onActionCompleteHandler: (action: {
|
|
title: string;
|
|
message: string;
|
|
type: "success" | "error" | "warning" | "info";
|
|
}) => void;
|
|
customClassName?: string;
|
|
editorContentCustomClassNames?: string;
|
|
onChange: (json: any, html: string) => void;
|
|
setIsSubmitting?: (
|
|
isSubmitting: "submitting" | "submitted" | "saved",
|
|
) => void;
|
|
setShouldShowAlert?: (showAlert: boolean) => void;
|
|
forwardedRef?: any;
|
|
updatePageTitle: (title: string) => Promise<void>;
|
|
debouncedUpdatesEnabled?: boolean;
|
|
isSubmitting: "submitting" | "submitted" | "saved";
|
|
|
|
// embed configuration
|
|
duplicationConfig?: IDuplicationConfig;
|
|
pageLockConfig?: IPageLockConfig;
|
|
pageArchiveConfig?: IPageArchiveConfig;
|
|
embedConfig?: IEmbedConfig;
|
|
}
|
|
interface DocumentEditorProps extends IDocumentEditor {
|
|
forwardedRef?: React.Ref<EditorHandle>;
|
|
}
|
|
|
|
interface EditorHandle {
|
|
clearEditor: () => void;
|
|
setEditorValue: (content: string) => void;
|
|
}
|
|
|
|
export interface IMarking {
|
|
type: "heading";
|
|
level: number;
|
|
text: string;
|
|
sequence: number;
|
|
}
|
|
|
|
const DocumentEditor = ({
|
|
documentDetails,
|
|
onChange,
|
|
debouncedUpdatesEnabled,
|
|
setIsSubmitting,
|
|
setShouldShowAlert,
|
|
editorContentCustomClassNames,
|
|
value,
|
|
uploadFile,
|
|
deleteFile,
|
|
restoreFile,
|
|
isSubmitting,
|
|
customClassName,
|
|
forwardedRef,
|
|
duplicationConfig,
|
|
pageLockConfig,
|
|
pageArchiveConfig,
|
|
embedConfig,
|
|
updatePageTitle,
|
|
cancelUploadImage,
|
|
onActionCompleteHandler,
|
|
rerenderOnPropsChange,
|
|
}: IDocumentEditor) => {
|
|
// const [alert, setAlert] = useState<string>("")
|
|
const { markings, updateMarkings } = useEditorMarkings();
|
|
const [sidePeekVisible, setSidePeekVisible] = useState(true);
|
|
const router = useRouter();
|
|
|
|
const editor = useEditor({
|
|
onChange(json, html) {
|
|
updateMarkings(json);
|
|
onChange(json, html);
|
|
},
|
|
onStart(json) {
|
|
updateMarkings(json);
|
|
},
|
|
debouncedUpdatesEnabled,
|
|
restoreFile,
|
|
setIsSubmitting,
|
|
setShouldShowAlert,
|
|
value,
|
|
uploadFile,
|
|
deleteFile,
|
|
cancelUploadImage,
|
|
rerenderOnPropsChange,
|
|
forwardedRef,
|
|
extensions: DocumentEditorExtensions(
|
|
uploadFile,
|
|
embedConfig?.issueEmbedConfig,
|
|
setIsSubmitting,
|
|
),
|
|
});
|
|
|
|
if (!editor) {
|
|
return null;
|
|
}
|
|
|
|
const KanbanMenuOptions = getMenuOptions({
|
|
editor: editor,
|
|
router: router,
|
|
duplicationConfig: duplicationConfig,
|
|
pageLockConfig: pageLockConfig,
|
|
pageArchiveConfig: pageArchiveConfig,
|
|
onActionCompleteHandler,
|
|
});
|
|
|
|
const editorClassNames = getEditorClassNames({
|
|
noBorder: true,
|
|
borderOnFocus: false,
|
|
customClassName,
|
|
});
|
|
|
|
if (!editor) return null;
|
|
|
|
return (
|
|
<div className="h-full w-full flex flex-col overflow-hidden">
|
|
<EditorHeader
|
|
readonly={false}
|
|
KanbanMenuOptions={KanbanMenuOptions}
|
|
editor={editor}
|
|
sidePeekVisible={sidePeekVisible}
|
|
setSidePeekVisible={(val) => setSidePeekVisible(val)}
|
|
markings={markings}
|
|
uploadFile={uploadFile}
|
|
setIsSubmitting={setIsSubmitting}
|
|
isLocked={!pageLockConfig ? false : pageLockConfig.is_locked}
|
|
isArchived={!pageArchiveConfig ? false : pageArchiveConfig.is_archived}
|
|
archivedAt={pageArchiveConfig && pageArchiveConfig.archived_at}
|
|
documentDetails={documentDetails}
|
|
isSubmitting={isSubmitting}
|
|
/>
|
|
<div className="h-full w-full flex overflow-y-auto">
|
|
<div className="flex-shrink-0 h-full w-56 lg:w-72 sticky top-0">
|
|
<SummarySideBar
|
|
editor={editor}
|
|
markings={markings}
|
|
sidePeekVisible={sidePeekVisible}
|
|
/>
|
|
</div>
|
|
<div className="h-full w-[calc(100%-14rem)] lg:w-[calc(100%-18rem-18rem)]">
|
|
<PageRenderer
|
|
readonly={false}
|
|
editor={editor}
|
|
editorContentCustomClassNames={editorContentCustomClassNames}
|
|
editorClassNames={editorClassNames}
|
|
documentDetails={documentDetails}
|
|
updatePageTitle={updatePageTitle}
|
|
/>
|
|
</div>
|
|
<div className="hidden lg:block flex-shrink-0 w-56 lg:w-72" />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const DocumentEditorWithRef = React.forwardRef<EditorHandle, IDocumentEditor>(
|
|
(props, ref) => <DocumentEditor {...props} forwardedRef={ref} />,
|
|
);
|
|
|
|
DocumentEditorWithRef.displayName = "DocumentEditorWithRef";
|
|
|
|
export { DocumentEditor, DocumentEditorWithRef };
|