Skip to content

Commit 4809abf

Browse files
aaryan610lifeiscontent
authored andcommitted
[WIKI-537] refactor: document editor (#7384)
* refactor: document editor * chore: update user prop * fix: type warning * chore: update value prop name * chore: remove unnecessary exports * hore: update initialValue type * chore: revert initialValue type * refactor: unnecessary string handlers
1 parent 8e03c5e commit 4809abf

File tree

23 files changed

+244
-183
lines changed

23 files changed

+244
-183
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { forwardRef } from "react";
2+
// plane imports
3+
import { DocumentEditorWithRef, EditorRefApi, IDocumentEditorProps, TFileHandler } from "@plane/editor";
4+
import { MakeOptional, TSearchEntityRequestPayload, TSearchResponse } from "@plane/types";
5+
import { cn } from "@plane/utils";
6+
// components
7+
import { EditorMentionsRoot } from "@/components/editor";
8+
// hooks
9+
import { useEditorConfig, useEditorMention } from "@/hooks/editor";
10+
import { useMember } from "@/hooks/store";
11+
// plane web hooks
12+
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
13+
import { useIssueEmbed } from "@/plane-web/hooks/use-issue-embed";
14+
15+
type DocumentEditorWrapperProps = MakeOptional<
16+
Omit<IDocumentEditorProps, "fileHandler" | "mentionHandler" | "embedHandler" | "user">,
17+
"disabledExtensions" | "editable" | "flaggedExtensions"
18+
> & {
19+
embedHandler?: Partial<IDocumentEditorProps["embedHandler"]>;
20+
workspaceSlug: string;
21+
workspaceId: string;
22+
projectId?: string;
23+
} & (
24+
| {
25+
editable: false;
26+
}
27+
| {
28+
editable: true;
29+
searchMentionCallback: (payload: TSearchEntityRequestPayload) => Promise<TSearchResponse>;
30+
uploadFile: TFileHandler["upload"];
31+
}
32+
);
33+
34+
export const DocumentEditor = forwardRef<EditorRefApi, DocumentEditorWrapperProps>((props, ref) => {
35+
const {
36+
containerClassName,
37+
editable,
38+
embedHandler,
39+
workspaceSlug,
40+
workspaceId,
41+
projectId,
42+
disabledExtensions: additionalDisabledExtensions = [],
43+
...rest
44+
} = props;
45+
// store hooks
46+
const { getUserDetails } = useMember();
47+
// editor flaggings
48+
const { document: documentEditorExtensions } = useEditorFlagging(workspaceSlug);
49+
// use editor mention
50+
const { fetchMentions } = useEditorMention({
51+
searchEntity: editable ? async (payload) => await props.searchMentionCallback(payload) : async () => ({}),
52+
});
53+
// editor config
54+
const { getEditorFileHandlers } = useEditorConfig();
55+
// issue-embed
56+
const { issueEmbedProps } = useIssueEmbed({
57+
projectId,
58+
workspaceSlug,
59+
});
60+
61+
return (
62+
<DocumentEditorWithRef
63+
ref={ref}
64+
disabledExtensions={[...documentEditorExtensions.disabled, ...(additionalDisabledExtensions ?? [])]}
65+
editable={editable}
66+
flaggedExtensions={documentEditorExtensions.flagged}
67+
fileHandler={getEditorFileHandlers({
68+
projectId,
69+
uploadFile: editable ? props.uploadFile : async () => "",
70+
workspaceId,
71+
workspaceSlug,
72+
})}
73+
mentionHandler={{
74+
searchCallback: async (query) => {
75+
const res = await fetchMentions(query);
76+
if (!res) throw new Error("Failed in fetching mentions");
77+
return res;
78+
},
79+
renderComponent: EditorMentionsRoot,
80+
getMentionedEntityDetails: (id: string) => ({ display_name: getUserDetails(id)?.display_name ?? "" }),
81+
}}
82+
embedHandler={{
83+
issue: issueEmbedProps,
84+
...embedHandler,
85+
}}
86+
{...rest}
87+
containerClassName={cn("relative pl-3 pb-3", containerClassName)}
88+
/>
89+
);
90+
});
91+
92+
DocumentEditor.displayName = "DocumentEditor";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from "./embeds";
2-
export * from "./lite-text-editor";
2+
export * from "./lite-text";
33
export * from "./pdf";
4-
export * from "./rich-text-editor";
4+
export * from "./rich-text";
55
export * from "./sticky-editor";

apps/web/core/components/editor/lite-text-editor/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/web/core/components/editor/lite-text-editor/lite-text-editor.tsx renamed to apps/web/core/components/editor/lite-text/editor.tsx

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./editor";
2+
export * from "./read-only-editor";
3+
export * from "./toolbar";

apps/web/core/components/editor/lite-text-editor/lite-text-read-only-editor.tsx renamed to apps/web/core/components/editor/lite-text/read-only-editor.tsx

File renamed without changes.

apps/web/core/components/editor/lite-text-editor/toolbar.tsx renamed to apps/web/core/components/editor/lite-text/toolbar.tsx

File renamed without changes.

apps/web/core/components/editor/rich-text-editor/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/web/core/components/editor/rich-text-editor/rich-text-editor.tsx renamed to apps/web/core/components/editor/rich-text/editor.tsx

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./editor";

0 commit comments

Comments
 (0)