diff --git a/editor/package-lock.json b/editor/package-lock.json index eabb190..51ba1f5 100644 --- a/editor/package-lock.json +++ b/editor/package-lock.json @@ -98,6 +98,7 @@ "@types/node": "20.9.4", "@types/react": "18.2.38", "@types/react-dom": "^18", + "@types/uuid": "^9.0.7", "autoprefixer": "^10.0.1", "eslint": "^8", "eslint-config-next": "14.0.3", @@ -8040,6 +8041,12 @@ "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==", "dev": true }, + "node_modules/@types/uuid": { + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz", + "integrity": "sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==", + "dev": true + }, "node_modules/@types/yargs": { "version": "17.0.32", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", diff --git a/editor/package.json b/editor/package.json index 0f0c7d4..6d24ed4 100644 --- a/editor/package.json +++ b/editor/package.json @@ -113,6 +113,7 @@ "@types/node": "20.9.4", "@types/react": "18.2.38", "@types/react-dom": "^18", + "@types/uuid": "^9.0.7", "autoprefixer": "^10.0.1", "eslint": "^8", "eslint-config-next": "14.0.3", diff --git a/editor/src/components/editor/comment.tsx b/editor/src/components/editor/comment.tsx new file mode 100644 index 0000000..9915503 --- /dev/null +++ b/editor/src/components/editor/comment.tsx @@ -0,0 +1,17 @@ +import { v4 } from 'uuid' + +export interface Comment { + id: string + content: string + replies: Comment[] + createdAt: Date +} + +export const getNewComment = (content: string): Comment => { + return { + id: `a${v4()}a`, + content, + replies: [], + createdAt: new Date() + } +} diff --git a/editor/src/components/editor/intelli/advice-extension.ts b/editor/src/components/editor/intelli/advice-extension.ts index 328bdb5..0754a63 100644 --- a/editor/src/components/editor/intelli/advice-extension.ts +++ b/editor/src/components/editor/intelli/advice-extension.ts @@ -2,11 +2,12 @@ import { Mark, mergeAttributes, Range } from "@tiptap/core"; import { Mark as PMMark } from "@tiptap/pm/model"; import { CommandProps } from "@tiptap/react"; +import { Comment } from "../comment"; declare module "@tiptap/core" { interface Commands { advice: { - setAdviceCommand: (advice: string) => ReturnType; + setAdviceCommand: (newComment: Comment) => ReturnType; setAdvice: (commentId: string) => ReturnType; unsetAdvice: (commentId: string) => ReturnType; }; @@ -19,7 +20,7 @@ export interface MarkWithRange { } export interface CommentOptions { - setAdviceCommand: (advice: string) => void; + setAdviceCommand: (comment: Comment) => void; HTMLAttributes: Record; onAdviceActivated: (commentId: string | null) => void; } @@ -36,7 +37,7 @@ export const AdviceExtension = Mark.create({ addOptions() { return { - setAdviceCommand: (advice: string) => { + setAdviceCommand: (comment: Comment) => { }, HTMLAttributes: {}, onAdviceActivated: () => { @@ -97,8 +98,8 @@ export const AdviceExtension = Mark.create({ // @ts-ignore addCommands() { return { - setAdviceCommand: (advice: string) => ({ commands }: CommandProps) => { - this.options.setAdviceCommand(advice); + setAdviceCommand: (comment: Comment) => ({ commands }: CommandProps) => { + this.options.setAdviceCommand(comment); }, setAdvice: (commentId) => ({ commands }) => { if (!commentId) return false; diff --git a/editor/src/components/editor/intelli/menu/menu-bubble.tsx b/editor/src/components/editor/intelli/menu/menu-bubble.tsx index 048281d..f997ca2 100644 --- a/editor/src/components/editor/intelli/menu/menu-bubble.tsx +++ b/editor/src/components/editor/intelli/menu/menu-bubble.tsx @@ -6,6 +6,7 @@ import { Editor } from "@tiptap/core"; import { CookieIcon } from "@radix-ui/react-icons"; import { ActionExecutor } from "@/components/editor/action/ActionExecutor"; import { Button, DropdownMenu } from "@radix-ui/themes"; +import { getNewComment } from '../../comment'; export const MenuBubble = ({ editor }: { editor: Editor @@ -101,7 +102,9 @@ export const MenuBubble = ({ editor }: { variant="outline" key={index} onClick={() => { - editor.commands?.setAdviceCommand("TODO, we are working on it") + const newComment = getNewComment("TODO, we are working on it") + editor.commands?.setAdvice(newComment.id) + editor.commands?.setAdviceCommand(newComment) menu.action?.(editor) }} > diff --git a/editor/src/components/editor/live-editor.tsx b/editor/src/components/editor/live-editor.tsx index 3ddf33f..d453175 100644 --- a/editor/src/components/editor/live-editor.tsx +++ b/editor/src/components/editor/live-editor.tsx @@ -7,7 +7,6 @@ import TextStyle from '@tiptap/extension-text-style' import StarterKit from '@tiptap/starter-kit' import { CharacterCount } from "@tiptap/extension-character-count"; import { useTranslation } from "react-i18next"; -import { v4 } from 'uuid' import MarkdownIt from 'markdown-it' import { useDebounce } from 'use-debounce'; @@ -24,26 +23,10 @@ import { CommandFunctions } from './action/command-functions' import { Sidebar } from './sidebar' import "./editor.css" +import { Comment } from "@/components/editor/comment"; const md = new MarkdownIt() - -interface Comment { - id: string - content: string - replies: Comment[] - createdAt: Date -} - -const getNewComment = (content: string): Comment => { - return { - id: `a${v4()}a`, - content, - replies: [], - createdAt: new Date() - } -} - const LiveEditor = () => { const { t, i18n } = useTranslation(); @@ -72,11 +55,9 @@ const LiveEditor = () => { HTMLAttributes: { class: "my-advice", }, - setAdviceCommand: (advice: string) => { - const newComment = getNewComment(advice) - setComments([...comments, newComment]) - editor?.commands.setAdvice(newComment.id) - setActiveCommentId(newComment.id) + setAdviceCommand: (comment: Comment) => { + setComments([...comments, comment]) + setActiveCommentId(comment.id) setTimeout(focusCommentWithActiveId) }, onAdviceActivated: (commentId) => {