|
| 1 | +/** |
| 2 | + * Tiptap comment types have moved to a private tiptap package and we don't want to create a dependency on it. |
| 3 | + * We've extracted the types from https://github.com/ueberdosis/hocuspocus/blob/v2.15.3/packages/provider/src/types.ts |
| 4 | + * and added them here. |
| 5 | + */ |
| 6 | + |
| 7 | +export type TCollabThread<Data = any, CommentData = any> = { |
| 8 | + id: string; |
| 9 | + createdAt: number; |
| 10 | + updatedAt: number; |
| 11 | + deletedAt: number | null; |
| 12 | + resolvedAt?: string; // (new Date()).toISOString() |
| 13 | + comments: TCollabComment<CommentData>[]; |
| 14 | + deletedComments: TCollabComment<CommentData>[]; |
| 15 | + data: Data; |
| 16 | +}; |
| 17 | + |
| 18 | +export type TCollabComment<Data = any> = { |
| 19 | + id: string; |
| 20 | + createdAt: string; |
| 21 | + updatedAt: string; |
| 22 | + deletedAt?: string; |
| 23 | + data: Data; |
| 24 | + content: any; |
| 25 | +}; |
| 26 | + |
| 27 | +export type ThreadType = "archived" | "unarchived"; |
| 28 | + |
| 29 | +export type GetThreadsOptions = { |
| 30 | + /** |
| 31 | + * The types of threads to get |
| 32 | + * @default ['unarchived'] |
| 33 | + */ |
| 34 | + types?: Array<ThreadType>; |
| 35 | +}; |
| 36 | + |
| 37 | +export type DeleteCommentOptions = { |
| 38 | + /** |
| 39 | + * If `true`, the thread will also be deleted if the deleted comment was the first comment in the thread. |
| 40 | + */ |
| 41 | + deleteThread?: boolean; |
| 42 | + |
| 43 | + /** |
| 44 | + * If `true`, will remove the content of the deleted comment |
| 45 | + */ |
| 46 | + deleteContent?: boolean; |
| 47 | +}; |
| 48 | + |
| 49 | +export type DeleteThreadOptions = { |
| 50 | + /** |
| 51 | + * If `true`, will remove the comments on the thread, |
| 52 | + * otherwise will only mark the thread as deleted |
| 53 | + * and keep the comments |
| 54 | + * @default false |
| 55 | + */ |
| 56 | + deleteComments?: boolean; |
| 57 | + |
| 58 | + /** |
| 59 | + * If `true`, will forcefully remove the thread and all comments, |
| 60 | + * otherwise will only mark the thread as deleted |
| 61 | + * and keep the comments |
| 62 | + * @default false |
| 63 | + */ |
| 64 | + force?: boolean; |
| 65 | +}; |
| 66 | + |
| 67 | +export type TiptapCollabProvider = { |
| 68 | + getThread<Data, CommentData>( |
| 69 | + id: string, |
| 70 | + ): TCollabThread<Data, CommentData> | null; |
| 71 | + |
| 72 | + getThreads<Data, CommentData>( |
| 73 | + options?: GetThreadsOptions, |
| 74 | + ): TCollabThread<Data, CommentData>[]; |
| 75 | + createThread( |
| 76 | + data: Omit< |
| 77 | + TCollabThread, |
| 78 | + | "id" |
| 79 | + | "createdAt" |
| 80 | + | "updatedAt" |
| 81 | + | "deletedAt" |
| 82 | + | "comments" |
| 83 | + | "deletedComments" |
| 84 | + >, |
| 85 | + ): TCollabThread; |
| 86 | + |
| 87 | + addComment( |
| 88 | + threadId: TCollabThread["id"], |
| 89 | + data: Omit<TCollabComment, "id" | "updatedAt" | "createdAt">, |
| 90 | + ): TCollabThread; |
| 91 | + |
| 92 | + updateComment( |
| 93 | + threadId: TCollabThread["id"], |
| 94 | + commentId: TCollabComment["id"], |
| 95 | + data: Partial<Pick<TCollabComment, "data" | "content">>, |
| 96 | + ): TCollabThread; |
| 97 | + |
| 98 | + deleteComment( |
| 99 | + threadId: TCollabThread["id"], |
| 100 | + commentId: TCollabComment["id"], |
| 101 | + options?: DeleteCommentOptions, |
| 102 | + ): TCollabThread; |
| 103 | + |
| 104 | + getThreadComments( |
| 105 | + threadId: TCollabThread["id"], |
| 106 | + includeDeleted?: boolean, |
| 107 | + ): TCollabComment[] | null; |
| 108 | + |
| 109 | + getThreadComment( |
| 110 | + threadId: TCollabThread["id"], |
| 111 | + commentId: TCollabComment["id"], |
| 112 | + includeDeleted?: boolean, |
| 113 | + ): TCollabComment | null; |
| 114 | + |
| 115 | + deleteThread( |
| 116 | + id: TCollabThread["id"], |
| 117 | + options?: DeleteThreadOptions, |
| 118 | + ): TCollabThread; |
| 119 | + |
| 120 | + updateThread( |
| 121 | + id: TCollabThread["id"], |
| 122 | + data: Partial< |
| 123 | + Pick<TCollabThread, "data"> & { |
| 124 | + resolvedAt: TCollabThread["resolvedAt"] | null; |
| 125 | + } |
| 126 | + >, |
| 127 | + ): TCollabThread; |
| 128 | + |
| 129 | + watchThreads(callback: () => void): void; |
| 130 | + unwatchThreads(callback: () => void): void; |
| 131 | +}; |
0 commit comments