From 7c4210cad25e67495874d6da79a022f07babae3f Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Fri, 7 Mar 2025 13:20:33 +0530 Subject: [PATCH 1/2] [WEB-3489] improvement: add support to disable extensions in rich text editor --- .../rich-text-editor/rich-text-editor.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/core/components/editor/rich-text-editor/rich-text-editor.tsx b/web/core/components/editor/rich-text-editor/rich-text-editor.tsx index fdd17f2c05c..05c91c70a2e 100644 --- a/web/core/components/editor/rich-text-editor/rich-text-editor.tsx +++ b/web/core/components/editor/rich-text-editor/rich-text-editor.tsx @@ -1,6 +1,6 @@ import React, { forwardRef } from "react"; // editor -import { EditorRefApi, IRichTextEditor, RichTextEditorWithRef, TFileHandler } from "@plane/editor"; +import { EditorRefApi, IRichTextEditor, RichTextEditorWithRef, TExtensions, TFileHandler } from "@plane/editor"; // plane types import { TSearchEntityRequestPayload, TSearchResponse } from "@plane/types"; // components @@ -19,11 +19,20 @@ interface RichTextEditorWrapperProps workspaceId: string; projectId?: string; uploadFile: TFileHandler["upload"]; + disabledExtensions?: TExtensions[]; } 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 +45,7 @@ export const RichTextEditor = forwardRef Date: Fri, 7 Mar 2025 14:23:30 +0530 Subject: [PATCH 2/2] improvements: disabled extensions prop for all editor components --- packages/types/src/utils.d.ts | 2 ++ space/core/components/editor/lite-text-editor.tsx | 8 +++++--- .../editor/lite-text-read-only-editor.tsx | 13 +++++++------ space/core/components/editor/rich-text-editor.tsx | 9 +++++---- .../editor/rich-text-read-only-editor.tsx | 13 +++++++------ .../editor/lite-text-editor/lite-text-editor.tsx | 6 ++++-- .../lite-text-editor/lite-text-read-only-editor.tsx | 13 +++++++------ .../editor/rich-text-editor/rich-text-editor.tsx | 10 ++++------ .../rich-text-editor/rich-text-read-only-editor.tsx | 13 +++++++------ 9 files changed, 48 insertions(+), 39 deletions(-) diff --git a/packages/types/src/utils.d.ts b/packages/types/src/utils.d.ts index aae5fd90ced..d7f7067b1d5 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 9f2cda4ad51..6c6a19641ae 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 c2d8c746fa6..b989e1e411c 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; projectId?: string; uploadFile: TFileHandler["upload"]; - disabledExtensions?: TExtensions[]; } export const RichTextEditor = forwardRef((props, ref) => { diff --git a/web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx b/web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx index 950f655cb95..31ce65159db 100644 --- a/web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx +++ b/web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx @@ -1,6 +1,7 @@ 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 @@ -10,9 +11,9 @@ import { useEditorConfig } from "@/hooks/editor"; // plane web hooks import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging"; -type RichTextReadOnlyEditorWrapperProps = Omit< - IRichTextReadOnlyEditor, - "disabledExtensions" | "fileHandler" | "mentionHandler" +type RichTextReadOnlyEditorWrapperProps = MakeOptional< + Omit, + "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