@blocknote/core 0.45.0 → 0.46.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/{BlockNoteSchema-BOW16JHv.js → BlockNoteSchema-DsMVJZv4.js} +2 -2
- package/dist/{BlockNoteSchema-BOW16JHv.js.map → BlockNoteSchema-DsMVJZv4.js.map} +1 -1
- package/dist/{BlockNoteSchema-CzZbr4Ed.cjs → BlockNoteSchema-qt4Czo0-.cjs} +2 -2
- package/dist/{BlockNoteSchema-CzZbr4Ed.cjs.map → BlockNoteSchema-qt4Czo0-.cjs.map} +1 -1
- package/dist/ShowSelection-B0ch3unP.js +51 -0
- package/dist/ShowSelection-B0ch3unP.js.map +1 -0
- package/dist/ShowSelection-BxnbRvy4.cjs +2 -0
- package/dist/ShowSelection-BxnbRvy4.cjs.map +1 -0
- package/dist/{TrailingNode-8cXFaQUm.js → TrailingNode-C-Kyrtf1.js} +378 -369
- package/dist/TrailingNode-C-Kyrtf1.js.map +1 -0
- package/dist/TrailingNode-W7GJVng5.cjs +2 -0
- package/dist/TrailingNode-W7GJVng5.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +7 -7
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +3 -3
- package/dist/comments.js.map +1 -1
- package/dist/{defaultBlocks-DvCGYzqu.js → defaultBlocks-CXOCngjC.js} +118 -119
- package/dist/defaultBlocks-CXOCngjC.js.map +1 -0
- package/dist/defaultBlocks-IsUGVZIq.cjs +6 -0
- package/dist/defaultBlocks-IsUGVZIq.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -5
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +17 -0
- package/src/blocks/ListItem/BulletListItem/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
- package/src/blocks/ListItem/NumberedListItem/block.ts +1 -1
- package/src/comments/extension.ts +6 -2
- package/src/editor/Block.css +1 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +1 -1
- package/src/extensions/LinkToolbar/LinkToolbar.ts +1 -1
- package/src/extensions/ShowSelection/ShowSelection.ts +14 -4
- package/types/src/extensions/ShowSelection/ShowSelection.d.ts +10 -4
- package/dist/ShowSelection-BW37oJ6h.cjs +0 -2
- package/dist/ShowSelection-BW37oJ6h.cjs.map +0 -1
- package/dist/ShowSelection-Dz-NEase.js +0 -43
- package/dist/ShowSelection-Dz-NEase.js.map +0 -1
- package/dist/TrailingNode-8cXFaQUm.js.map +0 -1
- package/dist/TrailingNode-DPu6X9ym.cjs +0 -2
- package/dist/TrailingNode-DPu6X9ym.cjs.map +0 -1
- package/dist/defaultBlocks-D1cc0lV9.cjs +0 -6
- package/dist/defaultBlocks-D1cc0lV9.cjs.map +0 -1
- package/dist/defaultBlocks-DvCGYzqu.js.map +0 -1
package/dist/blocks.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./defaultBlocks-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./defaultBlocks-IsUGVZIq.cjs"),t=require("./BlockNoteSchema-qt4Czo0-.cjs");exports.EMPTY_CELL_HEIGHT=e.EMPTY_CELL_HEIGHT;exports.EMPTY_CELL_WIDTH=e.EMPTY_CELL_WIDTH;exports.FILE_AUDIO_ICON_SVG=e.FILE_AUDIO_ICON_SVG;exports.FILE_IMAGE_ICON_SVG=e.FILE_IMAGE_ICON_SVG;exports.FILE_VIDEO_ICON_SVG=e.FILE_VIDEO_ICON_SVG;exports.addDefaultPropsExternalHTML=e.addDefaultPropsExternalHTML;exports.audioParse=e.audioParse;exports.audioRender=e.audioRender;exports.audioToExternalHTML=e.audioToExternalHTML;exports.blockHasType=e.blockHasType;exports.createAudioBlockConfig=e.createAudioBlockConfig;exports.createAudioBlockSpec=e.createAudioBlockSpec;exports.createBulletListItemBlockConfig=e.createBulletListItemBlockConfig;exports.createBulletListItemBlockSpec=e.createBulletListItemBlockSpec;exports.createCheckListItemBlockSpec=e.createCheckListItemBlockSpec;exports.createCheckListItemConfig=e.createCheckListItemConfig;exports.createCodeBlockConfig=e.createCodeBlockConfig;exports.createCodeBlockSpec=e.createCodeBlockSpec;exports.createDefaultBlockDOMOutputSpec=e.createDefaultBlockDOMOutputSpec;exports.createDividerBlockConfig=e.createDividerBlockConfig;exports.createDividerBlockSpec=e.createDividerBlockSpec;exports.createFileBlockConfig=e.createFileBlockConfig;exports.createFileBlockSpec=e.createFileBlockSpec;exports.createHeadingBlockConfig=e.createHeadingBlockConfig;exports.createHeadingBlockSpec=e.createHeadingBlockSpec;exports.createImageBlockConfig=e.createImageBlockConfig;exports.createImageBlockSpec=e.createImageBlockSpec;exports.createNumberedListItemBlockConfig=e.createNumberedListItemBlockConfig;exports.createNumberedListItemBlockSpec=e.createNumberedListItemBlockSpec;exports.createParagraphBlockConfig=e.createParagraphBlockConfig;exports.createParagraphBlockSpec=e.createParagraphBlockSpec;exports.createQuoteBlockConfig=e.createQuoteBlockConfig;exports.createQuoteBlockSpec=e.createQuoteBlockSpec;exports.createTableBlockSpec=e.createTableBlockSpec;exports.createToggleListItemBlockConfig=e.createToggleListItemBlockConfig;exports.createToggleListItemBlockSpec=e.createToggleListItemBlockSpec;exports.createToggleWrapper=e.createToggleWrapper;exports.createVideoBlockConfig=e.createVideoBlockConfig;exports.createVideoBlockSpec=e.createVideoBlockSpec;exports.defaultBlockSpecs=e.defaultBlockSpecs;exports.defaultBlockToHTML=e.defaultBlockToHTML;exports.defaultInlineContentSchema=e.defaultInlineContentSchema;exports.defaultInlineContentSpecs=e.defaultInlineContentSpecs;exports.defaultProps=e.defaultProps;exports.defaultStyleSchema=e.defaultStyleSchema;exports.defaultStyleSpecs=e.defaultStyleSpecs;exports.defaultToggledState=e.defaultToggledState;exports.editorHasBlockWithType=e.editorHasBlockWithType;exports.fileParse=e.fileParse;exports.getBackgroundColorAttribute=e.getBackgroundColorAttribute;exports.getLanguageId=e.getLanguageId;exports.getTextAlignmentAttribute=e.getTextAlignmentAttribute;exports.getTextColorAttribute=e.getTextColorAttribute;exports.imageParse=e.imageParse;exports.imageRender=e.imageRender;exports.imageToExternalHTML=e.imageToExternalHTML;exports.isTableCellSelection=e.isTableCellSelection;exports.mergeParagraphs=e.mergeParagraphs;exports.parseAudioElement=e.parseAudioElement;exports.parseDefaultProps=e.parseDefaultProps;exports.tablePropSchema=e.tablePropSchema;exports.videoParse=e.videoParse;exports.BlockNoteSchema=t.BlockNoteSchema;exports.checkPageBreakBlocksInSchema=t.checkPageBreakBlocksInSchema;exports.createPageBreakBlockConfig=t.createPageBreakBlockConfig;exports.createPageBreakBlockSpec=t.createPageBreakBlockSpec;exports.getPageBreakSlashMenuItems=t.getPageBreakSlashMenuItems;exports.uploadToTmpFilesDotOrg_DEV_ONLY=t.uploadToTmpFilesDotOrg_DEV_ONLY;exports.withPageBreak=t.withPageBreak;
|
|
2
2
|
//# sourceMappingURL=blocks.cjs.map
|
package/dist/blocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as t, a as c, F as s, r as o, N as l, a4 as r, b as i, d as g, e as k, a0 as B, c as n, f as p, x as d, y as u, A as S, z as f, g as C, h as m, T as I, j as T, k as L, l as P, n as E, o as _, q as h, s as D, w as H, B as b, C as A, H as M, I as O, J as x, K as N, M as V, D as F, G, S as y, O as v, Q as W, W as Y, U as w, _ as Q, Z as R, a2 as U, Y as j, X as q, R as z, $ as J, m as K, a5 as X, i as Z, a7 as $, a6 as ee, t as ae, u as te, v as ce, a1 as se, V as oe, p as le, a3 as re, L as ie, P as ge } from "./defaultBlocks-
|
|
2
|
-
import { B as Be, b as ne, c as pe, a as de, g as ue, u as Se, w as fe } from "./BlockNoteSchema-
|
|
1
|
+
import { E as t, a as c, F as s, r as o, N as l, a4 as r, b as i, d as g, e as k, a0 as B, c as n, f as p, x as d, y as u, A as S, z as f, g as C, h as m, T as I, j as T, k as L, l as P, n as E, o as _, q as h, s as D, w as H, B as b, C as A, H as M, I as O, J as x, K as N, M as V, D as F, G, S as y, O as v, Q as W, W as Y, U as w, _ as Q, Z as R, a2 as U, Y as j, X as q, R as z, $ as J, m as K, a5 as X, i as Z, a7 as $, a6 as ee, t as ae, u as te, v as ce, a1 as se, V as oe, p as le, a3 as re, L as ie, P as ge } from "./defaultBlocks-CXOCngjC.js";
|
|
2
|
+
import { B as Be, b as ne, c as pe, a as de, g as ue, u as Se, w as fe } from "./BlockNoteSchema-DsMVJZv4.js";
|
|
3
3
|
export {
|
|
4
4
|
Be as BlockNoteSchema,
|
|
5
5
|
t as EMPTY_CELL_HEIGHT,
|
package/dist/comments.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var B=Object.defineProperty;var O=(r,a,e)=>a in r?B(r,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[a]=e;var c=(r,a,e)=>O(r,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("prosemirror-state"),I=require("prosemirror-view"),R=require("y-prosemirror"),U=require("./BlockNoteExtension-BWw0r8Gy.cjs"),P=require("./ShowSelection-BW37oJ6h.cjs"),Y=require("@tiptap/core"),z=require("./EventEmitter-CLwfmbqG.cjs"),N=require("yjs"),S=require("uuid");function L(r){if(r&&typeof r=="object"&&"default"in r)return r;const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(a,e,t.get?t:{enumerable:!0,get:()=>r[e]})}}return a.default=r,Object.freeze(a)}const g=L(N),E=Y.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:r=>!!r.getAttribute("data-orphan"),renderHTML:r=>r.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:r=>r.getAttribute("data-bn-thread-id"),renderHTML:r=>({"data-bn-thread-id":r.threadId}),default:""}}},renderHTML({HTMLAttributes:r}){return["span",Y.mergeAttributes(r,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(r){return r.name==="comment"?{blocknoteIgnore:!0}:{}}});class _ extends z.EventEmitter{constructor(e){super();c(this,"userCache",new Map);c(this,"loadingUsers",new Set);this.resolveUsers=e}async loadUsers(e){const t=e.filter(d=>!this.userCache.has(d)&&!this.loadingUsers.has(d));if(t.length!==0){for(const d of t)this.loadingUsers.add(d);try{const d=await this.resolveUsers(t);for(const s of d)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const d of t)this.loadingUsers.delete(d)}}}getUser(e){return this.userCache.get(e)}subscribe(e){return this.on("update",e)}}const y=new x.PluginKey("blocknote-comments");function H(r,a){const e=new Map;return r.descendants((t,d)=>{t.marks.forEach(s=>{if(s.type.name===a){const o=s.attrs.threadId;if(!o)return;const m=d,n=m+t.nodeSize,i=e.get(o)??{from:1/0,to:0};e.set(o,{from:Math.min(m,i.from),to:Math.max(n,i.to)})}})}),e}const F=U.createExtension(({editor:r,options:{schema:a,threadStore:e,resolveUsers:t}})=>{if(!t)throw new Error("resolveUsers is required to be defined when using comments");if(!e)throw new Error("threadStore is required to be defined when using comments");const d=E.name,s=new _(t),o=U.createStore({pendingComment:!1,selectedThreadId:void 0,threadPositions:new Map},{onUpdate(){o.state.selectedThreadId!==o.prevState.selectedThreadId&&r.transact(n=>n.setMeta(y,!0))}}),m=n=>{r.transact(i=>{i.doc.descendants((u,l)=>{u.marks.forEach(h=>{if(h.type.name===d){const T=h.type,f=h.attrs.threadId,v=n.get(f),C=!!(!v||v.resolved||v.deletedAt);if(C!==h.attrs.orphan){const M=Math.max(l,0),j=Math.min(l+u.nodeSize,i.doc.content.size-1,i.doc.content.size-1);i.removeMark(M,j,h),i.addMark(M,j,T.create({...h.attrs,orphan:C})),C&&o.state.selectedThreadId===f&&o.setState(k=>({...k,selectedThreadId:void 0}))}}})})})};return{key:"comments",store:o,prosemirrorPlugins:[new x.Plugin({key:y,state:{init(){return{decorations:I.DecorationSet.empty}},apply(n,i){const u=n.getMeta(y);if(!n.docChanged&&!u)return i;const l=n.docChanged?H(n.doc,d):o.state.threadPositions;(l.size>0||o.state.threadPositions.size>0)&&o.setState(T=>({...T,threadPositions:l}));const h=[];if(o.state.selectedThreadId){const T=l.get(o.state.selectedThreadId);T&&h.push(I.Decoration.inline(T.from,T.to,{class:"bn-thread-mark-selected"}))}return{decorations:I.DecorationSet.create(n.doc,h)}}},props:{decorations(n){var i;return((i=y.getState(n))==null?void 0:i.decorations)??I.DecorationSet.empty},handleClick:(n,i,u)=>{if(u.button!==0)return;const l=n.state.doc.nodeAt(i);if(!l){o.setState(f=>({...f,selectedThreadId:void 0}));return}const h=l.marks.find(f=>f.type.name===d&&f.attrs.orphan!==!0),T=h==null?void 0:h.attrs.threadId;T!==o.state.selectedThreadId&&o.setState(f=>({...f,selectedThreadId:T}))}}})],threadStore:e,mount(){const n=e.subscribe(m);m(e.getThreads());const i=r.onSelectionChange(()=>{o.state.pendingComment&&o.setState(u=>({...u,pendingComment:!1}))});return()=>{n(),i()}},selectThread(n,i=!0){var u,l;if(o.state.selectedThreadId!==n&&(o.setState(h=>({...h,pendingComment:!1,selectedThreadId:n})),n&&i)){const h=o.state.threadPositions.get(n);if(!h)return;(l=(u=r.prosemirrorView)==null?void 0:u.domAtPos(h.from).node)==null||l.scrollIntoView({behavior:"smooth",block:"center"})}},startPendingComment(){var n;o.setState(i=>({...i,selectedThreadId:void 0,pendingComment:!0})),(n=r.getExtension(P.ShowSelectionExtension))==null||n.showSelection(!0)},stopPendingComment(){var n;o.setState(i=>({...i,selectedThreadId:void 0,pendingComment:!1})),(n=r.getExtension(P.ShowSelectionExtension))==null||n.showSelection(!1)},async createThread(n){const i=await e.createThread(n);if(e.addThreadToDocument){const u=r.prosemirrorView,l=u.state.selection,h=R.ySyncPluginKey.getState(u.state),T={prosemirror:{head:l.head,anchor:l.anchor},yjs:h?R.getRelativeSelection(h.binding,u.state):void 0};await e.addThreadToDocument({threadId:i.id,selection:T})}else r._tiptapEditor.commands.setMark(d,{orphan:!1,threadId:i.id})},userStore:s,commentEditorSchema:a,tiptapExtensions:[E]}});class ${}class V extends ${constructor(a,e){super(),this.userId=a,this.role=e}canCreateThread(){return!0}canAddComment(a){return!0}canUpdateComment(a){return a.userId===this.userId}canDeleteComment(a){return a.userId===this.userId||this.role==="editor"}canDeleteThread(a){return this.role==="editor"}canResolveThread(a){return!0}canUnresolveThread(a){return!0}canAddReaction(a,e){return e?!a.reactions.some(t=>t.emoji===e&&t.userIds.includes(this.userId)):!0}canDeleteReaction(a,e){return e?a.reactions.some(t=>t.emoji===e&&t.userIds.includes(this.userId)):!0}}class b{constructor(a){c(this,"auth");this.auth=a}}class K extends b{constructor(e,t,d){super(d);c(this,"addThreadToDocument");this.userId=e,this.provider=t}async createThread(e){let t=this.provider.createThread({data:e.metadata});return t=this.provider.addComment(t.id,{content:e.initialComment.body,data:{metadata:e.initialComment.metadata,userId:this.userId}}),this.tiptapThreadToThreadData(t)}async addComment(e){const t=this.provider.addComment(e.threadId,{content:e.comment.body,data:{metadata:e.comment.metadata,userId:this.userId}});return this.tiptapCommentToCommentData(t.comments[t.comments.length-1])}async updateComment(e){const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{content:e.comment.body,data:{...t.data,metadata:e.comment.metadata}})}tiptapCommentToCommentData(e){var d,s,o;const t=[];for(const m of((d=e.data)==null?void 0:d.reactions)||[]){const n=t.find(i=>i.emoji===m.emoji);n?(n.userIds.push(m.userId),n.createdAt=new Date(Math.min(n.createdAt.getTime(),m.createdAt))):t.push({emoji:m.emoji,createdAt:new Date(m.createdAt),userIds:[m.userId]})}return{type:"comment",id:e.id,body:e.content,metadata:(s=e.data)==null?void 0:s.metadata,userId:(o=e.data)==null?void 0:o.userId,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt),reactions:t}}tiptapThreadToThreadData(e){var t;return{type:"thread",id:e.id,comments:e.comments.map(d=>this.tiptapCommentToCommentData(d)),resolved:!!e.resolvedAt,metadata:(t=e.data)==null?void 0:t.metadata,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)}}async deleteComment(e){this.provider.deleteComment(e.threadId,e.commentId)}async deleteThread(e){this.provider.deleteThread(e.threadId)}async resolveThread(e){this.provider.updateThread(e.threadId,{resolvedAt:new Date().toISOString()})}async unresolveThread(e){this.provider.updateThread(e.threadId,{resolvedAt:null})}async addReaction(e){var d;const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{data:{...t.data,reactions:[...((d=t.data)==null?void 0:d.reactions)||[],{emoji:e.emoji,createdAt:Date.now(),userId:this.userId}]}})}async deleteReaction(e){var d;const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{data:{...t.data,reactions:(((d=t.data)==null?void 0:d.reactions)||[]).filter(s=>s.emoji!==e.emoji&&s.userId!==this.userId)}})}getThread(e){const t=this.provider.getThread(e);if(!t)throw new Error("Thread not found");return this.tiptapThreadToThreadData(t)}getThreads(){return new Map(this.provider.getThreads().map(e=>[e.id,this.tiptapThreadToThreadData(e)]))}subscribe(e){const t=()=>{e(this.getThreads())};return this.provider.watchThreads(t),()=>{this.provider.unwatchThreads(t)}}}function q(r){const a=new g.Map;if(a.set("id",r.id),a.set("userId",r.userId),a.set("createdAt",r.createdAt.getTime()),a.set("updatedAt",r.updatedAt.getTime()),r.deletedAt?(a.set("deletedAt",r.deletedAt.getTime()),a.set("body",void 0)):a.set("body",r.body),r.reactions.length>0)throw new Error("Reactions should be empty in commentToYMap");return a.set("reactionsByUser",new g.Map),a.set("metadata",r.metadata),a}function G(r){var t;const a=new g.Map;a.set("id",r.id),a.set("createdAt",r.createdAt.getTime()),a.set("updatedAt",r.updatedAt.getTime());const e=new g.Array;return e.push(r.comments.map(d=>q(d))),a.set("comments",e),a.set("resolved",r.resolved),a.set("resolvedUpdatedAt",(t=r.resolvedUpdatedAt)==null?void 0:t.getTime()),a.set("resolvedBy",r.resolvedBy),a.set("metadata",r.metadata),a}function J(r){return{emoji:r.get("emoji"),createdAt:new Date(r.get("createdAt")),userId:r.get("userId")}}function Q(r){return[...r.values()].map(e=>J(e)).reduce((e,t)=>{const d=e.find(s=>s.emoji===t.emoji);return d?(d.userIds.push(t.userId),d.createdAt=new Date(Math.min(d.createdAt.getTime(),t.createdAt.getTime()))):e.push({emoji:t.emoji,createdAt:t.createdAt,userIds:[t.userId]}),e},[])}function w(r){return{type:"comment",id:r.get("id"),userId:r.get("userId"),createdAt:new Date(r.get("createdAt")),updatedAt:new Date(r.get("updatedAt")),deletedAt:r.get("deletedAt")?new Date(r.get("deletedAt")):void 0,reactions:Q(r.get("reactionsByUser")),metadata:r.get("metadata"),body:r.get("body")}}function p(r){return{type:"thread",id:r.get("id"),createdAt:new Date(r.get("createdAt")),updatedAt:new Date(r.get("updatedAt")),comments:(r.get("comments")||[]).map(a=>w(a)),resolved:r.get("resolved"),resolvedUpdatedAt:new Date(r.get("resolvedUpdatedAt")),resolvedBy:r.get("resolvedBy"),metadata:r.get("metadata")}}class D extends b{constructor(a,e){super(e),this.threadsYMap=a}getThread(a){const e=this.threadsYMap.get(a);if(!e)throw new Error("Thread not found");return p(e)}getThreads(){const a=new Map;return this.threadsYMap.forEach((e,t)=>{e instanceof g.Map&&a.set(t,p(e))}),a}subscribe(a){const e=()=>{a(this.getThreads())};return this.threadsYMap.observeDeep(e),()=>{this.threadsYMap.unobserveDeep(e)}}}class W extends D{constructor(e,t,d,s){super(d,s);c(this,"doRequest",async(e,t,d)=>{const s=await fetch(`${this.BASE_URL}${e}`,{method:t,body:JSON.stringify(d),headers:{"Content-Type":"application/json",...this.headers}});if(!s.ok)throw new Error(`Failed to ${t} ${e}: ${s.statusText}`);return s.json()});c(this,"addThreadToDocument",async e=>{const{threadId:t,...d}=e;return this.doRequest(`/${t}/addToDocument`,"POST",d)});c(this,"createThread",async e=>this.doRequest("","POST",e));c(this,"addComment",e=>{const{threadId:t,...d}=e;return this.doRequest(`/${t}/comments`,"POST",d)});c(this,"updateComment",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}`,"PUT",s)});c(this,"deleteComment",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}?soft=${!!s.softDelete}`,"DELETE")});c(this,"deleteThread",e=>this.doRequest(`/${e.threadId}`,"DELETE"));c(this,"resolveThread",e=>this.doRequest(`/${e.threadId}/resolve`,"POST"));c(this,"unresolveThread",e=>this.doRequest(`/${e.threadId}/unresolve`,"POST"));c(this,"addReaction",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}/reactions`,"POST",s)});c(this,"deleteReaction",e=>this.doRequest(`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`,"DELETE"));this.BASE_URL=e,this.headers=t}}class X extends D{constructor(e,t,d){super(t,d);c(this,"transact",e=>async t=>this.threadsYMap.doc.transact(()=>e(t)));c(this,"createThread",this.transact(e=>{if(!this.auth.canCreateThread())throw new Error("Not authorized");const t=new Date,d={type:"comment",id:S.v4(),userId:this.userId,createdAt:t,updatedAt:t,reactions:[],metadata:e.initialComment.metadata,body:e.initialComment.body},s={type:"thread",id:S.v4(),createdAt:t,updatedAt:t,comments:[d],resolved:!1,metadata:e.metadata};return this.threadsYMap.set(s.id,G(s)),s}));c(this,"addThreadToDocument");c(this,"addComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canAddComment(p(t)))throw new Error("Not authorized");const d=new Date,s={type:"comment",id:S.v4(),userId:this.userId,createdAt:d,updatedAt:d,deletedAt:void 0,reactions:[],metadata:e.comment.metadata,body:e.comment.body};return t.get("comments").push([q(s)]),t.set("updatedAt",new Date().getTime()),s}));c(this,"updateComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),o=>o.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canUpdateComment(w(s)))throw new Error("Not authorized");s.set("body",e.comment.body),s.set("updatedAt",new Date().getTime()),s.set("metadata",e.comment.metadata)}));c(this,"deleteComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),o=>o.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canDeleteComment(w(s)))throw new Error("Not authorized");if(s.get("deletedAt"))throw new Error("Comment already deleted");e.softDelete?(s.set("deletedAt",new Date().getTime()),s.set("body",void 0)):t.get("comments").delete(d),t.get("comments").toArray().every(o=>o.get("deletedAt"))&&(e.softDelete?t.set("deletedAt",new Date().getTime()):this.threadsYMap.delete(e.threadId)),t.set("updatedAt",new Date().getTime())}));c(this,"deleteThread",this.transact(e=>{if(!this.auth.canDeleteThread(p(this.threadsYMap.get(e.threadId))))throw new Error("Not authorized");this.threadsYMap.delete(e.threadId)}));c(this,"resolveThread",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canResolveThread(p(t)))throw new Error("Not authorized");t.set("resolved",!0),t.set("resolvedUpdatedAt",new Date().getTime()),t.set("resolvedBy",this.userId)}));c(this,"unresolveThread",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canUnresolveThread(p(t)))throw new Error("Not authorized");t.set("resolved",!1),t.set("resolvedUpdatedAt",new Date().getTime())}));c(this,"addReaction",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),i=>i.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canAddReaction(w(s),e.emoji))throw new Error("Not authorized");const o=new Date,m=`${this.userId}-${e.emoji}`,n=s.get("reactionsByUser");if(!n.has(m)){const i=new g.Map;i.set("emoji",e.emoji),i.set("createdAt",o.getTime()),i.set("userId",this.userId),n.set(m,i)}}));c(this,"deleteReaction",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),n=>n.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canDeleteReaction(w(s),e.emoji))throw new Error("Not authorized");const o=`${this.userId}-${e.emoji}`;s.get("reactionsByUser").delete(o)}));this.userId=e}}function A(r,a){for(let e=0;e<r.length;e++)if(a(r.get(e)))return e;return-1}exports.CommentMark=E;exports.CommentsExtension=F;exports.DefaultThreadStoreAuth=V;exports.RESTYjsThreadStore=W;exports.ThreadStore=b;exports.ThreadStoreAuth=$;exports.TiptapThreadStore=K;exports.YjsThreadStore=X;exports.YjsThreadStoreBase=D;
|
|
1
|
+
"use strict";var B=Object.defineProperty;var O=(r,a,e)=>a in r?B(r,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[a]=e;var c=(r,a,e)=>O(r,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("prosemirror-state"),I=require("prosemirror-view"),R=require("y-prosemirror"),U=require("./BlockNoteExtension-BWw0r8Gy.cjs"),P=require("./ShowSelection-BxnbRvy4.cjs"),Y=require("@tiptap/core"),z=require("./EventEmitter-CLwfmbqG.cjs"),N=require("yjs"),S=require("uuid");function L(r){if(r&&typeof r=="object"&&"default"in r)return r;const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(a,e,t.get?t:{enumerable:!0,get:()=>r[e]})}}return a.default=r,Object.freeze(a)}const g=L(N),E=Y.Mark.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes(){return{orphan:{parseHTML:r=>!!r.getAttribute("data-orphan"),renderHTML:r=>r.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:r=>r.getAttribute("data-bn-thread-id"),renderHTML:r=>({"data-bn-thread-id":r.threadId}),default:""}}},renderHTML({HTMLAttributes:r}){return["span",Y.mergeAttributes(r,{class:"bn-thread-mark"})]},parseHTML(){return[{tag:"span.bn-thread-mark"}]},extendMarkSchema(r){return r.name==="comment"?{blocknoteIgnore:!0}:{}}});class _ extends z.EventEmitter{constructor(e){super();c(this,"userCache",new Map);c(this,"loadingUsers",new Set);this.resolveUsers=e}async loadUsers(e){const t=e.filter(d=>!this.userCache.has(d)&&!this.loadingUsers.has(d));if(t.length!==0){for(const d of t)this.loadingUsers.add(d);try{const d=await this.resolveUsers(t);for(const s of d)this.userCache.set(s.id,s);this.emit("update",this.userCache)}finally{for(const d of t)this.loadingUsers.delete(d)}}}getUser(e){return this.userCache.get(e)}subscribe(e){return this.on("update",e)}}const y=new x.PluginKey("blocknote-comments");function H(r,a){const e=new Map;return r.descendants((t,d)=>{t.marks.forEach(s=>{if(s.type.name===a){const o=s.attrs.threadId;if(!o)return;const m=d,n=m+t.nodeSize,i=e.get(o)??{from:1/0,to:0};e.set(o,{from:Math.min(m,i.from),to:Math.max(n,i.to)})}})}),e}const F=U.createExtension(({editor:r,options:{schema:a,threadStore:e,resolveUsers:t}})=>{if(!t)throw new Error("resolveUsers is required to be defined when using comments");if(!e)throw new Error("threadStore is required to be defined when using comments");const d=E.name,s=new _(t),o=U.createStore({pendingComment:!1,selectedThreadId:void 0,threadPositions:new Map},{onUpdate(){o.state.selectedThreadId!==o.prevState.selectedThreadId&&r.transact(n=>n.setMeta(y,!0))}}),m=n=>{r.transact(i=>{i.doc.descendants((u,l)=>{u.marks.forEach(h=>{if(h.type.name===d){const T=h.type,f=h.attrs.threadId,v=n.get(f),C=!!(!v||v.resolved||v.deletedAt);if(C!==h.attrs.orphan){const M=Math.max(l,0),j=Math.min(l+u.nodeSize,i.doc.content.size-1,i.doc.content.size-1);i.removeMark(M,j,h),i.addMark(M,j,T.create({...h.attrs,orphan:C})),C&&o.state.selectedThreadId===f&&o.setState(k=>({...k,selectedThreadId:void 0}))}}})})})};return{key:"comments",store:o,prosemirrorPlugins:[new x.Plugin({key:y,state:{init(){return{decorations:I.DecorationSet.empty}},apply(n,i){const u=n.getMeta(y);if(!n.docChanged&&!u)return i;const l=n.docChanged?H(n.doc,d):o.state.threadPositions;(l.size>0||o.state.threadPositions.size>0)&&o.setState(T=>({...T,threadPositions:l}));const h=[];if(o.state.selectedThreadId){const T=l.get(o.state.selectedThreadId);T&&h.push(I.Decoration.inline(T.from,T.to,{class:"bn-thread-mark-selected"}))}return{decorations:I.DecorationSet.create(n.doc,h)}}},props:{decorations(n){var i;return((i=y.getState(n))==null?void 0:i.decorations)??I.DecorationSet.empty},handleClick:(n,i,u)=>{if(u.button!==0)return;const l=n.state.doc.nodeAt(i);if(!l){o.setState(f=>({...f,selectedThreadId:void 0}));return}const h=l.marks.find(f=>f.type.name===d&&f.attrs.orphan!==!0),T=h==null?void 0:h.attrs.threadId;T!==o.state.selectedThreadId&&o.setState(f=>({...f,selectedThreadId:T}))}}})],threadStore:e,mount(){const n=e.subscribe(m);m(e.getThreads());const i=r.onSelectionChange(()=>{o.state.pendingComment&&o.setState(u=>({...u,pendingComment:!1}))});return()=>{n(),i()}},selectThread(n,i=!0){var u,l;if(o.state.selectedThreadId!==n&&(o.setState(h=>({...h,pendingComment:!1,selectedThreadId:n})),n&&i)){const h=o.state.threadPositions.get(n);if(!h)return;(l=(u=r.prosemirrorView)==null?void 0:u.domAtPos(h.from).node)==null||l.scrollIntoView({behavior:"smooth",block:"center"})}},startPendingComment(){var n;o.setState(i=>({...i,selectedThreadId:void 0,pendingComment:!0})),(n=r.getExtension(P.ShowSelectionExtension))==null||n.showSelection(!0,"comments")},stopPendingComment(){var n;o.setState(i=>({...i,selectedThreadId:void 0,pendingComment:!1})),(n=r.getExtension(P.ShowSelectionExtension))==null||n.showSelection(!1,"comments")},async createThread(n){const i=await e.createThread(n);if(e.addThreadToDocument){const u=r.prosemirrorView,l=u.state.selection,h=R.ySyncPluginKey.getState(u.state),T={prosemirror:{head:l.head,anchor:l.anchor},yjs:h?R.getRelativeSelection(h.binding,u.state):void 0};await e.addThreadToDocument({threadId:i.id,selection:T})}else r._tiptapEditor.commands.setMark(d,{orphan:!1,threadId:i.id})},userStore:s,commentEditorSchema:a,tiptapExtensions:[E]}});class ${}class V extends ${constructor(a,e){super(),this.userId=a,this.role=e}canCreateThread(){return!0}canAddComment(a){return!0}canUpdateComment(a){return a.userId===this.userId}canDeleteComment(a){return a.userId===this.userId||this.role==="editor"}canDeleteThread(a){return this.role==="editor"}canResolveThread(a){return!0}canUnresolveThread(a){return!0}canAddReaction(a,e){return e?!a.reactions.some(t=>t.emoji===e&&t.userIds.includes(this.userId)):!0}canDeleteReaction(a,e){return e?a.reactions.some(t=>t.emoji===e&&t.userIds.includes(this.userId)):!0}}class b{constructor(a){c(this,"auth");this.auth=a}}class K extends b{constructor(e,t,d){super(d);c(this,"addThreadToDocument");this.userId=e,this.provider=t}async createThread(e){let t=this.provider.createThread({data:e.metadata});return t=this.provider.addComment(t.id,{content:e.initialComment.body,data:{metadata:e.initialComment.metadata,userId:this.userId}}),this.tiptapThreadToThreadData(t)}async addComment(e){const t=this.provider.addComment(e.threadId,{content:e.comment.body,data:{metadata:e.comment.metadata,userId:this.userId}});return this.tiptapCommentToCommentData(t.comments[t.comments.length-1])}async updateComment(e){const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{content:e.comment.body,data:{...t.data,metadata:e.comment.metadata}})}tiptapCommentToCommentData(e){var d,s,o;const t=[];for(const m of((d=e.data)==null?void 0:d.reactions)||[]){const n=t.find(i=>i.emoji===m.emoji);n?(n.userIds.push(m.userId),n.createdAt=new Date(Math.min(n.createdAt.getTime(),m.createdAt))):t.push({emoji:m.emoji,createdAt:new Date(m.createdAt),userIds:[m.userId]})}return{type:"comment",id:e.id,body:e.content,metadata:(s=e.data)==null?void 0:s.metadata,userId:(o=e.data)==null?void 0:o.userId,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt),reactions:t}}tiptapThreadToThreadData(e){var t;return{type:"thread",id:e.id,comments:e.comments.map(d=>this.tiptapCommentToCommentData(d)),resolved:!!e.resolvedAt,metadata:(t=e.data)==null?void 0:t.metadata,createdAt:new Date(e.createdAt),updatedAt:new Date(e.updatedAt)}}async deleteComment(e){this.provider.deleteComment(e.threadId,e.commentId)}async deleteThread(e){this.provider.deleteThread(e.threadId)}async resolveThread(e){this.provider.updateThread(e.threadId,{resolvedAt:new Date().toISOString()})}async unresolveThread(e){this.provider.updateThread(e.threadId,{resolvedAt:null})}async addReaction(e){var d;const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{data:{...t.data,reactions:[...((d=t.data)==null?void 0:d.reactions)||[],{emoji:e.emoji,createdAt:Date.now(),userId:this.userId}]}})}async deleteReaction(e){var d;const t=this.provider.getThreadComment(e.threadId,e.commentId,!0);if(!t)throw new Error("Comment not found");this.provider.updateComment(e.threadId,e.commentId,{data:{...t.data,reactions:(((d=t.data)==null?void 0:d.reactions)||[]).filter(s=>s.emoji!==e.emoji&&s.userId!==this.userId)}})}getThread(e){const t=this.provider.getThread(e);if(!t)throw new Error("Thread not found");return this.tiptapThreadToThreadData(t)}getThreads(){return new Map(this.provider.getThreads().map(e=>[e.id,this.tiptapThreadToThreadData(e)]))}subscribe(e){const t=()=>{e(this.getThreads())};return this.provider.watchThreads(t),()=>{this.provider.unwatchThreads(t)}}}function q(r){const a=new g.Map;if(a.set("id",r.id),a.set("userId",r.userId),a.set("createdAt",r.createdAt.getTime()),a.set("updatedAt",r.updatedAt.getTime()),r.deletedAt?(a.set("deletedAt",r.deletedAt.getTime()),a.set("body",void 0)):a.set("body",r.body),r.reactions.length>0)throw new Error("Reactions should be empty in commentToYMap");return a.set("reactionsByUser",new g.Map),a.set("metadata",r.metadata),a}function G(r){var t;const a=new g.Map;a.set("id",r.id),a.set("createdAt",r.createdAt.getTime()),a.set("updatedAt",r.updatedAt.getTime());const e=new g.Array;return e.push(r.comments.map(d=>q(d))),a.set("comments",e),a.set("resolved",r.resolved),a.set("resolvedUpdatedAt",(t=r.resolvedUpdatedAt)==null?void 0:t.getTime()),a.set("resolvedBy",r.resolvedBy),a.set("metadata",r.metadata),a}function J(r){return{emoji:r.get("emoji"),createdAt:new Date(r.get("createdAt")),userId:r.get("userId")}}function Q(r){return[...r.values()].map(e=>J(e)).reduce((e,t)=>{const d=e.find(s=>s.emoji===t.emoji);return d?(d.userIds.push(t.userId),d.createdAt=new Date(Math.min(d.createdAt.getTime(),t.createdAt.getTime()))):e.push({emoji:t.emoji,createdAt:t.createdAt,userIds:[t.userId]}),e},[])}function w(r){return{type:"comment",id:r.get("id"),userId:r.get("userId"),createdAt:new Date(r.get("createdAt")),updatedAt:new Date(r.get("updatedAt")),deletedAt:r.get("deletedAt")?new Date(r.get("deletedAt")):void 0,reactions:Q(r.get("reactionsByUser")),metadata:r.get("metadata"),body:r.get("body")}}function p(r){return{type:"thread",id:r.get("id"),createdAt:new Date(r.get("createdAt")),updatedAt:new Date(r.get("updatedAt")),comments:(r.get("comments")||[]).map(a=>w(a)),resolved:r.get("resolved"),resolvedUpdatedAt:new Date(r.get("resolvedUpdatedAt")),resolvedBy:r.get("resolvedBy"),metadata:r.get("metadata")}}class D extends b{constructor(a,e){super(e),this.threadsYMap=a}getThread(a){const e=this.threadsYMap.get(a);if(!e)throw new Error("Thread not found");return p(e)}getThreads(){const a=new Map;return this.threadsYMap.forEach((e,t)=>{e instanceof g.Map&&a.set(t,p(e))}),a}subscribe(a){const e=()=>{a(this.getThreads())};return this.threadsYMap.observeDeep(e),()=>{this.threadsYMap.unobserveDeep(e)}}}class W extends D{constructor(e,t,d,s){super(d,s);c(this,"doRequest",async(e,t,d)=>{const s=await fetch(`${this.BASE_URL}${e}`,{method:t,body:JSON.stringify(d),headers:{"Content-Type":"application/json",...this.headers}});if(!s.ok)throw new Error(`Failed to ${t} ${e}: ${s.statusText}`);return s.json()});c(this,"addThreadToDocument",async e=>{const{threadId:t,...d}=e;return this.doRequest(`/${t}/addToDocument`,"POST",d)});c(this,"createThread",async e=>this.doRequest("","POST",e));c(this,"addComment",e=>{const{threadId:t,...d}=e;return this.doRequest(`/${t}/comments`,"POST",d)});c(this,"updateComment",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}`,"PUT",s)});c(this,"deleteComment",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}?soft=${!!s.softDelete}`,"DELETE")});c(this,"deleteThread",e=>this.doRequest(`/${e.threadId}`,"DELETE"));c(this,"resolveThread",e=>this.doRequest(`/${e.threadId}/resolve`,"POST"));c(this,"unresolveThread",e=>this.doRequest(`/${e.threadId}/unresolve`,"POST"));c(this,"addReaction",e=>{const{threadId:t,commentId:d,...s}=e;return this.doRequest(`/${t}/comments/${d}/reactions`,"POST",s)});c(this,"deleteReaction",e=>this.doRequest(`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`,"DELETE"));this.BASE_URL=e,this.headers=t}}class X extends D{constructor(e,t,d){super(t,d);c(this,"transact",e=>async t=>this.threadsYMap.doc.transact(()=>e(t)));c(this,"createThread",this.transact(e=>{if(!this.auth.canCreateThread())throw new Error("Not authorized");const t=new Date,d={type:"comment",id:S.v4(),userId:this.userId,createdAt:t,updatedAt:t,reactions:[],metadata:e.initialComment.metadata,body:e.initialComment.body},s={type:"thread",id:S.v4(),createdAt:t,updatedAt:t,comments:[d],resolved:!1,metadata:e.metadata};return this.threadsYMap.set(s.id,G(s)),s}));c(this,"addThreadToDocument");c(this,"addComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canAddComment(p(t)))throw new Error("Not authorized");const d=new Date,s={type:"comment",id:S.v4(),userId:this.userId,createdAt:d,updatedAt:d,deletedAt:void 0,reactions:[],metadata:e.comment.metadata,body:e.comment.body};return t.get("comments").push([q(s)]),t.set("updatedAt",new Date().getTime()),s}));c(this,"updateComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),o=>o.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canUpdateComment(w(s)))throw new Error("Not authorized");s.set("body",e.comment.body),s.set("updatedAt",new Date().getTime()),s.set("metadata",e.comment.metadata)}));c(this,"deleteComment",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),o=>o.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canDeleteComment(w(s)))throw new Error("Not authorized");if(s.get("deletedAt"))throw new Error("Comment already deleted");e.softDelete?(s.set("deletedAt",new Date().getTime()),s.set("body",void 0)):t.get("comments").delete(d),t.get("comments").toArray().every(o=>o.get("deletedAt"))&&(e.softDelete?t.set("deletedAt",new Date().getTime()):this.threadsYMap.delete(e.threadId)),t.set("updatedAt",new Date().getTime())}));c(this,"deleteThread",this.transact(e=>{if(!this.auth.canDeleteThread(p(this.threadsYMap.get(e.threadId))))throw new Error("Not authorized");this.threadsYMap.delete(e.threadId)}));c(this,"resolveThread",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canResolveThread(p(t)))throw new Error("Not authorized");t.set("resolved",!0),t.set("resolvedUpdatedAt",new Date().getTime()),t.set("resolvedBy",this.userId)}));c(this,"unresolveThread",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");if(!this.auth.canUnresolveThread(p(t)))throw new Error("Not authorized");t.set("resolved",!1),t.set("resolvedUpdatedAt",new Date().getTime())}));c(this,"addReaction",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),i=>i.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canAddReaction(w(s),e.emoji))throw new Error("Not authorized");const o=new Date,m=`${this.userId}-${e.emoji}`,n=s.get("reactionsByUser");if(!n.has(m)){const i=new g.Map;i.set("emoji",e.emoji),i.set("createdAt",o.getTime()),i.set("userId",this.userId),n.set(m,i)}}));c(this,"deleteReaction",this.transact(e=>{const t=this.threadsYMap.get(e.threadId);if(!t)throw new Error("Thread not found");const d=A(t.get("comments"),n=>n.get("id")===e.commentId);if(d===-1)throw new Error("Comment not found");const s=t.get("comments").get(d);if(!this.auth.canDeleteReaction(w(s),e.emoji))throw new Error("Not authorized");const o=`${this.userId}-${e.emoji}`;s.get("reactionsByUser").delete(o)}));this.userId=e}}function A(r,a){for(let e=0;e<r.length;e++)if(a(r.get(e)))return e;return-1}exports.CommentMark=E;exports.CommentsExtension=F;exports.DefaultThreadStoreAuth=V;exports.RESTYjsThreadStore=W;exports.ThreadStore=b;exports.ThreadStoreAuth=$;exports.TiptapThreadStore=K;exports.YjsThreadStore=X;exports.YjsThreadStoreBase=D;
|
|
2
2
|
//# sourceMappingURL=comments.cjs.map
|
package/dist/comments.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.cjs","sources":["../src/comments/mark.ts","../src/comments/userstore/UserStore.ts","../src/comments/extension.ts","../src/comments/threadstore/ThreadStoreAuth.ts","../src/comments/threadstore/DefaultThreadStoreAuth.ts","../src/comments/threadstore/ThreadStore.ts","../src/comments/threadstore/TipTapThreadStore.ts","../src/comments/threadstore/yjs/yjsHelpers.ts","../src/comments/threadstore/yjs/YjsThreadStoreBase.ts","../src/comments/threadstore/yjs/RESTYjsThreadStore.ts","../src/comments/threadstore/yjs/YjsThreadStore.ts"],"sourcesContent":["import { Mark, mergeAttributes } from \"@tiptap/core\";\n\nexport const CommentMark = Mark.create({\n name: \"comment\",\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n\n addAttributes() {\n // Return an object with attribute configuration\n return {\n // orphans are marks that currently don't have an active thread. It could be\n // that users have resolved the thread. Resolved threads by default are not shown in the document,\n // but we need to keep the mark (positioning) data so we can still \"revive\" it when the thread is unresolved\n // or we enter a \"comments\" view that includes resolved threads.\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-bn-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-bn-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"bn-thread-mark\",\n }),\n ];\n },\n\n parseHTML() {\n return [{ tag: \"span.bn-thread-mark\" }];\n },\n\n extendMarkSchema(extension) {\n if (extension.name === \"comment\") {\n return {\n blocknoteIgnore: true,\n };\n }\n return {};\n },\n});\n","import type { User } from \"../types.js\";\nimport { EventEmitter } from \"../../util/EventEmitter.js\";\n\n/**\n * The `UserStore` is used to retrieve and cache information about users.\n *\n * It does this by calling `resolveUsers` (which is user-defined in the Editor Options)\n * for users that are not yet cached.\n */\nexport class UserStore<U extends User> extends EventEmitter<any> {\n private userCache: Map<string, U> = new Map();\n\n // avoid duplicate loads\n private loadingUsers = new Set<string>();\n\n public constructor(\n private readonly resolveUsers: (userIds: string[]) => Promise<U[]>,\n ) {\n super();\n }\n\n /**\n * Load information about users based on an array of user ids.\n */\n public async loadUsers(userIds: string[]) {\n const missingUsers = userIds.filter(\n (id) => !this.userCache.has(id) && !this.loadingUsers.has(id),\n );\n\n if (missingUsers.length === 0) {\n return;\n }\n\n for (const id of missingUsers) {\n this.loadingUsers.add(id);\n }\n\n try {\n const users = await this.resolveUsers(missingUsers);\n for (const user of users) {\n this.userCache.set(user.id, user);\n }\n this.emit(\"update\", this.userCache);\n } finally {\n for (const id of missingUsers) {\n // delete the users from the loading set\n // on a next call to `loadUsers` we will either\n // return the cached user or retry loading the user if the request failed failed\n this.loadingUsers.delete(id);\n }\n }\n }\n\n /**\n * Retrieve information about a user based on their id, if cached.\n *\n * The user will have to be loaded via `loadUsers` first\n */\n public getUser(userId: string): U | undefined {\n return this.userCache.get(userId);\n }\n\n /**\n * Subscribe to changes in the user store.\n *\n * @param cb - The callback to call when the user store changes.\n * @returns A function to unsubscribe from the user store.\n */\n public subscribe(cb: (users: Map<string, U>) => void): () => void {\n return this.on(\"update\", cb);\n }\n}\n","import { Node } from \"prosemirror-model\";\nimport { Plugin, PluginKey } from \"prosemirror-state\";\nimport { Decoration, DecorationSet } from \"prosemirror-view\";\nimport { getRelativeSelection, ySyncPluginKey } from \"y-prosemirror\";\nimport {\n createExtension,\n createStore,\n ExtensionOptions,\n} from \"../editor/BlockNoteExtension.js\";\nimport { ShowSelectionExtension } from \"../extensions/ShowSelection/ShowSelection.js\";\nimport { CustomBlockNoteSchema } from \"../schema/schema.js\";\nimport { CommentMark } from \"./mark.js\";\nimport type { ThreadStore } from \"./threadstore/ThreadStore.js\";\nimport type { CommentBody, ThreadData } from \"./types.js\";\nimport { User } from \"./types.js\";\nimport { UserStore } from \"./userstore/UserStore.js\";\n\nconst PLUGIN_KEY = new PluginKey(\"blocknote-comments\");\n\ntype CommentsPluginState = {\n /**\n * Decorations to be rendered, specifically to indicate the selected thread\n */\n decorations: DecorationSet;\n};\n\n/**\n * Calculate the thread positions from the current document state\n */\nfunction getUpdatedThreadPositions(doc: Node, markType: string) {\n const threadPositions = new Map<string, { from: number; to: number }>();\n\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === markType) {\n const thisThreadId = (mark.attrs as { threadId: string | undefined })\n .threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n }\n });\n });\n return threadPositions;\n}\n\nexport const CommentsExtension = createExtension(\n ({\n editor,\n options: { schema: commentEditorSchema, threadStore, resolveUsers },\n }: ExtensionOptions<{\n /**\n * The thread store implementation to use for storing and retrieving comment threads\n */\n threadStore: ThreadStore;\n /**\n * Resolve user information for comments.\n *\n * See [Comments](https://www.blocknotejs.org/docs/features/collaboration/comments) for more info.\n */\n resolveUsers: (userIds: string[]) => Promise<User[]>;\n /**\n * A schema to use for the comment editor (which allows you to customize the blocks and styles that are available in the comment editor)\n */\n schema?: CustomBlockNoteSchema<any, any, any>;\n }>) => {\n if (!resolveUsers) {\n throw new Error(\n \"resolveUsers is required to be defined when using comments\",\n );\n }\n if (!threadStore) {\n throw new Error(\n \"threadStore is required to be defined when using comments\",\n );\n }\n const markType = CommentMark.name;\n\n const userStore = new UserStore<User>(resolveUsers);\n const store = createStore(\n {\n pendingComment: false,\n selectedThreadId: undefined as string | undefined,\n threadPositions: new Map<string, { from: number; to: number }>(),\n },\n {\n onUpdate() {\n // If the selected thread id changed, we need to update the decorations\n if (\n store.state.selectedThreadId !== store.prevState.selectedThreadId\n ) {\n // So, we issue a transaction to update the decorations\n editor.transact((tr) => tr.setMeta(PLUGIN_KEY, true));\n }\n },\n },\n );\n\n const updateMarksFromThreads = (threads: Map<string, ThreadData>) => {\n editor.transact((tr) => {\n tr.doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === markType) {\n const markTypeInstance = mark.type;\n const markThreadId = mark.attrs.threadId as string;\n const thread = threads.get(markThreadId);\n const isOrphan = !!(\n !thread ||\n thread.resolved ||\n thread.deletedAt\n );\n\n if (isOrphan !== mark.attrs.orphan) {\n const trimmedFrom = Math.max(pos, 0);\n const trimmedTo = Math.min(\n pos + node.nodeSize,\n tr.doc.content.size - 1,\n tr.doc.content.size - 1,\n );\n tr.removeMark(trimmedFrom, trimmedTo, mark);\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n markTypeInstance.create({\n ...mark.attrs,\n orphan: isOrphan,\n }),\n );\n\n if (isOrphan && store.state.selectedThreadId === markThreadId) {\n // unselect\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n }));\n }\n }\n }\n });\n });\n });\n };\n\n return {\n key: \"comments\",\n store,\n prosemirrorPlugins: [\n new Plugin<CommentsPluginState>({\n key: PLUGIN_KEY,\n state: {\n init() {\n return {\n decorations: DecorationSet.empty,\n };\n },\n apply(tr, state) {\n const action = tr.getMeta(PLUGIN_KEY);\n\n if (!tr.docChanged && !action) {\n return state;\n }\n\n // only update threadPositions if the doc changed\n const newThreadPositions = tr.docChanged\n ? getUpdatedThreadPositions(tr.doc, markType)\n : store.state.threadPositions;\n\n if (\n newThreadPositions.size > 0 ||\n store.state.threadPositions.size > 0\n ) {\n // small optimization; don't emit event if threadPositions before / after were both empty\n store.setState((prev) => ({\n ...prev,\n threadPositions: newThreadPositions,\n }));\n }\n\n // update decorations if doc or selected thread changed\n const decorations = [] as any[];\n\n if (store.state.selectedThreadId) {\n const selectedThreadPosition = newThreadPositions.get(\n store.state.selectedThreadId,\n );\n\n if (selectedThreadPosition) {\n decorations.push(\n Decoration.inline(\n selectedThreadPosition.from,\n selectedThreadPosition.to,\n {\n class: \"bn-thread-mark-selected\",\n },\n ),\n );\n }\n }\n\n return {\n decorations: DecorationSet.create(tr.doc, decorations),\n };\n },\n },\n props: {\n decorations(state) {\n return (\n PLUGIN_KEY.getState(state)?.decorations ?? DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const node = view.state.doc.nodeAt(pos);\n\n if (!node) {\n // unselect\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n }));\n return;\n }\n\n const commentMark = node.marks.find(\n (mark) =>\n mark.type.name === markType && mark.attrs.orphan !== true,\n );\n\n const threadId = commentMark?.attrs.threadId as\n | string\n | undefined;\n if (threadId !== store.state.selectedThreadId) {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: threadId,\n }));\n }\n },\n },\n }),\n ],\n threadStore: threadStore,\n mount() {\n const unsubscribe = threadStore.subscribe(updateMarksFromThreads);\n updateMarksFromThreads(threadStore.getThreads());\n\n const unsubscribeOnSelectionChange = editor.onSelectionChange(() => {\n if (store.state.pendingComment) {\n store.setState((prev) => ({\n ...prev,\n pendingComment: false,\n }));\n }\n });\n\n return () => {\n unsubscribe();\n unsubscribeOnSelectionChange();\n };\n },\n selectThread(threadId: string | undefined, scrollToThread = true) {\n if (store.state.selectedThreadId === threadId) {\n return;\n }\n store.setState((prev) => ({\n ...prev,\n pendingComment: false,\n selectedThreadId: threadId,\n }));\n\n if (threadId && scrollToThread) {\n const selectedThreadPosition =\n store.state.threadPositions.get(threadId);\n if (!selectedThreadPosition) {\n return;\n }\n (\n editor.prosemirrorView?.domAtPos(selectedThreadPosition.from)\n .node as Element | undefined\n )?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n });\n }\n },\n startPendingComment() {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n pendingComment: true,\n }));\n editor.getExtension(ShowSelectionExtension)?.showSelection(true);\n },\n stopPendingComment() {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n pendingComment: false,\n }));\n editor.getExtension(ShowSelectionExtension)?.showSelection(false);\n },\n async createThread(options: {\n initialComment: { body: CommentBody; metadata?: any };\n metadata?: any;\n }) {\n const thread = await threadStore.createThread(options);\n if (threadStore.addThreadToDocument) {\n const view = editor.prosemirrorView!;\n const pmSelection = view.state.selection;\n const ystate = ySyncPluginKey.getState(view.state);\n const selection = {\n prosemirror: {\n head: pmSelection.head,\n anchor: pmSelection.anchor,\n },\n yjs: ystate\n ? getRelativeSelection(ystate.binding, view.state)\n : undefined,\n };\n await threadStore.addThreadToDocument({\n threadId: thread.id,\n selection,\n });\n } else {\n (editor as any)._tiptapEditor.commands.setMark(markType, {\n orphan: false,\n threadId: thread.id,\n });\n }\n },\n userStore,\n commentEditorSchema,\n tiptapExtensions: [CommentMark],\n } as const;\n },\n);\n","import { CommentData, ThreadData } from \"../types.js\";\n\nexport abstract class ThreadStoreAuth {\n abstract canCreateThread(): boolean;\n abstract canAddComment(thread: ThreadData): boolean;\n abstract canUpdateComment(comment: CommentData): boolean;\n abstract canDeleteComment(comment: CommentData): boolean;\n abstract canDeleteThread(thread: ThreadData): boolean;\n abstract canResolveThread(thread: ThreadData): boolean;\n abstract canUnresolveThread(thread: ThreadData): boolean;\n abstract canAddReaction(comment: CommentData, emoji?: string): boolean;\n abstract canDeleteReaction(comment: CommentData, emoji?: string): boolean;\n}\n","import { CommentData, ThreadData } from \"../types.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\n/*\n * The DefaultThreadStoreAuth class defines the authorization rules for interacting with comments.\n * We take a role (\"comment\" or \"editor\") and implement the rules.\n *\n * This class is then used in the UI to show / hide specific interactions.\n *\n * Rules:\n * - View-only users should not be able to see any comments\n * - Comment-only users and editors can:\n * - - create new comments / replies / reactions\n * - - edit / delete their own comments / reactions\n * - - resolve / unresolve threads\n * - Editors can also delete any comment or thread\n */\nexport class DefaultThreadStoreAuth extends ThreadStoreAuth {\n constructor(\n private readonly userId: string,\n private readonly role: \"comment\" | \"editor\",\n ) {\n super();\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canCreateThread(): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canAddComment(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should only be possible by the comment author\n */\n canUpdateComment(comment: CommentData): boolean {\n return comment.userId === this.userId;\n }\n\n /**\n * Auth: should be possible by the comment author OR an editor of the document\n */\n canDeleteComment(comment: CommentData): boolean {\n return comment.userId === this.userId || this.role === \"editor\";\n }\n\n /**\n * Auth: should only be possible by an editor of the document\n */\n canDeleteThread(_thread: ThreadData): boolean {\n return this.role === \"editor\";\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canResolveThread(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canUnresolveThread(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n *\n * 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?\n */\n canAddReaction(comment: CommentData, emoji?: string): boolean {\n if (!emoji) {\n return true;\n }\n\n return !comment.reactions.some(\n (reaction) =>\n reaction.emoji === emoji && reaction.userIds.includes(this.userId),\n );\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n *\n * 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?\n */\n canDeleteReaction(comment: CommentData, emoji?: string): boolean {\n if (!emoji) {\n return true;\n }\n\n return comment.reactions.some(\n (reaction) =>\n reaction.emoji === emoji && reaction.userIds.includes(this.userId),\n );\n }\n}\n","import { CommentBody, CommentData, ThreadData } from \"../types.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\n/**\n * ThreadStore is an abstract class that defines the interface\n * to read / add / update / delete threads and comments.\n */\nexport abstract class ThreadStore {\n public readonly auth: ThreadStoreAuth;\n\n constructor(auth: ThreadStoreAuth) {\n this.auth = auth;\n }\n\n /**\n * A \"thread\" in the ThreadStore only contains information about the content\n * of the thread / comments. It does not contain information about the position.\n *\n * This function can be implemented to store the thread in the document (by creating a mark)\n * If not implemented, default behavior will apply (creating the mark via TipTap)\n * See CommentsPlugin.ts for more details.\n */\n abstract addThreadToDocument?(options: {\n threadId: string;\n selection: {\n prosemirror: {\n head: number;\n anchor: number;\n };\n yjs?: {\n head: any;\n anchor: any;\n };\n };\n }): Promise<void>;\n\n /**\n * Creates a new thread with an initial comment.\n */\n abstract createThread(options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }): Promise<ThreadData>;\n\n /**\n * Adds a comment to a thread.\n */\n abstract addComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }): Promise<CommentData>;\n\n /**\n * Updates a comment in a thread.\n */\n abstract updateComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }): Promise<void>;\n\n /**\n * Deletes a comment from a thread.\n */\n abstract deleteComment(options: {\n threadId: string;\n commentId: string;\n }): Promise<void>;\n\n /**\n * Deletes a thread.\n */\n abstract deleteThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Marks a thread as resolved.\n */\n abstract resolveThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Marks a thread as unresolved.\n */\n abstract unresolveThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Adds a reaction to a comment.\n *\n * Auth: should be possible by anyone with comment access\n */\n abstract addReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }): Promise<void>;\n\n /**\n * Deletes a reaction from a comment.\n *\n * Auth: should be possible by the reaction author\n */\n abstract deleteReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }): Promise<void>;\n\n /**\n * Retrieve data for a specific thread.\n */\n abstract getThread(threadId: string): ThreadData;\n\n /**\n * Retrieve all threads.\n */\n abstract getThreads(): Map<string, ThreadData>;\n\n /**\n * Subscribe to changes in the thread store.\n *\n * @returns a function to unsubscribe from the thread store\n */\n abstract subscribe(\n cb: (threads: Map<string, ThreadData>) => void,\n ): () => void;\n}\n","import type {\n TCollabComment,\n TCollabThread,\n TiptapCollabProvider,\n} from \"@hocuspocus/provider\";\nimport {\n CommentBody,\n CommentData,\n CommentReactionData,\n ThreadData,\n} from \"../types.js\";\nimport { ThreadStore } from \"./ThreadStore.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\ntype ReactionAsTiptapData = {\n emoji: string;\n createdAt: number;\n userId: string;\n};\n\n/**\n * The `TiptapThreadStore` integrates with Tiptap's collaboration provider for comment management.\n * You can pass a `TiptapCollabProvider` to the constructor which takes care of storing the comments.\n *\n * Under the hood, this actually works similarly to the `YjsThreadStore` implementation. (comments are stored in the Yjs document)\n */\nexport class TiptapThreadStore extends ThreadStore {\n constructor(\n private readonly userId: string,\n private readonly provider: TiptapCollabProvider,\n auth: ThreadStoreAuth, // TODO: use?\n ) {\n super(auth);\n }\n\n /**\n * Creates a new thread with an initial comment.\n */\n public async createThread(options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }): Promise<ThreadData> {\n let thread = this.provider.createThread({\n data: options.metadata,\n });\n\n thread = this.provider.addComment(thread.id, {\n content: options.initialComment.body,\n data: {\n metadata: options.initialComment.metadata,\n userId: this.userId,\n },\n });\n\n return this.tiptapThreadToThreadData(thread);\n }\n\n // TipTapThreadStore does not support addThreadToDocument\n public addThreadToDocument = undefined;\n\n /**\n * Adds a comment to a thread.\n */\n public async addComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }): Promise<CommentBody> {\n const thread = this.provider.addComment(options.threadId, {\n content: options.comment.body,\n data: {\n metadata: options.comment.metadata,\n userId: this.userId,\n },\n });\n\n return this.tiptapCommentToCommentData(\n thread.comments[thread.comments.length - 1],\n );\n }\n\n /**\n * Updates a comment in a thread.\n */\n public async updateComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n content: options.comment.body,\n data: {\n ...comment.data,\n metadata: options.comment.metadata,\n },\n });\n }\n\n private tiptapCommentToCommentData(comment: TCollabComment): CommentData {\n const reactions: CommentReactionData[] = [];\n\n for (const reaction of (comment.data?.reactions ||\n []) as ReactionAsTiptapData[]) {\n const existingReaction = reactions.find(\n (r) => r.emoji === reaction.emoji,\n );\n if (existingReaction) {\n existingReaction.userIds.push(reaction.userId);\n existingReaction.createdAt = new Date(\n Math.min(existingReaction.createdAt.getTime(), reaction.createdAt),\n );\n } else {\n reactions.push({\n emoji: reaction.emoji,\n createdAt: new Date(reaction.createdAt),\n userIds: [reaction.userId],\n });\n }\n }\n\n return {\n type: \"comment\",\n id: comment.id,\n body: comment.content,\n metadata: comment.data?.metadata,\n userId: comment.data?.userId,\n createdAt: new Date(comment.createdAt),\n updatedAt: new Date(comment.updatedAt),\n reactions,\n };\n }\n\n private tiptapThreadToThreadData(thread: TCollabThread): ThreadData {\n return {\n type: \"thread\",\n id: thread.id,\n comments: thread.comments.map((comment) =>\n this.tiptapCommentToCommentData(comment),\n ),\n resolved: !!thread.resolvedAt,\n metadata: thread.data?.metadata,\n createdAt: new Date(thread.createdAt),\n updatedAt: new Date(thread.updatedAt),\n };\n }\n\n /**\n * Deletes a comment from a thread.\n */\n public async deleteComment(options: { threadId: string; commentId: string }) {\n this.provider.deleteComment(options.threadId, options.commentId);\n }\n\n /**\n * Deletes a thread.\n */\n public async deleteThread(options: { threadId: string }) {\n this.provider.deleteThread(options.threadId);\n }\n\n /**\n * Marks a thread as resolved.\n */\n public async resolveThread(options: { threadId: string }) {\n this.provider.updateThread(options.threadId, {\n resolvedAt: new Date().toISOString(),\n });\n }\n\n /**\n * Marks a thread as unresolved.\n */\n public async unresolveThread(options: { threadId: string }) {\n this.provider.updateThread(options.threadId, {\n resolvedAt: null,\n });\n }\n\n /**\n * Adds a reaction to a comment.\n *\n * Auth: should be possible by anyone with comment access\n */\n public async addReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n data: {\n ...comment.data,\n reactions: [\n ...((comment.data?.reactions || []) as ReactionAsTiptapData[]),\n {\n emoji: options.emoji,\n createdAt: Date.now(),\n userId: this.userId,\n },\n ],\n },\n });\n }\n\n /**\n * Deletes a reaction from a comment.\n *\n * Auth: should be possible by the reaction author\n */\n public async deleteReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n data: {\n ...comment.data,\n reactions: (\n (comment.data?.reactions || []) as ReactionAsTiptapData[]\n ).filter(\n (reaction) =>\n reaction.emoji !== options.emoji && reaction.userId !== this.userId,\n ),\n },\n });\n }\n\n public getThread(threadId: string): ThreadData {\n const thread = this.provider.getThread(threadId);\n\n if (!thread) {\n throw new Error(\"Thread not found\");\n }\n\n return this.tiptapThreadToThreadData(thread);\n }\n\n public getThreads(): Map<string, ThreadData> {\n return new Map(\n this.provider\n .getThreads()\n .map((thread) => [thread.id, this.tiptapThreadToThreadData(thread)]),\n );\n }\n\n public subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void {\n const newCb = () => {\n cb(this.getThreads());\n };\n this.provider.watchThreads(newCb);\n return () => {\n this.provider.unwatchThreads(newCb);\n };\n }\n}\n","import * as Y from \"yjs\";\nimport { CommentData, CommentReactionData, ThreadData } from \"../../types.js\";\n\nexport function commentToYMap(comment: CommentData) {\n const yMap = new Y.Map<any>();\n yMap.set(\"id\", comment.id);\n yMap.set(\"userId\", comment.userId);\n yMap.set(\"createdAt\", comment.createdAt.getTime());\n yMap.set(\"updatedAt\", comment.updatedAt.getTime());\n if (comment.deletedAt) {\n yMap.set(\"deletedAt\", comment.deletedAt.getTime());\n yMap.set(\"body\", undefined);\n } else {\n yMap.set(\"body\", comment.body);\n }\n if (comment.reactions.length > 0) {\n throw new Error(\"Reactions should be empty in commentToYMap\");\n }\n\n /**\n * Reactions are stored in a map keyed by {userId-emoji},\n * this makes it easy to add / remove reactions and in a way that works local-first.\n * The cost is that \"reading\" the reactions is a bit more complex (see yMapToReactions).\n */\n yMap.set(\"reactionsByUser\", new Y.Map());\n yMap.set(\"metadata\", comment.metadata);\n\n return yMap;\n}\n\nexport function threadToYMap(thread: ThreadData) {\n const yMap = new Y.Map();\n yMap.set(\"id\", thread.id);\n yMap.set(\"createdAt\", thread.createdAt.getTime());\n yMap.set(\"updatedAt\", thread.updatedAt.getTime());\n const commentsArray = new Y.Array<Y.Map<any>>();\n\n commentsArray.push(thread.comments.map((comment) => commentToYMap(comment)));\n\n yMap.set(\"comments\", commentsArray);\n yMap.set(\"resolved\", thread.resolved);\n yMap.set(\"resolvedUpdatedAt\", thread.resolvedUpdatedAt?.getTime());\n yMap.set(\"resolvedBy\", thread.resolvedBy);\n yMap.set(\"metadata\", thread.metadata);\n return yMap;\n}\n\ntype SingleUserCommentReactionData = {\n emoji: string;\n createdAt: Date;\n userId: string;\n};\n\nexport function yMapToReaction(\n yMap: Y.Map<any>,\n): SingleUserCommentReactionData {\n return {\n emoji: yMap.get(\"emoji\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n userId: yMap.get(\"userId\"),\n };\n}\n\nfunction yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {\n const flatReactions = [...yMap.values()].map((reaction: Y.Map<any>) =>\n yMapToReaction(reaction),\n );\n // combine reactions by the same emoji\n return flatReactions.reduce(\n (acc: CommentReactionData[], reaction: SingleUserCommentReactionData) => {\n const existingReaction = acc.find((r) => r.emoji === reaction.emoji);\n if (existingReaction) {\n existingReaction.userIds.push(reaction.userId);\n existingReaction.createdAt = new Date(\n Math.min(\n existingReaction.createdAt.getTime(),\n reaction.createdAt.getTime(),\n ),\n );\n } else {\n acc.push({\n emoji: reaction.emoji,\n createdAt: reaction.createdAt,\n userIds: [reaction.userId],\n });\n }\n return acc;\n },\n [] as CommentReactionData[],\n );\n}\n\nexport function yMapToComment(yMap: Y.Map<any>): CommentData {\n return {\n type: \"comment\",\n id: yMap.get(\"id\"),\n userId: yMap.get(\"userId\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n deletedAt: yMap.get(\"deletedAt\")\n ? new Date(yMap.get(\"deletedAt\"))\n : undefined,\n reactions: yMapToReactions(yMap.get(\"reactionsByUser\")),\n metadata: yMap.get(\"metadata\"),\n body: yMap.get(\"body\"),\n };\n}\n\nexport function yMapToThread(yMap: Y.Map<any>): ThreadData {\n return {\n type: \"thread\",\n id: yMap.get(\"id\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n comments: ((yMap.get(\"comments\") as Y.Array<Y.Map<any>>) || []).map(\n (comment) => yMapToComment(comment),\n ),\n resolved: yMap.get(\"resolved\"),\n resolvedUpdatedAt: new Date(yMap.get(\"resolvedUpdatedAt\")),\n resolvedBy: yMap.get(\"resolvedBy\"),\n metadata: yMap.get(\"metadata\"),\n };\n}\n","import * as Y from \"yjs\";\nimport { ThreadData } from \"../../types.js\";\nimport { ThreadStore } from \"../ThreadStore.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { yMapToThread } from \"./yjsHelpers.js\";\n\n/**\n * This is an abstract class that only implements the READ methods required by the ThreadStore interface.\n * The data is read from a Yjs Map.\n */\nexport abstract class YjsThreadStoreBase extends ThreadStore {\n constructor(\n protected readonly threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(auth);\n }\n\n // TODO: async / reactive interface?\n public getThread(threadId: string) {\n const yThread = this.threadsYMap.get(threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n const thread = yMapToThread(yThread);\n return thread;\n }\n\n public getThreads(): Map<string, ThreadData> {\n const threadMap = new Map<string, ThreadData>();\n this.threadsYMap.forEach((yThread, id) => {\n if (yThread instanceof Y.Map) {\n threadMap.set(id, yMapToThread(yThread));\n }\n });\n return threadMap;\n }\n\n public subscribe(cb: (threads: Map<string, ThreadData>) => void) {\n const observer = () => {\n cb(this.getThreads());\n };\n\n this.threadsYMap.observeDeep(observer);\n\n return () => {\n this.threadsYMap.unobserveDeep(observer);\n };\n }\n}\n","import * as Y from \"yjs\";\nimport { CommentBody } from \"../../types.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\n\n/**\n * This is a REST-based implementation of the YjsThreadStoreBase.\n * It Reads data directly from the underlying document (same as YjsThreadStore),\n * but for Writes, it sends data to a REST API that should:\n * - check the user has the correct permissions to make the desired changes\n * - apply the updates to the underlying Yjs document\n *\n * (see https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus)\n *\n * The reason we still use the Yjs document as underlying storage is that it makes it easy to\n * sync updates in real-time to other collaborators.\n * (but technically, you could also implement a different storage altogether\n * and not store the thread related data in the Yjs document)\n */\nexport class RESTYjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly BASE_URL: string,\n private readonly headers: Record<string, string>,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private doRequest = async (path: string, method: string, body?: any) => {\n const response = await fetch(`${this.BASE_URL}${path}`, {\n method,\n body: JSON.stringify(body),\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.headers,\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to ${method} ${path}: ${response.statusText}`);\n }\n\n return response.json();\n };\n\n public addThreadToDocument = async (options: {\n threadId: string;\n selection: {\n prosemirror: {\n head: number;\n anchor: number;\n };\n yjs: {\n head: any;\n anchor: any;\n };\n };\n }) => {\n const { threadId, ...rest } = options;\n return this.doRequest(`/${threadId}/addToDocument`, \"POST\", rest);\n };\n\n public createThread = async (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n return this.doRequest(\"\", \"POST\", options);\n };\n\n public addComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const { threadId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments`, \"POST\", rest);\n };\n\n public updateComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments/${commentId}`, \"PUT\", rest);\n };\n\n public deleteComment = (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}?soft=${!!rest.softDelete}`,\n \"DELETE\",\n );\n };\n\n public deleteThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}`, \"DELETE\");\n };\n\n public resolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/resolve`, \"POST\");\n };\n\n public unresolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/unresolve`, \"POST\");\n };\n\n public addReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}/reactions`,\n \"POST\",\n rest,\n );\n };\n\n public deleteReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n return this.doRequest(\n `/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,\n \"DELETE\",\n );\n };\n}\n","import { v4 } from \"uuid\";\nimport * as Y from \"yjs\";\nimport { CommentBody, CommentData, ThreadData } from \"../../types.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\nimport {\n commentToYMap,\n threadToYMap,\n yMapToComment,\n yMapToThread,\n} from \"./yjsHelpers.js\";\n\n/**\n * This is a Yjs-based implementation of the ThreadStore interface.\n *\n * It reads and writes thread / comments information directly to the underlying Yjs Document.\n *\n * @important While this is the easiest to add to your app, there are two challenges:\n * - The user needs to be able to write to the Yjs document to store the information.\n * So a user without write access to the Yjs document cannot leave any comments.\n * - Even with write access, the operations are not secure. Unless your Yjs server\n * guards against malicious operations, it's technically possible for one user to make changes to another user's comments, etc.\n * (even though these options are not visible in the UI, a malicious user can make unauthorized changes to the underlying Yjs document)\n */\nexport class YjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly userId: string,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private transact = <T, R>(\n fn: (options: T) => R,\n ): ((options: T) => Promise<R>) => {\n return async (options: T) => {\n return this.threadsYMap.doc!.transact(() => {\n return fn(options);\n });\n };\n };\n\n public createThread = this.transact(\n (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n if (!this.auth.canCreateThread()) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const comment: CommentData = {\n type: \"comment\",\n id: v4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n reactions: [],\n metadata: options.initialComment.metadata,\n body: options.initialComment.body,\n };\n\n const thread: ThreadData = {\n type: \"thread\",\n id: v4(),\n createdAt: date,\n updatedAt: date,\n comments: [comment],\n resolved: false,\n metadata: options.metadata,\n };\n\n this.threadsYMap.set(thread.id, threadToYMap(thread));\n\n return thread;\n },\n );\n\n // YjsThreadStore does not support addThreadToDocument\n public addThreadToDocument = undefined;\n\n public addComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canAddComment(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n const comment: CommentData = {\n type: \"comment\",\n id: v4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n deletedAt: undefined,\n reactions: [],\n metadata: options.comment.metadata,\n body: options.comment.body,\n };\n\n (yThread.get(\"comments\") as Y.Array<Y.Map<any>>).push([\n commentToYMap(comment),\n ]);\n\n yThread.set(\"updatedAt\", new Date().getTime());\n return comment;\n },\n );\n\n public updateComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canUpdateComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n yComment.set(\"body\", options.comment.body);\n yComment.set(\"updatedAt\", new Date().getTime());\n yComment.set(\"metadata\", options.comment.metadata);\n },\n );\n\n public deleteComment = this.transact(\n (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canDeleteComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n if (yComment.get(\"deletedAt\")) {\n throw new Error(\"Comment already deleted\");\n }\n\n if (options.softDelete) {\n yComment.set(\"deletedAt\", new Date().getTime());\n yComment.set(\"body\", undefined);\n } else {\n yThread.get(\"comments\").delete(yCommentIndex);\n }\n\n if (\n (yThread.get(\"comments\") as Y.Array<any>)\n .toArray()\n .every((comment) => comment.get(\"deletedAt\"))\n ) {\n // all comments deleted\n if (options.softDelete) {\n yThread.set(\"deletedAt\", new Date().getTime());\n } else {\n this.threadsYMap.delete(options.threadId);\n }\n }\n\n yThread.set(\"updatedAt\", new Date().getTime());\n },\n );\n\n public deleteThread = this.transact((options: { threadId: string }) => {\n if (\n !this.auth.canDeleteThread(\n yMapToThread(this.threadsYMap.get(options.threadId)),\n )\n ) {\n throw new Error(\"Not authorized\");\n }\n\n this.threadsYMap.delete(options.threadId);\n });\n\n public resolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canResolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", true);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n yThread.set(\"resolvedBy\", this.userId);\n });\n\n public unresolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canUnresolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", false);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n });\n\n public addReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canAddReaction(yMapToComment(yComment), options.emoji)) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n if (reactionsByUser.has(key)) {\n // already exists\n return;\n } else {\n const reaction = new Y.Map();\n reaction.set(\"emoji\", options.emoji);\n reaction.set(\"createdAt\", date.getTime());\n reaction.set(\"userId\", this.userId);\n reactionsByUser.set(key, reaction);\n }\n },\n );\n\n public deleteReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (\n !this.auth.canDeleteReaction(yMapToComment(yComment), options.emoji)\n ) {\n throw new Error(\"Not authorized\");\n }\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n reactionsByUser.delete(key);\n },\n );\n}\n\nfunction yArrayFindIndex(\n yArray: Y.Array<any>,\n predicate: (item: any) => boolean,\n) {\n for (let i = 0; i < yArray.length; i++) {\n if (predicate(yArray.get(i))) {\n return i;\n }\n }\n return -1;\n}\n"],"names":["CommentMark","Mark","element","attributes","HTMLAttributes","mergeAttributes","extension","UserStore","EventEmitter","resolveUsers","__publicField","userIds","missingUsers","id","users","user","userId","cb","PLUGIN_KEY","PluginKey","getUpdatedThreadPositions","doc","markType","threadPositions","node","pos","mark","thisThreadId","from","to","currentPosition","CommentsExtension","createExtension","editor","commentEditorSchema","threadStore","userStore","store","createStore","tr","updateMarksFromThreads","threads","markTypeInstance","markThreadId","thread","isOrphan","trimmedFrom","trimmedTo","prev","Plugin","DecorationSet","state","action","newThreadPositions","decorations","selectedThreadPosition","Decoration","_a","view","event","commentMark","threadId","unsubscribe","unsubscribeOnSelectionChange","scrollToThread","_b","ShowSelectionExtension","options","pmSelection","ystate","ySyncPluginKey","selection","getRelativeSelection","ThreadStoreAuth","DefaultThreadStoreAuth","role","_thread","comment","emoji","reaction","ThreadStore","auth","TiptapThreadStore","provider","reactions","existingReaction","r","_c","newCb","commentToYMap","yMap","Y","threadToYMap","commentsArray","yMapToReaction","yMapToReactions","acc","yMapToComment","yMapToThread","YjsThreadStoreBase","threadsYMap","yThread","threadMap","observer","RESTYjsThreadStore","BASE_URL","headers","path","method","body","response","rest","commentId","YjsThreadStore","fn","date","v4","yCommentIndex","yArrayFindIndex","yComment","key","reactionsByUser","yArray","predicate","i"],"mappings":"41BAEaA,EAAcC,EAAAA,KAAK,OAAO,CACrC,KAAM,UACN,SAAU,GACV,UAAW,GACX,YAAa,GAEb,eAAgB,CAEd,MAAO,CAKL,OAAQ,CACN,UAAYC,GAAY,CAAC,CAACA,EAAQ,aAAa,aAAa,EAC5D,WAAaC,GACHA,EAAmC,OACvC,CACE,cAAe,MAAA,EAEjB,CAAA,EAEN,QAAS,EAAA,EAEX,SAAU,CACR,UAAYD,GAAYA,EAAQ,aAAa,mBAAmB,EAChE,WAAaC,IACJ,CACL,oBAAsBA,EAAoC,QAAA,GAG9D,QAAS,EAAA,CACX,CAEJ,EAEA,WAAW,CAAE,eAAAC,GAA2D,CACtE,MAAO,CACL,OACAC,EAAAA,gBAAgBD,EAAgB,CAC9B,MAAO,gBAAA,CACR,CAAA,CAEL,EAEA,WAAY,CACV,MAAO,CAAC,CAAE,IAAK,sBAAuB,CACxC,EA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D,GAAI,CAAAE,EAAgB,IAAID,CAAG,EAGpB,CACL,MAAMzC,EAAW,IAAIY,EAAE,IACvBZ,EAAS,IAAI,QAASZ,EAAQ,KAAK,EACnCY,EAAS,IAAI,YAAaoC,EAAK,QAAA,CAAS,EACxCpC,EAAS,IAAI,SAAU,KAAK,MAAM,EAClC0C,EAAgB,IAAID,EAAKzC,CAAQ,CACnC,CACF,CAAA,GAGKrE,EAAA,sBAAiB,KAAK,SAC1ByD,GAAoE,CACnE,MAAMkC,EAAU,KAAK,YAAY,IAAIlC,EAAQ,QAAQ,EACrD,GAAI,CAACkC,EACH,MAAM,IAAI,MAAM,kBAAkB,EAGpC,MAAMgB,EAAgBC,EACpBjB,EAAQ,IAAI,UAAU,EACrBxB,GAAYA,EAAQ,IAAI,IAAI,IAAMV,EAAQ,SAAA,EAG7C,GAAIkD,IAAkB,GACpB,MAAM,IAAI,MAAM,mBAAmB,EAGrC,MAAME,EAAWlB,EAAQ,IAAI,UAAU,EAAE,IAAIgB,CAAa,EAE1D,GACE,CAAC,KAAK,KAAK,kBAAkBpB,EAAcsB,CAAQ,EAAGpD,EAAQ,KAAK,EAEnE,MAAM,IAAI,MAAM,gBAAgB,EAGlC,MAAMqD,EAAM,GAAG,KAAK,MAAM,IAAIrD,EAAQ,KAAK,GAEnBoD,EAAS,IAAI,iBAAiB,EAEtC,OAAOC,CAAG,CAC5B,CAAA,GA5SiB,KAAA,OAAAxG,CAKnB,CAySF,CAEA,SAASsG,EACPI,EACAC,EACA,CACA,QAASC,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IACjC,GAAID,EAAUD,EAAO,IAAIE,CAAC,CAAC,EACzB,OAAOA,EAGX,MAAO,EACT"}
|
|
1
|
+
{"version":3,"file":"comments.cjs","sources":["../src/comments/mark.ts","../src/comments/userstore/UserStore.ts","../src/comments/extension.ts","../src/comments/threadstore/ThreadStoreAuth.ts","../src/comments/threadstore/DefaultThreadStoreAuth.ts","../src/comments/threadstore/ThreadStore.ts","../src/comments/threadstore/TipTapThreadStore.ts","../src/comments/threadstore/yjs/yjsHelpers.ts","../src/comments/threadstore/yjs/YjsThreadStoreBase.ts","../src/comments/threadstore/yjs/RESTYjsThreadStore.ts","../src/comments/threadstore/yjs/YjsThreadStore.ts"],"sourcesContent":["import { Mark, mergeAttributes } from \"@tiptap/core\";\n\nexport const CommentMark = Mark.create({\n name: \"comment\",\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n\n addAttributes() {\n // Return an object with attribute configuration\n return {\n // orphans are marks that currently don't have an active thread. It could be\n // that users have resolved the thread. Resolved threads by default are not shown in the document,\n // but we need to keep the mark (positioning) data so we can still \"revive\" it when the thread is unresolved\n // or we enter a \"comments\" view that includes resolved threads.\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-bn-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-bn-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"bn-thread-mark\",\n }),\n ];\n },\n\n parseHTML() {\n return [{ tag: \"span.bn-thread-mark\" }];\n },\n\n extendMarkSchema(extension) {\n if (extension.name === \"comment\") {\n return {\n blocknoteIgnore: true,\n };\n }\n return {};\n },\n});\n","import type { User } from \"../types.js\";\nimport { EventEmitter } from \"../../util/EventEmitter.js\";\n\n/**\n * The `UserStore` is used to retrieve and cache information about users.\n *\n * It does this by calling `resolveUsers` (which is user-defined in the Editor Options)\n * for users that are not yet cached.\n */\nexport class UserStore<U extends User> extends EventEmitter<any> {\n private userCache: Map<string, U> = new Map();\n\n // avoid duplicate loads\n private loadingUsers = new Set<string>();\n\n public constructor(\n private readonly resolveUsers: (userIds: string[]) => Promise<U[]>,\n ) {\n super();\n }\n\n /**\n * Load information about users based on an array of user ids.\n */\n public async loadUsers(userIds: string[]) {\n const missingUsers = userIds.filter(\n (id) => !this.userCache.has(id) && !this.loadingUsers.has(id),\n );\n\n if (missingUsers.length === 0) {\n return;\n }\n\n for (const id of missingUsers) {\n this.loadingUsers.add(id);\n }\n\n try {\n const users = await this.resolveUsers(missingUsers);\n for (const user of users) {\n this.userCache.set(user.id, user);\n }\n this.emit(\"update\", this.userCache);\n } finally {\n for (const id of missingUsers) {\n // delete the users from the loading set\n // on a next call to `loadUsers` we will either\n // return the cached user or retry loading the user if the request failed failed\n this.loadingUsers.delete(id);\n }\n }\n }\n\n /**\n * Retrieve information about a user based on their id, if cached.\n *\n * The user will have to be loaded via `loadUsers` first\n */\n public getUser(userId: string): U | undefined {\n return this.userCache.get(userId);\n }\n\n /**\n * Subscribe to changes in the user store.\n *\n * @param cb - The callback to call when the user store changes.\n * @returns A function to unsubscribe from the user store.\n */\n public subscribe(cb: (users: Map<string, U>) => void): () => void {\n return this.on(\"update\", cb);\n }\n}\n","import { Node } from \"prosemirror-model\";\nimport { Plugin, PluginKey } from \"prosemirror-state\";\nimport { Decoration, DecorationSet } from \"prosemirror-view\";\nimport { getRelativeSelection, ySyncPluginKey } from \"y-prosemirror\";\nimport {\n createExtension,\n createStore,\n ExtensionOptions,\n} from \"../editor/BlockNoteExtension.js\";\nimport { ShowSelectionExtension } from \"../extensions/ShowSelection/ShowSelection.js\";\nimport { CustomBlockNoteSchema } from \"../schema/schema.js\";\nimport { CommentMark } from \"./mark.js\";\nimport type { ThreadStore } from \"./threadstore/ThreadStore.js\";\nimport type { CommentBody, ThreadData } from \"./types.js\";\nimport { User } from \"./types.js\";\nimport { UserStore } from \"./userstore/UserStore.js\";\n\nconst PLUGIN_KEY = new PluginKey(\"blocknote-comments\");\n\ntype CommentsPluginState = {\n /**\n * Decorations to be rendered, specifically to indicate the selected thread\n */\n decorations: DecorationSet;\n};\n\n/**\n * Calculate the thread positions from the current document state\n */\nfunction getUpdatedThreadPositions(doc: Node, markType: string) {\n const threadPositions = new Map<string, { from: number; to: number }>();\n\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === markType) {\n const thisThreadId = (mark.attrs as { threadId: string | undefined })\n .threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n }\n });\n });\n return threadPositions;\n}\n\nexport const CommentsExtension = createExtension(\n ({\n editor,\n options: { schema: commentEditorSchema, threadStore, resolveUsers },\n }: ExtensionOptions<{\n /**\n * The thread store implementation to use for storing and retrieving comment threads\n */\n threadStore: ThreadStore;\n /**\n * Resolve user information for comments.\n *\n * See [Comments](https://www.blocknotejs.org/docs/features/collaboration/comments) for more info.\n */\n resolveUsers: (userIds: string[]) => Promise<User[]>;\n /**\n * A schema to use for the comment editor (which allows you to customize the blocks and styles that are available in the comment editor)\n */\n schema?: CustomBlockNoteSchema<any, any, any>;\n }>) => {\n if (!resolveUsers) {\n throw new Error(\n \"resolveUsers is required to be defined when using comments\",\n );\n }\n if (!threadStore) {\n throw new Error(\n \"threadStore is required to be defined when using comments\",\n );\n }\n const markType = CommentMark.name;\n\n const userStore = new UserStore<User>(resolveUsers);\n const store = createStore(\n {\n pendingComment: false,\n selectedThreadId: undefined as string | undefined,\n threadPositions: new Map<string, { from: number; to: number }>(),\n },\n {\n onUpdate() {\n // If the selected thread id changed, we need to update the decorations\n if (\n store.state.selectedThreadId !== store.prevState.selectedThreadId\n ) {\n // So, we issue a transaction to update the decorations\n editor.transact((tr) => tr.setMeta(PLUGIN_KEY, true));\n }\n },\n },\n );\n\n const updateMarksFromThreads = (threads: Map<string, ThreadData>) => {\n editor.transact((tr) => {\n tr.doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type.name === markType) {\n const markTypeInstance = mark.type;\n const markThreadId = mark.attrs.threadId as string;\n const thread = threads.get(markThreadId);\n const isOrphan = !!(\n !thread ||\n thread.resolved ||\n thread.deletedAt\n );\n\n if (isOrphan !== mark.attrs.orphan) {\n const trimmedFrom = Math.max(pos, 0);\n const trimmedTo = Math.min(\n pos + node.nodeSize,\n tr.doc.content.size - 1,\n tr.doc.content.size - 1,\n );\n tr.removeMark(trimmedFrom, trimmedTo, mark);\n tr.addMark(\n trimmedFrom,\n trimmedTo,\n markTypeInstance.create({\n ...mark.attrs,\n orphan: isOrphan,\n }),\n );\n\n if (isOrphan && store.state.selectedThreadId === markThreadId) {\n // unselect\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n }));\n }\n }\n }\n });\n });\n });\n };\n\n return {\n key: \"comments\",\n store,\n prosemirrorPlugins: [\n new Plugin<CommentsPluginState>({\n key: PLUGIN_KEY,\n state: {\n init() {\n return {\n decorations: DecorationSet.empty,\n };\n },\n apply(tr, state) {\n const action = tr.getMeta(PLUGIN_KEY);\n\n if (!tr.docChanged && !action) {\n return state;\n }\n\n // only update threadPositions if the doc changed\n const newThreadPositions = tr.docChanged\n ? getUpdatedThreadPositions(tr.doc, markType)\n : store.state.threadPositions;\n\n if (\n newThreadPositions.size > 0 ||\n store.state.threadPositions.size > 0\n ) {\n // small optimization; don't emit event if threadPositions before / after were both empty\n store.setState((prev) => ({\n ...prev,\n threadPositions: newThreadPositions,\n }));\n }\n\n // update decorations if doc or selected thread changed\n const decorations = [] as any[];\n\n if (store.state.selectedThreadId) {\n const selectedThreadPosition = newThreadPositions.get(\n store.state.selectedThreadId,\n );\n\n if (selectedThreadPosition) {\n decorations.push(\n Decoration.inline(\n selectedThreadPosition.from,\n selectedThreadPosition.to,\n {\n class: \"bn-thread-mark-selected\",\n },\n ),\n );\n }\n }\n\n return {\n decorations: DecorationSet.create(tr.doc, decorations),\n };\n },\n },\n props: {\n decorations(state) {\n return (\n PLUGIN_KEY.getState(state)?.decorations ?? DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const node = view.state.doc.nodeAt(pos);\n\n if (!node) {\n // unselect\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n }));\n return;\n }\n\n const commentMark = node.marks.find(\n (mark) =>\n mark.type.name === markType && mark.attrs.orphan !== true,\n );\n\n const threadId = commentMark?.attrs.threadId as\n | string\n | undefined;\n if (threadId !== store.state.selectedThreadId) {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: threadId,\n }));\n }\n },\n },\n }),\n ],\n threadStore: threadStore,\n mount() {\n const unsubscribe = threadStore.subscribe(updateMarksFromThreads);\n updateMarksFromThreads(threadStore.getThreads());\n\n const unsubscribeOnSelectionChange = editor.onSelectionChange(() => {\n if (store.state.pendingComment) {\n store.setState((prev) => ({\n ...prev,\n pendingComment: false,\n }));\n }\n });\n\n return () => {\n unsubscribe();\n unsubscribeOnSelectionChange();\n };\n },\n selectThread(threadId: string | undefined, scrollToThread = true) {\n if (store.state.selectedThreadId === threadId) {\n return;\n }\n store.setState((prev) => ({\n ...prev,\n pendingComment: false,\n selectedThreadId: threadId,\n }));\n\n if (threadId && scrollToThread) {\n const selectedThreadPosition =\n store.state.threadPositions.get(threadId);\n if (!selectedThreadPosition) {\n return;\n }\n (\n editor.prosemirrorView?.domAtPos(selectedThreadPosition.from)\n .node as Element | undefined\n )?.scrollIntoView({\n behavior: \"smooth\",\n block: \"center\",\n });\n }\n },\n startPendingComment() {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n pendingComment: true,\n }));\n editor\n .getExtension(ShowSelectionExtension)\n ?.showSelection(true, \"comments\");\n },\n stopPendingComment() {\n store.setState((prev) => ({\n ...prev,\n selectedThreadId: undefined,\n pendingComment: false,\n }));\n editor\n .getExtension(ShowSelectionExtension)\n ?.showSelection(false, \"comments\");\n },\n async createThread(options: {\n initialComment: { body: CommentBody; metadata?: any };\n metadata?: any;\n }) {\n const thread = await threadStore.createThread(options);\n if (threadStore.addThreadToDocument) {\n const view = editor.prosemirrorView!;\n const pmSelection = view.state.selection;\n const ystate = ySyncPluginKey.getState(view.state);\n const selection = {\n prosemirror: {\n head: pmSelection.head,\n anchor: pmSelection.anchor,\n },\n yjs: ystate\n ? getRelativeSelection(ystate.binding, view.state)\n : undefined,\n };\n await threadStore.addThreadToDocument({\n threadId: thread.id,\n selection,\n });\n } else {\n (editor as any)._tiptapEditor.commands.setMark(markType, {\n orphan: false,\n threadId: thread.id,\n });\n }\n },\n userStore,\n commentEditorSchema,\n tiptapExtensions: [CommentMark],\n } as const;\n },\n);\n","import { CommentData, ThreadData } from \"../types.js\";\n\nexport abstract class ThreadStoreAuth {\n abstract canCreateThread(): boolean;\n abstract canAddComment(thread: ThreadData): boolean;\n abstract canUpdateComment(comment: CommentData): boolean;\n abstract canDeleteComment(comment: CommentData): boolean;\n abstract canDeleteThread(thread: ThreadData): boolean;\n abstract canResolveThread(thread: ThreadData): boolean;\n abstract canUnresolveThread(thread: ThreadData): boolean;\n abstract canAddReaction(comment: CommentData, emoji?: string): boolean;\n abstract canDeleteReaction(comment: CommentData, emoji?: string): boolean;\n}\n","import { CommentData, ThreadData } from \"../types.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\n/*\n * The DefaultThreadStoreAuth class defines the authorization rules for interacting with comments.\n * We take a role (\"comment\" or \"editor\") and implement the rules.\n *\n * This class is then used in the UI to show / hide specific interactions.\n *\n * Rules:\n * - View-only users should not be able to see any comments\n * - Comment-only users and editors can:\n * - - create new comments / replies / reactions\n * - - edit / delete their own comments / reactions\n * - - resolve / unresolve threads\n * - Editors can also delete any comment or thread\n */\nexport class DefaultThreadStoreAuth extends ThreadStoreAuth {\n constructor(\n private readonly userId: string,\n private readonly role: \"comment\" | \"editor\",\n ) {\n super();\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canCreateThread(): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canAddComment(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should only be possible by the comment author\n */\n canUpdateComment(comment: CommentData): boolean {\n return comment.userId === this.userId;\n }\n\n /**\n * Auth: should be possible by the comment author OR an editor of the document\n */\n canDeleteComment(comment: CommentData): boolean {\n return comment.userId === this.userId || this.role === \"editor\";\n }\n\n /**\n * Auth: should only be possible by an editor of the document\n */\n canDeleteThread(_thread: ThreadData): boolean {\n return this.role === \"editor\";\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canResolveThread(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n */\n canUnresolveThread(_thread: ThreadData): boolean {\n return true;\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n *\n * 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?\n */\n canAddReaction(comment: CommentData, emoji?: string): boolean {\n if (!emoji) {\n return true;\n }\n\n return !comment.reactions.some(\n (reaction) =>\n reaction.emoji === emoji && reaction.userIds.includes(this.userId),\n );\n }\n\n /**\n * Auth: should be possible by anyone with comment access\n *\n * 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?\n */\n canDeleteReaction(comment: CommentData, emoji?: string): boolean {\n if (!emoji) {\n return true;\n }\n\n return comment.reactions.some(\n (reaction) =>\n reaction.emoji === emoji && reaction.userIds.includes(this.userId),\n );\n }\n}\n","import { CommentBody, CommentData, ThreadData } from \"../types.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\n/**\n * ThreadStore is an abstract class that defines the interface\n * to read / add / update / delete threads and comments.\n */\nexport abstract class ThreadStore {\n public readonly auth: ThreadStoreAuth;\n\n constructor(auth: ThreadStoreAuth) {\n this.auth = auth;\n }\n\n /**\n * A \"thread\" in the ThreadStore only contains information about the content\n * of the thread / comments. It does not contain information about the position.\n *\n * This function can be implemented to store the thread in the document (by creating a mark)\n * If not implemented, default behavior will apply (creating the mark via TipTap)\n * See CommentsPlugin.ts for more details.\n */\n abstract addThreadToDocument?(options: {\n threadId: string;\n selection: {\n prosemirror: {\n head: number;\n anchor: number;\n };\n yjs?: {\n head: any;\n anchor: any;\n };\n };\n }): Promise<void>;\n\n /**\n * Creates a new thread with an initial comment.\n */\n abstract createThread(options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }): Promise<ThreadData>;\n\n /**\n * Adds a comment to a thread.\n */\n abstract addComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }): Promise<CommentData>;\n\n /**\n * Updates a comment in a thread.\n */\n abstract updateComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }): Promise<void>;\n\n /**\n * Deletes a comment from a thread.\n */\n abstract deleteComment(options: {\n threadId: string;\n commentId: string;\n }): Promise<void>;\n\n /**\n * Deletes a thread.\n */\n abstract deleteThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Marks a thread as resolved.\n */\n abstract resolveThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Marks a thread as unresolved.\n */\n abstract unresolveThread(options: { threadId: string }): Promise<void>;\n\n /**\n * Adds a reaction to a comment.\n *\n * Auth: should be possible by anyone with comment access\n */\n abstract addReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }): Promise<void>;\n\n /**\n * Deletes a reaction from a comment.\n *\n * Auth: should be possible by the reaction author\n */\n abstract deleteReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }): Promise<void>;\n\n /**\n * Retrieve data for a specific thread.\n */\n abstract getThread(threadId: string): ThreadData;\n\n /**\n * Retrieve all threads.\n */\n abstract getThreads(): Map<string, ThreadData>;\n\n /**\n * Subscribe to changes in the thread store.\n *\n * @returns a function to unsubscribe from the thread store\n */\n abstract subscribe(\n cb: (threads: Map<string, ThreadData>) => void,\n ): () => void;\n}\n","import type {\n TCollabComment,\n TCollabThread,\n TiptapCollabProvider,\n} from \"@hocuspocus/provider\";\nimport {\n CommentBody,\n CommentData,\n CommentReactionData,\n ThreadData,\n} from \"../types.js\";\nimport { ThreadStore } from \"./ThreadStore.js\";\nimport { ThreadStoreAuth } from \"./ThreadStoreAuth.js\";\n\ntype ReactionAsTiptapData = {\n emoji: string;\n createdAt: number;\n userId: string;\n};\n\n/**\n * The `TiptapThreadStore` integrates with Tiptap's collaboration provider for comment management.\n * You can pass a `TiptapCollabProvider` to the constructor which takes care of storing the comments.\n *\n * Under the hood, this actually works similarly to the `YjsThreadStore` implementation. (comments are stored in the Yjs document)\n */\nexport class TiptapThreadStore extends ThreadStore {\n constructor(\n private readonly userId: string,\n private readonly provider: TiptapCollabProvider,\n auth: ThreadStoreAuth, // TODO: use?\n ) {\n super(auth);\n }\n\n /**\n * Creates a new thread with an initial comment.\n */\n public async createThread(options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }): Promise<ThreadData> {\n let thread = this.provider.createThread({\n data: options.metadata,\n });\n\n thread = this.provider.addComment(thread.id, {\n content: options.initialComment.body,\n data: {\n metadata: options.initialComment.metadata,\n userId: this.userId,\n },\n });\n\n return this.tiptapThreadToThreadData(thread);\n }\n\n // TipTapThreadStore does not support addThreadToDocument\n public addThreadToDocument = undefined;\n\n /**\n * Adds a comment to a thread.\n */\n public async addComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }): Promise<CommentBody> {\n const thread = this.provider.addComment(options.threadId, {\n content: options.comment.body,\n data: {\n metadata: options.comment.metadata,\n userId: this.userId,\n },\n });\n\n return this.tiptapCommentToCommentData(\n thread.comments[thread.comments.length - 1],\n );\n }\n\n /**\n * Updates a comment in a thread.\n */\n public async updateComment(options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n content: options.comment.body,\n data: {\n ...comment.data,\n metadata: options.comment.metadata,\n },\n });\n }\n\n private tiptapCommentToCommentData(comment: TCollabComment): CommentData {\n const reactions: CommentReactionData[] = [];\n\n for (const reaction of (comment.data?.reactions ||\n []) as ReactionAsTiptapData[]) {\n const existingReaction = reactions.find(\n (r) => r.emoji === reaction.emoji,\n );\n if (existingReaction) {\n existingReaction.userIds.push(reaction.userId);\n existingReaction.createdAt = new Date(\n Math.min(existingReaction.createdAt.getTime(), reaction.createdAt),\n );\n } else {\n reactions.push({\n emoji: reaction.emoji,\n createdAt: new Date(reaction.createdAt),\n userIds: [reaction.userId],\n });\n }\n }\n\n return {\n type: \"comment\",\n id: comment.id,\n body: comment.content,\n metadata: comment.data?.metadata,\n userId: comment.data?.userId,\n createdAt: new Date(comment.createdAt),\n updatedAt: new Date(comment.updatedAt),\n reactions,\n };\n }\n\n private tiptapThreadToThreadData(thread: TCollabThread): ThreadData {\n return {\n type: \"thread\",\n id: thread.id,\n comments: thread.comments.map((comment) =>\n this.tiptapCommentToCommentData(comment),\n ),\n resolved: !!thread.resolvedAt,\n metadata: thread.data?.metadata,\n createdAt: new Date(thread.createdAt),\n updatedAt: new Date(thread.updatedAt),\n };\n }\n\n /**\n * Deletes a comment from a thread.\n */\n public async deleteComment(options: { threadId: string; commentId: string }) {\n this.provider.deleteComment(options.threadId, options.commentId);\n }\n\n /**\n * Deletes a thread.\n */\n public async deleteThread(options: { threadId: string }) {\n this.provider.deleteThread(options.threadId);\n }\n\n /**\n * Marks a thread as resolved.\n */\n public async resolveThread(options: { threadId: string }) {\n this.provider.updateThread(options.threadId, {\n resolvedAt: new Date().toISOString(),\n });\n }\n\n /**\n * Marks a thread as unresolved.\n */\n public async unresolveThread(options: { threadId: string }) {\n this.provider.updateThread(options.threadId, {\n resolvedAt: null,\n });\n }\n\n /**\n * Adds a reaction to a comment.\n *\n * Auth: should be possible by anyone with comment access\n */\n public async addReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n data: {\n ...comment.data,\n reactions: [\n ...((comment.data?.reactions || []) as ReactionAsTiptapData[]),\n {\n emoji: options.emoji,\n createdAt: Date.now(),\n userId: this.userId,\n },\n ],\n },\n });\n }\n\n /**\n * Deletes a reaction from a comment.\n *\n * Auth: should be possible by the reaction author\n */\n public async deleteReaction(options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) {\n const comment = this.provider.getThreadComment(\n options.threadId,\n options.commentId,\n true,\n );\n\n if (!comment) {\n throw new Error(\"Comment not found\");\n }\n\n this.provider.updateComment(options.threadId, options.commentId, {\n data: {\n ...comment.data,\n reactions: (\n (comment.data?.reactions || []) as ReactionAsTiptapData[]\n ).filter(\n (reaction) =>\n reaction.emoji !== options.emoji && reaction.userId !== this.userId,\n ),\n },\n });\n }\n\n public getThread(threadId: string): ThreadData {\n const thread = this.provider.getThread(threadId);\n\n if (!thread) {\n throw new Error(\"Thread not found\");\n }\n\n return this.tiptapThreadToThreadData(thread);\n }\n\n public getThreads(): Map<string, ThreadData> {\n return new Map(\n this.provider\n .getThreads()\n .map((thread) => [thread.id, this.tiptapThreadToThreadData(thread)]),\n );\n }\n\n public subscribe(cb: (threads: Map<string, ThreadData>) => void): () => void {\n const newCb = () => {\n cb(this.getThreads());\n };\n this.provider.watchThreads(newCb);\n return () => {\n this.provider.unwatchThreads(newCb);\n };\n }\n}\n","import * as Y from \"yjs\";\nimport { CommentData, CommentReactionData, ThreadData } from \"../../types.js\";\n\nexport function commentToYMap(comment: CommentData) {\n const yMap = new Y.Map<any>();\n yMap.set(\"id\", comment.id);\n yMap.set(\"userId\", comment.userId);\n yMap.set(\"createdAt\", comment.createdAt.getTime());\n yMap.set(\"updatedAt\", comment.updatedAt.getTime());\n if (comment.deletedAt) {\n yMap.set(\"deletedAt\", comment.deletedAt.getTime());\n yMap.set(\"body\", undefined);\n } else {\n yMap.set(\"body\", comment.body);\n }\n if (comment.reactions.length > 0) {\n throw new Error(\"Reactions should be empty in commentToYMap\");\n }\n\n /**\n * Reactions are stored in a map keyed by {userId-emoji},\n * this makes it easy to add / remove reactions and in a way that works local-first.\n * The cost is that \"reading\" the reactions is a bit more complex (see yMapToReactions).\n */\n yMap.set(\"reactionsByUser\", new Y.Map());\n yMap.set(\"metadata\", comment.metadata);\n\n return yMap;\n}\n\nexport function threadToYMap(thread: ThreadData) {\n const yMap = new Y.Map();\n yMap.set(\"id\", thread.id);\n yMap.set(\"createdAt\", thread.createdAt.getTime());\n yMap.set(\"updatedAt\", thread.updatedAt.getTime());\n const commentsArray = new Y.Array<Y.Map<any>>();\n\n commentsArray.push(thread.comments.map((comment) => commentToYMap(comment)));\n\n yMap.set(\"comments\", commentsArray);\n yMap.set(\"resolved\", thread.resolved);\n yMap.set(\"resolvedUpdatedAt\", thread.resolvedUpdatedAt?.getTime());\n yMap.set(\"resolvedBy\", thread.resolvedBy);\n yMap.set(\"metadata\", thread.metadata);\n return yMap;\n}\n\ntype SingleUserCommentReactionData = {\n emoji: string;\n createdAt: Date;\n userId: string;\n};\n\nexport function yMapToReaction(\n yMap: Y.Map<any>,\n): SingleUserCommentReactionData {\n return {\n emoji: yMap.get(\"emoji\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n userId: yMap.get(\"userId\"),\n };\n}\n\nfunction yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {\n const flatReactions = [...yMap.values()].map((reaction: Y.Map<any>) =>\n yMapToReaction(reaction),\n );\n // combine reactions by the same emoji\n return flatReactions.reduce(\n (acc: CommentReactionData[], reaction: SingleUserCommentReactionData) => {\n const existingReaction = acc.find((r) => r.emoji === reaction.emoji);\n if (existingReaction) {\n existingReaction.userIds.push(reaction.userId);\n existingReaction.createdAt = new Date(\n Math.min(\n existingReaction.createdAt.getTime(),\n reaction.createdAt.getTime(),\n ),\n );\n } else {\n acc.push({\n emoji: reaction.emoji,\n createdAt: reaction.createdAt,\n userIds: [reaction.userId],\n });\n }\n return acc;\n },\n [] as CommentReactionData[],\n );\n}\n\nexport function yMapToComment(yMap: Y.Map<any>): CommentData {\n return {\n type: \"comment\",\n id: yMap.get(\"id\"),\n userId: yMap.get(\"userId\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n deletedAt: yMap.get(\"deletedAt\")\n ? new Date(yMap.get(\"deletedAt\"))\n : undefined,\n reactions: yMapToReactions(yMap.get(\"reactionsByUser\")),\n metadata: yMap.get(\"metadata\"),\n body: yMap.get(\"body\"),\n };\n}\n\nexport function yMapToThread(yMap: Y.Map<any>): ThreadData {\n return {\n type: \"thread\",\n id: yMap.get(\"id\"),\n createdAt: new Date(yMap.get(\"createdAt\")),\n updatedAt: new Date(yMap.get(\"updatedAt\")),\n comments: ((yMap.get(\"comments\") as Y.Array<Y.Map<any>>) || []).map(\n (comment) => yMapToComment(comment),\n ),\n resolved: yMap.get(\"resolved\"),\n resolvedUpdatedAt: new Date(yMap.get(\"resolvedUpdatedAt\")),\n resolvedBy: yMap.get(\"resolvedBy\"),\n metadata: yMap.get(\"metadata\"),\n };\n}\n","import * as Y from \"yjs\";\nimport { ThreadData } from \"../../types.js\";\nimport { ThreadStore } from \"../ThreadStore.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { yMapToThread } from \"./yjsHelpers.js\";\n\n/**\n * This is an abstract class that only implements the READ methods required by the ThreadStore interface.\n * The data is read from a Yjs Map.\n */\nexport abstract class YjsThreadStoreBase extends ThreadStore {\n constructor(\n protected readonly threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(auth);\n }\n\n // TODO: async / reactive interface?\n public getThread(threadId: string) {\n const yThread = this.threadsYMap.get(threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n const thread = yMapToThread(yThread);\n return thread;\n }\n\n public getThreads(): Map<string, ThreadData> {\n const threadMap = new Map<string, ThreadData>();\n this.threadsYMap.forEach((yThread, id) => {\n if (yThread instanceof Y.Map) {\n threadMap.set(id, yMapToThread(yThread));\n }\n });\n return threadMap;\n }\n\n public subscribe(cb: (threads: Map<string, ThreadData>) => void) {\n const observer = () => {\n cb(this.getThreads());\n };\n\n this.threadsYMap.observeDeep(observer);\n\n return () => {\n this.threadsYMap.unobserveDeep(observer);\n };\n }\n}\n","import * as Y from \"yjs\";\nimport { CommentBody } from \"../../types.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\n\n/**\n * This is a REST-based implementation of the YjsThreadStoreBase.\n * It Reads data directly from the underlying document (same as YjsThreadStore),\n * but for Writes, it sends data to a REST API that should:\n * - check the user has the correct permissions to make the desired changes\n * - apply the updates to the underlying Yjs document\n *\n * (see https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus)\n *\n * The reason we still use the Yjs document as underlying storage is that it makes it easy to\n * sync updates in real-time to other collaborators.\n * (but technically, you could also implement a different storage altogether\n * and not store the thread related data in the Yjs document)\n */\nexport class RESTYjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly BASE_URL: string,\n private readonly headers: Record<string, string>,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private doRequest = async (path: string, method: string, body?: any) => {\n const response = await fetch(`${this.BASE_URL}${path}`, {\n method,\n body: JSON.stringify(body),\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.headers,\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to ${method} ${path}: ${response.statusText}`);\n }\n\n return response.json();\n };\n\n public addThreadToDocument = async (options: {\n threadId: string;\n selection: {\n prosemirror: {\n head: number;\n anchor: number;\n };\n yjs: {\n head: any;\n anchor: any;\n };\n };\n }) => {\n const { threadId, ...rest } = options;\n return this.doRequest(`/${threadId}/addToDocument`, \"POST\", rest);\n };\n\n public createThread = async (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n return this.doRequest(\"\", \"POST\", options);\n };\n\n public addComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const { threadId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments`, \"POST\", rest);\n };\n\n public updateComment = (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(`/${threadId}/comments/${commentId}`, \"PUT\", rest);\n };\n\n public deleteComment = (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}?soft=${!!rest.softDelete}`,\n \"DELETE\",\n );\n };\n\n public deleteThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}`, \"DELETE\");\n };\n\n public resolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/resolve`, \"POST\");\n };\n\n public unresolveThread = (options: { threadId: string }) => {\n return this.doRequest(`/${options.threadId}/unresolve`, \"POST\");\n };\n\n public addReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n const { threadId, commentId, ...rest } = options;\n return this.doRequest(\n `/${threadId}/comments/${commentId}/reactions`,\n \"POST\",\n rest,\n );\n };\n\n public deleteReaction = (options: {\n threadId: string;\n commentId: string;\n emoji: string;\n }) => {\n return this.doRequest(\n `/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,\n \"DELETE\",\n );\n };\n}\n","import { v4 } from \"uuid\";\nimport * as Y from \"yjs\";\nimport { CommentBody, CommentData, ThreadData } from \"../../types.js\";\nimport { ThreadStoreAuth } from \"../ThreadStoreAuth.js\";\nimport { YjsThreadStoreBase } from \"./YjsThreadStoreBase.js\";\nimport {\n commentToYMap,\n threadToYMap,\n yMapToComment,\n yMapToThread,\n} from \"./yjsHelpers.js\";\n\n/**\n * This is a Yjs-based implementation of the ThreadStore interface.\n *\n * It reads and writes thread / comments information directly to the underlying Yjs Document.\n *\n * @important While this is the easiest to add to your app, there are two challenges:\n * - The user needs to be able to write to the Yjs document to store the information.\n * So a user without write access to the Yjs document cannot leave any comments.\n * - Even with write access, the operations are not secure. Unless your Yjs server\n * guards against malicious operations, it's technically possible for one user to make changes to another user's comments, etc.\n * (even though these options are not visible in the UI, a malicious user can make unauthorized changes to the underlying Yjs document)\n */\nexport class YjsThreadStore extends YjsThreadStoreBase {\n constructor(\n private readonly userId: string,\n threadsYMap: Y.Map<any>,\n auth: ThreadStoreAuth,\n ) {\n super(threadsYMap, auth);\n }\n\n private transact = <T, R>(\n fn: (options: T) => R,\n ): ((options: T) => Promise<R>) => {\n return async (options: T) => {\n return this.threadsYMap.doc!.transact(() => {\n return fn(options);\n });\n };\n };\n\n public createThread = this.transact(\n (options: {\n initialComment: {\n body: CommentBody;\n metadata?: any;\n };\n metadata?: any;\n }) => {\n if (!this.auth.canCreateThread()) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const comment: CommentData = {\n type: \"comment\",\n id: v4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n reactions: [],\n metadata: options.initialComment.metadata,\n body: options.initialComment.body,\n };\n\n const thread: ThreadData = {\n type: \"thread\",\n id: v4(),\n createdAt: date,\n updatedAt: date,\n comments: [comment],\n resolved: false,\n metadata: options.metadata,\n };\n\n this.threadsYMap.set(thread.id, threadToYMap(thread));\n\n return thread;\n },\n );\n\n // YjsThreadStore does not support addThreadToDocument\n public addThreadToDocument = undefined;\n\n public addComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canAddComment(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n const comment: CommentData = {\n type: \"comment\",\n id: v4(),\n userId: this.userId,\n createdAt: date,\n updatedAt: date,\n deletedAt: undefined,\n reactions: [],\n metadata: options.comment.metadata,\n body: options.comment.body,\n };\n\n (yThread.get(\"comments\") as Y.Array<Y.Map<any>>).push([\n commentToYMap(comment),\n ]);\n\n yThread.set(\"updatedAt\", new Date().getTime());\n return comment;\n },\n );\n\n public updateComment = this.transact(\n (options: {\n comment: {\n body: CommentBody;\n metadata?: any;\n };\n threadId: string;\n commentId: string;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canUpdateComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n yComment.set(\"body\", options.comment.body);\n yComment.set(\"updatedAt\", new Date().getTime());\n yComment.set(\"metadata\", options.comment.metadata);\n },\n );\n\n public deleteComment = this.transact(\n (options: {\n threadId: string;\n commentId: string;\n softDelete?: boolean;\n }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canDeleteComment(yMapToComment(yComment))) {\n throw new Error(\"Not authorized\");\n }\n\n if (yComment.get(\"deletedAt\")) {\n throw new Error(\"Comment already deleted\");\n }\n\n if (options.softDelete) {\n yComment.set(\"deletedAt\", new Date().getTime());\n yComment.set(\"body\", undefined);\n } else {\n yThread.get(\"comments\").delete(yCommentIndex);\n }\n\n if (\n (yThread.get(\"comments\") as Y.Array<any>)\n .toArray()\n .every((comment) => comment.get(\"deletedAt\"))\n ) {\n // all comments deleted\n if (options.softDelete) {\n yThread.set(\"deletedAt\", new Date().getTime());\n } else {\n this.threadsYMap.delete(options.threadId);\n }\n }\n\n yThread.set(\"updatedAt\", new Date().getTime());\n },\n );\n\n public deleteThread = this.transact((options: { threadId: string }) => {\n if (\n !this.auth.canDeleteThread(\n yMapToThread(this.threadsYMap.get(options.threadId)),\n )\n ) {\n throw new Error(\"Not authorized\");\n }\n\n this.threadsYMap.delete(options.threadId);\n });\n\n public resolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canResolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", true);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n yThread.set(\"resolvedBy\", this.userId);\n });\n\n public unresolveThread = this.transact((options: { threadId: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n if (!this.auth.canUnresolveThread(yMapToThread(yThread))) {\n throw new Error(\"Not authorized\");\n }\n\n yThread.set(\"resolved\", false);\n yThread.set(\"resolvedUpdatedAt\", new Date().getTime());\n });\n\n public addReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (!this.auth.canAddReaction(yMapToComment(yComment), options.emoji)) {\n throw new Error(\"Not authorized\");\n }\n\n const date = new Date();\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n if (reactionsByUser.has(key)) {\n // already exists\n return;\n } else {\n const reaction = new Y.Map();\n reaction.set(\"emoji\", options.emoji);\n reaction.set(\"createdAt\", date.getTime());\n reaction.set(\"userId\", this.userId);\n reactionsByUser.set(key, reaction);\n }\n },\n );\n\n public deleteReaction = this.transact(\n (options: { threadId: string; commentId: string; emoji: string }) => {\n const yThread = this.threadsYMap.get(options.threadId);\n if (!yThread) {\n throw new Error(\"Thread not found\");\n }\n\n const yCommentIndex = yArrayFindIndex(\n yThread.get(\"comments\"),\n (comment) => comment.get(\"id\") === options.commentId,\n );\n\n if (yCommentIndex === -1) {\n throw new Error(\"Comment not found\");\n }\n\n const yComment = yThread.get(\"comments\").get(yCommentIndex);\n\n if (\n !this.auth.canDeleteReaction(yMapToComment(yComment), options.emoji)\n ) {\n throw new Error(\"Not authorized\");\n }\n\n const key = `${this.userId}-${options.emoji}`;\n\n const reactionsByUser = yComment.get(\"reactionsByUser\");\n\n reactionsByUser.delete(key);\n },\n );\n}\n\nfunction yArrayFindIndex(\n yArray: Y.Array<any>,\n predicate: (item: any) => boolean,\n) {\n for (let i = 0; i < yArray.length; i++) {\n if (predicate(yArray.get(i))) {\n return i;\n }\n }\n return -1;\n}\n"],"names":["CommentMark","Mark","element","attributes","HTMLAttributes","mergeAttributes","extension","UserStore","EventEmitter","resolveUsers","__publicField","userIds","missingUsers","id","users","user","userId","cb","PLUGIN_KEY","PluginKey","getUpdatedThreadPositions","doc","markType","threadPositions","node","pos","mark","thisThreadId","from","to","currentPosition","CommentsExtension","createExtension","editor","commentEditorSchema","threadStore","userStore","store","createStore","tr","updateMarksFromThreads","threads","markTypeInstance","markThreadId","thread","isOrphan","trimmedFrom","trimmedTo","prev","Plugin","DecorationSet","state","action","newThreadPositions","decorations","selectedThreadPosition","Decoration","_a","view","event","commentMark","threadId","unsubscribe","unsubscribeOnSelectionChange","scrollToThread","_b","ShowSelectionExtension","options","pmSelection","ystate","ySyncPluginKey","selection","getRelativeSelection","ThreadStoreAuth","DefaultThreadStoreAuth","role","_thread","comment","emoji","reaction","ThreadStore","auth","TiptapThreadStore","provider","reactions","existingReaction","r","_c","newCb","commentToYMap","yMap","Y","threadToYMap","commentsArray","yMapToReaction","yMapToReactions","acc","yMapToComment","yMapToThread","YjsThreadStoreBase","threadsYMap","yThread","threadMap","observer","RESTYjsThreadStore","BASE_URL","headers","path","method","body","response","rest","commentId","YjsThreadStore","fn","date","v4","yCommentIndex","yArrayFindIndex","yComment","key","reactionsByUser","yArray","predicate","i"],"mappings":"41BAEaA,EAAcC,EAAAA,KAAK,OAAO,CACrC,KAAM,UACN,SAAU,GACV,UAAW,GACX,YAAa,GAEb,eAAgB,CAEd,MAAO,CAKL,OAAQ,CACN,UAAYC,GAAY,CAAC,CAACA,EAAQ,aAAa,aAAa,EAC5D,WAAaC,GACHA,EAAmC,OACvC,CACE,cAAe,MAAA,EAEjB,CAAA,EAEN,QAAS,EAAA,EAEX,SAAU,CACR,UAAYD,GAAYA,EAAQ,aAAa,mBAAmB,EAChE,WAAaC,IACJ,CACL,oBAAsBA,EAAoC,QAAA,GAG9D,QAAS,EAAA,CACX,CAEJ,EAEA,WAAW,CAAE,eAAAC,GAA2D,CACtE,MAAO,CACL,OACAC,EAAAA,gBAAgBD,EAAgB,CAC9B,MAAO,gBAAA,CACR,CAAA,CAEL,EAEA,WAAY,CACV,MAAO,CAAC,CAAE,IAAK,sBAAuB,CACxC,EAEA,iBAAiBE,EAAW,CAC1B,OAAIA,EAAU,OAAS,UACd,CACL,gBAAiB,EAAA,EAGd,CAAA,CACT,CACF,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,IAAI,QAASZ,EAAQ,KAAK,EACnCY,EAAS,IAAI,YAAaoC,EAAK,QAAA,CAAS,EACxCpC,EAAS,IAAI,SAAU,KAAK,MAAM,EAClC0C,EAAgB,IAAID,EAAKzC,CAAQ,CACnC,CACF,CAAA,GAGKrE,EAAA,sBAAiB,KAAK,SAC1ByD,GAAoE,CACnE,MAAMkC,EAAU,KAAK,YAAY,IAAIlC,EAAQ,QAAQ,EACrD,GAAI,CAACkC,EACH,MAAM,IAAI,MAAM,kBAAkB,EAGpC,MAAMgB,EAAgBC,EACpBjB,EAAQ,IAAI,UAAU,EACrBxB,GAAYA,EAAQ,IAAI,IAAI,IAAMV,EAAQ,SAAA,EAG7C,GAAIkD,IAAkB,GACpB,MAAM,IAAI,MAAM,mBAAmB,EAGrC,MAAME,EAAWlB,EAAQ,IAAI,UAAU,EAAE,IAAIgB,CAAa,EAE1D,GACE,CAAC,KAAK,KAAK,kBAAkBpB,EAAcsB,CAAQ,EAAGpD,EAAQ,KAAK,EAEnE,MAAM,IAAI,MAAM,gBAAgB,EAGlC,MAAMqD,EAAM,GAAG,KAAK,MAAM,IAAIrD,EAAQ,KAAK,GAEnBoD,EAAS,IAAI,iBAAiB,EAEtC,OAAOC,CAAG,CAC5B,CAAA,GA5SiB,KAAA,OAAAxG,CAKnB,CAySF,CAEA,SAASsG,EACPI,EACAC,EACA,CACA,QAASC,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IACjC,GAAID,EAAUD,EAAO,IAAIE,CAAC,CAAC,EACzB,OAAOA,EAGX,MAAO,EACT"}
|
package/dist/comments.js
CHANGED
|
@@ -5,7 +5,7 @@ import { PluginKey as $, Plugin as k } from "prosemirror-state";
|
|
|
5
5
|
import { DecorationSet as C, Decoration as z } from "prosemirror-view";
|
|
6
6
|
import { ySyncPluginKey as B, getRelativeSelection as q } from "y-prosemirror";
|
|
7
7
|
import { c as L, a as N } from "./BlockNoteExtension-C2X7LW-V.js";
|
|
8
|
-
import { S } from "./ShowSelection-
|
|
8
|
+
import { S } from "./ShowSelection-B0ch3unP.js";
|
|
9
9
|
import { Mark as O, mergeAttributes as _ } from "@tiptap/core";
|
|
10
10
|
import { E as H } from "./EventEmitter-CjSwpTbz.js";
|
|
11
11
|
import * as g from "yjs";
|
|
@@ -279,7 +279,7 @@ const ne = L(
|
|
|
279
279
|
...i,
|
|
280
280
|
selectedThreadId: void 0,
|
|
281
281
|
pendingComment: !0
|
|
282
|
-
})), (n = r.getExtension(S)) == null || n.showSelection(!0);
|
|
282
|
+
})), (n = r.getExtension(S)) == null || n.showSelection(!0, "comments");
|
|
283
283
|
},
|
|
284
284
|
stopPendingComment() {
|
|
285
285
|
var n;
|
|
@@ -287,7 +287,7 @@ const ne = L(
|
|
|
287
287
|
...i,
|
|
288
288
|
selectedThreadId: void 0,
|
|
289
289
|
pendingComment: !1
|
|
290
|
-
})), (n = r.getExtension(S)) == null || n.showSelection(!1);
|
|
290
|
+
})), (n = r.getExtension(S)) == null || n.showSelection(!1, "comments");
|
|
291
291
|
},
|
|
292
292
|
async createThread(n) {
|
|
293
293
|
const i = await e.createThread(n);
|