From a953013f70cbe689cf4d1897746f004909167b4f Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Fri, 7 Mar 2025 16:34:07 +0530 Subject: [PATCH] [WEB-3489] improvement: add support to disable extensions in rich and lite text editor (#6721) * [WEB-3489] improvement: add support to disable extensions in rich text editor * improvements: disabled extensions prop for all editor components --- packages/types/src/utils.d.ts | 2 ++ .../components/editor/lite-text-editor.tsx | 8 ++++--- .../editor/lite-text-read-only-editor.tsx | 13 ++++++------ .../components/editor/rich-text-editor.tsx | 9 ++++---- .../editor/rich-text-read-only-editor.tsx | 13 ++++++------ .../lite-text-editor/lite-text-editor.tsx | 6 ++++-- .../lite-text-read-only-editor.tsx | 13 ++++++------ .../rich-text-editor/rich-text-editor.tsx | 21 ++++++++++++------- .../rich-text-read-only-editor.tsx | 13 ++++++------ 9 files changed, 58 insertions(+), 40 deletions(-) diff --git a/packages/types/src/utils.d.ts b/packages/types/src/utils.d.ts index aae5fd90c..d7f7067b1 100644 --- a/packages/types/src/utils.d.ts +++ b/packages/types/src/utils.d.ts @@ -3,3 +3,5 @@ export type PartialDeep = { }; export type CompleteOrEmpty = T | Record; + +export type MakeOptional = Omit & Partial>; diff --git a/space/core/components/editor/lite-text-editor.tsx b/space/core/components/editor/lite-text-editor.tsx index 9f2cda4ad..6c6a19641 100644 --- a/space/core/components/editor/lite-text-editor.tsx +++ b/space/core/components/editor/lite-text-editor.tsx @@ -1,6 +1,7 @@ import React from "react"; -// editor +// plane imports import { EditorRefApi, ILiteTextEditor, LiteTextEditorWithRef, TFileHandler } from "@plane/editor"; +import { MakeOptional } from "@plane/types"; // components import { EditorMentionsRoot, IssueCommentToolbar } from "@/components/editor"; // helpers @@ -9,7 +10,7 @@ import { getEditorFileHandlers } from "@/helpers/editor.helper"; import { isCommentEmpty } from "@/helpers/string.helper"; interface LiteTextEditorWrapperProps - extends Omit { + extends MakeOptional, "disabledExtensions"> { anchor: string; workspaceId: string; isSubmitting?: boolean; @@ -25,6 +26,7 @@ export const LiteTextEditor = React.forwardRef(ref: React.ForwardedRef): ref is React.MutableRefObject { @@ -38,7 +40,7 @@ export const LiteTextEditor = React.forwardRef , + "disabledExtensions" > & { anchor: string; workspaceId: string; }; export const LiteTextReadOnlyEditor = React.forwardRef( - ({ anchor, workspaceId, ...props }, ref) => ( + ({ anchor, workspaceId, disabledExtensions, ...props }, ref) => ( { + extends MakeOptional, "disabledExtensions"> { anchor: string; uploadFile: TFileHandler["upload"]; workspaceId: string; } export const RichTextEditor = forwardRef((props, ref) => { - const { anchor, containerClassName, uploadFile, workspaceId, ...rest } = props; + const { anchor, containerClassName, uploadFile, workspaceId, disabledExtensions, ...rest } = props; return ( , }} ref={ref} - disabledExtensions={[]} + disabledExtensions={disabledExtensions ?? []} fileHandler={getEditorFileHandlers({ anchor, uploadFile, diff --git a/space/core/components/editor/rich-text-read-only-editor.tsx b/space/core/components/editor/rich-text-read-only-editor.tsx index c2d8c746f..b989e1e41 100644 --- a/space/core/components/editor/rich-text-read-only-editor.tsx +++ b/space/core/components/editor/rich-text-read-only-editor.tsx @@ -1,25 +1,26 @@ import React from "react"; -// editor +// plane imports import { EditorReadOnlyRefApi, IRichTextReadOnlyEditor, RichTextReadOnlyEditorWithRef } from "@plane/editor"; +import { MakeOptional } from "@plane/types"; // components import { EditorMentionsRoot } from "@/components/editor"; // helpers import { cn } from "@/helpers/common.helper"; import { getReadOnlyEditorFileHandlers } from "@/helpers/editor.helper"; -type RichTextReadOnlyEditorWrapperProps = Omit< - IRichTextReadOnlyEditor, - "disabledExtensions" | "fileHandler" | "mentionHandler" +type RichTextReadOnlyEditorWrapperProps = MakeOptional< + Omit, + "disabledExtensions" > & { anchor: string; workspaceId: string; }; export const RichTextReadOnlyEditor = React.forwardRef( - ({ anchor, workspaceId, ...props }, ref) => ( + ({ anchor, workspaceId, disabledExtensions, ...props }, ref) => ( { + extends MakeOptional, "disabledExtensions"> { workspaceSlug: string; workspaceId: string; projectId: string; @@ -49,6 +50,7 @@ export const LiteTextEditor = React.forwardRef , + "disabledExtensions" > & { workspaceId: string; workspaceSlug: string; @@ -20,7 +21,7 @@ type LiteTextReadOnlyEditorWrapperProps = Omit< }; export const LiteTextReadOnlyEditor = React.forwardRef( - ({ workspaceId, workspaceSlug, projectId, ...props }, ref) => { + ({ workspaceId, workspaceSlug, projectId, disabledExtensions: additionalDisabledExtensions, ...props }, ref) => { // editor flaggings const { liteTextEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString()); // editor config @@ -29,7 +30,7 @@ export const LiteTextReadOnlyEditor = React.forwardRef { + extends MakeOptional, "disabledExtensions"> { searchMentionCallback: (payload: TSearchEntityRequestPayload) => Promise; workspaceSlug: string; workspaceId: string; @@ -22,8 +21,16 @@ interface RichTextEditorWrapperProps } export const RichTextEditor = forwardRef((props, ref) => { - const { containerClassName, workspaceSlug, workspaceId, projectId, searchMentionCallback, uploadFile, ...rest } = - props; + const { + containerClassName, + workspaceSlug, + workspaceId, + projectId, + searchMentionCallback, + uploadFile, + disabledExtensions: additionalDisabledExtensions, + ...rest + } = props; // editor flaggings const { richTextEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString()); // use editor mention @@ -36,7 +43,7 @@ export const RichTextEditor = forwardRef, + "disabledExtensions" > & { workspaceId: string; workspaceSlug: string; @@ -20,7 +21,7 @@ type RichTextReadOnlyEditorWrapperProps = Omit< }; export const RichTextReadOnlyEditor = React.forwardRef( - ({ workspaceId, workspaceSlug, projectId, ...props }, ref) => { + ({ workspaceId, workspaceSlug, projectId, disabledExtensions: additionalDisabledExtensions, ...props }, ref) => { // editor flaggings const { richTextEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString()); // editor config @@ -29,7 +30,7 @@ export const RichTextReadOnlyEditor = React.forwardRef