removed comments and cleaned up types

This commit is contained in:
Palanikannan1437 2024-03-04 13:55:40 +05:30
parent 43fd94827f
commit 26646d512e
16 changed files with 80 additions and 52 deletions

View File

@ -48,7 +48,6 @@ export const useEditor = ({
mentionHighlights, mentionHighlights,
mentionSuggestions, mentionSuggestions,
}: CustomEditorProps) => { }: CustomEditorProps) => {
console.log("the mentions", mentionHighlights);
const editor = useCustomEditor( const editor = useCustomEditor(
{ {
editorProps: { editorProps: {

View File

@ -3,7 +3,7 @@ import { useImperativeHandle, useRef, MutableRefObject } from "react";
import { CoreReadOnlyEditorExtensions } from "src/ui/read-only/extensions"; import { CoreReadOnlyEditorExtensions } from "src/ui/read-only/extensions";
import { CoreReadOnlyEditorProps } from "src/ui/read-only/props"; import { CoreReadOnlyEditorProps } from "src/ui/read-only/props";
import { EditorProps } from "@tiptap/pm/view"; import { EditorProps } from "@tiptap/pm/view";
import { IMentionSuggestion } from "src/types/mention-suggestion"; import { IMentionHighlight, IMentionSuggestion } from "src/types/mention-suggestion";
interface CustomReadOnlyEditorProps { interface CustomReadOnlyEditorProps {
value: string; value: string;
@ -14,8 +14,8 @@ interface CustomReadOnlyEditorProps {
id: string; id: string;
description_html: string; description_html: string;
}; };
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
mentionSuggestions?: IMentionSuggestion[]; mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
} }
export const useReadOnlyEditor = ({ export const useReadOnlyEditor = ({
@ -37,8 +37,8 @@ export const useReadOnlyEditor = ({
}, },
extensions: [ extensions: [
...CoreReadOnlyEditorExtensions({ ...CoreReadOnlyEditorExtensions({
mentionSuggestions: mentionSuggestions ?? [], mentionSuggestions: mentionSuggestions,
mentionHighlights: mentionHighlights ?? [], mentionHighlights: mentionHighlights,
}), }),
...extensions, ...extensions,
], ],

View File

@ -2,6 +2,8 @@ import { Editor, Range } from "@tiptap/react";
export type IMentionSuggestion = { export type IMentionSuggestion = {
id: string; id: string;
type: string; type: string;
entity_name: string;
entity_identifier: string;
avatar: string; avatar: string;
title: string; title: string;
subtitle: string; subtitle: string;

View File

@ -109,5 +109,9 @@ export const CoreEditorExtensions = (
TableHeader, TableHeader,
TableCell, TableCell,
TableRow, TableRow,
Mentions(mentionConfig.mentionSuggestions, mentionConfig.mentionHighlights, false), Mentions({
mentionSuggestions: mentionConfig.mentionSuggestions,
mentionHighlights: mentionConfig.mentionHighlights,
readonly: false,
}),
]; ];

View File

@ -7,11 +7,15 @@ import tippy from "tippy.js";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { MentionList } from "src/ui/mentions/mention-list"; import { MentionList } from "src/ui/mentions/mention-list";
export const Mentions = ( export const Mentions = ({
mentionSuggestions: () => Promise<IMentionSuggestion[]>, mentionHighlights,
mentionHighlights: () => Promise<IMentionHighlight[]>, mentionSuggestions,
readonly: boolean readonly,
) => }: {
mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
mentionHighlights?: () => Promise<IMentionHighlight[]>;
readonly: boolean;
}) =>
CustomMention.configure({ CustomMention.configure({
HTMLAttributes: { HTMLAttributes: {
class: "mention", class: "mention",
@ -20,7 +24,10 @@ export const Mentions = (
mentionHighlights: mentionHighlights, mentionHighlights: mentionHighlights,
suggestion: { suggestion: {
items: async ({ query }) => { items: async ({ query }) => {
const suggestions = await mentionSuggestions(); const suggestions = await mentionSuggestions?.();
if (!suggestions) {
return [];
}
const mappedSuggestions: IMentionSuggestion[] = suggestions.map((suggestion): IMentionSuggestion => { const mappedSuggestions: IMentionSuggestion[] = suggestions.map((suggestion): IMentionSuggestion => {
const transactionId = uuidv4(); const transactionId = uuidv4();
return { return {
@ -37,7 +44,7 @@ export const Mentions = (
}, },
// @ts-ignore // @ts-ignore
render: () => { render: () => {
let reactRenderer: ReactRenderer | null = null; let component: ReactRenderer | null = null;
let popup: any | null = null; let popup: any | null = null;
const hidePopup = () => { const hidePopup = () => {
@ -48,7 +55,7 @@ export const Mentions = (
if (!props.clientRect) { if (!props.clientRect) {
return; return;
} }
reactRenderer = new ReactRenderer(MentionList, { component = new ReactRenderer(MentionList, {
props, props,
editor: props.editor, editor: props.editor,
}); });
@ -57,16 +64,16 @@ export const Mentions = (
popup = tippy("body", { popup = tippy("body", {
getReferenceClientRect: props.clientRect, getReferenceClientRect: props.clientRect,
appendTo: () => document.body, appendTo: () => document.body,
content: reactRenderer.element, content: component.element,
showOnCreate: true, showOnCreate: true,
interactive: true, interactive: true,
trigger: "manual", trigger: "manual",
placement: "bottom-start", placement: "bottom-start",
}); });
// document.addEventListener("scroll", hidePopup, true); document.addEventListener("scroll", hidePopup, true);
}, },
onUpdate: (props: { editor: Editor; clientRect: DOMRect }) => { onUpdate: (props: { editor: Editor; clientRect: DOMRect }) => {
reactRenderer?.updateProps(props); component?.updateProps(props);
if (!props.clientRect) { if (!props.clientRect) {
return; return;
@ -89,7 +96,7 @@ export const Mentions = (
if (navigationKeys.includes(props.event.key)) { if (navigationKeys.includes(props.event.key)) {
// @ts-ignore // @ts-ignore
reactRenderer?.ref?.onKeyDown(props); component?.ref?.onKeyDown(props);
event?.stopPropagation(); event?.stopPropagation();
return true; return true;
} }
@ -98,9 +105,9 @@ export const Mentions = (
onExit: (props: { editor: Editor; event: KeyboardEvent }) => { onExit: (props: { editor: Editor; event: KeyboardEvent }) => {
props.editor.storage.mentionsOpen = false; props.editor.storage.mentionsOpen = false;
popup?.[0].destroy(); popup?.[0].destroy();
reactRenderer?.destroy(); component?.destroy();
// document.removeEventListener("scroll", hidePopup, true); document.removeEventListener("scroll", hidePopup, true);
}, },
}; };
}, },

View File

@ -4,15 +4,20 @@ import { IMentionSuggestion } from "src/types/mention-suggestion";
interface MentionListProps { interface MentionListProps {
items: IMentionSuggestion[]; items: IMentionSuggestion[];
command: (item: { id: string; label: string; target: string; redirect_uri: string }) => void; command: (item: {
id: string;
label: string;
entity_name: string;
entity_identifier: string;
target: string;
redirect_uri: string;
}) => void;
editor: Editor; editor: Editor;
} }
// eslint-disable-next-line react/display-name
export const MentionList = forwardRef((props: MentionListProps, ref) => { export const MentionList = forwardRef((props: MentionListProps, ref) => {
const [selectedIndex, setSelectedIndex] = useState(0); const [selectedIndex, setSelectedIndex] = useState(0);
console.log("props", props);
const selectItem = (index: number) => { const selectItem = (index: number) => {
const item = props.items[index]; const item = props.items[index];

View File

@ -9,17 +9,15 @@ import { useEffect, useState } from "react";
// eslint-disable-next-line import/no-anonymous-default-export // eslint-disable-next-line import/no-anonymous-default-export
export const MentionNodeView = (props) => { export const MentionNodeView = (props) => {
const router = useRouter(); const router = useRouter();
// const highlights = props.extension.options.mentionHighlights as IMentionHighlight[]; const [highlightsState, setHighlightsState] = useState<IMentionHighlight[]>();
const [highlightsState, setHighlightsState] = useState();
useEffect(() => { useEffect(() => {
console.log("hightlights type", props.extension.options.mentionHighlights);
const hightlights = async () => { const hightlights = async () => {
const userId = await props.extension.options.mentionHighlights(); const userId = await props.extension.options.mentionHighlights();
setHighlightsState(userId); setHighlightsState(userId);
}; };
hightlights(); hightlights();
}, []); }, [props.extension.options]);
const handleClick = () => { const handleClick = () => {
if (!props.extension.options.readonly) { if (!props.extension.options.readonly) {
@ -27,7 +25,6 @@ export const MentionNodeView = (props) => {
} }
}; };
console.log("state of highlight", highlightsState);
return ( return (
<NodeViewWrapper className="mention-component inline w-fit"> <NodeViewWrapper className="mention-component inline w-fit">
<span <span

View File

@ -15,12 +15,12 @@ import { TableRow } from "src/ui/extensions/table/table-row/table-row";
import { ReadOnlyImageExtension } from "src/ui/extensions/image/read-only-image"; import { ReadOnlyImageExtension } from "src/ui/extensions/image/read-only-image";
import { isValidHttpUrl } from "src/lib/utils"; import { isValidHttpUrl } from "src/lib/utils";
import { Mentions } from "src/ui/mentions"; import { Mentions } from "src/ui/mentions";
import { IMentionSuggestion } from "src/types/mention-suggestion"; import { IMentionHighlight, IMentionSuggestion } from "src/types/mention-suggestion";
import { CustomLinkExtension } from "src/ui/extensions/custom-link"; import { CustomLinkExtension } from "src/ui/extensions/custom-link";
export const CoreReadOnlyEditorExtensions = (mentionConfig: { export const CoreReadOnlyEditorExtensions = (mentionConfig: {
mentionSuggestions: IMentionSuggestion[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
mentionHighlights: string[]; mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
}) => [ }) => [
StarterKit.configure({ StarterKit.configure({
bulletList: { bulletList: {
@ -95,5 +95,9 @@ export const CoreReadOnlyEditorExtensions = (mentionConfig: {
TableHeader, TableHeader,
TableCell, TableCell,
TableRow, TableRow,
Mentions(mentionConfig.mentionSuggestions, mentionConfig.mentionHighlights, true), Mentions({
mentionSuggestions: mentionConfig.mentionSuggestions,
mentionHighlights: mentionConfig.mentionHighlights,
readonly: true,
}),
]; ];

View File

@ -7,6 +7,7 @@ import {
getEditorClassNames, getEditorClassNames,
useEditor, useEditor,
IMentionSuggestion, IMentionSuggestion,
IMentionHighlight,
} from "@plane/editor-core"; } from "@plane/editor-core";
import { DocumentEditorExtensions } from "src/ui/extensions"; import { DocumentEditorExtensions } from "src/ui/extensions";
import { IDuplicationConfig, IPageArchiveConfig, IPageLockConfig } from "src/types/menu-actions"; import { IDuplicationConfig, IPageArchiveConfig, IPageLockConfig } from "src/types/menu-actions";
@ -50,17 +51,14 @@ interface IDocumentEditor {
debouncedUpdatesEnabled?: boolean; debouncedUpdatesEnabled?: boolean;
isSubmitting: "submitting" | "submitted" | "saved"; isSubmitting: "submitting" | "submitted" | "saved";
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
mentionSuggestions?: IMentionSuggestion[]; mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
// embed configuration // embed configuration
duplicationConfig?: IDuplicationConfig; duplicationConfig?: IDuplicationConfig;
pageLockConfig?: IPageLockConfig; pageLockConfig?: IPageLockConfig;
pageArchiveConfig?: IPageArchiveConfig; pageArchiveConfig?: IPageArchiveConfig;
} }
interface DocumentEditorProps extends IDocumentEditor {
forwardedRef?: React.Ref<EditorHandle>;
}
interface EditorHandle { interface EditorHandle {
clearEditor: () => void; clearEditor: () => void;
@ -126,7 +124,6 @@ const DocumentEditor = ({
extensions: DocumentEditorExtensions(uploadFile, setHideDragHandleFunction, setIsSubmitting), extensions: DocumentEditorExtensions(uploadFile, setHideDragHandleFunction, setIsSubmitting),
}); });
console.log("in document editor", mentionHighlights);
if (!editor) { if (!editor) {
return null; return null;
} }

View File

@ -1,4 +1,4 @@
import { getEditorClassNames, useReadOnlyEditor } from "@plane/editor-core"; import { getEditorClassNames, IMentionHighlight, useReadOnlyEditor } from "@plane/editor-core";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useState, forwardRef, useEffect } from "react"; import { useState, forwardRef, useEffect } from "react";
import { EditorHeader } from "src/ui/components/editor-header"; import { EditorHeader } from "src/ui/components/editor-header";
@ -22,7 +22,7 @@ interface IDocumentReadOnlyEditor {
documentDetails: DocumentDetails; documentDetails: DocumentDetails;
pageLockConfig?: IPageLockConfig; pageLockConfig?: IPageLockConfig;
pageArchiveConfig?: IPageArchiveConfig; pageArchiveConfig?: IPageArchiveConfig;
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
pageDuplicationConfig?: IDuplicationConfig; pageDuplicationConfig?: IDuplicationConfig;
onActionCompleteHandler: (action: { onActionCompleteHandler: (action: {
@ -71,6 +71,7 @@ const DocumentReadOnlyEditor = ({
if (editor) { if (editor) {
updateMarkings(editor.getJSON()); updateMarkings(editor.getJSON());
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editor]); }, [editor]);
if (!editor) { if (!editor) {

View File

@ -330,7 +330,7 @@ const renderItems = () => {
appendTo: () => document.body, appendTo: () => document.body,
content: component.element, content: component.element,
showOnCreate: true, showOnCreate: true,
// interactive: true, interactive: true,
trigger: "manual", trigger: "manual",
placement: "bottom-start", placement: "bottom-start",
}); });

View File

@ -8,6 +8,7 @@ import {
EditorContentWrapper, EditorContentWrapper,
getEditorClassNames, getEditorClassNames,
useEditor, useEditor,
IMentionHighlight,
} from "@plane/editor-core"; } from "@plane/editor-core";
import { FixedMenu } from "src/ui/menus/fixed-menu"; import { FixedMenu } from "src/ui/menus/fixed-menu";
import { LiteTextEditorExtensions } from "src/ui/extensions"; import { LiteTextEditorExtensions } from "src/ui/extensions";
@ -39,8 +40,8 @@ interface ILiteTextEditor {
}; };
onEnterKeyPress?: (e?: any) => void; onEnterKeyPress?: (e?: any) => void;
cancelUploadImage?: () => any; cancelUploadImage?: () => any;
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
mentionSuggestions?: IMentionSuggestion[]; mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
submitButton?: React.ReactNode; submitButton?: React.ReactNode;
} }

View File

@ -1,5 +1,11 @@
import * as React from "react"; import * as React from "react";
import { EditorContainer, EditorContentWrapper, getEditorClassNames, useReadOnlyEditor } from "@plane/editor-core"; import {
EditorContainer,
EditorContentWrapper,
getEditorClassNames,
IMentionHighlight,
useReadOnlyEditor,
} from "@plane/editor-core";
interface ICoreReadOnlyEditor { interface ICoreReadOnlyEditor {
value: string; value: string;
@ -7,7 +13,7 @@ interface ICoreReadOnlyEditor {
noBorder?: boolean; noBorder?: boolean;
borderOnFocus?: boolean; borderOnFocus?: boolean;
customClassName?: string; customClassName?: string;
mentionHighlights: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
} }
interface EditorCoreProps extends ICoreReadOnlyEditor { interface EditorCoreProps extends ICoreReadOnlyEditor {

View File

@ -4,6 +4,7 @@ import {
EditorContainer, EditorContainer,
EditorContentWrapper, EditorContentWrapper,
getEditorClassNames, getEditorClassNames,
IMentionHighlight,
IMentionSuggestion, IMentionSuggestion,
RestoreImage, RestoreImage,
UploadImage, UploadImage,
@ -33,8 +34,8 @@ export type IRichTextEditor = {
setShouldShowAlert?: (showAlert: boolean) => void; setShouldShowAlert?: (showAlert: boolean) => void;
forwardedRef?: any; forwardedRef?: any;
debouncedUpdatesEnabled?: boolean; debouncedUpdatesEnabled?: boolean;
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
mentionSuggestions?: IMentionSuggestion[]; mentionSuggestions?: () => Promise<IMentionSuggestion[]>;
}; };
export interface RichTextEditorProps extends IRichTextEditor { export interface RichTextEditorProps extends IRichTextEditor {

View File

@ -1,5 +1,11 @@
"use client"; "use client";
import { EditorContainer, EditorContentWrapper, getEditorClassNames, useReadOnlyEditor } from "@plane/editor-core"; import {
EditorContainer,
EditorContentWrapper,
getEditorClassNames,
IMentionHighlight,
useReadOnlyEditor,
} from "@plane/editor-core";
import * as React from "react"; import * as React from "react";
interface IRichTextReadOnlyEditor { interface IRichTextReadOnlyEditor {
@ -8,7 +14,7 @@ interface IRichTextReadOnlyEditor {
noBorder?: boolean; noBorder?: boolean;
borderOnFocus?: boolean; borderOnFocus?: boolean;
customClassName?: string; customClassName?: string;
mentionHighlights?: string[]; mentionHighlights?: () => Promise<IMentionHighlight[]>;
} }
interface RichTextReadOnlyEditorProps extends IRichTextReadOnlyEditor { interface RichTextReadOnlyEditorProps extends IRichTextReadOnlyEditor {

View File

@ -48,7 +48,6 @@ export const useMention = ({ workspaceSlug, projectId }: { workspaceSlug: string
}); });
const mentionHighlights = async () => { const mentionHighlights = async () => {
console.log("isme aaya highlights");
if (!userDataLoading && userRef.current) { if (!userDataLoading && userRef.current) {
return [userRef.current.id]; return [userRef.current.id];
} else { } else {
@ -85,7 +84,6 @@ export const useMention = ({ workspaceSlug, projectId }: { workspaceSlug: string
} else { } else {
// Wait for data to be available // Wait for data to be available
const members = await waitForData(); const members = await waitForData();
console.log("isme aaya", members);
return members.map((memberDetails) => ({ return members.map((memberDetails) => ({
entity_name: "user_mention", entity_name: "user_mention",
entity_identifier: `${memberDetails?.member?.id}`, entity_identifier: `${memberDetails?.member?.id}`,