@blocknote/core 0.42.3 → 0.44.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/BlockNoteExtension-BWw0r8Gy.cjs +2 -0
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -0
- package/dist/BlockNoteExtension-C2X7LW-V.js +25 -0
- package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -0
- package/dist/BlockNoteSchema-B4gm-Qco.cjs +2 -0
- package/dist/BlockNoteSchema-B4gm-Qco.cjs.map +1 -0
- package/dist/BlockNoteSchema-C-l154WP.js +270 -0
- package/dist/BlockNoteSchema-C-l154WP.js.map +1 -0
- package/dist/EventEmitter-CLwfmbqG.cjs +2 -0
- package/dist/EventEmitter-CLwfmbqG.cjs.map +1 -0
- package/dist/EventEmitter-CjSwpTbz.js +27 -0
- package/dist/EventEmitter-CjSwpTbz.js.map +1 -0
- package/dist/ShowSelection-BW37oJ6h.cjs +2 -0
- package/dist/ShowSelection-BW37oJ6h.cjs.map +1 -0
- package/dist/ShowSelection-Dz-NEase.js +43 -0
- package/dist/ShowSelection-Dz-NEase.js.map +1 -0
- package/dist/TrailingNode-B_zPMWxw.js +2098 -0
- package/dist/TrailingNode-B_zPMWxw.js.map +1 -0
- package/dist/TrailingNode-CRHrgOnK.cjs +2 -0
- package/dist/TrailingNode-CRHrgOnK.cjs.map +1 -0
- package/dist/{blockToNode-DIfPWLH8.js → blockToNode-DBNbhwwC.js} +33 -33
- package/dist/blockToNode-DBNbhwwC.js.map +1 -0
- package/dist/blockToNode-w7H99R6p.cjs.map +1 -1
- package/dist/blocknote.cjs +4 -4
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +2496 -5686
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +71 -70
- package/dist/blocks.js.map +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +451 -137
- package/dist/comments.js.map +1 -1
- package/dist/defaultBlocks-DLJ4Q1_J.cjs +6 -0
- package/dist/defaultBlocks-DLJ4Q1_J.cjs.map +1 -0
- package/dist/{BlockNoteSchema-Bi-eeHal.js → defaultBlocks-DgA_mtQV.js} +974 -1027
- package/dist/defaultBlocks-DgA_mtQV.js.map +1 -0
- package/dist/extensions.cjs +2 -0
- package/dist/extensions.cjs.map +1 -0
- package/dist/extensions.js +57 -0
- package/dist/extensions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.js +1 -1
- package/package.json +9 -3
- package/src/api/nodeConversions/blockToNode.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +1 -1
- package/src/blocks/Code/block.ts +4 -4
- package/src/blocks/Divider/block.ts +2 -2
- package/src/blocks/File/helpers/render/createAddFileButton.ts +7 -5
- package/src/blocks/Heading/block.ts +23 -20
- package/src/blocks/ListItem/BulletListItem/block.ts +2 -2
- package/src/blocks/ListItem/CheckListItem/block.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/block.ts +3 -3
- package/src/blocks/ListItem/ToggleListItem/block.ts +2 -2
- package/src/blocks/PageBreak/getPageBreakSlashMenuItems.ts +2 -2
- package/src/blocks/Paragraph/block.ts +2 -2
- package/src/blocks/Quote/block.ts +2 -2
- package/src/blocks/Table/block.ts +4 -3
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -1
- package/src/comments/extension.ts +353 -0
- package/src/comments/index.ts +2 -1
- package/src/comments/types.ts +8 -0
- package/src/{extensions/Comments → comments}/userstore/UserStore.ts +2 -2
- package/src/editor/BlockNoteEditor.test.ts +2 -23
- package/src/editor/BlockNoteEditor.ts +60 -453
- package/src/editor/BlockNoteExtension.test.ts +103 -0
- package/src/editor/BlockNoteExtension.ts +174 -56
- package/src/editor/managers/EventManager.ts +64 -35
- package/src/editor/managers/ExtensionManager/extensions.ts +214 -0
- package/src/editor/managers/ExtensionManager/index.ts +514 -0
- package/src/editor/managers/ExtensionManager/symbol.ts +6 -0
- package/src/editor/managers/SelectionManager.ts +5 -1
- package/src/editor/managers/StateManager.ts +29 -17
- package/src/editor/managers/index.ts +1 -5
- package/src/extensions/BlockChange/{BlockChangePlugin.ts → BlockChange.ts} +27 -29
- package/src/extensions/Collaboration/{ForkYDocPlugin.test.ts → ForkYDoc.test.ts} +6 -5
- package/src/extensions/Collaboration/ForkYDoc.ts +158 -0
- package/src/extensions/Collaboration/YCursorPlugin.ts +183 -0
- package/src/extensions/Collaboration/YSync.ts +16 -0
- package/src/extensions/Collaboration/YUndo.ts +12 -0
- package/src/extensions/Collaboration/schemaMigration/SchemaMigration.ts +59 -0
- package/src/extensions/DropCursor/DropCursor.ts +26 -0
- package/src/extensions/FilePanel/FilePanel.ts +41 -0
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +119 -0
- package/src/extensions/History/History.ts +11 -0
- package/src/extensions/LinkToolbar/LinkToolbar.ts +121 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +74 -0
- package/src/extensions/Placeholder/Placeholder.ts +148 -0
- package/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.ts → PreviousBlockType.ts} +9 -13
- package/src/extensions/ShowSelection/{ShowSelectionPlugin.ts → ShowSelection.ts} +27 -33
- package/src/extensions/SideMenu/{SideMenuPlugin.ts → SideMenu.ts} +63 -83
- package/src/extensions/SuggestionMenu/{SuggestionPlugin.ts → SuggestionMenu.ts} +71 -77
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +29 -44
- package/src/extensions/TableHandles/{TableHandlesPlugin.ts → TableHandles.ts} +416 -437
- package/src/extensions/TrailingNode/{TrailingNodeExtension.ts → TrailingNode.ts} +8 -17
- package/src/extensions/index.ts +24 -0
- package/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.ts +1 -1
- package/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.ts +21 -16
- package/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.ts +1 -1
- package/src/extensions/tiptap-extensions/index.ts +31 -0
- package/src/index.ts +1 -13
- package/src/schema/blocks/createSpec.ts +14 -11
- package/src/schema/blocks/internal.ts +2 -2
- package/src/schema/blocks/types.ts +8 -5
- package/src/schema/schema.ts +11 -36
- package/src/util/topo-sort.ts +46 -0
- package/types/src/comments/extension.d.ts +70 -0
- package/types/src/comments/index.d.ts +2 -1
- package/types/src/comments/types.d.ts +8 -0
- package/types/src/{extensions/Comments → comments}/userstore/UserStore.d.ts +2 -2
- package/types/src/editor/BlockNoteEditor.d.ts +34 -105
- package/types/src/editor/BlockNoteExtension.d.ts +87 -22
- package/types/src/editor/managers/EventManager.d.ts +25 -16
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +8 -0
- package/types/src/editor/managers/ExtensionManager/index.d.ts +83 -0
- package/types/src/editor/managers/ExtensionManager/symbol.d.ts +5 -0
- package/types/src/editor/managers/StateManager.d.ts +1 -12
- package/types/src/editor/managers/index.d.ts +1 -2
- package/types/src/extensions/BlockChange/BlockChange.d.ts +16 -0
- package/types/src/extensions/Collaboration/ForkYDoc.d.ts +34 -0
- package/types/src/extensions/Collaboration/ForkYDoc.test.d.ts +1 -0
- package/types/src/extensions/Collaboration/YCursorPlugin.d.ts +24 -0
- package/types/src/extensions/Collaboration/YSync.d.ts +8 -0
- package/types/src/extensions/Collaboration/YUndo.d.ts +12 -0
- package/types/src/extensions/Collaboration/schemaMigration/SchemaMigration.d.ts +8 -0
- package/types/src/extensions/DropCursor/DropCursor.d.ts +5 -0
- package/types/src/extensions/FilePanel/FilePanel.d.ts +11 -0
- package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +9 -0
- package/types/src/extensions/History/History.d.ts +6 -0
- package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +24 -0
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +5 -0
- package/types/src/extensions/Placeholder/Placeholder.d.ts +6 -0
- package/types/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.d.ts → PreviousBlockType.d.ts} +9 -5
- package/types/src/extensions/ShowSelection/ShowSelection.d.ts +21 -0
- package/types/src/extensions/SideMenu/{SideMenuPlugin.d.ts → SideMenu.d.ts} +11 -15
- package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +54 -0
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +1 -1
- package/types/src/extensions/TableHandles/{TableHandlesPlugin.d.ts → TableHandles.d.ts} +28 -31
- package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -0
- package/types/src/extensions/index.d.ts +24 -0
- package/types/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.d.ts +1 -1
- package/types/src/extensions/tiptap-extensions/index.d.ts +11 -0
- package/types/src/index.d.ts +1 -13
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/internal.d.ts +2 -2
- package/types/src/schema/blocks/types.d.ts +5 -5
- package/types/src/util/topo-sort.d.ts +8 -0
- package/dist/BlockNoteSchema-Bi-eeHal.js.map +0 -1
- package/dist/BlockNoteSchema-DjDaA2C3.cjs +0 -6
- package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +0 -1
- package/dist/blockToNode-DIfPWLH8.js.map +0 -1
- package/src/comments/models/User.ts +0 -8
- package/src/editor/BlockNoteExtensions.ts +0 -325
- package/src/editor/managers/CollaborationManager.ts +0 -212
- package/src/editor/managers/ExtensionManager.ts +0 -130
- package/src/extensions/Collaboration/CursorPlugin.ts +0 -189
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +0 -192
- package/src/extensions/Collaboration/SyncPlugin.ts +0 -18
- package/src/extensions/Collaboration/UndoPlugin.ts +0 -18
- package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +0 -59
- package/src/extensions/Comments/CommentsPlugin.ts +0 -392
- package/src/extensions/FilePanel/FilePanelPlugin.ts +0 -206
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +0 -363
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +0 -380
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +0 -75
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +0 -147
- package/types/src/comments/models/User.d.ts +0 -8
- package/types/src/editor/BlockNoteExtensions.d.ts +0 -43
- package/types/src/editor/managers/CollaborationManager.d.ts +0 -115
- package/types/src/editor/managers/ExtensionManager.d.ts +0 -68
- package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +0 -15
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +0 -37
- package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +0 -41
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +0 -7
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +0 -9
- package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +0 -7
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +0 -66
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +0 -31
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +0 -41
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +0 -42
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +0 -5
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +0 -6
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +0 -15
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +0 -31
- package/types/src/extensions/TrailingNode/TrailingNodeExtension.d.ts +0 -13
- /package/src/{extensions/Comments/CommentMark.ts → comments/mark.ts} +0 -0
- /package/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.ts +0 -0
- /package/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.ts +0 -0
- /package/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.ts +0 -0
- /package/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.ts +0 -0
- /package/types/src/{extensions/Comments/CommentMark.d.ts → comments/mark.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDocPlugin.test.d.ts → editor/BlockNoteExtension.test.d.ts} +0 -0
- /package/types/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.d.ts +0 -0
- /package/types/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.d.ts +0 -0
- /package/types/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.d.ts +0 -0
- /package/types/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.d.ts +0 -0
- /package/types/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.d.ts +0 -0
- /package/types/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.d.ts +0 -0
package/dist/comments.js
CHANGED
|
@@ -1,13 +1,325 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var Y = (r, d, e) => d in r ? x(r, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[d] = e;
|
|
3
|
+
var c = (r, d, e) => Y(r, typeof d != "symbol" ? d + "" : d, e);
|
|
4
|
+
import { PluginKey as $, Plugin as k } from "prosemirror-state";
|
|
5
|
+
import { DecorationSet as C, Decoration as z } from "prosemirror-view";
|
|
6
|
+
import { ySyncPluginKey as B, getRelativeSelection as q } from "y-prosemirror";
|
|
7
|
+
import { c as L, a as N } from "./BlockNoteExtension-C2X7LW-V.js";
|
|
8
|
+
import { S } from "./ShowSelection-Dz-NEase.js";
|
|
9
|
+
import { Mark as O, mergeAttributes as _ } from "@tiptap/core";
|
|
10
|
+
import { E as H } from "./EventEmitter-CjSwpTbz.js";
|
|
11
|
+
import * as g from "yjs";
|
|
12
|
+
import { v4 as D } from "uuid";
|
|
13
|
+
const M = O.create({
|
|
14
|
+
name: "comment",
|
|
15
|
+
excludes: "",
|
|
16
|
+
inclusive: !1,
|
|
17
|
+
keepOnSplit: !0,
|
|
18
|
+
addAttributes() {
|
|
19
|
+
return {
|
|
20
|
+
// orphans are marks that currently don't have an active thread. It could be
|
|
21
|
+
// that users have resolved the thread. Resolved threads by default are not shown in the document,
|
|
22
|
+
// but we need to keep the mark (positioning) data so we can still "revive" it when the thread is unresolved
|
|
23
|
+
// or we enter a "comments" view that includes resolved threads.
|
|
24
|
+
orphan: {
|
|
25
|
+
parseHTML: (r) => !!r.getAttribute("data-orphan"),
|
|
26
|
+
renderHTML: (r) => r.orphan ? {
|
|
27
|
+
"data-orphan": "true"
|
|
28
|
+
} : {},
|
|
29
|
+
default: !1
|
|
30
|
+
},
|
|
31
|
+
threadId: {
|
|
32
|
+
parseHTML: (r) => r.getAttribute("data-bn-thread-id"),
|
|
33
|
+
renderHTML: (r) => ({
|
|
34
|
+
"data-bn-thread-id": r.threadId
|
|
35
|
+
}),
|
|
36
|
+
default: ""
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
renderHTML({ HTMLAttributes: r }) {
|
|
41
|
+
return [
|
|
42
|
+
"span",
|
|
43
|
+
_(r, {
|
|
44
|
+
class: "bn-thread-mark"
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
},
|
|
48
|
+
parseHTML() {
|
|
49
|
+
return [{ tag: "span.bn-thread-mark" }];
|
|
50
|
+
},
|
|
51
|
+
extendMarkSchema(r) {
|
|
52
|
+
return r.name === "comment" ? {
|
|
53
|
+
blocknoteIgnore: !0
|
|
54
|
+
} : {};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
class F extends H {
|
|
58
|
+
constructor(e) {
|
|
59
|
+
super();
|
|
60
|
+
c(this, "userCache", /* @__PURE__ */ new Map());
|
|
61
|
+
// avoid duplicate loads
|
|
62
|
+
c(this, "loadingUsers", /* @__PURE__ */ new Set());
|
|
63
|
+
this.resolveUsers = e;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Load information about users based on an array of user ids.
|
|
67
|
+
*/
|
|
68
|
+
async loadUsers(e) {
|
|
69
|
+
const t = e.filter(
|
|
70
|
+
(a) => !this.userCache.has(a) && !this.loadingUsers.has(a)
|
|
71
|
+
);
|
|
72
|
+
if (t.length !== 0) {
|
|
73
|
+
for (const a of t)
|
|
74
|
+
this.loadingUsers.add(a);
|
|
75
|
+
try {
|
|
76
|
+
const a = await this.resolveUsers(t);
|
|
77
|
+
for (const s of a)
|
|
78
|
+
this.userCache.set(s.id, s);
|
|
79
|
+
this.emit("update", this.userCache);
|
|
80
|
+
} finally {
|
|
81
|
+
for (const a of t)
|
|
82
|
+
this.loadingUsers.delete(a);
|
|
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
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const w = new $("blocknote-comments");
|
|
105
|
+
function K(r, d) {
|
|
106
|
+
const e = /* @__PURE__ */ new Map();
|
|
107
|
+
return r.descendants((t, a) => {
|
|
108
|
+
t.marks.forEach((s) => {
|
|
109
|
+
if (s.type.name === d) {
|
|
110
|
+
const o = s.attrs.threadId;
|
|
111
|
+
if (!o)
|
|
112
|
+
return;
|
|
113
|
+
const m = a, n = m + t.nodeSize, i = e.get(o) ?? {
|
|
114
|
+
from: 1 / 0,
|
|
115
|
+
to: 0
|
|
116
|
+
};
|
|
117
|
+
e.set(o, {
|
|
118
|
+
from: Math.min(m, i.from),
|
|
119
|
+
to: Math.max(n, i.to)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}), e;
|
|
124
|
+
}
|
|
125
|
+
const ne = L(
|
|
126
|
+
({
|
|
127
|
+
editor: r,
|
|
128
|
+
options: { schema: d, threadStore: e, resolveUsers: t }
|
|
129
|
+
}) => {
|
|
130
|
+
if (!t)
|
|
131
|
+
throw new Error(
|
|
132
|
+
"resolveUsers is required to be defined when using comments"
|
|
133
|
+
);
|
|
134
|
+
if (!e)
|
|
135
|
+
throw new Error(
|
|
136
|
+
"threadStore is required to be defined when using comments"
|
|
137
|
+
);
|
|
138
|
+
const a = M.name, s = new F(t), o = N(
|
|
139
|
+
{
|
|
140
|
+
pendingComment: !1,
|
|
141
|
+
selectedThreadId: void 0,
|
|
142
|
+
threadPositions: /* @__PURE__ */ new Map()
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
onUpdate() {
|
|
146
|
+
o.state.selectedThreadId !== o.prevState.selectedThreadId && r.transact((n) => n.setMeta(w, !0));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
), m = (n) => {
|
|
150
|
+
r.transact((i) => {
|
|
151
|
+
i.doc.descendants((u, l) => {
|
|
152
|
+
u.marks.forEach((h) => {
|
|
153
|
+
if (h.type.name === a) {
|
|
154
|
+
const T = h.type, f = h.attrs.threadId, A = n.get(f), v = !!(!A || A.resolved || A.deletedAt);
|
|
155
|
+
if (v !== h.attrs.orphan) {
|
|
156
|
+
const E = Math.max(l, 0), b = Math.min(
|
|
157
|
+
l + u.nodeSize,
|
|
158
|
+
i.doc.content.size - 1,
|
|
159
|
+
i.doc.content.size - 1
|
|
160
|
+
);
|
|
161
|
+
i.removeMark(E, b, h), i.addMark(
|
|
162
|
+
E,
|
|
163
|
+
b,
|
|
164
|
+
T.create({
|
|
165
|
+
...h.attrs,
|
|
166
|
+
orphan: v
|
|
167
|
+
})
|
|
168
|
+
), v && o.state.selectedThreadId === f && o.setState((P) => ({
|
|
169
|
+
...P,
|
|
170
|
+
selectedThreadId: void 0
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
key: "comments",
|
|
180
|
+
store: o,
|
|
181
|
+
prosemirrorPlugins: [
|
|
182
|
+
new k({
|
|
183
|
+
key: w,
|
|
184
|
+
state: {
|
|
185
|
+
init() {
|
|
186
|
+
return {
|
|
187
|
+
decorations: C.empty
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
apply(n, i) {
|
|
191
|
+
const u = n.getMeta(w);
|
|
192
|
+
if (!n.docChanged && !u)
|
|
193
|
+
return i;
|
|
194
|
+
const l = n.docChanged ? K(n.doc, a) : o.state.threadPositions;
|
|
195
|
+
(l.size > 0 || o.state.threadPositions.size > 0) && o.setState((T) => ({
|
|
196
|
+
...T,
|
|
197
|
+
threadPositions: l
|
|
198
|
+
}));
|
|
199
|
+
const h = [];
|
|
200
|
+
if (o.state.selectedThreadId) {
|
|
201
|
+
const T = l.get(
|
|
202
|
+
o.state.selectedThreadId
|
|
203
|
+
);
|
|
204
|
+
T && h.push(
|
|
205
|
+
z.inline(
|
|
206
|
+
T.from,
|
|
207
|
+
T.to,
|
|
208
|
+
{
|
|
209
|
+
class: "bn-thread-mark-selected"
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
decorations: C.create(n.doc, h)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
props: {
|
|
220
|
+
decorations(n) {
|
|
221
|
+
var i;
|
|
222
|
+
return ((i = w.getState(n)) == null ? void 0 : i.decorations) ?? C.empty;
|
|
223
|
+
},
|
|
224
|
+
handleClick: (n, i, u) => {
|
|
225
|
+
if (u.button !== 0)
|
|
226
|
+
return;
|
|
227
|
+
const l = n.state.doc.nodeAt(i);
|
|
228
|
+
if (!l) {
|
|
229
|
+
o.setState((f) => ({
|
|
230
|
+
...f,
|
|
231
|
+
selectedThreadId: void 0
|
|
232
|
+
}));
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const h = l.marks.find(
|
|
236
|
+
(f) => f.type.name === a && f.attrs.orphan !== !0
|
|
237
|
+
), T = h == null ? void 0 : h.attrs.threadId;
|
|
238
|
+
T !== o.state.selectedThreadId && o.setState((f) => ({
|
|
239
|
+
...f,
|
|
240
|
+
selectedThreadId: T
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
],
|
|
246
|
+
threadStore: e,
|
|
247
|
+
mount() {
|
|
248
|
+
const n = e.subscribe(m);
|
|
249
|
+
m(e.getThreads());
|
|
250
|
+
const i = r.onSelectionChange(() => {
|
|
251
|
+
o.state.pendingComment && o.setState((u) => ({
|
|
252
|
+
...u,
|
|
253
|
+
pendingComment: !1
|
|
254
|
+
}));
|
|
255
|
+
});
|
|
256
|
+
return () => {
|
|
257
|
+
n(), i();
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
selectThread(n, i = !0) {
|
|
261
|
+
var u, l;
|
|
262
|
+
if (o.state.selectedThreadId !== n && (o.setState((h) => ({
|
|
263
|
+
...h,
|
|
264
|
+
pendingComment: !1,
|
|
265
|
+
selectedThreadId: n
|
|
266
|
+
})), n && i)) {
|
|
267
|
+
const h = o.state.threadPositions.get(n);
|
|
268
|
+
if (!h)
|
|
269
|
+
return;
|
|
270
|
+
(l = (u = r.prosemirrorView) == null ? void 0 : u.domAtPos(h.from).node) == null || l.scrollIntoView({
|
|
271
|
+
behavior: "smooth",
|
|
272
|
+
block: "center"
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
startPendingComment() {
|
|
277
|
+
var n;
|
|
278
|
+
o.setState((i) => ({
|
|
279
|
+
...i,
|
|
280
|
+
selectedThreadId: void 0,
|
|
281
|
+
pendingComment: !0
|
|
282
|
+
})), (n = r.getExtension(S)) == null || n.showSelection(!0);
|
|
283
|
+
},
|
|
284
|
+
stopPendingComment() {
|
|
285
|
+
var n;
|
|
286
|
+
o.setState((i) => ({
|
|
287
|
+
...i,
|
|
288
|
+
selectedThreadId: void 0,
|
|
289
|
+
pendingComment: !1
|
|
290
|
+
})), (n = r.getExtension(S)) == null || n.showSelection(!1);
|
|
291
|
+
},
|
|
292
|
+
async createThread(n) {
|
|
293
|
+
const i = await e.createThread(n);
|
|
294
|
+
if (e.addThreadToDocument) {
|
|
295
|
+
const u = r.prosemirrorView, l = u.state.selection, h = B.getState(u.state), T = {
|
|
296
|
+
prosemirror: {
|
|
297
|
+
head: l.head,
|
|
298
|
+
anchor: l.anchor
|
|
299
|
+
},
|
|
300
|
+
yjs: h ? q(h.binding, u.state) : void 0
|
|
301
|
+
};
|
|
302
|
+
await e.addThreadToDocument({
|
|
303
|
+
threadId: i.id,
|
|
304
|
+
selection: T
|
|
305
|
+
});
|
|
306
|
+
} else
|
|
307
|
+
r._tiptapEditor.commands.setMark(a, {
|
|
308
|
+
orphan: !1,
|
|
309
|
+
threadId: i.id
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
userStore: s,
|
|
313
|
+
commentEditorSchema: d,
|
|
314
|
+
tiptapExtensions: [M]
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
class V {
|
|
7
319
|
}
|
|
8
|
-
class
|
|
9
|
-
constructor(
|
|
10
|
-
super(), this.userId =
|
|
320
|
+
class oe extends V {
|
|
321
|
+
constructor(d, e) {
|
|
322
|
+
super(), this.userId = d, this.role = e;
|
|
11
323
|
}
|
|
12
324
|
/**
|
|
13
325
|
* Auth: should be possible by anyone with comment access
|
|
@@ -18,37 +330,37 @@ class b extends v {
|
|
|
18
330
|
/**
|
|
19
331
|
* Auth: should be possible by anyone with comment access
|
|
20
332
|
*/
|
|
21
|
-
canAddComment(
|
|
333
|
+
canAddComment(d) {
|
|
22
334
|
return !0;
|
|
23
335
|
}
|
|
24
336
|
/**
|
|
25
337
|
* Auth: should only be possible by the comment author
|
|
26
338
|
*/
|
|
27
|
-
canUpdateComment(
|
|
28
|
-
return
|
|
339
|
+
canUpdateComment(d) {
|
|
340
|
+
return d.userId === this.userId;
|
|
29
341
|
}
|
|
30
342
|
/**
|
|
31
343
|
* Auth: should be possible by the comment author OR an editor of the document
|
|
32
344
|
*/
|
|
33
|
-
canDeleteComment(
|
|
34
|
-
return
|
|
345
|
+
canDeleteComment(d) {
|
|
346
|
+
return d.userId === this.userId || this.role === "editor";
|
|
35
347
|
}
|
|
36
348
|
/**
|
|
37
349
|
* Auth: should only be possible by an editor of the document
|
|
38
350
|
*/
|
|
39
|
-
canDeleteThread(
|
|
351
|
+
canDeleteThread(d) {
|
|
40
352
|
return this.role === "editor";
|
|
41
353
|
}
|
|
42
354
|
/**
|
|
43
355
|
* Auth: should be possible by anyone with comment access
|
|
44
356
|
*/
|
|
45
|
-
canResolveThread(
|
|
357
|
+
canResolveThread(d) {
|
|
46
358
|
return !0;
|
|
47
359
|
}
|
|
48
360
|
/**
|
|
49
361
|
* Auth: should be possible by anyone with comment access
|
|
50
362
|
*/
|
|
51
|
-
canUnresolveThread(
|
|
363
|
+
canUnresolveThread(d) {
|
|
52
364
|
return !0;
|
|
53
365
|
}
|
|
54
366
|
/**
|
|
@@ -56,8 +368,8 @@ class b extends v {
|
|
|
56
368
|
*
|
|
57
369
|
* 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
370
|
*/
|
|
59
|
-
canAddReaction(
|
|
60
|
-
return e ? !
|
|
371
|
+
canAddReaction(d, e) {
|
|
372
|
+
return e ? !d.reactions.some(
|
|
61
373
|
(t) => t.emoji === e && t.userIds.includes(this.userId)
|
|
62
374
|
) : !0;
|
|
63
375
|
}
|
|
@@ -66,23 +378,23 @@ class b extends v {
|
|
|
66
378
|
*
|
|
67
379
|
* 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
380
|
*/
|
|
69
|
-
canDeleteReaction(
|
|
70
|
-
return e ?
|
|
381
|
+
canDeleteReaction(d, e) {
|
|
382
|
+
return e ? d.reactions.some(
|
|
71
383
|
(t) => t.emoji === e && t.userIds.includes(this.userId)
|
|
72
384
|
) : !0;
|
|
73
385
|
}
|
|
74
386
|
}
|
|
75
|
-
class
|
|
76
|
-
constructor(
|
|
77
|
-
|
|
78
|
-
this.auth =
|
|
387
|
+
class R {
|
|
388
|
+
constructor(d) {
|
|
389
|
+
c(this, "auth");
|
|
390
|
+
this.auth = d;
|
|
79
391
|
}
|
|
80
392
|
}
|
|
81
|
-
class
|
|
393
|
+
class ie extends R {
|
|
82
394
|
constructor(e, t, a) {
|
|
83
395
|
super(a);
|
|
84
396
|
// TipTapThreadStore does not support addThreadToDocument
|
|
85
|
-
|
|
397
|
+
c(this, "addThreadToDocument");
|
|
86
398
|
this.userId = e, this.provider = t;
|
|
87
399
|
}
|
|
88
400
|
/**
|
|
@@ -137,16 +449,16 @@ class j extends w {
|
|
|
137
449
|
tiptapCommentToCommentData(e) {
|
|
138
450
|
var a, s, o;
|
|
139
451
|
const t = [];
|
|
140
|
-
for (const
|
|
141
|
-
const
|
|
142
|
-
(i) => i.emoji ===
|
|
452
|
+
for (const m of ((a = e.data) == null ? void 0 : a.reactions) || []) {
|
|
453
|
+
const n = t.find(
|
|
454
|
+
(i) => i.emoji === m.emoji
|
|
143
455
|
);
|
|
144
|
-
|
|
145
|
-
Math.min(
|
|
456
|
+
n ? (n.userIds.push(m.userId), n.createdAt = new Date(
|
|
457
|
+
Math.min(n.createdAt.getTime(), m.createdAt)
|
|
146
458
|
)) : t.push({
|
|
147
|
-
emoji:
|
|
148
|
-
createdAt: new Date(
|
|
149
|
-
userIds: [
|
|
459
|
+
emoji: m.emoji,
|
|
460
|
+
createdAt: new Date(m.createdAt),
|
|
461
|
+
userIds: [m.userId]
|
|
150
462
|
});
|
|
151
463
|
}
|
|
152
464
|
return {
|
|
@@ -273,29 +585,29 @@ class j extends w {
|
|
|
273
585
|
};
|
|
274
586
|
}
|
|
275
587
|
}
|
|
276
|
-
function
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
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)
|
|
279
591
|
throw new Error("Reactions should be empty in commentToYMap");
|
|
280
|
-
return
|
|
592
|
+
return d.set("reactionsByUser", new g.Map()), d.set("metadata", r.metadata), d;
|
|
281
593
|
}
|
|
282
|
-
function
|
|
594
|
+
function G(r) {
|
|
283
595
|
var t;
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
const e = new
|
|
287
|
-
return e.push(
|
|
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;
|
|
288
600
|
}
|
|
289
|
-
function
|
|
601
|
+
function J(r) {
|
|
290
602
|
return {
|
|
291
|
-
emoji:
|
|
292
|
-
createdAt: new Date(
|
|
293
|
-
userId:
|
|
603
|
+
emoji: r.get("emoji"),
|
|
604
|
+
createdAt: new Date(r.get("createdAt")),
|
|
605
|
+
userId: r.get("userId")
|
|
294
606
|
};
|
|
295
607
|
}
|
|
296
|
-
function
|
|
297
|
-
return [...
|
|
298
|
-
(e) =>
|
|
608
|
+
function Q(r) {
|
|
609
|
+
return [...r.values()].map(
|
|
610
|
+
(e) => J(e)
|
|
299
611
|
).reduce(
|
|
300
612
|
(e, t) => {
|
|
301
613
|
const a = e.find((s) => s.emoji === t.emoji);
|
|
@@ -313,64 +625,64 @@ function D(d) {
|
|
|
313
625
|
[]
|
|
314
626
|
);
|
|
315
627
|
}
|
|
316
|
-
function
|
|
628
|
+
function I(r) {
|
|
317
629
|
return {
|
|
318
630
|
type: "comment",
|
|
319
|
-
id:
|
|
320
|
-
userId:
|
|
321
|
-
createdAt: new Date(
|
|
322
|
-
updatedAt: new Date(
|
|
323
|
-
deletedAt:
|
|
324
|
-
reactions:
|
|
325
|
-
metadata:
|
|
326
|
-
body:
|
|
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")
|
|
327
639
|
};
|
|
328
640
|
}
|
|
329
|
-
function
|
|
641
|
+
function p(r) {
|
|
330
642
|
return {
|
|
331
643
|
type: "thread",
|
|
332
|
-
id:
|
|
333
|
-
createdAt: new Date(
|
|
334
|
-
updatedAt: new Date(
|
|
335
|
-
comments: (
|
|
336
|
-
(
|
|
644
|
+
id: r.get("id"),
|
|
645
|
+
createdAt: new Date(r.get("createdAt")),
|
|
646
|
+
updatedAt: new Date(r.get("updatedAt")),
|
|
647
|
+
comments: (r.get("comments") || []).map(
|
|
648
|
+
(d) => I(d)
|
|
337
649
|
),
|
|
338
|
-
resolved:
|
|
339
|
-
resolvedUpdatedAt: new Date(
|
|
340
|
-
resolvedBy:
|
|
341
|
-
metadata:
|
|
650
|
+
resolved: r.get("resolved"),
|
|
651
|
+
resolvedUpdatedAt: new Date(r.get("resolvedUpdatedAt")),
|
|
652
|
+
resolvedBy: r.get("resolvedBy"),
|
|
653
|
+
metadata: r.get("metadata")
|
|
342
654
|
};
|
|
343
655
|
}
|
|
344
|
-
class
|
|
345
|
-
constructor(
|
|
346
|
-
super(e), this.threadsYMap =
|
|
656
|
+
class j extends R {
|
|
657
|
+
constructor(d, e) {
|
|
658
|
+
super(e), this.threadsYMap = d;
|
|
347
659
|
}
|
|
348
660
|
// TODO: async / reactive interface?
|
|
349
|
-
getThread(
|
|
350
|
-
const e = this.threadsYMap.get(
|
|
661
|
+
getThread(d) {
|
|
662
|
+
const e = this.threadsYMap.get(d);
|
|
351
663
|
if (!e)
|
|
352
664
|
throw new Error("Thread not found");
|
|
353
|
-
return
|
|
665
|
+
return p(e);
|
|
354
666
|
}
|
|
355
667
|
getThreads() {
|
|
356
|
-
const
|
|
668
|
+
const d = /* @__PURE__ */ new Map();
|
|
357
669
|
return this.threadsYMap.forEach((e, t) => {
|
|
358
|
-
e instanceof
|
|
359
|
-
}),
|
|
670
|
+
e instanceof g.Map && d.set(t, p(e));
|
|
671
|
+
}), d;
|
|
360
672
|
}
|
|
361
|
-
subscribe(
|
|
673
|
+
subscribe(d) {
|
|
362
674
|
const e = () => {
|
|
363
|
-
|
|
675
|
+
d(this.getThreads());
|
|
364
676
|
};
|
|
365
677
|
return this.threadsYMap.observeDeep(e), () => {
|
|
366
678
|
this.threadsYMap.unobserveDeep(e);
|
|
367
679
|
};
|
|
368
680
|
}
|
|
369
681
|
}
|
|
370
|
-
class
|
|
682
|
+
class ce extends j {
|
|
371
683
|
constructor(e, t, a, s) {
|
|
372
684
|
super(a, s);
|
|
373
|
-
|
|
685
|
+
c(this, "doRequest", async (e, t, a) => {
|
|
374
686
|
const s = await fetch(`${this.BASE_URL}${e}`, {
|
|
375
687
|
method: t,
|
|
376
688
|
body: JSON.stringify(a),
|
|
@@ -383,30 +695,30 @@ class Y extends f {
|
|
|
383
695
|
throw new Error(`Failed to ${t} ${e}: ${s.statusText}`);
|
|
384
696
|
return s.json();
|
|
385
697
|
});
|
|
386
|
-
|
|
698
|
+
c(this, "addThreadToDocument", async (e) => {
|
|
387
699
|
const { threadId: t, ...a } = e;
|
|
388
700
|
return this.doRequest(`/${t}/addToDocument`, "POST", a);
|
|
389
701
|
});
|
|
390
|
-
|
|
391
|
-
|
|
702
|
+
c(this, "createThread", async (e) => this.doRequest("", "POST", e));
|
|
703
|
+
c(this, "addComment", (e) => {
|
|
392
704
|
const { threadId: t, ...a } = e;
|
|
393
705
|
return this.doRequest(`/${t}/comments`, "POST", a);
|
|
394
706
|
});
|
|
395
|
-
|
|
707
|
+
c(this, "updateComment", (e) => {
|
|
396
708
|
const { threadId: t, commentId: a, ...s } = e;
|
|
397
709
|
return this.doRequest(`/${t}/comments/${a}`, "PUT", s);
|
|
398
710
|
});
|
|
399
|
-
|
|
711
|
+
c(this, "deleteComment", (e) => {
|
|
400
712
|
const { threadId: t, commentId: a, ...s } = e;
|
|
401
713
|
return this.doRequest(
|
|
402
714
|
`/${t}/comments/${a}?soft=${!!s.softDelete}`,
|
|
403
715
|
"DELETE"
|
|
404
716
|
);
|
|
405
717
|
});
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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) => {
|
|
410
722
|
const { threadId: t, commentId: a, ...s } = e;
|
|
411
723
|
return this.doRequest(
|
|
412
724
|
`/${t}/comments/${a}/reactions`,
|
|
@@ -414,24 +726,24 @@ class Y extends f {
|
|
|
414
726
|
s
|
|
415
727
|
);
|
|
416
728
|
});
|
|
417
|
-
|
|
729
|
+
c(this, "deleteReaction", (e) => this.doRequest(
|
|
418
730
|
`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`,
|
|
419
731
|
"DELETE"
|
|
420
732
|
));
|
|
421
733
|
this.BASE_URL = e, this.headers = t;
|
|
422
734
|
}
|
|
423
735
|
}
|
|
424
|
-
class
|
|
736
|
+
class he extends j {
|
|
425
737
|
constructor(e, t, a) {
|
|
426
738
|
super(t, a);
|
|
427
|
-
|
|
428
|
-
|
|
739
|
+
c(this, "transact", (e) => async (t) => this.threadsYMap.doc.transact(() => e(t)));
|
|
740
|
+
c(this, "createThread", this.transact(
|
|
429
741
|
(e) => {
|
|
430
742
|
if (!this.auth.canCreateThread())
|
|
431
743
|
throw new Error("Not authorized");
|
|
432
744
|
const t = /* @__PURE__ */ new Date(), a = {
|
|
433
745
|
type: "comment",
|
|
434
|
-
id:
|
|
746
|
+
id: D(),
|
|
435
747
|
userId: this.userId,
|
|
436
748
|
createdAt: t,
|
|
437
749
|
updatedAt: t,
|
|
@@ -440,28 +752,28 @@ class $ extends f {
|
|
|
440
752
|
body: e.initialComment.body
|
|
441
753
|
}, s = {
|
|
442
754
|
type: "thread",
|
|
443
|
-
id:
|
|
755
|
+
id: D(),
|
|
444
756
|
createdAt: t,
|
|
445
757
|
updatedAt: t,
|
|
446
758
|
comments: [a],
|
|
447
759
|
resolved: !1,
|
|
448
760
|
metadata: e.metadata
|
|
449
761
|
};
|
|
450
|
-
return this.threadsYMap.set(s.id,
|
|
762
|
+
return this.threadsYMap.set(s.id, G(s)), s;
|
|
451
763
|
}
|
|
452
764
|
));
|
|
453
765
|
// YjsThreadStore does not support addThreadToDocument
|
|
454
|
-
|
|
455
|
-
|
|
766
|
+
c(this, "addThreadToDocument");
|
|
767
|
+
c(this, "addComment", this.transact(
|
|
456
768
|
(e) => {
|
|
457
769
|
const t = this.threadsYMap.get(e.threadId);
|
|
458
770
|
if (!t)
|
|
459
771
|
throw new Error("Thread not found");
|
|
460
|
-
if (!this.auth.canAddComment(
|
|
772
|
+
if (!this.auth.canAddComment(p(t)))
|
|
461
773
|
throw new Error("Not authorized");
|
|
462
774
|
const a = /* @__PURE__ */ new Date(), s = {
|
|
463
775
|
type: "comment",
|
|
464
|
-
id:
|
|
776
|
+
id: D(),
|
|
465
777
|
userId: this.userId,
|
|
466
778
|
createdAt: a,
|
|
467
779
|
updatedAt: a,
|
|
@@ -471,103 +783,103 @@ class $ extends f {
|
|
|
471
783
|
body: e.comment.body
|
|
472
784
|
};
|
|
473
785
|
return t.get("comments").push([
|
|
474
|
-
|
|
786
|
+
U(s)
|
|
475
787
|
]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s;
|
|
476
788
|
}
|
|
477
789
|
));
|
|
478
|
-
|
|
790
|
+
c(this, "updateComment", this.transact(
|
|
479
791
|
(e) => {
|
|
480
792
|
const t = this.threadsYMap.get(e.threadId);
|
|
481
793
|
if (!t)
|
|
482
794
|
throw new Error("Thread not found");
|
|
483
|
-
const a =
|
|
795
|
+
const a = y(
|
|
484
796
|
t.get("comments"),
|
|
485
797
|
(o) => o.get("id") === e.commentId
|
|
486
798
|
);
|
|
487
799
|
if (a === -1)
|
|
488
800
|
throw new Error("Comment not found");
|
|
489
801
|
const s = t.get("comments").get(a);
|
|
490
|
-
if (!this.auth.canUpdateComment(
|
|
802
|
+
if (!this.auth.canUpdateComment(I(s)))
|
|
491
803
|
throw new Error("Not authorized");
|
|
492
804
|
s.set("body", e.comment.body), s.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s.set("metadata", e.comment.metadata);
|
|
493
805
|
}
|
|
494
806
|
));
|
|
495
|
-
|
|
807
|
+
c(this, "deleteComment", this.transact(
|
|
496
808
|
(e) => {
|
|
497
809
|
const t = this.threadsYMap.get(e.threadId);
|
|
498
810
|
if (!t)
|
|
499
811
|
throw new Error("Thread not found");
|
|
500
|
-
const a =
|
|
812
|
+
const a = y(
|
|
501
813
|
t.get("comments"),
|
|
502
814
|
(o) => o.get("id") === e.commentId
|
|
503
815
|
);
|
|
504
816
|
if (a === -1)
|
|
505
817
|
throw new Error("Comment not found");
|
|
506
818
|
const s = t.get("comments").get(a);
|
|
507
|
-
if (!this.auth.canDeleteComment(
|
|
819
|
+
if (!this.auth.canDeleteComment(I(s)))
|
|
508
820
|
throw new Error("Not authorized");
|
|
509
821
|
if (s.get("deletedAt"))
|
|
510
822
|
throw new Error("Comment already deleted");
|
|
511
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());
|
|
512
824
|
}
|
|
513
825
|
));
|
|
514
|
-
|
|
826
|
+
c(this, "deleteThread", this.transact((e) => {
|
|
515
827
|
if (!this.auth.canDeleteThread(
|
|
516
|
-
|
|
828
|
+
p(this.threadsYMap.get(e.threadId))
|
|
517
829
|
))
|
|
518
830
|
throw new Error("Not authorized");
|
|
519
831
|
this.threadsYMap.delete(e.threadId);
|
|
520
832
|
}));
|
|
521
|
-
|
|
833
|
+
c(this, "resolveThread", this.transact((e) => {
|
|
522
834
|
const t = this.threadsYMap.get(e.threadId);
|
|
523
835
|
if (!t)
|
|
524
836
|
throw new Error("Thread not found");
|
|
525
|
-
if (!this.auth.canResolveThread(
|
|
837
|
+
if (!this.auth.canResolveThread(p(t)))
|
|
526
838
|
throw new Error("Not authorized");
|
|
527
839
|
t.set("resolved", !0), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime()), t.set("resolvedBy", this.userId);
|
|
528
840
|
}));
|
|
529
|
-
|
|
841
|
+
c(this, "unresolveThread", this.transact((e) => {
|
|
530
842
|
const t = this.threadsYMap.get(e.threadId);
|
|
531
843
|
if (!t)
|
|
532
844
|
throw new Error("Thread not found");
|
|
533
|
-
if (!this.auth.canUnresolveThread(
|
|
845
|
+
if (!this.auth.canUnresolveThread(p(t)))
|
|
534
846
|
throw new Error("Not authorized");
|
|
535
847
|
t.set("resolved", !1), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
536
848
|
}));
|
|
537
|
-
|
|
849
|
+
c(this, "addReaction", this.transact(
|
|
538
850
|
(e) => {
|
|
539
851
|
const t = this.threadsYMap.get(e.threadId);
|
|
540
852
|
if (!t)
|
|
541
853
|
throw new Error("Thread not found");
|
|
542
|
-
const a =
|
|
854
|
+
const a = y(
|
|
543
855
|
t.get("comments"),
|
|
544
856
|
(i) => i.get("id") === e.commentId
|
|
545
857
|
);
|
|
546
858
|
if (a === -1)
|
|
547
859
|
throw new Error("Comment not found");
|
|
548
860
|
const s = t.get("comments").get(a);
|
|
549
|
-
if (!this.auth.canAddReaction(
|
|
861
|
+
if (!this.auth.canAddReaction(I(s), e.emoji))
|
|
550
862
|
throw new Error("Not authorized");
|
|
551
|
-
const o = /* @__PURE__ */ new Date(),
|
|
552
|
-
if (!
|
|
553
|
-
const i = new
|
|
554
|
-
i.set("emoji", e.emoji), i.set("createdAt", o.getTime()), i.set("userId", this.userId),
|
|
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);
|
|
555
867
|
}
|
|
556
868
|
}
|
|
557
869
|
));
|
|
558
|
-
|
|
870
|
+
c(this, "deleteReaction", this.transact(
|
|
559
871
|
(e) => {
|
|
560
872
|
const t = this.threadsYMap.get(e.threadId);
|
|
561
873
|
if (!t)
|
|
562
874
|
throw new Error("Thread not found");
|
|
563
|
-
const a =
|
|
875
|
+
const a = y(
|
|
564
876
|
t.get("comments"),
|
|
565
|
-
(
|
|
877
|
+
(n) => n.get("id") === e.commentId
|
|
566
878
|
);
|
|
567
879
|
if (a === -1)
|
|
568
880
|
throw new Error("Comment not found");
|
|
569
881
|
const s = t.get("comments").get(a);
|
|
570
|
-
if (!this.auth.canDeleteReaction(
|
|
882
|
+
if (!this.auth.canDeleteReaction(I(s), e.emoji))
|
|
571
883
|
throw new Error("Not authorized");
|
|
572
884
|
const o = `${this.userId}-${e.emoji}`;
|
|
573
885
|
s.get("reactionsByUser").delete(o);
|
|
@@ -576,19 +888,21 @@ class $ extends f {
|
|
|
576
888
|
this.userId = e;
|
|
577
889
|
}
|
|
578
890
|
}
|
|
579
|
-
function
|
|
580
|
-
for (let e = 0; e <
|
|
581
|
-
if (r
|
|
891
|
+
function y(r, d) {
|
|
892
|
+
for (let e = 0; e < r.length; e++)
|
|
893
|
+
if (d(r.get(e)))
|
|
582
894
|
return e;
|
|
583
895
|
return -1;
|
|
584
896
|
}
|
|
585
897
|
export {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
898
|
+
M as CommentMark,
|
|
899
|
+
ne as CommentsExtension,
|
|
900
|
+
oe as DefaultThreadStoreAuth,
|
|
901
|
+
ce as RESTYjsThreadStore,
|
|
902
|
+
R as ThreadStore,
|
|
903
|
+
V as ThreadStoreAuth,
|
|
904
|
+
ie as TiptapThreadStore,
|
|
905
|
+
he as YjsThreadStore,
|
|
906
|
+
j as YjsThreadStoreBase
|
|
593
907
|
};
|
|
594
908
|
//# sourceMappingURL=comments.js.map
|