Skip to content

Commit

Permalink
dev: editor extensions feature flagging
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 committed Jul 31, 2024
1 parent 8415df4 commit bb52b69
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 22 deletions.
6 changes: 5 additions & 1 deletion packages/editor/src/ce/extensions/document-extensions.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Extensions } from "@tiptap/core";
import { SlashCommand } from "@/extensions";
// hooks
import { TFileHandler } from "@/hooks/use-editor";
// plane editor types
import { TIssueEmbedConfig } from "@/plane-editor/types";
// types
import { TExtensions } from "@/types";

type Props = {
disabledExtensions?: TExtensions[];
fileHandler: TFileHandler;
issueEmbedConfig: TIssueEmbedConfig | undefined;
};

export const DocumentEditorAdditionalExtensions = (props: Props) => {
const { fileHandler } = props;

const extensions = [SlashCommand(fileHandler.upload)];
const extensions: Extensions = [SlashCommand(fileHandler.upload)];

return extensions;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { TFileHandler } from "@/hooks/use-editor";
// plane editor types
import { TEmbedConfig } from "@/plane-editor/types";
// types
import { EditorRefApi, IMentionHighlight, IMentionSuggestion } from "@/types";
import { EditorRefApi, IMentionHighlight, IMentionSuggestion, TExtensions } from "@/types";

interface IDocumentEditor {
containerClassName?: string;
disabledExtensions?: TExtensions[];
editorClassName?: string;
embedHandler: TEmbedConfig;
fileHandler: TFileHandler;
Expand All @@ -32,6 +33,7 @@ interface IDocumentEditor {
const DocumentEditor = (props: IDocumentEditor) => {
const {
containerClassName,
disabledExtensions,
editorClassName = "",
embedHandler,
fileHandler,
Expand All @@ -54,6 +56,7 @@ const DocumentEditor = (props: IDocumentEditor) => {

// use document editor
const { editor, isIndexedDbSynced } = useDocumentEditor({
disabledExtensions,
id,
editorClassName,
embedHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ const RichTextEditor = (props: IRichTextEditor) => {
};

const getExtensions = useCallback(() => {
const extensions = [
SlashCommand(fileHandler.upload),
// TODO; add the extension conditionally for forms that don't require it
// EnterKeyExtension(onEnterKeyPress),
];
const extensions = [SlashCommand(fileHandler.upload)];

if (dragDropEnabled) extensions.push(DragAndDrop(setHideDragHandleFunction));

Expand Down
10 changes: 8 additions & 2 deletions packages/editor/src/core/hooks/use-document-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import { CollaborationProvider } from "@/plane-editor/providers";
// plane editor types
import { TEmbedConfig } from "@/plane-editor/types";
// types
import { EditorRefApi, IMentionHighlight, IMentionSuggestion } from "@/types";
import { EditorRefApi, IMentionHighlight, IMentionSuggestion, TExtensions } from "@/types";

type DocumentEditorProps = {
disabledExtensions?: TExtensions[];
editorClassName: string;
editorProps?: EditorProps;
embedHandler?: TEmbedConfig;
Expand All @@ -36,6 +37,7 @@ type DocumentEditorProps = {

export const useDocumentEditor = (props: DocumentEditorProps) => {
const {
disabledExtensions,
editorClassName,
editorProps = {},
embedHandler,
Expand Down Expand Up @@ -102,6 +104,7 @@ export const useDocumentEditor = (props: DocumentEditorProps) => {
document: provider.document,
}),
...DocumentEditorAdditionalExtensions({
disabledExtensions,
fileHandler,
issueEmbedConfig: embedHandler?.issue,
}),
Expand All @@ -111,5 +114,8 @@ export const useDocumentEditor = (props: DocumentEditorProps) => {
tabIndex,
});

return { editor, isIndexedDbSynced };
return {
editor,
isIndexedDbSynced,
};
};
1 change: 1 addition & 0 deletions packages/editor/src/core/types/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TExtensions = "issue-embed";
1 change: 1 addition & 0 deletions packages/editor/src/core/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./editor";
export * from "./embed";
export * from "./extensions";
export * from "./image";
export * from "./mention-suggestion";
export * from "./slash-commands-suggestion";
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/core/types/slash-commands-suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export type TEditorCommands =
| "code"
| "table"
| "image"
| "divider";
| "divider"
| "issue-embed";

export type CommandProps = {
editor: Editor;
Expand Down
20 changes: 20 additions & 0 deletions web/ce/hooks/use-editor-flagging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// editor
import { TExtensions } from "@plane/editor";

/**
* @description extensions disabled in various editors
* @returns
* ```ts
* {
* documentEditor: TExtensions[]
* richTextEditor: TExtensions[]
* }
* ```
*/
export const useEditorFlagging = (): {
documentEditor: TExtensions[];
richTextEditor: TExtensions[];
} => ({
documentEditor: [],
richTextEditor: [],
});
7 changes: 1 addition & 6 deletions web/ce/hooks/use-issue-embed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// editor
import { TEmbedConfig, TReadOnlyEmbedConfig } from "@plane/editor";
import { TEmbedConfig } from "@plane/editor";
// types
import { TPageEmbedType } from "@plane/types";
// plane web components
Expand All @@ -13,12 +13,7 @@ export const useIssueEmbed = (workspaceSlug: string, projectId: string, queryTyp
widgetCallback,
};

const issueEmbedReadOnlyProps: TReadOnlyEmbedConfig["issue"] = {
widgetCallback,
};

return {
issueEmbedProps,
issueEmbedReadOnlyProps,
};
};
14 changes: 8 additions & 6 deletions web/core/components/pages/editor/editor-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { cn } from "@/helpers/common.helper";
import { useMember, useMention, useUser, useWorkspace } from "@/hooks/store";
import { usePageFilters } from "@/hooks/use-page-filters";
// plane web hooks
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
import { useIssueEmbed } from "@/plane-web/hooks/use-issue-embed";
// services
import { FileService } from "@/services/file.service";
Expand Down Expand Up @@ -72,22 +73,20 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
const { isContentEditable, updateTitle, setIsSubmitting } = page;
const projectMemberIds = projectId ? getProjectMemberIds(projectId.toString()) : [];
const projectMemberDetails = projectMemberIds?.map((id) => getUserDetails(id) as IUserLite);

// use-mention
const { mentionHighlights, mentionSuggestions } = useMention({
workspaceSlug: workspaceSlug?.toString() ?? "",
projectId: projectId?.toString() ?? "",
members: projectMemberDetails,
user: currentUser ?? undefined,
});
// editor flaggings
const { documentEditor } = useEditorFlagging();

// page filters
const { isFullWidth } = usePageFilters();
// issue-embed
const { issueEmbedProps, issueEmbedReadOnlyProps } = useIssueEmbed(
workspaceSlug?.toString() ?? "",
projectId?.toString() ?? ""
);
const { issueEmbedProps } = useIssueEmbed(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "");

useEffect(() => {
updateMarkings(pageDescription ?? "<p></p>");
Expand Down Expand Up @@ -149,6 +148,7 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
embedHandler={{
issue: issueEmbedProps,
}}
disabledExtensions={documentEditor}
/>
) : (
<DocumentReadOnlyEditorWithRef
Expand All @@ -162,7 +162,9 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
highlights: mentionHighlights,
}}
embedHandler={{
issue: issueEmbedReadOnlyProps,
issue: {
widgetCallback: issueEmbedProps.widgetCallback,
},
}}
/>
)}
Expand Down

0 comments on commit bb52b69

Please sign in to comment.