@blocknote/core 0.24.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/blocknote.cjs +12 -0
  2. package/dist/blocknote.cjs.map +1 -0
  3. package/dist/blocknote.js +5028 -3444
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs +2 -0
  6. package/dist/comments.cjs.map +1 -0
  7. package/dist/comments.js +593 -0
  8. package/dist/comments.js.map +1 -0
  9. package/dist/style.css +1 -1
  10. package/dist/tsconfig.tsbuildinfo +1 -1
  11. package/dist/webpack-stats.json +1 -1
  12. package/package.json +39 -26
  13. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +1022 -378
  14. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +730 -270
  15. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +3100 -1260
  16. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +438 -162
  17. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +1168 -432
  18. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +930 -378
  19. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2485 -1015
  20. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +28 -1
  21. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +1 -1
  22. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +292 -108
  23. package/src/api/blockManipulation/setupTestEnv.ts +14 -1
  24. package/src/api/blockManipulation/tables/tables.test.ts +1987 -0
  25. package/src/api/blockManipulation/tables/tables.ts +887 -0
  26. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +66 -24
  27. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +66 -24
  28. package/src/api/clipboard/__snapshots__/external/pasteImage.html +66 -24
  29. package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +66 -24
  30. package/src/api/clipboard/__snapshots__/external/pasteTable.html +132 -48
  31. package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +136 -44
  32. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +36 -14
  33. package/src/api/clipboard/toClipboard/copyExtension.ts +2 -3
  34. package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +1 -0
  35. package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +1 -0
  36. package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +1 -0
  37. package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +1 -0
  38. package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +1 -0
  39. package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +1 -0
  40. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +1 -0
  41. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +1 -0
  42. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +1 -0
  43. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +1 -0
  44. package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +4 -0
  45. package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +4 -0
  46. package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +5 -0
  47. package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +5 -0
  48. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +985 -20
  49. package/src/api/nodeConversions/blockToNode.ts +63 -20
  50. package/src/api/nodeConversions/nodeToBlock.ts +75 -13
  51. package/src/api/parsers/html/__snapshots__/parse-notion-html.json +145 -54
  52. package/src/api/testUtil/cases/defaultSchema.ts +782 -9
  53. package/src/api/testUtil/partialBlockTestUtil.ts +39 -4
  54. package/src/blocks/TableBlockContent/TableBlockContent.ts +11 -5
  55. package/src/blocks/defaultBlockTypeGuards.ts +8 -0
  56. package/src/comments/index.ts +9 -0
  57. package/src/comments/models/User.ts +8 -0
  58. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +106 -0
  59. package/src/comments/threadstore/ThreadStore.ts +134 -0
  60. package/src/comments/threadstore/ThreadStoreAuth.ts +13 -0
  61. package/src/comments/threadstore/TipTapThreadStore.ts +292 -0
  62. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +144 -0
  63. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +294 -0
  64. package/src/comments/threadstore/yjs/YjsThreadStore.ts +340 -0
  65. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +48 -0
  66. package/src/comments/threadstore/yjs/yjsHelpers.ts +121 -0
  67. package/src/comments/types.ts +117 -0
  68. package/src/editor/Block.css +16 -8
  69. package/src/editor/BlockNoteEditor.ts +269 -92
  70. package/src/editor/BlockNoteExtensions.ts +24 -1
  71. package/src/editor/BlockNoteTipTapEditor.ts +5 -1
  72. package/src/editor/editor.css +17 -0
  73. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
  74. package/src/extensions/Comments/CommentMark.ts +61 -0
  75. package/src/extensions/Comments/CommentsPlugin.ts +301 -0
  76. package/src/extensions/Comments/userstore/UserStore.ts +72 -0
  77. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +16 -10
  78. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +3 -3
  79. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +52 -0
  80. package/src/extensions/SideMenu/SideMenuPlugin.ts +22 -9
  81. package/src/extensions/TableHandles/TableHandlesPlugin.ts +409 -57
  82. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +2 -0
  83. package/src/extensions/TextColor/TextColorExtension.ts +1 -1
  84. package/src/extensions/UniqueID/UniqueID.ts +8 -3
  85. package/src/i18n/locales/ar.ts +23 -0
  86. package/src/i18n/locales/de.ts +15 -0
  87. package/src/i18n/locales/en.ts +25 -1
  88. package/src/i18n/locales/es.ts +16 -1
  89. package/src/i18n/locales/fr.ts +23 -0
  90. package/src/i18n/locales/hr.ts +18 -0
  91. package/src/i18n/locales/index.ts +1 -0
  92. package/src/i18n/locales/is.ts +24 -1
  93. package/src/i18n/locales/it.ts +21 -0
  94. package/src/i18n/locales/ja.ts +23 -0
  95. package/src/i18n/locales/ko.ts +23 -0
  96. package/src/i18n/locales/nl.ts +23 -0
  97. package/src/i18n/locales/no.ts +346 -0
  98. package/src/i18n/locales/pl.ts +23 -0
  99. package/src/i18n/locales/pt.ts +23 -0
  100. package/src/i18n/locales/ru.ts +23 -0
  101. package/src/i18n/locales/uk.ts +23 -0
  102. package/src/i18n/locales/vi.ts +23 -0
  103. package/src/i18n/locales/zh.ts +23 -0
  104. package/src/index.ts +6 -4
  105. package/src/schema/blocks/types.ts +32 -2
  106. package/src/util/browser.ts +1 -1
  107. package/src/util/table.ts +107 -0
  108. package/types/src/api/blockManipulation/tables/tables.d.ts +343 -0
  109. package/types/src/api/blockManipulation/tables/tables.test.d.ts +1 -0
  110. package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +1 -1
  111. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +1 -2
  112. package/types/src/blocks/defaultBlockTypeGuards.d.ts +3 -0
  113. package/types/src/comments/index.d.ts +9 -0
  114. package/types/src/comments/models/User.d.ts +8 -0
  115. package/types/src/comments/threadstore/DefaultThreadStoreAuth.d.ts +47 -0
  116. package/types/src/comments/threadstore/ThreadStore.d.ts +121 -0
  117. package/types/src/comments/threadstore/ThreadStoreAuth.d.ts +12 -0
  118. package/types/src/comments/threadstore/TipTapThreadStore.d.ts +97 -0
  119. package/types/src/comments/threadstore/yjs/RESTYjsThreadStore.d.ts +83 -0
  120. package/types/src/comments/threadstore/yjs/YjsThreadStore.d.ts +79 -0
  121. package/types/src/comments/threadstore/yjs/YjsThreadStore.test.d.ts +1 -0
  122. package/types/src/comments/threadstore/yjs/YjsThreadStoreBase.d.ts +15 -0
  123. package/types/src/comments/threadstore/yjs/yjsHelpers.d.ts +13 -0
  124. package/types/src/comments/types.d.ts +109 -0
  125. package/types/src/editor/BlockNoteEditor.d.ts +146 -66
  126. package/types/src/editor/BlockNoteExtensions.d.ts +4 -0
  127. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +1 -1
  128. package/types/src/extensions/Comments/CommentMark.d.ts +2 -0
  129. package/types/src/extensions/Comments/CommentsPlugin.d.ts +49 -0
  130. package/types/src/extensions/Comments/userstore/UserStore.d.ts +31 -0
  131. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +1 -1
  132. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +15 -0
  133. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +1 -0
  134. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +66 -1
  135. package/types/src/i18n/locales/de.d.ts +15 -0
  136. package/types/src/i18n/locales/en.d.ts +20 -0
  137. package/types/src/i18n/locales/es.d.ts +15 -0
  138. package/types/src/i18n/locales/hr.d.ts +18 -0
  139. package/types/src/i18n/locales/index.d.ts +1 -0
  140. package/types/src/i18n/locales/it.d.ts +21 -0
  141. package/types/src/i18n/locales/no.d.ts +2 -0
  142. package/types/src/index.d.ts +5 -4
  143. package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
  144. package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
  145. package/types/src/schema/blocks/types.d.ts +23 -2
  146. package/types/src/util/browser.d.ts +1 -1
  147. package/types/src/util/table.d.ts +12 -0
  148. package/dist/blocknote.umd.cjs +0 -11
  149. package/dist/blocknote.umd.cjs.map +0 -1
@@ -0,0 +1,121 @@
1
+ import { CommentBody, CommentData, ThreadData } from "../types.js";
2
+ import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
3
+ /**
4
+ * ThreadStore is an abstract class that defines the interface
5
+ * to read / add / update / delete threads and comments.
6
+ */
7
+ export declare abstract class ThreadStore {
8
+ readonly auth: ThreadStoreAuth;
9
+ constructor(auth: ThreadStoreAuth);
10
+ /**
11
+ * A "thread" in the ThreadStore only contains information about the content
12
+ * of the thread / comments. It does not contain information about the position.
13
+ *
14
+ * This function can be implemented to store the thread in the document (by creating a mark)
15
+ * If not implemented, default behavior will apply (creating the mark via TipTap)
16
+ * See CommentsPlugin.ts for more details.
17
+ */
18
+ abstract addThreadToDocument?(options: {
19
+ threadId: string;
20
+ selection: {
21
+ prosemirror: {
22
+ head: number;
23
+ anchor: number;
24
+ };
25
+ yjs: {
26
+ head: any;
27
+ anchor: any;
28
+ };
29
+ };
30
+ }): Promise<void>;
31
+ /**
32
+ * Creates a new thread with an initial comment.
33
+ */
34
+ abstract createThread(options: {
35
+ initialComment: {
36
+ body: CommentBody;
37
+ metadata?: any;
38
+ };
39
+ metadata?: any;
40
+ }): Promise<ThreadData>;
41
+ /**
42
+ * Adds a comment to a thread.
43
+ */
44
+ abstract addComment(options: {
45
+ comment: {
46
+ body: CommentBody;
47
+ metadata?: any;
48
+ };
49
+ threadId: string;
50
+ }): Promise<CommentData>;
51
+ /**
52
+ * Updates a comment in a thread.
53
+ */
54
+ abstract updateComment(options: {
55
+ comment: {
56
+ body: CommentBody;
57
+ metadata?: any;
58
+ };
59
+ threadId: string;
60
+ commentId: string;
61
+ }): Promise<void>;
62
+ /**
63
+ * Deletes a comment from a thread.
64
+ */
65
+ abstract deleteComment(options: {
66
+ threadId: string;
67
+ commentId: string;
68
+ }): Promise<void>;
69
+ /**
70
+ * Deletes a thread.
71
+ */
72
+ abstract deleteThread(options: {
73
+ threadId: string;
74
+ }): Promise<void>;
75
+ /**
76
+ * Marks a thread as resolved.
77
+ */
78
+ abstract resolveThread(options: {
79
+ threadId: string;
80
+ }): Promise<void>;
81
+ /**
82
+ * Marks a thread as unresolved.
83
+ */
84
+ abstract unresolveThread(options: {
85
+ threadId: string;
86
+ }): Promise<void>;
87
+ /**
88
+ * Adds a reaction to a comment.
89
+ *
90
+ * Auth: should be possible by anyone with comment access
91
+ */
92
+ abstract addReaction(options: {
93
+ threadId: string;
94
+ commentId: string;
95
+ emoji: string;
96
+ }): Promise<void>;
97
+ /**
98
+ * Deletes a reaction from a comment.
99
+ *
100
+ * Auth: should be possible by the reaction author
101
+ */
102
+ abstract deleteReaction(options: {
103
+ threadId: string;
104
+ commentId: string;
105
+ emoji: string;
106
+ }): Promise<void>;
107
+ /**
108
+ * Retrieve data for a specific thread.
109
+ */
110
+ abstract getThread(threadId: string): ThreadData;
111
+ /**
112
+ * Retrieve all threads.
113
+ */
114
+ abstract getThreads(): Map<string, ThreadData>;
115
+ /**
116
+ * Subscribe to changes in the thread store.
117
+ *
118
+ * @returns a function to unsubscribe from the thread store
119
+ */
120
+ abstract subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void;
121
+ }
@@ -0,0 +1,12 @@
1
+ import { CommentData, ThreadData } from "../types.js";
2
+ export declare abstract class ThreadStoreAuth {
3
+ abstract canCreateThread(): boolean;
4
+ abstract canAddComment(thread: ThreadData): boolean;
5
+ abstract canUpdateComment(comment: CommentData): boolean;
6
+ abstract canDeleteComment(comment: CommentData): boolean;
7
+ abstract canDeleteThread(thread: ThreadData): boolean;
8
+ abstract canResolveThread(thread: ThreadData): boolean;
9
+ abstract canUnresolveThread(thread: ThreadData): boolean;
10
+ abstract canAddReaction(comment: CommentData, emoji?: string): boolean;
11
+ abstract canDeleteReaction(comment: CommentData, emoji?: string): boolean;
12
+ }
@@ -0,0 +1,97 @@
1
+ import type { TiptapCollabProvider } from "@hocuspocus/provider";
2
+ import { CommentBody, ThreadData } from "../types.js";
3
+ import { ThreadStore } from "./ThreadStore.js";
4
+ import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
5
+ /**
6
+ * The `TiptapThreadStore` integrates with Tiptap's collaboration provider for comment management.
7
+ * You can pass a `TiptapCollabProvider` to the constructor which takes care of storing the comments.
8
+ *
9
+ * Under the hood, this actually works similarly to the `YjsThreadStore` implementation. (comments are stored in the Yjs document)
10
+ */
11
+ export declare class TiptapThreadStore extends ThreadStore {
12
+ private readonly userId;
13
+ private readonly provider;
14
+ constructor(userId: string, provider: TiptapCollabProvider, auth: ThreadStoreAuth);
15
+ /**
16
+ * Creates a new thread with an initial comment.
17
+ */
18
+ createThread(options: {
19
+ initialComment: {
20
+ body: CommentBody;
21
+ metadata?: any;
22
+ };
23
+ metadata?: any;
24
+ }): Promise<ThreadData>;
25
+ addThreadToDocument: undefined;
26
+ /**
27
+ * Adds a comment to a thread.
28
+ */
29
+ addComment(options: {
30
+ comment: {
31
+ body: CommentBody;
32
+ metadata?: any;
33
+ };
34
+ threadId: string;
35
+ }): Promise<CommentBody>;
36
+ /**
37
+ * Updates a comment in a thread.
38
+ */
39
+ updateComment(options: {
40
+ comment: {
41
+ body: CommentBody;
42
+ metadata?: any;
43
+ };
44
+ threadId: string;
45
+ commentId: string;
46
+ }): Promise<void>;
47
+ private tiptapCommentToCommentData;
48
+ private tiptapThreadToThreadData;
49
+ /**
50
+ * Deletes a comment from a thread.
51
+ */
52
+ deleteComment(options: {
53
+ threadId: string;
54
+ commentId: string;
55
+ }): Promise<void>;
56
+ /**
57
+ * Deletes a thread.
58
+ */
59
+ deleteThread(options: {
60
+ threadId: string;
61
+ }): Promise<void>;
62
+ /**
63
+ * Marks a thread as resolved.
64
+ */
65
+ resolveThread(options: {
66
+ threadId: string;
67
+ }): Promise<void>;
68
+ /**
69
+ * Marks a thread as unresolved.
70
+ */
71
+ unresolveThread(options: {
72
+ threadId: string;
73
+ }): Promise<void>;
74
+ /**
75
+ * Adds a reaction to a comment.
76
+ *
77
+ * Auth: should be possible by anyone with comment access
78
+ */
79
+ addReaction(options: {
80
+ threadId: string;
81
+ commentId: string;
82
+ emoji: string;
83
+ }): Promise<void>;
84
+ /**
85
+ * Deletes a reaction from a comment.
86
+ *
87
+ * Auth: should be possible by the reaction author
88
+ */
89
+ deleteReaction(options: {
90
+ threadId: string;
91
+ commentId: string;
92
+ emoji: string;
93
+ }): Promise<void>;
94
+ getThread(threadId: string): ThreadData;
95
+ getThreads(): Map<string, ThreadData>;
96
+ subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void;
97
+ }
@@ -0,0 +1,83 @@
1
+ import * as Y from "yjs";
2
+ import { CommentBody } from "../../types.js";
3
+ import { ThreadStoreAuth } from "../ThreadStoreAuth.js";
4
+ import { YjsThreadStoreBase } from "./YjsThreadStoreBase.js";
5
+ /**
6
+ * This is a REST-based implementation of the YjsThreadStoreBase.
7
+ * It Reads data directly from the underlying document (same as YjsThreadStore),
8
+ * but for Writes, it sends data to a REST API that should:
9
+ * - check the user has the correct permissions to make the desired changes
10
+ * - apply the updates to the underlying Yjs document
11
+ *
12
+ * (see https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus)
13
+ *
14
+ * The reason we still use the Yjs document as underlying storage is that it makes it easy to
15
+ * sync updates in real-time to other collaborators.
16
+ * (but technically, you could also implement a different storage altogether
17
+ * and not store the thread related data in the Yjs document)
18
+ */
19
+ export declare class RESTYjsThreadStore extends YjsThreadStoreBase {
20
+ private readonly BASE_URL;
21
+ private readonly headers;
22
+ constructor(BASE_URL: string, headers: Record<string, string>, threadsYMap: Y.Map<any>, auth: ThreadStoreAuth);
23
+ private doRequest;
24
+ addThreadToDocument: (options: {
25
+ threadId: string;
26
+ selection: {
27
+ prosemirror: {
28
+ head: number;
29
+ anchor: number;
30
+ };
31
+ yjs: {
32
+ head: any;
33
+ anchor: any;
34
+ };
35
+ };
36
+ }) => Promise<any>;
37
+ createThread: (options: {
38
+ initialComment: {
39
+ body: CommentBody;
40
+ metadata?: any;
41
+ };
42
+ metadata?: any;
43
+ }) => Promise<any>;
44
+ addComment: (options: {
45
+ comment: {
46
+ body: CommentBody;
47
+ metadata?: any;
48
+ };
49
+ threadId: string;
50
+ }) => Promise<any>;
51
+ updateComment: (options: {
52
+ comment: {
53
+ body: CommentBody;
54
+ metadata?: any;
55
+ };
56
+ threadId: string;
57
+ commentId: string;
58
+ }) => Promise<any>;
59
+ deleteComment: (options: {
60
+ threadId: string;
61
+ commentId: string;
62
+ softDelete?: boolean;
63
+ }) => Promise<any>;
64
+ deleteThread: (options: {
65
+ threadId: string;
66
+ }) => Promise<any>;
67
+ resolveThread: (options: {
68
+ threadId: string;
69
+ }) => Promise<any>;
70
+ unresolveThread: (options: {
71
+ threadId: string;
72
+ }) => Promise<any>;
73
+ addReaction: (options: {
74
+ threadId: string;
75
+ commentId: string;
76
+ emoji: string;
77
+ }) => Promise<any>;
78
+ deleteReaction: (options: {
79
+ threadId: string;
80
+ commentId: string;
81
+ emoji: string;
82
+ }) => Promise<any>;
83
+ }
@@ -0,0 +1,79 @@
1
+ import * as Y from "yjs";
2
+ import { CommentBody, ThreadData } from "../../types.js";
3
+ import { ThreadStoreAuth } from "../ThreadStoreAuth.js";
4
+ import { YjsThreadStoreBase } from "./YjsThreadStoreBase.js";
5
+ /**
6
+ * This is a Yjs-based implementation of the ThreadStore interface.
7
+ *
8
+ * It reads and writes thread / comments information directly to the underlying Yjs Document.
9
+ *
10
+ * @important While this is the easiest to add to your app, there are two challenges:
11
+ * - The user needs to be able to write to the Yjs document to store the information.
12
+ * So a user without write access to the Yjs document cannot leave any comments.
13
+ * - Even with write access, the operations are not secure. Unless your Yjs server
14
+ * guards against malicious operations, it's technically possible for one user to make changes to another user's comments, etc.
15
+ * (even though these options are not visible in the UI, a malicious user can make unauthorized changes to the underlying Yjs document)
16
+ */
17
+ export declare class YjsThreadStore extends YjsThreadStoreBase {
18
+ private readonly userId;
19
+ constructor(userId: string, threadsYMap: Y.Map<any>, auth: ThreadStoreAuth);
20
+ private transact;
21
+ createThread: (options: {
22
+ initialComment: {
23
+ body: CommentBody;
24
+ metadata?: any;
25
+ };
26
+ metadata?: any;
27
+ }) => Promise<ThreadData>;
28
+ addThreadToDocument: undefined;
29
+ addComment: (options: {
30
+ comment: {
31
+ body: CommentBody;
32
+ metadata?: any;
33
+ };
34
+ threadId: string;
35
+ }) => Promise<{
36
+ type: "comment";
37
+ id: string;
38
+ userId: string;
39
+ createdAt: Date;
40
+ updatedAt: Date;
41
+ reactions: import("../../types.js").CommentReactionData[];
42
+ metadata: any;
43
+ } & {
44
+ deletedAt?: undefined;
45
+ body: any;
46
+ }>;
47
+ updateComment: (options: {
48
+ comment: {
49
+ body: CommentBody;
50
+ metadata?: any;
51
+ };
52
+ threadId: string;
53
+ commentId: string;
54
+ }) => Promise<void>;
55
+ deleteComment: (options: {
56
+ threadId: string;
57
+ commentId: string;
58
+ softDelete?: boolean | undefined;
59
+ }) => Promise<void>;
60
+ deleteThread: (options: {
61
+ threadId: string;
62
+ }) => Promise<void>;
63
+ resolveThread: (options: {
64
+ threadId: string;
65
+ }) => Promise<void>;
66
+ unresolveThread: (options: {
67
+ threadId: string;
68
+ }) => Promise<void>;
69
+ addReaction: (options: {
70
+ threadId: string;
71
+ commentId: string;
72
+ emoji: string;
73
+ }) => Promise<void>;
74
+ deleteReaction: (options: {
75
+ threadId: string;
76
+ commentId: string;
77
+ emoji: string;
78
+ }) => Promise<void>;
79
+ }
@@ -0,0 +1,15 @@
1
+ import * as Y from "yjs";
2
+ import { ThreadData } from "../../types.js";
3
+ import { ThreadStore } from "../ThreadStore.js";
4
+ import { ThreadStoreAuth } from "../ThreadStoreAuth.js";
5
+ /**
6
+ * This is an abstract class that only implements the READ methods required by the ThreadStore interface.
7
+ * The data is read from a Yjs Map.
8
+ */
9
+ export declare abstract class YjsThreadStoreBase extends ThreadStore {
10
+ protected readonly threadsYMap: Y.Map<any>;
11
+ constructor(threadsYMap: Y.Map<any>, auth: ThreadStoreAuth);
12
+ getThread(threadId: string): ThreadData;
13
+ getThreads(): Map<string, ThreadData>;
14
+ subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void;
15
+ }
@@ -0,0 +1,13 @@
1
+ import * as Y from "yjs";
2
+ import { CommentData, ThreadData } from "../../types.js";
3
+ export declare function commentToYMap(comment: CommentData): Y.Map<any>;
4
+ export declare function threadToYMap(thread: ThreadData): Y.Map<unknown>;
5
+ type SingleUserCommentReactionData = {
6
+ emoji: string;
7
+ createdAt: Date;
8
+ userId: string;
9
+ };
10
+ export declare function yMapToReaction(yMap: Y.Map<any>): SingleUserCommentReactionData;
11
+ export declare function yMapToComment(yMap: Y.Map<any>): CommentData;
12
+ export declare function yMapToThread(yMap: Y.Map<any>): ThreadData;
13
+ export {};
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The body of a comment. This actually is a BlockNote document (array of blocks)
3
+ */
4
+ export type CommentBody = any;
5
+ /**
6
+ * A reaction to a comment.
7
+ */
8
+ export type CommentReactionData = {
9
+ /**
10
+ * The emoji that was reacted to the comment.
11
+ */
12
+ emoji: string;
13
+ /**
14
+ * The date the first user reacted to the comment with this emoji.
15
+ */
16
+ createdAt: Date;
17
+ /**
18
+ * The user ids of the users that have reacted to the comment with this emoji
19
+ */
20
+ userIds: string[];
21
+ };
22
+ /**
23
+ * Information about a comment.
24
+ */
25
+ export type CommentData = {
26
+ type: "comment";
27
+ /**
28
+ * The unique identifier for the comment.
29
+ */
30
+ id: string;
31
+ /**
32
+ * The user id of the author of the comment.
33
+ */
34
+ userId: string;
35
+ /**
36
+ * The date when the comment was created.
37
+ */
38
+ createdAt: Date;
39
+ /**
40
+ * The date when the comment was last updated.
41
+ */
42
+ updatedAt: Date;
43
+ /**
44
+ * The reactions (emoji reactions) to the comment.
45
+ */
46
+ reactions: CommentReactionData[];
47
+ /**
48
+ * You can use this store any additional information about the comment.
49
+ */
50
+ metadata: any;
51
+ } & ({
52
+ /**
53
+ * The date when the comment was deleted. This applies only for "soft deletes",
54
+ * otherwise the comment is removed entirely.
55
+ */
56
+ deletedAt: Date;
57
+ /**
58
+ * The body of the comment is undefined if the comment is deleted.
59
+ */
60
+ body: undefined;
61
+ } | {
62
+ /**
63
+ * In case of a non-deleted comment, this is not set
64
+ */
65
+ deletedAt?: never;
66
+ /**
67
+ * The body of the comment.
68
+ */
69
+ body: CommentBody;
70
+ });
71
+ /**
72
+ * Information about a thread. A thread holds a list of comments.
73
+ */
74
+ export type ThreadData = {
75
+ type: "thread";
76
+ /**
77
+ * The unique identifier for the thread.
78
+ */
79
+ id: string;
80
+ /**
81
+ * The date when the thread was created.
82
+ */
83
+ createdAt: Date;
84
+ /**
85
+ * The date when the thread was last updated.
86
+ */
87
+ updatedAt: Date;
88
+ /**
89
+ * The comments in the thread.
90
+ */
91
+ comments: CommentData[];
92
+ /**
93
+ * Whether the thread has been marked as resolved.
94
+ */
95
+ resolved: boolean;
96
+ /**
97
+ * The date when the thread was marked as resolved.
98
+ */
99
+ resolvedUpdatedAt?: Date;
100
+ /**
101
+ * You can use this store any additional information about the thread.
102
+ */
103
+ metadata: any;
104
+ /**
105
+ * The date when the thread was deleted. (or undefined if it is not deleted)
106
+ * This only applies for "soft deletes", otherwise the thread is removed entirely.
107
+ */
108
+ deletedAt?: Date;
109
+ };