@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.
Files changed (200) hide show
  1. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +2 -0
  2. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -0
  3. package/dist/BlockNoteExtension-C2X7LW-V.js +25 -0
  4. package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -0
  5. package/dist/BlockNoteSchema-B4gm-Qco.cjs +2 -0
  6. package/dist/BlockNoteSchema-B4gm-Qco.cjs.map +1 -0
  7. package/dist/BlockNoteSchema-C-l154WP.js +270 -0
  8. package/dist/BlockNoteSchema-C-l154WP.js.map +1 -0
  9. package/dist/EventEmitter-CLwfmbqG.cjs +2 -0
  10. package/dist/EventEmitter-CLwfmbqG.cjs.map +1 -0
  11. package/dist/EventEmitter-CjSwpTbz.js +27 -0
  12. package/dist/EventEmitter-CjSwpTbz.js.map +1 -0
  13. package/dist/ShowSelection-BW37oJ6h.cjs +2 -0
  14. package/dist/ShowSelection-BW37oJ6h.cjs.map +1 -0
  15. package/dist/ShowSelection-Dz-NEase.js +43 -0
  16. package/dist/ShowSelection-Dz-NEase.js.map +1 -0
  17. package/dist/TrailingNode-B_zPMWxw.js +2098 -0
  18. package/dist/TrailingNode-B_zPMWxw.js.map +1 -0
  19. package/dist/TrailingNode-CRHrgOnK.cjs +2 -0
  20. package/dist/TrailingNode-CRHrgOnK.cjs.map +1 -0
  21. package/dist/{blockToNode-DIfPWLH8.js → blockToNode-DBNbhwwC.js} +33 -33
  22. package/dist/blockToNode-DBNbhwwC.js.map +1 -0
  23. package/dist/blockToNode-w7H99R6p.cjs.map +1 -1
  24. package/dist/blocknote.cjs +4 -4
  25. package/dist/blocknote.cjs.map +1 -1
  26. package/dist/blocknote.js +2496 -5686
  27. package/dist/blocknote.js.map +1 -1
  28. package/dist/blocks.cjs +1 -1
  29. package/dist/blocks.js +71 -70
  30. package/dist/blocks.js.map +1 -1
  31. package/dist/comments.cjs +1 -1
  32. package/dist/comments.cjs.map +1 -1
  33. package/dist/comments.js +451 -137
  34. package/dist/comments.js.map +1 -1
  35. package/dist/defaultBlocks-DLJ4Q1_J.cjs +6 -0
  36. package/dist/defaultBlocks-DLJ4Q1_J.cjs.map +1 -0
  37. package/dist/{BlockNoteSchema-Bi-eeHal.js → defaultBlocks-DgA_mtQV.js} +974 -1027
  38. package/dist/defaultBlocks-DgA_mtQV.js.map +1 -0
  39. package/dist/extensions.cjs +2 -0
  40. package/dist/extensions.cjs.map +1 -0
  41. package/dist/extensions.js +57 -0
  42. package/dist/extensions.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.js +1 -1
  46. package/package.json +9 -3
  47. package/src/api/nodeConversions/blockToNode.ts +1 -1
  48. package/src/api/nodeConversions/nodeToBlock.ts +1 -1
  49. package/src/blocks/Code/block.ts +4 -4
  50. package/src/blocks/Divider/block.ts +2 -2
  51. package/src/blocks/File/helpers/render/createAddFileButton.ts +7 -5
  52. package/src/blocks/Heading/block.ts +23 -20
  53. package/src/blocks/ListItem/BulletListItem/block.ts +2 -2
  54. package/src/blocks/ListItem/CheckListItem/block.ts +2 -2
  55. package/src/blocks/ListItem/NumberedListItem/block.ts +3 -3
  56. package/src/blocks/ListItem/ToggleListItem/block.ts +2 -2
  57. package/src/blocks/PageBreak/getPageBreakSlashMenuItems.ts +2 -2
  58. package/src/blocks/Paragraph/block.ts +2 -2
  59. package/src/blocks/Quote/block.ts +2 -2
  60. package/src/blocks/Table/block.ts +4 -3
  61. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -1
  62. package/src/comments/extension.ts +353 -0
  63. package/src/comments/index.ts +2 -1
  64. package/src/comments/types.ts +8 -0
  65. package/src/{extensions/Comments → comments}/userstore/UserStore.ts +2 -2
  66. package/src/editor/BlockNoteEditor.test.ts +2 -23
  67. package/src/editor/BlockNoteEditor.ts +60 -453
  68. package/src/editor/BlockNoteExtension.test.ts +103 -0
  69. package/src/editor/BlockNoteExtension.ts +174 -56
  70. package/src/editor/managers/EventManager.ts +64 -35
  71. package/src/editor/managers/ExtensionManager/extensions.ts +214 -0
  72. package/src/editor/managers/ExtensionManager/index.ts +514 -0
  73. package/src/editor/managers/ExtensionManager/symbol.ts +6 -0
  74. package/src/editor/managers/SelectionManager.ts +5 -1
  75. package/src/editor/managers/StateManager.ts +29 -17
  76. package/src/editor/managers/index.ts +1 -5
  77. package/src/extensions/BlockChange/{BlockChangePlugin.ts → BlockChange.ts} +27 -29
  78. package/src/extensions/Collaboration/{ForkYDocPlugin.test.ts → ForkYDoc.test.ts} +6 -5
  79. package/src/extensions/Collaboration/ForkYDoc.ts +158 -0
  80. package/src/extensions/Collaboration/YCursorPlugin.ts +183 -0
  81. package/src/extensions/Collaboration/YSync.ts +16 -0
  82. package/src/extensions/Collaboration/YUndo.ts +12 -0
  83. package/src/extensions/Collaboration/schemaMigration/SchemaMigration.ts +59 -0
  84. package/src/extensions/DropCursor/DropCursor.ts +26 -0
  85. package/src/extensions/FilePanel/FilePanel.ts +41 -0
  86. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +119 -0
  87. package/src/extensions/History/History.ts +11 -0
  88. package/src/extensions/LinkToolbar/LinkToolbar.ts +121 -0
  89. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +74 -0
  90. package/src/extensions/Placeholder/Placeholder.ts +148 -0
  91. package/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.ts → PreviousBlockType.ts} +9 -13
  92. package/src/extensions/ShowSelection/{ShowSelectionPlugin.ts → ShowSelection.ts} +27 -33
  93. package/src/extensions/SideMenu/{SideMenuPlugin.ts → SideMenu.ts} +63 -83
  94. package/src/extensions/SuggestionMenu/{SuggestionPlugin.ts → SuggestionMenu.ts} +71 -77
  95. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +29 -44
  96. package/src/extensions/TableHandles/{TableHandlesPlugin.ts → TableHandles.ts} +416 -437
  97. package/src/extensions/TrailingNode/{TrailingNodeExtension.ts → TrailingNode.ts} +8 -17
  98. package/src/extensions/index.ts +24 -0
  99. package/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.ts +1 -1
  100. package/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.ts +21 -16
  101. package/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.ts +1 -1
  102. package/src/extensions/tiptap-extensions/index.ts +31 -0
  103. package/src/index.ts +1 -13
  104. package/src/schema/blocks/createSpec.ts +14 -11
  105. package/src/schema/blocks/internal.ts +2 -2
  106. package/src/schema/blocks/types.ts +8 -5
  107. package/src/schema/schema.ts +11 -36
  108. package/src/util/topo-sort.ts +46 -0
  109. package/types/src/comments/extension.d.ts +70 -0
  110. package/types/src/comments/index.d.ts +2 -1
  111. package/types/src/comments/types.d.ts +8 -0
  112. package/types/src/{extensions/Comments → comments}/userstore/UserStore.d.ts +2 -2
  113. package/types/src/editor/BlockNoteEditor.d.ts +34 -105
  114. package/types/src/editor/BlockNoteExtension.d.ts +87 -22
  115. package/types/src/editor/managers/EventManager.d.ts +25 -16
  116. package/types/src/editor/managers/ExtensionManager/extensions.d.ts +8 -0
  117. package/types/src/editor/managers/ExtensionManager/index.d.ts +83 -0
  118. package/types/src/editor/managers/ExtensionManager/symbol.d.ts +5 -0
  119. package/types/src/editor/managers/StateManager.d.ts +1 -12
  120. package/types/src/editor/managers/index.d.ts +1 -2
  121. package/types/src/extensions/BlockChange/BlockChange.d.ts +16 -0
  122. package/types/src/extensions/Collaboration/ForkYDoc.d.ts +34 -0
  123. package/types/src/extensions/Collaboration/ForkYDoc.test.d.ts +1 -0
  124. package/types/src/extensions/Collaboration/YCursorPlugin.d.ts +24 -0
  125. package/types/src/extensions/Collaboration/YSync.d.ts +8 -0
  126. package/types/src/extensions/Collaboration/YUndo.d.ts +12 -0
  127. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigration.d.ts +8 -0
  128. package/types/src/extensions/DropCursor/DropCursor.d.ts +5 -0
  129. package/types/src/extensions/FilePanel/FilePanel.d.ts +11 -0
  130. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +9 -0
  131. package/types/src/extensions/History/History.d.ts +6 -0
  132. package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +24 -0
  133. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +5 -0
  134. package/types/src/extensions/Placeholder/Placeholder.d.ts +6 -0
  135. package/types/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.d.ts → PreviousBlockType.d.ts} +9 -5
  136. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +21 -0
  137. package/types/src/extensions/SideMenu/{SideMenuPlugin.d.ts → SideMenu.d.ts} +11 -15
  138. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +54 -0
  139. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +1 -1
  140. package/types/src/extensions/TableHandles/{TableHandlesPlugin.d.ts → TableHandles.d.ts} +28 -31
  141. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -0
  142. package/types/src/extensions/index.d.ts +24 -0
  143. package/types/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.d.ts +1 -1
  144. package/types/src/extensions/tiptap-extensions/index.d.ts +11 -0
  145. package/types/src/index.d.ts +1 -13
  146. package/types/src/schema/blocks/createSpec.d.ts +4 -4
  147. package/types/src/schema/blocks/internal.d.ts +2 -2
  148. package/types/src/schema/blocks/types.d.ts +5 -5
  149. package/types/src/util/topo-sort.d.ts +8 -0
  150. package/dist/BlockNoteSchema-Bi-eeHal.js.map +0 -1
  151. package/dist/BlockNoteSchema-DjDaA2C3.cjs +0 -6
  152. package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +0 -1
  153. package/dist/blockToNode-DIfPWLH8.js.map +0 -1
  154. package/src/comments/models/User.ts +0 -8
  155. package/src/editor/BlockNoteExtensions.ts +0 -325
  156. package/src/editor/managers/CollaborationManager.ts +0 -212
  157. package/src/editor/managers/ExtensionManager.ts +0 -130
  158. package/src/extensions/Collaboration/CursorPlugin.ts +0 -189
  159. package/src/extensions/Collaboration/ForkYDocPlugin.ts +0 -192
  160. package/src/extensions/Collaboration/SyncPlugin.ts +0 -18
  161. package/src/extensions/Collaboration/UndoPlugin.ts +0 -18
  162. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +0 -59
  163. package/src/extensions/Comments/CommentsPlugin.ts +0 -392
  164. package/src/extensions/FilePanel/FilePanelPlugin.ts +0 -206
  165. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +0 -363
  166. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +0 -380
  167. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +0 -75
  168. package/src/extensions/Placeholder/PlaceholderPlugin.ts +0 -147
  169. package/types/src/comments/models/User.d.ts +0 -8
  170. package/types/src/editor/BlockNoteExtensions.d.ts +0 -43
  171. package/types/src/editor/managers/CollaborationManager.d.ts +0 -115
  172. package/types/src/editor/managers/ExtensionManager.d.ts +0 -68
  173. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +0 -15
  174. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +0 -37
  175. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +0 -41
  176. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +0 -7
  177. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +0 -9
  178. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +0 -7
  179. package/types/src/extensions/Comments/CommentsPlugin.d.ts +0 -66
  180. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +0 -31
  181. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +0 -41
  182. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +0 -42
  183. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +0 -5
  184. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +0 -6
  185. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +0 -15
  186. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +0 -31
  187. package/types/src/extensions/TrailingNode/TrailingNodeExtension.d.ts +0 -13
  188. /package/src/{extensions/Comments/CommentMark.ts → comments/mark.ts} +0 -0
  189. /package/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.ts +0 -0
  190. /package/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.ts +0 -0
  191. /package/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.ts +0 -0
  192. /package/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.ts +0 -0
  193. /package/types/src/{extensions/Comments/CommentMark.d.ts → comments/mark.d.ts} +0 -0
  194. /package/types/src/{extensions/Collaboration/ForkYDocPlugin.test.d.ts → editor/BlockNoteExtension.test.d.ts} +0 -0
  195. /package/types/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.d.ts +0 -0
  196. /package/types/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.d.ts +0 -0
  197. /package/types/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.d.ts +0 -0
  198. /package/types/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.d.ts +0 -0
  199. /package/types/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.d.ts +0 -0
  200. /package/types/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.d.ts +0 -0
package/dist/comments.js CHANGED
@@ -1,13 +1,325 @@
1
- var p = Object.defineProperty;
2
- var A = (d, r, e) => r in d ? p(d, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[r] = e;
3
- var n = (d, r, e) => A(d, typeof r != "symbol" ? r + "" : r, e);
4
- import * as u from "yjs";
5
- import { v4 as I } from "uuid";
6
- class v {
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 b extends v {
9
- constructor(r, e) {
10
- super(), this.userId = r, this.role = e;
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(r) {
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(r) {
28
- return r.userId === this.userId;
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(r) {
34
- return r.userId === this.userId || this.role === "editor";
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(r) {
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(r) {
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(r) {
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(r, e) {
60
- return e ? !r.reactions.some(
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(r, e) {
70
- return e ? r.reactions.some(
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 w {
76
- constructor(r) {
77
- n(this, "auth");
78
- this.auth = r;
387
+ class R {
388
+ constructor(d) {
389
+ c(this, "auth");
390
+ this.auth = d;
79
391
  }
80
392
  }
81
- class j extends w {
393
+ class ie extends R {
82
394
  constructor(e, t, a) {
83
395
  super(a);
84
396
  // TipTapThreadStore does not support addThreadToDocument
85
- n(this, "addThreadToDocument");
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 h of ((a = e.data) == null ? void 0 : a.reactions) || []) {
141
- const m = t.find(
142
- (i) => i.emoji === h.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
- m ? (m.userIds.push(h.userId), m.createdAt = new Date(
145
- Math.min(m.createdAt.getTime(), h.createdAt)
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: h.emoji,
148
- createdAt: new Date(h.createdAt),
149
- userIds: [h.userId]
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 g(d) {
277
- const r = new u.Map();
278
- if (r.set("id", d.id), r.set("userId", d.userId), r.set("createdAt", d.createdAt.getTime()), r.set("updatedAt", d.updatedAt.getTime()), d.deletedAt ? (r.set("deletedAt", d.deletedAt.getTime()), r.set("body", void 0)) : r.set("body", d.body), d.reactions.length > 0)
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 r.set("reactionsByUser", new u.Map()), r.set("metadata", d.metadata), r;
592
+ return d.set("reactionsByUser", new g.Map()), d.set("metadata", r.metadata), d;
281
593
  }
282
- function y(d) {
594
+ function G(r) {
283
595
  var t;
284
- const r = new u.Map();
285
- r.set("id", d.id), r.set("createdAt", d.createdAt.getTime()), r.set("updatedAt", d.updatedAt.getTime());
286
- const e = new u.Array();
287
- return e.push(d.comments.map((a) => g(a))), r.set("comments", e), r.set("resolved", d.resolved), r.set("resolvedUpdatedAt", (t = d.resolvedUpdatedAt) == null ? void 0 : t.getTime()), r.set("resolvedBy", d.resolvedBy), r.set("metadata", d.metadata), r;
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 C(d) {
601
+ function J(r) {
290
602
  return {
291
- emoji: d.get("emoji"),
292
- createdAt: new Date(d.get("createdAt")),
293
- userId: d.get("userId")
603
+ emoji: r.get("emoji"),
604
+ createdAt: new Date(r.get("createdAt")),
605
+ userId: r.get("userId")
294
606
  };
295
607
  }
296
- function D(d) {
297
- return [...d.values()].map(
298
- (e) => C(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 T(d) {
628
+ function I(r) {
317
629
  return {
318
630
  type: "comment",
319
- id: d.get("id"),
320
- userId: d.get("userId"),
321
- createdAt: new Date(d.get("createdAt")),
322
- updatedAt: new Date(d.get("updatedAt")),
323
- deletedAt: d.get("deletedAt") ? new Date(d.get("deletedAt")) : void 0,
324
- reactions: D(d.get("reactionsByUser")),
325
- metadata: d.get("metadata"),
326
- body: d.get("body")
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 c(d) {
641
+ function p(r) {
330
642
  return {
331
643
  type: "thread",
332
- id: d.get("id"),
333
- createdAt: new Date(d.get("createdAt")),
334
- updatedAt: new Date(d.get("updatedAt")),
335
- comments: (d.get("comments") || []).map(
336
- (r) => T(r)
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: d.get("resolved"),
339
- resolvedUpdatedAt: new Date(d.get("resolvedUpdatedAt")),
340
- resolvedBy: d.get("resolvedBy"),
341
- metadata: d.get("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 f extends w {
345
- constructor(r, e) {
346
- super(e), this.threadsYMap = r;
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(r) {
350
- const e = this.threadsYMap.get(r);
661
+ getThread(d) {
662
+ const e = this.threadsYMap.get(d);
351
663
  if (!e)
352
664
  throw new Error("Thread not found");
353
- return c(e);
665
+ return p(e);
354
666
  }
355
667
  getThreads() {
356
- const r = /* @__PURE__ */ new Map();
668
+ const d = /* @__PURE__ */ new Map();
357
669
  return this.threadsYMap.forEach((e, t) => {
358
- e instanceof u.Map && r.set(t, c(e));
359
- }), r;
670
+ e instanceof g.Map && d.set(t, p(e));
671
+ }), d;
360
672
  }
361
- subscribe(r) {
673
+ subscribe(d) {
362
674
  const e = () => {
363
- r(this.getThreads());
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 Y extends f {
682
+ class ce extends j {
371
683
  constructor(e, t, a, s) {
372
684
  super(a, s);
373
- n(this, "doRequest", async (e, t, a) => {
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
- n(this, "addThreadToDocument", async (e) => {
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
- n(this, "createThread", async (e) => this.doRequest("", "POST", e));
391
- n(this, "addComment", (e) => {
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
- n(this, "updateComment", (e) => {
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
- n(this, "deleteComment", (e) => {
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
- n(this, "deleteThread", (e) => this.doRequest(`/${e.threadId}`, "DELETE"));
407
- n(this, "resolveThread", (e) => this.doRequest(`/${e.threadId}/resolve`, "POST"));
408
- n(this, "unresolveThread", (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST"));
409
- n(this, "addReaction", (e) => {
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
- n(this, "deleteReaction", (e) => this.doRequest(
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 $ extends f {
736
+ class he extends j {
425
737
  constructor(e, t, a) {
426
738
  super(t, a);
427
- n(this, "transact", (e) => async (t) => this.threadsYMap.doc.transact(() => e(t)));
428
- n(this, "createThread", this.transact(
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: I(),
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: I(),
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, y(s)), s;
762
+ return this.threadsYMap.set(s.id, G(s)), s;
451
763
  }
452
764
  ));
453
765
  // YjsThreadStore does not support addThreadToDocument
454
- n(this, "addThreadToDocument");
455
- n(this, "addComment", this.transact(
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(c(t)))
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: I(),
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
- g(s)
786
+ U(s)
475
787
  ]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), s;
476
788
  }
477
789
  ));
478
- n(this, "updateComment", this.transact(
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 = l(
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(T(s)))
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
- n(this, "deleteComment", this.transact(
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 = l(
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(T(s)))
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
- n(this, "deleteThread", this.transact((e) => {
826
+ c(this, "deleteThread", this.transact((e) => {
515
827
  if (!this.auth.canDeleteThread(
516
- c(this.threadsYMap.get(e.threadId))
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
- n(this, "resolveThread", this.transact((e) => {
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(c(t)))
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
- n(this, "unresolveThread", this.transact((e) => {
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(c(t)))
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
- n(this, "addReaction", this.transact(
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 = l(
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(T(s), e.emoji))
861
+ if (!this.auth.canAddReaction(I(s), e.emoji))
550
862
  throw new Error("Not authorized");
551
- const o = /* @__PURE__ */ new Date(), h = `${this.userId}-${e.emoji}`, m = s.get("reactionsByUser");
552
- if (!m.has(h)) {
553
- const i = new u.Map();
554
- i.set("emoji", e.emoji), i.set("createdAt", o.getTime()), i.set("userId", this.userId), m.set(h, i);
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
- n(this, "deleteReaction", this.transact(
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 = l(
875
+ const a = y(
564
876
  t.get("comments"),
565
- (m) => m.get("id") === e.commentId
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(T(s), e.emoji))
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 l(d, r) {
580
- for (let e = 0; e < d.length; e++)
581
- if (r(d.get(e)))
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
- b as DefaultThreadStoreAuth,
587
- Y as RESTYjsThreadStore,
588
- w as ThreadStore,
589
- v as ThreadStoreAuth,
590
- j as TiptapThreadStore,
591
- $ as YjsThreadStore,
592
- f as YjsThreadStoreBase
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