@blocknote/core 0.47.3 → 0.48.1
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/BlockNoteExtension-B6RhuQ3V.js +27 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
- package/dist/EventEmitter-CuPnGDYt.js +22 -0
- package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
- package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
- package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
- package/dist/ShowSelection-BsHFfdMi.js +29 -0
- package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
- package/dist/ShowSelection-DhXglbt8.cjs +2 -0
- package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -5
- package/dist/blocknote.js +7 -4256
- package/dist/blocks-BEvIOzln.cjs +11 -0
- package/dist/blocks-BEvIOzln.cjs.map +1 -0
- package/dist/blocks-DYl7UTS4.js +3313 -0
- package/dist/blocks-DYl7UTS4.js.map +1 -0
- package/dist/blocks.cjs +1 -2
- package/dist/blocks.js +2 -74
- package/dist/comments.cjs +2 -2
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +604 -900
- package/dist/comments.js.map +1 -1
- package/dist/en-C4ykW581.cjs +2 -0
- package/dist/en-C4ykW581.cjs.map +1 -0
- package/dist/en-QsSI16s5.js +453 -0
- package/dist/en-QsSI16s5.js.map +1 -0
- package/dist/extensions-3nf9PPhA.js +1495 -0
- package/dist/extensions-3nf9PPhA.js.map +1 -0
- package/dist/extensions-D9y6evn6.cjs +2 -0
- package/dist/extensions-D9y6evn6.cjs.map +1 -0
- package/dist/extensions.cjs +1 -2
- package/dist/extensions.js +4 -36
- package/dist/locales.cjs +2 -2
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10049 -9111
- package/dist/locales.js.map +1 -1
- package/dist/src-BKJH7Jla.cjs +5 -0
- package/dist/src-BKJH7Jla.cjs.map +1 -0
- package/dist/src-Hjv1f5lc.js +2386 -0
- package/dist/src-Hjv1f5lc.js.map +1 -0
- package/dist/style.css +2 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +2 -2
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +20 -38
- package/dist/yjs.js.map +1 -1
- package/package.json +8 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
- package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
- package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
- package/src/editor/Block.css +5 -8
- package/src/editor/BlockNoteEditor.ts +38 -1
- package/src/editor/editor.css +0 -20
- package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
- package/src/editor/performance.test.ts +134 -0
- package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
- package/src/extensions/Placeholder/Placeholder.ts +1 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
- package/src/extensions/SideMenu/SideMenu.ts +14 -8
- package/src/extensions/TableHandles/TableHandles.ts +14 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
- package/src/index.ts +1 -1
- package/src/schema/blocks/createSpec.ts +6 -2
- package/src/schema/inlineContent/types.ts +0 -1
- package/src/vite-env.d.ts +6 -0
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +13 -0
- package/types/src/editor/performance.test.d.ts +1 -0
- package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
- package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
- package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
- package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
- package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
- package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
- package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
- package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
- package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
- package/dist/EventEmitter-CjSwpTbz.js +0 -27
- package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
- package/dist/ShowSelection-B0ch3unP.js +0 -51
- package/dist/ShowSelection-B0ch3unP.js.map +0 -1
- package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
- package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
- package/dist/TrailingNode-GzE59m_7.js +0 -2288
- package/dist/TrailingNode-GzE59m_7.js.map +0 -1
- package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
- package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
- package/dist/blockToNode-BNoNIXU7.js +0 -1140
- package/dist/blockToNode-BNoNIXU7.js.map +0 -1
- package/dist/blockToNode-CumVjgem.cjs +0 -7
- package/dist/blockToNode-CumVjgem.cjs.map +0 -1
- package/dist/blocknote.cjs.map +0 -1
- package/dist/blocknote.js.map +0 -1
- package/dist/blocks.cjs.map +0 -1
- package/dist/blocks.js.map +0 -1
- package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
- package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
- package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
- package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
- package/dist/en-Cl87Uuyf.cjs +0 -2
- package/dist/en-Cl87Uuyf.cjs.map +0 -1
- package/dist/en-njEqD7AG.js +0 -408
- package/dist/en-njEqD7AG.js.map +0 -1
- package/dist/extensions.cjs.map +0 -1
- package/dist/extensions.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/comments.js
CHANGED
|
@@ -1,908 +1,612 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Retrieve information about a user based on their id, if cached.
|
|
88
|
-
*
|
|
89
|
-
* The user will have to be loaded via `loadUsers` first
|
|
90
|
-
*/
|
|
91
|
-
getUser(e) {
|
|
92
|
-
return this.userCache.get(e);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Subscribe to changes in the user store.
|
|
96
|
-
*
|
|
97
|
-
* @param cb - The callback to call when the user store changes.
|
|
98
|
-
* @returns A function to unsubscribe from the user store.
|
|
99
|
-
*/
|
|
100
|
-
subscribe(e) {
|
|
101
|
-
return this.on("update", e);
|
|
102
|
-
}
|
|
1
|
+
import { n as e, t } from "./BlockNoteExtension-B6RhuQ3V.js";
|
|
2
|
+
import { t as n } from "./ShowSelection-BsHFfdMi.js";
|
|
3
|
+
import { t as r } from "./EventEmitter-CuPnGDYt.js";
|
|
4
|
+
import { Mark as i, mergeAttributes as a } from "@tiptap/core";
|
|
5
|
+
import { Plugin as o, PluginKey as s } from "prosemirror-state";
|
|
6
|
+
import { v4 as c } from "uuid";
|
|
7
|
+
import { Decoration as l, DecorationSet as u } from "prosemirror-view";
|
|
8
|
+
import { getRelativeSelection as d, ySyncPluginKey as f } from "y-prosemirror";
|
|
9
|
+
import * as p from "yjs";
|
|
10
|
+
//#region src/comments/mark.ts
|
|
11
|
+
var m = i.create({
|
|
12
|
+
name: "comment",
|
|
13
|
+
excludes: "",
|
|
14
|
+
inclusive: !1,
|
|
15
|
+
keepOnSplit: !0,
|
|
16
|
+
addAttributes() {
|
|
17
|
+
return {
|
|
18
|
+
orphan: {
|
|
19
|
+
parseHTML: (e) => !!e.getAttribute("data-orphan"),
|
|
20
|
+
renderHTML: (e) => e.orphan ? { "data-orphan": "true" } : {},
|
|
21
|
+
default: !1
|
|
22
|
+
},
|
|
23
|
+
threadId: {
|
|
24
|
+
parseHTML: (e) => e.getAttribute("data-bn-thread-id"),
|
|
25
|
+
renderHTML: (e) => ({ "data-bn-thread-id": e.threadId }),
|
|
26
|
+
default: ""
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
31
|
+
return ["span", a(e, { class: "bn-thread-mark" })];
|
|
32
|
+
},
|
|
33
|
+
parseHTML() {
|
|
34
|
+
return [{ tag: "span.bn-thread-mark" }];
|
|
35
|
+
},
|
|
36
|
+
extendMarkSchema(e) {
|
|
37
|
+
return e.name === "comment" ? { blocknoteIgnore: !0 } : {};
|
|
38
|
+
}
|
|
39
|
+
}), h = class extends r {
|
|
40
|
+
userCache = /* @__PURE__ */ new Map();
|
|
41
|
+
loadingUsers = /* @__PURE__ */ new Set();
|
|
42
|
+
constructor(e) {
|
|
43
|
+
super(), this.resolveUsers = e;
|
|
44
|
+
}
|
|
45
|
+
async loadUsers(e) {
|
|
46
|
+
let t = e.filter((e) => !this.userCache.has(e) && !this.loadingUsers.has(e));
|
|
47
|
+
if (t.length !== 0) {
|
|
48
|
+
for (let e of t) this.loadingUsers.add(e);
|
|
49
|
+
try {
|
|
50
|
+
let e = await this.resolveUsers(t);
|
|
51
|
+
for (let t of e) this.userCache.set(t.id, t);
|
|
52
|
+
this.emit("update", this.userCache);
|
|
53
|
+
} finally {
|
|
54
|
+
for (let e of t) this.loadingUsers.delete(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getUser(e) {
|
|
59
|
+
return this.userCache.get(e);
|
|
60
|
+
}
|
|
61
|
+
subscribe(e) {
|
|
62
|
+
return this.on("update", e);
|
|
63
|
+
}
|
|
64
|
+
}, g = new s("blocknote-comments");
|
|
65
|
+
function _(e, t) {
|
|
66
|
+
let n = /* @__PURE__ */ new Map();
|
|
67
|
+
return e.descendants((e, r) => {
|
|
68
|
+
e.marks.forEach((i) => {
|
|
69
|
+
if (i.type.name === t) {
|
|
70
|
+
let t = i.attrs.threadId;
|
|
71
|
+
if (!t) return;
|
|
72
|
+
let a = r, o = a + e.nodeSize, s = n.get(t) ?? {
|
|
73
|
+
from: Infinity,
|
|
74
|
+
to: 0
|
|
75
|
+
};
|
|
76
|
+
n.set(t, {
|
|
77
|
+
from: Math.min(a, s.from),
|
|
78
|
+
to: Math.max(o, s.to)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}), n;
|
|
103
83
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
data: e.metadata
|
|
406
|
-
});
|
|
407
|
-
return t = this.provider.addComment(t.id, {
|
|
408
|
-
content: e.initialComment.body,
|
|
409
|
-
data: {
|
|
410
|
-
metadata: e.initialComment.metadata,
|
|
411
|
-
userId: this.userId
|
|
412
|
-
}
|
|
413
|
-
}), this.tiptapThreadToThreadData(t);
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Adds a comment to a thread.
|
|
417
|
-
*/
|
|
418
|
-
async addComment(e) {
|
|
419
|
-
const t = this.provider.addComment(e.threadId, {
|
|
420
|
-
content: e.comment.body,
|
|
421
|
-
data: {
|
|
422
|
-
metadata: e.comment.metadata,
|
|
423
|
-
userId: this.userId
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
return this.tiptapCommentToCommentData(
|
|
427
|
-
t.comments[t.comments.length - 1]
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Updates a comment in a thread.
|
|
432
|
-
*/
|
|
433
|
-
async updateComment(e) {
|
|
434
|
-
const t = this.provider.getThreadComment(
|
|
435
|
-
e.threadId,
|
|
436
|
-
e.commentId,
|
|
437
|
-
!0
|
|
438
|
-
);
|
|
439
|
-
if (!t)
|
|
440
|
-
throw new Error("Comment not found");
|
|
441
|
-
this.provider.updateComment(e.threadId, e.commentId, {
|
|
442
|
-
content: e.comment.body,
|
|
443
|
-
data: {
|
|
444
|
-
...t.data,
|
|
445
|
-
metadata: e.comment.metadata
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
tiptapCommentToCommentData(e) {
|
|
450
|
-
var a, s, o;
|
|
451
|
-
const t = [];
|
|
452
|
-
for (const m of ((a = e.data) == null ? void 0 : a.reactions) || []) {
|
|
453
|
-
const n = t.find(
|
|
454
|
-
(i) => i.emoji === m.emoji
|
|
455
|
-
);
|
|
456
|
-
n ? (n.userIds.push(m.userId), n.createdAt = new Date(
|
|
457
|
-
Math.min(n.createdAt.getTime(), m.createdAt)
|
|
458
|
-
)) : t.push({
|
|
459
|
-
emoji: m.emoji,
|
|
460
|
-
createdAt: new Date(m.createdAt),
|
|
461
|
-
userIds: [m.userId]
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
return {
|
|
465
|
-
type: "comment",
|
|
466
|
-
id: e.id,
|
|
467
|
-
body: e.content,
|
|
468
|
-
metadata: (s = e.data) == null ? void 0 : s.metadata,
|
|
469
|
-
userId: (o = e.data) == null ? void 0 : o.userId,
|
|
470
|
-
createdAt: new Date(e.createdAt),
|
|
471
|
-
updatedAt: new Date(e.updatedAt),
|
|
472
|
-
reactions: t
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
tiptapThreadToThreadData(e) {
|
|
476
|
-
var t;
|
|
477
|
-
return {
|
|
478
|
-
type: "thread",
|
|
479
|
-
id: e.id,
|
|
480
|
-
comments: e.comments.map(
|
|
481
|
-
(a) => this.tiptapCommentToCommentData(a)
|
|
482
|
-
),
|
|
483
|
-
resolved: !!e.resolvedAt,
|
|
484
|
-
metadata: (t = e.data) == null ? void 0 : t.metadata,
|
|
485
|
-
createdAt: new Date(e.createdAt),
|
|
486
|
-
updatedAt: new Date(e.updatedAt)
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Deletes a comment from a thread.
|
|
491
|
-
*/
|
|
492
|
-
async deleteComment(e) {
|
|
493
|
-
this.provider.deleteComment(e.threadId, e.commentId);
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Deletes a thread.
|
|
497
|
-
*/
|
|
498
|
-
async deleteThread(e) {
|
|
499
|
-
this.provider.deleteThread(e.threadId);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Marks a thread as resolved.
|
|
503
|
-
*/
|
|
504
|
-
async resolveThread(e) {
|
|
505
|
-
this.provider.updateThread(e.threadId, {
|
|
506
|
-
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Marks a thread as unresolved.
|
|
511
|
-
*/
|
|
512
|
-
async unresolveThread(e) {
|
|
513
|
-
this.provider.updateThread(e.threadId, {
|
|
514
|
-
resolvedAt: null
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Adds a reaction to a comment.
|
|
519
|
-
*
|
|
520
|
-
* Auth: should be possible by anyone with comment access
|
|
521
|
-
*/
|
|
522
|
-
async addReaction(e) {
|
|
523
|
-
var a;
|
|
524
|
-
const t = this.provider.getThreadComment(
|
|
525
|
-
e.threadId,
|
|
526
|
-
e.commentId,
|
|
527
|
-
!0
|
|
528
|
-
);
|
|
529
|
-
if (!t)
|
|
530
|
-
throw new Error("Comment not found");
|
|
531
|
-
this.provider.updateComment(e.threadId, e.commentId, {
|
|
532
|
-
data: {
|
|
533
|
-
...t.data,
|
|
534
|
-
reactions: [
|
|
535
|
-
...((a = t.data) == null ? void 0 : a.reactions) || [],
|
|
536
|
-
{
|
|
537
|
-
emoji: e.emoji,
|
|
538
|
-
createdAt: Date.now(),
|
|
539
|
-
userId: this.userId
|
|
540
|
-
}
|
|
541
|
-
]
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Deletes a reaction from a comment.
|
|
547
|
-
*
|
|
548
|
-
* Auth: should be possible by the reaction author
|
|
549
|
-
*/
|
|
550
|
-
async deleteReaction(e) {
|
|
551
|
-
var a;
|
|
552
|
-
const t = this.provider.getThreadComment(
|
|
553
|
-
e.threadId,
|
|
554
|
-
e.commentId,
|
|
555
|
-
!0
|
|
556
|
-
);
|
|
557
|
-
if (!t)
|
|
558
|
-
throw new Error("Comment not found");
|
|
559
|
-
this.provider.updateComment(e.threadId, e.commentId, {
|
|
560
|
-
data: {
|
|
561
|
-
...t.data,
|
|
562
|
-
reactions: (((a = t.data) == null ? void 0 : a.reactions) || []).filter(
|
|
563
|
-
(s) => s.emoji !== e.emoji && s.userId !== this.userId
|
|
564
|
-
)
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
getThread(e) {
|
|
569
|
-
const t = this.provider.getThread(e);
|
|
570
|
-
if (!t)
|
|
571
|
-
throw new Error("Thread not found");
|
|
572
|
-
return this.tiptapThreadToThreadData(t);
|
|
573
|
-
}
|
|
574
|
-
getThreads() {
|
|
575
|
-
return new Map(
|
|
576
|
-
this.provider.getThreads().map((e) => [e.id, this.tiptapThreadToThreadData(e)])
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
subscribe(e) {
|
|
580
|
-
const t = () => {
|
|
581
|
-
e(this.getThreads());
|
|
582
|
-
};
|
|
583
|
-
return this.provider.watchThreads(t), () => {
|
|
584
|
-
this.provider.unwatchThreads(t);
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
function U(r) {
|
|
589
|
-
const d = new g.Map();
|
|
590
|
-
if (d.set("id", r.id), d.set("userId", r.userId), d.set("createdAt", r.createdAt.getTime()), d.set("updatedAt", r.updatedAt.getTime()), r.deletedAt ? (d.set("deletedAt", r.deletedAt.getTime()), d.set("body", void 0)) : d.set("body", r.body), r.reactions.length > 0)
|
|
591
|
-
throw new Error("Reactions should be empty in commentToYMap");
|
|
592
|
-
return d.set("reactionsByUser", new g.Map()), d.set("metadata", r.metadata), d;
|
|
593
|
-
}
|
|
594
|
-
function G(r) {
|
|
595
|
-
var t;
|
|
596
|
-
const d = new g.Map();
|
|
597
|
-
d.set("id", r.id), d.set("createdAt", r.createdAt.getTime()), d.set("updatedAt", r.updatedAt.getTime());
|
|
598
|
-
const e = new g.Array();
|
|
599
|
-
return e.push(r.comments.map((a) => U(a))), d.set("comments", e), d.set("resolved", r.resolved), d.set("resolvedUpdatedAt", (t = r.resolvedUpdatedAt) == null ? void 0 : t.getTime()), d.set("resolvedBy", r.resolvedBy), d.set("metadata", r.metadata), d;
|
|
600
|
-
}
|
|
601
|
-
function J(r) {
|
|
602
|
-
return {
|
|
603
|
-
emoji: r.get("emoji"),
|
|
604
|
-
createdAt: new Date(r.get("createdAt")),
|
|
605
|
-
userId: r.get("userId")
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function Q(r) {
|
|
609
|
-
return [...r.values()].map(
|
|
610
|
-
(e) => J(e)
|
|
611
|
-
).reduce(
|
|
612
|
-
(e, t) => {
|
|
613
|
-
const a = e.find((s) => s.emoji === t.emoji);
|
|
614
|
-
return a ? (a.userIds.push(t.userId), a.createdAt = new Date(
|
|
615
|
-
Math.min(
|
|
616
|
-
a.createdAt.getTime(),
|
|
617
|
-
t.createdAt.getTime()
|
|
618
|
-
)
|
|
619
|
-
)) : e.push({
|
|
620
|
-
emoji: t.emoji,
|
|
621
|
-
createdAt: t.createdAt,
|
|
622
|
-
userIds: [t.userId]
|
|
623
|
-
}), e;
|
|
624
|
-
},
|
|
625
|
-
[]
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
function I(r) {
|
|
629
|
-
return {
|
|
630
|
-
type: "comment",
|
|
631
|
-
id: r.get("id"),
|
|
632
|
-
userId: r.get("userId"),
|
|
633
|
-
createdAt: new Date(r.get("createdAt")),
|
|
634
|
-
updatedAt: new Date(r.get("updatedAt")),
|
|
635
|
-
deletedAt: r.get("deletedAt") ? new Date(r.get("deletedAt")) : void 0,
|
|
636
|
-
reactions: Q(r.get("reactionsByUser")),
|
|
637
|
-
metadata: r.get("metadata"),
|
|
638
|
-
body: r.get("body")
|
|
639
|
-
};
|
|
84
|
+
var v = t(({ editor: t, options: { schema: r, threadStore: i, resolveUsers: a } }) => {
|
|
85
|
+
if (!a) throw Error("resolveUsers is required to be defined when using comments");
|
|
86
|
+
if (!i) throw Error("threadStore is required to be defined when using comments");
|
|
87
|
+
let s = m.name, c = new h(a), p = e({
|
|
88
|
+
pendingComment: !1,
|
|
89
|
+
selectedThreadId: void 0,
|
|
90
|
+
threadPositions: /* @__PURE__ */ new Map()
|
|
91
|
+
}, { onUpdate() {
|
|
92
|
+
p.state.selectedThreadId !== p.prevState.selectedThreadId && t.transact((e) => e.setMeta(g, !0));
|
|
93
|
+
} }), v = (e) => {
|
|
94
|
+
t.transact((t) => {
|
|
95
|
+
t.doc.descendants((n, r) => {
|
|
96
|
+
n.marks.forEach((i) => {
|
|
97
|
+
if (i.type.name === s) {
|
|
98
|
+
let a = i.type, o = i.attrs.threadId, s = e.get(o), c = !!(!s || s.resolved || s.deletedAt);
|
|
99
|
+
if (c !== i.attrs.orphan) {
|
|
100
|
+
let e = Math.max(r, 0), s = Math.min(r + n.nodeSize, t.doc.content.size - 1, t.doc.content.size - 1);
|
|
101
|
+
t.removeMark(e, s, i), t.addMark(e, s, a.create({
|
|
102
|
+
...i.attrs,
|
|
103
|
+
orphan: c
|
|
104
|
+
})), c && p.state.selectedThreadId === o && p.setState((e) => ({
|
|
105
|
+
...e,
|
|
106
|
+
selectedThreadId: void 0
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
key: "comments",
|
|
116
|
+
store: p,
|
|
117
|
+
prosemirrorPlugins: [new o({
|
|
118
|
+
key: g,
|
|
119
|
+
state: {
|
|
120
|
+
init() {
|
|
121
|
+
return { decorations: u.empty };
|
|
122
|
+
},
|
|
123
|
+
apply(e, t) {
|
|
124
|
+
let n = e.getMeta(g);
|
|
125
|
+
if (!e.docChanged && !n) return t;
|
|
126
|
+
let r = e.docChanged ? _(e.doc, s) : p.state.threadPositions;
|
|
127
|
+
(r.size > 0 || p.state.threadPositions.size > 0) && p.setState((e) => ({
|
|
128
|
+
...e,
|
|
129
|
+
threadPositions: r
|
|
130
|
+
}));
|
|
131
|
+
let i = [];
|
|
132
|
+
if (p.state.selectedThreadId) {
|
|
133
|
+
let e = r.get(p.state.selectedThreadId);
|
|
134
|
+
e && i.push(l.inline(e.from, e.to, { class: "bn-thread-mark-selected" }));
|
|
135
|
+
}
|
|
136
|
+
return { decorations: u.create(e.doc, i) };
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
props: {
|
|
140
|
+
decorations(e) {
|
|
141
|
+
return g.getState(e)?.decorations ?? u.empty;
|
|
142
|
+
},
|
|
143
|
+
handleClick: (e, t, n) => {
|
|
144
|
+
if (n.button !== 0) return;
|
|
145
|
+
let r = e.state.doc.nodeAt(t);
|
|
146
|
+
if (!r) {
|
|
147
|
+
p.setState((e) => ({
|
|
148
|
+
...e,
|
|
149
|
+
selectedThreadId: void 0
|
|
150
|
+
}));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let i = r.marks.find((e) => e.type.name === s && e.attrs.orphan !== !0)?.attrs.threadId;
|
|
154
|
+
i !== p.state.selectedThreadId && p.setState((e) => ({
|
|
155
|
+
...e,
|
|
156
|
+
selectedThreadId: i
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
})],
|
|
161
|
+
threadStore: i,
|
|
162
|
+
mount() {
|
|
163
|
+
let e = i.subscribe(v);
|
|
164
|
+
v(i.getThreads());
|
|
165
|
+
let n = t.onSelectionChange(() => {
|
|
166
|
+
p.state.pendingComment && p.setState((e) => ({
|
|
167
|
+
...e,
|
|
168
|
+
pendingComment: !1
|
|
169
|
+
}));
|
|
170
|
+
});
|
|
171
|
+
return () => {
|
|
172
|
+
e(), n();
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
selectThread(e, n = !0) {
|
|
176
|
+
if (p.state.selectedThreadId !== e && (p.setState((t) => ({
|
|
177
|
+
...t,
|
|
178
|
+
pendingComment: !1,
|
|
179
|
+
selectedThreadId: e
|
|
180
|
+
})), e && n)) {
|
|
181
|
+
let n = p.state.threadPositions.get(e);
|
|
182
|
+
if (!n) return;
|
|
183
|
+
(t.prosemirrorView?.domAtPos(n.from).node)?.scrollIntoView({
|
|
184
|
+
behavior: "smooth",
|
|
185
|
+
block: "center"
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
startPendingComment() {
|
|
190
|
+
p.setState((e) => ({
|
|
191
|
+
...e,
|
|
192
|
+
selectedThreadId: void 0,
|
|
193
|
+
pendingComment: !0
|
|
194
|
+
})), t.getExtension(n)?.showSelection(!0, "comments");
|
|
195
|
+
},
|
|
196
|
+
stopPendingComment() {
|
|
197
|
+
p.setState((e) => ({
|
|
198
|
+
...e,
|
|
199
|
+
selectedThreadId: void 0,
|
|
200
|
+
pendingComment: !1
|
|
201
|
+
})), t.getExtension(n)?.showSelection(!1, "comments");
|
|
202
|
+
},
|
|
203
|
+
async createThread(e) {
|
|
204
|
+
let n = await i.createThread(e);
|
|
205
|
+
if (i.addThreadToDocument) {
|
|
206
|
+
let e = t.prosemirrorView, r = e.state.selection, a = f.getState(e.state), o = {
|
|
207
|
+
prosemirror: {
|
|
208
|
+
head: r.head,
|
|
209
|
+
anchor: r.anchor
|
|
210
|
+
},
|
|
211
|
+
yjs: a ? d(a.binding, e.state) : void 0
|
|
212
|
+
};
|
|
213
|
+
await i.addThreadToDocument({
|
|
214
|
+
threadId: n.id,
|
|
215
|
+
selection: o
|
|
216
|
+
});
|
|
217
|
+
} else t._tiptapEditor.commands.setMark(s, {
|
|
218
|
+
orphan: !1,
|
|
219
|
+
threadId: n.id
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
userStore: c,
|
|
223
|
+
commentEditorSchema: r,
|
|
224
|
+
tiptapExtensions: [m]
|
|
225
|
+
};
|
|
226
|
+
}), y = class {}, b = class extends y {
|
|
227
|
+
constructor(e, t) {
|
|
228
|
+
super(), this.userId = e, this.role = t;
|
|
229
|
+
}
|
|
230
|
+
canCreateThread() {
|
|
231
|
+
return !0;
|
|
232
|
+
}
|
|
233
|
+
canAddComment(e) {
|
|
234
|
+
return !0;
|
|
235
|
+
}
|
|
236
|
+
canUpdateComment(e) {
|
|
237
|
+
return e.userId === this.userId;
|
|
238
|
+
}
|
|
239
|
+
canDeleteComment(e) {
|
|
240
|
+
return e.userId === this.userId || this.role === "editor";
|
|
241
|
+
}
|
|
242
|
+
canDeleteThread(e) {
|
|
243
|
+
return this.role === "editor";
|
|
244
|
+
}
|
|
245
|
+
canResolveThread(e) {
|
|
246
|
+
return !0;
|
|
247
|
+
}
|
|
248
|
+
canUnresolveThread(e) {
|
|
249
|
+
return !0;
|
|
250
|
+
}
|
|
251
|
+
canAddReaction(e, t) {
|
|
252
|
+
return t ? !e.reactions.some((e) => e.emoji === t && e.userIds.includes(this.userId)) : !0;
|
|
253
|
+
}
|
|
254
|
+
canDeleteReaction(e, t) {
|
|
255
|
+
return t ? e.reactions.some((e) => e.emoji === t && e.userIds.includes(this.userId)) : !0;
|
|
256
|
+
}
|
|
257
|
+
}, x = class {
|
|
258
|
+
auth;
|
|
259
|
+
constructor(e) {
|
|
260
|
+
this.auth = e;
|
|
261
|
+
}
|
|
262
|
+
}, S = class extends x {
|
|
263
|
+
constructor(e, t, n) {
|
|
264
|
+
super(n), this.userId = e, this.provider = t;
|
|
265
|
+
}
|
|
266
|
+
async createThread(e) {
|
|
267
|
+
let t = this.provider.createThread({ data: e.metadata });
|
|
268
|
+
return t = this.provider.addComment(t.id, {
|
|
269
|
+
content: e.initialComment.body,
|
|
270
|
+
data: {
|
|
271
|
+
metadata: e.initialComment.metadata,
|
|
272
|
+
userId: this.userId
|
|
273
|
+
}
|
|
274
|
+
}), this.tiptapThreadToThreadData(t);
|
|
275
|
+
}
|
|
276
|
+
addThreadToDocument = void 0;
|
|
277
|
+
async addComment(e) {
|
|
278
|
+
let t = this.provider.addComment(e.threadId, {
|
|
279
|
+
content: e.comment.body,
|
|
280
|
+
data: {
|
|
281
|
+
metadata: e.comment.metadata,
|
|
282
|
+
userId: this.userId
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
return this.tiptapCommentToCommentData(t.comments[t.comments.length - 1]);
|
|
286
|
+
}
|
|
287
|
+
async updateComment(e) {
|
|
288
|
+
let t = this.provider.getThreadComment(e.threadId, e.commentId, !0);
|
|
289
|
+
if (!t) throw Error("Comment not found");
|
|
290
|
+
this.provider.updateComment(e.threadId, e.commentId, {
|
|
291
|
+
content: e.comment.body,
|
|
292
|
+
data: {
|
|
293
|
+
...t.data,
|
|
294
|
+
metadata: e.comment.metadata
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
tiptapCommentToCommentData(e) {
|
|
299
|
+
let t = [];
|
|
300
|
+
for (let n of e.data?.reactions || []) {
|
|
301
|
+
let e = t.find((e) => e.emoji === n.emoji);
|
|
302
|
+
e ? (e.userIds.push(n.userId), e.createdAt = new Date(Math.min(e.createdAt.getTime(), n.createdAt))) : t.push({
|
|
303
|
+
emoji: n.emoji,
|
|
304
|
+
createdAt: new Date(n.createdAt),
|
|
305
|
+
userIds: [n.userId]
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
type: "comment",
|
|
310
|
+
id: e.id,
|
|
311
|
+
body: e.content,
|
|
312
|
+
metadata: e.data?.metadata,
|
|
313
|
+
userId: e.data?.userId,
|
|
314
|
+
createdAt: new Date(e.createdAt),
|
|
315
|
+
updatedAt: new Date(e.updatedAt),
|
|
316
|
+
reactions: t
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
tiptapThreadToThreadData(e) {
|
|
320
|
+
return {
|
|
321
|
+
type: "thread",
|
|
322
|
+
id: e.id,
|
|
323
|
+
comments: e.comments.map((e) => this.tiptapCommentToCommentData(e)),
|
|
324
|
+
resolved: !!e.resolvedAt,
|
|
325
|
+
metadata: e.data?.metadata,
|
|
326
|
+
createdAt: new Date(e.createdAt),
|
|
327
|
+
updatedAt: new Date(e.updatedAt)
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
async deleteComment(e) {
|
|
331
|
+
this.provider.deleteComment(e.threadId, e.commentId);
|
|
332
|
+
}
|
|
333
|
+
async deleteThread(e) {
|
|
334
|
+
this.provider.deleteThread(e.threadId);
|
|
335
|
+
}
|
|
336
|
+
async resolveThread(e) {
|
|
337
|
+
this.provider.updateThread(e.threadId, { resolvedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
338
|
+
}
|
|
339
|
+
async unresolveThread(e) {
|
|
340
|
+
this.provider.updateThread(e.threadId, { resolvedAt: null });
|
|
341
|
+
}
|
|
342
|
+
async addReaction(e) {
|
|
343
|
+
let t = this.provider.getThreadComment(e.threadId, e.commentId, !0);
|
|
344
|
+
if (!t) throw Error("Comment not found");
|
|
345
|
+
this.provider.updateComment(e.threadId, e.commentId, { data: {
|
|
346
|
+
...t.data,
|
|
347
|
+
reactions: [...t.data?.reactions || [], {
|
|
348
|
+
emoji: e.emoji,
|
|
349
|
+
createdAt: Date.now(),
|
|
350
|
+
userId: this.userId
|
|
351
|
+
}]
|
|
352
|
+
} });
|
|
353
|
+
}
|
|
354
|
+
async deleteReaction(e) {
|
|
355
|
+
let t = this.provider.getThreadComment(e.threadId, e.commentId, !0);
|
|
356
|
+
if (!t) throw Error("Comment not found");
|
|
357
|
+
this.provider.updateComment(e.threadId, e.commentId, { data: {
|
|
358
|
+
...t.data,
|
|
359
|
+
reactions: (t.data?.reactions || []).filter((t) => t.emoji !== e.emoji && t.userId !== this.userId)
|
|
360
|
+
} });
|
|
361
|
+
}
|
|
362
|
+
getThread(e) {
|
|
363
|
+
let t = this.provider.getThread(e);
|
|
364
|
+
if (!t) throw Error("Thread not found");
|
|
365
|
+
return this.tiptapThreadToThreadData(t);
|
|
366
|
+
}
|
|
367
|
+
getThreads() {
|
|
368
|
+
return new Map(this.provider.getThreads().map((e) => [e.id, this.tiptapThreadToThreadData(e)]));
|
|
369
|
+
}
|
|
370
|
+
subscribe(e) {
|
|
371
|
+
let t = () => {
|
|
372
|
+
e(this.getThreads());
|
|
373
|
+
};
|
|
374
|
+
return this.provider.watchThreads(t), () => {
|
|
375
|
+
this.provider.unwatchThreads(t);
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/comments/threadstore/yjs/yjsHelpers.ts
|
|
381
|
+
function C(e) {
|
|
382
|
+
let t = new p.Map();
|
|
383
|
+
if (t.set("id", e.id), t.set("userId", e.userId), t.set("createdAt", e.createdAt.getTime()), t.set("updatedAt", e.updatedAt.getTime()), e.deletedAt ? (t.set("deletedAt", e.deletedAt.getTime()), t.set("body", void 0)) : t.set("body", e.body), e.reactions.length > 0) throw Error("Reactions should be empty in commentToYMap");
|
|
384
|
+
return t.set("reactionsByUser", new p.Map()), t.set("metadata", e.metadata), t;
|
|
640
385
|
}
|
|
641
|
-
function
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
updatedAt: new Date(r.get("updatedAt")),
|
|
647
|
-
comments: (r.get("comments") || []).map(
|
|
648
|
-
(d) => I(d)
|
|
649
|
-
),
|
|
650
|
-
resolved: r.get("resolved"),
|
|
651
|
-
resolvedUpdatedAt: new Date(r.get("resolvedUpdatedAt")),
|
|
652
|
-
resolvedBy: r.get("resolvedBy"),
|
|
653
|
-
metadata: r.get("metadata")
|
|
654
|
-
};
|
|
386
|
+
function w(e) {
|
|
387
|
+
let t = new p.Map();
|
|
388
|
+
t.set("id", e.id), t.set("createdAt", e.createdAt.getTime()), t.set("updatedAt", e.updatedAt.getTime());
|
|
389
|
+
let n = new p.Array();
|
|
390
|
+
return n.push(e.comments.map((e) => C(e))), t.set("comments", n), t.set("resolved", e.resolved), t.set("resolvedUpdatedAt", e.resolvedUpdatedAt?.getTime()), t.set("resolvedBy", e.resolvedBy), t.set("metadata", e.metadata), t;
|
|
655
391
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
const e = this.threadsYMap.get(d);
|
|
663
|
-
if (!e)
|
|
664
|
-
throw new Error("Thread not found");
|
|
665
|
-
return p(e);
|
|
666
|
-
}
|
|
667
|
-
getThreads() {
|
|
668
|
-
const d = /* @__PURE__ */ new Map();
|
|
669
|
-
return this.threadsYMap.forEach((e, t) => {
|
|
670
|
-
e instanceof g.Map && d.set(t, p(e));
|
|
671
|
-
}), d;
|
|
672
|
-
}
|
|
673
|
-
subscribe(d) {
|
|
674
|
-
const e = () => {
|
|
675
|
-
d(this.getThreads());
|
|
676
|
-
};
|
|
677
|
-
return this.threadsYMap.observeDeep(e), () => {
|
|
678
|
-
this.threadsYMap.unobserveDeep(e);
|
|
679
|
-
};
|
|
680
|
-
}
|
|
392
|
+
function T(e) {
|
|
393
|
+
return {
|
|
394
|
+
emoji: e.get("emoji"),
|
|
395
|
+
createdAt: new Date(e.get("createdAt")),
|
|
396
|
+
userId: e.get("userId")
|
|
397
|
+
};
|
|
681
398
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
...this.headers
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
if (!s.ok)
|
|
695
|
-
throw new Error(`Failed to ${t} ${e}: ${s.statusText}`);
|
|
696
|
-
return s.json();
|
|
697
|
-
});
|
|
698
|
-
c(this, "addThreadToDocument", async (e) => {
|
|
699
|
-
const { threadId: t, ...a } = e;
|
|
700
|
-
return this.doRequest(`/${t}/addToDocument`, "POST", a);
|
|
701
|
-
});
|
|
702
|
-
c(this, "createThread", async (e) => this.doRequest("", "POST", e));
|
|
703
|
-
c(this, "addComment", (e) => {
|
|
704
|
-
const { threadId: t, ...a } = e;
|
|
705
|
-
return this.doRequest(`/${t}/comments`, "POST", a);
|
|
706
|
-
});
|
|
707
|
-
c(this, "updateComment", (e) => {
|
|
708
|
-
const { threadId: t, commentId: a, ...s } = e;
|
|
709
|
-
return this.doRequest(`/${t}/comments/${a}`, "PUT", s);
|
|
710
|
-
});
|
|
711
|
-
c(this, "deleteComment", (e) => {
|
|
712
|
-
const { threadId: t, commentId: a, ...s } = e;
|
|
713
|
-
return this.doRequest(
|
|
714
|
-
`/${t}/comments/${a}?soft=${!!s.softDelete}`,
|
|
715
|
-
"DELETE"
|
|
716
|
-
);
|
|
717
|
-
});
|
|
718
|
-
c(this, "deleteThread", (e) => this.doRequest(`/${e.threadId}`, "DELETE"));
|
|
719
|
-
c(this, "resolveThread", (e) => this.doRequest(`/${e.threadId}/resolve`, "POST"));
|
|
720
|
-
c(this, "unresolveThread", (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST"));
|
|
721
|
-
c(this, "addReaction", (e) => {
|
|
722
|
-
const { threadId: t, commentId: a, ...s } = e;
|
|
723
|
-
return this.doRequest(
|
|
724
|
-
`/${t}/comments/${a}/reactions`,
|
|
725
|
-
"POST",
|
|
726
|
-
s
|
|
727
|
-
);
|
|
728
|
-
});
|
|
729
|
-
c(this, "deleteReaction", (e) => this.doRequest(
|
|
730
|
-
`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`,
|
|
731
|
-
"DELETE"
|
|
732
|
-
));
|
|
733
|
-
this.BASE_URL = e, this.headers = t;
|
|
734
|
-
}
|
|
399
|
+
function E(e) {
|
|
400
|
+
return [...e.values()].map((e) => T(e)).reduce((e, t) => {
|
|
401
|
+
let n = e.find((e) => e.emoji === t.emoji);
|
|
402
|
+
return n ? (n.userIds.push(t.userId), n.createdAt = new Date(Math.min(n.createdAt.getTime(), t.createdAt.getTime()))) : e.push({
|
|
403
|
+
emoji: t.emoji,
|
|
404
|
+
createdAt: t.createdAt,
|
|
405
|
+
userIds: [t.userId]
|
|
406
|
+
}), e;
|
|
407
|
+
}, []);
|
|
735
408
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
createdAt: t,
|
|
749
|
-
updatedAt: t,
|
|
750
|
-
reactions: [],
|
|
751
|
-
metadata: e.initialComment.metadata,
|
|
752
|
-
body: e.initialComment.body
|
|
753
|
-
}, s = {
|
|
754
|
-
type: "thread",
|
|
755
|
-
id: D(),
|
|
756
|
-
createdAt: t,
|
|
757
|
-
updatedAt: t,
|
|
758
|
-
comments: [a],
|
|
759
|
-
resolved: !1,
|
|
760
|
-
metadata: e.metadata
|
|
761
|
-
};
|
|
762
|
-
return this.threadsYMap.set(s.id, G(s)), s;
|
|
763
|
-
}
|
|
764
|
-
));
|
|
765
|
-
// YjsThreadStore does not support addThreadToDocument
|
|
766
|
-
c(this, "addThreadToDocument");
|
|
767
|
-
c(this, "addComment", this.transact(
|
|
768
|
-
(e) => {
|
|
769
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
770
|
-
if (!t)
|
|
771
|
-
throw new Error("Thread not found");
|
|
772
|
-
if (!this.auth.canAddComment(p(t)))
|
|
773
|
-
throw new Error("Not authorized");
|
|
774
|
-
const a = /* @__PURE__ */ new Date(), s = {
|
|
775
|
-
type: "comment",
|
|
776
|
-
id: D(),
|
|
777
|
-
userId: this.userId,
|
|
778
|
-
createdAt: a,
|
|
779
|
-
updatedAt: a,
|
|
780
|
-
deletedAt: void 0,
|
|
781
|
-
reactions: [],
|
|
782
|
-
metadata: e.comment.metadata,
|
|
783
|
-
body: e.comment.body
|
|
784
|
-
};
|
|
785
|
-
return t.get("comments").push([
|
|
786
|
-
U(s)
|
|
787
|
-
]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s;
|
|
788
|
-
}
|
|
789
|
-
));
|
|
790
|
-
c(this, "updateComment", this.transact(
|
|
791
|
-
(e) => {
|
|
792
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
793
|
-
if (!t)
|
|
794
|
-
throw new Error("Thread not found");
|
|
795
|
-
const a = y(
|
|
796
|
-
t.get("comments"),
|
|
797
|
-
(o) => o.get("id") === e.commentId
|
|
798
|
-
);
|
|
799
|
-
if (a === -1)
|
|
800
|
-
throw new Error("Comment not found");
|
|
801
|
-
const s = t.get("comments").get(a);
|
|
802
|
-
if (!this.auth.canUpdateComment(I(s)))
|
|
803
|
-
throw new Error("Not authorized");
|
|
804
|
-
s.set("body", e.comment.body), s.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s.set("metadata", e.comment.metadata);
|
|
805
|
-
}
|
|
806
|
-
));
|
|
807
|
-
c(this, "deleteComment", this.transact(
|
|
808
|
-
(e) => {
|
|
809
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
810
|
-
if (!t)
|
|
811
|
-
throw new Error("Thread not found");
|
|
812
|
-
const a = y(
|
|
813
|
-
t.get("comments"),
|
|
814
|
-
(o) => o.get("id") === e.commentId
|
|
815
|
-
);
|
|
816
|
-
if (a === -1)
|
|
817
|
-
throw new Error("Comment not found");
|
|
818
|
-
const s = t.get("comments").get(a);
|
|
819
|
-
if (!this.auth.canDeleteComment(I(s)))
|
|
820
|
-
throw new Error("Not authorized");
|
|
821
|
-
if (s.get("deletedAt"))
|
|
822
|
-
throw new Error("Comment already deleted");
|
|
823
|
-
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());
|
|
824
|
-
}
|
|
825
|
-
));
|
|
826
|
-
c(this, "deleteThread", this.transact((e) => {
|
|
827
|
-
if (!this.auth.canDeleteThread(
|
|
828
|
-
p(this.threadsYMap.get(e.threadId))
|
|
829
|
-
))
|
|
830
|
-
throw new Error("Not authorized");
|
|
831
|
-
this.threadsYMap.delete(e.threadId);
|
|
832
|
-
}));
|
|
833
|
-
c(this, "resolveThread", this.transact((e) => {
|
|
834
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
835
|
-
if (!t)
|
|
836
|
-
throw new Error("Thread not found");
|
|
837
|
-
if (!this.auth.canResolveThread(p(t)))
|
|
838
|
-
throw new Error("Not authorized");
|
|
839
|
-
t.set("resolved", !0), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime()), t.set("resolvedBy", this.userId);
|
|
840
|
-
}));
|
|
841
|
-
c(this, "unresolveThread", this.transact((e) => {
|
|
842
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
843
|
-
if (!t)
|
|
844
|
-
throw new Error("Thread not found");
|
|
845
|
-
if (!this.auth.canUnresolveThread(p(t)))
|
|
846
|
-
throw new Error("Not authorized");
|
|
847
|
-
t.set("resolved", !1), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
848
|
-
}));
|
|
849
|
-
c(this, "addReaction", this.transact(
|
|
850
|
-
(e) => {
|
|
851
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
852
|
-
if (!t)
|
|
853
|
-
throw new Error("Thread not found");
|
|
854
|
-
const a = y(
|
|
855
|
-
t.get("comments"),
|
|
856
|
-
(i) => i.get("id") === e.commentId
|
|
857
|
-
);
|
|
858
|
-
if (a === -1)
|
|
859
|
-
throw new Error("Comment not found");
|
|
860
|
-
const s = t.get("comments").get(a);
|
|
861
|
-
if (!this.auth.canAddReaction(I(s), e.emoji))
|
|
862
|
-
throw new Error("Not authorized");
|
|
863
|
-
const o = /* @__PURE__ */ new Date(), m = `${this.userId}-${e.emoji}`, n = s.get("reactionsByUser");
|
|
864
|
-
if (!n.has(m)) {
|
|
865
|
-
const i = new g.Map();
|
|
866
|
-
i.set("emoji", e.emoji), i.set("createdAt", o.getTime()), i.set("userId", this.userId), n.set(m, i);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
));
|
|
870
|
-
c(this, "deleteReaction", this.transact(
|
|
871
|
-
(e) => {
|
|
872
|
-
const t = this.threadsYMap.get(e.threadId);
|
|
873
|
-
if (!t)
|
|
874
|
-
throw new Error("Thread not found");
|
|
875
|
-
const a = y(
|
|
876
|
-
t.get("comments"),
|
|
877
|
-
(n) => n.get("id") === e.commentId
|
|
878
|
-
);
|
|
879
|
-
if (a === -1)
|
|
880
|
-
throw new Error("Comment not found");
|
|
881
|
-
const s = t.get("comments").get(a);
|
|
882
|
-
if (!this.auth.canDeleteReaction(I(s), e.emoji))
|
|
883
|
-
throw new Error("Not authorized");
|
|
884
|
-
const o = `${this.userId}-${e.emoji}`;
|
|
885
|
-
s.get("reactionsByUser").delete(o);
|
|
886
|
-
}
|
|
887
|
-
));
|
|
888
|
-
this.userId = e;
|
|
889
|
-
}
|
|
409
|
+
function D(e) {
|
|
410
|
+
return {
|
|
411
|
+
type: "comment",
|
|
412
|
+
id: e.get("id"),
|
|
413
|
+
userId: e.get("userId"),
|
|
414
|
+
createdAt: new Date(e.get("createdAt")),
|
|
415
|
+
updatedAt: new Date(e.get("updatedAt")),
|
|
416
|
+
deletedAt: e.get("deletedAt") ? new Date(e.get("deletedAt")) : void 0,
|
|
417
|
+
reactions: E(e.get("reactionsByUser")),
|
|
418
|
+
metadata: e.get("metadata"),
|
|
419
|
+
body: e.get("body")
|
|
420
|
+
};
|
|
890
421
|
}
|
|
891
|
-
function
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
422
|
+
function O(e) {
|
|
423
|
+
return {
|
|
424
|
+
type: "thread",
|
|
425
|
+
id: e.get("id"),
|
|
426
|
+
createdAt: new Date(e.get("createdAt")),
|
|
427
|
+
updatedAt: new Date(e.get("updatedAt")),
|
|
428
|
+
comments: (e.get("comments") || []).map((e) => D(e)),
|
|
429
|
+
resolved: e.get("resolved"),
|
|
430
|
+
resolvedUpdatedAt: new Date(e.get("resolvedUpdatedAt")),
|
|
431
|
+
resolvedBy: e.get("resolvedBy"),
|
|
432
|
+
metadata: e.get("metadata")
|
|
433
|
+
};
|
|
896
434
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/comments/threadstore/yjs/YjsThreadStoreBase.ts
|
|
437
|
+
var k = class extends x {
|
|
438
|
+
constructor(e, t) {
|
|
439
|
+
super(t), this.threadsYMap = e;
|
|
440
|
+
}
|
|
441
|
+
getThread(e) {
|
|
442
|
+
let t = this.threadsYMap.get(e);
|
|
443
|
+
if (!t) throw Error("Thread not found");
|
|
444
|
+
return O(t);
|
|
445
|
+
}
|
|
446
|
+
getThreads() {
|
|
447
|
+
let e = /* @__PURE__ */ new Map();
|
|
448
|
+
return this.threadsYMap.forEach((t, n) => {
|
|
449
|
+
t instanceof p.Map && e.set(n, O(t));
|
|
450
|
+
}), e;
|
|
451
|
+
}
|
|
452
|
+
subscribe(e) {
|
|
453
|
+
let t = () => {
|
|
454
|
+
e(this.getThreads());
|
|
455
|
+
};
|
|
456
|
+
return this.threadsYMap.observeDeep(t), () => {
|
|
457
|
+
this.threadsYMap.unobserveDeep(t);
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
}, A = class extends k {
|
|
461
|
+
constructor(e, t, n, r) {
|
|
462
|
+
super(n, r), this.BASE_URL = e, this.headers = t;
|
|
463
|
+
}
|
|
464
|
+
doRequest = async (e, t, n) => {
|
|
465
|
+
let r = await fetch(`${this.BASE_URL}${e}`, {
|
|
466
|
+
method: t,
|
|
467
|
+
body: JSON.stringify(n),
|
|
468
|
+
headers: {
|
|
469
|
+
"Content-Type": "application/json",
|
|
470
|
+
...this.headers
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
if (!r.ok) throw Error(`Failed to ${t} ${e}: ${r.statusText}`);
|
|
474
|
+
return r.json();
|
|
475
|
+
};
|
|
476
|
+
addThreadToDocument = async (e) => {
|
|
477
|
+
let { threadId: t, ...n } = e;
|
|
478
|
+
return this.doRequest(`/${t}/addToDocument`, "POST", n);
|
|
479
|
+
};
|
|
480
|
+
createThread = async (e) => this.doRequest("", "POST", e);
|
|
481
|
+
addComment = (e) => {
|
|
482
|
+
let { threadId: t, ...n } = e;
|
|
483
|
+
return this.doRequest(`/${t}/comments`, "POST", n);
|
|
484
|
+
};
|
|
485
|
+
updateComment = (e) => {
|
|
486
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
487
|
+
return this.doRequest(`/${t}/comments/${n}`, "PUT", r);
|
|
488
|
+
};
|
|
489
|
+
deleteComment = (e) => {
|
|
490
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
491
|
+
return this.doRequest(`/${t}/comments/${n}?soft=${!!r.softDelete}`, "DELETE");
|
|
492
|
+
};
|
|
493
|
+
deleteThread = (e) => this.doRequest(`/${e.threadId}`, "DELETE");
|
|
494
|
+
resolveThread = (e) => this.doRequest(`/${e.threadId}/resolve`, "POST");
|
|
495
|
+
unresolveThread = (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST");
|
|
496
|
+
addReaction = (e) => {
|
|
497
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
498
|
+
return this.doRequest(`/${t}/comments/${n}/reactions`, "POST", r);
|
|
499
|
+
};
|
|
500
|
+
deleteReaction = (e) => this.doRequest(`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`, "DELETE");
|
|
501
|
+
}, j = class extends k {
|
|
502
|
+
constructor(e, t, n) {
|
|
503
|
+
super(t, n), this.userId = e;
|
|
504
|
+
}
|
|
505
|
+
transact = (e) => async (t) => this.threadsYMap.doc.transact(() => e(t));
|
|
506
|
+
createThread = this.transact((e) => {
|
|
507
|
+
if (!this.auth.canCreateThread()) throw Error("Not authorized");
|
|
508
|
+
let t = /* @__PURE__ */ new Date(), n = {
|
|
509
|
+
type: "comment",
|
|
510
|
+
id: c(),
|
|
511
|
+
userId: this.userId,
|
|
512
|
+
createdAt: t,
|
|
513
|
+
updatedAt: t,
|
|
514
|
+
reactions: [],
|
|
515
|
+
metadata: e.initialComment.metadata,
|
|
516
|
+
body: e.initialComment.body
|
|
517
|
+
}, r = {
|
|
518
|
+
type: "thread",
|
|
519
|
+
id: c(),
|
|
520
|
+
createdAt: t,
|
|
521
|
+
updatedAt: t,
|
|
522
|
+
comments: [n],
|
|
523
|
+
resolved: !1,
|
|
524
|
+
metadata: e.metadata
|
|
525
|
+
};
|
|
526
|
+
return this.threadsYMap.set(r.id, w(r)), r;
|
|
527
|
+
});
|
|
528
|
+
addThreadToDocument = void 0;
|
|
529
|
+
addComment = this.transact((e) => {
|
|
530
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
531
|
+
if (!t) throw Error("Thread not found");
|
|
532
|
+
if (!this.auth.canAddComment(O(t))) throw Error("Not authorized");
|
|
533
|
+
let n = /* @__PURE__ */ new Date(), r = {
|
|
534
|
+
type: "comment",
|
|
535
|
+
id: c(),
|
|
536
|
+
userId: this.userId,
|
|
537
|
+
createdAt: n,
|
|
538
|
+
updatedAt: n,
|
|
539
|
+
deletedAt: void 0,
|
|
540
|
+
reactions: [],
|
|
541
|
+
metadata: e.comment.metadata,
|
|
542
|
+
body: e.comment.body
|
|
543
|
+
};
|
|
544
|
+
return t.get("comments").push([C(r)]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), r;
|
|
545
|
+
});
|
|
546
|
+
updateComment = this.transact((e) => {
|
|
547
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
548
|
+
if (!t) throw Error("Thread not found");
|
|
549
|
+
let n = M(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
550
|
+
if (n === -1) throw Error("Comment not found");
|
|
551
|
+
let r = t.get("comments").get(n);
|
|
552
|
+
if (!this.auth.canUpdateComment(D(r))) throw Error("Not authorized");
|
|
553
|
+
r.set("body", e.comment.body), r.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), r.set("metadata", e.comment.metadata);
|
|
554
|
+
});
|
|
555
|
+
deleteComment = this.transact((e) => {
|
|
556
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
557
|
+
if (!t) throw Error("Thread not found");
|
|
558
|
+
let n = M(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
559
|
+
if (n === -1) throw Error("Comment not found");
|
|
560
|
+
let r = t.get("comments").get(n);
|
|
561
|
+
if (!this.auth.canDeleteComment(D(r))) throw Error("Not authorized");
|
|
562
|
+
if (r.get("deletedAt")) throw Error("Comment already deleted");
|
|
563
|
+
e.softDelete ? (r.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()), r.set("body", void 0)) : t.get("comments").delete(n), t.get("comments").toArray().every((e) => e.get("deletedAt")) && (e.softDelete ? t.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()) : this.threadsYMap.delete(e.threadId)), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
564
|
+
});
|
|
565
|
+
deleteThread = this.transact((e) => {
|
|
566
|
+
if (!this.auth.canDeleteThread(O(this.threadsYMap.get(e.threadId)))) throw Error("Not authorized");
|
|
567
|
+
this.threadsYMap.delete(e.threadId);
|
|
568
|
+
});
|
|
569
|
+
resolveThread = this.transact((e) => {
|
|
570
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
571
|
+
if (!t) throw Error("Thread not found");
|
|
572
|
+
if (!this.auth.canResolveThread(O(t))) throw Error("Not authorized");
|
|
573
|
+
t.set("resolved", !0), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime()), t.set("resolvedBy", this.userId);
|
|
574
|
+
});
|
|
575
|
+
unresolveThread = this.transact((e) => {
|
|
576
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
577
|
+
if (!t) throw Error("Thread not found");
|
|
578
|
+
if (!this.auth.canUnresolveThread(O(t))) throw Error("Not authorized");
|
|
579
|
+
t.set("resolved", !1), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
580
|
+
});
|
|
581
|
+
addReaction = this.transact((e) => {
|
|
582
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
583
|
+
if (!t) throw Error("Thread not found");
|
|
584
|
+
let n = M(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
585
|
+
if (n === -1) throw Error("Comment not found");
|
|
586
|
+
let r = t.get("comments").get(n);
|
|
587
|
+
if (!this.auth.canAddReaction(D(r), e.emoji)) throw Error("Not authorized");
|
|
588
|
+
let i = /* @__PURE__ */ new Date(), a = `${this.userId}-${e.emoji}`, o = r.get("reactionsByUser");
|
|
589
|
+
if (!o.has(a)) {
|
|
590
|
+
let t = new p.Map();
|
|
591
|
+
t.set("emoji", e.emoji), t.set("createdAt", i.getTime()), t.set("userId", this.userId), o.set(a, t);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
deleteReaction = this.transact((e) => {
|
|
595
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
596
|
+
if (!t) throw Error("Thread not found");
|
|
597
|
+
let n = M(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
598
|
+
if (n === -1) throw Error("Comment not found");
|
|
599
|
+
let r = t.get("comments").get(n);
|
|
600
|
+
if (!this.auth.canDeleteReaction(D(r), e.emoji)) throw Error("Not authorized");
|
|
601
|
+
let i = `${this.userId}-${e.emoji}`;
|
|
602
|
+
r.get("reactionsByUser").delete(i);
|
|
603
|
+
});
|
|
907
604
|
};
|
|
908
|
-
|
|
605
|
+
function M(e, t) {
|
|
606
|
+
for (let n = 0; n < e.length; n++) if (t(e.get(n))) return n;
|
|
607
|
+
return -1;
|
|
608
|
+
}
|
|
609
|
+
//#endregion
|
|
610
|
+
export { m as CommentMark, v as CommentsExtension, b as DefaultThreadStoreAuth, A as RESTYjsThreadStore, x as ThreadStore, y as ThreadStoreAuth, S as TiptapThreadStore, j as YjsThreadStore, k as YjsThreadStoreBase };
|
|
611
|
+
|
|
612
|
+
//# sourceMappingURL=comments.js.map
|