@blocknote/core 0.24.2 → 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.
- package/dist/blocknote.cjs +12 -0
- package/dist/blocknote.cjs.map +1 -0
- package/dist/blocknote.js +4754 -3514
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs +2 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.js +593 -0
- package/dist/comments.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +39 -26
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +1022 -378
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +730 -270
- package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +3100 -1260
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +438 -162
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +1168 -432
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +930 -378
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2485 -1015
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +28 -1
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +1 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +292 -108
- package/src/api/blockManipulation/setupTestEnv.ts +14 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1987 -0
- package/src/api/blockManipulation/tables/tables.ts +887 -0
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteImage.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +66 -24
- package/src/api/clipboard/__snapshots__/external/pasteTable.html +132 -48
- package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +136 -44
- package/src/api/clipboard/toClipboard/copyExtension.ts +2 -3
- package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +1 -0
- package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +4 -0
- package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +4 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +5 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +985 -20
- package/src/api/nodeConversions/blockToNode.ts +63 -20
- package/src/api/nodeConversions/nodeToBlock.ts +75 -13
- package/src/api/parsers/html/__snapshots__/parse-notion-html.json +145 -54
- package/src/api/testUtil/cases/defaultSchema.ts +782 -9
- package/src/api/testUtil/partialBlockTestUtil.ts +39 -4
- package/src/blocks/TableBlockContent/TableBlockContent.ts +11 -5
- package/src/blocks/defaultBlockTypeGuards.ts +8 -0
- package/src/comments/index.ts +9 -0
- package/src/comments/models/User.ts +8 -0
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +106 -0
- package/src/comments/threadstore/ThreadStore.ts +134 -0
- package/src/comments/threadstore/ThreadStoreAuth.ts +13 -0
- package/src/comments/threadstore/TipTapThreadStore.ts +292 -0
- package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +144 -0
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +294 -0
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +340 -0
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +48 -0
- package/src/comments/threadstore/yjs/yjsHelpers.ts +121 -0
- package/src/comments/types.ts +117 -0
- package/src/editor/Block.css +16 -8
- package/src/editor/BlockNoteEditor.ts +269 -92
- package/src/editor/BlockNoteExtensions.ts +24 -1
- package/src/editor/BlockNoteTipTapEditor.ts +5 -1
- package/src/editor/editor.css +17 -0
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
- package/src/extensions/Comments/CommentMark.ts +61 -0
- package/src/extensions/Comments/CommentsPlugin.ts +301 -0
- package/src/extensions/Comments/userstore/UserStore.ts +72 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +9 -5
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +3 -3
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +52 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +409 -57
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +2 -0
- package/src/extensions/TextColor/TextColorExtension.ts +1 -1
- package/src/i18n/locales/ar.ts +23 -0
- package/src/i18n/locales/de.ts +15 -0
- package/src/i18n/locales/en.ts +25 -1
- package/src/i18n/locales/es.ts +16 -1
- package/src/i18n/locales/fr.ts +23 -0
- package/src/i18n/locales/hr.ts +18 -0
- package/src/i18n/locales/is.ts +24 -1
- package/src/i18n/locales/it.ts +15 -0
- package/src/i18n/locales/ja.ts +23 -0
- package/src/i18n/locales/ko.ts +23 -0
- package/src/i18n/locales/nl.ts +23 -0
- package/src/i18n/locales/no.ts +23 -0
- package/src/i18n/locales/pl.ts +23 -0
- package/src/i18n/locales/pt.ts +23 -0
- package/src/i18n/locales/ru.ts +23 -0
- package/src/i18n/locales/uk.ts +23 -0
- package/src/i18n/locales/vi.ts +23 -0
- package/src/i18n/locales/zh.ts +23 -0
- package/src/index.ts +6 -4
- package/src/schema/blocks/types.ts +32 -2
- package/src/util/browser.ts +1 -1
- package/src/util/table.ts +107 -0
- package/types/src/api/blockManipulation/tables/tables.d.ts +343 -0
- package/types/src/api/blockManipulation/tables/tables.test.d.ts +1 -0
- package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +1 -1
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +1 -2
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +3 -0
- package/types/src/comments/index.d.ts +9 -0
- package/types/src/comments/models/User.d.ts +8 -0
- package/types/src/comments/threadstore/DefaultThreadStoreAuth.d.ts +47 -0
- package/types/src/comments/threadstore/ThreadStore.d.ts +121 -0
- package/types/src/comments/threadstore/ThreadStoreAuth.d.ts +12 -0
- package/types/src/comments/threadstore/TipTapThreadStore.d.ts +97 -0
- package/types/src/comments/threadstore/yjs/RESTYjsThreadStore.d.ts +83 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStore.d.ts +79 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStore.test.d.ts +1 -0
- package/types/src/comments/threadstore/yjs/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/comments/threadstore/yjs/yjsHelpers.d.ts +13 -0
- package/types/src/comments/types.d.ts +109 -0
- package/types/src/editor/BlockNoteEditor.d.ts +146 -66
- package/types/src/editor/BlockNoteExtensions.d.ts +4 -0
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +1 -1
- package/types/src/extensions/Comments/CommentMark.d.ts +2 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +49 -0
- package/types/src/extensions/Comments/userstore/UserStore.d.ts +31 -0
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +15 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +66 -1
- package/types/src/i18n/locales/de.d.ts +15 -0
- package/types/src/i18n/locales/en.d.ts +20 -0
- package/types/src/i18n/locales/es.d.ts +15 -0
- package/types/src/i18n/locales/hr.d.ts +18 -0
- package/types/src/i18n/locales/it.d.ts +15 -0
- package/types/src/index.d.ts +5 -4
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
- package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
- package/types/src/schema/blocks/types.d.ts +23 -2
- package/types/src/util/browser.d.ts +1 -1
- package/types/src/util/table.d.ts +12 -0
- package/dist/blocknote.umd.cjs +0 -11
- package/dist/blocknote.umd.cjs.map +0 -1
package/dist/comments.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var A = (d, r, e) => r in d ? p(d, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[r] = e;
|
|
3
|
+
var n = (d, r, e) => A(d, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
import * as T from "yjs";
|
|
5
|
+
import { v4 as I } from "uuid";
|
|
6
|
+
class y {
|
|
7
|
+
}
|
|
8
|
+
class b extends y {
|
|
9
|
+
constructor(r, e) {
|
|
10
|
+
super(), this.userId = r, this.role = e;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Auth: should be possible by anyone with comment access
|
|
14
|
+
*/
|
|
15
|
+
canCreateThread() {
|
|
16
|
+
return !0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Auth: should be possible by anyone with comment access
|
|
20
|
+
*/
|
|
21
|
+
canAddComment(r) {
|
|
22
|
+
return !0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Auth: should only be possible by the comment author
|
|
26
|
+
*/
|
|
27
|
+
canUpdateComment(r) {
|
|
28
|
+
return r.userId === this.userId;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Auth: should be possible by the comment author OR an editor of the document
|
|
32
|
+
*/
|
|
33
|
+
canDeleteComment(r) {
|
|
34
|
+
return r.userId === this.userId || this.role === "editor";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Auth: should only be possible by an editor of the document
|
|
38
|
+
*/
|
|
39
|
+
canDeleteThread(r) {
|
|
40
|
+
return this.role === "editor";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Auth: should be possible by anyone with comment access
|
|
44
|
+
*/
|
|
45
|
+
canResolveThread(r) {
|
|
46
|
+
return !0;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Auth: should be possible by anyone with comment access
|
|
50
|
+
*/
|
|
51
|
+
canUnresolveThread(r) {
|
|
52
|
+
return !0;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Auth: should be possible by anyone with comment access
|
|
56
|
+
*
|
|
57
|
+
* Note: will also check if the user has already reacted with the same emoji. TBD: is that a nice design or should this responsibility be outside of auth?
|
|
58
|
+
*/
|
|
59
|
+
canAddReaction(r, e) {
|
|
60
|
+
return e ? !r.reactions.some(
|
|
61
|
+
(t) => t.emoji === e && t.userIds.includes(this.userId)
|
|
62
|
+
) : !0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Auth: should be possible by anyone with comment access
|
|
66
|
+
*
|
|
67
|
+
* Note: will also check if the user has already reacted with the same emoji. TBD: is that a nice design or should this responsibility be outside of auth?
|
|
68
|
+
*/
|
|
69
|
+
canDeleteReaction(r, e) {
|
|
70
|
+
return e ? r.reactions.some(
|
|
71
|
+
(t) => t.emoji === e && t.userIds.includes(this.userId)
|
|
72
|
+
) : !0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class w {
|
|
76
|
+
constructor(r) {
|
|
77
|
+
n(this, "auth");
|
|
78
|
+
this.auth = r;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class j extends w {
|
|
82
|
+
constructor(e, t, a) {
|
|
83
|
+
super(a);
|
|
84
|
+
// TipTapThreadStore does not support addThreadToDocument
|
|
85
|
+
n(this, "addThreadToDocument");
|
|
86
|
+
this.userId = e, this.provider = t;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new thread with an initial comment.
|
|
90
|
+
*/
|
|
91
|
+
async createThread(e) {
|
|
92
|
+
let t = this.provider.createThread({
|
|
93
|
+
data: e.metadata
|
|
94
|
+
});
|
|
95
|
+
return t = this.provider.addComment(t.id, {
|
|
96
|
+
content: e.initialComment.body,
|
|
97
|
+
data: {
|
|
98
|
+
metadata: e.initialComment.metadata,
|
|
99
|
+
userId: this.userId
|
|
100
|
+
}
|
|
101
|
+
}), this.tiptapThreadToThreadData(t);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Adds a comment to a thread.
|
|
105
|
+
*/
|
|
106
|
+
async addComment(e) {
|
|
107
|
+
const t = this.provider.addComment(e.threadId, {
|
|
108
|
+
content: e.comment.body,
|
|
109
|
+
data: {
|
|
110
|
+
metadata: e.comment.metadata,
|
|
111
|
+
userId: this.userId
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return this.tiptapCommentToCommentData(
|
|
115
|
+
t.comments[t.comments.length - 1]
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Updates a comment in a thread.
|
|
120
|
+
*/
|
|
121
|
+
async updateComment(e) {
|
|
122
|
+
const t = this.provider.getThreadComment(
|
|
123
|
+
e.threadId,
|
|
124
|
+
e.commentId,
|
|
125
|
+
!0
|
|
126
|
+
);
|
|
127
|
+
if (!t)
|
|
128
|
+
throw new Error("Comment not found");
|
|
129
|
+
this.provider.updateComment(e.threadId, e.commentId, {
|
|
130
|
+
content: e.comment.body,
|
|
131
|
+
data: {
|
|
132
|
+
...t.data,
|
|
133
|
+
metadata: e.comment.metadata
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
tiptapCommentToCommentData(e) {
|
|
138
|
+
var a, s, o;
|
|
139
|
+
const t = [];
|
|
140
|
+
for (const h of ((a = e.data) == null ? void 0 : a.reactions) || []) {
|
|
141
|
+
const m = t.find(
|
|
142
|
+
(i) => i.emoji === h.emoji
|
|
143
|
+
);
|
|
144
|
+
m ? (m.userIds.push(h.userId), m.createdAt = new Date(
|
|
145
|
+
Math.min(m.createdAt.getTime(), h.createdAt)
|
|
146
|
+
)) : t.push({
|
|
147
|
+
emoji: h.emoji,
|
|
148
|
+
createdAt: new Date(h.createdAt),
|
|
149
|
+
userIds: [h.userId]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
type: "comment",
|
|
154
|
+
id: e.id,
|
|
155
|
+
body: e.content,
|
|
156
|
+
metadata: (s = e.data) == null ? void 0 : s.metadata,
|
|
157
|
+
userId: (o = e.data) == null ? void 0 : o.userId,
|
|
158
|
+
createdAt: new Date(e.createdAt),
|
|
159
|
+
updatedAt: new Date(e.updatedAt),
|
|
160
|
+
reactions: t
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
tiptapThreadToThreadData(e) {
|
|
164
|
+
var t;
|
|
165
|
+
return {
|
|
166
|
+
type: "thread",
|
|
167
|
+
id: e.id,
|
|
168
|
+
comments: e.comments.map(
|
|
169
|
+
(a) => this.tiptapCommentToCommentData(a)
|
|
170
|
+
),
|
|
171
|
+
resolved: !!e.resolvedAt,
|
|
172
|
+
metadata: (t = e.data) == null ? void 0 : t.metadata,
|
|
173
|
+
createdAt: new Date(e.createdAt),
|
|
174
|
+
updatedAt: new Date(e.updatedAt)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Deletes a comment from a thread.
|
|
179
|
+
*/
|
|
180
|
+
async deleteComment(e) {
|
|
181
|
+
this.provider.deleteComment(e.threadId, e.commentId);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Deletes a thread.
|
|
185
|
+
*/
|
|
186
|
+
async deleteThread(e) {
|
|
187
|
+
this.provider.deleteThread(e.threadId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Marks a thread as resolved.
|
|
191
|
+
*/
|
|
192
|
+
async resolveThread(e) {
|
|
193
|
+
this.provider.updateThread(e.threadId, {
|
|
194
|
+
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Marks a thread as unresolved.
|
|
199
|
+
*/
|
|
200
|
+
async unresolveThread(e) {
|
|
201
|
+
this.provider.updateThread(e.threadId, {
|
|
202
|
+
resolvedAt: null
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Adds a reaction to a comment.
|
|
207
|
+
*
|
|
208
|
+
* Auth: should be possible by anyone with comment access
|
|
209
|
+
*/
|
|
210
|
+
async addReaction(e) {
|
|
211
|
+
var a;
|
|
212
|
+
const t = this.provider.getThreadComment(
|
|
213
|
+
e.threadId,
|
|
214
|
+
e.commentId,
|
|
215
|
+
!0
|
|
216
|
+
);
|
|
217
|
+
if (!t)
|
|
218
|
+
throw new Error("Comment not found");
|
|
219
|
+
this.provider.updateComment(e.threadId, e.commentId, {
|
|
220
|
+
data: {
|
|
221
|
+
...t.data,
|
|
222
|
+
reactions: [
|
|
223
|
+
...((a = t.data) == null ? void 0 : a.reactions) || [],
|
|
224
|
+
{
|
|
225
|
+
emoji: e.emoji,
|
|
226
|
+
createdAt: Date.now(),
|
|
227
|
+
userId: this.userId
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Deletes a reaction from a comment.
|
|
235
|
+
*
|
|
236
|
+
* Auth: should be possible by the reaction author
|
|
237
|
+
*/
|
|
238
|
+
async deleteReaction(e) {
|
|
239
|
+
var a;
|
|
240
|
+
const t = this.provider.getThreadComment(
|
|
241
|
+
e.threadId,
|
|
242
|
+
e.commentId,
|
|
243
|
+
!0
|
|
244
|
+
);
|
|
245
|
+
if (!t)
|
|
246
|
+
throw new Error("Comment not found");
|
|
247
|
+
this.provider.updateComment(e.threadId, e.commentId, {
|
|
248
|
+
data: {
|
|
249
|
+
...t.data,
|
|
250
|
+
reactions: (((a = t.data) == null ? void 0 : a.reactions) || []).filter(
|
|
251
|
+
(s) => s.emoji !== e.emoji && s.userId !== this.userId
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
getThread(e) {
|
|
257
|
+
const t = this.provider.getThread(e);
|
|
258
|
+
if (!t)
|
|
259
|
+
throw new Error("Thread not found");
|
|
260
|
+
return this.tiptapThreadToThreadData(t);
|
|
261
|
+
}
|
|
262
|
+
getThreads() {
|
|
263
|
+
return new Map(
|
|
264
|
+
this.provider.getThreads().map((e) => [e.id, this.tiptapThreadToThreadData(e)])
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
subscribe(e) {
|
|
268
|
+
const t = () => {
|
|
269
|
+
e(this.getThreads());
|
|
270
|
+
};
|
|
271
|
+
return this.provider.watchThreads(t), () => {
|
|
272
|
+
this.provider.unwatchThreads(t);
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function g(d) {
|
|
277
|
+
const r = new T.Map();
|
|
278
|
+
if (r.set("id", d.id), r.set("userId", d.userId), r.set("createdAt", d.createdAt.getTime()), r.set("updatedAt", d.updatedAt.getTime()), d.deletedAt ? (r.set("deletedAt", d.deletedAt.getTime()), r.set("body", void 0)) : r.set("body", d.body), d.reactions.length > 0)
|
|
279
|
+
throw new Error("Reactions should be empty in commentToYMap");
|
|
280
|
+
return r.set("reactionsByUser", new T.Map()), r.set("metadata", d.metadata), r;
|
|
281
|
+
}
|
|
282
|
+
function v(d) {
|
|
283
|
+
var t;
|
|
284
|
+
const r = new T.Map();
|
|
285
|
+
r.set("id", d.id), r.set("createdAt", d.createdAt.getTime()), r.set("updatedAt", d.updatedAt.getTime());
|
|
286
|
+
const e = new T.Array();
|
|
287
|
+
return e.push(d.comments.map((a) => g(a))), r.set("comments", e), r.set("resolved", d.resolved), r.set("resolvedUpdatedAt", (t = d.resolvedUpdatedAt) == null ? void 0 : t.getTime()), r.set("metadata", d.metadata), r;
|
|
288
|
+
}
|
|
289
|
+
function C(d) {
|
|
290
|
+
return {
|
|
291
|
+
emoji: d.get("emoji"),
|
|
292
|
+
createdAt: new Date(d.get("createdAt")),
|
|
293
|
+
userId: d.get("userId")
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function D(d) {
|
|
297
|
+
return [...d.values()].map(
|
|
298
|
+
(e) => C(e)
|
|
299
|
+
).reduce(
|
|
300
|
+
(e, t) => {
|
|
301
|
+
const a = e.find((s) => s.emoji === t.emoji);
|
|
302
|
+
return a ? (a.userIds.push(t.userId), a.createdAt = new Date(
|
|
303
|
+
Math.min(
|
|
304
|
+
a.createdAt.getTime(),
|
|
305
|
+
t.createdAt.getTime()
|
|
306
|
+
)
|
|
307
|
+
)) : e.push({
|
|
308
|
+
emoji: t.emoji,
|
|
309
|
+
createdAt: t.createdAt,
|
|
310
|
+
userIds: [t.userId]
|
|
311
|
+
}), e;
|
|
312
|
+
},
|
|
313
|
+
[]
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function u(d) {
|
|
317
|
+
return {
|
|
318
|
+
type: "comment",
|
|
319
|
+
id: d.get("id"),
|
|
320
|
+
userId: d.get("userId"),
|
|
321
|
+
createdAt: new Date(d.get("createdAt")),
|
|
322
|
+
updatedAt: new Date(d.get("updatedAt")),
|
|
323
|
+
deletedAt: d.get("deletedAt") ? new Date(d.get("deletedAt")) : void 0,
|
|
324
|
+
reactions: D(d.get("reactionsByUser")),
|
|
325
|
+
metadata: d.get("metadata"),
|
|
326
|
+
body: d.get("body")
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function c(d) {
|
|
330
|
+
return {
|
|
331
|
+
type: "thread",
|
|
332
|
+
id: d.get("id"),
|
|
333
|
+
createdAt: new Date(d.get("createdAt")),
|
|
334
|
+
updatedAt: new Date(d.get("updatedAt")),
|
|
335
|
+
comments: (d.get("comments") || []).map(
|
|
336
|
+
(r) => u(r)
|
|
337
|
+
),
|
|
338
|
+
resolved: d.get("resolved"),
|
|
339
|
+
resolvedUpdatedAt: d.get("resolvedUpdatedAt"),
|
|
340
|
+
metadata: d.get("metadata")
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
class f extends w {
|
|
344
|
+
constructor(r, e) {
|
|
345
|
+
super(e), this.threadsYMap = r;
|
|
346
|
+
}
|
|
347
|
+
// TODO: async / reactive interface?
|
|
348
|
+
getThread(r) {
|
|
349
|
+
const e = this.threadsYMap.get(r);
|
|
350
|
+
if (!e)
|
|
351
|
+
throw new Error("Thread not found");
|
|
352
|
+
return c(e);
|
|
353
|
+
}
|
|
354
|
+
getThreads() {
|
|
355
|
+
const r = /* @__PURE__ */ new Map();
|
|
356
|
+
return this.threadsYMap.forEach((e, t) => {
|
|
357
|
+
r.set(t, c(e));
|
|
358
|
+
}), r;
|
|
359
|
+
}
|
|
360
|
+
subscribe(r) {
|
|
361
|
+
const e = () => {
|
|
362
|
+
r(this.getThreads());
|
|
363
|
+
};
|
|
364
|
+
return this.threadsYMap.observeDeep(e), () => {
|
|
365
|
+
this.threadsYMap.unobserveDeep(e);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
class Y extends f {
|
|
370
|
+
constructor(e, t, a, s) {
|
|
371
|
+
super(a, s);
|
|
372
|
+
n(this, "doRequest", async (e, t, a) => {
|
|
373
|
+
const s = await fetch(`${this.BASE_URL}${e}`, {
|
|
374
|
+
method: t,
|
|
375
|
+
body: JSON.stringify(a),
|
|
376
|
+
headers: {
|
|
377
|
+
"Content-Type": "application/json",
|
|
378
|
+
...this.headers
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
if (!s.ok)
|
|
382
|
+
throw new Error(`Failed to ${t} ${e}: ${s.statusText}`);
|
|
383
|
+
return s.json();
|
|
384
|
+
});
|
|
385
|
+
n(this, "addThreadToDocument", async (e) => {
|
|
386
|
+
const { threadId: t, ...a } = e;
|
|
387
|
+
return this.doRequest(`/${t}/addToDocument`, "POST", a);
|
|
388
|
+
});
|
|
389
|
+
n(this, "createThread", async (e) => this.doRequest("", "POST", e));
|
|
390
|
+
n(this, "addComment", (e) => {
|
|
391
|
+
const { threadId: t, ...a } = e;
|
|
392
|
+
return this.doRequest(`/${t}/comments`, "POST", a);
|
|
393
|
+
});
|
|
394
|
+
n(this, "updateComment", (e) => {
|
|
395
|
+
const { threadId: t, commentId: a, ...s } = e;
|
|
396
|
+
return this.doRequest(`/${t}/comments/${a}`, "PUT", s);
|
|
397
|
+
});
|
|
398
|
+
n(this, "deleteComment", (e) => {
|
|
399
|
+
const { threadId: t, commentId: a, ...s } = e;
|
|
400
|
+
return this.doRequest(
|
|
401
|
+
`/${t}/comments/${a}?soft=${!!s.softDelete}`,
|
|
402
|
+
"DELETE"
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
n(this, "deleteThread", (e) => this.doRequest(`/${e.threadId}`, "DELETE"));
|
|
406
|
+
n(this, "resolveThread", (e) => this.doRequest(`/${e.threadId}/resolve`, "POST"));
|
|
407
|
+
n(this, "unresolveThread", (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST"));
|
|
408
|
+
n(this, "addReaction", (e) => {
|
|
409
|
+
const { threadId: t, commentId: a, ...s } = e;
|
|
410
|
+
return this.doRequest(
|
|
411
|
+
`/${t}/comments/${a}/reactions`,
|
|
412
|
+
"POST",
|
|
413
|
+
s
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
n(this, "deleteReaction", (e) => this.doRequest(
|
|
417
|
+
`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`,
|
|
418
|
+
"DELETE"
|
|
419
|
+
));
|
|
420
|
+
this.BASE_URL = e, this.headers = t;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
class $ extends f {
|
|
424
|
+
constructor(e, t, a) {
|
|
425
|
+
super(t, a);
|
|
426
|
+
n(this, "transact", (e) => async (t) => this.threadsYMap.doc.transact(() => e(t)));
|
|
427
|
+
n(this, "createThread", this.transact(
|
|
428
|
+
(e) => {
|
|
429
|
+
if (!this.auth.canCreateThread())
|
|
430
|
+
throw new Error("Not authorized");
|
|
431
|
+
const t = /* @__PURE__ */ new Date(), a = {
|
|
432
|
+
type: "comment",
|
|
433
|
+
id: I(),
|
|
434
|
+
userId: this.userId,
|
|
435
|
+
createdAt: t,
|
|
436
|
+
updatedAt: t,
|
|
437
|
+
reactions: [],
|
|
438
|
+
metadata: e.initialComment.metadata,
|
|
439
|
+
body: e.initialComment.body
|
|
440
|
+
}, s = {
|
|
441
|
+
type: "thread",
|
|
442
|
+
id: I(),
|
|
443
|
+
createdAt: t,
|
|
444
|
+
updatedAt: t,
|
|
445
|
+
comments: [a],
|
|
446
|
+
resolved: !1,
|
|
447
|
+
metadata: e.metadata
|
|
448
|
+
};
|
|
449
|
+
return this.threadsYMap.set(s.id, v(s)), s;
|
|
450
|
+
}
|
|
451
|
+
));
|
|
452
|
+
// YjsThreadStore does not support addThreadToDocument
|
|
453
|
+
n(this, "addThreadToDocument");
|
|
454
|
+
n(this, "addComment", this.transact(
|
|
455
|
+
(e) => {
|
|
456
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
457
|
+
if (!t)
|
|
458
|
+
throw new Error("Thread not found");
|
|
459
|
+
if (!this.auth.canAddComment(c(t)))
|
|
460
|
+
throw new Error("Not authorized");
|
|
461
|
+
const a = /* @__PURE__ */ new Date(), s = {
|
|
462
|
+
type: "comment",
|
|
463
|
+
id: I(),
|
|
464
|
+
userId: this.userId,
|
|
465
|
+
createdAt: a,
|
|
466
|
+
updatedAt: a,
|
|
467
|
+
deletedAt: void 0,
|
|
468
|
+
reactions: [],
|
|
469
|
+
metadata: e.comment.metadata,
|
|
470
|
+
body: e.comment.body
|
|
471
|
+
};
|
|
472
|
+
return t.get("comments").push([
|
|
473
|
+
g(s)
|
|
474
|
+
]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s;
|
|
475
|
+
}
|
|
476
|
+
));
|
|
477
|
+
n(this, "updateComment", this.transact(
|
|
478
|
+
(e) => {
|
|
479
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
480
|
+
if (!t)
|
|
481
|
+
throw new Error("Thread not found");
|
|
482
|
+
const a = l(
|
|
483
|
+
t.get("comments"),
|
|
484
|
+
(o) => o.get("id") === e.commentId
|
|
485
|
+
);
|
|
486
|
+
if (a === -1)
|
|
487
|
+
throw new Error("Comment not found");
|
|
488
|
+
const s = t.get("comments").get(a);
|
|
489
|
+
if (!this.auth.canUpdateComment(u(s)))
|
|
490
|
+
throw new Error("Not authorized");
|
|
491
|
+
s.set("body", e.comment.body), s.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s.set("metadata", e.comment.metadata);
|
|
492
|
+
}
|
|
493
|
+
));
|
|
494
|
+
n(this, "deleteComment", this.transact(
|
|
495
|
+
(e) => {
|
|
496
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
497
|
+
if (!t)
|
|
498
|
+
throw new Error("Thread not found");
|
|
499
|
+
const a = l(
|
|
500
|
+
t.get("comments"),
|
|
501
|
+
(o) => o.get("id") === e.commentId
|
|
502
|
+
);
|
|
503
|
+
if (a === -1)
|
|
504
|
+
throw new Error("Comment not found");
|
|
505
|
+
const s = t.get("comments").get(a);
|
|
506
|
+
if (!this.auth.canDeleteComment(u(s)))
|
|
507
|
+
throw new Error("Not authorized");
|
|
508
|
+
if (s.get("deletedAt"))
|
|
509
|
+
throw new Error("Comment already deleted");
|
|
510
|
+
e.softDelete ? (s.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()), s.set("body", void 0)) : t.get("comments").delete(a), t.get("comments").toArray().every((o) => o.get("deletedAt")) && (e.softDelete ? t.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()) : this.threadsYMap.delete(e.threadId)), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
511
|
+
}
|
|
512
|
+
));
|
|
513
|
+
n(this, "deleteThread", this.transact((e) => {
|
|
514
|
+
if (!this.auth.canDeleteThread(
|
|
515
|
+
c(this.threadsYMap.get(e.threadId))
|
|
516
|
+
))
|
|
517
|
+
throw new Error("Not authorized");
|
|
518
|
+
this.threadsYMap.delete(e.threadId);
|
|
519
|
+
}));
|
|
520
|
+
n(this, "resolveThread", this.transact((e) => {
|
|
521
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
522
|
+
if (!t)
|
|
523
|
+
throw new Error("Thread not found");
|
|
524
|
+
if (!this.auth.canResolveThread(c(t)))
|
|
525
|
+
throw new Error("Not authorized");
|
|
526
|
+
t.set("resolved", !0), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
527
|
+
}));
|
|
528
|
+
n(this, "unresolveThread", this.transact((e) => {
|
|
529
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
530
|
+
if (!t)
|
|
531
|
+
throw new Error("Thread not found");
|
|
532
|
+
if (!this.auth.canUnresolveThread(c(t)))
|
|
533
|
+
throw new Error("Not authorized");
|
|
534
|
+
t.set("resolved", !1), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
535
|
+
}));
|
|
536
|
+
n(this, "addReaction", this.transact(
|
|
537
|
+
(e) => {
|
|
538
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
539
|
+
if (!t)
|
|
540
|
+
throw new Error("Thread not found");
|
|
541
|
+
const a = l(
|
|
542
|
+
t.get("comments"),
|
|
543
|
+
(i) => i.get("id") === e.commentId
|
|
544
|
+
);
|
|
545
|
+
if (a === -1)
|
|
546
|
+
throw new Error("Comment not found");
|
|
547
|
+
const s = t.get("comments").get(a);
|
|
548
|
+
if (!this.auth.canAddReaction(u(s), e.emoji))
|
|
549
|
+
throw new Error("Not authorized");
|
|
550
|
+
const o = /* @__PURE__ */ new Date(), h = `${this.userId}-${e.emoji}`, m = s.get("reactionsByUser");
|
|
551
|
+
if (!m.has(h)) {
|
|
552
|
+
const i = new T.Map();
|
|
553
|
+
i.set("emoji", e.emoji), i.set("createdAt", o.getTime()), i.set("userId", this.userId), m.set(h, i);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
));
|
|
557
|
+
n(this, "deleteReaction", this.transact(
|
|
558
|
+
(e) => {
|
|
559
|
+
const t = this.threadsYMap.get(e.threadId);
|
|
560
|
+
if (!t)
|
|
561
|
+
throw new Error("Thread not found");
|
|
562
|
+
const a = l(
|
|
563
|
+
t.get("comments"),
|
|
564
|
+
(m) => m.get("id") === e.commentId
|
|
565
|
+
);
|
|
566
|
+
if (a === -1)
|
|
567
|
+
throw new Error("Comment not found");
|
|
568
|
+
const s = t.get("comments").get(a);
|
|
569
|
+
if (!this.auth.canDeleteReaction(u(s), e.emoji))
|
|
570
|
+
throw new Error("Not authorized");
|
|
571
|
+
const o = `${this.userId}-${e.emoji}`;
|
|
572
|
+
s.get("reactionsByUser").delete(o);
|
|
573
|
+
}
|
|
574
|
+
));
|
|
575
|
+
this.userId = e;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function l(d, r) {
|
|
579
|
+
for (let e = 0; e < d.length; e++)
|
|
580
|
+
if (r(d.get(e)))
|
|
581
|
+
return e;
|
|
582
|
+
return -1;
|
|
583
|
+
}
|
|
584
|
+
export {
|
|
585
|
+
b as DefaultThreadStoreAuth,
|
|
586
|
+
Y as RESTYjsThreadStore,
|
|
587
|
+
w as ThreadStore,
|
|
588
|
+
y as ThreadStoreAuth,
|
|
589
|
+
j as TiptapThreadStore,
|
|
590
|
+
$ as YjsThreadStore,
|
|
591
|
+
f as YjsThreadStoreBase
|
|
592
|
+
};
|
|
593
|
+
//# sourceMappingURL=comments.js.map
|