[WIKI-644] fix: remove unnecessary props from the editor package #7726
This commit is contained in:
parent
88f194ca8e
commit
a1500c2206
12 changed files with 36 additions and 87 deletions
|
|
@ -4,7 +4,7 @@ import type { IEditorProps } from "@/types";
|
|||
|
||||
export type TCoreAdditionalExtensionsProps = Pick<
|
||||
IEditorProps,
|
||||
"disabledExtensions" | "flaggedExtensions" | "fileHandler" | "embedHandler"
|
||||
"disabledExtensions" | "flaggedExtensions" | "fileHandler" | "extendedEditorProps"
|
||||
>;
|
||||
|
||||
export const CoreEditorAdditionalExtensions = (props: TCoreAdditionalExtensionsProps): Extensions => {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
import type { HocuspocusProvider } from "@hocuspocus/provider";
|
||||
import type { AnyExtension } from "@tiptap/core";
|
||||
import { SlashCommands } from "@/extensions";
|
||||
// plane editor types
|
||||
import type { TEmbedConfig } from "@/plane-editor/types";
|
||||
// types
|
||||
import type { IEditorProps, TExtensions, TUserDetails } from "@/types";
|
||||
|
||||
export type TDocumentEditorAdditionalExtensionsProps = Pick<
|
||||
IEditorProps,
|
||||
"disabledExtensions" | "flaggedExtensions" | "fileHandler"
|
||||
"disabledExtensions" | "flaggedExtensions" | "fileHandler" | "extendedEditorProps"
|
||||
> & {
|
||||
embedConfig: TEmbedConfig | undefined;
|
||||
isEditable: boolean;
|
||||
provider?: HocuspocusProvider;
|
||||
userDetails: TUserDetails;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
import type { Extensions } from "@tiptap/core";
|
||||
import React, { useMemo } from "react";
|
||||
import React from "react";
|
||||
// plane imports
|
||||
import { cn } from "@plane/utils";
|
||||
// components
|
||||
import { PageRenderer } from "@/components/editors";
|
||||
// constants
|
||||
import { DEFAULT_DISPLAY_CONFIG } from "@/constants/config";
|
||||
// extensions
|
||||
import { WorkItemEmbedExtension } from "@/extensions";
|
||||
// helpers
|
||||
import { getEditorClassNames } from "@/helpers/common";
|
||||
// hooks
|
||||
|
|
@ -23,14 +20,13 @@ const CollaborativeDocumentEditor: React.FC<ICollaborativeDocumentEditorProps> =
|
|||
bubbleMenuEnabled = true,
|
||||
containerClassName,
|
||||
documentLoaderClassName,
|
||||
extensions: externalExtensions = [],
|
||||
extensions = [],
|
||||
disabledExtensions,
|
||||
displayConfig = DEFAULT_DISPLAY_CONFIG,
|
||||
editable,
|
||||
editorClassName = "",
|
||||
editorProps,
|
||||
extendedEditorProps,
|
||||
embedHandler,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
forwardedRef,
|
||||
|
|
@ -50,27 +46,13 @@ const CollaborativeDocumentEditor: React.FC<ICollaborativeDocumentEditorProps> =
|
|||
user,
|
||||
} = props;
|
||||
|
||||
const extensions: Extensions = useMemo(() => {
|
||||
const allExtensions = [...externalExtensions];
|
||||
|
||||
if (embedHandler?.issue) {
|
||||
allExtensions.push(
|
||||
WorkItemEmbedExtension({
|
||||
widgetCallback: embedHandler.issue.widgetCallback,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return allExtensions;
|
||||
}, [externalExtensions, embedHandler.issue]);
|
||||
|
||||
// use document editor
|
||||
const { editor, hasServerConnectionFailed, hasServerSynced } = useCollaborativeEditor({
|
||||
disabledExtensions,
|
||||
editable,
|
||||
editorClassName,
|
||||
editorProps,
|
||||
embedHandler,
|
||||
extendedEditorProps,
|
||||
extensions,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { PageRenderer } from "@/components/editors";
|
|||
// constants
|
||||
import { DEFAULT_DISPLAY_CONFIG } from "@/constants/config";
|
||||
// extensions
|
||||
import { HeadingListExtension, WorkItemEmbedExtension, SideMenuExtension } from "@/extensions";
|
||||
import { HeadingListExtension, SideMenuExtension } from "@/extensions";
|
||||
// helpers
|
||||
import { getEditorClassNames } from "@/helpers/common";
|
||||
// hooks
|
||||
|
|
@ -25,7 +25,7 @@ const DocumentEditor = (props: IDocumentEditorProps) => {
|
|||
displayConfig = DEFAULT_DISPLAY_CONFIG,
|
||||
editable,
|
||||
editorClassName = "",
|
||||
embedHandler,
|
||||
extendedEditorProps,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
forwardedRef,
|
||||
|
|
@ -39,13 +39,6 @@ const DocumentEditor = (props: IDocumentEditorProps) => {
|
|||
} = props;
|
||||
const extensions: Extensions = useMemo(() => {
|
||||
const additionalExtensions: Extensions = [];
|
||||
if (embedHandler?.issue) {
|
||||
additionalExtensions.push(
|
||||
WorkItemEmbedExtension({
|
||||
widgetCallback: embedHandler.issue.widgetCallback,
|
||||
})
|
||||
);
|
||||
}
|
||||
additionalExtensions.push(
|
||||
SideMenuExtension({
|
||||
aiEnabled: !disabledExtensions?.includes("ai"),
|
||||
|
|
@ -54,7 +47,7 @@ const DocumentEditor = (props: IDocumentEditorProps) => {
|
|||
HeadingListExtension,
|
||||
...DocumentEditorAdditionalExtensions({
|
||||
disabledExtensions,
|
||||
embedConfig: embedHandler,
|
||||
extendedEditorProps,
|
||||
flaggedExtensions,
|
||||
isEditable: editable,
|
||||
fileHandler,
|
||||
|
|
@ -73,6 +66,7 @@ const DocumentEditor = (props: IDocumentEditorProps) => {
|
|||
editable,
|
||||
editorClassName,
|
||||
enableHistory: true,
|
||||
extendedEditorProps,
|
||||
extensions,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
|
|
@ -82,7 +76,6 @@ const DocumentEditor = (props: IDocumentEditorProps) => {
|
|||
initialValue: value,
|
||||
mentionHandler,
|
||||
onChange,
|
||||
embedHandler,
|
||||
});
|
||||
|
||||
const editorContainerClassName = getEditorClassNames({
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export const EditorWrapper: React.FC<Props> = (props) => {
|
|||
editable,
|
||||
editorClassName = "",
|
||||
editorProps,
|
||||
extendedEditorProps,
|
||||
extensions,
|
||||
id,
|
||||
initialValue,
|
||||
|
|
@ -41,7 +42,6 @@ export const EditorWrapper: React.FC<Props> = (props) => {
|
|||
placeholder,
|
||||
tabIndex,
|
||||
value,
|
||||
embedHandler,
|
||||
} = props;
|
||||
|
||||
const editor = useEditor({
|
||||
|
|
@ -50,6 +50,7 @@ export const EditorWrapper: React.FC<Props> = (props) => {
|
|||
editorClassName,
|
||||
editorProps,
|
||||
enableHistory: true,
|
||||
extendedEditorProps,
|
||||
extensions,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
|
|
@ -66,7 +67,6 @@ export const EditorWrapper: React.FC<Props> = (props) => {
|
|||
placeholder,
|
||||
tabIndex,
|
||||
value,
|
||||
embedHandler,
|
||||
});
|
||||
|
||||
const editorContainerClassName = getEditorClassNames({
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import {
|
|||
// plane editor extensions
|
||||
import { CoreEditorAdditionalExtensions } from "@/plane-editor/extensions";
|
||||
// types
|
||||
import type { IEditorProps, TEmbedConfig } from "@/types";
|
||||
import type { IEditorProps } from "@/types";
|
||||
// local imports
|
||||
import { CustomImageExtension } from "./custom-image/extension";
|
||||
import { EmojiExtension } from "./emoji/extension";
|
||||
|
|
@ -45,11 +45,10 @@ type TArguments = Pick<
|
|||
| "mentionHandler"
|
||||
| "placeholder"
|
||||
| "tabIndex"
|
||||
| "embedHandler"
|
||||
| "extendedEditorProps"
|
||||
> & {
|
||||
enableHistory: boolean;
|
||||
editable: boolean;
|
||||
embedHandler?: TEmbedConfig;
|
||||
};
|
||||
|
||||
export const CoreEditorExtensions = (args: TArguments): Extensions => {
|
||||
|
|
@ -62,8 +61,8 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
|
|||
mentionHandler,
|
||||
placeholder,
|
||||
tabIndex,
|
||||
embedHandler,
|
||||
editable,
|
||||
extendedEditorProps,
|
||||
} = args;
|
||||
|
||||
const extensions = [
|
||||
|
|
@ -118,7 +117,7 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
|
|||
disabledExtensions,
|
||||
flaggedExtensions,
|
||||
fileHandler,
|
||||
embedHandler,
|
||||
extendedEditorProps,
|
||||
}),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
|
|||
editable,
|
||||
editorClassName = "",
|
||||
editorProps = {},
|
||||
embedHandler,
|
||||
extendedEditorProps,
|
||||
extensions = [],
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
|
|
@ -80,8 +80,8 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
|
|||
);
|
||||
|
||||
const editor = useEditor({
|
||||
embedHandler,
|
||||
disabledExtensions,
|
||||
extendedEditorProps,
|
||||
id,
|
||||
editable,
|
||||
editorProps,
|
||||
|
|
@ -99,7 +99,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
|
|||
...extensions,
|
||||
...DocumentEditorAdditionalExtensions({
|
||||
disabledExtensions,
|
||||
embedConfig: embedHandler,
|
||||
extendedEditorProps,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
isEditable: editable,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export const useEditor = (props: TEditorHookProps) => {
|
|||
editorClassName = "",
|
||||
editorProps = {},
|
||||
enableHistory,
|
||||
extendedEditorProps,
|
||||
extensions = [],
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
|
|
@ -32,7 +33,6 @@ export const useEditor = (props: TEditorHookProps) => {
|
|||
onAssetChange,
|
||||
onChange,
|
||||
onEditorFocus,
|
||||
embedHandler,
|
||||
onTransaction,
|
||||
placeholder,
|
||||
provider,
|
||||
|
|
@ -55,16 +55,16 @@ export const useEditor = (props: TEditorHookProps) => {
|
|||
},
|
||||
extensions: [
|
||||
...CoreEditorExtensions({
|
||||
editable,
|
||||
disabledExtensions,
|
||||
editable,
|
||||
enableHistory,
|
||||
extendedEditorProps,
|
||||
fileHandler,
|
||||
flaggedExtensions,
|
||||
isTouchDevice,
|
||||
mentionHandler,
|
||||
placeholder,
|
||||
tabIndex,
|
||||
embedHandler,
|
||||
}),
|
||||
...extensions,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@ export type IEditorProps = {
|
|||
editorClassName?: string;
|
||||
editorProps?: EditorProps;
|
||||
extensions?: Extensions;
|
||||
embedHandler?: TEmbedConfig;
|
||||
flaggedExtensions: TExtensions[];
|
||||
fileHandler: TFileHandler;
|
||||
forwardedRef?: React.MutableRefObject<EditorRefApi | null>;
|
||||
|
|
@ -174,7 +173,6 @@ export type ICollaborativeDocumentEditorProps = Omit<IEditorProps, "initialValue
|
|||
documentLoaderClassName?: string;
|
||||
dragDropEnabled?: boolean;
|
||||
editable: boolean;
|
||||
embedHandler: TEmbedConfig;
|
||||
realtimeConfig: TRealtimeConfig;
|
||||
serverHandler?: TServerHandler;
|
||||
user: TUserDetails;
|
||||
|
|
@ -182,7 +180,6 @@ export type ICollaborativeDocumentEditorProps = Omit<IEditorProps, "initialValue
|
|||
|
||||
export type IDocumentEditorProps = Omit<IEditorProps, "initialValue" | "onEnterKeyPress" | "value"> & {
|
||||
aiHandler?: TAIHandler;
|
||||
embedHandler: TEmbedConfig;
|
||||
user?: TUserDetails;
|
||||
value: Content;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ type TCoreHookProps = Pick<
|
|||
| "disabledExtensions"
|
||||
| "editorClassName"
|
||||
| "editorProps"
|
||||
| "extendedEditorProps"
|
||||
| "extensions"
|
||||
| "flaggedExtensions"
|
||||
| "handleEditorReady"
|
||||
| "isTouchDevice"
|
||||
| "onEditorFocus"
|
||||
| "embedHandler"
|
||||
>;
|
||||
|
||||
export type TEditorHookProps = TCoreHookProps &
|
||||
|
|
@ -51,7 +51,4 @@ export type TCollaborativeEditorHookProps = TCoreHookProps &
|
|||
| "placeholder"
|
||||
| "tabIndex"
|
||||
> &
|
||||
Pick<
|
||||
ICollaborativeDocumentEditorProps,
|
||||
"dragDropEnabled" | "embedHandler" | "realtimeConfig" | "serverHandler" | "user"
|
||||
>;
|
||||
Pick<ICollaborativeDocumentEditorProps, "dragDropEnabled" | "realtimeConfig" | "serverHandler" | "user">;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue