"use client"; import * as React from "react"; import { EditorContainer, EditorContentWrapper, getEditorClassNames, useEditor, } from "@plane/editor-core"; import { FixedMenu } from "./menus/fixed-menu"; import { LiteTextEditorExtensions } from "./extensions"; export type UploadImage = (file: File) => Promise; export type DeleteImage = (assetUrlWithWorkspaceId: string) => Promise; export type IMentionSuggestion = { id: string; type: string; avatar: string; title: string; subtitle: string; redirect_uri: string; }; export type IMentionHighlight = string; interface ILiteTextEditor { value: string; uploadFile: UploadImage; deleteFile: DeleteImage; noBorder?: boolean; borderOnFocus?: boolean; customClassName?: string; editorContentCustomClassNames?: string; onChange?: (json: any, html: string) => void; setIsSubmitting?: ( isSubmitting: "submitting" | "submitted" | "saved", ) => void; setShouldShowAlert?: (showAlert: boolean) => void; forwardedRef?: any; debouncedUpdatesEnabled?: boolean; commentAccessSpecifier?: { accessValue: string; onAccessChange: (accessKey: string) => void; showAccessSpecifier: boolean; commentAccess: { icon: any; key: string; label: "Private" | "Public"; }[]; }; onEnterKeyPress?: (e?: any) => void; mentionHighlights?: string[]; mentionSuggestions?: IMentionSuggestion[]; submitButton?: React.ReactNode; } interface LiteTextEditorProps extends ILiteTextEditor { forwardedRef?: React.Ref; } interface EditorHandle { clearEditor: () => void; setEditorValue: (content: string) => void; } const LiteTextEditor = (props: LiteTextEditorProps) => { const { onChange, debouncedUpdatesEnabled, setIsSubmitting, setShouldShowAlert, editorContentCustomClassNames, value, uploadFile, deleteFile, noBorder, borderOnFocus, customClassName, forwardedRef, commentAccessSpecifier, onEnterKeyPress, mentionHighlights, mentionSuggestions, submitButton, } = props; const editor = useEditor({ onChange, debouncedUpdatesEnabled, setIsSubmitting, setShouldShowAlert, value, uploadFile, deleteFile, forwardedRef, extensions: LiteTextEditorExtensions(onEnterKeyPress), mentionHighlights, mentionSuggestions, }); const editorClassNames = getEditorClassNames({ noBorder, borderOnFocus, customClassName, }); if (!editor) return null; return (
); }; const LiteTextEditorWithRef = React.forwardRef( (props, ref) => , ); LiteTextEditorWithRef.displayName = "LiteTextEditorWithRef"; export { LiteTextEditor, LiteTextEditorWithRef };